From b3f649f6e833485a45e94f99bd78d1dce03b3852 Mon Sep 17 00:00:00 2001 From: delmon Date: Mon, 4 Apr 2011 15:40:44 +0000 Subject: [PATCH] Mathieu Malaterre : - From gdcm 1.x to gdcm 2.0 - Upgrade RT_Contour --- common/clitkDicomRT_Contour.cxx | 60 +++++++++++++++++++++++++++++++ common/clitkDicomRT_Contour.h | 1 + common/clitkDicomRT_ROI.cxx | 64 +++++++++++++++++++++++++++++++++ common/clitkDicomRT_ROI.h | 1 + 4 files changed, 126 insertions(+) diff --git a/common/clitkDicomRT_Contour.cxx b/common/clitkDicomRT_Contour.cxx index 9f63dac..e39928a 100644 --- a/common/clitkDicomRT_Contour.cxx +++ b/common/clitkDicomRT_Contour.cxx @@ -20,6 +20,11 @@ #include "clitkDicomRT_Contour.h" #include +#if GDCM_MAJOR_VERSION == 2 +#include "gdcmAttribute.h" +#include "gdcmItem.h" +#endif + //-------------------------------------------------------------------- clitk::DicomRT_Contour::DicomRT_Contour() { @@ -49,6 +54,61 @@ void clitk::DicomRT_Contour::Print(std::ostream & os) const //-------------------------------------------------------------------- #if GDCM_MAJOR_VERSION == 2 +bool clitk::DicomRT_Contour::Read(gdcm::Item const & item) +{ + const gdcm::DataSet& nestedds2 = item.GetNestedDataSet(); + + // Contour type [Contour Geometric Type] + gdcm::Attribute<0x3006,0x0042> contgeotype; + contgeotype.SetFromDataSet( nestedds2 ); + + if (contgeotype.GetValue() != "CLOSED_PLANAR " && contgeotype.GetValue() != "POINT ") { ///WARNING to the space after the name ... + //std::cerr << "Skip this contour : type=" << mType << std::endl; + return false; + } + if (contgeotype.GetValue() == "POINT ") { + std::cerr << "Warning: POINT type not fully supported. (don't use GetMesh() with this!)" + << std::endl; + } + + gdcm::Attribute<0x3006,0x0046> numcontpoints; + numcontpoints.SetFromDataSet( nestedds2 ); + // Number of points [Number of Contour Points] + mNbOfPoints = numcontpoints.GetValue(); + // DD(mNbOfPoints); + + gdcm::Attribute<0x3006,0x0050> at; + gdcm::Tag tcontourdata(0x3006,0x0050); + const gdcm::DataElement & contourdata = nestedds2.GetDataElement( tcontourdata ); + at.SetFromDataElement( contourdata ); + const double* points = at.GetValues(); + unsigned int npts = at.GetNumberOfValues() / 3; + + assert(at.GetNumberOfValues() == static_cast(mNbOfPoints)*3); + + // Organize values + mData = vtkSmartPointer::New(); + mData->SetDataTypeToDouble(); + mData->SetNumberOfPoints(mNbOfPoints); + for(unsigned int i=0; iSetPoint(i, p); + if (mZ == -1) mZ = p[2]; + if (p[2] != mZ) { + DD(i); + DD(p[2]); + DD(mZ); + std::cout << "ERROR ! contour not in the same slice" << std::endl; + assert(p[2] == mZ); + } + } + + return true; + +} #else bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item) { diff --git a/common/clitkDicomRT_Contour.h b/common/clitkDicomRT_Contour.h index 53a1875..abf069f 100644 --- a/common/clitkDicomRT_Contour.h +++ b/common/clitkDicomRT_Contour.h @@ -43,6 +43,7 @@ public: void Print(std::ostream & os = std::cout) const; #if GDCM_MAJOR_VERSION == 2 + bool Read(gdcm::Item const & item); #else bool Read(gdcm::SQItem * item); #endif diff --git a/common/clitkDicomRT_ROI.cxx b/common/clitkDicomRT_ROI.cxx index 67e5341..cd8af0c 100644 --- a/common/clitkDicomRT_ROI.cxx +++ b/common/clitkDicomRT_ROI.cxx @@ -21,6 +21,11 @@ #include #include +#if GDCM_MAJOR_VERSION == 2 +#include "gdcmAttribute.h" +#include "gdcmItem.h" +#endif + //-------------------------------------------------------------------- clitk::DicomRT_ROI::DicomRT_ROI() { @@ -130,6 +135,65 @@ double clitk::DicomRT_ROI::GetForegroundValueLabelImage() const //-------------------------------------------------------------------- #if GDCM_MAJOR_VERSION == 2 +void clitk::DicomRT_ROI::Read(std::map & rois, gdcm::Item const & item) +{ + const gdcm::DataSet& nestedds = item.GetNestedDataSet(); + + gdcm::Attribute<0x3006,0x0084> referencedroinumber; + referencedroinumber.SetFromDataSet( nestedds ); + // Change number if needed + + // TODO + + // ROI number [Referenced ROI Number] + mNumber = referencedroinumber.GetValue(); + + // Retrieve ROI Name + mName = rois[mNumber]; + + // ROI Color [ROI Display Color] + gdcm::Attribute<0x3006,0x002a> color = {}; + color.SetFromDataSet( nestedds ); + assert( color.GetNumberOfValues() == 3 ); + mColor[0] = color.GetValue(0); + mColor[1] = color.GetValue(1); + mColor[2] = color.GetValue(2); + + // Read contours [Contour Sequence] + gdcm::Tag tcsq(0x3006,0x0040); + if( !nestedds.FindDataElement( tcsq ) ) + { + } + const gdcm::DataElement& csq = nestedds.GetDataElement( tcsq ); + gdcm::SmartPointer sqi2 = csq.GetValueAsSQ(); + if( !sqi2 || !sqi2->GetNumberOfItems() ) + { + } + unsigned int nitems = sqi2->GetNumberOfItems(); + + bool contour_processed=false; + bool delta_computed=false; + double last_z=0; + for(unsigned int i = 0; i < nitems; ++i) + { + const gdcm::Item & j = sqi2->GetItem(i+1); // Item start at #1 + DicomRT_Contour::Pointer c = DicomRT_Contour::New(); + bool b = c->Read(j); + 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(); + } + } + +} #else void clitk::DicomRT_ROI::Read(std::map & rois, gdcm::SQItem * item) { diff --git a/common/clitkDicomRT_ROI.h b/common/clitkDicomRT_ROI.h index 8a24b47..b6cc676 100644 --- a/common/clitkDicomRT_ROI.h +++ b/common/clitkDicomRT_ROI.h @@ -36,6 +36,7 @@ public: void Print(std::ostream & os = std::cout) const; #if GDCM_MAJOR_VERSION == 2 + void Read(std::map & rois, gdcm::Item const & item); #else void Read(std::map & rois, gdcm::SQItem * item); #endif -- 2.47.1