From f5520fc0840c94bb971c49018ac0aa926eddf7e4 Mon Sep 17 00:00:00 2001 From: Nico Kruithof Date: Fri, 29 Sep 2006 20:26:50 +0000 Subject: [PATCH] working on the subdivision of the skin surface mesh --- .../NGHK_skin_surface_subdiv.cpp | 14 +-- .../Skin_surface_3/skin_surface_writer.h | 3 + ...ching_tetrahedra_observer_skin_surface_3.h | 61 ---------- Skin_surface_3/include/CGAL/Skin_surface_3.h | 109 +++++++++--------- ...n_surface_marching_tetrahedra_observer_3.h | 90 +++++++++++++++ ...3.h => Skin_surface_refinement_policy_3.h} | 40 +++---- .../CGAL/subdivide_skin_surface_mesh_3.h | 32 ++--- 7 files changed, 193 insertions(+), 156 deletions(-) delete mode 100644 Skin_surface_3/include/CGAL/Marching_tetrahedra_observer_skin_surface_3.h create mode 100644 Skin_surface_3/include/CGAL/Skin_surface_marching_tetrahedra_observer_3.h rename Skin_surface_3/include/CGAL/{Skin_surface_refinement_traits_3.h => Skin_surface_refinement_policy_3.h} (74%) diff --git a/Skin_surface_3/examples/Skin_surface_3/NGHK_skin_surface_subdiv.cpp b/Skin_surface_3/examples/Skin_surface_3/NGHK_skin_surface_subdiv.cpp index 839cb4efcc6..e3128cba1c8 100644 --- a/Skin_surface_3/examples/Skin_surface_3/NGHK_skin_surface_subdiv.cpp +++ b/Skin_surface_3/examples/Skin_surface_3/NGHK_skin_surface_subdiv.cpp @@ -1,6 +1,6 @@ // examples/Skin_surface_3/NGHK_skin_surface_subdiv.C -#define CGAL_PROFILE -#define CGAL_NO_ASSERTIONS +//#define CGAL_PROFILE +//#define CGAL_NO_ASSERTIONS #include #include @@ -15,13 +15,11 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Skin_surface_traits_3 Traits; typedef CGAL::Skin_surface_3 Skin_surface_3; -typedef Skin_surface_3::FT FT; +typedef Skin_surface_3::RT RT; typedef Skin_surface_3::Weighted_point Weighted_point; typedef Weighted_point::Point Bare_point; -typedef CGAL::Polyhedron_3< - K, - CGAL::Skin_surface_polyhedral_items_3 - > Polyhedron; +typedef CGAL::Polyhedron_3 > Polyhedron; int main(int argc, char *argv[]) { if (argc < 2) { @@ -30,7 +28,7 @@ int main(int argc, char *argv[]) { } std::list l; - FT shrinkfactor = 0.5; + RT shrinkfactor = 0.5; Weighted_point wp; std::ifstream in(argv[1]); diff --git a/Skin_surface_3/examples/Skin_surface_3/skin_surface_writer.h b/Skin_surface_3/examples/Skin_surface_3/skin_surface_writer.h index cc506ede6a8..c30d475853c 100644 --- a/Skin_surface_3/examples/Skin_surface_3/skin_surface_writer.h +++ b/Skin_surface_3/examples/Skin_surface_3/skin_surface_writer.h @@ -24,6 +24,9 @@ void write_polyhedron_with_normals(SkinSurface &skin, << std::endl; // Write vertices +// typedef CGAL::Skin_surface_subdivision_policy_default_3 +// Subdivision_policy; +// Subdivision_policy *policy = get_subdivision_policy(p, skin); for (Vertex_iterator vit = p.vertices_begin(); vit != p.vertices_end(); vit ++) { Vector_3 n = skin.normal(vit->point()); diff --git a/Skin_surface_3/include/CGAL/Marching_tetrahedra_observer_skin_surface_3.h b/Skin_surface_3/include/CGAL/Marching_tetrahedra_observer_skin_surface_3.h deleted file mode 100644 index 24d9c339132..00000000000 --- a/Skin_surface_3/include/CGAL/Marching_tetrahedra_observer_skin_surface_3.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2005 Rijksuniversiteit Groningen (Netherlands) -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you may redistribute it under -// the terms of the Q Public License version 1.0. -// See the file LICENSE.QPL distributed with CGAL. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// -// -// Author(s) : Nico Kruithof - -#ifndef CGAL_MARCHING_TETRAHEDRA_OBSERVER_SKIN_SURFACE_3_H -#define CGAL_MARCHING_TETRAHEDRA_OBSERVER_SKIN_SURFACE_3_H - -#include - -CGAL_BEGIN_NAMESPACE - -template -class Marching_tetrahedra_observer_skin_surface_3 - : public Marching_tetrahedra_observer_default_3 - -{ -public: - typedef Marching_tetrahedra_observer_default_3 - Base; - - typedef Polyhedron_3 Polyhedron; - - typedef Cell_iterator T_Cell_iterator; - typedef typename Polyhedron::Vertex_handle Polyhedron_vertex_handle; - typedef typename Polyhedron::Facet_handle Polyhedron_facet_handle; - - Marching_tetrahedra_observer_skin_surface_3() : Base() { - } - - Marching_tetrahedra_observer_skin_surface_3( - const Marching_tetrahedra_observer_skin_surface_3& traits2) : Base(traits2) - {} - - void after_facet_insertion( - T_Cell_iterator ch, - Polyhedron_facet_handle fh) { - fh->sim = ch->mixed_cell(); - } - -}; - -CGAL_END_NAMESPACE - -#endif // CGAL_MARCHING_TETRAHEDRA_OBSERVER_SKIN_SURFACE_3_H diff --git a/Skin_surface_3/include/CGAL/Skin_surface_3.h b/Skin_surface_3/include/CGAL/Skin_surface_3.h index 30843153d10..6596e29e2e5 100644 --- a/Skin_surface_3/include/CGAL/Skin_surface_3.h +++ b/Skin_surface_3/include/CGAL/Skin_surface_3.h @@ -41,6 +41,10 @@ #include #include +#include +#include +#include + CGAL_BEGIN_NAMESPACE template @@ -50,10 +54,10 @@ class Skin_surface_3 { public: typedef MixedComplexTraits_3 Geometric_traits; typedef typename Gt::Weighted_point Weighted_point; - typedef typename Gt::FT FT; + typedef typename Weighted_point::Weight RT; // NGHK:: added for the Delaunay mesher typedef typename Gt::Sphere_3 Sphere; - typedef typename Gt::Bare_point Bare_point; + typedef typename Weighted_point::Point Bare_point; typedef typename Gt::Vector_3 Vector; typedef Regular_triangulation_3 Regular; @@ -97,7 +101,7 @@ private: public: template < class WP_iterator > Skin_surface_3(WP_iterator begin, WP_iterator end, - FT shrink_factor, + RT shrink_factor, bool grow_balls = true, Gt gt_ = Gt(), bool _verbose = false @@ -139,12 +143,16 @@ public: class HalfedgeDS> friend class Marching_tetrahedra_traits_skin_surface_3; - template - friend class Skin_surface_subdivision_policy_default_3; - template void mesh_skin_surface_3(Polyhedron_3 &p) const; + // This class has to be a friend: + template + friend class Skin_surface_refinement_policy_3; + + template + void subdivide_skin_surface_mesh_3(Polyhedron_3 &p) const; + Sign sign(const Bare_point &p, const Simplex &start = Simplex()) const { return get_sign(locate_mixed(p,start), p); } @@ -289,13 +297,13 @@ private: (sim, Exact_predicates_exact_constructions_kernel()).sign(p); } - FT + RT value(const Bare_point &p) const { Simplex sim = locate_mixed(p); return value(sim,p); } - FT + RT value(const Simplex &sim, const Bare_point &p) const { return construct_surface(sim, typename Geometric_traits::Kernel()).value(p); @@ -351,11 +359,11 @@ private: Simplex &s1, Simplex &s2, Bare_point &p) const { typedef typename Bare_point::R Traits; - typedef typename Traits::FT FT; + typedef typename Traits::RT RT; Cartesian_converter converter; - FT sq_dist = squared_distance(p1,p2); + RT sq_dist = squared_distance(p1,p2); // 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; @@ -379,9 +387,9 @@ private: p = midpoint(p1, p2); } - void - intersect_with_transversal_segment(Bare_point &p, - const Simplex &start = Simplex()) const + void intersect_with_transversal_segment + (Bare_point &p, + const Simplex &start = Simplex()) const { typedef typename Geometric_traits::Kernel::Plane_3 Plane; @@ -469,8 +477,8 @@ private: typedef Weighted_converter_3 > Converter; typedef typename Traits::Point_3 Point; - typedef typename Traits::FT FT; - typedef CGAL::Weighted_point Weighted_point; + typedef typename Traits::RT RT; + typedef CGAL::Weighted_point Weighted_point; Converter conv; @@ -528,11 +536,11 @@ private: Sphere bounding_sphere() const { return _bounding_sphere; } - FT squared_error_bound() const { + RT squared_error_bound() const { return .01; } - typename Mesher_Gt::FT + typename Mesher_Gt::RT get_density(const typename Mesher_Gt::Point_3 &p) const { // NGHK: Make adaptive return 1; @@ -540,7 +548,7 @@ private: const Regular &get_regular_triangulation() const { return regular; } - FT get_shrink_factor() const { + RT get_shrink_factor() const { return gt.get_shrink(); } @@ -568,12 +576,12 @@ construct_bounding_box(Regular ®ular) typedef typename Regular::Geom_traits GT; typedef typename GT::Bare_point Point; typedef typename GT::Point Weighted_point; - typedef typename GT::FT FT; + typedef typename GT::RT RT; Finite_vertices_iterator vit = regular.finite_vertices_begin(); if (vit != regular.finite_vertices_end()) { Bbox_3 bbox = vit->point().bbox(); - FT max_weight=vit->point().weight(); + RT max_weight=vit->point().weight(); while (++vit != regular.finite_vertices_end()) { bbox = bbox + vit->point().bbox(); if (max_weight < vit->point().weight()) @@ -581,12 +589,12 @@ construct_bounding_box(Regular ®ular) } // add a bounding octahedron: - FT dx = bbox.xmax() - bbox.xmin(); - FT dy = bbox.ymax() - bbox.ymin(); - FT dz = bbox.zmax() - bbox.zmin(); + RT dx = bbox.xmax() - bbox.xmin(); + RT dy = bbox.ymax() - bbox.ymin(); + RT dz = bbox.zmax() - bbox.zmin(); Bare_point mid(bbox.xmin() + dx/2, bbox.ymin() + dy/2, bbox.zmin() + dz/2); - FT dr = sqrt(CGAL::to_double(max_weight)) + .001; + RT dr = sqrt(CGAL::to_double(max_weight)) + .001; regular.insert(Weighted_point( Bare_point(bbox.xmax()+(dy+dz+dr)/gt.get_shrink(),mid.y(),mid.z()),-1)); @@ -790,30 +798,6 @@ locate_mixed(const Bare_point &p, const Simplex &start) const { return s; } -template -struct Skin_surface_3_marching_tetrahedra_observer { - typedef Marching_tetrahedra_observer_default_3< - typename SkinSurface_3::CMCT_Vertex_iterator, - typename SkinSurface_3::CMCT_Cell_iterator, - Polyhedron_3> value_type; -}; - -template -struct Skin_surface_3_marching_tetrahedra_observer - > > -{ - typedef Polyhedron_3 - > Polyhedron; - typedef Marching_tetrahedra_observer_skin_surface_3< - typename SkinSurface_3::CMCT_Vertex_iterator, - typename SkinSurface_3::CMCT_Cell_iterator, - Polyhedron> value_type; -}; - - template template void @@ -826,14 +810,15 @@ Skin_surface_3::mesh_skin_surface_3(Polyhedron_3 &p) const Self, CMCT_Vertex_iterator, CMCT_Cell_iterator, - typename Polyhedron::HalfedgeDS> Marching_tetrahedra_traits; - typedef typename - Skin_surface_3_marching_tetrahedra_observer::value_type - Marching_tetrahedra_observer; + typename Polyhedron::HalfedgeDS> Traits; + typedef Skin_surface_marching_tetrahedra_observer_3< + CMCT_Vertex_iterator, + CMCT_Cell_iterator, + Polyhedron> Observer; // Extract the coarse mesh using marching_tetrahedra - Marching_tetrahedra_traits marching_traits(*this); - Marching_tetrahedra_observer marching_observer; + Traits marching_traits(*this); + Observer marching_observer; marching_tetrahedra_3(cmct_vertices_begin(), cmct_vertices_end(), cmct_cells_begin(), @@ -843,6 +828,22 @@ Skin_surface_3::mesh_skin_surface_3(Polyhedron_3 &p) const marching_observer); } +template +template +void +Skin_surface_3::subdivide_skin_surface_mesh_3(Polyhedron_3 &p) const { + std::cout << "Skin_Surface_3.subdivide_skin_surface_mesh_3(p)" << std::endl; + + typedef Skin_surface_refinement_policy_3 Policy; + typedef Skin_surface_sqrt3 Subdivider; + + Policy policy(*this); + Subdivider subdivider(*this, p, policy); + subdivider.subdivide(); +} + + + CGAL_END_NAMESPACE diff --git a/Skin_surface_3/include/CGAL/Skin_surface_marching_tetrahedra_observer_3.h b/Skin_surface_3/include/CGAL/Skin_surface_marching_tetrahedra_observer_3.h new file mode 100644 index 00000000000..410cdc1411c --- /dev/null +++ b/Skin_surface_3/include/CGAL/Skin_surface_marching_tetrahedra_observer_3.h @@ -0,0 +1,90 @@ +// Copyright (c) 2005 Rijksuniversiteit Groningen (Netherlands) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Nico Kruithof + +#ifndef CGAL_SKIN_SURFACE_MARCHING_TETRAHEDRA_OBSERVER_3_H +#define CGAL_SKIN_SURFACE_MARCHING_TETRAHEDRA_OBSERVER_3_H + +#include + +CGAL_BEGIN_NAMESPACE + +template +class Skin_surface_marching_tetrahedra_observer_3 + : public Marching_tetrahedra_observer_default_3 + +{ + typedef Polyhedron_3 Polyhedron; + typedef Marching_tetrahedra_observer_default_3 + Base; + +public: + Skin_surface_marching_tetrahedra_observer_3() : Base() { + std::cout << "Default Skin_surface_marching_tetrahedra_observer_3" + << std::endl; + } + +}; + + +template +class Skin_surface_marching_tetrahedra_observer_3 + > > + : public Marching_tetrahedra_observer_default_3 + > > +{ +public: + typedef Polyhedron_3 > + Polyhedron; + typedef Marching_tetrahedra_observer_default_3 + Base; + + typedef Cell_iterator T_Cell_iterator; + typedef typename Polyhedron::Vertex_handle Polyhedron_vertex_handle; + typedef typename Polyhedron::Facet_handle Polyhedron_facet_handle; + + Skin_surface_marching_tetrahedra_observer_3() : Base() { + std::cout << "Optimized Skin_surface_marching_tetrahedra_observer_3" + << std::endl; + } + + Skin_surface_marching_tetrahedra_observer_3( + const Skin_surface_marching_tetrahedra_observer_3& traits2) : Base(traits2) + {} + + void after_facet_insertion( + T_Cell_iterator ch, + Polyhedron_facet_handle fh) { + fh->sim = ch->mixed_cell(); + } + +}; + +CGAL_END_NAMESPACE + +#endif // CGAL_SKIN_SURFACE_MARCHING_TETRAHEDRA_OBSERVER_3_H diff --git a/Skin_surface_3/include/CGAL/Skin_surface_refinement_traits_3.h b/Skin_surface_3/include/CGAL/Skin_surface_refinement_policy_3.h similarity index 74% rename from Skin_surface_3/include/CGAL/Skin_surface_refinement_traits_3.h rename to Skin_surface_3/include/CGAL/Skin_surface_refinement_policy_3.h index 0fa4d2ba797..cfa20e9d03b 100644 --- a/Skin_surface_3/include/CGAL/Skin_surface_refinement_traits_3.h +++ b/Skin_surface_3/include/CGAL/Skin_surface_refinement_policy_3.h @@ -17,29 +17,29 @@ // // Author(s) : Nico Kruithof -#ifndef CGAL_SKIN_SURFACE_SUBDIVISION_POLICY_H -#define CGAL_SKIN_SURFACE_SUBDIVISION_POLICY_H +#ifndef CGAL_SKIN_SURFACE_REFINEMENT_POLICY_3_H +#define CGAL_SKIN_SURFACE_REFINEMENT_POLICY_3_H #include CGAL_BEGIN_NAMESPACE // template -// class Skin_surface_subdivision_policy_base_3 { +// class Skin_surface_refinement_policy_3 { // public: // typedef Polyhedron_3 Polyhedron; // typedef SkinSurface_3 Skin_surface; -// typedef typename Polyhedron::Traits P_traits; +// typedef typename Polyhedron::Policy P_policy; // typedef typename Polyhedron::Vertex_handle P_vertex_handle; -// typedef typename P_traits::RT P_rt; -// typedef typename P_traits::Point_3 P_point; -// typedef typename P_traits::Segment_3 P_segment; -// typedef typename P_traits::Line_3 P_line; -// typedef typename P_traits::Vector_3 P_vector; -// typedef typename P_traits::Plane_3 P_plane; +// typedef typename P_policy::RT P_rt; +// typedef typename P_policy::Point_3 P_point; +// typedef typename P_policy::Segment_3 P_segment; +// typedef typename P_policy::Line_3 P_line; +// typedef typename P_policy::Vector_3 P_vector; +// typedef typename P_policy::Plane_3 P_plane; -// Skin_surface_subdivision_policy_base_3(Skin_surface const& skin) +// Skin_surface_refinement_policy_base_3(Skin_surface const& skin) // : ss_3(skin) // {} @@ -52,7 +52,7 @@ CGAL_BEGIN_NAMESPACE // }; template -class Skin_surface_subdivision_policy_default_3 +class Skin_surface_refinement_policy_3 { public: typedef SkinSurface_3 Skin_surface; @@ -68,7 +68,7 @@ public: typedef typename P_traits::Vector_3 P_vector; typedef typename P_traits::Plane_3 P_plane; - Skin_surface_subdivision_policy_default_3(Skin_surface const& skin) + Skin_surface_refinement_policy_3(Skin_surface const& skin) : ss_3(skin) { @@ -105,23 +105,23 @@ protected: // // Partial specialisation for Skin_surface_polyhedral_items_3 // #include -// #include +// #include // CGAL_BEGIN_NAMESPACE -// template -// Skin_surface_subdivision_policy_base_3 >, SkinSurface_3> * -// get_subdivision_policy(Polyhedron_3 > &p, // const SkinSurface_3 &skinsurface) // { -// typedef Polyhedron_3 > Polyhedron; // typedef -// Skin_surface_subdivision_policy_with_face_info_3 +// Skin_surface_refinement_policy_with_face_info_3 // Policy; // return new Policy(skinsurface); @@ -130,4 +130,4 @@ protected: CGAL_END_NAMESPACE -#endif // CGAL_SKIN_SURFACE_SUBDIVISION_TRAITS_H +#endif // CGAL_SKIN_SURFACE_REFINEMENT_POLICY_3_H diff --git a/Skin_surface_3/include/CGAL/subdivide_skin_surface_mesh_3.h b/Skin_surface_3/include/CGAL/subdivide_skin_surface_mesh_3.h index 7b361d6e307..8651a2550fb 100644 --- a/Skin_surface_3/include/CGAL/subdivide_skin_surface_mesh_3.h +++ b/Skin_surface_3/include/CGAL/subdivide_skin_surface_mesh_3.h @@ -20,7 +20,7 @@ #ifndef CGAL_SUBDIVIDE_SKIN_SURFACE_MESH_3_H #define CGAL_SUBDIVIDE_SKIN_SURFACE_MESH_3_H -#include +#include #include CGAL_BEGIN_NAMESPACE @@ -57,14 +57,15 @@ class Skin_surface_sqrt3 typedef typename Kernel::FT FT; public: - Skin_surface_sqrt3(const SkinSurface_3 &skin, Polyhedron &P, + Skin_surface_sqrt3(const SkinSurface_3 &skin, + Polyhedron &P, const SubdivisionPolicy_3 &policy) : P(P), ss(skin), policy(policy) {} //********************************************* // Subdivision //********************************************* - int subdivide(int iter) + int subdivide(int iter=1) { // check for valid polygon mesh if(P.size_of_facets() == 0) @@ -74,7 +75,7 @@ public: P.normalize_border(); while (iter > 0) { - subdivide(); + do_subdivide(); iter--; } return true; @@ -85,7 +86,7 @@ private: //********************************************* // Subdivide //********************************************* - void subdivide() + void do_subdivide() { // We use that new vertices/halfedges/facets are appended at the end. @@ -141,20 +142,25 @@ private: const Subdivision_policy &policy; }; -template +template void subdivide_skin_surface_mesh_3( const SkinSurface_3 &skin, Polyhedron_3 &p, int nSubdiv = 1) { - typedef Skin_surface_subdivision_policy_default_3 Policy; - typedef Skin_surface_sqrt3 Subdivider; + while (nSubdiv > 0) { + skin.subdivide_skin_surface_mesh_3(p); + nSubdiv--; + } +// typedef Skin_surface_subdivision_policy_default_3 Policy; +// typedef Skin_surface_sqrt3 Subdivider; - Policy policy(skin); - Subdivider subdivider(skin, p, policy); - subdivider.subdivide(nSubdiv); +// Policy policy(skin); +// Subdivider subdivider(p, skin, policy); +// subdivider.subdivide(nSubdiv); } CGAL_END_NAMESPACE