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-2014 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 private:
125  EPixelType m_pixel_type;
126 };
127 
130 
131 
133 typedef std::vector<P3DImage> C3DImageSeries;
134 typedef std::shared_ptr<C3DImageSeries> P3DImageSeries;
135 
142 template <typename T>
143 class EXPORT_3D T3DImage : public C3DImage {
144 public:
146  typedef C3DImage Super;
147 
149  typedef typename T3DDatafield<T>::iterator iterator;
150  typedef typename T3DDatafield<T>::const_iterator const_iterator;
151  typedef typename T3DDatafield<T>::const_reference const_reference;
152  typedef typename T3DDatafield<T>::reference reference;
153  typedef typename T3DDatafield<T>::const_pointer const_pointer;
154  typedef typename T3DDatafield<T>::pointer pointer;
155  typedef typename T3DDatafield<T>::value_type value_type;
156  typedef typename T3DDatafield<T>::difference_type difference_type;
157  typedef typename T3DDatafield<T>::size_type size_type;
158  typedef typename T3DDatafield<T>::range_iterator range_iterator;
159  typedef typename T3DDatafield<T>::const_range_iterator const_range_iterator;
160  typedef typename T3DDatafield<T>::range_iterator_with_boundary_flag range_iterator_with_boundary_flag;
161  typedef typename T3DDatafield<T>::const_range_iterator_with_boundary_flag const_range_iterator_with_boundary_flag;
162 
163  typedef typename T2DDatafield<T>::data_array data_array;
165 
171  T3DImage(const C3DBounds& size, const T* init_data);
172 
178  T3DImage(const C3DBounds& size, const CAttributedData& attr);
179 
180 
181  T3DImage(const C3DBounds& size, const data_array& init_data);
186  T3DImage(const C3DBounds& size);
187 
188  //T3DImage(const T3DDatafield<T>& size);
189 
193  T3DImage(const T3DImage& orig);
194 
198  T3DImage();
199 
200 
202  virtual Pointer clone() const;
203 
205  void get_data_line_x(int y, int z, std::vector<T>& buffer)const;
206 
208  void get_data_line_y(int x, int z, std::vector<T>& buffer)const;
209 
211  void get_data_line_z(int x, int y, std::vector<T>& buffer)const;
212 
214  void put_data_line_x(int y, int z, const std::vector<T> &buffer);
215 
217  void put_data_line_y(int x, int z, const std::vector<T> &buffer);
218 
220  void put_data_line_z(int x, int y, const std::vector<T> &buffer);
221 
223  T2DImage<T> get_data_plane_xy(size_t z)const;
224 
226  T2DImage<T> get_data_plane_yz(size_t x)const;
227 
229  T2DImage<T> get_data_plane_xz(size_t y)const;
230 
232  void put_data_plane_xy(size_t z, const T2DImage<T>& p);
233 
235  void put_data_plane_yz(size_t x, const T2DImage<T>& p);
236 
238  void put_data_plane_xz(size_t y, const T2DImage<T>& p);
239 
240 
242  const_reference operator()(size_t x, size_t y, size_t z) const {
243  return m_image(x,y,z);
244  }
245 
247  reference operator()(size_t x, size_t y, size_t z){
248  return m_image(x,y,z);
249  }
250 
252  const_reference operator()(const C3DBounds& l) const{
253  return m_image(l.x,l.y, l.z);
254  }
255 
257  reference operator()(const C3DBounds& l){
258  return m_image(l.x,l.y, l.z);
259  }
260 
262  const_iterator begin()const {
263  return m_image.begin();
264  }
265 
267  const_iterator end()const {
268  return m_image.end();
269  }
270 
272  range_iterator begin_range(const C3DBounds& begin, const C3DBounds& end) {
273  return m_image.begin_range(begin, end);
274  }
275 
277  range_iterator end_range(const C3DBounds& begin, const C3DBounds& end){
278  return m_image.end_range(begin, end);
279  }
280 
282  const_range_iterator begin_range(const C3DBounds& begin, const C3DBounds& end)const {
283  return m_image.begin_range(begin, end);
284  }
285 
287  const_range_iterator end_range(const C3DBounds& begin, const C3DBounds& end) const{
288  return m_image.end_range(begin, end);
289  }
290 
291 
292 
294  size_t size() const;
295 
297  iterator begin() {
298  return m_image.begin();
299  }
300 
302  iterator end() {
303  return m_image.end();
304  }
305 
307  const_iterator begin_at(size_t x, size_t y, size_t z) const {
308  return m_image.begin_at(x, y, z);
309  }
310 
312  iterator begin_at(size_t x, size_t y, size_t z) {
313  return m_image.begin_at(x, y, z);
314  }
315 
317  const_reference operator[](int i)const
318  {
319  return m_image[i];
320  }
321 
325  reference operator[](int i)
326  {
327  return m_image[i];
328  }
329 
331  const T3DDatafield<T>& data() const;
332 
334  //T3DDatafield<T>& data();
335 
340  C3DFVector get_gradient(int index) const
341  {
342  return m_image.template get_gradient<float>(index);
343  }
344 
346  virtual const C3DBounds& get_size() const;
347 
348 private:
349  T3DDatafield<T> m_image;
350 };
351 
352 
364 template <typename O>
365 struct FConvert3DImageToPixeltypeO: public TFilter<T3DImage<O> > {
366 
372  template <typename T>
373  T3DImage<O> operator () (const T3DImage<T> &image) const {
374  T3DImage<O> result(image.get_size(), image);
375  copy(image.begin(), image.end(), result.begin());
376  return result;
377  }
378 
385  T3DImage<O> operator () (const C3DImage &image) const {
386  return filter(*this, image);
387  }
388 
396  return filter(*this, *image);
397  }
398 };
399 
407 
408 
419 
420 
423 
426 
429 
432 
435 
438 
441 
442 #ifdef LONG_64BIT
443 
445 typedef T3DImage<signed long> C3DSLImage;
446 
448 typedef T3DImage<unsigned long> C3DULImage;
449 #endif
450 
453 
456 
462 template <>
463 struct Binder<C3DImage> {
464  typedef __bind_all<T3DImage> Derived;
465 };
466 
468 
470 
471 #endif
T3DImage< unsigned short > C3DUSImage
3D image with unsigned 16 bit integer values
Definition: 3d/image.hh:434
Specific type of the 3D images that hold real pixel data.
Definition: 3d/image.hh:143
const_iterator end() const
constant iterator
Definition: 3d/image.hh:267
std::vector< P3DImage > C3DImageSeries
helper type for image series
Definition: 3d/image.hh:133
EPixelType
Definition: pixeltype.hh:32
reference operator()(const C3DBounds &l)
element access operator - read/write
Definition: 3d/image.hh:257
virtual Pointer clone() const =0
C3DImage::Pointer P3DImage
define a shortcut to the 3D image shared pointer.
Definition: 3d/image.hh:129
reference operator()(size_t x, size_t y, size_t z)
element access operator - read/write
Definition: 3d/image.hh:247
T z
vector element
Definition: 3d/vector.hh:55
T3DImage< signed char > C3DSBImage
3D image with signed 8 bit integer values
Definition: 3d/image.hh:425
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:287
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:431
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:118
const_reference operator()(const C3DBounds &l) const
element access operator - read only
Definition: 3d/image.hh:252
T3DImage< O > operator()(const T3DImage< T > &image) const
Definition: 3d/image.hh:373
#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:406
A collection of attributes.
Definition: attributes.hh:252
#define EXPORT_3D
Definition: defines3d.hh:44
static F::result_type filter(const F &f, const B &b)
Definition: core/filter.hh:230
C3DImage Super
define the super class of this class for generic processing
Definition: 3d/image.hh:146
functor to convert an image with an abitrary pixel type to single floating point pixels ...
Definition: 3d/image.hh:365
iterator begin()
read/write iterator, issues copy-on-write
Definition: 3d/image.hh:297
const_reference operator()(size_t x, size_t y, size_t z) const
element access operator - read only
Definition: 3d/image.hh:242
T3DImage< double > C3DDImage
3D image with signed 64 bit floating point values
Definition: 3d/image.hh:455
T y
vector element
Definition: 3d/vector.hh:53
std::shared_ptr< C3DImageSeries > P3DImageSeries
Definition: 3d/image.hh:134
virtual const C3DBounds & get_size() const =0
const_reference operator[](int i) const
Definition: 3d/image.hh:317
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:262
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:307
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:422
T3DImage< unsigned int > C3DUIImage
3D image with unsigned 32 bit integer values
Definition: 3d/image.hh:440
iterator begin_at(size_t x, size_t y, size_t z)
read/write iterator starting at the given location
Definition: 3d/image.hh:312
iterator end()
read/write iterator, issues copy-on-write
Definition: 3d/image.hh:302
T3DImage< unsigned char > C3DUBImage
3D image with unsigned 8 bit integer values
Definition: 3d/image.hh:428
T3DImage< signed int > C3DSIImage
3D image with signed 32 bit integer values
Definition: 3d/image.hh:437
reference operator[](int i)
Definition: 3d/image.hh:325
static const char * data_descr
data type description for the plug-in path component
Definition: 3d/image.hh:65
::std::vector< T > data_array
type for the flat reprentation of the 2D data field
Definition: 2d/datafield.hh:57
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:272
C3DFVector get_gradient(int index) const
read/write access to the underlying data
Definition: 3d/image.hh:340
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:452
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:282
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:277
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:46