Loading...
Searching...
No Matches
TriMeshT.hh
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2022, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= */
//=============================================================================
//
// CLASS TriMeshT
//
//=============================================================================
#ifndef OPENMESH_TRIMESH_HH
#define OPENMESH_TRIMESH_HH
//== INCLUDES =================================================================
#include <OpenMesh/Core/System/config.h>
#include <OpenMesh/Core/Mesh/PolyMeshT.hh>
#include <OpenMesh/Core/Mesh/Tags.hh>
#include <vector>
//== NAMESPACES ===============================================================
namespace OpenMesh {
//== CLASS DEFINITION =========================================================
template <class Kernel>
class TriMeshT : public PolyMeshT<Kernel>
{
public:
// self
typedef TriMeshT<Kernel> This;
typedef PolyMeshT<Kernel> PolyMesh;
static constexpr bool is_polymesh() { return false; }
static constexpr bool is_trimesh() { return true; }
using ConnectivityTag = TriConnectivityTag;
enum { IsPolyMesh = 0 };
enum { IsTriMesh = 1 };
//--- items ---
typedef typename PolyMesh::Scalar Scalar;
typedef typename PolyMesh::Point Point;
typedef typename PolyMesh::Normal Normal;
typedef typename PolyMesh::Color Color;
typedef typename PolyMesh::TexCoord1D TexCoord1D;
typedef typename PolyMesh::TexCoord2D TexCoord2D;
typedef typename PolyMesh::TexCoord3D TexCoord3D;
typedef typename PolyMesh::Vertex Vertex;
typedef typename PolyMesh::Halfedge Halfedge;
typedef typename PolyMesh::Edge Edge;
typedef typename PolyMesh::Face Face;
//--- handles ---
typedef typename PolyMesh::VertexHandle VertexHandle;
typedef typename PolyMesh::HalfedgeHandle HalfedgeHandle;
typedef typename PolyMesh::EdgeHandle EdgeHandle;
typedef typename PolyMesh::FaceHandle FaceHandle;
//--- iterators ---
typedef typename PolyMesh::VertexIter VertexIter;
typedef typename PolyMesh::ConstVertexIter ConstVertexIter;
typedef typename PolyMesh::EdgeIter EdgeIter;
typedef typename PolyMesh::ConstEdgeIter ConstEdgeIter;
typedef typename PolyMesh::FaceIter FaceIter;
typedef typename PolyMesh::ConstFaceIter ConstFaceIter;
//--- circulators ---
typedef typename PolyMesh::VertexVertexIter VertexVertexIter;
typedef typename PolyMesh::VertexOHalfedgeIter VertexOHalfedgeIter;
typedef typename PolyMesh::VertexIHalfedgeIter VertexIHalfedgeIter;
typedef typename PolyMesh::VertexEdgeIter VertexEdgeIter;
typedef typename PolyMesh::VertexFaceIter VertexFaceIter;
typedef typename PolyMesh::FaceVertexIter FaceVertexIter;
typedef typename PolyMesh::FaceHalfedgeIter FaceHalfedgeIter;
typedef typename PolyMesh::FaceEdgeIter FaceEdgeIter;
typedef typename PolyMesh::FaceFaceIter FaceFaceIter;
typedef typename PolyMesh::ConstVertexVertexIter ConstVertexVertexIter;
typedef typename PolyMesh::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter;
typedef typename PolyMesh::ConstVertexIHalfedgeIter ConstVertexIHalfedgeIter;
typedef typename PolyMesh::ConstVertexEdgeIter ConstVertexEdgeIter;
typedef typename PolyMesh::ConstVertexFaceIter ConstVertexFaceIter;
typedef typename PolyMesh::ConstFaceVertexIter ConstFaceVertexIter;
typedef typename PolyMesh::ConstFaceHalfedgeIter ConstFaceHalfedgeIter;
typedef typename PolyMesh::ConstFaceEdgeIter ConstFaceEdgeIter;
typedef typename PolyMesh::ConstFaceFaceIter ConstFaceFaceIter;
// --- constructor/destructor
TriMeshT() : PolyMesh() {}
explicit TriMeshT(PolyMesh rhs) : PolyMesh((rhs.triangulate(), rhs))
{
}
virtual ~TriMeshT() {}
//--- halfedge collapse / vertex split ---
inline HalfedgeHandle vertex_split(Point _v0_point, VertexHandle _v1,
VertexHandle _vl, VertexHandle _vr)
{ return PolyMesh::vertex_split(this->add_vertex(_v0_point), _v1, _vl, _vr); }
inline HalfedgeHandle vertex_split(VertexHandle _v0, VertexHandle _v1,
VertexHandle _vl, VertexHandle _vr)
{ return PolyMesh::vertex_split(_v0, _v1, _vl, _vr); }
inline SmartVertexHandle split(EdgeHandle _eh, const Point& _p)
{
//Do not call PolyMeshT function below as this does the wrong operation
const SmartVertexHandle vh = this->add_vertex(_p); Kernel::split(_eh, vh); return vh;
}
inline SmartVertexHandle split_copy(EdgeHandle _eh, const Point& _p)
{
//Do not call PolyMeshT function below as this does the wrong operation
const SmartVertexHandle vh = this->add_vertex(_p); Kernel::split_copy(_eh, vh); return vh;
}
inline void split(EdgeHandle _eh, VertexHandle _vh)
{
//Do not call PolyMeshT function below as this does the wrong operation
Kernel::split(_eh, _vh);
}
inline void split_copy(EdgeHandle _eh, VertexHandle _vh)
{
//Do not call PolyMeshT function below as this does the wrong operation
Kernel::split_copy(_eh, _vh);
}
inline SmartVertexHandle split(FaceHandle _fh, const Point& _p)
{ const SmartVertexHandle vh = this->add_vertex(_p); PolyMesh::split(_fh, vh); return vh; }
inline SmartVertexHandle split_copy(FaceHandle _fh, const Point& _p)
{ const SmartVertexHandle vh = this->add_vertex(_p); PolyMesh::split_copy(_fh, vh); return vh; }
inline void split(FaceHandle _fh)
{
// Collect halfedges of face
HalfedgeHandle he0 = this->halfedge_handle(_fh);
HalfedgeHandle he1 = this->next_halfedge_handle(he0);
HalfedgeHandle he2 = this->next_halfedge_handle(he1);
EdgeHandle eh0 = this->edge_handle(he0);
EdgeHandle eh1 = this->edge_handle(he1);
EdgeHandle eh2 = this->edge_handle(he2);
// Collect points of face
VertexHandle p0 = this->to_vertex_handle(he0);
VertexHandle p1 = this->to_vertex_handle(he1);
VertexHandle p2 = this->to_vertex_handle(he2);
// Calculate midpoint coordinates
const Point new0 = (this->point(p0) + this->point(p2)) * static_cast<typename vector_traits<Point>::value_type >(0.5);
const Point new1 = (this->point(p0) + this->point(p1)) * static_cast<typename vector_traits<Point>::value_type >(0.5);
const Point new2 = (this->point(p1) + this->point(p2)) * static_cast<typename vector_traits<Point>::value_type >(0.5);
// Add vertices at midpoint coordinates
VertexHandle v0 = this->add_vertex(new0);
VertexHandle v1 = this->add_vertex(new1);
VertexHandle v2 = this->add_vertex(new2);
const bool split0 = !this->is_boundary(eh0);
const bool split1 = !this->is_boundary(eh1);
const bool split2 = !this->is_boundary(eh2);
// delete original face
this->delete_face(_fh);
// split boundary edges of deleted face ( if not boundary )
if ( split0 ) {
this->split(eh0,v0);
}
if ( split1 ) {
this->split(eh1,v1);
}
if ( split2 ) {
this->split(eh2,v2);
}
// Retriangulate
this->add_face(v0 , p0, v1);
this->add_face(p2, v0 , v2);
this->add_face(v2,v1,p1);
this->add_face(v2 , v0, v1);
}
inline void split(FaceHandle _fh, VertexHandle _vh)
{ PolyMesh::split(_fh, _vh); }
inline void split_copy(FaceHandle _fh, VertexHandle _vh)
{ PolyMesh::split_copy(_fh, _vh); }
Scalar calc_face_area(FaceHandle _fh) const
{
const HalfedgeHandle heh = this->halfedge_handle(_fh);
return this->calc_sector_area(heh);
}
Normal calc_face_normal(FaceHandle _fh) const;
};
//=============================================================================
} // namespace OpenMesh
//=============================================================================
#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_TRIMESH_C)
#define OPENMESH_TRIMESH_TEMPLATES
#include "TriMeshT_impl.hh"
#endif
//=============================================================================
#endif // OPENMESH_TRIMESH_HH defined
//=============================================================================
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:59
OpenMesh::FaceHandle
Handle for a face entity.
Definition Handles.hh:142
OpenMesh::PolyMesh_ArrayKernelT
Polygonal mesh based on the ArrayKernel.
Definition PolyMesh_ArrayKernelT.hh:96
OpenMesh::PolyMeshT
Base type for a polygonal mesh.
Definition PolyMeshT.hh:91
OpenMesh::PolyMeshT::Vertex
Kernel::Vertex Vertex
Vertex type.
Definition PolyMeshT.hh:124
OpenMesh::PolyMeshT::FaceEdgeIter
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
Definition PolyMeshT.hh:169
OpenMesh::PolyMeshT::ConstFaceIter
Kernel::ConstFaceIter ConstFaceIter
Scalar type.
Definition PolyMeshT.hh:151
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition PolyMeshT.hh:136
OpenMesh::PolyMeshT::Scalar
Kernel::Scalar Scalar
Scalar type.
Definition PolyMeshT.hh:110
OpenMesh::PolyMeshT::ConstVertexVertexIter
Kernel::ConstVertexVertexIter ConstVertexVertexIter
Circulator.
Definition PolyMeshT.hh:172
OpenMesh::PolyMeshT::ConstFaceHalfedgeIter
Kernel::ConstFaceHalfedgeIter ConstFaceHalfedgeIter
Circulator.
Definition PolyMeshT.hh:178
OpenMesh::PolyMeshT::EdgeHandle
Kernel::EdgeHandle EdgeHandle
Scalar type.
Definition PolyMeshT.hh:138
OpenMesh::PolyMeshT::VertexFaceIter
Kernel::VertexFaceIter VertexFaceIter
Circulator.
Definition PolyMeshT.hh:166
OpenMesh::PolyMeshT::ConstFaceVertexIter
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
Definition PolyMeshT.hh:177
OpenMesh::PolyMeshT::Halfedge
Kernel::Halfedge Halfedge
Halfedge type.
Definition PolyMeshT.hh:126
OpenMesh::PolyMeshT::FaceIter
Kernel::FaceIter FaceIter
Scalar type.
Definition PolyMeshT.hh:146
OpenMesh::PolyMeshT::Normal
Kernel::Normal Normal
Normal type.
Definition PolyMeshT.hh:114
OpenMesh::PolyMeshT::FaceVertexIter
Kernel::FaceVertexIter FaceVertexIter
Circulator.
Definition PolyMeshT.hh:167
OpenMesh::PolyMeshT::VertexIHalfedgeIter
Kernel::VertexIHalfedgeIter VertexIHalfedgeIter
Circulator.
Definition PolyMeshT.hh:164
OpenMesh::PolyMeshT::TexCoord2D
Kernel::TexCoord2D TexCoord2D
TexCoord2D type.
Definition PolyMeshT.hh:120
OpenMesh::PolyMeshT::calc_sector_area
Scalar calc_sector_area(HalfedgeHandle _in_heh) const
calculates the area of the face sector defined by the angle <(_in_heh,next_halfedge(_in_heh)) NOTE: s...
Definition PolyMeshT.hh:537
OpenMesh::PolyMeshT::add_vertex
SmartVertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition PolyMeshT.hh:245
OpenMesh::PolyMeshT::ConstFaceEdgeIter
Kernel::ConstFaceEdgeIter ConstFaceEdgeIter
Circulator.
Definition PolyMeshT.hh:179
OpenMesh::PolyMeshT::TexCoord3D
Kernel::TexCoord3D TexCoord3D
TexCoord3D type.
Definition PolyMeshT.hh:122
OpenMesh::PolyMeshT::ConstVertexFaceIter
Kernel::ConstVertexFaceIter ConstVertexFaceIter
Circulator.
Definition PolyMeshT.hh:176
OpenMesh::PolyMeshT::VertexOHalfedgeIter
Kernel::VertexOHalfedgeIter VertexOHalfedgeIter
Circulator.
Definition PolyMeshT.hh:163
OpenMesh::PolyMeshT::VertexEdgeIter
Kernel::VertexEdgeIter VertexEdgeIter
Circulator.
Definition PolyMeshT.hh:165
OpenMesh::PolyMeshT::Face
Kernel::Face Face
Face type.
Definition PolyMeshT.hh:130
OpenMesh::PolyMeshT::ConstVertexIHalfedgeIter
Kernel::ConstVertexIHalfedgeIter ConstVertexIHalfedgeIter
Circulator.
Definition PolyMeshT.hh:174
OpenMesh::PolyMeshT::FaceFaceIter
Kernel::FaceFaceIter FaceFaceIter
Circulator.
Definition PolyMeshT.hh:170
OpenMesh::PolyMeshT::ConstVertexEdgeIter
Kernel::ConstVertexEdgeIter ConstVertexEdgeIter
Circulator.
Definition PolyMeshT.hh:175
OpenMesh::PolyMeshT::Edge
Kernel::Edge Edge
Edge type.
Definition PolyMeshT.hh:128
OpenMesh::PolyMeshT::FaceHandle
Kernel::FaceHandle FaceHandle
Scalar type.
Definition PolyMeshT.hh:139
OpenMesh::PolyMeshT::HalfedgeHandle
Kernel::HalfedgeHandle HalfedgeHandle
Scalar type.
Definition PolyMeshT.hh:137
OpenMesh::PolyMeshT::EdgeIter
Kernel::EdgeIter EdgeIter
Scalar type.
Definition PolyMeshT.hh:145
OpenMesh::PolyMeshT::ConstEdgeIter
Kernel::ConstEdgeIter ConstEdgeIter
Scalar type.
Definition PolyMeshT.hh:150
OpenMesh::PolyMeshT::ConstVertexIter
Kernel::ConstVertexIter ConstVertexIter
Scalar type.
Definition PolyMeshT.hh:148
OpenMesh::PolyMeshT::ConstVertexOHalfedgeIter
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
Definition PolyMeshT.hh:173
OpenMesh::PolyMeshT::VertexVertexIter
Kernel::VertexVertexIter VertexVertexIter
Circulator.
Definition PolyMeshT.hh:162
OpenMesh::PolyMeshT::FaceHalfedgeIter
Kernel::FaceHalfedgeIter FaceHalfedgeIter
Circulator.
Definition PolyMeshT.hh:168
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition PolyMeshT.hh:112
OpenMesh::PolyMeshT::ConstFaceFaceIter
Kernel::ConstFaceFaceIter ConstFaceFaceIter
Circulator.
Definition PolyMeshT.hh:180
OpenMesh::PolyMeshT::split
void split(FaceHandle _fh, const Point &_p)
Face split (= 1-to-n split)
Definition PolyMeshT.hh:602
OpenMesh::PolyMeshT::Color
Kernel::Color Color
Color type.
Definition PolyMeshT.hh:116
OpenMesh::PolyMeshT::TexCoord1D
Kernel::TexCoord1D TexCoord1D
TexCoord1D type.
Definition PolyMeshT.hh:118
OpenMesh::PolyMeshT::VertexIter
Kernel::VertexIter VertexIter
Scalar type.
Definition PolyMeshT.hh:143
OpenMesh::SmartVertexHandle
Smart version of VertexHandle contains a pointer to the corresponding mesh and allows easier access t...
Definition SmartHandles.hh:110
OpenMesh::TriMeshT
Base type for a triangle mesh.
Definition TriMeshT.hh:92
OpenMesh::TriMeshT::split
void split(EdgeHandle _eh, VertexHandle _vh)
Edge split (= 2-to-4 split)
Definition TriMeshT.hh:302
OpenMesh::TriMeshT::split
void split(FaceHandle _fh)
Face split (= 1-to-4) split, splits edges at midpoints and adds 4 new faces in the interior).
Definition TriMeshT.hh:350
OpenMesh::TriMeshT::TriMeshT
TriMeshT()
Default constructor.
Definition TriMeshT.hh:168
OpenMesh::TriMeshT::split
void split(FaceHandle _fh, VertexHandle _vh)
Face split (= 1-to-3 split, calls corresponding PolyMeshT function).
Definition TriMeshT.hh:410
OpenMesh::TriMeshT::calc_face_normal
Normal calc_face_normal(FaceHandle _fh) const
Calculate normal vector for face _fh (specialized for TriMesh).
Definition TriMeshT_impl.hh:74
OpenMesh::TriMeshT::split
SmartVertexHandle split(EdgeHandle _eh, const Point &_p)
Edge split (= 2-to-4 split)
Definition TriMeshT.hh:275
OpenMesh::TriMeshT::vertex_split
HalfedgeHandle vertex_split(Point _v0_point, VertexHandle _v1, VertexHandle _vl, VertexHandle _vr)
Vertex Split: inverse operation to collapse().
Definition TriMeshT.hh:218
OpenMesh::TriMeshT::is_polymesh
static constexpr bool is_polymesh()
Determine whether this is a PolyMeshT or TriMeshT (This function does not check the per face vertex c...
Definition TriMeshT.hh:103
OpenMesh::TriMeshT::calc_face_area
Scalar calc_face_area(FaceHandle _fh) const
Calculates the area of a face.
Definition TriMeshT.hh:427
OpenMesh::TriMeshT::split
SmartVertexHandle split(FaceHandle _fh, const Point &_p)
Face split (= 1-to-3 split, calls corresponding PolyMeshT function).
Definition TriMeshT.hh:330
OpenMesh::TriMeshT::~TriMeshT
virtual ~TriMeshT()
Destructor.
Definition TriMeshT.hh:174
OpenMesh::TriMeshT::split_copy
void split_copy(FaceHandle _fh, VertexHandle _vh)
Face split (= 1-to-3 split, calls corresponding PolyMeshT function).
Definition TriMeshT.hh:420
OpenMesh::TriMeshT::split_copy
SmartVertexHandle split_copy(FaceHandle _fh, const Point &_p)
Face split (= 1-to-3 split, calls corresponding PolyMeshT function).
Definition TriMeshT.hh:342
OpenMesh::TriMeshT::vertex_split
HalfedgeHandle vertex_split(VertexHandle _v0, VertexHandle _v1, VertexHandle _vl, VertexHandle _vr)
Vertex Split: inverse operation to collapse().
Definition TriMeshT.hh:262
OpenMesh::TriMeshT::split_copy
void split_copy(EdgeHandle _eh, VertexHandle _vh)
Edge split (= 2-to-4 split)
Definition TriMeshT.hh:315
OpenMesh::TriMeshT::split_copy
SmartVertexHandle split_copy(EdgeHandle _eh, const Point &_p)
Edge split (= 2-to-4 split)
Definition TriMeshT.hh:289
OpenMesh::vector_traits::value_type
T::value_type value_type
Type of the scalar value.
Definition vector_traits.hh:94