diff --git a/Modules/DicomRT/Testing/mitkRTDoseReaderTest.cpp b/Modules/DicomRT/Testing/mitkRTDoseReaderTest.cpp index 42bb697650..1b4affddb9 100644 --- a/Modules/DicomRT/Testing/mitkRTDoseReaderTest.cpp +++ b/Modules/DicomRT/Testing/mitkRTDoseReaderTest.cpp @@ -1,58 +1,54 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include class mitkRTDoseReaderTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkRTDoseReaderTestSuite); MITK_TEST(TestDoseImage); CPPUNIT_TEST_SUITE_END(); private: mitk::RTDoseReader::Pointer m_rtDoseReader; public: void setUp() { m_rtDoseReader = mitk::RTDoseReader::New(); CPPUNIT_ASSERT_MESSAGE("Failed to initialize RTDoseReader", m_rtDoseReader.IsNotNull()); } void TestDoseImage() { mitk::Image::Pointer refImage = mitk::IOUtil::LoadImage(GetTestDataFilePath("RT/Dose/RT_Dose.nrrd")); - DcmFileFormat file; - file.loadFile(GetTestDataFilePath("RT/Dose/Dose.dcm").c_str(), EXS_Unknown); - DcmDataset *dataset = file.getDataset(); - - mitk::DataNode::Pointer node = m_rtDoseReader->LoadRTDose(dataset,GetTestDataFilePath("RT/Dose/Dose.dcm").c_str()); + mitk::DataNode::Pointer node = m_rtDoseReader->LoadRTDose(GetTestDataFilePath("RT/Dose/Dose.dcm").c_str()); mitk::Image::Pointer image = dynamic_cast(node->GetData()); MITK_ASSERT_EQUAL(refImage, image, "referece-Image and image should be equal"); } }; MITK_TEST_SUITE_REGISTRATION(mitkRTDoseReader) diff --git a/Modules/DicomRT/mitkRTDoseReader.cpp b/Modules/DicomRT/mitkRTDoseReader.cpp index d606aa3c6a..68f41e8efd 100644 --- a/Modules/DicomRT/mitkRTDoseReader.cpp +++ b/Modules/DicomRT/mitkRTDoseReader.cpp @@ -1,137 +1,145 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkRTDoseReader.h" #include #include #include #include #include #include #include namespace mitk { RTDoseReader::RTDoseReader(){} RTDoseReader::~RTDoseReader(){} mitk::DataNode::Pointer RTDoseReader:: - LoadRTDose(DcmDataset* dataset, const char* filename) + LoadRTDose(const char* filename) { + DcmFileFormat fileformat; + OFCondition outp = fileformat.loadFile(filename, EXS_Unknown); + if(outp.bad()) + { + MITK_ERROR << "Cant read the file" << endl; + } + DcmDataset *dataset = fileformat.getDataset(); + std::string name = filename; itk::FilenamesContainer file; file.push_back(name); mitk::DicomSeriesReader* reader = new mitk::DicomSeriesReader; mitk::DataNode::Pointer originalNode = reader->LoadDicomSeries(file,false); if(originalNode.IsNull()) { MITK_ERROR << "Error reading the dcm file" << endl; return 0; } mitk::Image::Pointer originalImage = dynamic_cast(originalNode->GetData()); DRTDoseIOD doseObject; OFCondition result = doseObject.read(*dataset); if(result.bad()) { MITK_ERROR << "Error reading the Dataset" << endl; return 0; } OFString gridScaling; Float32 gridscale; doseObject.getDoseGridScaling(gridScaling); gridscale = OFStandard::atof(gridScaling.c_str()); AccessByItk_1(originalImage, MultiplayGridScaling, gridscale); double prescripeDose = this->GetMaxDoseValue(dataset); originalNode->SetName("RT Dose"); originalNode->SetFloatProperty(mitk::Constants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str(),prescripeDose); originalNode->SetFloatProperty(mitk::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), 40); originalNode->SetBoolProperty(mitk::Constants::DOSE_PROPERTY_NAME.c_str(),true); return originalNode; } template void RTDoseReader::MultiplayGridScaling(itk::Image* image, Float32 gridscale) { typedef itk::Image InputImageType; itk::ImageRegionIterator it(image, image->GetRequestedRegion()); for(it=it.Begin(); !it.IsAtEnd(); ++it) { it.Set(it.Get()*gridscale); } } double RTDoseReader::GetMaxDoseValue(DcmDataset* dataSet) { DRTDoseIOD doseObject; OFCondition result = doseObject.read(*dataSet); if(result.bad()) { MITK_ERROR << "Error reading the RT Dose dataset" << endl; return 0; } Uint16 rows, columns, frames; OFString nrframes, gridScaling; const Uint16 *pixelData = NULL; Float32 gridscale; Uint16 &rows_ref = rows; Uint16 &columns_ref = columns; doseObject.getRows(rows_ref); doseObject.getColumns(columns_ref); doseObject.getNumberOfFrames(nrframes); doseObject.getDoseGridScaling(gridScaling); frames = atoi(nrframes.c_str()); gridscale = OFStandard::atof(gridScaling.c_str()); dataSet->findAndGetUint16Array(DCM_PixelData, pixelData, 0); int size = columns*rows*frames; double highest = 0; for(int i=0; ihighest) { highest = pixelData[i] * gridscale; } } return highest; } } diff --git a/Modules/DicomRT/mitkRTDoseReader.h b/Modules/DicomRT/mitkRTDoseReader.h index bb5c711b7d..af90d0d14d 100644 --- a/Modules/DicomRT/mitkRTDoseReader.h +++ b/Modules/DicomRT/mitkRTDoseReader.h @@ -1,86 +1,86 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkDicomRTReader_h #define mitkDicomRTReader_h #include #include #include #include #include "dcmtk/dcmrt/drtdose.h" #include #include #include namespace mitk { class MitkDicomRT_EXPORT RTDoseReader: public itk::Object { public: mitkClassMacro( RTDoseReader, itk::Object ); itkNewMacro( Self ); template void MultiplayGridScaling( itk::Image< TPixel, VImageDimension>* image, Float32 gridscale); /** * @brief Get the maximum dose value from the dose file * @param dataSet The DcmDataset of the DicomRTDose file * @return The dose value * * Checks all pixel values for the maximum value */ double GetMaxDoseValue(DcmDataset* dataSet); /** * @brief Reads a DcmDataset from a DicomRT dose file * @param dataset DcmDataset-object from DCMTK * @param filename The path with the dose file used for getting the geometry * @return Returns a mitkDataNode::Pointer in which a mitk::Image is stored * * The method reads the PixelData from the DicomRT dose file and scales * them with a factor for getting Gray-values instead of pixel-values. * The Gray-values are stored in a mitkImage with a vtkColorTransferFunc. * Relative values are used for coloring the image. The relative values are * relative to a PrescriptionDose definied in the RT-Plan. If there is no * RT-Plan file PrescriptionDose is set to 80% of the maximum dose. */ - mitk::DataNode::Pointer LoadRTDose(DcmDataset* dataset, const char* filename); + mitk::DataNode::Pointer LoadRTDose(const char* filename); /** * Virtual destructor. */ virtual ~RTDoseReader(); protected: /** * Constructor. */ RTDoseReader(); }; } #endif