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