X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvMeshReader.cxx;h=fb0baf47a10c0edd5cd9ef7edb01dbab36db1bf6;hb=431fea9a7c825943b07fc4b4f3423355a5fee501;hp=d5100b1e336218485b608022da329ade80515765;hpb=1e034c70105f0926939acaaa27ddb46e904ae8bf;p=clitk.git diff --git a/vv/vvMeshReader.cxx b/vv/vvMeshReader.cxx index d5100b1..fb0baf4 100644 --- a/vv/vvMeshReader.cxx +++ b/vv/vvMeshReader.cxx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,13 +14,20 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ +===========================================================================**/ #include #include -#include -#include +#include +#if GDCM_MAJOR_VERSION == 2 + #include + #include + #include +#else + #include + #include +#endif #include #include @@ -35,6 +42,7 @@ #include "clitkCommon.h" #include "vvMeshReader.h" #include "vvProgressDialog.h" +#include vvMeshReader::vvMeshReader() : vtk_mode(false) @@ -60,7 +68,7 @@ void vvMeshReader::run() vvMesh::Pointer m=vvMesh::New(); m->ReadFromVTK(filename.c_str()); if (vf) m->propagateContour(vf); - m->ComputeMasks(image->GetVTKImages()[0],true); + m->ComputeMasks(image->GetVTKImages()[0],false); //don't extrude the contour result.push_back(m); } else { //Read a Dicom-struct file assert(selected_contours.size() > 0); @@ -76,31 +84,39 @@ void vvMeshReader::run() } } -template -ElementType parse_value(std::string str) -{ - std::istringstream parser(str); - ElementType value; - parser >> value; - assert(!parser.fail()); - return value; -} - -template -std::vector parse_string(std::string str,char delim) -{ - std::istringstream ss(str); - std::string token; - std::vector result; - while (getline(ss,token,delim)) { - result.push_back(parse_value(token)); - } - return result; -} - std::vector > vvMeshReader::GetROINames() { assert(filename!=""); + std::vector > roi_names; +#if GDCM_MAJOR_VERSION == 2 + // duplicate code from clitk::DicomRT_StructureSet::Read + gdcm::Reader reader; + reader.SetFileName( filename.c_str() ); + reader.Read(); + + const gdcm::DataSet &ds = reader.GetFile().GetDataSet(); + + gdcm::Tag tssroisq(0x3006,0x0020); + const gdcm::DataElement &ssroisq = ds.GetDataElement( tssroisq ); + gdcm::SmartPointer roi_seq = ssroisq.GetValueAsSQ(); + assert(roi_seq); // TODO error message + for(unsigned int ridx = 0; ridx < roi_seq->GetNumberOfItems(); ++ridx) + { + gdcm::Item & item = roi_seq->GetItem( ridx + 1); // Item starts at 1 + const gdcm::DataSet& nestedds = item.GetNestedDataSet(); + if( nestedds.FindDataElement( gdcm::Tag(0x3006,0x22) ) ) + { + gdcm::Attribute<0x3006,0x26> roiname; + roiname.SetFromDataSet( nestedds ); + std::string name = roiname.GetValue(); // 0x3006,0x0026 = [ROI Name] + gdcm::Attribute<0x3006,0x0022> roinumber; + roinumber.SetFromDataSet( nestedds ); + int nb = roinumber.GetValue(); // 0x3006,0x0022 = [ROI Number] + + roi_names.push_back(make_pair(nb,name)); + } + } +#else gdcm::File reader; reader.SetFileName(filename.c_str()); reader.SetMaxSizeLoadEntry(16384); @@ -108,23 +124,25 @@ std::vector > vvMeshReader::GetROINames() gdcm::SeqEntry * roi_info=reader.GetSeqEntry(0x3006,0x0020); assert(roi_info); - std::vector > roi_names; // DD("ici"); //int n=0; for (gdcm::SQItem* i=roi_info->GetFirstSQItem(); i!=0; i=roi_info->GetNextSQItem()) if (i->GetEntryValue(0x3006,0x0022)!= gdcm::GDCM_UNFOUND) roi_names.push_back(make_pair(atoi(i->GetEntryValue(0x3006,0x0022).c_str()),i->GetEntryValue(0x3006,0x0026))); +#endif return roi_names; } std::vector vvMeshReader::readSelectedContours() { + std::vector result; +#if GDCM_MAJOR_VERSION == 2 +#else gdcm::File reader; reader.SetFileName(filename.c_str()); reader.SetMaxSizeLoadEntry(16384); reader.Load(); - std::vector result; gdcm::SeqEntry * rois=reader.GetSeqEntry(0x3006,0x0039); ///We need to iterate both on the contours themselves, and on the contour info gdcm::SeqEntry * roi_info=reader.GetSeqEntry(0x3006,0x0020); @@ -137,7 +155,7 @@ std::vector vvMeshReader::readSelectedContours() ss >> roi_number; if (std::find(selected_contours.begin(),selected_contours.end(),roi_number) != selected_contours.end()) { //Only read selected ROIs vvMesh::Pointer current_roi=vvMesh::New(); - std::vector rgb=parse_string(i->GetEntryValue(0x3006,0x002a),'\\'); + std::vector rgb=clitk::parse_string(i->GetEntryValue(0x3006,0x002a),'\\'); assert(rgb.size()==3); current_roi->r=rgb[0]/255; current_roi->g=rgb[1]/255; @@ -148,8 +166,8 @@ std::vector vvMeshReader::readSelectedContours() for(gdcm::SQItem* j=contours->GetFirstSQItem(); j!=0; j=contours->GetNextSQItem()) { //loop over 2D contours std::string contour_type=j->GetEntryValue(0x3006,0x0042); if (contour_type=="CLOSED_PLANAR ") { - int point_number=parse_value(j->GetEntryValue(0x3006,0x0046)); - std::vector points=parse_string(j->GetEntryValue(0x3006,0x0050),'\\'); + int point_number=clitk::parse_value(j->GetEntryValue(0x3006,0x0046)); + std::vector points=clitk::parse_string(j->GetEntryValue(0x3006,0x0050),'\\'); assert(points.size() == static_cast(point_number)*3); if (z0 == -1) //First contour z0=points[2]; @@ -181,6 +199,7 @@ std::vector vvMeshReader::readSelectedContours() } k=roi_info->GetNextSQItem(); //increment the second loop variable } +#endif return result; }