My Project
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{
48protected:
56
61 explicit C3DImage(EPixelType type);
62
63
66public:
68 static const char *data_descr;
69
72
74 typedef std::shared_ptr<C3DImage > Pointer;
75
76 virtual ~C3DImage();
77
82
83
87 virtual size_t size() const = 0;
88
92 virtual const C3DBounds& get_size() const = 0;
93
97 virtual Pointer clone() const = 0;
98
101
103 void set_voxel_size(const C3DFVector& voxel);
104
105
108
110 void set_origin(const C3DFVector& voxel);
111
112
115
117 void set_rotation(const C3DRotation& voxel);
118
121
127
129 virtual std::pair<double, double> get_minmax_intensity() const = 0;
130private:
131 EPixelType m_pixel_type;
132};
133
136
137
139typedef std::vector<P3DImage> C3DImageSeries;
140typedef std::shared_ptr<C3DImageSeries> P3DImageSeries;
141
148template <typename T>
150{
151public:
154
156 typedef typename T3DDatafield<T>::iterator iterator;
157 typedef typename T3DDatafield<T>::const_iterator const_iterator;
158 typedef typename T3DDatafield<T>::const_reference const_reference;
159 typedef typename T3DDatafield<T>::reference reference;
160 typedef typename T3DDatafield<T>::const_pointer const_pointer;
161 typedef typename T3DDatafield<T>::pointer pointer;
162 typedef typename T3DDatafield<T>::value_type value_type;
163 typedef typename T3DDatafield<T>::difference_type difference_type;
164 typedef typename T3DDatafield<T>::size_type size_type;
165 typedef typename T3DDatafield<T>::range_iterator range_iterator;
166 typedef typename T3DDatafield<T>::const_range_iterator const_range_iterator;
167 typedef typename T3DDatafield<T>::range_iterator_with_boundary_flag range_iterator_with_boundary_flag;
168 typedef typename T3DDatafield<T>::const_range_iterator_with_boundary_flag const_range_iterator_with_boundary_flag;
169
170 typedef typename T2DDatafield<T>::data_array data_array;
172
178 T3DImage(const C3DBounds& size, const T *init_data);
179
185 T3DImage(const C3DBounds& size, const CAttributedData& attr);
186
187
188 T3DImage(const C3DBounds& size, const data_array& init_data);
193 explicit T3DImage(const C3DBounds& size);
194
195 //T3DImage(const T3DDatafield<T>& size);
196
200 T3DImage(const T3DImage<T>& orig);
201
206
211
216
221 explicit T3DImage(const T3DDatafield<T>& orig);
222
227
228
230 virtual Pointer clone() const;
231
233 void get_data_line_x(int y, int z, std::vector<T>& buffer)const;
234
236 void get_data_line_y(int x, int z, std::vector<T>& buffer)const;
237
239 void get_data_line_z(int x, int y, std::vector<T>& buffer)const;
240
242 void put_data_line_x(int y, int z, const std::vector<T>& buffer);
243
245 void put_data_line_y(int x, int z, const std::vector<T>& buffer);
246
248 void put_data_line_z(int x, int y, const std::vector<T>& buffer);
249
252
255
258
260 void put_data_plane_xy(size_t z, const T2DImage<T>& p);
261
263 void put_data_plane_yz(size_t x, const T2DImage<T>& p);
264
266 void put_data_plane_xz(size_t y, const T2DImage<T>& p);
267
268
270 const_reference operator()(size_t x, size_t y, size_t z) const
271 {
272 return m_image(x, y, z);
273 }
274
276 reference operator()(size_t x, size_t y, size_t z)
277 {
278 return m_image(x, y, z);
279 }
280
282 const_reference operator()(const C3DBounds& l) const
283 {
284 return m_image(l.x, l.y, l.z);
285 }
286
288 reference operator()(const C3DBounds& l)
289 {
290 return m_image(l.x, l.y, l.z);
291 }
292
294 const_iterator begin()const
295 {
296 return m_image.begin();
297 }
298
300 const_iterator end()const
301 {
302 return m_image.end();
303 }
304
306 range_iterator begin_range(const C3DBounds& begin, const C3DBounds& end)
307 {
308 return m_image.begin_range(begin, end);
309 }
310
312 range_iterator end_range(const C3DBounds& begin, const C3DBounds& end)
313 {
314 return m_image.end_range(begin, end);
315 }
316
318 const_range_iterator begin_range(const C3DBounds& begin, const C3DBounds& end)const
319 {
320 return m_image.begin_range(begin, end);
321 }
322
324 const_range_iterator end_range(const C3DBounds& begin, const C3DBounds& end) const
325 {
326 return m_image.end_range(begin, end);
327 }
328
329
331 range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end)
332 {
333 return m_image.begin_range_with_boundary_flags(begin, end);
334 }
335
337 range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end)
338 {
339 return m_image.end_range_with_boundary_flags(begin, end);
340 }
341
342
345 const_range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end)const
346 {
347 return m_image.begin_range_with_boundary_flags(begin, end);
348 }
349
351 const_range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds& begin, const C3DBounds& end)const
352 {
353 return m_image.end_range_with_boundary_flags(begin, end);
354 }
355
357 size_t size() const;
358
360 iterator begin()
361 {
362 return m_image.begin();
363 }
364
366 iterator end()
367 {
368 return m_image.end();
369 }
370
372 const_iterator begin_at(size_t x, size_t y, size_t z) const
373 {
374 return m_image.begin_at(x, y, z);
375 }
376
378 iterator begin_at(size_t x, size_t y, size_t z)
379 {
380 return m_image.begin_at(x, y, z);
381 }
382
384 const_reference operator[](int i)const
385 {
386 return m_image[i];
387 }
388
392 reference operator[](int i)
393 {
394 return m_image[i];
395 }
396
398 const T3DDatafield<T>& data() const;
399
401 //T3DDatafield<T>& data();
402
407 C3DFVector get_gradient(int index) const
408 {
409 return m_image.template get_gradient<float>(index);
410 }
411
413 virtual const C3DBounds& get_size() const;
414
416 std::pair<double, double> get_minmax_intensity() const;
417private:
418 T3DDatafield<T> m_image;
419};
420
421
433template <typename O>
434struct FConvert3DImageToPixeltypeO: public TFilter<T3DImage<O>> {
435
441 template <typename T>
443 {
444 T3DImage<O> result(image.get_size(), image);
445 copy(image.begin(), image.end(), result.begin());
446 return result;
447 }
448
456 {
457 return filter(*this, image);
458 }
459
467 {
468 return filter(*this, *image);
469 }
470};
471
479
480
491
492
495
498
501
504
507
510
513
516
519
522
525
531template <>
532struct Binder<C3DImage> {
533 typedef __bind_all<T3DImage> Derived;
534};
535
537
539
540#endif
std::shared_ptr< C3DImageSeries > P3DImageSeries
Definition: 3d/image.hh:140
T3DImage< int64_t > C3DSLImage
3D image with signed 64 bit integer values
Definition: 3d/image.hh:515
FConvert3DImageToPixeltypeO< float > FCopy3DImageToFloatRepn
short name for 3DImage to float pixel repn copy functor
Definition: 3d/image.hh:478
T3DImage< uint16_t > C3DUSImage
3D image with unsigned 16 bit integer values
Definition: 3d/image.hh:506
T3DImage< uint8_t > C3DUBImage
3D image with unsigned 8 bit integer values
Definition: 3d/image.hh:500
T3DImage< int32_t > C3DSIImage
3D image with signed 32 bit integer values
Definition: 3d/image.hh:509
T3DImage< float > C3DFImage
3D image with signed 32 bit floating point values
Definition: 3d/image.hh:521
T3DImage< uint64_t > C3DULImage
3D image with unsigned 64 bit integer values
Definition: 3d/image.hh:518
std::vector< P3DImage > C3DImageSeries
helper type for image series
Definition: 3d/image.hh:139
T3DImage< double > C3DDImage
3D image with signed 64 bit floating point values
Definition: 3d/image.hh:524
T3DImage< bool > C3DBitImage
3D image with binary values
Definition: 3d/image.hh:494
T3DImage< int16_t > C3DSSImage
3D image with signed 16 bit integer values
Definition: 3d/image.hh:503
T3DImage< int8_t > C3DSBImage
3D image with signed 8 bit integer values
Definition: 3d/image.hh:497
T3DImage< uint32_t > C3DUIImage
3D image with unsigned 32 bit integer values
Definition: 3d/image.hh:512
C3DImage::Pointer P3DImage
define a shortcut to the 3D image shared pointer.
Definition: 3d/image.hh:135
a 3D field of floating point single accuracy 3D vectors
The generic base type of a 3D image.
Definition: 3d/image.hh:47
virtual std::pair< double, double > get_minmax_intensity() const =0
static const char * data_descr
data type description for the plug-in path component
Definition: 3d/image.hh:68
C3DRotation get_rotation() const
E3DImageOrientation get_orientation() const
C3DFVector get_voxel_size() const
void set_voxel_size(const C3DFVector &voxel)
set the voxel size on world units
virtual ~C3DImage()
void set_rotation(const C3DRotation &voxel)
set the rotation about the origin of the image
EPixelType get_pixel_type() const
void set_orientation(E3DImageOrientation orient)
C3DImage(EPixelType type)
virtual Pointer clone() const =0
virtual const C3DBounds & get_size() const =0
std::shared_ptr< C3DImage > Pointer
Pointer type of the image.
Definition: 3d/image.hh:74
void set_origin(const C3DFVector &voxel)
set the origin i.e. world units of the pixel at (0,0,0)
C3DImage(const CAttributedData &data, EPixelType type)
C3DFVector get_origin() const
virtual size_t size() const =0
C3DBounds dimsize_type
generic type for the dimension of the image
Definition: 3d/image.hh:71
C3DImage()
standard constructor
A collection of attributes.
Definition: attributes.hh:260
CAttributedData & operator=(const CAttributedData &org)
Assignemt operator.
::std::vector< typename __holder_type_dispatch< T >::type > data_array
type for the flat reprentation of the 2D data field
Definition: 2d/datafield.hh:95
This is the template version of a 2D image that is used for holding real data.
Definition: 2d/image.hh:140
A templated class of a 3D data field.
Definition: 3d/datafield.hh:83
Specific type of the 3D images that hold real pixel data.
Definition: 3d/image.hh:150
void put_data_line_z(int x, int y, const std::vector< T > &buffer)
void put_data_line_y(int x, int z, const std::vector< T > &buffer)
void put_data_line_x(int y, int z, const std::vector< T > &buffer)
void put_data_plane_xy(size_t z, const T2DImage< T > &p)
forwarding function to access the underlying T3DDatafield
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:318
void get_data_line_y(int x, int z, std::vector< T > &buffer) const
void get_data_line_z(int x, int y, std::vector< T > &buffer) const
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:306
const_iterator begin() const
constant iterator
Definition: 3d/image.hh:294
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:324
iterator begin()
read/write iterator, issues copy-on-write
Definition: 3d/image.hh:360
T2DImage< T > get_data_plane_xz(size_t y) const
forwarding function to access the underlying T3DDatafield
T3DImage(const C3DBounds &size, const T *init_data)
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:372
reference operator()(const C3DBounds &l)
element access operator - read/write
Definition: 3d/image.hh:288
T3DImage(const C3DBounds &size, const data_array &init_data)
T2DImage< T > get_data_plane_xy(size_t z) const
forwarding function to access the underlying T3DDatafield
T3DImage(const T3DImage< T > &orig)
const_range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end) const
Definition: 3d/image.hh:345
range_iterator_with_boundary_flag begin_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end)
Definition: 3d/image.hh:331
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:312
virtual const C3DBounds & get_size() const
reference operator[](int i)
Definition: 3d/image.hh:392
T2DImage< T > get_data_plane_yz(size_t x) const
forwarding function to access the underlying T3DDatafield
T3DImage(const C3DBounds &size)
const_reference operator[](int i) const
Definition: 3d/image.hh:384
void put_data_plane_xz(size_t y, const T2DImage< T > &p)
forwarding function to access the underlying T3DDatafield
void put_data_plane_yz(size_t x, const T2DImage< T > &p)
forwarding function to access the underlying T3DDatafield
T3DImage(const C3DBounds &size, const CAttributedData &attr)
void get_data_line_x(int y, int z, std::vector< T > &buffer) const
const_reference operator()(size_t x, size_t y, size_t z) const
element access operator - read only
Definition: 3d/image.hh:270
iterator end()
read/write iterator, issues copy-on-write
Definition: 3d/image.hh:366
C3DImage Super
define the super class of this class for generic processing
Definition: 3d/image.hh:153
T3DImage(const T3DDatafield< T > &orig)
const T3DDatafield< T > & data() const
read only access to the underlying data
const_iterator end() const
constant iterator
Definition: 3d/image.hh:300
iterator begin_at(size_t x, size_t y, size_t z)
read/write iterator starting at the given location
Definition: 3d/image.hh:378
size_t size() const
C3DFVector get_gradient(int index) const
read/write access to the underlying data
Definition: 3d/image.hh:407
reference operator()(size_t x, size_t y, size_t z)
element access operator - read/write
Definition: 3d/image.hh:276
const_reference operator()(const C3DBounds &l) const
element access operator - read only
Definition: 3d/image.hh:282
std::pair< double, double > get_minmax_intensity() const
virtual Pointer clone() const
range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end)
Definition: 3d/image.hh:337
const_range_iterator_with_boundary_flag end_range_with_boundary_flags(const C3DBounds &begin, const C3DBounds &end) const
Definition: 3d/image.hh:351
T3DImage(T3DImage< T > &&orig)
T y
vector element
Definition: 3d/vector.hh:54
T z
vector element
Definition: 3d/vector.hh:56
T x
vector element
Definition: 3d/vector.hh:52
#define EXPORT_3D
Definition: defines3d.hh:45
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
EXPORT_3D C3DFVectorfield get_gradient(const C3DImage &image)
E3DImageOrientation
Definition: orientation.hh:40
static F::result_type filter(const F &f, const B &b)
Definition: core/filter.hh:258
EPixelType
Definition: pixeltype.hh:33
functor to convert an image with an abitrary pixel type to single floating point pixels
Definition: 3d/image.hh:434
T3DImage< O > operator()(const T3DImage< T > &image) const
Definition: 3d/image.hh:442
base class for all filer type functors.
Definition: core/filter.hh:70