OpenWalnut 1.2.5
WDataSetScalar.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 WDATASETSCALAR_H
00026 #define WDATASETSCALAR_H
00027 
00028 #include <map>
00029 
00030 #include <boost/thread.hpp>
00031 
00032 #include "datastructures/WValueSetHistogram.h"
00033 
00034 #include "WDataSetSingle.h"
00035 #include "WExportDataHandler.h"
00036 
00037 /**
00038  * This data set type contains scalars as values.
00039  * \ingroup dataHandler
00040  */
00041 class OWDATAHANDLER_EXPORT WDataSetScalar : public WDataSetSingle // NOLINT
00042 {
00043 public:
00044 
00045     /**
00046      * Constructs an instance out of an appropriate value set and a grid.
00047      * Computes the maximum an minimum values stored as member variables.
00048      *
00049      * \param newValueSet the scalar value set to use
00050      * \param newGrid the grid which maps world space to the value set
00051      */
00052     WDataSetScalar( boost::shared_ptr< WValueSetBase > newValueSet,
00053                     boost::shared_ptr< WGrid > newGrid );
00054 
00055     /**
00056      * Construct an empty and unusable instance. This is needed for the prototype mechanism.
00057      */
00058     WDataSetScalar();
00059 
00060     /**
00061      * Destroys this DataSet instance
00062      */
00063     virtual ~WDataSetScalar();
00064 
00065     /**
00066      * Creates a copy (clone) of this instance but allows to change the valueset. Unlike copy construction, this is a very useful function if you
00067      * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
00068      *
00069      * \param newValueSet the new valueset.
00070      *
00071      * \return the clone
00072      */
00073     virtual WDataSetSingle::SPtr clone( boost::shared_ptr< WValueSetBase > newValueSet ) const;
00074 
00075     /**
00076      * Creates a copy (clone) of this instance but allows to change the grid. Unlike copy construction, this is a very useful function if you
00077      * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
00078      *
00079      * \param newGrid the new grid.
00080      *
00081      * \return the clone
00082      */
00083     virtual WDataSetSingle::SPtr clone( boost::shared_ptr< WGrid > newGrid ) const;
00084 
00085     /**
00086      * Creates a copy (clone) of this instance. Unlike copy construction, this is a very useful function if you
00087      * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
00088      *
00089      * \return the clone
00090      */
00091     virtual WDataSetSingle::SPtr clone() const;
00092 
00093     /**
00094      * Returns the largest of the scalars stored in the data set
00095      *
00096      * \return maximum value in dataset
00097      */
00098     double getMax() const;
00099 
00100     /**
00101      * Returns the smallest of the scalars stored in the data set
00102      *
00103      * \return minimum value in dataset
00104      */
00105     double getMin() const;
00106 
00107     /**
00108      * Returns the histogram of this dataset's valueset. If it does not exist yet, it will be created and cached. It does NOT make use of the
00109      * WValueSetHistogram down scaling feature even though the number of buckets might be lower than the default as the down scaling might
00110      * introduce errors. To use down-scaling, grab the default histogram and call WValueSetHistogram( getHistogram(), buckets ) manually.
00111      *
00112      * \param buckets the number of buckets inside the histogram.
00113      *
00114      * \return the histogram.
00115      */
00116     boost::shared_ptr< const WValueSetHistogram > getHistogram( size_t buckets = 1000 );
00117 
00118     /**
00119      * Interpolate the value fo the valueset at the given position.
00120      * If interpolation fails, the success parameter will be false
00121      * and the value returned zero.
00122      *
00123      * \param pos The position for wich we would like to get a value.
00124      * \param success indicates whether the interpolation was successful
00125      *
00126      * \return Scalar value for that given position
00127      */
00128     double interpolate( const WPosition& pos, bool* success ) const;
00129 
00130     /**
00131      * Get the value stored at a certain grid position of the data set
00132      * \param x index in x direction
00133      * \param y index in y direction
00134      * \param z index in z direction
00135      *
00136      * \return the value at the grid position with the given index tuple.
00137      */
00138     template< typename T > T getValueAt( int x, int y, int z ) const;
00139 
00140     /**
00141      * Get the value stored at a certain grid position of the data set
00142      * \param x index in x direction
00143      * \param y index in y direction
00144      * \param z index in z direction
00145      *
00146      * \return the double the grid position with the given index tuple.
00147      */
00148     double getValueAt( int x, int y, int z ) const;
00149 
00150 
00151     /**
00152      * Returns a prototype instantiated with the true type of the deriving class.
00153      *
00154      * \return the prototype.
00155      */
00156     static boost::shared_ptr< WPrototyped > getPrototype();
00157 
00158     using WDataSetSingle::getValueAt;
00159 
00160 protected:
00161 
00162     /**
00163      * The prototype as singleton.
00164      */
00165     static boost::shared_ptr< WPrototyped > m_prototype;
00166 
00167 private:
00168 
00169     /**
00170      * The histograms for later use. Each histogram for a requested bucket count gets cached.
00171      **/
00172     std::map< size_t, boost::shared_ptr< WValueSetHistogram > > m_histograms;
00173 
00174     /**
00175      * The lock used for securely creating m_histogram on demand.
00176      */
00177     boost::mutex m_histogramLock;
00178 };
00179 
00180 template< typename T > T WDataSetScalar::getValueAt( int x, int y, int z ) const
00181 {
00182     boost::shared_ptr< WValueSet< T > > vs = boost::shared_dynamic_cast< WValueSet< T > >( m_valueSet );
00183     boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
00184 
00185     size_t id = x + y * grid->getNbCoordsX() + z * grid->getNbCoordsX() * grid->getNbCoordsY();
00186 
00187     T v = vs->getScalar( id );
00188     return v;
00189 }
00190 
00191 #endif  // WDATASETSCALAR_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends