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