OpenWalnut  1.4.0
WDataSetScalar.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 WDATASETSCALAR_H
26 #define WDATASETSCALAR_H
27 
28 #include <map>
29 #include <string>
30 
31 #ifndef Q_MOC_RUN
32 #include <boost/thread.hpp>
33 #endif
34 #ifndef Q_MOC_RUN
35 #include <boost/shared_ptr.hpp>
36 #endif
37 
38 #include "datastructures/WValueSetHistogram.h"
39 
40 #include "WDataSetSingle.h"
41 
42 
43 /**
44  * This data set type contains scalars as values.
45  * \ingroup dataHandler
46  */
47 class WDataSetScalar : public WDataSetSingle // NOLINT
48 {
49 public:
50  /**
51  * shared_ptr abbreviation
52  */
53  typedef boost::shared_ptr< WDataSetScalar > SPtr;
54 
55  /**
56  * const shared_ptr abbreviation
57  */
58  typedef boost::shared_ptr< const WDataSetScalar > ConstSPtr;
59 
60  /**
61  * Constructs an instance out of an appropriate value set and a grid.
62  * Computes the maximum an minimum values stored as member variables.
63  *
64  * \param newValueSet the scalar value set to use
65  * \param newGrid the grid which maps world space to the value set
66  */
67  WDataSetScalar( boost::shared_ptr< WValueSetBase > newValueSet,
68  boost::shared_ptr< WGrid > newGrid );
69 
70  /**
71  * Construct an empty and unusable instance. This is needed for the prototype mechanism.
72  */
74 
75  /**
76  * Destroys this DataSet instance
77  */
78  virtual ~WDataSetScalar();
79 
80  /**
81  * 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
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 one 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  * Returns the largest of the scalars stored in the data set
110  *
111  * \return maximum value in dataset
112  */
113  double getMax() const;
114 
115  /**
116  * Returns the smallest of the scalars stored in the data set
117  *
118  * \return minimum value in dataset
119  */
120  double getMin() const;
121 
122  /**
123  * Gets the name of this prototype.
124  *
125  * \return the name.
126  */
127  virtual const std::string getName() const;
128 
129  /**
130  * Gets the description for this prototype.
131  *
132  * \return the description
133  */
134  virtual const std::string getDescription() const;
135 
136  /**
137  * Returns the histogram of this dataset's valueset. If it does not exist yet, it will be created and cached. It does NOT make use of the
138  * WValueSetHistogram down scaling feature even though the number of buckets might be lower than the default as the down scaling might
139  * introduce errors. To use down-scaling, grab the default histogram and call WValueSetHistogram( getHistogram(), buckets ) manually.
140  *
141  * \param buckets the number of buckets inside the histogram.
142  *
143  * \return the histogram.
144  */
145  boost::shared_ptr< const WValueSetHistogram > getHistogram( size_t buckets = 1000 );
146 
147  /**
148  * Interpolate the value fo the valueset at the given position.
149  * If interpolation fails, the success parameter will be false
150  * and the value returned zero.
151  *
152  * \param pos The position for wich we would like to get a value.
153  * \param success indicates whether the interpolation was successful
154  *
155  * \return Scalar value for that given position
156  */
157  double interpolate( const WPosition& pos, bool* success ) const;
158 
159  /**
160  * Get the value stored at a certain grid position of the data set
161  * \param x index in x direction
162  * \param y index in y direction
163  * \param z index in z direction
164  *
165  * \return the value at the grid position with the given index tuple.
166  */
167  template< typename T > T getValueAt( int x, int y, int z ) const;
168 
169  /**
170  * Get the value stored at a certain grid position of the data set
171  * \param x index in x direction
172  * \param y index in y direction
173  * \param z index in z direction
174  *
175  * \return the double the grid position with the given index tuple.
176  */
177  double getValueAt( int x, int y, int z ) const;
178 
179 
180  /**
181  * Returns a prototype instantiated with the true type of the deriving class.
182  *
183  * \return the prototype.
184  */
185  static boost::shared_ptr< WPrototyped > getPrototype();
186 
188 
189 protected:
190  /**
191  * The prototype as singleton.
192  */
193  static boost::shared_ptr< WPrototyped > m_prototype;
194 
195 private:
196  /**
197  * The histograms for later use. Each histogram for a requested bucket count gets cached.
198  **/
199  std::map< size_t, boost::shared_ptr< WValueSetHistogram > > m_histograms;
200 
201  /**
202  * The lock used for securely creating m_histogram on demand.
203  */
204  boost::mutex m_histogramLock;
205 };
206 
207 template< typename T > T WDataSetScalar::getValueAt( int x, int y, int z ) const
208 {
209  boost::shared_ptr< WValueSet< T > > vs = boost::dynamic_pointer_cast< WValueSet< T > >( m_valueSet );
210  boost::shared_ptr< WGridRegular3D > grid = boost::dynamic_pointer_cast< WGridRegular3D >( m_grid );
211 
212  size_t id = x + y * grid->getNbCoordsX() + z * grid->getNbCoordsX() * grid->getNbCoordsY();
213 
214  T v = vs->getScalar( id );
215  return v;
216 }
217 
218 #endif // WDATASETSCALAR_H
boost::shared_ptr< WGrid > m_grid
Stores the reference of the WGrid of this DataSetSingle instance.
A grid that has parallelepiped cells which all have the same proportion.
static boost::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
virtual ~WDataSetScalar()
Destroys this DataSet instance.
virtual const std::string getName() const
Gets the name of this prototype.
double interpolate(const WPosition &pos, bool *success) const
Interpolate the value fo the valueset at the given position.
boost::mutex m_histogramLock
The lock used for securely creating m_histogram on demand.
std::map< size_t, boost::shared_ptr< WValueSetHistogram > > m_histograms
The histograms for later use.
This only is a 3d double vector.
WDataSetScalar()
Construct an empty and unusable instance.
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 const std::string getDescription() const
Gets the description for this prototype.
double getMin() const
Returns the smallest of the scalars stored in the data set.
boost::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a boost::shared_ptr.
T getValueAt(int x, int y, int z) const
Get the value stored at a certain grid position of the data set.
Base Class for all value set types.
Definition: WValueSet.h:48
boost::shared_ptr< const WValueSetHistogram > getHistogram(size_t buckets=1000)
Returns the histogram of this dataset's valueset.
virtual WDataSetSingle::SPtr clone() const
Creates a copy (clone) of this instance.
double getMax() const
Returns the largest of the scalars stored in the data set.
This data set type contains scalars as values.
unsigned int getNbCoordsX() const
Returns the number of samples in x direction.
boost::shared_ptr< const WDataSetScalar > ConstSPtr
const shared_ptr abbreviation
boost::shared_ptr< WDataSetScalar > SPtr
shared_ptr abbreviation
T getValueAt(size_t id)
Get the value stored at position of the value set.