VMTK
Loading...
Searching...
No Matches
vtkvmtkITKArchetypeImageSeriesReader.h
Go to the documentation of this file.
1/*=========================================================================
2
3Copyright Brigham and Women's Hospital (BWH) All Rights Reserved.
4
5See COPYRIGHT.txt
6or http://www.slicer.org/copyright/copyright.txt for details.
7
8Program: vtkITK
9
10==========================================================================*/
11
12#ifndef __vtkvmtkITKArchetypeImageSeriesReader_h
13#define __vtkvmtkITKArchetypeImageSeriesReader_h
14
15// VTKITK includes
16#include "vtkvmtkITK.h"
17
18// VTK includes
19#include "vtkImageAlgorithm.h"
20class vtkMatrix4x4;
21
22// ITK includes
23#include "itkMetaDataDictionary.h"
24#include "itkSpatialOrientation.h"
25
26// STD includes
27#include <algorithm>
28#include <string>
29#include <vector>
30#include <cmath>
31
43class VTK_VMTK_ITK_EXPORT vtkvmtkITKArchetypeImageSeriesReader : public vtkImageAlgorithm
44{
45public:
47 vtkTypeMacro(vtkvmtkITKArchetypeImageSeriesReader,vtkImageAlgorithm);
48 void PrintSelf(std::ostream& os, vtkIndent indent) override;
49
50#if (ITK_VERSION_MAJOR >= 5)
51 typedef itk::SpatialOrientationEnums::ValidCoordinateOrientations CoordinateOrientationCode;
52#else
53 typedef itk::SpatialOrientation::ValidCoordinateOrientationFlags CoordinateOrientationCode;
54#endif
55
58 vtkSetStringMacro(Archetype);
59 vtkGetStringMacro(Archetype);
60
63 unsigned int GetNumberOfFileNames();
66 const std::vector<std::string>& GetFileNames();
67
72 unsigned int AddFileName( const char* filename );
73 const char* GetFileName( unsigned int n );
74 void ResetFileNames();
75
79 vtkSetVector3Macro(DefaultDataSpacing,double);
80 vtkGetVector3Macro(DefaultDataSpacing,double);
81
86 vtkSetVector3Macro(DefaultDataOrigin,double);
87 vtkGetVector3Macro(DefaultDataOrigin,double);
88
92 vtkSetMacro(FileNameSliceOffset,int);
93 vtkGetMacro(FileNameSliceOffset,int);
94
99 vtkSetMacro(FileNameSliceSpacing,int);
100 vtkGetMacro(FileNameSliceSpacing,int);
101
105 vtkSetMacro(FileNameSliceCount,int);
106 vtkGetMacro(FileNameSliceCount,int);
107
109 virtual int CanReadFile(const char* filename);
110
114 {
115#if (ITK_VERSION_MAJOR >= 5)
117 itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RAI;
118#else
120 itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAI;
121#endif
124 this->Modified();
125 }
127 {
128#if (ITK_VERSION_MAJOR >= 5)
130 itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RSA;
131#else
133 itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSA;
134#endif
137 this->Modified();
138 }
140 {
142#if (ITK_VERSION_MAJOR >= 5)
143 itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_ASL;
144#else
145 itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_ASL;
146#endif
149 this->Modified();
150 }
152 {
154 this->Modified();
155 }
158
164 {
166 this->SetOutputScalarType(VTK_DOUBLE);
167 }
169 {
171 this->SetOutputScalarType(VTK_FLOAT);
172 }
174 {
176 this->SetOutputScalarType(VTK_LONG);
177 }
179 {
181 this->SetOutputScalarType(VTK_UNSIGNED_LONG);
182 }
184 {
186 this->SetOutputScalarType(VTK_INT);
187 }
189 {
191 this->SetOutputScalarType(VTK_UNSIGNED_INT);
192 }
194 {
196 this->SetOutputScalarType(VTK_SHORT);
197 }
199 {
201 this->SetOutputScalarType(VTK_UNSIGNED_SHORT);
202 }
204 {
206 this->SetOutputScalarType(VTK_CHAR);
207 }
209 {
211 this->SetOutputScalarType(VTK_UNSIGNED_CHAR);
212 }
214 {
216 this->Modified();
217 }
218
222 {
223 UseNativeOrigin = true;
224 }
225
229 {
230 UseNativeOrigin = false;
231 }
232
235 vtkSetMacro(OutputScalarType, int);
236 vtkGetMacro(OutputScalarType, int);
237
240 vtkSetMacro(NumberOfComponents, unsigned int);
241 vtkGetMacro(NumberOfComponents, unsigned int);
242
245 vtkSetMacro(SingleFile, int);
246 vtkGetMacro(SingleFile, int);
247
250 vtkSetMacro(UseOrientationFromFile, int);
251 vtkGetMacro(UseOrientationFromFile, int);
252
255 vtkMatrix4x4* GetRasToIjkMatrix();
256
259 vtkMatrix4x4* GetMeasurementFrameMatrix();
260
263 const itk::MetaDataDictionary &GetMetaDataDictionary() const;
264 std::vector<std::string> Tags;
265 std::vector<std::string> TagValues;
266 void ParseDictionary();
267
268 unsigned int GetNumberOfItemsInDictionary();
269 bool HasKey( char* tag );
270 const char* GetNthKey( unsigned int n );
271 const char* GetNthValue( unsigned int n );
272 const char* GetTagValue( char* tag );
273
276 {
277 return GroupingByTags;
278 }
279
281 {
282 GroupingByTags = true;
283 }
284
286 {
287 GroupingByTags = false;
288 }
289
292 {
293 return SelectedUID;
294 }
295
296 void SetSelectedUID( int v )
297 {
298 SelectedUID = v;
300 }
301
304 {
305 return SelectedContentTime;
306 }
307
309 {
312 }
313
316 {
317 return SelectedTriggerTime;
318 }
319
321 {
324 }
325
328 {
329 return SelectedEchoNumbers;
330 }
331
333 {
336 }
337
338
341 {
342 return SelectedDiffusion;
343 }
344
346 {
349 }
350
353 {
354 return SelectedSlice;
355 }
356
357 void SetSelectedSlice( int v )
358 {
359 SelectedSlice = v;
361 }
362
365 {
366 return SelectedOrientation;
367 }
368
370 {
373 }
374
377 {
378 return this->SeriesInstanceUIDs.size();
379 }
380
382 {
383 return this->ContentTime.size();
384 }
385
387 {
388 return this->TriggerTime.size();
389 }
390
392 {
393 return this->EchoNumbers.size();
394 }
395
397 {
398 return this->SliceLocation.size();
399 }
400
402 {
403 return this->DiffusionGradientOrientation.size();
404 };
405
407 {
408 return this->ImageOrientationPatient.size();
409 };
410
412 {
413 return this->ImagePositionPatient.size();
414 }
415
417 int ExistSeriesInstanceUID( const char* SeriesInstanceUID )
418 {
419 for (unsigned int k = 0; k < GetNumberOfSeriesInstanceUIDs(); k++)
420 {
421 if ( this->SeriesInstanceUIDs[k].find(SeriesInstanceUID) != std::string::npos )
422 {
423 return k;
424 }
425 }
426 return -1;
427 }
428
429 int ExistContentTime( const char* contentTime )
430 {
431 for (unsigned int k = 0; k < GetNumberOfContentTime(); k++)
432 {
433 if ( this->ContentTime[k].find(contentTime) != std::string::npos )
434 {
435 return k;
436 }
437 }
438 return -1;
439 }
440
441 int ExistTriggerTime( const char* triggerTime )
442 {
443 for (unsigned int k = 0; k < GetNumberOfTriggerTime(); k++)
444 {
445 if ( this->TriggerTime[k].find(triggerTime) != std::string::npos )
446 {
447 return k;
448 }
449 }
450 return -1;
451 }
452
453 int ExistEchoNumbers( const char* echoNumbers )
454 {
455 for (unsigned int k = 0; k < GetNumberOfEchoNumbers(); k++)
456 {
457 if ( this->EchoNumbers[k].find(echoNumbers) != std::string::npos )
458 {
459 return k;
460 }
461 }
462 return -1;
463 }
464
466 {
467 float a = 0;
468 for (int n = 0; n < 3; n++)
469 {
470 a += dgo[n]*dgo[n];
471 }
472
473 for (unsigned int k = 0; k < GetNumberOfDiffusionGradientOrientation(); k++)
474 {
475 float b = 0;
476 float c = 0;
477 for (int n = 0; n < 3; n++)
478 {
479 b += this->DiffusionGradientOrientation[k][n] * this->DiffusionGradientOrientation[k][n];
480 c += this->DiffusionGradientOrientation[k][n] * dgo[n];
481 }
482 c = std::fabs(c)/std::sqrt(a*b);
483
484 if ( c > 0.99999 )
485 {
486 return k;
487 }
488 }
489 return -1;
490 }
491
492 int ExistSliceLocation( float sliceLocation )
493 {
494 std::vector<float>::iterator iter =
495 std::find(this->SliceLocation.begin(), this->SliceLocation.end(), sliceLocation);
496 return iter != this->SliceLocation.end() ?
497 std::distance(this->SliceLocation.begin(), iter) : -1;
498 }
499
500 int ExistImageOrientationPatient( float * directionCosine )
501 {
503 float a = std::sqrt( directionCosine[0]*directionCosine[0] + directionCosine[1]*directionCosine[1] + directionCosine[2]*directionCosine[2] );
504 for (int k = 0; k < 3; k++)
505 {
506 directionCosine[k] /= a;
507 }
508 a = std::sqrt( directionCosine[3]*directionCosine[3] + directionCosine[4]*directionCosine[4] + directionCosine[5]*directionCosine[5] );
509 for (int k = 3; k < 6; k++)
510 {
511 directionCosine[k] /= a;
512 }
513
514 for (unsigned int k = 0; k < GetNumberOfImageOrientationPatient(); k++)
515 {
516 std::vector<float> aVec = ImageOrientationPatient[k];
517 a = std::sqrt( aVec[0]*aVec[0] + aVec[1]*aVec[1] + aVec[2]*aVec[2] );
518 float b = (directionCosine[0]*aVec[0] + directionCosine[1]*aVec[1] + directionCosine[2]*aVec[2])/a;
519 if ( b < 0.99999 )
520 {
521 continue;
522 }
523
524 a = std::sqrt( aVec[3]*aVec[3] + aVec[4]*aVec[4] + aVec[5]*aVec[5] );
525 b = (directionCosine[3]*aVec[3] + directionCosine[4]*aVec[4] + directionCosine[5]*aVec[5])/a;
526 if ( b > 0.99999 )
527 {
528 return k;
529 }
530 }
531 return -1;
532 }
533
535 {
536 float a = 0;
537 for (int n = 0; n < 3; n++)
538 {
539 a += ipp[n]*ipp[n];
540 }
541
542 for (unsigned int k = 0; k < GetNumberOfImagePositionPatient(); k++)
543 {
544 float b = 0;
545 float c = 0;
546 for (int n = 0; n < 3; n++)
547 {
548 b += this->ImagePositionPatient[k][n] * this->ImagePositionPatient[k][n];
549 c += this->ImagePositionPatient[k][n] * ipp[n];
550 }
551 c = std::fabs(c)/std::sqrt(a*b);
552 if ( c > 0.99999 )
553 {
554 return k;
555 }
556 }
557 return -1;
558 }
559
561 const char* GetNthSeriesInstanceUID( unsigned int n )
562 {
563 if ( n >= this->GetNumberOfSeriesInstanceUIDs() )
564 {
565 return NULL;
566 }
567 return this->SeriesInstanceUIDs[n].c_str();
568 }
569
570 const char* GetNthContentTime( unsigned int n )
571 {
572 if ( n >= this->GetNumberOfContentTime() )
573 {
574 return NULL;
575 }
576 return this->ContentTime[n].c_str();
577 }
578
579 const char* GetNthTriggerTime( unsigned int n )
580 {
581 if ( n >= this->GetNumberOfTriggerTime() )
582 {
583 return NULL;
584 }
585 return this->TriggerTime[n].c_str();
586 }
587
588 const char* GetNthEchoNumbers( unsigned int n )
589 {
590 if ( n >= this->GetNumberOfEchoNumbers() )
591 {
592 return NULL;
593 }
594 return this->EchoNumbers[n].c_str();
595 }
596
597 float* GetNthDiffusionGradientOrientation( unsigned int n )
598 {
600 {
601 return NULL;
602 }
603 float *dgo = new float [3];
604 for (int k = 0; k <3; k++)
605 {
606 dgo[k] = this->DiffusionGradientOrientation[n][k];
607 }
608 return dgo;
609 }
610
611 float GetNthSliceLocation( unsigned int n )
612 {
613 if ( n >= this->GetNumberOfSliceLocation() )
614 {
615 return this->SliceLocation[0];
616 }
617 return this->SliceLocation[0];
618 }
619
620 float* GetNthImageOrientationPatient( unsigned int n )
621 {
622 if ( n >= this->GetNumberOfImageOrientationPatient() )
623 {
624 return NULL;
625 }
626 float *dgo = new float [6];
627 for (int k = 0; k <6; k++)
628 {
629 dgo[k] = this->ImageOrientationPatient[n][k];
630 }
631 return dgo;
632 }
633
634 float* GetNthImagePositionPatient( unsigned int n )
635 {
636 if (n >= this->GetNumberOfImagePositionPatient() )
637 {
638 return NULL;
639 }
640 float *ipp = new float [3];
641 for (int k = 0; k <3; k++)
642 {
643 ipp[k] = this->ImagePositionPatient[n][k];
644 }
645 return ipp;
646 }
647
650 int InsertSeriesInstanceUIDs ( const char * aUID )
651 {
652 int k = ExistSeriesInstanceUID( aUID );
653 if ( k >= 0 )
654 {
655 return k;
656 }
657
658 std::string aVector(aUID);
659 this->SeriesInstanceUIDs.push_back( aVector );
660 return (this->SeriesInstanceUIDs.size()-1);
661 }
662
663 int InsertContentTime ( const char * aTime )
664 {
665 int k = ExistContentTime( aTime );
666 if ( k >= 0 )
667 {
668 return k;
669 }
670
671 std::string aVector(aTime);
672 this->ContentTime.push_back( aVector );
673 return (this->ContentTime.size()-1);
674 }
675
676 int InsertTriggerTime ( const char * aTime )
677 {
678 int k = ExistTriggerTime( aTime );
679 if ( k >= 0 )
680 {
681 return k;
682 }
683
684 std::string aVector(aTime);
685 this->TriggerTime.push_back( aVector );
686 return (this->TriggerTime.size()-1);
687 }
688
689 int InsertEchoNumbers ( const char * aEcho )
690 {
691 int k = ExistEchoNumbers( aEcho );
692 if ( k >= 0 )
693 {
694 return k;
695 }
696
697 std::string aVector(aEcho);
698 this->EchoNumbers.push_back( aVector );
699 return (this->EchoNumbers.size()-1);
700 }
701
703 {
705 if ( k >= 0 )
706 {
707 return k;
708 }
709 std::vector< float > aVector(3);
710 float aMag = std::sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
711 for (k = 0; k < 3; k++)
712 {
713 aVector[k] = a[k]/aMag;
714 }
715
716 this->DiffusionGradientOrientation.push_back( aVector );
717 return (this->DiffusionGradientOrientation.size()-1);
718 }
719
723 int InsertSliceLocation ( float a )
724 {
725 int k = ExistSliceLocation( a );
726 if ( k >= 0 )
727 {
728 return k;
729 }
730
731 this->SliceLocation.push_back( a );
732 return (this->SliceLocation.size()-1);
733 }
734
737 {
738 int size = this->SliceLocation.size();
739 this->SliceLocation.push_back(
740 size > 0 ? this->SliceLocation.back() + 1 : 0.f);
741 return size;
742 }
743
745 {
746 int k = ExistImageOrientationPatient( a );
747 if ( k >= 0 )
748 {
749 return k;
750 }
751 std::vector< float > aVector(6);
752 float aMag = std::sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
753 float bMag = std::sqrt(a[3]*a[3]+a[4]*a[4]+a[5]*a[5]);
754 for (k = 0; k < 3; k++)
755 {
756 aVector[k] = a[k]/aMag;
757 aVector[k+3] = a[k+3]/bMag;
758 }
759
760 this->ImageOrientationPatient.push_back( aVector );
761 return (this->ImageOrientationPatient.size()-1);
762 }
763
765 {
766 int k = ExistImagePositionPatient( a );
767 if ( k >= 0 )
768 {
769 return k;
770 }
771
772 std::vector< float > aVector(3);
773 for ( unsigned int i = 0; i < 3; i++ ) aVector[i] = a[i];
774 this->ImagePositionPatient.push_back( aVector );
775 return (this->ImagePositionPatient.size()-1);
776 }
777
778 void AnalyzeDicomHeaders( );
779
780 void AssembleNthVolume( int n );
781 int AssembleVolumeContainingArchetype();
782
783 void GroupFiles ( int idxSeriesInstanceUID,
784 int idxContentTime,
785 int idxTriggerTime,
786 int idxEchoNumbers,
787 int idxDiffusionGradientOrientation,
788 int idxSliceLocation,
789 int idxImageOrientationPatient );
790
791 const char* GetNthFileName ( int idxSeriesInstanceUID,
792 int idxContentTime,
793 int idxTriggerTime,
794 int idxEchoNumbers,
795 int idxDiffusionGradientOrientation,
796 int idxSliceLocation,
797 int idxImageOrientationPatient,
798 int n );
799
800
801protected:
804
809
811 unsigned int NumberOfComponents;
812
815 float ScanAxis[3];
816 float ScanOrigin[3];
817
821
822 vtkMatrix4x4* RasToIjkMatrix;
824
828
837
838 unsigned int IndexArchetype;
839
840 std::vector<std::string> FileNames;
841 std::vector<std::pair <double, int> > FileNameSliceKey;
843 virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
844
845 itk::MetaDataDictionary Dictionary;
846
860
861 std::vector<std::string> AllFileNames;
864
865 std::vector<std::string> SeriesInstanceUIDs;
866 std::vector<std::string> ContentTime;
867 std::vector<std::string> TriggerTime;
868 std::vector<std::string> EchoNumbers;
869 std::vector< std::vector<float> > DiffusionGradientOrientation;
870 std::vector<float> SliceLocation;
871 std::vector< std::vector<float> > ImageOrientationPatient;
872 std::vector< std::vector<float> > ImagePositionPatient;
873
875 std::vector<long int> IndexSeriesInstanceUIDs;
876 std::vector<long int> IndexContentTime;
877 std::vector<long int> IndexTriggerTime;
878 std::vector<long int> IndexEchoNumbers;
880 std::vector<long int> IndexSliceLocation;
881 std::vector<long int> IndexImageOrientationPatient;
882 std::vector<long int> IndexImagePositionPatient;
883
884private:
886 void operator=(const vtkvmtkITKArchetypeImageSeriesReader&);
887};
888
889#endif
Read a series of files that have a common naming convention.
itk::SpatialOrientation::ValidCoordinateOrientationFlags CoordinateOrientationCode
virtual void SetOutputScalarType(int)
Get the file format. Pixels are this type in the file.
void PrintSelf(std::ostream &os, vtkIndent indent) override
std::vector< std::pair< double, int > > FileNameSliceKey
const itk::MetaDataDictionary & GetMetaDataDictionary() const
Return the MetaDataDictionary from the ITK layer.
const char * GetNthSeriesInstanceUID(unsigned int n)
methods to get N-th discriminator
std::vector< std::vector< float > > ImagePositionPatient
static vtkvmtkITKArchetypeImageSeriesReader * New()
virtual int CanReadFile(const char *filename)
is the given file name a NRRD file?
void SetDesiredCoordinateOrientationToAxial()
Set the orientation of the output image.
unsigned int GetNumberOfFileNames()
See how many file names were generated during ExecuteInformation.
vtkMatrix4x4 * GetRasToIjkMatrix()
Returns an IJK to RAS transformation matrix.
std::vector< std::vector< float > > DiffusionGradientOrientation
vtkMatrix4x4 * GetMeasurementFrameMatrix()
Returns the Measurement frame matrix.
bool GetGroupingByTags()
set/get functions for grouping by tags
virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
int ExistSeriesInstanceUID(const char *SeriesInstanceUID)
check the existance of given discriminator
std::vector< long int > IndexSeriesInstanceUIDs
index of each dicom file into the above arrays
void SetUseNativeOriginOn()
Use image origin from the file.
unsigned int GetNumberOfSeriesInstanceUIDs()
get number of certain discriminators in the directory
const std::vector< std::string > & GetFileNames()
Return all the file names.
std::vector< std::vector< float > > ImageOrientationPatient
Common include pulling in the Utilities/vtkvmtkITK module's Windows export-macro header; included by ...