1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
3 Main authors : XX XX XX
6 - University of LYON http://www.universite-lyon.fr/
7 - Léon Bérard cancer center http://www.centreleonberard.fr
8 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the copyright notices for more information.
14 It is distributed under dual licence
15 - BSD http://www.opensource.org/licenses/bsd-license.php
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
18 =========================================================================*/
20 #include "clitkDicomRT_Contour.h"
21 #include <vtkCellArray.h>
23 #if GDCM_MAJOR_VERSION == 2
24 #include "gdcmAttribute.h"
28 //--------------------------------------------------------------------
29 clitk::DicomRT_Contour::DicomRT_Contour()
31 mMeshIsUpToDate = false;
35 //--------------------------------------------------------------------
38 //--------------------------------------------------------------------
39 clitk::DicomRT_Contour::~DicomRT_Contour()
43 //--------------------------------------------------------------------
47 //--------------------------------------------------------------------
48 void clitk::DicomRT_Contour::Print(std::ostream & os) const
50 DD("TODO : print Contours");
52 //--------------------------------------------------------------------
55 //--------------------------------------------------------------------
56 #if GDCM_MAJOR_VERSION == 2
57 bool clitk::DicomRT_Contour::Read(gdcm::Item const & item)
59 const gdcm::DataSet& nestedds2 = item.GetNestedDataSet();
61 // Contour type [Contour Geometric Type]
62 gdcm::Attribute<0x3006,0x0042> contgeotype;
63 contgeotype.SetFromDataSet( nestedds2 );
65 if (contgeotype.GetValue() != "CLOSED_PLANAR " && contgeotype.GetValue() != "POINT ") { ///WARNING to the space after the name ...
66 //std::cerr << "Skip this contour : type=" << mType << std::endl;
69 if (contgeotype.GetValue() == "POINT ") {
70 std::cerr << "Warning: POINT type not fully supported. (don't use GetMesh() with this!)"
74 gdcm::Attribute<0x3006,0x0046> numcontpoints;
75 numcontpoints.SetFromDataSet( nestedds2 );
76 // Number of points [Number of Contour Points]
77 mNbOfPoints = numcontpoints.GetValue();
80 gdcm::Attribute<0x3006,0x0050> at;
81 gdcm::Tag tcontourdata(0x3006,0x0050);
82 const gdcm::DataElement & contourdata = nestedds2.GetDataElement( tcontourdata );
83 at.SetFromDataElement( contourdata );
84 const double* points = at.GetValues();
85 unsigned int npts = at.GetNumberOfValues() / 3;
87 assert(at.GetNumberOfValues() == static_cast<unsigned int>(mNbOfPoints)*3);
90 mData = vtkSmartPointer<vtkPoints>::New();
91 mData->SetDataTypeToDouble();
92 mData->SetNumberOfPoints(mNbOfPoints);
93 for(unsigned int i=0; i<mNbOfPoints; i++) {
98 mData->SetPoint(i, p);
99 if (mZ == -1) mZ = p[2];
104 std::cout << "ERROR ! contour not in the same slice" << std::endl;
113 bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item)
116 // Contour type [Contour Geometric Type]
117 mType = item->GetEntryValue(0x3006,0x0042);
119 if (mType != "CLOSED_PLANAR " && mType != "POINT ") { ///WARNING to the space after the name ...
120 //std::cerr << "Skip this contour : type=" << mType << std::endl;
123 if (mType == "POINT ") {
124 std::cerr << "Warning: POINT type not fully supported. (don't use GetMesh() with this!)"
128 // Number of points [Number of Contour Points]
129 mNbOfPoints = parse_value<int>(item->GetEntryValue(0x3006,0x0046));
132 // Read values [Contour Data]
133 std::vector<float> points = parse_string<float>(item->GetEntryValue(0x3006,0x0050),'\\');
134 assert(points.size() == static_cast<unsigned int>(mNbOfPoints)*3);
137 mData = vtkSmartPointer<vtkPoints>::New();
138 mData->SetDataTypeToDouble();
139 mData->SetNumberOfPoints(mNbOfPoints);
140 for(unsigned int i=0; i<mNbOfPoints; i++) {
143 p[1] = points[i*3+1];
144 p[2] = points[i*3+2];
145 mData->SetPoint(i, p);
146 if (mZ == -1) mZ = p[2];
151 std::cout << "ERROR ! contour not in the same slice" << std::endl;
159 //--------------------------------------------------------------------
162 //--------------------------------------------------------------------
163 vtkPolyData * clitk::DicomRT_Contour::GetMesh()
165 if (!mMeshIsUpToDate) {
170 //--------------------------------------------------------------------
173 //--------------------------------------------------------------------
174 void clitk::DicomRT_Contour::ComputeMesh()
176 // DD("ComputeMesh Contour");
177 mMesh = vtkSmartPointer<vtkPolyData>::New();
178 mMesh->Allocate(); //for cell structures
179 mPoints = vtkSmartPointer<vtkPoints>::New();
180 mMesh->SetPoints(mPoints);
182 for (unsigned int idx=0 ; idx<mNbOfPoints ; idx++) {
183 mMesh->GetPoints()->InsertNextPoint(mData->GetPoint(idx)[0],
184 mData->GetPoint(idx)[1],
185 mData->GetPoint(idx)[2]);
187 ids[1]=(ids[0]+1) % mNbOfPoints; //0-1,1-2,...,n-1-0
190 mMesh->GetLines()->InsertNextCell(2,ids);
192 // DD(mMesh->GetNumberOfCells());
193 mMeshIsUpToDate = true;
195 //--------------------------------------------------------------------