Slicer  4.8
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 
38  itkNewMacro(Self);
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  virtual void GenerateOutputInformation(void) ITK_OVERRIDE;
89  virtual void GenerateData(void) ITK_OVERRIDE;
90 
95  void GetVoxelTimeSeries ( typename OutputImageType::IndexType idx, ArrayType& array );
96 
99  void SetCacheSizeInMiB ( float sz );
102  float GetCacheSizeInMiB ();
103 
104 
105 protected:
108  virtual void PrintSelf(std::ostream& os, Indent indent) const ITK_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;
138 
139  std::vector<StreamPtr> m_DatabaseFiles;
140  std::vector<std::string> m_DatabaseFileNames;
141  unsigned long m_BlocksPerFile;
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)
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
#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)
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_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)
virtual void GenerateOutputInformation(void) ITK_OVERRIDE
virtual void GenerateData(void) ITK_OVERRIDE
WeakPointer< const Self > ConstWeakPointer