OpenWalnut 1.2.5
WValueSetBase.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WVALUESETBASE_H
00026 #define WVALUESETBASE_H
00027 
00028 #include <cstddef>
00029 #include <cmath>
00030 
00031 #include <boost/variant.hpp>
00032 
00033 #include "../common/math/WValue.h"
00034 #include "WDataHandlerEnums.h"
00035 #include "WExportDataHandler.h"
00036 
00037 //! forward declaration
00038 template< typename T >
00039 class WValueSet;
00040 
00041 //! declare a boost::variant of all possible valuesets
00042 typedef boost::variant< WValueSet< uint8_t > const*,
00043                         WValueSet< int8_t > const*,
00044                         WValueSet< uint16_t > const*,
00045                         WValueSet< int16_t > const*,
00046                         WValueSet< uint32_t > const*,
00047                         WValueSet< int32_t > const*,
00048                         WValueSet< uint64_t > const*,
00049                         WValueSet< int64_t > const*,
00050                         WValueSet< float > const*,
00051                         WValueSet< double > const* > WValueSetVariant;
00052 
00053 /**
00054  * Abstract base class to all WValueSets. This class doesn't provide any genericness.
00055  * \ingroup dataHandler
00056  */
00057 class OWDATAHANDLER_EXPORT WValueSetBase // NOLINT
00058 {
00059 public:
00060     /**
00061      * Despite this is an abstract class all subclasses should have an order
00062      * and dimension.
00063      * \param order the tensor order of the values stored in this WValueSet
00064      * \param dimension the tensor dimension of the values stored in this WValueSet
00065      * \param inDataType indication of the primitive data type used to store the values
00066      */
00067     WValueSetBase( size_t order, size_t dimension, dataType inDataType );
00068 
00069     /**
00070      * Dummy since each class with virtual member functions needs one.
00071      */
00072     virtual ~WValueSetBase() = 0;
00073 
00074     /**
00075      * \return The number of tensors in this ValueSet.
00076      */
00077     virtual size_t size() const = 0;
00078 
00079     /**
00080      * \return The number of integrals (POD like int, double) in this ValueSet.
00081      */
00082     virtual size_t rawSize() const = 0;
00083 
00084     /**
00085      * \param i id of the scalar to retrieve
00086      * \return The i-th scalar stored in this value set. There are rawSize() such scalars.
00087      */
00088     virtual double getScalarDouble( size_t i ) const = 0;
00089 
00090     /**
00091      * \param i id of the WValue to retrieve
00092      * \return The i-th WValue stored in this value set. There are size() such scalars.
00093      */
00094     virtual WValue< double > getWValueDouble( size_t i ) const = 0;
00095 
00096     /**
00097      * \param i id of the WVector to retrieve
00098      * \return The i-th WValue (stored in this value set) as WVector. There are size() such scalars.
00099      */
00100     virtual WVector_2 getWVector( size_t i ) const = 0;
00101 
00102     /**
00103      * \return Dimension of the values in this ValueSet
00104      */
00105     virtual size_t dimension() const
00106     {
00107         return m_dimension;
00108     }
00109 
00110     /**
00111      * \return Order of the values in this ValueSet
00112      */
00113     virtual size_t order() const
00114     {
00115         return m_order;
00116     }
00117 
00118     /**
00119      * Returns the number of elements of type T per value.
00120      * \note this is dimension to the power of order.
00121      * \return number of elements per value
00122      */
00123     virtual size_t elementsPerValue() const
00124     {
00125         // Windows Hack: the MSVC obviously does not support ( oh wonder, which wonder ) pow with integers.
00126         return static_cast< size_t >( std::pow( static_cast< double >( m_dimension ), static_cast< int >( m_order ) ) );
00127     }
00128 
00129     /**
00130      * \return Dimension of the values in this ValueSet
00131      */
00132     virtual dataType getDataType() const
00133     {
00134         return m_dataType;
00135     }
00136 
00137     /**
00138      * This method returns the smallest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
00139      * smallest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
00140      *
00141      * \return the smallest value in the data.
00142      */
00143     virtual double getMinimumValue() const = 0;
00144 
00145     /**
00146      * This method returns the largest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
00147      * largest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
00148      *
00149      * \return the largest value in the data.
00150      */
00151     virtual double getMaximumValue() const = 0;
00152 
00153     /**
00154      * Apply a function object to this valueset.
00155      *
00156      * \tparam Func_T The type of the function object, should be derived from the boost::static_visitor template.
00157      *
00158      * \param func The function object to apply.
00159      * \return The result of the operation.
00160      */
00161     template< typename Func_T >
00162     typename Func_T::result_type applyFunction( Func_T const& func )
00163     {
00164         return boost::apply_visitor( func, getVariant() );
00165     }
00166 
00167 protected:
00168     /**
00169      * The order of the tensors for this ValueSet
00170      */
00171     const size_t m_order;
00172 
00173     /**
00174      * The dimension of the tensors for this ValueSet
00175      */
00176     const size_t m_dimension;
00177 
00178     /**
00179      * The data type of the values' elements.
00180      */
00181     const dataType m_dataType;
00182 
00183 private:
00184     /**
00185      * Creates a boost::variant reference.
00186      *
00187      * \return var A pointer to a variant reference to the valueset.
00188      */
00189     virtual WValueSetVariant const getVariant() const
00190     {
00191         return WValueSetVariant();
00192     }
00193 };
00194 
00195 #endif  // WVALUESETBASE_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends