Skip to content

Commit

Permalink
Add helper methods to be able to create all the geometries.
Browse files Browse the repository at this point in the history
Signed-off-by: Joey Kleingers <[email protected]>
  • Loading branch information
joeykleingers committed May 29, 2024
1 parent f867a30 commit 51557dc
Showing 1 changed file with 167 additions and 0 deletions.
167 changes: 167 additions & 0 deletions src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <pybind11/stl.h>
#include <pybind11/stl/filesystem.h>

#include "SimplnxCore/Filters/CreateGeometryFilter.hpp"
#include "SimplnxCore/SimplnxCoreFilterBinding.hpp"
#include "SimplnxCore/SimplnxCorePlugin.hpp"

Expand Down Expand Up @@ -1516,4 +1517,170 @@ PYBIND11_MODULE(simplnx, mod)
manualImportFinder.def("clear", &ManualImportFinder::clear);
manualImportFinder.def("contains_path", &ManualImportFinder::containsPath, "path"_a);
manualImportFinder.def("contains_module", &ManualImportFinder::containsModule, "mod_name"_a);

// Geometry Helper Methods
py::module_ sub = mod.def_submodule("ArrayHandlingType", "How existing arrays will be handled when creating the new geometry.");
sub.attr("CopyArray") = CreateGeometryFilter::k_CopyArray;
sub.attr("MoveArray") = CreateGeometryFilter::k_MoveArray;

mod.def(
"create_image_geometry",
[](DataStructure& ds, const DataPath& geometryPath, const std::vector<uint64>& dims, const std::vector<float32>& origin, const std::vector<float32>& spacing,
const std::string& cellAttrMatrixName) {
CreateGeometryFilter filter;
Arguments args;

args.insertOrAssign(CreateGeometryFilter::k_GeometryType_Key, std::make_any<ChoicesParameter::ValueType>(CreateGeometryFilter::k_ImageGeometry));
args.insertOrAssign(CreateGeometryFilter::k_GeometryPath_Key, std::make_any<DataPath>(geometryPath));
args.insertOrAssign(CreateGeometryFilter::k_Dimensions_Key, std::make_any<VectorUInt64Parameter::ValueType>(dims));
args.insertOrAssign(CreateGeometryFilter::k_Origin_Key, std::make_any<VectorFloat32Parameter::ValueType>(origin));
args.insertOrAssign(CreateGeometryFilter::k_Spacing_Key, std::make_any<VectorFloat32Parameter::ValueType>(spacing));
args.insertOrAssign(CreateGeometryFilter::k_CellAttributeMatrixName_Key, std::make_any<std::string>(cellAttrMatrixName));

IFilter::ExecuteResult executeResult = filter.execute(ds, args);
return executeResult.result;
},
"data_structure"_a, "geometry_path"_a, "dimensions"_a, "origin"_a, "spacing"_a, "cell_attr_matrix_name"_a = "Cell Data");

mod.def(
"create_rect_grid_geometry",
[](DataStructure& ds, const DataPath& geometryPath, const DataPath& xBoundsPath, const DataPath& yBoundsPath, const DataPath& zBoundsPath, const std::string& cellAttrMatrixName,
ChoicesParameter::ValueType arrayHandling) {
CreateGeometryFilter filter;
Arguments args;

args.insertOrAssign(CreateGeometryFilter::k_GeometryType_Key, std::make_any<ChoicesParameter::ValueType>(CreateGeometryFilter::k_RectGridGeometry));
args.insertOrAssign(CreateGeometryFilter::k_GeometryPath_Key, std::make_any<DataPath>(geometryPath));
args.insertOrAssign(CreateGeometryFilter::k_XBoundsPath_Key, std::make_any<DataPath>(xBoundsPath));
args.insertOrAssign(CreateGeometryFilter::k_YBoundsPath_Key, std::make_any<DataPath>(yBoundsPath));
args.insertOrAssign(CreateGeometryFilter::k_ZBoundsPath_Key, std::make_any<DataPath>(zBoundsPath));
args.insertOrAssign(CreateGeometryFilter::k_CellAttributeMatrixName_Key, std::make_any<std::string>(cellAttrMatrixName));
args.insertOrAssign(CreateGeometryFilter::k_ArrayHandling_Key, std::make_any<ChoicesParameter::ValueType>(arrayHandling));

IFilter::ExecuteResult executeResult = filter.execute(ds, args);
return executeResult.result;
},
"data_structure"_a, "geometry_path"_a, "x_bounds_path"_a, "y_bounds_path"_a, "z_bounds_path"_a, "cell_attr_matrix_name"_a = "Cell Data", "array_handling"_a = CreateGeometryFilter::k_CopyArray);

mod.def(
"create_vertex_geometry",
[](DataStructure& ds, const DataPath& geometryPath, const DataPath& verticesPath, const std::string& vertexAttrMatrixName, ChoicesParameter::ValueType arrayHandling) {
CreateGeometryFilter filter;
Arguments args;

args.insertOrAssign(CreateGeometryFilter::k_GeometryType_Key, std::make_any<ChoicesParameter::ValueType>(CreateGeometryFilter::k_VertexGeometry));
args.insertOrAssign(CreateGeometryFilter::k_GeometryPath_Key, std::make_any<DataPath>(geometryPath));
args.insertOrAssign(CreateGeometryFilter::k_ArrayHandling_Key, std::make_any<ChoicesParameter::ValueType>(arrayHandling));
args.insertOrAssign(CreateGeometryFilter::k_VertexListPath_Key, std::make_any<DataPath>(verticesPath));
args.insertOrAssign(CreateGeometryFilter::k_VertexAttributeMatrixName_Key, std::make_any<std::string>(vertexAttrMatrixName));

IFilter::ExecuteResult executeResult = filter.execute(ds, args);
return executeResult.result;
},
"data_structure"_a, "geometry_path"_a, "vertices_path"_a, "vertex_attr_matrix_name"_a = "Vertex Data", "array_handling"_a = CreateGeometryFilter::k_CopyArray);

mod.def(
"create_edge_geometry",
[](DataStructure& ds, const DataPath& geometryPath, const DataPath& verticesPath, const DataPath& edgeListPath, const std::string& vertexAttrMatrixName, const std::string& edgeAttrMatrixName,
ChoicesParameter::ValueType arrayHandling) {
CreateGeometryFilter filter;
Arguments args;

args.insertOrAssign(CreateGeometryFilter::k_GeometryType_Key, std::make_any<ChoicesParameter::ValueType>(CreateGeometryFilter::k_EdgeGeometry));
args.insertOrAssign(CreateGeometryFilter::k_GeometryPath_Key, std::make_any<DataPath>(geometryPath));
args.insertOrAssign(CreateGeometryFilter::k_ArrayHandling_Key, std::make_any<ChoicesParameter::ValueType>(arrayHandling));
args.insertOrAssign(CreateGeometryFilter::k_VertexListPath_Key, std::make_any<DataPath>(verticesPath));
args.insertOrAssign(CreateGeometryFilter::k_VertexAttributeMatrixName_Key, std::make_any<std::string>(vertexAttrMatrixName));
args.insertOrAssign(CreateGeometryFilter::k_EdgeListPath_Key, std::make_any<DataPath>(edgeListPath));
args.insertOrAssign(CreateGeometryFilter::k_EdgeAttributeMatrixName_Key, std::make_any<std::string>(edgeAttrMatrixName));

IFilter::ExecuteResult executeResult = filter.execute(ds, args);
return executeResult.result;
},
"data_structure"_a, "geometry_path"_a, "vertices_path"_a, "edge_list_path"_a, "vertex_attr_matrix_name"_a = "Vertex Data", "edge_attr_matrix_name"_a = "Edge Data",
"array_handling"_a = CreateGeometryFilter::k_CopyArray);

mod.def(
"create_triangle_geometry",
[](DataStructure& ds, const DataPath& geometryPath, const DataPath& verticesPath, const DataPath& triangleListPath, const std::string& vertexAttrMatrixName,
const std::string& faceAttrMatrixName, ChoicesParameter::ValueType arrayHandling) {
CreateGeometryFilter filter;
Arguments args;

args.insertOrAssign(CreateGeometryFilter::k_GeometryType_Key, std::make_any<ChoicesParameter::ValueType>(CreateGeometryFilter::k_TriangleGeometry));
args.insertOrAssign(CreateGeometryFilter::k_GeometryPath_Key, std::make_any<DataPath>(geometryPath));
args.insertOrAssign(CreateGeometryFilter::k_ArrayHandling_Key, std::make_any<ChoicesParameter::ValueType>(arrayHandling));
args.insertOrAssign(CreateGeometryFilter::k_VertexListPath_Key, std::make_any<DataPath>(verticesPath));
args.insertOrAssign(CreateGeometryFilter::k_VertexAttributeMatrixName_Key, std::make_any<std::string>(vertexAttrMatrixName));
args.insertOrAssign(CreateGeometryFilter::k_TriangleListPath_Key, std::make_any<DataPath>(triangleListPath));
args.insertOrAssign(CreateGeometryFilter::k_FaceAttributeMatrixName_Key, std::make_any<std::string>(faceAttrMatrixName));

IFilter::ExecuteResult executeResult = filter.execute(ds, args);
return executeResult.result;
},
"data_structure"_a, "geometry_path"_a, "vertices_path"_a, "triangle_list_path"_a, "vertex_attr_matrix_name"_a = "Vertex Data", "face_attr_matrix_name"_a = "Face Data",
"array_handling"_a = CreateGeometryFilter::k_CopyArray);

mod.def(
"create_quad_geometry",
[](DataStructure& ds, const DataPath& geometryPath, const DataPath& verticesPath, const DataPath& quadListPath, const std::string& vertexAttrMatrixName, const std::string& faceAttrMatrixName,
ChoicesParameter::ValueType arrayHandling) {
CreateGeometryFilter filter;
Arguments args;

args.insertOrAssign(CreateGeometryFilter::k_GeometryType_Key, std::make_any<ChoicesParameter::ValueType>(CreateGeometryFilter::k_QuadGeometry));
args.insertOrAssign(CreateGeometryFilter::k_GeometryPath_Key, std::make_any<DataPath>(geometryPath));
args.insertOrAssign(CreateGeometryFilter::k_ArrayHandling_Key, std::make_any<ChoicesParameter::ValueType>(arrayHandling));
args.insertOrAssign(CreateGeometryFilter::k_VertexListPath_Key, std::make_any<DataPath>(verticesPath));
args.insertOrAssign(CreateGeometryFilter::k_VertexAttributeMatrixName_Key, std::make_any<std::string>(vertexAttrMatrixName));
args.insertOrAssign(CreateGeometryFilter::k_QuadrilateralListPath_Key, std::make_any<DataPath>(quadListPath));
args.insertOrAssign(CreateGeometryFilter::k_FaceAttributeMatrixName_Key, std::make_any<std::string>(faceAttrMatrixName));

IFilter::ExecuteResult executeResult = filter.execute(ds, args);
return executeResult.result;
},
"data_structure"_a, "geometry_path"_a, "vertices_path"_a, "quad_list_path"_a, "vertex_attr_matrix_name"_a = "Vertex Data", "face_attr_matrix_name"_a = "Quad Data",
"array_handling"_a = CreateGeometryFilter::k_CopyArray);

mod.def(
"create_tetrahedral_geometry",
[](DataStructure& ds, const DataPath& geometryPath, const DataPath& verticesPath, const DataPath& tetrahedralListPath, const std::string& vertexAttrMatrixName,
const std::string& cellAttrMatrixName, ChoicesParameter::ValueType arrayHandling) {
CreateGeometryFilter filter;
Arguments args;

args.insertOrAssign(CreateGeometryFilter::k_GeometryType_Key, std::make_any<ChoicesParameter::ValueType>(CreateGeometryFilter::k_TetGeometry));
args.insertOrAssign(CreateGeometryFilter::k_GeometryPath_Key, std::make_any<DataPath>(geometryPath));
args.insertOrAssign(CreateGeometryFilter::k_ArrayHandling_Key, std::make_any<ChoicesParameter::ValueType>(arrayHandling));
args.insertOrAssign(CreateGeometryFilter::k_VertexListPath_Key, std::make_any<DataPath>(verticesPath));
args.insertOrAssign(CreateGeometryFilter::k_VertexAttributeMatrixName_Key, std::make_any<std::string>(vertexAttrMatrixName));
args.insertOrAssign(CreateGeometryFilter::k_TetrahedralListPath_Key, std::make_any<DataPath>(tetrahedralListPath));
args.insertOrAssign(CreateGeometryFilter::k_CellAttributeMatrixName_Key, std::make_any<std::string>(cellAttrMatrixName));

IFilter::ExecuteResult executeResult = filter.execute(ds, args);
return executeResult.result;
},
"data_structure"_a, "geometry_path"_a, "vertices_path"_a, "tetrahedral_list_path"_a, "vertex_attr_matrix_name"_a = "Vertex Data", "cell_attr_matrix_name"_a = "Cell Data",
"array_handling"_a = CreateGeometryFilter::k_CopyArray);

mod.def(
"create_hexahedral_geometry",
[](DataStructure& ds, const DataPath& geometryPath, const DataPath& verticesPath, const DataPath& hexahedralListPath, const std::string& vertexAttrMatrixName,
const std::string& cellAttrMatrixName, ChoicesParameter::ValueType arrayHandling) {
CreateGeometryFilter filter;
Arguments args;

args.insertOrAssign(CreateGeometryFilter::k_GeometryType_Key, std::make_any<ChoicesParameter::ValueType>(CreateGeometryFilter::k_HexGeometry));
args.insertOrAssign(CreateGeometryFilter::k_GeometryPath_Key, std::make_any<DataPath>(geometryPath));
args.insertOrAssign(CreateGeometryFilter::k_ArrayHandling_Key, std::make_any<ChoicesParameter::ValueType>(arrayHandling));
args.insertOrAssign(CreateGeometryFilter::k_VertexListPath_Key, std::make_any<DataPath>(verticesPath));
args.insertOrAssign(CreateGeometryFilter::k_VertexAttributeMatrixName_Key, std::make_any<std::string>(vertexAttrMatrixName));
args.insertOrAssign(CreateGeometryFilter::k_HexahedralListPath_Key, std::make_any<DataPath>(hexahedralListPath));
args.insertOrAssign(CreateGeometryFilter::k_CellAttributeMatrixName_Key, std::make_any<std::string>(cellAttrMatrixName));

IFilter::ExecuteResult executeResult = filter.execute(ds, args);
return executeResult.result;
},
"data_structure"_a, "geometry_path"_a, "vertices_path"_a, "hexahedral_list_path"_a, "vertex_attr_matrix_name"_a = "Vertex Data", "cell_attr_matrix_name"_a = "Cell Data",
"array_handling"_a = CreateGeometryFilter::k_CopyArray);
}

0 comments on commit 51557dc

Please sign in to comment.