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