- gdcm::File reader;
- reader.SetFileName(filename.c_str());
- reader.SetMaxSizeLoadEntry(16384);
- reader.Load();
-
- std::vector<vvMesh::Pointer> 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);
- gdcm::SQItem* k=roi_info->GetFirstSQItem();
- for(gdcm::SQItem* i=rois->GetFirstSQItem();i!=0;i=rois->GetNextSQItem()) //loop over ROIS
- {
- assert(k!=0);
- vtkSmartPointer<vtkAppendPolyData> append=vtkSmartPointer<vtkAppendPolyData>::New();
- std::istringstream ss(i->GetEntryValue(0x3006,0x0084));
- int roi_number;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<double> rgb=parse_string<double>(i->GetEntryValue(0x3006,0x002a),'\\');
- assert(rgb.size()==3);
- current_roi->r=rgb[0]/255; current_roi->g=rgb[1]/255; current_roi->b=rgb[2]/255;
- current_roi->structure_name=k->GetEntryValue(0x3006,0x0026);
- gdcm::SeqEntry * contours=i->GetSeqEntry(0x3006,0x0040);
- double z0=-1; //Used to determine spacing between slices, assumed to be constant
- 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<int>(j->GetEntryValue(0x3006,0x0046));
- std::vector<float> points=parse_string<float>(j->GetEntryValue(0x3006,0x0050),'\\');
- assert(points.size() == static_cast<unsigned int>(point_number)*3);
- if (z0 == -1) //First contour
- z0=points[2];
- //2nd contour, spacing not yet set. Need to be sure we are on a different slice,
- //sometimes there is more than one closed contour per slice
- else if (current_roi->GetSpacing()==-1 && points[2] != z0 )
- current_roi->SetSpacing(points[2]-z0);
- vtkPolyData * contour=vtkPolyData::New();
- contour->Allocate(); //for cell structures
- contour->SetPoints(vtkPoints::New());
- vtkIdType ids[2];
- for (unsigned int idx=0;idx<points.size();idx+=3)
- {
- contour->GetPoints()->InsertNextPoint(points[idx],points[idx+1],points[idx+2]);
- ids[0]=idx/3;ids[1]=(ids[0]+1)%point_number; //0-1,1-2,...,n-1-0
- contour->GetLines()->InsertNextCell(2,ids);
- }
- append->AddInput(contour);
- }
- else if (contour_type == "POINT ")
- ; // silently ignore POINT type since we don't need them at the moment
- else
- std::cerr << "Warning: contour type " << contour_type << " not handled!" << std::endl;
- }
- append->Update();
- current_roi->AddMesh(append->GetOutput());
- result.push_back(current_roi);
- }
+ gdcm::File reader;
+ reader.SetFileName(filename.c_str());
+ reader.SetMaxSizeLoadEntry(16384);
+ reader.Load();
+
+ std::vector<vvMesh::Pointer> 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);
+ gdcm::SQItem* k=roi_info->GetFirstSQItem();
+ for(gdcm::SQItem* i=rois->GetFirstSQItem(); i!=0; i=rois->GetNextSQItem()) { //loop over ROIS
+ assert(k!=0);
+ vtkSmartPointer<vtkAppendPolyData> append=vtkSmartPointer<vtkAppendPolyData>::New();
+ std::istringstream ss(i->GetEntryValue(0x3006,0x0084));
+ int roi_number;
+ 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<double> rgb=clitk::parse_string<double>(i->GetEntryValue(0x3006,0x002a),'\\');
+ assert(rgb.size()==3);
+ current_roi->r=rgb[0]/255;
+ current_roi->g=rgb[1]/255;
+ current_roi->b=rgb[2]/255;
+ current_roi->structure_name=k->GetEntryValue(0x3006,0x0026);
+ gdcm::SeqEntry * contours=i->GetSeqEntry(0x3006,0x0040);
+ double z0=-1; //Used to determine spacing between slices, assumed to be constant
+ 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=clitk::parse_value<int>(j->GetEntryValue(0x3006,0x0046));
+ std::vector<float> points=clitk::parse_string<float>(j->GetEntryValue(0x3006,0x0050),'\\');
+ assert(points.size() == static_cast<unsigned int>(point_number)*3);
+ if (z0 == -1) //First contour
+ z0=points[2];
+ //2nd contour, spacing not yet set. Need to be sure we are on a different slice,
+ //sometimes there is more than one closed contour per slice
+ else if (current_roi->GetSpacing()==-1 && points[2] != z0 )
+ current_roi->SetSpacing(points[2]-z0);
+ vtkPolyData * contour=vtkPolyData::New();
+ contour->Allocate(); //for cell structures
+ contour->SetPoints(vtkPoints::New());
+ vtkIdType ids[2];
+ for (unsigned int idx=0; idx<points.size(); idx+=3) {
+ contour->GetPoints()->InsertNextPoint(points[idx],points[idx+1],points[idx+2]);
+ ids[0]=idx/3;
+ ids[1]=(ids[0]+1)%point_number; //0-1,1-2,...,n-1-0
+ contour->GetLines()->InsertNextCell(2,ids);
+ }
+ append->AddInput(contour);
+ } else if (contour_type == "POINT ")
+ ; // silently ignore POINT type since we don't need them at the moment