2323
2424#pragma once
2525
26- #include < geode/geometry/basic_objects/segment.hpp>
27- #include < geode/geometry/basic_objects/sphere.hpp>
26+ // #include <geode/geometry/basic_objects/segment.hpp>
2827
28+ #include < geode/stochastic/sampling/direct/double_sampler.hpp>
2929#include < geode/stochastic/sampling/direct/object_set_sampler/object_set_sampler.hpp>
30- #include < geode/stochastic/sampling/direct/point_uniform_sampler.hpp>
31- #include < geode/stochastic/sampling/direct/segment_uniform_sampler.hpp>
32- #include < geode/stochastic/spatial/spatial_domain.hpp>
3330
3431namespace geode
3532{
33+ template <>
34+ struct ObjectSamplerConfig < OwnerSegment2D >
35+ {
36+ double move_ratio = 0.1 ;
37+
38+ DoubleSampler::DistributionDescription length;
39+ DoubleSampler::DistributionDescription azimuth;
40+ };
41+
3642 class UniformSegmentSetSampler : public ObjectSetSampler < OwnerSegment2D >
3743 {
3844 public:
3945 UniformSegmentSetSampler ( const SpatialDomain< 2 >& domain,
40- const ObjectSamplerConfig< Segment2D >& config )
41- : ObjectSetSampler< OwnerSegment2D >{},
42- domain_{ domain },
43- length_{ DoubleSampler::build_distribution ( config.length ) },
44- azimuth_{ DoubleSampler::build_distribution ( config.azimuth ) },
45- move_ratio_{ config.move_ratio }
46- {
47- auto volume = domain_.extended_n_volume ();
48- OpenGeodeStochasticStochasticException::check_exception (
49- volume != 0 ., nullptr , OpenGeodeException::TYPE ::data,
50- " [UniformSegmentSetSampler] Undefined Extended Bounding "
51- " Box (volume ==0)." );
52- this ->log_pdf_ = -std::log ( volume );
53- }
46+ const ObjectSamplerConfig< OwnerSegment2D >& config );
5447
55- OwnerSegment2D sample ( RandomEngine& engine ) const override
56- {
57- auto seg = SegmentUniformSampler::sample (
58- engine, domain_.extended_box (), length_, azimuth_ );
59- return seg;
60- }
48+ [[nodiscard]] OwnerSegment2D sample (
49+ RandomEngine& engine ) const override ;
6150
62- OwnerSegment2D change (
63- const OwnerSegment2D& obj, RandomEngine& engine ) const override
64- {
65- const auto & extremities = obj.vertices ();
66- const auto current =
67- static_cast < local_index_t >( engine.sample_bernoulli ( 0.5 ) );
68- const auto other = 1 - current;
69-
70- geode::Sphere< 2 > ball{ extremities[current],
71- move_ratio_ * obj.length () };
72-
73- auto new_point = PointUniformSampler::sample< 2 >( engine, ball );
74- constexpr index_t max_try{ 100 };
75- for ( const auto try_id : geode::Range{ max_try } )
76- {
77- if ( domain_.extended_contains ( new_point )
78- || domain_.extended_contains ( extremities[other] ) )
79- {
80- OwnerSegment2D new_segment{ obj };
81- new_segment.set_point ( current, new_point );
82- return new_segment;
83- }
84- new_point = PointUniformSampler::sample< 2 >( engine, ball );
85- }
86- throw OpenGeodeStochasticStochasticException{ nullptr ,
87- OpenGeodeException::TYPE ::internal,
88- " [SegmentSetSampler] - Cannot find a point in the box" };
89- return obj;
90- }
51+ [[nodiscard]] OwnerSegment2D change (
52+ const OwnerSegment2D& obj, RandomEngine& engine ) const override ;
9153
9254 private:
93- bool is_valid_object ( const OwnerSegment2D& obj ) const override
94- {
95- const auto & extremities = obj.vertices ();
96- return domain_.extended_contains ( extremities[0 ] )
97- || domain_.extended_contains ( extremities[1 ] );
98- }
55+ [[nodiscard]] bool is_valid_object (
56+ const OwnerSegment2D& obj ) const override ;
9957
10058 private:
10159 const SpatialDomain< 2 >& domain_;
@@ -104,21 +62,4 @@ namespace geode
10462 double move_ratio_{ 0.1 };
10563 };
10664
107- template <>
108- struct ObjectSamplerConfig < OwnerSegment2D >
109- {
110- double move_ratio = 0.1 ;
111-
112- DoubleSampler::DistributionDescription length;
113- DoubleSampler::DistributionDescription azimuth;
114- };
115-
116- template <>
117- std::unique_ptr< ObjectSetSampler< OwnerSegment2D > >
118- build_objectset_sampler ( const SpatialDomain< 2 >& domain,
119- const ObjectSamplerConfig< OwnerSegment2D >& config )
120- {
121- return std::make_unique< UniformSegmentSetSampler >( domain, config );
122- }
123-
12465} // namespace geode
0 commit comments