HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_Surfacer.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: GU_Surfacer.h (C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __GU_Surfacer_h__
13 #define __GU_Surfacer_h__
14 
15 #include "GU_API.h"
16 #include "GU_Detail.h"
17 #include <UT/UT_Map.h>
18 
19 GU_API extern const unsigned char guTopologyPolygonList[];
20 GU_API extern const int guTopologyLookup[256];
21 
22 class GEO_PrimPolySoup;
23 class guSurfacerCellEvaluator;
24 
26 {
27 public:
29  const UT_Vector3 &pos,
30  const UT_Vector3 &size,
31  int xdivs, int ydivs, int zdivs,
32  bool do_normals,
33  bool makepolysoup = false);
34  virtual ~GU_Surfacer();
35 
36  /// Return the size of a cell
37  const UT_Vector3 &getStepSize() const { return myStepSize; }
38 
39  /// create polygons for cell given density values at the corners and
40  /// optionally gradient values
41  void addCell(int x, int y, int z,
42  const fpreal density[8],
43  const UT_Vector3 gradient[8]);
44 
45  /// If using addCell directly, instead of polygonize, call done to finish.
46  void done();
47 
48  class Evaluator {
49  public:
50  Evaluator(bool hasgradient, bool isthreadsafe=false, bool subsample=false)
51  : myHasGradient(hasgradient)
52  , myIsThreadSafe(isthreadsafe)
53  , mySubSample(subsample)
54  {}
55  virtual ~Evaluator() {}
56 
57  virtual fpreal density(const UT_Vector3 &pos) const = 0;
58 
59  bool hasGradient() const { return myHasGradient; }
60  virtual UT_Vector3 gradient(const UT_Vector3 &pos) const
61  { return UT_Vector3(0, 0, 0); }
62  /// This indicates whether density and gradient
63  /// can be called in multiple threads at the same time.
64  bool isThreadSafe() const {return myIsThreadSafe;}
65  /// This indicates whether the density function should be sampled
66  /// along a cell edge to find the zero crossing.
67  bool subsample() const { return mySubSample; }
68 
69  private:
70  bool myHasGradient;
71  bool myIsThreadSafe;
72  bool mySubSample;
73  };
74 
75  /// Surface the entire range, using the Evaluator to calculate density
76  /// and possibly gradient values.
77  void polygonize(Evaluator &eval);
78 
79 protected:
80  /// called after adding a new point to the detail
81  virtual void pointAdded(GEO_Detail *gdp, GA_Offset ptoff, int idx0, int idx1, fpreal u) {}
82  /// called after adding a complete polygon or polysoup to the detail
83  virtual void primitiveAdded(GEO_Primitive *primitive) {}
84 
85 private:
86  void addCell(int x, int y, int z, const guSurfacerCellEvaluator *e);
87 
88  GU_Detail &myGdp;
89  UT_Vector3 myP;
90  UT_Vector3 mySize;
91  UT_Vector3 myStepSize;
92  int myXDivs;
93  int myYDivs;
94  int myZDivs;
95  GA_RWHandleV3 myNormalAttrib;
96  UT_Map<int64, GA_Offset> myPoints;
97  GEO_PrimPolySoup *myPolySoup;
98 };
99 
100 #endif
GU_API const unsigned char guTopologyPolygonList[]
UT_Vector3T< float > UT_Vector3
**And then you can **find out if it s done
Definition: thread.h:622
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
A soup of polygons.
bool isThreadSafe() const
Definition: GU_Surfacer.h:64
GLint y
Definition: glcorearb.h:103
virtual void pointAdded(GEO_Detail *gdp, GA_Offset ptoff, int idx0, int idx1, fpreal u)
called after adding a new point to the detail
Definition: GU_Surfacer.h:81
GA_Size GA_Offset
Definition: GA_Types.h:646
const UT_Vector3 & getStepSize() const
Return the size of a cell.
Definition: GU_Surfacer.h:37
Evaluator(bool hasgradient, bool isthreadsafe=false, bool subsample=false)
Definition: GU_Surfacer.h:50
virtual UT_Vector3 gradient(const UT_Vector3 &pos) const
Definition: GU_Surfacer.h:60
GU_API const int guTopologyLookup[256]
HUSD_API bool eval(VtValue &val, T &ret_val)
#define GU_API
Definition: GU_API.h:14
GLint GLenum GLint x
Definition: glcorearb.h:409
GLsizeiptr size
Definition: glcorearb.h:664
fpreal64 fpreal
Definition: SYS_Types.h:277
bool hasGradient() const
Definition: GU_Surfacer.h:59
ScalarToVectorConverter< GridType >::Type::Ptr gradient(const GridType &grid, bool threaded, InterruptT *interrupt)
Compute the gradient of the given scalar grid.
bool subsample() const
Definition: GU_Surfacer.h:67
virtual void primitiveAdded(GEO_Primitive *primitive)
called after adding a complete polygon or polysoup to the detail
Definition: GU_Surfacer.h:83