HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_Smooth.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_Smooth.h (GU Library, C++)
7  *
8  * COMMENTS: Declarations of functions for smoothing meshes
9  */
10 
11 #pragma once
12 
13 #include "GU_API.h"
14 #include <GA/GA_ElementGroup.h>
15 #include <GA/GA_Types.h>
16 #include <UT/UT_Array.h>
17 #include <UT/UT_Map.h>
18 
19 class GA_Attribute;
20 class GA_Detail;
21 class GA_PointGroup;
22 class GA_PrimitiveGroup;
23 class GA_Range;
24 
25 /// Returns true iff the attribute is able to be smoothed,
26 /// (i.e. a point or vertex numeric attribute), and the
27 /// function is not interrupted.
28 /// primgroup is used to determine the point range and connectivity.
29 GU_API bool GUsmooth(
30  GA_Attribute *attrib,
31  float frequency,
32  int iterations,
33  const GA_PrimitiveGroup *primgroup = NULL,
34  bool second_order = false);
35 
36 /// Returns true iff the attribute is able to be smoothed,
37 /// (i.e. a point or vertex numeric attribute), and the
38 /// function is not interrupted.
39 /// primgroup is only used if the attribute is a vertex attribute.
40 GU_API bool GUsmooth(
41  GA_Attribute *attrib,
42  const GA_Range &pointrange,
43  float frequency,
44  int iterations,
45  const UT_Array<GA_OffsetArray> &ringzeropoints,
46  const GA_PrimitiveGroup *primgroup = 0,
47  bool second_order = false);
48 
49 /// Like the GUsmooth above, except with weights specified explicitly,
50 /// instead of using frequency.
51 GU_API bool GUsmooth(
52  GA_Attribute *attrib,
53  const GA_Range &pointrange,
54  float weight1,
55  float weight2,
56  int iterations,
57  const UT_Array<GA_OffsetArray> &ringzeropoints,
58  const GA_PrimitiveGroup *primgroup = 0,
59  bool second_order = false);
60 
62 {
63  GU_SMOOTH_WEIGHT_UNIFORM, // 1.0 aka "umbrella" weights
64  GU_SMOOTH_WEIGHT_EDGE_LENGTH, // inverse edge length aka
65  // "scale dependent umbrella" weights
66 // GU_SMOOTH_WEIGHT_COTAN, // 0.5*sum_angles_facing_edge aka
67  // "mean curvature flow"
68  GU_SMOOTH_WEIGHT_N // sentinel
69 };
70 
71 GU_API bool
73  UT_Array<UT_Array<fpreal>>& edge_weights,
74  const GU_SmoothWeightMethod method,
75  const GA_Attribute& pt_attrib,
76  const GA_Range& pt_range,
77  const UT_Array<GA_OffsetArray>& pt_ringzero);
78 
80 {
84  const UT_Array<GA_OffsetArray> * myRingZero; // optional
86 
87  explicit
89  int iterations = 1,
90  fpreal step_size = 1.0,
92  const UT_Array<GA_OffsetArray> *ring_zero = nullptr,
93  const UT_Array<UT_Array<fpreal>> *edge_weights = nullptr
94  )
95  : myIterations(iterations)
96  , myStepSize(step_size)
97  , myWeightMethod(method)
98  , myRingZero(ring_zero)
99  , myEdgeWeights(edge_weights)
100  {
101  }
102 };
103 
104 /// Smooth a point V3 attribute using simple laplacian smoothing via average of
105 /// point neighbours. This method is faster but causes shrinkage.
107  GA_Attribute &pt_attrib,
108  const GU_SmoothParms &parms,
109  const GA_PointGroup *pt_group = nullptr,
110  GA_Attribute *work_attrib = nullptr);
111 
112 // Strategy for implicit smoothing
114 {
118 };
119 
120 // Bitmask for boundary type
126 };
127 typedef unsigned int GU_SmoothBoundaryMask;
128 
130 {
131  // The magnitude of smoothing in the range [0, infty) to apply to the mesh.
132  // The higher this value, the more smoothing is applied.
134 
135  // The exponent of the Laplacian matrix that is used to fair the mesh in the
136  // range [1, infty). The higher this exponent, the closer to a low-pass
137  // filter this operation becomes and thus the more details are preserved.
138  // Computation time is significantly increased by increasing this number so
139  // in practice we limit this to small values.
141 
142  // The smoothing algorithm to apply.
144 
145  // The mode of boundary preservation to use.
147 
148  // Points/vertices in this group will be held in place. If this is not a
149  // GA_PointGroup/GA_VertexGroup, then it will be converted to a
150  // GA_PointGroup. This parameter is optional.
152 
153  // A map from points/vertices to a float value in the range [0, infty). The
154  // weight will scale how much its respective point is moved; i.e. a point
155  // with a higher weight will be smoothed more than a point with a lower one.
156  // If this is provided and a point is not in the map, its weight is assumed
157  // to be 0.
159 
161  fpreal64 strength = 1.0,
162  int filterQuality = 2,
165  const GA_Group *constrainGroup = NULL,
166  const UT_Map<GA_Offset, fpreal> *weights = NULL
167  )
168  : myStrength(strength)
169  , myFilterQuality(filterQuality)
170  , myMethod(method)
171  , myBoundaryMask(boundaryMask)
172  , myConstrainGroup(constrainGroup)
173  , myWeights(weights)
174  {}
175 };
176 
177 // Performs implicit fairing on the points/vertices contained in the given
178 // element group for the given list of point/vertex attributes.
179 // Points/vertices/edges in the constraingroup will be held in place.
180 // The type of the group determines how boundary type is computed. For
181 // primitive/vertex groups, a point is a selection boundary point only if it has
182 // a vertex not in the group. For other group types, a point is a selection
183 // boundary point only if it has a neighbour not in the group.
185  UT_Array<GA_Attribute *> &attribs,
186  const GU_ImplicitSmoothParms &parms,
187  const GA_Group *group);
188 
189 // Performs implicit fairing on the given attribute and writes the changes
190 // to the given map. The same boundary type rules for the group from above
191 // applies here.
193  const GA_Attribute &attrib,
194  const GU_ImplicitSmoothParms &parms,
195  const GA_Group *group,
GU_ImplicitSmoothParms(fpreal64 strength=1.0, int filterQuality=2, GU_ImplicitSmoothMethod method=GU_IMPLICIT_SMOOTH_METHOD_UNIFORM, GU_SmoothBoundaryMask boundaryMask=GU_SMOOTH_BOUNDARY_ALL, const GA_Group *constrainGroup=NULL, const UT_Map< GA_Offset, fpreal > *weights=NULL)
Definition: GU_Smooth.h:160
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
GU_SmoothWeightMethod
Definition: GU_Smooth.h:61
GU_API bool GUsmoothComputeEdgeWeights(UT_Array< UT_Array< fpreal >> &edge_weights, const GU_SmoothWeightMethod method, const GA_Attribute &pt_attrib, const GA_Range &pt_range, const UT_Array< GA_OffsetArray > &pt_ringzero)
GU_SmoothBoundaryType
Definition: GU_Smooth.h:121
GU_SmoothWeightMethod myWeightMethod
Definition: GU_Smooth.h:83
GU_API bool GUsmoothLaplace(GA_Attribute &pt_attrib, const GU_SmoothParms &parms, const GA_PointGroup *pt_group=nullptr, GA_Attribute *work_attrib=nullptr)
const UT_Array< GA_OffsetArray > * myRingZero
Definition: GU_Smooth.h:84
const GA_Group * myConstrainGroup
Definition: GU_Smooth.h:151
GU_SmoothParms(int iterations=1, fpreal step_size=1.0, GU_SmoothWeightMethod method=GU_SMOOTH_WEIGHT_UNIFORM, const UT_Array< GA_OffsetArray > *ring_zero=nullptr, const UT_Array< UT_Array< fpreal >> *edge_weights=nullptr)
Definition: GU_Smooth.h:88
GU_SmoothBoundaryMask myBoundaryMask
Definition: GU_Smooth.h:146
GU_API void GUimplicitSmooth(UT_Array< GA_Attribute * > &attribs, const GU_ImplicitSmoothParms &parms, const GA_Group *group)
A range of elements in an index-map.
Definition: GA_Range.h:42
double fpreal64
Definition: SYS_Types.h:201
unsigned int GU_SmoothBoundaryMask
Definition: GU_Smooth.h:127
fpreal myStepSize
Definition: GU_Smooth.h:82
GU_API bool GUsmooth(GA_Attribute *attrib, float frequency, int iterations, const GA_PrimitiveGroup *primgroup=NULL, bool second_order=false)
int myIterations
Definition: GU_Smooth.h:81
#define GU_API
Definition: GU_API.h:14
fpreal64 fpreal
Definition: SYS_Types.h:277
GU_ImplicitSmoothMethod myMethod
Definition: GU_Smooth.h:143
Container class for all geometry.
Definition: GA_Detail.h:96
GU_ImplicitSmoothMethod
Definition: GU_Smooth.h:113
const UT_Map< GA_Offset, fpreal > * myWeights
Definition: GU_Smooth.h:158
const UT_Array< UT_Array< fpreal > > * myEdgeWeights
Definition: GU_Smooth.h:85