HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_SurfaceDistance.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_SurfaceDistance.h (GU Library, C++)
7  *
8  * COMMENTS:
9  * Approximates geodesic distance.
10  * This code is related to the soft falloff code in GEO_Transform, but is
11  * mostly a replacement for it as of Houdini 16.5.
12  */
13 
14 #ifndef __GU_SurfaceDistance_h__
15 #define __GU_SurfaceDistance_h__
16 
17 #include "GU_API.h"
18 
19 #include <GA/GA_Types.h>
20 #include <GA/GA_Handle.h>
21 #include <GEO/GEO_Detail.h>
22 #include <UT/UT_Function.h>
23 
24 
25 // keep this synced with the parameter in $PRM/PRM_Shared.C
27 {
34 };
35 
36 // Utility class for measuring distances along a surface (or along edges).
37 // Call findDistances() to discover distances to points within 'max_dist' from
38 // the seed points/position.
39 //
40 // The geometry given to the constructor will be converted to polygons (or
41 // polylines if measuring along edges). The converted geometry can be explored
42 // with methods on this class.
44 {
45 public:
46  GU_SurfaceDistance(const GEO_Detail &gdp, bool as_polylines);
47 
48  // Returns true if the converted geometry representation is polylines.
49  bool getAsPolylines() const { return myAsPolylines; }
50 
51  // Returns number of polygons in the converted geometry.
52  exint getNumPrimitives() const { return myPrimEnd.entries(); }
53 
54  // Returns range of vertices for the given converted polygon.
55  void getVertexRange(exint pr, exint &start, exint &end) const
56  {
57  end = myPrimEnd(pr);
58  start = pr ? myPrimEnd(pr - 1) : 0;
59  }
60 
61  // Returns the first vertex referencing the given point.
62  exint firstVertex(GA_Offset pt) const { return myPtFirstVtx(exint(pt)); }
63 
64  // Returns the next vertex referencing the same point.
65  exint nextVertex(exint vtx) const { return myVtxNextVtx(vtx); }
66 
67  // Returns the point the given vertex references.
68  GA_Offset vertexPoint(exint vtx) const { return myVtxPt(vtx); }
69 
70  // Returns the primitive to which the given vertex belongs.
71  exint vertexPrimitive(exint vtx) const { return myVtxPrim(vtx); }
72 
73  // Seeds known distances for a set of points. All found distances within
74  // 'max_dist' are reported by calling 'func'.
75  void findDistances(const GA_ROHandleV3 &p_attr,
76  fpreal max_dist, // negative means no max_dist
77  const GA_OffsetArray &pts,
78  const UT_FloatArray &dists,
79  const UT_Function<void(GA_Offset, fpreal)> &func) const;
80 
81  // Seeds known distances for a set of points. All found distances within
82  // 'max_dist' are reported by calling 'func'.
83  void findDistances(const GA_ROHandleV3 &p_attr,
84  fpreal max_dist, // negative means no max_dist
85  const GA_OffsetArray &pts,
86  const UT_FloatArray &dists,
87  const UT_Array<exint> &src,
88  const UT_Function<void(GA_Offset, fpreal, exint)> &func) const;
89 
90  int64 getMemoryUsage(bool inclusive) const;
91 private:
92  void internalVertex(GA_Offset pt);
93  void internalEndPrimitive() { myPrimEnd.append(myVtxPt.entries()); }
94 
95  // The following are used by convertPrimitive() to record polygon
96  // representation of geometry. They will discard invalid vertices
97  // and convex the results before passing the data along to the internal*
98  // methods.
99  void polyVertex(GA_OffsetArray &pts, GA_Offset pt)
100  {
101  if(pt != GA_INVALID_OFFSET)
102  pts.append(pt);
103  }
104  void endPolygon(GA_OffsetArray &pts);
105  void endPolyline(GA_OffsetArray &pts);
106 
107  bool myAsPolylines;
108 
109  // points
110  UT_Array<exint> myPtFirstVtx; // first vertex referencing the point
111 
112  // converted prim data
113  UT_Array<exint> myPrimEnd; // end of vertex list for a given polygon
114 
115  // converted vertex data
116  UT_Array<GA_Offset> myVtxPt; // vertexPoint
117  UT_Array<exint> myVtxPrim; // vertexPrimitive
118  UT_Array<exint> myVtxNextVtx; // next vertex referencing the point or -1
119 };
120 
121 // This class contains all the data needed to efficiently compute surface
122 // distances. It will automatically invalidate cache items when inputs to the
123 // query are incompatible with the cached data. This can help SOPs that want
124 // to save time on repeated calls.
126 {
127 public:
128  GU_SurfaceDistanceCache() { clear(); }
130 
131  void clear();
132 
133  // utility method to support multithreading of the surfdist VEX function
134  bool canReuse(const GEO_Detail &gdp, const char *p_attr, fpreal radius,
135  GU_SoftDistanceMetric metric) const;
136 
137  // group of points with valid distances (and lead points)
139  { return myAffectedGroup.get(); }
140 
141  // handle to detached attribute describing measured distances
143  { return GA_ROHandleF(myDistances.get()); }
144 
145  // handle to detached attribute describing closest lead point
147  { return GA_ROHandleID(mySourcePoints.get()); }
148 
149  // compute distances for points within the radius
150  void updateDistances(const GEO_Detail &gdp,
151  const GA_Group *srcgroup,
152  fpreal radius,
153  GU_SoftDistanceMetric metric,
154  const char *p_attr = "P",
155  const GEO_Detail::SoftSymmetryParms *symmetry = nullptr,
156  const GEO_Rolloff *rolloff = nullptr);
157 
158  int64 getMemoryUsage(bool inclusive) const;
159 private:
160  bool hasSameTopology(const GEO_Detail &gdp) const;
161 
162  void updateSurfAndEdgeDistances(const GEO_Detail &gdp,
163  const GA_PointGroup *srcgroup,
164  fpreal radius,
165  GU_SoftDistanceMetric metric,
166  const GA_ROHandleV3 &p_attrib,
167  const GEO_Detail::SoftSymmetryParms *symmetry);
168 
170 
171  // set of points with computed distances (and lead points)
172  GA_PointGroupUPtr myAffectedGroup;
173  // distance to the closest point in the input group
174  GA_AttributeUPtr myDistances;
175  // the point in the input group that the current point is closest to
176  GA_AttributeUPtr mySourcePoints;
177 
178  // values used to determine when to invalidate cached data
179  GU_SoftDistanceMetric myMetric;
180  fpreal myRadius;
181  GA_DataId myGdpUniqueId;
182  GA_DataId myGdpPrimitiveId;
183  GA_DataId myGdpTopologyId;
184 
185  bool myHasSymmetryParms;
186  bool myHasPtGroup;
187  GEO_Detail::SoftSymmetryParms mySymmetryParms;
188  UT_String myPAttrib;
189  GA_OffsetArray myPts;
190 };
191 
192 // Utility class for measuring the distances along a surface from a point on the mesh
193 // to the point groups for the same mesh. Allows to compute distances to multiple point groups
194 // at the same time.
196  const GEO_Detail &gdp,
197  const GA_ROHandleV3 &p_attrib,
198  const GA_Offset &pt, // starting point
199  const UT_Array<GA_PointGroupUPtr> &psubset, // points we want to measure the distance to
200  int k, // stop when we find the k closest points for each group in the psubset
201  UT_Array<GA_PointGroupUPtr> &affectedgroups, // set of k closest points to pt with computed distances
202  GA_RWHandleF &h_dists); // distances from the pt to the points in the affectedgroups
203 #endif
GA_ROHandleF getDistances() const
void GU_API GU_FindDistancesToPointGroups(const GU_SurfaceDistance &sdist, const GEO_Detail &gdp, const GA_ROHandleV3 &p_attrib, const GA_Offset &pt, const UT_Array< GA_PointGroupUPtr > &psubset, int k, UT_Array< GA_PointGroupUPtr > &affectedgroups, GA_RWHandleF &h_dists)
void getVertexRange(exint pr, exint &start, exint &end) const
int64 GA_DataId
Definition: GA_Types.h:696
GLuint start
Definition: glcorearb.h:475
int64 exint
Definition: SYS_Types.h:125
exint nextVertex(exint vtx) const
const GA_PointGroup * getAffectedGroup() const
GA_ROHandleT< int64 > GA_ROHandleID
Definition: GA_Handle.h:1387
exint vertexPrimitive(exint vtx) const
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GA_Size GA_Offset
Definition: GA_Types.h:646
GA_ROHandleID getSourcePoints() const
exint firstVertex(GA_Offset pt) const
GLuint GLuint end
Definition: glcorearb.h:475
GA_ROHandleT< fpreal32 > GA_ROHandleF
Definition: GA_Handle.h:1354
GU_SoftDistanceMetric
long long int64
Definition: SYS_Types.h:116
bool getAsPolylines() const
GA_Offset vertexPoint(exint vtx) const
#define GU_API
Definition: GU_API.h:14
std::function< T > UT_Function
Definition: UT_Function.h:37
exint append()
Definition: UT_Array.h:142
UT_UniquePtr< GA_Attribute > GA_AttributeUPtr
Definition: GA_Attribute.h:930
GLenum func
Definition: glcorearb.h:783
fpreal64 fpreal
Definition: SYS_Types.h:277
UT_UniquePtr< GA_PointGroup > GA_PointGroupUPtr
exint getNumPrimitives() const
GLenum src
Definition: glcorearb.h:1793