SIVIC API  0.9.26
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
svkDcmHeader.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2009-2014 The Regents of the University of California.
3  * All Rights Reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * • Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * • Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * • None of the names of any campus of the University of California, the name
13  * "The Regents of the University of California," or the names of any of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
26  * OF SUCH DAMAGE.
27  */
28 
29 
30 
31 /*
32  * $URL$
33  * $Rev$
34  * $Author$
35  * $Date$
36  *
37  * Authors:
38  * Jason C. Crane, Ph.D.
39  * Beck Olson
40  */
41 
42 
43 #ifndef SVK_DCM_HEADER_H
44 #define SVK_DCM_HEADER_H
45 
46 
47 #include <vtkObjectFactory.h>
48 #include <vtkObject.h>
49 #include <vtkMath.h>
50 
51 #include <iostream>
52 #include <sstream>
53 #include <stdexcept>
54 #include <map>
55 #include <vector>
56 
57 
58 namespace svk {
59 
60 using namespace std;
61 
62 
66 class svkDcmHeader: public vtkObject
67 {
68 
69  public:
70 
71  vtkTypeMacro( svkDcmHeader, vtkObject );
72 
73  // Members:
74 
78  typedef enum {
79  MR_IMAGE = 0,
82  SECONDARY_CAPTURE, // Deprecated
83  MULTI_FRAME_BYTE_SC, // 8 bit gray scale multi-frame SC image
84  MULTI_FRAME_WORD_SC, // >8 bit gray scale multi-frame SC image
85  RAW_DATA
86  } DcmIodType;
87 
88  enum {
89  DCMTK_API = 0
90  };
91 
92  typedef enum {
93  UNDEFINED = -1,
94  UNSIGNED_INT_1 = 0,
98  SIGNED_FLOAT_8
99  } DcmPixelDataFormat;
100 
101  typedef enum {
102  UNKNOWN_ORIENTATION = -1,
103  AXIAL = 0,
105  SAGITTAL
106  } Orientation;
107 
108  typedef enum{
109  SLICE_ORDER_UNDEFINED = -1,
110  INCREMENT_ALONG_POS_NORMAL = 0,
111  INCREMENT_ALONG_NEG_NORMAL = 1
112  } DcmDataOrderingDirection;
113 
114 
115  typedef enum {
116  PHI_IDENTIFIED = 0,
118  PHI_DEIDENTIFIED
119  } PHIType;
120 
121 
122  typedef enum {
123  COL_INDEX = -2,
124  ROW_INDEX = -1,
125  SLICE_INDEX = 0, // first index in DimensionIndexSequence
126  TIME_INDEX = 1,
127  CHANNEL_INDEX = 2,
128  EPSI_ACQ_INDEX = 3
129  } DimensionIndexLabel;
130 
131  typedef vector< map < svkDcmHeader::DimensionIndexLabel, int> > DimensionVector;
132 
133  static const float UNKNOWN_TIME;
134  static const string UNKNOWN_STRING;
135 
136 
137 #ifdef SVK_ADAPT_DCMTK
138  static const int adapter_type = DCMTK_API;
139 #endif
140 
141 
142  // Methods:
143 
148  virtual void CreateIOD(DcmIodType iodType) = 0;
149  virtual void SetSOPClassUID(DcmIodType iodType) = 0;
150  virtual void PrintDcmHeader() = 0;
151  virtual void PrintDcmHeader(ostream& os) = 0;
152 
157  virtual void InsertEmptyElement(const char* name) = 0;
158 
164  virtual void InsertUniqueUID(const char* name) = 0;
165 
169  virtual string GenerateUniqueUID() = 0;
170 
175  virtual void SetValue(const char *name, int value) = 0;
176 
181  virtual void SetValue(const char *name, float value) = 0;
182 
187  virtual void SetValue(const char *name, double value) = 0;
188 
194  virtual void SetValue(const char *name, string value, bool setMetaInfo = false) = 0;
195 
205  virtual void SetValue(const char* name, unsigned char* values, int numValues) = 0;
206 
216  virtual void SetValue(const char* name, unsigned short* values, int numValues) = 0;
217 
227  virtual void SetValue(const char* name, signed short* values, int numValues) = 0;
228 
238  virtual void SetValue(const char* name, float* values, int numValues) = 0;
239 
240  /*
241  * Sets values recursively into sub sequences
242  */
243  virtual void ModifyValueRecursive(const char* name, string value) = 0;
244 
249  virtual void GetByteValue(const char* name, char* values, long unsigned int numValues) = 0;
250 
255  virtual void GetShortValue(const char* name, short* values, long unsigned int numValues) = 0;
256 
261  virtual unsigned short GetShortValue(const char* name, long unsigned int position) = 0;
262 
267  virtual unsigned short GetPixelValue(long unsigned int position) = 0;
268 
273  virtual int GetIntValue(const char *name) = 0;
274 
279  virtual float GetFloatValue(const char *name) = 0;
280 
285  virtual void GetFloatValue(const char* name, float* values, long unsigned int numValues) = 0;
286 
287 
292  virtual double GetDoubleValue(const char *name) = 0;
293 
298  virtual string GetStringValue(const char *name) = 0;
299 
304  virtual string GetStringValue(const char *name, int pos) = 0;
305 
310  virtual void AddSequenceItemElement(
311  const char* parentSeqName,
312  int parentSeqItemPosition,
313  const char* elementName
314  ) = 0;
315 
321  virtual void AddSequenceItemElement(
322  const char* seqName,
323  int seqItemPosition,
324  const char* elementName,
325  string value,
326  const char* parentSeqName = NULL,
327  int parentSeqItemPosition = 0
328  ) = 0;
329 
330 
336  virtual void AddSequenceItemElement(
337  const char* seqName,
338  int seqItemPosition,
339  const char* elementName,
340  char* values,
341  int numValues,
342  const char* parentSeqName = NULL,
343  int parentSeqItemPosition = 0
344  ) = 0;
345 
346 
352  virtual void AddSequenceItemElement(
353  const char* seqName,
354  int seqItemPosition,
355  const char* elementName,
356  unsigned short* values,
357  int numValues,
358  const char* parentSeqName = NULL,
359  int parentSeqItemPosition = 0
360  ) = 0;
361 
367  virtual void AddSequenceItemElement(
368  const char* seqName,
369  int seqItemPosition,
370  const char* elementName,
371  unsigned int* values,
372  int numValues,
373  const char* parentSeqName = NULL,
374  int parentSeqItemPosition = 0
375  ) = 0;
376 
382  virtual void AddSequenceItemElement(
383  const char* seqName,
384  int seqItemPosition,
385  const char* elementName,
386  float* values,
387  unsigned long int numValues,
388  const char* parentSeqName = NULL,
389  int parentSeqItemPosition = 0
390  ) = 0;
391 
397  virtual void AddSequenceItemElement(
398  const char* seqName,
399  int seqItemPosition,
400  const char* elementName,
401  int value,
402  const char* parentSeqName = NULL,
403  int parentSeqItemPosition = 0
404  ) = 0;
405 
411  virtual void AddSequenceItemElement(
412  const char* seqName,
413  int seqItemPosition,
414  const char* elementName,
415  long int value,
416  const char* parentSeqName = NULL,
417  int parentSeqItemPosition = 0
418  ) = 0;
419 
425  virtual void AddSequenceItemElement(
426  const char* seqName,
427  int seqItemPosition,
428  const char* elementName,
429  float value,
430  const char* parentSeqName = NULL,
431  int parentSeqItemPosition = 0
432  ) = 0;
433 
439  virtual void AddSequenceItemElement(
440  const char* seqName,
441  int seqItemPosition,
442  const char* elementName,
443  double value,
444  const char* parentSeqName = NULL,
445  int parentSeqItemPosition = 0
446  ) = 0;
447 
448 
453  virtual void CopySequence( svkDcmHeader* target, const char* seqName ) = 0;
454 
455 
459  virtual void ClearSequence( const char* parentSeqName ) = 0;
460 
461 
465  virtual void ClearElement( const char* elementName ) = 0;
466 
470  virtual void RemoveElement( const char* elementName ) = 0;
471 
482  virtual int GetIntSequenceItemElement(
483  const char* seqName,
484  int seqItemPosition,
485  const char* elementName,
486  const char* parentSeqName = NULL,
487  int parentSeqItemPosition = 0,
488  int pos = 0
489  ) = 0;
490 
501  virtual long int GetLongIntSequenceItemElement(
502  const char* seqName,
503  int seqItemPosition,
504  const char* elementName,
505  const char* parentSeqName = NULL,
506  int parentSeqItemPosition = 0,
507  int pos = 0
508  ) = 0;
514  virtual float GetFloatSequenceItemElement(
515  const char* seqName,
516  int seqItemPosition,
517  const char* elementName,
518  const char* parentSeqName = NULL,
519  int parentSeqItemPosition = 0,
520  int pos = 0
521  ) = 0;
522 
528  virtual void GetFloatSequenceItemElement(
529  const char* seqName,
530  int seqItemPosition,
531  const char* elementName,
532  float* values,
533  int numValues,
534  const char* parentSeqName = NULL,
535  int parentSeqItemPosition = 0
536  ) = 0;
537 
543  virtual double GetDoubleSequenceItemElement(
544  const char* seqName,
545  int seqItemPosition,
546  const char* elementName,
547  const char* parentSeqName = NULL,
548  int parentSeqItemPosition = 0
549  ) = 0;
550 
556  virtual string GetStringSequenceItemElement(
557  const char* seqName,
558  int seqItemPosition,
559  const char* elementName,
560  const char* parentSeqName = NULL,
561  int parentSeqItemPosition = 0
562  ) = 0;
563 
569  virtual string GetStringSequenceItemElement(
570  const char* seqName,
571  int seqItemPosition,
572  const char* elementName,
573  int pos,
574  const char* parentSeqName = NULL,
575  int parentSeqItemPosition = 0
576  ) = 0;
577 
578 
582  virtual int GetNumberOfElements( const char* elementName ) = 0;
583 
584 
588  virtual int GetNumberOfItemsInSequence( const char* seqName ) = 0;
589 
590 
594  virtual int GetNumberOfItemsInSequence(
595  const char* seqName,
596  const char* parentSeqName,
597  int parentSeqItemPosition
598  ) = 0;
599 
605  virtual void WriteDcmFile(string fileName) = 0;
606 
607 
614  virtual void WriteDcmFileCompressed(string fileName) = 0;
615 
616 
624  virtual int ReadDcmFile(string fileName, unsigned int max_length = 0) = 0;
625 
633  virtual int ReadDcmFileHeaderOnly(string fileName) = 0;
634 
642  virtual int GetOriginalXFerSyntax() = 0;
643 
651  virtual void CopyDcmHeader(svkDcmHeader* headerCopy) = 0;
652 
653 
662  void MakeDerivedDcmHeader(svkDcmHeader* headerCopy, string seriesDescription);
663 
667  void MakeDerivedDcmHeader(string seriesDescription = "");
668 
669 
673  virtual bool ElementExists(const char* elementName, const char* parentSeqName = NULL) = 0;
674 
675 
679  virtual void ReplaceOldElements( bool replaceElements ) = 0;
680 
681 
682  string GetDcmPatientName( string PatientName );
683  void SetDcmPatientName( string PatientName );
684  void SetPixelDataType( DcmPixelDataFormat dataType );
685  int GetPixelDataType( int vtkDataType = svkDcmHeader::UNDEFINED );
686 
687  int GetOrigin( double origin[3], int frameNumber = 0 );
688  void GetPixelSpacing(double spacing[3]);
689  void GetPixelSize(double size[3]);
690  void GetOrientation(double orientation[2][3]);
691  Orientation GetOrientationType();
692  int GetOrientationIndex( svkDcmHeader::Orientation orientation );
693  void GetNormalVector(double normal[3]);
694  void GetDataDcos(
695  double dcos[3][3],
696  DcmDataOrderingDirection dataSliceOrder = SLICE_ORDER_UNDEFINED
697  );
698  void SetSliceOrder( DcmDataOrderingDirection sliceOrderVal );
699  int GetNumberOfCoils();
700  int GetNumberOfSlices();
701  static int GetNumberOfDimensionIndices(int numTimePts, int numCoils);
702  static void SetDimensionIndices(
703  unsigned int* indexValues,
704  int numFrameIndices,
705  int sliceNum,
706  int timePt,
707  int coilNum,
708  int numTimePts,
709  int numCoils
710  );
711  int GetNumberOfTimePoints();
712  int GetSliceForFrame( int frame );
713  void UpdateNumTimePoints();
714  void UpdateNumCoils();
715 
716  int GetDimensionIndexPosition(string indexLabel);
717  string GetDimensionIndexLabel(int dimensionIndexNumber );
718  void AddDimensionIndex( svkDcmHeader::DimensionVector* dimensionVector,
719  svkDcmHeader::DimensionIndexLabel indexType, int maxIndex = 0);
720  void RemoveDimensionIndex( svkDcmHeader::DimensionIndexLabel indexType );
721  void SetDimensionIndexSize(
722  svkDcmHeader::DimensionIndexLabel indexType, int maxIndex);
723  virtual int GetSequenceItemElementLength(
724  const char* seqName,
725  int seqItemPosition,
726  const char* elementName,
727  const char* parentSeqName,
728  int parentSeqItemPosition) = 0;
729 
730  static void PrintDimensionIndexVector( svkDcmHeader::DimensionVector* dimensionVector );
731  DimensionVector GetDimensionIndexVector();
732  static void SwapDimensionIndexLabels(
733  svkDcmHeader::DimensionVector* dimensionVector,
736  );
737 
738  static DimensionIndexLabel
739  StringToDimensionIndexLabel( string dimensionIndexLabelString );
740  static string DimensionIndexLabelToString( svkDcmHeader::DimensionIndexLabel label);
741  static DimensionIndexLabel
742  GetDimensionLabelFromIndex(
743  svkDcmHeader::DimensionVector* dimensionVector,
744  int index );
745  static int GetDimensionVectorValue(svkDcmHeader::DimensionVector* dimensionVector,
746  svkDcmHeader::DimensionIndexLabel dimensionLabel);
747  static int GetDimensionVectorValue(svkDcmHeader::DimensionVector* dimensionVector, int index);
748  static void SetDimensionVectorValue(svkDcmHeader::DimensionVector* dimensionVector,
749  int index,
750  int value
751  );
752  static void SetDimensionVectorValue(svkDcmHeader::DimensionVector* dimensionVector,
754  int value
755  );
756  static bool IsDimensionDefined(svkDcmHeader::DimensionVector* dimensionVector,
758  static void GetDimensionVectorIndexFromFrame( svkDcmHeader::DimensionVector* dimensionVector,
759  svkDcmHeader::DimensionVector* loopIndex, int frame);
760  static void GetDimensionVectorIndexFromCellID( svkDcmHeader::DimensionVector* dimensionVector,
761  svkDcmHeader::DimensionVector* loopIndex, int cellID);
762  static int GetCellIDFromDimensionVectorIndex( svkDcmHeader::DimensionVector* dimensionVector,
763  svkDcmHeader::DimensionVector* loopIndex);
764  static int GetSpatialCellIDFromDimensionVectorIndex( svkDcmHeader::DimensionVector* dimensionVector,
765  svkDcmHeader::DimensionVector* loopIndex);
766 
767  int GetNumberOfFramesInDimension( int dimensionIndex );
768  static int GetNumberOfCells(svkDcmHeader::DimensionVector* dimensionVector);
769  int GetNumberOfFrames(svkDcmHeader::DimensionVector* dimensionVector);
770  static long int GetPixelDataOffset( string fileName );
771  static short GetPixelValueAsShort(
772  long int offsetToPixelData,
773  long int pixelIndex,
774  string fileName);
775 
776 
777  //==================================================
778  // DICOM IE and macro initialization methods:
779  //==================================================
780  void InitPatientModule(
781  string PatientName,
782  string patientID,
783  string PatientBirthDate,
784  string PatientSex
785  );
786 
787  void InitGeneralStudyModule(
788  string studyDate,
789  string studyTime,
790  string referringPhysiciansName,
791  string studyID,
792  string accessionNumber,
793  string studyInstanceUID
794  );
795  void InitGeneralSeriesModule(
796  string seriesNumber,
797  string seriesDescription,
798  string patientPosition
799  );
800  void InitImagePixelModule( int rows, int columns, svkDcmHeader::DcmPixelDataFormat dataType);
801  void InitImagePlaneModule(
802  string imagePositionPatient,
803  string pixelSpacing = "",
804  string imageOrientationPatient = "",
805  string sliceThickness = ""
806  );
807  void InitMRImageModule( string repetitionTime, string echoTime);
808  void InitPlaneOrientationMacro( double dcos[3][3] );
809  void InitPlaneOrientationMacro( string orientationString );
810  void InitPixelMeasuresMacro( string pixelSizes, string sliceThickness );
811  void InitMultiFrameDimensionModule( svkDcmHeader::DimensionVector* dimensionVector);
812  void InitPerFrameFunctionalGroupSequence(
813  double toplc[3],
814  double voxelSpacing[3],
815  double dcos[3][3],
816  svkDcmHeader::DimensionVector* dimensionVector
817  );
818 
819  void InitVOILUTModule(float center, float width);
820  void InitPixelValueTransformationMacro(double slope = 1.00000, double intercept = 0.00000);
821  void InitMRImagingModifierMacro(
822  float transmitFreq,
823  float pixelBandwidth,
824  string magTransfer = "NONE",
825  string bloodNulling = "NO"
826  );
827  void InitVolumeLocalizationSeq(float size[3], float center[3], float dcos[3][3]);
828  void InitMRTimingAndRelatedParametersMacro(float tr = UNKNOWN_TIME, float flipAngle= -999, int numEchoes = 1);
829  void InitMREchoMacro(float TE = UNKNOWN_TIME );
830  void InitMRModifierMacro(float inversionTime = UNKNOWN_TIME);
831  void InitMRTransmitCoilMacro(
832  string coilMfg = "UNKNOWN",
833  string coilName = "UNKNOWN",
834  string coilType = "UNKNOWN"
835  );
836  void InitMRAveragesMacro(int numAverages = 1);
837  void InitRawDataModule(
838  string contentDate,
839  string contentTime,
840  void* rawFile
841  );
842 
843  int InitDerivedMRIHeader(svkDcmHeader* mri, vtkIdType dataType, string seriesDescription);
844  int ConvertEnhancedMriToMriHeader( svkDcmHeader* mri, vtkIdType dataType );
845  virtual string GetDcmNameFromTag( string groupElementString ) = 0;
846 
847 
848 
849  //==================================================
850  // Deidentification methods
851  //==================================================
852  void Deidentify( PHIType phiType );
853  void Deidentify( PHIType phiType, string id );
854  void Deidentify( PHIType phyType, string patientId, string studyId );
855 
856  static bool IsFileDICOM( string fname);
857  static svkDcmHeader::DcmPixelDataFormat GetVtkDataTypeFromSvkDataType( vtkIdType vtkType);
858  void Redimension(svkDcmHeader::DimensionVector* dimensionVector);
859  void Redimension(svkDcmHeader::DimensionVector* dimensionVector, double* newToplcOrigin, double* newPixelSpacing );
860 
861 
862  static void GetCenterFromOrigin(
863  double origin[3],
864  int numVoxels[3],
865  double voxelSpacing[3],
866  double dcos[3][3],
867  double center[3]
868  );
869  static void GetCenterFromOrigin( svkDcmHeader* hdr, double center[3] );
870  static void GetOriginFromCenter(
871  double center[3],
872  int numVoxels[3],
873  double voxelSpacing[3],
874  double dcos[3][3],
875  double origin[3]
876  );
877  static void GetSpatialDimensions(
878  svkDcmHeader::DimensionVector* dimensionVector,
879  int* numVoxels
880  );
881  static int GetNumSpatialVoxels(svkDcmHeader::DimensionVector* dimensionVector);
882 
883 
884 
885  protected:
886 
887  svkDcmHeader();
888  ~svkDcmHeader();
889  bool WasModified();
890 
891 
892  private:
893  double pixelSize[3];
894  double pixelSpacing[3];
895  double origin0[3];
896  double orientation[2][3];
897  int numTimePts;
898  int numCoils;
899  unsigned long lastUpdateTime;
900  DcmDataOrderingDirection dataSliceOrder;
901  DimensionVector dimensionIndexVector;
902 
903  void UpdateSpatialParams();
904  void UpdateOrientation();
905  void UpdatePixelSpacing();
906  void UpdatePixelSize();
907  void UpdateOrigin0();
908  void UpdateDimensionIndexVector();
909  void InitPlanePositionMacro(
910  double toplc[3], double voxelSpacing[3],
911  double dcos[3][3], svkDcmHeader::DimensionVector* dimensionVector
912  );
913  void InitFrameContentMacro( svkDcmHeader::DimensionVector* dimensionVector);
914 
915  int GetNumberOfFrames();
916  void InsertDimensionIndexLabels( );
917  void GetDimensionIndexPointer(
919  unsigned short* dimensionIndexPointer,
920  unsigned short* functionalGroupPointer
921  );
922 
923 
924 };
925 
926 
927 } //svk
928 
929 
930 #endif //SVK_DCM_HEADER_H
931 
DcmIodType
Definition: svkDcmHeader.h:78
Definition: svkDcmHeader.h:66
Definition: svkDcmHeader.h:104
Definition: svkDcmHeader.h:84
Definition: svkDcmHeader.h:96
static const float UNKNOWN_TIME
Definition: svkDcmHeader.h:133
Definition: svkDcmHeader.h:83
Definition: svkDcmHeader.h:80
DcmPixelDataFormat
Definition: svkDcmHeader.h:92
Orientation
Definition: svkDcmHeader.h:101
PHIType
Definition: svkDcmHeader.h:115
Definition: svkDcmHeader.h:81
static const string UNKNOWN_STRING
Definition: svkDcmHeader.h:134
Definition: svkDcmHeader.h:97
Definition: svkDcmHeader.h:93
DcmDataOrderingDirection
Definition: svkDcmHeader.h:108
Definition: svkDcmHeader.h:95
vector< map< svkDcmHeader::DimensionIndexLabel, int > > DimensionVector
Definition: svkDcmHeader.h:131
Definition: svkDcmHeader.h:82
DimensionIndexLabel
Definition: svkDcmHeader.h:122
Definition: svkDcmHeader.h:117