|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TCG_TRIANGULATE_H
|
|
Toshihiro Shimizu |
890ddd |
#define TCG_TRIANGULATE_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// tcg includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tcg_mesh.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace tcg
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace TriMeshStuff
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\brief Traits class providing useful accessor to vertex data
|
|
Toshihiro Shimizu |
890ddd |
in a form compatible with the GLU tessellator.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\details Vertex types usable with the GLU tessellator must have:
|
|
Toshihiro Shimizu |
890ddd |
\li A vertex position member, in the form of a
|
|
Toshihiro Shimizu |
890ddd |
<tt>double[3]</tt> array containing its <tt>(x,y,z)</tt>
|
|
Toshihiro Shimizu |
890ddd |
coordinates.
|
|
Toshihiro Shimizu |
890ddd |
\li An index member to identify the vertex.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename vertex_type=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct glu_vertex_traits {
|
|
Toshihiro Shimizu |
890ddd |
static inline double(&vertex3d(vertex_type &vx))[3]
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return vx.m_pos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static inline int &index(vertex_type &vx) { return vx.m_idx; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename trimesh_type=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct ActionEvaluator {
|
|
Toshihiro Shimizu |
890ddd |
enum Action { NONE,
|
|
Toshihiro Shimizu |
890ddd |
SWAP,
|
|
Toshihiro Shimizu |
890ddd |
COLLAPSE,
|
|
Toshihiro Shimizu |
890ddd |
SPLIT };
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Fill in the 3-array actionSequence with the actions you would want performed
|
|
Toshihiro Shimizu |
890ddd |
first on edge e of given mesh. Provided the actions are feasible, they will be
|
|
Toshihiro Shimizu |
890ddd |
performed in the returned order.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
virtual void actionSort(const TriMesh_type &mesh, int e, Action *actionSequence) = 0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename trimesh_type=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct DefaultEvaluator : public ActionEvaluator<trimesh_type> {</trimesh_type>
|
|
Toshihiro Shimizu |
890ddd |
double m_collapseValue;
|
|
Toshihiro Shimizu |
890ddd |
double m_splitValue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Sorts actions to achieve near-targetLength edge lengths.
|
|
Toshihiro Shimizu |
890ddd |
Split and collapse actions follow the rules:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Collapse if length < collapseValue <\li>
|
|
Toshihiro Shimizu |
890ddd |
Split if length > splitValue <\li>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\warning The simplification procedure may loop on certain configurations where
|
|
Toshihiro Shimizu |
890ddd |
collapses and splits alternate repeatedly.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DefaultEvaluator(double collapseValue, double splitValue)
|
|
Toshihiro Shimizu |
890ddd |
: m_collapseValue(collapseValue), m_splitValue(splitValue) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void actionSort(const TriMesh_type &mesh, int e, typename ActionEvaluator<trimesh_type>::Action *actionSequence);</trimesh_type>
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} //namespace TriMeshStuff
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//! Uses the glu tessellator to build a triangular mesh from a specified tribe of polygons.
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
The algorithm accepts a tribe (that is, a container of containers, where each container class stores
|
|
Toshihiro Shimizu |
890ddd |
pointer type objects <\I> to sub-containers) of polygons, and reads out a sequence of meshes with
|
|
Toshihiro Shimizu |
890ddd |
triangular faces.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Each family of the tribe should contain a list of polygons representing a connected component
|
|
Toshihiro Shimizu |
890ddd |
to triangulate, where its first element is the external border, and the following ones are the internals.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
The output meshes are the tessellation of each family in the tribe.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
template <typename containersreader="" forit,="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
void gluTriangulate(ForIt polygonsTribeBegin, ForIt polygonsTribeEnd, ContainersReader &meshes_reader);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename trimesh_type=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
void refineMesh(
|
|
Toshihiro Shimizu |
890ddd |
TriMesh_type &mesh,
|
|
Toshihiro Shimizu |
890ddd |
TriMeshStuff::ActionEvaluator<trimesh_type> &eval,</trimesh_type>
|
|
Toshihiro Shimizu |
890ddd |
unsigned long maxActions = (std::numeric_limits<unsigned long="">::max)());</unsigned>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} //namespace tcg
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif // TCG_TRIANGULATE_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef INCLUDE_HPP
|
|
Toshihiro Shimizu |
890ddd |
#include "hpp/triangulate.hpp"
|
|
Toshihiro Shimizu |
890ddd |
#endif
|