15 #ifndef __vtkITKArchetypeImageSeriesReader_h 16 #define __vtkITKArchetypeImageSeriesReader_h 22 #include "vtkImageAlgorithm.h" 26 #include "itkImageIOBase.h" 27 #include "itkMetaDataDictionary.h" 28 #include "itkSpatialOrientation.h" 50 void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
56 vtkSetStringMacro(Archetype);
57 vtkGetStringMacro(Archetype);
61 unsigned int GetNumberOfFileNames();
64 const std::vector<std::string>& GetFileNames();
70 unsigned int AddFileName(
const char* filename );
71 const char* GetFileName(
unsigned int n );
72 void ResetFileNames();
77 vtkSetVector3Macro(DefaultDataSpacing,
double);
78 vtkGetVector3Macro(DefaultDataSpacing,
double);
84 vtkSetVector3Macro(DefaultDataOrigin,
double);
85 vtkGetVector3Macro(DefaultDataOrigin,
double);
90 vtkSetMacro(FileNameSliceOffset,
int);
91 vtkGetMacro(FileNameSliceOffset,
int);
97 vtkSetMacro(FileNameSliceSpacing,
int);
98 vtkGetMacro(FileNameSliceSpacing,
int);
103 vtkSetMacro(FileNameSliceCount,
int);
104 vtkGetMacro(FileNameSliceCount,
int);
107 virtual int CanReadFile(
const char* filename);
113 this->DesiredCoordinateOrientation =
114 itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAI;
116 this->UseNativeCoordinateOrientation = 0;
121 this->DesiredCoordinateOrientation =
122 itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSA;
124 this->UseNativeCoordinateOrientation = 0;
129 this->DesiredCoordinateOrientation =
130 itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_ASL;
132 this->UseNativeCoordinateOrientation = 0;
137 this->UseNativeCoordinateOrientation = 1;
140 vtkGetMacro(DesiredCoordinateOrientation, CoordinateOrientationCode);
141 vtkGetMacro(UseNativeCoordinateOrientation,
char);
149 UseNativeScalarType = 0;
150 this->SetOutputScalarType(VTK_DOUBLE);
154 UseNativeScalarType = 0;
155 this->SetOutputScalarType(VTK_FLOAT);
159 UseNativeScalarType = 0;
160 this->SetOutputScalarType(VTK_LONG);
164 UseNativeScalarType = 0;
165 this->SetOutputScalarType(VTK_UNSIGNED_LONG);
169 UseNativeScalarType = 0;
170 this->SetOutputScalarType(VTK_INT);
174 UseNativeScalarType = 0;
175 this->SetOutputScalarType(VTK_UNSIGNED_INT);
179 UseNativeScalarType = 0;
180 this->SetOutputScalarType(VTK_SHORT);
184 UseNativeScalarType = 0;
185 this->SetOutputScalarType(VTK_UNSIGNED_SHORT);
189 UseNativeScalarType = 0;
190 this->SetOutputScalarType(VTK_CHAR);
194 UseNativeScalarType = 0;
195 this->SetOutputScalarType(VTK_UNSIGNED_CHAR);
199 UseNativeScalarType = 1;
207 UseNativeOrigin =
true;
214 UseNativeOrigin =
false;
225 vtkGetMacro(DICOMImageIOApproach,
int);
231 vtkSetMacro(OutputScalarType,
int);
232 vtkGetMacro(OutputScalarType,
int);
236 vtkSetMacro(NumberOfComponents,
unsigned int);
237 vtkGetMacro(NumberOfComponents,
unsigned int);
241 vtkSetMacro(SingleFile,
int);
242 vtkGetMacro(SingleFile,
int);
246 vtkSetMacro(AnalyzeHeader,
bool);
247 vtkGetMacro(AnalyzeHeader,
bool);
251 vtkSetMacro(UseOrientationFromFile,
int);
252 vtkGetMacro(UseOrientationFromFile,
int);
256 vtkMatrix4x4* GetRasToIjkMatrix();
260 vtkMatrix4x4* GetMeasurementFrameMatrix();
264 const itk::MetaDataDictionary &GetMetaDataDictionary()
const;
267 void ParseDictionary();
269 unsigned int GetNumberOfItemsInDictionary();
270 bool HasKey(
char* tag );
271 const char* GetNthKey(
unsigned int n );
272 const char* GetNthValue(
unsigned int n );
273 const char* GetTagValue(
char* tag );
278 return GroupingByTags;
283 GroupingByTags =
true;
288 GroupingByTags =
false;
300 SetGroupingByTagsOn();
306 return SelectedContentTime;
311 SelectedContentTime = v;
312 SetGroupingByTagsOn();
318 return SelectedTriggerTime;
323 SelectedTriggerTime = v;
324 SetGroupingByTagsOn();
330 return SelectedEchoNumbers;
335 SelectedEchoNumbers = v;
336 SetGroupingByTagsOn();
343 return SelectedDiffusion;
348 SelectedDiffusion = v;
349 SetGroupingByTagsOn();
355 return SelectedSlice;
361 SetGroupingByTagsOn();
367 return SelectedOrientation;
372 SelectedOrientation = v;
373 SetGroupingByTagsOn();
379 return this->SeriesInstanceUIDs.size();
384 return this->ContentTime.size();
389 return this->TriggerTime.size();
394 return this->EchoNumbers.size();
399 return this->SliceLocation.size();
404 return this->DiffusionGradientOrientation.size();
409 return this->ImageOrientationPatient.size();
414 return this->ImagePositionPatient.size();
420 for (
unsigned int k = 0; k < GetNumberOfSeriesInstanceUIDs(); k++)
422 if ( this->SeriesInstanceUIDs[k].find(SeriesInstanceUID) != std::string::npos )
432 for (
unsigned int k = 0; k < GetNumberOfContentTime(); k++)
434 if ( this->ContentTime[k].find(contentTime) != std::string::npos )
444 for (
unsigned int k = 0; k < GetNumberOfTriggerTime(); k++)
446 if ( this->TriggerTime[k].find(triggerTime) != std::string::npos )
456 for (
unsigned int k = 0; k < GetNumberOfEchoNumbers(); k++)
458 if ( this->EchoNumbers[k].find(echoNumbers) != std::string::npos )
469 for (
int n = 0;
n < 3;
n++)
474 for (
unsigned int k = 0; k < GetNumberOfDiffusionGradientOrientation(); k++)
478 for (
int n = 0;
n < 3;
n++)
480 b += this->DiffusionGradientOrientation[k][
n] * this->DiffusionGradientOrientation[k][
n];
481 c += this->DiffusionGradientOrientation[k][
n] * dgo[
n];
483 c = fabs(c)/sqrt(a*b);
495 std::vector<float>::iterator iter =
496 std::find(this->SliceLocation.begin(), this->SliceLocation.end(), sliceLocation);
497 return iter != this->SliceLocation.end() ?
498 std::distance(this->SliceLocation.begin(), iter) : -1;
504 float a = sqrt( directionCosine[0]*directionCosine[0] + directionCosine[1]*directionCosine[1] + directionCosine[2]*directionCosine[2] );
505 for (
int k = 0; k < 3; k++)
507 directionCosine[k] /= a;
509 a = sqrt( directionCosine[3]*directionCosine[3] + directionCosine[4]*directionCosine[4] + directionCosine[5]*directionCosine[5] );
510 for (
int k = 3; k < 6; k++)
512 directionCosine[k] /= a;
515 for (
unsigned int k = 0; k < GetNumberOfImageOrientationPatient(); k++)
517 std::vector<float> aVec = ImageOrientationPatient[k];
518 a = sqrt( aVec[0]*aVec[0] + aVec[1]*aVec[1] + aVec[2]*aVec[2] );
519 float b = (directionCosine[0]*aVec[0] + directionCosine[1]*aVec[1] + directionCosine[2]*aVec[2])/a;
525 a = sqrt( aVec[3]*aVec[3] + aVec[4]*aVec[4] + aVec[5]*aVec[5] );
526 b = (directionCosine[3]*aVec[3] + directionCosine[4]*aVec[4] + directionCosine[5]*aVec[5])/a;
538 for (
int n = 0;
n < 3;
n++)
543 for (
unsigned int k = 0; k < GetNumberOfImagePositionPatient(); k++)
547 for (
int n = 0;
n < 3;
n++)
549 b += this->ImagePositionPatient[k][
n] * this->ImagePositionPatient[k][
n];
550 c += this->ImagePositionPatient[k][
n] * ipp[
n];
552 c = fabs(c)/sqrt(a*b);
564 if (
n >= this->GetNumberOfSeriesInstanceUIDs() )
568 return this->SeriesInstanceUIDs[
n].c_str();
573 if (
n >= this->GetNumberOfContentTime() )
577 return this->ContentTime[
n].c_str();
582 if (
n >= this->GetNumberOfTriggerTime() )
586 return this->TriggerTime[
n].c_str();
591 if (
n >= this->GetNumberOfEchoNumbers() )
595 return this->EchoNumbers[
n].c_str();
600 if (
n >= this->GetNumberOfDiffusionGradientOrientation() )
604 float *dgo =
new float [3];
605 for (
int k = 0; k <3; k++)
607 dgo[k] = this->DiffusionGradientOrientation[
n][k];
614 if (
n >= this->GetNumberOfSliceLocation() )
616 return this->SliceLocation[0];
618 return this->SliceLocation[0];
623 if (
n >= this->GetNumberOfImageOrientationPatient() )
627 float *dgo =
new float [6];
628 for (
int k = 0; k <6; k++)
630 dgo[k] = this->ImageOrientationPatient[
n][k];
637 if (
n >= this->GetNumberOfImagePositionPatient() )
641 float *ipp =
new float [3];
642 for (
int k = 0; k <3; k++)
644 ipp[k] = this->ImagePositionPatient[
n][k];
653 int k = ExistSeriesInstanceUID( aUID );
659 std::string aVector(aUID);
660 this->SeriesInstanceUIDs.push_back( aVector );
661 return (this->SeriesInstanceUIDs.size()-1);
666 int k = ExistContentTime( aTime );
672 std::string aVector(aTime);
673 this->ContentTime.push_back( aVector );
674 return (this->ContentTime.size()-1);
679 int k = ExistTriggerTime( aTime );
685 std::string aVector(aTime);
686 this->TriggerTime.push_back( aVector );
687 return (this->TriggerTime.size()-1);
692 int k = ExistEchoNumbers( aEcho );
698 std::string aVector(aEcho);
699 this->EchoNumbers.push_back( aVector );
700 return (this->EchoNumbers.size()-1);
705 int k = ExistDiffusionGradientOrientation( a );
710 std::vector< float > aVector(3);
711 float aMag = sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
712 for (k = 0; k < 3; k++)
714 aVector[k] = a[k]/aMag;
717 this->DiffusionGradientOrientation.push_back( aVector );
718 return (this->DiffusionGradientOrientation.size()-1);
726 int k = ExistSliceLocation( a );
732 this->SliceLocation.push_back( a );
733 return (this->SliceLocation.size()-1);
739 int size = this->SliceLocation.size();
740 this->SliceLocation.push_back(
741 size > 0 ? this->SliceLocation.back() + 1 : 0.f);
747 int k = ExistImageOrientationPatient( a );
752 std::vector< float > aVector(6);
753 float aMag = sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
754 float bMag = sqrt(a[3]*a[3]+a[4]*a[4]+a[5]*a[5]);
755 for (k = 0; k < 3; k++)
757 aVector[k] = a[k]/aMag;
758 aVector[k+3] = a[k+3]/bMag;
761 this->ImageOrientationPatient.push_back( aVector );
762 return (this->ImageOrientationPatient.size()-1);
767 int k = ExistImagePositionPatient( a );
773 std::vector< float > aVector(3);
774 for (
unsigned int i = 0; i < 3; i++ ) aVector[i] = a[i];
775 this->ImagePositionPatient.push_back( aVector );
776 return (this->ImagePositionPatient.size()-1);
779 void AnalyzeDicomHeaders( );
781 void AssembleNthVolume(
int n );
782 int AssembleVolumeContainingArchetype();
784 void GroupFiles (
int idxSeriesInstanceUID,
788 int idxDiffusionGradientOrientation,
789 int idxSliceLocation,
790 int idxImageOrientationPatient );
792 const char* GetNthFileName (
int idxSeriesInstanceUID,
796 int idxDiffusionGradientOrientation,
797 int idxSliceLocation,
798 int idxImageOrientationPatient,
807 static std::string GetMetaDataWithoutSpaces(
const itk::MetaDataDictionary &dict,
const std::string& tag);
819 void GetScalarRangeMetaDataKeys(itk::ImageIOBase::Pointer imageIO,
820 std::string range_keys[2]);
821 void SetMetaDataScalarRangeToPointDataInfo(vtkImageData* data);
823 double DefaultDataSpacing[3];
824 double DefaultDataOrigin[3];
855 virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) VTK_OVERRIDE;
std::vector< std::string > Tags
std::vector< long int > IndexSeriesInstanceUIDs
index of each dicom file into the above arrays
std::vector< std::vector< float > > ImageOrientationPatient
void SetDesiredCoordinateOrientationToCoronal()
std::vector< std::vector< float > > DiffusionGradientOrientation
virtual void SetOutputScalarTypeToUnsignedChar()
int GetSelectedTriggerTime()
void SetDICOMImageIOApproachToGDCM()
int GetSelectedContentTime()
std::vector< std::string > TagValues
itk::MetaDataDictionary Dictionary
float * GetNthImageOrientationPatient(unsigned int n)
int ExistImagePositionPatient(float *ipp)
vtkMatrix4x4 * MeasurementFrameMatrix
std::vector< double > MetaDataScalarRangeMaxima
std::vector< long int > IndexImageOrientationPatient
void SetSelectedSlice(int v)
int InsertSeriesInstanceUIDs(const char *aUID)
unsigned int GetNumberOfTriggerTime()
const char * GetNthTriggerTime(unsigned int n)
int ExistDiffusionGradientOrientation(float *dgo)
void SetGroupingByTagsOn()
const char * GetNthSeriesInstanceUID(unsigned int n)
methods to get N-th discriminator
int ExistSeriesInstanceUID(const char *SeriesInstanceUID)
check the existence of given discriminator
std::vector< std::string > EchoNumbers
int ExistSliceLocation(float sliceLocation)
std::vector< double > MetaDataScalarRangeMinima
virtual void SetOutputScalarTypeToNative()
void SetUseNativeOriginOff()
Use image center as origin
int GetSelectedEchoNumbers()
Read a series of files that have a common naming convention.
void SetUseNativeOriginOn()
Use image origin from the file
unsigned int GetNumberOfSliceLocation()
std::vector< long int > IndexContentTime
virtual void SetOutputScalarTypeToUnsignedShort()
const char * GetNthContentTime(unsigned int n)
vtkMatrix4x4 * RasToIjkMatrix
unsigned int GetNumberOfImageOrientationPatient()
int InsertNextSliceLocation()
int InsertSliceLocation(float a)
void SetGroupingByTagsOff()
std::vector< std::string > SeriesInstanceUIDs
unsigned int IndexArchetype
virtual void SetOutputScalarTypeToDouble()
virtual void SetOutputScalarTypeToUnsignedLong()
int ExistEchoNumbers(const char *echoNumbers)
CoordinateOrientationCode DesiredCoordinateOrientation
void SetDICOMImageIOApproachToDCMTK()
void SetSelectedContentTime(int v)
std::vector< std::pair< double, int > > FileNameSliceKey
float * GetNthDiffusionGradientOrientation(unsigned int n)
virtual void SetOutputScalarTypeToShort()
int ExistContentTime(const char *contentTime)
unsigned int GetNumberOfSeriesInstanceUIDs()
get number of certain discriminators in the directory
int InsertImageOrientationPatient(float *a)
int InsertDiffusionGradientOrientation(float *a)
void SetSelectedOrientation(int v)
bool GetGroupingByTags()
set/get functions for grouping by tags
int InsertEchoNumbers(const char *aEcho)
virtual void SetOutputScalarTypeToInt()
void SetDesiredCoordinateOrientationToSagittal()
std::vector< std::string > FileNames
char UseNativeCoordinateOrientation
void SetSelectedUID(int v)
std::vector< long int > IndexDiffusionGradientOrientation
int UseOrientationFromFile
int ExistImageOrientationPatient(float *directionCosine)
std::vector< float > SliceLocation
std::vector< std::string > TriggerTime
const char * GetNthEchoNumbers(unsigned int n)
int InsertContentTime(const char *aTime)
int InsertTriggerTime(const char *aTime)
unsigned int GetNumberOfContentTime()
unsigned int GetNumberOfImagePositionPatient()
std::vector< long int > IndexTriggerTime
unsigned int GetNumberOfDiffusionGradientOrientation()
int GetSelectedDiffusion()
void SetSelectedTriggerTime(int v)
int GetSelectedOrientation()
virtual void SetOutputScalarTypeToLong()
int InsertImagePositionPatient(float *a)
float * GetNthImagePositionPatient(unsigned int n)
virtual void SetOutputScalarTypeToFloat()
void SetSelectedDiffusion(int v)
std::vector< std::string > ContentTime
unsigned int GetNumberOfEchoNumbers()
unsigned int NumberOfComponents
std::vector< std::vector< float > > ImagePositionPatient
virtual void SetOutputScalarTypeToUnsignedInt()
std::vector< long int > IndexEchoNumbers
int ExistTriggerTime(const char *triggerTime)
void SetSelectedEchoNumbers(int v)
itk::SpatialOrientation::ValidCoordinateOrientationFlags CoordinateOrientationCode
std::vector< long int > IndexImagePositionPatient
std::vector< long int > IndexSliceLocation
void SetDesiredCoordinateOrientationToNative()
void SetDesiredCoordinateOrientationToAxial()
Set the orientation of the output image
virtual void SetOutputScalarTypeToChar()
std::vector< std::string > AllFileNames
float GetNthSliceLocation(unsigned int n)