OpenSubdiv: opensubdiv/sdc/crease.h Source File

| 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
45 class 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 {
66 RULE_UNKNOWN = 0,
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
185 return (_options.GetVtxBoundaryInterpolation() == Options::VTX_BOUNDARY_EDGE_AND_CORNER) ?
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);
195 return Crease::SHARPNESS_SMOOTH;
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 */
options.h
OpenSubdiv
Definition limits.h:15
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:16
OpenSubdiv::OPENSUBDIV_VERSION::Sdc
Definition bilinearScheme.h:17
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SubdivideVertexSharpness
float SubdivideVertexSharpness(float vertexSharpness) const
Definition crease.h:205
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::IsInfinite
static bool IsInfinite(float sharpness)
Definition crease.h:55
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::Rule
Rule
Definition crease.h:65
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::RULE_CORNER
@ RULE_CORNER
Definition crease.h:70
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::RULE_DART
@ RULE_DART
Definition crease.h:68
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::RULE_SMOOTH
@ RULE_SMOOTH
Definition crease.h:67
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::RULE_CREASE
@ RULE_CREASE
Definition crease.h:69
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::RULE_UNKNOWN
@ RULE_UNKNOWN
Definition crease.h:66
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SharpenBoundaryVertex
float SharpenBoundaryVertex(float edgeSharpness) const
Definition crease.h:183
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SHARPNESS_SMOOTH
static float const SHARPNESS_SMOOTH
Definition crease.h:50
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::GetSharpEdgePairOfCrease
void GetSharpEdgePairOfCrease(float const *incidentEdgeSharpness, int incidentEdgeCount, int sharpEdgePair[2]) const
Definition crease.h:211
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SHARPNESS_INFINITE
static float const SHARPNESS_INFINITE
Definition crease.h:51
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::DetermineVertexVertexRule
Rule DetermineVertexVertexRule(float vertexSharpness, int incidentEdgeCount, float const *incidentEdgeSharpness) const
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::decrementSharpness
float decrementSharpness(float sharpness) const
Definition crease.h:190
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::IsSmooth
static bool IsSmooth(float sharpness)
Definition crease.h:53
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::DetermineVertexVertexRule
Rule DetermineVertexVertexRule(float vertexSharpness, int sharpEdgeCount) const
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::IsUniform
bool IsUniform() const
Definition crease.h:78
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::IsSemiSharp
static bool IsSemiSharp(float sharpness)
Definition crease.h:56
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::Crease
Crease(Options const &options)
Definition crease.h:75
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SubdivideEdgeSharpnessesAroundVertex
void SubdivideEdgeSharpnessesAroundVertex(int incidentEdgeCountAtVertex, float const *incidentEdgeSharpnessAroundVertex, float *childEdgesSharpnessAroundVertex) const
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SubdivideUniformSharpness
float SubdivideUniformSharpness(float vertexOrEdgeSharpness) const
Definition crease.h:199
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::Crease
Crease()
Definition crease.h:74
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SharpenBoundaryEdge
float SharpenBoundaryEdge(float edgeSharpness) const
Definition crease.h:172
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::ComputeFractionalWeightAtVertex
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,...
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SubdivideEdgeSharpnessAtVertex
float SubdivideEdgeSharpnessAtVertex(float edgeSharpness, int incidentEdgeCountAtEndVertex, float const *edgeSharpnessAroundEndVertex) const
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::IsSharp
static bool IsSharp(float sharpness)
Definition crease.h:54
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::~Crease
~Crease()
Definition crease.h:76
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options
All supported options applying to subdivision scheme.
Definition options.h:34
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options::CREASE_UNIFORM
@ CREASE_UNIFORM
Catmark rule.
Definition options.h:52
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options::VTX_BOUNDARY_EDGE_AND_CORNER
@ VTX_BOUNDARY_EDGE_AND_CORNER
Definition options.h:40