20 #ifndef MIRTK_ImageSequence_HH 21 #define MIRTK_ImageSequence_HH 23 #include "mirtk/ImageSequence.h" 24 #include "mirtk/Stream.h" 36 ImageChannel<irtkBaseImage>::ImageChannel(ImageType *image,
bool manage,
bool copy)
42 if (image->GetT() > 0) {
43 cerr <<
"ImageChannel::ImageChannel: Channel image cannot have fourth dimension" << endl;
46 if (copy && !manage) {
54 template <
class TImage>
61 if (image->GetT() > 0) {
62 cerr <<
"ImageChannel::ImageChannel: Channel image cannot have fourth dimension" << endl;
65 if (copy && !manage) {
73 template <
class TImage>
84 template <
class TImage>
95 template <>
template <
class TOtherImage>
106 template <>
template <
class TOtherImage>
117 template <
class TImage>
128 if (image && copy && !manage) {
138 template <
class TImage>
142 if (image && copy && !manage) {
152 template <
class TImage>
167 template <
class TChannel>
173 template <
class TChannel>
183 template <
class TChannel>
186 if (_Channel.size() > 0) {
189 attr.
_dt = _Channel[0].Image().GetTSize();
190 if (attr != _Channel[0].
Image().Attributes()) {
191 cerr <<
"ImageFrame::Add: Attributes of image do not match those of first channel" << endl;
195 const int T = image->GetT();
197 for (
int t = 0; t < T; ++t) {
200 _Channel.push_back(
ChannelType(channel,
true,
false));
203 _Channel.push_back(
ChannelType(image, manage, copy));
208 template <
class TChannel>
219 template <
class TChannel>
226 template <
class TChannel>
229 return static_cast<int>(_Channel.size());
233 template <
class TChannel>
236 return _Channel[idx];
240 template <
class TChannel>
243 return _Channel[idx];
247 template <
class TChannel>
250 _Channel[idx].Image(image, manage, copy);
254 template <
class TChannel>
257 return _Channel[idx].Image();
265 template <
class TChannel>
273 template <
class TChannel>
277 return image ? image->GetNumberOfVoxels() : 0;
281 template <
class TChannel>
285 return image ? image->GetX() : 0;
289 template <
class TChannel>
293 return image ? image->GetY() : 0;
297 template <
class TChannel>
301 return image ? image->GetZ() : 0;
305 template <
class TChannel>
309 return image ? image->GetXSize() : .0;
313 template <
class TChannel>
317 return image ? image->GetYSize() : .0;
321 template <
class TChannel>
325 return image ? image->GetZSize() : .0;
329 template <
class TChannel>
333 if (image) image->GetPixelSize(dx, dy, dz);
342 template <
class TChannel>
346 if (image) image->ImageToWorld(x, y, z);
350 template <
class TChannel>
354 if (image) image->WorldToImage(x, y, z);
358 template <
class TChannel>
362 if (image) image->ImageToTime(.0);
374 template <
class TFrame>
380 template <
class TFrame>
389 template <
class TFrame>
392 _Frame = other._Frame;
397 template <
class TFrame>
407 template <
class TFrame>
411 if (!image->HasSpatialAttributesOf(
Image(0, 0))) {
412 cerr <<
"ImageSequence::Add: Spatial attributes of image differ from those of first frame" << endl;
418 _Frame.reserve(_Frame.size() + image->GetT());
421 for (
int l = 0; l < image->GetT(); ++l) {
423 const double time = image->ImageToTime(l);
424 typename Array<FrameType>::iterator frame = _Frame.begin();
425 while (frame != _Frame.end()) {
426 const double t = frame->Time();
427 if (t == time)
break;
429 typename Array<FrameType>::iterator tmp = frame - 1;
436 if (frame == _Frame.end()) {
438 frame = _Frame.end() - 1;
441 if (image->GetT() > 0) {
444 frame->Add(channel,
true,
false);
446 frame->Add(image, manage, copy);
452 template <
class TFrame>
463 template <
class TFrame>
470 template <
class TFrame>
473 return static_cast<int>(_Frame.size());
477 template <
class TFrame>
484 template <
class TFrame>
495 template <
class TFrame>
502 template <
class TFrame>
509 template <
class TFrame>
513 return _Frame[idx / num][idx % num];
517 template <
class TFrame>
521 return _Frame[idx / num][idx % num];
525 template <
class TFrame>
532 template <
class TFrame>
543 template <
class TFrame>
550 template <
class TFrame>
557 template <
class TFrame>
568 template <
class TFrame>
573 if (image) attr = image->GetImageAttributes();
579 template <
class TFrame>
583 return image ? image->NumberOfVoxels() : 0;
587 template <
class TFrame>
591 return image ? image->GetX() : 0;
595 template <
class TFrame>
599 return image ? image->GetY() : 0;
603 template <
class TFrame>
607 return image ? image->GetZ() : 0;
611 template <
class TFrame>
618 template <
class TFrame>
622 return image ? image->GetXSize() : .0;
626 template <
class TFrame>
630 return image ? image->GetYSize() : .0;
634 template <
class TFrame>
638 return image ? image->GetZSize() : .0;
642 template <
class TFrame>
646 if (image) image->GetPixelSize(dx, dy, dz);
655 template <
class TFrame>
659 if (image) image->ImageToWorld(x, y, z);
663 template <
class TFrame>
667 if (image) image->WorldToImage(x, y, z);
673 #endif // MIRTK_ImageSequence_HH ~ImageSequence()
Destructor.
double _dt
Voxel t-dimensions (in ms)
double Time() const
Get time of temporal frame.
double YSize() const
Get size of each voxel in y dimension.
int Z() const
Get number of voxels in z dimension for each channel.
TImage ImageType
Type of image associated with this channel.
int NumberOfChannels() const
Get number of channels per frame.
int X() const
Get number of voxels in x dimension for each channel.
static BaseImage * New(const char *)
Read file and construct image.
double YSize() const
Get size of each voxel in y dimension.
int NumberOfChannels() const
Get number of image channels.
void Image(int idx, ImageType *image, bool manage=false, bool copy=false)
TChannel::ImageType ImageType
Type of channel image.
void Clear()
Clear image sequence.
void WorldToImage(double &, double &, double &) const
Convert world to voxel coordinate.
double XSize() const
Get size of each voxel in x dimension.
int Y() const
Get number of voxels in y dimension for each channel.
int Y() const
Get number of voxels in y dimension for each channel.
void Add(ImageType *image, bool manage=false, bool copy=false)
ImageType * _Image
Image associated with this channel.
TFrame::ImageType ImageType
Type of images.
void WorldToImage(double &, double &, double &) const
Convert world to voxel coordinate.
void GetPixelSize(double *, double *, double *) const
Get voxel size.
void ImageToWorld(double &, double &, double &) const
Convert voxel to world coordinate.
TFrame FrameType
Type of frames.
void Image(int f, int c, ImageType *image, bool manage, bool copy)
TChannel ChannelType
Type of a channel.
virtual ~ImageChannel()
Destructor.
int _t
Image t-dimension (in voxels)
virtual void GetFrame(BaseImage *&, int, int=-1) const =0
Get time instance (i.e., frame) or channel of image.
int T() const
Get number of frames.
double ZSize() const
Get size of each voxel in z dimension.
ChannelType & Channel(int idx)
int NumberOfFrames() const
Get number of frames.
virtual ~ImageFrame()
Destructor.
ImageAttributes Attributes() const
int Z() const
Get number of voxels in z dimension for each channel.
void GetPixelSize(double *, double *, double *) const
Get voxel size.
bool _Manage
Whether to manage the associated image.
ImageFrame()
Default constructor.
int NumberOfVoxels() const
Get number of voxels per channel.
double ZSize() const
Get size of each voxel in z dimension.
ImageAttributes Attributes() const
ImageSequence & operator=(const ImageSequence &)
Assignment operator.
ImageChannel & operator=(const ImageChannel &)
int X() const
Get number of voxels in x dimension for each channel.
void ImageToWorld(double &, double &, double &) const
Convert voxel to world coordinate.
void Add(ImageType *image, bool manage=false, bool copy=false)
ImageSequence()
Constructor.
FrameType & Frame(int)
Get frame of sequence.
double XSize() const
Get size of each voxel in x dimension.
ChannelType & Channel(int=0)
Get image channel.
int NumberOfVoxels() const
Get number of voxels per channel.
ImageType * Image() const
Get image associated with this channel.
TFrame::ChannelType ChannelType
Type of channels.
int NumberOfImages() const
Get number of frames times number of channels.