2014-11-25 20:41:19 +00:00
|
|
|
//
|
|
|
|
// 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 FAR_PATCH_DESCRIPTOR_H
|
|
|
|
#define FAR_PATCH_DESCRIPTOR_H
|
|
|
|
|
|
|
|
#include "../version.h"
|
|
|
|
|
2015-02-11 22:25:44 +00:00
|
|
|
#include "../far/types.h"
|
2015-01-06 22:26:20 +00:00
|
|
|
#include "../sdc/types.h"
|
2014-11-25 20:41:19 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
namespace Far {
|
|
|
|
|
|
|
|
/// \brief Describes the type of a patch
|
|
|
|
///
|
|
|
|
/// Uniquely identifies all the different types of patches
|
|
|
|
///
|
|
|
|
/// * Uniformly subdivided meshes contain bilinear patches of either QUADS
|
|
|
|
/// or TRIANGLES
|
|
|
|
///
|
|
|
|
/// * Adaptively subdivided meshes contain bicubic patches of types REGULAR,
|
2015-05-13 18:31:02 +00:00
|
|
|
/// GREGORY, GREGORY_BOUNDARY, GREGORY_BASIS.
|
2014-11-25 20:41:19 +00:00
|
|
|
/// These bicubic patches are also further distinguished by a transition
|
|
|
|
/// pattern as well as a rotational orientation.
|
|
|
|
///
|
|
|
|
/// Bitfield layout :
|
|
|
|
///
|
2015-04-17 14:42:53 +00:00
|
|
|
/// Field | Bits | Content
|
|
|
|
/// ------------|:----:|------------------------------------------------------
|
|
|
|
/// _type | 4 | patch type
|
2014-11-25 20:41:19 +00:00
|
|
|
///
|
|
|
|
class PatchDescriptor {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum Type {
|
|
|
|
NON_PATCH = 0, ///< undefined
|
|
|
|
|
|
|
|
POINTS, ///< points (useful for cage drawing)
|
|
|
|
LINES, ///< lines (useful for cage drawing)
|
|
|
|
|
|
|
|
QUADS, ///< bilinear quads-only patches
|
|
|
|
TRIANGLES, ///< bilinear triangles-only mesh
|
|
|
|
|
|
|
|
LOOP, ///< Loop patch
|
|
|
|
|
|
|
|
REGULAR, ///< feature-adaptive bicubic patches
|
|
|
|
GREGORY,
|
|
|
|
GREGORY_BOUNDARY,
|
|
|
|
GREGORY_BASIS
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// \brief Default constructor.
|
|
|
|
PatchDescriptor() :
|
2015-04-17 14:42:53 +00:00
|
|
|
_type(NON_PATCH) { }
|
2014-11-25 20:41:19 +00:00
|
|
|
|
|
|
|
/// \brief Constructor
|
2015-04-17 14:42:53 +00:00
|
|
|
PatchDescriptor(int type) :
|
|
|
|
_type(type) { }
|
2014-11-25 20:41:19 +00:00
|
|
|
|
|
|
|
/// \brief Copy Constructor
|
|
|
|
PatchDescriptor( PatchDescriptor const & d ) :
|
2015-04-17 14:42:53 +00:00
|
|
|
_type(d.GetType()) { }
|
2014-11-25 20:41:19 +00:00
|
|
|
|
|
|
|
/// \brief Returns the type of the patch
|
|
|
|
Type GetType() const {
|
|
|
|
return (Type)_type;
|
|
|
|
}
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
/// \brief Returns true if the type is an adaptive patch
|
|
|
|
static inline bool IsAdaptive(Type type) {
|
|
|
|
return (type>=LOOP and type<=GREGORY_BASIS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns true if the type is an adaptive patch
|
|
|
|
bool IsAdaptive() const {
|
|
|
|
return IsAdaptive( this->GetType() );
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
/// \brief Returns the number of control vertices expected for a patch of the
|
|
|
|
/// type described
|
|
|
|
static inline short GetNumControlVertices( Type t );
|
|
|
|
|
|
|
|
static inline short GetNumFVarControlVertices( Type t );
|
|
|
|
|
|
|
|
/// \brief Returns the number of control vertices expected for a patch of the
|
|
|
|
/// type described
|
|
|
|
short GetNumControlVertices() const {
|
|
|
|
return GetNumControlVertices( this->GetType() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the number of control vertices expected for a patch of the
|
|
|
|
/// type described
|
|
|
|
short GetNumFVarControlVertices() const {
|
|
|
|
return GetNumFVarControlVertices( this->GetType() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Number of control vertices of Regular Patches in table.
|
|
|
|
static short GetRegularPatchSize() { return 16; }
|
|
|
|
|
|
|
|
/// \brief Number of control vertices of Gregory (and Gregory Boundary) Patches in table.
|
|
|
|
static short GetGregoryPatchSize() { return 4; }
|
|
|
|
|
|
|
|
/// \brief Number of control vertices of Gregory patch basis (20)
|
|
|
|
static short GetGregoryBasisPatchSize() { return 20; }
|
|
|
|
|
|
|
|
|
|
|
|
/// \brief Returns a vector of all the legal patch descriptors for the
|
|
|
|
/// given adaptive subdivision scheme
|
2015-02-11 22:25:44 +00:00
|
|
|
static Vtr::ConstArray<PatchDescriptor> GetAdaptivePatchDescriptors(Sdc::SchemeType type);
|
2014-11-25 20:41:19 +00:00
|
|
|
|
|
|
|
/// \brief Allows ordering of patches by type
|
|
|
|
inline bool operator < ( PatchDescriptor const other ) const;
|
|
|
|
|
|
|
|
/// \brief True if the descriptors are identical
|
|
|
|
inline bool operator == ( PatchDescriptor const other ) const;
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
// debug helper
|
|
|
|
void print() const;
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
private:
|
|
|
|
unsigned int _type:4;
|
|
|
|
};
|
|
|
|
|
2015-02-11 22:25:44 +00:00
|
|
|
typedef Vtr::ConstArray<PatchDescriptor> ConstPatchDescriptorArray;
|
2014-11-25 20:41:19 +00:00
|
|
|
|
|
|
|
// Returns the number of control vertices expected for a patch of this type
|
|
|
|
inline short
|
|
|
|
PatchDescriptor::GetNumControlVertices( Type type ) {
|
|
|
|
switch (type) {
|
|
|
|
case REGULAR : return GetRegularPatchSize();
|
|
|
|
case QUADS : return 4;
|
|
|
|
case GREGORY :
|
|
|
|
case GREGORY_BOUNDARY : return GetGregoryPatchSize();
|
|
|
|
case GREGORY_BASIS : return GetGregoryBasisPatchSize();
|
|
|
|
case TRIANGLES : return 3;
|
|
|
|
case LINES : return 2;
|
|
|
|
case POINTS : return 1;
|
|
|
|
default : return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the number of face-varying control vertices expected for a patch of this type
|
|
|
|
inline short
|
|
|
|
PatchDescriptor::GetNumFVarControlVertices( Type type ) {
|
|
|
|
switch (type) {
|
2015-02-26 21:57:47 +00:00
|
|
|
case REGULAR : return GetRegularPatchSize();
|
|
|
|
case QUADS : return 4;
|
2014-11-25 20:41:19 +00:00
|
|
|
case TRIANGLES : return 3;
|
|
|
|
case LINES : return 2;
|
|
|
|
case POINTS : return 1;
|
2015-02-26 21:57:47 +00:00
|
|
|
case GREGORY_BASIS : assert(0); return GetGregoryBasisPatchSize();
|
|
|
|
case GREGORY :
|
|
|
|
case GREGORY_BOUNDARY : assert(0); // unsupported types
|
2014-11-25 20:41:19 +00:00
|
|
|
default : return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allows ordering of patches by type
|
|
|
|
inline bool
|
|
|
|
PatchDescriptor::operator < ( PatchDescriptor const other ) const {
|
2015-04-17 14:42:53 +00:00
|
|
|
return (_type < other._type);
|
2014-11-25 20:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// True if the descriptors are identical
|
|
|
|
inline bool
|
|
|
|
PatchDescriptor::operator == ( PatchDescriptor const other ) const {
|
2015-04-17 14:42:53 +00:00
|
|
|
return _type == other._type;
|
2014-11-25 20:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace Far
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
|
|
|
#endif /* FAR_PATCH_DESCRIPTOR_H */
|