crease.h
Go to the documentation of this file.
1 //
2 // Copyright 2014 DreamWorks Animation LLC.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef OPENSUBDIV3_SDC_CREASE_H
25 #define OPENSUBDIV3_SDC_CREASE_H
26 
27 #include "../version.h"
28 
29 #include "../sdc/options.h"
30 
31 namespace OpenSubdiv {
32 namespace OPENSUBDIV_VERSION {
33 
34 namespace Sdc {
35 
61 
62 class Crease {
63 public:
65  static float const SHARPNESS_SMOOTH; // = 0.0f, do we really need this?
68  static float const SHARPNESS_INFINITE; // = 10.0f;
69 
70  static bool IsSmooth(float sharpness) { return sharpness <= SHARPNESS_SMOOTH; }
71  static bool IsSharp(float sharpness) { return sharpness > SHARPNESS_SMOOTH; }
72  static bool IsInfinite(float sharpness) { return sharpness >= SHARPNESS_INFINITE; }
73  static bool IsSemiSharp(float sharpness) { return (SHARPNESS_SMOOTH < sharpness) && (sharpness < SHARPNESS_INFINITE); }
75 
82  enum Rule {
84  RULE_SMOOTH = (1 << 0),
85  RULE_DART = (1 << 1),
86  RULE_CREASE = (1 << 2),
87  RULE_CORNER = (1 << 3)
88  };
89 
90 public:
91  Crease() : _options() { }
92  Crease(Options const& options) : _options(options) { }
93  ~Crease() { }
94 
95  bool IsUniform() const { return _options.GetCreasingMethod() == Options::CREASE_UNIFORM; }
96 
98  float SharpenBoundaryEdge(float edgeSharpness) const;
105  float SharpenBoundaryVertex(float edgeSharpness) const;
106 
107  // For future consideration
108  //float SharpenNonManifoldEdge(float edgeSharpness) const;
109  //float SharpenNonManifoldVertex(float edgeSharpness) const;
111 
113  float SubdivideUniformSharpness(float vertexOrEdgeSharpness) const;
125 
126  float SubdivideVertexSharpness(float vertexSharpness) const;
127 
128  float SubdivideEdgeSharpnessAtVertex(float edgeSharpness,
129  int incidentEdgeCountAtEndVertex,
130  float const* edgeSharpnessAroundEndVertex) const;
131 
132  void SubdivideEdgeSharpnessesAroundVertex(int incidentEdgeCountAtVertex,
133  float const* incidentEdgeSharpnessAroundVertex,
134  float* childEdgesSharpnessAroundVertex) const;
136 
138  Rule DetermineVertexVertexRule(float vertexSharpness,
145  int incidentEdgeCount,
146  float const* incidentEdgeSharpness) const;
147  Rule DetermineVertexVertexRule(float vertexSharpness,
148  int sharpEdgeCount) const;
150 
162  float ComputeFractionalWeightAtVertex(float vertexSharpness,
163  float childVertexSharpness,
164  int incidentEdgeCount,
165  float const* incidentEdgeSharpness,
166  float const* childEdgesSharpness) const;
167 
168  void GetSharpEdgePairOfCrease(float const * incidentEdgeSharpness,
169  int incidentEdgeCount,
170  int sharpEdgePair[2]) const;
171 
172  // Would these really help? Maybe only need Rules for the vertex-vertex case...
173  //
174  // Rule DetermineEdgeVertexRule(float parentEdgeSharpness) const;
175  // Rule DetermineEdgeVertexRule(float childEdge1Sharpness, float childEdge2Sharpness) const;
176 
177 protected:
178  float decrementSharpness(float sharpness) const;
179 
180 private:
181  Options _options;
182 };
183 
184 
185 //
186 // Inline declarations:
187 //
188 inline float
189 Crease::SharpenBoundaryEdge(float /* edgeSharpness */) const {
190 
191  //
192  // Despite the presence of the BOUNDARY_NONE option, boundary edges are always sharpened.
193  // Much of the code relies on sharpess to indicate boundaries to avoid the more complex
194  // topological inspection
195  //
196  return SHARPNESS_INFINITE;
197 }
198 
199 inline float
200 Crease::SharpenBoundaryVertex(float vertexSharpness) const {
201 
203  SHARPNESS_INFINITE : vertexSharpness;
204 }
205 
206 inline float
207 Crease::decrementSharpness(float sharpness) const {
208 
209  if (IsSmooth(sharpness)) return Crease::SHARPNESS_SMOOTH; // redundant but most common
210  if (IsInfinite(sharpness)) return Crease::SHARPNESS_INFINITE;
211  if (sharpness > 1.0f) return (sharpness - 1.0f);
213 }
214 
215 inline float
216 Crease::SubdivideUniformSharpness(float vertexOrEdgeSharpness) const {
217 
218  return decrementSharpness(vertexOrEdgeSharpness);
219 }
220 
221 inline float
222 Crease::SubdivideVertexSharpness(float vertexSharpness) const {
223 
224  return decrementSharpness(vertexSharpness);
225 }
226 
227 inline void
228 Crease::GetSharpEdgePairOfCrease(float const * incidentEdgeSharpness, int incidentEdgeCount,
229  int sharpEdgePair[2]) const {
230 
231  // Only to be called when a crease is present at a vertex -- exactly two sharp
232  // edges are expected here:
233  //
234  sharpEdgePair[0] = 0;
235  while (IsSmooth(incidentEdgeSharpness[sharpEdgePair[0]])) ++ sharpEdgePair[0];
236 
237  sharpEdgePair[1] = incidentEdgeCount - 1;
238  while (IsSmooth(incidentEdgeSharpness[sharpEdgePair[1]])) -- sharpEdgePair[1];
239 }
240 
241 } // end namespace sdc
242 
243 } // end namespace OPENSUBDIV_VERSION
244 using namespace OPENSUBDIV_VERSION;
245 } // end namespace OpenSubdiv
246 
247 #endif /* OPENSUBDIV3_SDC_CREASE_H */
CreasingMethod GetCreasingMethod() const
Get edge crease rule.
Definition: options.h:99
Rule DetermineVertexVertexRule(float vertexSharpness, int incidentEdgeCount, float const *incidentEdgeSharpness) const
float decrementSharpness(float sharpness) const
Definition: crease.h:207
VtxBoundaryInterpolation GetVtxBoundaryInterpolation() const
Set vertex boundary interpolation rule.
Definition: options.h:87
float SharpenBoundaryEdge(float edgeSharpness) const
Definition: crease.h:189
static bool IsInfinite(float sharpness)
Definition: crease.h:72
float SubdivideVertexSharpness(float vertexSharpness) const
Definition: crease.h:222
Crease(Options const &options)
Definition: crease.h:92
All supported options applying to subdivision scheme.
Definition: options.h:51
static bool IsSemiSharp(float sharpness)
Definition: crease.h:73
float SharpenBoundaryVertex(float edgeSharpness) const
Definition: crease.h:200
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...
void SubdivideEdgeSharpnessesAroundVertex(int incidentEdgeCountAtVertex, float const *incidentEdgeSharpnessAroundVertex, float *childEdgesSharpnessAroundVertex) const
void GetSharpEdgePairOfCrease(float const *incidentEdgeSharpness, int incidentEdgeCount, int sharpEdgePair[2]) const
Definition: crease.h:228
float SubdivideUniformSharpness(float vertexOrEdgeSharpness) const
Definition: crease.h:216
static bool IsSharp(float sharpness)
Definition: crease.h:71
static bool IsSmooth(float sharpness)
Definition: crease.h:70
float SubdivideEdgeSharpnessAtVertex(float edgeSharpness, int incidentEdgeCountAtEndVertex, float const *edgeSharpnessAroundEndVertex) const
Types, constants and utilities related to semi-sharp creasing – whose implementation is independent ...
Definition: crease.h:62