3d/image.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2016 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_3d_image_hh
22 #define mia_3d_image_hh
23 
24 #include <mia/3d/vectorfield.hh>
25 #include <mia/3d/orientation.hh>
26 #include <mia/3d/rot.hh>
27 
28 #include <mia/2d/image.hh>
29 
31 #include <mia/core/pixeltype.hh>
32 #include <mia/core/filter.hh>
33 
34 
36 
47 protected:
54  C3DImage(const CAttributedData& data, EPixelType type);
59  C3DImage(EPixelType type);
60 
62  C3DImage();
63 public:
65  static const char *data_descr;
66 
69 
71  typedef std::shared_ptr<C3DImage > Pointer;
72 
73  virtual ~C3DImage();
74 
78  EPixelType get_pixel_type() const;
79 
80 
84  virtual size_t size() const = 0;
85 
89  virtual const C3DBounds& get_size() const = 0;
90 
94  virtual Pointer clone() const = 0;
95 
97  C3DFVector get_voxel_size() const;
98 
100  void set_voxel_size(const C3DFVector& voxel);
101 
102 
104  C3DFVector get_origin() const;
105 
107  void set_origin(const C3DFVector& voxel);
108 
109 
111  C3DRotation get_rotation() const;
112 
114  void set_rotation(const C3DRotation& voxel);
115 
117  E3DImageOrientation get_orientation() const;
118 
123  void set_orientation(E3DImageOrientation orient);
124 
126  virtual std::pair<double, double> get_minmax_intensity() const = 0;
127 private:
128  EPixelType m_pixel_type;
129 };
130 
133 
134 
136 typedef std::vector<P3DImage> C3DImageSeries;
137 typedef std::shared_ptr<C3DImageSeries> P3DImageSeries;
138 
145 template <typename T>
146 class EXPORT_3D T3DImage : public C3DImage {
147 public:
149  typedef C3DImage Super;
150 
152  typedef typename T3DDatafield<T>::iterator iterator;
153  typedef typename T3DDatafield<T>::const_iterator const_iterator;
154  typedef typename T3DDatafield<T>::const_reference const_reference;
155  typedef typename T3DDatafield<T>::reference reference;
156  typedef typename T3DDatafield<T>::const_pointer const_pointer;
157  typedef typename T3DDatafield<T>::pointer pointer;
158  typedef typename T3DDatafield<T>::value_type value_type;
159  typedef typename T3DDatafield<T>::difference_type difference_type;
160  typedef typename T3DDatafield<T>::size_type size_type;
161  typedef typename T3DDatafield<T>::range_iterator range_iterator;
162  typedef typename T3DDatafield<T>::const_range_iterator const_range_iterator;
163  typedef typename T3DDatafield<T>::range_iterator_with_boundary_flag range_iterator_with_boundary_flag;
164  typedef typename T3DDatafield<T>::const_range_iterator_with_boundary_flag const_range_iterator_with_boundary_flag;
165 
166  typedef typename T2DDatafield<T>::data_array data_array;
168 
174  T3DImage(const C3DBounds& size, const T* init_data);
175 
181  T3DImage(const C3DBounds& size, const CAttributedData& attr);
182 
183 
184  T3DImage(const C3DBounds& size, const data_array& init_data);
189  T3DImage(const C3DBounds& size);
190 
191  //T3DImage(const T3DDatafield<T>& size);
192 
196  T3DImage(const T3DImage& orig);
197 
201  T3DImage();
202 
203 
205  virtual Pointer clone() const;
206 
208  void get_data_line_x(int y, int z, std::vector<T>& buffer)const;
209 
211  void get_data_line_y(int x, int z, std::vector<T>& buffer)const;
212 
214  void get_data_line_z(int x, int y, std::vector<T>& buffer)const;
215 
217  void put_data_line_x(int y, int z, const std::vector<T> &buffer);
218 
220  void put_data_line_y(int x, int z, const std::vector<T> &buffer);
221 
223  void put_data_line_z(int x, int y, const std::vector<T> &buffer);
224 
226  T2DImage<T> get_data_plane_xy(size_t z)const;
227 
229  T2DImage<T> get_data_plane_yz(size_t x)const;
230 
232  T2DImage<T> get_data_plane_xz(size_t y)const;
233 
235  void put_data_plane_xy(size_t z, const T2DImage<T>& p);
236 
238  void put_data_plane_yz(size_t x, const T2DImage<T>& p);
239 
241  void put_data_plane_xz(size_t y, const T2DImage<T>& p);
242 
243 
245  const_reference operator()(size_t x, size_t y, size_t z) const {
246  return m_image(x,y,z);
247  }
248 
250  reference operator()(size_t x, size_t y, size_t z){
251  return m_image(x,y,z);
252  }
253 
255  const_reference operator()(const C3DBounds& l) const{
256  return m_image(l.x,l.y, l.z);
257  }
258 
260  reference operator()(const C3DBounds& l){
261  return m_image(l.x,l.y, l.z);
262  }
263 
265  const_iterator begin()const {
266  return m_image.begin();
267  }
268 
270  const_iterator end()const {
271  return m_image.end();
272  }
273 
275  range_iterator begin_range(const C3DBounds& begin, const C3DBounds& end) {
276  return m_image.begin_range(begin, end);
277  }
278 
280  range_iterator end_range(const C3DBounds& begin, const C3DBounds& end){
281  return m_image.end_range(begin, end);
282  }
283 
285  const_range_iterator begin_range(const C3DBounds& begin, const C3DBounds& end)const {
286  return m_image.begin_range(begin, end);
287  }
288 
290  const_range_iterator end_range(const C3DBounds& begin, const C3DBounds& end) const{
291  return m_image.end_range(begin, end);
292  }
293 
294 
296  range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end){
297  return m_image.begin_range_with_boundary_flags(begin, end);
298  }
299 
301  range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end){
302  return m_image.end_range_with_boundary_flags(begin, end);
303  }
304 
305 
308  const_range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end)const{
309  return m_image.begin_range_with_boundary_flags(begin, end);
310  }
311 
313  const_range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end)const{
314  return m_image.end_range_with_boundary_flags(begin, end);
315  }
316 
318  size_t size() const;
319 
321  iterator begin() {
322  return m_image.begin();
323  }
324 
326  iterator end() {
327  return m_image.end();
328  }
329 
331  const_iterator begin_at(size_t x, size_t y, size_t z) const {
332  return m_image.begin_at(x, y, z);
333  }
334 
336  iterator begin_at(size_t x, size_t y, size_t z) {
337  return m_image.begin_at(x, y, z);
338  }
339 
341  const_reference operator[](int i)const
342  {
343  return m_image[i];
344  }
345 
349  reference operator[](int i)
350  {
351  return m_image[i];
352  }
353 
355  const T3DDatafield<T>& data() const;
356 
358  //T3DDatafield<T>& data();
359 
364  C3DFVector get_gradient(int index) const
365  {
366  return m_image.template get_gradient<float>(index);
367  }
368 
370  virtual const C3DBounds& get_size() const;
371 
373  std::pair<double, double> get_minmax_intensity() const;
374 private:
375  T3DDatafield<T> m_image;
376 };
377 
378 
390 template <typename O>
391 struct FConvert3DImageToPixeltypeO: public TFilter<T3DImage<O> > {
392 
398  template <typename T>
399  T3DImage<O> operator () (const T3DImage<T> &image) const {
400  T3DImage<O> result(image.get_size(), image);
401  copy(image.begin(), image.end(), result.begin());
402  return result;
403  }
404 
411  T3DImage<O> operator () (const C3DImage &image) const {
412  return filter(*this, image);
413  }
414 
421  T3DImage<O> operator () (P3DImage image) const {
422  return filter(*this, *image);
423  }
424 };
425 
433 
434 
445 
446 
449 
452 
455 
458 
461 
464 
467 
468 #ifdef LONG_64BIT
469 
471 typedef T3DImage<signed long> C3DSLImage;
472 
474 typedef T3DImage<unsigned long> C3DULImage;
475 #endif
476 
479 
482 
488 template <>
489 struct Binder<C3DImage> {
490  typedef __bind_all<T3DImage> Derived;
491 };
492 
494 
496 
497 #endif
T3DImage< unsigned short > C3DUSImage
3D image with unsigned 16 bit integer values
Definition: 3d/image.hh:460
Specific type of the 3D images that hold real pixel data.
Definition: 3d/image.hh:146
const_iterator end() const
constant iterator
Definition: 3d/image.hh:270
std::vector< P3DImage > C3DImageSeries
helper type for image series
Definition: 3d/image.hh:136
range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end)
Definition: 3d/image.hh:301
EPixelType
Definition: pixeltype.hh:32
reference operator()(const C3DBounds &l)
element access operator - read/write
Definition: 3d/image.hh:260
virtual Pointer clone() const =0
C3DImage::Pointer P3DImage
define a shortcut to the 3D image shared pointer.
Definition: 3d/image.hh:132
a 3D field of floating point single accuracy 3D vectors
reference operator()(size_t x, size_t y, size_t z)
element access operator - read/write
Definition: 3d/image.hh:250
T z
vector element
Definition: 3d/vector.hh:55
range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end)
Definition: 3d/image.hh:296
T3DImage< signed char > C3DSBImage
3D image with signed 8 bit integer values
Definition: 3d/image.hh:451
A templated class of a 3D data field.
Definition: 3d/datafield.hh:84
const_range_iterator end_range(const C3DBounds &begin, const C3DBounds &end) const
forwarding function to access the specified range of the underlying T3DDatafield
Definition: 3d/image.hh:290
base class for all filer type functors.
Definition: core/filter.hh:68
T3DImage< signed short > C3DSSImage
3D image with signed 16 bit integer values
Definition: 3d/image.hh:457
virtual const C3DBounds & get_size() const
This is the template version of a 2D image that is used for holding real data.
Definition: 2d/image.hh:129
const_reference operator()(const C3DBounds &l) const
element access operator - read only
Definition: 3d/image.hh:255
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
FConvert3DImageToPixeltypeO< float > FCopy3DImageToFloatRepn
short name for 3DImage to float pixel repn copy functor
Definition: 3d/image.hh:432
A collection of attributes.
Definition: attributes.hh:255
#define EXPORT_3D
Definition: defines3d.hh:44
static F::result_type filter(const F &f, const B &b)
Definition: core/filter.hh:250
C3DImage Super
define the super class of this class for generic processing
Definition: 3d/image.hh:149
functor to convert an image with an abitrary pixel type to single floating point pixels ...
Definition: 3d/image.hh:391
iterator begin()
read/write iterator, issues copy-on-write
Definition: 3d/image.hh:321
const_reference operator()(size_t x, size_t y, size_t z) const
element access operator - read only
Definition: 3d/image.hh:245
T3DImage< double > C3DDImage
3D image with signed 64 bit floating point values
Definition: 3d/image.hh:481
T y
vector element
Definition: 3d/vector.hh:53
virtual std::pair< double, double > get_minmax_intensity() const =0
std::shared_ptr< C3DImageSeries > P3DImageSeries
Definition: 3d/image.hh:137
virtual const C3DBounds & get_size() const =0
const_reference operator[](int i) const
Definition: 3d/image.hh:341
std::shared_ptr< C3DImage > Pointer
Pointer type of the image.
Definition: 3d/image.hh:71
The generic base type of a 3D image.
Definition: 3d/image.hh:46
const_iterator begin() const
constant iterator
Definition: 3d/image.hh:265
const_iterator begin_at(size_t x, size_t y, size_t z) const
constant iterator starting at the given location
Definition: 3d/image.hh:331
E3DImageOrientation
Definition: orientation.hh:40
C3DBounds dimsize_type
generic type for the dimension of the image
Definition: 3d/image.hh:68
T3DImage< bool > C3DBitImage
3D image with binary values
Definition: 3d/image.hh:448
T3DImage< unsigned int > C3DUIImage
3D image with unsigned 32 bit integer values
Definition: 3d/image.hh:466
const_range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end) const
Definition: 3d/image.hh:308
iterator begin_at(size_t x, size_t y, size_t z)
read/write iterator starting at the given location
Definition: 3d/image.hh:336
iterator end()
read/write iterator, issues copy-on-write
Definition: 3d/image.hh:326
T3DImage< unsigned char > C3DUBImage
3D image with unsigned 8 bit integer values
Definition: 3d/image.hh:454
T3DImage< signed int > C3DSIImage
3D image with signed 32 bit integer values
Definition: 3d/image.hh:463
reference operator[](int i)
Definition: 3d/image.hh:349
static const char * data_descr
data type description for the plug-in path component
Definition: 3d/image.hh:65
::std::vector< typename __holder_type_dispatch< T >::type > data_array
type for the flat reprentation of the 2D data field
Definition: 2d/datafield.hh:58
virtual size_t size() const =0
range_iterator begin_range(const C3DBounds &begin, const C3DBounds &end)
forwarding function to access the specified range of the underlying T3DDatafield
Definition: 3d/image.hh:275
const_range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end) const
Definition: 3d/image.hh:313
C3DFVector get_gradient(int index) const
read/write access to the underlying data
Definition: 3d/image.hh:364
T x
vector element
Definition: 3d/vector.hh:51
T3DImage< float > C3DFImage
3D image with signed 32 bit floating point values
Definition: 3d/image.hh:478
const_range_iterator begin_range(const C3DBounds &begin, const C3DBounds &end) const
forwarding function to access the specified range of the underlying T3DDatafield
Definition: 3d/image.hh:285
EXPORT_3D C3DFVectorfield get_gradient(const C3DImage &image)
range_iterator end_range(const C3DBounds &begin, const C3DBounds &end)
forwarding function to access the specified range of the underlying T3DDatafield
Definition: 3d/image.hh:280
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36