HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_FieldSampler.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SIM_FieldSampler.h ( SIM Library, C++)
7  *
8  * COMMENTS:
9  * This file contains relative sampler classes for probing field values at
10  * index coordinates of the reference field. The sampler backend will select
11  * the best probing method for the given field pair.
12  * The common approach to working on fields involves iterating over voxels of
13  * the destination grid. At these voxel locations, values of other fields may
14  * be required. Here, field samplers declared in this header can be used for
15  * efficient sampling, without having to worry about matching and alignment.
16  * In addition to getValue() methods, samplers also support checking if target
17  * tiles lie in a constant area of the source field.
18  */
19 
20 #ifndef __SIM_FieldSampler__
21 #define __SIM_FieldSampler__
22 
23 #include "SIM_API.h"
24 #include "SIM_ScalarField.h"
25 
26 #include <UT/UT_NonCopyable.h>
27 #include <UT/UT_VoxelArray.h>
28 
29 #include <SYS/SYS_TypeDecorate.h>
30 
31 class SIM_RawField;
32 class SIM_RawIndexField;
33 
34 /// This internal abstract class implements sampling for scalar fields. Hidden
35 /// concrete subclasses take care of actual probing.
36 /// The createSampler static method should be used to instantiate a sampler.
38 {
39 protected:
41 
42 public:
44 
45  /// This static method creates an appropriate sampler for the given fields.
46  template <typename FIELD_TYPE>
48  createSampler(const FIELD_TYPE* target,
49  const SIM_RawField* source);
50  /// This static method creates an appropriate sampler for reading the source
51  /// field as cells of target are iterated at target_sample locations.
54  const SIM_RawField* source,
55  SIM_FieldSample target_sample);
56 
57  virtual float getValue(int x, int y, int z) = 0;
58  virtual float getValue(float x, float y, float z) = 0;
59  virtual bool isTileConstant(int tx, int ty, int tz,
60  const UT_VoxelTile<float>* tile,
61  float& val) = 0;
62 
63 protected:
65 };
66 
67 /// This internal abstract class implements sampling for vector fields.
68 /// The createSampler static method should be used to instantiate a sampler.
70 {
71 protected:
73 
74 public:
76 
77  template <typename FIELD_TYPE>
79  createSampler(const FIELD_TYPE* target,
80  const SIM_VectorField* source);
81 
82  virtual UT_Vector3 getValue(int x, int y, int z) = 0;
83  virtual UT_Vector3 getValue(float x, float y, float z) = 0;
84  virtual bool isTileConstant(int tx, int ty, int tz,
85  const UT_VoxelTile<float>* tile,
86  UT_Vector3& val) = 0;
87 
88 protected:
90 };
91 
92 /// This class is an efficient relative scalar field sampler. It samples the
93 /// source field, given coordinates in index space of the target (or an iterator
94 /// running over the target field).
96 {
97 public:
98  /// Default constructor; init() method must be called before the sampler is
99  /// usable.
101  {
102  }
103 
104  /// These constructors also initialize the sampler for immediate use.
106  const SIM_RawField* source)
107  {
108  init(target, source);
109  }
111  const SIM_ScalarField* source)
112  {
113  init(target, source->getField());
114  }
116  const SIM_RawField* source)
117  {
118  init(target, source);
119  }
121  const SIM_ScalarField* source)
122  {
123  init(target, source->getField());
124  }
125  /// These constructors initialize the sampler for immediate use, when
126  /// iterating over the target vector field with sampling given by
127  /// target_sample.
129  const SIM_RawField* source,
130  SIM_FieldSample target_sample)
131  {
132  init(target, source, target_sample);
133  }
135  const SIM_ScalarField* source,
136  SIM_FieldSample target_sample)
137  {
138  init(target, source->getField(), target_sample);
139  }
140 
141  /// The destructor.
143  {
144  }
145 
146  /// Initialization routines that must be called before the sampler can be
147  /// used. Note that constructors that accept field pointers call init() to
148  /// ensure that the object is ready for use.
150  {
151  mySampler = SIM_SFSImplementation::createSampler(target, source);
152  }
154  {
155  mySampler = SIM_SFSImplementation::createSampler(target, source);
156  }
157  /// This version of initialization is for sampling source with respect to
158  /// cells of target at locations given by target_sample.
160  SIM_FieldSample target_sample)
161  {
162  mySampler = SIM_SFSImplementation::createSampler(target, source,
163  target_sample);
164  }
165 
166  /// Returns value of the source field at the given (exact) coordinates of
167  /// the target field.
168  SYS_FORCE_INLINE float getValue(int x, int y, int z)
169  {
170  return mySampler->getValue(x, y, z);
171  }
172 
173  /// Returns value of the source field at the current voxel of the iterator.
175  {
176  return mySampler->getValue(iter.x(), iter.y(), iter.z());
177  }
178 
179  /// Returns value of the source field at the given coordinates of the target
180  /// field.
181  SYS_FORCE_INLINE float getValue(float x, float y, float z)
182  {
183  return mySampler->getValue(x, y, z);
184  }
185 
186  /// Returns value of the source field at the given coordinates of the target
187  /// field.
189  {
190  return mySampler->getValue(p.x(), p.y(), p.z());
191  }
192 
193  /// Returns true if the source field is constant within the current tile of
194  /// the target iterator. If it's constant, the constant value is stored in
195  /// val. Note that this method doesn't exhaustively look into voxels, but
196  /// only checks for compressed ones.
198  float& val)
199  {
200  return mySampler->isTileConstant(iter.myTilePos[0], iter.myTilePos[1],
201  iter.myTilePos[2], iter.getTile(),
202  val);
203  }
204 
205 protected:
208 };
209 
211 
212 /// This class is an efficient relative vector field sampler. It samples the
213 /// source field, given coordinates in index space of the target (or an iterator
214 /// running over the target field).
216 {
217 public:
218  /// Default constructor; init() method must be called before the sampler is
219  /// usable.
221  {
222  }
223 
224  /// These constructors also initialize the sampler for immediate use.
226  const SIM_VectorField* source)
227  {
228  init(target, source);
229  }
231  const SIM_VectorField* source)
232  {
233  init(target, source);
234  }
235 
236  /// The destructor.
238  {
239  }
240 
241  /// Initialization routines that must be called before the sampler can be
242  /// used. Note that constructors that accept field pointers call init() to
243  /// ensure that the object is ready for use.
245  {
246  mySampler = SIM_VFSImplementation::createSampler(target, source);
247  }
249  {
250  mySampler = SIM_VFSImplementation::createSampler(target, source);
251  }
252 
253  /// Returns value of the source field at the given (exact) coordinates of
254  /// the target field.
256  {
257  return mySampler->getValue(x, y, z);
258  }
259 
260  /// Returns value of the source field at the current voxel of the iterator.
262  {
263  return mySampler->getValue(iter.x(), iter.y(), iter.z());
264  }
265 
266  /// Returns value of the source field at the given coordinates of the target
267  /// field.
268  SYS_FORCE_INLINE UT_Vector3 getValue(float x, float y, float z)
269  {
270  return mySampler->getValue(x, y, z);
271  }
272 
273  /// Returns value of the source field at the given coordinates of the target
274  /// field.
276  {
277  return mySampler->getValue(p.x(), p.y(), p.z());
278  }
279 
280  /// Returns true if the source field is constant within the current tile of
281  /// the target iterator. If it's constant, the constant value is stored in
282  /// val. Note that this method doesn't exhaustively look into voxels, but
283  /// only checks for compressed ones.
285  UT_Vector3& val)
286  {
287  return mySampler->isTileConstant(iter.myTilePos[0], iter.myTilePos[1],
288  iter.myTilePos[2], iter.getTile(),
289  val);
290  }
291 
292 protected:
295 };
296 
297 #endif
298 
int x() const
Retrieve the current location of the iterator.
~SIM_VectorFieldSampler()
The destructor.
SYS_FORCE_INLINE bool isTileConstant(const UT_VoxelArrayIteratorF &iter, float &val)
UT_VoxelTile< T > * getTile() const
Returns the VoxelTile we are currently processing.
virtual ~SIM_VFSImplementation()
SIM_VectorFieldSampler(const SIM_RawIndexField *target, const SIM_VectorField *source)
SYS_FORCE_INLINE UT_Vector3 getValue(const UT_VoxelArrayIteratorF &iter)
Returns value of the source field at the current voxel of the iterator.
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
SYS_FORCE_INLINE float getValue(int x, int y, int z)
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector3.h:667
SYS_FORCE_INLINE float getValue(const UT_VoxelArrayIteratorF &iter)
Returns value of the source field at the current voxel of the iterator.
GLint y
Definition: glcorearb.h:103
int myTilePos[3]
Which tile we are as per tx,ty,tz rather than linear index.
SIM_ScalarFieldSampler(const SIM_VectorField *target, const SIM_RawField *source, SIM_FieldSample target_sample)
static SIM_API UT_UniquePtr< SIM_VFSImplementation > createSampler(const FIELD_TYPE *target, const SIM_VectorField *source)
~SIM_ScalarFieldSampler()
The destructor.
void init(const SIM_RawField *target, const SIM_VectorField *source)
SIM_FieldSample
Definition: SIM_RawField.h:38
virtual float getValue(int x, int y, int z)=0
void init(const SIM_RawIndexField *target, const SIM_VectorField *source)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
SIM_ScalarFieldSampler(const SIM_RawField *target, const SIM_RawField *source)
These constructors also initialize the sampler for immediate use.
SYS_FORCE_INLINE UT_Vector3 getValue(int x, int y, int z)
SIM_ScalarFieldSampler(const SIM_RawIndexField *target, const SIM_ScalarField *source)
void init(const SIM_RawField *target, const SIM_RawField *source)
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
SIM_ScalarFieldSampler(const SIM_VectorField *target, const SIM_ScalarField *source, SIM_FieldSample target_sample)
GLenum target
Definition: glcorearb.h:1667
virtual bool isTileConstant(int tx, int ty, int tz, const UT_VoxelTile< float > *tile, UT_Vector3 &val)=0
SYS_FORCE_INLINE bool isTileConstant(const UT_VoxelArrayIteratorF &iter, UT_Vector3 &val)
SYS_DECLARE_LEGACY_TR(GU_Detail)
UT_UniquePtr< SIM_VFSImplementation > mySampler
GLint GLenum GLint x
Definition: glcorearb.h:409
void init(const SIM_VectorField *target, const SIM_RawField *source, SIM_FieldSample target_sample)
UT_UniquePtr< SIM_SFSImplementation > mySampler
const SIM_RawField * getField() const
Retrieve raw field.
SYS_FORCE_INLINE float getValue(const UT_Vector3 &p)
SIM_ScalarFieldSampler(const SIM_RawIndexField *target, const SIM_RawField *source)
const UT_VoxelArrayF * mySourceArrays[3]
SIM_ScalarFieldSampler(const SIM_RawField *target, const SIM_ScalarField *source)
virtual UT_Vector3 getValue(int x, int y, int z)=0
#define SIM_API
Definition: SIM_API.h:12
GLuint GLfloat * val
Definition: glcorearb.h:1608
This class holds a three dimensional scalar field.
void init(const SIM_RawIndexField *target, const SIM_RawField *source)
SYS_FORCE_INLINE float getValue(float x, float y, float z)
SIM_VectorFieldSampler(const SIM_RawField *target, const SIM_VectorField *source)
These constructors also initialize the sampler for immediate use.
SYS_FORCE_INLINE UT_Vector3 getValue(const UT_Vector3 &p)
virtual ~SIM_SFSImplementation()
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:665
const UT_VoxelArrayF * mySourceArray
This class holds a three dimensional vector field.
SYS_FORCE_INLINE UT_Vector3 getValue(float x, float y, float z)
static SIM_API UT_UniquePtr< SIM_SFSImplementation > createSampler(const FIELD_TYPE *target, const SIM_RawField *source)
This static method creates an appropriate sampler for the given fields.
virtual bool isTileConstant(int tx, int ty, int tz, const UT_VoxelTile< float > *tile, float &val)=0
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:663