From 9832ce9d9b6dae3e112bb57c687572ede6d7fd9e Mon Sep 17 00:00:00 2001 From: Nico Kruithof Date: Mon, 7 Aug 2006 13:47:15 +0000 Subject: [PATCH] - Make the examples working - Comment old code - Try caching --- .../skin_surface_pdb_reader.cpp | 11 +- .../Skin_surface_3/skin_surface_simple.cpp | 8 - .../Skin_surface_3/union_of_balls_simple.cpp | 2 +- Skin_surface_3/include/CGAL/Skin_surface_3.h | 210 +++++++++++------- .../include/CGAL/Triangulation_simplex_3.h | 38 +++- .../include/CGAL/mesh_skin_surface_3.h | 4 +- 6 files changed, 172 insertions(+), 101 deletions(-) diff --git a/Skin_surface_3/examples/Skin_surface_3/skin_surface_pdb_reader.cpp b/Skin_surface_3/examples/Skin_surface_3/skin_surface_pdb_reader.cpp index 64fce8970c4..e7a6914c1bd 100644 --- a/Skin_surface_3/examples/Skin_surface_3/skin_surface_pdb_reader.cpp +++ b/Skin_surface_3/examples/Skin_surface_3/skin_surface_pdb_reader.cpp @@ -11,7 +11,7 @@ #include "skin_surface_writer.h" typedef CGAL::Exact_predicates_inexact_constructions_kernel K; -typedef CGAL::Regular_triangulation_euclidean_traits_3 Traits; +typedef CGAL::Mixed_complex_traits_3 Traits; typedef CGAL::Skin_surface_3 Skin_surface_3; typedef Skin_surface_3::RT RT; typedef Skin_surface_3::Weighted_point Weighted_point; @@ -29,20 +29,17 @@ int main(int argc, char *argv[]) { extract_balls_from_pdb(argv[1], K(), std::back_inserter(l)); // Construct skin surface: - Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor, true, - Traits(), true); + Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor); // Extract mesh from the skin surface: Polyhedron p; CGAL::mesh_skin_surface_3(skin_surface, p); - // CGAL::subdivide_skin_surface_mesh_3(p, skin_surface, 1); - // std::cout << "Subdivided Skin_surface_3" << std::endl; + // Subdivide skin surface + // CGAL::subdivide_skin_surface_mesh_3(p, skin_surface, 1); std::ofstream out("mesh.off"); write_polyhedron_with_normals(p, skin_surface, out); - // write without normals: - //out << p; return 0; } diff --git a/Skin_surface_3/examples/Skin_surface_3/skin_surface_simple.cpp b/Skin_surface_3/examples/Skin_surface_3/skin_surface_simple.cpp index d419ef61060..216210014a1 100644 --- a/Skin_surface_3/examples/Skin_surface_3/skin_surface_simple.cpp +++ b/Skin_surface_3/examples/Skin_surface_3/skin_surface_simple.cpp @@ -7,10 +7,6 @@ #include #include -// NGHK: remove later -#include -#include "skin_surface_writer.h" - typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Mixed_complex_traits_3 Traits; typedef CGAL::Skin_surface_3 Skin_surface_3; @@ -32,9 +28,5 @@ int main(int argc, char *argv[]) { Polyhedron p; CGAL::mesh_skin_surface_3(skin_surface, p); - // NGHK: remove later - std::ofstream out("mesh.off"); - write_polyhedron_with_normals(p, skin_surface, out); - return 0; } diff --git a/Skin_surface_3/examples/Skin_surface_3/union_of_balls_simple.cpp b/Skin_surface_3/examples/Skin_surface_3/union_of_balls_simple.cpp index 6e6c7edc4b3..722bb97fb54 100644 --- a/Skin_surface_3/examples/Skin_surface_3/union_of_balls_simple.cpp +++ b/Skin_surface_3/examples/Skin_surface_3/union_of_balls_simple.cpp @@ -6,7 +6,7 @@ #include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; -typedef CGAL::Regular_triangulation_euclidean_traits_3 Traits; +typedef CGAL::Mixed_complex_traits_3 Traits; typedef CGAL::Union_of_balls_3 Union_of_balls_3; typedef Union_of_balls_3::RT RT; typedef Union_of_balls_3::Weighted_point Weighted_point; diff --git a/Skin_surface_3/include/CGAL/Skin_surface_3.h b/Skin_surface_3/include/CGAL/Skin_surface_3.h index ebb9afc3f53..3d4ab57826f 100644 --- a/Skin_surface_3/include/CGAL/Skin_surface_3.h +++ b/Skin_surface_3/include/CGAL/Skin_surface_3.h @@ -41,59 +41,59 @@ CGAL_BEGIN_NAMESPACE -template < class GT, - class SkinSurface_3, - class Cb = Triangulation_cell_base_3 > -class Triangulated_mixed_complex_cell_3 : public Cb -{ -public: - typedef typename Cb::Triangulation_data_structure Triangulation_data_structure; - typedef typename Triangulation_data_structure::Vertex_handle Vertex_handle; - typedef typename Triangulation_data_structure::Cell_handle Cell_handle; +// template < class GT, +// class SkinSurface_3, +// class Cb = Triangulation_cell_base_3 > +// class Triangulated_mixed_complex_cell_3 : public Cb +// { +// public: +// typedef typename Cb::Triangulation_data_structure Triangulation_data_structure; +// typedef typename Triangulation_data_structure::Vertex_handle Vertex_handle; +// typedef typename Triangulation_data_structure::Cell_handle Cell_handle; - typedef typename SkinSurface_3::Quadratic_surface Quadratic_surface; - typedef typename SkinSurface_3::Simplex Simplex; +// typedef typename SkinSurface_3::Quadratic_surface Quadratic_surface; +// typedef typename SkinSurface_3::Simplex Simplex; - template < class TDS2 > - struct Rebind_TDS { - typedef typename Cb::template Rebind_TDS::Other Cb2; - typedef Triangulated_mixed_complex_cell_3 - Other; - }; +// template < class TDS2 > +// struct Rebind_TDS { +// typedef typename Cb::template Rebind_TDS::Other Cb2; +// typedef Triangulated_mixed_complex_cell_3 +// Other; +// }; - Triangulated_mixed_complex_cell_3() : Cb() { - } - Triangulated_mixed_complex_cell_3(Vertex_handle v0, Vertex_handle v1, - Vertex_handle v2, Vertex_handle v3) - : Cb(v0, v1, v2, v3) { - } +// Triangulated_mixed_complex_cell_3() : Cb() { +// } +// Triangulated_mixed_complex_cell_3(Vertex_handle v0, Vertex_handle v1, +// Vertex_handle v2, Vertex_handle v3) +// : Cb(v0, v1, v2, v3) { +// } - Quadratic_surface *surf; - Simplex simp; -}; +// Quadratic_surface *surf; +// Simplex simp; +// }; -template < class GT, - class Vb = Triangulation_vertex_base_3 > -class Triangulated_mixed_complex_vertex_3 : public Vb -{ -public: - typedef typename Vb::Point Point; - typedef typename Vb::Cell_handle Cell_handle; +// template < class GT, +// class Vb = Triangulation_vertex_base_3 > +// class Triangulated_mixed_complex_vertex_3 : public Vb +// { +// public: +// typedef typename Vb::Point Point; +// typedef typename Vb::Cell_handle Cell_handle; - template < class TDS2 > - struct Rebind_TDS { - typedef typename Vb::template Rebind_TDS::Other Vb2; - typedef Triangulated_mixed_complex_vertex_3 Other; - }; +// template < class TDS2 > +// struct Rebind_TDS { +// typedef typename Vb::template Rebind_TDS::Other Vb2; +// typedef Triangulated_mixed_complex_vertex_3 Other; +// }; - Triangulated_mixed_complex_vertex_3() {} - Triangulated_mixed_complex_vertex_3(const Point&p) : Vb(p) {} - Triangulated_mixed_complex_vertex_3(const Point&p, Cell_handle c) : Vb(p, c) {} +// Triangulated_mixed_complex_vertex_3() {} +// Triangulated_mixed_complex_vertex_3(const Point&p) : Vb(p) {} +// Triangulated_mixed_complex_vertex_3(const Point&p, Cell_handle c) : Vb(p, c) {} - Sign sign() const { - return Vb::cell()->surf->sign(Vb::point()); - } -}; +// Sign sign() const { +// return Vb::cell()->surf->sign(Vb::point()); +// } +// }; template class Skin_surface_3 { @@ -110,6 +110,9 @@ private: typedef Regular_triangulation_3 Regular; + typedef Exact_predicates_inexact_constructions_kernel Filtered_kernel; + typedef Skin_surface_quadratic_surface_3 + Filtered_quadratic_surface; public: typedef typename Regular::Vertex_handle Vertex_handle; typedef typename Regular::Edge Edge; @@ -118,16 +121,21 @@ public: typedef typename Regular::Cell_handle Cell_handle; typedef Triangulation_simplex_3 Simplex; - // defining the triangulated mixed complex: - typedef Exact_predicates_exact_constructions_kernel TMC_traits; - typedef Skin_surface_quadratic_surface_3 Quadratic_surface; + typedef typename Regular::Finite_vertices_iterator Finite_vertices_iterator; + typedef typename Regular::Finite_edges_iterator Finite_edges_iterator; + typedef typename Regular::Finite_facets_iterator Finite_facets_iterator; + typedef typename Regular::Finite_cells_iterator Finite_cells_iterator; - typedef Triangulation_3< - TMC_traits, - Triangulation_data_structure_3 - < Triangulated_mixed_complex_vertex_3, - Triangulated_mixed_complex_cell_3 > - > Triangulated_mixed_complex; +// // defining the triangulated mixed complex: +// typedef Exact_predicates_exact_constructions_kernel TMC_traits; +// typedef Skin_surface_quadratic_surface_3 Quadratic_surface; + +// typedef Triangulation_3< +// TMC_traits, +// Triangulation_data_structure_3 +// < Triangulated_mixed_complex_vertex_3, +// Triangulated_mixed_complex_cell_3 > +// > Triangulated_mixed_complex; typedef Combinatorial_mixed_complex_triangulator_3 CMCT; typedef typename CMCT::Vertex_handle CMCT_Vertex_handle; typedef typename CMCT::Vertex_iterator CMCT_Vertex_iterator; @@ -135,17 +143,17 @@ public: typedef typename CMCT::Cell_iterator CMCT_Cell_iterator; - typedef typename Triangulated_mixed_complex::Vertex_handle TMC_Vertex_handle; - typedef typename Triangulated_mixed_complex::Cell_handle TMC_Cell_handle; - typedef typename Triangulated_mixed_complex::Vertex_iterator TMC_Vertex_iterator; - typedef typename Triangulated_mixed_complex::Cell_iterator TMC_Cell_iterator; +// typedef typename Triangulated_mixed_complex::Vertex_handle TMC_Vertex_handle; +// typedef typename Triangulated_mixed_complex::Cell_handle TMC_Cell_handle; +// typedef typename Triangulated_mixed_complex::Vertex_iterator TMC_Vertex_iterator; +// typedef typename Triangulated_mixed_complex::Cell_iterator TMC_Cell_iterator; // NGHK: added for the (Delaunay) surface mesher, document typedef Exact_predicates_inexact_constructions_kernel Mesher_Gt; typedef Skin_surface_mesher_oracle_3 Surface_mesher_traits_3; private: - typedef typename TMC_traits::Point_3 TMC_Point; + //typedef typename TMC_traits::Point_3 TMC_Point; public: template < class WP_iterator > @@ -186,6 +194,38 @@ public: // } mc_triangulator = new CMCT(regular, verbose); + +// { +// Simplex s; +// for (Finite_vertices_iterator vit = regular.finite_vertices_begin(); +// vit == regular.finite_vertices_end(); vit++) { +// s= vit; +// filtered_quadr_surfaces[s] = +// construct_surface(s, +// Exact_predicates_inexact_constructions_kernel()); +// } +// for (Finite_edges_iterator eit = regular.finite_edges_begin(); +// eit == regular.finite_edges_end(); eit++) { +// s= eit; +// filtered_quadr_surfaces[s] = +// construct_surface(s, +// Exact_predicates_inexact_constructions_kernel()); +// } +// for (Finite_facets_iterator fit = regular.finite_facets_begin(); +// fit == regular.finite_facets_end(); fit++) { +// s= fit; +// filtered_quadr_surfaces[s] = +// construct_surface(s, +// Exact_predicates_inexact_constructions_kernel()); +// } +// for (Finite_cells_iterator cit = regular.finite_cells_begin(); +// cit == regular.finite_cells_end(); cit++) { +// s= cit; +// filtered_quadr_surfaces[s] = +// construct_surface(s, +// Exact_predicates_inexact_constructions_kernel()); +// } +// } } // const Triangulated_mixed_complex &triangulated_mixed_complex() const { // return _tmc; @@ -313,7 +353,22 @@ public: } template< class Point > Sign sign(const Simplex &sim, const Point &p) const { - return construct_surface(sim, typename Point::R()).sign(p); + try + { + CGAL_PROFILER(std::string("NGHK: calls to : ") + std::string(CGAL_PRETTY_FUNCTION)); + Protect_FPU_rounding P; + Sign result = construct_surface + (sim, + Exact_predicates_inexact_constructions_kernel()).sign(p); + if (! is_indeterminate(result)) + return result; + } + catch (Interval_nt_advanced::unsafe_comparison) {} + CGAL_PROFILER(std::string("NGHK: failures of : ") + std::string(CGAL_PRETTY_FUNCTION)); + Protect_FPU_rounding P(CGAL_FE_TONEAREST); + return construct_surface + (sim, + Exact_predicates_exact_constructions_kernel()).sign(p); } template< class Point > typename Point::R::RT @@ -371,28 +426,22 @@ public: // Use value to make the computation robust (endpoints near the surface) if (value(s1, p1) > value(s2, p2)) std::swap(p1, p2); Simplex sp = s1; - while (sq_dist > 1e-18) { + + while ((s1 != s2) && (sq_dist > 1e-18)) { p = midpoint(p1, p2); sp = locate_mixed(converter(p), sp); - if (sign(sp, p) == NEGATIVE) { p1 = p; } + + if (sign(sp, p) == NEGATIVE) { p1 = p; s1 = sp; } + else { p2 = p; s2 = sp; } + + sq_dist *= .25; + } + while (sq_dist > 1e-18) { + p = midpoint(p1, p2); + if (sign(s1, p) == NEGATIVE) { p1 = p; } else { p2 = p; } sq_dist *= .25; } -// while ((s1 != s2) && (sq_dist > 1e-18)) { -// p = midpoint(p1, p2); -// sp = locate_mixed(converter(p), sp); - -// if (sign(sp, p) == NEGATIVE) { p1 = p; s1 = sp; } -// else { p2 = p; s2 = sp; } - -// sq_dist *= .25; -// } -// while (sq_dist > 1e-18) { -// p = midpoint(p1, p2); -// if (sign(s1, p) == NEGATIVE) { p1 = p; } -// else { p2 = p; } -// sq_dist *= .25; -// } p = midpoint(p1, p2); } @@ -472,10 +521,6 @@ public: CGAL_assertion(false); } - std::cerr << "SKEL 2 1" << std::endl - << " " << p1 << std::endl - << " " << p2 << std::endl - << " 2 0 1" << std::endl; // Find the intersection: intersect(p1, p2, sim, sim, p); } @@ -573,7 +618,7 @@ public: private: // Used to optimize the point location in TMC: - mutable TMC_Cell_handle last_ch; +// mutable TMC_Cell_handle last_ch; void construct_bounding_box(Regular ®ular); @@ -586,6 +631,7 @@ private: // We want to construct this object later (the pointer): CMCT *mc_triangulator; +// std::map filtered_quadr_surfaces; }; template diff --git a/Skin_surface_3/include/CGAL/Triangulation_simplex_3.h b/Skin_surface_3/include/CGAL/Triangulation_simplex_3.h index 52c0d21b682..c91cf95c1d7 100644 --- a/Skin_surface_3/include/CGAL/Triangulation_simplex_3.h +++ b/Skin_surface_3/include/CGAL/Triangulation_simplex_3.h @@ -24,7 +24,9 @@ CGAL_BEGIN_NAMESPACE template < class Triangulation_3 > class Triangulation_simplex_3 { +public: typedef Triangulation_3 T; + typedef Triangulation_simplex_3 Self; typedef typename T::Vertex_handle Vertex_handle; typedef typename T::Edge Edge; typedef typename T::Facet Facet; @@ -36,7 +38,11 @@ class Triangulation_simplex_3 { typedef typename T::Edge_iterator Edge_iterator; typedef typename T::Facet_iterator Facet_iterator; -public: + typedef typename T::Finite_vertices_iterator Finite_vertices_iterator; + typedef typename T::Finite_edges_iterator Finite_edges_iterator; + typedef typename T::Finite_facets_iterator Finite_facets_iterator; + typedef typename T::Finite_cells_iterator Finite_cells_iterator; + Triangulation_simplex_3() : ref(-1), ch() { } Triangulation_simplex_3(Vertex_handle v) { @@ -79,6 +85,36 @@ public: CGAL_assertion (ch != Cell_handle()); } + Self &operator=(const Vertex_handle &vh) { + ch = vh->cell(); + ref = (ch->index(vh) << 2); /* dim == 0 */ + CGAL_assertion (ch != Cell_handle()); + return (*this); + } + Self &operator=(const Finite_vertices_iterator &vh) { + ch = vh->cell(); + ref = (ch->index(vh) << 2); /* dim == 0 */ + CGAL_assertion (ch != Cell_handle()); + return (*this); + } + Self &operator=(const Finite_edges_iterator &eit) { + ch = (*eit).first; + ref = ((((*eit).third<< 2) + (*eit).second) << 2) + 1; /* dim */ + CGAL_assertion (ch != Cell_handle()); + return (*this); + } + Self &operator=(const Finite_facets_iterator &fit) { + ch = (*fit).first; + ref = ((*fit).second << 2) + 2; /* dim */ + CGAL_assertion (ch != Cell_handle()); + return (*this); + } + Self &operator=(const Finite_cells_iterator &cit) { + ch = cit; + ref = 3; /* dim */ + CGAL_assertion (ch != Cell_handle()); + return (*this); + } operator Vertex_handle () const { diff --git a/Skin_surface_3/include/CGAL/mesh_skin_surface_3.h b/Skin_surface_3/include/CGAL/mesh_skin_surface_3.h index e56f181a74f..9d7491099d4 100644 --- a/Skin_surface_3/include/CGAL/mesh_skin_surface_3.h +++ b/Skin_surface_3/include/CGAL/mesh_skin_surface_3.h @@ -33,8 +33,8 @@ template void mesh_skin_surface_3(SkinSurface_3 const &skin_surface, Polyhedron &p) { - typedef typename SkinSurface_3::Triangulated_mixed_complex - Triangulated_mixed_complex; +// typedef typename SkinSurface_3::Triangulated_mixed_complex +// Triangulated_mixed_complex; typedef Marching_tetrahedra_traits_skin_surface_3< SkinSurface_3, typename SkinSurface_3::CMCT_Vertex_iterator,