|
30 | 30 |
|
31 | 31 | #include <geode/mesh/core/light_regular_grid.hpp> |
32 | 32 |
|
33 | | -#define PYTHON_LIGHT_REGULAR_GRID( dimension ) \ |
34 | | - const auto name##dimension = \ |
35 | | - "LightRegularGrid" + std::to_string( dimension ) + "D"; \ |
36 | | - pybind11::class_< LightRegularGrid##dimension##D, Grid##dimension##D, \ |
37 | | - Identifier >( module, name##dimension.c_str() ) \ |
38 | | - .def( pybind11::init< Point< dimension >, \ |
39 | | - std::array< index_t, dimension >, \ |
40 | | - std::array< double, dimension > >() ) \ |
41 | | - .def( pybind11::init< Point< dimension >, \ |
42 | | - std::array< index_t, dimension >, \ |
43 | | - std::array< Vector< dimension >, dimension > >() ) \ |
44 | | - .def( "vertex_attribute_manager", \ |
45 | | - &Grid##dimension##D::grid_vertex_attribute_manager, \ |
46 | | - pybind11::return_value_policy::reference ) \ |
47 | | - .def( "native_extension", \ |
48 | | - &LightRegularGrid##dimension##D::native_extension ) |
| 33 | +namespace |
| 34 | +{ |
| 35 | + template < geode::index_t dimension > |
| 36 | + void define_python_light_regular_grid( pybind11::module& module ) |
| 37 | + { |
| 38 | + const auto class_name = |
| 39 | + absl::StrCat( "LightRegularGrid", dimension, "D" ); |
| 40 | + pybind11::class_< geode::LightRegularGrid< dimension >, |
| 41 | + geode::Grid< dimension >, geode::Identifier >( |
| 42 | + module, class_name.c_str() ) |
| 43 | + .def( pybind11::init< geode::Point< dimension >, |
| 44 | + std::array< geode::index_t, dimension >, |
| 45 | + std::array< double, dimension > >() ) |
| 46 | + .def( pybind11::init< geode::Point< dimension >, |
| 47 | + std::array< geode::index_t, dimension >, |
| 48 | + std::array< geode::Vector< dimension >, dimension > >() ) |
| 49 | + .def( "vertex_attribute_manager", |
| 50 | + &geode::Grid< dimension >::grid_vertex_attribute_manager, |
| 51 | + pybind11::return_value_policy::reference ) |
| 52 | + .def( dimension == 2 ? "polygon_attribute_manager" |
| 53 | + : "polyhedron_attribute_manager", |
| 54 | + &geode::Grid< dimension >::cell_attribute_manager, |
| 55 | + pybind11::return_value_policy::reference ) |
| 56 | + .def( "native_extension", |
| 57 | + &geode::LightRegularGrid< dimension >::native_extension ); |
| 58 | + } |
| 59 | +} // namespace |
49 | 60 |
|
50 | 61 | namespace geode |
51 | 62 | { |
52 | 63 | void define_light_regular_grid( pybind11::module& module ) |
53 | 64 | { |
54 | | - PYTHON_LIGHT_REGULAR_GRID( 2 ); |
55 | | - PYTHON_LIGHT_REGULAR_GRID( 3 ); |
| 65 | + define_python_light_regular_grid< 2 >( module ); |
| 66 | + define_python_light_regular_grid< 3 >( module ); |
56 | 67 | } |
57 | 68 | } // namespace geode |
0 commit comments