OpenWalnut  1.5.0dev
WDataSetSingle.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WDATASETSINGLE_H
26 #define WDATASETSINGLE_H
27 
28 #include <memory>
29 #include <string>
30 
31 #include <osg/ref_ptr>
32 
33 #include "WDataSet.h"
34 #include "WGrid.h"
35 #include "WGridRegular3D.h"
36 #include "WValueSet.h"
37 
38 class WDataTexture3D;
39 
40 /**
41  * A data set consisting of a set of values based on a grid.
42  * \ingroup dataHandler
43  */
44 class WDataSetSingle : public WDataSet // NOLINT
45 {
46 public:
47  /**
48  * Convenience typedef for a std::shared_ptr
49  */
50  typedef std::shared_ptr< WDataSetSingle > SPtr;
51 
52  /**
53  * Convenience typedef for a std::shared_ptr; const
54  */
55  typedef std::shared_ptr< const WDataSetSingle > ConstSPtr;
56 
57  /**
58  * Constructs an instance out of a value set and a grid.
59  *
60  * \param newValueSet the value set to use
61  * \param newGrid the grid which maps world space to the value set
62  */
63  WDataSetSingle( std::shared_ptr< WValueSetBase > newValueSet,
64  std::shared_ptr< WGrid > newGrid );
65 
66  /**
67  * Construct an empty and unusable instance. This is useful for prototypes.
68  */
70 
71  /**
72  * Destroys this DataSet instance
73  */
74  virtual ~WDataSetSingle();
75 
76  /**
77  * 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
78  * want to keep the dynamic type of your dataset.
79  *
80  * \param newValueSet the new valueset.
81  * \param newGrid the new grid.
82  *
83  * \return the clone
84  */
85  virtual WDataSetSingle::SPtr clone( std::shared_ptr< WValueSetBase > newValueSet, std::shared_ptr< WGrid > newGrid ) const;
86 
87  /**
88  * 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
89  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
90  *
91  * \param newValueSet the new valueset.
92  *
93  * \return the clone
94  */
95  virtual WDataSetSingle::SPtr clone( std::shared_ptr< WValueSetBase > newValueSet ) const;
96 
97  /**
98  * 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
99  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
100  *
101  * \param newGrid the new grid.
102  *
103  * \return the clone
104  */
105  virtual WDataSetSingle::SPtr clone( std::shared_ptr< WGrid > newGrid ) const;
106 
107  /**
108  * Creates a copy (clone) of this instance. Unlike copy construction, this is a very useful function if you
109  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
110  *
111  * \return the clone
112  */
113  virtual WDataSetSingle::SPtr clone() const;
114 
115  /**
116  * \return Reference to its WValueSet
117  */
118  std::shared_ptr< WValueSetBase > getValueSet() const;
119 
120  /**
121  * \return Reference to its WGrid
122  */
123  std::shared_ptr< WGrid > getGrid() const;
124 
125  /**
126  * Get the scalar value stored at id-th position of the array of the value set. This is the id-th grid position \b only for scalar data sets.
127  * \deprecated use getSingleRawValue
128  *
129  * \param id The id of the value to be obtained
130  *
131  * \return Scalar value for that given position
132  */
133  template< typename T > OW_API_DEPRECATED T getValueAt( size_t id );
134 
135  /// @cond Supress doxygen because it produces warning here becuase it does not correctly understand the C++ code.
136  /**
137  * Get the scalar value stored at id-th position of the array of the value set. This is the id-th grid position \b only for scalar data sets.
138  *
139  * \param id The id of the value to be obtained
140  *
141  * \return Scalar value for that given position
142  */
143  template< typename T > T getSingleRawValue( size_t id );
144  /// @endcond
145 
146  /**
147  * Get the scalar value stored at id-th position of the array of the value set. This is the id-th grid position \b only for scalar data sets.
148  * \deprecated use getSingleRawValue
149  *
150  * \param id The id of the value to be obtained
151  *
152  * \return Scalar value for that given position
153  */
154  double OW_API_DEPRECATED getValueAt( size_t id ) const;
155 
156  /**
157  * Get the raw scalar value stored at id-th position of the raw array of the value set.
158  * This is the value at the id-th \b grid position \b only for scalar data sets.
159  *
160  * \param id The id of the raw value to be obtained
161  *
162  * \return Scalar value for that given id
163  */
164  double getSingleRawValue( size_t id ) const;
165 
166  /**
167  * Determines whether this dataset can be used as a texture.
168  *
169  * \return true if usable as texture.
170  */
171  virtual bool isTexture() const;
172 
173  /**
174  * Returns the texture representation of the dataset. May throw an exception if no texture is available.
175  *
176  * \return the texture.
177  */
178  virtual osg::ref_ptr< WDataTexture3D > getTexture() const;
179 
180  /**
181  * Gets the name of this prototype.
182  *
183  * \return the name.
184  */
185  virtual const std::string getName() const;
186 
187  /**
188  * Gets the description for this prototype.
189  *
190  * \return the description
191  */
192  virtual const std::string getDescription() const;
193 
194  /**
195  * Returns a prototype instantiated with the true type of the deriving class.
196  *
197  * \return the prototype.
198  */
199  static std::shared_ptr< WPrototyped > getPrototype();
200 
201 protected:
202  /**
203  * The prototype as singleton.
204  */
205  static std::shared_ptr< WPrototyped > m_prototype;
206 
207  /**
208  * Stores the reference of the WGrid of this DataSetSingle instance.
209  */
210  std::shared_ptr< WGrid > m_grid;
211 
212  /**
213  * Stores the reference of the WValueSet of this DataSetSingle instance.
214  */
215  std::shared_ptr< WValueSetBase > m_valueSet;
216 
217 private:
218  /**
219  * The 3D texture representing this dataset.
220  */
221  osg::ref_ptr< WDataTexture3D > m_texture;
222 };
223 
224 template< typename T > OW_API_DEPRECATED T WDataSetSingle::getValueAt( size_t id )
225 {
226  return getSingleRawValue< T >( id );
227 }
228 
229 template< typename T > T WDataSetSingle::getSingleRawValue( size_t id )
230 {
231  std::shared_ptr< WValueSet< T > > vs = std::dynamic_pointer_cast< WValueSet< T > >( m_valueSet );
232  return vs->getScalar( id );
233 }
234 #endif // WDATASETSINGLE_H
A data set consisting of a set of values based on a grid.
std::shared_ptr< WValueSetBase > getValueSet() const
WDataSetSingle()
Construct an empty and unusable instance.
virtual const std::string getDescription() const
Gets the description for this prototype.
virtual const std::string getName() const
Gets the name of this prototype.
virtual bool isTexture() const
Determines whether this dataset can be used as a texture.
virtual WDataSetSingle::SPtr clone() const
Creates a copy (clone) of this instance.
std::shared_ptr< const WDataSetSingle > ConstSPtr
Convenience typedef for a std::shared_ptr; const.
OW_API_DEPRECATED T getValueAt(size_t id)
Get the scalar value stored at id-th position of the array of the value set.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
std::shared_ptr< WGrid > m_grid
Stores the reference of the WGrid of this DataSetSingle instance.
osg::ref_ptr< WDataTexture3D > m_texture
The 3D texture representing this dataset.
static std::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
virtual osg::ref_ptr< WDataTexture3D > getTexture() const
Returns the texture representation of the dataset.
std::shared_ptr< WGrid > getGrid() const
double getSingleRawValue(size_t id) const
Get the raw scalar value stored at id-th position of the raw array of the value set.
std::shared_ptr< WValueSetBase > m_valueSet
Stores the reference of the WValueSet of this DataSetSingle instance.
std::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a std::shared_ptr.
virtual ~WDataSetSingle()
Destroys this DataSet instance.
Base class for all data set types.
Definition: WDataSet.h:50
This class allows simple creation of WGETexture3D by using a specified grid and value-set.
#define OW_API_DEPRECATED
In order to mark functions for the compiler as deprecated we need to put this before each deprecated ...
Definition: WDefines.h:44