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-2013 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_3dimage_hh
22 #define mia_3d_3dimage_hh
23 
24 #include <mia/3d/vectorfield.hh>
25 #include <mia/3d/orientation.hh>
26 #include <mia/2d/image.hh>
27 
28 #include <mia/core/attributes.hh>
29 #include <mia/core/pixeltype.hh>
30 #include <mia/core/filter.hh>
31 
32 
34 
45 protected:
52  C3DImage(const CAttributedData& data, EPixelType type);
57  C3DImage(EPixelType type);
58 
60  C3DImage();
61 public:
63  static const char *data_descr;
64 
67 
69  typedef std::shared_ptr<C3DImage > Pointer;
70 
71  virtual ~C3DImage();
72 
76  EPixelType get_pixel_type() const;
77 
78 
82  virtual size_t size() const = 0;
83 
87  virtual const C3DBounds& get_size() const = 0;
88 
92  virtual Pointer clone() const = 0;
93 
95 
96  virtual C3DFVector get_voxel_size() const = 0;
97 
99  virtual void set_voxel_size(const C3DFVector& voxel) = 0;
100 
102  E3DImageOrientation get_orientation() const;
103 
108  void set_orientation(E3DImageOrientation orient);
109 private:
110  EPixelType m_pixel_type;
111 };
112 
115 
116 
118 typedef std::vector<P3DImage> C3DImageSeries;
119 typedef std::shared_ptr<C3DImageSeries> P3DImageSeries;
120 
127 template <typename T>
128 class EXPORT_3D T3DImage : public C3DImage {
129 public:
131  typedef C3DImage Super;
132 
134  typedef typename T3DDatafield<T>::iterator iterator;
135  typedef typename T3DDatafield<T>::const_iterator const_iterator;
136  typedef typename T3DDatafield<T>::const_reference const_reference;
137  typedef typename T3DDatafield<T>::reference reference;
138  typedef typename T3DDatafield<T>::const_pointer const_pointer;
139  typedef typename T3DDatafield<T>::pointer pointer;
140  typedef typename T3DDatafield<T>::value_type value_type;
141  typedef typename T3DDatafield<T>::difference_type difference_type;
142  typedef typename T3DDatafield<T>::size_type size_type;
143  typedef typename T3DDatafield<T>::range_iterator range_iterator;
144  typedef typename T3DDatafield<T>::const_range_iterator const_range_iterator;
146 
152  T3DImage(const C3DBounds& size, const T* init_data);
153 
159  T3DImage(const C3DBounds& size, const CAttributedData& attr);
164  T3DImage(const C3DBounds& size);
165 
166  //T3DImage(const T3DDatafield<T>& size);
167 
171  T3DImage(const T3DImage& orig);
172 
176  T3DImage();
177 
178 
180  virtual Pointer clone() const;
181 
183  void get_data_line_x(int y, int z, std::vector<T>& buffer)const;
184 
186  void get_data_line_y(int x, int z, std::vector<T>& buffer)const;
187 
189  void get_data_line_z(int x, int y, std::vector<T>& buffer)const;
190 
192  void put_data_line_x(int y, int z, const std::vector<T> &buffer);
193 
195  void put_data_line_y(int x, int z, const std::vector<T> &buffer);
196 
198  void put_data_line_z(int x, int y, const std::vector<T> &buffer);
199 
201  T2DImage<T> get_data_plane_xy(size_t z)const;
202 
204  T2DImage<T> get_data_plane_yz(size_t x)const;
205 
207  T2DImage<T> get_data_plane_xz(size_t y)const;
208 
210  void put_data_plane_xy(size_t z, const T2DImage<T>& p);
211 
213  void put_data_plane_yz(size_t x, const T2DImage<T>& p);
214 
216  void put_data_plane_xz(size_t y, const T2DImage<T>& p);
217 
218 
220  const_reference operator()(size_t x, size_t y, size_t z) const {
221  return m_image(x,y,z);
222  }
223 
225  reference operator()(size_t x, size_t y, size_t z){
226  return m_image(x,y,z);
227  }
228 
230  const_reference operator()(const C3DBounds& l) const{
231  return m_image(l.x,l.y, l.z);
232  }
233 
235  reference operator()(const C3DBounds& l){
236  return m_image(l.x,l.y, l.z);
237  }
238 
240  const_iterator begin()const {
241  return m_image.begin();
242  }
243 
245  const_iterator end()const {
246  return m_image.end();
247  }
248 
250  range_iterator begin_range(const C3DBounds& begin, const C3DBounds& end) {
251  return m_image.begin_range(begin, end);
252  }
253 
255  range_iterator end_range(const C3DBounds& begin, const C3DBounds& end){
256  return m_image.end_range(begin, end);
257  }
258 
260  const_range_iterator begin_range(const C3DBounds& begin, const C3DBounds& end)const {
261  return m_image.begin_range(begin, end);
262  }
263 
265  const_range_iterator end_range(const C3DBounds& begin, const C3DBounds& end) const{
266  return m_image.end_range(begin, end);
267  }
268 
269 
270 
272  size_t size() const;
273 
275  iterator begin() {
276  return m_image.begin();
277  }
278 
280  iterator end() {
281  return m_image.end();
282  }
283 
285  const_iterator begin_at(size_t x, size_t y, size_t z) const {
286  return m_image.begin_at(x, y, z);
287  }
288 
290  iterator begin_at(size_t x, size_t y, size_t z) {
291  return m_image.begin_at(x, y, z);
292  }
293 
295  const_reference operator[](int i)const
296  {
297  return m_image[i];
298  }
299 
303  reference operator[](int i)
304  {
305  return m_image[i];
306  }
307 
309  const T3DDatafield<T>& data() const;
310 
312  //T3DDatafield<T>& data();
313 
318  C3DFVector get_gradient(int index) const
319  {
320  return m_image.template get_gradient<float>(index);
321  }
322 
324  virtual const C3DBounds& get_size() const;
325 
327  virtual C3DFVector get_voxel_size() const;
328 
330  virtual void set_voxel_size(const C3DFVector& voxel);
331 
332 private:
333  T3DDatafield<T> m_image;
334 };
335 
336 
348 template <typename O>
349 struct FConvert3DImageToPixeltypeO: public TFilter<T3DImage<O> > {
350 
356  template <typename T>
357  T3DImage<O> operator () (const T3DImage<T> &image) const {
358  T3DImage<O> result(image.get_size(), image);
359  copy(image.begin(), image.end(), result.begin());
360  return result;
361  }
362 
369  T3DImage<O> operator () (const C3DImage &image) const {
370  return filter(*this, image);
371  }
372 
380  return filter(*this, *image);
381  }
382 };
383 
391 
392 
403 
404 
407 
410 
413 
416 
419 
422 
425 
426 #ifdef LONG_64BIT
427 
429 typedef T3DImage<signed long> C3DSLImage;
430 
432 typedef T3DImage<unsigned long> C3DULImage;
433 #endif
434 
437 
440 
446 template <>
447 struct Binder<C3DImage> {
448  typedef __bind_all<T3DImage> Derived;
449 };
450 
452 
457 template <typename T>
459 public:
460  static void register_for(const std::string& key);
461 private:
462  PAttribute do_from_string(const std::string& value) const;
463 };
464 
470 template <typename T>
472 public:
473 
478  C3DValueAttribute(const T3DVector<T>& value);
479 
481  operator T3DVector<T>()const;
482 
487  const char *typedescr() const {
488  return typeid(T3DVector<T>).name();
489  }
490 private:
491  std::string do_as_string() const;
492  bool do_is_equal(const CAttribute& other) const;
493  bool do_is_less(const CAttribute& other) const;
494  T3DVector<T> m_value;
495 };
496 
502 
508 
514 
520 
522 
523 #endif
T3DImage< unsigned short > C3DUSImage
3D image with unsigned 16 bit integer values
Definition: 3d/image.hh:418
Specific type of the 3D images that hold real pixel data.
Definition: 3d/image.hh:128
const_iterator end() const
constant iterator
Definition: 3d/image.hh:245
std::vector< P3DImage > C3DImageSeries
helper type for image series
Definition: 3d/image.hh:118
EPixelType
Definition: pixeltype.hh:32
reference operator()(const C3DBounds &l)
element access operator - read/write
Definition: 3d/image.hh:235
virtual Pointer clone() const =0
C3DImage::Pointer P3DImage
define a shortcut to the 3D image shared pointer.
Definition: 3d/image.hh:114
reference operator()(size_t x, size_t y, size_t z)
element access operator - read/write
Definition: 3d/image.hh:225
T z
vector element
Definition: 3d/vector.hh:53
T3DImage< signed char > C3DSBImage
3D image with signed 8 bit integer values
Definition: 3d/image.hh:409
A templated class of a 3D data field.
Definition: 3d/datafield.hh:45
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:265
const char * typedescr() const
Definition: 3d/image.hh:487
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:415
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:117
const_reference operator()(const C3DBounds &l) const
element access operator - read only
Definition: 3d/image.hh:230
The class of all attributes of data that is considered to ve meta-data.
Definition: attributes.hh:48
T3DImage< O > operator()(const T3DImage< T > &image) const
Definition: 3d/image.hh:357
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:43
FConvert3DImageToPixeltypeO< float > FCopy3DImageToFloatRepn
short name for 3DImage to float pixel repn copy functor
Definition: 3d/image.hh:390
A collection of attributes.
Definition: attributes.hh:252
C3DValueAttributeTranslator< float > CVoxelAttributeTranslator
attribute translator for a 3D floating point vector used for the voxel size
Definition: 3d/image.hh:507
#define EXPORT_3D
Definition: defines3d.hh:44
static F::result_type filter(const F &f, const B &b)
Definition: core/filter.hh:196
C3DImage Super
define the super class of this class for generic processing
Definition: 3d/image.hh:131
functor to convert an image with an abitrary pixel type to single floating point pixels ...
Definition: 3d/image.hh:349
C3DValueAttribute< int > C3DIntAttribute
a 3D integer vector
Definition: 3d/image.hh:513
std::shared_ptr< CAttribute > PAttribute
define the shared pointer wrapped attribute pointer
Definition: attributes.hh:98
iterator begin()
read/write iterator, issues copy-on-write
Definition: 3d/image.hh:275
const_reference operator()(size_t x, size_t y, size_t z) const
element access operator - read only
Definition: 3d/image.hh:220
a translater for 3D vectors to and from a std::string
Definition: 3d/image.hh:458
T3DImage< double > C3DDImage
3D image with signed 64 bit floating point values
Definition: 3d/image.hh:439
A class to translate an attribute from a string.
Definition: attributes.hh:366
EXPORT_2D C2DFVectorfield get_gradient(const C2DImage &image)
T y
vector element
Definition: 3d/vector.hh:51
std::shared_ptr< C3DImageSeries > P3DImageSeries
Definition: 3d/image.hh:119
virtual const C3DBounds & get_size() const =0
const_reference operator[](int i) const
Definition: 3d/image.hh:295
std::shared_ptr< C3DImage > Pointer
Pointer type of the image.
Definition: 3d/image.hh:69
virtual void set_voxel_size(const C3DFVector &voxel)=0
set the voxel size on world units
The generic base type of a 3D image.
Definition: 3d/image.hh:44
const_iterator begin() const
constant iterator
Definition: 3d/image.hh:240
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:285
E3DImageOrientation
Definition: orientation.hh:38
C3DValueAttribute< float > CVoxelAttribute
a 3D floating point vector used for the voxel size attribute
Definition: 3d/image.hh:501
C3DValueAttributeTranslator< int > C3DIntAttributeTranslator
attribute translator for a 3D integer vector
Definition: 3d/image.hh:519
C3DBounds dimsize_type
generic type for the dimension of the image
Definition: 3d/image.hh:66
T3DImage< bool > C3DBitImage
3D image with binary values
Definition: 3d/image.hh:406
T3DImage< unsigned int > C3DUIImage
3D image with unsigned 32 bit integer values
Definition: 3d/image.hh:424
iterator begin_at(size_t x, size_t y, size_t z)
read/write iterator starting at the given location
Definition: 3d/image.hh:290
iterator end()
read/write iterator, issues copy-on-write
Definition: 3d/image.hh:280
T3DImage< unsigned char > C3DUBImage
3D image with unsigned 8 bit integer values
Definition: 3d/image.hh:412
virtual C3DFVector get_voxel_size() const =0
T3DImage< signed int > C3DSIImage
3D image with signed 32 bit integer values
Definition: 3d/image.hh:421
reference operator[](int i)
Definition: 3d/image.hh:303
static const char * data_descr
data type description for the plug-in path component
Definition: 3d/image.hh:63
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:250
C3DFVector get_gradient(int index) const
read/write access to the underlying data
Definition: 3d/image.hh:318
T x
vector element
Definition: 3d/vector.hh:49
a 3D vector value used in attributes
Definition: 3d/image.hh:471
T3DImage< float > C3DFImage
3D image with signed 32 bit floating point values
Definition: 3d/image.hh:436
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:260
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:255
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:46