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-2014 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/typedescr.hh>
34 #include <miaconfig.h>
35 
36 #ifndef EXPORT_2DDATAFIELD
37 # define EXPORT_2DDATAFIELD EXPORT_2D
39 #endif
40 
42 
51 template <class T>
53 
54 public:
55 
57  typedef ::std::vector<T> data_array;
58 
60  typedef std::shared_ptr<data_array > data_pointer;
61 
63  typedef typename data_array::iterator iterator;
64  typedef typename data_array::const_iterator const_iterator;
65  typedef typename data_array::const_reference const_reference;
66  typedef typename data_array::reference reference;
67  typedef typename data_array::const_pointer const_pointer;
68  typedef typename data_array::pointer pointer;
69  typedef typename data_array::value_type value_type;
70  typedef typename data_array::difference_type difference_type;
71  typedef typename data_array::size_type size_type;
72  typedef range2d_iterator<iterator> range_iterator;
73  typedef range2d_iterator<const_iterator> const_range_iterator;
74  typedef range2d_iterator_with_boundary_flag<iterator> range_iterator_with_boundary_flag;
75  typedef range2d_iterator_with_boundary_flag<const_iterator> const_range_iterator_with_boundary_flag;
76 
77 
78 
79  typedef C2DBounds dimsize_type;
80  typedef C2DFVector coord_type;
82 
83  T2DDatafield();
84 
89  T2DDatafield(const C2DBounds& size);
90 
96  T2DDatafield(const C2DBounds& size, const T *_data);
97 
103  T2DDatafield(const C2DBounds& size, const data_array& data);
104 
109  T2DDatafield(const T2DDatafield<T>& org);
110 
116  T2DDatafield& operator = (const T2DDatafield& org);
117 
118  virtual ~T2DDatafield();
119 
120 
122  T get_interpol_val_at(const C2DFVector& p) const; // __attribute__((deprecated));
123 
128  void make_single_ref();
129 
131  const C2DBounds& get_size() const;
132 
137  void clear();
138 
146  const_reference operator()(size_t x, size_t y) const;
147 
153  reference operator()(size_t x, size_t y);
154 
163  const_reference operator[](size_t idx) const{
164  return (*m_data)[idx];
165  }
166 
175  reference operator[](size_t idx){
176  return (*m_data)[idx];
177  }
178 
180  const_reference operator()(const C2DBounds& l) const;
181 
183  reference operator()(const C2DBounds& l);
184 
185 
191  void get_data_line_x(size_t y, std::vector<T>& buffer) const;
192 
198  void get_data_line_y(size_t x, std::vector<T>& buffer) const;
199 
206  void put_data_line_x(size_t y, const std::vector<T>& buffer);
207 
214  void put_data_line_y(size_t x, const std::vector<T>& buffer);
215 
217  size_type size() const;
218 
220  const_iterator begin()const {
221  const data_array& data = *m_data;
222  return data.begin();
223  }
224 
226  const_iterator end()const {
227  const data_array& data = *m_data;
228  return data.end();
229  }
230 
235  iterator begin() {
236  make_single_ref();
237  return m_data->begin();
238  }
239 
245  iterator end() {
246  make_single_ref();
247  return m_data->end();
248  }
249 
256  const_iterator begin_at(size_t x, size_t y)const {
257 
258 
259  const_iterator b = begin();
260  advance(b, x + y * m_size.x);
261  return b;
262  }
263 
269  iterator begin_at(size_t x, size_t y) {
270  iterator b = begin();
271  advance(b, x + y * m_size.x);
272  return b;
273  }
274 
277  range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end);
278 
280  range_iterator end_range(const C2DBounds& begin, const C2DBounds& end);
281 
282 
285  const_range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)const;
286 
288  const_range_iterator end_range(const C2DBounds& begin, const C2DBounds& end)const;
289 
290 
291 private:
292  C2DBounds m_size;
293  data_pointer m_data;
294  const static T Zero;
295 };
296 
299 
302 
305 
308 
309 #ifdef LONG_64BIT
310 typedef T2DDatafield<unsigned long> C2DULDatafield;
311 
313 typedef T2DDatafield<signed long> C2DSLDatafield;
314 #endif
315 
318 
321 
324 
327 
330 
333 
336 
338 DECLARE_TYPE_DESCR(C2DBounds);
339 DECLARE_TYPE_DESCR(C2DFVector);
341 
343 
344 #endif
345 
T2DDatafield< unsigned short > C2DUSDatafield
2D scalar field that holds unsigned short values
const_iterator begin_at(size_t x, size_t y) const
const_reference operator[](size_t idx) const
iterator end()
#define EXPORT_2DDATAFIELD
define used export 2D symbols
Definition: 2d/datafield.hh:38
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:43
iterator begin_at(size_t x, size_t y)
CTParameter< C2DFVector > C2DFVectorParameter
Parameter type for 2D vector.
Generic type of a complex paramter.
Definition: parameter.hh:164
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:52
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
const_iterator begin() const
::std::vector< T > data_array
type for the flat reprentation of the 2D data field
Definition: 2d/datafield.hh:57
std::shared_ptr< data_array > data_pointer
pointer type
Definition: 2d/datafield.hh:60
T2DDatafield< signed char > C2DSBDatafield
2D scalar field that holds signed char values
T2DDatafield< double > C2DDDatafield
2D scalar field that holds double values
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:46