X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkDicomRT_ROI.cxx;h=af8bee67a77a769e680c3ea892e91fd98e235a47;hb=HEAD;hp=98f9f59d1519bd0c8e5a99ca8ae631c3b8d0a1fa;hpb=f6ec1c5f4f1c2105b428fe2d87e794417897a4e8;p=clitk.git diff --git a/common/clitkDicomRT_ROI.cxx b/common/clitkDicomRT_ROI.cxx index 98f9f59..af8bee6 100644 --- a/common/clitkDicomRT_ROI.cxx +++ b/common/clitkDicomRT_ROI.cxx @@ -22,8 +22,10 @@ #include #include #include +#include +#include -#if GDCM_MAJOR_VERSION == 2 +#if GDCM_MAJOR_VERSION >= 2 #include "gdcmAttribute.h" #include "gdcmItem.h" #endif @@ -40,6 +42,7 @@ clitk::DicomRT_ROI::DicomRT_ROI() mBackgroundValue = 0; mForegroundValue = 1; SetDicomUptodateFlag(false); + mFilename = ""; } //-------------------------------------------------------------------- @@ -70,6 +73,14 @@ int clitk::DicomRT_ROI::GetROINumber() const //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +void clitk::DicomRT_ROI::SetROINumber(int number) +{ + mNumber = number; +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- const std::string & clitk::DicomRT_ROI::GetName() const { @@ -137,9 +148,10 @@ double clitk::DicomRT_ROI::GetForegroundValueLabelImage() const //-------------------------------------------------------------------- -#if GDCM_MAJOR_VERSION == 2 +#if GDCM_MAJOR_VERSION >= 2 bool clitk::DicomRT_ROI::Read(gdcm::Item * itemInfo, gdcm::Item * itemContour) { + //FATAL("Error : compile vv with itk4 + external gdcm"); // Keep dicom item mItemInfo = itemInfo; mItemContour = itemContour; @@ -192,6 +204,7 @@ bool clitk::DicomRT_ROI::Read(gdcm::Item * itemInfo, gdcm::Item * itemContour) gdcm::SmartPointer & sqi2 = mContoursSequenceOfItems; if( !sqi2 || !sqi2->GetNumberOfItems() ) { + return false; } unsigned int nitems = sqi2->GetNumberOfItems(); @@ -199,6 +212,7 @@ bool clitk::DicomRT_ROI::Read(gdcm::Item * itemInfo, gdcm::Item * itemContour) { gdcm::Item & j = sqi2->GetItem(i+1); // Item start at #1 DicomRT_Contour::Pointer c = DicomRT_Contour::New(); + c->SetTransformMatrix(mTransformMatrix); bool b = c->Read(&j); if (b) { mListOfContours.push_back(c); @@ -225,6 +239,7 @@ void clitk::DicomRT_ROI::Read(std::map & rois, gdcm::SQItem * int i=0; for(gdcm::SQItem* j=contours->GetFirstSQItem(); j!=0; j=contours->GetNextSQItem()) { DicomRT_Contour::Pointer c = DicomRT_Contour::New(); + c->SetTransformMatrix(mTransformMatrix); bool b = c->Read(j); if (b) { mListOfContours.push_back(c); @@ -273,7 +288,11 @@ void clitk::DicomRT_ROI::ComputeMeshFromContour() { vtkSmartPointer append = vtkSmartPointer::New(); for(unsigned int i=0; iAddInput(mListOfContours[i]->GetMesh()); +#if VTK_MAJOR_VERSION <= 5 + append->AddInput(mListOfContours[i]->GetMesh()); +#else + append->AddInputData(mListOfContours[i]->GetMesh()); +#endif } append->Update(); @@ -284,11 +303,12 @@ void clitk::DicomRT_ROI::ComputeMeshFromContour() //-------------------------------------------------------------------- -#if GDCM_MAJOR_VERSION == 2 - +#if GDCM_MAJOR_VERSION >= 2 //-------------------------------------------------------------------- void clitk::DicomRT_ROI::UpdateDicomItem() { + FATAL("Error : compile vv with itk4 + external gdcm"); + if (GetDicomUptoDateFlag()) return; DD("ROI::UpdateDicomItem"); DD(GetName()); @@ -343,7 +363,6 @@ void clitk::DicomRT_ROI::SetFromBinaryImage(vvImage::Pointer image, int n, std::vector color, std::string filename) { - // ROI number [Referenced ROI Number] mNumber = n; @@ -371,9 +390,18 @@ vvImage * clitk::DicomRT_ROI::GetImage() const //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +void clitk::DicomRT_ROI::SetTransformMatrix(vtkMatrix4x4* matrix) +{ + mTransformMatrix = matrix; +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- void clitk::DicomRT_ROI::ComputeContoursFromImage() { + FATAL("ComputeContoursFromImage should not be call. To be replace"); DD("ComputeMeshFromImage"); // Check that an image is loaded @@ -389,29 +417,123 @@ void clitk::DicomRT_ROI::ComputeContoursFromImage() // Get initial extend for the clipping vtkSmartPointer clipper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 clipper->SetInput(image); +#else + clipper->SetInputData(image); +#endif + int* extent = image->GetExtent(); DDV(extent, 6); // std::vector extend; - // Prepare the marching squares - vtkSmartPointer squares = vtkSmartPointer::New(); - squares->SetInput(clipper->GetOutput()); // Loop on slice uint n = image->GetDimensions()[2]; DD(n); + DD(mListOfContours.size()); + mListOfContours.resize(n); /// ???FIXME + DD(mListOfContours.size()); + std::vector > contours; for(uint i=0; i squares = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 + squares->SetInput(image); +#else + squares->SetInputData(image); +#endif + squares->SetImageRange(extent[0], extent[1], extent[2], extent[3], i, i); + squares->SetValue(1, 1.0); + squares->Update(); + DD(squares->GetNumberOfContours()); + + //clitk::DicomRT_Contour * contour = new clitk::DicomRT_Contour(); + //mListOfContours[i]->SetMesh(squares->GetOutput()); + + + vtkSmartPointer m = squares->GetOutput(); + contours.push_back(m); + + /* // Clip to the current slice extent[4] = extent[5] = image->GetOrigin()[2]+i*image->GetSpacing()[2]; DDV(extent, 6); + // Prepare the marching squares + vtkSmartPointer squares = vtkSmartPointer::New(); clipper->SetOutputWholeExtent(extent[0],extent[1],extent[2], - extent[3],extent[4],extent[5]); - + extent[3],extent[4],extent[5]); + squares->SetInput(clipper->GetOutput()); squares->Update(); DD(squares->GetNumberOfContours()); mListOfContours[i]->SetMesh(squares->GetOutput()); + */ + } + DD("done"); + + vtkSmartPointer append = vtkSmartPointer::New(); + for(unsigned int i=0; iAddInput(contours[i]); +#else + append->AddInputData(contours[i]); +#endif } + append->Update(); + + mMesh = vtkSmartPointer::New(); + mMesh->DeepCopy(append->GetOutput()); + + // Write vtk + vtkPolyDataWriter * w = vtkPolyDataWriter::New(); +#if VTK_MAJOR_VERSION <= 5 + w->SetInput(mMesh); +#else + w->SetInputData(mMesh); +#endif + w->SetFileName("toto.vtk"); + w->Write(); + + DD("done"); } //-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +#if CLITK_USE_SYSTEM_GDCM == 1 +void clitk::DicomRT_ROI::Read(vtkSmartPointer & reader, int roiindex) +{ + vtkRTStructSetProperties * p = reader->GetRTStructSetProperties(); + + mName = p->GetStructureSetROIName(roiindex); + mNumber = p->GetStructureSetROINumber(roiindex); + + //mColor = //FIXME !! + + // gdcm::Attribute<0x3006,0x002a> color = {}; + + // const gdcm::DataSet & nestedds = mItemContour->GetNestedDataSet(); + // color.SetFromDataSet( nestedds ); + // assert( color.GetNumberOfValues() == 3 ); + // mColor[0] = color.GetValue(0); + // mColor[1] = color.GetValue(1); + // mColor[2] = color.GetValue(2); + + + SetDicomUptodateFlag(true); + // Get the contour + mMesh = reader->GetOutput(roiindex); + DicomRT_Contour::Pointer c = DicomRT_Contour::New(); + c->SetTransformMatrix(mTransformMatrix); + c->SetMesh(mMesh); // FIXME no GetZ, not GetPoints + mMeshIsUpToDate = true; + mListOfContours.push_back(c); +} +#endif +//-------------------------------------------------------------------- +