20 #ifndef MIRTK_ImageRegion_H 21 #define MIRTK_ImageRegion_H 23 #include "mirtk/Voxel.h" 24 #include "mirtk/Parallel.h" 25 #include "mirtk/Vector4D.h" 26 #include "mirtk/GenericImage.h" 27 #include "mirtk/Stream.h" 39 #define _NextPrevMethod(name, stride) \ 41 inline const T *Next##name(const T *&p) const { return p + stride; } \ 43 inline T *Next##name(T *&p) const { return p + stride; } \ 45 inline const T *Prev##name(const T *&p) const { return p - stride; } \ 47 inline T *Prev##name(T *&p) const { return p - stride; } 51 #define _ToMethod1(name, op, stride) \ 53 inline void To##name(const T *&p) const { p = p op stride; } \ 55 inline void To##name(T *&p) const { p = p op stride; } 59 #define _ToMethod2(name, op, stride) \ 60 template <class T1, class T2> \ 61 inline void To##name(const T1 *&p1, const T2 *&p2) const \ 62 { p1 = p1 op stride; p2 = p2 op stride; } \ 63 template <class T1, class T2> \ 64 inline void To##name(const T1 *&p1, T2 *&p2) const \ 65 { p1 = p1 op stride; p2 = p2 op stride; } \ 66 template <class T1, class T2> \ 67 inline void To##name(T1 *&p1, const T2 *&p2) const \ 68 { p1 = p1 op stride; p2 = p2 op stride; } \ 69 template <class T1, class T2> \ 70 inline void To##name(T1 *&p1, T2 *&p2) const \ 71 { p1 = p1 op stride; p2 = p2 op stride; } 75 #define _ToMethod3(name, op, stride) \ 76 template <class T1, class T2, class T3> \ 77 inline void To##name(const T1 *&p1, const T2 *&p2, const T3 *&p3) const \ 78 { p1 = p1 op stride; p2 = p2 op stride; p3 = p3 op stride; } \ 79 template <class T1, class T2, class T3> \ 80 inline void To##name(const T1 *&p1, const T2 *&p2, T3 *&p3) const \ 81 { p1 = p1 op stride; p2 = p2 op stride; p3 = p3 op stride; } \ 82 template <class T1, class T2, class T3> \ 83 inline void To##name(const T1 *&p1, T2 *&p2, const T3 *&p3) const \ 84 { p1 = p1 op stride; p2 = p2 op stride; p3 = p3 op stride; } \ 85 template <class T1, class T2, class T3> \ 86 inline void To##name(const T1 *&p1, T2 *&p2, T3 *&p3) const \ 87 { p1 = p1 op stride; p2 = p2 op stride; p3 = p3 op stride; } \ 88 template <class T1, class T2, class T3> \ 89 inline void To##name(T1 *&p1, const T2 *&p2, const T3 *&p3) const \ 90 { p1 = p1 op stride; p2 = p2 op stride; p3 = p3 op stride; } \ 91 template <class T1, class T2, class T3> \ 92 inline void To##name(T1 *&p1, const T2 *&p2, T3 *&p3) const \ 93 { p1 = p1 op stride; p2 = p2 op stride; p3 = p3 op stride; } \ 94 template <class T1, class T2, class T3> \ 95 inline void To##name(T1 *&p1, T2 *&p2, const T3 *&p3) const \ 96 { p1 = p1 op stride; p2 = p2 op stride; p3 = p3 op stride; } \ 97 template <class T1, class T2, class T3> \ 98 inline void To##name(T1 *&p1, T2 *&p2, T3 *&p3) const \ 99 { p1 = p1 op stride; p2 = p2 op stride; p3 = p3 op stride; } 103 #define _ToMethod(name, stride) \ 104 _ToMethod1(Next##name, +, stride) \ 105 _ToMethod2(Next##name, +, stride) \ 106 _ToMethod3(Next##name, +, stride) \ 107 _ToMethod1(Prev##name, -, stride) \ 108 _ToMethod2(Prev##name, -, stride) \ 109 _ToMethod3(Prev##name, -, stride) \ 309 void SetStart(
int,
int,
int = 0,
int = -1);
315 void SetSize(
int,
int,
int = 1,
int = 1);
318 void SetCenter(
int,
int,
int = 0,
int = -1);
324 void SetRadius(
int,
int,
int = 0,
int = 0);
333 void SetRegion(
int,
int,
int,
int,
int,
int);
339 void SetRegion(
int,
int,
int,
int,
int,
int,
int,
int);
423 template <
class VoxelType>
427 template <
class VoxelType>
431 template <
class VoxelType>
435 template <
class VoxelType>
439 template <
class VoxelType>
443 template <
class VoxelType>
447 template <
class VoxelType>
451 template <
class VoxelType>
455 template <
class VoxelType>
459 template <
class VoxelType>
463 template <
class VoxelType>
467 template <
class VoxelType>
474 _NextPrevMethod(Column, 1)
726 SetRegion(r.cols().begin(), r.rows().begin(), r.cols().end(), r.rows().end());
758 SetRegion(r.cols().begin(), r.rows().begin(), r.pages().begin(),
759 r.cols().end(), r.rows().end(), r.pages().end());
767 cerr <<
"ImageRegion::SetChannel: Index out of bounds" << endl;
773 cerr <<
"ImageRegion::SetChannel: Index out of bounds (an image sequence can only have one channel)" << endl;
783 cerr <<
"ImageRegion::SetChannel: Index out of bounds" << endl;
789 }
else if (bl != 0 || el != 0) {
790 cerr <<
"ImageRegion::SetChannel: Index out of bounds (an image sequence can only have one channel)" << endl;
806 cerr <<
"ImageRegion::SetComponent: Index out of bounds" << endl;
812 cerr <<
"ImageRegion::SetComponent: Index out of bounds (an image sequence can only have one component)" << endl;
822 cerr <<
"ImageRegion::SetComponent: Index out of bounds" << endl;
828 }
else if (bl != 0 || el != 0) {
829 cerr <<
"ImageRegion::SetComponent: Index out of bounds (an image sequence can only have one component)" << endl;
845 cerr <<
"ImageRegion::SetFrame: Index out of bounds" << endl;
851 cerr <<
"ImageRegion::SetFrame: Index out of bounds (image seems to have multiple channels/vector components instead)" << endl;
861 cerr <<
"ImageRegion::SetFrame: Index out of bounds" << endl;
867 }
else if (bl != 0 || el != 0) {
868 cerr <<
"ImageRegion::SetFrame: Index out of bounds (image seems to have multiple channels/vector components instead)" << endl;
886 _DataSize (attr._x, attr._y, attr._z, attr._t),
889 _Size (attr._x, attr._y, attr._z, attr._t)
897 _DataSize (attr._x, attr._y, attr._z, attr._t),
900 _Size (region.cols ().end() - region.cols ().begin(),
901 region.rows ().end() - region.rows ().begin(), 1, 1)
909 _DataSize (attr._x, attr._y, attr._z, attr._t),
912 _Size (region.cols ().end() - region.cols ().begin(),
913 region.rows ().end() - region.rows ().begin(),
914 region.pages().end() - region.pages().begin(), 1)
922 _DataSize (image.X(), image.Y(), image.Z(), image.T()),
925 _Size (image.X(), image.Y(), image.GetZ(), image.T())
933 _DataSize (image.X(), image.Y(), image.Z(), image.T()),
936 _Size (region.cols ().end() - region.cols ().begin(),
937 region.rows ().end() - region.rows ().begin(), 1, 1)
945 _DataSize (image.X(), image.Y(), image.Z(), image.T()),
948 _Size (region.cols ().end() - region.cols ().begin(),
949 region.rows ().end() - region.rows ().begin(),
950 region.pages().end() - region.pages().begin(), 1)
958 _DataSize (image->X(), image->Y(), image->Z(), image->T()),
961 _Size (image->X(), image->Y(), image->Z(), image->T())
969 _DataSize (image->X(), image->Y(), image->Z(), image->T()),
972 _Size (region.cols ().end() - region.cols ().begin(),
973 region.rows ().end() - region.rows ().begin(), 1, 1)
981 _DataSize (image->X(), image->Y(), image->Z(), image->T()),
984 _Size (region.cols ().end() - region.cols ().begin(),
985 region.rows ().end() - region.rows ().begin(),
986 region.pages().end() - region.pages().begin(), 1)
1031 template <
class VoxelType>
1034 if (image.
GetScalarType() != voxel_info<VoxelType>::type()) {
1035 cerr <<
"ImageRegion::GetPointerToBegin: Type of image differs from VoxelType template argument" << endl;
1043 template <
class VoxelType>
1046 if (image->
GetScalarType() != voxel_info<VoxelType>::type()) {
1047 cerr <<
"ImageRegion::GetPointerToBegin: Type of image differs from VoxelType template argument" << endl;
1055 template <
class VoxelType>
1063 template <
class VoxelType>
1071 template <
class VoxelType>
1079 template <
class VoxelType>
1087 template <
class VoxelType>
1090 if (image.
GetScalarType() != voxel_info<VoxelType>::type()) {
1091 cerr <<
"ImageRegion::GetPointerToEnd: Type of image differs from VoxelType template argument" << endl;
1099 template <
class VoxelType>
1102 if (image->
GetScalarType() != voxel_info<VoxelType>::type()) {
1103 cerr <<
"ImageRegion::GetPointerToEnd: Type of image differs from VoxelType template argument" << endl;
1111 template <
class VoxelType>
1119 template <
class VoxelType>
1127 template <
class VoxelType>
1135 template <
class VoxelType>
1146 #undef _NextPrevMethod 1155 #endif // MIRTK_ImageRegion_H int GetScalarType() const
void SetRadius(int)
Set radius of image region.
int MaxNumberOfChannels() const
Get number of channels in set image region.
void SetNeighborhood(int, int, int, int)
Set 2D neighborhood.
int NumberOfImageChannels() const
int NumberOfImageVoxels() const
Number of voxels in the entire image.
int BeginZ() const
Get start of image region to iterate over in z dimension.
int NumberOfComponents() const
Get number of vector components in overlap of set image region and image domain.
bool IsImageSequence() const
int _SliceStride
Increment at end of slice in number of voxels.
Vector4D< int > _Size
Size of set image region.
int NumberOfFrames() const
Get number of frames in overlap of set image region and image domain.
int EndY() const
Get end of image region to iterate over in y dimension.
int MaxNumberOfFrames() const
Get number of frames in set image region.
void SetCenter(int, int, int=0, int=-1)
Set center of image region.
Vector4D< int > _Begin
First index of actual image region.
bool IsScalarImage() const
void SetRegion(int, int, int, int)
Set 2D image region.
int ColumnStride() const
Get stride between columns in number of voxels.
int BeginT() const
Get start of image region to iterate over in t dimension.
const VoxelType * GetPointerToEnd(const BaseImage &) const
Get raw image pointer to last voxel image of region.
void SetSize(int)
Set size of image region.
VoxelType * GetPointerToVoxels(int=0, int=0, int=0, int=0)
int FrameStride() const
Get stride between frames in number of voxels.
void SetFrame(int)
Set temporal region.
int LineStride() const
Get stride between rows/lines in number of voxels.
void SetStart(int, int, int=0, int=-1)
Set start of image region.
int NumberOfChannels() const
Get number of channels in overlap of set image region and image domain.
bool _IsImageSequence
Whether the image is a sequence.
int EndZ() const
Get end of image region to iterate over in z dimension.
int NumberOfVoxels() const
Number of voxels in overlap of set image region and image domain.
int MaxNumberOfVoxels() const
Number of voxels in set image region.
int NumberOfVectorComponents() const
int EndX() const
Get end of image region to iterate over in x dimension.
ImageRegion & operator=(const ImageRegion &)
Assignment operator.
void * GetScalarPointer(int=0, int=0, int=0, int=0)
Vector4D< int > _DataSize
Size of the entire image.
int MaxNumberOfComponents() const
Get number of vector components in set image region.
int EndT() const
Get end of image region to iterate over in t dimension.
const VoxelType * GetPointerToBegin(const BaseImage &) const
Get raw image pointer to first voxel of of region.
void SetComponent(int)
Set temporal region.
int _LineStride
Increment at end of line in number of voxels.
ImageRegion(const ImageAttributes &)
Constructor.
int BeginY() const
Get start of image region to iterate over in y dimension.
Vector4D< int > _Index
Start of set image region.
~ImageRegion()
Destructor.
int BeginX() const
Get start of image region to iterate over in x dimension.
int NumberOfSequenceFrames() const
int _FrameStride
Increment at end of frame in number of voxels.
Vector4D< int > _End
Last index of actual image region.
int SliceStride() const
Get stride between slices in number of voxels.
void SetChannel(int)
Set temporal region.