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