Skip to content

Commit 23cfdf1

Browse files
committed
feat(Attributes): add uuid to identify attributes and remove find or create method
1 parent a9482f0 commit 23cfdf1

40 files changed

Lines changed: 234 additions & 218 deletions

bindings/python/src/basic/attribute_manager.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ namespace geode
3636
void python_attribute_class( pybind11::class_< AttributeManager >& manager,
3737
const std::string& suffix )
3838
{
39-
const auto read_suffix = absl::StrCat( "read_attribute_", suffix );
40-
manager.def(
41-
read_suffix.c_str(), &AttributeManager::read_attribute< type > );
39+
const auto read_suffix =
40+
absl::StrCat( "find_read_only_attribute_", suffix );
41+
manager.def( read_suffix.c_str(),
42+
&AttributeManager::find_read_only_attribute< type > );
4243
const auto create_constant_suffix =
4344
absl::StrCat( "create_attribute_constant_", suffix );
4445
manager.def( create_constant_suffix.c_str(),
4546
static_cast< geode::uuid ( AttributeManager::* )(
46-
std::string_view, type ) >(
47+
std::string_view, type, AttributeProperties ) >(
4748
&AttributeManager::create_attribute< ConstantAttribute,
4849
type > ) );
4950
const auto find_constant_suffix =
@@ -57,7 +58,7 @@ namespace geode
5758
absl::StrCat( "create_attribute_variable_", suffix );
5859
manager.def( create_variable_suffix.c_str(),
5960
static_cast< geode::uuid ( AttributeManager::* )(
60-
std::string_view, type ) >(
61+
std::string_view, type, AttributeProperties ) >(
6162
&AttributeManager::create_attribute< VariableAttribute,
6263
type > ) );
6364
const auto find_variable_suffix =
@@ -70,9 +71,10 @@ namespace geode
7071
const auto create_sparse_suffix =
7172
absl::StrCat( "create_attribute_sparse_", suffix );
7273
manager.def( create_sparse_suffix.c_str(),
73-
static_cast< geode::uuid ( AttributeManager::* )( std::string_view,
74-
type ) >( &AttributeManager::create_attribute< SparseAttribute,
75-
type > ) );
74+
static_cast< geode::uuid ( AttributeManager::* )(
75+
std::string_view, type, AttributeProperties ) >(
76+
&AttributeManager::create_attribute< SparseAttribute,
77+
type > ) );
7678
const auto find_sparse_suffix =
7779
absl::StrCat( "find_attribute_sparse_", suffix );
7880
manager.def( find_sparse_suffix.c_str(),

bindings/python/tests/basic/test-py-attribute.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
def test_constant_attribute(manager):
3333

3434
constant_attribute_id = manager.create_attribute_constant_bool(
35-
"bool", True)
35+
"bool", True, basic.AttributeProperties())
3636
constant_attribute = manager.find_attribute_constant_bool(constant_attribute_id)
37-
attribute = manager.read_attribute_bool(constant_attribute_id)
37+
attribute = manager.find_read_only_attribute_bool(constant_attribute_id)
3838
if not attribute.value(0):
3939
raise ValueError("[Test] Should be equal to True")
4040

@@ -46,7 +46,7 @@ def test_constant_attribute(manager):
4646

4747
def test_int_variable_attribute(manager):
4848
variable_attribute_id = manager.create_attribute_variable_int(
49-
"int", 12)
49+
"int", 12,basic.AttributeProperties())
5050
variable_attribute = manager.find_attribute_variable_int(variable_attribute_id)
5151
variable_attribute.set_value(3, 3)
5252
if not variable_attribute.is_genericable():
@@ -56,48 +56,48 @@ def test_int_variable_attribute(manager):
5656
if not variable_attribute.properties().assignable or not variable_attribute.properties().interpolable :
5757
raise ValueError("[Test] Should be assignable and interpolable")
5858

59-
read_attribute = manager.read_attribute_int(variable_attribute_id)
59+
find_read_only_attribute = manager.find_read_only_attribute_int(variable_attribute_id)
6060
if variable_attribute.value(3) != 3:
6161
raise ValueError("[Test] Should be equal to 3")
6262
if variable_attribute.value(6) != 12:
6363
raise ValueError("[Test] Should be equal to 12")
64-
if read_attribute.value(3) != 3:
64+
if find_read_only_attribute.value(3) != 3:
6565
raise ValueError("[Test] Should be equal to 3")
66-
if read_attribute.value(6) != 12:
66+
if find_read_only_attribute.value(6) != 12:
6767
raise ValueError("[Test] Should be equal to 12")
6868

6969
variable_attribute.set_value(3, 5)
7070
if variable_attribute.value(3) != 5:
7171
raise ValueError("[Test] Should be equal to 5")
72-
if read_attribute.value(3) != 5:
72+
if find_read_only_attribute.value(3) != 5:
7373
raise ValueError("[Test] Should be equal to 5")
7474

7575

7676
def test_double_sparse_attribute(manager):
7777
sparse_attribute_id = manager.create_attribute_sparse_double(
78-
"double", 12)
78+
"double", 12,basic.AttributeProperties())
7979
attribute = manager.find_attribute_sparse_double(sparse_attribute_id)
8080
attribute.set_value(3, 3)
8181
attribute.set_value(7, 7)
8282

83-
read_attribute = manager.read_attribute_double(sparse_attribute_id)
83+
find_read_only_attribute = manager.find_read_only_attribute_double(sparse_attribute_id)
8484
if attribute.value(3) != 3:
8585
raise ValueError("[Test] Should be equal to 3")
8686
if attribute.value(6) != 12:
8787
raise ValueError("[Test] Should be equal to 12")
8888
if attribute.value(7) != 7:
8989
raise ValueError("[Test] Should be equal to 7")
90-
if read_attribute.value(3) != 3:
90+
if find_read_only_attribute.value(3) != 3:
9191
raise ValueError("[Test] Should be equal to 3")
92-
if read_attribute.value(6) != 12:
92+
if find_read_only_attribute.value(6) != 12:
9393
raise ValueError("[Test] Should be equal to 12")
94-
if read_attribute.value(7) != 7:
94+
if find_read_only_attribute.value(7) != 7:
9595
raise ValueError("[Test] Should be equal to 7")
9696

9797
attribute.set_value(3, 5)
9898
if attribute.value(3) != 5:
9999
raise ValueError("[Test] Should be equal to 5")
100-
if read_attribute.value(3) != 5:
100+
if find_read_only_attribute.value(3) != 5:
101101
raise ValueError("[Test] Should be equal to 5")
102102
return sparse_attribute_id
103103

@@ -119,7 +119,7 @@ def test_delete_attribute_elements(manager):
119119

120120

121121
def test_sparse_attribute_after_element_deletion(manager, double_attribute_id):
122-
sparse_attribute = manager.read_attribute_double(double_attribute_id)
122+
sparse_attribute = manager.find_read_only_attribute_double(double_attribute_id)
123123
if sparse_attribute.value(0) != 12:
124124
raise ValueError("Element 0 of sparse attribute should be 12 ")
125125
if sparse_attribute.value(5) != 7:

bindings/python/tests/mesh/test-py-edged-curve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_edge_requests(edged_curve, builder):
124124

125125
def test_clone(edged_curve):
126126
attribute_id = edged_curve.edge_attribute_manager(
127-
).create_attribute_variable_int("test", 0)
127+
).create_attribute_variable_int("test", 0,opengeode_py_basic.AttributeProperties())
128128

129129
attribute = edged_curve.edge_attribute_manager().find_attribute_variable_int(attribute_id)
130130
attribute.set_value(0, 42)
@@ -135,7 +135,7 @@ def test_clone(edged_curve):
135135
if edged_curve2.nb_edges() != 3:
136136
raise ValueError("[Test] EdgedCurve2 should have 3 edge")
137137

138-
attribute2 = edged_curve2.edge_attribute_manager().read_attribute_int(attribute_id)
138+
attribute2 = edged_curve2.edge_attribute_manager().find_read_only_attribute_int(attribute_id)
139139
if attribute2.value(0) != 42:
140140
raise ValueError("[Test] EdgedCurve2 attribute should be 42")
141141

bindings/python/tests/mesh/test-py-gradient-computation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_gradient_grid2D():
3535
builder = mesh.RegularGridBuilder2D.create( grid )
3636
builder.initialize_cartesian_grid( geom.Point2D([ 0, 0 ] ), [ 3, 3 ], 1 )
3737
scalar_function_name = "scalar_function"
38-
attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0 )
38+
attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0,opengeode_py_basic.AttributeProperties() )
3939
attribute = grid.vertex_attribute_manager().find_attribute_variable_double( attribute_id )
4040
attribute.set_value( 1, 1 )
4141
attribute.set_value( 4, 1 )
@@ -81,7 +81,7 @@ def test_gradient_triangulated_surface2D():
8181
builder.create_polygon( [ 5, 6, 8 ] )
8282
builder.compute_polygon_adjacencies()
8383
scalar_function_name = "scalar_function"
84-
attribute_id = surface.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0 )
84+
attribute_id = surface.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0,opengeode_py_basic.AttributeProperties() )
8585
attribute = surface.vertex_attribute_manager().find_attribute_variable_double( attribute_id )
8686
attribute.set_value( 1, 1 )
8787
attribute.set_value( 2, 1 )
@@ -100,7 +100,7 @@ def test_gradient_grid3D():
100100
builder = mesh.RegularGridBuilder3D.create( grid )
101101
builder.initialize_cartesian_grid( geom.Point3D([ 0, 0, 0 ]), [ 2, 2, 2 ], 1 )
102102
scalar_function_name = "scalar_function"
103-
attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0 )
103+
attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0,opengeode_py_basic.AttributeProperties() )
104104
attribute = grid.vertex_attribute_manager().find_attribute_variable_double( attribute_id )
105105
attribute.set_value( 4, 1 )
106106
attribute.set_value( 10, 1 )

bindings/python/tests/mesh/test-py-light-regular-grid.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,11 @@ def test_closest_vertex(grid):
288288

289289
def test_attribute_3d(grid):
290290
attribute_id = grid.cell_attribute_manager().create_attribute_variable_double(
291-
"toto", -1
291+
"toto", -1,geode.AttributeProperties()
292292
)
293293
attribute = grid.cell_attribute_manager().find_attribute_variable_double(attribute_id)
294294
attribute.set_value(10, 10)
295-
attribute = grid.cell_attribute_manager().read_attribute_double(attribute_id)
295+
attribute = grid.cell_attribute_manager().find_read_only_attribute_double(attribute_id)
296296
if attribute.value(0) != -1:
297297
raise ValueError("[Test] Wrong attribute value")
298298
if attribute.value(10) != 10:
@@ -301,7 +301,7 @@ def test_attribute_3d(grid):
301301
raise ValueError("[Test] Wrong attribute value")
302302
attribute_id = (
303303
grid.grid_vertex_attribute_manager().create_attribute_variable_double(
304-
"toto_vertex", 1
304+
"toto_vertex", 1,geode.AttributeProperties()
305305
)
306306
)
307307
attribute = grid.grid_vertex_attribute_manager().find_attribute_variable_double(
@@ -319,11 +319,11 @@ def test_attribute_3d(grid):
319319
def test_attribute_2d():
320320
grid = mesh.LightRegularGrid2D(geom.Point2D([1.5, 0]), [5, 10], [1.0, 2.0])
321321
attribute_id = grid.cell_attribute_manager().create_attribute_variable_double(
322-
"toto", -1
322+
"toto", -1,geode.AttributeProperties()
323323
)
324324
attribute = grid.cell_attribute_manager().find_attribute_variable_double(attribute_id)
325325
attribute.set_value(10, 10)
326-
attribute = grid.cell_attribute_manager().read_attribute_double(attribute_id)
326+
attribute = grid.cell_attribute_manager().find_read_only_attribute_double(attribute_id)
327327
if attribute.value(0) != -1:
328328
raise ValueError("[Test] Wrong attribute value")
329329
if attribute.value(10) != 10:
@@ -332,7 +332,7 @@ def test_attribute_2d():
332332
raise ValueError("[Test] Wrong attribute value")
333333
attribute_id = (
334334
grid.grid_vertex_attribute_manager().create_attribute_variable_double(
335-
"toto_vertex", 1
335+
"toto_vertex", 1,geode.AttributeProperties()
336336
)
337337
)
338338
attribute = grid.grid_vertex_attribute_manager().find_attribute_variable_double(

bindings/python/tests/mesh/test-py-point-set.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_bounding_box(point_set):
5959
def test_create_vertex_attribute(point_set):
6060
manager = point_set.vertex_attribute_manager()
6161
attribute_id = point_set.vertex_attribute_manager(
62-
).create_attribute_constant_bool("test", True)
62+
).create_attribute_constant_bool("test", True,opengeode_py_basic.AttributeProperties())
6363
attribute = manager.find_attribute_constant_bool(attribute_id)
6464
if attribute.constant_value() != True:
6565
raise ValueError("[Test] PointSet attribute value should be true")
@@ -87,7 +87,7 @@ def test_clone(point_set, attribute_id):
8787
if point_set2.nb_vertices() != 3:
8888
raise ValueError("[Test] PointSet2 should have 3 vertices")
8989

90-
attribute = point_set2.vertex_attribute_manager().read_attribute_bool(attribute_id)
90+
attribute = point_set2.vertex_attribute_manager().find_read_only_attribute_bool(attribute_id)
9191
if attribute.value(0) != True:
9292
raise ValueError("[Test] PointSet2 attribute value should be true")
9393

bindings/python/tests/mesh/test-py-polygonal-surface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_create_polygons(polygonal_surface, builder):
6767

6868
def test_create_edge_attribute(polygonal_surface):
6969
attribute_id = polygonal_surface.edges().edge_attribute_manager(
70-
).create_attribute_variable_uint("test", basic.NO_ID)
70+
).create_attribute_variable_uint("test", basic.NO_ID,basic.AttributeProperties())
7171
attribute = polygonal_surface.edges().edge_attribute_manager(
7272
).find_attribute_variable_uint(attribute_id)
7373
for e in range(polygonal_surface.edges().nb_edges()):
@@ -136,7 +136,7 @@ def test_delete_polygon(polygonal_surface, builder, attribute_id):
136136
raise ValueError("[Test] PolygonalSurface should have 6 edges")
137137

138138
attribute = polygonal_surface.edges(
139-
).edge_attribute_manager().read_attribute_uint(attribute_id)
139+
).edge_attribute_manager().find_read_only_attribute_uint(attribute_id)
140140
for e in range(6):
141141
if attribute.value(e) != e:
142142
raise ValueError("[Test] Update of edge attributes after "
@@ -221,7 +221,7 @@ def test_io(polygonal_surface, filename, attribute_id):
221221
raise ValueError(
222222
"[Test] Reloaded PolygonalSurface should have 3 polygons")
223223
attribute = new_polygonal_surface.edges(
224-
).edge_attribute_manager().read_attribute_uint(attribute_id)
224+
).edge_attribute_manager().find_read_only_attribute_uint(attribute_id)
225225
for e in range(new_polygonal_surface.edges().nb_edges()):
226226
if attribute.value(e) != e:
227227
raise ValueError(

bindings/python/tests/mesh/test-py-polyhedral-solid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_create_polyhedra(polyhedral_solid, builder):
7373

7474
def test_create_facet_attribute(polyhedral_solid):
7575
attribute_id = polyhedral_solid.facets().facet_attribute_manager(
76-
).create_attribute_variable_uint("test", basic.NO_ID)
76+
).create_attribute_variable_uint("test", basic.NO_ID, basic.AttributeProperties())
7777
attribute = polyhedral_solid.facets().facet_attribute_manager(
7878
).find_attribute_variable_uint(attribute_id)
7979
for f in range(polyhedral_solid.facets().nb_facets()):
@@ -83,7 +83,7 @@ def test_create_facet_attribute(polyhedral_solid):
8383

8484
def test_create_edge_attribute(polyhedral_solid):
8585
attribute_id = polyhedral_solid.edges().edge_attribute_manager(
86-
).create_attribute_variable_uint("test", basic.NO_ID)
86+
).create_attribute_variable_uint("test", basic.NO_ID, basic.AttributeProperties())
8787
attribute = polyhedral_solid.edges().edge_attribute_manager(
8888
).find_attribute_variable_uint(attribute_id)
8989
for e in range(polyhedral_solid.edges().nb_edges()):
@@ -166,7 +166,7 @@ def test_delete_polyhedra(polyhedral_solid, builder,edge_attribute_id):
166166
if polyhedral_solid.edges().nb_edges() != 12:
167167
raise ValueError("[Test] PolyhedralSolid should have 12 edges")
168168
attribute = polyhedral_solid.edges(
169-
).edge_attribute_manager().read_attribute_uint(edge_attribute_id)
169+
).edge_attribute_manager().find_read_only_attribute_uint(edge_attribute_id)
170170
if attribute.value(0) != 1:
171171
raise ValueError(
172172
"[Test] Wrong value for attribute on edge 0 after polyhedron deletion")
@@ -192,7 +192,7 @@ def test_io(polyhedral_solid, filename, facet_attribute_id):
192192
raise ValueError(
193193
"[Test] Reloaded PolyhedralSolid should have 3 polyhedra")
194194
attribute = new_polyhedral_solid.facets(
195-
).facet_attribute_manager().read_attribute_uint(facet_attribute_id)
195+
).facet_attribute_manager().find_read_only_attribute_uint(facet_attribute_id)
196196
for f in range(new_polyhedral_solid.facets().nb_facets()):
197197
if attribute.value(f) != f:
198198
raise ValueError(

bindings/python/tests/mesh/test-py-regular-grid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ def test_clone(grid):
248248
attribute_name_d = "double_attribute"
249249
attribute_id = (
250250
grid.polyhedron_attribute_manager().create_attribute_variable_int(
251-
attribute_name, 0
251+
attribute_name, 0,geode.AttributeProperties()
252252
)
253253
)
254254
attribute = grid.polyhedron_attribute_manager().find_attribute_variable_int(
255255
attribute_id
256256
)
257257
attribute_d_id = (
258258
grid.vertex_attribute_manager().create_attribute_variable_double(
259-
attribute_name_d, 0
259+
attribute_name_d, 0,geode.AttributeProperties()
260260
)
261261
)
262262
attribute_d = grid.vertex_attribute_manager().find_attribute_variable_double(
@@ -273,13 +273,13 @@ def test_clone(grid):
273273
raise ValueError("[Test] Clone missing attribute")
274274
if not clone.vertex_attribute_manager().attribute_exists(attribute_d_id):
275275
raise ValueError("[Test] Clone missing attribute")
276-
clone_attribute = clone.polyhedron_attribute_manager().read_attribute_int(
276+
clone_attribute = clone.polyhedron_attribute_manager().find_read_only_attribute_int(
277277
attribute_id
278278
)
279279
for c in range(clone.nb_cells()):
280280
if clone_attribute.value(c) != 2 * c:
281281
raise ValueError("[Test] Wrong clone attribute")
282-
clone_attribute_d = clone.vertex_attribute_manager().read_attribute_double(
282+
clone_attribute_d = clone.vertex_attribute_manager().find_read_only_attribute_double(
283283
attribute_d_id
284284
)
285285
for c in range(clone.nb_vertices()):

0 commit comments

Comments
 (0)