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-2013 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 
75  typedef C2DBounds dimsize_type;
76  typedef C2DFVector coord_type;
78 
79  T2DDatafield();
80 
85  T2DDatafield(const C2DBounds& size);
86 
92  T2DDatafield(const C2DBounds& size, const T *_data);
93 
99  T2DDatafield(const C2DBounds& size, const data_array& data);
100 
105  T2DDatafield(const T2DDatafield<T>& org);
106 
112  T2DDatafield& operator = (const T2DDatafield& org);
113 
114  virtual ~T2DDatafield();
115 
116 
118  T get_interpol_val_at(const C2DFVector& p) const; // __attribute__((deprecated));
119 
124  void make_single_ref();
125 
127  const C2DBounds& get_size() const;
128 
133  void clear();
134 
142  const_reference operator()(size_t x, size_t y) const;
143 
149  reference operator()(size_t x, size_t y);
150 
159  const_reference operator[](size_t idx) const{
160  return (*m_data)[idx];
161  }
162 
171  reference operator[](size_t idx){
172  return (*m_data)[idx];
173  }
174 
176  const_reference operator()(const C2DBounds& l) const;
177 
179  reference operator()(const C2DBounds& l);
180 
181 
187  void get_data_line_x(size_t y, std::vector<T>& buffer) const;
188 
194  void get_data_line_y(size_t x, std::vector<T>& buffer) const;
195 
202  void put_data_line_x(size_t y, const std::vector<T>& buffer);
203 
210  void put_data_line_y(size_t x, const std::vector<T>& buffer);
211 
213  size_type size() const;
214 
216  const_iterator begin()const {
217  const data_array& data = *m_data;
218  return data.begin();
219  }
220 
222  const_iterator end()const {
223  const data_array& data = *m_data;
224  return data.end();
225  }
226 
231  iterator begin() {
232  make_single_ref();
233  return m_data->begin();
234  }
235 
241  iterator end() {
242  make_single_ref();
243  return m_data->end();
244  }
245 
252  const_iterator begin_at(size_t x, size_t y)const {
253 
254 
255  const_iterator b = begin();
256  advance(b, x + y * m_size.x);
257  return b;
258  }
259 
265  iterator begin_at(size_t x, size_t y) {
266  iterator b = begin();
267  advance(b, x + y * m_size.x);
268  return b;
269  }
270 
273  range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end);
274 
276  range_iterator end_range(const C2DBounds& begin, const C2DBounds& end);
277 
278 
281  const_range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)const;
282 
284  const_range_iterator end_range(const C2DBounds& begin, const C2DBounds& end)const;
285 
286 
287 private:
288  C2DBounds m_size;
289  data_pointer m_data;
290  const static T Zero;
291 };
292 
295 
298 
301 
304 
305 #ifdef LONG_64BIT
306 typedef T2DDatafield<unsigned long> C2DULDatafield;
307 
309 typedef T2DDatafield<signed long> C2DSLDatafield;
310 #endif
311 
314 
317 
320 
323 
326 
329 
332 
334 DECLARE_TYPE_DESCR(C2DBounds);
335 DECLARE_TYPE_DESCR(C2DFVector);
337 
339 
340 #endif
341 
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
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: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:52
a 2D iterator that knows its position in the 2D grid ans supports iterating over sub-ranges ...
Definition: 2d/iterator.hh:42
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