Commit of changes for 0.9.3: split of Mesh_2.h into Mesh_2.h and

Conform_2.h
This commit is contained in:
Laurent Rineau 2003-05-09 23:02:21 +00:00
parent 1b1517b006
commit b84bddbcbd
15 changed files with 2108 additions and 1933 deletions

View File

@ -1,3 +1,7 @@
version 0.9.3 (2003/05/10)
--------------------------
o split of the code into Mesh_2 and Conform_2
version 0.9.2 (2003/03/12)
--------------------------
o added a bench sub-directory

View File

@ -0,0 +1,159 @@
// ============================================================================
//
// Copyright (c) 1997-2000 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------------
//
// file :
// package :
// author(s) : Laurent Rineau
// release :
// release_date :
//
//
//
// ============================================================================
#include <CGAL/IO/Qt_widget.h>
#include <CGAL/IO/Qt_widget_layer.h>
class Show_clusters_aux : public CGAL::Qt_widget_layer
{
Q_OBJECT
private:
virtual voir reinit_clusters() {}
public slots:
void reinitClusters()
{
reinit_clusters();
}
};
template <class Conform>
class Show_clusters : public Show_clusters_aux
{
public:
typedef typename Conform::Point Point;
typedef typename Conform::Triangulation DT;
typedef typename Conform::Segment Segment;
typedef typename Conform::Face_handle Face_handle;
typedef typename Conform::Vertex_handle Vertex_handle;
typedef typename Conform::Geom_traits::FT FT;
typedef typename Conform::Cluster_vertices_iterator CVIt;
typedef typename Conform::Vertices_in_cluster_iterator ViCIt
typedef std::list<Point> List_of_points;
typedef typename List_of_points::const_iterator Point_iterator;
Show_clusters(Conform &conform,
Color c = CGAL::GREEN,
int pointsize = 3,
PointStyle pointstyle = CGAL::DISC,
Color lc = CGAL::RED,
int linewidth = 2)
: c(conform), first_time(true), dt(), _color(c),
size(pointsize), style(pointstyle), _line_color(lc),
width(linewidth) {}
void reinit_clusters()
{
dt.clear();
for(CVIt it = c.clusters_vertices_begin();
it != c.clusters_vertices_end();
++it)
dt.push_back( (*it)->point() );
}
void draw(){first_time = true;}
void mouseMoveEvent(QMouseEvent *e)
{
if (dt.dimension()<1) return;
FT x, y;
widget->x_real(e->x(), x);
widget->y_real(e->y(), y);
Point p(x, y);
RasterOp old = widget->rasterOp(); //save the initial raster mode
widget->setRasterOp(XorROP);
widget->lock();
Vertex_handle v = dt.nearest_vertex(p);
*widget << _color << CGAL::PointSize (pointsize)
<< CGAL::PointStyle (pointstyle);
if(!first_time)
*widget << oldPoint;
*widget << v->point();
*widget << _line_color << CGAL::LineWidth(width);
if(!first_time)
for(Point_iterator pIt = oldPoints.begin();
pIt != oldPoints.end();
++pIt)
*widget << Segment(oldPoint, *pIt);
oldPoints.clear();
typename Conform::Locate_type lt;
int i;
Face_handle fh = c.locate(v->point(), lt, t);
CGAL_assertion( lt == this->VERTEX );
Vertex_handle v2 = fh->vertex(i);
int n = c.number_of_clusters_at_vertex(v2);
for(int j = 0; j < n; ++j)
{
std::pair<ViCIt> seq = c.vertices_in_cluster_sequence(v2, j);
for(ViCIt it = seq.first;
it != seq.second;
++it)
{
oldPoints.push_back((*it)->point());
*widget << Segment(*v2, (*it)->point());
}
}
widget->unlock();
widget->setRasterOp(old);
oldPoint = v->point();
first_time = false;
}
void leaveEvent(QEvent *)
{
widget->lock();
RasterOp old = widget->rasterOp(); //save the initial raster mode
widget->setRasterOp(XorROP);
*widget << _color << CGAL::PointSize (pointsize)
<< CGAL::PointStyle (pointstyle);
if(!first_time) *widget << oldPoint;
widget->unlock();
widget->setRasterOp(old);
first_time = true;
}
private:
Conform& c;
DT dt;
Point oldPoint, newPoint;
List_of_points oldPoints;
bool first_time;
Color _color;
int size;
PointStyle style;
Color _line_color;
int width;
};
// moc_source_file: Show_clusters.h
#include "Show_clusters.moc"

View File

@ -1,61 +1,99 @@
// ============================================================================
//
// Copyright (c) 1997-2000 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------------
//
// file : include/CGAL/IO/Qt_layer_show_points.h
// package : Qt_widget
// author(s) : Radu Ursu
// release :
// release_date :
//
// coordinator : Laurent Rineau <rineau@clipper.ens.fr>
//
// ============================================================================
#ifndef CGAL_QT_LAYER_SHOW_POINTS_H
#define CGAL_QT_LAYER_SHOW_POINTS_H
#include <CGAL/IO/Qt_widget_layer.h>
#include <CGAL/function_objects.h>
#include <qcolor.h>
namespace CGAL {
template <class T>
template <class C, class It,
class Transform = Identity<typename It::value_type> >
class Qt_layer_show_points : public Qt_widget_layer {
public:
// typedef typename T::Point Point;
// typedef typename T::Segment Segment;
// typedef typename T::Vertex Vertex;
typedef typename T::Vertex_iterator Vertex_iterator;
typedef It (C::* iterator_function)() const;
Qt_layer_show_points(T *&t, Color c=CGAL::GREEN, int pointsize=3,
Qt_layer_show_points(C *&container,
iterator_function begin,
iterator_function end,
const Transform& t = Transform(),
Color c = CGAL::GREEN,
int pointsize = 3,
PointStyle pointstyle = CGAL::DISC)
: tr(t), color(c), size(pointsize), style(pointstyle) {};
: cont(container), _begin(begin), _end(end), _color(c),
size(pointsize), style(pointstyle), trans(t) {};
Qt_layer_show_points(C *&container,
iterator_function begin,
iterator_function end,
Color c = CGAL::GREEN,
int pointsize = 3,
PointStyle pointstyle = CGAL::DISC)
: cont(container), _begin(begin), _end(end), _color(c),
size(pointsize), style(pointstyle), trans(Transform()) {};
void draw()
{
Vertex_iterator it = tr->vertices_begin(),
beyond = tr->vertices_end();
*widget << color << CGAL::PointSize (size)
<< CGAL::PointStyle (style);
while(it != beyond) {
*widget << (*it).point();
++it;
}
{
widget->lock();
QColor old_color = widget->color();
int old_point_size = widget->pointSize();
*widget << _color << CGAL::PointSize (size)
<< CGAL::PointStyle (style);
for(It it = (cont->*_begin)();
it!=(cont->*_end)();
++it)
*widget << trans(*it);
widget->setPointSize(old_point_size);
widget->setColor(old_color);
widget->unlock();
};
QColor color() const { return _color; };
int pointSize() const { return size; };
void setColor(const QColor c)
{
_color = c;
widget->redraw();
};
void setPointSize(const int s)
{
size = s;
widget->redraw();
};
private:
T *&tr;
Color color;
C *&cont;
iterator_function _begin;
iterator_function _end;
Color _color;
int size;
PointStyle style;
const Transform trans;
};//end class
// template <class C, class It,
// class Transform = Identity<typename It::value_type> >
// // Qt_layer_show_points<C, It, Transform>*
// void*
// make_show_points_layer(C *&container,
// It (C::*)() const begin,
// It (C::*)() const end,
// Transform& t = Transform(),
// Color c = CGAL::GREEN,
// int pointsize = 3,
// PointStyle pointstyle = CGAL::DISC)
// {
// return new CGAL::Qt_layer_show_points<C, It, Transform>
// (container, begin, end, t, c, pointsize, pointstyle);
// };
} // namespace CGAL
#endif // CGAL_QT_LAYER_SHOW_POINTS_H

View File

@ -13,8 +13,7 @@ include $(CGAL_MAKEFILE)
# compiler flags
#---------------------------------------------------------------------#
CXXFLAGS = -I../../../Qt_widget/include \
-I../../include \
CXXFLAGS = -I../../include \
$(CGAL_CXXFLAGS) \
$(LONG_NAME_PROBLEM_CXXFLAGS) \
$(DEBUG_OPT)
@ -35,6 +34,7 @@ LDFLAGS = \
#---------------------------------------------------------------------#
all: \
icons$(EXE_EXT) \
mesh_demo$(EXE_EXT)
icons$(EXE_EXT): icons$(OBJ_EXT)
@ -43,10 +43,14 @@ icons$(EXE_EXT): icons$(OBJ_EXT)
mesh_demo.moc: mesh_demo.C
$(QT_MOC) -o mesh_demo.moc $<
Show_clusters.moc: Show_clusters.h
$(QT_MOC) -o Show_clusters.moc $<
mesh_demo$(OBJ_EXT): mesh_demo.moc \
Show_clusters.moc \
../../include/CGAL/Double_map.h \
../../include/CGAL/Filtred_circulator.h \
../../include/CGAL/Filtred_container.h \
../../include/CGAL/Filter_circulator.h \
../../include/CGAL/Filtered_container.h \
../../include/CGAL/Mesh_2.h \
../../include/CGAL/Mesh_default_traits_2.h \
../../include/CGAL/Mesh_face_base_2.h \

View File

@ -15,6 +15,10 @@ int main(int, char*)
#include <CGAL/basic.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <iostream>
#include <fstream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Filtered_kernel.h>
@ -25,6 +29,8 @@ int main(int, char*)
#include <CGAL/Mesh_local_size_traits_2.h>
#include <CGAL/Mesh_face_base_2.h>
#include <CGAL/Read_write.h>
#include <CGAL/IO/Qt_widget.h>
#include <CGAL/IO/Qt_widget_standard_toolbar.h>
#include <CGAL/IO/Qt_widget_get_point.h>
@ -79,6 +85,7 @@ typedef K::Circle_2 Circle;
typedef CGAL::Polygon_2<K> CGALPolygon;
typedef CGAL::Mesh_2<Tr> Mesh;
typedef Mesh::Vertex Vertex;
template <class M>
class Show_marked_faces : public CGAL::Qt_widget_layer
@ -130,36 +137,13 @@ public:
};
};
namespace {
class Seeds_wrapper_point : public Point {
public:
Seeds_wrapper_point(const Point& p): Point(p) {};
inline Point point() const { return *this; };
};
class Seeds : public std::list<Seeds_wrapper_point> {
public:
typedef std::list<Seeds_wrapper_point> List;
typedef List::const_iterator const_iterator;
typedef const_iterator Vertex_iterator;
inline const_iterator vertices_begin() { return begin(); }
inline const_iterator vertices_end() { return end(); }
};
};
class MyWindow : public QMainWindow
{
Q_OBJECT
public:
MyWindow() : is_mesh_initialized(false), traits()
{
triangulation = new Tr(traits);
mesh = 0;
seeds = new Seeds();
mesh = new Mesh(traits);
QFrame* mainframe = new QFrame(this, "mainframe");
QHBoxLayout *hbox = new QHBoxLayout(mainframe, 0, 0,
@ -198,22 +182,32 @@ public:
// statusBar()->addWidget(aspect_ratio_label, 0, true);
// LAYERS
show_points = new CGAL::Qt_layer_show_points<Tr>(triangulation);
show_seeds = new CGAL::Qt_layer_show_points<Seeds>(seeds,
CGAL::BLUE,
5,
CGAL::CROSS);
show_points =
new Show_points_from_triangulation(mesh,
&Mesh::finite_vertices_begin,
&Mesh::finite_vertices_end,
std::mem_fun_ref(&Vertex::point));
show_seeds = new Show_seeds(mesh,
&Mesh::seeds_begin,
&Mesh::seeds_end,
CGAL::BLUE,
5,
CGAL::CROSS);
show_triangulation =
new CGAL::Qt_layer_show_triangulation<Tr>(triangulation);
new CGAL::Qt_layer_show_triangulation<Mesh>(mesh);
show_marked =
new Show_marked_faces<Tr>(triangulation);
new Show_marked_faces<Mesh>(mesh);
show_constraints =
new CGAL::Qt_layer_show_triangulation_constraints<Tr>
(triangulation);
new CGAL::Qt_layer_show_triangulation_constraints<Mesh>
(mesh);
show_circles =
new CGAL::Qt_layer_show_circles<Tr>(triangulation);
new CGAL::Qt_layer_show_circles<Mesh>(mesh);
show_mouse = new CGAL::Qt_layer_mouse_coordinates(*this);
show_clusters = new Show_Clusters<Mesh>(*mesh);
// layers order, first attached are "under" last attached
widget->attach(show_marked);
widget->attach(show_triangulation);
@ -450,7 +444,11 @@ public:
CTRL+Key_L );
menuBar()->insertItem("&Advanced", this, SLOT(advanced()));
;
connect(this, SLOT(insertedInput()),
this, SIGNAL(set_not_initialized()));
connect(this, SLOT(initializedMesh()),
this, SIGNAL(set_initialized()));
widget->set_window(-1.,1.,-1.,1.);
widget->setMouseTracking(TRUE);
@ -460,11 +458,11 @@ public:
void bounds(FT &xmin, FT &ymin,
FT &xmax, FT &ymax)
{
Mesh::Finite_vertices_iterator vi=triangulation->finite_vertices_begin();
Mesh::Finite_vertices_iterator vi=mesh->finite_vertices_begin();
xmin=xmax=vi->point().x();
ymin=ymax=vi->point().y();
vi++;
while(vi != triangulation->finite_vertices_end())
while(vi != mesh->finite_vertices_end())
{
if(vi->point().x() < xmin) xmin=vi->point().x();
if(vi->point().x() > xmax) xmax=vi->point().x();
@ -474,35 +472,21 @@ public:
}
}
void switch_to_mesh()
{
if(mesh == 0)
{
// std::cerr << "switch_to_mesh()" << std::endl;
// "construct" a mesh from triangulation without refining it
// (because of the third parameter dont_refine=true)
mesh = new Mesh(*triangulation, traits, true);
delete triangulation;
triangulation = mesh;
};
}
void switch_to_triangulation()
{
if(mesh != 0)
{
// std::cerr << "switch_to_triangulation()" << std::endl
// << mesh->number_of_vertices() << std::endl;
triangulation = new Tr(); // empty triangulation
triangulation->swap(*mesh); // swap *triangulation and *mesh
// *mesh is now empty
delete mesh;
mesh = 0; // in case delete does not the job
};
}
signals:
void insertedInput();
void initializedMesh();
public slots:
void set_initialized()
{
is_mesh_initialized = true;
}
void set_not_initialized()
{
is_mesh_initialized = false;
}
void get_cgal_object(CGAL::Object obj)
{ // TODO: when inputs arise, seeds should be cleared
@ -512,7 +496,6 @@ public slots:
if(CGAL::assign(p,obj))
if(follow_mouse->is_active())
{
switch_to_mesh();
typedef Mesh::Face_handle Face_handle;
std::list<Face_handle> l;
@ -528,66 +511,45 @@ public slots:
if(traits.is_bad_object().operator()(a, b, c))
l.push_back(fh);
}
mesh->set_geom_traits(traits, l.begin(), l.end());
mesh->set_geom_traits(traits);
mesh->set_bad_faces(l.begin(), l.end());
mesh->calculate_bad_faces();
while( mesh->refine_step() );
widget->redraw();
}
else
if(get_seed->is_active())
{
seeds->push_back(p);
switch_to_mesh();
mesh->mark_facets(seeds->begin(), seeds->end());
Mesh::Seeds seeds;
std::copy(mesh->seeds_begin(), mesh->seeds_end(),
std::back_inserter(seeds));
seeds.push_back(p);
mesh->set_seeds(seeds.begin(), seeds.end());
mesh->mark_facets();
}
else // get_point is active
{
switch_to_triangulation();
triangulation->insert(p);
switch_to_mesh();
mesh->mark_facets(seeds->begin(), seeds->end());
is_mesh_initialized = false;
mesh->insert(p);
mesh->mark_facets();
emit( insertedInput() );
}
else
if (CGAL::assign(poly,obj))
{
switch_to_triangulation();
for(CGALPolygon::Edge_const_iterator it=poly.edges_begin();
it!=poly.edges_end();
it++)
triangulation->insert((*it).source(),(*it).target());
switch_to_mesh();
mesh->mark_facets(seeds->begin(), seeds->end());
is_mesh_initialized = false;
mesh->insert((*it).source(),(*it).target());
mesh->mark_facets();
emit( insertedInput() );
}
updatePointCouter();
widget->redraw();
}
// void redraw_win()
// {
// widget->lock();
// widget->clear();
// for(Mesh::Edge_iterator it=mesh->edges_begin();
// it!=mesh->edges_end();
// it++)
// if(mesh->is_constrained(*it))
// *widget << CGAL::RED << mesh->segment(*it);
// else
// *widget << CGAL::BLUE << mesh->segment(*it);
// *widget << CGAL::GREEN;
// for(Mesh::Vertex_iterator it=mesh->vertices_begin();
// it!=mesh->vertices_end();
// it++)
// *widget << it->point();
// widget->unlock();
// }
//insert a bounding box around the mesh
//insert a bounding box around the mesh
void insert_bounding_box()
{
switch_to_triangulation();
FT xmin, xmax, ymin, ymax;
bounds(xmin, ymin, xmax, ymax);
@ -600,29 +562,28 @@ public slots:
Point bb2(xcenter + 1.5*xspan, ycenter - 1.5*yspan);
Point bb3(xcenter + 1.5*xspan, ycenter + 1.5*yspan);
Point bb4(xcenter - 1.5*xspan, ycenter + 1.5*yspan);
triangulation->insert(bb1);
triangulation->insert(bb2);
triangulation->insert(bb3);
triangulation->insert(bb4);
triangulation->insert(bb1, bb2);
triangulation->insert(bb2, bb3);
triangulation->insert(bb3, bb4);
triangulation->insert(bb4, bb1);
switch_to_mesh();
mesh->mark_facets(seeds->begin(), seeds->end());
mesh->insert(bb1);
mesh->insert(bb2);
mesh->insert(bb3);
mesh->insert(bb4);
mesh->insert(bb1, bb2);
mesh->insert(bb2, bb3);
mesh->insert(bb3, bb4);
mesh->insert(bb4, bb1);
mesh->mark_facets();
emit( insertedInput() );
widget->redraw();
}
void updatePointCouter()
{
nbre_de_points->setNum(triangulation->number_of_vertices());
nbre_de_points->setNum(mesh->number_of_vertices());
}
void refineMesh()
{
switch_to_mesh();
saveTriangulationUrgently("last_input.edg");
mesh->refine(seeds->begin(), seeds->end());
mesh->refine();
is_mesh_initialized=true;
updatePointCouter();
widget->redraw();
@ -630,14 +591,13 @@ public slots:
void conformMesh()
{
switch_to_mesh();
if(!is_mesh_initialized)
{
saveTriangulationUrgently("last_input.edg");
mesh->init(seeds->begin(), seeds->end());
mesh->init();
is_mesh_initialized=true;
}
mesh->conform();
mesh->conform(CGAL::Gabriel_conform_inside_policy_2());
updatePointCouter();
widget->redraw();
}
@ -645,10 +605,10 @@ public slots:
void refineMeshStep()
{
int counter = step_lenght;
switch_to_mesh();
if(!is_mesh_initialized)
{
mesh->init(seeds->begin(), seeds->end());
mesh->init();
std::cerr << "mesh->init();"<< std::endl;
is_mesh_initialized=true;
saveTriangulationUrgently("last_input.edg");
}
@ -692,11 +652,8 @@ public slots:
void clearMesh()
{
switch_to_mesh();
mesh->clear();
seeds->clear();
is_mesh_initialized=false;
switch_to_triangulation();
emit( insertedInput() );
updatePointCouter();
widget->clear_history();
widget->redraw();
@ -704,14 +661,13 @@ public slots:
void clearSeeds()
{
seeds->clear();
mesh->mark_facets(seeds->begin(), seeds->end());
mesh->clear_seeds();
mesh->mark_facets();
widget->redraw();
}
void openTriangulation()
{
switch_to_mesh();
QString s( QFileDialog::getOpenFileName( QString::null,
my_filters, this ) );
if ( s.isEmpty() )
@ -719,13 +675,8 @@ public slots:
std::ifstream f(s);
if(s.right(5) == ".poly")
{
mesh->read_poly(f, true);
seeds->clear();
for(Mesh::Seeds::iterator it = mesh->seeds.begin();
it != mesh->seeds.end();
++it)
seeds->push_back(*it);
is_mesh_initialized=true;
read_poly(*mesh, f);
emit( insertedInput() );
}
else if(s.right(5) == ".data")
{
@ -810,13 +761,13 @@ public slots:
mesh->insert_constraint(tl, bl);
clearSeeds();
is_mesh_initialized=false;
emit( insertedInput() );
}
else
{
mesh->read(f, true);
read(*mesh, f);
clearSeeds();
is_mesh_initialized=false;
emit( insertedInput() );
}
// compute bounds
@ -838,23 +789,21 @@ public slots:
void saveTriangulation()
{
switch_to_mesh();
QString s( QFileDialog::getSaveFileName( "filename.edg",
my_filters, this ) );
if ( s.isEmpty() )
return;
std::ofstream of(s);
if(s.right(5) == ".poly")
mesh->write_poly(of);
write_poly(*mesh, of);
else
mesh->write(of);
write(*mesh, of);
}
void saveTriangulationUrgently(QString s=QString("dump.edg"))
{
switch_to_mesh();
std::ofstream of(s);
mesh->write(of);
write(*mesh, of);
}
inline
@ -891,7 +840,6 @@ public slots:
void setLocal()
{
switch_to_mesh();
traits.set_local_size(!mesh->geom_traits().is_local_size());
pmCriteria->setItemChecked(menu_id, traits.is_local_size());
mesh->set_geom_traits(traits);
@ -913,11 +861,8 @@ private:
static const QString my_filters;
bool is_mesh_initialized;
Meshtraits traits;
Tr* triangulation;
Mesh* mesh;
Seeds* seeds;
QPopupMenu *pmCriteria;
int menu_id;
@ -927,13 +872,22 @@ private:
CGAL::Qt_widget_get_polygon<CGALPolygon>* get_polygon;
Follow_mouse* follow_mouse;
CGAL::Qt_layer_show_points<Tr>* show_points;
CGAL::Qt_layer_show_points<Seeds>* show_seeds;
CGAL::Qt_layer_show_triangulation<Tr>* show_triangulation;
CGAL::Qt_layer_show_triangulation_constraints<Tr>* show_constraints;
CGAL::Qt_layer_show_circles<Tr>* show_circles;
typedef CGAL::Qt_layer_show_points<Mesh, Mesh::Finite_vertices_iterator,
std::const_mem_fun_ref_t<const Vertex::Point&, Vertex::Vb> >
Show_points_from_triangulation;
typedef CGAL::Qt_layer_show_points<Mesh, Mesh::Seeds_const_iterator>
Show_seeds;
Show_points_from_triangulation* show_points;
Show_seeds* show_seeds;
CGAL::Qt_layer_show_triangulation<Mesh>* show_triangulation;
CGAL::Qt_layer_show_triangulation_constraints<Mesh>* show_constraints;
CGAL::Qt_layer_show_circles<Mesh>* show_circles;
CGAL::Qt_layer_mouse_coordinates* show_mouse;
Show_marked_faces<Tr>* show_marked;
Show_marked_faces<Mesh>* show_marked;
Show_clusters<Mesh>* show_clusters;
// QLabel* aspect_ratio_label;
QLabel *nbre_de_points;

View File

@ -34,20 +34,30 @@ LDFLAGS = \
#---------------------------------------------------------------------#
all: \
conform$(EXE_EXT) \
mesh$(EXE_EXT)
conform$(OBJ_EXT): ../../include/CGAL/Conform_2.h \
../../include/CGAL/Mesh_default_traits_2.h \
../../include/CGAL/Double_map.h \
../../include/CGAL/Filter_circulator.h \
../../include/CGAL/Filtered_container.h
conform$(EXE_EXT): conform$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)conform conform$(OBJ_EXT) $(LDFLAGS)
mesh$(OBJ_EXT): ../../include/CGAL/Mesh_2.h \
../../include/CGAL/Mesh_face_base_2.h \
../../include/CGAL/Mesh_default_traits_2.h \
../../include/CGAL/Double_map.h \
../../include/CGAL/Filtred_circulator.h \
../../include/CGAL/Filtred_container.h \
../../include/CGAL/Filter_circulator.h \
../../include/CGAL/Filtered_container.h \
mesh$(EXE_EXT): mesh$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)mesh mesh$(OBJ_EXT) $(LDFLAGS)
clean: \
mesh.clean
mesh.clean conform.clean
#---------------------------------------------------------------------#
# suffix rules
@ -56,3 +66,5 @@ clean: \
.C$(OBJ_EXT):
$(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<
%.h.gch: %.h
$(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<

View File

@ -0,0 +1,129 @@
#include <CGAL/basic.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Filtered_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Conform_2.h>
#include <CGAL/Read_write.h>
#include <CGAL/Mesh_default_traits_2.h>
typedef CGAL::Simple_cartesian<double> K1;
typedef CGAL::Filtered_kernel<K1> K2;
struct K : public K2 {};
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Constrained_triangulation_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Mesh_default_traits_2<K> Meshtraits;
typedef CGAL::Constrained_Delaunay_triangulation_2<Meshtraits, Tds,
CGAL::Exact_predicates_tag> Tr;
typedef CGAL::Conform_triangulation_2<Tr> Conform;
typedef K::Point_2 Point;
Conform conform;
void usage(char** argv)
{
std::cerr << "Usage: " << std::endl
<< argv[0] << " [-Q] input.poly [output.poly]" << std::endl;
}
int main(int argc, char** argv)
{
int arg_count = 1;
bool terminal_output = true;
if(argc < 2)
{
usage(argv);
return 1;
}
while(argv[arg_count][0] == '-' && argv[arg_count] != "--")
{
if(std::string(argv[arg_count]) == "-Q")
terminal_output = false;
else
{
std::cerr << "Unknown option " << argv[arg_count] << std::endl;
usage(argv);
return 1;
}
++arg_count;
}
if(argv[arg_count] == "--")
++arg_count;
if(argc < arg_count+1 || argc > arg_count+2)
{
usage(argv);
return 1;
};
std::ifstream input(argv[arg_count]);
if(input)
{
read_poly(conform, input);
conform.init(CGAL::Gabriel_conform_policy_2());
typedef Conform::cluster_vertices_iterator Vh_iterator;
for(Vh_iterator it = conform.clusters_vertices_begin();
it != conform.clusters_vertices_end();
++it)
{
typedef std::pair<Conform::vertices_in_cluster_iterator,
Conform::vertices_in_cluster_iterator> It_pair;
int n = conform.number_of_clusters_at_vertex(*it);
std::cout << "Point(" << (*it)->point() << ")" << std::endl
<< " " << n
<< " cluster(s)." << std::endl;
for(int i = 0; i<n; ++i)
{
std::cout << " cluster " << i << ":" << std::endl;
const It_pair& it_pair =
conform.vertices_in_cluster_sequence(*it, i);
for(Conform::vertices_in_cluster_iterator
vic_it = it_pair.first;
vic_it != it_pair.second;
++vic_it)
std::cout << " " << (*vic_it)->point() << std::endl;
}
};
conform.gabriel_conform();
}
else
{
std::cerr << "Bad file: " << argv[arg_count] << std::endl;
usage(argv);
return 1;
}
if(argc==arg_count+1)
{
if(terminal_output)
write_poly(conform, std::cout);
}
else
{
std::ofstream output(argv[arg_count+1]);
write_poly(conform, output);
}
if(terminal_output)
std::cerr
<< "Mesh points: " << conform.number_of_vertices() << std::endl
<< "Mesh triangles: " << conform.number_of_faces () << std::endl;
return 0;
};

View File

@ -1,4 +1,4 @@
#include <CGAL/basic.h>
#include <CGAL/basic.h>
#include <iostream>
#include <fstream>
#include <string>
@ -13,6 +13,8 @@
#include <CGAL/Mesh_face_base_2.h>
#include <CGAL/Mesh_area_traits_2.h>
#include <CGAL/Read_write.h>
typedef CGAL::Simple_cartesian<double> K1;
typedef CGAL::Filtered_kernel<K1> K2;
struct K : public K2 {};
@ -88,7 +90,10 @@ int main(int argc, char** argv)
};
std::ifstream input(argv[arg_count]);
if(input)
mesh.read_poly(input);
{
read_poly(mesh, input);
mesh.refine();
}
else
{
std::cerr << "Bad file: " << argv[arg_count] << std::endl;
@ -99,12 +104,12 @@ int main(int argc, char** argv)
if(argc==arg_count+1)
{
if(terminal_output)
mesh.write_poly(std::cout);
write_poly(mesh, std::cout);
}
else
{
std::ofstream output(argv[arg_count+1]);
mesh.write_poly(output);
write_poly(mesh, output);
}
if(terminal_output)
std::cerr

File diff suppressed because it is too large Load Diff

View File

@ -1,664 +0,0 @@
// ======================================================================
//
// Copyright (c) 1997 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------
//
// release : $CGAL_Revision: CGAL-2.5-I-22 $
// release_date : $CGAL_Date: 2002/09/03 $
//
// file : include/CGAL/Constrained_Delaunay_triangulation_2.h
// package : Triangulation_2 (7.46)
// maintainer : Mariette Yvinec <Mariette.Yvinec@sophia.inria.fr>
// source : $RCSfile$
// revision : $Revision$
// revision_date : $Date$
// author(s) : Mariette Yvinec, Jean Daniel Boissonnat
//
// coordinator : Mariette Yvinec < Mariette Yvinec@sophia.inria.fr>
//
// ======================================================================
#ifndef CGAL_CONSTRAINED_DELAUNAY_TRIANGULATION_2_H
#define CGAL_CONSTRAINED_DELAUNAY_TRIANGULATION_2_H
#include <CGAL/triangulation_assertions.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Constrained_triangulation_2.h>
CGAL_BEGIN_NAMESPACE
template <class Gt,
class Tds = Triangulation_data_structure_2 <
Triangulation_vertex_base_2<Gt>,
Constrained_triangulation_face_base_2<Gt> >,
class Itag = No_intersection_tag >
class Constrained_Delaunay_triangulation_2
: public Constrained_triangulation_2<Gt, Tds, Itag>
{
public:
typedef Constrained_triangulation_2<Gt,Tds,Itag> Ctr;
typedef Constrained_Delaunay_triangulation_2<Gt,Tds,Itag> CDt;
typedef typename Ctr::Geom_traits Geom_traits;
typedef typename Ctr::Intersection_tag Intersection_tag;
typedef typename Ctr::Constraint Constraint;
typedef typename Ctr::Vertex_handle Vertex_handle;
typedef typename Ctr::Face_handle Face_handle;
typedef typename Ctr::Edge Edge;
typedef typename Ctr::Finite_faces_iterator Finite_faces_iterator;
typedef typename Ctr::Face_circulator Face_circulator;
typedef typename Ctr::Locate_type Locate_type;
typedef typename Ctr::List_edges List_edges;
typedef typename Ctr::List_faces List_faces;
typedef typename Ctr::List_vertices List_vertices;
typedef typename Ctr::List_constraints List_constraints;
typedef typename Ctr::Less_edge less_edge;
typedef typename Ctr::Edge_set Edge_set;
typedef typename Geom_traits::Point_2 Point;
Constrained_Delaunay_triangulation_2(const Geom_traits& gt=Geom_traits())
: Ctr(gt) { }
Constrained_Delaunay_triangulation_2(const CDt& cdt)
: Ctr(cdt) {}
Constrained_Delaunay_triangulation_2(List_constraints& lc,
const Geom_traits& gt=Geom_traits())
: Ctr(gt)
{
typename List_constraints::iterator itc = lc.begin();
for( ; itc != lc.end(); ++itc) {
insert((*itc).first, (*itc).second);
}
CGAL_triangulation_postcondition( is_valid() );
}
template<class InputIterator>
Constrained_Delaunay_triangulation_2(InputIterator it,
InputIterator last,
const Geom_traits& gt=Geom_traits() )
: Ctr(gt)
{
for ( ; it != last; it++) {
insert((*it).first, (*it).second);
}
CGAL_triangulation_postcondition( is_valid() );
}
virtual ~Constrained_Delaunay_triangulation_2() {}
// FLIPS
bool is_flipable(Face_handle f, int i) const;
void flip(Face_handle& f, int i);
void flip_around(Vertex_handle va);
void flip_around(List_vertices & new_vertices);
void propagating_flip(Face_handle& f,int i);
void propagating_flip(List_edges & edges);
// CONFLICTS
bool test_conflict(Face_handle fh, const Point& p) const; //deprecated
bool test_conflict(const Point& p, Face_handle fh) const;
void find_conflicts(const Point& p, std::list<Edge>& le, //deprecated
Face_handle hint= Face_handle(NULL)) const;
// //template member functions, declared and defined at the end
// template <class Out_it1, class Out_it2>
// bool get_conflicts_and_boundary(const Point &p,
// Out_it1 fit,
// Out_it2 eit,
// Face_handle start) const;
// template <class Out_it1>
// bool get_conflicts(const Point &p,
// Out_it1 fit,
// Face_handle start ) const;
// template <class Out_it2>
// bool get_boundary_of_conflicts(const Point &p,
// Out_it2 eit,
// Face_handle start ) const;
// INSERTION-REMOVAL
Vertex_handle insert(const Point & a, Face_handle start = Face_handle(NULL));
Vertex_handle insert(const Point& p,
Locate_type lt,
Face_handle loc, int li );
Vertex_handle push_back(const Point& a);
// template < class InputIterator >
// int insert(InputIterator first, InputIterator last);
void remove(Vertex_handle v);
void remove_incident_constraints(Vertex_handle v);
void remove_constraint(Face_handle f, int i);
//for backward compatibility
void insert(Point a, Point b) { insert_constraint(a, b);}
void insert(Vertex_handle va, Vertex_handle vb) {insert_constraint(va,vb);}
// CHECK
bool is_valid(bool verbose = false, int level = 0) const;
protected:
virtual Vertex_handle virtual_insert(const Point & a,
Face_handle start = Face_handle(NULL));
virtual Vertex_handle virtual_insert(const Point& a,
Locate_type lt,
Face_handle loc,
int li );
//Vertex_handle special_insert_in_edge(const Point & a, Face_handle f, int i);
void remove_2D(Vertex_handle v );
virtual void triangulate_hole(List_faces& intersected_faces,
List_edges& conflict_boundary_ab,
List_edges& conflict_boundary_ba);
public:
// MESHING
// suppressed meshing functions from here
//template member functions
public:
template < class InputIterator >
#if defined(_MSC_VER) || defined(__SUNPRO_CC)
int insert(InputIterator first, InputIterator last, int i = 0)
#else
int insert(InputIterator first, InputIterator last)
#endif
{
int n = number_of_vertices();
while(first != last){
insert(*first);
++first;
}
return number_of_vertices() - n;
}
#warning "File patched by Laurent Rineau, for Mesh_2 robustness!"
template <class Out_it1, class Out_it2>
bool
get_conflicts_and_boundary(const Point &p,
Out_it1 fit,
Out_it2 eit,
Face_handle start = Face_handle(NULL)) const
{
CGAL_triangulation_precondition( dimension() == 2);
int li;
Locate_type lt;
Face_handle fh = locate(p,lt,li, start);
return get_conflicts_and_boundary(p, fit, eit, lt, fh, li);
}
template <class Out_it1, class Out_it2>
bool
get_conflicts_and_boundary(const Point &p,
Out_it1 fit,
Out_it2 eit,
Locate_type lt,
Face_handle fh,
int li) const
{
CGAL_triangulation_precondition( dimension() == 2);
switch(lt) {
case OUTSIDE_AFFINE_HULL:
case VERTEX:
return false;
case EDGE:
// std::cerr << "EDGE!" << std::endl;
if( fh->is_constrained(li) )
{
Face_handle neighbor = fh->neighbor(li);
if( ! is_infinite(neighbor) )
{
*fit++ = neighbor;
propagate_conflicts(p,neighbor,0,fit,eit);
propagate_conflicts(p,neighbor,1,fit,eit);
propagate_conflicts(p,neighbor,2,fit,eit);
}
}
case FACE:
case OUTSIDE_CONVEX_HULL:
// std::cerr << "OUTSIDE_CONVEX_HULL!" << std::endl;
*fit++ = fh; //put fh in Out_it1
propagate_conflicts(p,fh,0,fit,eit);
propagate_conflicts(p,fh,1,fit,eit);
propagate_conflicts(p,fh,2,fit,eit);
return true;
}
CGAL_triangulation_assertion(false);
return false;
}
template <class Out_it1>
bool
get_conflicts(const Point &p,
Out_it1 fit,
Face_handle start= Face_handle(NULL)) const
{
return get_conflicts_and_boundary(p, fit, Emptyset_iterator(), start);
}
template <class Out_it2>
inline bool
get_boundary_of_conflicts(const Point &p,
Out_it2 eit,
Face_handle start= Face_handle(NULL)) const
{
return get_conflicts_and_boundary(p, Emptyset_iterator(), eit, start);
}
private:
template <class Out_it1, class Out_it2>
void propagate_conflicts (const Point &p,
Face_handle fh,
int i,
Out_it1 fit,
Out_it2 eit) const
{
Face_handle fn = fh->neighbor(i);
if ( fh->is_constrained(i) || ! test_conflict(p,fn)) {
*eit++ = Edge(fn, fn->index(fh));
return;
}
*fit++ = fn;
int j = fn->index(fh);
propagate_conflicts(p,fn,ccw(j),fit,eit);
propagate_conflicts(p,fn,cw(j),fit,eit);
return;
}
};
template < class Gt, class Tds, class Itag >
bool
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
is_flipable(Face_handle f, int i) const
// determines if edge (f,i) can be flipped
{
Face_handle ni = f->neighbor(i);
if (is_infinite(f) || is_infinite(ni)) return false;
if (f->is_constrained(i)) return false;
return (side_of_oriented_circle(ni, f->vertex(i)->point())
== ON_POSITIVE_SIDE);
}
template < class Gt, class Tds, class Itag >
void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
flip(Face_handle& f, int i)
{
// The following precondition prevents the test suit
// of triangulation to work on constrained Delaunay triangulation
//CGAL_triangulation_precondition(is_flipable(f,i));
Face_handle g = f->neighbor(i);
_tds.flip( &(*f), i);
int ig=g->index(f->vertex(i));
// set constraints to new triangles
Face_handle nfi=f->neighbor(i);
Face_handle nfj=f->neighbor(cw(i));
Face_handle ngi=g->neighbor(ig);
Face_handle ngj=g->neighbor(ccw(ig));
f->set_constraint(ccw(i),false);
g->set_constraint(cw(ig),false);
if (nfi->is_constrained(f->mirror_index(i)))
f->set_constraint(i,true);
else f->set_constraint(i,false);
if (nfj->is_constrained(f->mirror_index(cw(i))))
f->set_constraint(cw(i),true);
else f->set_constraint(cw(i),false);
if (ngi->is_constrained(g->mirror_index(ig)))
g->set_constraint(ig,true);
else g->set_constraint(ig,false);
if (ngj->is_constrained(g->mirror_index(ccw(ig))))
g->set_constraint(ccw(ig),true);
else g->set_constraint(ccw(ig),false);
}
template < class Gt, class Tds, class Itag >
void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
flip_around(Vertex_handle va)
// makes the triangles incident to vertex va Delaunay using flips
{
if (dimension() <= 1) return;
Face_handle f=va->face();
Face_handle next;
Face_handle start(f);
int i;
do {
i = f->index(va); // FRAGILE : DIM 1
next = f->neighbor(ccw(i)); // turns ccw around a
propagating_flip(f,i);
f=next;
} while(next != start);
}
template < class Gt, class Tds, class Itag >
void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
flip_around(List_vertices& new_vertices)
{
typename List_vertices::iterator itv=new_vertices.begin();
for( ; itv != new_vertices.end(); itv++) {
flip_around(*itv);
}
return;
}
template < class Gt, class Tds, class Itag >
void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
propagating_flip(Face_handle& f,int i)
// similar to the corresponding function in Delaunay_triangulation_2.h
{
if (!is_flipable(f,i)) return;
Face_handle ni = f->neighbor(i);
flip(f, i); // flip for constrained triangulations
propagating_flip(f,i);
i = ni->index(f->vertex(i));
propagating_flip(ni,i);
}
template < class Gt, class Tds, class Itag >
void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
propagating_flip(List_edges & edges)
// makes the triangulation Delaunay by flipping
// List edges contains an initial list of edges to be flipped
// Precondition : the output triangulation is Delaunay if the list
// edges contains all edges of the input triangulation that need to be
// flipped (plus possibly others)
{
int i, ii, indf, indn;
Face_handle ni, f,ff;
Edge ei,eni;
typename Ctr::Edge_set edge_set;
typename Ctr::Less_edge less_edge;
Edge e[4];
typename List_edges::iterator itedge=edges.begin();
// initialization of the set of edges to be flip
while (itedge != edges.end()) {
f=(*itedge).first;
i=(*itedge).second;
if (is_flipable(f,i)) {
eni=Edge(f->neighbor(i),f->mirror_index(i));
if (less_edge(*itedge,eni)) edge_set.insert(*itedge);
else edge_set.insert(eni);
}
++itedge;
}
// flip edges and updates the set of edges to be flipped
while (!(edge_set.empty())) {
f=(*(edge_set.begin())).first;
indf=(*(edge_set.begin())).second;
// erase from edge_set the 4 edges of the wing of the edge to be
// flipped (edge_set.begin) , i.e. the edges of the faces f and
// f->neighbor(indf) that are distinct from the edge to be flipped
ni = f->neighbor(indf);
indn=f->mirror_index(indf);
ei= Edge(f,indf);
edge_set.erase(ei);
e[0]= Edge(f,cw(indf));
e[1]= Edge(f,ccw(indf));
e[2]= Edge(ni,cw(indn));
e[3]= Edge(ni,ccw(indn));
for(i=0;i<4;i++) {
ff=e[i].first;
ii=e[i].second;
if (is_flipable(ff,ii)) {
eni=Edge(ff->neighbor(ii),ff->mirror_index(ii));
if (less_edge(e[i],eni)) {
edge_set.erase(e[i]);}
else {
edge_set.erase(eni);}
}
}
// here is the flip
flip(f, indf);
//insert in edge_set the 4 edges of the wing of the edge that
//have been flipped
e[0]= Edge(f,indf);
e[1]= Edge(f,cw(indf));
e[2]= Edge(ni,indn);
e[3]= Edge(ni,cw(indn));
for(i=0;i<4;i++) {
ff=e[i].first;
ii=e[i].second;
if (is_flipable(ff,ii)) {
eni=Edge(ff->neighbor(ii),ff->mirror_index(ii));
if (less_edge(e[i],eni)) {
edge_set.insert(e[i]);}
else {
edge_set.insert(eni);}
}
}
}
}
template < class Gt, class Tds, class Itag >
inline bool
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
test_conflict(const Point& p, Face_handle fh) const
// true if point P lies inside the circle circumscribing face fh
{
return ( side_of_oriented_circle(fh,p) == ON_POSITIVE_SIDE );
}
template < class Gt, class Tds, class Itag >
inline bool
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
test_conflict(Face_handle fh, const Point& p) const
// true if point P lies inside the circle circumscribing face fh
{
return test_conflict(p,fh);
}
template < class Gt, class Tds, class Itag >
void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
find_conflicts(const Point& p, std::list<Edge>& le, Face_handle hint) const
{
// sets in le the counterclocwise list of the edges of the boundary of the
// union of the faces in conflict with p
// an edge is represented by the incident face that is not in conflict with p
get_boundary_of_conflicts(p, std::back_inserter(le), hint);
}
template < class Gt, class Tds, class Itag >
inline
typename Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::Vertex_handle
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
virtual_insert(const Point & a, Face_handle start)
// virtual version of the insertion
{
return insert(a,start);
}
template < class Gt, class Tds, class Itag >
inline
typename Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::Vertex_handle
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
virtual_insert(const Point& a,
Locate_type lt,
Face_handle loc,
int li )
// virtual version of insert
{
return insert(a,lt,loc,li);
}
template < class Gt, class Tds, class Itag >
inline
typename Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::Vertex_handle
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
insert(const Point & a, Face_handle start)
// inserts a in the triangulation
// constrained edges are updated
// Delaunay property is restored
{
Vertex_handle va= Ctr::insert(a, start);
flip_around(va);
return va;
}
template < class Gt, class Tds, class Itag >
typename Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::Vertex_handle
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
insert(const Point& a, Locate_type lt, Face_handle loc, int li)
// insert a point p, whose localisation is known (lt, f, i)
// constrained edges are updated
// Delaunay property is restored
{
Vertex_handle va= Ctr::insert(a,lt,loc,li);
flip_around(va);
return va;
}
template < class Gt, class Tds, class Itag >
inline
typename Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::Vertex_handle
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
push_back(const Point &p)
{
return insert(p);
}
template < class Gt, class Tds, class Itag >
void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
triangulate_hole(List_faces& intersected_faces,
List_edges& conflict_boundary_ab,
List_edges& conflict_boundary_ba)
{
List_edges new_edges;
Ctr::triangulate_hole(intersected_faces,
conflict_boundary_ab,
conflict_boundary_ba,
new_edges);
propagating_flip(new_edges);
return;
}
template < class Gt, class Tds, class Itag >
inline void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
remove(Vertex_handle v)
// remove a vertex and updates the constrained edges of the new faces
// precondition : there is no incident constraints
{
CGAL_triangulation_precondition( v != NULL );
CGAL_triangulation_precondition( ! is_infinite(v));
CGAL_triangulation_precondition( ! are_there_incident_constraints(v));
if (dimension() <= 1) Ctr::remove(v);
else remove_2D(v);
return;
}
// template < class Gt, class Tds, class Itag >
// typename
// Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::Vertex_handle
// Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
// special_insert_in_edge(const Point & a, Face_handle f, int i)
// // insert point p in edge(f,i)
// // bypass the precondition for point a to be in edge(f,i)
// // update constrained status
// // this member fonction is not robust with exact predicates
// // and approximate construction. Should be removed
// {
// Vertex_handle vh=Ctr::special_insert_in_edge(a,f,i);
// flip_around(vh);
// return vh;
// }
template < class Gt, class Tds, class Itag >
void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
remove_2D(Vertex_handle v)
{
if (test_dim_down(v)) { _tds.remove_dim_down(&(*v)); }
else {
std::list<Edge> hole;
make_hole(v, hole);
std::list<Edge> shell=hole; //because hole will be emptied by fill_hole
fill_hole_delaunay(hole);
update_constraints(shell);
delete_vertex(v);
}
return;
}
template < class Gt, class Tds, class Itag >
void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
remove_incident_constraints(Vertex_handle v)
{
List_edges iconstraints;
if (are_there_incident_constraints(v,
std::back_inserter(iconstraints))) {
Ctr::remove_incident_constraints(v);
if (dimension()==2) propagating_flip(iconstraints);
}
return;
}
template < class Gt, class Tds, class Itag >
void
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
remove_constraint(Face_handle f, int i)
{
Ctr::remove_constraint(f,i);
if(dimension() == 2) {
List_edges le;
le.push_back(Edge(f,i));
propagating_flip(le);
}
return;
}
template < class Gt, class Tds, class Itag >
bool
Constrained_Delaunay_triangulation_2<Gt,Tds,Itag>::
is_valid(bool verbose, int level) const
{
bool result = Ctr::is_valid(verbose, level);
CGAL_triangulation_assertion( result );
Finite_faces_iterator fit= finite_faces_begin();
for (; fit != finite_faces_end(); fit++) {
for(int i=0;i<3;i++) {
result = result && !is_flipable(fit,i);
CGAL_triangulation_assertion( result );
}
}
return result;
}
CGAL_END_NAMESPACE
#endif // CGAL_CONSTRAINED_DELAUNAY_TRIANGULATION_2_H

View File

@ -4,13 +4,13 @@
CGAL_BEGIN_NAMESPACE
template <class Cont, class Pred>
class Filtred_container
class Filtered_container
{
Cont cont;
Pred test;
public:
Filtred_container(Pred p=Pred()) : cont(), test(p) {};
Filtred_container(Cont& c, Pred p=Pred()) : cont(c), test(p) {};
Filtered_container(Pred p=Pred()) : cont(), test(p) {};
Filtered_container(Cont& c, Pred p=Pred()) : cont(c), test(p) {};
typedef typename Cont::reference reference;
typedef typename Cont::iterator iterator;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,174 @@
#include <iostream>
#include <fstream>
#include <CGAL/IO/File_header_extended_OFF.h>
// to skip comments and EOF in the function read_poly
// // IO
// // write and read the constrained edges in the format:
// // number_of_edges
// // segment1
// // segment2
// // ...
// void write(std::ostream &f) const;
// void read(std::istream &f, bool dont_refine = false);
// // write and read a mesh in the Triangle .poly format
// // (see http://www-2.cs.cmu.edu/~quake/triangle.poly.html)
// void write_poly(std::ostream &f) const;
// void read_poly(std::istream &f, bool dont_refine = false);
CGAL_BEGIN_NAMESPACE
// IO
//the function that writes a file
template <class Tr>
void
write(const Conform_triangulation_2<Tr>& mesh, std::ostream &f)
{
typedef typename Conform_triangulation_2<Tr>::Finite_edges_iterator
Finite_edges_iterator;
f << mesh.number_of_constrained_edges() << std::endl;
for(Finite_edges_iterator eit = mesh.finite_edges_begin();
eit!=mesh.finite_edges_end();
++eit)
if((*eit).first->is_constrained((*eit).second))
{
f << (*eit).first->vertex(mesh.cw((*eit).second))->point() << " "
<< (*eit).first->vertex(mesh.ccw((*eit).second))->point() <<std::endl;
}
}
//the function that reads a file
template <class Tr>
void
read(Conform_triangulation_2<Tr>& mesh, std::istream &f)
{
typedef typename Conform_triangulation_2<Tr>::Point Point;
int nedges = 0;
mesh.clear();
f>>nedges;
for(int n = 0; n<nedges; n++) {
Point p1, p2;
f >> p1 >> p2;
mesh.insert_constraint(p1, p2);
}
}
//the function that write a Shewchuk Triangle .poly file
template <class Tr>
void
write_poly(const Conform_triangulation_2<Tr>& mesh, std::ostream &f)
{
typedef Conform_triangulation_2<Tr> Triangulation;
typedef typename Triangulation::Vertex_handle Vertex_handle;
typedef typename Triangulation::Finite_vertices_iterator
Finite_vertices_iterator;
typedef typename Triangulation::Finite_edges_iterator
Finite_edges_iterator;
std::map<Vertex_handle, unsigned int> index;
// write vertices
f << "# Shewchuk Triangle .poly file, produced by the CGAL::Mesh_2 package"
<< std::endl
<< "# Neither attributes nor boundary markers are used." << std::endl
<< mesh.number_of_vertices() << " " << 2 << " "
<< 0 << " " << 0 << std::endl;
f << std::endl;
unsigned int vertices_counter = 0;
for(Finite_vertices_iterator vit = mesh.finite_vertices_begin();
vit != mesh.finite_vertices_end();
++vit)
{
f << ++vertices_counter << " " << vit->point() << std::endl;
index[vit] = vertices_counter;
}
f << std::endl;
// write constrained edges
f << mesh.number_of_constrained_edges() << " " << 0 << std::endl;
unsigned int edges_counter = 0;
for(Finite_edges_iterator eit = mesh.finite_edges_begin();
eit != mesh.finite_edges_end();
++eit)
if((*eit).first->is_constrained((*eit).second))
f << ++edges_counter << " "
<< index[(*eit).first->vertex(mesh.cw((*eit).second))] << " "
<< index[(*eit).first->vertex(mesh.ccw((*eit).second))]
<< std::endl;
f << std::endl;
// // write seeds, assuming that the seeds unmarks faces
// unsigned int seeds_counter = 0;
// f << mesh.seeds.size() << std::endl;
// for(typename Seeds::const_iterator sit = seeds.begin();
// sit!=seeds.end(); ++sit)
// f << ++seeds_counter << " " << *sit << std::endl;
}
//the function that reads a Shewchuk Triangle .poly file
template <class Tr>
void
read_poly(Conform_triangulation_2<Tr>& mesh, std::istream &f)
{
typedef Conform_triangulation_2<Tr> Triangulation;
typedef typename Triangulation::Vertex_handle Vertex_handle;
typedef typename Triangulation::Point Point;
mesh.clear();
unsigned int number_of_points;
skip_comment_OFF(f);
f >> number_of_points;
skip_until_EOL(f);
skip_comment_OFF(f);
// read vertices
std::vector<Vertex_handle> vertices(number_of_points);
for(unsigned int i = 0; i < number_of_points; ++i)
{
unsigned int j;
Point p;
f >> j >> p;
skip_until_EOL(f); skip_comment_OFF(f);
vertices[--j] = mesh.insert(p);
}
// read segments
unsigned int number_of_segments;
f >> number_of_segments;
skip_until_EOL(f); skip_comment_OFF(f);
for(unsigned int k = 0; k < number_of_segments; ++k)
{
unsigned int l, v1, v2;
f >> l >> v1 >> v2;
skip_until_EOL(f); skip_comment_OFF(f);
mesh.insert_constraint(vertices[--v1], vertices[--v2]);
}
// read holes
unsigned int number_of_holes;
f >> number_of_holes;
for(unsigned int m = 0; m < number_of_holes; ++m)
{
unsigned int n;
Point p;
f >> n >> p;
skip_until_EOL(f); skip_comment_OFF(f);
//seeds.push_back(p);
}
}
CGAL_END_NAMESPACE

View File

@ -1,5 +1,5 @@
#include <CGAL/basic.h>
#include <CGAL/Filtred_container.h>
#include <CGAL/Filtered_container.h>
#include <CGAL/Random.h>
#include <list>
@ -13,7 +13,7 @@ public:
}
};
typedef CGAL::Filtred_container<std::list<int>, Is_odd> List;
typedef CGAL::Filtered_container<std::list<int>, Is_odd> List;
int main(int, char**)
{