X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkDicomRT_Contour.cxx;h=9a5042befdef6b7b14f63a86d8e23aa42e290704;hb=342abd5c807dab47a30d8369aca8f7e5c9242b2b;hp=0cc62b0439c74dc7a756e050792f0a8e8a2d3dd9;hpb=8b7357d079eaecb4cbbc3c0cf8f104aa4dce9b0a;p=clitk.git diff --git a/common/clitkDicomRT_Contour.cxx b/common/clitkDicomRT_Contour.cxx index 0cc62b0..9a5042b 100644 --- a/common/clitkDicomRT_Contour.cxx +++ b/common/clitkDicomRT_Contour.cxx @@ -20,7 +20,7 @@ #include "clitkDicomRT_Contour.h" #include -#if GDCM_MAJOR_VERSION == 2 +#if GDCM_MAJOR_VERSION >= 2 #include "gdcmAttribute.h" #include "gdcmItem.h" #endif @@ -53,10 +53,78 @@ void clitk::DicomRT_Contour::Print(std::ostream & os) const //-------------------------------------------------------------------- -#if GDCM_MAJOR_VERSION == 2 -bool clitk::DicomRT_Contour::Read(gdcm::Item const & item) +#if GDCM_MAJOR_VERSION >= 2 +void clitk::DicomRT_Contour::UpdateDicomItem() { - const gdcm::DataSet& nestedds2 = item.GetNestedDataSet(); + 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]; +#if VTK_MAJOR_VERSION <= 5 + points[i*3+1] = p[2]; +#else + points[i*3+1] = p[2]-0.5; +#endif + } + + // 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; @@ -82,7 +150,7 @@ bool clitk::DicomRT_Contour::Read(gdcm::Item const & item) 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 @@ -93,7 +161,11 @@ bool clitk::DicomRT_Contour::Read(gdcm::Item const & item) double p[3]; p[0] = points[i*3]; p[1] = points[i*3+1]; +#if VTK_MAJOR_VERSION <= 5 p[2] = points[i*3+2]; +#else + p[2] = points[i*3+2]+0.5; +#endif mData->SetPoint(i, p); if (mZ == -1) mZ = p[2]; if (p[2] != mZ) { @@ -140,7 +212,11 @@ bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item) double p[3]; p[0] = points[i*3]; p[1] = points[i*3+1]; +#if VTK_MAJOR_VERSION <= 5 p[2] = points[i*3+2]; +#else + p[2] = points[i*3+2]+0.5; +#endif mData->SetPoint(i, p); if (mZ == -1) mZ = p[2]; if (p[2] != mZ) { @@ -162,7 +238,7 @@ bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item) vtkPolyData * clitk::DicomRT_Contour::GetMesh() { if (!mMeshIsUpToDate) { - ComputeMesh(); + ComputeMeshFromDataPoints(); } return mMesh; } @@ -170,9 +246,63 @@ vtkPolyData * clitk::DicomRT_Contour::GetMesh() //-------------------------------------------------------------------- -void clitk::DicomRT_Contour::ComputeMesh() +void clitk::DicomRT_Contour::SetMesh(vtkPolyData * mesh) +{ + mMesh = mesh; +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::DicomRT_Contour::SetTransformMatrix(vtkMatrix4x4* matrix) +{ + mTransformMatrix = matrix; +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::DicomRT_Contour::ComputeMeshFromDataPoints() { // DD("ComputeMesh Contour"); + mMesh = vtkSmartPointer::New(); + mMesh->Allocate(); //for cell structures + mPoints = vtkSmartPointer::New(); + mMesh->SetPoints(mPoints); + vtkIdType ids[2]; + for (unsigned int idx=0 ; idxGetPoint(idx)[j]; + pointIn[3] = 1.0; + /*double pointOut[4]; + mTransformMatrix->MultiplyPoint(pointIn, pointOut); + std::cout << pointOut[0] << " " << pointOut[1] << " " << pointOut[2] << " " << pointOut[3] << std::endl; + mMesh->GetPoints()->InsertNextPoint(pointOut[0], + pointOut[1], + pointOut[2]);*/ + mMesh->GetPoints()->InsertNextPoint(mData->GetPoint(idx)[0], + mData->GetPoint(idx)[1], + mData->GetPoint(idx)[2]); + //std::cout << mData->GetPoint(idx)[0] << " " << mData->GetPoint(idx)[1] << " " << mData->GetPoint(idx)[2] << std::endl; + ids[0]=idx; + ids[1]=(ids[0]+1) % mNbOfPoints; //0-1,1-2,...,n-1-0 + mMesh->GetLines()->InsertNextCell(2,ids); + } + //std::cout << std::endl; + mMeshIsUpToDate = true; +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::DicomRT_Contour::ComputeDataPointsFromMesh() +{ + DD("ComputeDataPointsFromMesh"); + + + /*todo + mMesh = vtkSmartPointer::New(); mMesh->Allocate(); //for cell structures mPoints = vtkSmartPointer::New(); @@ -184,11 +314,9 @@ 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; +*/ } //--------------------------------------------------------------------