]> Creatis software - clitk.git/blob - common/clitkDicomRT_Contour.cxx
ac6d441e3b82694f59a532d154759a319b7374f4
[clitk.git] / common / clitkDicomRT_Contour.cxx
1 /*=========================================================================
2   Program:         vv http://www.creatis.insa-lyon.fr/rio/vv
3   Main authors :   XX XX XX
4
5   Authors belongs to: 
6   - University of LYON           http://www.universite-lyon.fr/
7   - Léon Bérard cancer center    http://oncora1.lyon.fnclcc.fr
8   - CREATIS CNRS laboratory      http://www.creatis.insa-lyon.fr
9
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.
13
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
17
18   =========================================================================*/
19
20 #include "clitkDicomRT_Contour.h" 
21 #include <vtkCellArray.h>
22
23 //--------------------------------------------------------------------
24 clitk::DicomRT_Contour::DicomRT_Contour() {
25   mMeshIsUpToDate = false;
26   mNbOfPoints = 0;
27 }
28 //--------------------------------------------------------------------
29
30
31 //--------------------------------------------------------------------
32 clitk::DicomRT_Contour::~DicomRT_Contour() {
33   
34 }
35 //--------------------------------------------------------------------
36
37
38
39 //--------------------------------------------------------------------
40 void clitk::DicomRT_Contour::Print(std::ostream & os) const {
41   DD("TODO : print Contours");
42 }
43 //--------------------------------------------------------------------
44
45
46 //--------------------------------------------------------------------
47 bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item) {
48   
49   // Contour type [Contour Geometric Type]
50   mType = item->GetEntryValue(0x3006,0x0042);
51   // DD(mType);
52   if (mType != "CLOSED_PLANAR ") { ///WARNING to the space after the name ...
53     std::cerr << "Skip this contour : type=" << mType << std::endl;
54     return false;
55   }
56   
57   // Number of points [Number of Contour Points]
58   mNbOfPoints = parse_value<int>(item->GetEntryValue(0x3006,0x0046));
59   // DD(mNbOfPoints);
60   
61   // Read values [Contour Data]
62   std::vector<float> points = parse_string<float>(item->GetEntryValue(0x3006,0x0050),'\\');
63   assert(points.size() == static_cast<unsigned int>(mNbOfPoints)*3);
64   
65   // Organize values
66   mData = vtkPoints::New();
67   mData->SetDataTypeToDouble();
68   mData->SetNumberOfPoints(mNbOfPoints);
69   double z = -1;
70   for(unsigned int i=0; i<mNbOfPoints; i++) {
71     double p[3];
72     p[0] = points[i*3];
73     p[1] = points[i*3+1];
74     p[2] = points[i*3+2];
75     mData->SetPoint(i, p);
76     if (z == -1) z = p[2];
77     if (p[2] != z) {
78       DD(i);
79       DD(p[2]);
80       DD(z);
81       std::cout << "ERROR ! contour not in the same slice" << std::endl;
82       assert(p[2] == z);
83     }
84   }
85
86   return true;
87 }
88 //--------------------------------------------------------------------
89
90
91 //--------------------------------------------------------------------
92 vtkPolyData * clitk::DicomRT_Contour::GetMesh() {
93   if (!mMeshIsUpToDate) {
94     ComputeMesh();
95   }
96   return mMesh;
97 }
98 //--------------------------------------------------------------------
99
100
101 //--------------------------------------------------------------------
102 void clitk::DicomRT_Contour::ComputeMesh() {  
103  //  DD("ComputeMesh Contour");
104   mMesh = vtkPolyData::New();
105   mMesh->Allocate(); //for cell structures
106   mMesh->SetPoints(vtkPoints::New());
107   vtkIdType ids[2];
108   for (unsigned int idx=0 ; idx<mNbOfPoints ; idx++) {
109     mMesh->GetPoints()->InsertNextPoint(mData->GetPoint(idx)[0], 
110                                         mData->GetPoint(idx)[1], 
111                                         mData->GetPoint(idx)[2]);
112     ids[0]=idx; 
113     ids[1]=(ids[0]+1) % mNbOfPoints; //0-1,1-2,...,n-1-0
114     // DD(ids[0]);
115 //     DD(ids[1]);
116     mMesh->GetLines()->InsertNextCell(2,ids);
117   }
118   // DD(mMesh->GetNumberOfCells());
119   mMeshIsUpToDate = true;
120 }
121 //--------------------------------------------------------------------