Cafu Engine
cf::math::BezierPatchT< T > Class Template Reference

This class represents a mesh that approximates a Bezier patch. More...

#include "BezierPatch.hpp"

Classes

struct  VertexT
 Represents a single vertex. More...
 

Public Member Functions

 BezierPatchT ()
 Constructor for creating an empty Bezier patch. More...
 
 BezierPatchT (unsigned long Width_, unsigned long Height_, const ArrayT< Vector3T< T > > &Coords_)
 Constructor for creating a patch from given coordinates. More...
 
 BezierPatchT (unsigned long Width_, unsigned long Height_, const ArrayT< Vector3T< T > > &Coords_, const ArrayT< Vector3T< T > > &TexCoords_)
 Constructor for creating a patch from given coordinates and texture-coordinates. More...
 
void ComputeTangentSpace ()
 (Re-)computes the tangent space vectors (normal and tangents) for each vertex of the mesh. More...
 
void ComputeTangentSpace_Obsolete ()
 (Re-)computes the tangent space vectors (normal and tangents) for each vertex of the mesh. More...
 
void Subdivide (T MaxError, T MaxLength, bool OptimizeFlat=true)
 This method subdivides the patch "automatically", that is, by the given maximal error and length bounds. More...
 
void Subdivide (unsigned long SubDivsHorz, unsigned long SubDivsVert, bool OptimizeFlat=true)
 Subdivides the patch "manually", that is, as often as explicitly stated by the parameter values. More...
 
void ForceLinearMaxLength (T MaxLength)
 Intended to be called after one of the Subdivide() methods has been called, this methods linearly subdivides the rows and columns of the mesh so that the MaxLength is never exceeded. More...
 
GetSurfaceAreaAtVertex (unsigned long i, unsigned long j) const
 Returns the area of the Bezier patch surface around vertex (i, j). More...
 
const VertexTGetVertex (unsigned long i, unsigned long j) const
 Returns the const mesh vertex at (i, j). More...
 
VertexTGetVertex (unsigned long i, unsigned long j)
 Returns the (non-const) mesh vertex at (i, j). More...
 
bool WrapsHorz () const
 Returns whether the left and right borders are identical. More...
 
bool WrapsVert () const
 Returns whether the top and bottom borders are identical. More...
 

Public Attributes

unsigned long Width
 Number of vertices in width direction. More...
 
unsigned long Height
 Number of vertices in height direction. More...
 
ArrayT< VertexTMesh
 Array of Width*Heights vertices that build up the bezier patch. More...
 

Detailed Description

template<class T>
class cf::math::BezierPatchT< T >

This class represents a mesh that approximates a Bezier patch.

Two invariants are possible: a) Before one of the Subdivide() methods has been called, the mesh is considered to be a control mesh. A control mesh consists alternatingly of interpolation and approximation vertices which are quasi a composition of 3x3 sub-patches with shared borders. The width and height therefore must be odd numbers >= 3. b) After one of the Subdivide() methods has been called, the mesh is just an approximation of the Bezier patch. Contrary to a), all it's vertices lie on the patch curve.

Constructor & Destructor Documentation

template<class T >
BezierPatchT::BezierPatchT ( )

Constructor for creating an empty Bezier patch.

template<class T >
BezierPatchT::BezierPatchT ( unsigned long  Width_,
unsigned long  Height_,
const ArrayT< Vector3T< T > > &  Coords_ 
)

Constructor for creating a patch from given coordinates.

template<class T >
BezierPatchT::BezierPatchT ( unsigned long  Width_,
unsigned long  Height_,
const ArrayT< Vector3T< T > > &  Coords_,
const ArrayT< Vector3T< T > > &  TexCoords_ 
)

Constructor for creating a patch from given coordinates and texture-coordinates.

Member Function Documentation

template<class T >
void BezierPatchT::ComputeTangentSpace ( )

(Re-)computes the tangent space vectors (normal and tangents) for each vertex of the mesh.

This method must only be called before any of the Subdivide() methods is called, it does not work thereafter.

template<class T >
void BezierPatchT::ComputeTangentSpace_Obsolete ( )

(Re-)computes the tangent space vectors (normal and tangents) for each vertex of the mesh.

This method is supposed to be called before one of the Subdivide() methods is called, but it is actually independent of it. That is, it does not matter whether this method is called first and Subdivide() second, or vice versa - both orders are possible and valid, and they should even yield the same result. OBSOLETE NOTE: This method does not really work reliable, the tangent space axes that it generates are frequently questionable... Instead of debugging its code, I rather provide a completely new implementation in a seperate method.

template<class T >
void BezierPatchT::ForceLinearMaxLength ( MaxLength)

Intended to be called after one of the Subdivide() methods has been called, this methods linearly subdivides the rows and columns of the mesh so that the MaxLength is never exceeded.

This is useful/intended for obtaining meshes for lightmap computation purposes. Note that this method quasi does the very opposite from what OptimizeFlatRowAndColumnStrips() does: it inserts "flat" (linear) rows and columns of vertices. Q: Couldn't we just call Subdivide(LargeNum, MaxLength, false); to achieve the same result? A: No!! Two counter examples, both observed with the handrails in the TechDemo map: a) The end pads are small 3x3 patches with sides shorter than MaxLength. However they are not reduced to 2x2 meshes when Subdivide() is called with OptimizeFlat being set to false. b) The rails themselves suffer from the same problem (at each of the four cylindrical sides), plus they rely on their explicitly stated number of subdivisions for ignoring their central interpolating control vertex, whose consideration would deform the handrail!

Parameters
MaxLengthMaximum length of the subdivisions.
template<class T >
T BezierPatchT::GetSurfaceAreaAtVertex ( unsigned long  i,
unsigned long  j 
) const

Returns the area of the Bezier patch surface around vertex (i, j).

template<class T>
const VertexT& cf::math::BezierPatchT< T >::GetVertex ( unsigned long  i,
unsigned long  j 
) const
inline

Returns the const mesh vertex at (i, j).

template<class T>
VertexT& cf::math::BezierPatchT< T >::GetVertex ( unsigned long  i,
unsigned long  j 
)
inline

Returns the (non-const) mesh vertex at (i, j).

template<class T >
void BezierPatchT::Subdivide ( MaxError,
MaxLength,
bool  OptimizeFlat = true 
)

This method subdivides the patch "automatically", that is, by the given maximal error and length bounds.

Parameters
MaxErrorThe maximum allowed spatial distance between the computed approximation mesh and the true mathematical curve.
MaxLengthThe maximum side length that one mesh element may have.
OptimizeFlatIf true unnecessary vertices from flat substrips are removed.
template<class T >
void BezierPatchT::Subdivide ( unsigned long  SubDivsHorz,
unsigned long  SubDivsVert,
bool  OptimizeFlat = true 
)

Subdivides the patch "manually", that is, as often as explicitly stated by the parameter values.

Parameters
SubDivsHorzThe number of horizontal subdivisions that each 3x3 sub-patch is subdivided into.
SubDivsVertThe number of vertical subdivisions that each 3x3 sub-patch is subdivided into.
OptimizeFlatIf true unnecessary vertices from flat substrips are removed.
template<class T >
bool BezierPatchT::WrapsHorz ( ) const

Returns whether the left and right borders are identical.

Returns whether the patch mesh wraps "in the width", i.e. if the left and right borders are identical.

template<class T >
bool BezierPatchT::WrapsVert ( ) const

Returns whether the top and bottom borders are identical.

Returns whether the patch mesh wraps "in the height", i.e. if the top and bottom borders are identical.

Member Data Documentation

template<class T>
unsigned long cf::math::BezierPatchT< T >::Height

Number of vertices in height direction.

template<class T>
ArrayT<VertexT> cf::math::BezierPatchT< T >::Mesh

Array of Width*Heights vertices that build up the bezier patch.

template<class T>
unsigned long cf::math::BezierPatchT< T >::Width

Number of vertices in width direction.


The documentation for this class was generated from the following files: