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