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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ list(APPEND SIMPLNX_GENERATED_HEADERS
# Generate Python-Bindings Supporting Files
set(SIMPLNX_GENERATED_PYTHON_HEADER ${SIMPLNX_GENERATED_HEADER_DIR}/SimplnxPython.hpp)
set(SIMPLNX_PYTHON_MODULE "simplnx")
configure_file(${simplnx_SOURCE_DIR}/wrapping/python/CxPybind/SimplnxPython.hpp.in ${SIMPLNX_GENERATED_PYTHON_HEADER})
configure_file(${simplnx_SOURCE_DIR}/wrapping/python/NxPybind/SimplnxPython.hpp.in ${SIMPLNX_GENERATED_PYTHON_HEADER})

list(APPEND SIMPLNX_GENERATED_HEADERS
${SIMPLNX_GENERATED_PYTHON_HEADER}
Expand Down
54 changes: 27 additions & 27 deletions scripts/generate_simpl_conversion_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def from_json(json_object):
stripped_uuid = json_object['uuid'].strip('{}')
return SIMPLFilterInfo(name=json_object['name'], uuid=stripped_uuid, parameters=parameters)

def create_filter_conversion(simpl_filter: SIMPLFilterInfo, complex_filter_name: str) -> List[str]:
def create_filter_conversion(simpl_filter: SIMPLFilterInfo, simplnx_filter_name: str) -> List[str]:
converter_code: List[str] = []
converter_code.append('\n')
converter_code.append('namespace\n')
Expand All @@ -44,7 +44,7 @@ def create_filter_conversion(simpl_filter: SIMPLFilterInfo, complex_filter_name:
converter_code.append('} // namespace SIMPL\n')
converter_code.append('} // namespace\n')
converter_code.append('\n')
converter_code.append(f'Result<Arguments> {complex_filter_name}::FromSIMPLJson(const nlohmann::json& json)\n')
converter_code.append(f'Result<Arguments> {simplnx_filter_name}::FromSIMPLJson(const nlohmann::json& json)\n')
converter_code.append('{\n')
converter_code.append(' Arguments args = CreateDataArrayFilter().getDefaultArguments();\n')
converter_code.append('\n')
Expand Down Expand Up @@ -136,14 +136,14 @@ def find_filter(mappings: Dict[str, Dict[str, str]], filter_uuid: str) -> Tuple[
return (plugin_name, plugin_mapping[filter_uuid])
raise RuntimeError(f'{filter_uuid} not found')

def get_filter_base_path(simplnx_source_dir: Path, plugin_name: str, complex_filter: str) -> Path:
return simplnx_source_dir / f'src/Plugins/{plugin_name}/src/{plugin_name}/Filters/{complex_filter}'
def get_filter_base_path(simplnx_source_dir: Path, plugin_name: str, simplnx_filter: str) -> Path:
return simplnx_source_dir / f'src/Plugins/{plugin_name}/src/{plugin_name}/Filters/{simplnx_filter}'

def get_filter_hpp_path(simplnx_source_dir: Path, plugin_name: str, complex_filter: str) -> Path:
return get_filter_base_path(simplnx_source_dir, plugin_name, complex_filter).with_suffix('.hpp')
def get_filter_hpp_path(simplnx_source_dir: Path, plugin_name: str, simplnx_filter: str) -> Path:
return get_filter_base_path(simplnx_source_dir, plugin_name, simplnx_filter).with_suffix('.hpp')

def get_filter_cpp_path(simplnx_source_dir: Path, plugin_name: str, complex_filter: str) -> Path:
return get_filter_base_path(simplnx_source_dir, plugin_name, complex_filter).with_suffix('.cpp')
def get_filter_cpp_path(simplnx_source_dir: Path, plugin_name: str, simplnx_filter: str) -> Path:
return get_filter_base_path(simplnx_source_dir, plugin_name, simplnx_filter).with_suffix('.cpp')

def read_simpl_json(path: Path) -> Dict[str, SIMPLFilterInfo]:
with open(path, 'r') as file:
Expand All @@ -162,44 +162,44 @@ def update_hpp_lines(lines: List[str]) -> None:
function_decl_lines = create_function_decl()
lines[last_parameter_key_index:last_parameter_key_index] = function_decl_lines

def update_cpp_lines(lines: List[str], simpl_filter_info: SIMPLFilterInfo, complex_filter_name: str) -> None:
def update_cpp_lines(lines: List[str], simpl_filter_info: SIMPLFilterInfo, simplnx_filter_name: str) -> None:
last_include_index = find_last_include(lines)

include_lines = create_includes()

lines[last_include_index:last_include_index] = include_lines

filter_conversion_lines = create_filter_conversion(simpl_filter_info, complex_filter_name)
filter_conversion_lines = create_filter_conversion(simpl_filter_info, simplnx_filter_name)

lines.extend(filter_conversion_lines)

def update_filter_hpp(complex_filter_path: Path) -> None:
with open(complex_filter_path, 'r') as input_file:
def update_filter_hpp(simplnx_filter_path: Path) -> None:
with open(simplnx_filter_path, 'r') as input_file:
lines = input_file.readlines()

update_hpp_lines(lines)

with open(complex_filter_path, 'w') as output_file:
with open(simplnx_filter_path, 'w') as output_file:
output_file.writelines(lines)

def update_filter_cpp(complex_filter_path: Path, simpl_filter_info: SIMPLFilterInfo, complex_filter_name: str) -> None:
with open(complex_filter_path, 'r') as input_file:
def update_filter_cpp(simplnx_filter_path: Path, simpl_filter_info: SIMPLFilterInfo, simplnx_filter_name: str) -> None:
with open(simplnx_filter_path, 'r') as input_file:
lines = input_file.readlines()

update_cpp_lines(lines, simpl_filter_info, complex_filter_name)
update_cpp_lines(lines, simpl_filter_info, simplnx_filter_name)

with open(complex_filter_path, 'w') as output_file:
with open(simplnx_filter_path, 'w') as output_file:
output_file.writelines(lines)

def update_mapping_lines(lines: List[str], simpl_uuid: str, complex_filter_name: str) -> None:
def update_mapping_lines(lines: List[str], simpl_uuid: str, simplnx_filter_name: str) -> None:
index = find_mapping_line(lines, simpl_uuid)
lines[index] = lines[index].replace('{}', f'&{complex_filter_name}::FromSIMPLJson')
lines[index] = lines[index].replace('{}', f'&{simplnx_filter_name}::FromSIMPLJson')

def update_mapping_file(mapping_file_path: Path, simpl_uuid: str, complex_filter_name: str) -> None:
def update_mapping_file(mapping_file_path: Path, simpl_uuid: str, simplnx_filter_name: str) -> None:
with open(mapping_file_path, 'r') as input_file:
lines = input_file.readlines()

update_mapping_lines(lines, simpl_uuid, complex_filter_name)
update_mapping_lines(lines, simpl_uuid, simplnx_filter_name)

with open(mapping_file_path, 'w') as output_file:
output_file.writelines(lines)
Expand All @@ -210,13 +210,13 @@ def generate_converter_code(simplnx_source_dir: Path, simpl_json_path: Path, sim
for simpl_filter_uuid in simpl_filters:
if simpl_filter_uuid not in simpl_filters_info:
raise RuntimeError(f'SIMPL filter json does not contain {simpl_filter_uuid}')
plugin_name, complex_filter_name = find_filter(mappings, simpl_filter_uuid)
plugin_name, simplnx_filter_name = find_filter(mappings, simpl_filter_uuid)
mapping_file_path = get_plugin_mapping_file_path_from_root_dir(simplnx_source_dir, plugin_name)
complex_filter_hpp_path = get_filter_hpp_path(simplnx_source_dir, plugin_name, complex_filter_name)
complex_filter_cpp_path = get_filter_cpp_path(simplnx_source_dir, plugin_name, complex_filter_name)
update_filter_hpp(complex_filter_hpp_path)
update_filter_cpp(complex_filter_cpp_path, simpl_filters_info[simpl_filter_uuid], complex_filter_name)
update_mapping_file(mapping_file_path, simpl_filter_uuid, complex_filter_name)
simplnx_filter_hpp_path = get_filter_hpp_path(simplnx_source_dir, plugin_name, simplnx_filter_name)
simplnx_filter_cpp_path = get_filter_cpp_path(simplnx_source_dir, plugin_name, simplnx_filter_name)
update_filter_hpp(simplnx_filter_hpp_path)
update_filter_cpp(simplnx_filter_cpp_path, simpl_filters_info[simpl_filter_uuid], simplnx_filter_name)
update_mapping_file(mapping_file_path, simpl_filter_uuid, simplnx_filter_name)

# e.g. python generate_simpl_conversion_code.py . --simpl-filters "53df5340-f632-598f-8a9b-802296b3a95c"
# simpl-json is assumed to be next to this file, but can be overriden
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <CxPybind/CxPybind.hpp>
#include <NxPybind/NxPybind.hpp>

#include "ITKImageProcessing/ITKImageProcessingFilterBinding.hpp"
#include "ITKImageProcessing/ITKImageProcessingPlugin.hpp"

using namespace nx::core;
using namespace nx::core::CxPybind;
using namespace nx::core::NxPybind;
namespace py = pybind11;

PYBIND11_MODULE(itkimageprocessing, mod)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <CxPybind/CxPybind.hpp>
#include <NxPybind/NxPybind.hpp>

#include <OrientationAnalysis/OrientationAnalysisPlugin.hpp>

Expand All @@ -8,7 +8,7 @@
#include "OrientationAnalysis/OrientationAnalysisFilterBinding.hpp"

using namespace nx::core;
using namespace nx::core::CxPybind;
using namespace nx::core::NxPybind;
namespace py = pybind11;

using namespace pybind11::literals;
Expand Down
19 changes: 17 additions & 2 deletions src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <CxPybind/CxPybind.hpp>
#include <NxPybind/NxPybind.hpp>

#include <pybind11/pybind11.h>

Expand Down Expand Up @@ -92,7 +92,7 @@
#include <filesystem>

using namespace nx::core;
using namespace nx::core::CxPybind;
using namespace nx::core::NxPybind;

namespace py = pybind11;
namespace fs = std::filesystem;
Expand Down Expand Up @@ -1638,6 +1638,21 @@ PYBIND11_MODULE(simplnx, mod)
"set_args", [internals](PipelineFilter& self, py::dict& args) { self.setArguments(ConvertDictToArgs(*internals, self.getParameters(), args)); }, "args"_a);
pipelineFilter.def(
"get_filter", [](PipelineFilter& self) { return self.getFilter(); }, py::return_value_policy::reference_internal);
pipelineFilter.def(
"get_parameter_uuids",
[](const PipelineFilter& self) {
py::dict uuidDict;
const Parameters& params = self.getParameters();
for(const auto& [name, value] : self.getArguments())
{
if(params.contains(name))
{
uuidDict[name.c_str()] = params.at(name).getRef().uuid().str();
}
}
return uuidDict;
},
"Returns a dict mapping argument names to their parameter type UUID strings");
pipelineFilter.def(
"name",
[](const PipelineFilter& self) {
Expand Down
23 changes: 18 additions & 5 deletions wrapping/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
find_package(pybind11 2.10.0 CONFIG REQUIRED)

add_library(CxPybind INTERFACE)
add_library(NxPybind INTERFACE)

target_include_directories(CxPybind INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/CxPybind)
target_include_directories(NxPybind INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/NxPybind)

target_link_libraries(CxPybind
target_link_libraries(NxPybind
INTERFACE
simplnx
pybind11::headers
Expand Down Expand Up @@ -56,7 +56,7 @@ endif()
target_link_libraries(simplnxpy
PUBLIC
SimplnxCore
CxPybind
NxPybind
)

target_compile_options(simplnxpy
Expand Down Expand Up @@ -199,13 +199,26 @@ if(SIMPLNX_PY_ENABLE_INSTALL)
LIBRARY
DESTINATION ${SIMPLNX_PY_INSTALL_DIR}
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/utils/simplnx_utilities.py
DESTINATION ${SIMPLNX_PY_INSTALL_DIR}
)
Comment on lines +202 to +204
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should make sure this is good for conda builds.

if(SIMPLNX_PY_GENERATE_PYI)
install(FILES $<TARGET_FILE_DIR:simplnx>/simplnx.pyi
DESTINATION ${SIMPLNX_PY_INSTALL_DIR}
)
endif()
endif()

#-------------------------------------------------------------------------------
# Copy the Pipeline to Python Code utilities at build time
#-------------------------------------------------------------------------------
add_custom_target(CopySimplnxUtilities ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/utils/simplnx_utilities.py"
"$<TARGET_FILE_DIR:simplnx>/simplnx_utilities.py"
COMMENT "Copying simplnx_utilities.py to build output"
)


#-------------------------------------------------------------------------------
# FUNCTION: simplnx_add_python_plugin
Expand Down Expand Up @@ -236,7 +249,7 @@ function(simplnx_add_python_plugin)
target_link_libraries(${PYTHON_MODULE_NAME}
PUBLIC
${ARGS_PLUGIN_NAME}
CxPybind
NxPybind
)

target_compile_definitions(${PYTHON_MODULE_NAME} PUBLIC PYBIND11_DETAILED_ERROR_MESSAGES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define SIMPLNX_PY_BIND_CLASS_VARIADIC(scope, className, ...) pybind11::class_<className, __VA_ARGS__>(scope, #className)
#define SIMPLNX_PY_BIND_PARAMETER(scope, className) SIMPLNX_PY_BIND_CLASS_VARIADIC(scope, className, nx::core::IParameter)

namespace nx::core::CxPybind
namespace nx::core::NxPybind
{
namespace py = pybind11;

Expand Down Expand Up @@ -751,4 +751,4 @@ void BindParameterConstructor(py::class_<T, Options...>& object)

object.def(py::init<const std::string&, const std::string&, const std::string&, const typename T::ValueType&>(), "name"_a, "human_name"_a, "help_text"_a, "default_value"_a);
}
} // namespace nx::core::CxPybind
} // namespace nx::core::NxPybind
2 changes: 1 addition & 1 deletion wrapping/python/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ are developing new python bindings for `simplnx`.

- cmake
This directory holds various files used by CMake during the configuration of the python bindings
- CxPybind
- NxPybind
This directory holds C++ implementation details for the python bindings
- docs
This directory holds the entirety of the python binding documentation
Expand Down
4 changes: 2 additions & 2 deletions wrapping/python/cmake/FilterBinding.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace nx::core::@PLUGIN_NAME@
{
void BindFilters(pybind11::handle scope, const nx::core::CxPybind::Internals& internals)
void BindFilters(pybind11::handle scope, const nx::core::NxPybind::Internals& internals)
{
using namespace CxPybind;
using namespace NxPybind;
@FILTER_BINDING_CODE@
}
} // namespace nx::core
4 changes: 2 additions & 2 deletions wrapping/python/cmake/FilterBinding.hpp.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "CxPybind/CxPybind.hpp"
#include "NxPybind/NxPybind.hpp"

namespace nx::core::@PLUGIN_NAME@
{
void BindFilters(pybind11::handle scope, const nx::core::CxPybind::Internals& internals);
void BindFilters(pybind11::handle scope, const nx::core::NxPybind::Internals& internals);
} // namespace nx::core
4 changes: 2 additions & 2 deletions wrapping/python/examples/notebooks/angle_conversion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"# Import the DREAM3D Base library and Plugins\n",
"import simplnx as nx\n",
"\n",
"import orientationanalysis as cxor\n",
"import orientationanalysis as nxor\n",
"\n",
"import numpy as np"
]
Expand Down Expand Up @@ -85,7 +85,7 @@
"outputs": [],
"source": [
"quat_path = nx.DataPath(['Quaternions'])\n",
"result = cxor.ConvertOrientations.execute(data_structure=data_structure,\n",
"result = nxor.ConvertOrientations.execute(data_structure=data_structure,\n",
" input_orientation_array_path=array_path,\n",
" input_type=0,\n",
" output_orientation_array_name='Quaternions',\n",
Expand Down
14 changes: 7 additions & 7 deletions wrapping/python/examples/notebooks/basic_ebsd_ipf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"# Import the DREAM3D Base library and Plugins\n",
"import simplnx as nx\n",
"\n",
"import itkimageprocessing as cxitk\n",
"import orientationanalysis as cxor\n",
"import itkimageprocessing as nxitk\n",
"import orientationanalysis as nxor\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
Expand Down Expand Up @@ -46,7 +46,7 @@
"metadata": {},
"outputs": [],
"source": [
"result = cxor.ReadAngDataFilter.execute(data_structure=data_structure,\n",
"result = nxor.ReadAngDataFilter.execute(data_structure=data_structure,\n",
" cell_attribute_matrix_name='Scan Data',\n",
" cell_ensemble_attribute_matrix_name='Phase Data',\n",
" data_container_name=.nxDataPath(['Small IN100']),\n",
Expand All @@ -72,7 +72,7 @@
"metadata": {},
"outputs": [],
"source": [
"result = cxor.RotateEulerRefFrameFilter.execute(data_structure=data_structure,\n",
"result = nxor.RotateEulerRefFrameFilter.execute(data_structure=data_structure,\n",
" cell_euler_angles_array_path=.nxDataPath(['Small IN100', 'Scan Data', 'EulerAngles']),\n",
" rotation_axis=[0, 0, 1, 90],\n",
")\n",
Expand Down Expand Up @@ -165,7 +165,7 @@
"metadata": {},
"outputs": [],
"source": [
"result = cxor.ComputeIPFColorsFilter.execute(data_structure=data_structure,\n",
"result = nxor.ComputeIPFColorsFilter.execute(data_structure=data_structure,\n",
" cell_euler_angles_array_path=.nxDataPath(['Small IN100', 'Scan Data', 'EulerAngles']),\n",
" cell_ipf_colors_array_name='IPFColors',\n",
" cell_phases_array_path=.nxDataPath(['Small IN100', 'Scan Data', 'Phases']),\n",
Expand Down Expand Up @@ -194,7 +194,7 @@
"metadata": {},
"outputs": [],
"source": [
"result = cxitk.ITKImageWriter.execute(data_structure=data_structure, file_name='/tmp/Small_IN100_IPF_Z.png',\n",
"result = nxitk.ITKImageWriter.execute(data_structure=data_structure, file_name='/tmp/Small_IN100_IPF_Z.png',\n",
" image_array_path=.nxDataPath(['Small IN100', 'Scan Data', 'IPFColors']),\n",
" input_image_geometry_path=.nxDataPath(['Small IN100']),\n",
" index_offset=0,\n",
Expand Down Expand Up @@ -248,7 +248,7 @@
"outputs": [],
"source": [
"prefix = 'Small_IN100_'\n",
"result = cxor.WritePoleFigureFilter.execute(data_structure=data_structure,\n",
"result = nxor.WritePoleFigureFilter.execute(data_structure=data_structure,\n",
" cell_euler_angles_array_path=.nxDataPath(['Small IN100', 'Scan Data', 'EulerAngles']),\n",
" cell_phases_array_path=.nxDataPath(['Small IN100', 'Scan Data', 'Phases']),\n",
" crystal_structures_array_path=.nxDataPath(['Small IN100', 'Phase Data', 'CrystalStructures']),\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import simplnx as nx

import itkimageprocessing as cxitk
import orientationanalysis as cxor
import itkimageprocessing as nxitk
import orientationanalysis as nxor
import simplnx_test_dirs as nxtest

import numpy as np
Expand All @@ -24,7 +24,7 @@
generated_file_list_value.padding_digits = 2

# Instantiate Filter
nx_filter = cxitk.ITKImportImageStackFilter()
nx_filter = nxitk.ITKImportImageStackFilter()
# Execute Filter with Parameters
result = nx_filter.execute(
data_structure=data_structure,
Expand Down
Loading
Loading