2d/datafield.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_2DDATAFIELD_HH
22 #define __MIA_2DDATAFIELD_HH 1
23 
24 
25 #include <vector>
26 #include <memory>
27 
28 // MIA specific
29 #include <mia/2d/defines2d.hh>
30 #include <mia/2d/vector.hh>
31 #include <mia/2d/iterator.hh>
32 #include <mia/core/parameter.hh>
33 #include <mia/core/attributes.hh>
34 #include <mia/core/typedescr.hh>
35 #include <miaconfig.h>
36 
37 #ifndef EXPORT_2DDATAFIELD
38 # define EXPORT_2DDATAFIELD EXPORT_2D
40 #endif
41 
43 
44 #define DECLARE_EXTERN_ITERATORS(TYPE) \
45  extern template class EXPORT_2D range2d_iterator<std::vector<TYPE>::iterator>; \
46  extern template class EXPORT_2D range2d_iterator<std::vector<TYPE>::const_iterator>; \
47  extern template class EXPORT_2D range2d_iterator_with_boundary_flag<std::vector<TYPE>::iterator>; \
48  extern template class EXPORT_2D range2d_iterator_with_boundary_flag<std::vector<TYPE>::const_iterator>;
49 
50 #ifdef __GNUC__
51 #pragma GCC diagnostic push
52 #ifndef __clang__
53 #pragma GCC diagnostic ignored "-Wattributes"
54 #endif
55 #endif
56 
59 DECLARE_EXTERN_ITERATORS(uint32_t);
62 DECLARE_EXTERN_ITERATORS(uint16_t);
67 DECLARE_EXTERN_ITERATORS(uint64_t);
68 
72 
73 #undef DECLARE_EXTERN_ITERATORS
74 
75 #ifdef __GNUC__
76 #pragma GCC diagnostic pop
77 #endif
78 
79 
88 template <class T>
90 
91 public:
92 
94  typedef ::std::vector<typename __holder_type_dispatch<T>::type> data_array;
95 
96 
97 
99  typedef typename data_array::iterator iterator;
100  typedef typename data_array::const_iterator const_iterator;
101  typedef typename data_array::const_reference const_reference;
102  typedef typename data_array::reference reference;
103  typedef typename data_array::const_pointer const_pointer;
104  typedef typename data_array::pointer pointer;
105  typedef typename data_array::value_type value_type;
106  typedef typename data_array::difference_type difference_type;
107  typedef typename data_array::size_type size_type;
108  typedef range2d_iterator<iterator> range_iterator;
109  typedef range2d_iterator<const_iterator> const_range_iterator;
110  typedef range2d_iterator_with_boundary_flag<iterator> range_iterator_with_boundary_flag;
111  typedef range2d_iterator_with_boundary_flag<const_iterator> const_range_iterator_with_boundary_flag;
112 
113 
114 
115  typedef C2DBounds dimsize_type;
116  typedef C2DFVector coord_type;
118 
120  friend class T2DDatafield<T>;
121  friend class ConstRange;
122  public:
123 
125 
126  iterator begin();
127 
128  iterator end();
129 
130  private:
131  Range(const C2DBounds& start, const C2DBounds& end, T2DDatafield<T>& field);
132 
133  iterator m_begin;
134  iterator m_end;
135  };
136 
138  public:
139  friend class T2DDatafield<T>;
140 
142 
143  iterator begin() const;
144 
145  iterator end() const;
146 
147  private:
148  ConstRange(const C2DBounds& start, const C2DBounds& end, const T2DDatafield<T>& field);
149 
150  ConstRange(const Range& range);
151 
152  iterator m_begin;
153  iterator m_end;
154  };
155 
156 
157  T2DDatafield();
158 
163  explicit T2DDatafield(const C2DBounds& size);
164 
174  T2DDatafield(const C2DBounds& size, const T *_data);
175 
181  T2DDatafield(const C2DBounds& size, const std::vector<T>& data);
182 
186  T2DDatafield(const T2DDatafield<T>& org);
187 
192 
195 
198 
199 
200  virtual ~T2DDatafield();
201 
202 
207  void make_single_ref() __attribute__((deprecated));
208 
210  const C2DBounds& get_size() const;
211 
215  void clear();
216 
224  const_reference operator()(size_t x, size_t y) const;
225 
231  reference operator()(size_t x, size_t y);
232 
241  const_reference operator[](size_t idx) const{
242  return m_data[idx];
243  }
244 
253  reference operator[](size_t idx){
254  return m_data[idx];
255  }
256 
258  const_reference operator()(const C2DBounds& l) const;
259 
261  reference operator()(const C2DBounds& l);
262 
263 
269  void get_data_line_x(size_t y, std::vector<T>& buffer) const;
270 
276  void get_data_line_y(size_t x, std::vector<T>& buffer) const;
277 
284  void put_data_line_x(size_t y, const std::vector<T>& buffer);
285 
292  void put_data_line_y(size_t x, const std::vector<T>& buffer);
293 
295  size_type size() const;
296 
298  const_iterator begin()const {
299  return m_data.begin();
300  }
301 
303  const_iterator end()const {
304  return m_data.end();
305  }
306 
311  iterator begin() {
312  return m_data.begin();
313  }
314 
320  iterator end() {
321  return m_data.end();
322  }
323 
330  const_iterator begin_at(size_t x, size_t y)const {
331 
332 
333  const_iterator b = begin();
334  advance(b, x + y * m_size.x);
335  return b;
336  }
337 
343  iterator begin_at(size_t x, size_t y) {
344  iterator b = begin();
345  advance(b, x + y * m_size.x);
346  return b;
347  }
348 
349  Range get_range(const C2DBounds& start, const C2DBounds& end);
350 
351  ConstRange get_range(const C2DBounds& start, const C2DBounds& end) const;
352 
353 
356  range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end);
357 
359  range_iterator end_range(const C2DBounds& begin, const C2DBounds& end);
360 
361 
364  const_range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)const;
365 
367  const_range_iterator end_range(const C2DBounds& begin, const C2DBounds& end)const;
368 
369 
370 private:
371  C2DBounds m_size;
372  data_array m_data;
373  const static value_type Zero;
374 };
375 
378 
381 
384 
387 
389 
392 
395 
398 
401 
404 
407 
410 
413 
416 
418 
419 #define DEFINE_2DFIELD_TEMPLATE(TYPE) \
420  extern template class EXPORT_2D T2DDatafield<TYPE>; \
421  extern template class EXPORT_2D range2d_iterator<T2DDatafield<TYPE>::iterator>; \
422  extern template class EXPORT_2D range2d_iterator<T2DDatafield<TYPE>::const_iterator>; \
423  extern template class EXPORT_2D range2d_iterator_with_boundary_flag<T2DDatafield<TYPE>::iterator>; \
424  extern template class EXPORT_2D range2d_iterator_with_boundary_flag<T2DDatafield<TYPE>::const_iterator>;
425 
426 
427 #ifdef __GNUC__
428 #pragma GCC diagnostic push
429 #ifndef __clang__
430 #pragma GCC diagnostic ignored "-Wattributes"
431 #endif
432 #endif
433 
434 
435 DEFINE_2DFIELD_TEMPLATE(double);
436 DEFINE_2DFIELD_TEMPLATE(float);
437 DEFINE_2DFIELD_TEMPLATE(int64_t);
438 DEFINE_2DFIELD_TEMPLATE(uint64_t);
439 DEFINE_2DFIELD_TEMPLATE(uint32_t);
440 DEFINE_2DFIELD_TEMPLATE(int32_t);
441 DEFINE_2DFIELD_TEMPLATE(uint16_t);
442 DEFINE_2DFIELD_TEMPLATE(int16_t);
443 DEFINE_2DFIELD_TEMPLATE(uint8_t);
444 DEFINE_2DFIELD_TEMPLATE(int8_t);
445 
446 DEFINE_2DFIELD_TEMPLATE(C2DBounds);
447 DEFINE_2DFIELD_TEMPLATE(C2DFVector)
448 DEFINE_2DFIELD_TEMPLATE(C2DDVector)
449 
450 DECLARE_TYPE_DESCR(C2DBounds);
451 DECLARE_TYPE_DESCR(C2DFVector);
452 DECLARE_TYPE_DESCR(C2DDVector);
453 
454 #ifdef __GNUC__
455 #pragma GCC diagnostic pop
456 #endif
457 
458 
459 extern template class EXPORT_2D CTParameter<C2DFVector>;
460 extern template class EXPORT_2D CTParameter<C2DBounds>;
461 extern template class EXPORT_2D TTranslator<C2DFVector>;
462 extern template class EXPORT_2D TAttribute<C2DFVector>;
463 
465 
467 
468 #endif
469 
TTranslator< C2DFVector > C2DFVectorTranslator
typedef for the C2DFVector to std::string translator
void put_data_line_x(size_t y, const std::vector< T > &buffer)
const_iterator begin_at(size_t x, size_t y) const
T2DDatafield< int8_t > C2DSBDatafield
2D scalar field that holds signed char values
void put_data_line_y(size_t x, const std::vector< T > &buffer)
Generic string vs. attribute translator singleton.
Definition: attributes.hh:509
range_iterator end_range(const C2DBounds &begin, const C2DBounds &end)
T2DDatafield< uint16_t > C2DUSDatafield
2D scalar field that holds unsigned short values
T2DDatafield< T > & operator=(const T2DDatafield< T > &org)
iterator end()
const_iterator begin() const
#define EXPORT_2DDATAFIELD
define used export 2D symbols
Definition: 2d/datafield.hh:39
T2DDatafield< bool > C2DBitDatafield
2D scalar field that holds bool values
a 2D iterator that knows its position in the 2D grid ans supports iterating over sub-ranges ...
Definition: 2d/iterator.hh:42
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
iterator begin_at(size_t x, size_t y)
size_type size() const
T2DDatafield< int32_t > C2DSIDatafield
2D scalar field that holds signed int values
T2DDatafield< int16_t > C2DSSDatafield
2D scalar field that holds signed short values
const_iterator end() const
void make_single_ref() __attribute__((deprecated))
T2DDatafield< T >::range_iterator iterator
T2DDatafield< uint32_t > C2DUIDatafield
2D scalar field that holds unsigned int values
range_iterator begin_range(const C2DBounds &begin, const C2DBounds &end)
#define EXPORT_2D
Definition: defines2d.hh:37
CTParameter< C2DFVector > C2DFVectorParameter
Parameter type for 2D vector.
Generic type of a complex paramter.
Definition: parameter.hh:169
const C2DBounds & get_size() const
T2DDatafield< uint8_t > C2DUBDatafield
2D scalar field that holds unsigned char (=byte) values
CTParameter< C2DBounds > C2DBoundsParameter
Parameter type for 2D size definitions.
A class to hold data on a regular 2D grid.
Definition: 2d/datafield.hh:89
iterator begin()
#define DECLARE_EXTERN_ITERATORS(TYPE)
Definition: 2d/datafield.hh:44
T2DDatafield< float > C2DFDatafield
2D scalar field that holds float values
reference operator[](size_t idx)
virtual ~T2DDatafield()
T2DDatafield< T >::const_range_iterator iterator
::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
T2DDatafield< uint64_t > C2DULDatafield
T2DDatafield< int64_t > C2DSLDatafield
long instanziation of a 2D data field
void get_data_line_x(size_t y, std::vector< T > &buffer) const
const_reference operator()(size_t x, size_t y) const
Class of an attribute that holds data of type T.
Definition: attributes.hh:116
T2DDatafield< double > C2DDDatafield
2D scalar field that holds double values
Range get_range(const C2DBounds &start, const C2DBounds &end)
void get_data_line_y(size_t x, std::vector< T > &buffer) const
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36