HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 
35 /// Returns true iff the attribute is able to be smoothed,
36 /// (i.e. a point or vertex numeric attribute), and the
37 /// function is not interrupted.
38 /// primgroup is only used if the attribute is a vertex attribute.
39 GU_API bool GUsmooth(
40  GA_Attribute *attrib,
41  const GA_Range &pointrange,
42  float frequency,
43  int iterations,
44  const UT_Array<GA_OffsetArray> &ringzeropoints,
45  const GA_PrimitiveGroup *primgroup = 0);
46 
47 /// Like the GUsmooth above, except with weights specified explicitly,
48 /// instead of using frequency.
49 GU_API bool GUsmooth(
50  GA_Attribute *attrib,
51  const GA_Range &pointrange,
52  float weight1,
53  float weight2,
54  int iterations,
55  const UT_Array<GA_OffsetArray> &ringzeropoints,
56  const GA_PrimitiveGroup *primgroup = 0);
57 
59 {
60  GU_SMOOTH_WEIGHT_UNIFORM, // 1.0 aka "umbrella" weights
61  GU_SMOOTH_WEIGHT_EDGE_LENGTH, // inverse edge length aka
62  // "scale dependent umbrella" weights
63 // GU_SMOOTH_WEIGHT_COTAN, // 0.5*sum_angles_facing_edge aka
64  // "mean curvature flow"
65  GU_SMOOTH_WEIGHT_N // sentinel
66 };
67 
68 GU_API bool
70  UT_Array<UT_Array<fpreal>>& edge_weights,
72  const GA_Attribute& pt_attrib,
73  const GA_Range& pt_range,
74  const UT_Array<GA_OffsetArray>& pt_ringzero);
75 
77 {
81  const UT_Array<GA_OffsetArray> * myRingZero; // optional
83 
84  explicit
86  int iterations = 1,
87  fpreal step_size = 1.0,
89  const UT_Array<GA_OffsetArray> *ring_zero = nullptr,
90  const UT_Array<UT_Array<fpreal>> *edge_weights = nullptr
91  )
92  : myIterations(iterations)
93  , myStepSize(step_size)
94  , myWeightMethod(method)
95  , myRingZero(ring_zero)
96  , myEdgeWeights(edge_weights)
97  {
98  }
99 };
100 
101 /// Smooth a point V3 attribute using simple laplacian smoothing via average of
102 /// point neighbours. This method is faster but causes shrinkage.
104  GA_Attribute &pt_attrib,
105  const GU_SmoothParms &parms,
106  const GA_PointGroup *pt_group = nullptr,
107  GA_Attribute *work_attrib = nullptr);
108 
109 // Strategy for implicit smoothing
111 {
115 };
116 
117 // Bitmask for boundary type
123 };
124 typedef unsigned int GU_SmoothBoundaryMask;
125 
127 {
128  // The magnitude of smoothing in the range [0, infty) to apply to the mesh.
129  // The higher this value, the more smoothing is applied.
131 
132  // The exponent of the Laplacian matrix that is used to fair the mesh in the
133  // range [1, infty). The higher this exponent, the closer to a low-pass
134  // filter this operation becomes and thus the more details are preserved.
135  // Computation time is significantly increased by increasing this number so
136  // in practice we limit this to small values.
138 
139  // The smoothing algorithm to apply.
141 
142  // The mode of boundary preservation to use.
144 
145  // Points/vertices in this group will be held in place. If this is not a
146  // GA_PointGroup/GA_VertexGroup, then it will be converted to a
147  // GA_PointGroup. This parameter is optional.
149 
150  // A map from points/vertices to a float value in the range [0, infty). The
151  // weight will scale how much its respective point is moved; i.e. a point
152  // with a higher weight will be smoothed more than a point with a lower one.
153  // If this is provided and a point is not in the map, its weight is assumed
154  // to be 0.
156 
158  fpreal64 strength = 1.0,
159  int filterQuality = 2,
162  const GA_Group *constrainGroup = NULL,
163  const UT_Map<GA_Offset, fpreal> *weights = NULL
164  )
165  : myStrength(strength)
166  , myFilterQuality(filterQuality)
167  , myMethod(method)
168  , myBoundaryMask(boundaryMask)
169  , myConstrainGroup(constrainGroup)
170  , myWeights(weights)
171  {}
172 };
173 
174 // Performs implicit fairing on the points/vertices contained in the given
175 // element group for the given list of point/vertex attributes.
176 // Points/vertices/edges in the constraingroup will be held in place.
177 // The type of the group determines how boundary type is computed. For
178 // primitive/vertex groups, a point is a selection boundary point only if it has
179 // a vertex not in the group. For other group types, a point is a selection
180 // boundary point only if it has a neighbour not in the group.
182  UT_Array<GA_Attribute *> &attribs,
183  const GU_ImplicitSmoothParms &parms,
184  const GA_Group *group);
185 
186 // Performs implicit fairing on the given attribute and writes the changes
187 // to the given map. The same boundary type rules for the group from above
188 // applies here.
190  const GA_Attribute &attrib,
191  const GU_ImplicitSmoothParms &parms,
192  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:157
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
GU_SmoothWeightMethod
Definition: GU_Smooth.h:58
Unsorted map container.
Definition: UT_Map.h:83
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:118
GU_SmoothWeightMethod myWeightMethod
Definition: GU_Smooth.h:80
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:81
const GA_Group * myConstrainGroup
Definition: GU_Smooth.h:148
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:85
GU_SmoothBoundaryMask myBoundaryMask
Definition: GU_Smooth.h:143
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
unsigned int GU_SmoothBoundaryMask
Definition: GU_Smooth.h:124
GU_API bool GUsmooth(GA_Attribute *attrib, float frequency, int iterations, const GA_PrimitiveGroup *primgroup=NULL)
fpreal myStepSize
Definition: GU_Smooth.h:79
double fpreal64
Definition: SYS_Types.h:185
int method
Definition: png.h:1924
int myIterations
Definition: GU_Smooth.h:78
#define GU_API
Definition: GU_API.h:11
double fpreal
Definition: SYS_Types.h:263
GU_ImplicitSmoothMethod myMethod
Definition: GU_Smooth.h:140
Container class for all geometry.
Definition: GA_Detail.h:96
GU_ImplicitSmoothMethod
Definition: GU_Smooth.h:110
const UT_Map< GA_Offset, fpreal > * myWeights
Definition: GU_Smooth.h:155
const UT_Array< UT_Array< fpreal > > * myEdgeWeights
Definition: GU_Smooth.h:82