OpenWalnut  1.4.0
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 <string>
29 
30 #include <osg/ref_ptr>
31 
32 #ifndef Q_MOC_RUN
33 #include <boost/shared_ptr.hpp>
34 #endif
35 
36 #include "WDataSet.h"
37 #include "WGrid.h"
38 #include "WGridRegular3D.h"
39 #include "WValueSet.h"
40 
41 class WDataTexture3D;
42 
43 /**
44  * A data set consisting of a set of values based on a grid.
45  * \ingroup dataHandler
46  */
47 class WDataSetSingle : public WDataSet // NOLINT
48 {
49 public:
50  /**
51  * Convenience typedef for a boost::shared_ptr
52  */
53  typedef boost::shared_ptr< WDataSetSingle > SPtr;
54 
55  /**
56  * Convenience typedef for a boost::shared_ptr; const
57  */
58  typedef boost::shared_ptr< const WDataSetSingle > ConstSPtr;
59 
60  /**
61  * Constructs an instance out of a value set and a grid.
62  *
63  * \param newValueSet the value set to use
64  * \param newGrid the grid which maps world space to the value set
65  */
66  WDataSetSingle( boost::shared_ptr< WValueSetBase > newValueSet,
67  boost::shared_ptr< WGrid > newGrid );
68 
69  /**
70  * Construct an empty and unusable instance. This is useful for prototypes.
71  */
73 
74  /**
75  * Destroys this DataSet instance
76  */
77  virtual ~WDataSetSingle();
78 
79  /**
80  * 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
81  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
82  *
83  * \param newValueSet the new valueset.
84  *
85  * \return the clone
86  */
87  virtual WDataSetSingle::SPtr clone( boost::shared_ptr< WValueSetBase > newValueSet ) const;
88 
89  /**
90  * 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
91  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
92  *
93  * \param newGrid the new grid.
94  *
95  * \return the clone
96  */
97  virtual WDataSetSingle::SPtr clone( boost::shared_ptr< WGrid > newGrid ) const;
98 
99  /**
100  * Creates a copy (clone) of this instance. Unlike copy construction, this is a very useful function if you
101  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
102  *
103  * \return the clone
104  */
105  virtual WDataSetSingle::SPtr clone() const;
106 
107  /**
108  * \return Reference to its WValueSet
109  */
110  boost::shared_ptr< WValueSetBase > getValueSet() const;
111 
112  /**
113  * \return Reference to its WGrid
114  */
115  boost::shared_ptr< WGrid > getGrid() const;
116 
117  /**
118  * Get the value stored at position of the value set. This is the grid position only for scalar data sets.
119  *
120  * \param id The id'th value in the data set
121  *
122  * \return Scalar value for that given position
123  */
124  template< typename T > T getValueAt( size_t id );
125 
126  /**
127  * Get the value stored at position of the value set. This is the grid position only for scalar data sets.
128  *
129  * \param id The id'th value in the data set
130  *
131  * \return Scalar value for that given position
132  */
133  double getValueAt( size_t id ) const;
134 
135  /**
136  * Determines whether this dataset can be used as a texture.
137  *
138  * \return true if usable as texture.
139  */
140  virtual bool isTexture() const;
141 
142  /**
143  * Returns the texture representation of the dataset. May throw an exception if no texture is available.
144  *
145  * \return the texture.
146  */
147  virtual osg::ref_ptr< WDataTexture3D > getTexture() const;
148 
149  /**
150  * Gets the name of this prototype.
151  *
152  * \return the name.
153  */
154  virtual const std::string getName() const;
155 
156  /**
157  * Gets the description for this prototype.
158  *
159  * \return the description
160  */
161  virtual const std::string getDescription() const;
162 
163  /**
164  * Returns a prototype instantiated with the true type of the deriving class.
165  *
166  * \return the prototype.
167  */
168  static boost::shared_ptr< WPrototyped > getPrototype();
169 
170 protected:
171  /**
172  * The prototype as singleton.
173  */
174  static boost::shared_ptr< WPrototyped > m_prototype;
175 
176  /**
177  * Stores the reference of the WGrid of this DataSetSingle instance.
178  */
179  boost::shared_ptr< WGrid > m_grid;
180 
181  /**
182  * Stores the reference of the WValueSet of this DataSetSingle instance.
183  */
184  boost::shared_ptr< WValueSetBase > m_valueSet;
185 
186 private:
187  /**
188  * The 3D texture representing this dataset.
189  */
190  osg::ref_ptr< WDataTexture3D > m_texture;
191 };
192 
193 template< typename T > T WDataSetSingle::getValueAt( size_t id )
194 {
195  boost::shared_ptr< WValueSet< T > > vs = boost::dynamic_pointer_cast< WValueSet< T > >( m_valueSet );
196  return vs->getScalar( id );
197 }
198 #endif // WDATASETSINGLE_H
boost::shared_ptr< WGrid > m_grid
Stores the reference of the WGrid of this DataSetSingle instance.
static boost::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
Base class for all data set types.
Definition: WDataSet.h:55
boost::shared_ptr< WValueSetBase > getValueSet() const
virtual WDataSetSingle::SPtr clone() const
Creates a copy (clone) of this instance.
osg::ref_ptr< WDataTexture3D > m_texture
The 3D texture representing this dataset.
boost::shared_ptr< WGrid > getGrid() const
virtual const std::string getName() const
Gets the name of this prototype.
virtual T getScalar(size_t i) const
Definition: WValueSet.h:195
boost::shared_ptr< WValueSetBase > m_valueSet
Stores the reference of the WValueSet of this DataSetSingle instance.
A data set consisting of a set of values based on a grid.
static boost::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
virtual ~WDataSetSingle()
Destroys this DataSet instance.
boost::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a boost::shared_ptr.
Base Class for all value set types.
Definition: WValueSet.h:48
WDataSetSingle()
Construct an empty and unusable instance.
virtual const std::string getDescription() const
Gets the description for this prototype.
virtual osg::ref_ptr< WDataTexture3D > getTexture() const
Returns the texture representation of the dataset.
This class allows simple creation of WGETexture3D by using a specified grid and value-set.
boost::shared_ptr< const WDataSetSingle > ConstSPtr
Convenience typedef for a boost::shared_ptr; const.
virtual bool isTexture() const
Determines whether this dataset can be used as a texture.
T getValueAt(size_t id)
Get the value stored at position of the value set.