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