diff --git a/Modules/DicomRT/include/mitkRTDoseReader.h b/Modules/DicomRT/include/mitkRTDoseReader.h index 2142547ea2..c37a10885b 100644 --- a/Modules/DicomRT/include/mitkRTDoseReader.h +++ b/Modules/DicomRT/include/mitkRTDoseReader.h @@ -1,86 +1,88 @@ /*=================================================================== 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: mitkClassMacroItkParent( 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(const char* filename); /** * Virtual destructor. */ virtual ~RTDoseReader(); protected: + mitk::Image::Pointer scaledDoseImage; + /** * Constructor. */ RTDoseReader(); }; } #endif diff --git a/Modules/DicomRT/src/mitkRTDoseReader.cpp b/Modules/DicomRT/src/mitkRTDoseReader.cpp index e7cd45d90c..10aaa9d86b 100644 --- a/Modules/DicomRT/src/mitkRTDoseReader.cpp +++ b/Modules/DicomRT/src/mitkRTDoseReader.cpp @@ -1,144 +1,157 @@ /*=================================================================== 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 +#include #include namespace mitk { RTDoseReader::RTDoseReader(){} RTDoseReader::~RTDoseReader(){} mitk::DataNode::Pointer RTDoseReader:: LoadRTDose(const char* filename) { DcmFileFormat fileformat; OFCondition outp = fileformat.loadFile(filename, EXS_Unknown); if(outp.bad()) { MITK_ERROR << "Cant read the file" << std::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" << std::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" << std::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->SetData(this->scaledDoseImage); originalNode->SetFloatProperty(mitk::RTConstants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str(),prescripeDose); originalNode->SetFloatProperty(mitk::RTConstants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), 40); originalNode->SetBoolProperty(mitk::RTConstants::DOSE_PROPERTY_NAME.c_str(),true); return originalNode; } template void RTDoseReader::MultiplayGridScaling(itk::Image* image, Float32 gridscale) { + typedef itk::Image OutputImageType; typedef itk::Image InputImageType; - itk::ImageRegionIterator it(image, - image->GetRequestedRegion()); - for(it=it.Begin(); !it.IsAtEnd(); ++it) - { - it.Set(it.Get()*gridscale); - } + + typedef itk::CastImageFilter CastFilterType; + typedef itk::ShiftScaleImageFilter ScaleFilterType; + typename CastFilterType::Pointer castFilter = CastFilterType::New(); + typename ScaleFilterType::Pointer scaleFilter = ScaleFilterType::New(); + + castFilter->SetInput(image); + scaleFilter->SetInput(castFilter->GetOutput()); + scaleFilter->SetScale(gridscale); + scaleFilter->Update(); + typename OutputImageType::Pointer scaledOutput = scaleFilter->GetOutput(); + this->scaledDoseImage = mitk::Image::New(); + + mitk::CastToMitkImage(scaledOutput, this->scaledDoseImage); } double RTDoseReader::GetMaxDoseValue(DcmDataset* dataSet) { DRTDoseIOD doseObject; OFCondition result = doseObject.read(*dataSet); if(result.bad()) { MITK_ERROR << "Error reading the RT Dose dataset" << std::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; } }