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