From ad5506d214ace1bf61d1d257533e9d1db05ab09f Mon Sep 17 00:00:00 2001 From: Peter Hachenberger Date: Mon, 25 Nov 2002 16:40:34 +0000 Subject: [PATCH] correction of 1 dimensional features adaption of pluecker lines to the extended kernel` --- Packages/Nef_3/demo/Nef_3/nef_3.C | 14 ++- .../include/CGAL/Nef_3/Pluecker_line_3.h | 48 +++++---- .../include/CGAL/Nef_3/SNC_SM_overlayer.h | 97 ++++--------------- .../include/CGAL/Nef_3/SNC_SM_point_locator.h | 7 +- .../include/CGAL/Nef_3/SNC_constructor.h | 97 ++++++++++++++++--- .../Nef_3/include/CGAL/Nef_3/SNC_decorator.h | 57 ++++++++--- Packages/Nef_3/include/CGAL/Nef_3/SNC_items.h | 2 + .../include/CGAL/Nef_3/SNC_ray_shooter.h | 20 ++-- .../Nef_3/include/CGAL/Nef_3/SNC_structure.h | 29 +++--- .../Nef_3/include/CGAL/Nef_3/bounded_side_3.h | 3 +- .../Nef_3/include/CGAL/Nef_polyhedron_3.h | 20 +++- 11 files changed, 241 insertions(+), 153 deletions(-) diff --git a/Packages/Nef_3/demo/Nef_3/nef_3.C b/Packages/Nef_3/demo/Nef_3/nef_3.C index 83a7834abfa..7382ffa8e56 100644 --- a/Packages/Nef_3/demo/Nef_3/nef_3.C +++ b/Packages/Nef_3/demo/Nef_3/nef_3.C @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -52,8 +53,11 @@ using std::strcmp; using std::exit; // Types -typedef CGAL::Gmpz NT; -typedef CGAL::Simple_homogeneous Kernel; +typedef CGAL::Gmpz NT; +//typedef CGAL::Simple_homogeneous Kernel; + +typedef CGAL::Extended_homogeneous_3 Kernel; +// struct Kernel : public CGAL::Extended_homogeneous_3 {}; typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::SNC_items SNC_items; @@ -212,8 +216,8 @@ int eval( int argc, char* argv[]) { << argv[i+1] << "' correctly." << endl; error = 5; } else { - Nef_polyhedron nf(poly); - nef.push_back( nf); + Nef_polyhedron nf(poly); + nef.push_back( nf); } } ++i; @@ -289,6 +293,7 @@ int eval( int argc, char* argv[]) { } else { error = 4; } + } else if ( strcmp( argv[i], "scale") == 0) { if ( nef.size() == 0) { cerr << "Error: '" << argv[i] << "' on empty stack." << endl; @@ -386,7 +391,6 @@ int eval( int argc, char* argv[]) { error = 2; continue; } - cerr << "inters" << std::endl; Nef_polyhedron nf1 = nef.back(); nef.pop_back(); Nef_polyhedron nf2 = nef.back(); diff --git a/Packages/Nef_3/include/CGAL/Nef_3/Pluecker_line_3.h b/Packages/Nef_3/include/CGAL/Nef_3/Pluecker_line_3.h index bc21280d19b..63b27e8f2e0 100644 --- a/Packages/Nef_3/include/CGAL/Nef_3/Pluecker_line_3.h +++ b/Packages/Nef_3/include/CGAL/Nef_3/Pluecker_line_3.h @@ -53,15 +53,16 @@ class Pluecker_line_3 { typedef R_ R; /*{\Mtypemember the standard kernel type.}*/ typedef typename R::RT RT; + typedef typename RT::NT NT; /*{\Mtypemember the ring type.}*/ typedef typename R::Point_3 Point_3; /*{\Mtypemember the point type of the standard kernel.}*/ typedef typename R::Line_3 Line_3; /*{\Mtypemember the line type of the standard kernel.}*/ -typedef const RT* const_iterator; +typedef const NT* const_iterator; /*{\Mtypemember iterator over Pluecker coefficients.}*/ typedef Pluecker_line_3 Self; -RT c_[6]; +NT c_[6]; public: /*{\Mcreation 3}*/ @@ -73,25 +74,28 @@ Pluecker_line_3(const Line_3& l) /*{\Mcreate creates an instance |\Mvar| of type |\Mname| and initializes it to |l|.}*/ { + TRACEN("Vorsicht"); Point_3 p(l.point(0)), q(l.point(1)); - c_[0] = p.hx()*q.hy() - p.hy()*q.hx(); - c_[1] = p.hx()*q.hz() - p.hz()*q.hx(); - c_[2] = p.hy()*q.hz() - p.hz()*q.hy(); - c_[3] = p.hx()*q.hw() - p.hw()*q.hx(); - c_[4] = p.hy()*q.hw() - p.hw()*q.hy(); - c_[5] = p.hz()*q.hw() - p.hw()*q.hz(); + c_[0] = (p.hx()*q.hy() - p.hy()*q.hx()).eval_at(1); + c_[1] = (p.hx()*q.hz() - p.hz()*q.hx()).eval_at(1); + c_[2] = (p.hy()*q.hz() - p.hz()*q.hy()).eval_at(1); + c_[3] = (p.hx()*q.hw() - p.hw()*q.hx()).eval_at(1); + c_[4] = (p.hy()*q.hw() - p.hw()*q.hy()).eval_at(1); + c_[5] = (p.hz()*q.hw() - p.hw()*q.hz()).eval_at(1); } Pluecker_line_3(const Point_3& p, const Point_3& q) /*{\Mcreate creates an instance |\Mvar| of type |\Mname| and initializes it to the oriented line through |p| and |q|.}*/ { - c_[0] = p.hx()*q.hy() - p.hy()*q.hx(); - c_[1] = p.hx()*q.hz() - p.hz()*q.hx(); - c_[2] = p.hy()*q.hz() - p.hz()*q.hy(); - c_[3] = p.hx()*q.hw() - p.hw()*q.hx(); - c_[4] = p.hy()*q.hw() - p.hw()*q.hy(); - c_[5] = p.hz()*q.hw() - p.hw()*q.hz(); + TRACEN("Pluecker"); + + c_[0] = (p.hx()*q.hy() - p.hy()*q.hx()).eval_at(1); + c_[1] = (p.hx()*q.hz() - p.hz()*q.hx()).eval_at(1); + c_[2] = (p.hy()*q.hz() - p.hz()*q.hy()).eval_at(1); + c_[3] = (p.hx()*q.hw() - p.hw()*q.hx()).eval_at(1); + c_[4] = (p.hy()*q.hw() - p.hw()*q.hy()).eval_at(1); + c_[5] = (p.hz()*q.hw() - p.hw()*q.hz()).eval_at(1); } @@ -120,7 +124,7 @@ Self& operator=(const Self& l) { if (&l!=this) std::copy(l.begin(),l.end(),c_); return *this; } -const RT& operator[](unsigned i) const +const NT& operator[](unsigned i) const /*{\Marrop returns constant access to the $i$th Pluecker coefficient.}*/ { CGAL_assertion(i<6); return c_[i]; } @@ -137,19 +141,21 @@ void normalize() representation. This is done by dividing all Pluecker coefficients by their common gcd.}*/ { + TRACEN("normalize"); int i=0; while(i<6 && c_[i]==0) i++; - + if(i>5) return; - RT D = c_[i]; + NT D = c_[i]; CGAL_assertion(D!=0); for(++i; i<6; ++i) D = (c_[i]==0 ? D : CGAL_NTS gcd(D, c_[i])); if (D==0) return; + TRACEN("gcd" << D); for(int i=0; i<6; ++i) c_[i]/=D; } @@ -160,7 +166,7 @@ void negate() Pluecker_line_3 opposite() const /*{\Mop returns the line opposite to |\Mvar|. }*/ { Pluecker_line_3 res; - std::negate N; + std::negate N; std::transform(begin(), end(), res.c_, N); return res; } @@ -170,8 +176,8 @@ static int cmp(const Pluecker_line_3& l1, /*{\Mstatic returns the lexicographic order on lines defined on their Pluecker coefficient tuples.}*/ { for (unsigned i=0; i<5; ++i) { - typename R::RT diff = l1[i]-l2[i]; - if ( diff != typename R::RT(0) ) return CGAL_NTS sign(diff); + typename R::RT::NT diff = l1[i]-l2[i]; + if ( diff != typename R::RT::NT(0) ) return CGAL_NTS sign(diff); } return CGAL_NTS sign(l1[5]-l2[5]); } @@ -179,7 +185,7 @@ on their Pluecker coefficient tuples.}*/ }; // Pluecker_line_3 /*{\Mimplementation The Pluecker coefficients of a line are stored -in a six-tuple of |RT| coefficients.}*/ +in a six-tuple of |NT| coefficients.}*/ template diff --git a/Packages/Nef_3/include/CGAL/Nef_3/SNC_SM_overlayer.h b/Packages/Nef_3/include/CGAL/Nef_3/SNC_SM_overlayer.h index 6a0c1ae3b87..77ea6bad0e3 100644 --- a/Packages/Nef_3/include/CGAL/Nef_3/SNC_SM_overlayer.h +++ b/Packages/Nef_3/include/CGAL/Nef_3/SNC_SM_overlayer.h @@ -859,6 +859,10 @@ subdivide(Vertex_handle v0, Vertex_handle v1) merge_halfsphere_maps(svertices_begin(),v,O); check_integrity_and_topological_planarity(); + TRACEN("subdivided"); + CGAL_nef3_forall_svertices(v,*this) { + TRACEN(PH(v)); + } } @@ -873,8 +877,9 @@ partition_to_halfsphere(Iterator start, Iterator beyond, Seg_list& L, Sphere_circle xycircle(0,0,pos); while ( start != beyond ) { int i = start->intersection(xycircle,s1,s2); - if (i>1) { L.push_back(s2); M[--L.end()] = M[start]; } - if (i>0) { L.push_back(s1); M[--L.end()] = M[start]; } + TRACEN("segment " << start->source() << " " << start->target()); + if (i>1) { L.push_back(s2); M[--L.end()] = M[start]; TRACEN(">1 " << s2.source() << " " << s2.target()); } + if (i>0) { L.push_back(s1); M[--L.end()] = M[start]; TRACEN(">0 " << s1.source() << " " << s1.target()); } ++start; } // now all segments are split into hemispheres @@ -889,17 +894,20 @@ partition_to_halfsphere(Iterator start, Iterator beyond, Seg_list& L, CGAL_nef3_forall_iterators(it,L) { TRACEN(" "<<*it); if ( equal_as_sets(it->sphere_circle(),xycircle) ) { TRACEN(" splitting xy seg "<<*it); + bool added=false; int n1 = it->intersection(yzcircle,s1,s2); if (n1 > 1 && !s2.is_degenerate()) - { M[ L.insert(it,s2) ] = M[it]; } + { M[ L.insert(it,s2) ] = M[it]; added=true; TRACEN(">1 " << s2.source() << " " << s2.target()); } if (n1 > 0 && !s1.is_degenerate()) - { M[ L.insert(it,s1) ] = M[it]; } + { M[ L.insert(it,s1) ] = M[it]; added = true; TRACEN(">1 " << s1.source() << " " << s1.target()); } int n2 = it->intersection(yzcircle.opposite(),s1,s2); if (n2 > 1 && !s2.is_degenerate()) - { M[ L.insert(it,s2) ] = M[it]; } + { M[ L.insert(it,s2) ] = M[it]; added=true; TRACEN(">1 " << s2.source() << " " << s2.target()); } if (n2 > 0 && !s1.is_degenerate()) - { M[ L.insert(it,s1) ] = M[it]; } - itl = it; --it; L.erase(itl); M[itl] = T(); + { M[ L.insert(it,s1) ] = M[it]; added=true; TRACEN(">1 " << s1.source() << " " << s1.target()); } + if(added) { + itl = it; --it; L.erase(itl); M[itl] = T(); + } // at least one item was appended } } @@ -1000,7 +1008,6 @@ complete_face_support(SVertex_iterator v_start, SVertex_iterator v_end, if(supp_object(e,i) != NULL) break; } - if(supp_object(e,i) != NULL) { SHalfedge_handle ei; if ( assign(ei,supp_object(e,i)) ) { @@ -1035,7 +1042,7 @@ complete_face_support(SVertex_iterator v_start, SVertex_iterator v_end, for (int i=0; i<2; ++i) { SObject_handle o = supp_object(v,i); - if ( o == NULL ) { mark(v,i) = m_buffer[i]; continue; } + if ( o == NULL ) { TRACEN("no vertex support"); mark(v,i) = m_buffer[i]; continue; } SVertex_handle vs; SHalfedge_handle es; SHalfloop_handle ls; @@ -1235,7 +1242,9 @@ select(const Selection& SP) const template void SNC_SM_overlayer::simplify() const { + TRACEN("simplifying"); + /* typedef typename CGAL::Partition::item partition_item; CGAL::Unique_hash_map Pitem; CGAL::Partition FP; */ @@ -1257,33 +1266,17 @@ void SNC_SM_overlayer::simplify() const TRACEN("deleting "< linked(false); @@ -1302,21 +1295,6 @@ void SNC_SM_overlayer::simplify() const link_as_loop(twin(l),f); } - SVertex_handle vi; - CGAL_nef3_forall_svertices(vi,*this) - TRACEN(PH(vi) << " " << mark(vi)); - TRACEN(" "); - - SHalfedge_handle ei; - CGAL_nef3_forall_shalfedges(ei,*this) - TRACEN(PH(ei)<< " " << mark(ei)); - TRACEN(" "); - - SFace_handle ff; - CGAL_nef3_forall_sfaces(ff,*this) - TRACEN(&*ff << " " << mark(ff)); - TRACEN(" "); - SVertex_iterator v,vn; for(v = svertices_begin(); v != svertices_end(); v=vn) { vn=v; ++vn; @@ -1338,23 +1316,6 @@ void SNC_SM_overlayer::simplify() const } } - - - CGAL_nef3_forall_svertices(vi,*this) - TRACEN(PH(vi) << " " << mark(vi)); - TRACEN(" "); - - - CGAL_nef3_forall_shalfedges(ei,*this) - TRACEN(PH(ei)<< " " << mark(ei)); - TRACEN(" "); - - - - CGAL_nef3_forall_sfaces(ff,*this) - TRACEN(&*ff << " " << mark(ff)); - TRACEN(" "); - SFace_iterator fn; for (f = fn = sfaces_begin(); f != sfaces_end(); f=fn) { ++fn; @@ -1363,22 +1324,6 @@ void SNC_SM_overlayer::simplify() const delete_face_only(f); } - - CGAL_nef3_forall_svertices(vi,*this) - TRACEN(PH(vi) << " " << mark(vi)); - TRACEN(" "); - - - CGAL_nef3_forall_shalfedges(ei,*this) - TRACEN(PH(ei)<< " " << mark(ei)); - TRACEN(" "); - - - - CGAL_nef3_forall_sfaces(ff,*this) - TRACEN(&*ff << " " << mark(ff)); - TRACEN(" "); - } diff --git a/Packages/Nef_3/include/CGAL/Nef_3/SNC_SM_point_locator.h b/Packages/Nef_3/include/CGAL/Nef_3/SNC_SM_point_locator.h index 3535346f8e0..bef2b0076ec 100644 --- a/Packages/Nef_3/include/CGAL/Nef_3/SNC_SM_point_locator.h +++ b/Packages/Nef_3/include/CGAL/Nef_3/SNC_SM_point_locator.h @@ -456,7 +456,12 @@ void SNC_SM_point_locator::init_marks_of_halfspheres() else mark_of_halfsphere(-1) = mark(face(e)); return; } - CGAL_nef3_assertion_msg(0,"damn wrong type."); + /* + TRACEN("1 dimensional object"); + mark_of_halfsphere(-1) = mark_of_halfsphere(+1) = 0; + */ + CGAL_nef3_assertion_msg(0,"damn wrong type"); + return; } CGAL_END_NAMESPACE diff --git a/Packages/Nef_3/include/CGAL/Nef_3/SNC_constructor.h b/Packages/Nef_3/include/CGAL/Nef_3/SNC_constructor.h index 225ca8dfb74..115ee93b327 100644 --- a/Packages/Nef_3/include/CGAL/Nef_3/SNC_constructor.h +++ b/Packages/Nef_3/include/CGAL/Nef_3/SNC_constructor.h @@ -97,9 +97,14 @@ int sign_of(const CGAL::Plane_3& h) template CGAL::Plane_3 normalized(CGAL::Plane_3& h) -{ typedef typename R::RT RT; - RT a(h.a()),b(h.b()),c(h.c()),d(h.d()); - RT x = (a==0) ? ((b==0) ? ((c==0) ? ((d==0) ? 1: d): c): b): a; +{ + typedef typename R::RT::NT NT; + CGAL_assertion(h.a().degree()==0); + CGAL_assertion(h.b().degree()==0); + CGAL_assertion(h.c().degree()==0); + CGAL_assertion(h.d().degree()==0); + NT a(h.a().eval_at(1)),b(h.b().eval_at(1)),c(h.c().eval_at(1)),d(h.d().eval_at(1)); + NT x = (a==0) ? ((b==0) ? ((c==0) ? ((d==0) ? 1: d): c): b): a; TRACE("gcd... i"< { public: typedef SNC_structure_ SNC_structure; - typedef typename SNC_structure_::Sphere_kernel Sphere_kernel; - typedef typename SNC_structure_::Kernel Kernel; + typedef typename SNC_structure_::Sphere_kernel Sphere_kernel; + typedef typename SNC_structure_::Kernel Kernel; typedef CGAL::SNC_constructor Self; typedef CGAL::SNC_decorator Base; typedef CGAL::SNC_decorator SNC_decorator; - typedef CGAL::SNC_ray_shooter SNC_ray_shooter; + typedef CGAL::SNC_ray_shooter SNC_ray_shooter; typedef CGAL::SNC_FM_decorator FM_decorator; typedef CGAL::SNC_SM_decorator SM_decorator; typedef CGAL::SNC_SM_overlayer SM_overlayer; @@ -258,11 +263,12 @@ public: } void visit(Halfedge_handle h) { TRACEN("visit he "<sfaces_begin(); if( Closed[sf] ) { - SM_decorator SD(D.vertex(h)); - if( SD.first_out_edge(h) == SD.last_out_edge(h) ) + if( SD.is_isolated(h) || SD.first_out_edge(h) == SD.last_out_edge(h) ) { Closed[sf] = false; + } } } void visit(Halffacet_handle h) { /* do nothing */ } @@ -281,6 +287,10 @@ public: Vertex_handle create_box_corner(int x, int y, int z, bool space=true, bool boundary=true) const; + + Vertex_handle create_extended_box_corner(int x, int y, int z, + bool space=true, bool boundary=true) const; + /*{\Mop produces the sphere map representing thp,e box corner in direction $(x,y,z)$.}*/ @@ -317,6 +327,7 @@ public: /*{\Mop determines the volume |C| that a shell |S| pointed by |sf| belongs to. \precondition |S| separates the volume |C| from an enclosed volume.}*/ { + TRACEN("determine volume"); Vertex_handle v_min = MinimalVertex[Shell[sf]]; Halffacet_handle f_below = get_facet_below(v_min); if ( f_below == Halffacet_handle()) @@ -342,11 +353,12 @@ public: // ######### Non-generic code ########## Segment_3 ray( p, Point_3( p.hx(), p.hy(), -INT_MAX*p.hw(), p.hw())); // #################################### - SNC_ray_shooter rs(*sncp()); + SNC_ray_shooter rs(*sncp()); Object_handle o = rs.shoot(ray); Vertex_handle v; Halfedge_handle e; Halffacet_handle f; + TRACEN("get_facet_below"); if( assign(v, o)) { TRACEN("facet below from from vertex..."); f_below = get_visible_facet(v, ray); @@ -430,6 +442,58 @@ create_box_corner(int x, int y, int z, bool space, bool boundary) const { return v; } +template +typename SNC_::Vertex_handle +SNC_constructor:: +create_extended_box_corner(int x, int y, int z, bool space, bool boundary) const { + CGAL_nef3_assertion(CGAL_NTS abs(x) == CGAL_NTS abs(y) && + CGAL_NTS abs(y) == CGAL_NTS abs(z)); + TRACEN(" constructing box corner on "<new_vertex( epoint(x,0,y,0,z,0,1), boundary); + SM_decorator SD(v); + Sphere_point sp[] = { Sphere_point(-x, 0, 0), + Sphere_point(0, -y, 0), + Sphere_point(0, 0, -z) }; + /* create box vertices */ + SVertex_handle sv[3]; + for(int vi=0; vi<3; ++vi) { + sv[vi] = SD.new_vertex(sp[vi]); + mark(sv[vi]) = boundary; + } + /* create facet's edge uses */ + Sphere_segment ss[3]; + SHalfedge_handle she[3]; + for(int si=0; si<3; ++si) { + she[si] = SD.new_edge_pair(sv[si], sv[(si+1)%3]); + ss[si] = Sphere_segment(sp[si],sp[(si+1)%3]); + SD.circle(she[si]) = ss[si].sphere_circle(); + SD.circle(SD.twin(she[si])) = ss[si].opposite().sphere_circle(); + SD.mark(she[si]) = boundary; + } + /* create facets */ + SFace_handle fi = SD.new_face(); + SFace_handle fe = SD.new_face(); + SD.link_as_face_cycle(she[0], fi); + SD.link_as_face_cycle(SD.twin(she[0]), fe); + /* set face mark */ + SHalfedge_iterator e = SD.shalfedges_begin(); + SFace_handle f; + Sphere_point p1 = SD.point(SD.source(e)); + Sphere_point p2 = SD.point(SD.target(e)); + Sphere_point p3 = SD.point(SD.target(SD.next(e))); + if ( spherical_orientation(p1,p2,p3) > 0 ) + f = SD.face(e); + else + f = SD.face(SD.twin(e)); + SD.mark(f) = space; + // SD.mark_of_halfsphere(-1) = (x<0 && y>0 && z>0); + // SD.mark_of_halfsphere(+1) = (x>0 && y>0 && z<0); + /* TODO: to check if the commented code above could be wrong */ + SM_point_locator L(v); + L.init_marks_of_halfspheres(); + return v; +} + // ---------------------------------------------------------------------------- // create_from_facet() // Creates the local graph of a facet f at point p. @@ -533,7 +597,9 @@ create_from_edge(Halfedge_handle e, template void SNC_constructor:: pair_up_halfedges() const -{ TRACEN(">>>>>pair_up_halfedges"); +{ + // SETDTHREAD(43*61); + TRACEN(">>>>>pair_up_halfedges"); typedef Halfedge_key< Point_3, Halfedge_handle, SNC_decorator> Halfedge_key; typedef Halfedge_key_lt< Point_3, Halfedge_handle, SNC_decorator> @@ -550,18 +616,20 @@ pair_up_halfedges() const Halfedge_iterator e; CGAL_nef3_forall_halfedges(e,*sncp()) { Point_3 p = point(vertex(e)); - Pluecker_line_3 l(p, p + tmp_point(e)); + Pluecker_line_3 l(p, p + Vector_3(tmp_point(e))); int inverted; l = categorize(l,inverted); M[l].push_back(Halfedge_key(p,inverted,e,D)); - TRACEN(" ("<second.sort(Halfedge_key_lt()); - TRACEN("search opposite "<first<< "\n " <<(debug_container(it->second),"")<< std::endl); + TRACEN("search opposite "<first<< "\n "); typename Halfedge_list::iterator itl; + CGAL_nef3_forall_iterators(itl,it->second) + TRACEN(PH(itl->e)); CGAL_nef3_forall_iterators(itl,it->second) { Halfedge_handle e1 = itl->e; ++itl; CGAL_nef3_assertion(itl != it->second.end()); @@ -717,6 +785,7 @@ create_volumes() const SFace_handle f = EntrySFace[i]; CGAL_nef3_assertion( Shell[EntrySFace[i]] == i ); if( Closed[f] ) { + TRACEN("Shell #" << i << " is closed"); SM_decorator SD(v); Volume_handle c = sncp()->new_volume(); mark(c) = SD.mark(f); diff --git a/Packages/Nef_3/include/CGAL/Nef_3/SNC_decorator.h b/Packages/Nef_3/include/CGAL/Nef_3/SNC_decorator.h index 8fa2c5cd391..101d70cf4d2 100644 --- a/Packages/Nef_3/include/CGAL/Nef_3/SNC_decorator.h +++ b/Packages/Nef_3/include/CGAL/Nef_3/SNC_decorator.h @@ -371,7 +371,7 @@ public: template void set_facet(H h, Halffacet_handle f) const { h->incident_facet_ = f; } void set_volume(Halffacet_handle h, Volume_handle c) const - { h->volume_ = c; } + { TRACEN("VOLUME dec"); h->volume_ = c; } void set_volume(SFace_handle h, Volume_handle c) const { h->incident_volume_ = c; } @@ -428,9 +428,18 @@ public: TRACEN( "Locating " << sp <<" in " << point(v)); SM_point_locator L(v); SObject_handle o = L.locate(sp); + SFace_const_handle sf; - CGAL_nef3_assertion( assign( sf, o)); - assign( sf, o); + // CGAL_nef3_assertion(assign(sf,o)); + // assign(sf,o); + if(!assign( sf, o)) + return Halffacet_handle(); + /* SM_decorator SD; + if(sncp()->halfedges_begin() == sncp()->halfedges_end() || + SD.is_isolated(sncp()->halfedges_begin())) + return Halffacet_handle(); + */ + SFace_cycle_const_iterator fc = sf->sface_cycles_begin(), fce = sf->sface_cycles_end(); if( is_empty_range( fc, fce)) { @@ -442,18 +451,22 @@ public: SHalfloop_handle sl; if ( assign( se, fc)) { TRACEN( "adjacent facet found (SEdges cycle)."); + TRACEN("se" << PH(se)); f_visible = facet(twin(se)); + TRACEN("f_visible" << &f_visible); } else if ( assign( sl, fc)) { TRACEN( "adjacent facet found (SHalfloop cycle)."); f_visible = facet(twin(sl)); } else - CGAL_nef3_assertion_msg(0, "Damn, wrong handle."); + // CGAL_nef3_assertion_msg(0,"Damn wrong handle"); + return Halffacet_handle(); } + TRACEN("return"); return f_visible; } - + Halffacet_handle get_visible_facet( const Halfedge_handle e, const Segment_3& ray) const /*{\Mop when one shoot a ray |ray| in order to find the facet below to @@ -631,7 +644,7 @@ public: O1.print(); #endif // CGAL_NEF3_DUMP_SNC_OPERATORS - // SETDTHREAD(131*19*43); + SETDTHREAD(131*19*43); TRACEN("=> for all v0 in snc0, qualify v0 with respect snc1"); @@ -799,7 +812,10 @@ public: } // synthesis of spatial structure + SNC_constructor C(result); + SNC_io_parser Op(std::cout, result); + Op.print(); C.pair_up_halfedges(); C.link_shalfedges_to_facet_cycles(); C.categorize_facet_cycles_and_create_facets(); @@ -890,20 +906,24 @@ visit_shell_objects(SFace_handle f, Visitor& V) const while ( true ) { if ( SFaceCandidates.empty() && FacetCandidates.empty() ) break; if ( !FacetCandidates.empty() ) { + TRACEN("Facet"); Halffacet_handle f = *FacetCandidates.begin(); FacetCandidates.pop_front(); V.visit(f); // report facet Halffacet_cycle_iterator fc; CGAL_nef3_forall_facet_cycles_of(fc,f) { SHalfedge_handle e; SHalfloop_handle l; - if ( assign(e,fc) ) { + if ( assign(e,fc) ) { + TRACEN("Sedge assigned"); SHalfedge_around_facet_circulator ec(e),ee(e); CGAL_For_all(ec,ee) { e = twin(ec); if ( Done[sface(e)] ) continue; SFaceCandidates.push_back(sface(e)); Done[sface(e)] = true; } - } else if ( assign(l,fc) ) { l = twin(l); + } else if ( assign(l,fc) ) { + TRACEN("sloop assigned"); + l = twin(l); if ( Done[sface(l)] ) continue; SFaceCandidates.push_back(sface(l)); Done[sface(l)] = true; @@ -911,16 +931,24 @@ visit_shell_objects(SFace_handle f, Visitor& V) const } } if ( !SFaceCandidates.empty() ) { + TRACEN("Sface"); SFace_handle sf = *SFaceCandidates.begin(); SFaceCandidates.pop_front(); V.visit(sf); if ( !Done[vertex(sf)] ) V.visit(vertex(sf)); // report vertex + SVertex_handle sv; + SM_decorator SD(vertex(sf)); + CGAL_nef3_forall_svertices(sv,SD){ + if(SD.is_isolated(sv) && !Done[sv]) + V.visit(sv); + } SFace_cycle_iterator fc; CGAL_nef3_forall_sface_cycles_of(fc,sf) { SVertex_handle v; SHalfedge_handle e; SHalfloop_handle l; if ( assign(e,fc) ) { - SHalfedge_around_sface_circulator ec(e),ee(e); + TRACEN("sedge assigned2"); + SHalfedge_around_sface_circulator ec(e),ee(e); CGAL_For_all(ec,ee) { v = starget(ec); if ( !Done[v] ) { @@ -932,14 +960,21 @@ visit_shell_objects(SFace_handle f, Visitor& V) const FacetCandidates.push_back(f); Done[f] = true; } } else if ( assign(v,fc) ) { + TRACEN("svertex assigned"); if ( Done[v] ) continue; V.visit(v); // report edge Done[v] = Done[twin(v)] = true; // note that v is isolated, thus twin(v) is isolated too - SFace_handle fo = sface(twin(v)); - if ( Done[fo] ) continue; + SM_decorator SD; + SFace_handle fo; + if(SD.is_isolated(v)) + fo = source(v)->sfaces_begin(); + else + fo = sface(twin(v)); + if ( Done[fo] ) continue; SFaceCandidates.push_back(fo); Done[fo] = true; } else if ( assign(l,fc) ) { + TRACEN("sloop assigned"); Halffacet_handle f = facet(twin(l)); if ( Done[f] ) continue; FacetCandidates.push_back(f); Done[f] = true; diff --git a/Packages/Nef_3/include/CGAL/Nef_3/SNC_items.h b/Packages/Nef_3/include/CGAL/Nef_3/SNC_items.h index 347aa175697..7d04b0906ef 100644 --- a/Packages/Nef_3/include/CGAL/Nef_3/SNC_items.h +++ b/Packages/Nef_3/include/CGAL/Nef_3/SNC_items.h @@ -445,6 +445,7 @@ public: { supporting_plane_ = f.supporting_plane_; mark_ = f.mark_; twin_ = f.twin_; + TRACEN("VOLUME const"); volume_ = f.volume_; boundary_entry_objects_ = f.boundary_entry_objects_; } @@ -454,6 +455,7 @@ public: supporting_plane_ = f.supporting_plane_; mark_ = f.mark_; twin_ = f.twin_; + TRACEN("VOLUME op="); volume_ = f.volume_; boundary_entry_objects_ = f.boundary_entry_objects_; return *this; diff --git a/Packages/Nef_3/include/CGAL/Nef_3/SNC_ray_shooter.h b/Packages/Nef_3/include/CGAL/Nef_3/SNC_ray_shooter.h index 53b27d067b3..12dd8e92ebe 100644 --- a/Packages/Nef_3/include/CGAL/Nef_3/SNC_ray_shooter.h +++ b/Packages/Nef_3/include/CGAL/Nef_3/SNC_ray_shooter.h @@ -80,7 +80,7 @@ class SNC_ray_shooter : public SNC_decorator typedef SNC_structure_ SNC_structure; protected: - typedef SNC_ray_shooter Self; + typedef SNC_ray_shooter Self; typedef SNC_decorator Base; public: @@ -233,21 +233,24 @@ public: return Object_handle(f); } } - Volume_handle c; /* lets be |s| be the segment that connects |p| to any fixed vertex |va| */ Vertex_handle va = --(sncp()->vertices_end()); Segment_3 s( p, point(va)); /* prune |s| by |o| if |o| intersects |s| in its relative interior */ Object_handle o = shoot(s); /* determine the volume that contains |s| from the last pruning object */ + + Halffacet_handle hf; if( assign( v, o)) - c = volume(get_visible_facet( v, s)); + hf = get_visible_facet( v, s); else if( assign( e, o)) - c = volume(get_visible_facet( e, s)); + hf = get_visible_facet( e, s); else if( assign( f, o)) - c = volume(get_visible_facet( f, s)); + hf = get_visible_facet( f, s); else CGAL_nef3_assertion_msg(0, "where is our point, eh?"); - return Object_handle(c); + if(hf==Halffacet_handle()) + return ++(sncp()->volumes_begin()); + return Object_handle(volume(hf)); } void shorten(Segment_3& s, const Point_3& p) const { @@ -255,10 +258,11 @@ public: TRACEN("shooted ray "<>> simplifying"); SNC_decorator D(*this); - SNC_io_parser IO_parser(std::cout, *this); + SNC_io_parser IO_parser(std::cerr, *this); IO = &IO_parser; Unique_hash_map< Volume_handle, UFH_volume> hash_volume; @@ -1087,7 +1088,7 @@ public: hash_sface[sf] = uf_sface.make_set(sf); reset_sm_object_list(sf->boundary_entry_objects_); } - + /* * Volumes simplification */ @@ -1103,7 +1104,7 @@ public: CGAL_nef3_assertion( f != D.twin(f)); Volume_handle c1 = D.volume(f), c2 = D.volume(D.twin(f)); TRACEN(" mark("<index(c1)<<")="<index(f) <<")="<index(f) <<")="<index(c2)<<")="<index(e)<<' '<index(D.twin(e))); - delete_halfedge_pair(e); + if( SD.is_isolated(e)) { + if(D.mark(e) == D.mark(D.volume(D.source(e)->sfaces_begin()))) { + TRACEN("removing pair "<index(e)<<' '<index(D.twin(e))); + delete_halfedge_pair(e); + } } else { if( D.has_outdeg_two(e)) { @@ -1159,8 +1163,10 @@ public: } } } + e = e_next; } + /* * Vertices simplification @@ -1202,14 +1208,13 @@ public: v = v_next; } - purge_no_find_objects(hash_volume, hash_facet, hash_sface, - uf_volume, uf_facet, uf_sface); + purge_no_find_objects(hash_volume, hash_facet, hash_sface, uf_volume, uf_facet, uf_sface); create_boundary_links_forall_sfaces( hash_sface, uf_sface); create_boundary_links_forall_facets( hash_facet, uf_facet); create_boundary_links_forall_volumes( hash_volume, uf_volume); TRACEN(">>> simplifying done"); - } + } void remove_edge_and_merge_facet_cycles( Halfedge_handle e) { SNC_decorator D(*this); @@ -1322,7 +1327,7 @@ public: CGAL_nef3_forall_svertices(sv, *this) { SM_decorator SD(D.vertex(sv)); if( SD.is_isolated(sv)) { - SFace_handle sf = *(uf.find(hash[D.sface(sv)])); + SFace_handle sf = *(uf.find(hash[D.source(sv)->sfaces_begin()])); CGAL_nef3_assertion( sf != SFace_handle()); SD.set_face( sv, sf); SD.store_boundary_object( sv, sf); @@ -1563,7 +1568,7 @@ pointer_update(const SNC_structure& D) for(sfc = sf->sface_cycles_begin(); sfc != sf->sface_cycles_end(); ++sfc) { SVertex_handle sv; - if ( assign(sv,sf) ) + if ( assign(sv,sfc) ) { *sfc = SObject_handle(EM[sv]); store_sm_boundary_item(sv,sfc); } else if ( assign(se,sfc) ) { *sfc = SObject_handle(SEM[se]); store_sm_boundary_item(se,sfc); } diff --git a/Packages/Nef_3/include/CGAL/Nef_3/bounded_side_3.h b/Packages/Nef_3/include/CGAL/Nef_3/bounded_side_3.h index b9e729b599f..2dbb3c83c89 100644 --- a/Packages/Nef_3/include/CGAL/Nef_3/bounded_side_3.h +++ b/Packages/Nef_3/include/CGAL/Nef_3/bounded_side_3.h @@ -79,7 +79,8 @@ Bounded_side bounded_side_3(IteratorForward first, plane = Plane_3(p0, p1, p2); /* since we just need to project the points to a non-perpendicular plane we don't need to care about the plane orientation */ - } + } + CGAL_assertion(!plane.is_degenerate()); TRACEN(plane); Point_2 (*t)(Point_3); diff --git a/Packages/Nef_3/include/CGAL/Nef_polyhedron_3.h b/Packages/Nef_3/include/CGAL/Nef_polyhedron_3.h index 080834228e7..2dbcfc53696 100644 --- a/Packages/Nef_3/include/CGAL/Nef_polyhedron_3.h +++ b/Packages/Nef_3/include/CGAL/Nef_polyhedron_3.h @@ -232,6 +232,18 @@ protected: SFace_const_iterator; + void initialize_extended_cube_vertices(Content space) { + SNC_constructor C(snc()); + C.create_extended_box_corner( 1, 1, 1, space ); + C.create_extended_box_corner(-1, 1, 1, space ); + C.create_extended_box_corner( 1,-1, 1, space ); + C.create_extended_box_corner(-1,-1, 1, space ); + C.create_extended_box_corner( 1, 1,-1, space ); + C.create_extended_box_corner(-1, 1,-1, space ); + C.create_extended_box_corner( 1,-1,-1, space ); + C.create_extended_box_corner(-1,-1,-1, space ); + } + void initialize_simple_cube_vertices(Content space) { SNC_constructor C(snc()); C.create_box_corner( INT_MAX, INT_MAX, INT_MAX, space ); @@ -287,12 +299,11 @@ public: typedef Polyhedron_3< Kernel> Polyhedron; Nef_polyhedron_3( Polyhedron& P) { - SETDTHREAD(11*131*19*43); initialize_simple_cube_vertices(EMPTY); polyhedron_3_to_nef_3< Polyhedron, SNC_structure, SNC_constructor> ( P, snc() ); - // build_external_structure(); - // simplify(); + build_external_structure(); + simplify(); } template @@ -566,7 +577,7 @@ public: Nef_polyhedron_3 intersection(Nef_polyhedron_3& N1) /*{\Mop returns |\Mvar| $\cap$ |N1|. }*/ { - SETDTHREAD(11*131*19*43); + TRACEN(" intersection between nef3 "<<&*this<<" and "<<&N1); AND _and; SNC_structure rsnc; @@ -581,6 +592,7 @@ public: /*{\Mop returns |\Mvar| $\cup$ |N1|. }*/ { TRACEN(" join between nef3 "<<&*this<<" and "<<&N1); OR _or; + // SETDTHREAD(131*19*43); SNC_structure rsnc; SNC_decorator D(snc()); D.binary_operation( N1.snc(), _or, rsnc);