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