Loading...
Searching...
No Matches
patchParam.h
Go to the documentation of this file.
//
// Copyright 2013 Pixar
//
// 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_FAR_PATCH_PARAM_H
#define OPENSUBDIV3_FAR_PATCH_PARAM_H
#include "../version.h"
#include "../far/types.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
struct PatchParam {
void Set(Index faceid, short u, short v,
unsigned short depth, bool nonquad,
unsigned short boundary, unsigned short transition,
bool regular = false);
void Clear() { field0 = field1 = 0; }
Index GetFaceId() const { return Index(unpack(field0,28,0)); }
unsigned short GetU() const { return (unsigned short)unpack(field1,10,22); }
unsigned short GetV() const { return (unsigned short)unpack(field1,10,12); }
unsigned short GetTransition() const { return (unsigned short)unpack(field0,4,28); }
unsigned short GetBoundary() const { return (unsigned short)unpack(field1,5,7); }
bool NonQuadRoot() const { return (unpack(field1,1,4) != 0); }
unsigned short GetDepth() const { return (unsigned short)unpack(field1,4,0); }
float GetParamFraction() const;
template <typename REAL>
void Normalize( REAL & u, REAL & v ) const;
template <typename REAL>
void NormalizeTriangle( REAL & u, REAL & v ) const;
template <typename REAL>
void Unnormalize( REAL & u, REAL & v ) const;
template <typename REAL>
void UnnormalizeTriangle( REAL & u, REAL & v ) const;
bool IsTriangleRotated() const;
bool IsRegular() const { return (unpack(field1,1,5) != 0); }
unsigned int field0:32;
unsigned int field1:32;
private:
unsigned int pack(unsigned int value, int width, int offset) const {
return (unsigned int)((value & ((1<<width)-1)) << offset);
}
unsigned int unpack(unsigned int value, int width, int offset) const {
return (unsigned int)((value >> offset) & ((1<<width)-1));
}
};
typedef std::vector<PatchParam> PatchParamTable;
typedef Vtr::Array<PatchParam> PatchParamArray;
typedef Vtr::ConstArray<PatchParam> ConstPatchParamArray;
inline void
PatchParam::Set(Index faceid, short u, short v,
unsigned short depth, bool nonquad,
unsigned short boundary, unsigned short transition,
bool regular) {
field0 = pack(faceid, 28, 0) |
pack(transition, 4, 28);
field1 = pack(u, 10, 22) |
pack(v, 10, 12) |
pack(boundary, 5, 7) |
pack(regular, 1, 5) |
pack(nonquad, 1, 4) |
pack(depth, 4, 0);
}
inline float
PatchParam::GetParamFraction( ) const {
return 1.0f / (float)(1 << (GetDepth() - NonQuadRoot()));
}
template <typename REAL>
inline void
PatchParam::Normalize( REAL & u, REAL & v ) const {
REAL fracInv = (REAL)(1.0f / GetParamFraction());
u = u * fracInv - (REAL)GetU();
v = v * fracInv - (REAL)GetV();
}
template <typename REAL>
inline void
PatchParam::Unnormalize( REAL & u, REAL & v ) const {
REAL frac = (REAL)GetParamFraction();
u = (u + (REAL)GetU()) * frac;
v = (v + (REAL)GetV()) * frac;
}
inline bool
PatchParam::IsTriangleRotated() const {
return (GetU() + GetV()) >= (1 << GetDepth());
}
template <typename REAL>
inline void
PatchParam::NormalizeTriangle( REAL & u, REAL & v ) const {
if (IsTriangleRotated()) {
REAL fracInv = (REAL)(1.0f / GetParamFraction());
int depthFactor = 1 << GetDepth();
u = (REAL)(depthFactor - GetU()) - (u * fracInv);
v = (REAL)(depthFactor - GetV()) - (v * fracInv);
} else {
Normalize(u, v);
}
}
template <typename REAL>
inline void
PatchParam::UnnormalizeTriangle( REAL & u, REAL & v ) const {
if (IsTriangleRotated()) {
REAL frac = GetParamFraction();
int depthFactor = 1 << GetDepth();
u = ((REAL)(depthFactor - GetU()) - u) * frac;
v = ((REAL)(depthFactor - GetV()) - v) * frac;
} else {
Unnormalize(u, v);
}
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_PATCH_PARAM */
OpenSubdiv
Definition error.h:30
OpenSubdiv::OPENSUBDIV_VERSION::Far::ConstPatchParamArray
Vtr::ConstArray< PatchParam > ConstPatchParamArray
Definition patchParam.h:246
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParamTable
std::vector< PatchParam > PatchParamTable
Definition patchParam.h:243
OpenSubdiv::OPENSUBDIV_VERSION::Far::Index
Vtr::Index Index
Definition types.h:41
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParamArray
Vtr::Array< PatchParam > PatchParamArray
Definition patchParam.h:245
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam
Patch parameterization.
Definition patchParam.h:152
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::IsTriangleRotated
bool IsTriangleRotated() const
Returns if a triangular patch is parametrically rotated 180 degrees.
Definition patchParam.h:290
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::IsRegular
bool IsRegular() const
Returns whether the patch is regular.
Definition patchParam.h:228
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::NormalizeTriangle
void NormalizeTriangle(REAL &u, REAL &v) const
Definition patchParam.h:297
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetBoundary
unsigned short GetBoundary() const
Returns the boundary edge encoding for the patch.
Definition patchParam.h:191
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetTransition
unsigned short GetTransition() const
Returns the transition edge encoding for the patch.
Definition patchParam.h:188
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetParamFraction
float GetParamFraction() const
Returns the fraction of unit parametric space covered by this face.
Definition patchParam.h:265
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetU
unsigned short GetU() const
Returns the log2 value of the u parameter at the first corner of the patch.
Definition patchParam.h:181
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetFaceId
Index GetFaceId() const
Returns the faceid.
Definition patchParam.h:177
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetDepth
unsigned short GetDepth() const
Returns the level of subdivision of the patch.
Definition patchParam.h:197
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::NonQuadRoot
bool NonQuadRoot() const
True if the parent base face is a non-quad.
Definition patchParam.h:194
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::Set
void Set(Index faceid, short u, short v, unsigned short depth, bool nonquad, unsigned short boundary, unsigned short transition, bool regular=false)
Sets the values of the bit fields.
Definition patchParam.h:249
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::Clear
void Clear()
Resets everything to 0.
Definition patchParam.h:174
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::field1
unsigned int field1
Definition patchParam.h:231
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::Unnormalize
void Unnormalize(REAL &u, REAL &v) const
A (u,v) pair in a normalized parametric space is mapped back into the fraction of parametric space co...
Definition patchParam.h:281
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::UnnormalizeTriangle
void UnnormalizeTriangle(REAL &u, REAL &v) const
Definition patchParam.h:312
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetV
unsigned short GetV() const
Returns the log2 value of the v parameter at the first corner of the patch.
Definition patchParam.h:185
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::field0
unsigned int field0
Definition patchParam.h:230
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::Normalize
void Normalize(REAL &u, REAL &v) const
A (u,v) pair in the fraction of parametric space covered by this face is mapped into a normalized par...
Definition patchParam.h:271
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::ConstArray
Definition array.h:53
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::Array
Definition array.h:105
types.h