Loading...
Searching...
No Matches
parameterization.h
Go to the documentation of this file.
//
// Copyright 2021 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_BFR_PARAMETERIZATION_H
#define OPENSUBDIV3_BFR_PARAMETERIZATION_H
#include "../version.h"
#include "../sdc/types.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Bfr {
class Parameterization {
public:
enum Type { QUAD,
TRI,
QUAD_SUBFACES
};
public:
Parameterization(Sdc::SchemeType scheme, int faceSize);
bool IsValid() const { return (_faceSize > 0); }
Parameterization() : _type(0), _uDim(0), _faceSize(0) { }
Parameterization(Parameterization const &) = default;
Parameterization & operator=(Parameterization const &) = default;
~Parameterization() = default;
Type GetType() const { return (Type) _type; }
int GetFaceSize() const { return _faceSize; }
public:
template <typename REAL>
void GetVertexCoord(int vertexIndex, REAL uvCoord[2]) const;
template <typename REAL>
void GetEdgeCoord(int edgeIndex, REAL t, REAL uvCoord[2]) const;
template <typename REAL>
void GetCenterCoord(REAL uvCoord[2]) const;
public:
bool HasSubFaces() const;
template <typename REAL>
int GetSubFace(REAL const uvCoord[2]) const;
template <typename REAL>
int ConvertCoordToSubFace(
REAL const uvCoord[2], REAL subFaceCoord[2]) const;
template <typename REAL>
void ConvertSubFaceToCoord(int subFace,
REAL const subFaceCoord[2], REAL uvCoord[2]) const;
template <typename REAL>
int ConvertCoordToNormalizedSubFace(
REAL const uvCoord[2], REAL subFaceCoord[2]) const;
template <typename REAL>
void ConvertNormalizedSubFaceToCoord(int subFace,
REAL const subFaceCoord[2], REAL uvCoord[2]) const;
private:
template <typename REAL>
int convertCoordToSubFace(bool normalized,
REAL const uvCoord[2], REAL subFaceCoord[2]) const;
template <typename REAL>
void convertSubFaceToCoord(bool normalized, int subFace,
REAL const subFaceCoord[2], REAL uvCoord[2]) const;
private:
unsigned char _type;
unsigned char _uDim;
unsigned short _faceSize;
};
//
// Inline sub-face coordinate conversion methods:
//
inline bool
Parameterization::HasSubFaces() const {
return (_type == QUAD_SUBFACES);
}
template <typename REAL>
inline int
Parameterization::GetSubFace(REAL const uvCoord[2]) const {
if (!HasSubFaces()) return 0;
int uTile = (int) uvCoord[0];
int vTile = (int) uvCoord[1];
return (vTile + ((uvCoord[1] - (REAL) vTile) > 0.75f)) * _uDim +
(uTile + ((uvCoord[0] - (REAL) uTile) > 0.75f));
}
// Conversions to unnormalized sub-face coordinates:
template <typename REAL>
inline int
Parameterization::ConvertCoordToSubFace(
REAL const uvCoord[2], REAL subCoord[2]) const {
return convertCoordToSubFace<REAL>(false, uvCoord, subCoord);
}
template <typename REAL>
inline void
Parameterization::ConvertSubFaceToCoord(
int subFace, REAL const subCoord[2], REAL uvCoord[2]) const {
convertSubFaceToCoord<REAL>(false, subFace, subCoord, uvCoord);
}
// Conversions to normalized sub-face coordinates:
template <typename REAL>
inline int
Parameterization::ConvertCoordToNormalizedSubFace(
REAL const uvCoord[2], REAL subCoord[2]) const {
return convertCoordToSubFace<REAL>(true, uvCoord, subCoord);
}
template <typename REAL>
inline void
Parameterization::ConvertNormalizedSubFaceToCoord(
int subFace, REAL const subCoord[2], REAL uvCoord[2]) const {
convertSubFaceToCoord<REAL>(true, subFace, subCoord, uvCoord);
}
} // end namespace Bfr
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_BFR_PARAMETERIZATION */
OpenSubdiv
Definition limits.h:32
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:33
OpenSubdiv::OPENSUBDIV_VERSION::Bfr
Definition limits.h:35
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::SchemeType
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition types.h:37
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetSubFace
int GetSubFace(REAL const uvCoord[2]) const
Returns the integer sub-face containing the given (u,v).
Definition parameterization.h:202
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetFaceSize
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
Definition parameterization.h:101
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::Type
Type
Enumerated type for the different kinds of Parameterizations.
Definition parameterization.h:62
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::QUAD_SUBFACES
@ QUAD_SUBFACES
Partitioned into quadrilateral sub-faces.
Definition parameterization.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::TRI
@ TRI
Triangle.
Definition parameterization.h:63
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::QUAD
@ QUAD
Quadrilateral.
Definition parameterization.h:62
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::Parameterization
Parameterization(Sdc::SchemeType scheme, int faceSize)
Primary constructor with subdivision scheme and face size.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::ConvertCoordToSubFace
int ConvertCoordToSubFace(REAL const uvCoord[2], REAL subFaceCoord[2]) const
Convert (u,v) to a sub-face (return value) and its local (u,v) coordinate.
Definition parameterization.h:215
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetCenterCoord
void GetCenterCoord(REAL uvCoord[2]) const
Returns the (u,v) coordinate for the center of the face.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetType
Type GetType() const
Returns the type of parameterization assigned.
Definition parameterization.h:98
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::~Parameterization
~Parameterization()=default
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::Parameterization
Parameterization(Parameterization const &)=default
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetEdgeCoord
void GetEdgeCoord(int edgeIndex, REAL t, REAL uvCoord[2]) const
Returns the (u,v) coordinate at any point on a given edge.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::ConvertNormalizedSubFaceToCoord
void ConvertNormalizedSubFaceToCoord(int subFace, REAL const subFaceCoord[2], REAL uvCoord[2]) const
Convert a sub-face and its normalized (u,v) coordinate to (u,v).
Definition parameterization.h:235
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetVertexCoord
void GetVertexCoord(int vertexIndex, REAL uvCoord[2]) const
Returns the (u,v) coordinate of a given vertex.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::Parameterization
Parameterization()
Default construction produces an invalid instance.
Definition parameterization.h:84
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::IsValid
bool IsValid() const
Returns true if correctly initialized.
Definition parameterization.h:81
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::HasSubFaces
bool HasSubFaces() const
Returns if Parameterization has been partitioned into sub-faces.
Definition parameterization.h:196
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::ConvertCoordToNormalizedSubFace
int ConvertCoordToNormalizedSubFace(REAL const uvCoord[2], REAL subFaceCoord[2]) const
Convert (u,v) to a sub-face (return value) and its normalized (u,v) coordinate.
Definition parameterization.h:229
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::ConvertSubFaceToCoord
void ConvertSubFaceToCoord(int subFace, REAL const subFaceCoord[2], REAL uvCoord[2]) const
Convert a sub-face and its local (u,v) coordinate to (u,v).
Definition parameterization.h:221
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::operator=
Parameterization & operator=(Parameterization const &)=default
types.h