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
Shinya Kitaoka 120a6e
namespace tcg {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace TriMeshStuff {
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 {
Shinya Kitaoka 120a6e
  static inline double (&vertex3d(vertex_type &vx))[3] { return vx.m_pos; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  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 {
Shinya Kitaoka 120a6e
  enum Action { NONE, SWAP, COLLAPSE, SPLIT };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
Fill in the 3-array actionSequence with the actions you would want performed
Shinya Kitaoka 120a6e
first on edge e of given mesh. Provided the actions are feasible, they will be
Shinya Kitaoka 120a6e
performed in the returned order.
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  virtual void actionSort(const TriMesh_type &mesh, int e,
Shinya Kitaoka 120a6e
                          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>
Shinya Kitaoka 120a6e
  double m_collapseValue;
Shinya Kitaoka 120a6e
  double m_splitValue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
Sorts actions to achieve near-targetLength edge lengths.
Shinya Kitaoka 120a6e
Split and collapse actions follow the rules:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  
  • Collapse if length < collapseValue <\li>
  • Shinya Kitaoka 120a6e
      
  • Split if length > splitValue <\li>
  • Toshihiro Shimizu 890ddd
    Shinya Kitaoka 120a6e
    \warning The simplification procedure may loop on certain configurations where
    Shinya Kitaoka 120a6e
    collapses and splits alternate repeatedly.
    Shinya Kitaoka 120a6e
    */
    Shinya Kitaoka 120a6e
      DefaultEvaluator(double collapseValue, double splitValue)
    Shinya Kitaoka 120a6e
          : m_collapseValue(collapseValue), m_splitValue(splitValue) {}
    Toshihiro Shimizu 890ddd
    Shinya Kitaoka 120a6e
      void actionSort(
    Shinya Kitaoka 120a6e
          const TriMesh_type &mesh, int e,
    Shinya Kitaoka 120a6e
          typename ActionEvaluator<trimesh_type>::Action *actionSequence);</trimesh_type>
    Toshihiro Shimizu 890ddd
    };
    Toshihiro Shimizu 890ddd
    Shinya Kitaoka 120a6e
    }  // namespace TriMeshStuff
    Toshihiro Shimizu 890ddd
    Toshihiro Shimizu 890ddd
    //==============================================================================================
    Toshihiro Shimizu 890ddd
    Shinya Kitaoka 120a6e
    //! Uses the glu tessellator to build a triangular mesh from a specified tribe
    Shinya Kitaoka 120a6e
    //! of polygons.
    Toshihiro Shimizu 890ddd
    /*!
    Shinya Kitaoka 120a6e
      The algorithm accepts a tribe (that is, a container of containers, where each
    Shinya Kitaoka 120a6e
      container class stores
    Shinya Kitaoka 120a6e
       pointer type objects <\I> to sub-containers) of polygons, and reads out a
    Shinya Kitaoka 120a6e
      sequence of meshes with
    Toshihiro Shimizu 890ddd
      triangular faces.
    Toshihiro Shimizu 890ddd
    Shinya Kitaoka 120a6e
      Each family of the tribe should contain a list of polygons representing a
    Shinya Kitaoka 120a6e
      connected component
    Shinya Kitaoka 120a6e
      to triangulate, where its first element is the external border, and the
    Shinya Kitaoka 120a6e
      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>
    Shinya Kitaoka 120a6e
    void gluTriangulate(ForIt polygonsTribeBegin, ForIt polygonsTribeEnd,
    Shinya Kitaoka 120a6e
                        ContainersReader &meshes_reader);
    Toshihiro Shimizu 890ddd
    Toshihiro Shimizu 890ddd
    template <typename trimesh_type=""></typename>
    Toshihiro Shimizu 890ddd
    void refineMesh(
    Shinya Kitaoka 120a6e
        TriMesh_type &mesh, TriMeshStuff::ActionEvaluator<trimesh_type> &eval,</trimesh_type>
    Shinya Kitaoka 120a6e
        unsigned long maxActions = (std::numeric_limits<unsigned long="">::max)());</unsigned>
    Toshihiro Shimizu 890ddd
    Shinya Kitaoka 120a6e
    }  // namespace tcg
    Toshihiro Shimizu 890ddd
    Shinya Kitaoka 120a6e
    #endif  // TCG_TRIANGULATE_H
    Toshihiro Shimizu 890ddd
    Toshihiro Shimizu 890ddd
    #ifdef INCLUDE_HPP
    Toshihiro Shimizu 890ddd
    #include "hpp/triangulate.hpp"
    Toshihiro Shimizu 890ddd
    #endif