2828
2929#include < geode/stochastic/sampling/direct/object_set_sampler/object_set_sampler.hpp>
3030#include < geode/stochastic/sampling/direct/point_uniform_sampler.hpp>
31+ #include < geode/stochastic/spatial/spatial_domain.hpp>
3132
3233namespace geode
3334{
3435 template < index_t dimension >
3536 class UniformPointSetSampler : public ObjectSetSampler < Point< dimension > >
3637 {
3738 public:
38- UniformPointSetSampler ( const BoundingBox < dimension >& box )
39- : ObjectSetSampler< Point< dimension > >{}, box_( box )
39+ UniformPointSetSampler ( const SpatialDomain < dimension >& domain )
40+ : ObjectSetSampler< Point< dimension > >{}, domain_( domain )
4041 {
41- auto volume = box_. n_volume ();
42+ auto volume = domain_. extended_n_volume ();
4243 OPENGEODE_EXCEPTION ( volume != 0 .,
43- " [PointSetSampler] - Undefined Bounding Box (volume ==0)." );
44+ " [PointSetSampler] - Undefined Extended Bounding "
45+ " Box (volume ==0)." );
4446 this ->log_pdf_ = -std::log ( volume );
47+ step_move_ = define_step_for_move ();
48+ OPENGEODE_EXCEPTION ( step_move_ > 0 .,
49+ " [PointSetSampler] - Undefined step length for move (value == " ,
50+ step_move_, " )." );
4551 }
4652
4753 Point< dimension > sample ( RandomEngine& engine ) const override
4854 {
49- return PointUniformSampler::sample< dimension >( engine, box_ );
55+ return PointUniformSampler::sample< dimension >(
56+ engine, domain_.extended_box () );
5057 }
5158
5259 Point< dimension > change (
5360 const Point< dimension >& obj, RandomEngine& engine ) const override
5461 {
55- double ratio = 0.1 ;
56- geode::Sphere< dimension > ball{ obj,
57- ratio * std::get< 1 >( box_.smallest_length () ) };
62+ geode::Sphere< dimension > ball{ obj, step_move_ };
5863
5964 auto new_point =
6065 PointUniformSampler::sample< dimension >( engine, ball );
6166 constexpr index_t max_try{ 100 };
6267 for ( const auto try_id : geode::Range{ max_try } )
6368 {
64- if ( box_. contains ( new_point ) )
69+ if ( domain_. extended_contains ( new_point ) )
6570 {
6671 return new_point;
6772 }
6873 new_point =
6974 PointUniformSampler::sample< dimension >( engine, ball );
7075 }
71- throw OpenGeodeException ( absl::StrCat (
72- " [PointSampler] - Cannot find a point in the box: " ,
73- box_. string () ) );
76+ throw OpenGeodeException (
77+ absl::StrCat ( " [PointSampler] - Cannot find a point in the "
78+ " extended domain " ) );
7479 return obj;
7580 }
7681
7782 private:
83+ double define_step_for_move ()
84+ {
85+ double ratio = 0.1 ;
86+ return ratio * domain_.smallest_length ();
87+ }
88+
7889 bool is_valid_object ( const Point< dimension >& obj ) const override
7990 {
80- return box_. contains ( obj );
91+ return domain_. extended_contains ( obj );
8192 }
8293
8394 private:
84- BoundingBox< dimension > box_;
95+ const SpatialDomain< dimension >& domain_;
96+ double step_move_{ 0 . };
8597 };
8698
8799} // namespace geode
0 commit comments