last commit before migration to Git.

This commit is contained in:
Claudia Werner 2012-10-23 13:48:09 +00:00
parent 8ed86471dc
commit 6eec0d1567
7 changed files with 352 additions and 1226 deletions

2
.gitattributes vendored
View File

@ -4574,8 +4574,8 @@ Triangulation_on_sphere_2/include/CGAL/Triangulation_sphere_traits_2.h -text
Triangulation_on_sphere_2/include/CGAL/algebraic_kernel_for_spheres_extensions_ntC3.h -text
Triangulation_on_sphere_2/include/CGAL/static_in_cone_ntC3.h -text
Triangulation_on_sphere_2/test/bugs_minimal_examples.cpp -text
Triangulation_on_sphere_2/test/test_random.cpp -text
Triangulation_on_sphere_2/test/test_regular_sphere_traits.cpp -text
Triangulation_on_sphere_2/test/test_regular_triangulation_on_sphere_2.cpp -text
Triangulation_on_sphere_2/test/test_triangulation_on_sphere_2.cpp -text
Voronoi_diagram_2/doc_tex/Voronoi_diagram_2/voronoi.png -text
wininst/developer_scripts/CGAL.bmp -text svneol=unset#image/bmp

View File

@ -31,7 +31,7 @@ class Regular_triangulation_on_sphere_2
{
typedef Regular_triangulation_on_sphere_2<Gt, Tds> Self;
typedef Triangulation_on_sphere_2<Gt,Tds> Base;
typedef Triangulation_on_sphere_2<Gt,Tds> Base;
@ -41,7 +41,6 @@ public:
typedef Tds Triangulation_data_structure;
typedef Gt Geom_traits;
typedef typename Gt::Point_2 Point;
typedef typename Base::size_type size_type;
typedef typename Base::Face_handle Face_handle;
typedef typename Base::Vertex_handle Vertex_handle;
@ -80,6 +79,7 @@ public:
using Base ::show_face;
using Base ::show_vertex;
using Base::clear;
using Base::delete_faces;
#endif
public:
@ -93,10 +93,10 @@ public:
bool is_valid(bool verbose = false, int level = 0) const;
bool is_valid_face(Face_handle fh,bool verbose = false, int level = 0 ) const;
bool is_valid_vertex(Vertex_handle fh, bool verbose = false, int level = 0) const;
bool is_plane() const;
bool test_conflict(const Point &p, Face_handle fh) const;
bool update_negative_faces(Vertex_handle v=Vertex_handle());
bool check_neighboring()
{
@ -137,53 +137,22 @@ public:
Vertex_handle insert_hole_approach_2(const Point &p, Locate_type lt, Face_handle loc, int li) ;
Vertex_handle insert_in_plane_triangulation(const Point &p);
bool test_conflict(const Point &p, Face_handle fh) const;
bool update_negative_faces(Vertex_handle v=Vertex_handle());
//REMOVAL
void remove_degree_3(Vertex_handle v, Face_handle f = Face_handle());
void remove(Vertex_handle v);
void remove_1D(Vertex_handle v);
void remove_2D(Vertex_handle v);
bool test_dim_down(Vertex_handle v);
bool test_dim_up(Point p);
bool test_dim_up(const Point &p)const;
void fill_hole_regular(std::list<Edge> & hole);
//TEMPLATE MEMBERS
//----------------------------------------------------------------------HOLE APPROACH
template < class InputIterator >
int insert(InputIterator first, InputIterator last)
{
int n = number_of_vertices();
std::vector<Point> points (first, last);
std::random_shuffle (points.begin(), points.end());
//~ spatial_sort (points.begin(), points.end(), geom_traits());
spatial_sort (points.begin(), points.end());
Face_handle hint;
for (typename std::vector<Point>::const_iterator p = points.begin(),
end = points.end();
p != end; ++p)
hint = insert (*p, hint)->face();
return number_of_vertices() - n;
}
template<class FaceIt>
void delete_faces(FaceIt face_begin, FaceIt face_end)
{
FaceIt fit=face_begin;
for(;fit!=face_end;++fit)
{
delete_face(*fit);
}
}
template <class Stream>
Stream &write_vertices(Stream &out,std::vector<Vertex_handle> &t)
{
@ -198,11 +167,11 @@ Stream &write_vertices(Stream &out,std::vector<Vertex_handle> &t)
return out;
}
template <class Stream>
Stream &write_triangulation_to_off_2(Stream &out,Stream &out2){
template <class Stream>
Stream &write_triangulation_to_off_2(Stream &out,Stream &out2){
// Points of triangulation
for (Faces_iterator it = this->_tds.face_iterator_base_begin(); it != faces_end(); it++) {
for (Faces_iterator it = this->_tds.face_iterator_base_begin(); it != faces_end(); it++) {
if(!it->is_negative()
/*(t.orientation(it->vertex(0)->point(),it->vertex(1)->point(),it->vertex(2)->point())==1)*/
){//assert(orientation(it)==POSITIVE);
@ -306,18 +275,31 @@ Stream &write_edges_to_off(Stream &out,FaceIt face_begin, FaceIt face_end){
return out;
}
template < class InputIterator >
int insert(InputIterator first, InputIterator last)
{
int n = number_of_vertices();
std::vector<Point> points (first, last);
std::random_shuffle (points.begin(), points.end());
//~ spatial_sort (points.begin(), points.end(), geom_traits());
spatial_sort (points.begin(), points.end());
Face_handle hint;
for (typename std::vector<Point>::const_iterator p = points.begin(),end = points.end(); p != end; ++p)
hint = insert (*p, hint)->face();
return number_of_vertices() - n;
}
template <class OutputItFaces, class OutputItBoundaryEdges>
std::pair<OutputItFaces,OutputItBoundaryEdges>
get_conflicts_and_boundary(const Point &p, OutputItFaces fit, OutputItBoundaryEdges eit,
Face_handle start ) const {
Face_handle fh ) const {
CGAL_triangulation_precondition( dimension() == 2);
Face_handle fh = start;
CGAL_triangulation_precondition(test_conflict(p,fh));
CGAL_triangulation_precondition(test_conflict(p,fh));
Face_handle tmp;
*fit++ = fh; //put fh in OutputItFaces
*fit++ = fh; //put fh in OutputItFaces
fh->set_in_conflict_flag(1);
std::pair<OutputItFaces,OutputItBoundaryEdges>
pit = std::make_pair(fit,eit);
@ -351,65 +333,84 @@ propagate_conflicts (const Point &p, Face_handle fh, int i,
}
return pit;
}
};
//----------------------------------------------------------------------CHECK---------------------------------------------------------------//
template <class Gt, class Tds>
bool
Regular_triangulation_on_sphere_2<Gt, Tds>::
is_plane()const{
bool plane = true;
if(dimension()==2)
return false;
if(number_of_vertices() > 3){
Vertices_iterator it1 = vertices_begin(),
it2(it1), it3(it1), it4(it1);
++it2;
++it3; ++it3;
++it4; ++it4; ++it4;
while( it4 != vertices_end()) {
Orientation s = Base ::power_test( it1->point(),it2->point(),it3->point(), it4->point());
plane = plane && s == ON_ORIENTED_BOUNDARY ;
++it1 ; ++it2; ++it3;++it4;
if (!plane)
return plane;
}return true;
}
if(number_of_vertices()==3)
return true;
return plane;
}
template < class Gt, class Tds >
bool
Regular_triangulation_on_sphere_2<Gt,Tds>::
is_valid(bool verbose, int level ) const //int level
is_valid(bool verbose, int level ) const //int level
{
bool result = true;
if ( !this-> _tds.is_valid(verbose,level) ) {
if (verbose)
std::cerr << "invalid data structure" << std::endl;
CGAL_triangulation_assertion(false);
return false;
CGAL_triangulation_assertion(false);
return false;
}
for(Faces_iterator fit = faces_begin(); fit != faces_end(); ++fit) {
result = result && is_valid_face(fit, verbose, level);
CGAL_triangulation_assertion(result);
}
for(Vertices_iterator vit = vertices_begin(); vit != vertices_end(); ++vit) {
result = result && is_valid_vertex(vit);
}CGAL_triangulation_assertion(result);
for(Faces_iterator fit = faces_begin(); fit != faces_end(); ++fit)
is_valid_face(fit, verbose, level);
for(Vertices_iterator vit = vertices_begin(); vit != vertices_end(); ++vit)
is_valid_vertex(vit);
switch(dimension()) {
case 0 :
break;
case 1:
if (number_of_vertices() > 3 ) {
Vertices_iterator it1 = vertices_begin(),
it2(it1), it3(it1), it4(it1);
++it2;
++it3; ++it3;
++it4; ++it4; ++it4;
while( it4 != vertices_end()) {
Orientation s = Base ::power_test( it1->point(),it2->point(),it3->point(), it4->point());
result = result && s == ON_ORIENTED_BOUNDARY ;
CGAL_triangulation_assertion(result);
++it1 ; ++it2; ++it3;++it4;
}
}
break;
CGAL_triangulation_assertion(this->is_plane());
break;
case 2 :
for(Faces_iterator it=faces_begin(); it!=faces_end(); it++) {
Orientation s = orientation(it->vertex(0)->point(), it->vertex(1)->point(), it->vertex(2)->point());
result = result && ( s == LEFT_TURN || it->is_negative());
CGAL_triangulation_assertion(result);
}
CGAL_triangulation_assertion(result);
}
result = result && (number_of_faces() == 2*(number_of_vertices()) - 4 );
CGAL_triangulation_assertion( result);
@ -417,10 +418,9 @@ Regular_triangulation_on_sphere_2<Gt,Tds>::
}
// in any dimension
if(verbose) {
std::cerr << " number of vertices " << number_of_vertices() << "\t"
<< std::endl;
}
if(verbose)
std::cerr << " number of vertices " << number_of_vertices() << "\t" << std::endl;
CGAL_triangulation_assertion( result);
return result;
}
@ -431,20 +431,19 @@ bool
Regular_triangulation_on_sphere_2<Gt,Tds>::
is_valid_vertex(Vertex_handle vh, bool verbose, int level) const
{
bool result = true;
result = result && vh->face()->has_vertex(vh);
if ( !result )
if(verbose) {
std::cerr << " from is_valid_vertex " << std::endl;
bool result = vh->face()->has_vertex(vh);
if ( !result ) {
if(verbose) {
std::cerr << " from is_valid_vertex " << std::endl;
std::cerr << "normal vertex " << &(*vh) << std::endl;
std::cerr << vh->point() << " " << std::endl;
std::cerr << "vh_>face " << &*(vh->face()) << " " << std::endl;
show_face(vh->face());
show_face(vh->face());
}
CGAL_triangulation_assertion(result);
return result;
CGAL_triangulation_assertion(false);
return false;
}
return true;
}
template < class Gt, class Tds >
@ -452,23 +451,19 @@ bool
Regular_triangulation_on_sphere_2<Gt,Tds>::
is_valid_face(Face_handle fh, bool verbose, int level) const
{
bool result = true;
CGAL_triangulation_assertion(result);
result = fh->get_in_conflict_flag()==0;
typename Vertex_list::iterator vlit = fh->vertex_list().begin(),
vldone = fh->vertex_list().end();
for (; vlit != vldone; vlit++) {
result = result && Base::power_test(fh, (*vlit)->point()) == ON_NEGATIVE_SIDE;
bool result = fh->get_in_conflict_flag()==0;
for (int i = 0; i<+2; i++) {
Orientation test = Base::power_test(fh, fh->vertex(i)->point());
result = result && test == ON_ORIENTED_BOUNDARY;
CGAL_triangulation_assertion(result);
result = result && ((*vlit)->face() == fh);
if (!result)
if (verbose)
show_face(fh);
}
if (!result)
if (verbose){
std::cerr<<" from is_valid_face "<<std::endl;
std::cerr<<" face "<<std::endl;
show_face(fh);
}
CGAL_triangulation_assertion(result);
}
return result;
}
@ -483,6 +478,8 @@ test_conflict(const Point &p, Face_handle fh) const
//----------------------------------------------------------------------INSERTION-------------------------------------------------------------//
template < class Gt, class Tds >
typename Regular_triangulation_on_sphere_2<Gt,Tds>::Vertex_handle
Regular_triangulation_on_sphere_2<Gt,Tds>::
@ -490,16 +487,18 @@ insert(const Point &p, Face_handle start)
{
Locate_type lt;
int li;
Face_handle loc = locate(p, lt, li, start);
Face_handle loc = Base::locate(p, lt, li, start);
return insert_hole_approach_2(p, lt, loc, li);
}
template < class Gt, class Tds>
typename Regular_triangulation_on_sphere_2<Gt,Tds>::Vertex_handle
Regular_triangulation_on_sphere_2<Gt, Tds>::
insert_in_plane_triangulation(const Point &p){
CGAL_triangulation_precondition(!test_dim_up(p));
CGAL_triangulation_precondition(dimension()==1);
Face_handle loc;
Edges_iterator eit=edges_begin();
@ -509,10 +508,9 @@ insert_in_plane_triangulation(const Point &p){
Vertex_handle v2 = f -> vertex(1);
if(orientation(v1->point(), v2->point(), p)==RIGHT_TURN){
loc = f;
break;
break;
}
eit++;
} eit++;
}while( eit!=edges_end());
Vertex_handle v0 = loc->vertex(0);
@ -545,7 +543,7 @@ Regular_triangulation_on_sphere_2<Gt,Tds>::
insert_first(const Point& p)
{
CGAL_triangulation_precondition(number_of_vertices() == 0);
Vertex_handle v =this-> _tds.insert_first();
Vertex_handle v =this->_tds.insert_first();
v->set_point(p);
return v;
}
@ -556,8 +554,7 @@ Regular_triangulation_on_sphere_2<Gt,Tds>::
insert_second(const Point& p)
{
CGAL_triangulation_precondition(number_of_vertices() == 1);
Vertex_handle v =this-> _tds.insert_second();
Vertex_handle v =this->_tds.insert_second();
v->set_point(p);
return v;
}
@ -570,18 +567,20 @@ Regular_triangulation_on_sphere_2<Gt,Tds>::
insert_hole_approach_2(const Point &p, Locate_type lt, Face_handle loc, int li) {
//!!!!!!!!!!!!TODO point is valide!!!!!!!!!!!!!!!!!!!!!!!!
Vertex_handle v;
if( dimension() == -2)
Vertex_handle v;
switch (dimension()){
case -2 :
return insert_first(p);
if( dimension() == -1)
case -1:
return insert_second(p);
if( dimension() == 0)
case 0:
return insert_outside_affine_hull_regular(p);
if(dimension() == 1){
case 1:
if(test_dim_up(p)){
Face_handle f=edges_begin()->first;
Vertex_handle v1=f->vertex(0);
@ -591,24 +590,17 @@ insert_hole_approach_2(const Point &p, Locate_type lt, Face_handle loc, int li)
v = insert_outside_affine_hull_regular(p,orient==COLLINEAR);
return v;
}
else {
v= insert_in_plane_triangulation(p);
return v;
}
}
if (dimension()==2){
return v;
}
case 2:
std::vector<Face_handle> faces;
std::vector<Edge> edges;
faces.reserve(32);
edges.reserve(32);
get_conflicts_and_boundary(p, std::back_inserter(faces), std::back_inserter(edges), loc);
v =this->_tds.star_hole(edges.begin(), edges.end());
v->set_point(p);
@ -618,11 +610,9 @@ insert_hole_approach_2(const Point &p, Locate_type lt, Face_handle loc, int li)
//if( lt != FACE )
update_negative_faces(v);
return v;
}
}
return v;
}
}
template <class Gt, class Tds >
typename Triangulation_on_sphere_2<Gt,Tds>::Vertex_handle
@ -737,16 +727,15 @@ update_negative_faces(Vertex_handle v)
Face_circulator fc=incident_faces(v,v->face());
Face_circulator done(fc);
//bool neg_found=false;
do{
if(orientation(fc)==NEGATIVE){
fc->negative()=true;
neg_found=true;
this->_negative=fc;
fc->negative()=true;
neg_found=true;
this->_negative=fc;
}
else{
fc->negative()=false;
fc->negative()=false;
}
}while(++fc!=done);
@ -777,15 +766,15 @@ Regular_triangulation_on_sphere_2<Gt,Tds>::
remove(Vertex_handle v )
{
CGAL_triangulation_precondition( v != Vertex_handle() );
if(number_of_vertices()<=3){
if(number_of_vertices()<=3)
this->_tds.remove_dim_down(v);
}
else if(dimension()==2) {
else if(dimension()==2)
remove_2D (v);
}
else {
else
remove_1D(v);
}
}
@ -817,7 +806,7 @@ remove_2D(Vertex_handle v)
std::list<Edge> hole;
make_hole(v, hole);
fill_hole_regular(hole);
delete_vertex(v);
//delete_vertex(v);
}
return;
}
@ -852,7 +841,7 @@ test_dim_down(Vertex_handle v)
template <class Gt, class Tds >
bool
Regular_triangulation_on_sphere_2<Gt,Tds>::
test_dim_up(Point p){
test_dim_up(const Point &p) const{
// dimension of triangulation increase from 1 to 2 iff the new vertex in not coplanar with the old vertices
//first three points of triangulation

View File

@ -23,12 +23,13 @@
#include <CGAL/Random.h>
#include <CGAL/spatial_sort.h>
#include <CGaL/Triangulation_2.h>
//TO DO
//oriented_side
//insertion, location, removal dim 0,1
//, location, dim 0,1
//March locate 2D improve code and cases Vertex and Edge of boundary
//Line face circulator & marchlocate LFC
//includes_edge
@ -58,10 +59,14 @@ class Triangulation_on_sphere_2
friend std::istream& operator>> <>
(std::istream& is, Triangulation_on_sphere_2 &tr);
typedef Triangulation_on_sphere_2<Gt,Tds> Self;
public:
typedef Tds Triangulation_data_structure;
typedef Gt Geom_traits;
typedef Triangulation_2<Gt, Tds> Triangulation_2;
typedef typename Geom_traits::Point_2 Point;
typedef typename Geom_traits::Orientation_2 Orientation_2;
typedef typename Geom_traits::Coradial_sphere_2 Coradial_sphere_2;
@ -158,8 +163,8 @@ size_type number_of_faces() const{return _tds.number_of_faces();}
Oriented_side power_test(const Point &p, const Point &r) const;
Oriented_side power_test(const Face_handle &f,const Point &p) const;
Oriented_side power_test(const Face_handle& f, int i, const Point &p) const;
Oriented_side oriented_side(const Point &p0, const Point &p1,const Point &p2, const Point &p) const;
Bounded_side bounded_side(const Point &p0, const Point &p1,const Point &p2, const Point &p) const;
//Oriented_side oriented_side(const Point &p0, const Point &p1,const Point &p2, const Point &p) const;
//Bounded_side bounded_side(const Point &p0, const Point &p1,const Point &p2, const Point &p) const;
Oriented_side oriented_side(Face_handle f, const Point &p) const;
bool xy_equal(const Point& p, const Point& q) const;
bool collinear_between(const Point& p, const Point& q, const Point& r) const;
@ -258,13 +263,8 @@ size_type number_of_faces() const{return _tds.number_of_faces();}
{
FaceIt fit=face_begin;
for(;fit!=face_end;++fit)
{
delete_face(*fit);
}
delete_face(*fit);
}
};
@ -331,8 +331,6 @@ swap(Triangulation_on_sphere_2 &tr)
tr._gt = t;
}
//ACCESS FUNCTION
//CHECKING
template <class Gt, class Tds >
@ -397,10 +395,7 @@ is_face(Vertex_handle v1, Vertex_handle v2, Vertex_handle v3) const
template <class Gt, class Tds >
inline bool
Triangulation_on_sphere_2<Gt, Tds>::
is_face(Vertex_handle v1,
Vertex_handle v2,
Vertex_handle v3,
Face_handle &fr) const
is_face(Vertex_handle v1, Vertex_handle v2, Vertex_handle v3,Face_handle &fr) const
{
return _tds.is_face(v1, v2, v3, fr);
}
@ -410,9 +405,7 @@ is_face(Vertex_handle v1,
template <class Gt, class Tds >
typename Triangulation_on_sphere_2<Gt, Tds>::Face_handle
Triangulation_on_sphere_2<Gt, Tds>::
march_locate_1D(const Point& t,
Locate_type& lt,
int& li) const
march_locate_1D(const Point& t, Locate_type& lt, int& li) const
{
Face_handle f = edges_begin()->first;
@ -542,10 +535,6 @@ march_locate_2D(Face_handle c,
}
}
// Instead of testing c's edges in a random order we do the following
// until we find a neighbor to go further:
// As we come from prev we do not have to check the edge leading to prev
@ -855,154 +844,48 @@ orientation(const Face_handle f) const
return orientation(f->vertex(0)->point(),f->vertex(1)->point(),f->vertex(2)->point());
}
/*
template <class Gt, class Tds >
template < class Gt, class Tds >
Oriented_side
Triangulation_on_sphere_2<Gt, Tds>::
oriented_side(const Point &p0, const Point &p1,const Point &p2, const Point &p) const {
Orientation o1 = orientation(p0, p1, p),
o2 = orientation(p1, p2, p),
o3 = orientation(p2, p0, p);
if(orientation(p0, p1, p2)==POSITIVE){
if(o1==POSITIVE)
if(o2==POSITIVE)
if(o3==POSITIVE)
return ON_POSITIVE_SIDE;
if (o1 == COLLINEAR){
if (o2 == COLLINEAR || o3 == COLLINEAR) return ON_ORIENTED_BOUNDARY;
return ON_NEGATIVE_SIDE;
}
if (o2 == COLLINEAR){
if (o1 == COLLINEAR || o3 == COLLINEAR) return ON_ORIENTED_BOUNDARY;
return ON_NEGATIVE_SIDE;
}
if (o3 == COLLINEAR){
if (o2 == COLLINEAR || o1 == COLLINEAR) return ON_ORIENTED_BOUNDARY;
return ON_NEGATIVE_SIDE;
}
if(o1 == COLLINEAR || o2==COLLINEAR || o3==COLLINEAR)
return ON_ORIENTED_BOUNDARY;
return ON_NEGATIVE_SIDE;
}else{
if(o1==POSITIVE && o2==POSITIVE && o3==POSITIVE)
return ON_POSITIVE_SIDE;
if(o1==NEGATIVE && o2==NEGATIVE && o3==NEGATIVE )
return ON_NEGATIVE_SIDE;
else
return ON_NEGATIVE_SIDE;
}
}*/
Triangulation_on_sphere_2<Gt,Tds>::
power_test(const Face_handle &f, const Point &p) const
{
return power_test(f->vertex(0)->point(), f->vertex(1)->point(), f->vertex(2)->point(),p);
}
template < class Gt, class Tds >
Oriented_side
Triangulation_on_sphere_2<Gt,Tds>::
power_test(const Face_handle &f, const Point &p) const
{
return power_test(f->vertex(0)->point(),
f->vertex(1)->point(),
f->vertex(2)->point(),p);
}
template < class Gt, class Tds >
Oriented_side
Triangulation_on_sphere_2<Gt,Tds>::
power_test(const Face_handle& f, int i,
const Point &p) const
{
CGAL_triangulation_precondition (
orientation(f->vertex(ccw(i))->point(),
f->vertex( cw(i))->point(),
p)
template < class Gt, class Tds >
Oriented_side
Triangulation_on_sphere_2<Gt,Tds>::
power_test(const Face_handle& f, int i, const Point &p) const
{
CGAL_triangulation_precondition ( orientation(f->vertex(ccw(i))->point(),
f->vertex( cw(i))->point(), p)
== COLLINEAR);
return power_test(f->vertex(ccw(i))->point(),
f->vertex( cw(i))->point(),
p);
}
template < class Gt, class Tds >
inline
Oriented_side
Triangulation_on_sphere_2<Gt,Tds>::
power_test(const Point &p,
const Point &q,
const Point &r,
const Point &s) const
{
return geom_traits().power_test_2_object()(p,q,r,s);
}
return power_test(f->vertex(ccw(i))->point(), f->vertex( cw(i))->point(), p);
}
template < class Gt, class Tds >
inline
Oriented_side
Triangulation_on_sphere_2<Gt,Tds>::
power_test(const Point &p,
const Point &q,
const Point &r) const
{
if(number_of_vertices()==2)
if(orientation_1(p,q)==COLLINEAR)
template < class Gt, class Tds >
inline
Oriented_side
Triangulation_on_sphere_2<Gt,Tds>::
power_test(const Point &p, const Point &q, const Point &r, const Point &s) const
{
return geom_traits().power_test_2_object()(p,q,r,s);
}
template < class Gt, class Tds >
inline
Oriented_side
Triangulation_on_sphere_2<Gt,Tds>::
power_test(const Point &p, const Point &q, const Point &r) const
{
if(number_of_vertices()==2)
if(orientation_1(p,q)==COLLINEAR)
return ON_POSITIVE_SIDE;
return geom_traits().power_test_2_object()(p,q,r);
}
return geom_traits().power_test_2_object()(p,q,r);
}
/*
template <class Gt, class Tds >
Bounded_side
Triangulation_on_sphere_2<Gt, Tds>::
bounded_side(const Point &p0, const Point &p1,
const Point &p2, const Point &p) const
{
// return position of point p with respect to triangle p0p1p2, depends on the orientation of the vertives
CGAL_triangulation_precondition( orientation(p0, p1, p2) != COLLINEAR);
Orientation o1 = orientation(p0, p1, p),
o2 = orientation(p1, p2, p),
o3 = orientation(p2, p0, p);
if (o1 == COLLINEAR){
if (o2 == COLLINEAR || o3 == COLLINEAR) return ON_BOUNDARY;
if (o2 == ON_NEGATIVE_SIDE && o3 == ON_NEGATIVE_SIDE) return ON_BOUNDARY;
return ON_UNBOUNDED_SIDE;
}
if (o2 == COLLINEAR){
if (o3 == COLLINEAR) return ON_BOUNDARY;
if (o3 == ON_NEGATIVE_SIDE && o1 == ON_NEGATIVE_SIDE) return ON_BOUNDARY;
return ON_UNBOUNDED_SIDE;
}
if (o3 == COLLINEAR){
if (o1 == ON_NEGATIVE_SIDE && o2 == ON_NEGATIVE_SIDE) return ON_BOUNDARY;
return ON_UNBOUNDED_SIDE;
}
// from here none ot, o1, o2 and o3 are known to be non null
if (o1 == o2 && o2 == o3) return ON_BOUNDED_SIDE;
return ON_UNBOUNDED_SIDE;
}
template <class Gt, class Tds >
Oriented_side
Triangulation_on_sphere_2<Gt, Tds>::
oriented_side(Face_handle f, const Point &p) const
{
CGAL_triangulation_precondition ( dimension()==2);
return oriented_side(f->vertex(0)->point(),
f->vertex(1)->point(),
f->vertex(2)->point(),
p);
}
*/
template <class Gt, class Tds >
bool
Triangulation_on_sphere_2<Gt, Tds>::
@ -1015,8 +898,7 @@ template <class Gt, class Tds >
bool
Triangulation_on_sphere_2<Gt, Tds>::
collinear_between(const Point& p, const Point& q, const Point& r) const
{
// return true if r lies inside the cone defined by trait.sphere, p and q
{ // return true if r lies inside the cone defined by trait.sphere, p and q
return geom_traits().inside_cone_2_object()(p,q,r);
}
//------------------------------------------------------------------------------DEBUG-------------------------------------------------
@ -1026,6 +908,7 @@ void
Triangulation_on_sphere_2<Gt, Tds>::
show_all() const
{
//Triangulation_2::show_all();
std::cerr<< "AFFICHE TOUTE LA TRIANGULATION :"<<std::endl;
std::cerr << std::endl<<"====> "<< this;
std::cerr << " dimension " << dimension() << std::endl;
@ -1071,7 +954,8 @@ number_of_negative_faces()
{
int nb=0;
for(Faces_iterator it=faces_begin();it!=faces_end();++it)
{if(it->is_negative())nb++;}
if(it->is_negative())
nb++;
return nb;
}
@ -1152,36 +1036,10 @@ template <class Gt, class Tds >
void
Triangulation_on_sphere_2<Gt, Tds>::
make_hole ( Vertex_handle v, std::list<Edge> & hole)
{
std::list<Face_handle> to_delete;
Face_handle f, fn;
int i, in ;
Vertex_handle vv;
Face_circulator fc = incident_faces(v);
Face_circulator done(fc);
do {
f = fc; fc++;
i = f->index(v);
fn = f->neighbor(i);
in = fn->index(f);
vv = f->vertex(cw(i));
if( vv->face()== f) vv->set_face(fn);
vv = f->vertex(ccw(i));
if( vv->face()== f) vv->set_face(fn);
fn->set_neighbor(in, Face_handle());
hole.push_back(Edge(fn,in));
to_delete.push_back(f);
}
while(fc != done);
while (! to_delete.empty()){
delete_face(to_delete.front());
to_delete.pop_front();
}
return;
{
return this->_tds.make_hole(v, hole);
}
template <class Gt, class Tds >
inline
void

View File

@ -63,10 +63,7 @@ Vertex_handle v4 = rtos.insert(p4);
rtos.is_valid();
rtos.remove(v5);*/
//insert coplanar Points. Points are coplanar but not coplanar with the center of the sphere
rtos.clear();
Point_3 p0 = Point_3(0,0,radius);
@ -82,7 +79,7 @@ Vertex_handle v4 = rtos.insert(p4);
Vertex_handle v22 = rtos.insert(p22);
Vertex_handle v23 = rtos.insert(p23);
rtos.show_vertex(v23);
Vertex_handle v24 = rtos.insert(p24);
@ -133,6 +130,11 @@ Vertex_handle v4 = rtos.insert(p4);
rtos.show_all();
rtos.remove(v27);

View File

@ -0,0 +1,145 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Regular_triangulation_sphere_traits_2.h>
#include <CGAL/Regular_triangulation_on_sphere_2.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/point_generators_2.h>
#include <fstream>
#include <CGAL/Timer.h>
#include <CGAL/number_utils.h>
#include <CGAL/squared_distance_3.h>
#include <cmath>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Regular_triangulation_sphere_traits_2<K> Gt;
typedef CGAL::Regular_triangulation_on_sphere_2<Gt> RTOS;
typedef RTOS::Vertex_handle Vertex_handle;
typedef RTOS::Face_handle Face_handle;
typedef RTOS::Point Point;
typedef RTOS::Faces_iterator Face_iterator;
typedef RTOS::Vertices_iterator Vertex_iterator;
typedef RTOS::Locate_type Locate_type;
typedef RTOS::Edge Edge;
bool is_ok(K::Point_3 p, std::vector<K::Point_3> po, double minDist2, int ind)
{
bool ok= true;
for(int j= 0; j<ind; j++){
if( squared_distance(p, po.at(j))<=minDist2 ){
ok = false;
}
}
return ok;
}
int main(){
int nu_of_pts;
double radius;
nu_of_pts =10000;
radius=6000000;
//radius = 1;
//double minDist = radius*2e-25;
double minDist = radius * pow (2, -25);
double minDist2 = pow(minDist, 2);
int invalid = 0;
int random = 0;
CGAL::Timer t;
for(int i=1; i<= 1; i++){
random++;
std::cout<<" ************************* run "<< random << "**********************"<<std::endl;
CGAL::Random random(nu_of_pts);
typedef CGAL::Creator_uniform_3<double, K::Point_3> Creator;
CGAL::Random_points_on_sphere_3<K::Point_3, Creator> on_sphere(radius);
RTOS tos;
std::vector<K::Point_3> points;
std::vector<Vertex_handle> vertices;
vertices.reserve(nu_of_pts*2);
for (int count=0; count<nu_of_pts; count++) {
K::Point_3 p = *on_sphere;
double tmp = p.x();
double tmp1 = p.y();
double tmp2 = p.z();
p=K::Point_3(fabs(tmp), fabs(tmp1), fabs(tmp2));
//points.push_back(*on_sphere);
points.push_back(p);
on_sphere++;
}
for (int count=0; count<nu_of_pts; count++) {
K::Point_3 p = *on_sphere;
double tmp = p.x();
double tmp1 = p.y();
double tmp2 = p.z();
p=K::Point_3(-1*fabs(tmp), -1*fabs(tmp1), -1*fabs(tmp2));
points.push_back(p);
on_sphere++;
}
t.start();
//====insert new points============
for (int count=0; count<nu_of_pts*2; count++) {
std::cout<< "================= point number "<< count+1 <<" =================="<<std::endl;
K::Point_3 p = points.at(count);
if(is_ok(p, points, minDist2, count)){
Vertex_handle v = tos.insert(p);
vertices.push_back(v);
}
else {
std::cout<<"invalide point"<<std::endl;
invalid ++;
}
//tos.is_valid(true);
}
tos.is_valid();
std::cout<<"starting to remove"<<std::endl;
//==remove points=============================
std::random_shuffle(vertices.begin(), vertices.end());
for( int i=0; i< (int)vertices.size(); i++){
tos.remove(vertices.at(i));
std::cout<<tos.number_of_vertices()<<std::endl;
//tos.is_valid();
}
t.stop();
tos.show_all();
std::cout<<"running time"<< t.time()<<std::endl;
}
}

View File

@ -1,4 +1,3 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Regular_triangulation_sphere_traits_2.h>
#include <CGAL/enum.h>

View File

@ -1,867 +0,0 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Regular_triangulation_sphere_traits_2.h>
#include <CGAL/Regular_triangulation_on_sphere_2.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/point_generators_2.h>
#include <fstream>
#include <CGAL/Timer.h>
#include <CGAL/number_utils.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Regular_triangulation_sphere_traits_2<K> Gt;
typedef CGAL::Regular_triangulation_on_sphere_2<Gt> RTOS;
typedef RTOS::Vertex_handle Vertex_handle;
typedef RTOS::Face_handle Face_handle;
typedef RTOS::Point Point;
typedef RTOS::Faces_iterator Face_iterator;
typedef RTOS::Vertices_iterator Vertex_iterator;
typedef RTOS::Locate_type Locate_type;
typedef RTOS::Edge Edge;
typedef RTOS::Hidden_vertices_iterator Hidden_points_iterator;
template <class Stream>
Stream &write_vertices(Stream &out,std::vector<Vertex_handle> &t);
template <class Stream, class Triangulation>
Stream &write_vertices(Stream &out, Triangulation &t);
template <class Stream>
Stream &write_points(Stream &out,std::vector<Point> &t);
template <class Stream>
Stream &write_face_to_off(Stream &out, Face_handle loc);
template <class Stream, class Triangulation>
Stream &write_triangulation_to_off_2(Stream &out,Stream &out2, Triangulation &t);
template <class Stream, class Triangulation>
Stream &write_hpts_to_off(Stream &out, Triangulation &t);
template <class Stream, class Triangulation>
Stream &write_triangulation_to_off(Stream &out, Triangulation &t);
int main()
{
RTOS tr_2_h;
RTOS tr_2_s;
RTOS tr;
RTOS tr2_1;
RTOS tr2_2;
RTOS tr2_3;
RTOS tr1_1;
RTOS tr0_1;
Locate_type lt;
int li;
Face_handle Loc_result;
Face_handle start;
std::ofstream verts("verts.off");
std::ofstream pos("pos.off");
std::ofstream neg("neg.off");
//std::ofstream pos2("pos2.off");
//std::ofstream neg2("neg2.off");
std::ofstream hpts("hpts.off");
//std::ofstream hpts2("hpts2.off");
/*--------------------------*/
// TEST INPUTS //
/*--------------------------*/
// SPHERES
Point S1=Point(0,0,0);
// POINTS
Point p1(1,0,0);
Point p2(0,1,0);
Point p3(0,0,1);
Point p4(-1/sqrt(3.),-1/sqrt(3.),-1/sqrt(3.));
//on a circle z=0
Point P0=Point(1,0,0);
Point P1=Point(1/sqrt(2.),1/sqrt(2.),0);
Point P2=Point(0,1,0);
Point P3=Point(-1/sqrt(2.),1/sqrt(2.),0);
Point P4=Point(-1,0,0);
Point P5=Point(-1/sqrt(2.),-1/sqrt(2.),0);
Point P6=Point(1/sqrt(2.),-1/sqrt(2.),0);
Point P30=Point(0.5,0,0);
Point P31=Point(0.25,0.25,0);
Point P32=Point(0.5,0.25,0);
Point P33=Point(2,-0.25,0);
//on a line
Point P34=Point(1,1,0);
Point P35=Point(1,-1,0);
Point P36=Point(1,0.5,0);
Point P37=Point(2,2,0);
//top tetrahedron
Point P15=Point(1/sqrt(2.),0,1/sqrt(2.));
Point P9=Point(-0.5,-0.5,1/sqrt(2.));
Point P10=Point(0,1/sqrt(2.),1/sqrt(2.));
Point P11=Point(0,0,1);
Point P12=Point(-0.5,0.5,1/sqrt(2.));
Point P13=Point(0.5,-0.5,1/sqrt(2.));
Point P14=Point(0,-0.5,1/sqrt(2.));//edge P9,P13
//Point P15=Point(0.25/sqrt(2.),0.25/sqrt(2.),0.5/sqrt(2.));//under edge
Point P16=Point(-0.5,0.5*(1+sqrt(2.)),2/sqrt(2.));//over edge
Point P17=Point(0.5,0,0.5);
Point P18=Point(-1/sqrt(2.),0,-1/sqrt(2.));
Point P19=Point(0,0,-1);
Point P40=Point(-0.25,-0.25,0.5/sqrt(2.));
Point P41=Point(-1,-1,2/sqrt(2.));
Point P42=Point(0,0,0.5);
Point P43=Point(2,-0.5,1);
Point P20=Point(0.5,0,0);
Point P21=Point(1,0,0);
Point P22=Point(2,0,0);
Vertex_handle v20;
Vertex_handle v21;
Vertex_handle v22;
Point P23=Point(0,0.25,0.25);
Point P24=Point(0,0.5,0.5);
Vertex_handle v23;
Vertex_handle v24;
Point P25=Point(0.75,0.25,0.1);
Point P26=Point(0.5,0.5,0.5);
Point P27=Point(1,1,1);
Vertex_handle v25;
Vertex_handle v26;
Vertex_handle v27;
Vertex_handle v0;
Vertex_handle vv1;
Vertex_handle vv0;
Vertex_handle v1;
Vertex_handle v2;
Vertex_handle v3;
Vertex_handle v4;
Vertex_handle v01;
Vertex_handle vv2;
Vertex_handle vv3;
Vertex_handle vv4;
Vertex_handle v5;
Vertex_handle v6;
Vertex_handle v7;
Vertex_handle v8;
Vertex_handle v9;
Vertex_handle v10;
Vertex_handle v11;
Vertex_handle v12;
Vertex_handle v13;
Vertex_handle v14;
Vertex_handle v15;
Vertex_handle v33;
Vertex_handle v16;
Vertex_handle v31;
Vertex_handle v34;
Vertex_handle v32;
Vertex_handle v19;
Vertex_handle v42;
Vertex_handle v37;
Vertex_handle vv33;
Vertex_handle vv34;
Vertex_handle vv31;
std::list<Point> l; l.push_back(P15);
l.push_back(P9); l.push_back(P10); l.push_back(P19);
l.push_back(P0); l.push_back(P1); l.push_back(P2);
std::vector<Point> v; v.push_back(P15);
v.push_back(P9); v.push_back(P10); v.push_back(P19);
v.push_back(P0); v.push_back(P1); v.push_back(P2);
/*------------------------------*/
/* INSERTION */
/*------------------------------*/
//dim-1
std::cout<<"test insertion dim-1"<<std::endl;
RTOS T0_0;
assert(T0_0.dimension()==-2);
v01=T0_0.insert(P1);
T0_0.insert(P1);
assert(T0_0.number_of_vertices()==1);assert(T0_0.number_of_hidden_vertices()==0);assert(T0_0.dimension()==-1);
vv31=T0_0.insert(P31);//hidden
assert(T0_0.number_of_vertices()==1);assert(T0_0.number_of_hidden_vertices()==1);assert(T0_0.dimension()==-1);
vv34=T0_0.insert(P34);//hidding
assert(T0_0.number_of_vertices()==1);assert(T0_0.number_of_hidden_vertices()==2);assert(T0_0.dimension()==-1);
// tr.insert(P31);//already hidden here ve store 2 versions of the hidden vertex
//assert(tr.number_of_vertices()==1);//assert(tr0_1.number_of_hidden_vertices()==2);
//assert(tr.dimension()==-1);
//assert(tr0_1.is_valid());
//dim0
std::cout<<"test insertion dim0"<<std::endl;
tr0_1.insert(P30);
tr0_1.insert(P32);
assert(tr0_1.number_of_vertices()==2);assert(tr0_1.number_of_hidden_vertices()==0);assert(tr0_1.dimension()==0);
tr0_1.insert(P30);//vertex
tr0_1.insert(P32);//vertex
assert(tr0_1.number_of_vertices()==2);assert(tr0_1.number_of_hidden_vertices()==0);assert(tr0_1.dimension()==0);
tr0_1.insert(P0);//outside affine hull hidding
assert(tr0_1.number_of_vertices()==2);assert(tr0_1.number_of_hidden_vertices()==1);assert(tr0_1.dimension()==0);
tr0_1.insert(P1);//outside affine hull hidding
std::cout<<tr0_1.dimension()<<std::endl;
assert(tr0_1.number_of_vertices()==2);assert(tr0_1.number_of_hidden_vertices()==2);assert(tr0_1.dimension()==0);
tr0_1.insert(P31);//outside affine hull hidden
assert(tr0_1.number_of_vertices()==2);assert(tr0_1.number_of_hidden_vertices()==3);assert(tr0_1.dimension()==0);
tr0_1.insert(P33);//hidding
assert(tr0_1.number_of_vertices()==2);assert(tr0_1.number_of_hidden_vertices()==4);assert(tr0_1.dimension()==0);
tr0_1.insert(P32);//allready hidden
assert(tr0_1.number_of_vertices()==2);//assert(tr0_1.number_of_hidden_vertices()==4);
assert(tr0_1.dimension()==0);
//assert(tr0_1.is_valid());
//opposed vertices case
tr0_1.clear();
tr0_1.insert(P0);
tr0_1.insert(P4);
assert(tr0_1.dimension()==0);
tr0_1.insert(P0);
tr0_1.insert(P4);
tr0_1.insert(P30);
assert(tr0_1.dimension()==0);
tr0_1.insert(P2);
assert(tr0_1.dimension()==1);
//dim1
std::cout<<"test insertion dim1"<<std::endl;
tr0_1.clear();
v0=tr0_1.insert(P0);
tr0_1.insert(P3);
tr0_1.insert(P1);//dim 1 half circle
assert(tr0_1.dimension()==1); assert(tr0_1.number_of_vertices()==3);
assert(tr0_1.is_valid());
tr0_1.insert(P0);
tr0_1.insert(P3);
tr0_1.insert(P1);
tr0_1.insert(P2);//in edge
tr0_1.insert(P30);//vertex hidden
assert(tr0_1.number_of_vertices()==4);assert(tr0_1.number_of_hidden_vertices()==1);
assert(tr0_1.is_valid());
tr0_1.insert(P32);//edge hidden
vv33=tr0_1.insert(P33);//outside hidding P0
assert(tr0_1.number_of_hidden_vertices()==3); assert(tr0_1.number_of_vertices()==4);
v37=tr0_1.insert(P37);//vertex hidding P2 and P1
assert(tr0_1.number_of_hidden_vertices()==5); assert(tr0_1.number_of_vertices()==3);
assert(tr0_1.is_valid());
//full circle todo
//opposed vertices case
RTOS tr1_2;
tr1_2.insert(P0);
tr1_2.insert(P2);
tr1_2.insert(P4);//half circle
assert(tr1_2.dimension()==1);
tr1_2.insert(P1);
tr1_2.insert(P3);;
assert(tr1_2.number_of_vertices()==5);
tr1_2.insert(P5);
assert(tr1_2.is_valid());
//non-coplanar with _sphere
tr1_1.insert(P15);
tr1_1.insert(P9);
tr1_1.insert(P10);
assert(tr1_1.dimension()==1);
tr1_1.insert(P40);//vertex hidden
tr1_1.insert(P41);//vertex_hidding
assert(tr1_1.dimension()==1);assert(tr1_1.number_of_vertices()==3);assert(tr1_1.number_of_hidden_vertices()==2);
assert(tr1_1.is_valid());
tr1_1.insert(P42);//outside affine hull hidden
assert(tr1_1.dimension()==1);assert(tr1_1.number_of_hidden_vertices()==3);
tr1_1.insert(P43);//outside affine hull hidding case 1lt42n
// write_hpts_to_off(hpts,tr1_1);
//write_vertices(verts,tr1_1);
//write_triangulation_to_off_2(pos,neg,tr1_1);
assert(tr1_1.dimension()==1);assert(tr1_1.number_of_hidden_vertices()==4);
assert(tr1_1.is_valid());
//dim1->dim2
std::cout<<"dim1 to dim2"<<std::endl;
//with full circle
tr2_1.clear();
vv0=tr2_1.insert(P0);
tr2_1.insert(P3);
v5=tr2_1.insert(P5);
v11=tr2_1.insert(P11);
assert(tr2_1.dimension()==2);
assert(tr2_1.is_valid());
//with half circle
tr2_2.insert(P0);
tr2_2.insert(P6);
tr2_2.insert(P1);
assert(tr2_2.is_valid());
tr2_2.insert(P2);
assert(tr2_2.number_of_hidden_vertices()==0);
assert(tr2_2.is_valid());
tr2_2.insert(P11);
assert(tr2_2.dimension()==2);
assert(tr2_2.is_valid());
//from non coplanar points with _sphere circle
tr2_3.insert(P15);
v9=tr2_3.insert(P9);
tr2_3.insert(P10);
tr2_3.insert(P11);
assert(tr2_3.dimension()==2);
assert(tr2_3.is_valid());
//dim2
//must write a test for excessive hidding corner point
std::cout<<"insertion dim 2"<<std::endl;
//with full circle
v1=tr2_1.insert(P1);//edge boundary
v3=tr2_1.insert(P2);//
v4=tr2_1.insert(P4);//
v6=tr2_1.insert(P6);//
assert(tr2_1.is_valid());
v3=tr2_1.insert(P3);//vertex of boundary
v31=tr2_1.insert(P31);//vertex of boundary hidden
v34=tr2_1.insert(P34);//vertex of boundary hidding
assert(tr2_1.is_valid());
assert(tr2_1.number_of_hidden_vertices()==2);assert(tr2_1.number_of_vertices()==8);
v33=tr2_1.insert(P33);//edge of boundary hidding
v32=tr2_1.insert(P32);//edge of boundary hidden
assert(tr2_1.number_of_hidden_vertices()==4);assert(tr2_1.number_of_vertices()==8);
v19=tr2_1.insert(P19);//outside convex_hullx
v42=tr2_1.insert(P42);
assert(tr2_1.is_valid());
//with half circle
tr2_2.insert(P36); //edge
tr2_2.insert(P5); //outside
tr2_2.insert(P19);//full sphere
assert(tr2_2.is_valid());
//general case
std::cout<<"general case"<<std::endl;
vv1=tr_2_s.insert(p1);
vv2=tr_2_s.insert(p2);
vv3=tr_2_s.insert(p3);
vv4=tr_2_s.insert(p4);
assert(tr_2_s.number_of_vertices()==4);
assert(tr_2_s.is_valid());
//write_triangulation_to_off_2(pos,neg,tr2_3);
// write_vertices(verts,tr2_3);
// write_hpts_to_off(hpts,tr2_3);
//VERTEX
v20 =tr_2_s.insert(P20);//hidden
assert(tr_2_s.number_of_vertices()==4); assert(tr_2_s.number_of_hidden_vertices()==1);
v21 = tr_2_s.insert(P21);//exactly on point
assert(tr_2_s.number_of_vertices()==4); assert(tr_2_s.number_of_hidden_vertices()==1);
v22 = tr_2_s.insert(P22);//hidding init vertex (1,1,1)
assert(tr_2_s.number_of_vertices()==4); assert(tr_2_s.number_of_hidden_vertices()==2);
//EDGE
v23 = tr_2_s.insert(P23); //hidden
assert(tr_2_s.number_of_vertices()==4); assert(tr_2_s.number_of_hidden_vertices()==3);
v24 = tr_2_s.insert(P24); //on edge
assert(tr_2_s.number_of_vertices()==5); assert(tr_2_s.number_of_hidden_vertices()==3);
//FACE
v25 = tr_2_s.insert(P25); //hidden
assert(tr_2_s.number_of_vertices()==5); assert(tr_2_s.number_of_hidden_vertices()==4);
v26 = tr_2_s.insert(P26); //on face, not hidding points
assert(tr_2_s.number_of_vertices()==6); assert(tr_2_s.number_of_hidden_vertices()==4);
v27 = tr_2_s.insert(P27); //on face, hidding point
assert(tr_2_s.number_of_vertices()==6); assert(tr_2_s.number_of_hidden_vertices()==5);
assert(tr_2_s.is_valid());
/*
std::cout << "test copy constructor" << std::endl;
// test copy_constructor with non-empty 1-triangulation
RTOS T1_5_1( tr0_1 );
assert( T1_5_1.dimension() == tr0_1.dimension() );
assert( T1_5_1.number_of_vertices() == tr0_1.number_of_vertices());
assert( T1_5_1.number_of_hidden_vertices()==
tr0_1.number_of_hidden_vertices() );
assert( T1_5_1.is_valid() );
// Test assignment operator
RTOS T1_5_2 = tr0_1;
assert( T1_5_1.dimension() == tr0_1.dimension() );
assert( T1_5_1.number_of_vertices() == tr0_1.number_of_vertices());
assert( T1_5_1.number_of_hidden_vertices()==
tr0_1.number_of_hidden_vertices() );
assert( T1_5_1.is_valid() );
// test copy_constructor with non-empty 2-triangulation
RTOS T2_3_1( tr2_2 );
assert( T2_3_1.dimension() == tr2_2.dimension());
assert( T2_3_1.number_of_vertices() == tr2_2.number_of_vertices());
assert( T2_3_1.number_of_hidden_vertices()==
tr2_2.number_of_hidden_vertices() );
assert( T2_3_1.is_valid() );
// test assignment operator
RTOS T2_3_4 = tr2_2;
assert( T2_3_1.dimension() == tr2_2.dimension());
assert( T2_3_1.number_of_vertices() == tr2_2.number_of_vertices());
assert( T2_3_1.number_of_hidden_vertices()==
tr2_2.number_of_hidden_vertices() );
assert( T2_3_1.is_valid() );
// make sure push_back exists and does the same thing as insert
assert( tr_2_s.push_back(P27) == v27 );
assert( tr_2_s.number_of_vertices() == 6 );
// test list iterator insert
RTOS T2_5;
assert( T2_5.insert(l.begin(), l.end()) == 7 );
assert( T2_5.dimension() == 2 );
assert( T2_5.number_of_vertices() == 7 );
assert( T2_5.is_valid() );
// test vector iterator insert
RTOS T2_6;
assert( T2_6.insert(v.begin(), v.end()) == 7 );
assert( T2_6.dimension() == 2 );
assert( T2_6.number_of_vertices() == 7 );
assert( T2_6.is_valid() );
/*
// test flip
std::cout << " test flip " << std::endl;
Triangul T2_8;
T2_8.insert(Point(0,0,1));
T2_8.insert(Point(1,0,1));
T2_8.insert(Point(1,1,1));
T2_8.insert(Point(0,1,1));
ff = T2_8.locate(Point(1,1,2),lt,li);
assert(lt == Triangul::EDGE);
assert(!T2_8.is_infinite(ff));
Face_handle f2 = ff->neighbor(li);
assert(!T2_8.is_infinite(f2));
T2_8.flip(ff,0);
assert( T2_8.is_valid() );
/*
/********************/
/******** I/O *******/
/*
std::cout << "test output to a file" << std::endl;
std::ofstream of0_0("T00.triangulation", std::ios::out);
CGAL::set_ascii_mode(of0_0);
of0_0 << T0_0; of0_0.close();
std::ofstream of0_1("T01.triangulation");
CGAL::set_ascii_mode(of0_1);
of0_1 << tr0_1; of0_1.close();
std::ofstream of1_2("T12.triangulation");
CGAL::set_ascii_mode(of1_2);
of1_2 << tr1_2; of1_2.close();
std::ofstream of1_5("T11.triangulation");
CGAL::set_ascii_mode(of1_5);
of1_5 << tr1_1; of1_5.close();
std::ofstream of1_6("T21.triangulation");
CGAL::set_ascii_mode(of1_6);
of1_6 << tr2_1; of1_6.close();
std::ofstream of2_1("T22.triangulation");
CGAL::set_ascii_mode(of2_1);
of2_1 << tr2_2; of2_1.close();
std::ofstream of2_3("T23.triangulation");
CGAL::set_ascii_mode(of2_3);
of2_3 << tr2_3; of2_3.close();
std::ofstream of2_5("T25.triangulation");
CGAL::set_ascii_mode(of2_5);
of2_5 << T2_5; of2_5.close();
std::ofstream of2_6("T26.triangulation");
CGAL::set_ascii_mode(of2_6);
of2_6 << T2_6; of2_6.close();
/*
std::cout << "test input from a file" << std::endl;
std::ifstream if0_0("T00.triangulation"); CGAL::set_ascii_mode(if0_0);
RTOS T0_0_copy; if0_0 >> T0_0_copy;
assert( T0_0_copy.is_valid() &&
T0_0_copy.number_of_vertices() == T0_0.number_of_vertices() );
std::ifstream if0_1("T01.triangulation"); CGAL::set_ascii_mode(if0_1);
RTOS T0_1_copy; if0_1 >> T0_1_copy;
assert( T0_1_copy.is_valid() &&
T0_1_copy.number_of_vertices() == tr0_1.number_of_vertices() );
std::ifstream if1_2("T12.triangulation"); CGAL::set_ascii_mode(if1_2);
RTOS T1_2_copy; if1_2 >> T1_2_copy;
assert( T1_2_copy.is_valid() &&
T1_2_copy.number_of_vertices() == tr1_2.number_of_vertices() );
std::ifstream if1_5("T11.triangulation"); CGAL::set_ascii_mode(if1_5);
RTOS T1_1_copy; if1_5 >> T1_2_copy;
assert( T1_1_copy.is_valid() &&
T1_1_copy.number_of_vertices() == tr1_1.number_of_vertices() );
std::ifstream if1_6("T21.triangulation"); CGAL::set_ascii_mode(if1_6);
RTOS T2_1_copy; if1_6 >> T2_1_copy;
assert( T2_1_copy.is_valid() &&
T2_1_copy.number_of_vertices() == tr2_1.number_of_vertices() );
std::ifstream if2_1("T22.triangulation"); CGAL::set_ascii_mode(if2_1);
RTOS T2_2_copy; if2_1 >> T2_2_copy;
assert( T2_2_copy.is_valid() &&
T2_2_copy.number_of_vertices() == tr2_2.number_of_vertices() );
std::ifstream if2_3("T23.triangulation"); CGAL::set_ascii_mode(if2_3);
RTOS T2_3_copy; if2_3 >> T2_3_copy;
assert( T2_3_copy.is_valid() &&
T2_3_copy.number_of_vertices() == tr2_3.number_of_vertices() );
std::ifstream if2_5("T25.triangulation"); CGAL::set_ascii_mode(if2_5);
RTOS T2_5_copy; if2_5 >> T2_5_copy;
assert( T2_5_copy.is_valid() &&
T2_5_copy.number_of_vertices() == T2_5.number_of_vertices() );
std::ifstream if2_6("T26.triangulation"); CGAL::set_ascii_mode(if2_6);
RTOS T2_6_copy; if2_6 >> T2_6_copy;
assert( T2_6_copy.is_valid() &&
T2_6_copy.number_of_vertices() == T2_6.number_of_vertices() );
*/
/*
std::cout<<"test_remove"<<std::endl;
//remove dim2
tr_2_s.remove(v27);
assert(tr_2_s.number_of_hidden_vertices()==4);assert(tr_2_s.number_of_vertices()==6);
tr_2_s.remove(v26);
assert(tr_2_s.number_of_hidden_vertices()==4);assert(tr_2_s.number_of_vertices()==5);//a bug occurs sometimes here
tr_2_s.remove(v25);
assert(tr_2_s.number_of_hidden_vertices()==3);assert(tr_2_s.number_of_vertices()==5);
tr_2_s.remove(v24);
assert(tr_2_s.number_of_hidden_vertices()==3);assert(tr_2_s.number_of_vertices()==4);
tr_2_s.remove(v23);
assert(tr_2_s.number_of_hidden_vertices()==2);assert(tr_2_s.number_of_vertices()==4);
assert(tr_2_s.is_valid());
//full->half
tr2_1.remove(v11);//->half sphere but reinsertion of an hidden vertex restores it
tr2_1.remove(v42); //->half here
assert(tr2_1.number_of_vertices()==8);assert(tr2_1.number_of_hidden_vertices()==4);
tr2_1.remove(v33);
//dim2-dim1
tr2_1.remove(v19);
assert(tr2_1.dimension()==1);assert(tr2_1.is_valid());
tr2_3.remove(v9);
assert(tr2_1.dimension()==1);assert(tr2_3.is_valid());
tr_2_s.remove(v22); //->dim1 but reinsertion of hidden vertex restores dim2
assert(tr_2_s.number_of_hidden_vertices()==1);assert(tr_2_s.number_of_vertices()==4);assert(tr_2_s.dimension()==2);
tr_2_s.remove(vv2); //->dim1
assert(tr_2_s.number_of_hidden_vertices()==1);assert(tr_2_s.number_of_vertices()==3);assert(tr_2_s.dimension()==1);
assert(tr_2_s.is_valid());
// write_triangulation_to_off_2(pos,neg,tr2_1);
// write_vertices(verts,tr2_1);
// write_hpts_to_off(hpts,tr2_1);
//dim1
tr2_1.remove(v31);//hidden
assert(tr2_1.number_of_hidden_vertices()==2);
tr2_1.remove(v34);//unhidding
assert(tr2_1.number_of_hidden_vertices()==1);
assert(tr2_1.is_valid());
tr2_1.remove(v3);
tr2_1.remove(v4);
tr2_1.remove(v5);
assert(tr2_1.is_valid());
tr0_1.remove(v37); //assertion fault due to removing
//of faces_begin_2 that was cheating to acces faces in dim1
//right solition is to use edges_begin
//I implemented it but it causes this bug
//I don't know why
//maybee comparing with previous version with face will help
assert(tr0_1.is_valid());
//tr0_1.remove(vv33); // bug here because an hidden vertex (1,0,0) occurs twice in a list (also in 2D package)
//remove 1 of them first :
tr0_1.remove(v0);
tr0_1.remove(vv33);
assert(tr0_1.is_valid());
//dim1->dim0
tr2_1.remove(v6);
tr2_1.remove(vv0);
assert(tr2_1.dimension()==1);
tr2_1.remove(v32);
assert(tr2_1.dimension()==0);
//dim0
Point P50=Point(0.25,0.5,0);
Vertex_handle v50=tr2_1.insert(P31);
tr2_1.remove(v1);
assert(tr2_1.dimension()==0);
tr2_1.remove(v50);
assert(tr2_1.dimension()==-1);
//dim-1
T0_0.remove(vv34);
assert(T0_0.dimension()==-2);assert(T0_0.number_of_vertices()==0);assert(T0_0.number_of_hidden_vertices()==0);
//test if hidden vertices reinserted in dim -1, currently they are deleted
//assert(tr.number_of_hidden_vertices()==1);
//tr.remove(vv31);
//assert(tr.number_of_hidden_vertices()==0);assert(tr.dimension()==-1);
//tr.remove(v01);
//assert(tr.dimension()==-2);
std::cout<<"revomal test passed successfully"<<std::endl;
/**********************/
/******* MOVE *********/
/*
std::cout << " moves" << std::endl;
std::cout << " degenerate cases: " << std::endl;
Triangul TM_0, TM_1;
Vertex_handle tmv1 = TM_0.insert(Point(0,0));
Vertex_handle tmv2 = TM_0.insert(Point(1,0));
Vertex_handle tmv3 = TM_0.insert(Point(2,0));
Vertex_handle tmv4 = TM_0.insert(Point(1,1));
assert(TM_0.dimension() == 2);
TM_0.move(tmv4, Point(2, 1));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 2);
TM_0.move(tmv4, Point(3, 0));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 1);
TM_0.move(tmv3, Point(1, 1));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 2);
TM_0.move(tmv3, Point(-1, 0));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 1);
TM_0.move(tmv2, Point(-1, 0, 2));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 1);
TM_0.move(tmv2, Point(-1, 0, 2));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 1);
TM_0.move(tmv2, Point(-1, 0, 4));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 1);
TM_0.move(tmv2, Point(-1, 0, 2));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 1);
TM_0.move(tmv2, Point(-1, 1, 2));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 2);
TM_0.move(tmv1, Point(0, 2));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 2);
TM_0.move(tmv1, Point(0, 1));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 2);
TM_0.move(tmv1, Point(0, 0));
assert(TM_0.tds().is_valid());
assert(TM_0.is_valid());
assert(TM_0.dimension() == 2);
assert(!TM_0.move(tmv1, Point(3, 0)));
std::cout << " non-degenerate cases: " << std::endl;
// non-degenerate cases
CGAL::Random_points_in_square_2<Point> g(50);
std::list<Point> points;
for(int count=0; count<50; count++) points.push_back(*g++);
TM_1.insert(points.begin(), points.end());
for(int i=0; i<50; i++) {
for(Finite_vertices_iterator fvi = TM_1.finite_vertices_begin();
fvi != TM_1.finite_vertices_end(); fvi++) {
Point p = *g++;
TM_1.move(fvi, p);
assert(TM_1.tds().is_valid());
assert(TM_1.is_valid());
}
*/
//Test random insertion in or on the sphere on a restricted area of the sphere
//good way to find bugs because points are close
//at the moment, in sphere we have a bug,
//this bug must be related with a case documented in my notes
//this case is not tested, we talk about it with manuel
//the source is in the first face of the find conflict
//it has been fixed with get conflict but it may be the source of another bug
//when the center is outside the sphere we saw vertives inside the lower envelope faces not hidden
//bug occurs at nb = 107
tr_2_s.clear();
assert(tr_2_s.is_valid());
// tr_2_s.insert_four_init_vertices();
assert(tr_2_s.is_valid());
CGAL::Random random(7);
typedef CGAL::Creator_uniform_3<double, Point> Creator;
int nb_of_pts=107;
std::cout<<"\tINSERTION OF "<<nb_of_pts<<" RANDOM POINTS\n"<<std::endl;
std::ofstream fout("test.off");
//Without hidden points
CGAL::Random_points_in_sphere_3<Point, Creator> on_sphere(1, random);
for (int count=0; count<nb_of_pts; count++) {
Point p = *on_sphere; on_sphere ++;
p = Point(p.x(),p.y(),p.z());
if(p.z()>0.1 && p.y()>0.1 && p.x()>0.1){
std::cout<<count<<std::endl;
tr_2_s.insert(p);
}
assert(tr_2_s.is_valid());
std::ofstream pos2("pos2.off");
std::ofstream neg2("neg2.off");
write_vertices(verts,tr_2_s);
write_hpts_to_off(hpts,tr_2_s);
write_triangulation_to_off_2(pos2,neg2,tr_2_s);
}
write_vertices(verts,tr_2_s);
write_hpts_to_off(hpts,tr_2_s);
write_triangulation_to_off_2(pos,neg,tr_2_s);
assert(tr_2_s.number_of_hidden_vertices()==0);
assert(tr_2_s.is_valid());
return 0;
}
template <class Stream, class Triangulation>
Stream &write_triangulation_to_off(Stream &out, Triangulation &t) {
std::vector<Face_handle> faces;
// Points of triangulation
for (Face_iterator it = t.faces_begin(); it != t.faces_end(); it++) {
for (int i=0 ; i<3 ; i++) {
Point p = it->vertex(i)->point();
out << p.x() << " "
<< p.y() << " "
<< p.z() << std::endl;
}
}
return out;
}
template <class Stream, class Triangulation>
Stream &write_hpts_to_off(Stream &out, Triangulation &t) {
// Points of triangulation
for (Hidden_points_iterator it = t.hidden_vertices_begin(); it != t.hidden_vertices_end(); it++) {
out << (it)->point().x() << " "
<< (it)->point().y() << " "
<< (it)->point().z() << std::endl;
}
return out;
}
template <class Stream, class Triangulation>
Stream &write_triangulation_to_off_2(Stream &out,Stream &out2, Triangulation &t){
// Points of triangulation
for (Face_iterator it = t.faces_begin(); it != t.faces_end(); it++) {
if(!it->is_negative()
/*(t.orientation(it->vertex(0)->point(),it->vertex(1)->point(),it->vertex(2)->point())==1)*/
){
for (int i=0 ; i<3 ; i++) {
if(it->vertex(i)!=Vertex_handle())
{
Point p = it->vertex(i)->point();
out << p.x() << " "
<< p.y() << " "
<< p.z() << std::endl;
}
}
}
else{
for (int i=0 ; i<3 ; i++){
if(it->vertex(i)!=Vertex_handle())
{
Point p = it->vertex(i)->point();
out2 << p.x() << " "
<< p.y() << " "
<< p.z() << std::endl;
}
}
}
}
return out;
}
template <class Stream>
Stream &write_face_to_off(Stream &out, Face_handle loc){
for (int i=0 ; i<3 ; i++) {
Point p = loc->vertex(i)->point();
out << p.x() << " "
<< p.y() << " "
<< p.z() << std::endl;
}
return out;
}
template <class Stream>
Stream &write_points(Stream &out,std::vector<Point> &t)
{
for(std::vector<Point>::iterator it= t.begin(); it!= t.end(); ++it)
{
out << (*it).x() << " "
<< (*it).y() << " "
<< (*it).z() << std::endl;
}
}
template <class Stream>
Stream &write_vertices(Stream &out,std::vector<Vertex_handle> &t)
{
for(std::vector<Vertex_handle>::iterator it= t.begin(); it!= t.end(); ++it)
{
Point p=(*it)->point();
out << p.x() << " "
<< p.y() << " "
<< p.z() << std::endl;
}
}
template <class Stream, class Triangulation>
Stream &write_vertices(Stream &out, Triangulation &t)
{
for(Vertex_iterator it= t.vertices_begin(); it!= t.vertices_end(); ++it)
{
Point p=(it)->point();
out << p.x() << " "
<< p.y() << " "
<< p.z() << std::endl;
}
}