From: schaerer Date: Tue, 7 Sep 2010 16:39:55 +0000 (+0000) Subject: improvements to the Dicom struct handling code, including better computation of extruding X-Git-Tag: v1.2.0~412 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=75e2e05324d6eef978c5324160dd46eaaac66ea6;p=clitk.git improvements to the Dicom struct handling code, including better computation of extruding depth based on actual contour spacing and not image spacing --- diff --git a/common/clitkDicomRT_Contour.cxx b/common/clitkDicomRT_Contour.cxx index cee3b67..6059f03 100644 --- a/common/clitkDicomRT_Contour.cxx +++ b/common/clitkDicomRT_Contour.cxx @@ -25,6 +25,7 @@ clitk::DicomRT_Contour::DicomRT_Contour() { mMeshIsUpToDate = false; mNbOfPoints = 0; + mZ = -1; } //-------------------------------------------------------------------- @@ -74,20 +75,19 @@ bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item) mData = vtkPoints::New(); mData->SetDataTypeToDouble(); mData->SetNumberOfPoints(mNbOfPoints); - double z = -1; for(unsigned int i=0; iSetPoint(i, p); - if (z == -1) z = p[2]; - if (p[2] != z) { + if (mZ == -1) mZ = p[2]; + if (p[2] != mZ) { DD(i); DD(p[2]); - DD(z); + DD(mZ); std::cout << "ERROR ! contour not in the same slice" << std::endl; - assert(p[2] == z); + assert(p[2] == mZ); } } diff --git a/common/clitkDicomRT_Contour.h b/common/clitkDicomRT_Contour.h index 3e9ad8c..940f25a 100644 --- a/common/clitkDicomRT_Contour.h +++ b/common/clitkDicomRT_Contour.h @@ -40,6 +40,7 @@ namespace clitk { bool Read(gdcm::SQItem * item); vtkPolyData * GetMesh(); vtkPoints * GetPoints() {return mData;} + double GetZ() const {return mZ;} protected: void ComputeMesh(); @@ -48,6 +49,8 @@ namespace clitk { vtkPoints * mData; vtkPolyData * mMesh; bool mMeshIsUpToDate; + ///Z location of the contour + double mZ; }; //-------------------------------------------------------------------- diff --git a/common/clitkDicomRT_ROI.cxx b/common/clitkDicomRT_ROI.cxx index eb15105..6c9e977 100644 --- a/common/clitkDicomRT_ROI.cxx +++ b/common/clitkDicomRT_ROI.cxx @@ -31,6 +31,7 @@ clitk::DicomRT_ROI::DicomRT_ROI() mMeshIsUpToDate = false; mBackgroundValue = 0; mForegroundValue = 1; + mZDelta = 0; } //-------------------------------------------------------------------- @@ -147,10 +148,24 @@ void clitk::DicomRT_ROI::Read(std::map & rois, gdcm::SQItem * // Read contours [Contour Sequence] gdcm::SeqEntry * contours=item->GetSeqEntry(0x3006,0x0040); + bool contour_processed=false; + bool delta_computed=false; + double last_z=0; for(gdcm::SQItem* j=contours->GetFirstSQItem(); j!=0; j=contours->GetNextSQItem()) { DicomRT_Contour * c = new DicomRT_Contour; bool b = c->Read(j); - if (b) mListOfContours.push_back(c); + if (b) { + mListOfContours.push_back(c); + if (contour_processed) { + double delta=c->GetZ() - last_z; + if (delta_computed) + assert(mZDelta == delta); + else + mZDelta = delta; + } else + contour_processed=true; + last_z=c->GetZ(); + } } } //-------------------------------------------------------------------- diff --git a/common/clitkDicomRT_ROI.h b/common/clitkDicomRT_ROI.h index 288d4d9..c1cf977 100644 --- a/common/clitkDicomRT_ROI.h +++ b/common/clitkDicomRT_ROI.h @@ -57,6 +57,8 @@ namespace clitk { void SetImage(vvImage * im); DicomRT_Contour* GetContour(int n); + + double GetContourSpacing() const {return mZDelta;} protected: void ComputeMesh(); @@ -70,6 +72,8 @@ namespace clitk { vvImage::Pointer mImage; double mBackgroundValue; double mForegroundValue; + ///Spacing between two contours + double mZDelta; }; //-------------------------------------------------------------------- diff --git a/common/clitkDicomRT_ROI_ConvertToImageFilter.cxx b/common/clitkDicomRT_ROI_ConvertToImageFilter.cxx index 9694639..6c2fd39 100644 --- a/common/clitkDicomRT_ROI_ConvertToImageFilter.cxx +++ b/common/clitkDicomRT_ROI_ConvertToImageFilter.cxx @@ -17,19 +17,19 @@ =========================================================================*/ +#include +#include #include "clitkDicomRT_ROI_ConvertToImageFilter.h" #include #include #include #include -#include #include "clitkImageCommon.h" //-------------------------------------------------------------------- clitk::DicomRT_ROI_ConvertToImageFilter::DicomRT_ROI_ConvertToImageFilter() { mROI = NULL; - mImageInfoIsSet = false; mWriteOutput = false; mCropMask = true; } @@ -43,6 +43,10 @@ clitk::DicomRT_ROI_ConvertToImageFilter::~DicomRT_ROI_ConvertToImageFilter() } //-------------------------------------------------------------------- +bool clitk::DicomRT_ROI_ConvertToImageFilter::ImageInfoIsSet() const +{ + return mSize.size() && mSpacing.size() && mOrigin.size(); +} //-------------------------------------------------------------------- void clitk::DicomRT_ROI_ConvertToImageFilter::SetROI(clitk::DicomRT_ROI * roi) @@ -88,10 +92,23 @@ void clitk::DicomRT_ROI_ConvertToImageFilter::SetImageFilename(std::string f) mOrigin[i] = header->GetOrigin(i); mSize[i] = header->GetDimensions(i); } - mImageInfoIsSet = true; } //-------------------------------------------------------------------- +void clitk::DicomRT_ROI_ConvertToImageFilter::SetOutputOrigin(const double* origin) +{ + std::copy(origin,origin+3,std::back_inserter(mOrigin)); +} +//-------------------------------------------------------------------- +void clitk::DicomRT_ROI_ConvertToImageFilter::SetOutputSpacing(const double* spacing) +{ + std::copy(spacing,spacing+3,std::back_inserter(mSpacing)); +} +//-------------------------------------------------------------------- +void clitk::DicomRT_ROI_ConvertToImageFilter::SetOutputSize(const unsigned long* size) +{ + std::copy(size,size+3,std::back_inserter(mSize)); +} //-------------------------------------------------------------------- void clitk::DicomRT_ROI_ConvertToImageFilter::Update() @@ -100,7 +117,7 @@ void clitk::DicomRT_ROI_ConvertToImageFilter::Update() std::cerr << "Error. No ROI set, please use SetROI." << std::endl; exit(0); } - if (!mImageInfoIsSet) { + if (!ImageInfoIsSet()) { std::cerr << "Error. Please provide image info (spacing/origin) with SetImageFilename" << std::endl; exit(0); } @@ -159,8 +176,7 @@ void clitk::DicomRT_ROI_ConvertToImageFilter::Update() // Extrude vtkSmartPointer extrude=vtkSmartPointer::New(); extrude->SetInput(mesh); - ///We extrude in the -slice_spacing direction to respect the FOCAL convention // ????????????? - extrude->SetVector(0, 0, -mSpacing[2]); + extrude->SetVector(0, 0, mROI->GetContourSpacing()); // Binarization vtkSmartPointer sts=vtkSmartPointer::New(); @@ -194,6 +210,8 @@ void clitk::DicomRT_ROI_ConvertToImageFilter::Update() //-------------------------------------------------------------------- vtkImageData * clitk::DicomRT_ROI_ConvertToImageFilter::GetOutput() { + assert(mBinaryImage); return mBinaryImage; } //-------------------------------------------------------------------- + diff --git a/common/clitkDicomRT_ROI_ConvertToImageFilter.h b/common/clitkDicomRT_ROI_ConvertToImageFilter.h index d5d27b3..33d74b6 100644 --- a/common/clitkDicomRT_ROI_ConvertToImageFilter.h +++ b/common/clitkDicomRT_ROI_ConvertToImageFilter.h @@ -23,6 +23,8 @@ #include "clitkDicomRT_ROI.h" #include "clitkImageCommon.h" #include +#include +#include namespace clitk { @@ -34,25 +36,46 @@ namespace clitk { ~DicomRT_ROI_ConvertToImageFilter(); void SetROI(clitk::DicomRT_ROI * roi); + ///This is used to create a mask with the same characteristics as an input image void SetImageFilename(std::string s); + void SetOutputOrigin(const double* origin); + void SetOutputSpacing(const double* spacing); + void SetOutputSize(const unsigned long* size); void SetOutputImageFilename(std::string s); void Update(); vtkImageData * GetOutput(); + template typename itk::Image::ConstPointer GetITKOutput(); void SetCropMaskEnabled(bool b); protected: - bool mImageInfoIsSet; + bool ImageInfoIsSet() const; bool mWriteOutput; bool mCropMask; std::string mOutputFilename; std::vector mSpacing; std::vector mOrigin; - std::vector mSize; + std::vector mSize; clitk::DicomRT_ROI * mROI; vtkImageData * mBinaryImage; }; //-------------------------------------------------------------------- } // end namespace clitk + + +//-------------------------------------------------------------------- + +template +typename itk::Image::ConstPointer clitk::DicomRT_ROI_ConvertToImageFilter::GetITKOutput() +{ + assert(mBinaryImage); + typedef itk::Image ConnectorImageType; + typedef itk::VTKImageToImageFilter ConnectorType; + typename ConnectorType::Pointer connector = ConnectorType::New(); + connector->SetInput(mBinaryImage); + connector->Update(); + return connector->GetOutput(); +} +//-------------------------------------------------------------------- #endif // CLITKDICOMRT_ROI_CONVERTTOIMAGEFILTER_H