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()
44 //--------------------------------------------------------------------
47 //--------------------------------------------------------------------
48 void clitk::DicomRT_ROI::SetDisplayColor(double r, double v, double b)
55 //--------------------------------------------------------------------
58 //--------------------------------------------------------------------
59 int clitk::DicomRT_ROI::GetROINumber() const
63 //--------------------------------------------------------------------
66 //--------------------------------------------------------------------
67 const std::string & clitk::DicomRT_ROI::GetName() const
71 //--------------------------------------------------------------------
74 //--------------------------------------------------------------------
75 const std::string & clitk::DicomRT_ROI::GetFilename() const
79 //--------------------------------------------------------------------
82 //--------------------------------------------------------------------
83 const std::vector<double> & clitk::DicomRT_ROI::GetDisplayColor() const
87 //--------------------------------------------------------------------
90 //--------------------------------------------------------------------
91 void clitk::DicomRT_ROI::Print(std::ostream & os) const
93 os << "ROI " << mNumber << "\t" << mName
94 << "\t(" << mColor[0] << " " << mColor[1] << " " << mColor[2] << ")"
95 << "\t Contours = " << mListOfContours.size() << std::endl;
97 //--------------------------------------------------------------------
100 //--------------------------------------------------------------------
101 void clitk::DicomRT_ROI::SetBackgroundValueLabelImage(double bg)
103 mBackgroundValue = bg;
105 //--------------------------------------------------------------------
108 //--------------------------------------------------------------------
109 double clitk::DicomRT_ROI::GetBackgroundValueLabelImage() const
111 return mBackgroundValue;
113 //--------------------------------------------------------------------
116 //--------------------------------------------------------------------
117 void clitk::DicomRT_ROI::SetForegroundValueLabelImage(double bg)
119 mForegroundValue = bg;
121 //--------------------------------------------------------------------
124 //--------------------------------------------------------------------
125 double clitk::DicomRT_ROI::GetForegroundValueLabelImage() const
127 return mForegroundValue;
129 //--------------------------------------------------------------------
132 //--------------------------------------------------------------------
133 void clitk::DicomRT_ROI::Read(std::map<int, std::string> & rois, gdcm::SQItem * item)
136 // Change number if needed
140 // ROI number [Referenced ROI Number]
141 mNumber = atoi(item->GetEntryValue(0x3006,0x0084).c_str());
144 mName = rois[mNumber];
146 // ROI Color [ROI Display Color]
147 mColor = clitk::parse_string<double>(item->GetEntryValue(0x3006,0x002a),'\\');
149 // Read contours [Contour Sequence]
150 gdcm::SeqEntry * contours=item->GetSeqEntry(0x3006,0x0040);
151 bool contour_processed=false;
152 bool delta_computed=false;
154 for(gdcm::SQItem* j=contours->GetFirstSQItem(); j!=0; j=contours->GetNextSQItem()) {
155 DicomRT_Contour * c = new DicomRT_Contour;
158 mListOfContours.push_back(c);
159 if (contour_processed) {
160 double delta=c->GetZ() - last_z;
162 assert(mZDelta == delta);
166 contour_processed=true;
171 //--------------------------------------------------------------------
174 //--------------------------------------------------------------------
175 void clitk::DicomRT_ROI::SetImage(vvImage * image)
179 //--------------------------------------------------------------------
182 //--------------------------------------------------------------------
183 vtkPolyData * clitk::DicomRT_ROI::GetMesh()
185 if (!mMeshIsUpToDate) {
190 //--------------------------------------------------------------------
191 clitk::DicomRT_Contour * clitk::DicomRT_ROI::GetContour(int n)
193 return mListOfContours[n];
196 //--------------------------------------------------------------------
197 void clitk::DicomRT_ROI::ComputeMesh()
199 vtkAppendPolyData * append = vtkAppendPolyData::New();
200 for(unsigned int i=0; i<mListOfContours.size(); i++) {
201 append->AddInput(mListOfContours[i]->GetMesh());
204 mMesh = append->GetOutput();
205 mMeshIsUpToDate = true;
207 //--------------------------------------------------------------------
210 //--------------------------------------------------------------------
211 void clitk::DicomRT_ROI::SetFromBinaryImage(vvImage * image, int n,
213 std::vector<double> color,
214 std::string filename)
217 // ROI number [Referenced ROI Number]
222 mFilename = filename;
224 // ROI Color [ROI Display Color]
227 // No contours [Contour Sequence]
228 mListOfContours.clear();
233 //--------------------------------------------------------------------
236 //--------------------------------------------------------------------
237 vvImage * clitk::DicomRT_ROI::GetImage() const
241 //--------------------------------------------------------------------