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);
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);
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;
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);
263 vtkSetMacro(VoxelVectorType,
int);
264 vtkGetMacro(VoxelVectorType,
int);
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);
792 int idxDiffusionGradientOrientation,
793 int idxSliceLocation,
794 int idxImageOrientationPatient );
800 int idxDiffusionGradientOrientation,
801 int idxSliceLocation,
802 int idxImageOrientationPatient,
827 std::string range_keys[2]);
830 double DefaultDataSpacing[3];
831 double DefaultDataOrigin[3];
Read a series of files that have a common naming convention.
bool GetGroupingByTags()
set/get functions for grouping by tags
void GetScalarRangeMetaDataKeys(itk::ImageIOBase::Pointer imageIO, std::string range_keys[2])
char UseNativeCoordinateOrientation
unsigned int GetNumberOfEchoNumbers()
void SetGroupingByTagsOff()
const char * GetNthContentTime(unsigned int n)
virtual void SetOutputScalarTypeToUnsignedLong()
void SetSelectedTriggerTime(int v)
float * GetNthImageOrientationPatient(unsigned int n)
const char * GetNthFileName(int idxSeriesInstanceUID, int idxContentTime, int idxTriggerTime, int idxEchoNumbers, int idxDiffusionGradientOrientation, int idxSliceLocation, int idxImageOrientationPatient, int n)
std::vector< std::vector< float > > DiffusionGradientOrientation
virtual int CanReadFile(const char *filename)
is the given file name a NRRD file?
std::vector< std::string > TagValues
unsigned int GetNumberOfImagePositionPatient()
unsigned int AddFileName(const char *filename)
vtkMatrix4x4 * RasToIjkMatrix
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
int InsertSliceLocation(float a)
void SetGroupingByTagsOn()
virtual void SetOutputScalarTypeToFloat()
~vtkITKArchetypeImageSeriesReader() override
void SetSelectedContentTime(int v)
vtkMatrix4x4 * MeasurementFrameMatrix
std::vector< std::string > EchoNumbers
void SetMetaDataScalarRangeToPointDataInfo(vtkImageData *data)
int ExistSliceLocation(float sliceLocation)
CoordinateOrientationCode DesiredCoordinateOrientation
void SetDesiredCoordinateOrientationToAxial()
Set the orientation of the output image.
unsigned int GetNumberOfFileNames()
See how many file names were generated during ExecuteInformation.
void SetSelectedDiffusion(int v)
void SetSelectedOrientation(int v)
int ExistTriggerTime(const char *triggerTime)
void SetUseNativeOriginOn()
Use image origin from the file.
int InsertSeriesInstanceUIDs(const char *aUID)
void PrintSelf(ostream &os, vtkIndent indent) override
virtual void SetOutputScalarTypeToNative()
virtual void SetOutputScalarTypeToDouble()
int ExistImageOrientationPatient(float *directionCosine)
static vtkITKArchetypeImageSeriesReader * New()
std::vector< std::vector< float > > ImageOrientationPatient
std::vector< float > SliceLocation
unsigned int GetNumberOfDiffusionGradientOrientation()
int UseOrientationFromFile
unsigned int NumberOfComponents
std::vector< std::string > TriggerTime
virtual void SetOutputScalarTypeToInt()
void SetSelectedUID(int v)
unsigned int GetNumberOfImageOrientationPatient()
unsigned int GetNumberOfTriggerTime()
itk::MetaDataDictionary Dictionary
void SetDesiredCoordinateOrientationToNative()
int ExistImagePositionPatient(float *ipp)
void AnalyzeDicomHeaders()
static std::string GetMetaDataWithoutSpaces(const itk::MetaDataDictionary &dict, const std::string &tag)
Get MetaData from dictionary, removing all whitespaces from the string.
vtkMatrix4x4 * GetRasToIjkMatrix()
Returns an IJK to RAS transformation matrix.
int ExistSeriesInstanceUID(const char *SeriesInstanceUID)
check the existence of given discriminator
int InsertDiffusionGradientOrientation(float *a)
unsigned int IndexArchetype
void AssembleNthVolume(int n)
const char * GetNthValue(unsigned int n)
unsigned int GetNumberOfItemsInDictionary()
virtual void SetOutputScalarTypeToUnsignedChar()
void SetUseNativeOriginOff()
Use image center as origin.
int AssembleVolumeContainingArchetype()
float GetNthSliceLocation(unsigned int n)
int InsertTriggerTime(const char *aTime)
void SetDesiredCoordinateOrientationToSagittal()
virtual void SetOutputScalarTypeToUnsignedInt()
int GetSelectedEchoNumbers()
std::vector< long int > IndexEchoNumbers
std::vector< std::string > Tags
std::vector< long int > IndexImagePositionPatient
const char * GetTagValue(char *tag)
int GetSelectedContentTime()
const char * GetNthSeriesInstanceUID(unsigned int n)
methods to get N-th discriminator
std::vector< long int > IndexContentTime
unsigned int GetNumberOfContentTime()
std::vector< std::string > ContentTime
const itk::MetaDataDictionary & GetMetaDataDictionary() const
Return the MetaDataDictionary from the ITK layer.
std::vector< long int > IndexImageOrientationPatient
int InsertEchoNumbers(const char *aEcho)
const char * GetNthKey(unsigned int n)
std::vector< std::string > FileNames
std::vector< long int > IndexTriggerTime
int ExistEchoNumbers(const char *echoNumbers)
std::vector< std::string > SeriesInstanceUIDs
void GroupFiles(int idxSeriesInstanceUID, int idxContentTime, int idxTriggerTime, int idxEchoNumbers, int idxDiffusionGradientOrientation, int idxSliceLocation, int idxImageOrientationPatient)
void SetSelectedEchoNumbers(int v)
std::vector< std::vector< float > > ImagePositionPatient
const char * GetNthEchoNumbers(unsigned int n)
int GetSelectedTriggerTime()
virtual void SetOutputScalarTypeToUnsignedShort()
unsigned int GetNumberOfSliceLocation()
unsigned int GetNumberOfSeriesInstanceUIDs()
get number of certain discriminators in the directory
void SetDesiredCoordinateOrientationToCoronal()
int GetSelectedOrientation()
int ExistDiffusionGradientOrientation(float *dgo)
itk::SpatialOrientation::ValidCoordinateOrientationFlags CoordinateOrientationCode
int ExistContentTime(const char *contentTime)
vtkMatrix4x4 * GetMeasurementFrameMatrix()
Returns the Measurement frame matrix.
virtual void SetOutputScalarTypeToChar()
itk::ImageIOBase::Pointer GetImageIO(const char *filename)
Get the image IO for the specified filename.
float * GetNthImagePositionPatient(unsigned int n)
int InsertNextSliceLocation()
std::vector< std::string > AllFileNames
void SetDICOMImageIOApproachToGDCM()
int InsertImagePositionPatient(float *a)
const char * GetFileName(unsigned int n)
float * GetNthDiffusionGradientOrientation(unsigned int n)
const std::vector< std::string > & GetFileNames()
Return all the file names.
void SetSelectedSlice(int v)
std::vector< double > MetaDataScalarRangeMaxima
void SetDICOMImageIOApproachToDCMTK()
std::vector< double > MetaDataScalarRangeMinima
const char * GetNthTriggerTime(unsigned int n)
int GetSelectedDiffusion()
int InsertImageOrientationPatient(float *a)
virtual void SetOutputScalarTypeToLong()
virtual void SetOutputScalarTypeToShort()
std::vector< long int > IndexDiffusionGradientOrientation
std::vector< std::pair< double, int > > FileNameSliceKey
int InsertContentTime(const char *aTime)
std::vector< long int > IndexSeriesInstanceUIDs
index of each dicom file into the above arrays
vtkITKArchetypeImageSeriesReader()
std::vector< long int > IndexSliceLocation