28 #ifndef CGAL_MESH_3_SIGNED_MESH_DOMAIN_3_H
29 #define CGAL_MESH_3_SIGNED_MESH_DOMAIN_3_H
31 #if defined(BOOST_MSVC)
32 # pragma warning(push)
33 # pragma warning(disable:4180) // qualifier applied to function type has no meaning; ignored
36 #include <CGAL/Mesh_3/Labeled_mesh_domain_3.h>
53 template<
class Function,
class BGT>
55 :
public Mesh_3::Labeled_mesh_domain_3<Function, BGT >
59 typedef Mesh_3::Labeled_mesh_domain_3<Function, BGT>
Base;
62 typedef typename Mesh_3::Labeled_mesh_domain_3<Function, BGT>::Subdomain
Subdomain;
63 typedef typename Mesh_3::Labeled_mesh_domain_3<Function, BGT>::Subdomain_index Subdomain_index;
64 typedef typename Mesh_3::Labeled_mesh_domain_3<Function, BGT>::Surface_patch Surface_patch;
65 typedef typename Mesh_3::Labeled_mesh_domain_3<Function, BGT>::Segment_3 Segment_3;
66 typedef typename Mesh_3::Labeled_mesh_domain_3<Function, BGT>::Ray_3 Ray_3;
67 typedef typename Mesh_3::Labeled_mesh_domain_3<Function, BGT>::Line_3 Line_3;
68 typedef typename Mesh_3::Labeled_mesh_domain_3<Function, BGT>::Vector_3 Vector_3;
69 typedef typename Mesh_3::Labeled_mesh_domain_3<Function, BGT>::Surface_patch_index Surface_patch_index;
70 typedef typename Mesh_3::Labeled_mesh_domain_3<Function, BGT>::Index Index;
71 typedef typename Mesh_3::Labeled_mesh_domain_3<Function, BGT>::Intersection Intersection;
72 typedef typename BGT::Iso_cuboid_3 Iso_cuboid_3;
73 typedef typename Base::Sphere_3 Sphere_3;
74 typedef typename Base::Point_3 Point_3;
75 typedef typename Base::FT FT;
82 const FT& error_bound = FT(1e-3),
83 CGAL::Random* p_rng = NULL);
87 const FT& error_bound = FT(1e-3),
88 CGAL::Random* p_rng = NULL);
91 const Iso_cuboid_3& bbox,
92 const FT& error_bound = FT(1e-3),
93 CGAL::Random* p_rng = NULL);
110 : r_domain_(domain) {}
112 template<
class OutputIterator>
113 OutputIterator operator()(OutputIterator pts,
const int n = 12)
const;
129 Subdomain operator()(
const Point_3& p)
const
133 if ( Subdomain_index() >= index )
156 : r_domain_(domain) {}
158 Surface_patch operator()(
const Segment_3& s)
const
160 return this->operator()(s.source(), s.target());
163 Surface_patch operator()(
const Ray_3& r)
const
165 return clip_to_segment(r);
168 Surface_patch operator()(
const Line_3& l)
const
170 return clip_to_segment(l);
176 Surface_patch operator()(
const Point_3& a,
const Point_3& b)
const
184 if ( (value_a > 0 || value_b > 0) && value_a != value_b )
185 return Surface_patch(r_domain_.make_surface_index(value_a, value_b));
187 return Surface_patch();
193 template<
typename Query>
194 Surface_patch clip_to_segment(
const Query& query)
const
196 typename cpp11::result_of<typename BGT::Intersect_3(Query, Iso_cuboid_3)>::type
197 clipped = CGAL::intersection(query, r_domain_.bounding_box());
200 #if CGAL_INTERSECTION_VERSION > 1
201 if(
const Segment_3* s = boost::get<Segment_3>(&*clipped))
202 return this->
operator()(*s);
204 if(
const Segment_3* s = object_cast<Segment_3>(&clipped))
205 return this->
operator()(*s);
208 return Surface_patch();
233 : r_domain_(domain) {}
235 Intersection operator()(
const Segment_3& s)
const
237 #ifndef CGAL_MESH_3_NO_LONGER_CALLS_DO_INTERSECT_3
239 #endif // NOT CGAL_MESH_3_NO_LONGER_CALLS_DO_INTERSECT_3
240 return this->operator()(s.source(),s.target());
243 Intersection operator()(
const Ray_3& r)
const
245 return clip_to_segment(r);
248 Intersection operator()(
const Line_3& l)
const
250 return clip_to_segment(l);
261 Intersection operator()(
const Point_3& a,
const Point_3& b)
const
264 typename BGT::Compute_squared_distance_3 squared_distance =
265 BGT().compute_squared_distance_3_object();
266 typename BGT::Construct_midpoint_3 midpoint =
267 BGT().construct_midpoint_3_object();
272 Point_3 mid = midpoint(p1, p2);
282 if( value_at_p1 == value_at_p2 || (value_at_p1 <= 0 && value_at_p2 <= 0) )
284 return Intersection();
291 const Surface_patch_index sp_index =
292 r_domain_.make_surface_index(value_at_p1, value_at_p2);
293 const Index index = r_domain_.index_from_surface_patch_index(sp_index);
300 if ( squared_distance(p1, p2) < r_domain_.squared_error_bound_ )
302 CGAL_assertion(value_at_p1 != value_at_p2 && (value_at_p1 > 0 || value_at_p2 > 0));
303 return Intersection(mid, index, 2);
311 if ( value_at_p1 != value_at_mid && (value_at_p1 > 0 || value_at_mid > 0) )
314 value_at_p2 = value_at_mid;
319 value_at_p1 = value_at_mid;
322 mid = midpoint(p1, p2);
328 template<
typename Query>
329 Intersection clip_to_segment(
const Query& query)
const
331 typename cpp11::result_of<typename BGT::Intersect_3(Query, Iso_cuboid_3)>::type
332 clipped = CGAL::intersection(query, r_domain_.bounding_box());
335 #if CGAL_INTERSECTION_VERSION > 1
336 if(
const Segment_3* s = boost::get<Segment_3>(&*clipped))
337 return this->
operator()(*s);
339 if(
const Segment_3* s = object_cast<Segment_3>(&clipped))
340 return this->
operator()(*s);
343 return Intersection();
359 typename BGT::Construct_sphere_3 sphere = BGT().construct_sphere_3_object();
360 return sphere((bbox.min)(), (bbox.max)());
366 FT squared_error_bound_;
369 CGAL::Random* p_rng_;
376 Self& operator=(
const Self& src);
380 Surface_patch_index make_surface_index(
const Subdomain_index i,
381 const Subdomain_index j)
const
383 if ( i < j )
return Surface_patch_index(i,j);
384 else return Surface_patch_index(j,i);
388 FT squared_error_bound(
const Sphere_3& sphere,
const FT& error)
const
390 typename BGT::Compute_squared_radius_3 squared_radius =
391 BGT().compute_squared_radius_3_object();
392 return squared_radius(sphere)*error*error;
401 template<
class F,
class BGT>
404 const Sphere_3& bounding_sphere,
405 const FT& error_bound,
407 :
CGAL::Mesh_3::Labeled_mesh_domain_3<F, BGT>(f, bounding_sphere, error_bound)
408 , signed_function_(f)
409 , squared_error_bound_(squared_error_bound(bounding_sphere,error_bound))
416 p_rng_ =
new CGAL::Random(0);
421 template<
class F,
class BGT>
425 const FT& error_bound,
427 :
CGAL::Mesh_3::Labeled_mesh_domain_3<F, BGT>(f, bbox, error_bound)
428 , signed_function_(f)
429 , squared_error_bound_(squared_error_bound(
CGAL::Mesh_3::Labeled_mesh_domain_3<F, BGT>::bounding_box(),error_bound))
436 p_rng_ =
new CGAL::Random(0);
441 template<
class F,
class BGT>
444 const Iso_cuboid_3& bbox,
445 const FT& error_bound,
447 :
CGAL::Mesh_3::Labeled_mesh_domain_3<F, BGT>(f, bbox, error_bound, p_rng)
448 , signed_function_(f)
449 , squared_error_bound_(squared_error_bound(
CGAL::Mesh_3::Labeled_mesh_domain_3<F, BGT>::bounding_box(),error_bound))
456 p_rng_ =
new CGAL::Random(0);
461 template<
class F,
class BGT>
462 template<
class OutputIterator>
464 Signed_mesh_domain_3<F,BGT>::Construct_initial_points::operator()(
466 const int nb_points)
const
469 typedef Random_points_on_sphere_3<Point_3> Random_points_on_sphere_3;
470 typedef Random_points_in_sphere_3<Point_3> Random_points_in_sphere_3;
473 const FT squared_radius = BGT().compute_squared_radius_3_object()(
476 const double radius = std::sqrt(CGAL::to_double(squared_radius));
478 CGAL::Random& rng = *(r_domain_.p_rng_);
479 Random_points_on_sphere_3 random_point_on_sphere(radius, rng);
480 Random_points_in_sphere_3 random_point_in_sphere(radius, rng);
483 typename BGT::Construct_segment_3 segment_3 =
484 BGT().construct_segment_3_object();
485 typename BGT::Construct_vector_3 vector_3 =
486 BGT().construct_vector_3_object();
487 typename BGT::Construct_translated_point_3 translate =
488 BGT().construct_translated_point_3_object();
489 typename BGT::Construct_center_3 center = BGT().construct_center_3_object();
492 Point_3 center_pt = center(r_domain_.
bounding_sphere(r_domain_.bounding_box()));
493 const Vector_3 sphere_translation = vector_3(CGAL::ORIGIN, center_pt);
497 #ifdef CGAL_MESH_3_VERBOSE
498 std::cerr <<
"construct initial points:\n";
503 const Point_3 random_point = translate(*random_point_on_sphere,
505 const Segment_3 random_seg = segment_3(center_pt, random_point);
511 const Point_3 intersect_pt = CGAL::cpp11::get<0>(
513 *pts++ = std::make_pair(intersect_pt,
514 r_domain_.index_from_surface_patch_index(*surface));
517 #ifdef CGAL_MESH_3_VERBOSE
518 std::cerr << boost::format(
"\r \r"
519 "%1%/%2% initial point(s) found...")
529 ++random_point_in_sphere;
530 center_pt = translate(*random_point_in_sphere, sphere_translation);
532 ++random_point_on_sphere;
535 #ifdef CGAL_MESH_3_VERBOSE
544 #if defined(BOOST_MSVC)
545 # pragma warning(pop)
548 #endif // CGAL_SIGNED_MESH_DOMAIN_3_H
Definition: Signed_mesh_domain_3.h:230
virtual ~Signed_mesh_domain_3()
Destructor.
Definition: Signed_mesh_domain_3.h:96
Construct_initial_points construct_initial_points_object() const
Returns Construct_initial_points object.
Definition: Signed_mesh_domain_3.h:120
Definition: Signed_mesh_domain_3.h:107
Do_intersect_surface do_intersect_surface_object() const
Returns Do_intersect_surface object.
Definition: Signed_mesh_domain_3.h:216
Definition: Signed_mesh_domain_3.h:153
Definition: write_c3t3_to_gmsh_file.h:50
const Function signed_function_
The function which answers subdomain queries (this would not be required if Lmd3._function were prote...
Definition: Signed_mesh_domain_3.h:365
Definition: Signed_mesh_domain_3.h:54
Sphere_3 bounding_sphere(const Iso_cuboid_3 &bbox) const
Returns the bounding sphere of an Iso_cuboid_3.
Definition: Signed_mesh_domain_3.h:357
Mesh_3::Labeled_mesh_domain_3< Function, BGT >::Subdomain Subdomain
Public types.
Definition: Signed_mesh_domain_3.h:62
Construct_intersection construct_intersection_object() const
Returns Construct_intersection object.
Definition: Signed_mesh_domain_3.h:351
Definition: Signed_mesh_domain_3.h:125
Signed_mesh_domain_3(const Function &f, const Sphere_3 &bounding_sphere, const FT &error_bound=FT(1e-3), CGAL::Random *p_rng=NULL)
Constructor.
Mesh_3::Labeled_mesh_domain_3< Function, BGT > Base
Base type.
Definition: Signed_mesh_domain_3.h:59