Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions bindings/python/src/basic/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace geode
{
template < typename type >
void python_attribute_class(

Check warning on line 34 in bindings/python/src/basic/attribute.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/basic/attribute.cpp:34:10 [misc-use-internal-linkage]

function 'python_attribute_class' can be made static or moved into an anonymous namespace to enforce internal linkage
pybind11::module& module, const std::string& typestr )
{
const auto read_name = absl::StrCat( "ReadOnlyAttribute", typestr );
Expand All @@ -53,23 +53,47 @@
std::shared_ptr< VariableAttribute< type > > >(
module, variable_name.c_str() )
.def( "set_value", &VariableAttribute< type >::set_value )
.def( "default_value", &VariableAttribute< type >::default_value );
.def(
"default_values", &VariableAttribute< type >::default_values );
const auto sparse_name = absl::StrCat( "SparseAttribute", typestr );
pybind11::class_< SparseAttribute< type >, ReadOnlyAttribute< type >,
std::shared_ptr< SparseAttribute< type > > >(
module, sparse_name.c_str() )
.def( "set_value", &SparseAttribute< type >::set_value )
.def( "default_value", &SparseAttribute< type >::default_value );
.def( "default_values", &SparseAttribute< type >::default_values );
}

template < typename type >
void python_attribute_values_class(

Check warning on line 67 in bindings/python/src/basic/attribute.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/basic/attribute.cpp:67:10 [misc-use-internal-linkage]

function 'python_attribute_values_class' can be made static or moved into an anonymous namespace to enforce internal linkage
pybind11::module& module, const std::string& typestr )
{
const auto values_name = absl::StrCat( "AttributeValues", typestr );
pybind11::class_< AttributeValues< type > >(
module, values_name.c_str() )
.def( pybind11::init<>() )
.def_readwrite(
"default_value", &AttributeValues< type >::default_value )
.def_readwrite( "no_value", &AttributeValues< type >::no_value );
}

void define_attributes( pybind11::module& module )

Check warning on line 79 in bindings/python/src/basic/attribute.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/basic/attribute.cpp:79:10 [misc-use-internal-linkage]

function 'define_attributes' can be made static or moved into an anonymous namespace to enforce internal linkage
{
pybind11::class_< AttributeProperties >( module, "AttributeProperties" )
.def( pybind11::init<>() )
.def( pybind11::init< bool, bool >() )
.def_readwrite( "assignable", &AttributeProperties::assignable )
.def_readwrite( "interpolable", &AttributeProperties::interpolable )
.def_readwrite(
"interpolable", &AttributeProperties::interpolable );
"transferable", &AttributeProperties::transferable );

python_attribute_values_class< bool >( module, "Bool" );
python_attribute_values_class< int >( module, "Int" );
python_attribute_values_class< unsigned int >( module, "UInt" );
python_attribute_values_class< float >( module, "Float" );
python_attribute_values_class< double >( module, "Double" );
python_attribute_values_class< std::array< double, 2 > >(
module, "ArrayDouble2" );
python_attribute_values_class< std::array< double, 3 > >(
module, "ArrayDouble3" );

pybind11::class_< AttributeBase, std::shared_ptr< AttributeBase > >(
module, "AttributeBase" )
Expand Down
24 changes: 12 additions & 12 deletions bindings/python/src/basic/attribute_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
namespace geode
{
template < typename type >
void python_attribute_class( pybind11::class_< AttributeManager >& manager,

Check warning on line 36 in bindings/python/src/basic/attribute_manager.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/basic/attribute_manager.cpp:36:10 [misc-use-internal-linkage]

variable 'python_attribute_class' can be made static or moved into an anonymous namespace to enforce internal linkage

Check warning on line 36 in bindings/python/src/basic/attribute_manager.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/basic/attribute_manager.cpp:36:10 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'python_attribute_class' is non-const and globally accessible, consider making it const
const std::string& suffix )
{
const auto read_suffix =
Expand All @@ -43,13 +43,13 @@
const auto create_constant_suffix =
absl::StrCat( "create_attribute_constant_", suffix );
manager.def( create_constant_suffix.c_str(),
static_cast< geode::uuid ( AttributeManager::* )(
std::string_view, type, AttributeProperties ) >(
static_cast< geode::uuid ( AttributeManager::* )( std::string_view,
AttributeValues< type >, AttributeProperties ) >(
&AttributeManager::create_attribute< ConstantAttribute,
type > ) );
manager.def( create_constant_suffix.c_str(),
static_cast< void ( AttributeManager::* )(
std::string_view, const uuid&, type, AttributeProperties ) >(
static_cast< void ( AttributeManager::* )( std::string_view,
const uuid&, AttributeValues< type >, AttributeProperties ) >(
&AttributeManager::create_attribute< ConstantAttribute,
type > ) );
const auto find_constant_suffix =
Expand All @@ -62,13 +62,13 @@
const auto create_variable_suffix =
absl::StrCat( "create_attribute_variable_", suffix );
manager.def( create_variable_suffix.c_str(),
static_cast< geode::uuid ( AttributeManager::* )(
std::string_view, type, AttributeProperties ) >(
static_cast< geode::uuid ( AttributeManager::* )( std::string_view,
AttributeValues< type >, AttributeProperties ) >(
&AttributeManager::create_attribute< VariableAttribute,
type > ) );
manager.def( create_variable_suffix.c_str(),
static_cast< void ( AttributeManager::* )(
std::string_view, const uuid&, type, AttributeProperties ) >(
static_cast< void ( AttributeManager::* )( std::string_view,
const uuid&, AttributeValues< type >, AttributeProperties ) >(
&AttributeManager::create_attribute< VariableAttribute,
type > ) );
const auto find_variable_suffix =
Expand All @@ -81,13 +81,13 @@
const auto create_sparse_suffix =
absl::StrCat( "create_attribute_sparse_", suffix );
manager.def( create_sparse_suffix.c_str(),
static_cast< geode::uuid ( AttributeManager::* )(
std::string_view, type, AttributeProperties ) >(
static_cast< geode::uuid ( AttributeManager::* )( std::string_view,
AttributeValues< type >, AttributeProperties ) >(
&AttributeManager::create_attribute< SparseAttribute,
type > ) );
manager.def( create_sparse_suffix.c_str(),
static_cast< void ( AttributeManager::* )(
std::string_view, const uuid&, type, AttributeProperties ) >(
static_cast< void ( AttributeManager::* )( std::string_view,
const uuid&, AttributeValues< type >, AttributeProperties ) >(
&AttributeManager::create_attribute< SparseAttribute,
type > ) );
const auto find_sparse_suffix =
Expand All @@ -98,7 +98,7 @@
&AttributeManager::find_attribute< SparseAttribute, type > ) );
}

void define_attribute_manager( pybind11::module& module )

Check warning on line 101 in bindings/python/src/basic/attribute_manager.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/basic/attribute_manager.cpp:101:10 [misc-use-internal-linkage]

function 'define_attribute_manager' can be made static or moved into an anonymous namespace to enforce internal linkage
{
pybind11::class_< AttributeManager > manager(
module, "AttributeManager" );
Expand Down
36 changes: 32 additions & 4 deletions bindings/python/tests/basic/test-py-attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@

def test_constant_attribute(manager):

properties = basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = basic.AttributeValuesBool()
values.default_value = True
values.no_value = False
constant_attribute_id = manager.create_attribute_constant_bool(
"bool", True, basic.AttributeProperties())
"bool", values, properties)
constant_attribute = manager.find_attribute_constant_bool(constant_attribute_id)
attribute = manager.find_read_only_attribute_bool(constant_attribute_id)
if not attribute.value(0):
Expand All @@ -45,14 +52,27 @@ def test_constant_attribute(manager):


def test_int_variable_attribute(manager):

properties = basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = basic.AttributeValuesInt()
values.default_value = 12
values.no_value = 12
variable_attribute_id = manager.create_attribute_variable_int(
"int", 12,basic.AttributeProperties())
"int", values, properties)
variable_attribute = manager.find_attribute_variable_int(variable_attribute_id)
variable_attribute.set_value(3, 3)
if not variable_attribute.is_genericable():
raise ValueError("[Test] Should be genericable")

new_properties = basic.AttributeProperties()
new_properties.assignable = True
new_properties.interpolable = True
properties.transferable = True
manager.set_attribute_properties(variable_attribute_id,new_properties)

manager.set_attribute_properties(variable_attribute_id,basic.AttributeProperties(True,True))
if not variable_attribute.properties().assignable or not variable_attribute.properties().interpolable :
raise ValueError("[Test] Should be assignable and interpolable")

Expand All @@ -74,8 +94,16 @@ def test_int_variable_attribute(manager):


def test_double_sparse_attribute(manager):

properties = basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = basic.AttributeValuesDouble()
values.default_value = 12
values.no_value = 12
sparse_attribute_id = manager.create_attribute_sparse_double(
"double", 12,basic.AttributeProperties())
"double", values,properties)
attribute = manager.find_attribute_sparse_double(sparse_attribute_id)
attribute.set_value(3, 3)
attribute.set_value(7, 7)
Expand Down
10 changes: 9 additions & 1 deletion bindings/python/tests/mesh/test-py-edged-curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,16 @@ def test_edge_requests(edged_curve, builder):


def test_clone(edged_curve):

properties = opengeode_py_basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = opengeode_py_basic.AttributeValuesInt()
values.default_value = 0
values.no_value = 0
attribute_id = edged_curve.edge_attribute_manager(
).create_attribute_variable_int("test", 0,opengeode_py_basic.AttributeProperties())
).create_attribute_variable_int("test", values,properties)

attribute = edged_curve.edge_attribute_manager().find_attribute_variable_int(attribute_id)
attribute.set_value(0, 42)
Expand Down
27 changes: 24 additions & 3 deletions bindings/python/tests/mesh/test-py-gradient-computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ def test_gradient_grid2D():
builder = mesh.RegularGridBuilder2D.create( grid )
builder.initialize_cartesian_grid( geom.Point2D([ 0, 0 ] ), [ 3, 3 ], 1 )
scalar_function_name = "scalar_function"
attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0,opengeode_py_basic.AttributeProperties() )
properties = opengeode_py_basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = opengeode_py_basic.AttributeValuesDouble()
values.default_value = 0
values.no_value = 0
attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, values,properties )
attribute = grid.vertex_attribute_manager().find_attribute_variable_double( attribute_id )
attribute.set_value( 1, 1 )
attribute.set_value( 4, 1 )
Expand Down Expand Up @@ -81,7 +88,14 @@ def test_gradient_triangulated_surface2D():
builder.create_polygon( [ 5, 6, 8 ] )
builder.compute_polygon_adjacencies()
scalar_function_name = "scalar_function"
attribute_id = surface.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0,opengeode_py_basic.AttributeProperties() )
properties = opengeode_py_basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = opengeode_py_basic.AttributeValuesDouble()
values.default_value = 0
values.no_value = 0
attribute_id = surface.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, values,properties )
attribute = surface.vertex_attribute_manager().find_attribute_variable_double( attribute_id )
attribute.set_value( 1, 1 )
attribute.set_value( 2, 1 )
Expand All @@ -100,7 +114,14 @@ def test_gradient_grid3D():
builder = mesh.RegularGridBuilder3D.create( grid )
builder.initialize_cartesian_grid( geom.Point3D([ 0, 0, 0 ]), [ 2, 2, 2 ], 1 )
scalar_function_name = "scalar_function"
attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0,opengeode_py_basic.AttributeProperties() )
properties = opengeode_py_basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = opengeode_py_basic.AttributeValuesDouble()
values.default_value = 0
values.no_value = 0
attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, values,properties )
attribute = grid.vertex_attribute_manager().find_attribute_variable_double( attribute_id )
attribute.set_value( 4, 1 )
attribute.set_value( 10, 1 )
Expand Down
28 changes: 24 additions & 4 deletions bindings/python/tests/mesh/test-py-light-regular-grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,15 @@ def test_closest_vertex(grid):


def test_attribute_3d(grid):
properties = geode.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
first_values = geode.AttributeValuesDouble()
first_values.default_value = -1
first_values.no_value = -1
attribute_id = grid.cell_attribute_manager().create_attribute_variable_double(
"toto", -1,geode.AttributeProperties()
"toto", first_values,properties
)
attribute = grid.cell_attribute_manager().find_attribute_variable_double(attribute_id)
attribute.set_value(10, 10)
Expand All @@ -299,9 +306,12 @@ def test_attribute_3d(grid):
raise ValueError("[Test] Wrong attribute value")
if attribute.value(grid.nb_cells() - 1) != -1:
raise ValueError("[Test] Wrong attribute value")
second_values = geode.AttributeValuesDouble()
second_values.default_value = 1
second_values.no_value = 1
attribute_id = (
grid.grid_vertex_attribute_manager().create_attribute_variable_double(
"toto_vertex", 1,geode.AttributeProperties()
"toto_vertex", second_values,properties
)
)
attribute = grid.grid_vertex_attribute_manager().find_attribute_variable_double(
Expand All @@ -318,8 +328,15 @@ def test_attribute_3d(grid):

def test_attribute_2d():
grid = mesh.LightRegularGrid2D(geom.Point2D([1.5, 0]), [5, 10], [1.0, 2.0])
properties = geode.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
first_values = geode.AttributeValuesDouble()
first_values.default_value = -1
first_values.no_value = -1
attribute_id = grid.cell_attribute_manager().create_attribute_variable_double(
"toto", -1,geode.AttributeProperties()
"toto", first_values,properties
)
attribute = grid.cell_attribute_manager().find_attribute_variable_double(attribute_id)
attribute.set_value(10, 10)
Expand All @@ -330,9 +347,12 @@ def test_attribute_2d():
raise ValueError("[Test] Wrong attribute value")
if attribute.value(grid.nb_cells() - 1) != -1:
raise ValueError("[Test] Wrong attribute value")
second_values = geode.AttributeValuesDouble()
second_values.default_value = 1
second_values.no_value = 1
attribute_id = (
grid.grid_vertex_attribute_manager().create_attribute_variable_double(
"toto_vertex", 1,geode.AttributeProperties()
"toto_vertex",second_values,properties
)
)
attribute = grid.grid_vertex_attribute_manager().find_attribute_variable_double(
Expand Down
9 changes: 8 additions & 1 deletion bindings/python/tests/mesh/test-py-point-set.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ def test_bounding_box(point_set):

def test_create_vertex_attribute(point_set):
manager = point_set.vertex_attribute_manager()
properties = opengeode_py_basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = opengeode_py_basic.AttributeValuesBool()
values.default_value = True
values.no_value = True
attribute_id = point_set.vertex_attribute_manager(
).create_attribute_constant_bool("test", True,opengeode_py_basic.AttributeProperties())
).create_attribute_constant_bool("test", values,properties)
attribute = manager.find_attribute_constant_bool(attribute_id)
if attribute.constant_value() != True:
raise ValueError("[Test] PointSet attribute value should be true")
Expand Down
9 changes: 8 additions & 1 deletion bindings/python/tests/mesh/test-py-polygonal-surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ def test_create_polygons(polygonal_surface, builder):


def test_create_edge_attribute(polygonal_surface):
properties = basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = basic.AttributeValuesUInt()
values.default_value = basic.NO_ID
values.no_value = basic.NO_ID
attribute_id = polygonal_surface.edges().edge_attribute_manager(
).create_attribute_variable_uint("test", basic.NO_ID,basic.AttributeProperties())
).create_attribute_variable_uint("test", values,properties)
attribute = polygonal_surface.edges().edge_attribute_manager(
).find_attribute_variable_uint(attribute_id)
for e in range(polygonal_surface.edges().nb_edges()):
Expand Down
18 changes: 16 additions & 2 deletions bindings/python/tests/mesh/test-py-polyhedral-solid.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,15 @@ def test_create_polyhedra(polyhedral_solid, builder):


def test_create_facet_attribute(polyhedral_solid):
properties = basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = basic.AttributeValuesUInt()
values.default_value = basic.NO_ID
values.no_value = basic.NO_ID
attribute_id = polyhedral_solid.facets().facet_attribute_manager(
).create_attribute_variable_uint("test", basic.NO_ID, basic.AttributeProperties())
).create_attribute_variable_uint("test", values, properties)
attribute = polyhedral_solid.facets().facet_attribute_manager(
).find_attribute_variable_uint(attribute_id)
for f in range(polyhedral_solid.facets().nb_facets()):
Expand All @@ -82,8 +89,15 @@ def test_create_facet_attribute(polyhedral_solid):


def test_create_edge_attribute(polyhedral_solid):
properties = basic.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
values = basic.AttributeValuesUInt()
values.default_value = basic.NO_ID
values.no_value = basic.NO_ID
attribute_id = polyhedral_solid.edges().edge_attribute_manager(
).create_attribute_variable_uint("test", basic.NO_ID, basic.AttributeProperties())
).create_attribute_variable_uint("test", values, properties)
attribute = polyhedral_solid.edges().edge_attribute_manager(
).find_attribute_variable_uint(attribute_id)
for e in range(polyhedral_solid.edges().nb_edges()):
Expand Down
14 changes: 12 additions & 2 deletions bindings/python/tests/mesh/test-py-regular-grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,27 @@ def test_closest_vertex(grid):
def test_clone(grid):
attribute_name = "int_attribute"
attribute_name_d = "double_attribute"
properties = geode.AttributeProperties()
properties.assignable = False
properties.interpolable = False
properties.transferable = True
int_values = geode.AttributeValuesInt()
int_values.default_value = 0
int_values.no_value = 0
attribute_id = (
grid.polyhedron_attribute_manager().create_attribute_variable_int(
attribute_name, 0,geode.AttributeProperties()
attribute_name, int_values, properties
)
)
attribute = grid.polyhedron_attribute_manager().find_attribute_variable_int(
attribute_id
)
double_values = geode.AttributeValuesDouble()
double_values.default_value = 0
double_values.no_value = 0
attribute_d_id = (
grid.vertex_attribute_manager().create_attribute_variable_double(
attribute_name_d, 0,geode.AttributeProperties()
attribute_name_d, double_values,properties
)
)
attribute_d = grid.vertex_attribute_manager().find_attribute_variable_double(
Expand Down
Loading
Loading