OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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/variant.hpp>
32 
33 #include "../common/math/WValue.h"
34 #include "WDataHandlerEnums.h"
35 #include "WExportDataHandler.h"
36 
37 //! forward declaration
38 template< typename T >
39 class WValueSet;
40 
41 //! declare a boost::variant of all possible valuesets
42 typedef boost::variant< WValueSet< uint8_t > const*,
43  WValueSet< int8_t > const*,
44  WValueSet< uint16_t > const*,
45  WValueSet< int16_t > const*,
46  WValueSet< uint32_t > const*,
47  WValueSet< int32_t > const*,
48  WValueSet< uint64_t > const*,
49  WValueSet< int64_t > const*,
50  WValueSet< float > const*,
51  WValueSet< double > const* > WValueSetVariant;
52 
53 /**
54  * Abstract base class to all WValueSets. This class doesn't provide any genericness.
55  * \ingroup dataHandler
56  */
58 {
59 public:
60  /**
61  * Despite this is an abstract class all subclasses should have an order
62  * and dimension.
63  * \param order the tensor order of the values stored in this WValueSet
64  * \param dimension the tensor dimension of the values stored in this WValueSet
65  * \param inDataType indication of the primitive data type used to store the values
66  */
67  WValueSetBase( size_t order, size_t dimension, dataType inDataType );
68 
69  /**
70  * Dummy since each class with virtual member functions needs one.
71  */
72  virtual ~WValueSetBase() = 0;
73 
74  /**
75  * \return The number of tensors in this ValueSet.
76  */
77  virtual size_t size() const = 0;
78 
79  /**
80  * \return The number of integrals (POD like int, double) in this ValueSet.
81  */
82  virtual size_t rawSize() const = 0;
83 
84  /**
85  * \param i id of the scalar to retrieve
86  * \return The i-th scalar stored in this value set. There are rawSize() such scalars.
87  */
88  virtual double getScalarDouble( size_t i ) const = 0;
89 
90  /**
91  * \param i id of the WValue to retrieve
92  * \return The i-th WValue stored in this value set. There are size() such scalars.
93  */
94  virtual WValue< double > getWValueDouble( size_t i ) const = 0;
95 
96  /**
97  * \param i id of the WVector to retrieve
98  * \return The i-th WValue (stored in this value set) as WVector. There are size() such scalars.
99  */
100  virtual WVector_2 getWVector( size_t i ) const = 0;
101 
102  /**
103  * \return Dimension of the values in this ValueSet
104  */
105  virtual size_t dimension() const
106  {
107  return m_dimension;
108  }
109 
110  /**
111  * \return Order of the values in this ValueSet
112  */
113  virtual size_t order() const
114  {
115  return m_order;
116  }
117 
118  /**
119  * Returns the number of elements of type T per value.
120  * \note this is dimension to the power of order.
121  * \return number of elements per value
122  */
123  virtual size_t elementsPerValue() const
124  {
125  // Windows Hack: the MSVC obviously does not support ( oh wonder, which wonder ) pow with integers.
126  return static_cast< size_t >( std::pow( static_cast< double >( m_dimension ), static_cast< int >( m_order ) ) );
127  }
128 
129  /**
130  * \return Dimension of the values in this ValueSet
131  */
132  virtual dataType getDataType() const
133  {
134  return m_dataType;
135  }
136 
137  /**
138  * This method returns the smallest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
139  * smallest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
140  *
141  * \return the smallest value in the data.
142  */
143  virtual double getMinimumValue() const = 0;
144 
145  /**
146  * This method returns the largest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
147  * largest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
148  *
149  * \return the largest value in the data.
150  */
151  virtual double getMaximumValue() const = 0;
152 
153  /**
154  * Apply a function object to this valueset.
155  *
156  * \tparam Func_T The type of the function object, should be derived from the boost::static_visitor template.
157  *
158  * \param func The function object to apply.
159  * \return The result of the operation.
160  */
161  template< typename Func_T >
162  typename Func_T::result_type applyFunction( Func_T const& func )
163  {
164  return boost::apply_visitor( func, getVariant() );
165  }
166 
167 protected:
168  /**
169  * The order of the tensors for this ValueSet
170  */
171  const size_t m_order;
172 
173  /**
174  * The dimension of the tensors for this ValueSet
175  */
176  const size_t m_dimension;
177 
178  /**
179  * The data type of the values' elements.
180  */
182 
183 private:
184  /**
185  * Creates a boost::variant reference.
186  *
187  * \return var A pointer to a variant reference to the valueset.
188  */
189  virtual WValueSetVariant const getVariant() const
190  {
191  return WValueSetVariant();
192  }
193 };
194 
195 #endif // WVALUESETBASE_H