1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
3 Main authors : XX XX XX
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
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.
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
18 =========================================================================*/
20 #include "clitkDicomRT_ROI.h"
21 #include <vtkSmartPointer.h>
22 #include <vtkAppendPolyData.h>
24 //--------------------------------------------------------------------
25 clitk::DicomRT_ROI::DicomRT_ROI()
30 mColor[0] = mColor[1] = mColor[2] = 0;
31 mMeshIsUpToDate = false;
36 //--------------------------------------------------------------------
39 //--------------------------------------------------------------------
40 clitk::DicomRT_ROI::~DicomRT_ROI()
43 //--------------------------------------------------------------------
46 //--------------------------------------------------------------------
47 void clitk::DicomRT_ROI::SetDisplayColor(double r, double v, double b)
54 //--------------------------------------------------------------------
57 //--------------------------------------------------------------------
58 int clitk::DicomRT_ROI::GetROINumber() const
62 //--------------------------------------------------------------------
65 //--------------------------------------------------------------------
66 const std::string & clitk::DicomRT_ROI::GetName() const
70 //--------------------------------------------------------------------
73 //--------------------------------------------------------------------
74 const std::string & clitk::DicomRT_ROI::GetFilename() const
78 //--------------------------------------------------------------------
81 //--------------------------------------------------------------------
82 const std::vector<double> & clitk::DicomRT_ROI::GetDisplayColor() const
86 //--------------------------------------------------------------------
89 //--------------------------------------------------------------------
90 void clitk::DicomRT_ROI::Print(std::ostream & os) const
92 os << "ROI " << mNumber << "\t" << mName
93 << "\t(" << mColor[0] << " " << mColor[1] << " " << mColor[2] << ")"
94 << "\t Contours = " << mListOfContours.size() << std::endl;
96 //--------------------------------------------------------------------
99 //--------------------------------------------------------------------
100 void clitk::DicomRT_ROI::SetBackgroundValueLabelImage(double bg)
102 mBackgroundValue = bg;
104 //--------------------------------------------------------------------
107 //--------------------------------------------------------------------
108 double clitk::DicomRT_ROI::GetBackgroundValueLabelImage() const
110 return mBackgroundValue;
112 //--------------------------------------------------------------------
115 //--------------------------------------------------------------------
116 void clitk::DicomRT_ROI::SetForegroundValueLabelImage(double bg)
118 mForegroundValue = bg;
120 //--------------------------------------------------------------------
123 //--------------------------------------------------------------------
124 double clitk::DicomRT_ROI::GetForegroundValueLabelImage() const
126 return mForegroundValue;
128 //--------------------------------------------------------------------
131 //--------------------------------------------------------------------
132 void clitk::DicomRT_ROI::Read(std::map<int, std::string> & rois, gdcm::SQItem * item)
135 // Change number if needed
139 // ROI number [Referenced ROI Number]
140 mNumber = atoi(item->GetEntryValue(0x3006,0x0084).c_str());
143 mName = rois[mNumber];
145 // ROI Color [ROI Display Color]
146 mColor = clitk::parse_string<double>(item->GetEntryValue(0x3006,0x002a),'\\');
148 // Read contours [Contour Sequence]
149 gdcm::SeqEntry * contours=item->GetSeqEntry(0x3006,0x0040);
150 bool contour_processed=false;
151 bool delta_computed=false;
153 for(gdcm::SQItem* j=contours->GetFirstSQItem(); j!=0; j=contours->GetNextSQItem()) {
154 DicomRT_Contour::Pointer c = DicomRT_Contour::New();
157 mListOfContours.push_back(c);
158 if (contour_processed) {
159 double delta=c->GetZ() - last_z;
161 assert(mZDelta == delta);
165 contour_processed=true;
170 //--------------------------------------------------------------------
173 //--------------------------------------------------------------------
174 void clitk::DicomRT_ROI::SetImage(vvImage * image)
178 //--------------------------------------------------------------------
181 //--------------------------------------------------------------------
182 vtkPolyData * clitk::DicomRT_ROI::GetMesh()
184 if (!mMeshIsUpToDate) {
189 //--------------------------------------------------------------------
190 clitk::DicomRT_Contour * clitk::DicomRT_ROI::GetContour(int n)
192 return mListOfContours[n];
195 //--------------------------------------------------------------------
196 void clitk::DicomRT_ROI::ComputeMesh()
198 vtkSmartPointer<vtkAppendPolyData> append = vtkSmartPointer<vtkAppendPolyData>::New();
199 for(unsigned int i=0; i<mListOfContours.size(); i++) {
200 append->AddInput(mListOfContours[i]->GetMesh());
204 mMesh = vtkSmartPointer<vtkPolyData>::New();
205 mMesh->DeepCopy(append->GetOutput());
206 mMeshIsUpToDate = true;
208 //--------------------------------------------------------------------
211 //--------------------------------------------------------------------
212 void clitk::DicomRT_ROI::SetFromBinaryImage(vvImage * image, int n,
214 std::vector<double> color,
215 std::string filename)
218 // ROI number [Referenced ROI Number]
223 mFilename = filename;
225 // ROI Color [ROI Display Color]
228 // No contours [Contour Sequence]
229 mListOfContours.clear();
234 //--------------------------------------------------------------------
237 //--------------------------------------------------------------------
238 vvImage * clitk::DicomRT_ROI::GetImage() const
242 //--------------------------------------------------------------------