WValueSetBase.h 5.92 KB
Newer Older
wiebel's avatar
wiebel committed
1 2
//---------------------------------------------------------------------------
//
3
// Project: OpenWalnut ( http://www.openwalnut.org )
wiebel's avatar
wiebel committed
4
//
5 6
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
wiebel's avatar
wiebel committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

25 26 27 28
#ifndef WVALUESETBASE_H
#define WVALUESETBASE_H

#include <cstddef>
29
#include <cmath>
30 31 32

#include <boost/variant.hpp>

33
#include "../common/math/WValue.h"
34
#include "WDataHandlerEnums.h"
35
#include "WExportDataHandler.h"
wiebel's avatar
wiebel committed
36

37 38 39 40 41
//! forward declaration
template< typename T >
class WValueSet;

//! declare a boost::variant of all possible valuesets
42
typedef boost::variant< WValueSet< uint8_t > const*,
43 44 45 46 47 48 49 50 51 52
                        WValueSet< int8_t > const*,
                        WValueSet< uint16_t > const*,
                        WValueSet< int16_t > const*,
                        WValueSet< uint32_t > const*,
                        WValueSet< int32_t > const*,
                        WValueSet< uint64_t > const*,
                        WValueSet< int64_t > const*,
                        WValueSet< float > const*,
                        WValueSet< double > const* > WValueSetVariant;

wiebel's avatar
wiebel committed
53
/**
54
 * Abstract base class to all WValueSets. This class doesn't provide any genericness.
55
 * \ingroup dataHandler
wiebel's avatar
wiebel committed
56
 */
57
class OWDATAHANDLER_EXPORT WValueSetBase // NOLINT
wiebel's avatar
wiebel committed
58 59
{
public:
math's avatar
math committed
60
    /**
61 62
     * Despite this is an abstract class all subclasses should have an order
     * and dimension.
Alexander Wiebel's avatar
Alexander Wiebel committed
63 64 65
     * \param order the tensor order of the values stored in this WValueSet
     * \param dimension the tensor dimension of the values stored in this WValueSet
     * \param inDataType indication of the primitive data type used to store the values
math's avatar
math committed
66
     */
67
    WValueSetBase( size_t order, size_t dimension, dataType inDataType );
math's avatar
math committed
68 69

    /**
70
     * Dummy since each class with virtual member functions needs one.
math's avatar
math committed
71
     */
72 73 74 75 76 77 78 79 80 81 82
    virtual ~WValueSetBase() = 0;

    /**
     * \return The number of tensors in this ValueSet.
     */
    virtual size_t size() const = 0;

    /**
     * \return The number of integrals (POD like int, double) in this ValueSet.
     */
    virtual size_t rawSize() const = 0;
math's avatar
math committed
83

84 85 86 87 88 89
    /**
     * \param i id of the scalar to retrieve
     * \return The i-th scalar stored in this value set. There are rawSize() such scalars.
     */
    virtual double getScalarDouble( size_t i ) const = 0;

90 91 92 93 94 95
    /**
     * \param i id of the WValue to retrieve
     * \return The i-th WValue stored in this value set. There are size() such scalars.
     */
    virtual wmath::WValue< double > getWValueDouble( size_t i ) const = 0;

96 97 98
    /**
     * \return Dimension of the values in this ValueSet
     */
99
    virtual size_t dimension() const
100 101 102 103
    {
        return m_dimension;
    }

104 105 106
    /**
     * \return Order of the values in this ValueSet
     */
107
    virtual size_t order() const
108
    {
Alexander Wiebel's avatar
Alexander Wiebel committed
109
        return m_order;
110 111
    }

112 113 114 115 116 117 118
    /**
     * Returns the number of elements of type T per value.
     * \note this is dimension to the power of order.
     * \return number of elements per value
     */
    virtual size_t elementsPerValue() const
    {
119
        // Windows Hack: the MSVC obviously does not support ( oh wonder, which wonder ) pow with integers.
ledig's avatar
ledig committed
120
        return static_cast< size_t >( std::pow( static_cast< double >( m_dimension ), static_cast< int >( m_order ) ) );
121 122
    }

123 124 125
    /**
     * \return Dimension of the values in this ValueSet
     */
126
    virtual dataType getDataType() const
127 128 129 130
    {
        return m_dataType;
    }

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    /**
     * This method returns the smallest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
     * smallest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
     *
     * \return the smallest value in the data.
     */
    virtual double getMinimumValue() const = 0;

    /**
     * This method returns the largest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
     * largest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
     *
     * \return the largest value in the data.
     */
    virtual double getMaximumValue() const = 0;

147 148 149 150
    /**
     * Apply a function object to this valueset.
     *
     * \tparam Func_T The type of the function object, should be derived from the boost::static_visitor template.
151
     *
152 153 154 155 156 157 158 159 160
     * \param func The function object to apply.
     * \return The result of the operation.
     */
    template< typename Func_T >
    typename Func_T::result_type applyFunction( Func_T const& func )
    {
        return boost::apply_visitor( func, getVariant() );
    }

wiebel's avatar
wiebel committed
161
protected:
162 163 164
    /**
     * The order of the tensors for this ValueSet
     */
Alexander Wiebel's avatar
Alexander Wiebel committed
165
    const size_t m_order;
math's avatar
math committed
166 167

    /**
168
     * The dimension of the tensors for this ValueSet
math's avatar
math committed
169
     */
Alexander Wiebel's avatar
Alexander Wiebel committed
170
    const size_t m_dimension;
171

172 173 174
    /**
     * The data type of the values' elements.
     */
Alexander Wiebel's avatar
Alexander Wiebel committed
175
    const dataType m_dataType;
176

177
private:
178 179 180 181 182 183 184 185 186
    /**
     * Creates a boost::variant reference.
     *
     * \return var A pointer to a variant reference to the valueset.
     */
    virtual WValueSetVariant const getVariant() const
    {
        return WValueSetVariant();
    }
wiebel's avatar
wiebel committed
187 188
};

189
#endif  // WVALUESETBASE_H