2d/datafield.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __MIA_2DDATAFIELD_HH
#define __MIA_2DDATAFIELD_HH 1
#include <vector>
#include <memory>
// MIA specific
#include <mia/2d/defines2d.hh>
#include <mia/2d/vector.hh>
#include <mia/2d/iterator.hh>
#include <mia/core/parameter.hh>
#include <mia/core/attributes.hh>
#include <mia/core/typedescr.hh>
#include <miaconfig.h>
#ifndef EXPORT_2DDATAFIELD
# define EXPORT_2DDATAFIELD EXPORT_2D
#endif
NS_MIA_BEGIN
#define DECLARE_EXTERN_ITERATORS(TYPE) \
extern template class EXPORT_2D range2d_iterator<std::vector<TYPE>::iterator>; \
extern template class EXPORT_2D range2d_iterator<std::vector<TYPE>::const_iterator>; \
extern template class EXPORT_2D range2d_iterator_with_boundary_flag<std::vector<TYPE>::iterator>; \
extern template class EXPORT_2D range2d_iterator_with_boundary_flag<std::vector<TYPE>::const_iterator>;
#ifdef __GNUC__
#pragma GCC diagnostic push
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wattributes"
#endif
#endif
DECLARE_EXTERN_ITERATORS(double);
DECLARE_EXTERN_ITERATORS(float);
DECLARE_EXTERN_ITERATORS(uint32_t);
DECLARE_EXTERN_ITERATORS(int32_t);
DECLARE_EXTERN_ITERATORS(int16_t);
DECLARE_EXTERN_ITERATORS(uint16_t);
DECLARE_EXTERN_ITERATORS(int8_t);
DECLARE_EXTERN_ITERATORS(uint8_t);
DECLARE_EXTERN_ITERATORS(bool);
DECLARE_EXTERN_ITERATORS(int64_t);
DECLARE_EXTERN_ITERATORS(uint64_t);
DECLARE_EXTERN_ITERATORS(C2DBounds)
DECLARE_EXTERN_ITERATORS(C2DFVector)
DECLARE_EXTERN_ITERATORS(C2DDVector)
#undef DECLARE_EXTERN_ITERATORS
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
template <class T>
class EXPORT_2DDATAFIELD T2DDatafield
{
public:
typedef ::std::vector<typename __holder_type_dispatch<T>::type> data_array;
typedef typename data_array::iterator iterator;
typedef typename data_array::const_iterator const_iterator;
typedef typename data_array::const_reference const_reference;
typedef typename data_array::reference reference;
typedef typename data_array::const_pointer const_pointer;
typedef typename data_array::pointer pointer;
typedef typename data_array::value_type value_type;
typedef typename data_array::difference_type difference_type;
typedef typename data_array::size_type size_type;
typedef range2d_iterator<iterator> range_iterator;
typedef range2d_iterator<const_iterator> const_range_iterator;
typedef range2d_iterator_with_boundary_flag<iterator> range_iterator_with_boundary_flag;
typedef range2d_iterator_with_boundary_flag<const_iterator> const_range_iterator_with_boundary_flag;
typedef C2DBounds dimsize_type;
typedef C2DFVector coord_type;
class EXPORT_2DDATAFIELD Range
{
friend class T2DDatafield<T>;
friend class ConstRange;
public:
typedef T2DDatafield<T>::range_iterator iterator;
iterator begin();
iterator end();
private:
Range(const C2DBounds& start, const C2DBounds& end, T2DDatafield<T>& field);
iterator m_begin;
iterator m_end;
};
class EXPORT_2D ConstRange
{
public:
friend class T2DDatafield<T>;
typedef T2DDatafield<T>::const_range_iterator iterator;
iterator begin() const;
iterator end() const;
private:
ConstRange(const C2DBounds& start, const C2DBounds& end, const T2DDatafield<T>& field);
ConstRange(const Range& range);
iterator m_begin;
iterator m_end;
};
T2DDatafield();
explicit T2DDatafield(const C2DBounds& size);
T2DDatafield(const C2DBounds& size, const T *_data);
T2DDatafield(const C2DBounds& size, const std::vector<T>& data);
T2DDatafield(const T2DDatafield<T>& org);
T2DDatafield<T>& operator = (const T2DDatafield<T>& org);
T2DDatafield(T2DDatafield<T>&& org);
T2DDatafield<T>& operator = (T2DDatafield<T>&& org);
virtual ~T2DDatafield();
void make_single_ref() __attribute__((deprecated));
const C2DBounds& get_size() const;
void clear();
const_reference operator()(size_t x, size_t y) const;
reference operator()(size_t x, size_t y);
const_reference operator[](size_t idx) const
{
return m_data[idx];
}
reference operator[](size_t idx)
{
return m_data[idx];
}
const_reference operator()(const C2DBounds& l) const;
reference operator()(const C2DBounds& l);
void get_data_line_x(size_t y, std::vector<T>& buffer) const;
void get_data_line_y(size_t x, std::vector<T>& buffer) const;
void put_data_line_x(size_t y, const std::vector<T>& buffer);
void put_data_line_y(size_t x, const std::vector<T>& buffer);
size_type size() const;
const_iterator begin()const
{
return m_data.begin();
}
const_iterator end()const
{
return m_data.end();
}
iterator begin()
{
return m_data.begin();
}
iterator end()
{
return m_data.end();
}
const_iterator begin_at(size_t x, size_t y)const
{
const_iterator b = begin();
advance(b, x + y * m_size.x);
return b;
}
iterator begin_at(size_t x, size_t y)
{
iterator b = begin();
advance(b, x + y * m_size.x);
return b;
}
Range get_range(const C2DBounds& start, const C2DBounds& end);
ConstRange get_range(const C2DBounds& start, const C2DBounds& end) const;
range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end);
range_iterator end_range(const C2DBounds& begin, const C2DBounds& end);
const_range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)const;
const_range_iterator end_range(const C2DBounds& begin, const C2DBounds& end)const;
private:
C2DBounds m_size;
data_array m_data;
const static value_type Zero;
};
typedef T2DDatafield<double> C2DDDatafield;
typedef T2DDatafield<float> C2DFDatafield;
typedef T2DDatafield<uint32_t> C2DUIDatafield;
typedef T2DDatafield<int32_t> C2DSIDatafield;
typedef T2DDatafield<uint64_t> C2DULDatafield;
typedef T2DDatafield<int64_t> C2DSLDatafield;
typedef T2DDatafield<uint16_t> C2DUSDatafield;
typedef T2DDatafield<int16_t> C2DSSDatafield;
typedef T2DDatafield<uint8_t> C2DUBDatafield;
typedef T2DDatafield<int8_t> C2DSBDatafield;
typedef T2DDatafield<bool> C2DBitDatafield;
typedef CTParameter<C2DBounds> C2DBoundsParameter;
typedef CTParameter<C2DFVector> C2DFVectorParameter;
typedef TTranslator<C2DFVector> C2DFVectorTranslator;
#define DEFINE_2DFIELD_TEMPLATE(TYPE) \
extern template class EXPORT_2D T2DDatafield<TYPE>; \
extern template class EXPORT_2D range2d_iterator<T2DDatafield<TYPE>::iterator>; \
extern template class EXPORT_2D range2d_iterator<T2DDatafield<TYPE>::const_iterator>; \
extern template class EXPORT_2D range2d_iterator_with_boundary_flag<T2DDatafield<TYPE>::iterator>; \
extern template class EXPORT_2D range2d_iterator_with_boundary_flag<T2DDatafield<TYPE>::const_iterator>;
#ifdef __GNUC__
#pragma GCC diagnostic push
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wattributes"
#endif
#endif
DEFINE_2DFIELD_TEMPLATE(double);
DEFINE_2DFIELD_TEMPLATE(float);
DEFINE_2DFIELD_TEMPLATE(int64_t);
DEFINE_2DFIELD_TEMPLATE(uint64_t);
DEFINE_2DFIELD_TEMPLATE(uint32_t);
DEFINE_2DFIELD_TEMPLATE(int32_t);
DEFINE_2DFIELD_TEMPLATE(uint16_t);
DEFINE_2DFIELD_TEMPLATE(int16_t);
DEFINE_2DFIELD_TEMPLATE(uint8_t);
DEFINE_2DFIELD_TEMPLATE(int8_t);
DEFINE_2DFIELD_TEMPLATE(C2DBounds);
DEFINE_2DFIELD_TEMPLATE(C2DFVector)
DEFINE_2DFIELD_TEMPLATE(C2DDVector)
DECLARE_TYPE_DESCR(C2DBounds);
DECLARE_TYPE_DESCR(C2DFVector);
DECLARE_TYPE_DESCR(C2DDVector);
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
extern template class EXPORT_2D CTParameter<C2DFVector>;
extern template class EXPORT_2D CTParameter<C2DBounds>;
extern template class EXPORT_2D TTranslator<C2DFVector>;
extern template class EXPORT_2D TAttribute<C2DFVector>;
NS_MIA_END
#endif
C2DFDatafield
T2DDatafield< float > C2DFDatafield
2D scalar field that holds float values
Definition 2d/datafield.hh:389
C2DSSDatafield
T2DDatafield< int16_t > C2DSSDatafield
2D scalar field that holds signed short values
Definition 2d/datafield.hh:406
C2DSIDatafield
T2DDatafield< int32_t > C2DSIDatafield
2D scalar field that holds signed int values
Definition 2d/datafield.hh:395
C2DUBDatafield
T2DDatafield< uint8_t > C2DUBDatafield
2D scalar field that holds unsigned char (=byte) values
Definition 2d/datafield.hh:409
C2DUIDatafield
T2DDatafield< uint32_t > C2DUIDatafield
2D scalar field that holds unsigned int values
Definition 2d/datafield.hh:392
C2DFVectorTranslator
TTranslator< C2DFVector > C2DFVectorTranslator
typedef for the C2DFVector to std::string translator
Definition 2d/datafield.hh:424
C2DDDatafield
T2DDatafield< double > C2DDDatafield
2D scalar field that holds double values
Definition 2d/datafield.hh:386
C2DBitDatafield
T2DDatafield< bool > C2DBitDatafield
2D scalar field that holds bool values
Definition 2d/datafield.hh:415
C2DBoundsParameter
CTParameter< C2DBounds > C2DBoundsParameter
Parameter type for 2D size definitions.
Definition 2d/datafield.hh:418
C2DFVectorParameter
CTParameter< C2DFVector > C2DFVectorParameter
Parameter type for 2D vector.
Definition 2d/datafield.hh:421
DECLARE_EXTERN_ITERATORS
#define DECLARE_EXTERN_ITERATORS(TYPE)
Definition 2d/datafield.hh:44
EXPORT_2DDATAFIELD
#define EXPORT_2DDATAFIELD
define used export 2D symbols
Definition 2d/datafield.hh:39
C2DUSDatafield
T2DDatafield< uint16_t > C2DUSDatafield
2D scalar field that holds unsigned short values
Definition 2d/datafield.hh:403
C2DULDatafield
T2DDatafield< uint64_t > C2DULDatafield
Definition 2d/datafield.hh:397
C2DSLDatafield
T2DDatafield< int64_t > C2DSLDatafield
long instanziation of a 2D data field
Definition 2d/datafield.hh:400
C2DSBDatafield
T2DDatafield< int8_t > C2DSBDatafield
2D scalar field that holds signed char values
Definition 2d/datafield.hh:412
iterator.hh
vector.hh
C2DBounds
T2DVector< unsigned int > C2DBounds
unsigned int valued 2D vector - used as 2D size parameter
Definition 2d/vector.hh:540
C2DFVector
T2DVector< float > C2DFVector
float valued 2D vector
Definition 2d/vector.hh:534
C2DDVector
T2DVector< double > C2DDVector
double valued 2D vector
Definition 2d/vector.hh:537
attributes.hh
CTParameter
Generic type of a complex paramter.
Definition parameter.hh:171
T2DDatafield::ConstRange::begin
iterator begin() const
T2DDatafield::ConstRange::iterator
T2DDatafield< T >::const_range_iterator iterator
Definition 2d/datafield.hh:144
T2DDatafield::ConstRange::end
iterator end() const
T2DDatafield::Range
Definition 2d/datafield.hh:121
T2DDatafield::Range::begin
iterator begin()
T2DDatafield::Range::ConstRange
friend class ConstRange
Definition 2d/datafield.hh:123
T2DDatafield::Range::iterator
T2DDatafield< T >::range_iterator iterator
Definition 2d/datafield.hh:126
T2DDatafield::Range::end
iterator end()
range_iterator
range_iterator::get_size
const C2DBounds & get_size() const
T2DDatafield::put_data_line_x
void put_data_line_x(size_t y, const std::vector< T > &buffer)
T2DDatafield::~T2DDatafield
virtual ~T2DDatafield()
T2DDatafield::operator[]
reference operator[](size_t idx)
Definition 2d/datafield.hh:257
range_iterator::clear
void clear()
T2DDatafield::begin_range
const_range_iterator begin_range(const C2DBounds &begin, const C2DBounds &end) const
T2DDatafield::begin
iterator begin()
Definition 2d/datafield.hh:318
T2DDatafield::get_data_line_y
void get_data_line_y(size_t x, std::vector< T > &buffer) const
T2DDatafield::begin_at
const_iterator begin_at(size_t x, size_t y) const
Definition 2d/datafield.hh:339
T2DDatafield::operator()
reference operator()(const C2DBounds &l)
T2DDatafield::T2DDatafield
T2DDatafield()
T2DDatafield::end_range
const_range_iterator end_range(const C2DBounds &begin, const C2DBounds &end) const
range_iterator::size
size_type size() const
T2DDatafield::begin_at
iterator begin_at(size_t x, size_t y)
Definition 2d/datafield.hh:351
T2DDatafield::T2DDatafield
T2DDatafield(const T2DDatafield< T > &org)
T2DDatafield::data_array
::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::T2DDatafield
T2DDatafield(const C2DBounds &size)
T2DDatafield::T2DDatafield
T2DDatafield(T2DDatafield< T > &&org)
T2DDatafield::begin_range
range_iterator begin_range(const C2DBounds &begin, const C2DBounds &end)
T2DDatafield::get_range
ConstRange get_range(const C2DBounds &start, const C2DBounds &end) const
T2DDatafield::end
iterator end()
Definition 2d/datafield.hh:328
T2DDatafield::end
const_iterator end() const
Definition 2d/datafield.hh:309
T2DDatafield::put_data_line_y
void put_data_line_y(size_t x, const std::vector< T > &buffer)
T2DDatafield::get_data_line_x
void get_data_line_x(size_t y, std::vector< T > &buffer) const
T2DDatafield::operator()
const_reference operator()(const C2DBounds &l) const
T2DDatafield::T2DDatafield
T2DDatafield(const C2DBounds &size, const std::vector< T > &data)
T2DDatafield::get_range
Range get_range(const C2DBounds &start, const C2DBounds &end)
T2DDatafield::T2DDatafield
T2DDatafield(const C2DBounds &size, const T *_data)
T2DDatafield::make_single_ref
void make_single_ref() __attribute__((deprecated))
T2DDatafield::end_range
range_iterator end_range(const C2DBounds &begin, const C2DBounds &end)
T2DDatafield::begin
const_iterator begin() const
Definition 2d/datafield.hh:303
TAttribute
Class of an attribute that holds data of type T.
Definition attributes.hh:119
const_iterator
TPluginHandler::end
const_iterator end() const
TPluginHandler::begin
const_iterator begin() const
TTranslator
Generic string vs. attribute translator singleton.
Definition attributes.hh:518
range2d_iterator_with_boundary_flag
a 2D iterator that knows its position in the 2D grid ans supports iterating over sub-ranges
Definition 2d/iterator.hh:43
range2d_iterator
Definition 2d/iterator.hh:216
defines2d.hh
EXPORT_2D
#define EXPORT_2D
Definition defines2d.hh:37
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
parameter.hh
dimsize_type
typedescr.hh