Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
itkTimeSeriesDatabase.h
Go to the documentation of this file.
1 
2 #ifndef itkTimeSeriesDatabase_h
3 #define itkTimeSeriesDatabase_h
4 
5 #include <itkImage.h>
6 #include <itkArray.h>
7 #include <itkImageSource.h>
8 #include <iostream>
9 #include <fstream>
11 
12 #define TimeSeriesBlockSize 16
13 #define TimeSeriesBlockSizeP2 TimeSeriesBlockSize*TimeSeriesBlockSize
14 #define TimeSeriesBlockSizeP3 TimeSeriesBlockSize*TimeSeriesBlockSize*TimeSeriesBlockSize
15 #define TimeSeriesVolumeBlockSize TimeSeriesBlockSize*TimeSeriesBlockSize*TimeSeriesBlockSize
16 #define TimeSeriesVolumeBlockSizeP3 TimeSeriesVolumeBlockSize*TimeSeriesVolumeBlockSize*TimeSeriesVolumeBlockSize
17 
18 namespace itk
19 {
20 
28 template <class TPixel> class TimeSeriesDatabase : public ImageSource<Image<TPixel,3> > {
29 public:
30 
32  typedef ImageSource<Image<TPixel,3> > Superclass;
33  typedef SmartPointer<Self> Pointer;
34  typedef SmartPointer<const Self> ConstPointer;
35  typedef WeakPointer<const Self> ConstWeakPointer;
36 
39 
41  itkTypeMacro(TimeSeriesDatabase, ImageSource);
42 
43  typedef Image<TPixel, 3> OutputImageType;
44  typedef typename OutputImageType::Pointer OutputImageTypePointer;
45  typedef Image<TPixel, 2> OutputSliceType;
46  typedef typename OutputSliceType::Pointer OutputSliceTypePointer;
47  typedef Array<TPixel> ArrayType;
48 
54  void Connect ( const char* filename );
55 
60  void Disconnect();
61 
69  static void CreateFromFileArchetype ( const char* filename, const char* archetype );
70  static void CreateFromFileArchetype ( const char* filename, const char* archetype, unsigned long BlocksPerFile );
71 
77  itkSetMacro ( CurrentImage, unsigned int );
78  itkGetMacro ( CurrentImage, unsigned int );
79 
81  int GetNumberOfVolumes() { return this->m_Dimensions[3]; };
82  itkGetMacro ( OutputSpacing, typename OutputImageType::SpacingType );
83  itkGetMacro ( OutputRegion, typename OutputImageType::RegionType );
84  itkGetMacro ( OutputOrigin, typename OutputImageType::PointType );
85  itkGetMacro ( OutputDirection, typename OutputImageType::DirectionType );
86 
88  void GenerateOutputInformation() override;
89  void GenerateData() override;
90 
95  void GetVoxelTimeSeries ( typename OutputImageType::IndexType idx, ArrayType& array );
96 
99  void SetCacheSizeInMiB ( float sz );
102  float GetCacheSizeInMiB ();
103 
104 
105 protected:
107  ~TimeSeriesDatabase() override;
108  void PrintSelf(std::ostream& os, Indent indent) const override;
109 
110  Array<unsigned int> m_Dimensions;
111  Array<unsigned int> m_BlocksPerImage;
112 
113  typename OutputImageType::SpacingType m_OutputSpacing;
114  typename OutputImageType::RegionType m_OutputRegion;
115  typename OutputImageType::PointType m_OutputOrigin;
116  typename OutputImageType::DirectionType m_OutputDirection;
117 
119 
120  static std::streampos CalculatePosition ( unsigned long index, unsigned long BlocksPerFile );
121 
122  unsigned int CalculateFileIndex ( unsigned long Index );
123  static unsigned int CalculateFileIndex ( unsigned long Index, unsigned long BlocksPerFile );
124 
125  unsigned long CalculateIndex ( Size<3> Position, int ImageCount );
126  static unsigned long CalculateIndex ( Size<3> Position, int ImageCount, unsigned int BlocksPerImage[3] );
128  bool CalculateIntersection ( Size<3> BlockIndex, typename OutputImageType::RegionType RequestedRegion,
129  typename OutputImageType::RegionType& BlockRegion,
130  typename OutputImageType::RegionType& ImageRegion );
131  bool IsOpen() const;
132 
134  Array<unsigned int> m_PixelRemainder;
135 
136  std::string m_Filename;
137  unsigned int m_CurrentImage{0};
138 
139  std::vector<StreamPtr> m_DatabaseFiles;
140  std::vector<std::string> m_DatabaseFileNames;
141  unsigned long m_BlocksPerFile{0};
142 
144  struct CacheBlock
145  {
147  };
149  CacheBlock* GetCacheBlock ( unsigned long index );
150 };
151 
152 } // end namespace itk
153 # include "itkTimeSeriesDatabase.txx"
154 
155 #endif
SmartPointer< Self > Pointer
void GetVoxelTimeSeries(typename OutputImageType::IndexType idx, ArrayType &array)
itk::TimeSeriesDatabaseHelper::counted_ptr< std::fstream > StreamPtr
void Connect(const char *filename)
itkGetMacro(CurrentImage, unsigned int)
void PrintSelf(std::ostream &os, Indent indent) const override
Array< unsigned int > m_BlocksPerImage
std::vector< StreamPtr > m_DatabaseFiles
Image< TPixel, 2 > OutputSliceType
Array< unsigned int > m_PixelRemainder
How many pixels are in the last block?
Array< unsigned int > m_Dimensions
static void CreateFromFileArchetype(const char *filename, const char *archetype)
TimeSeriesDatabaseHelper::LRUCache< unsigned long, CacheBlock > m_Cache
TPixel data[TimeSeriesBlockSize *TimeSeriesBlockSize *TimeSeriesBlockSize]
std::vector< std::string > m_DatabaseFileNames
itkTypeMacro(TimeSeriesDatabase, ImageSource)
Simplified inverse ITK transforms.
bool CalculateIntersection(Size< 3 > BlockIndex, typename OutputImageType::RegionType RequestedRegion, typename OutputImageType::RegionType &BlockRegion, typename OutputImageType::RegionType &ImageRegion)
Return true if this is a full block, false otherwise. Assumes there is overlap!
unsigned long CalculateIndex(Size< 3 > Position, int ImageCount)
OutputImageType::Pointer OutputImageTypePointer
OutputImageType::DirectionType m_OutputDirection
void GenerateOutputInformation() override
#define TimeSeriesBlockSize
SmartPointer< const Self > ConstPointer
static std::streampos CalculatePosition(unsigned long index, unsigned long BlocksPerFile)
void SetCacheSizeInMiB(float sz)
unsigned int CalculateFileIndex(unsigned long Index)
void GenerateData() override
OutputSliceType::Pointer OutputSliceTypePointer
Image< TPixel, 3 > OutputImageType
CacheBlock * GetCacheBlock(unsigned long index)
TimeSeriesDatabase transforms a series of images stored on disk into a high performance database...
OutputImageType::SpacingType m_OutputSpacing
OutputImageType::RegionType m_OutputRegion
ImageSource< Image< TPixel, 3 > > Superclass
OutputImageType::PointType m_OutputOrigin
itkSetMacro(CurrentImage, unsigned int)
~TimeSeriesDatabase() override
WeakPointer< const Self > ConstWeakPointer