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3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 #include "DicomFileStructure.hh"
 27 
 28 #include "dcmtk/config/osconfig.h"  // make sure OS specific configuration is included
 29 #include "dcmtk/dcmdata/dcdeftag.h"
 30 #include "dcmtk/dcmdata/dcfilefo.h"
 31 #include "dcmtk/dcmdata/dcpixel.h"
 32 #include "dcmtk/dcmdata/dcpixseq.h"
 33 #include "dcmtk/dcmdata/dcpxitem.h"
 34 #include "dcmtk/dcmrt/drtstrct.h"
 35 #include "dcmtk/dcmrt/seq/drtcis.h"  // for ContourImageSequence
 36 #include "dcmtk/dcmrt/seq/drtcs.h"  // for ContourSequence
 37 #include "dcmtk/dcmrt/seq/drtrcs.h"  // for ROIContourSequence
 38 #include "dcmtk/dcmrt/seq/drtrfors.h"  // for ReferencedFrameOfReferenceSequence
 39 #include "dcmtk/dcmrt/seq/drtssrs.h"  // for StructureSetROISequence
 40 
 41 #include "G4ThreeVector.hh"
 42 #include "G4UIcommand.hh"
 43 
 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 45 DicomFileStructure::DicomFileStructure(DcmDataset* dset) : DicomVFile(dset) {}
 46 
 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 48 void DicomFileStructure::ReadData()
 49 {
 50   DRTStructureSetIOD rtstruct;
 51   OFCondition result = rtstruct.read(*theDataset);
 52   //  DCMRT_INFO("Read RT Structure Set: " << status.text());
 53   if (!result.good()) {
 54     G4Exception("DicomFileStructure::ReadData", "DFS001", FatalException, result.text());
 55   }
 56 
 57   //@@@@@@@@@@@@ DRTReferencedFrameOfReferenceSequence
 58   DRTReferencedFrameOfReferenceSequence refSeq = rtstruct.getReferencedFrameOfReferenceSequence();
 59   if (refSeq.isEmpty()) {
 60     G4Exception("DicomFileStructure::ReadData", "DFS002", JustWarning,
 61                 "DRTReferencedFrameOfReferenceSequence is empty");
 62   }
 63 
 64   G4cout << "@@@@@ NUMBER OF ReferenceSequences " << refSeq.getNumberOfItems() << G4endl;
 65   refSeq.gotoFirstItem();
 66   for (size_t i1 = 0; i1 < refSeq.getNumberOfItems(); i1++) {
 67     DRTReferencedFrameOfReferenceSequence::Item& item = refSeq.getCurrentItem();
 68     OFString uid;
 69     item.getFrameOfReferenceUID(uid);
 70     G4cout << " FrameOfReferenceUID " << uid << G4endl;
 71     DRTRTReferencedStudySequence& reference_study_sequence_ref =
 72       item.getRTReferencedStudySequence();
 73     G4cout << "@@@@ NUMBER OF ReferenceStudySequences "
 74            << reference_study_sequence_ref.getNumberOfItems() << G4endl;
 75     reference_study_sequence_ref.gotoFirstItem();
 76     for (size_t i2 = 0; i2 < reference_study_sequence_ref.getNumberOfItems(); i2++) {
 77       DRTRTReferencedStudySequence::Item& rss_item = reference_study_sequence_ref.getCurrentItem();
 78       DRTRTReferencedSeriesSequence& series_seq_ref = rss_item.getRTReferencedSeriesSequence();
 79       G4cout << "@@@ NUMBER OF SeriesSequences " << series_seq_ref.getNumberOfItems() << G4endl;
 80       series_seq_ref.gotoFirstItem();
 81       for (size_t i3 = 0; i3 < series_seq_ref.getNumberOfItems(); i3++) {
 82         DRTRTReferencedSeriesSequence::Item& ref_series_seq_item = series_seq_ref.getCurrentItem();
 83         DRTContourImageSequence& image_sequence_seq_ref =
 84           ref_series_seq_item.getContourImageSequence();
 85         G4cout << "@@ NUMBER OF ContourImageSequences " << image_sequence_seq_ref.getNumberOfItems()
 86                << G4endl;
 87         image_sequence_seq_ref.gotoFirstItem();
 88         for (size_t i4 = 0; i4 < image_sequence_seq_ref.getNumberOfItems(); i4++) {
 89           DRTContourImageSequence::Item& image_contour_item =
 90             image_sequence_seq_ref.getCurrentItem();
 91           OFString refSOPInstUID;
 92           image_contour_item.getReferencedSOPInstanceUID(refSOPInstUID);
 93           std::cout << "ReferencedSOPInstanceUID= " << refSOPInstUID << std::endl;
 94           image_sequence_seq_ref.gotoNextItem().good();
 95         }  // end if image_sequence_seq_ref
 96         series_seq_ref.gotoNextItem();
 97       }  // end if series_seq_ref good
 98       reference_study_sequence_ref.gotoNextItem();
 99     }  // end if reference_study_sequence_ref good
100     refSeq.gotoNextItem();
101   }  // end if refSeq.first item
102 
103   //@@@@@@@@@@@@   DRTROISequence
104   DRTStructureSetROISequence ROISeq = rtstruct.getStructureSetROISequence();
105   G4cout << "@@@@@ NUMBER OF ROISequences " << ROISeq.getNumberOfItems() << G4endl;
106   for (size_t i1 = 0; i1 < ROISeq.getNumberOfItems(); i1++) {
107     DRTStructureSetROISequence::Item& item = ROISeq.getCurrentItem();
108     OFString ROIName, ROINumber, ROIGenerationAlgorithm;
109     item.getROINumber(ROINumber);
110     item.getROIName(ROIName);
111     item.getROIGenerationAlgorithm(ROIGenerationAlgorithm);
112     if (ROINumber != "") {
113       DicomROI* roi = new DicomROI(G4UIcommand::ConvertToInt(ROINumber.c_str()), ROIName.c_str());
114       theROIs.push_back(roi);
115       G4cout << " ROI: " << roi->GetNumber() << " " << roi->GetName() << " "
116              << ROIGenerationAlgorithm << G4endl;
117     }
118 
119     ROISeq.gotoNextItem().good();
120   }  // end if ROISeq.first item
121 
122   //@@@@@@@@@@@@   DRTROIContourSequence
123   DRTROIContourSequence ROIContourSeq = rtstruct.getROIContourSequence();
124   if (ROISeq.getNumberOfItems() != ROIContourSeq.getNumberOfItems()) {
125     G4Exception("DicomFileStructure", "DCS0001", FatalException,
126                 ("Different number of ROIs and ROI Contours "
127                  + std::to_string(ROISeq.getNumberOfItems()) + " <> "
128                  + std::to_string(ROIContourSeq.getNumberOfItems()))
129                   .c_str());
130   }
131 
132   ROIContourSeq.gotoFirstItem();
133   for (size_t i1 = 0; i1 < ROIContourSeq.getNumberOfItems(); i1++) {
134     DRTROIContourSequence::Item& item = ROIContourSeq.getCurrentItem();
135     OFString displayColor;
136     item.getROIDisplayColor(displayColor);
137     //    G4cout << " ROIDisplayColor " << displayColor << G4endl;
138 
139     DRTContourSequence contour_seq = item.getContourSequence();
140     //    G4cout << "@@@@ NUMBER OF ContourSequences " << contour_seq.getNumberOfItems() << G4endl;
141     contour_seq.gotoFirstItem();
142     for (size_t i2 = 0; i2 < contour_seq.getNumberOfItems(); i2++) {
143       //      if (contour_seq.gotoFirstItem().good()) {
144       //        do {
145       DRTContourSequence::Item& cs_item = contour_seq.getCurrentItem();
146 
147       DicomROIContour* roiC = new DicomROIContour();
148 
149       DRTContourImageSequence& contour_image_seq = cs_item.getContourImageSequence();
150 
151       contour_image_seq.gotoFirstItem();
152       for (size_t i3 = 0; i3 < contour_image_seq.getNumberOfItems(); i3++) {
153         DRTContourImageSequence::Item cis_item = contour_image_seq.getCurrentItem();
154         OFString refSOPCUID;
155         cis_item.getReferencedSOPClassUID(refSOPCUID);
156         OFString refSOPIUID;
157         cis_item.getReferencedSOPInstanceUID(refSOPIUID);
158         if (refSOPIUID != "") roiC->AddImageIUID(refSOPIUID.c_str());
159         contour_image_seq.gotoNextItem();
160       }  // end if contour_image_seq
161 
162       //@@@
163       OFString geomType;
164       cs_item.getContourGeometricType(geomType);
165       Sint32 nPoints;
166       cs_item.getNumberOfContourPoints(nPoints);
167       roiC->SetGeomType(geomType);
168       OFVector<Float64> data;
169       cs_item.getContourData(data);
170       std::vector<G4ThreeVector> dataV;
171       for (Sint32 ii = 0; ii < nPoints * 3; ii++) {
172         if (ii % 3 == 2) dataV.push_back(G4ThreeVector(data[ii - 2], data[ii - 1], data[ii]));
173       }
174       roiC->SetData(dataV);
175       theROIs[i1]->AddContour(roiC);
176 
177       contour_seq.gotoNextItem();
178     }
179     ROIContourSeq.gotoNextItem();
180   }  // end if ROIContourSeq.first item
181 
182   //@@@@ Print ROIs
183   G4cout << " @@@@@@@@@@@ ROIs " << G4endl;
184   for (size_t ii = 0; ii < theROIs.size(); ii++) {
185     theROIs[ii]->Print(G4cout);
186   }
187 }
188