Skip to Content.
Sympa Menu

cgal-discuss - error in polyhedron_self_intersection.cpp?

Subject: CGAL users discussion list

List archive

error in polyhedron_self_intersection.cpp?


Chronological Thread 
  • From: "Isabel" <>
  • To: <>
  • Subject: error in polyhedron_self_intersection.cpp?
  • Date: Fri, 20 Jul 2007 10:51:07 +0200

Hi all.
There is an error if I use a polyhedron that are two spheres that intersect. I send you the file "esferas.off". It has 420 faces.
The error message is:
Debug Assertion Failed!
_expression_: vector insert iterator outside range
This code is only for a few faces?

typedef CGAL::Bbox_3 Bbox;

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;

typedef Kernel::Triangle_3 Triangle;

typedef Kernel::Segment_3 Segment;

typedef Kernel::Point_3 Point;

typedef CGAL::Polyhedron_3<Kernel> Polyhedron;

typedef Polyhedron::Halfedge_const_handle Halfedge_const_handle;

typedef Polyhedron::Facet_const_iterator Facet_const_iterator;

typedef Polyhedron::Facet_const_handle Facet_const_handle;

typedef CGAL::Box_intersection_d::Box_with_handle_d<

double, 3, Facet_const_handle> Box;

std::vector<Triangle> triangles;

struct Intersect_facets {

void operator()( const Box* b, const Box* c) const {

Halfedge_const_handle h = b->handle()->halfedge();

// check for shared egde --> no intersection

if ( h->opposite()->facet() == c->handle()

|| h->next()->opposite()->facet() == c->handle()

|| h->next()->next()->opposite()->facet() == c->handle())

return;

// check for shared vertex --> maybe intersection, maybe not

Halfedge_const_handle g = c->handle()->halfedge();

Halfedge_const_handle v;

if ( h->vertex() == g->vertex())

v = g;

if ( h->vertex() == g->next()->vertex())

v = g->next();

if ( h->vertex() == g->next()->next()->vertex())

v = g->next()->next();

if ( v == Halfedge_const_handle()) {

h = h->next();

if ( h->vertex() == g->vertex())

v = g;

if ( h->vertex() == g->next()->vertex())

v = g->next();

if ( h->vertex() == g->next()->next()->vertex())

v = g->next()->next();

if ( v == Halfedge_const_handle()) {

h = h->next();

if ( h->vertex() == g->vertex())

v = g;

if ( h->vertex() == g->next()->vertex())

v = g->next();

if ( h->vertex() == g->next()->next()->vertex())

v = g->next()->next();

}

}

if ( v != Halfedge_const_handle()) {

// found shared vertex:

CGAL_assertion( h->vertex() == v->vertex());

// geomtric check if the opposite segments intersect the triangles

Triangle t1( h->vertex()->point(),

h->next()->vertex()->point(),

h->next()->next()->vertex()->point());

Triangle t2( v->vertex()->point(),

v->next()->vertex()->point(),

v->next()->next()->vertex()->point());

Segment s1( h->next()->vertex()->point(),

h->next()->next()->vertex()->point());

Segment s2( v->next()->vertex()->point(),

v->next()->next()->vertex()->point());

if ( CGAL::do_intersect( t1, s2)) {

//cerr << "Triangles intersect (t1,s2):\n T1: " << t1

// << "\n T2 :" << t2 << endl;

triangles.push_back(t1);

triangles.push_back(t2);

} else if ( CGAL::do_intersect( t2, s1)) {

//cerr << "Triangles intersect (t2,s1):\n T1: " << t1

// << "\n T2 :" << t2 << endl;

triangles.push_back(t1);

triangles.push_back(t2);

}

return;

}

// check for geometric intersection

Triangle t1( h->vertex()->point(),

h->next()->vertex()->point(),

h->next()->next()->vertex()->point());

Triangle t2( g->vertex()->point(),

g->next()->vertex()->point(),

g->next()->next()->vertex()->point());

 

if ( CGAL::do_intersect( t1, t2)) {

//cerr << "Triangles intersect:\n T1: " << t1 << "\n T2 :"

// << t2 << endl;

cerr << "triangles intersect: " << endl;

triangles.push_back(t1);

triangles.push_back(t2);

}

}

};

void write_off() {

cout << "OFF\n" << ( triangles.size( ) * 3 ) << ' ' << triangles.size( )

<< " 0\n";

for ( std::vector<Triangle>::iterator i = triangles.begin(); i != triangles.end(); ++i) {

cout << i->vertex( 0 ) << '\n';

cout << i->vertex( 1 ) << '\n';

cout << i->vertex( 2 ) << '\n';

}

for ( std::size_t k = 0; k != triangles.size(); ++k) {

cout << "3 " << ( 3 * k ) << ' ' << ( 3 * k+1 ) << ' ' << ( 3 * k + 2 ) << '\n';

}

}

 

 

void intersection( const Polyhedron& P) {

std::vector<Box> boxes;

boxes.reserve( P.size_of_facets());

for ( Facet_const_iterator i = P.facets_begin(); i != P.facets_end(); ++i){

boxes.push_back(

Box( i->halfedge()->vertex()->point().bbox()

+ i->halfedge()->next()->vertex()->point().bbox()

+ i->halfedge()->next()->next()->vertex()->point().bbox(),

i));

}

std::vector<const Box*> box_ptr;

box_ptr.reserve( P.size_of_facets());

for ( std::vector<Box>::iterator j = boxes.begin(); j != boxes.end(); ++j){

box_ptr.push_back( &*j);

}

CGAL::box_self_intersection_d( box_ptr.begin(), box_ptr.end(), Intersect_facets(), std::ptrdiff_t(2000));

}

int main() {

Polyhedron P;

const char* name = "cin";

istream* p_in1 = &cin;

ifstream in1;

char par[ 10 ];

CGAL::Timer user_time;

cerr << "Loading OFF file ... " << endl;

user_time.start();

in1.open( ".\\esferas.off");

p_in1 = &in1;

(*p_in1) >> P;

cerr << "Loading OFF file : " << user_time.time() << " seconds." << endl;

if ( ! P.is_pure_triangle()) {

cerr << "The input object is not triangulated. Cannot intersect."

<< endl;

exit(1);

}

user_time.reset();

cerr << "Intersection ... " << endl;

intersection( P );

cerr << "Intersection : " << user_time.time() << " seconds." << endl;

write_off();

scanf( " %s ", par );

return 0;

}

Thanks. Isabel
 

Attachment: esferas.off
Description: Binary data




Archive powered by MHonArc 2.6.16.

Top of Page