]> Creatis software - clitk.git/commitdiff
improvements to the Dicom struct handling code, including better computation of extruding
authorschaerer <schaerer>
Tue, 7 Sep 2010 16:39:55 +0000 (16:39 +0000)
committerschaerer <schaerer>
Tue, 7 Sep 2010 16:39:55 +0000 (16:39 +0000)
depth based on actual contour spacing and not image spacing

common/clitkDicomRT_Contour.cxx
common/clitkDicomRT_Contour.h
common/clitkDicomRT_ROI.cxx
common/clitkDicomRT_ROI.h
common/clitkDicomRT_ROI_ConvertToImageFilter.cxx
common/clitkDicomRT_ROI_ConvertToImageFilter.h

index cee3b678b8891718ece52546469e5e4eef23af27..6059f03b6644799d1bfff59410b17d499355e5b4 100644 (file)
@@ -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; i<mNbOfPoints; i++) {
     double p[3];
     p[0] = points[i*3];
     p[1] = points[i*3+1];
     p[2] = points[i*3+2];
     mData->SetPoint(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);
     }
   }
 
index 3e9ad8cf4edb6be410a9a16fe94e7cd1b8ae1978..940f25a7371e609d3b0186d054958e566ecd52fc 100644 (file)
@@ -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;
 
   };
   //--------------------------------------------------------------------
index eb1510530450cc50fd437f5534024cace98897ca..6c9e9777bebfd372168c55d1dbee3caf8b0b21ab 100644 (file)
@@ -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<int, std::string> & 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();
+    }
   }
 }
 //--------------------------------------------------------------------
index 288d4d950e8a5c82dbb30c1f0c9ff2eb1ceee40b..c1cf9778f2ca13838137b43b4b0f441ce32e6bfe 100644 (file)
@@ -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;
   };
   //--------------------------------------------------------------------
 
index 969463990b6fb71cb2534590299a9d254613cbb5..6c2fd39b035cc7c8337b9415579a6cea63489cff 100644 (file)
 
   =========================================================================*/
 
+#include <iterator>
+#include <algorithm>
 #include "clitkDicomRT_ROI_ConvertToImageFilter.h"
 #include <vtkPolyDataToImageStencil.h>
 #include <vtkSmartPointer.h>
 #include <vtkImageStencil.h>
 #include <vtkLinearExtrusionFilter.h>
-#include <itkVTKImageToImageFilter.h>
 #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<vtkLinearExtrusionFilter> extrude=vtkSmartPointer<vtkLinearExtrusionFilter>::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<vtkPolyDataToImageStencil> sts=vtkSmartPointer<vtkPolyDataToImageStencil>::New();
@@ -194,6 +210,8 @@ void clitk::DicomRT_ROI_ConvertToImageFilter::Update()
 //--------------------------------------------------------------------
 vtkImageData * clitk::DicomRT_ROI_ConvertToImageFilter::GetOutput()
 {
+  assert(mBinaryImage);
   return mBinaryImage;
 }
 //--------------------------------------------------------------------
+
index d5d27b31bbcd03bdf31f84f1d0ce9ba33307b18f..33d74b63df6acde0dd1027bdcc819b262deb27e3 100644 (file)
@@ -23,6 +23,8 @@
 #include "clitkDicomRT_ROI.h"
 #include "clitkImageCommon.h"
 #include <vtkImageData.h>
+#include <itkImage.h>
+#include <itkVTKImageToImageFilter.h>
 
 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 <int Dimension> typename itk::Image<unsigned char,Dimension>::ConstPointer GetITKOutput();
     void SetCropMaskEnabled(bool b);
 
   protected:
-    bool mImageInfoIsSet;
+    bool ImageInfoIsSet() const;
     bool mWriteOutput;
     bool mCropMask;
     std::string mOutputFilename;
     std::vector<double> mSpacing;
     std::vector<double> mOrigin;
-    std::vector<int> mSize;
+    std::vector<unsigned long> mSize;
     clitk::DicomRT_ROI * mROI;
     vtkImageData * mBinaryImage;
   };
   //--------------------------------------------------------------------
 
 } // end namespace clitk
+
+
+//--------------------------------------------------------------------
+
+template <int Dimension> 
+typename itk::Image<unsigned char,Dimension>::ConstPointer clitk::DicomRT_ROI_ConvertToImageFilter::GetITKOutput()
+{
+  assert(mBinaryImage);
+  typedef itk::Image<unsigned char,Dimension> ConnectorImageType;
+  typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
+  typename ConnectorType::Pointer connector = ConnectorType::New();
+  connector->SetInput(mBinaryImage);
+  connector->Update();
+  return connector->GetOutput();
+}
+//--------------------------------------------------------------------
 #endif // CLITKDICOMRT_ROI_CONVERTTOIMAGEFILTER_H