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-2017 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);
55 
60  explicit C3DImage(EPixelType type);
61 
62 
64  C3DImage();
65 public:
67  static const char *data_descr;
68 
71 
73  typedef std::shared_ptr<C3DImage > Pointer;
74 
75  virtual ~C3DImage();
76 
80  EPixelType get_pixel_type() const;
81 
82 
86  virtual size_t size() const = 0;
87 
91  virtual const C3DBounds& get_size() const = 0;
92 
96  virtual Pointer clone() const = 0;
97 
99  C3DFVector get_voxel_size() const;
100 
102  void set_voxel_size(const C3DFVector& voxel);
103 
104 
106  C3DFVector get_origin() const;
107 
109  void set_origin(const C3DFVector& voxel);
110 
111 
113  C3DRotation get_rotation() const;
114 
116  void set_rotation(const C3DRotation& voxel);
117 
119  E3DImageOrientation get_orientation() const;
120 
125  void set_orientation(E3DImageOrientation orient);
126 
128  virtual std::pair<double, double> get_minmax_intensity() const = 0;
129 private:
130  EPixelType m_pixel_type;
131 };
132 
135 
136 
138 typedef std::vector<P3DImage> C3DImageSeries;
139 typedef std::shared_ptr<C3DImageSeries> P3DImageSeries;
140 
147 template <typename T>
148 class EXPORT_3D T3DImage : public C3DImage {
149 public:
151  typedef C3DImage Super;
152 
154  typedef typename T3DDatafield<T>::iterator iterator;
155  typedef typename T3DDatafield<T>::const_iterator const_iterator;
156  typedef typename T3DDatafield<T>::const_reference const_reference;
157  typedef typename T3DDatafield<T>::reference reference;
158  typedef typename T3DDatafield<T>::const_pointer const_pointer;
159  typedef typename T3DDatafield<T>::pointer pointer;
160  typedef typename T3DDatafield<T>::value_type value_type;
161  typedef typename T3DDatafield<T>::difference_type difference_type;
162  typedef typename T3DDatafield<T>::size_type size_type;
163  typedef typename T3DDatafield<T>::range_iterator range_iterator;
164  typedef typename T3DDatafield<T>::const_range_iterator const_range_iterator;
165  typedef typename T3DDatafield<T>::range_iterator_with_boundary_flag range_iterator_with_boundary_flag;
166  typedef typename T3DDatafield<T>::const_range_iterator_with_boundary_flag const_range_iterator_with_boundary_flag;
167 
168  typedef typename T2DDatafield<T>::data_array data_array;
170 
176  T3DImage(const C3DBounds& size, const T* init_data);
177 
183  T3DImage(const C3DBounds& size, const CAttributedData& attr);
184 
185 
186  T3DImage(const C3DBounds& size, const data_array& init_data);
191  explicit T3DImage(const C3DBounds& size);
192 
193  //T3DImage(const T3DDatafield<T>& size);
194 
198  T3DImage(const T3DImage<T>& orig);
199 
203  T3DImage(T3DImage<T>&& orig);
204 
208  T3DImage& operator = (const T3DImage<T>& orig);
209 
214 
219  explicit T3DImage(const T3DDatafield<T>& orig);
220 
224  T3DImage();
225 
226 
228  virtual Pointer clone() const;
229 
231  void get_data_line_x(int y, int z, std::vector<T>& buffer)const;
232 
234  void get_data_line_y(int x, int z, std::vector<T>& buffer)const;
235 
237  void get_data_line_z(int x, int y, std::vector<T>& buffer)const;
238 
240  void put_data_line_x(int y, int z, const std::vector<T> &buffer);
241 
243  void put_data_line_y(int x, int z, const std::vector<T> &buffer);
244 
246  void put_data_line_z(int x, int y, const std::vector<T> &buffer);
247 
249  T2DImage<T> get_data_plane_xy(size_t z)const;
250 
252  T2DImage<T> get_data_plane_yz(size_t x)const;
253 
255  T2DImage<T> get_data_plane_xz(size_t y)const;
256 
258  void put_data_plane_xy(size_t z, const T2DImage<T>& p);
259 
261  void put_data_plane_yz(size_t x, const T2DImage<T>& p);
262 
264  void put_data_plane_xz(size_t y, const T2DImage<T>& p);
265 
266 
268  const_reference operator()(size_t x, size_t y, size_t z) const {
269  return m_image(x,y,z);
270  }
271 
273  reference operator()(size_t x, size_t y, size_t z){
274  return m_image(x,y,z);
275  }
276 
278  const_reference operator()(const C3DBounds& l) const{
279  return m_image(l.x,l.y, l.z);
280  }
281 
283  reference operator()(const C3DBounds& l){
284  return m_image(l.x,l.y, l.z);
285  }
286 
288  const_iterator begin()const {
289  return m_image.begin();
290  }
291 
293  const_iterator end()const {
294  return m_image.end();
295  }
296 
298  range_iterator begin_range(const C3DBounds& begin, const C3DBounds& end) {
299  return m_image.begin_range(begin, end);
300  }
301 
303  range_iterator end_range(const C3DBounds& begin, const C3DBounds& end){
304  return m_image.end_range(begin, end);
305  }
306 
308  const_range_iterator begin_range(const C3DBounds& begin, const C3DBounds& end)const {
309  return m_image.begin_range(begin, end);
310  }
311 
313  const_range_iterator end_range(const C3DBounds& begin, const C3DBounds& end) const{
314  return m_image.end_range(begin, end);
315  }
316 
317 
319  range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end){
320  return m_image.begin_range_with_boundary_flags(begin, end);
321  }
322 
324  range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end){
325  return m_image.end_range_with_boundary_flags(begin, end);
326  }
327 
328 
331  const_range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end)const{
332  return m_image.begin_range_with_boundary_flags(begin, end);
333  }
334 
336  const_range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end)const{
337  return m_image.end_range_with_boundary_flags(begin, end);
338  }
339 
341  size_t size() const;
342 
344  iterator begin() {
345  return m_image.begin();
346  }
347 
349  iterator end() {
350  return m_image.end();
351  }
352 
354  const_iterator begin_at(size_t x, size_t y, size_t z) const {
355  return m_image.begin_at(x, y, z);
356  }
357 
359  iterator begin_at(size_t x, size_t y, size_t z) {
360  return m_image.begin_at(x, y, z);
361  }
362 
364  const_reference operator[](int i)const
365  {
366  return m_image[i];
367  }
368 
372  reference operator[](int i)
373  {
374  return m_image[i];
375  }
376 
378  const T3DDatafield<T>& data() const;
379 
381  //T3DDatafield<T>& data();
382 
387  C3DFVector get_gradient(int index) const
388  {
389  return m_image.template get_gradient<float>(index);
390  }
391 
393  virtual const C3DBounds& get_size() const;
394 
396  std::pair<double, double> get_minmax_intensity() const;
397 private:
398  T3DDatafield<T> m_image;
399 };
400 
401 
413 template <typename O>
414 struct FConvert3DImageToPixeltypeO: public TFilter<T3DImage<O> > {
415 
421  template <typename T>
422  T3DImage<O> operator () (const T3DImage<T> &image) const {
423  T3DImage<O> result(image.get_size(), image);
424  copy(image.begin(), image.end(), result.begin());
425  return result;
426  }
427 
434  T3DImage<O> operator () (const C3DImage &image) const {
435  return filter(*this, image);
436  }
437 
444  T3DImage<O> operator () (P3DImage image) const {
445  return filter(*this, *image);
446  }
447 };
448 
456 
457 
468 
469 
472 
475 
478 
481 
484 
487 
490 
493 
496 
499 
502 
508 template <>
509 struct Binder<C3DImage> {
510  typedef __bind_all<T3DImage> Derived;
511 };
512 
514 
516 
517 #endif
Specific type of the 3D images that hold real pixel data.
Definition: 3d/image.hh:148
T3DImage< uint32_t > C3DUIImage
3D image with unsigned 32 bit integer values
Definition: 3d/image.hh:489
std::vector< P3DImage > C3DImageSeries
helper type for image series
Definition: 3d/image.hh:138
range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end)
Definition: 3d/image.hh:324
EPixelType
Definition: pixeltype.hh:32
reference operator()(const C3DBounds &l)
element access operator - read/write
Definition: 3d/image.hh:283
virtual Pointer clone() const =0
C3DImage::Pointer P3DImage
define a shortcut to the 3D image shared pointer.
Definition: 3d/image.hh:134
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:273
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:319
A templated class of a 3D data field.
Definition: 3d/datafield.hh:82
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:313
base class for all filer type functors.
Definition: core/filter.hh:70
T3DImage< int32_t > C3DSIImage
3D image with signed 32 bit integer values
Definition: 3d/image.hh:486
This is the template version of a 2D image that is used for holding real data.
Definition: 2d/image.hh:138
#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:455
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
T3DImage< int8_t > C3DSBImage
3D image with signed 8 bit integer values
Definition: 3d/image.hh:474
C3DImage Super
define the super class of this class for generic processing
Definition: 3d/image.hh:151
functor to convert an image with an abitrary pixel type to single floating point pixels ...
Definition: 3d/image.hh:414
const_iterator end() const
constant iterator
Definition: 3d/image.hh:293
const_reference operator()(const C3DBounds &l) const
element access operator - read only
Definition: 3d/image.hh:278
const_reference operator()(size_t x, size_t y, size_t z) const
element access operator - read only
Definition: 3d/image.hh:268
iterator begin()
read/write iterator, issues copy-on-write
Definition: 3d/image.hh:344
T3DImage< double > C3DDImage
3D image with signed 64 bit floating point values
Definition: 3d/image.hh:501
T y
vector element
Definition: 3d/vector.hh:53
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:308
virtual std::pair< double, double > get_minmax_intensity() const =0
std::shared_ptr< C3DImageSeries > P3DImageSeries
Definition: 3d/image.hh:139
virtual const C3DBounds & get_size() const =0
C3DFVector get_gradient(int index) const
read/write access to the underlying data
Definition: 3d/image.hh:387
std::shared_ptr< C3DImage > Pointer
Pointer type of the image.
Definition: 3d/image.hh:73
const_reference operator[](int i) const
Definition: 3d/image.hh:364
T3DImage< uint8_t > C3DUBImage
3D image with unsigned 8 bit integer values
Definition: 3d/image.hh:477
const_range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end) const
Definition: 3d/image.hh:331
The generic base type of a 3D image.
Definition: 3d/image.hh:46
virtual const C3DBounds & get_size() const
E3DImageOrientation
Definition: orientation.hh:40
const_range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end) const
Definition: 3d/image.hh:336
C3DBounds dimsize_type
generic type for the dimension of the image
Definition: 3d/image.hh:70
T3DImage< bool > C3DBitImage
3D image with binary values
Definition: 3d/image.hh:471
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:354
iterator begin_at(size_t x, size_t y, size_t z)
read/write iterator starting at the given location
Definition: 3d/image.hh:359
iterator end()
read/write iterator, issues copy-on-write
Definition: 3d/image.hh:349
reference operator[](int i)
Definition: 3d/image.hh:372
T3DImage< uint16_t > C3DUSImage
3D image with unsigned 16 bit integer values
Definition: 3d/image.hh:483
static const char * data_descr
data type description for the plug-in path component
Definition: 3d/image.hh:67
T3DImage< int16_t > C3DSSImage
3D image with signed 16 bit integer values
Definition: 3d/image.hh:480
const_iterator begin() const
constant iterator
Definition: 3d/image.hh:288
CAttributedData & operator=(const CAttributedData &org)
Assignemt operator.
T3DImage< int64_t > C3DSLImage
3D image with signed 64 bit integer values
Definition: 3d/image.hh:492
::std::vector< typename __holder_type_dispatch< T >::type > data_array
type for the flat reprentation of the 2D data field
Definition: 2d/datafield.hh:94
T3DImage< uint64_t > C3DULImage
3D image with unsigned 64 bit integer values
Definition: 3d/image.hh:495
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:298
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:498
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:303
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36