HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEO_VolumeSampler.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: GEO_VolumeSampler.h (GEO Library, C++)
7  *
8  * COMMENTS:
9  * This is an adapter class that lets you efficiently
10  * sample both PrimVolumes and PrimVDBs.
11  *
12  * It is *not* threadsafe to use the same volume sampler
13  * from multiple threads!
14  */
15 
16 #ifndef __GEO_VOLUMESAMPLER_H_INCLUDED__
17 #define __GEO_VOLUMESAMPLER_H_INCLUDED__
18 
19 #include <UT/UT_VoxelArray.h>
20 
21 #include "GEO_API.h"
22 #include "GEO_PrimVolume.h"
23 #include "GEO_PrimVDB.h"
24 
26 {
27 public:
30 
31  virtual fpreal getValueF(const UT_Vector3 &pos) = 0;
32  virtual fpreal getValueAtIndexF(int ix, int iy, int iz) = 0;
33  virtual UT_Vector3D getValueV3(const UT_Vector3 &pos) = 0;
34 };
35 
37 {
38 public:
40  {
41  myVDBCache = 0;
42  bindPrim(0);
43  }
45  {
46  myVDBCache = 0;
47  bindPrim(prim);
48  }
49 
51  {
52  myVDBCache = 0;
53  bindPrim(src.myPrim);
54  }
56  {
57  delete myVDBCache;
58  }
59 
61  {
62  delete myVDBCache;
63  myVDBCache = 0;
64  bindPrim(src.myPrim);
65 
66  return *this;
67  }
68 
69  void bindPrim(const GEO_Primitive *prim)
70  {
71  delete myVDBCache;
72  myVDBCache = 0;
73 
74  myPrim = prim;
75  myVol = dynamic_cast<const GEO_PrimVolume *>(prim);
76  myVdb = dynamic_cast<const GEO_PrimVDB *>(prim);
77  myVectorSize = 0;
78  if (myVol)
79  {
80  myHandle = myVol->getVoxelHandle();
81  myVectorSize = 1;
82  }
83  if (myVdb)
84  {
85  myVectorSize = myVdb->getTupleSize();
86  myVDBCache = createVDBCache(myVdb);
87 
88  if (!myVDBCache)
89  myVdb = 0;
90  }
91  }
92 
93  int getVectorSize() const { return myVectorSize; }
94 
95  inline fpreal getValueF(const UT_Vector3 &pos)
96  {
97  if (myVol)
98  return myVol->getValue(pos, myHandle);
99  if (myVdb)
100  return myVDBCache->getValueF(pos);
101 
102  return 0;
103  }
104 
105  inline fpreal getValueAtIndexF(int ix, int iy, int iz)
106  {
107  if (myVol)
108  return myHandle->getValue(ix, iy, iz);
109  if (myVdb)
110  return myVDBCache->getValueAtIndexF(ix, iy, iz);
111 
112  return 0;
113  }
114 
115  inline UT_Vector3D getValueV3(const UT_Vector3 &pos)
116  {
117  if (myVol)
118  return UT_Vector3D(myVol->getValue(pos, myHandle), 0, 0);
119  if (myVdb)
120  return myVDBCache->getValueV3(pos);
121 
122  return UT_Vector3D(0, 0, 0);
123  }
124 
125  static GEO_VolumeSamplerVDBCache *createVDBCache(const GEO_PrimVDB *vdb);
126 
127 protected:
134 };
135 
136 #endif // __GEO_VOLUMESAMPLER_H_INCLUDED__
137 
int getVectorSize() const
GEO_VolumeSamplerVDBCache * myVDBCache
GEO_VolumeSampler & operator=(const GEO_VolumeSampler &src)
UT_VoxelArrayReadHandleF myHandle
int getTupleSize() const
Get the tuple size, usually 1 or 3.
Definition: GEO_PrimVDB.h:191
fpreal getValueAtIndexF(int ix, int iy, int iz)
GEO_VolumeSampler(const GEO_Primitive *prim)
GEO_VolumeSampler(const GEO_VolumeSampler &src)
const GEO_PrimVDB * myVdb
#define GEO_API
Definition: GEO_API.h:10
UT_Vector3T< fpreal64 > UT_Vector3D
double fpreal
Definition: SYS_Types.h:269
const GEO_Primitive * myPrim
void bindPrim(const GEO_Primitive *prim)
fpreal getValueF(const UT_Vector3 &pos)
UT_Vector3D getValueV3(const UT_Vector3 &pos)
const GEO_PrimVolume * myVol
GLenum src
Definition: glcorearb.h:1792