OpenWalnut  1.4.0
WValueSetBase.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WVALUESETBASE_H
26 #define WVALUESETBASE_H
27 
28 #include <cstddef>
29 #include <cmath>
30 
31 #include <boost/shared_ptr.hpp>
32 #include <boost/variant.hpp>
33 
34 #include "../common/math/WValue.h"
35 #include "WDataHandlerEnums.h"
36 
37 
38 //! forward declaration
39 template< typename T >
40 class WValueSet;
41 
42 //! declare a boost::variant of all possible valuesets
43 typedef boost::variant< WValueSet< uint8_t > const*,
44  WValueSet< int8_t > const*,
45  WValueSet< uint16_t > const*,
46  WValueSet< int16_t > const*,
47  WValueSet< uint32_t > const*,
48  WValueSet< int32_t > const*,
49  WValueSet< uint64_t > const*,
50  WValueSet< int64_t > const*,
51  WValueSet< float > const*,
52  WValueSet< double > const*,
53  WValueSet< long double > const* > WValueSetVariant;
54 
55 /**
56  * Abstract base class to all WValueSets. This class doesn't provide any genericness.
57  * \ingroup dataHandler
58  */
59 class WValueSetBase // NOLINT
60 {
61 public:
62  /**
63  * Shared pointer to an instance of this class.
64  */
65  typedef boost::shared_ptr< WValueSetBase > SPtr;
66 
67  /**
68  * Shared pointer to an const instance of this class.
69  */
70  typedef boost::shared_ptr< const WValueSetBase > ConstSPtr;
71 
72  /**
73  * Despite this is an abstract class all subclasses should have an order
74  * and dimension.
75  * \param order the tensor order of the values stored in this WValueSet
76  * \param dimension the tensor dimension of the values stored in this WValueSet
77  * \param inDataType indication of the primitive data type used to store the values
78  */
79  WValueSetBase( size_t order, size_t dimension, dataType inDataType );
80 
81  /**
82  * Dummy since each class with virtual member functions needs one.
83  */
84  virtual ~WValueSetBase() = 0;
85 
86  /**
87  * \return The number of tensors in this ValueSet.
88  */
89  virtual size_t size() const = 0;
90 
91  /**
92  * \return The number of integrals (POD like int, double) in this ValueSet.
93  */
94  virtual size_t rawSize() const = 0;
95 
96  /**
97  * \param i id of the scalar to retrieve
98  * \return The i-th scalar stored in this value set. There are rawSize() such scalars.
99  */
100  virtual double getScalarDouble( size_t i ) const = 0;
101 
102  /**
103  * \param i id of the WValue to retrieve
104  * \return The i-th WValue stored in this value set. There are size() such scalars.
105  */
106  virtual WValue< double > getWValueDouble( size_t i ) const = 0;
107 
108  /**
109  * \return Dimension of the values in this ValueSet
110  */
111  virtual size_t dimension() const
112  {
113  return m_dimension;
114  }
115 
116  /**
117  * \return Order of the values in this ValueSet
118  */
119  virtual size_t order() const
120  {
121  return m_order;
122  }
123 
124  /**
125  * Returns the number of elements of type T per value.
126  * \note this is dimension to the power of order.
127  * \return number of elements per value
128  */
129  virtual size_t elementsPerValue() const
130  {
131  return static_cast< size_t >( std::pow( static_cast< double >( m_dimension ), static_cast< int >( m_order ) ) );
132  }
133 
134  /**
135  * \return Dimension of the values in this ValueSet
136  */
137  virtual dataType getDataType() const
138  {
139  return m_dataType;
140  }
141 
142  /**
143  * This method returns the smallest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
144  * smallest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
145  *
146  * \return the smallest value in the data.
147  */
148  virtual double getMinimumValue() const = 0;
149 
150  /**
151  * This method returns the largest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
152  * largest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
153  *
154  * \return the largest value in the data.
155  */
156  virtual double getMaximumValue() const = 0;
157 
158  /**
159  * Apply a function object to this valueset.
160  *
161  * \tparam Func_T The type of the function object, should be derived from the boost::static_visitor template.
162  *
163  * \param func The function object to apply.
164  * \return The result of the operation.
165  */
166  template< typename Func_T >
167  typename Func_T::result_type applyFunction( Func_T const& func )
168  {
169  return boost::apply_visitor( func, getVariant() );
170  }
171 
172 protected:
173  /**
174  * The order of the tensors for this ValueSet
175  */
176  const size_t m_order;
177 
178  /**
179  * The dimension of the tensors for this ValueSet
180  */
181  const size_t m_dimension;
182 
183  /**
184  * The data type of the values' elements.
185  */
187 
188 private:
189  /**
190  * Creates a boost::variant reference.
191  *
192  * \return var A pointer to a variant reference to the valueset.
193  */
194  virtual WValueSetVariant const getVariant() const
195  {
196  return WValueSetVariant();
197  }
198 };
199 
200 #endif // WVALUESETBASE_H
boost::shared_ptr< WValueSetBase > SPtr
Shared pointer to an instance of this class.
Definition: WValueSetBase.h:65
virtual size_t order() const
const size_t m_dimension
The dimension of the tensors for this ValueSet.
Func_T::result_type applyFunction(Func_T const &func)
Apply a function object to this valueset.
Base class for all higher level values like tensors, vectors, matrices and so on. ...
Definition: WValue.h:40
virtual WValueSetVariant const getVariant() const
Creates a boost::variant reference.
const dataType m_dataType
The data type of the values' elements.
virtual double getMinimumValue() const =0
This method returns the smallest value in the valueset.
boost::shared_ptr< const WValueSetBase > ConstSPtr
Shared pointer to an const instance of this class.
Definition: WValueSetBase.h:70
virtual dataType getDataType() const
virtual WValue< double > getWValueDouble(size_t i) const =0
virtual double getScalarDouble(size_t i) const =0
virtual size_t rawSize() const =0
virtual double getMaximumValue() const =0
This method returns the largest value in the valueset.
dataType
Data types and number values taken from the nifti1.h, at this point it's unknown if it makes sense to...
virtual size_t elementsPerValue() const
Returns the number of elements of type T per value.
virtual ~WValueSetBase()=0
Dummy since each class with virtual member functions needs one.
Base Class for all value set types.
Definition: WValueSet.h:46
WValueSetBase(size_t order, size_t dimension, dataType inDataType)
Despite this is an abstract class all subclasses should have an order and dimension.
Abstract base class to all WValueSets.
Definition: WValueSetBase.h:59
virtual size_t dimension() const
virtual size_t size() const =0
const size_t m_order
The order of the tensors for this ValueSet.