32 #include "dcmtk/dcmdata/dcfilefo.h"
33 #include "dcmtk/dcmdata/dcdeftag.h"
34 #include "dcmtk/dcmdata/dcpixel.h"
35 #include "dcmtk/dcmdata/dcpxitem.h"
36 #include "dcmtk/dcmdata/dcpixseq.h"
37 #include "dcmtk/dcmrt/drtimage.h"
57 std::vector<double> dImagePositionPatient =
Read1Data(
theDataset, DCM_ImagePositionPatient,3);
68 fMinX = dImagePositionPatient[0];
69 fMaxX = dImagePositionPatient[0]+dColumns[0]*dPixelSpacing[0];
71 fMinY = dImagePositionPatient[1];
72 fMaxY = dImagePositionPatient[1]+dRows[0]*dPixelSpacing[1];
74 fMinZ = dImagePositionPatient[2]-dSliceThickness[0]/2.;
75 fMaxZ = dImagePositionPatient[2]+dSliceThickness[0]/2.;
89 std::vector<double> dImageOrientationPatient =
92 dImageOrientationPatient[2]);
94 dImageOrientationPatient[5]);
103 "OrientationRows must be (1,0,0) and OrientationColumns (0,1,0), please contact GAMOS authors");
109 if( dRescaleSlope.size() == 1 ) {
115 if( dRescaleIntercept.size() == 1 ) {
126 void DicomVFileImage::ReadPixelData()
129 OFCondition
result = EC_Normal;
131 DcmElement* element = NULL;
132 result =
theDataset->findAndGetElement(DCM_PixelData, element);
133 if (result.bad() || element == NULL) {
135 "findAndGetElement(DCM_PixelData, ",
137 (
"Element PixelData not found: " +
G4String(result.text())).c_str());
139 DcmPixelData *dpix = NULL;
140 dpix = OFstatic_cast(DcmPixelData*, element);
144 DcmPixelSequence *dseq = NULL;
145 E_TransferSyntax xferSyntax = EXS_Unknown;
146 const DcmRepresentationParameter *rep = NULL;
148 dpix->getOriginalRepresentationKey(xferSyntax, rep);
150 result = dpix->getEncapsulatedRepresentation(xferSyntax, rep, dseq);
151 if ( result == EC_Normal )
156 "Compressed pixel data is not supported");
159 <<
" DicomVFileImage::ReadData: result == EC_Normal Reading compressed data " << std::endl;
160 DcmPixelItem* pixitem = NULL;
162 for(
int ii = 1; ii < 2; ii++ ) {
163 OFCondition cond = dseq->getItem(pixitem, ii);
164 if( !cond.good())
break;
165 G4cout << ii <<
" PIX LENGTH " << pixitem->getLength() <<
G4endl;
167 if (pixitem == NULL) {
171 "No DcmPixelItem in DcmPixelSequence");
173 Uint8* pixData = NULL;
176 Uint32 length = pixitem->getLength();
179 "pixitem->getLength()",
185 <<
" DicomVFileImage::ReadData: number of pixels " << length <<
G4endl;
187 result = pixitem->getUint8Array(pixData);
190 Uint8* pixData = NULL;
191 if(! (element->getUint8Array(pixData)).good() ) {
193 "getUint8Array pixData, ",
195 (
"PixelData not found: " +
G4String(result.text())).c_str());
197 for(
int ir = 0; ir <
fNoVoxelY; ir++ ) {
198 for(
int ic = 0; ic <
fNoVoxelX; ic++ ) {
203 Uint16* pixData = NULL;
204 if(! (element->getUint16Array(pixData)).good() ) {
206 "getUint16Array pixData, ",
208 (
"PixelData not found: " +
G4String(result.text())).c_str());
210 for(
int ir = 0; ir <
fNoVoxelY; ir++ ) {
211 for(
int ic = 0; ic <
fNoVoxelX; ic++ ) {
216 Uint32* pixData = NULL;
217 if(! (element->getUint32Array(pixData)).good() ) {
219 "getUint32Array pixData, ",
221 (
"PixelData not found: " +
G4String(result.text())).c_str());
223 for(
int ir = 0; ir <
fNoVoxelY; ir++ ) {
224 for(
int ic = 0; ic <
fNoVoxelX; ic++ ) {
245 G4cerr <<
"DicomVFileImage error adding two slice headers:\
246 !!! Different number of voxels: "
248 <<
" Y= " << fNoVoxelY <<
" =? " << rhs.
GetNoVoxelY()
257 G4cerr <<
"DicomVFileImage error adding two slice headers:\
258 !!! Different extensions: "
271 G4cerr <<
"DicomVFileImage error adding two slice headers: !!!\
272 Slices have different orientations "
285 G4cerr <<
"DicomVFileImage error adding two slice headers: !!!\
286 Slices are not contiguous in Z "
312 std::ofstream out(fName.c_str());
315 <<
"### DicomVFileImage::Dumping Z Slice header to Text file " <<
G4endl;
318 fout <<
fNoVoxelX/fCompress <<
" " << fNoVoxelY/fCompress <<
" " <<
fNoVoxelZ << std::endl;
326 void DicomVFileImage::Print(std::ostream& out )
331 out <<
"@ NoVoxels " <<
fNoVoxelX/fCompress <<
" " << fNoVoxelY/fCompress <<
" "
G4double G4ParticleHPJENDLHEData::G4double result
G4double fRescaleIntercept
CLHEP::Hep3Vector G4ThreeVector
void SetMinZ(const G4double &val)
G4int GetCompression() const
virtual std::vector< G4double > Read1Data(DcmDataset *dset, DcmTagKey tagKey, G4int nData)
G4ThreeVector GetOrientationRows() const
G4int GetNoVoxelY() const
void operator+=(const DicomVFileImage &rhs)
G4int GetNoVoxelZ() const
void SetMaxZ(const G4double &val)
G4GLOB_DLL std::ostream G4cout
DicomVFileImage operator+(const DicomVFileImage &rhs)
G4double GetRadialTolerance() const
std::vector< int > fHounsfieldV
G4ThreeVector fOrientationRows
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
DicomFileMgr * theFileMgr
T max(const T t1, const T t2)
brief Return the largest of the two arguments
void DumpHeaderToTextFile(std::ofstream &fout)
G4ThreeVector fOrientationColumns
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4ThreeVector GetOrientationColumns() const
void SetNoVoxelZ(const G4int &val)
G4int GetNoVoxelX() const
static G4GeometryTolerance * GetInstance()
static DicomFileMgr * GetInstance()
G4GLOB_DLL std::ostream G4cerr