mirror of https://github.com/CGAL/cgal
use CGAL::Random* as member variable
it avoids using temporary CGAL::Random(0) that would be deleted as soon as we get out of the constructor + make examples deterministic and tests not (all but test_meshing_determinism)
This commit is contained in:
parent
98e8e85364
commit
215b463812
|
|
@ -29,7 +29,7 @@ int main()
|
|||
image.read("data/liver.inr.gz");
|
||||
|
||||
// Domain
|
||||
Mesh_domain domain(image, CGAL::default_random);
|
||||
Mesh_domain domain(image);
|
||||
|
||||
// Mesh criteria
|
||||
Mesh_criteria criteria(facet_angle=30, facet_size=6, facet_distance=4,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
#define CGAL_MESH_3_VERBOSE
|
||||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
#include <CGAL/Mesh_triangulation_3.h>
|
||||
|
|
@ -32,7 +34,7 @@ int main()
|
|||
image.read("data/liver.inr.gz");
|
||||
|
||||
// Domain
|
||||
Mesh_domain domain(image, CGAL::default_random);
|
||||
Mesh_domain domain(image);
|
||||
|
||||
// Sizing field: set global size to 8 and kidney size (label 127) to 3
|
||||
double kidney_size = 3.;
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ int main()
|
|||
{
|
||||
// Domain (Warning: Sphere_3 constructor uses squared radius !)
|
||||
Mesh_domain domain(sphere_function,
|
||||
K::Sphere_3(CGAL::ORIGIN, 2.),
|
||||
CGAL::default_random);
|
||||
K::Sphere_3(CGAL::ORIGIN, 2.));
|
||||
|
||||
// Mesh criteria
|
||||
Mesh_criteria criteria(facet_angle=30, facet_size=0.1, facet_distance=0.025,
|
||||
|
|
|
|||
|
|
@ -46,8 +46,7 @@ int main()
|
|||
{
|
||||
// Domain (Warning: Sphere_3 constructor uses squared radius !)
|
||||
Mesh_domain domain(sphere_function,
|
||||
K::Sphere_3(CGAL::ORIGIN, 2.),
|
||||
CGAL::default_random);
|
||||
K::Sphere_3(CGAL::ORIGIN, 2.));
|
||||
|
||||
// Mesh criteria
|
||||
Spherical_sizing_field size;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ int main()
|
|||
// Domain
|
||||
CGAL::Image_3 image;
|
||||
image.read("data/liver.inr.gz");
|
||||
Mesh_domain domain(image, CGAL::default_random);
|
||||
Mesh_domain domain(image);
|
||||
|
||||
// Mesh criteria
|
||||
Mesh_criteria criteria(facet_angle=30, facet_size=5, facet_distance=1.5,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ int main()
|
|||
// Domain
|
||||
CGAL::Image_3 image;
|
||||
image.read("data/liver.inr.gz");
|
||||
Mesh_domain domain(image, CGAL::default_random);
|
||||
Mesh_domain domain(image);
|
||||
|
||||
// Mesh criteria
|
||||
Mesh_criteria criteria(facet_angle=30, facet_distance=1.2,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ int main()
|
|||
input >> polyhedron;
|
||||
|
||||
// Create domain
|
||||
Mesh_domain domain(polyhedron, CGAL::default_random);
|
||||
Mesh_domain domain(polyhedron);
|
||||
|
||||
// Mesh criteria (no cell_size set)
|
||||
Mesh_criteria criteria(facet_angle=25, facet_size=0.15, facet_distance=0.008,
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ using namespace CGAL::parameters;
|
|||
int main()
|
||||
{
|
||||
// Create domain
|
||||
Mesh_domain domain("data/fandisk.off", CGAL::default_random);
|
||||
Mesh_domain domain("data/fandisk.off");
|
||||
|
||||
// Get sharp features
|
||||
domain.detect_features();
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ FT sphere_function (const Point& p)
|
|||
int main()
|
||||
{
|
||||
// Domain (Warning: Sphere_3 constructor uses squared radius !)
|
||||
Mesh_domain domain(sphere_function, K::Sphere_3(Point(1, 0, 0), 6.));
|
||||
Mesh_domain domain(sphere_function,
|
||||
K::Sphere_3(Point(1, 0, 0), 6.));
|
||||
|
||||
// Mesh criteria
|
||||
Mesh_criteria criteria(edge_size = 0.15,
|
||||
|
|
|
|||
|
|
@ -67,9 +67,9 @@ public:
|
|||
*/
|
||||
Implicit_mesh_domain_3(const Function& f,
|
||||
const Sphere_3& bounding_sphere,
|
||||
CGAL::Random& rng = CGAL::Random(0),
|
||||
CGAL::Random* p_rng = NULL,
|
||||
const FT& error_bound = FT(1e-3))
|
||||
: Base(Wrapper(f), bounding_sphere, rng, error_bound) {}
|
||||
: Base(Wrapper(f), bounding_sphere, p_rng, error_bound) {}
|
||||
|
||||
/// Destructor
|
||||
virtual ~Implicit_mesh_domain_3() {}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,11 @@ public:
|
|||
|
||||
/// Constructor
|
||||
Labeled_image_mesh_domain_3(const Image& image,
|
||||
CGAL::Random& rng = CGAL::Random(0),
|
||||
CGAL::Random* p_rng = NULL,
|
||||
const FT& error_bound = FT(1e-3))
|
||||
: Base(Wrapper(image),
|
||||
compute_bounding_box(image),
|
||||
rng,
|
||||
p_rng,
|
||||
error_bound)
|
||||
{}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,16 +96,20 @@ public:
|
|||
*/
|
||||
Labeled_mesh_domain_3(const Function& f,
|
||||
const Sphere_3& bounding_sphere,
|
||||
CGAL::Random& rng = CGAL::Random(0),
|
||||
CGAL::Random* p_rng = NULL,
|
||||
const FT& error_bound = FT(1e-3));
|
||||
|
||||
Labeled_mesh_domain_3(const Function& f,
|
||||
const Bbox_3& bbox,
|
||||
CGAL::Random& rng = CGAL::Random(0),
|
||||
CGAL::Random* p_rng = NULL,
|
||||
const FT& error_bound = FT(1e-3));
|
||||
|
||||
/// Destructor
|
||||
virtual ~Labeled_mesh_domain_3() {}
|
||||
virtual ~Labeled_mesh_domain_3()
|
||||
{
|
||||
if(delete_rng_)
|
||||
delete p_rng_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a set of \ccc{n} points on the surface, and output them to
|
||||
|
|
@ -466,7 +470,8 @@ private:
|
|||
/// The bounding box
|
||||
const Iso_cuboid_3 bbox_;
|
||||
/// The random number generator used by Construct_initial_points
|
||||
CGAL::Random& rng_;
|
||||
CGAL::Random* p_rng_;
|
||||
bool delete_rng_;
|
||||
/// Error bound relative to sphere radius
|
||||
FT squared_error_bound_;
|
||||
|
||||
|
|
@ -489,30 +494,40 @@ template<class F, class BGT>
|
|||
Labeled_mesh_domain_3<F,BGT>::Labeled_mesh_domain_3(
|
||||
const F& f,
|
||||
const Sphere_3& bounding_sphere,
|
||||
CGAL::Random& rng,
|
||||
CGAL::Random* p_rng,
|
||||
const FT& error_bound )
|
||||
: function_(f)
|
||||
, bbox_(iso_cuboid(bounding_sphere.bbox()))
|
||||
, rng_(rng)
|
||||
, p_rng_(p_rng)
|
||||
, delete_rng_(false)
|
||||
, squared_error_bound_(squared_error_bound(bounding_sphere,error_bound))
|
||||
{
|
||||
std::cout << "seed : " << rng_.get_seed() << std::endl;
|
||||
// TODO : CGAL_ASSERT(0 < f(bounding_sphere.get_center()) ) ?
|
||||
if(!p_rng_)
|
||||
{
|
||||
p_rng_ = new CGAL::Random(0);
|
||||
delete_rng_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
template<class F, class BGT>
|
||||
Labeled_mesh_domain_3<F,BGT>::Labeled_mesh_domain_3(
|
||||
const F& f,
|
||||
const Bbox_3& bbox,
|
||||
CGAL::Random& rng,
|
||||
CGAL::Random* p_rng,
|
||||
const FT& error_bound )
|
||||
: function_(f)
|
||||
, bbox_(iso_cuboid(bbox))
|
||||
, rng_(rng)
|
||||
, p_rng_(p_rng)
|
||||
, delete_rng_(false)
|
||||
, squared_error_bound_(squared_error_bound(bbox_,error_bound))
|
||||
{
|
||||
std::cout << "seed : " << rng_.get_seed() << std::endl;
|
||||
// TODO : CGAL_ASSERT(0 < f(bounding_sphere.get_center()) ) ?
|
||||
if(!p_rng_)
|
||||
{
|
||||
p_rng_ = new CGAL::Random(0);
|
||||
delete_rng_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -534,8 +549,9 @@ Labeled_mesh_domain_3<F,BGT>::Construct_initial_points::operator()(
|
|||
|
||||
const double radius = std::sqrt(CGAL::to_double(squared_radius));
|
||||
|
||||
Random_points_on_sphere_3 random_point_on_sphere(radius, r_domain_.rng_);
|
||||
Random_points_in_sphere_3 random_point_in_sphere(radius, r_domain_.rng_);
|
||||
CGAL::Random& rng = *(r_domain_.p_rng_);
|
||||
Random_points_on_sphere_3 random_point_on_sphere(radius, rng);
|
||||
Random_points_in_sphere_3 random_point_in_sphere(radius, rng);
|
||||
|
||||
// Get some functors
|
||||
typename BGT::Construct_segment_3 segment_3 =
|
||||
|
|
@ -571,7 +587,6 @@ Labeled_mesh_domain_3<F,BGT>::Construct_initial_points::operator()(
|
|||
*pts++ = std::make_pair(intersect_pt,
|
||||
r_domain_.index_from_surface_patch_index(*surface));
|
||||
--n;
|
||||
std::cout << "ipoint : " << intersect_pt << std::endl;
|
||||
|
||||
#ifdef CGAL_MESH_3_VERBOSE
|
||||
std::cerr << boost::format("\r \r"
|
||||
|
|
|
|||
|
|
@ -205,9 +205,10 @@ public:
|
|||
: tree_()
|
||||
, bounding_tree_(&tree_)
|
||||
, has_cache(false)
|
||||
, rng_(CGAL::default_random)
|
||||
, p_rng_(NULL)
|
||||
, delete_rng_(true)
|
||||
{
|
||||
rng_ = CGAL::Random(0);
|
||||
p_rng_ = new CGAL::Random(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -215,33 +216,45 @@ public:
|
|||
* @param polyhedron the polyhedron describing the polyhedral surface
|
||||
*/
|
||||
Polyhedral_mesh_domain_3(const Polyhedron& p,
|
||||
CGAL::Random& rng = CGAL::Random(0))
|
||||
CGAL::Random* p_rng = NULL)
|
||||
: tree_(TriangleAccessor().triangles_begin(p),
|
||||
TriangleAccessor().triangles_end(p)),
|
||||
bounding_tree_(&tree_) // the bounding tree is tree_
|
||||
, has_cache(false)
|
||||
, rng_(rng)
|
||||
, p_rng_(p_rng)
|
||||
, delete_rng_(false)
|
||||
{
|
||||
if(!p.is_pure_triangle()) {
|
||||
std::cerr << "Your input polyhedron must be triangulated!\n";
|
||||
CGAL_error_msg("Your input polyhedron must be triangulated!");
|
||||
}
|
||||
if(!p_rng_)
|
||||
{
|
||||
p_rng_ = new CGAL::Random(0);
|
||||
delete_rng_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
Polyhedral_mesh_domain_3(const Polyhedron& p,
|
||||
const Polyhedron& bounding_polyhedron,
|
||||
CGAL::Random& rng = CGAL::Random(0))
|
||||
CGAL::Random* p_rng = NULL)
|
||||
: tree_(TriangleAccessor().triangles_begin(p),
|
||||
TriangleAccessor().triangles_end(p))
|
||||
, bounding_tree_(new AABB_tree_(TriangleAccessor().triangles_begin(bounding_polyhedron),
|
||||
TriangleAccessor().triangles_end(bounding_polyhedron)))
|
||||
, has_cache(false)
|
||||
, rng_(rng)
|
||||
, p_rng_(p_rng)
|
||||
, delete_rng_(false)
|
||||
{
|
||||
tree_.insert(TriangleAccessor().triangles_begin(bounding_polyhedron),
|
||||
TriangleAccessor().triangles_end(bounding_polyhedron));
|
||||
tree_.build();
|
||||
bounding_tree_->build();
|
||||
if(!p_rng_)
|
||||
{
|
||||
p_rng_ = new CGAL::Random(0);
|
||||
delete_rng_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -259,9 +272,10 @@ public:
|
|||
Polyhedral_mesh_domain_3(InputPolyhedraPtrIterator begin,
|
||||
InputPolyhedraPtrIterator end,
|
||||
const Polyhedron& bounding_polyhedron,
|
||||
CGAL::Random& rng = CGAL::Random(0))
|
||||
CGAL::Random* p_rng = NULL)
|
||||
: has_cache(false)
|
||||
, rng_(rng)
|
||||
, p_rng_(p_rng)
|
||||
, delete_rng_(false)
|
||||
{
|
||||
if(begin != end) {
|
||||
for(; begin != end; ++begin) {
|
||||
|
|
@ -281,6 +295,11 @@ public:
|
|||
TriangleAccessor().triangles_end(bounding_polyhedron));
|
||||
bounding_tree_ = &tree_;
|
||||
}
|
||||
if(!p_rng_)
|
||||
{
|
||||
p_rng_ = new CGAL::Random(0);
|
||||
delete_rng_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -296,9 +315,10 @@ public:
|
|||
template <typename InputPolyhedraPtrIterator>
|
||||
Polyhedral_mesh_domain_3(InputPolyhedraPtrIterator begin,
|
||||
InputPolyhedraPtrIterator end,
|
||||
CGAL::Random& rng = CGAL::Random(0))
|
||||
CGAL::Random* p_rng = NULL)
|
||||
: has_cache(false)
|
||||
, rng_(rng)
|
||||
, p_rng_(p_rng)
|
||||
, delete_rng_(false)
|
||||
{
|
||||
if(begin != end) {
|
||||
for(; begin != end; ++begin) {
|
||||
|
|
@ -308,6 +328,11 @@ public:
|
|||
tree_.build();
|
||||
}
|
||||
bounding_tree_ = 0;
|
||||
if(!p_rng_)
|
||||
{
|
||||
p_rng_ = new CGAL::Random(0);
|
||||
delete_rng_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Destructor
|
||||
|
|
@ -315,6 +340,8 @@ public:
|
|||
if(bounding_tree_ != 0 && bounding_tree_ != &tree_) {
|
||||
delete bounding_tree_;
|
||||
}
|
||||
if(delete_rng_)
|
||||
delete p_rng_;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -609,7 +636,8 @@ private:
|
|||
mutable AABB_primitive_id cached_primitive_id;
|
||||
|
||||
//random number generator for Construct_initial_points
|
||||
mutable CGAL::Random rng_;
|
||||
CGAL::Random* p_rng_;
|
||||
bool delete_rng_;
|
||||
|
||||
public:
|
||||
|
||||
|
|
@ -627,9 +655,15 @@ public:
|
|||
return has_cache && (cached_query == Cached_query(q));
|
||||
}
|
||||
|
||||
void set_random_generator(CGAL::Random& rng)
|
||||
void set_random_generator(CGAL::Random* p_rng)
|
||||
{
|
||||
rng_ = rng;
|
||||
if(!p_rng_)
|
||||
{
|
||||
p_rng_ = new CGAL::Random(0);
|
||||
delete_rng_ = true;
|
||||
}
|
||||
else
|
||||
p_rng_ = p_rng;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -660,7 +694,8 @@ Construct_initial_points::operator()(OutputIterator pts,
|
|||
FT( (bbox.ymin() + bbox.ymax()) / 2),
|
||||
FT( (bbox.zmin() + bbox.zmax()) / 2) );
|
||||
|
||||
Random_points_on_sphere_3<Point_3> random_point(1., r_domain_.rng_);
|
||||
CGAL::Random& rng = *(r_domain_.p_rng_);
|
||||
Random_points_on_sphere_3<Point_3> random_point(1., rng);
|
||||
|
||||
int i = n;
|
||||
#ifdef CGAL_MESH_3_VERBOSE
|
||||
|
|
|
|||
|
|
@ -95,9 +95,9 @@ public:
|
|||
|
||||
/// Constructors
|
||||
Polyhedral_mesh_domain_with_features_3(const Polyhedron& p,
|
||||
CGAL::Random& rng = CGAL::Random(0));
|
||||
CGAL::Random* p_rng = NULL);
|
||||
Polyhedral_mesh_domain_with_features_3(const std::string& filename,
|
||||
CGAL::Random& rng = CGAL::Random(0));
|
||||
CGAL::Random* p_rng = NULL);
|
||||
|
||||
template <typename T1, typename T2, typename T3>
|
||||
Polyhedral_mesh_domain_with_features_3(const T1& a, const T2& b, const T3& c)
|
||||
|
|
@ -128,19 +128,19 @@ template < typename GT_, typename P_, typename TA_,
|
|||
typename Tag_, typename E_tag_>
|
||||
Polyhedral_mesh_domain_with_features_3<GT_,P_,TA_,Tag_,E_tag_>::
|
||||
Polyhedral_mesh_domain_with_features_3(const Polyhedron& p,
|
||||
CGAL::Random& rng)
|
||||
CGAL::Random* p_rng)
|
||||
: Base()
|
||||
, polyhedron_(p)
|
||||
{
|
||||
this->add_primitives(polyhedron_);
|
||||
this->set_random_generator(rng);
|
||||
this->set_random_generator(p_rng);
|
||||
}
|
||||
|
||||
template < typename GT_, typename P_, typename TA_,
|
||||
typename Tag_, typename E_tag_>
|
||||
Polyhedral_mesh_domain_with_features_3<GT_,P_,TA_,Tag_,E_tag_>::
|
||||
Polyhedral_mesh_domain_with_features_3(const std::string& filename,
|
||||
CGAL::Random& rng)
|
||||
CGAL::Random* p_rng)
|
||||
: Base()
|
||||
, polyhedron_()
|
||||
{
|
||||
|
|
@ -148,7 +148,7 @@ Polyhedral_mesh_domain_with_features_3(const std::string& filename,
|
|||
std::ifstream input(filename.c_str());
|
||||
input >> polyhedron_;
|
||||
this->add_primitives(polyhedron_);
|
||||
this->set_random_generator(rng);
|
||||
this->set_random_generator(p_rng);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public:
|
|||
//-------------------------------------------------------
|
||||
Image image;
|
||||
image.read("data/liver.inr.gz");
|
||||
Mesh_domain domain(image,CGAL::default_random,1e-9);
|
||||
Mesh_domain domain(image,&CGAL::default_random,1e-9);
|
||||
|
||||
// Set mesh criteria
|
||||
Facet_criteria facet_criteria(25, 20*image.vx(), 5*image.vx());
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ struct Implicit_tester : public Tester<K>
|
|||
//-------------------------------------------------------
|
||||
Mesh_domain domain(Implicit_tester<K>::sphere_function,
|
||||
Sphere_3(CGAL::ORIGIN,2.),
|
||||
CGAL::default_random);
|
||||
&CGAL::default_random);
|
||||
|
||||
// Set mesh criteria
|
||||
Facet_criteria facet_criteria(0, 0, 0.3);
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ struct Polyhedron_tester : public Tester<K>
|
|||
input >> polyhedron;
|
||||
input.close();
|
||||
|
||||
Mesh_domain domain(polyhedron);
|
||||
Mesh_domain domain(polyhedron, &CGAL::default_random);
|
||||
|
||||
// Set mesh criteria
|
||||
Facet_criteria facet_criteria(30, 0.2, 0.02);
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ struct Polyhedron_with_features_tester : public Tester<K>
|
|||
//-------------------------------------------------------
|
||||
// Data generation
|
||||
//-------------------------------------------------------
|
||||
Mesh_domain domain("data/cube.off");
|
||||
Mesh_domain domain("data/cube.off", &CGAL::default_random);
|
||||
domain.detect_features();
|
||||
|
||||
// Set mesh criteria
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ int main(int argc, char** argv)
|
|||
Point(0, 1, 0),
|
||||
Point(0, 0, 1));
|
||||
|
||||
Mesh_domain domain(p);
|
||||
Mesh_domain domain(p, &CGAL::default_random);
|
||||
|
||||
typedef std::vector<K::Point_3> Polyline;
|
||||
typedef std::vector<Polyline> Polylines;
|
||||
|
|
|
|||
Loading…
Reference in New Issue