File: gdcmDefs.cxx

package info (click to toggle)
gdcm 2.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 29,952 kB
  • ctags: 49,807
  • sloc: cpp: 193,527; ansic: 119,435; xml: 44,906; sh: 7,153; python: 3,670; cs: 2,202; java: 1,344; lex: 1,290; tcl: 677; php: 128; makefile: 119
file content (369 lines) | stat: -rw-r--r-- 11,625 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*=========================================================================

  Program: GDCM (Grassroots DICOM). A DICOM library

  Copyright (c) 2006-2011 Mathieu Malaterre
  All rights reserved.
  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "gdcmDefs.h"
#include "gdcmTableReader.h"
#include "gdcmMediaStorage.h"
//#include "gdcmGlobal.h"
#include "gdcmTrace.h"
#include "gdcmFile.h"

#include <stdlib.h>

namespace gdcm
{

Defs::Defs()
{
}

Defs::~Defs()
{
}

void Defs::LoadDefaults()
{
//  TableReader tr(*this);
//  const Global &g = Global::GetInstance();
//  const char *filename = g.Locate( "Part3.xml" );
//
//  if( filename )
//    {
//    tr.SetFilename(filename);
//    tr.Read();
//    }
//  else
//    {
//    gdcmErrorMacro( "Could not find Part3.xml file. Please report" );
//    throw Exception( "Impossible" );
//    }
}

void Defs::LoadFromFile(const char *filename)
{
  assert( filename );
  TableReader tr(*this);
  tr.SetFilename(filename);
  tr.Read();
}

const char *Defs::GetIODNameFromMediaStorage(MediaStorage const &ms)
{
  const char *iodname;
  switch(ms)
    {
    case MediaStorage::MediaStorageDirectoryStorage:
      iodname = "Basic Directory IOD Modules";
      break;
    case MediaStorage::MRImageStorage:
      iodname = "MR Image IOD Modules";
      break;
    case MediaStorage::EnhancedMRImageStorage:
      iodname = "Enhanced MR Image IOD Modules";
      break;
    case MediaStorage::CTImageStorage:
      iodname = "CT Image IOD Modules";
      break;
    case MediaStorage::EnhancedCTImageStorage:
      iodname = "Enhanced CT Image IOD Modules";
      break;
    case MediaStorage::ComputedRadiographyImageStorage:
      iodname = "CR Image IOD Modules";
      break;
    case MediaStorage::XRayAngiographicImageStorage:
    //case MediaStorage::XRayAngiographicBiPlaneImageStorageRetired: // FIXME ???
      iodname = "X Ray Angiographic Image IOD Modules";
      break;
    case MediaStorage::UltrasoundImageStorageRetired:
    case MediaStorage::UltrasoundImageStorage:
      iodname = "US Image IOD Modules";
      break;
    case MediaStorage::UltrasoundMultiFrameImageStorageRetired:
    case MediaStorage::UltrasoundMultiFrameImageStorage:
      iodname ="US Multi Frame Image IOD Modules";
      break;
    case MediaStorage::SecondaryCaptureImageStorage:
      iodname = "SC Image IOD Modules";
      break;
    case MediaStorage::XRayRadiofluoroscopingImageStorage:
      iodname = "XRF Image IOD Modules";
      break;
    case MediaStorage::MRSpectroscopyStorage:
      iodname = "MR Spectroscopy IOD Modules";
      break;
    case MediaStorage::NuclearMedicineImageStorageRetired:
    case MediaStorage::NuclearMedicineImageStorage:
      iodname = "NM Image IOD Modules";
      break;
    case MediaStorage::MultiframeSingleBitSecondaryCaptureImageStorage:
      iodname = "Multi Frame Single Bit SC Image IOD Modules";
      break;
    case MediaStorage::MultiframeGrayscaleByteSecondaryCaptureImageStorage:
      iodname = "Multi Frame Grayscale Byte SC Image IOD Modules";
      break;
    case MediaStorage::MultiframeGrayscaleWordSecondaryCaptureImageStorage:
      iodname = "Multi Frame Grayscale Word SC Image IOD Modules";
      break;
    case MediaStorage::MultiframeTrueColorSecondaryCaptureImageStorage:
      iodname = "Multi Frame True Color SC Image IOD Modules";
      break;
    case MediaStorage::EncapsulatedPDFStorage:
      iodname = "Encapsulated PDF IOD Modules";
      break;
    case MediaStorage::EncapsulatedCDAStorage:
      iodname = "Encapsulated CDA IOD Modules";
      break;
    case MediaStorage::VLPhotographicImageStorage:
      iodname = "VL Photographic Image IOD Modules";
      break;
    case MediaStorage::SegmentationStorage:
      iodname = "Segmentation IOD Modules";
      break;
    case MediaStorage::RawDataStorage:
      iodname = "Raw Data IOD Modules";
      break;
    case MediaStorage::MammographyCADSR:
      iodname = "Mammography CAD SR IOD Modules";
      break;
    case MediaStorage::VideoEndoscopicImageStorage:
      iodname = "Video Endoscopic Image IOD Modules";
      break;
    case MediaStorage::RTImageStorage:
      iodname = "RT Image IOD Modules";
      break;
    case MediaStorage::RTDoseStorage:
      iodname = "RT Dose IOD Modules";
      break;
    case MediaStorage::RTStructureSetStorage:
      iodname = "RT Structure Set IOD Modules";
      break;
    case MediaStorage::RTPlanStorage:
      iodname = "RT Plan IOD Modules";
      break;
    case MediaStorage::ModalityPerformedProcedureStepSOPClass:
      iodname = "Modality Performed Procedure Step IOD Modules";
      break;
    case MediaStorage::HangingProtocolStorage:
      iodname = "Hanging Protocol IOD Modules";
      break;
    case MediaStorage::KeyObjectSelectionDocument:
      iodname = "Key Object Selection Document IOD Modules";
      break;
    case MediaStorage::ComprehensiveSR:
      iodname = "Comprehensive SR IOD Modules";
      break;
    case MediaStorage::HemodynamicWaveformStorage:
      iodname = "Hemodynamic IOD Modules";
      break;
    case MediaStorage::DigitalIntraoralXrayImageStorageForPresentation:
    case MediaStorage::DigitalIntraoralXRayImageStorageForProcessing:
      iodname = "Digital Intra Oral X Ray Image IOD Modules";
      break;
    case MediaStorage::DigitalXRayImageStorageForPresentation:
    case MediaStorage::DigitalXRayImageStorageForProcessing:
      iodname = "Digital X Ray Image IOD Modules";
      break;
    case MediaStorage::DigitalMammographyImageStorageForPresentation:
    case MediaStorage::DigitalMammographyImageStorageForProcessing:
      iodname = "Digital Mammography X Ray Image IOD Modules";
      break;
    case MediaStorage::GrayscaleSoftcopyPresentationStateStorageSOPClass:
      iodname = "Grayscale Softcopy Presentation State IOD Modules";
      break;
    case MediaStorage::LeadECGWaveformStorage:
      iodname = "12 Lead ECG IOD Modules";
      break;
    case MediaStorage::GeneralECGWaveformStorage:
      iodname = "General ECG IOD Modules";
      break;
    case MediaStorage::AmbulatoryECGWaveformStorage:
      iodname = "Ambulatory ECG IOD Modules";
      break;
    case MediaStorage::BasicVoiceAudioWaveformStorage:
      iodname = "Basic Voice Audio IOD Modules";
      break;
    case MediaStorage::SpacialFiducialsStorage:
      iodname = "Spatial Fiducials IOD Modules";
      break;
    case MediaStorage::BasicTextSR:
      iodname = "Basic Text SR IOD Modules";
      break;
    case MediaStorage::CardiacElectrophysiologyWaveformStorage:
      iodname = "Basic Cardiac EP IOD Modules";
      break;
    case MediaStorage::PETImageStorage:
      iodname = "PET Image IOD Modules";
      break;
    case MediaStorage::EnhancedSR:
      iodname = "Enhanced SR IOD Modules";
      break;
    case MediaStorage::SpacialRegistrationStorage:
      iodname = "Spatial Registration IOD Modules";
      break;
    case MediaStorage::RTIonPlanStorage:
      iodname = "RT Ion Plan IOD Modules";
      break;
    case MediaStorage::XRay3DAngiographicImageStorage:
      iodname = "X Ray 3D Angiographic Image IOD Modules";
      break;
    case MediaStorage::EnhancedXAImageStorage:
      iodname = "Enhanced X Ray Angiographic Image IOD Modules";
      break;
    case MediaStorage::RTIonBeamsTreatmentRecordStorage:
      iodname = "RT Ion Beams Treatment Record IOD Modules";
      break;
    case MediaStorage::RTTreatmentSummaryRecordStorage:
      iodname = "RT Treatment Summary Record IOD Modules";
      break;
    case MediaStorage::VLEndoscopicImageStorage:
      iodname = "VL Endoscopic Image IOD Modules";
      break;
    case MediaStorage::XRayRadiationDoseSR:
      iodname = "X Ray Radiation Dose SR IOD Modules";
      break;
    case MediaStorage::CSANonImageStorage:
      iodname = "Siemens Non-image IOD Modules";
      break;
    case MediaStorage::VLMicroscopicImageStorage:
      iodname = "VL Microscopic Image IOD Modules";
      break;
    default:
      iodname = 0;
    }
  return iodname;
}

const IOD& Defs::GetIODFromFile(const File& file) const
{
  MediaStorage ms;
  ms.SetFromFile(file); // SetFromDataSet does not handle DICOMDIR

  const IODs &iods = GetIODs();
  const char *iodname = GetIODNameFromMediaStorage( ms );
  if( !iodname )
    {
    gdcmErrorMacro( "Not implemented: " << ms );
    throw "Not Implemented";
    }
  const IOD &iod = iods.GetIOD( iodname );
  return iod;
}

Type Defs::GetTypeFromTag(const File& file, const Tag& tag) const
{
  Type ret;
  MediaStorage ms;
  ms.SetFromFile(file); // SetFromDataSet does not handle DICOMDIR

  const IODs &iods = GetIODs();
  const Modules &modules = GetModules();
  const char *iodname = GetIODNameFromMediaStorage( ms );
  if( !iodname )
    {
    gdcmErrorMacro( "Not implemented: " << ms );
    return ret;
    }
  const IOD &iod = iods.GetIOD( iodname );
  const Macros &macros = GetMacros();

  IOD::SizeType niods = iod.GetNumberOfIODs();
  // Iterate over each iod entry in order:
  for(unsigned int idx = 0; idx < niods; ++idx)
    {
    const IODEntry &iodentry = iod.GetIODEntry(idx);
    const char *ref = iodentry.GetRef();
    //Usage::UsageType ut = iodentry.GetUsageType();

    const Module &module = modules.GetModule( ref );
    if( module.FindModuleEntryInMacros(macros, tag ) )
      {
      const ModuleEntry &module_entry = module.GetModuleEntryInMacros(macros,tag);
      ret = module_entry.GetType();
      }
    }

  return ret;
}

bool Defs::Verify(const File& file) const
{
  MediaStorage ms;
  ms.SetFromFile(file);

  const IODs &iods = GetIODs();
  const Modules &modules = GetModules();
  const char *iodname = GetIODNameFromMediaStorage( ms );
  if( !iodname )
    {
    gdcmErrorMacro( "Not implemented" );
    return false;
    }
  const IOD &iod = iods.GetIOD( iodname );

  //std::cout << iod << std::endl;
  //std::cout << iod.GetIODEntry(14) << std::endl;
  IOD::SizeType niods = iod.GetNumberOfIODs();
  bool v = true;
  // Iterate over each iod entry in order:
  for(unsigned int idx = 0; idx < niods; ++idx)
    {
    const IODEntry &iodentry = iod.GetIODEntry(idx);
    const char *ref = iodentry.GetRef();
    Usage::UsageType ut = iodentry.GetUsageType();

    const Module &module = modules.GetModule( ref );
    //std::cout << module << std::endl;
    v = v && module.Verify( file.GetDataSet(), ut );
    }

  return v;

}

bool Defs::Verify(const DataSet& ds) const
{
  MediaStorage ms;
  ms.SetFromDataSet(ds);

  const IODs &iods = GetIODs();
  const Modules &modules = GetModules();
  const char *iodname = GetIODNameFromMediaStorage( ms );
  if( !iodname )
    {
    gdcmErrorMacro( "Not implemented" );
    return false;
    }
  const IOD &iod = iods.GetIOD( iodname );

  //std::cout << iod << std::endl;
  //std::cout << iod.GetIODEntry(14) << std::endl;
  IOD::SizeType niods = iod.GetNumberOfIODs();
  bool v = true;
  // Iterate over each iod entry in order:
  for(unsigned int idx = 0; idx < niods; ++idx)
    {
    const IODEntry &iodentry = iod.GetIODEntry(idx);
    const char *ref = iodentry.GetRef();
    Usage::UsageType ut = iodentry.GetUsageType();

    const Module &module = modules.GetModule( ref );
    //std::cout << module << std::endl;
    v = v && module.Verify( ds, ut );
    }

  return v;

}


} // end namespace gdcm