]> Creatis software - clitk.git/blob - common/clitkDicomRT_Contour.cxx
Reformatted using new coding style
[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 {
26   mMeshIsUpToDate = false;
27   mNbOfPoints = 0;
28 }
29 //--------------------------------------------------------------------
30
31
32 //--------------------------------------------------------------------
33 clitk::DicomRT_Contour::~DicomRT_Contour()
34 {
35
36 }
37 //--------------------------------------------------------------------
38
39
40
41 //--------------------------------------------------------------------
42 void clitk::DicomRT_Contour::Print(std::ostream & os) const
43 {
44   DD("TODO : print Contours");
45 }
46 //--------------------------------------------------------------------
47
48
49 //--------------------------------------------------------------------
50 bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item)
51 {
52
53   // Contour type [Contour Geometric Type]
54   mType = item->GetEntryValue(0x3006,0x0042);
55   // DD(mType);
56   if (mType != "CLOSED_PLANAR ") { ///WARNING to the space after the name ...
57     std::cerr << "Skip this contour : type=" << mType << std::endl;
58     return false;
59   }
60
61   // Number of points [Number of Contour Points]
62   mNbOfPoints = parse_value<int>(item->GetEntryValue(0x3006,0x0046));
63   // DD(mNbOfPoints);
64
65   // Read values [Contour Data]
66   std::vector<float> points = parse_string<float>(item->GetEntryValue(0x3006,0x0050),'\\');
67   assert(points.size() == static_cast<unsigned int>(mNbOfPoints)*3);
68
69   // Organize values
70   mData = vtkPoints::New();
71   mData->SetDataTypeToDouble();
72   mData->SetNumberOfPoints(mNbOfPoints);
73   double z = -1;
74   for(unsigned int i=0; i<mNbOfPoints; i++) {
75     double p[3];
76     p[0] = points[i*3];
77     p[1] = points[i*3+1];
78     p[2] = points[i*3+2];
79     mData->SetPoint(i, p);
80     if (z == -1) z = p[2];
81     if (p[2] != z) {
82       DD(i);
83       DD(p[2]);
84       DD(z);
85       std::cout << "ERROR ! contour not in the same slice" << std::endl;
86       assert(p[2] == z);
87     }
88   }
89
90   return true;
91 }
92 //--------------------------------------------------------------------
93
94
95 //--------------------------------------------------------------------
96 vtkPolyData * clitk::DicomRT_Contour::GetMesh()
97 {
98   if (!mMeshIsUpToDate) {
99     ComputeMesh();
100   }
101   return mMesh;
102 }
103 //--------------------------------------------------------------------
104
105
106 //--------------------------------------------------------------------
107 void clitk::DicomRT_Contour::ComputeMesh()
108 {
109 //  DD("ComputeMesh Contour");
110   mMesh = vtkPolyData::New();
111   mMesh->Allocate(); //for cell structures
112   mMesh->SetPoints(vtkPoints::New());
113   vtkIdType ids[2];
114   for (unsigned int idx=0 ; idx<mNbOfPoints ; idx++) {
115     mMesh->GetPoints()->InsertNextPoint(mData->GetPoint(idx)[0],
116                                         mData->GetPoint(idx)[1],
117                                         mData->GetPoint(idx)[2]);
118     ids[0]=idx;
119     ids[1]=(ids[0]+1) % mNbOfPoints; //0-1,1-2,...,n-1-0
120     // DD(ids[0]);
121 //     DD(ids[1]);
122     mMesh->GetLines()->InsertNextCell(2,ids);
123   }
124   // DD(mMesh->GetNumberOfCells());
125   mMeshIsUpToDate = true;
126 }
127 //--------------------------------------------------------------------