20 #ifndef MIRTK_HashImage_H 21 #define MIRTK_HashImage_H 23 #include "mirtk/BaseImage.h" 24 #include "mirtk/VoxelCast.h" 25 #include "mirtk/UnorderedMap.h" 38 template <
class TVoxel>
53 typedef typename voxel_info<VoxelType>::RealType
RealType;
56 typedef UnorderedMap<int, VoxelType>
DataMap;
62 typedef typename voxel_info<VoxelType>::ScalarType
ScalarType;
95 explicit HashImage(
int,
int,
int = 1,
int = 1);
98 explicit HashImage(
int,
int,
int,
int,
int);
110 template <
class TVoxel2>
114 template <
class TVoxel2>
142 template <
class TVoxel2>
146 template <
class TVoxel2>
150 template <
class TVoxel2>
160 template <
class TVoxel2>
167 template <
class TVoxel2>
186 DataIterator Begin()
const;
187 DataIterator End()
const;
189 int NumberOfNonDefaultVoxels()
const;
192 VoxelType
Get(
int)
const;
195 VoxelType
Get(
int,
int,
int = 0,
int = 0)
const;
198 void Put(
int, VoxelType);
201 void Put(
int,
int, VoxelType);
204 void Put(
int,
int,
int, VoxelType);
207 void Put(
int,
int,
int,
int, VoxelType);
215 virtual double GetAsDouble(
int,
int,
int = 0,
int = 0)
const;
227 virtual void PutAsDouble(
int,
int,
int,
int,
double);
266 virtual const void *
GetDataPointer(
int,
int,
int = 0,
int = 0)
const;
294 int,
int,
int)
const;
298 int,
int,
int)
const;
302 int,
int,
int)
const;
306 int,
int,
int,
int)
const;
310 int,
int,
int,
int)
const;
314 int,
int,
int,
int)
const;
335 template <
class TVoxel2>
367 void GetMinMax(VoxelType &, VoxelType &)
const;
370 void GetMinMax(VoxelType &, VoxelType &, VoxelType)
const;
378 virtual void ReflectX(
bool modify_axes =
false);
379 virtual void ReflectY(
bool modify_axes =
false);
380 virtual void ReflectZ(
bool modify_axes =
false);
381 virtual void ReflectT(
bool modify_axes =
false);
383 virtual void FlipXY(
bool modify_origin =
false);
384 virtual void FlipXZ(
bool modify_origin =
false);
385 virtual void FlipYZ(
bool modify_origin =
false);
386 virtual void FlipXT(
bool modify_origin =
false);
387 virtual void FlipYT(
bool modify_origin =
false);
388 virtual void FlipZT(
bool modify_origin =
false);
390 virtual void SwapXY(
bool modify_axes =
true);
391 virtual void SwapXZ(
bool modify_axes =
true);
392 virtual void SwapYZ(
bool modify_axes =
true);
393 virtual void SwapXT(
bool modify_axes =
true);
394 virtual void SwapYT(
bool modify_axes =
true);
395 virtual void SwapZT(
bool modify_axes =
true);
401 #if defined(HAVE_VTK) && MIRTK_Image_WITH_VTK 406 virtual void ImageToVTK(vtkStructuredPoints *)
const;
411 virtual void VTKToImage(vtkStructuredPoints *);
413 #endif // MIRTK_Image_WITH_VTK 419 virtual void Read(
const char *);
422 virtual void Write(
const char *)
const;
429 template <
class TVoxel2>
437 void GetMinMax(VoxelType *, VoxelType *)
const;
441 void GetMinMax(VoxelType *, VoxelType *, VoxelType)
const;
445 void GetMinMaxPad(VoxelType *, VoxelType *, VoxelType)
const;
464 template <
class VoxelType>
467 return voxel_info<VoxelType>::vector_size();
471 template <
class VoxelType>
482 template <
class VoxelType>
486 if(val==_DefaultValue){
495 template <
class VoxelType>
502 template <
class VoxelType>
509 template <
class VoxelType>
516 template <
class VoxelType>
519 cerr <<
"HashImage::Access: Not implemented" << endl;
525 template <
class VoxelType>
528 return _Data.begin();
533 template <
class VoxelType>
541 template <
class VoxelType>
549 template <
class VoxelType>
552 auto pos=_Data.find (index);
553 if ( pos == End() )
return _DefaultValue;
554 return voxel_cast<
VoxelType>(pos->second);
558 template <
class VoxelType>
569 template <
class VoxelType>
572 Put(index, voxel_cast<VoxelType>(val));
576 template <
class VoxelType>
583 template <
class VoxelType>
590 template <
class VoxelType>
597 template <
class VoxelType>
600 return voxel_cast<
double>(
Get(index));
604 template <
class VoxelType>
611 template <
class VoxelType>
614 Put(index, voxel_cast<VoxelType>(value));
618 template <
class VoxelType>
625 template <
class VoxelType>
632 template <
class VoxelType>
639 template <
class VoxelType>
646 template <
class VoxelType>
653 template <
class VoxelType>
660 template <
class VoxelType>
673 template <
class VoxelType>
676 cerr <<
"HashImage<VoxelType>::GetDataPointer: Not implemented" << endl;
681 template <
class VoxelType>
684 cerr <<
"HashImage<VoxelType>::GetDataPointer: Not implemented" << endl;
689 template <
class VoxelType>
692 cerr <<
"HashImage<VoxelType>::GetDataPointer: Not implemented" << endl;
697 template <
class VoxelType>
700 cerr <<
"HashImage<VoxelType>::GetDataPointer: Not implemented" << endl;
705 template <
class VoxelType>
708 return voxel_info<VoxelType>::type();
712 template <
class VoxelType>
715 return static_cast<int>(
sizeof(
VoxelType));
719 template <
class VoxelType>
722 return voxel_limits<VoxelType>::min();
726 template <
class VoxelType>
729 return voxel_limits<VoxelType>::max();
737 template <
class VoxelType>
744 template <
class VoxelType>
751 template <
class VoxelType>
766 #include "mirtk/HashImage.hxx" 768 #endif // MIRTK_HashImage_H virtual int GetDataTypeSize() const
Get size of each voxel in bytes.
HashImage & operator/=(ScalarType)
Divide by scalar.
virtual void * GetDataPointer(int=0)
Get raw pointer to contiguous image data.
int VoxelToIndex(int, int, int=0, int=0) const
virtual void ReflectZ(bool modify_axes=false)
Reflect image along z.
void PutBackgroundValueAsDouble(double)
Put background value.
virtual void SwapYT(bool modify_axes=true)
Swap y and t axis.
void CopyFrom(const BaseImage &)
Copy image data from other image of same size.
virtual double GetAsDouble(int) const
Function for pixel get access as double.
void Put(int, VoxelType)
Function for pixel put access.
voxel_info< VoxelType >::ScalarType ScalarType
Scalar type corresponding to voxel type.
virtual void FlipYT(bool modify_origin=false)
Flip y and t axis, always also swaps voxel size.
HashImage operator+(const HashImage &) const
Add images.
HashImage operator*(const HashImage &) const
Multiply images voxel-wise.
virtual int GetDataType() const
Get enumeration value corresponding to voxel type.
void PutMinMax(VoxelType, VoxelType)
Linearly rescale intensities.
virtual void FlipZT(bool modify_origin=false)
Flip z and t axis, always also swaps voxel size.
int _y
Image y-dimension (in voxels)
void Clear()
Clear an image.
HashImage GetFrame(int, int=-1) const
Get time instance (i.e., frame) or channel of image.
virtual void ReflectX(bool modify_axes=false)
Reflect image along x.
voxel_info< VoxelType >::RealType RealType
HashImage & operator*=(ScalarType)
Multiply by scalar.
virtual void SwapYZ(bool modify_axes=true)
Swap y and z axis.
virtual void FlipXY(bool modify_origin=false)
Flip x and y axis, always also swaps voxel size.
virtual void SwapXT(bool modify_axes=true)
Swap x and t axis.
HashImage operator/(const HashImage &) const
Divide images voxel-wise.
ImageAttributes _attr
Image attributes.
HashImage()
Default constructor.
void AllocateImage()
Allocate image memory.
VoxelType Get(int) const
Function for pixel get access.
void GetMinMax(VoxelType &, VoxelType &) const
Minimum and maximum pixel values get accessor.
void GetMinMaxPad(VoxelType *, VoxelType *, VoxelType) const
virtual double GetDataTypeMin() const
Minimum value a pixel can hold without overflowing.
virtual void SwapXZ(bool modify_axes=true)
Swap x and z axis.
UnorderedMap< int, VoxelType > DataMap
Data map (hashmap)
virtual void FlipXT(bool modify_origin=false)
Flip x and t axis, always also swaps voxel size.
int _z
Image z-dimension (in voxels)
HashImage & operator-=(ScalarType)
Subtract scalar.
virtual void PutAsDouble(int, double)
Function for pixel put access.
virtual void Read(const char *)
Read image from file.
virtual void ReflectY(bool modify_axes=false)
Reflect image along y.
int N() const
Number of vector components per voxel.
virtual double GetDataTypeMax() const
Maximum value a pixel can hold without overflowing.
virtual void FlipXZ(bool modify_origin=false)
Flip x and z axis, always also swaps voxel size.
HashImage GetRegion(int, int) const
Get image consisting of specified 2D slice.
virtual void FlipYZ(bool modify_origin=false)
Flip y and z axis, always also swaps voxel size.
bool operator==(const HashImage< TVoxel2 > &) const
mirtkPublicAttributeMacro(DataMap, Data)
DataMap::const_iterator DataIterator
Data map iterator.
HashImage & operator+=(ScalarType)
Add scalar.
VoxelType Access(int)
Function for not const pixel get access.
void CopyTo(GenericImage< TVoxel2 > &) const
Copy image data to GenericImage.
virtual void ReflectT(bool modify_axes=false)
Reflect image along t.
virtual void PutBackgroundValueAsDouble(double, bool)
Put background value.
virtual void PutAsVector(int, const Vector &)
Function for pixel put access.
virtual void Initialize()
Initialize a previously allocated image.
virtual void SwapZT(bool modify_axes=true)
Swap z and t axis.
HashImage & operator=(VoxelType)
Assign constant value to each voxel.
virtual void SwapXY(bool modify_axes=true)
Swap x and y axis.
int _x
Image x-dimension (in voxels)
HashImage operator-(const HashImage &) const
Subtract images.
TVoxel VoxelType
Voxel type.
virtual void Write(const char *) const
Write image to file.
virtual void GetAsVector(Vector &, int) const
Function for pixel get access as double.
virtual BaseImage * Copy() const
Create copy of this image.