From 5411669c8897e095b3c655f5af1e20b7d651ea01 Mon Sep 17 00:00:00 2001 From: iyaz Date: Thu, 20 Jun 2013 01:00:44 +0300 Subject: [PATCH 1/6] Integrate point inside query to Polyhedral_mesh_domain_3 --- .../include/CGAL/Polyhedral_mesh_domain_3.h | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h b/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h index be7d62af5e1..2c4fa34fdf7 100644 --- a/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h +++ b/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h @@ -27,6 +27,8 @@ #ifndef CGAL_POLYHEDRAL_MESH_DOMAIN_3_H #define CGAL_POLYHEDRAL_MESH_DOMAIN_3_H +#include + #include #include #include @@ -603,27 +605,12 @@ Polyhedral_mesh_domain_3:: Is_in_domain::operator()(const Point_3& p) const { if(r_domain_.bounding_tree_ == 0) return Subdomain(); - const Bounding_box bbox = r_domain_.bounding_tree_->bbox(); - if( p.x() < bbox.xmin() || p.x() > bbox.xmax() - || p.y() < bbox.ymin() || p.y() > bbox.ymax() - || p.z() < bbox.zmin() || p.z() > bbox.zmax() ) - { - return Subdomain(); - } - - // Shoot ray - typename IGT::Construct_ray_3 ray = IGT().construct_ray_3_object(); - typename IGT::Construct_vector_3 vector = IGT().construct_vector_3_object(); - - Random_points_on_sphere_3 random_point(1.); + internal::Point_inside_vertical_ray_cast inside_functor; + Bounded_side side = inside_functor(p, *(r_domain_.bounding_tree_)); - const Ray_3 ray_shot = ray(p, vector(CGAL::ORIGIN,*random_point)); - - if ( (r_domain_.bounding_tree_->number_of_intersected_primitives(ray_shot)&1) == 1 ) - return Subdomain(Subdomain_index(1)); - else - return Subdomain(); + if(side == CGAL::ON_UNBOUNDED_SIDE) { return Subdomain(); } + else { return Subdomain(Subdomain_index(1)); } // case ON_BOUNDARY && ON_BOUNDED_SIDE } From 2d160e77cabbbc42e80c5708a4085f874944c203 Mon Sep 17 00:00:00 2001 From: iyaz Date: Thu, 20 Jun 2013 00:50:03 +0300 Subject: [PATCH 2/6] internal class for point inside test, using existing AABB tree Conflicts: Operations_on_polyhedra/include/CGAL/Point_inside_polyhedron_3.h --- .../include/CGAL/Point_inside_polyhedron_3.h | 57 +------------ .../Point_inside_vertical_ray_cast.h | 80 +++++++++++++++++++ 2 files changed, 83 insertions(+), 54 deletions(-) create mode 100644 Point_inside_Polyhedron/include/CGAL/internal/Point_inside_Polyhedron/Point_inside_vertical_ray_cast.h diff --git a/Operations_on_polyhedra/include/CGAL/Point_inside_polyhedron_3.h b/Operations_on_polyhedra/include/CGAL/Point_inside_polyhedron_3.h index 5b9da2df4d8..a2b03e0b35a 100644 --- a/Operations_on_polyhedra/include/CGAL/Point_inside_polyhedron_3.h +++ b/Operations_on_polyhedra/include/CGAL/Point_inside_polyhedron_3.h @@ -22,16 +22,13 @@ #ifndef CGAL_POINT_INSIDE_POLYHEDRON_H #define CGAL_POINT_INSIDE_POLYHEDRON_H -#include +#include #include #include #include -#include #include -#include - namespace CGAL { /** @@ -57,17 +54,14 @@ class Point_inside_polyhedron_3{ // typedefs typedef CGAL::internal::AABB_triangle_accessor_3_primitive Primitive; typedef CGAL::AABB_traits Traits; - typedef typename Traits::Bounding_box Bounding_box; typedef CGAL::AABB_tree Tree; typedef typename Kernel::Point_3 Point; - typedef typename Kernel::Ray_3 Ray; + //members typename Kernel::Construct_ray_3 ray_functor; typename Kernel::Construct_vector_3 vector_functor; Tree tree; - const static unsigned int seed = 1340818006; - public: /** * Default constructor. The domain is considered to be empty. @@ -137,53 +131,8 @@ public: */ Bounded_side operator()(const Point& point) const { - const Bounding_box& bbox = tree.bbox(); - - if( point.x() < bbox.xmin() || point.x() > bbox.xmax() - || point.y() < bbox.ymin() || point.y() > bbox.ymax() - || point.z() < bbox.zmin() || point.z() > bbox.zmax() ) - { - return ON_UNBOUNDED_SIDE; - } - - //the direction of the vertical ray depends on the position of the point in the bbox - //in order to limit the expected number of nodes visited. - Ray query = ray_functor(point, vector_functor(0,0,(2*point.z() < tree.bbox().zmax()+tree.bbox().zmin()?-1:1))); - boost::optional res = is_inside_ray_tree_traversal(query); - - if(!res) { - CGAL::Random rg(seed); // seed some value for make it easy to debug - Random_points_on_sphere_3 random_point(1.,rg); - - do { //retry with a random ray - query = ray_functor(point, vector_functor(CGAL::ORIGIN,*random_point++)); - res = is_inside_ray_tree_traversal(query); - } while (!res); - } - return *res; + return internal::Point_inside_vertical_ray_cast()(point, tree, ray_functor, vector_functor); } - -private: - template - boost::optional - is_inside_ray_tree_traversal(const Query& query) const - { - std::pair status( boost::logic::tribool(boost::logic::indeterminate), 0); - - internal::Ray_3_Triangle_3_traversal_traits > traversal_traits(status); - tree.traversal(query, traversal_traits); - - if ( !boost::logic::indeterminate(status.first) ) - { - if (status.first) { - return (status.second&1) == 1 ? ON_BOUNDED_SIDE : ON_UNBOUNDED_SIDE; - } - //otherwise the point is on the facet - return ON_BOUNDARY; - } - return boost::optional(); // indeterminate - } - }; } // namespace CGAL diff --git a/Point_inside_Polyhedron/include/CGAL/internal/Point_inside_Polyhedron/Point_inside_vertical_ray_cast.h b/Point_inside_Polyhedron/include/CGAL/internal/Point_inside_Polyhedron/Point_inside_vertical_ray_cast.h new file mode 100644 index 00000000000..5f34cbb79fc --- /dev/null +++ b/Point_inside_Polyhedron/include/CGAL/internal/Point_inside_Polyhedron/Point_inside_vertical_ray_cast.h @@ -0,0 +1,80 @@ +#ifndef CGAL_POINT_INSIDE_POLYHEDRON_POINT_INSIDE_VERTICAL_RAY_CAST_H +#define CGAL_POINT_INSIDE_POLYHEDRON_POINT_INSIDE_VERTICAL_RAY_CAST_H + +#include +#include + +#include + +namespace CGAL { +namespace internal { + +// internal class for point inside test, using existing AABB tree +template +class Point_inside_vertical_ray_cast +{ + typedef typename Kernel::Point_3 Point; + typedef typename Kernel::Ray_3 Ray; + typedef typename AABBTree::AABB_traits Traits; + + const static unsigned int seed = 1340818006; + +public: + Bounded_side operator()( + const Point& point, + const AABBTree& tree, + typename Kernel::Construct_ray_3 ray_functor = Kernel().construct_ray_3_object(), + typename Kernel::Construct_vector_3 vector_functor = Kernel().construct_vector_3_object() ) const + { + const Traits::Bounding_box& bbox = tree.bbox(); + + if( point.x() < bbox.xmin() || point.x() > bbox.xmax() + || point.y() < bbox.ymin() || point.y() > bbox.ymax() + || point.z() < bbox.zmin() || point.z() > bbox.zmax() ) + { + return ON_UNBOUNDED_SIDE; + } + + //the direction of the vertical ray depends on the position of the point in the bbox + //in order to limit the expected number of nodes visited. + Ray query = ray_functor(point, vector_functor(0,0,(2*point.z() < tree.bbox().zmax()+tree.bbox().zmin()?-1:1))); + boost::optional res = is_inside_ray_tree_traversal(query, tree); + + if(!res) { + CGAL::Random rg(seed); // seed some value for make it easy to debug + Random_points_on_sphere_3 random_point(1.,rg); + + do { //retry with a random ray + query = ray_functor(point, vector_functor(CGAL::ORIGIN,*random_point++)); + res = is_inside_ray_tree_traversal(query, tree); + } while (!res); + } + return *res; + } + +private: + template + boost::optional + is_inside_ray_tree_traversal(const Ray& ray, const AABBTree& tree) const + { + std::pair status( boost::logic::tribool(boost::logic::indeterminate), 0); + + Ray_3_Triangle_3_traversal_traits > traversal_traits(status); + tree.traversal(ray, traversal_traits); + + if ( !boost::logic::indeterminate(status.first) ) + { + if (status.first) { + return (status.second&1) == 1 ? ON_BOUNDED_SIDE : ON_UNBOUNDED_SIDE; + } + //otherwise the point is on the facet + return ON_BOUNDARY; + } + return boost::optional(); // indeterminate + } +}; + +}// namespace internal +}// namespace CGAL + +#endif \ No newline at end of file From 4f70640db862985e4b478c23769c80d0ada10228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 24 Jun 2013 14:46:22 +0200 Subject: [PATCH 3/6] move file --- .../Operations_on_polyhedra}/Point_inside_vertical_ray_cast.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Point_inside_Polyhedron/include/CGAL/internal/Point_inside_Polyhedron => Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra}/Point_inside_vertical_ray_cast.h (100%) diff --git a/Point_inside_Polyhedron/include/CGAL/internal/Point_inside_Polyhedron/Point_inside_vertical_ray_cast.h b/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h similarity index 100% rename from Point_inside_Polyhedron/include/CGAL/internal/Point_inside_Polyhedron/Point_inside_vertical_ray_cast.h rename to Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h From 4620b38ffd3429a1d0536694d48b89f39ce52ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 24 Jun 2013 17:27:41 +0200 Subject: [PATCH 4/6] update include path --- Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h | 2 +- .../Operations_on_polyhedra/Point_inside_vertical_ray_cast.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h b/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h index 2c4fa34fdf7..ea58e8f84dd 100644 --- a/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h +++ b/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h @@ -27,7 +27,7 @@ #ifndef CGAL_POLYHEDRAL_MESH_DOMAIN_3_H #define CGAL_POLYHEDRAL_MESH_DOMAIN_3_H -#include +#include #include #include diff --git a/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h b/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h index 5f34cbb79fc..fa5020d0c8d 100644 --- a/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h +++ b/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h @@ -1,7 +1,7 @@ #ifndef CGAL_POINT_INSIDE_POLYHEDRON_POINT_INSIDE_VERTICAL_RAY_CAST_H #define CGAL_POINT_INSIDE_POLYHEDRON_POINT_INSIDE_VERTICAL_RAY_CAST_H -#include +#include #include #include From 98d212b2c07ad1a060dff340390fb4413866692b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 24 Jun 2013 17:46:48 +0200 Subject: [PATCH 5/6] add missing typename --- .../Operations_on_polyhedra/Point_inside_vertical_ray_cast.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h b/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h index fa5020d0c8d..5050e6dfe1a 100644 --- a/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h +++ b/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h @@ -26,7 +26,7 @@ public: typename Kernel::Construct_ray_3 ray_functor = Kernel().construct_ray_3_object(), typename Kernel::Construct_vector_3 vector_functor = Kernel().construct_vector_3_object() ) const { - const Traits::Bounding_box& bbox = tree.bbox(); + const typename Traits::Bounding_box& bbox = tree.bbox(); if( point.x() < bbox.xmin() || point.x() > bbox.xmax() || point.y() < bbox.ymin() || point.y() > bbox.ymax() From 755b41e67b29ea1066b6146f2e50ad3b9f4075a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 3 Jul 2013 10:45:31 +0200 Subject: [PATCH 6/6] add a new line at the end of file to please msvc --- .../Operations_on_polyhedra/Point_inside_vertical_ray_cast.h | 2 +- .../Operations_on_polyhedra/Ray_3_Triangle_3_traversal_traits.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h b/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h index 5050e6dfe1a..12803897282 100644 --- a/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h +++ b/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Point_inside_vertical_ray_cast.h @@ -77,4 +77,4 @@ private: }// namespace internal }// namespace CGAL -#endif \ No newline at end of file +#endif diff --git a/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Ray_3_Triangle_3_traversal_traits.h b/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Ray_3_Triangle_3_traversal_traits.h index cc305011f61..344899e44a3 100644 --- a/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Ray_3_Triangle_3_traversal_traits.h +++ b/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/Ray_3_Triangle_3_traversal_traits.h @@ -214,4 +214,4 @@ public: }// namespace internal }// namespace CGAL -#endif \ No newline at end of file +#endif