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_Contour.h"
21 #include <vtkCellArray.h>
23 //--------------------------------------------------------------------
24 clitk::DicomRT_Contour::DicomRT_Contour()
26 mMeshIsUpToDate = false;
30 //--------------------------------------------------------------------
33 //--------------------------------------------------------------------
34 clitk::DicomRT_Contour::~DicomRT_Contour()
38 //--------------------------------------------------------------------
42 //--------------------------------------------------------------------
43 void clitk::DicomRT_Contour::Print(std::ostream & os) const
45 DD("TODO : print Contours");
47 //--------------------------------------------------------------------
50 //--------------------------------------------------------------------
51 bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item)
54 // Contour type [Contour Geometric Type]
55 mType = item->GetEntryValue(0x3006,0x0042);
57 if (mType != "CLOSED_PLANAR " && mType != "POINT ") { ///WARNING to the space after the name ...
58 //std::cerr << "Skip this contour : type=" << mType << std::endl;
61 if (mType == "POINT ") {
62 std::cerr << "Warning: POINT type not fully supported. (don't use GetMesh() with this!)"
66 // Number of points [Number of Contour Points]
67 mNbOfPoints = parse_value<int>(item->GetEntryValue(0x3006,0x0046));
70 // Read values [Contour Data]
71 std::vector<float> points = parse_string<float>(item->GetEntryValue(0x3006,0x0050),'\\');
72 assert(points.size() == static_cast<unsigned int>(mNbOfPoints)*3);
75 mData = vtkPoints::New();
76 mData->SetDataTypeToDouble();
77 mData->SetNumberOfPoints(mNbOfPoints);
78 for(unsigned int i=0; i<mNbOfPoints; i++) {
83 mData->SetPoint(i, p);
84 if (mZ == -1) mZ = p[2];
89 std::cout << "ERROR ! contour not in the same slice" << std::endl;
96 //--------------------------------------------------------------------
99 //--------------------------------------------------------------------
100 vtkPolyData * clitk::DicomRT_Contour::GetMesh()
102 if (!mMeshIsUpToDate) {
107 //--------------------------------------------------------------------
110 //--------------------------------------------------------------------
111 void clitk::DicomRT_Contour::ComputeMesh()
113 // DD("ComputeMesh Contour");
114 mMesh = vtkPolyData::New();
115 mMesh->Allocate(); //for cell structures
116 mMesh->SetPoints(vtkPoints::New());
118 for (unsigned int idx=0 ; idx<mNbOfPoints ; idx++) {
119 mMesh->GetPoints()->InsertNextPoint(mData->GetPoint(idx)[0],
120 mData->GetPoint(idx)[1],
121 mData->GetPoint(idx)[2]);
123 ids[1]=(ids[0]+1) % mNbOfPoints; //0-1,1-2,...,n-1-0
126 mMesh->GetLines()->InsertNextCell(2,ids);
128 // DD(mMesh->GetNumberOfCells());
129 mMeshIsUpToDate = true;
131 //--------------------------------------------------------------------