My Project
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
39 # 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 
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 
92 public:
93 
95  typedef ::std::vector<typename __holder_type_dispatch<T>::type> data_array;
96 
97 
98 
100  typedef typename data_array::iterator iterator;
101  typedef typename data_array::const_iterator const_iterator;
102  typedef typename data_array::const_reference const_reference;
103  typedef typename data_array::reference reference;
104  typedef typename data_array::const_pointer const_pointer;
105  typedef typename data_array::pointer pointer;
106  typedef typename data_array::value_type value_type;
107  typedef typename data_array::difference_type difference_type;
108  typedef typename data_array::size_type size_type;
109  typedef range2d_iterator<iterator> range_iterator;
110  typedef range2d_iterator<const_iterator> const_range_iterator;
111  typedef range2d_iterator_with_boundary_flag<iterator> range_iterator_with_boundary_flag;
112  typedef range2d_iterator_with_boundary_flag<const_iterator> const_range_iterator_with_boundary_flag;
113 
114 
115 
116  typedef C2DBounds dimsize_type;
117  typedef C2DFVector coord_type;
119 
121  {
122  friend class T2DDatafield<T>;
123  friend class ConstRange;
124  public:
125 
127 
129 
131 
132  private:
133  Range(const C2DBounds& start, const C2DBounds& end, T2DDatafield<T>& field);
134 
135  iterator m_begin;
136  iterator m_end;
137  };
138 
140  {
141  public:
142  friend class T2DDatafield<T>;
143 
145 
146  iterator begin() const;
147 
148  iterator end() const;
149 
150  private:
151  ConstRange(const C2DBounds& start, const C2DBounds& end, const T2DDatafield<T>& field);
152 
153  ConstRange(const Range& range);
154 
155  iterator m_begin;
156  iterator m_end;
157  };
158 
159 
161 
166  explicit T2DDatafield(const C2DBounds& size);
167 
177  T2DDatafield(const C2DBounds& size, const T *_data);
178 
184  T2DDatafield(const C2DBounds& size, const std::vector<T>& data);
185 
190 
195 
198 
201 
202 
203  virtual ~T2DDatafield();
204 
205 
210  void make_single_ref() __attribute__((deprecated));
211 
213  const C2DBounds& get_size() const;
214 
218  void clear();
219 
227  const_reference operator()(size_t x, size_t y) const;
228 
234  reference operator()(size_t x, size_t y);
235 
244  const_reference operator[](size_t idx) const
245  {
246  return m_data[idx];
247  }
248 
257  reference operator[](size_t idx)
258  {
259  return m_data[idx];
260  }
261 
263  const_reference operator()(const C2DBounds& l) const;
264 
266  reference operator()(const C2DBounds& l);
267 
268 
274  void get_data_line_x(size_t y, std::vector<T>& buffer) const;
275 
281  void get_data_line_y(size_t x, std::vector<T>& buffer) const;
282 
289  void put_data_line_x(size_t y, const std::vector<T>& buffer);
290 
297  void put_data_line_y(size_t x, const std::vector<T>& buffer);
298 
300  size_type size() const;
301 
303  const_iterator begin()const
304  {
305  return m_data.begin();
306  }
307 
309  const_iterator end()const
310  {
311  return m_data.end();
312  }
313 
318  iterator begin()
319  {
320  return m_data.begin();
321  }
322 
328  iterator end()
329  {
330  return m_data.end();
331  }
332 
339  const_iterator begin_at(size_t x, size_t y)const
340  {
341  const_iterator b = begin();
342  advance(b, x + y * m_size.x);
343  return b;
344  }
345 
351  iterator begin_at(size_t x, size_t y)
352  {
353  iterator b = begin();
354  advance(b, x + y * m_size.x);
355  return b;
356  }
357 
358  Range get_range(const C2DBounds& start, const C2DBounds& end);
359 
360  ConstRange get_range(const C2DBounds& start, const C2DBounds& end) const;
361 
362 
365  range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end);
366 
368  range_iterator end_range(const C2DBounds& begin, const C2DBounds& end);
369 
370 
373  const_range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)const;
374 
376  const_range_iterator end_range(const C2DBounds& begin, const C2DBounds& end)const;
377 
378 
379 private:
380  C2DBounds m_size;
381  data_array m_data;
382  const static value_type Zero;
383 };
384 
387 
390 
393 
396 
398 
401 
404 
407 
410 
413 
416 
419 
422 
425 
427 
428 #define DEFINE_2DFIELD_TEMPLATE(TYPE) \
429  extern template class EXPORT_2D T2DDatafield<TYPE>; \
430  extern template class EXPORT_2D range2d_iterator<T2DDatafield<TYPE>::iterator>; \
431  extern template class EXPORT_2D range2d_iterator<T2DDatafield<TYPE>::const_iterator>; \
432  extern template class EXPORT_2D range2d_iterator_with_boundary_flag<T2DDatafield<TYPE>::iterator>; \
433  extern template class EXPORT_2D range2d_iterator_with_boundary_flag<T2DDatafield<TYPE>::const_iterator>;
434 
435 
436 #ifdef __GNUC__
437 #pragma GCC diagnostic push
438 #ifndef __clang__
439 #pragma GCC diagnostic ignored "-Wattributes"
440 #endif
441 #endif
442 
443 
444 DEFINE_2DFIELD_TEMPLATE(double);
445 DEFINE_2DFIELD_TEMPLATE(float);
446 DEFINE_2DFIELD_TEMPLATE(int64_t);
447 DEFINE_2DFIELD_TEMPLATE(uint64_t);
448 DEFINE_2DFIELD_TEMPLATE(uint32_t);
449 DEFINE_2DFIELD_TEMPLATE(int32_t);
450 DEFINE_2DFIELD_TEMPLATE(uint16_t);
451 DEFINE_2DFIELD_TEMPLATE(int16_t);
452 DEFINE_2DFIELD_TEMPLATE(uint8_t);
453 DEFINE_2DFIELD_TEMPLATE(int8_t);
454 
455 DEFINE_2DFIELD_TEMPLATE(C2DBounds);
456 DEFINE_2DFIELD_TEMPLATE(C2DFVector)
457 DEFINE_2DFIELD_TEMPLATE(C2DDVector)
458 
459 DECLARE_TYPE_DESCR(C2DBounds);
460 DECLARE_TYPE_DESCR(C2DFVector);
461 DECLARE_TYPE_DESCR(C2DDVector);
462 
463 #ifdef __GNUC__
464 #pragma GCC diagnostic pop
465 #endif
466 
467 
468 extern template class EXPORT_2D CTParameter<C2DFVector>;
469 extern template class EXPORT_2D CTParameter<C2DBounds>;
470 extern template class EXPORT_2D TTranslator<C2DFVector>;
471 extern template class EXPORT_2D TAttribute<C2DFVector>;
472 
474 
476 
477 #endif
478 
T2DDatafield< float > C2DFDatafield
2D scalar field that holds float values
T2DDatafield< int16_t > C2DSSDatafield
2D scalar field that holds signed short values
T2DDatafield< int32_t > C2DSIDatafield
2D scalar field that holds signed int values
T2DDatafield< uint8_t > C2DUBDatafield
2D scalar field that holds unsigned char (=byte) values
T2DDatafield< uint32_t > C2DUIDatafield
2D scalar field that holds unsigned int values
TTranslator< C2DFVector > C2DFVectorTranslator
typedef for the C2DFVector to std::string translator
T2DDatafield< double > C2DDDatafield
2D scalar field that holds double values
T2DDatafield< bool > C2DBitDatafield
2D scalar field that holds bool values
CTParameter< C2DBounds > C2DBoundsParameter
Parameter type for 2D size definitions.
CTParameter< C2DFVector > C2DFVectorParameter
Parameter type for 2D vector.
#define DECLARE_EXTERN_ITERATORS(TYPE)
Definition: 2d/datafield.hh:44
#define EXPORT_2DDATAFIELD
define used export 2D symbols
Definition: 2d/datafield.hh:39
T2DDatafield< uint16_t > C2DUSDatafield
2D scalar field that holds unsigned short values
T2DDatafield< uint64_t > C2DULDatafield
T2DDatafield< int64_t > C2DSLDatafield
long instanziation of a 2D data field
T2DDatafield< int8_t > C2DSBDatafield
2D scalar field that holds signed char values
Generic type of a complex paramter.
Definition: parameter.hh:171
iterator begin() const
T2DDatafield< T >::const_range_iterator iterator
iterator end() const
T2DDatafield< T >::range_iterator iterator
A class to hold data on a regular 2D grid.
Definition: 2d/datafield.hh:90
void put_data_line_x(size_t y, const std::vector< T > &buffer)
const C2DBounds & get_size() const
virtual ~T2DDatafield()
reference operator[](size_t idx)
const_range_iterator begin_range(const C2DBounds &begin, const C2DBounds &end) const
iterator begin()
void get_data_line_y(size_t x, std::vector< T > &buffer) const
const_iterator begin_at(size_t x, size_t y) const
T2DDatafield< T > & operator=(const T2DDatafield< T > &org)
reference operator()(const C2DBounds &l)
const_range_iterator end_range(const C2DBounds &begin, const C2DBounds &end) const
size_type size() const
iterator begin_at(size_t x, size_t y)
T2DDatafield(const T2DDatafield< T > &org)
::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
T2DDatafield(const C2DBounds &size)
T2DDatafield(T2DDatafield< T > &&org)
range_iterator begin_range(const C2DBounds &begin, const C2DBounds &end)
ConstRange get_range(const C2DBounds &start, const C2DBounds &end) const
iterator end()
const_iterator end() const
void put_data_line_y(size_t x, const std::vector< T > &buffer)
void get_data_line_x(size_t y, std::vector< T > &buffer) const
const_reference operator()(const C2DBounds &l) const
T2DDatafield(const C2DBounds &size, const std::vector< T > &data)
Range get_range(const C2DBounds &start, const C2DBounds &end)
T2DDatafield(const C2DBounds &size, const T *_data)
void make_single_ref() __attribute__((deprecated))
range_iterator end_range(const C2DBounds &begin, const C2DBounds &end)
const_iterator begin() const
Class of an attribute that holds data of type T.
Definition: attributes.hh:119
Generic string vs. attribute translator singleton.
Definition: attributes.hh:518
a 2D iterator that knows its position in the 2D grid ans supports iterating over sub-ranges
Definition: 2d/iterator.hh:43
#define EXPORT_2D
Definition: defines2d.hh:37
#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