crease.h
Go to the documentation of this file.
//
// Copyright 2014 DreamWorks Animation LLC.
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef OPENSUBDIV3_SDC_CREASE_H
#define OPENSUBDIV3_SDC_CREASE_H
#include "../version.h"
#include "../sdc/options.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Sdc {
class Crease {
public:
static float const SHARPNESS_SMOOTH; // = 0.0f, do we really need this?
static float const SHARPNESS_INFINITE; // = 10.0f;
static bool IsSmooth(float sharpness) { return sharpness <= SHARPNESS_SMOOTH; }
static bool IsSharp(float sharpness) { return sharpness > SHARPNESS_SMOOTH; }
static bool IsInfinite(float sharpness) { return sharpness >= SHARPNESS_INFINITE; }
static bool IsSemiSharp(float sharpness) { return (SHARPNESS_SMOOTH < sharpness) && (sharpness < SHARPNESS_INFINITE); }
enum Rule {
RULE_UNKNOWN = 0,
RULE_SMOOTH = (1 << 0),
RULE_DART = (1 << 1),
RULE_CREASE = (1 << 2),
RULE_CORNER = (1 << 3)
};
public:
Crease() : _options() { }
Crease(Options const& options) : _options(options) { }
~Crease() { }
bool IsUniform() const { return _options.GetCreasingMethod() == Options::CREASE_UNIFORM; }
float SharpenBoundaryEdge(float edgeSharpness) const;
float SharpenBoundaryVertex(float edgeSharpness) const;
// For future consideration
//float SharpenNonManifoldEdge(float edgeSharpness) const;
//float SharpenNonManifoldVertex(float edgeSharpness) const;
float SubdivideUniformSharpness(float vertexOrEdgeSharpness) const;
float SubdivideVertexSharpness(float vertexSharpness) const;
float SubdivideEdgeSharpnessAtVertex(float edgeSharpness,
int incidentEdgeCountAtEndVertex,
float const* edgeSharpnessAroundEndVertex) const;
void SubdivideEdgeSharpnessesAroundVertex(int incidentEdgeCountAtVertex,
float const* incidentEdgeSharpnessAroundVertex,
float* childEdgesSharpnessAroundVertex) const;
Rule DetermineVertexVertexRule(float vertexSharpness,
int incidentEdgeCount,
float const* incidentEdgeSharpness) const;
Rule DetermineVertexVertexRule(float vertexSharpness,
int sharpEdgeCount) const;
float ComputeFractionalWeightAtVertex(float vertexSharpness,
float childVertexSharpness,
int incidentEdgeCount,
float const* incidentEdgeSharpness,
float const* childEdgesSharpness) const;
void GetSharpEdgePairOfCrease(float const * incidentEdgeSharpness,
int incidentEdgeCount,
int sharpEdgePair[2]) const;
// Would these really help? Maybe only need Rules for the vertex-vertex case...
//
// Rule DetermineEdgeVertexRule(float parentEdgeSharpness) const;
// Rule DetermineEdgeVertexRule(float childEdge1Sharpness, float childEdge2Sharpness) const;
protected:
float decrementSharpness(float sharpness) const;
private:
Options _options;
};
//
// Inline declarations:
//
inline float
Crease::SharpenBoundaryEdge(float /* edgeSharpness */) const {
//
// Despite the presence of the BOUNDARY_NONE option, boundary edges are always sharpened.
// Much of the code relies on sharpness to indicate boundaries to avoid the more complex
// topological inspection
//
return SHARPNESS_INFINITE;
}
inline float
Crease::SharpenBoundaryVertex(float vertexSharpness) const {
return (_options.GetVtxBoundaryInterpolation() == Options::VTX_BOUNDARY_EDGE_AND_CORNER) ?
SHARPNESS_INFINITE : vertexSharpness;
}
inline float
Crease::decrementSharpness(float sharpness) const {
if (IsSmooth(sharpness)) return Crease::SHARPNESS_SMOOTH; // redundant but most common
if (IsInfinite(sharpness)) return Crease::SHARPNESS_INFINITE;
if (sharpness > 1.0f) return (sharpness - 1.0f);
return Crease::SHARPNESS_SMOOTH;
}
inline float
Crease::SubdivideUniformSharpness(float vertexOrEdgeSharpness) const {
return decrementSharpness(vertexOrEdgeSharpness);
}
inline float
Crease::SubdivideVertexSharpness(float vertexSharpness) const {
return decrementSharpness(vertexSharpness);
}
inline void
Crease::GetSharpEdgePairOfCrease(float const * incidentEdgeSharpness, int incidentEdgeCount,
int sharpEdgePair[2]) const {
// Only to be called when a crease is present at a vertex -- exactly two sharp
// edges are expected here:
//
sharpEdgePair[0] = 0;
while (IsSmooth(incidentEdgeSharpness[sharpEdgePair[0]])) ++ sharpEdgePair[0];
sharpEdgePair[1] = incidentEdgeCount - 1;
while (IsSmooth(incidentEdgeSharpness[sharpEdgePair[1]])) -- sharpEdgePair[1];
}
} // end namespace sdc
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_SDC_CREASE_H */
OpenSubdiv
Definition: limits.h:32
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease
Types, constants and utilities related to semi-sharp creasing – whose implementation is independent o...
Definition: crease.h:62
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SubdivideVertexSharpness
float SubdivideVertexSharpness(float vertexSharpness) const
Definition: crease.h:222
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::IsInfinite
static bool IsInfinite(float sharpness)
Definition: crease.h:72
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::Rule
Rule
Definition: crease.h:82
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::RULE_CORNER
@ RULE_CORNER
Definition: crease.h:87
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::RULE_DART
@ RULE_DART
Definition: crease.h:85
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::RULE_SMOOTH
@ RULE_SMOOTH
Definition: crease.h:84
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::RULE_CREASE
@ RULE_CREASE
Definition: crease.h:86
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::RULE_UNKNOWN
@ RULE_UNKNOWN
Definition: crease.h:83
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SharpenBoundaryVertex
float SharpenBoundaryVertex(float edgeSharpness) const
Definition: crease.h:200
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SHARPNESS_SMOOTH
static float const SHARPNESS_SMOOTH
Definition: crease.h:67
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::GetSharpEdgePairOfCrease
void GetSharpEdgePairOfCrease(float const *incidentEdgeSharpness, int incidentEdgeCount, int sharpEdgePair[2]) const
Definition: crease.h:228
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SHARPNESS_INFINITE
static float const SHARPNESS_INFINITE
Definition: crease.h:68
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:207
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::IsSmooth
static bool IsSmooth(float sharpness)
Definition: crease.h:70
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:95
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::IsSemiSharp
static bool IsSemiSharp(float sharpness)
Definition: crease.h:73
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::Crease
Crease(Options const &options)
Definition: crease.h:92
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:216
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::Crease
Crease()
Definition: crease.h:91
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SharpenBoundaryEdge
float SharpenBoundaryEdge(float edgeSharpness) const
Definition: crease.h:189
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:71
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::~Crease
~Crease()
Definition: crease.h:93
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options
All supported options applying to subdivision scheme.
Definition: options.h:51
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options::CREASE_UNIFORM
@ CREASE_UNIFORM
Catmark rule.
Definition: options.h:69
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options::GetCreasingMethod
CreasingMethod GetCreasingMethod() const
Get edge crease rule.
Definition: options.h:101
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options::GetVtxBoundaryInterpolation
VtxBoundaryInterpolation GetVtxBoundaryInterpolation() const
Get vertex boundary interpolation rule.
Definition: options.h:89
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options::VTX_BOUNDARY_EDGE_AND_CORNER
@ VTX_BOUNDARY_EDGE_AND_CORNER
Definition: options.h:57