]> Creatis software - clitk.git/blob - common/clitkDicomRT_ROI.cxx
- remove comments and add reload capabilities
[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::string & clitk::DicomRT_ROI::GetFilename() const
73 {
74   return mFilename;
75 }
76 //--------------------------------------------------------------------
77
78
79 //--------------------------------------------------------------------
80 const std::vector<double> & clitk::DicomRT_ROI::GetDisplayColor() const
81 {
82   return mColor;
83 }
84 //--------------------------------------------------------------------
85
86
87 //--------------------------------------------------------------------
88 void clitk::DicomRT_ROI::Print(std::ostream & os) const
89 {
90   os << "ROI " << mNumber << "\t" << mName
91      << "\t(" << mColor[0] << " " << mColor[1] << " " << mColor[2] << ")"
92      << "\t Contours = " << mListOfContours.size() << std::endl;
93 }
94 //--------------------------------------------------------------------
95
96
97 //--------------------------------------------------------------------
98 void clitk::DicomRT_ROI::SetBackgroundValueLabelImage(double bg)
99 {
100   mBackgroundValue = bg;
101 }
102 //--------------------------------------------------------------------
103
104
105 //--------------------------------------------------------------------
106 double clitk::DicomRT_ROI::GetBackgroundValueLabelImage() const
107 {
108   return mBackgroundValue;
109 }
110 //--------------------------------------------------------------------
111
112
113 //--------------------------------------------------------------------
114 void clitk::DicomRT_ROI::Read(std::map<int, std::string> & rois, gdcm::SQItem * item)
115 {
116
117   // Change number if needed
118
119   // TODO
120
121   // ROI number [Referenced ROI Number]
122   mNumber = atoi(item->GetEntryValue(0x3006,0x0084).c_str());
123
124   // Retrieve ROI Name
125   mName = rois[mNumber];
126
127   // ROI Color [ROI Display Color]
128   mColor = clitk::parse_string<double>(item->GetEntryValue(0x3006,0x002a),'\\');
129
130   // Read contours [Contour Sequence]
131   gdcm::SeqEntry * contours=item->GetSeqEntry(0x3006,0x0040);
132   for(gdcm::SQItem* j=contours->GetFirstSQItem(); j!=0; j=contours->GetNextSQItem()) {
133     DicomRT_Contour * c = new DicomRT_Contour;
134     bool b = c->Read(j);
135     if (b) mListOfContours.push_back(c);
136   }
137 }
138 //--------------------------------------------------------------------
139
140
141 //--------------------------------------------------------------------
142 void clitk::DicomRT_ROI::SetImage(vvImage * image)
143 {
144   mImage = image;
145 }
146 //--------------------------------------------------------------------
147
148
149 //--------------------------------------------------------------------
150 vtkPolyData * clitk::DicomRT_ROI::GetMesh()
151 {
152   if (!mMeshIsUpToDate) {
153     ComputeMesh();
154   }
155   return mMesh;
156 }
157 //--------------------------------------------------------------------
158
159
160 //--------------------------------------------------------------------
161 void clitk::DicomRT_ROI::ComputeMesh()
162 {
163   vtkAppendPolyData * append = vtkAppendPolyData::New();
164   for(unsigned int i=0; i<mListOfContours.size(); i++) {
165     append->AddInput(mListOfContours[i]->GetMesh());
166   }
167   append->Update();
168   mMesh = append->GetOutput();
169   mMeshIsUpToDate = true;
170 }
171 //--------------------------------------------------------------------
172
173
174 //--------------------------------------------------------------------
175 void clitk::DicomRT_ROI::SetFromBinaryImage(vvImage::Pointer image, int n,
176                                             std::string name,
177                                             std::vector<double> color, 
178                                             std::string filename)
179 {
180
181   // ROI number [Referenced ROI Number]
182   mNumber = n;
183
184   // ROI Name
185   mName = name;
186   mFilename = filename;
187
188   // ROI Color [ROI Display Color]
189   mColor = color;
190
191   // No contours [Contour Sequence]
192   mListOfContours.clear();
193
194   // Set image
195   mImage = image;
196 }
197 //--------------------------------------------------------------------
198
199
200 //--------------------------------------------------------------------
201 const vvImage::Pointer clitk::DicomRT_ROI::GetImage() const
202 {
203   return mImage;
204 }
205 //--------------------------------------------------------------------