|
25 | 25 | #include <simplnx/DataStructure/Geometry/TetrahedralGeom.hpp>
|
26 | 26 | #include <simplnx/DataStructure/Geometry/TriangleGeom.hpp>
|
27 | 27 | #include <simplnx/DataStructure/Geometry/VertexGeom.hpp>
|
| 28 | +#include <simplnx/DataStructure/NeighborList.hpp> |
28 | 29 | #include <simplnx/DataStructure/StringArray.hpp>
|
29 | 30 | #include <simplnx/Filter/Actions/CopyArrayInstanceAction.hpp>
|
30 | 31 | #include <simplnx/Filter/Actions/CopyDataObjectAction.hpp>
|
@@ -209,6 +210,35 @@ auto BindDataArray(py::handle scope, const char* name)
|
209 | 210 | #define SIMPLNX_PY_BIND_DATA_STORE(scope, className) BindDataStore<className::value_type>(scope, #className)
|
210 | 211 | #define SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(scope, className) SIMPLNX_PY_BIND_CLASS_VARIADIC(scope, className, IDataStore, std::shared_ptr<className>)
|
211 | 212 |
|
| 213 | +template <class T> |
| 214 | +auto BindNeighborList(py::handle scope, const char* name) |
| 215 | +{ |
| 216 | + using NeighborListType = NeighborList<T>; |
| 217 | + |
| 218 | + auto neighborList = py::class_<NeighborListType, INeighborList, std::shared_ptr<NeighborListType>>(scope, name); |
| 219 | + neighborList.def_property_readonly_static("dtype", []([[maybe_unused]] py::object self) { return py::dtype::of<T>(); }); |
| 220 | + neighborList.def("get_list", &NeighborListType::getList, "grain_id"_a); |
| 221 | + neighborList.def("set_list", py::overload_cast<int32, const typename NeighborListType::VectorType&>(&NeighborListType::setList), "grain_id"_a, "neighbor_list"_a); |
| 222 | + neighborList.def( |
| 223 | + "get_value", |
| 224 | + [](const NeighborListType& self, int32 grainId, int32 index) { |
| 225 | + bool ok = false; |
| 226 | + int32 value = self.getValue(grainId, index, ok); |
| 227 | + if(!ok) |
| 228 | + { |
| 229 | + throw std::out_of_range(fmt::format("NeighborList.get_value called with grain_id = {} and index = {} which was out of range", grainId, index)); |
| 230 | + } |
| 231 | + return value; |
| 232 | + }, |
| 233 | + "grain_id"_a, "index"_a); |
| 234 | + neighborList.def("add_entry", &NeighborListType::addEntry, "grain_id"_a, "value"_a); |
| 235 | + neighborList.def("get_list_size", &NeighborListType::getListSize, "grain_id"_a); |
| 236 | + neighborList.def("get_number_of_lists", &NeighborListType::getNumberOfLists); |
| 237 | + return neighborList; |
| 238 | +} |
| 239 | + |
| 240 | +#define SIMPLNX_PY_BIND_NEIGHBOR_LIST(scope, className) BindNeighborList<className::value_type>(scope, #className) |
| 241 | + |
212 | 242 | template <class GeomT>
|
213 | 243 | auto BindCreateGeometry2DAction(py::handle scope, const char* name)
|
214 | 244 | {
|
@@ -1026,6 +1056,19 @@ PYBIND11_MODULE(simplnx, mod)
|
1026 | 1056 | stringArray.def_property_readonly("values", &StringArray::values);
|
1027 | 1057 | stringArray.def("resize_tuples", &StringArray::resizeTuples, "Resize the tuples with the given shape");
|
1028 | 1058 |
|
| 1059 | + auto iNeighborList = py::class_<INeighborList, IArray, std::shared_ptr<INeighborList>>(mod, "INeighborList"); |
| 1060 | + |
| 1061 | + auto neighborListInt8 = SIMPLNX_PY_BIND_NEIGHBOR_LIST(mod, Int8NeighborList); |
| 1062 | + auto neighborListUInt8 = SIMPLNX_PY_BIND_NEIGHBOR_LIST(mod, UInt8NeighborList); |
| 1063 | + auto neighborListInt16 = SIMPLNX_PY_BIND_NEIGHBOR_LIST(mod, Int16NeighborList); |
| 1064 | + auto neighborListUInt16 = SIMPLNX_PY_BIND_NEIGHBOR_LIST(mod, UInt16NeighborList); |
| 1065 | + auto neighborListInt32 = SIMPLNX_PY_BIND_NEIGHBOR_LIST(mod, Int32NeighborList); |
| 1066 | + auto neighborListUInt32 = SIMPLNX_PY_BIND_NEIGHBOR_LIST(mod, UInt32NeighborList); |
| 1067 | + auto neighborListInt64 = SIMPLNX_PY_BIND_NEIGHBOR_LIST(mod, Int64NeighborList); |
| 1068 | + auto neighborListUInt64 = SIMPLNX_PY_BIND_NEIGHBOR_LIST(mod, UInt64NeighborList); |
| 1069 | + auto neighborListFloat32 = SIMPLNX_PY_BIND_NEIGHBOR_LIST(mod, Float32NeighborList); |
| 1070 | + auto neighborListFloat64 = SIMPLNX_PY_BIND_NEIGHBOR_LIST(mod, Float64NeighborList); |
| 1071 | + |
1029 | 1072 | auto dataArrayInt8 = SIMPLNX_PY_BIND_DATA_ARRAY(mod, Int8Array);
|
1030 | 1073 | auto dataArrayUInt8 = SIMPLNX_PY_BIND_DATA_ARRAY(mod, UInt8Array);
|
1031 | 1074 | auto dataArrayInt16 = SIMPLNX_PY_BIND_DATA_ARRAY(mod, Int16Array);
|
|
0 commit comments