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 WDATASETSINGLE_H 00026 #define WDATASETSINGLE_H 00027 00028 #include <string> 00029 00030 #include <osg/ref_ptr> 00031 00032 #include <boost/shared_ptr.hpp> 00033 00034 #include "WDataSet.h" 00035 #include "WGrid.h" 00036 #include "WGridRegular3D.h" 00037 #include "WValueSet.h" 00038 00039 class WDataTexture3D; 00040 00041 /** 00042 * A data set consisting of a set of values based on a grid. 00043 * \ingroup dataHandler 00044 */ 00045 class WDataSetSingle : public WDataSet // NOLINT 00046 { 00047 public: 00048 /** 00049 * Convenience typedef for a boost::shared_ptr 00050 */ 00051 typedef boost::shared_ptr< WDataSetSingle > SPtr; 00052 00053 /** 00054 * Convenience typedef for a boost::shared_ptr; const 00055 */ 00056 typedef boost::shared_ptr< const WDataSetSingle > ConstSPtr; 00057 00058 /** 00059 * Constructs an instance out of a value set and a grid. 00060 * 00061 * \param newValueSet the value set to use 00062 * \param newGrid the grid which maps world space to the value set 00063 */ 00064 WDataSetSingle( boost::shared_ptr< WValueSetBase > newValueSet, 00065 boost::shared_ptr< WGrid > newGrid ); 00066 00067 /** 00068 * Construct an empty and unusable instance. This is useful for prototypes. 00069 */ 00070 WDataSetSingle(); 00071 00072 /** 00073 * Destroys this DataSet instance 00074 */ 00075 virtual ~WDataSetSingle(); 00076 00077 /** 00078 * 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 00079 * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle. 00080 * 00081 * \param newValueSet the new valueset. 00082 * 00083 * \return the clone 00084 */ 00085 virtual WDataSetSingle::SPtr clone( boost::shared_ptr< WValueSetBase > newValueSet ) const; 00086 00087 /** 00088 * 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 00089 * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle. 00090 * 00091 * \param newGrid the new grid. 00092 * 00093 * \return the clone 00094 */ 00095 virtual WDataSetSingle::SPtr clone( boost::shared_ptr< WGrid > newGrid ) const; 00096 00097 /** 00098 * Creates a copy (clone) of this instance. Unlike copy construction, this is a very useful function if you 00099 * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle. 00100 * 00101 * \return the clone 00102 */ 00103 virtual WDataSetSingle::SPtr clone() const; 00104 00105 /** 00106 * \return Reference to its WValueSet 00107 */ 00108 boost::shared_ptr< WValueSetBase > getValueSet() const; 00109 00110 /** 00111 * \return Reference to its WGrid 00112 */ 00113 boost::shared_ptr< WGrid > getGrid() const; 00114 00115 /** 00116 * Get the value stored at position of the value set. This is the grid position only for scalar data sets. 00117 * 00118 * \param id The id'th value in the data set 00119 * 00120 * \return Scalar value for that given position 00121 */ 00122 template< typename T > T getValueAt( size_t id ); 00123 00124 /** 00125 * Get the value stored at position of the value set. This is the grid position only for scalar data sets. 00126 * 00127 * \param id The id'th value in the data set 00128 * 00129 * \return Scalar value for that given position 00130 */ 00131 double getValueAt( size_t id ) const; 00132 00133 /** 00134 * Determines whether this dataset can be used as a texture. 00135 * 00136 * \return true if usable as texture. 00137 */ 00138 virtual bool isTexture() const; 00139 00140 /** 00141 * Returns the texture representation of the dataset. May throw an exception if no texture is available. 00142 * 00143 * \return the texture. 00144 */ 00145 virtual osg::ref_ptr< WDataTexture3D > getTexture() const; 00146 00147 /** 00148 * Gets the name of this prototype. 00149 * 00150 * \return the name. 00151 */ 00152 virtual const std::string getName() const; 00153 00154 /** 00155 * Gets the description for this prototype. 00156 * 00157 * \return the description 00158 */ 00159 virtual const std::string getDescription() const; 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 protected: 00169 /** 00170 * The prototype as singleton. 00171 */ 00172 static boost::shared_ptr< WPrototyped > m_prototype; 00173 00174 /** 00175 * Stores the reference of the WGrid of this DataSetSingle instance. 00176 */ 00177 boost::shared_ptr< WGrid > m_grid; 00178 00179 /** 00180 * Stores the reference of the WValueSet of this DataSetSingle instance. 00181 */ 00182 boost::shared_ptr< WValueSetBase > m_valueSet; 00183 00184 private: 00185 /** 00186 * The 3D texture representing this dataset. 00187 */ 00188 osg::ref_ptr< WDataTexture3D > m_texture; 00189 }; 00190 00191 template< typename T > T WDataSetSingle::getValueAt( size_t id ) 00192 { 00193 boost::shared_ptr< WValueSet< T > > vs = boost::dynamic_pointer_cast< WValueSet< T > >( m_valueSet ); 00194 return vs->getScalar( id ); 00195 } 00196 #endif // WDATASETSINGLE_H