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