Skip to content

Commit cd5aaa4

Browse files
start refactoring
1 parent 2c34132 commit cd5aaa4

21 files changed

Lines changed: 2420 additions & 552 deletions

include/geode/stochastic/configuration/configuration.hpp

Lines changed: 74 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,63 +25,89 @@
2525

2626
#include <vector>
2727

28-
#include <geode/stochastic/configuration/marked_object.hpp>
28+
#include <geode/geometry/basic_objects/segment.hpp>
29+
#include <geode/geometry/bounding_box.hpp>
30+
#include <geode/geometry/point.hpp>
2931

32+
// #include <geode/stochastic/configuration/neighbors_object_ids.hpp>
3033
namespace geode
3134
{
32-
template < typename Geometry >
35+
// can be a index_t used as a key in unordored map but maybe a "string is
36+
// beter?"
37+
struct GroupId
38+
{
39+
index_t value;
40+
bool operator==( GroupId const& other ) const noexcept
41+
{
42+
{
43+
return value == other.value;
44+
}
45+
}
46+
};
47+
48+
struct ObjectId
49+
{
50+
index_t object;
51+
GroupId group;
52+
bool operator==( const ObjectId& other ) const noexcept
53+
{
54+
return object == other.object && group == other.group;
55+
}
56+
};
57+
} // namespace geode
58+
// Hash support for unordered_map
59+
namespace std
60+
{
61+
template <>
62+
struct hash< geode::GroupId >
63+
{
64+
std::size_t operator()( geode::GroupId const& g ) const noexcept
65+
{
66+
return std::hash< geode::index_t >()( g.value );
67+
}
68+
};
69+
70+
// template <>
71+
// struct hash< geode::ObjectId >
72+
//{
73+
// std::size_t operator()( geode::ObjectId const& id ) const noexcept
74+
// {
75+
// return ( std::hash< geode::index_t >()( id.group.value ) << 1 )
76+
// ^ std::hash< geode::index_t >()( id.object );
77+
// }
78+
// };
79+
} // namespace std
80+
namespace geode
81+
{
82+
template < typename Object >
3383
class Configuration
3484
{
3585
public:
36-
void add_object( MarkedObject< Geometry >&& object );
37-
void change_object( index_t idx, MarkedObject< Geometry >&& object );
38-
void remove_object( index_t idx );
39-
index_t size() const;
86+
const Object& get_object( ObjectId object_id ) const;
87+
const std::vector< Object >& get_group( const GroupId& group_id ) const;
88+
std::vector< ObjectId > get_all_object() const;
89+
90+
index_t nb_groups() const;
91+
index_t nb_objects_in_group( const GroupId& group_id ) const;
92+
index_t nb_objects() const;
4093

41-
/**
42-
* @brief Bounds-checked access to the marked object at index @p idx.
43-
* Wrapper for std::vector::at().
44-
* @throws std::out_of_range if idx is out of range.
45-
*/
46-
const MarkedObject< Geometry >& object( index_t idx ) const;
47-
/**
48-
* @brief Unchecked access to the marked object at index @p idx.
49-
* Wrapper for std::vector::operator[]().
50-
*/
51-
const MarkedObject< Geometry >& operator[]( index_t idx ) const;
94+
ObjectId add_object( Object&& object, GroupId group_id );
95+
void update_object( ObjectId object_id, Object&& object );
96+
void remove_object( ObjectId object_id );
5297

53-
std::vector< index_t > object_ids_with_mark( const Mark& mark );
98+
// Object neighbor search by ObjectId (always excludes self)
99+
std::vector< ObjectId > neighbors(
100+
const ObjectId object_id, double searching_distance ) const;
101+
// Object neighbor search by arbitrary object (return self if in the
102+
// configuration)
103+
std::vector< ObjectId > neighbors(
104+
const Object& object, double searching_distance ) const;
54105

55106
private:
56-
std::vector< MarkedObject< Geometry > > objects_;
107+
std::vector< Object >& get_group( const GroupId& group_id );
108+
109+
private:
110+
std::unordered_map< GroupId, std::vector< Object > > groups_;
111+
// ObjectIndexRTree< 2 > tree_;
57112
};
58113
} // namespace geode
59-
60-
// std::string sample_three( absl::BitGen& gen, double p1, double p2, double p3
61-
// )
62-
//{
63-
// if( absl::Bernoulli( gen, p1 ) )
64-
// {
65-
// return "A";
66-
// }
67-
// if( absl::Bernoulli( gen, p2 / ( p2 + p3 ) ) )
68-
// { // conditional probability
69-
// return "B";
70-
// }
71-
// return "C";
72-
// }
73-
// A configuration is collection of spatialized objects:
74-
// * Basic Object
75-
// * parametric Object-->marked points
76-
// * meshes
77-
// a pattern is the superposition of several subcollection of object of
78-
// différent type. ( fracture sets)
79-
80-
// a pattern should be easy to modify...
81-
// each object can be added, removed or modified several times.
82-
// we also want to have access to neighbors( fist, second or third circle of
83-
// neighbors) rtree?
84-
//
85-
// a collections of helpers need to be done to evaluates "interactions" between
86-
// objects.
87-
//

include/geode/stochastic/configuration/marked_object.hpp

Lines changed: 0 additions & 104 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2019 - 2025 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#pragma once
25+
#include <geode/stochastic/configuration/r_tree.hpp>
26+
27+
namespace geode
28+
{
29+
FORWARD_DECLARATION_DIMENSION_CLASS( BoundingBox );
30+
}
31+
32+
namespace geode
33+
{
34+
35+
template < index_t dimension >
36+
class ObjectIndexRTree
37+
{
38+
OPENGEODE_DISABLE_COPY_AND_MOVE( ObjectIndexRTree );
39+
40+
public:
41+
ObjectIndexRTree();
42+
~ObjectIndexRTree() = default;
43+
44+
void add( const BoundingBox< dimension >& box, ObjectId id );
45+
46+
void remove( const BoundingBox< dimension >& box, ObjectId id );
47+
48+
void remove_all();
49+
50+
std::vector< ObjectId > get(
51+
const BoundingBox< dimension >& box ) const;
52+
53+
int count()
54+
{
55+
return tree_.Count();
56+
}
57+
58+
private:
59+
RTree< ObjectId, double, dimension > tree_;
60+
};
61+
62+
} // namespace geode
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2019 - 2025 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#pragma once
25+
26+
#include <optional>
27+
28+
#include <geode/stochastic/common.hpp>
29+
30+
#include <geode/geometry/basic_objects/segment.hpp>
31+
#include <geode/geometry/bounding_box.hpp>
32+
#include <geode/geometry/point.hpp>
33+
34+
namespace geode
35+
{
36+
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
37+
} // namespace geode
38+
namespace geode
39+
{
40+
41+
template < typename Object >
42+
auto object_bounding_box( const Object& object )
43+
{
44+
if constexpr( std::is_same_v< Object, Point2D > )
45+
{
46+
geode::BoundingBox< 2 > box;
47+
box.add_point( object );
48+
return box;
49+
}
50+
else if constexpr( std::is_same_v< Object, Point3D > )
51+
{
52+
geode::BoundingBox< 3 > box;
53+
box.add_point( object );
54+
return box;
55+
}
56+
else
57+
{
58+
return object.bounding_box();
59+
}
60+
}
61+
template < typename Object >
62+
auto object_barycenter( const Object& object )
63+
{
64+
if constexpr( std::is_same_v< Object, Point2D >
65+
|| std::is_same_v< Object, Point3D > )
66+
{
67+
return object;
68+
}
69+
else
70+
{
71+
return object.barycenter();
72+
}
73+
}
74+
75+
} // namespace geode

0 commit comments

Comments
 (0)