]> Creatis software - clitk.git/blob - common/clitkDicomRT_ROI.cxx
Reformatted using new coding style
[clitk.git] / common / clitkDicomRT_ROI.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_ROI.h"
21 #include <vtkSmartPointer.h>
22 #include <vtkAppendPolyData.h>
23
24 //--------------------------------------------------------------------
25 clitk::DicomRT_ROI::DicomRT_ROI()
26 {
27   mName = "NoName";
28   mNumber = -1;
29   mColor.resize(3);
30   mColor[0] = mColor[1] = mColor[2] = 0;
31   mMeshIsUpToDate = false;
32 }
33 //--------------------------------------------------------------------
34
35
36 //--------------------------------------------------------------------
37 clitk::DicomRT_ROI::~DicomRT_ROI()
38 {
39
40 }
41 //--------------------------------------------------------------------
42
43
44 //--------------------------------------------------------------------
45 void clitk::DicomRT_ROI::SetDisplayColor(double r, double v, double b)
46 {
47   mColor.resize(3);
48   mColor[0] = r;
49   mColor[1] = v;
50   mColor[2] = b;
51 }
52 //--------------------------------------------------------------------
53
54
55 //--------------------------------------------------------------------
56 int clitk::DicomRT_ROI::GetROINumber() const
57 {
58   return mNumber;
59 }
60 //--------------------------------------------------------------------
61
62
63 //--------------------------------------------------------------------
64 const std::string & clitk::DicomRT_ROI::GetName() const
65 {
66   return mName;
67 }
68 //--------------------------------------------------------------------
69
70
71 //--------------------------------------------------------------------
72 const std::vector<double> & clitk::DicomRT_ROI::GetDisplayColor() const
73 {
74   return mColor;
75 }
76 //--------------------------------------------------------------------
77
78
79 //--------------------------------------------------------------------
80 void clitk::DicomRT_ROI::Print(std::ostream & os) const
81 {
82   os << "ROI " << mNumber << "\t" << mName
83      << "\t(" << mColor[0] << " " << mColor[1] << " " << mColor[2] << ")"
84      << "\t Contours = " << mListOfContours.size() << std::endl;
85 }
86 //--------------------------------------------------------------------
87
88
89 //--------------------------------------------------------------------
90 void clitk::DicomRT_ROI::SetBackgroundValueLabelImage(double bg)
91 {
92   mBackgroundValue = bg;
93 }
94 //--------------------------------------------------------------------
95
96
97 //--------------------------------------------------------------------
98 double clitk::DicomRT_ROI::GetBackgroundValueLabelImage() const
99 {
100   return mBackgroundValue;
101 }
102 //--------------------------------------------------------------------
103
104
105 //--------------------------------------------------------------------
106 void clitk::DicomRT_ROI::Read(std::map<int, std::string> & rois, gdcm::SQItem * item)
107 {
108
109   // Change number if needed
110
111   // TODO
112
113   // ROI number [Referenced ROI Number]
114   mNumber = atoi(item->GetEntryValue(0x3006,0x0084).c_str());
115
116   // Retrieve ROI Name
117   mName = rois[mNumber];
118
119   // ROI Color [ROI Display Color]
120   mColor = clitk::parse_string<double>(item->GetEntryValue(0x3006,0x002a),'\\');
121
122   // Read contours [Contour Sequence]
123   gdcm::SeqEntry * contours=item->GetSeqEntry(0x3006,0x0040);
124   for(gdcm::SQItem* j=contours->GetFirstSQItem(); j!=0; j=contours->GetNextSQItem()) {
125     DicomRT_Contour * c = new DicomRT_Contour;
126     bool b = c->Read(j);
127     if (b) mListOfContours.push_back(c);
128   }
129 }
130 //--------------------------------------------------------------------
131
132
133 //--------------------------------------------------------------------
134 vtkPolyData * clitk::DicomRT_ROI::GetMesh()
135 {
136   if (!mMeshIsUpToDate) {
137     ComputeMesh();
138   }
139   return mMesh;
140 }
141 //--------------------------------------------------------------------
142
143
144 //--------------------------------------------------------------------
145 void clitk::DicomRT_ROI::ComputeMesh()
146 {
147   vtkAppendPolyData * append = vtkAppendPolyData::New();
148   for(unsigned int i=0; i<mListOfContours.size(); i++) {
149     append->AddInput(mListOfContours[i]->GetMesh());
150   }
151   append->Update();
152   mMesh = append->GetOutput();
153   mMeshIsUpToDate = true;
154 }
155 //--------------------------------------------------------------------
156
157
158 //--------------------------------------------------------------------
159 void clitk::DicomRT_ROI::SetFromBinaryImage(vvImage::Pointer image, int n,
160     std::string name,
161     std::vector<double> color)
162 {
163
164   // ROI number [Referenced ROI Number]
165   mNumber = n;
166
167   // ROI Name
168   mName = name;
169
170   // ROI Color [ROI Display Color]
171   mColor = color;
172
173   // No contours [Contour Sequence]
174   mListOfContours.clear();
175
176   // Set image
177   mImage = image;
178 }
179 //--------------------------------------------------------------------
180
181
182 //--------------------------------------------------------------------
183 const vvImage::Pointer clitk::DicomRT_ROI::GetImage() const
184 {
185   return mImage;
186 }
187 //--------------------------------------------------------------------