HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 bool isActive(const UT_Vector3 &pos) = 0;
32  virtual fpreal getValueF(const UT_Vector3 &pos) = 0;
33  virtual fpreal getValueAtIndexF(int ix, int iy, int iz) = 0;
34  virtual UT_Vector3D getValueV3(const UT_Vector3 &pos) = 0;
35 };
36 
38 {
39 public:
41  {
42  myVDBCache = 0;
43  bindPrim(0);
44  }
46  {
47  myVDBCache = 0;
48  bindPrim(prim);
49  }
50 
52  {
53  myVDBCache = 0;
54  bindPrim(src.myPrim);
55  }
57  {
58  delete myVDBCache;
59  }
60 
62  {
63  delete myVDBCache;
64  myVDBCache = 0;
65  bindPrim(src.myPrim);
66 
67  return *this;
68  }
69 
70  bool isBound()
71  {
72  return myVol != NULL || myVdb != NULL;
73  }
74 
75  void bindPrim(const GEO_Primitive *prim)
76  {
77  delete myVDBCache;
78  myVDBCache = 0;
79 
80  myPrim = prim;
81  myVol = dynamic_cast<const GEO_PrimVolume *>(prim);
82  myVdb = dynamic_cast<const GEO_PrimVDB *>(prim);
83  myVectorSize = 0;
84  if (myVol)
85  {
86  myHandle = myVol->getVoxelHandle();
87  myVectorSize = 1;
88  }
89  if (myVdb)
90  {
91  myVectorSize = myVdb->getTupleSize();
92  myVDBCache = createVDBCache(myVdb);
93 
94  if (!myVDBCache)
95  myVdb = 0;
96  }
97  }
98 
99  int getVectorSize() const { return myVectorSize; }
100 
101  /// Checks whether the given location falls within the volume's active
102  /// region.
103  inline bool isActive(const UT_Vector3 &pos)
104  {
105  if(myVol)
106  return myVol->isInsideStrict(pos, myHandle);
107  if(myVdb)
108  return myVDBCache->isActive(pos);
109 
110  return false;
111  }
112 
113  inline fpreal getValueF(const UT_Vector3 &pos)
114  {
115  if (myVol)
116  return myVol->getValue(pos, myHandle);
117  if (myVdb)
118  return myVDBCache->getValueF(pos);
119 
120  return 0;
121  }
122 
123  inline fpreal getValueAtIndexF(int ix, int iy, int iz)
124  {
125  if (myVol)
126  return myHandle->getValue(ix, iy, iz);
127  if (myVdb)
128  return myVDBCache->getValueAtIndexF(ix, iy, iz);
129 
130  return 0;
131  }
132 
133  inline UT_Vector3D getValueV3(const UT_Vector3 &pos)
134  {
135  if (myVol)
136  return UT_Vector3D(myVol->getValue(pos, myHandle), 0, 0);
137  if (myVdb)
138  return myVDBCache->getValueV3(pos);
139 
140  return UT_Vector3D(0, 0, 0);
141  }
142 
143  static GEO_VolumeSamplerVDBCache *createVDBCache(const GEO_PrimVDB *vdb);
144 
145 protected:
152 };
153 
154 #endif // __GEO_VOLUMESAMPLER_H_INCLUDED__
155 
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)
bool isActive(const UT_Vector3 &pos)
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:270
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