1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
// ======================================================================
//
// Copyright (c) 2005-2011 GeometryFactory (France). All Rights Reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s): Le-Jeng Shiue <Andy.Shiue@gmail.com>
//
// ======================================================================
#ifndef CGAL_POLYHEDRON_DECORATOR_H_01282002
#define CGAL_POLYHEDRON_DECORATOR_H_01282002
#include <CGAL/assertions.h>
namespace CGAL {
template <class Poly>
class Polyhedron_decorator_3 {
typedef Poly Polyhedron;
typedef typename Polyhedron::Traits Traits;
typedef typename Traits::Kernel Kernel;
typedef typename Polyhedron::Halfedge_data_structure HDS;
typedef typename Polyhedron::Vertex Vertex;
typedef typename Polyhedron::Halfedge Halfedge;
typedef typename Polyhedron::Facet Facet;
typedef typename Polyhedron::Vertex_handle Vertex_handle;
typedef typename Polyhedron::Halfedge_handle Halfedge_handle;
typedef typename Polyhedron::Facet_handle Facet_handle;
typedef typename Polyhedron::Vertex_iterator Vertex_iterator;
typedef typename Polyhedron::Halfedge_iterator Halfedge_iterator;
typedef typename Polyhedron::Edge_iterator Edge_iterator;
typedef typename Polyhedron::Facet_iterator Facet_iterator;
typedef typename Polyhedron::Halfedge_around_facet_circulator
Halfedge_around_facet_circulator;
typedef typename Polyhedron::Halfedge_around_vertex_circulator
Halfedge_around_vertex_circulator;
typedef typename Polyhedron::Point_3 Point;
typedef typename Kernel::FT FT;
public:
/** Insert a new vertex into an helfedge h (a--b)
Precondition:
h
a <-----> b
-h
h is the halfedge connecting vertex a to b
-h is the oppsite halfedge connecting b to a
Postcondition:
h r
a <-----> V <-----> b
-h -r
V is the return vertex whose geometry is UNDEFINED.
-r is the return halfedge that is pointing to V
*/
static Vertex* insert_vertex(Polyhedron& p, Halfedge* h) {
return insert_vertex(p, Halfedge_handle(h)).ptr();
}
//
static Vertex* insert_vertex(Polyhedron& p, Vertex* a, Vertex* b) {
return insert_vertex(p, Vertex_handle(a), Vertex_handle(b)).ptr();
}
//
static Vertex_handle insert_vertex(Polyhedron& p, Halfedge_handle h) {
return insert_vertex_return_edge(p, h)->vertex();
}
//
static Vertex_handle insert_vertex(Polyhedron& p,
Vertex_handle a, Vertex_handle b) {
return insert_vertex_return_edge(p, a, b)->vertex();
}
//
static Halfedge* insert_vertex_return_edge(Polyhedron& p, Halfedge* h) {
return insert_vertex_return_edge(p, Halfedge_handle(h)).ptr();
}
//
static Halfedge* insert_vertex_return_edge(Polyhedron& p,
Vertex* a, Vertex* b) {
return insert_vertex_return_edge(p, Vertex_handle(a),
Vertex_handle(b)).ptr();
}
//
static inline Halfedge_handle insert_vertex_return_edge(Polyhedron& p,
Halfedge_handle h);
//
static inline Halfedge_handle insert_vertex_return_edge(Polyhedron& p,
Vertex_handle a,
Vertex_handle b);
/** Insert a new edge (two halfedges) between the two vertices
Precondition:
vertex a and b are in the SAME facet and do NOT connect to each other
Postcondition:
H
a <----------> b
H is the return halfedge connecting vertex a to b.
*/
static Halfedge* insert_edge(Polyhedron& /*p*/, Vertex* a, Vertex* b) {
return insert_edge(Vertex_handle(a), Vertex_handle(b)).ptr();
}
//
static Halfedge_handle insert_edge(Polyhedron& p,
Halfedge_handle a,
Halfedge_handle b) {
return p.split_facet(a, b);
}
//
static inline Halfedge_handle insert_edge(Polyhedron& p,
Vertex_handle a,
Vertex_handle b);
/** Set the vertex of index vidx to the new position to the new
position (x,y,z)
Precondition:
0 <= vidx < p.size_of_vertices()
Postcondition:
If failed procondition, do nothing.
The new vertex of index vidx has the new position (x,y,z)
*/
static void set_vertex_position(Polyhedron& p, int vidx, FT x, FT y, FT z) {
if (vidx >= 0 && vidx < p.size_of_vertices()) {
Vertex_iterator vitr = p.vertices_begin();
for (int i = 0; i < vidx; i++) ++vitr;
vitr->point() = Point(x,y,z);
}
}
};
// ======================================================================
//
template <class Poly>
typename Polyhedron_decorator_3<Poly>::Halfedge_handle
Polyhedron_decorator_3<Poly>::insert_vertex_return_edge(Polyhedron& p,
Halfedge_handle h) {
Halfedge_handle hopp = h->opposite();
Halfedge_handle r = p.split_vertex(hopp->prev(), h);
if (!h->is_border())
((typename HDS::Face_handle) h->facet())->set_halfedge(r);
if (!hopp->is_border())
((typename HDS::Face_handle) hopp->facet())->set_halfedge(hopp);
return r->opposite();
}
// ======================================================================
//
template <class Poly>
typename Polyhedron_decorator_3<Poly>::Halfedge_handle
Polyhedron_decorator_3<Poly>::insert_vertex_return_edge(Polyhedron& p,
Vertex_handle a,
Vertex_handle b) {
Halfedge_around_vertex_circulator a_cir_begin = a->vertex_begin();
Halfedge_around_vertex_circulator a_cir = a_cir_begin;
do {
if (a_cir->opposite()->vertex() == b)
return insert_vertex_return_edge(p, a_cir->opposite());
} while (++a_cir != a_cir_begin);
CGAL_precondition_msg(0, "vertex a and b must be incident to each other");
return Halfedge_handle(NULL);
}
// ======================================================================
//
template <class Poly>
typename Polyhedron_decorator_3<Poly>::Halfedge_handle
Polyhedron_decorator_3<Poly>::insert_edge(Polyhedron& p,
Vertex_handle a,
Vertex_handle b) {
Halfedge_around_vertex_circulator a_cir_begin = a->vertex_begin();
Halfedge_around_vertex_circulator a_cir = a_cir_begin;
Halfedge_around_vertex_circulator b_cir_begin = b->vertex_begin();
Halfedge_around_vertex_circulator b_cir = b_cir_begin;
do {
do {
if (a_cir->facet() == b_cir->facet())
return p.split_facet(a_cir, b_cir);
} while (++b_cir != b_cir_begin);
} while (++a_cir != a_cir_begin);
CGAL_precondition_msg(0, "vertex a and b must share the same face");
return Halfedge_handle(NULL);
}
} //namespace CGAL
#endif //CGAL_POLYHEDRON_DECORATOR_H_01282002
|