HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_ImplicitBasicSurface.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_ImplicitBasicSurface.h
7  *
8  * COMMENTS: Base class/wrapper for implicit surface shapes with transform.
9  */
10 
11 #pragma once
12 
13 
14 #ifndef __GEO_ImplicitBasicSurface_h__
15 #define __GEO_ImplicitBasicSurface_h__
16 
17 #include <UT/UT_BoundingBox.h>
18 #include <UT/UT_Interval.h>
19 #include <UT/UT_Matrix3.h>
20 #include <UT/UT_Matrix4.h>
21 #include <UT/UT_Quaternion.h>
22 #include <UT/UT_String.h>
23 #include <UT/UT_Vector4.h>
24 #include <VEX/VEX_PodTypes.h>
25 
26 /// Shape ID enumeration matching VEX implicit_shapes_shape.h
28 {
29  Empty = 0,
30  End = 1, // Marks end of a group for binary operations
31  Box = 2,
32  Plane = 3,
33  Ball = 4,
34  RoundedBox = 5,
35  Torus = 6,
36  Segment = 7,
37  Ellipsoid = 8,
38  Link = 9,
39  Capsule = 10,
40  Cylinder = 11,
41  CappedCone = 12
42 };
43 
44 
45 /// Maximum SDF value for empty/invalid shapes
46 constexpr float GEO_SDF_MAX = 1e30f;
47 
48 //////////////////////////////////////////////////////////////////////////////
49 // GEO_ImplicitBasicSurface
50 //////////////////////////////////////////////////////////////////////////////
51 
52 /// Basic Implicit Surface - unified wrapper for elementary implicit surfaces.
53 /// This class stores transform (position, orientation) and shape parameters,
54 /// dispatching to the appropriate SDF based on shape ID.
55 ///
56 /// Typically initialized from geometry point attributes:
57 /// `P`, `orient`, `shape_parms`, `shape_id`, `shape_invert`
58 template <VEX_Precision PREC>
60 {
61 public:
62  /// Position of the shape in world space
63  VEXvec3<PREC> myPos = {0, 0, 0};
64  /// Rotation matrix from reference frame to world space
65  /// It is assumed that this matrix is rotation!
66  VEXmat3<PREC> myTransform = {1,0,0, 0,1,0, 0,0,1};
67  /// Parameters describing the shape.
70 
71  GEO_ImplicitBasicSurface() = default;
72 
73  /// Make basic shape fron its name, position, transform and parameters
74  ///
75  /// The transform does not have to be rotation matrix. Scales are extracted and applied to parameters
76  /// Any shearing or non-uniform scaling is ignored
77  GEO_ImplicitBasicSurface(const char * name,
78  const VEXvec3<PREC> &P,
79  const VEXmat3<PREC> &transform,
80  const VEXvec4<PREC> &shapevals);
81 
82  // ========================================
83  // Evaluation methods
84  // ========================================
85 
86  /// Evaluate SDF at point P (world space)
87  VEXfloat<PREC> eval(const VEXvec3<PREC> &P) const;
88 
89  /// Evaluate SDF with spatial gradient
90  VEXfloat<PREC> eval(const VEXvec3<PREC> &P, VEXvec3<PREC> &grad) const;
91 
92  /// Evaluate SDF with spatial and parameter gradients
94  UT_Vector4T<VEXfloat<PREC>> &parms_grad) const;
95 
96  /// Batched evaluation helper with compile-time output control.
97  template <bool WantGrad, bool WantParmGrad>
98  void evalBatched(int npts, const VEXvec3<PREC> *P, VEXfloat<PREC> *sdf,
99  VEXvec3<PREC> *grad, UT_Vector4T<VEXfloat<PREC>> *parms_grad) const;
100 
101  /// Evaluate SDF bounds for interval box (world space)
103  const UT_BoundingBoxT<VEXfloat<PREC>> &P) const;
104 
105  /// Evaluate SDF bounds for bounding sphere (world space).
106  /// Cheaper than evalInterval when P comes from a rotated region, since
107  /// transforming a sphere to local space only rotates the center.
109  const VEXvec3<PREC> &center, VEXfloat<PREC> radius) const;
110 
111  /// Operator() overloads
113  {
114  return eval(P);
115  }
117  {
118  return eval(P, grad);
119  }
121  UT_Vector4T<VEXfloat<PREC>> &parms_grad) const
122  {
123  return eval(P, grad, parms_grad);
124  }
126  const UT_BoundingBoxT<VEXfloat<PREC>> &P) const
127  {
128  return evalInterval(P);
129  }
131  const VEXvec3<PREC> &center, VEXfloat<PREC> radius) const
132  {
133  return evalInterval(center, radius);
134  }
135 
136  // ========================================
137  // Uniform scale
138  // ========================================
139 
140  /// Scale all distance-valued parameters by uniform factor.
142  {
143  // all parameters are distance based right now
144  myParms *= s;
145  }
146 
147  // ========================================
148  // Shape ID utilities
149  // ========================================
150 
151  /// Convert shape name string to ID
152  static GEO_ImplicitShapeID shapeNameToID(const char *name);
153 
154  /// Convert shape ID to name string
155  static const char *shapeIDToName(GEO_ImplicitShapeID id);
156 
157  /// Transform world point to local reference frame
159 
160  /// Transform point from reference frame to world space
162 
163  /// Transform local gradient to world space
164  VEXvec3<PREC> worldToLocalVec(const VEXvec3<PREC> &vec) const;
165 
166  /// Transform local gradient to world space
167  VEXvec3<PREC> localToWorldVec(const VEXvec3<PREC> &vec) const;
168 
169  /// Transform world interval box to local reference frame
171  const UT_BoundingBoxT<VEXfloat<PREC>> &P) const;
172 };
173 
174 #endif // __GEO_ImplicitBasicSurface_h__
UT_IntervalT< VEXfloat< PREC > > evalInterval(const UT_BoundingBoxT< VEXfloat< PREC >> &P) const
Evaluate SDF bounds for interval box (world space)
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
VEXfloat< PREC > operator()(const VEXvec3< PREC > &P, VEXvec3< PREC > &grad, UT_Vector4T< VEXfloat< PREC >> &parms_grad) const
Axis-aligned bounding box (AABB).
Definition: GEO_Detail.h:41
UT_Vector4T< VEXfloat< PREC > > myParms
Parameters describing the shape.
VEXvec3< PREC > localToWorldVec(const VEXvec3< PREC > &vec) const
Transform local gradient to world space.
VEXvec3< PREC > worldToLocalVec(const VEXvec3< PREC > &vec) const
Transform local gradient to world space.
UT_BoundingBoxT< VEXfloat< PREC > > worldToLocalInterval(const UT_BoundingBoxT< VEXfloat< PREC >> &P) const
Transform world interval box to local reference frame.
GLdouble s
Definition: glad.h:3009
4D Vector class.
Definition: UT_Vector4.h:176
typename VEX_PrecisionResolver< P >::vec3_type VEXvec3
Definition: VEX_PodTypes.h:70
void scale(VEXfloat< PREC > s)
Scale all distance-valued parameters by uniform factor.
VEXfloat< PREC > operator()(const VEXvec3< PREC > &P) const
Operator() overloads.
static GEO_ImplicitShapeID shapeNameToID(const char *name)
Convert shape name string to ID.
VEXfloat< PREC > operator()(const VEXvec3< PREC > &P, VEXvec3< PREC > &grad) const
GEO_ImplicitShapeID
Shape ID enumeration matching VEX implicit_shapes_shape.h.
typename VEX_PrecisionResolver< P >::float_type VEXfloat
Definition: VEX_PodTypes.h:67
GLuint const GLchar * name
Definition: glcorearb.h:786
constexpr float GEO_SDF_MAX
Maximum SDF value for empty/invalid shapes.
GA_API const UT_StringHolder transform
VEXvec3< PREC > myPos
Position of the shape in world space.
GEO_ImplicitBasicSurface()=default
void evalBatched(int npts, const VEXvec3< PREC > *P, VEXfloat< PREC > *sdf, VEXvec3< PREC > *grad, UT_Vector4T< VEXfloat< PREC >> *parms_grad) const
Batched evaluation helper with compile-time output control.
UT_IntervalT< VEXfloat< PREC > > operator()(const UT_BoundingBoxT< VEXfloat< PREC >> &P) const
VEXvec3< PREC > localToWorld(const VEXvec3< PREC > &P) const
Transform point from reference frame to world space.
typename VEX_PrecisionResolver< P >::vec4_type VEXvec4
Definition: VEX_PodTypes.h:71
static const char * shapeIDToName(GEO_ImplicitShapeID id)
Convert shape ID to name string.
UT_IntervalT< VEXfloat< PREC > > operator()(const VEXvec3< PREC > &center, VEXfloat< PREC > radius) const
VEXfloat< PREC > eval(const VEXvec3< PREC > &P) const
Evaluate SDF at point P (world space)
VEXvec3< PREC > worldToLocal(const VEXvec3< PREC > &P) const
Transform world point to local reference frame.
Definition: ImathBox.h:37
typename VEX_PrecisionResolver< P >::mat3_type VEXmat3
Definition: VEX_PodTypes.h:73