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-2016 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 
52 template <class T>
54 
55 public:
56 
58  typedef ::std::vector<typename __holder_type_dispatch<T>::type> data_array;
59 
61  typedef std::shared_ptr<data_array > data_pointer;
62 
64  typedef typename data_array::iterator iterator;
65  typedef typename data_array::const_iterator const_iterator;
66  typedef typename data_array::const_reference const_reference;
67  typedef typename data_array::reference reference;
68  typedef typename data_array::const_pointer const_pointer;
69  typedef typename data_array::pointer pointer;
70  typedef typename data_array::value_type value_type;
71  typedef typename data_array::difference_type difference_type;
72  typedef typename data_array::size_type size_type;
73  typedef range2d_iterator<iterator> range_iterator;
74  typedef range2d_iterator<const_iterator> const_range_iterator;
75  typedef range2d_iterator_with_boundary_flag<iterator> range_iterator_with_boundary_flag;
76  typedef range2d_iterator_with_boundary_flag<const_iterator> const_range_iterator_with_boundary_flag;
77 
78 
79 
80  typedef C2DBounds dimsize_type;
81  typedef C2DFVector coord_type;
83 
84  T2DDatafield();
85 
90  T2DDatafield(const C2DBounds& size);
91 
97  T2DDatafield(const C2DBounds& size, const T *_data);
98 
104  T2DDatafield(const C2DBounds& size, const std::vector<T>& data);
105 
110  T2DDatafield(const T2DDatafield<T>& org);
111 
117  T2DDatafield& operator = (const T2DDatafield& org);
118 
119  virtual ~T2DDatafield();
120 
121 
123  T get_interpol_val_at(const C2DFVector& p) const; // __attribute__((deprecated));
124 
129  void make_single_ref();
130 
132  const C2DBounds& get_size() const;
133 
138  void clear();
139 
147  const_reference operator()(size_t x, size_t y) const;
148 
154  reference operator()(size_t x, size_t y);
155 
164  const_reference operator[](size_t idx) const{
165  return (*m_data)[idx];
166  }
167 
176  reference operator[](size_t idx){
177  return (*m_data)[idx];
178  }
179 
181  const_reference operator()(const C2DBounds& l) const;
182 
184  reference operator()(const C2DBounds& l);
185 
186 
192  void get_data_line_x(size_t y, std::vector<T>& buffer) const;
193 
199  void get_data_line_y(size_t x, std::vector<T>& buffer) const;
200 
207  void put_data_line_x(size_t y, const std::vector<T>& buffer);
208 
215  void put_data_line_y(size_t x, const std::vector<T>& buffer);
216 
218  size_type size() const;
219 
221  const_iterator begin()const {
222  const data_array& data = *m_data;
223  return data.begin();
224  }
225 
227  const_iterator end()const {
228  const data_array& data = *m_data;
229  return data.end();
230  }
231 
236  iterator begin() {
237  make_single_ref();
238  return m_data->begin();
239  }
240 
246  iterator end() {
247  make_single_ref();
248  return m_data->end();
249  }
250 
257  const_iterator begin_at(size_t x, size_t y)const {
258 
259 
260  const_iterator b = begin();
261  advance(b, x + y * m_size.x);
262  return b;
263  }
264 
270  iterator begin_at(size_t x, size_t y) {
271  iterator b = begin();
272  advance(b, x + y * m_size.x);
273  return b;
274  }
275 
278  range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end);
279 
281  range_iterator end_range(const C2DBounds& begin, const C2DBounds& end);
282 
283 
286  const_range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)const;
287 
289  const_range_iterator end_range(const C2DBounds& begin, const C2DBounds& end)const;
290 
291 
292 private:
293  C2DBounds m_size;
294  data_pointer m_data;
295  const static value_type Zero;
296 };
297 
300 
303 
306 
309 
310 #ifdef LONG_64BIT
311 typedef T2DDatafield<unsigned long> C2DULDatafield;
312 
314 typedef T2DDatafield<signed long> C2DSLDatafield;
315 #endif
316 
319 
322 
325 
328 
331 
334 
337 
340 
342 
343 #define DEFINE_2DFIELD_TEMPLATE(TYPE) \
344  extern template class EXPORT_2D EXPORT_2D T2DDatafield<TYPE>; \
345  extern template class EXPORT_2D range2d_iterator<T2DDatafield<TYPE>::iterator>; \
346  extern template class EXPORT_2D range2d_iterator<T2DDatafield<TYPE>::const_iterator>; \
347  extern template class EXPORT_2D range2d_iterator_with_boundary_flag<T2DDatafield<TYPE>::iterator>; \
348  extern template class EXPORT_2D range2d_iterator_with_boundary_flag<T2DDatafield<TYPE>::const_iterator>;
349 
350 DEFINE_2DFIELD_TEMPLATE(float);
351 
352 #ifdef LONG_64BIT
353 DEFINE_2DFIELD_TEMPLATE(signed long);
354 DEFINE_2DFIELD_TEMPLATE(unsigned long);
355 #endif
356 DEFINE_2DFIELD_TEMPLATE(double);
357 DEFINE_2DFIELD_TEMPLATE(unsigned int);
358 DEFINE_2DFIELD_TEMPLATE(signed int);
359 DEFINE_2DFIELD_TEMPLATE(unsigned short);
360 DEFINE_2DFIELD_TEMPLATE(signed short);
361 DEFINE_2DFIELD_TEMPLATE(unsigned char);
362 DEFINE_2DFIELD_TEMPLATE(signed char);
363 
364 
365 DECLARE_TYPE_DESCR(C2DBounds);
366 DECLARE_TYPE_DESCR(C2DFVector);
367 
368 extern template class EXPORT_2D CTParameter<C2DFVector>;
369 extern template class EXPORT_2D CTParameter<C2DBounds>;
370 extern template class EXPORT_2D TTranslator<C2DFVector>;
371 extern template class EXPORT_2D TAttribute<C2DFVector>;
372 
374 
376 
377 #endif
378 
T2DDatafield< unsigned short > C2DUSDatafield
2D scalar field that holds unsigned short values
TTranslator< C2DFVector > C2DFVectorTranslator
typedef for the C2DFVector to std::string translator
const_iterator begin_at(size_t x, size_t y) const
Generic string vs. attribute translator singleton.
Definition: attributes.hh:509
const_reference operator[](size_t idx) const
iterator end()
#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
T2DDatafield< signed int > C2DSIDatafield
2D scalar field that holds signed int values
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
iterator begin_at(size_t x, size_t y)
#define EXPORT_2D
Definition: defines2d.hh:37
CTParameter< C2DFVector > C2DFVectorParameter
Parameter type for 2D vector.
Generic type of a complex paramter.
Definition: parameter.hh:163
T2DDatafield< unsigned int > C2DUIDatafield
2D scalar field that holds unsigned int values
T2DDatafield< unsigned char > 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:53
iterator begin()
T2DDatafield< float > C2DFDatafield
2D scalar field that holds float values
T2DDatafield< signed short > C2DSSDatafield
2D scalar field that holds signed short values
reference operator[](size_t idx)
const_iterator end() const
::std::vector< typename __holder_type_dispatch< T >::type > data_array
type for the flat reprentation of the 2D data field
Definition: 2d/datafield.hh:58
const_iterator begin() const
std::shared_ptr< data_array > data_pointer
pointer type
Definition: 2d/datafield.hh:61
T2DDatafield< signed char > C2DSBDatafield
2D scalar field that holds signed char values
Class of an attribute that holds data of type T.
Definition: attributes.hh:116
T2DDatafield< double > C2DDDatafield
2D scalar field that holds double values
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36