X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkDicomRT_Contour.cxx;h=ee55e44bc704986ce736c82e19fa7a9c423b145b;hb=e45a45ee23c57b4875d349f7210fbcdb24e375e1;hp=9f63dac8060b2a8ac0e2b97a20ea79a4043cc634;hpb=c69e6ac8e16ac42d32f3a13d60396ddf65616188;p=clitk.git diff --git a/common/clitkDicomRT_Contour.cxx b/common/clitkDicomRT_Contour.cxx index 9f63dac..ee55e44 100644 --- a/common/clitkDicomRT_Contour.cxx +++ b/common/clitkDicomRT_Contour.cxx @@ -4,7 +4,7 @@ Authors belongs to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -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,124 @@ void clitk::DicomRT_Contour::Print(std::ostream & os) const //-------------------------------------------------------------------- #if GDCM_MAJOR_VERSION == 2 +void clitk::DicomRT_Contour::UpdateDicomItem() +{ + DD("DicomRT_Contour::UpdateDicomItem"); + + gdcm::DataSet & nestedds = mItem->GetNestedDataSet(); + + //NON CONSIDER CONTOUR ITEM NOT SEQ ITEM ? + + // Contour type [Contour Geometric Type] + gdcm::Attribute<0x3006,0x0042> contgeotype; + contgeotype.SetFromDataSet( nestedds ); + + // Number of points [Number of Contour Points] + gdcm::Attribute<0x3006,0x0046> numcontpoints; + numcontpoints.SetFromDataSet( nestedds ); + DD(mNbOfPoints); + mNbOfPoints = numcontpoints.GetValue(); + DD(mNbOfPoints); + + // Contour dicom values from DataPoints + //ComputeDataPointsFromMesh(); + uint nb = mData->GetNumberOfPoints(); + std::vector points; + points.resize(mNbOfPoints*3); + for(unsigned int i=0; iGetPoint(i); + points[i*3] = p[0]; + points[i*3+1] = p[1]; + points[i*3+2] = p[2]; + } + + // Get attribute + gdcm::Attribute<0x3006,0x0050> at; + gdcm::Tag tcontourdata(0x3006,0x0050); + gdcm::DataElement contourdata = nestedds.GetDataElement( tcontourdata ); + at.SetFromDataElement( contourdata ); + + // Set attribute + at.SetValues(&points[0], points.size(), false); + DD(at.GetValues()[0]); + + DD("replace"); + nestedds.Replace(at.GetAsDataElement()); + DD("done"); + + // Change Number of points [Number of Contour Points] + numcontpoints.SetValue(nb); + nestedds.Replace(numcontpoints.GetAsDataElement()); + + // Test + gdcm::DataElement aa = nestedds.GetDataElement( tcontourdata ); + at.SetFromDataElement( aa ); + const double* bb = at.GetValues(); + DD(bb[0]); + +} +#endif +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +#if GDCM_MAJOR_VERSION == 2 +bool clitk::DicomRT_Contour::Read(gdcm::Item * item) +{ + mItem = 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) { @@ -103,7 +226,7 @@ bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item) vtkPolyData * clitk::DicomRT_Contour::GetMesh() { if (!mMeshIsUpToDate) { - ComputeMesh(); + ComputeMeshFromDataPoints(); } return mMesh; } @@ -111,7 +234,15 @@ vtkPolyData * clitk::DicomRT_Contour::GetMesh() //-------------------------------------------------------------------- -void clitk::DicomRT_Contour::ComputeMesh() +void clitk::DicomRT_Contour::SetMesh(vtkPolyData * mesh) +{ + mMesh = mesh; +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::DicomRT_Contour::ComputeMeshFromDataPoints() { // DD("ComputeMesh Contour"); mMesh = vtkSmartPointer::New(); @@ -125,11 +256,35 @@ void clitk::DicomRT_Contour::ComputeMesh() mData->GetPoint(idx)[2]); ids[0]=idx; ids[1]=(ids[0]+1) % mNbOfPoints; //0-1,1-2,...,n-1-0 - // DD(ids[0]); -// DD(ids[1]); mMesh->GetLines()->InsertNextCell(2,ids); } - // DD(mMesh->GetNumberOfCells()); mMeshIsUpToDate = true; } //-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::DicomRT_Contour::ComputeDataPointsFromMesh() +{ + DD("ComputeDataPointsFromMesh"); + + + /*todo + + mMesh = vtkSmartPointer::New(); + mMesh->Allocate(); //for cell structures + mPoints = vtkSmartPointer::New(); + mMesh->SetPoints(mPoints); + vtkIdType ids[2]; + for (unsigned int idx=0 ; idxGetPoints()->InsertNextPoint(mData->GetPoint(idx)[0], + mData->GetPoint(idx)[1], + mData->GetPoint(idx)[2]); + ids[0]=idx; + ids[1]=(ids[0]+1) % mNbOfPoints; //0-1,1-2,...,n-1-0 + mMesh->GetLines()->InsertNextCell(2,ids); + } + mMeshIsUpToDate = true; +*/ +} +//--------------------------------------------------------------------