OpenSubdiv
Loading...
Searching...
No Matches
crease.h
Go to the documentation of this file.
1//
2// Copyright 2014 DreamWorks Animation LLC.
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://opensubdiv.org/license.
6//
7#ifndef OPENSUBDIV3_SDC_CREASE_H
8#define OPENSUBDIV3_SDC_CREASE_H
9
10#include "../version.h"
11
12#include "../sdc/options.h"
13
14namespace OpenSubdiv {
15namespace OPENSUBDIV_VERSION {
16
17namespace Sdc {
18
44
45class Crease {
46public:
48
50 static float const SHARPNESS_SMOOTH; // = 0.0f, do we really need this?
51 static float const SHARPNESS_INFINITE; // = 10.0f;
52
53 static bool IsSmooth(float sharpness) { return sharpness <= SHARPNESS_SMOOTH; }
54 static bool IsSharp(float sharpness) { return sharpness > SHARPNESS_SMOOTH; }
55 static bool IsInfinite(float sharpness) { return sharpness >= SHARPNESS_INFINITE; }
56 static bool IsSemiSharp(float sharpness) { return (SHARPNESS_SMOOTH < sharpness) && (sharpness < SHARPNESS_INFINITE); }
58
65 enum Rule {
67 RULE_SMOOTH = (1 << 0),
68 RULE_DART = (1 << 1),
69 RULE_CREASE = (1 << 2),
70 RULE_CORNER = (1 << 3)
71 };
72
73public:
74 Crease() : _options() { }
75 Crease(Options const& options) : _options(options) { }
76 ~Crease() { }
77
78 bool IsUniform() const { return _options.GetCreasingMethod() == Options::CREASE_UNIFORM; }
79
81
87 float SharpenBoundaryEdge(float edgeSharpness) const;
88 float SharpenBoundaryVertex(float edgeSharpness) const;
89
90 // For future consideration
91 //float SharpenNonManifoldEdge(float edgeSharpness) const;
92 //float SharpenNonManifoldVertex(float edgeSharpness) const;
94
96
107 float SubdivideUniformSharpness(float vertexOrEdgeSharpness) const;
108
109 float SubdivideVertexSharpness(float vertexSharpness) const;
110
111 float SubdivideEdgeSharpnessAtVertex(float edgeSharpness,
112 int incidentEdgeCountAtEndVertex,
113 float const* edgeSharpnessAroundEndVertex) const;
114
115 void SubdivideEdgeSharpnessesAroundVertex(int incidentEdgeCountAtVertex,
116 float const* incidentEdgeSharpnessAroundVertex,
117 float* childEdgesSharpnessAroundVertex) const;
119
121
127 Rule DetermineVertexVertexRule(float vertexSharpness,
128 int incidentEdgeCount,
129 float const* incidentEdgeSharpness) const;
130 Rule DetermineVertexVertexRule(float vertexSharpness,
131 int sharpEdgeCount) const;
133
145 float ComputeFractionalWeightAtVertex(float vertexSharpness,
146 float childVertexSharpness,
147 int incidentEdgeCount,
148 float const* incidentEdgeSharpness,
149 float const* childEdgesSharpness) const;
150
151 void GetSharpEdgePairOfCrease(float const * incidentEdgeSharpness,
152 int incidentEdgeCount,
153 int sharpEdgePair[2]) const;
154
155 // Would these really help? Maybe only need Rules for the vertex-vertex case...
156 //
157 // Rule DetermineEdgeVertexRule(float parentEdgeSharpness) const;
158 // Rule DetermineEdgeVertexRule(float childEdge1Sharpness, float childEdge2Sharpness) const;
159
160protected:
161 float decrementSharpness(float sharpness) const;
162
163private:
164 Options _options;
165};
166
167
168//
169// Inline declarations:
170//
171inline float
172Crease::SharpenBoundaryEdge(float /* edgeSharpness */) const {
173
174 //
175 // Despite the presence of the BOUNDARY_NONE option, boundary edges are always sharpened.
176 // Much of the code relies on sharpness to indicate boundaries to avoid the more complex
177 // topological inspection
178 //
179 return SHARPNESS_INFINITE;
180}
181
182inline float
183Crease::SharpenBoundaryVertex(float vertexSharpness) const {
184
186 SHARPNESS_INFINITE : vertexSharpness;
187}
188
189inline float
190Crease::decrementSharpness(float sharpness) const {
191
192 if (IsSmooth(sharpness)) return Crease::SHARPNESS_SMOOTH; // redundant but most common
193 if (IsInfinite(sharpness)) return Crease::SHARPNESS_INFINITE;
194 if (sharpness > 1.0f) return (sharpness - 1.0f);
196}
197
198inline float
199Crease::SubdivideUniformSharpness(float vertexOrEdgeSharpness) const {
200
201 return decrementSharpness(vertexOrEdgeSharpness);
202}
203
204inline float
205Crease::SubdivideVertexSharpness(float vertexSharpness) const {
206
207 return decrementSharpness(vertexSharpness);
208}
209
210inline void
211Crease::GetSharpEdgePairOfCrease(float const * incidentEdgeSharpness, int incidentEdgeCount,
212 int sharpEdgePair[2]) const {
213
214 // Only to be called when a crease is present at a vertex -- exactly two sharp
215 // edges are expected here:
216 //
217 sharpEdgePair[0] = 0;
218 while (IsSmooth(incidentEdgeSharpness[sharpEdgePair[0]])) ++ sharpEdgePair[0];
219
220 sharpEdgePair[1] = incidentEdgeCount - 1;
221 while (IsSmooth(incidentEdgeSharpness[sharpEdgePair[1]])) -- sharpEdgePair[1];
222}
223
224} // end namespace sdc
225
226} // end namespace OPENSUBDIV_VERSION
227using namespace OPENSUBDIV_VERSION;
228} // end namespace OpenSubdiv
229
230#endif /* OPENSUBDIV3_SDC_CREASE_H */
Types, constants and utilities related to semi-sharp creasing – whose implementation is independent o...
Definition crease.h:45
float SubdivideVertexSharpness(float vertexSharpness) const
Definition crease.h:205
static bool IsInfinite(float sharpness)
Definition crease.h:55
float SharpenBoundaryVertex(float edgeSharpness) const
Definition crease.h:183
void GetSharpEdgePairOfCrease(float const *incidentEdgeSharpness, int incidentEdgeCount, int sharpEdgePair[2]) const
Definition crease.h:211
Rule DetermineVertexVertexRule(float vertexSharpness, int incidentEdgeCount, float const *incidentEdgeSharpness) const
float decrementSharpness(float sharpness) const
Definition crease.h:190
static bool IsSmooth(float sharpness)
Definition crease.h:53
Rule DetermineVertexVertexRule(float vertexSharpness, int sharpEdgeCount) const
static bool IsSemiSharp(float sharpness)
Definition crease.h:56
void SubdivideEdgeSharpnessesAroundVertex(int incidentEdgeCountAtVertex, float const *incidentEdgeSharpnessAroundVertex, float *childEdgesSharpnessAroundVertex) const
float SubdivideUniformSharpness(float vertexOrEdgeSharpness) const
Definition crease.h:199
float SharpenBoundaryEdge(float edgeSharpness) const
Definition crease.h:172
float ComputeFractionalWeightAtVertex(float vertexSharpness, float childVertexSharpness, int incidentEdgeCount, float const *incidentEdgeSharpness, float const *childEdgesSharpness) const
Transitional weighting: When the rules applicable to a parent vertex and its child differ,...
float SubdivideEdgeSharpnessAtVertex(float edgeSharpness, int incidentEdgeCountAtEndVertex, float const *edgeSharpnessAroundEndVertex) const
static bool IsSharp(float sharpness)
Definition crease.h:54
All supported options applying to subdivision scheme.
Definition options.h:34
CreasingMethod GetCreasingMethod() const
Get edge crease rule.
Definition options.h:84
VtxBoundaryInterpolation GetVtxBoundaryInterpolation() const
Get vertex boundary interpolation rule.
Definition options.h:72