Loading...
Searching...
No Matches
DicomFileStructure.cc
Go to the documentation of this file.
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 "G4ThreeVector.hh"
29
30#include "dcmtk/dcmdata/dcfilefo.h"
31#include "dcmtk/dcmdata/dcdeftag.h"
32#include "dcmtk/dcmdata/dcpixel.h"
33#include "dcmtk/dcmdata/dcpxitem.h"
34#include "dcmtk/dcmdata/dcpixseq.h"
35#include "dcmtk/dcmrt/drtstrct.h"
36#include "dcmtk/dcmrt/seq/drtrfors.h" // for ReferencedFrameOfReferenceSequence
37#include "dcmtk/dcmrt/seq/drtssrs.h" // for StructureSetROISequence
38#include "dcmtk/dcmrt/seq/drtrcs.h" // for ROIContourSequence
39#include "dcmtk/dcmrt/seq/drtcs.h" // for ContourSequence
40#include "dcmtk/dcmrt/seq/drtcis.h" // for ContourImageSequence
41#include "dcmtk/config/osconfig.h" // make sure OS specific configuration is included
42#include "G4UIcommand.hh"
43
44//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46{
47}
48
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51{
52 DRTStructureSetIOD rtstruct;
53 OFCondition result = rtstruct.read(*theDataset);
54 // DCMRT_INFO("Read RT Structure Set: " << status.text());
55 if (!result.good()) {
56 G4Exception("DicomFileStructure::ReadData",
57 "DFS001",
58 FatalException,
59 result.text());
60 }
61
62
63 //@@@@@@@@@@@@ DRTReferencedFrameOfReferenceSequence
64 DRTReferencedFrameOfReferenceSequence refSeq = rtstruct.getReferencedFrameOfReferenceSequence();
65 if( refSeq.isEmpty() ) {
66 G4Exception("DicomFileStructure::ReadData",
67 "DFS002",
68 JustWarning,
69 "DRTReferencedFrameOfReferenceSequence is empty");
70 }
71
72 G4cout << "@@@@@ NUMBER OF ReferenceSequences " << refSeq.getNumberOfItems() << G4endl;
73 refSeq.gotoFirstItem();
74 for( size_t i1 = 0; i1 < refSeq.getNumberOfItems(); i1++ ) {
75 DRTReferencedFrameOfReferenceSequence::Item &item = refSeq.getCurrentItem();
76 OFString uid;
77 item.getFrameOfReferenceUID(uid);
78 G4cout << " FrameOfReferenceUID " << uid << G4endl;
79 DRTRTReferencedStudySequence &reference_study_sequence_ref =
80 item.getRTReferencedStudySequence();
81 G4cout << "@@@@ NUMBER OF ReferenceStudySequences "
82 << reference_study_sequence_ref.getNumberOfItems() << G4endl;
83 reference_study_sequence_ref.gotoFirstItem();
84 for( size_t i2 = 0; i2 < reference_study_sequence_ref.getNumberOfItems(); i2++ ) {
85 DRTRTReferencedStudySequence::Item &rss_item = reference_study_sequence_ref.getCurrentItem();
86 DRTRTReferencedSeriesSequence &series_seq_ref = rss_item.getRTReferencedSeriesSequence();
87 G4cout << "@@@ NUMBER OF SeriesSequences " << series_seq_ref.getNumberOfItems() << G4endl;
88 series_seq_ref.gotoFirstItem();
89 for( size_t i3 = 0; i3 < series_seq_ref.getNumberOfItems(); i3++ ) {
90 DRTRTReferencedSeriesSequence::Item &ref_series_seq_item = series_seq_ref.getCurrentItem();
91 DRTContourImageSequence &image_sequence_seq_ref =
92 ref_series_seq_item.getContourImageSequence();
93 G4cout << "@@ NUMBER OF ContourImageSequences "
94 << image_sequence_seq_ref.getNumberOfItems() << G4endl;
95 image_sequence_seq_ref.gotoFirstItem();
96 for( size_t i4 = 0; i4 < image_sequence_seq_ref.getNumberOfItems(); i4++ ) {
97 DRTContourImageSequence::Item &image_contour_item =
98 image_sequence_seq_ref.getCurrentItem();
99 OFString refSOPInstUID;
100 image_contour_item.getReferencedSOPInstanceUID(refSOPInstUID);
101 std::cout <<"ReferencedSOPInstanceUID= " << refSOPInstUID << std::endl;
102 image_sequence_seq_ref.gotoNextItem().good();
103 } // end if image_sequence_seq_ref
104 series_seq_ref.gotoNextItem();
105 } // end if series_seq_ref good
106 reference_study_sequence_ref.gotoNextItem();
107 } // end if reference_study_sequence_ref good
108 refSeq.gotoNextItem();
109 } // end if refSeq.first item
110
111 //@@@@@@@@@@@@ DRTROISequence
112 DRTStructureSetROISequence ROISeq = rtstruct.getStructureSetROISequence();
113 G4cout << "@@@@@ NUMBER OF ROISequences " << ROISeq.getNumberOfItems() << G4endl;
114 for( size_t i1 = 0; i1 < ROISeq.getNumberOfItems(); i1++ ) {
115 DRTStructureSetROISequence::Item &item = ROISeq.getCurrentItem();
116 OFString ROIName, ROINumber, ROIGenerationAlgorithm;
117 item.getROINumber(ROINumber);
118 item.getROIName(ROIName);
119 item.getROIGenerationAlgorithm(ROIGenerationAlgorithm);
120 if( ROINumber != "" ) {
121 DicomROI* roi = new DicomROI(G4UIcommand::ConvertToInt(ROINumber.c_str()), ROIName.c_str());
122 theROIs.push_back( roi );
123 G4cout << " ROI: " << roi->GetNumber() << " " << roi->GetName() << " "
124 << ROIGenerationAlgorithm << G4endl;
125 }
126
127 ROISeq.gotoNextItem().good();
128 } // end if ROISeq.first item
129
130
131 //@@@@@@@@@@@@ DRTROIContourSequence
132 DRTROIContourSequence ROIContourSeq = rtstruct.getROIContourSequence();
133 if( ROISeq.getNumberOfItems() != ROIContourSeq.getNumberOfItems() ) {
134 G4Exception("DicomFileStructure",
135 "DCS0001",
136 FatalException,
137 ("Different number of ROIs and ROI Contours "
138 + std::to_string(ROISeq.getNumberOfItems()) + " <> "
139 + std::to_string(ROIContourSeq.getNumberOfItems())).c_str());
140 }
141
142 ROIContourSeq.gotoFirstItem();
143 for( size_t i1 = 0; i1 < ROIContourSeq.getNumberOfItems(); i1++ ) {
144 DRTROIContourSequence::Item &item = ROIContourSeq.getCurrentItem();
145 OFString displayColor;
146 item.getROIDisplayColor(displayColor);
147 // G4cout << " ROIDisplayColor " << displayColor << G4endl;
148
149 DRTContourSequence contour_seq = item.getContourSequence();
150 // G4cout << "@@@@ NUMBER OF ContourSequences " << contour_seq.getNumberOfItems() << G4endl;
151 contour_seq.gotoFirstItem();
152 for( size_t i2 = 0; i2 < contour_seq.getNumberOfItems(); i2++ ) {
153 // if (contour_seq.gotoFirstItem().good()) {
154 // do {
155 DRTContourSequence::Item &cs_item = contour_seq.getCurrentItem();
156
157 DicomROIContour* roiC = new DicomROIContour();
158
159 DRTContourImageSequence &contour_image_seq = cs_item.getContourImageSequence();
160
161 contour_image_seq.gotoFirstItem();
162 for( size_t i3 = 0; i3 < contour_image_seq.getNumberOfItems(); i3++ ) {
163 DRTContourImageSequence::Item cis_item = contour_image_seq.getCurrentItem();
164 OFString refSOPCUID;
165 cis_item.getReferencedSOPClassUID(refSOPCUID);
166 OFString refSOPIUID;
167 cis_item.getReferencedSOPInstanceUID(refSOPIUID);
168 if( refSOPIUID != "") roiC->AddImageIUID(refSOPIUID.c_str());
169 contour_image_seq.gotoNextItem();
170 } // end if contour_image_seq
171
172 //@@@
173 OFString geomType;
174 cs_item.getContourGeometricType(geomType);
175 Sint32 nPoints;
176 cs_item.getNumberOfContourPoints(nPoints);
177 roiC->SetGeomType(geomType);
178 OFVector<Float64> data;
179 cs_item.getContourData(data);
180 std::vector<G4ThreeVector> dataV;
181 for( Sint32 ii = 0; ii < nPoints*3; ii++ ) {
182 if( ii%3 == 2 ) dataV.push_back( G4ThreeVector( data[ii-2], data[ii-1], data[ii] ) );
183 }
184 roiC->SetData(dataV);
185 theROIs[i1]->AddContour(roiC);
186
187 contour_seq.gotoNextItem();
188 }
189 ROIContourSeq.gotoNextItem();
190 } // end if ROIContourSeq.first item
191
192 //@@@@ Print ROIs
193 G4cout << " @@@@@@@@@@@ ROIs " << G4endl;
194 for( size_t ii = 0; ii < theROIs.size(); ii++ ) {
195 theROIs[ii]->Print(G4cout);
196 }
197}
198
std::vector< DicomROI * > theROIs
DicomFileStructure(DcmDataset *dset)
void SetGeomType(OFString gt)
void SetData(std::vector< G4ThreeVector > data)
void AddImageIUID(OFString ima)
int GetNumber() const
Definition DicomROI.hh:47
OFString GetName() const
Definition DicomROI.hh:50
DcmDataset * theDataset
Definition DicomVFile.hh:52

Applications | User Support | Publications | Collaboration