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)
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();
263 vtkSetMacro(VoxelVectorType,
int);
264 vtkGetMacro(VoxelVectorType,
int);
268 const itk::MetaDataDictionary &GetMetaDataDictionary()
const;
271 void ParseDictionary();
273 unsigned int GetNumberOfItemsInDictionary();
274 bool HasKey(
char* tag );
275 const char* GetNthKey(
unsigned int n );
276 const char* GetNthValue(
unsigned int n );
277 const char* GetTagValue(
char* tag );
282 return GroupingByTags;
287 GroupingByTags =
true;
292 GroupingByTags =
false;
304 SetGroupingByTagsOn();
310 return SelectedContentTime;
315 SelectedContentTime = v;
316 SetGroupingByTagsOn();
322 return SelectedTriggerTime;
327 SelectedTriggerTime = v;
328 SetGroupingByTagsOn();
334 return SelectedEchoNumbers;
339 SelectedEchoNumbers = v;
340 SetGroupingByTagsOn();
347 return SelectedDiffusion;
352 SelectedDiffusion = v;
353 SetGroupingByTagsOn();
359 return SelectedSlice;
365 SetGroupingByTagsOn();
371 return SelectedOrientation;
376 SelectedOrientation = v;
377 SetGroupingByTagsOn();
383 return this->SeriesInstanceUIDs.size();
388 return this->ContentTime.size();
393 return this->TriggerTime.size();
398 return this->EchoNumbers.size();
403 return this->SliceLocation.size();
408 return this->DiffusionGradientOrientation.size();
413 return this->ImageOrientationPatient.size();
418 return this->ImagePositionPatient.size();
424 for (
unsigned int k = 0; k < GetNumberOfSeriesInstanceUIDs(); k++)
426 if ( this->SeriesInstanceUIDs[k].find(SeriesInstanceUID) != std::string::npos )
436 for (
unsigned int k = 0; k < GetNumberOfContentTime(); k++)
438 if ( this->ContentTime[k].find(contentTime) != std::string::npos )
448 for (
unsigned int k = 0; k < GetNumberOfTriggerTime(); k++)
450 if ( this->TriggerTime[k].find(triggerTime) != std::string::npos )
460 for (
unsigned int k = 0; k < GetNumberOfEchoNumbers(); k++)
462 if ( this->EchoNumbers[k].find(echoNumbers) != std::string::npos )
473 for (
int n = 0;
n < 3;
n++)
478 for (
unsigned int k = 0; k < GetNumberOfDiffusionGradientOrientation(); k++)
482 for (
int n = 0;
n < 3;
n++)
484 b += this->DiffusionGradientOrientation[k][
n] * this->DiffusionGradientOrientation[k][
n];
485 c += this->DiffusionGradientOrientation[k][
n] * dgo[
n];
487 c = fabs(c)/sqrt(a*b);
499 std::vector<float>::iterator iter =
500 std::find(this->SliceLocation.begin(), this->SliceLocation.end(), sliceLocation);
501 return iter != this->SliceLocation.end() ?
502 std::distance(this->SliceLocation.begin(), iter) : -1;
508 float a = sqrt( directionCosine[0]*directionCosine[0] + directionCosine[1]*directionCosine[1] + directionCosine[2]*directionCosine[2] );
509 for (
int k = 0; k < 3; k++)
511 directionCosine[k] /= a;
513 a = sqrt( directionCosine[3]*directionCosine[3] + directionCosine[4]*directionCosine[4] + directionCosine[5]*directionCosine[5] );
514 for (
int k = 3; k < 6; k++)
516 directionCosine[k] /= a;
519 for (
unsigned int k = 0; k < GetNumberOfImageOrientationPatient(); k++)
521 std::vector<float> aVec = ImageOrientationPatient[k];
522 a = sqrt( aVec[0]*aVec[0] + aVec[1]*aVec[1] + aVec[2]*aVec[2] );
523 float b = (directionCosine[0]*aVec[0] + directionCosine[1]*aVec[1] + directionCosine[2]*aVec[2])/a;
529 a = sqrt( aVec[3]*aVec[3] + aVec[4]*aVec[4] + aVec[5]*aVec[5] );
530 b = (directionCosine[3]*aVec[3] + directionCosine[4]*aVec[4] + directionCosine[5]*aVec[5])/a;
542 for (
int n = 0;
n < 3;
n++)
547 for (
unsigned int k = 0; k < GetNumberOfImagePositionPatient(); k++)
551 for (
int n = 0;
n < 3;
n++)
553 b += this->ImagePositionPatient[k][
n] * this->ImagePositionPatient[k][
n];
554 c += this->ImagePositionPatient[k][
n] * ipp[
n];
556 c = fabs(c)/sqrt(a*b);
568 if (
n >= this->GetNumberOfSeriesInstanceUIDs() )
572 return this->SeriesInstanceUIDs[
n].c_str();
577 if (
n >= this->GetNumberOfContentTime() )
581 return this->ContentTime[
n].c_str();
586 if (
n >= this->GetNumberOfTriggerTime() )
590 return this->TriggerTime[
n].c_str();
595 if (
n >= this->GetNumberOfEchoNumbers() )
599 return this->EchoNumbers[
n].c_str();
604 if (
n >= this->GetNumberOfDiffusionGradientOrientation() )
608 float *dgo =
new float [3];
609 for (
int k = 0; k <3; k++)
611 dgo[k] = this->DiffusionGradientOrientation[
n][k];
618 if (
n >= this->GetNumberOfSliceLocation() )
620 return this->SliceLocation[0];
622 return this->SliceLocation[0];
627 if (
n >= this->GetNumberOfImageOrientationPatient() )
631 float *dgo =
new float [6];
632 for (
int k = 0; k <6; k++)
634 dgo[k] = this->ImageOrientationPatient[
n][k];
641 if (
n >= this->GetNumberOfImagePositionPatient() )
645 float *ipp =
new float [3];
646 for (
int k = 0; k <3; k++)
648 ipp[k] = this->ImagePositionPatient[
n][k];
657 int k = ExistSeriesInstanceUID( aUID );
663 std::string aVector(aUID);
664 this->SeriesInstanceUIDs.push_back( aVector );
665 return (this->SeriesInstanceUIDs.size()-1);
670 int k = ExistContentTime( aTime );
676 std::string aVector(aTime);
677 this->ContentTime.push_back( aVector );
678 return (this->ContentTime.size()-1);
683 int k = ExistTriggerTime( aTime );
689 std::string aVector(aTime);
690 this->TriggerTime.push_back( aVector );
691 return (this->TriggerTime.size()-1);
696 int k = ExistEchoNumbers( aEcho );
702 std::string aVector(aEcho);
703 this->EchoNumbers.push_back( aVector );
704 return (this->EchoNumbers.size()-1);
709 int k = ExistDiffusionGradientOrientation( a );
714 std::vector< float > aVector(3);
715 float aMag = sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
716 for (k = 0; k < 3; k++)
718 aVector[k] = a[k]/aMag;
721 this->DiffusionGradientOrientation.push_back( aVector );
722 return (this->DiffusionGradientOrientation.size()-1);
730 int k = ExistSliceLocation( a );
736 this->SliceLocation.push_back( a );
737 return (this->SliceLocation.size()-1);
743 int size = this->SliceLocation.size();
744 this->SliceLocation.push_back(
745 size > 0 ? this->SliceLocation.back() + 1 : 0.f);
751 int k = ExistImageOrientationPatient( a );
756 std::vector< float > aVector(6);
757 float aMag = sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
758 float bMag = sqrt(a[3]*a[3]+a[4]*a[4]+a[5]*a[5]);
759 for (k = 0; k < 3; k++)
761 aVector[k] = a[k]/aMag;
762 aVector[k+3] = a[k+3]/bMag;
765 this->ImageOrientationPatient.push_back( aVector );
766 return (this->ImageOrientationPatient.size()-1);
771 int k = ExistImagePositionPatient( a );
777 std::vector< float > aVector(3);
778 for (
unsigned int i = 0; i < 3; i++ ) aVector[i] = a[i];
779 this->ImagePositionPatient.push_back( aVector );
780 return (this->ImagePositionPatient.size()-1);
783 void AnalyzeDicomHeaders( );
785 void AssembleNthVolume(
int n );
786 int AssembleVolumeContainingArchetype();
788 void GroupFiles (
int idxSeriesInstanceUID,
792 int idxDiffusionGradientOrientation,
793 int idxSliceLocation,
794 int idxImageOrientationPatient );
796 const char* GetNthFileName (
int idxSeriesInstanceUID,
800 int idxDiffusionGradientOrientation,
801 int idxSliceLocation,
802 int idxImageOrientationPatient,
811 static std::string GetMetaDataWithoutSpaces(
const itk::MetaDataDictionary &dict,
const std::string& tag);
814 itk::ImageIOBase::Pointer GetImageIO(
const char* filename);
826 void GetScalarRangeMetaDataKeys(itk::ImageIOBase::Pointer imageIO,
827 std::string range_keys[2]);
828 void SetMetaDataScalarRangeToPointDataInfo(vtkImageData* data);
830 double DefaultDataSpacing[3];
831 double DefaultDataOrigin[3];
862 int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
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)