HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_IsoAdaptive.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_IsoAdaptive.h ( GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_IsoAdaptive__
12 #define __GU_IsoAdaptive__
13 
14 #include "GU_API.h"
15 #include <GEO/GEO_PrimList.h>
16 #include <UT/UT_Array.h>
17 #include <UT/UT_FloatArray.h>
18 
19 class GU_Detail;
20 class GEO_PrimVolume;
21 class GEO_PrimPoly;
22 
23 class gu_isotrisoup;
24 class gu_isotri;
25 class gu_isopt;
26 class gu_isoedge;
27 
28 ///
29 /// This sampler base class is used by the adaptive sampler
30 /// to query the implicit function. Because some operations may
31 /// be accelerated with special knowledge of your implicit function,
32 /// some higher level tools are present here as virtuals.
33 ///
35 {
36 public:
39 
40  /// Returns the value of the implicit function at a given point
41  /// negative is inside, positive outside.
42  virtual float sample(const UT_Vector3 &pos) = 0;
43 
44  /// Computes the gradient of the implicit function
45  virtual UT_Vector3 gradient(const UT_Vector3 &pos) = 0;
46 
47  /// Settles the given point onto the iso surface. The base class
48  /// does a search along the normal until an opposite signed
49  /// value is found, then a brent search is done from there.
50  /// Returns false if failed to settle
51  virtual bool settle(UT_Vector3 &pos, float tol);
52 
53  /// Does a hinge settle.
54  /// First we run a normal settle, but if it fails or is too far
55  /// we switch to a search on the circle
56  /// described by the direction, normal, and distance.
57  virtual bool hingeSettle(UT_Vector3 &result, UT_Vector3 center, UT_Vector3 stepdir, UT_Vector3 normal, float stepsize, float tol);
58 
59  /// Reports the ideal step size for any location in space.
60  float stepsize(const UT_Vector3 &pos);
61 
62  /// The subclass stepsize will be multiplied by the scale and clamped
63  /// to the given min/max.
64  void setStepScale(float minstep, float maxstep, float stepscale);
65 
66  /// Overloads the curvature based step calcuation with another sampler,
67  /// it will invoke the given sampler to determine the step size.
68  void setStepSizeSampler(GU_IsoAdaptiveSampler *sampler);
69 
70  /// To compute the curvature the gradient is sampled at nearby
71  /// points. This controls the distance to do the sampling.
72  /// Default is 0.01
73  void setCurvatureTestDist(float querydist);
74 
75 
76  /// Returns true if pos is inside the active region.
77  virtual bool isInside(const UT_Vector3 &pos);
78 
79 protected:
80  /// Computes the ideal step size at this location. Step
81  /// size should be a smooth function over space. It must be fine
82  /// enough to capture any sudden changes in direction or thin
83  /// connections.
84  /// The default will use a curvature computation by computing
85  /// the gradient at small offsets in the non-normal directions.
86  /// The result is scaled by the global stepsize scale and clamped
87  /// by the min/max step sizes.
88  virtual float stepsizeSubclass(const UT_Vector3 &pos);
89 
90  float myMinStep, myMaxStep, myStepScale;
91  float myQueryDist;
92 
94 };
95 
96 ///
97 /// This sampler works with a hierarchy of SDF volumes defined by
98 /// GEO_PrimVolume
99 ///
100 class gu_VolumeHierarchy;
101 
103 {
104 public:
105  GU_IsoAdaptiveSamplerVolume(const UT_Array<const GEO_PrimVolume *> &vollist, float offset, bool invert, float overlap, bool usesmallest, bool strict);
106  ~GU_IsoAdaptiveSamplerVolume() override;
107 
108  float sample(const UT_Vector3 &pos) override;
109  UT_Vector3 gradient(const UT_Vector3 &pos) override;
110 
111  /// Returns true if pos is inside the active region.
112  bool isInside(const UT_Vector3 &pos) override;
113 protected:
114  gu_VolumeHierarchy *myHierarchy;
116  float myOffset;
117  // -1 for flipping, 1 for no flip.
118  float mySide;
119  // If true, only the finest resolution is used.
121  // If true, use a strict is inside on the volumes.
122  bool myStrict;
123 };
124 
125 
126 ///
127 /// GU_IsoAdaptive is a verb class to do an adaptive surfacing of
128 /// an iso surface.
129 ///
131 {
132 public:
133  GU_IsoAdaptive();
134  virtual ~GU_IsoAdaptive();
135 
136  void isosurface(GU_Detail *gdp,
138  UT_Vector3 seedpos,
139  float tol,
140  // Maximum change in step size per triangle,
141  // ie, 0.5 to insist new triangle is between
142  // 0.5 and 2 distance.
143  float maxchange,
144  bool closegaps,
145  bool flipedges,
146  bool computenml,
147  bool stopatvolume);
148 protected:
149  /// Searchs outwards from seedpos to build an equaliteral triangle
150  /// settled to the surface
151  gu_isotri *buildSeedTri(UT_Vector3 seedpos);
152 
153  /// Given an edge grows it into an equaliteral triangle scaled
154  /// to the surface.
155  /// Returns false if fails, and does nothing then.
156  bool growEdge(gu_isoedge *edge, bool stopatvolume);
157 
158  /// Checks if the given point is within an overlap of another
159  /// triangle. The maxedge length of the triangles in question
160  /// will be scaled by the searchscale
161  bool checkOverlap(gu_isotri *ntri, UT_Vector3 testpos,
162  gu_isotri *ignore, float searchscale);
163 
164  /// Looks at this edge and its successive edge to see if
165  /// they are close enough together to form an ear to cut off.
166  bool cutEar(gu_isoedge *edge);
167 
168 
169 private:
170  gu_isotrisoup *mySoup;
171  GU_IsoAdaptiveSampler *mySampler;
172  float myTol;
173  float myMaxShrink, myMaxGrow;
174 };
175 
176 
177 #endif
gu_VolumeHierarchy * myHierarchy
GLboolean invert
Definition: glcorearb.h:549
**But if you need a result
Definition: thread.h:613
GLuint sampler
Definition: glcorearb.h:1656
GLintptr offset
Definition: glcorearb.h:665
void ignore(T const &) VULKAN_HPP_NOEXCEPT
Definition: vulkan.hpp:6508
const GEO_PrimVolume * myRefVolume
virtual ~GU_IsoAdaptiveSampler()
#define GU_API
Definition: GU_API.h:14
virtual bool isInside(const UT_Vector3 &pos)
Returns true if pos is inside the active region.
virtual UT_Vector3 gradient(const UT_Vector3 &pos)=0
Computes the gradient of the implicit function.
ScalarToVectorConverter< GridType >::Type::Ptr gradient(const GridType &grid, bool threaded, InterruptT *interrupt)
Compute the gradient of the given scalar grid.
GU_IsoAdaptiveSampler * myStepSizeSampler
virtual float sample(const UT_Vector3 &pos)=0