HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GVEX_GeoCache.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: GVEX_GeoCache.h ( GVEX Library, C++)
7  *
8  * COMMENTS: Geometry cache for GVEX functions
9  */
10 
11 #ifndef __GVEX_GeoCache__
12 #define __GVEX_GeoCache__
13 
14 #include "GVEX_API.h"
15 #include <GA/GA_Types.h>
16 #include <VEX/VEX_PodTypes.h>
17 #include <UT/UT_BoundingBox.h>
18 #include <UT/UT_IntrusivePtr.h>
19 #include <UT/UT_SharedPtr.h>
20 #include <UT/UT_VectorTypes.h>
21 #include <SYS/SYS_Types.h>
23 #include <hboost/any.hpp>
24 
25 namespace GEO {
26 template<uint NAXES> class PointBVHT;
27 using PointBVH = PointBVHT<3>;
28 }
29 
30 class GVEX_MetaList;
31 
32 template <VEX_Precision PREC> class VEX_Instance;
33 class VEX_ProcArray;
34 
35 class GT_UtilOpenSubdiv;
36 class GU_Detail;
37 class GU_OceanEvaluator;
38 class GU_PrimRTree;
39 class GU_RayIntersect;
42 class GU_VexGeoInputs;
46 class IMG3D_PCloud;
47 
48 class TS_MetaExpression;
50 
51 template <typename T> class UT_Array;
52 
53 
55 {
56 public:
57  const char *myFilename;
58  int myMemory;
59 };
60 
61 
62 /// An item in the geometry cache, which can be a pointer to anything. The
63 /// cache will take over ownership of the pointer and delete it at the
64 /// appropriate time.
66 {
67 public:
69  {
70  }
71 
72  template <typename T>
73  GVEX_GeoCacheItem(const T *value) : myItem(UT_SharedPtr<const T>(value))
74  {
75  }
76 
77  /// Access this item's data. The type must match, otherwise an exception
78  /// will be thrown.
79  template <typename T>
80  const T *get() const
81  {
82  return hboost::any_cast< UT_SharedPtr<const T> >(myItem).get();
83  }
84 
85 private:
86  hboost::any myItem;
87 };
88 
89 /// Callback to create a new item for the GVEX_GeoCache.
90 template <VEX_Precision PREC>
92 
94 
96 
98 {
99 public:
100  // Cache controls
101  // The memory available to the cache
102  // Auto-flush turns on automatic flushing of de-referenced geometry
103  // All methods return the previous value.
104  // Pruning the cache will attempt to free up some memory if possible
105  static int64 setCacheMemory(int64 memoryinkb=8192);
106  static int64 getCacheMemorySize();
107  static int setAutoFlush(int flush);
108  static int getAutoFlush();
109  static void clearCache(int out_of_date_only=0);
110  static void clearCache(const char* file);
111  static void pruneCache();
112 
113  static int64 getMemoryUsage();
114  static int64 getPeakUsage();
115 
116  static void setDefaultMetaballGeometry(GU_Detail *gdp);
117 
118  // Cache queries
119  // Find out how many entries are in the geometry cache
120  // Find out information about each entry (it's possible that the gdp
121  // returned might be null).
122  static int getCacheEntries();
123  static void getCacheStat(GVEX_GeoStat stat[]);
124 
125  // Construct a gvex_internalGeo * that refers to a given GU_Detail.
126  // This can be used to pre-populate the vexcache of GU_VexGeoInputs.
127  static void createInternalGeos(GU_VexGeoInputs *geoinputs);
128 
129  // Look up a GVEX_MetaList given the handle
130  static GVEX_MetaList *getMetaList(int id);
131 
132  // Retrieve a new handle id for metaball iteration. Use getMetaList()
133  // to retrieve the object.
134  static int startMetaList(VEX_Instance<VEX_32> &state,
135  VEX_ProcArray &proc,
136  const UT_Vector3 *P,
137  int pinc, const char *file);
138 
139 };
140 
141 template <VEX_Precision PREC>
143 {
144 public:
145  // Internal helper functions for binding geometry to VEX instructions.
146  // The bind function will return the index to access the detail (via the
147  // getDetail/getRayTree methods).
148  static void bindDetail(VEX_Instance<PREC> &state);
149 
150  // Access methods (once the detail has been bound)
151  static const GU_Detail *getDetail(VEX_Instance<PREC> &state,
152  const char *file);
153  static void getPrimBBox(VEX_Instance<PREC> &state,
154  UT_BoundingBox &box,
155  const char *file);
156  static void getPrimBBox(VEX_Instance<PREC> &state,
157  UT_BoundingBox &box,
158  const char *file,
159  const char *group);
160  static void getPointBBox(VEX_Instance<PREC> &state,
161  UT_BoundingBox &box,
162  const char *file);
163  static void getPointBBox(VEX_Instance<PREC> &state,
164  UT_BoundingBox &box,
165  const char *file,
166  const char *group);
167  static GU_RayIntersect *getRayTree(VEX_Instance<PREC> &state,
168  const char *file);
169  static GU_RayIntersect *getRayTree(VEX_Instance<PREC> &state,
170  const char *file,
171  const char *group);
172  static GU_RayIntersect *getMinTree(VEX_Instance<PREC> &state,
173  const char *file);
174  static GU_RayIntersect *getMinTree(VEX_Instance<PREC> &state,
175  const char *file,
176  const char *group);
177  static const openvdb::tools::PointIndexGrid *getPointGrid(VEX_Instance<PREC> &state,
178  float divsize,
179  const char *file,
180  const char *group);
181  static GA_IndexArray *getRingZero(VEX_Instance<PREC> &state,
182  int ptnum,
183  const char *file);
184  static UT_Array<GA_Size> *getPrimVertexArray(VEX_Instance<PREC> &state,
185  const char *file);
186  static UT_Array<GA_IndexArray> *getRingZeroArray(VEX_Instance<PREC> &state,
187  const char *file);
188  static GEO_DetachedHedgeInterface *getHedge(VEX_Instance<PREC> &state,
189  const char *file);
190 
191  static const GT_UtilOpenSubdiv *getOSDEvaluator(VEX_Instance<PREC> &state,
192  const char *file);
193 
194  static TS_MetaExpressionPtr getTSMetaExpr(VEX_Instance<PREC> &state,
195  const char *file);
196  static IMG3D_PCloud *getPCloud(VEX_Instance<PREC> &state,
197  const char *file);
198 
199  static void expandGroup(VEX_Instance<PREC> &state,
200  const char *file,
201  const char *group,
202  int grouptype,
203  bool ordered,
204  exint &alen,
205  const exint *&adata);
206 
207  static GU_PrimRTree *getPrimTree(VEX_Instance<PREC> &state,
208  const char *file);
209  static GU_PrimRTree *getPrimTree(VEX_Instance<PREC> &state,
210  const char *file,
211  const char *group);
212 
213  static GVEX_PointTreeType *getPointTree(VEX_Instance<PREC> &state,
214  const char *file,
215  const char *group,
216  const char *attrib);
217 
218  static GVEX_PointTreeType *getRadTree(VEX_Instance<PREC> &state,
219  const char *file,
220  const char *group,
221  const char *attrib,
222  const char *rad,
223  float radscale);
224 
225  static GU_OceanEvaluator *getOceanEval(VEX_Instance<PREC> &state,
226  const char *file,
227  int phase, int freq, int amp,
228  float hscale, float time,
229  int mode, int downsample);
230 
231  static GU_TetrahedronAdjacency *getTetAdj(VEX_Instance<PREC> &state,
232  const char *file);
233 
234  static GU_SurfaceDistanceCache *getSDCache(VEX_Instance<PREC> &state,
235  const char *file,
236  const char *group,
237  const char *p_attrib,
238  float radius,
239  const char *dist_metric);
240 
241  static GU_WindingNumber3DApprox *getWindingNumber(VEX_Instance<PREC> &state,
242  const char *file);
243  static GU_WindingNumber3DApprox *getWindingNumber(VEX_Instance<PREC> &state,
244  const char *file,
245  const char *group);
246  static GU_WindingNumber2DApprox *getWindingNumber2D(VEX_Instance<PREC> &state,
247  const char *file);
248  static GU_WindingNumber2DApprox *getWindingNumber2D(VEX_Instance<PREC> &state,
249  const char *file,
250  const char *group);
251 
252 
253  /// Access a custom item in the cache. The type must match, otherwise an
254  /// exception will be thrown. The callback will be run to create the item
255  /// if an item with that id does not already exist.
256  template <typename T>
257  static const T *get(const char *id, VEX_Instance<PREC> &state, const char *file,
259  {
260  return getCacheItem(id, state, file, callback).template get<T>();
261  }
262 
263 private:
264  /// Helper function to fetch a custom item from the cache, or create it if
265  /// necessary.
266  static GVEX_GeoCacheItem
267  getCacheItem(const char *id, VEX_Instance<PREC> &state, const char *file,
269 };
270 
273 
274 #endif
GVEX_ConstructCacheItemT< VEX_32 > GVEX_ConstructCacheItem
Definition: GVEX_GeoCache.h:93
#define GVEX_API
Definition: GVEX_API.h:12
GT_API const UT_StringHolder filename
const char * myFilename
Definition: GVEX_GeoCache.h:57
GT_API const UT_StringHolder time
GLsizei const GLfloat * value
Definition: glcorearb.h:824
int64 exint
Definition: SYS_Types.h:125
GVEX_GeoCacheItem(*)(VEX_Instance< PREC > &state, const char *filename) GVEX_ConstructCacheItemT
Callback to create a new item for the GVEX_GeoCache.
Definition: GVEX_GeoCache.h:91
GVEX_GeoCacheItem(const T *value)
Definition: GVEX_GeoCache.h:73
PointBVHT< 3 > PointBVH
Definition: GEO_BVH.h:598
GVEX_EXTERN_TEMPLATE(GVEX_GeoCacheT< VEX_32 >)
bool any(const vbool4 &v)
Definition: simd.h:3600
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
long long int64
Definition: SYS_Types.h:116
GLuint id
Definition: glcorearb.h:655
GLenum mode
Definition: glcorearb.h:99
Grid< PointIndexTree > PointIndexGrid
Point index grid.
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
Processor proc(inIter, Adapter::tree(outGrid), op, merge)
state
Definition: core.h:2289
Class to perform subdivision refinement using OpenSubdivision.