| OpenMesh

TriMeshT.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42
43
44
45 //=============================================================================
46 //
47 // CLASS TriMeshT
48 //
49 //=============================================================================
50
51
52 #ifndef OPENMESH_TRIMESH_HH
53 #define OPENMESH_TRIMESH_HH
54
55
56 //== INCLUDES =================================================================
57
58
59 #include <OpenMesh/Core/System/config.h>
60 #include <OpenMesh/Core/Mesh/PolyMeshT.hh>
61 #include <OpenMesh/Core/Mesh/Tags.hh>
62 #include <vector>
63
64
65 //== NAMESPACES ===============================================================
66
67
68 namespace OpenMesh {
69
70
71 //== CLASS DEFINITION =========================================================
72
73
90 template <class Kernel>
91 class TriMeshT : public PolyMeshT<Kernel>
92 {
93
94 public:
95
96
97 // self
98 typedef TriMeshT<Kernel> This;
99 typedef PolyMeshT<Kernel> PolyMesh;
100
102 static constexpr bool is_polymesh() { return false; }
104 static constexpr bool is_trimesh() { return true; }
105 using ConnectivityTag = TriConnectivityTag;
106 enum { IsPolyMesh = 0 };
107 enum { IsTriMesh = 1 };
109
110 //--- items ---
111
112 typedef typename PolyMesh::Scalar Scalar;
113 typedef typename PolyMesh::Point Point;
114 typedef typename PolyMesh::Normal Normal;
115 typedef typename PolyMesh::Color Color;
116 typedef typename PolyMesh::TexCoord1D TexCoord1D;
117 typedef typename PolyMesh::TexCoord2D TexCoord2D;
118 typedef typename PolyMesh::TexCoord3D TexCoord3D;
119 typedef typename PolyMesh::Vertex Vertex;
120 typedef typename PolyMesh::Halfedge Halfedge;
121 typedef typename PolyMesh::Edge Edge;
122 typedef typename PolyMesh::Face Face;
123
124
125 //--- handles ---
126
127 typedef typename PolyMesh::VertexHandle VertexHandle;
128 typedef typename PolyMesh::HalfedgeHandle HalfedgeHandle;
129 typedef typename PolyMesh::EdgeHandle EdgeHandle;
130 typedef typename PolyMesh::FaceHandle FaceHandle;
131
132
133 //--- iterators ---
134
135 typedef typename PolyMesh::VertexIter VertexIter;
136 typedef typename PolyMesh::ConstVertexIter ConstVertexIter;
137 typedef typename PolyMesh::EdgeIter EdgeIter;
138 typedef typename PolyMesh::ConstEdgeIter ConstEdgeIter;
139 typedef typename PolyMesh::FaceIter FaceIter;
140 typedef typename PolyMesh::ConstFaceIter ConstFaceIter;
141
142
143
144 //--- circulators ---
145
146 typedef typename PolyMesh::VertexVertexIter VertexVertexIter;
147 typedef typename PolyMesh::VertexOHalfedgeIter VertexOHalfedgeIter;
148 typedef typename PolyMesh::VertexIHalfedgeIter VertexIHalfedgeIter;
149 typedef typename PolyMesh::VertexEdgeIter VertexEdgeIter;
150 typedef typename PolyMesh::VertexFaceIter VertexFaceIter;
151 typedef typename PolyMesh::FaceVertexIter FaceVertexIter;
152 typedef typename PolyMesh::FaceHalfedgeIter FaceHalfedgeIter;
153 typedef typename PolyMesh::FaceEdgeIter FaceEdgeIter;
154 typedef typename PolyMesh::FaceFaceIter FaceFaceIter;
155 typedef typename PolyMesh::ConstVertexVertexIter ConstVertexVertexIter;
156 typedef typename PolyMesh::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter;
157 typedef typename PolyMesh::ConstVertexIHalfedgeIter ConstVertexIHalfedgeIter;
158 typedef typename PolyMesh::ConstVertexEdgeIter ConstVertexEdgeIter;
159 typedef typename PolyMesh::ConstVertexFaceIter ConstVertexFaceIter;
160 typedef typename PolyMesh::ConstFaceVertexIter ConstFaceVertexIter;
161 typedef typename PolyMesh::ConstFaceHalfedgeIter ConstFaceHalfedgeIter;
162 typedef typename PolyMesh::ConstFaceEdgeIter ConstFaceEdgeIter;
163 typedef typename PolyMesh::ConstFaceFaceIter ConstFaceFaceIter;
164
165 // --- constructor/destructor
166
168 TriMeshT() : PolyMesh() {}
169 explicit TriMeshT(PolyMesh rhs) : PolyMesh((rhs.triangulate(), rhs))
170 {
171 }
172
174 virtual ~TriMeshT() {}
175
176 //--- halfedge collapse / vertex split ---
177
218 inline HalfedgeHandle vertex_split(Point _v0_point, VertexHandle _v1,
219 VertexHandle _vl, VertexHandle _vr)
220 { return PolyMesh::vertex_split(this->add_vertex(_v0_point), _v1, _vl, _vr); }
221
262 inline HalfedgeHandle vertex_split(VertexHandle _v0, VertexHandle _v1,
263 VertexHandle _vl, VertexHandle _vr)
264 { return PolyMesh::vertex_split(_v0, _v1, _vl, _vr); }
265
275 inline SmartVertexHandle split(EdgeHandle _eh, const Point& _p)
276 {
277 //Do not call PolyMeshT function below as this does the wrong operation
278 const SmartVertexHandle vh = this->add_vertex(_p); Kernel::split(_eh, vh); return vh;
279 }
280
289 inline SmartVertexHandle split_copy(EdgeHandle _eh, const Point& _p)
290 {
291 //Do not call PolyMeshT function below as this does the wrong operation
292 const SmartVertexHandle vh = this->add_vertex(_p); Kernel::split_copy(_eh, vh); return vh;
293 }
294
302 inline void split(EdgeHandle _eh, VertexHandle _vh)
303 {
304 //Do not call PolyMeshT function below as this does the wrong operation
305 Kernel::split(_eh, _vh);
306 }
307
315 inline void split_copy(EdgeHandle _eh, VertexHandle _vh)
316 {
317 //Do not call PolyMeshT function below as this does the wrong operation
318 Kernel::split_copy(_eh, _vh);
319 }
320
330 inline SmartVertexHandle split(FaceHandle _fh, const Point& _p)
331 { const SmartVertexHandle vh = this->add_vertex(_p); PolyMesh::split(_fh, vh); return vh; }
332
342 inline SmartVertexHandle split_copy(FaceHandle _fh, const Point& _p)
343 { const SmartVertexHandle vh = this->add_vertex(_p); PolyMesh::split_copy(_fh, vh); return vh; }
344
345
350 inline void split(FaceHandle _fh)
351 {
352 // Collect halfedges of face
353 HalfedgeHandle he0 = this->halfedge_handle(_fh);
354 HalfedgeHandle he1 = this->next_halfedge_handle(he0);
355 HalfedgeHandle he2 = this->next_halfedge_handle(he1);
356
357 EdgeHandle eh0 = this->edge_handle(he0);
358 EdgeHandle eh1 = this->edge_handle(he1);
359 EdgeHandle eh2 = this->edge_handle(he2);
360
361 // Collect points of face
362 VertexHandle p0 = this->to_vertex_handle(he0);
363 VertexHandle p1 = this->to_vertex_handle(he1);
364 VertexHandle p2 = this->to_vertex_handle(he2);
365
366 // Calculate midpoint coordinates
367 const Point new0 = (this->point(p0) + this->point(p2)) * static_cast<typename vector_traits<Point>::value_type >(0.5);
368 const Point new1 = (this->point(p0) + this->point(p1)) * static_cast<typename vector_traits<Point>::value_type >(0.5);
369 const Point new2 = (this->point(p1) + this->point(p2)) * static_cast<typename vector_traits<Point>::value_type >(0.5);
370
371 // Add vertices at midpoint coordinates
372 VertexHandle v0 = this->add_vertex(new0);
373 VertexHandle v1 = this->add_vertex(new1);
374 VertexHandle v2 = this->add_vertex(new2);
375
376 const bool split0 = !this->is_boundary(eh0);
377 const bool split1 = !this->is_boundary(eh1);
378 const bool split2 = !this->is_boundary(eh2);
379
380 // delete original face
381 this->delete_face(_fh);
382
383 // split boundary edges of deleted face ( if not boundary )
384 if ( split0 ) {
385 this->split(eh0,v0);
386 }
387
388 if ( split1 ) {
389 this->split(eh1,v1);
390 }
391
392 if ( split2 ) {
393 this->split(eh2,v2);
394 }
395
396 // Retriangulate
397 this->add_face(v0 , p0, v1);
398 this->add_face(p2, v0 , v2);
399 this->add_face(v2,v1,p1);
400 this->add_face(v2 , v0, v1);
401 }
402
410 inline void split(FaceHandle _fh, VertexHandle _vh)
411 { PolyMesh::split(_fh, _vh); }
412
420 inline void split_copy(FaceHandle _fh, VertexHandle _vh)
421 { PolyMesh::split_copy(_fh, _vh); }
422
427 Scalar calc_face_area(FaceHandle _fh) const
428 {
429 const HalfedgeHandle heh = this->halfedge_handle(_fh);
430 return this->calc_sector_area(heh);
431 }
432
436
438 Normal calc_face_normal(FaceHandle _fh) const;
439
441 };
442
443
444 //=============================================================================
445 } // namespace OpenMesh
446 //=============================================================================
447 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_TRIMESH_C)
448 #define OPENMESH_TRIMESH_TEMPLATES
449 #include "TriMeshT_impl.hh"
450 #endif
451 //=============================================================================
452 #endif // OPENMESH_TRIMESH_HH defined
453 //=============================================================================
OpenMesh::TriMeshT::split
void split(FaceHandle _fh, VertexHandle _vh)
Face split (= 1-to-3 split, calls corresponding PolyMeshT function).
Definition: TriMeshT.hh:410
OpenMesh::TriConnectivityTag
Connectivity tag indicating that the tagged mesh has triangle connectivity.
Definition: Tags.hh:49
OpenMesh::PolyMeshT::Face
Kernel::Face Face
Face type.
Definition: PolyMeshT.hh:130
OpenMesh::PolyMeshT::Scalar
Kernel::Scalar Scalar
Scalar type.
Definition: PolyMeshT.hh:110
OpenMesh::TriMeshT::~TriMeshT
virtual ~TriMeshT()
Destructor.
Definition: TriMeshT.hh:174
OpenMesh::PolyMeshT::ConstVertexEdgeIter
Kernel::ConstVertexEdgeIter ConstVertexEdgeIter
Circulator.
Definition: PolyMeshT.hh:175
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::PolyMeshT::Halfedge
Kernel::Halfedge Halfedge
Halfedge type.
Definition: PolyMeshT.hh:126
OpenMesh::TriMeshT::calc_face_area
Scalar calc_face_area(FaceHandle _fh) const
Calculates the area of a face.
Definition: TriMeshT.hh:427
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::PolyMeshT::VertexIHalfedgeIter
Kernel::VertexIHalfedgeIter VertexIHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:164
OpenMesh::PolyMeshT::TexCoord2D
Kernel::TexCoord2D TexCoord2D
TexCoord2D type.
Definition: PolyMeshT.hh:120
OpenMesh::PolyMeshT::ConstFaceVertexIter
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
Definition: PolyMeshT.hh:177
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:527
OpenMesh::PolyMeshT::split
void split(FaceHandle _fh, const Point &_p)
Face split (= 1-to-n split)
Definition: PolyMeshT.hh:592
OpenMesh::PolyMeshT::VertexOHalfedgeIter
Kernel::VertexOHalfedgeIter VertexOHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:163
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::PolyMeshT::Edge
Kernel::Edge Edge
Edge type.
Definition: PolyMeshT.hh:128
OpenMesh::PolyMeshT::VertexFaceIter
Kernel::VertexFaceIter VertexFaceIter
Circulator.
Definition: PolyMeshT.hh:166
OpenMesh::vector_traits
Helper class providing information about a vector type.
Definition: vector_traits.hh:88
OpenMesh::PolyMeshT::ConstFaceHalfedgeIter
Kernel::ConstFaceHalfedgeIter ConstFaceHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:178
OpenMesh::PolyMeshT::TexCoord1D
Kernel::TexCoord1D TexCoord1D
TexCoord1D type.
Definition: PolyMeshT.hh:118
OpenMesh::PolyMeshT::VertexVertexIter
Kernel::VertexVertexIter VertexVertexIter
Circulator.
Definition: PolyMeshT.hh:162
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::PolyMeshT::ConstVertexOHalfedgeIter
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:173
OpenMesh::PolyMeshT::Vertex
Kernel::Vertex Vertex
Vertex type.
Definition: PolyMeshT.hh:124
OpenMesh::PolyMeshT::Normal
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:114
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::ConstFaceEdgeIter
Kernel::ConstFaceEdgeIter ConstFaceEdgeIter
Circulator.
Definition: PolyMeshT.hh:179
OpenMesh::PolyConnectivityTag
Connectivity tag indicating that the tagged mesh has polygon connectivity.
Definition: Tags.hh:47
OpenMesh::PolyMeshT::FaceHalfedgeIter
Kernel::FaceHalfedgeIter FaceHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:168
OpenMesh::PolyMeshT::FaceVertexIter
Kernel::FaceVertexIter FaceVertexIter
Circulator.
Definition: PolyMeshT.hh:167
OpenMesh::PolyMeshT::ConstVertexVertexIter
Kernel::ConstVertexVertexIter ConstVertexVertexIter
Circulator.
Definition: PolyMeshT.hh:172
OpenMesh::PolyMeshT::add_vertex
SmartVertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:235
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_copy
SmartVertexHandle split_copy(FaceHandle _fh, const Point &_p)
Face split (= 1-to-3 split, calls corresponding PolyMeshT function).
Definition: TriMeshT.hh:342
OpenMesh::PolyMeshT::FaceEdgeIter
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
Definition: PolyMeshT.hh:169
OpenMesh::TriMeshT::split_copy
void split_copy(EdgeHandle _eh, VertexHandle _vh)
Edge split (= 2-to-4 split)
Definition: TriMeshT.hh:315
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::SmartVertexHandle
Smart version of VertexHandle contains a pointer to the corresponding mesh and allows easier access t...
Definition: SmartHandles.hh:84
OpenMesh::TriMeshT::is_trimesh
static constexpr bool is_trimesh()
Determine whether this is a PolyMeshT or TriMeshT (This function does not check the per face vertex c...
Definition: TriMeshT.hh:104
OpenMesh::PolyMeshT::FaceFaceIter
Kernel::FaceFaceIter FaceFaceIter
Circulator.
Definition: PolyMeshT.hh:170
OpenMesh::PolyMeshT::ConstFaceFaceIter
Kernel::ConstFaceFaceIter ConstFaceFaceIter
Circulator.
Definition: PolyMeshT.hh:180
OpenMesh::TriMeshT::split
SmartVertexHandle split(EdgeHandle _eh, const Point &_p)
Edge split (= 2-to-4 split)
Definition: TriMeshT.hh:275
OpenMesh::TriMeshT::split
void split(EdgeHandle _eh, VertexHandle _vh)
Edge split (= 2-to-4 split)
Definition: TriMeshT.hh:302
OpenMesh::PolyMeshT::VertexEdgeIter
Kernel::VertexEdgeIter VertexEdgeIter
Circulator.
Definition: PolyMeshT.hh:165
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
OpenMesh::PolyMeshT::ConstVertexIHalfedgeIter
Kernel::ConstVertexIHalfedgeIter ConstVertexIHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:174
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136
OpenMesh::TriMeshT::TriMeshT
TriMeshT()
Default constructor.
Definition: TriMeshT.hh:168
OpenMesh::TriMeshT::split_copy
SmartVertexHandle split_copy(EdgeHandle _eh, const Point &_p)
Edge split (= 2-to-4 split)
Definition: TriMeshT.hh:289
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
Base type for a triangle mesh.
Definition: TriMeshT.hh:91
OpenMesh::PolyMeshT
Base type for a polygonal mesh.
Definition: PolyMeshT.hh:90
OpenMesh::PolyMeshT::Color
Kernel::Color Color
Color type.
Definition: PolyMeshT.hh:116