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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
// Copyright (c) 2004 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/Mesh_2/include/CGAL/Triangulation_conformer_2.h $
// $Id: include/CGAL/Triangulation_conformer_2.h 08b27d3db14 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Laurent RINEAU
#ifndef CGAL_TRIANGULATION_CONFORMER_2_H
#define CGAL_TRIANGULATION_CONFORMER_2_H
#include <CGAL/license/Mesh_2.h>
#include <CGAL/disable_warnings.h>
#include <CGAL/Mesh_2/Refine_edges_with_clusters.h>
namespace CGAL {
template <typename Tr>
class Triangulation_conformer_2
{
typedef typename Tr::Finite_edges_iterator Finite_edges_iterator;
typedef typename Tr::Vertex_handle Vertex_handle;
typedef Mesh_2::Refine_edges_with_clusters<Tr,
Mesh_2::Is_locally_conforming_Gabriel<Tr> > Edges_level_Gabriel;
typedef Mesh_2::Refine_edges_with_clusters<Tr,
Mesh_2::Is_locally_conforming_Delaunay<Tr> > Edges_level_Delaunay;
protected:
/** \name INITIALIZED */
enum Initialization {
NONE, /**< `this` is not initialized. */
CLUSTERS, /**< `this` clusters are initialized. */
DELAUNAY, /**< `this` has been \e Delaunay-initialized. */
GABRIEL /**< `this` has been \e Gabriel-initialized. */
};
// --- PROTECTED DATA ---
Initialization initialized;
Tr& tr;
Null_mesher_level null_level;
Null_mesh_visitor null_visitor;
Mesh_2::Clusters<Tr> clusters;
Edges_level_Gabriel edges_level_Gabriel;
Edges_level_Delaunay edges_level_Delaunay;
public:
/** \name CONSTRUCTORS */
Triangulation_conformer_2(Tr& tr_)
: initialized(NONE),
tr(tr_),
null_level(), null_visitor(),
clusters(tr_),
edges_level_Gabriel(tr, clusters, null_level),
edges_level_Delaunay(tr, clusters, null_level)
{
}
private:
/** \name CHECKING METHODS*/
template <typename Is_locally_conforming>
bool is_conforming_XXX(Is_locally_conforming is_locally_conforming) const
{
for(Finite_edges_iterator ei = tr.finite_edges_begin();
ei != tr.finite_edges_end();
++ei)
if(ei->first->is_constrained(ei->second) &&
!is_locally_conforming(tr, ei->first, ei->second) )
return false;
return true;
}
public: /** \name ACCESS TO CLUSTERS */
typedef typename Mesh_2::Clusters<Tr>::Cluster_vertices_iterator
Cluster_vertices_iterator;
typedef typename Mesh_2::Clusters<Tr>::Vertices_in_cluster_iterator
Vertices_in_cluster_iterator;
public:
/** \name ACCESS FUNCTIONS */
/** Access to the private initialized member data. */
//@{
void set_initialized(Initialization init) { initialized = init; }
Initialization get_initialized() const { return initialized; }
//@}
int number_of_constrained_edges()
{
int nedges = 0;
for(typename Tr::Finite_edges_iterator eit = tr.finite_edges_begin();
eit != tr.finite_edges_end();
++eit)
if(eit->first->is_constrained(eit->second))
++nedges;
return nedges;
}
int number_of_clusters_vertices() const
{
return clusters.size();
}
Cluster_vertices_iterator clusters_vertices_begin() const
{
return clusters.clusters_vertices_begin();
}
Cluster_vertices_iterator clusters_vertices_end() const
{
return clusters.clusters_vertices_end();
}
unsigned int number_of_clusters_at_vertex(const Vertex_handle& vh)
{
return clusters.number_of_clusters_at_vertex(vh);
}
#if 0
// returns the sequence of vertices belonging to the n-th cluster of vh
std::pair<Vertices_in_cluster_iterator, Vertices_in_cluster_iterator>
vertices_in_cluster_sequence(const Vertex_handle& vh,
const unsigned int n)
{
return clusters.vertices_in_cluster_sequence();
}
#endif
public:
/** \name CHECKING METHODS */
bool is_conforming_Delaunay()
{
typedef typename Mesh_2::Is_locally_conforming_Delaunay<Tr> Is_loc_conf;
return is_conforming_XXX(Is_loc_conf());
}
bool is_conforming_Gabriel()
{
typedef typename Mesh_2::Is_locally_conforming_Gabriel<Tr> Is_loc_conf;
return is_conforming_XXX(Is_loc_conf());
}
/** \name CONFORMING FUNCTIONS */
void make_conforming_Delaunay()
{
if(initialized!=DELAUNAY) init_Delaunay();
edges_level_Delaunay.refine(null_visitor);
}
void make_conforming_Gabriel()
{
if(initialized!=GABRIEL) init_Gabriel();
edges_level_Gabriel.refine(null_visitor);
}
/** \name STEP BY STEP FUNCTIONS */
// Note: step by step functions are not efficient at all!
private:
void init_clusters()
{
if(initialized == NONE)
clusters.create_clusters();
initialized = CLUSTERS;
}
public:
/**
Initializes the data structures
(The call of this function is REQUIRED before any step by step
operation).
*/
//@{
void init_Delaunay()
{
init_clusters();
initialized = DELAUNAY;
edges_level_Delaunay.scan_triangulation();
}
void init_Gabriel()
{
init_clusters();
initialized = GABRIEL;
edges_level_Gabriel.scan_triangulation();
}
//@}
/** Tells if all constrained edges are conformed. */
bool is_conforming_done()
// This function cannot be "const" because, as edges_to_be_conformed is
// filtred, its empty() method is not const.
{ return ( edges_level_Gabriel.no_longer_element_to_refine()
&& edges_level_Delaunay.no_longer_element_to_refine() );
}
/** Execute on step of the algorithm.
init_XXX() should have been called before.
*/
//@{
bool try_one_step_conforming_Delaunay()
{
return edges_level_Delaunay.one_step(null_visitor);
}
bool try_one_step_conforming_Gabriel()
{
return edges_level_Gabriel.one_step(null_visitor);
}
bool step_by_step_conforming_Delaunay()
{
return edges_level_Delaunay.try_to_insert_one_point(null_visitor);
}
bool step_by_step_conforming_Gabriel()
{
return edges_level_Gabriel.try_to_insert_one_point(null_visitor);
}
//@}
}; // end Triangulation_conformer_2
// --- GLOBAL FUNCTIONS ---
template <class Tr>
void
make_conforming_Gabriel_2(Tr& t)
{
typedef Triangulation_conformer_2<Tr> Conform;
Conform conform(t);
conform.make_conforming_Gabriel();
}
template <class Tr>
void
make_conforming_Delaunay_2(Tr& t)
{
typedef Triangulation_conformer_2<Tr> Conform;
Conform conform(t);
conform.make_conforming_Delaunay();
}
} // end namespace CGAL
#include <CGAL/enable_warnings.h>
#endif // CGAL_TRIANGULATION_CONFORMER_2_H
|