diff --git a/.gitlab/ci/configure_fedora41_paraview.cmake b/.gitlab/ci/configure_fedora41_paraview.cmake index 68cce9431610d580e7f505e6eaa8a0feaca8e0e8..bc056e5cc994896e993c873aaad42161b3957671 100644 --- a/.gitlab/ci/configure_fedora41_paraview.cmake +++ b/.gitlab/ci/configure_fedora41_paraview.cmake @@ -1,15 +1,12 @@ set(SMTK_PLUGIN_CONTRACT_FILE_URLS - "https://gitlab.kitware.com/cmb/plugins/openfoam-windtunnel/-/raw/master/cmake/openfoam-windtunnel.cmake" + # Disabled until importing into smtk::mesh can be replaced with another resource type. + # "https://gitlab.kitware.com/cmb/plugins/openfoam-windtunnel/-/raw/master/cmake/openfoam-windtunnel.cmake" "https://gitlab.kitware.com/cmb/plugins/opencascade-session/-/raw/master/cmake/opencascade-smtk-contract.cmake" - "https://gitlab.kitware.com/cmb/plugins/adh-extensions/-/raw/master/CMake/adh-extensions.cmake" - "https://gitlab.kitware.com/cmb/plugins/rgg-session/-/raw/master/CMake/rgg-session.cmake" # https://gitlab.kitware.com/cmb/smtk/-/issues/543 # "https://gitlab.kitware.com/cmb/plugins/truchas-extensions/-/raw/master/CMake/truchas-extensions.cmake" "https://gitlab.kitware.com/cmb/cmb/-/raw/master/cmake/cmb.cmake" # https://gitlab.kitware.com/cmb/smtk/-/issues/543 # "https://gitlab.kitware.com/cmb/plugins/ace3p-extensions/-/raw/master/CMake/ace3p-extensions.cmake" - "https://gitlab.kitware.com/cmb/plugins/xmsmeshoperation/-/raw/master/CMake/xms-mesh-operation.cmake" - "https://gitlab.kitware.com/cmb/plugins/cmb-2d/-/raw/master/cmake/cmb-2d.cmake" CACHE STRING "") include("${CMAKE_CURRENT_LIST_DIR}/configure_fedora41.cmake") diff --git a/.gitmodules b/.gitmodules index 9e0b580b0be984c1c1eaf57451cc3a071b2aa50d..19dbb924db4a0a4dcb282c41dabcb1fc71eed622 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ -[submodule "thirdparty/delaunay"] - path = thirdparty/delaunay - url = https://gitlab.kitware.com/cmb/delaunay.git - branch = for/smtk [submodule "data/simulation-workflows"] path = data/simulation-workflows url = https://gitlab.kitware.com/cmb/simulation-workflows.git diff --git a/CMake/Options.h.in b/CMake/Options.h.in index 87dd2e03bb8280be142c14326cd0a53f2452adf5..0e8ebd753a3a6b92151a6857f1134bc7fd799601 100644 --- a/CMake/Options.h.in +++ b/CMake/Options.h.in @@ -21,19 +21,12 @@ // Was SMTK built with the markup resource? If so, the smtkMarkup library will exist. #cmakedefine01 SMTK_ENABLE_MARKUP -// Was SMTK built with mesh session? If true, -// the SMTKMeshSession library will exist. -#cmakedefine SMTK_ENABLE_MESH_SESSION - // Was SMTK built with python bindings? #cmakedefine01 SMTK_ENABLE_PYTHON_WRAPPING // Was SMTK built with Qt? If true, smtkQtExt library will exist. #cmakedefine SMTK_ENABLE_QT_SUPPORT -// Was SMTK built with Remus? If true, smtkRemoteSession library will exist. -#cmakedefine SMTK_ENABLE_REMUS_SUPPORT - // Was SMTK built with VTK? If true, the smtkVTKExt library will exist. #cmakedefine SMTK_ENABLE_VTK_SUPPORT diff --git a/CMake/SMTKInstallCMakePackageHelpers.cmake b/CMake/SMTKInstallCMakePackageHelpers.cmake index 07814f47db0163080cd4b97190423eec39dab1b1..8458bb544e0f7718b11a722fbb88d9e3e454f41e 100644 --- a/CMake/SMTKInstallCMakePackageHelpers.cmake +++ b/CMake/SMTKInstallCMakePackageHelpers.cmake @@ -32,7 +32,6 @@ set(_smtk_packages nlohmann_json pegtl LibArchive - MOAB Qt5 ParaView Python3 diff --git a/CMake/SMTKTestingMacros.cmake b/CMake/SMTKTestingMacros.cmake index c5eaaf8bbb2876b46cf628e7df33aff4f4e64473..d613bdb8615e8bd7e168e125adf6ae181adbfdd7 100644 --- a/CMake/SMTKTestingMacros.cmake +++ b/CMake/SMTKTestingMacros.cmake @@ -42,7 +42,6 @@ function(smtk_unit_tests) target_include_directories(${test_prog} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} - ${MOAB_INCLUDE_DIRS} ${VTK_INCLUDE_DIRS} ) @@ -130,7 +129,6 @@ function(smtk_build_failure_tests) target_include_directories(${tname} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} - ${MOAB_INCLUDE_DIRS} ${VTK_INCLUDE_DIRS} ) add_test( diff --git a/CMake/smtkConfig.cmake.in b/CMake/smtkConfig.cmake.in index 130cbfe6888a7651dec2510f4696a6e72e28c42d..767218ddec569556cd70943e947f2dcf398a3d73 100644 --- a/CMake/smtkConfig.cmake.in +++ b/CMake/smtkConfig.cmake.in @@ -14,7 +14,6 @@ The following variables are provided by this module: * `SMTK_ENABLE_PYTHON_WRAPPING`: Whether Python wrapping is available or not. * `SMTK_PYTHONPATH`: The path to smtk python. * `SMTK_ENABLE_QT_SUPPORT`: Whether Qt support is available or not. - * `SMTK_ENABLE_REMUS_SUPPORT`: Whether Remus support is available or not. * `SMTK_ENABLE_VTK_SUPPORT`: Whether VTK support is available or not. #]==] @@ -40,7 +39,6 @@ set(SMTK_ENABLE_MARKUP "@SMTK_ENABLE_MARKUP@") set(SMTK_ENABLE_PARAVIEW_SUPPORT "@SMTK_ENABLE_PARAVIEW_SUPPORT@") set(SMTK_ENABLE_PYTHON_WRAPPING "@SMTK_ENABLE_PYTHON_WRAPPING@") set(SMTK_ENABLE_QT_SUPPORT "@SMTK_ENABLE_QT_SUPPORT@") -set(SMTK_ENABLE_REMUS_SUPPORT "@SMTK_ENABLE_REMUS_SUPPORT@") set(SMTK_ENABLE_VTK_SUPPORT "@SMTK_ENABLE_VTK_SUPPORT@") set(SMTK_USE_BOOST_REGEX "@SMTK_USE_BOOST_REGEX@") @@ -53,10 +51,6 @@ endif () # Required dependencies. -# Delaunay is always embedded. -set(Delaunay_DIR "${CMAKE_CURRENT_LIST_DIR}/Delaunay") -find_package(Delaunay REQUIRED ${_smtk_find_quietly}) - find_package(Boost EXACT "@Boost_MAJOR_VERSION@.@Boost_MINOR_VERSION@.@Boost_SUBMINOR_VERSION@" ${_smtk_find_quietly} @@ -110,13 +104,6 @@ if (NOT fmt_FOUND) set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0) endif () -find_package(MOAB ${_smtk_find_quietly}) -if (NOT MOAB_FOUND) - list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE" - "MOAB dependency not found") - set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0) -endif () - find_package(Threads ${_smtk_find_quietly}) if (NOT Threads_FOUND) list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE" @@ -189,15 +176,6 @@ if (SMTK_ENABLE_PARAVIEW_SUPPORT) include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewPlugins-paraview-plugin-properties.cmake") endif () -if (SMTK_ENABLE_REMUS_SUPPORT) - find_package(Remus ${_smtk_find_quietly}) - if (NOT Remus_FOUND) - list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE" - "Remus dependency not found") - set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0) - endif () -endif () - if (SMTK_ENABLE_PYTHON_WRAPPING) find_package(Python3 ${_smtk_find_quietly} COMPONENTS Development Interpreter) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae0988f4b3056b9aa70d440ce21a21a3ce82b2fc..93e704374ac5792980c842d4b686cc5e7942e9a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,7 +121,6 @@ cmake_dependent_option( SMTK_ENABLE_OPERATION_THREADS "Run operations in asynchronous threads" ON SMTK_ENABLE_QT_SUPPORT OFF) mark_as_advanced(SMTK_ENABLE_OPERATION_THREADS) option(SMTK_ENABLE_VTK_SUPPORT "Build VTK component" ON) -option(SMTK_ENABLE_REMUS_SUPPORT "Build Remus components" OFF) cmake_dependent_option(SMTK_ENABLE_PARAVIEW_SUPPORT "Build paraview plugins for model sessions" OFF "SMTK_ENABLE_VTK_SUPPORT;SMTK_ENABLE_QT_SUPPORT" OFF) @@ -206,19 +205,6 @@ if (SMTK_ENABLE_TESTING) endif() # -- contract-example -- - # Build an example application (Windows is not yet supported) - if (NOT WIN32) - if (SMTK_ENABLE_EXAMPLES AND SMTK_ENABLE_MESH_SESSION AND - SMTK_ENABLE_VTK_SUPPORT AND SMTK_ENABLE_QT_SUPPORT) - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/applications/ModelViewer/model-viewer.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/applications/ModelViewer/model-viewer.cmake" - @ONLY) - list(APPEND SMTK_PLUGIN_CONTRACT_FILE_URLS - "file://${CMAKE_CURRENT_BINARY_DIR}/applications/ModelViewer/model-viewer.cmake") - endif() - endif() - set(SMTK_COVERAGE_ENABLED OFF) if(SMTK_ENABLE_COVERAGE) set(SMTK_COVERAGE_ENABLED ON) @@ -369,15 +355,6 @@ find_package(units REQUIRED) ################################################################################ find_package(fmt REQUIRED) -################################################################################ -# Moab Related Settings -################################################################################ - -# Moab is required for building smtk::mesh, as it is the default storage -# format for meshes. -find_package(MOAB REQUIRED) - - ################################################################################ # Qt Related Settings ################################################################################ @@ -415,14 +392,6 @@ if(SMTK_ENABLE_VTK_SUPPORT AND NOT SMTK_ENABLE_PARAVIEW_SUPPORT) endif () endif() -################################################################################ -# Remus related settings -################################################################################ - -if (SMTK_ENABLE_REMUS_SUPPORT) - find_package(Remus REQUIRED) -endif() - ################################################################################ # Build utility executables ################################################################################ @@ -662,8 +631,7 @@ export(EXPORT ${PROJECT_NAME} FILE "${PROJECT_BINARY_DIR}/${SMTK_INSTALL_CONFIG_ # Create a build directory package configuration file # # Setup the config file for exports that stores what other thirdparty -# packages we need to search for ( MOAB, Remus, etc ) for when using the -# build version of smtk +# packages we need to search for when using the build version of smtk # # Required to happen before we include the docs directory @@ -696,8 +664,7 @@ configure_file( # Create an install package configuration file # # Setup the config file for exports that stores what other thirdparty -# packages we need to search for ( MOAB, Remus, etc ) for when using the -# install version of smtk +# packages we need to search for when using the install version of smtk # If we are performing a relocatable install, we must erase the hard-coded # install paths we set in smtk_prefix_path before constructing the install diff --git a/applications/ModelViewer/CMakeLists.txt b/applications/ModelViewer/CMakeLists.txt deleted file mode 100644 index 30ab84e18a11a1cdc36115ba2205fd127a669440..0000000000000000000000000000000000000000 --- a/applications/ModelViewer/CMakeLists.txt +++ /dev/null @@ -1,383 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -#----------------------------------------------------------------------------- -# Project name and version -project(ModelViewer VERSION 1.0) - -#----------------------------------------------------------------------------- -# Include GNU install directory module to detect where to install -# files on Linux/Unix systems (e.g., lib vs lib64) -include(GNUInstallDirs) - -#----------------------------------------------------------------------------- -# Find packages -find_package(smtk REQUIRED) - -if (NOT SMTK_ENABLE_VTK_SUPPORT) - message(FATAL_ERROR - "This project requires SMTK to be built with VTK support.") -endif() - -find_package(VTK REQUIRED COMPONENTS GUISupportQt) - -find_package(Qt5 REQUIRED COMPONENTS Core Gui Svg Widgets) - -#----------------------------------------------------------------------------- -# Build the executable -add_executable(ModelViewer MACOSX_BUNDLE - main.cxx - ModelViewer.cxx - ModelViewer.ui) - -target_link_libraries(ModelViewer - smtkCore - smtkMeshSession - smtkQtExt - vtkSMTKSourceExt - vtkSMTKMeshExt - VTK::CommonCore - VTK::CommonDataModel - VTK::InteractionStyle - VTK::RenderingCore - VTK::RenderingOpenGL2 - VTK::GUISupportQt - Qt5::Core - Qt5::Gui - Qt5::Svg - Qt5::Widgets -) - -vtk_module_autoinit( - TARGETS ModelViewer - MODULES VTK::CommonCore - VTK::CommonDataModel - VTK::InteractionStyle - VTK::RenderingCore - VTK::RenderingOpenGL2 - VTK::GUISupportQt -) - -set_target_properties( - ModelViewer PROPERTIES - AUTOMOC TRUE - AUTORCC TRUE - AUTOUIC TRUE - ) - -if (NOT DEFINED CMAKE_INSTALL_NAME_DIR) - set_target_properties(ModelViewer PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/bin") -endif () - -if (NOT CMAKE_INSTALL_RPATH_USE_LINK_PATH) - set_target_properties(ModelViewer PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) -endif() - -if (APPLE) - install(TARGETS ModelViewer DESTINATION . COMPONENT Runtime) -elseif(UNIX) - install(TARGETS ModelViewer COMPONENT Runtime) -endif() -#----------------------------------------------------------------------------- -# Set CPack variables -include(InstallRequiredSystemLibraries) -set(CPACK_PACKAGE_VERSION_MAJOR "${ModelViewer_VERSION_MAJOR}") -set(CPACK_PACKAGE_VERSION_MINOR "${ModelViewer_VERSION_MINOR}") -set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") -set(CPACK_PACKAGE_VENDOR Kitware) -set(CPACK_SOURCE_TBZ2 OFF) -set(CPACK_SOURCE_TGZ OFF) -set(CPACK_SOURCE_TZ OFF) - -if(UNIX) - set(CPACK_GENERATOR "TGZ") - if(APPLE) - set(CPACK_GENERATOR "DragNDrop") - endif() -elseif(WIN32) - set(CPACK_GENERATOR "NSIS") -endif() - -#----------------------------------------------------------------------------- -# Set variables for generating the install script -set(bundle ModelViewer) -set(plugin_dest_dir plugins) -set(lib_dest_dir lib) -set(qtconf_dest_dir bin) -set(exe_dest_dir bin) -set(suffix "${CMAKE_SHARED_LIBRARY_SUFFIX}") -set(lib_search_dirs) -set(ignore_items) -if(APPLE) - set(bundle "${bundle}.app") - set(plugin_dest_dir ${bundle}/Contents/Plugins) - set(lib_dest_dir ${bundle}/Contents/Libraries) - set(qtconf_dest_dir ${bundle}/Contents/Resources) - set(exe_dest_dir ${bundle}/Contents/MacOS) - if (SMTK_ENABLE_PYTHON_WRAPPING AND Python3_FOUND) - list(APPEND ignore_items - # When Python is enabled, the Python executables get added to the list of - # dependencies to package. We don't need them, so we ignore them - # explicitly. - Python - python${Python3_VERSION_MAJOR} - python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR} - ) - endif() -elseif(UNIX) - # For Linux + system Qt5, GET_RUNTIME_DEPENDENCIES has difficulty finding Qt5 - # libraries. We help it out by passing the directories in which these libraries - # can be found to the algorithm. - set(targets_to_find Qt5::Gui Qt5::Svg Qt5::Widgets) - - # For VTK-only builds (no ParaView), VTK is often built with kits enabled. - # VTK's Filters kit brings in VTK::FiltersVerdict, which depends on - # VTK::verdict. For some reason, GET_RUNTIME_DEPENDENCIES has difficulty - # finding VTK::verdict, so we add it here too. - list(APPEND targets_to_find VTK::verdict) - - foreach(target IN LISTS targets_to_find) - get_target_property(loc ${target} LOCATION) - get_filename_component(real_loc ${loc} REALPATH) - get_filename_component(dir ${real_loc} DIRECTORY) - list(APPEND lib_search_dirs ${dir}) - endforeach() -endif() - -#----------------------------------------------------------------------------- -# Add the plugins needed by the Qt frameworks used by the application -set(qt5_version "${Qt5Core_VERSION_MAJOR}.${Qt5Core_VERSION_MINOR}") - -set(qt_plugins - Qt5::QSvgIconPlugin - Qt5::QSvgPlugin - ) - -if (APPLE) - list(APPEND qt_plugins - Qt5::QCocoaIntegrationPlugin - Qt5::QCocoaPrinterSupportPlugin - ) - - if (NOT qt_version VERSION_LESS "5.10") - list(APPEND qt5_plugins - Qt5::QMacStylePlugin - ) - endif () -elseif (UNIX) - list(APPEND qt_plugins - Qt5::QXcbIntegrationPlugin - Qt5::QComposePlatformInputContextPlugin - Qt5::QXcbGlxIntegrationPlugin - ) -endif () - -foreach(plugin IN LISTS qt_plugins) - # Qt plugins are required to have the same directory structure as - # in their install tree, so we replicate it here. - get_target_property(loc ${plugin} LOCATION) - get_filename_component(dir ${loc} DIRECTORY) - get_filename_component(last_dir ${dir} NAME) - install(FILES "${loc}" DESTINATION "${plugin_dest_dir}/${last_dir}" COMPONENT Runtime) -endforeach() - -#----------------------------------------------------------------------------- -# For UNIX, some libraries may be system installed, but we still -# want them bundled. For example, LibXml2 is frequently installed as -# a system library. If this setup has system libraries that we want, -# bundled, the call to GET_RUNTIME_DEPENDENCIES below will omit them -# from them package. We therefore force their inclusion if they are -# available as system libraries. -if (UNIX AND NOT APPLE) - set(required_libs) - find_package(ZLIB QUIET) - find_package(LibXml2 QUIET) - - if (ZLIB_FOUND) - list(APPEND required_libs ZLIB::ZLIB) - endif() - if (LibXml2_FOUND) - list(APPEND required_libs LibXml2::LibXml2) - endif() - foreach(lib IN LISTS required_libs) - get_target_property(loc ${lib} LOCATION) - get_filename_component(real_loc ${loc} REALPATH) - get_filename_component(real_loc_wle ${real_loc} NAME_WLE) - get_filename_component(real_loc_wle ${real_loc_wle} NAME_WLE) - install(FILES "${real_loc}" DESTINATION ${lib_dest_dir} RENAME ${real_loc_wle} COMPONENT Runtime) - endforeach() -endif() - -#----------------------------------------------------------------------------- -# install a qt.conf file -if (APPLE) - install(CODE " - file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"\") - " COMPONENT Runtime) -elseif (UNIX) - # Linux builds need the path to the plugins directory, so we add it here. - install(CODE " - file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]\nPrefix = ..\") - " COMPONENT Runtime) -endif() - -#----------------------------------------------------------------------------- -# Generate the packaging script -install(CODE "set(bundle \"${bundle}\")" COMPONENT Runtime) -install(CODE "set(plugin_dest_dir \"${plugin_dest_dir}\")" COMPONENT Runtime) -install(CODE "set(lib_dest_dir \"${lib_dest_dir}\")" COMPONENT Runtime) -install(CODE "set(exe_dest_dir \"${exe_dest_dir}\")" COMPONENT Runtime) -install(CODE "set(suffix \"${CMAKE_SHARED_LIBRARY_SUFFIX}\")" COMPONENT Runtime) -install(CODE "set(ignore_items \"${ignore_items}\")" COMPONENT Runtime) -install(CODE "set(lib_search_dirs \"${lib_search_dirs}\")" COMPONENT Runtime) -install(CODE - "# Construct a list of the application's plugins - file(GLOB_RECURSE qt_plugins \"\${CMAKE_INSTALL_PREFIX}/\${plugin_dest_dir}/*/*\${suffix}\") - - # Construct a list of libraries already in the application bundle - file(GLOB_RECURSE required_libs \"\${CMAKE_INSTALL_PREFIX}/\${lib_dest_dir}/*\${suffix}\") - - # Construct a regex for libraries that we should package, even if they are - # considered system libraries (e.g., \"^.*(gfortran|quadmath).*\$\"). - set(post_include_regex \"\") - - # Construct a list of the application's runtime dependencies - file(GET_RUNTIME_DEPENDENCIES - RESOLVED_DEPENDENCIES_VAR resolved_deps - UNRESOLVED_DEPENDENCIES_VAR unresolved_deps - CONFLICTING_DEPENDENCIES_PREFIX conflicting_deps - POST_EXCLUDE_REGEXES \"^/(System|lib|usr/lib)\" - EXECUTABLES \${CMAKE_INSTALL_PREFIX}/\${exe_dest_dir}/ModelViewer - LIBRARIES \${qt_plugins} \${required_libs} - DIRECTORIES \${lib_search_dirs} - ) - - # Conflicting dependencies are dependencies that are found in multiple - # places. If a dependency in this list matches our post_include_regex - # and is not in our ignore_items list, use the first instance of the - # dependency found. - set(conflicting_deps) - foreach (conflicting_dep IN LISTS conflicting_deps_FILENAMES) - if (NOT post_include_regex) - continue () - endif () - string(REGEX MATCH \"\${post_include_regex}\" match \"\${conflicting_dep}\") - if (match) - set(add_to_list ON) - if (ignore_items) - if (\${conflicting_dep} NOT IN_LIST ignore_items) - set(add_to_list OFF) - endif() - endif() - if (add_to_list) - list(GET conflicting_deps_\${conflicting_dep} 0 dep) - list(APPEND conflicting_deps \${dep}) - endif() - endif() - endforeach() - - include(BundleUtilities) - - # Copy each resolved dependency into the application bundle - foreach (lib IN LISTS resolved_deps conflicting_deps required_libs) - get_filename_component(libname \${lib} NAME) - - # Copy the library into the bundle - execute_process(COMMAND \${CMAKE_COMMAND} -E - copy \${lib} \${CMAKE_INSTALL_PREFIX}/\${lib_dest_dir}/\${libname}) - - if (UNIX AND NOT APPLE) - # Change its permissions to allow us to modify its rpath - execute_process(COMMAND chmod u+w \"\${CMAKE_INSTALL_PREFIX}/\${lib_dest_dir}/\${libname}\") - - # Modify its rpath so it only attempts to resolve dependencies within - # the bundle - execute_process(COMMAND - chrpath --replace \$ORIGIN \"\${CMAKE_INSTALL_PREFIX}/\${lib_dest_dir}/\${libname}\") - endif() - endforeach() - - # Linux requires that the bundle's plugins also have a relative rpath set - if(UNIX AND NOT APPLE) - foreach (plugin IN LISTS qt_plugins) - execute_process(COMMAND - chrpath --replace \"\$ORIGIN:\$ORIGIN/../lib\" \"\${plugin}\" - RESULT_VARIABLE ignore) - endforeach() - endif() - - # Construct a list of directories inside the bundle where the application - # should look to resolve its dependencies - set(dirs \${CMAKE_INSTALL_PREFIX}/\${lib_dest_dir}) - list(APPEND dirs \${CMAKE_INSTALL_PREFIX}/\${CMAKE_INSTALL_LIBDIR}) - - # Add the bundle's library directory to the executable's rpath list - if (APPLE) - set(rpath \"@executable_path/../Libraries/\") - execute_process(COMMAND - ${CMAKE_INSTALL_NAME_TOOL} -add_rpath \"\${rpath}\" - \${CMAKE_INSTALL_PREFIX}/\${exe_dest_dir}/ModelViewer) - elseif(UNIX) - set(rpath \"\$ORIGIN/../lib\") - execute_process(COMMAND - chrpath --replace \"\${rpath}\" \${CMAKE_INSTALL_PREFIX}/\${exe_dest_dir}/ModelViewer) - endif() - - # By default, CPack on Apple puts all libraries and Frameworks in the Frameworks - # directory, and on Linux it puts all libraries in the bin directory. This behavior - # can be modified by defining the following function, which CMake looks for when - # fixup_bundle is run. - function(gp_item_default_embedded_path_override item default_embedded_path_var) - - # By default, embed items as set by gp_item_default_embedded_path - # (which puts things in Framework): - set(path \"\${\${default_embedded_path_var}}\") - - # If we're on APPLE and it's a library, put it in Libraries - if(APPLE AND item MATCHES \"\${suffix}\$\") - set(path \"@executable_path/../Libraries\") - endif() - - # If we're on Linux and it's a library, put it in lib - if(UNIX AND NOT APPLE) - get_filename_component(item_name \${item} NAME) - if (item_name MATCHES \"^lib.*\${suffix}.*\") - set(path \"@executable_path/../lib\") - endif() - endif() - - set(\${default_embedded_path_var} \"\${path}\" PARENT_SCOPE) - - endfunction() - - # Becasue we use the above custom function to decide where libraries go, we - # must also provide a custom function that verifies if an item is in the - # bundle. - function(gp_resolved_file_type_override resolved_file type_var) - - # For CPack on Linux, the default behavior of this method involves - # checking if an item's path is the same as the executable. Since we - # have split libraries into their own subdirectory, we must accommodate - # the new directory layout here. - if (UNIX AND NOT APPLE AND \${type_var} STREQUAL \"other\") - get_filename_component(dir \${resolved_file} DIRECTORY) - if (\"\${dir}\" MATCHES \"^\${CMAKE_INSTALL_PREFIX}*\") - set(\${type_var} \"local\" PARENT_SCOPE) - endif() - endif() - - endfunction() - - # Change the access rights for objects copied into the bundle, so the fixup - # logic can correctly fix them - set(BU_CHMOD_BUNDLE_ITEMS TRUE) - - # Execute fixup_bundle on the application (1) with additional plugins (2) using - # the listed directories (3) to find dependencies. Also, ignore unwanted - # dependencies (4) that may have been incorrectly gathered during the - # dependency search. - fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/\${exe_dest_dir}/ModelViewer\" - \"\${qt_plugins}\" \"\${dirs}\" IGNORE_ITEM \"\${ignore_items}\") - " - COMPONENT Runtime) - -include(CPack) diff --git a/applications/ModelViewer/ModelViewer.cxx b/applications/ModelViewer/ModelViewer.cxx deleted file mode 100644 index de456ac459ebc6bad1b4463a2b4796670f1caec5..0000000000000000000000000000000000000000 --- a/applications/ModelViewer/ModelViewer.cxx +++ /dev/null @@ -1,28 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "ModelViewer.h" -#include "ui_ModelViewer.h" - -class ModelViewer::Internals : public Ui::ModelViewer -{ -public: -}; - -ModelViewer::ModelViewer(QWidget* p) - : QWidget(p) -{ - m_p = new ModelViewer::Internals; - m_p->setupUi(this); -} - -ModelViewer::~ModelViewer() -{ - delete m_p; -} diff --git a/applications/ModelViewer/ModelViewer.h b/applications/ModelViewer/ModelViewer.h deleted file mode 100644 index 0158300c643903542778725cab899dcb179723ad..0000000000000000000000000000000000000000 --- a/applications/ModelViewer/ModelViewer.h +++ /dev/null @@ -1,30 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef __ModelViewer_h -#define __ModelViewer_h - -#include - -class QTreeView; -class QModelIndex; - -class ModelViewer : public QWidget -{ - Q_OBJECT -public: - ModelViewer(QWidget* parent = nullptr); - ~ModelViewer() override; - -protected: - class Internals; - Internals* m_p; -}; - -#endif diff --git a/applications/ModelViewer/ModelViewer.ui b/applications/ModelViewer/ModelViewer.ui deleted file mode 100644 index 905ce1f885101a098d8dab3bc4beb90aa2642a68..0000000000000000000000000000000000000000 --- a/applications/ModelViewer/ModelViewer.ui +++ /dev/null @@ -1,24 +0,0 @@ - - - ModelViewer - - - - 0 - 0 - 500 - 500 - - - - SMTK Model Viewer - - - - 0 - - - - - - diff --git a/applications/ModelViewer/main.cxx b/applications/ModelViewer/main.cxx deleted file mode 100644 index 05b0828d962d541d0585cbbc8e79043fdee19cbc..0000000000000000000000000000000000000000 --- a/applications/ModelViewer/main.cxx +++ /dev/null @@ -1,155 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/extension/vtk/source/vtkResourceMultiBlockSource.h" - -#include "smtk/geometry/Manager.h" - -#include "smtk/session/mesh/Registrar.h" -#include "smtk/session/mesh/Session.h" -#include "smtk/session/mesh/operators/CreateUniformGrid.h" - -#include "smtk/common/testing/cxx/helpers.h" - -#include "smtk/model/CellEntity.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Group.h" -#include "smtk/model/Resource.h" - -#include "smtk/resource/Manager.h" - -#include "smtk/operation/Manager.h" - -#include "smtk/plugin/Registry.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "ModelViewer.h" - -#include -#include -#include - -#include - -// This macro ensures the vtk io library is loaded into the executable -smtkComponentInitMacro(smtk_extension_vtk_io_mesh_MeshIOVTK); - -int main(int argc, char* argv[]) -{ - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Create a geometry manager - smtk::geometry::Manager::Ptr geometryManager = smtk::geometry::Manager::create(); - - // Register mesh resources to the resource, operation, and geomety managers. - auto registry = smtk::plugin::addToManagers( - resourceManager, operationManager, geometryManager); - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - // Create a "create background domain" operator - smtk::operation::Operation::Ptr createBackgroundDomainOp = - operationManager->create(); - - if (!createBackgroundDomainOp) - { - std::cerr << "Couldn't create \"create uniform grid\" operator" << std::endl; - return 1; - } - - createBackgroundDomainOp->parameters()->findString("dimension")->setValue("3"); - createBackgroundDomainOp->parameters()->findDouble("size3d")->setValue(0, 2); - - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(0, 5); - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(1, 5); - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(2, 5); - - smtk::operation::Operation::Result createBackgroundDomainOpResult = - createBackgroundDomainOp->operate(); - - if ( - createBackgroundDomainOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"create uniform grid\" operator failed\n"; - return 1; - } - - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - createBackgroundDomainOpResult->findComponent("created")); - - smtk::model::Entity::Ptr model = - std::dynamic_pointer_cast(componentItem->value()); - - smtk::resource::Resource::Ptr resource = model->resource(); - - QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat()); - QApplication app(argc, argv); - - vtkSmartPointer generator = - vtkSmartPointer::New(); - generator->SetResource(resource); - generator->Update(); - - ModelViewer modelViewer; - - QVTKOpenGLNativeWidget widget; - widget.resize(256, 256); - - vtkSmartPointer sphereMapper = - vtkSmartPointer::New(); - sphereMapper->SetInputConnection(generator->GetOutputPort()); - - vtkSmartPointer sphereActor = vtkSmartPointer::New(); - sphereActor->SetMapper(sphereMapper); - - vtkSmartPointer renderer = vtkSmartPointer::New(); - renderer->AddActor(sphereActor); - - widget.renderWindow()->AddRenderer(renderer); - - modelViewer.layout()->addWidget(&widget); - - modelViewer.show(); - - int status = app.exec(); - - return status; -} diff --git a/applications/ModelViewer/model-viewer.cmake.in b/applications/ModelViewer/model-viewer.cmake.in deleted file mode 100644 index cdfd17810adb90a388fbb89a4d1b77bdb9e2a3f0..0000000000000000000000000000000000000000 --- a/applications/ModelViewer/model-viewer.cmake.in +++ /dev/null @@ -1,26 +0,0 @@ -# This file is provided with SMTK as an example of how to configure a plugin -# contract file. In general, SMTK should not contain these files. Instead, the -# dashboard computer that runs SMTK tests should be passed a list of URLs for -# plugin contract test files during its configuration. - -cmake_minimum_required(VERSION 3.10) -project(model-viewer) - -include(ExternalProject) - -ExternalProject_Add(model-viewer - URL @PROJECT_SOURCE_DIR@/applications/ModelViewer - DOWNLOAD_NO_EXTRACT TRUET - PREFIX plugin - STAMP_DIR plugin/stamp - SOURCE_DIR plugin/src - BINARY_DIR plugin/build - CMAKE_ARGS - -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -Dsmtk_DIR=${smtk_DIR} - ${response_file} - INSTALL_DIR plugin/install - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target package - TEST_BEFORE_INSTALL True -) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index ccd2974daaac59e03290b6a0be23539bf400e85c..1cd72232f42ee2218a2de8a0d32042a08c3beb2f 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -137,9 +137,6 @@ if (SPHINX_FOUND) userguide/graph/filtering-and-searching.rst userguide/graph/index.rst userguide/graph/nodes-and-arcs.rst - userguide/mesh/concepts.rst - userguide/mesh/index.rst - userguide/mesh/IO.rst userguide/model/concepts.rst userguide/model/index.rst userguide/model/operators.rst diff --git a/doc/dev/build.md b/doc/dev/build.md index 74a145fe5b65973f142111d5a896d4e6a607388c..b44e2726413cacb09d49f6c4577ff35789d888ab 100644 --- a/doc/dev/build.md +++ b/doc/dev/build.md @@ -29,10 +29,6 @@ We recommend using [Ninja](http://martine.github.io/ninja/) for fast builds. These components are provided by the CMB superbuild, and are mostly optional: + [Boost](http://boost.org) 1.60.0 or newer (required) -+ [MOAB](https://bitbucket.org/fathomteam/moab), - (optionally built with - [Netcdf](http://www.unidata.ucar.edu/software/netcdf/), - for importing and exporting mesh files). + [OpenCascade](http://opencascade.org/) 7.4.0 or newer for importing CAD models; + [Python](http://python.org) version 2.7.3 or newer and [Pybind11](http://github.com/pybind/pybind11), for Python wrappings of diff --git a/doc/release/notes/mesh-removal.rst b/doc/release/notes/mesh-removal.rst new file mode 100644 index 0000000000000000000000000000000000000000..f794ac74d844e2f356865cfdb0c43c3b8b4061a9 --- /dev/null +++ b/doc/release/notes/mesh-removal.rst @@ -0,0 +1,10 @@ +Mesh Subsystem +============== + +The mesh subsystem (which introduced a dependency on the MOAB library +which is no longer maintained) has been removed from SMTK. +In practice, we have also realized mesh data using other resource +types (such as the VTK or markup sessions); either we will continue +with this pattern in the future (implementation-dependent mesh resources +as needed) or develop a mesh abstraction that is not tied so closely +to a particular implementation. diff --git a/doc/smtk.doxyfile.in b/doc/smtk.doxyfile.in index 05f95c944128d04b0255a90dc3899d73f90091d1..ec4f917b7d5f5ac99d302b0d27d5311a29670a58 100644 --- a/doc/smtk.doxyfile.in +++ b/doc/smtk.doxyfile.in @@ -681,15 +681,6 @@ INPUT = \ "@smtk_SOURCE_DIR@/smtk/markup/queries" \ "@smtk_SOURCE_DIR@/smtk/markup/ontology" \ "@smtk_SOURCE_DIR@/smtk/markup/operators" \ - "@smtk_SOURCE_DIR@/smtk/mesh" \ - "@smtk_SOURCE_DIR@/smtk/mesh/core" \ - "@smtk_SOURCE_DIR@/smtk/mesh/core/queries" \ - "@smtk_SOURCE_DIR@/smtk/mesh/operators" \ - "@smtk_SOURCE_DIR@/smtk/mesh/plugin" \ - "@smtk_SOURCE_DIR@/smtk/mesh/moab" \ - "@smtk_SOURCE_DIR@/smtk/mesh/resource" \ - "@smtk_SOURCE_DIR@/smtk/mesh/interpolation" \ - "@smtk_SOURCE_DIR@/smtk/mesh/utility" \ "@smtk_SOURCE_DIR@/smtk/operation" \ "@smtk_SOURCE_DIR@/smtk/operation/operators" \ "@smtk_SOURCE_DIR@/smtk/operation/plugin" \ @@ -721,9 +712,7 @@ INPUT = \ "@smtk_SOURCE_DIR@/smtk/extension/vtk" \ "@smtk_SOURCE_DIR@/smtk/extension/vtk/geometry" \ "@smtk_SOURCE_DIR@/smtk/extension/vtk/io" \ - "@smtk_SOURCE_DIR@/smtk/extension/vtk/io/mesh" \ "@smtk_SOURCE_DIR@/smtk/extension/vtk/markup" \ - "@smtk_SOURCE_DIR@/smtk/extension/vtk/mesh" \ "@smtk_SOURCE_DIR@/smtk/extension/vtk/model" \ "@smtk_SOURCE_DIR@/smtk/extension/vtk/operators" \ "@smtk_SOURCE_DIR@/smtk/extension/vtk/operators/plugin" \ @@ -738,7 +727,6 @@ INPUT = \ "@smtk_SOURCE_DIR@/smtk/attribute/queries" \ "@smtk_SOURCE_DIR@/smtk/attribute/utility" \ "@smtk_SOURCE_DIR@/smtk/io" \ - "@smtk_SOURCE_DIR@/smtk/io/mesh" \ "@smtk_SOURCE_DIR@/smtk/graph" \ "@smtk_SOURCE_DIR@/smtk/graph/detail" \ "@smtk_SOURCE_DIR@/smtk/graph/evaluators" \ @@ -768,11 +756,6 @@ INPUT = \ "@smtk_SOURCE_DIR@/smtk/resource/properties" \ "@smtk_SOURCE_DIR@/smtk/resource/query" \ "@smtk_SOURCE_DIR@/smtk/session" \ - "@smtk_SOURCE_DIR@/smtk/session/mesh" \ - "@smtk_SOURCE_DIR@/smtk/session/mesh/operators" \ - "@smtk_SOURCE_DIR@/smtk/session/mesh/plugin" \ - "@smtk_SOURCE_DIR@/smtk/session/mesh/queries" \ - "@smtk_SOURCE_DIR@/smtk/session/mesh/vtk" \ "@smtk_SOURCE_DIR@/smtk/session/polygon" \ "@smtk_SOURCE_DIR@/smtk/session/polygon/operators" \ "@smtk_SOURCE_DIR@/smtk/session/polygon/plugin" \ @@ -788,15 +771,6 @@ INPUT = \ \ "@smtk_BINARY_DIR@/smtk" \ "@smtk_BINARY_DIR@/smtk/markup" \ - "@smtk_BINARY_DIR@/smtk/mesh" \ - "@smtk_BINARY_DIR@/smtk/mesh/core" \ - "@smtk_BINARY_DIR@/smtk/mesh/core/queries" \ - "@smtk_BINARY_DIR@/smtk/mesh/operators" \ - "@smtk_BINARY_DIR@/smtk/mesh/plugin" \ - "@smtk_BINARY_DIR@/smtk/mesh/moab" \ - "@smtk_BINARY_DIR@/smtk/mesh/resource" \ - "@smtk_BINARY_DIR@/smtk/mesh/interpolation" \ - "@smtk_BINARY_DIR@/smtk/mesh/utility" \ "@smtk_BINARY_DIR@/smtk/operation" \ "@smtk_BINARY_DIR@/smtk/operation/operators" \ "@smtk_BINARY_DIR@/smtk/operation/plugin" \ @@ -826,12 +800,10 @@ INPUT = \ "@smtk_BINARY_DIR@/smtk/extension/delaunay/io" \ "@smtk_BINARY_DIR@/smtk/extension/delaunay/plugin" \ "@smtk_BINARY_DIR@/smtk/extension/vtk" \ - "@smtk_BINARY_DIR@/smtk/extension/vtk/mesh" \ "@smtk_BINARY_DIR@/smtk/extension/vtk/operators" \ "@smtk_BINARY_DIR@/smtk/extension/vtk/operators/plugin" \ "@smtk_BINARY_DIR@/smtk/extension/vtk/source" \ "@smtk_BINARY_DIR@/smtk/extension/vtk/io" \ - "@smtk_BINARY_DIR@/smtk/extension/vtk/io/mesh" \ "@smtk_BINARY_DIR@/smtk/extension/vtk/model" \ "@smtk_BINARY_DIR@/smtk/extension/vtk/geometry" \ "@smtk_BINARY_DIR@/smtk/extension/vtk/filter" \ @@ -844,7 +816,6 @@ INPUT = \ "@smtk_BINARY_DIR@/smtk/attribute/queries" \ "@smtk_BINARY_DIR@/smtk/attribute/utility" \ "@smtk_BINARY_DIR@/smtk/io" \ - "@smtk_BINARY_DIR@/smtk/io/mesh" \ "@smtk_BINARY_DIR@/smtk/graph" \ "@smtk_BINARY_DIR@/smtk/graph/detail" \ "@smtk_BINARY_DIR@/smtk/graph/evaluators" \ @@ -873,11 +844,6 @@ INPUT = \ "@smtk_BINARY_DIR@/smtk/resource/properties" \ "@smtk_BINARY_DIR@/smtk/resource/query" \ "@smtk_BINARY_DIR@/smtk/session" \ - "@smtk_BINARY_DIR@/smtk/session/mesh" \ - "@smtk_BINARY_DIR@/smtk/session/mesh/operators" \ - "@smtk_BINARY_DIR@/smtk/session/mesh/plugin" \ - "@smtk_BINARY_DIR@/smtk/session/mesh/queries" \ - "@smtk_BINARY_DIR@/smtk/session/mesh/vtk" \ "@smtk_BINARY_DIR@/smtk/session/polygon" \ "@smtk_BINARY_DIR@/smtk/session/polygon/operators" \ "@smtk_BINARY_DIR@/smtk/session/polygon/plugin" \ diff --git a/doc/userguide/index.rst b/doc/userguide/index.rst index 6951e6e887832a5dd48b21ec6489994cc3be4233..b3c8293d7a8c8f6c5ad0572aa1d5cdd1a907ad7f 100644 --- a/doc/userguide/index.rst +++ b/doc/userguide/index.rst @@ -43,7 +43,6 @@ simulation domain. model/index.rst graph/index.rst markup/index.rst - mesh/index.rst project/index.rst task/index.rst simulation/index.rst diff --git a/doc/userguide/mesh/IO.rst b/doc/userguide/mesh/IO.rst deleted file mode 100644 index ac25e04bc277d8e1b623f715023e7e2df3541ca4..0000000000000000000000000000000000000000 --- a/doc/userguide/mesh/IO.rst +++ /dev/null @@ -1,151 +0,0 @@ -== -IO -== - -:smtk:`WriteMesh ` - Writes out a given :smtk:`Collection `, or only - the elements that match a given Domain, Dirichlet or Neumann - property. This is a preserving process: all information relevant to - the mesh is written to file, and subsequent reads from this file - should restore the mesh exactly. - - Supported formats: - + MOAB (h5m, mhdf) - + Exodus II (exo exoII exo2 g gen) - -:smtk:`ReadMesh ` - Load a given file in as a new :smtk:`Collection ` or - part of an existing :smtk:`Collection `. Also - supports loading just elements that a given Domain, Dirichlet or Neumann - property. This is a preserving process: all information relevant to - the mesh should restore the mesh in the same state as when it was written. - - Supported formats: - + MOAB (h5m, mhdf) - + Exodus II (exo exoII exo2 g gen) - -:smtk:`ImportMesh ` - Import a given file in as a new :smtk:`Collection ` or - part of an existing :smtk:`Collection - `. Imports are not preserving processes: - all mesh information contained in a file is not guaranteed to be - read into the mesh database via `ImportMesh`. - - Supported formats: - + MOAB (h5m, mhdf) - + Exodus II (exo exoII exo2 g gen) - + VTK (vtk) - + SLAC (slac) - + General Mesh Viewer (gmv) - + ANSYS (ans) - + Gmsh (msh gmsh) - + Stereolithography (stl) - -:smtk:`ExportMesh ` - Export a given :smtk:`Collection ` to - file. Exports are not preserving processes: - all mesh information contained in the mesh database is not - guaranteed to be written to file via `ExportMesh`. - - Supported formats: - + MOAB (h5m, mhdf) - + Exodus II (exo exoII exo2 g gen) - + VTK (vtk) - + SLAC (slac) - + General Mesh Viewer (gmv) - + ANSYS (ans) - + Gmsh (msh gmsh) - + Stereolithography (stl) - + XMS 2D/3D (2dm 3dm) - - -Serialization -============= - -:smtk:`SaveJSON ` - Export all the :smtk:`Collection ` that have - associations with the any model that is part of the passed in - :smtk:`Resource `. The exporter will save each - Collection using :smtk:`WriteMesh ` with the file - type MOAB and extension h5m. - - The format of the created json is: - -.. highlight:: json -.. code-block:: json - - "70ec982c-9562-44bd-a7e7-bd12b84a3271": { - "formatVersion": 1, - "name": "", - "fileType": "moab", - "location": "/tmp/output.0.h5m", - "nc": 40, - "np": 28, - "cell_types": "000000100", - "domains": [], - "boundary_conditions": { - "0": { - "value": 2, - "type": "dirichlet" - }, - "1": { - "value": 2, - "type": "neumann" - }, - }, - "modelEntityIds": ["0442f22c-26dc-4e6b-bdd8-1e77b75e5d36", "7d42284b-c7e0-4777-8836-3b77d6aed0e3", "8cdcf988-36bd-43ed-bb60-c76443907f16", "c7a90a24-f058-4d79-8b75-bb58470547bf"], - "meshes": { - "0": { - "nc": 10, - "np": 7, - "cell_types": "000000100", - "domains": [], - "boundary_conditions": { - "0": { - "value": 2, - "type": "neumann" - } - }, - "modelEntityIds": ["0442f22c-26dc-4e6b-bdd8-1e77b75e5d36"] - }, - "1": { - "nc": 10, - "np": 7, - "cell_types": "000000100", - "domains": [], - "boundary_conditions": { }, - "modelEntityIds": ["7d42284b-c7e0-4777-8836-3b77d6aed0e3"] - }, - "2": { - "nc": 10, - "np": 7, - "cell_types": "000000100", - "domains": [], - "boundary_conditions": { - "0": { - "value": 2, - "type": "dirichlet" - } - "1": { - "value": 2, - "type": "neumann" - } - }, - "modelEntityIds": ["8cdcf988-36bd-43ed-bb60-c76443907f16"] - }, - "3": { - "nc": 10, - "np": 7, - "cell_types": "000000100", - "domains": [], - "boundary_conditions": { }, - "modelEntityIds": ["c7a90a24-f058-4d79-8b75-bb58470547bf"] - } - } - } - - -:smtk:`LoadJSON ` - Imports all the :smtk:`Collection ` that are listed - in the provided JSON string. Each Collection will be marked as being associated - with the provided model :smtk:`Resource `. diff --git a/doc/userguide/mesh/concepts.rst b/doc/userguide/mesh/concepts.rst deleted file mode 100644 index 90c7fe9a1c201b62dc4b7287a3301c7775b1817b..0000000000000000000000000000000000000000 --- a/doc/userguide/mesh/concepts.rst +++ /dev/null @@ -1,99 +0,0 @@ -Key Concepts -============ - -Like the model resource, the mesh resource is composed of C++ classes, -also accessible in Python, and is based on concepts from MOAB_, -which it uses internally. The paradigm we use facilitates an -interaction with meshes and their components in aggregate, -avoiding granular queries whereever possible (e.g. favoring -such set-theretical actions as "intersection" and "union", rather than -iterating over individual elements). - -To enforce the concept of interacting with mesh elements in -aggregate, all mesh elements are represented as sets: there are no -classes that represent individual mesh elements (point, cell or -mesh). A user can interact with individual mesh elements via the -:smtk:`MeshForEach ` interface, which iterates -over single elements that may be represented as element sets containing -a single element. It should be noted that element-wise access to a mesh -is usually not the correct approach for most algorithms. - -The class instances, listed hierarchically from the most granular to -the most aggregate, are as follows: - -:smtk:`Handle ` - instances refer to a single `smtk::mesh` entity, which may be a - single primitive mesh element (a point or a cell, e.g., a triangle or - quadrilateral), a set of points (an :smtk:`PointSet`), a set of - cells (an :smtk:`CellSet`), or a set of mesh elements (an - :smtk:`MeshSet`) grouped together for some purpose. - -:smtk:`HandleRange ` - instances refer to a range of mesh entities. - A range is a run-length encoded list of mesh handles (which are opaque - but internally represented by integers). - By making HandleRanges a primitive type, - meshes with implicit connectivity can be compactly represented. - -:smtk:`PointSet ` - instances group :smtk:`HandleRange ` instances referring to points - together so they can be marked with properties such as a common - association with a model entity, material, boundary condition, or - initial condition. As a set, each :smtk:`PointSet` supports set-theoretic - actions (intersect, difference and union). Each `PointSet` - instance holds a reference to its parent resource (described below) - and provides methods for setting attributes, computing subsets, and accessing - individual points. - -:smtk:`CellSet ` - instances group :smtk:`HandleRange ` instances referring to cells - together so they can be marked with properties such as a common - association with a model entity, material, boundary condition, or - initial condition. As a set, each :smtk:`CellSet` supports set-theoretic - actions (intersect, difference and union). Each `CellSet` - instance holds a reference to its parent resource (described below) - and provides methods for setting attributes, computing subsets, and accessing - individual cells. - -:smtk:`MeshSet ` - instances group :smtk:`HandleRange ` instances referring to meshes - together so that they can be marked with properties such as a common - association with a model entity, material, boundary condition, or - initial condition. As a set, each :smtk:`MeshSet` supports set-theoretic - actions (intersect, difference and union). Each `MeshSet` instance - holds a reference to a parent resource (described below) and - provides methods for setting attributes, computing subsets, and - accessing individual meshes. A `MeshSet` also has access to its - underlying `CellSet` and `PointSet`. - - In general, a MeshSet will not contain elements that overlap spatially. - Instead, a meshset usually has a boundary that conforms to neighboring - meshsets (or to empty space). - Often, an SMTK modeling entity (corresponding to a - :smtk:`CellEntity `) will be associated - with a meshset that approximates its point locus; - however, not all MeshSets have an associated model entity. - -:smtk:`Collection ` - instances hold related MeshSets together. - Problem domains are often the union of several instances of - `MeshSet` in a `Collection`. Often, the problem domain may be - decomposed in several ways, so that all of the `MeshSet`s in a - resource may cover the problem domain several - times over. - For example, a `Collection` may have one `MeshSet` for each geometric model - cell as well as a `MeshSet` for each material. - Either of these alone would cover the entire problem domain; - together, they cover it twice. - - All of the cells in all of the `MeshSet` instances of a `Collection` have their - connectivity defined by indices into the same set of points. - - Each `Collection` has a parent mesh `Manager`. - -:smtk:`Manager ` - instances contain `Collections` and provide an interface to an - underlying mesh package, such as MOAB_, that implements methods to - access the mesh. - -.. _MOAB: https://bitbucket.org/fathomteam/moab diff --git a/doc/userguide/mesh/index.rst b/doc/userguide/mesh/index.rst deleted file mode 100644 index e8ab1ef0ffdb89cf2630b5acacfecc52e6ef89e5..0000000000000000000000000000000000000000 --- a/doc/userguide/mesh/index.rst +++ /dev/null @@ -1,16 +0,0 @@ -.. _smtk-mesh-sys: - ------------------- -SMTK's Mesh Resource ------------------- - -SMTK's third major component is its meshing resource, -which allows you to interact with multiple mesh generators -and associate one or more meshes with each geometric model -entity. - -.. toctree:: - :maxdepth: 3 - - concepts.rst - IO.rst diff --git a/smtk/CMakeLists.txt b/smtk/CMakeLists.txt index f881020364407b457eae258c7ad3449c36491615..b0cb35c11005ae5cf5af709cd31b42f27e6341d5 100644 --- a/smtk/CMakeLists.txt +++ b/smtk/CMakeLists.txt @@ -27,9 +27,6 @@ smtk_source_group(operation) add_subdirectory(project) smtk_source_group(project) -add_subdirectory(mesh) -smtk_source_group(mesh) - add_subdirectory(model) smtk_source_group(model) @@ -59,7 +56,6 @@ set(smtk_headers ${graphHeaders} ${attributeHeaders} ${operationHeaders} - ${meshHeaders} ${modelHeaders} ${projectHeaders} ${viewHeaders} @@ -78,7 +74,6 @@ set(smtk_srcs ${attributeSrcs} ${operationSrcs} ${projectSrcs} - ${meshSrcs} ${modelSrcs} ${viewSrcs} ${workflowSrcs} @@ -95,7 +90,6 @@ set(smtkCore_public_include_directories ) set(smtkCore_public_link_libraries - MOAB nlohmann_json taocpp::pegtl Threads::Threads @@ -133,7 +127,6 @@ target_compile_features(smtkCore add_dependencies(smtkCore attributeGenHeaders graphGenHeaders - meshGenHeaders modelGenHeaders operationGenHeaders projectGenHeaders diff --git a/smtk/PublicPointerDefs.h b/smtk/PublicPointerDefs.h index 99bb5c98b9dc8e25b5f088066b39aab3d85df231..413d34ac0939315adcfa2d1543dc762efb237c5c 100644 --- a/smtk/PublicPointerDefs.h +++ b/smtk/PublicPointerDefs.h @@ -109,28 +109,6 @@ class qtSelectionManager; typedef smtk::shared_ptr qtSelectionManagerPtr; } // namespace extension -namespace mesh -{ -class Resource; -class Component; -class Interface; -class Allocator; -class BufferedCellAllocator; -class IncrementalAllocator; -class ConnectivityStorage; -class PointLocatorImpl; - -namespace moab -{ -class Interface; -} - -namespace json -{ -class Interface; -} -} // namespace mesh - namespace model { class Arrangement; @@ -183,9 +161,6 @@ typedef std::set FaceSet; class FaceUse; /// @see smtk::model::FaceUse typedef std::vector FaceUses; -class GridInfo; -class GridInfo2D; -class GridInfo3D; class Instance; /// @see smtk::model::Instance typedef std::vector Instances; @@ -357,40 +332,6 @@ typedef smtk::shared_ptr ManagerPtr; typedef smtk::weak_ptr WeakManagerPtr; } // namespace operation -namespace mesh -{ -/// @see smtk::mesh::Resource -typedef smtk::shared_ptr ResourcePtr; -/// @see smtk::mesh::Resource -typedef smtk::shared_ptr ConstResourcePtr; -/// @see smtk::mesh::Component -typedef smtk::shared_ptr ComponentPtr; -/// @see smtk::mesh::Interface -typedef smtk::shared_ptr InterfacePtr; -/// @see smtk::mesh::Allocator -typedef smtk::shared_ptr AllocatorPtr; -/// @see smtk::mesh::BufferedCellAllocator -typedef smtk::shared_ptr BufferedCellAllocatorPtr; -/// @see smtk::mesh::IncrementalAllocator -typedef smtk::shared_ptr IncrementalAllocatorPtr; -/// @see smtk::mesh::ConnectivityStorage -typedef smtk::shared_ptr ConnectivityStoragePtr; -/// @see smtk::mesh::PointLocatorImpl -typedef smtk::shared_ptr PointLocatorImplPtr; - -namespace moab -{ -/// @see smtk::mesh::moab::Interface -typedef smtk::shared_ptr InterfacePtr; -} // namespace moab - -namespace json -{ -/// @see smtk::mesh::json::Interface -typedef smtk::shared_ptr InterfacePtr; -} // namespace json -} // namespace mesh - namespace model { // Model Related Pointer Classes @@ -440,14 +381,6 @@ typedef smtk::weak_ptr WeakArrangementPtr; typedef smtk::shared_ptr TessellationPtr; /// @see smtk::model::Tessellation typedef smtk::weak_ptr WeakTessellationPtr; - -// class for making the analysis grid information available in SMTK -/// @see smtk::model::GridInfo -typedef smtk::shared_ptr GridInfoPtr; -/// @see smtk::model::GridInfo2D -// typedef smtk::shared_ptr GridInfo2DPtr; -/// @see smtk::model::GridInfo3D -// typedef smtk::shared_ptr GridInfo3DPtr; } // namespace model namespace attribute diff --git a/smtk/attribute/json/jsonComponentItemDefinition.cxx b/smtk/attribute/json/jsonComponentItemDefinition.cxx index 06036dcf110c005119af8892924eec8f7b288786..6cd1c4334405148ad3c7645fd3dfa09ae3c401b3 100644 --- a/smtk/attribute/json/jsonComponentItemDefinition.cxx +++ b/smtk/attribute/json/jsonComponentItemDefinition.cxx @@ -14,7 +14,6 @@ #include "smtk/attribute/json/jsonReferenceItemDefinition.h" #include "smtk/PublicPointerDefs.h" -#include "smtk/mesh/core/Resource.h" #include "smtk/model/Entity.h" #include "nlohmann/json.hpp" @@ -97,38 +96,5 @@ SMTKCORE_EXPORT void processFromRefItemDef( } } -SMTKCORE_EXPORT void processFromMeshItemDef( - const nlohmann::json& j, - smtk::attribute::ComponentItemDefinitionPtr& defPtr) -{ - // The caller should make sure that defPtr is valid since it's not default constructible - if (!defPtr.get()) - { - return; - } - // Create the appropriate query for mesh sets - defPtr->setAcceptsEntries(smtk::common::typeName(), "meshset", true); - - auto itemDef = smtk::dynamic_pointer_cast(defPtr); - smtk::attribute::from_json(j, itemDef); - - auto result = j.find("NumberOfRequiredValues"); - if (result != j.end()) - { - defPtr->setNumberOfRequiredValues(*result); - } - - result = j.find("Extensible"); - if (result != j.end()) - { - defPtr->setIsExtensible(*result); - } - - result = j.find("MaxNumberOfValues"); - if (result != j.end()) - { - defPtr->setMaxNumberOfValues(*result); - } -} } // namespace attribute } // namespace smtk diff --git a/smtk/attribute/json/jsonComponentItemDefinition.h b/smtk/attribute/json/jsonComponentItemDefinition.h index 616721888a7da51affe084fdc83126e6f14797ba..69d149f735c2b4191b82f0db568f6a3f039c0fc0 100644 --- a/smtk/attribute/json/jsonComponentItemDefinition.h +++ b/smtk/attribute/json/jsonComponentItemDefinition.h @@ -38,10 +38,6 @@ SMTKCORE_EXPORT void from_json( SMTKCORE_EXPORT void processFromRefItemDef( const nlohmann::json& j, smtk::attribute::ComponentItemDefinitionPtr& defPtr); - -SMTKCORE_EXPORT void processFromMeshItemDef( - const nlohmann::json& j, - smtk::attribute::ComponentItemDefinitionPtr& defPtr); } // namespace attribute } // namespace smtk diff --git a/smtk/attribute/json/jsonHelperFunction.cxx b/smtk/attribute/json/jsonHelperFunction.cxx index 2fec0b8671bdcf2a04e920fb8c2c5c722745a901..414cf68f2548ace1a498e76b84d856e44b8152c5 100644 --- a/smtk/attribute/json/jsonHelperFunction.cxx +++ b/smtk/attribute/json/jsonHelperFunction.cxx @@ -168,14 +168,6 @@ void processItemDef( smtk::attribute::from_json(itemDef, temp); } break; - case smtk::attribute::Item::MeshEntityType: - if ((cidef = - idef->template addItemDefinition(citemName))) - { - auto temp = smtk::dynamic_pointer_cast(cidef); - smtk::attribute::processFromMeshItemDef(itemDef, temp); - } - break; case smtk::attribute::Item::DateTimeType: if ((cidef = idef->template addItemDefinition(citemName))) diff --git a/smtk/attribute/testing/cxx/CMakeLists.txt b/smtk/attribute/testing/cxx/CMakeLists.txt index 576cd286815128ab2adc36653fa654b9380fb4c9..4372f30395179745081d69c50c188ad60b36e492 100644 --- a/smtk/attribute/testing/cxx/CMakeLists.txt +++ b/smtk/attribute/testing/cxx/CMakeLists.txt @@ -146,5 +146,4 @@ smtk_unit_tests( LIBRARIES smtkCore ${extra_libs} - MOAB ) diff --git a/smtk/attribute/testing/cxx/unitAssociationRulesTest.cxx b/smtk/attribute/testing/cxx/unitAssociationRulesTest.cxx index c32364968d7bec5d9d93654908dd5ed576a6448e..606abf58342b7e1bf7fd241dd440385e055b7aa7 100644 --- a/smtk/attribute/testing/cxx/unitAssociationRulesTest.cxx +++ b/smtk/attribute/testing/cxx/unitAssociationRulesTest.cxx @@ -24,8 +24,9 @@ #include "smtk/io/AttributeReader.h" #include "smtk/io/AttributeWriter.h" #include "smtk/io/Logger.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/utility/Create.h" +#include "smtk/model/Entity.h" +#include "smtk/model/Model.h" +#include "smtk/model/Resource.h" //force to use filesystem version 3 #define BOOST_FILESYSTEM_VERSION 3 @@ -63,23 +64,20 @@ int testAssociationRule(const smtk::attribute::AttributePtr& attribute) } // Test if the attribute instance with a custom association rule can be - // associated with a mesh component (it should). + // associated with a markup component (it should). { - // Create a new mesh mesh resource - smtk::mesh::ResourcePtr meshResource = smtk::mesh::Resource::create(); + // Create a new model resource + smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - // Construct a uniform grid - std::array discretization = { { 2, 2, 2 } }; - std::function(std::array)> transform = - [](std::array x) { return x; }; - auto meshes = smtk::mesh::utility::createUniformGrid(meshResource, discretization, transform); - auto meshComponent = smtk::mesh::Component::create(meshes[0]); + // Construct a uniform model + auto mmodel = modelResource->addModel(); + auto modelComponent = mmodel.component(); // Test whether the attribute resource can be associated to the newly - // created mesh component. - if (!attribute->canBeAssociated(meshComponent)) + // created model component. + if (!attribute->canBeAssociated(modelComponent)) { - std::cerr << "Custom Python rule should accept mesh components\n"; + std::cerr << "Custom Python rule should accept model components\n"; std::cerr << smtk::io::Logger::instance().convertToString(); return -2; } @@ -89,11 +87,11 @@ int testAssociationRule(const smtk::attribute::AttributePtr& attribute) } const char* testPy = R"python( -import smtk.mesh +import smtk.model def mySpecialAssociationRule(object, attribute): - meshComponent = smtk.mesh.Component.CastTo(object) - return meshComponent != None + modelComponent = smtk.model.Entity.CastTo(object) + return modelComponent != None )python"; const char* testInput = R"xml( diff --git a/smtk/common/testing/cxx/CMakeLists.txt b/smtk/common/testing/cxx/CMakeLists.txt index 98a565978879f8679507ab7d28d55616a75df602..250de9b49c0ac7d1251a192604d564ca0de3c60d 100644 --- a/smtk/common/testing/cxx/CMakeLists.txt +++ b/smtk/common/testing/cxx/CMakeLists.txt @@ -59,7 +59,6 @@ set(unit_tests_which_require_data set(_extra_libraries ${Boost_LIBRARIES} Threads::Threads - MOAB ) smtk_unit_tests( diff --git a/smtk/doc.h b/smtk/doc.h index 15a848d3f8d5555b9035b331c121c11733284c90..880ff404951b3ef45c5676128753b71c13a442bb 100644 --- a/smtk/doc.h +++ b/smtk/doc.h @@ -111,21 +111,6 @@ namespace model { } -/**\brief Mesh representation, classification, and manipulation. - * - */ -namespace mesh -{ -/// moab is an external meshing library. -namespace moab -{ -} -/// json serialization. -namespace json -{ -} -} // namespace mesh - /**\brief Projects organize a user workspace. * */ @@ -220,12 +205,6 @@ namespace polygon namespace extension { -/**\brief A simple mesh generator. - * - */ -namespace delaunay -{ -} /**\brief matplotlib. * */ diff --git a/smtk/extension/CMakeLists.txt b/smtk/extension/CMakeLists.txt index 6f03e52347381fae71cd6bd39e0bae8b1f7f8449..8645e86187bc44b19f54189e55bb0f07ab84f13b 100644 --- a/smtk/extension/CMakeLists.txt +++ b/smtk/extension/CMakeLists.txt @@ -3,9 +3,6 @@ if(SMTK_ENABLE_QT_SUPPORT) add_subdirectory(qt) endif() -# Add operators that use Delaunay 2d meshing -add_subdirectory(delaunay) - set(SMTK_VTK_SUPPORT_ENABLED "False") if (SMTK_ENABLE_VTK_SUPPORT) @@ -28,13 +25,5 @@ if(SMTK_ENABLE_PARAVIEW_SUPPORT) endif() if (SMTK_ENABLE_PYTHON_WRAPPING) - - option(SMTK_ENABLE_MATPLOTLIB "Enable matplotlib" OFF) - set(SMTK_MATPLOTLIB_SUPPORT_ENABLED "False") - if(SMTK_ENABLE_MATPLOTLIB) - set(SMTK_MATPLOTLIB_SUPPORT_ENABLED "True") - add_subdirectory(matplotlib) - endif() - add_subdirectory(pybind11) endif() diff --git a/smtk/extension/delaunay/CMakeLists.txt b/smtk/extension/delaunay/CMakeLists.txt deleted file mode 100644 index 18107831ca3f239ad4e1938ad6df1a80e7939123..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/CMakeLists.txt +++ /dev/null @@ -1,57 +0,0 @@ -set(delaunaySrcs - Registrar.cxx - io/ImportDelaunayMesh.cxx - io/ExportDelaunayMesh.cxx - ) -set(delaunayHeaders - Registrar.h - io/ImportDelaunayMesh.h - io/ExportDelaunayMesh.h - ) - -set(delaunayOperators - TessellateFaces - TriangulateFaces - ) - -foreach (operator ${delaunayOperators}) - list(APPEND delaunaySrcs operators/${operator}.cxx) - list(APPEND delaunayHeaders operators/${operator}.h) -endforeach() - -add_library(smtkDelaunayExt ${delaunaySrcs}) -target_link_libraries(smtkDelaunayExt - PRIVATE - smtkCore - DelaunayShape - DelaunayMesh - DelaunayMisc - DelaunayValidation - DelaunayDiscretization -) - -smtk_export_header(smtkDelaunayExt Exports.h) -smtk_public_headers(smtkDelaunayExt ${delaunayHeaders}) -smtk_install_library(smtkDelaunayExt) - -foreach (operator ${delaunayOperators}) - smtk_encode_file("${CMAKE_CURRENT_SOURCE_DIR}/operators/${operator}.sbt" - HEADER_OUTPUT headerName) - list(APPEND delaunayDependencies ${headerName}) -endforeach() -add_custom_target("delaunayGenHeaders" DEPENDS ${delaunayDependencies}) - -add_dependencies(smtkDelaunayExt "delaunayGenHeaders") - -if (SMTK_ENABLE_PARAVIEW_SUPPORT) - set_property(GLOBAL APPEND - PROPERTY _smtk_plugin_files "${CMAKE_CURRENT_SOURCE_DIR}/plugin/paraview.plugin") -endif () - -if (SMTK_ENABLE_PYTHON_WRAPPING) - add_subdirectory(pybind11) -endif() - -if (SMTK_ENABLE_TESTING) - add_subdirectory(testing) -endif() diff --git a/smtk/extension/delaunay/Registrar.cxx b/smtk/extension/delaunay/Registrar.cxx deleted file mode 100644 index 8dc277ea0b0d6fb942f15d85398a317c0d08fbfe..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/Registrar.cxx +++ /dev/null @@ -1,41 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/extension/delaunay/Registrar.h" - -#include "smtk/extension/delaunay/operators/TessellateFaces.h" -#include "smtk/extension/delaunay/operators/TriangulateFaces.h" - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ - -namespace -{ -typedef std::tuple OperationList; -} - -void Registrar::registerTo(const smtk::operation::Manager::Ptr& operationManager) -{ - // Register operations - operationManager->registerOperations(); -} - -void Registrar::unregisterFrom(const smtk::operation::Manager::Ptr& operationManager) -{ - operationManager->unregisterOperations(); -} -} // namespace delaunay -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/delaunay/Registrar.h b/smtk/extension/delaunay/Registrar.h deleted file mode 100644 index 852355138333273dfead15d842afcea622b35e05..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/Registrar.h +++ /dev/null @@ -1,41 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_extension_delaunay_Registrar_h -#define smtk_extension_delaunay_Registrar_h - -#include "smtk/extension/delaunay/Exports.h" - -#include "smtk/attribute/Registrar.h" -#include "smtk/mesh/resource/Registrar.h" -#include "smtk/model/Registrar.h" -#include "smtk/operation/Manager.h" -#include "smtk/operation/Registrar.h" - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ - -class SMTKDELAUNAYEXT_EXPORT Registrar -{ -public: - using Dependencies = - std::tuple; - - static void registerTo(const smtk::operation::Manager::Ptr&); - static void unregisterFrom(const smtk::operation::Manager::Ptr&); -}; -} // namespace delaunay -} // namespace extension -} // namespace smtk - -#endif diff --git a/smtk/extension/delaunay/io/ExportDelaunayMesh.cxx b/smtk/extension/delaunay/io/ExportDelaunayMesh.cxx deleted file mode 100644 index fd55c17d86b492ea54ac6af2511171e2b50f8fd5..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/io/ExportDelaunayMesh.cxx +++ /dev/null @@ -1,126 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#include "smtk/extension/delaunay/io/ExportDelaunayMesh.h" - -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/ExtractTessellation.h" - -#include "smtk/model/Edge.h" -#include "smtk/model/EdgeUse.h" -#include "smtk/model/Loop.h" - -#include "Shape/Point.hh" - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ -namespace io -{ - -std::vector ExportDelaunayMesh::operator()( - const smtk::model::Loop& loop) const -{ - std::vector points; - // We collect the points for each edge and insert them at once into our - // points vector. This allows us to properly account for the edge use - // orientation while using smtk::model::Tessellation's forward iterator to - // loop through tessellation cells. - std::vector pointsForEdge; - - for (auto& eu : loop.edgeUses()) - { - const smtk::model::Tessellation* tess = eu.edge().hasTessellation(); - std::vector cell_conn; - smtk::model::Tessellation::size_type start_off; - std::vector numCellsOfType(smtk::mesh::CellType_MAX, 0); - for (start_off = tess->begin(); start_off != tess->end(); - start_off = tess->nextCellOffset(start_off)) - { - tess->vertexIdsOfCell(start_off, cell_conn); - for (std::size_t j = 0; j < cell_conn.size(); j++) - { - pointsForEdge.emplace_back( - tess->coords()[cell_conn[j] * 3 + 0], tess->coords()[cell_conn[j] * 3 + 1]); - } - cell_conn.clear(); - } - - // We transplant the edge's points into the global point vector according to - // the edge use's orientation. We skip the first point, as it is always a - // duplicate of the last point in the global vector. - if (eu.orientation() == 1) - { - for (auto p = pointsForEdge.begin() + 1; p != pointsForEdge.end(); ++p) - { - points.emplace_back(p->x, p->y); - } - } - else - { - for (auto p = pointsForEdge.rbegin() + 1; p != pointsForEdge.rend(); ++p) - { - points.emplace_back(p->x, p->y); - } - } - pointsForEdge.clear(); - } - - return points; -} - -std::vector ExportDelaunayMesh::operator()( - const smtk::model::Loop& loop, - smtk::mesh::ResourcePtr& resource) const -{ - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - loop, resource, connectivityLength, numberOfCells, numberOfPoints); - - std::vector conn(connectivityLength); - std::vector fpoints(numberOfPoints * 3); - - smtk::mesh::utility::PreAllocatedTessellation ftess(conn.data(), fpoints.data()); - - ftess.disableVTKStyleConnectivity(true); - ftess.disableVTKCellTypes(true); - - smtk::mesh::utility::extractOrderedTessellation(loop, resource, ftess); - - std::vector points; - - for (std::size_t i = 0; i < fpoints.size(); i += 3) - { - points.emplace_back(fpoints[i], fpoints[i + 1]); - } - - // Delaunay polygons do not use a repeated point to denote a loop. - if (points.front() == points.back()) - { - points.pop_back(); - } - - return points; -} -} // namespace io -} // namespace delaunay -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/delaunay/io/ExportDelaunayMesh.h b/smtk/extension/delaunay/io/ExportDelaunayMesh.h deleted file mode 100644 index d321d9c5f3ae51be169e4911d2814278be35a23e..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/io/ExportDelaunayMesh.h +++ /dev/null @@ -1,67 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_extension_delaunay_io_ExportDelaunayMesh_h -#define smtk_extension_delaunay_io_ExportDelaunayMesh_h - -#include "smtk/extension/delaunay/Exports.h" -//forward declarers for Manager and Resource -#include "smtk/PublicPointerDefs.h" - -namespace Delaunay -{ -namespace Shape -{ -class Point; -} -} // namespace Delaunay - -namespace smtk -{ -namespace model -{ -class Loop; -} -} // namespace smtk - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ -namespace io -{ - -/**\brief Export from smtk into a Delaunay mesh - * - */ -class SMTKDELAUNAYEXT_EXPORT ExportDelaunayMesh -{ -public: - ExportDelaunayMesh() = default; - ExportDelaunayMesh(const ExportDelaunayMesh&) = delete; - ExportDelaunayMesh& operator=(const ExportDelaunayMesh&) = delete; - - //Export a model loop with a tessellation into a vector of Delaunay points. - std::vector operator()(const smtk::model::Loop&) const; - - //Export a model loop with a mesh representation stored in the given - // resource into a vector of Delaunay points. - std::vector operator()(const smtk::model::Loop&, smtk::mesh::ResourcePtr&) - const; -}; -} // namespace io -} // namespace delaunay -} // namespace extension -} // namespace smtk - -#endif diff --git a/smtk/extension/delaunay/io/ImportDelaunayMesh.cxx b/smtk/extension/delaunay/io/ImportDelaunayMesh.cxx deleted file mode 100644 index d6dd9fc947bd3da29d72b2fe68ef36e104d1837a..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/io/ImportDelaunayMesh.cxx +++ /dev/null @@ -1,131 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#include "smtk/extension/delaunay/io/ImportDelaunayMesh.h" - -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "Mesh/Mesh.hh" -#include "Shape/Point.hh" -#include "Shape/Polygon.hh" -#include "Shape/PolygonUtilities.hh" - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ -namespace io -{ - -namespace -{ - -template -std::size_t IndexOf(Point& point, const PointContainer& points) -{ - return std::distance(points.begin(), std::find(points.begin(), points.end(), point)); -} -} // namespace - -smtk::mesh::MeshSet ImportDelaunayMesh::operator()( - const Delaunay::Mesh::Mesh& mesh, - smtk::mesh::ResourcePtr meshresource) const -{ - smtk::mesh::InterfacePtr iface = meshresource->interface(); - smtk::mesh::AllocatorPtr alloc = iface->allocator(); - smtk::mesh::Handle firstVertex = 0; - std::vector coordinateMemory; - - if (!alloc->allocatePoints(mesh.GetVertices().size(), firstVertex, coordinateMemory)) - { - return meshresource->createMesh(smtk::mesh::CellSet(meshresource, smtk::mesh::HandleRange())); - } - - std::size_t idx = 0; - for (const auto& p : mesh.GetVertices()) - { - idx = IndexOf(p, mesh.GetVertices()); - coordinateMemory[0][idx] = p.x; - coordinateMemory[1][idx] = p.y; - coordinateMemory[2][idx] = 0.; - } - - smtk::mesh::HandleRange createdCellIds; - smtk::mesh::Handle* connectivity; - - if (!alloc->allocateCells( - smtk::mesh::Triangle, - mesh.GetTriangles().size(), - smtk::mesh::verticesPerCell(smtk::mesh::Triangle), - createdCellIds, - connectivity)) - { - return meshresource->createMesh(smtk::mesh::CellSet(meshresource, smtk::mesh::HandleRange())); - } - - idx = 0; - for (const auto& t : mesh.GetTriangles()) - { - connectivity[idx++] = firstVertex + IndexOf(t.AB().A(), mesh.GetVertices()); - connectivity[idx++] = firstVertex + IndexOf(t.AB().B(), mesh.GetVertices()); - connectivity[idx++] = firstVertex + IndexOf(t.AC().B(), mesh.GetVertices()); - } - - alloc->connectivityModified( - createdCellIds, smtk::mesh::verticesPerCell(smtk::mesh::Triangle), connectivity); - - return meshresource->createMesh(smtk::mesh::CellSet(meshresource, createdCellIds)); -} - -bool ImportDelaunayMesh::operator()(const Delaunay::Mesh::Mesh& mesh, smtk::model::EntityRef& eRef) - const -{ - if (!eRef.isValid() || !eRef.isFace()) - { - return false; - } - - smtk::model::Tessellation* tess = eRef.resetTessellation(); - - tess->coords().resize(mesh.GetVertices().size() * 3); - std::size_t index = 0; - double xyz[3]; - for (const auto& p : mesh.GetVertices()) - { - index = IndexOf(p, mesh.GetVertices()); - xyz[0] = p.x; - xyz[1] = p.y; - xyz[2] = 0.; - tess->setPoint(static_cast(index), xyz); - } - - for (const auto& t : mesh.GetTriangles()) - { - tess->addTriangle( - static_cast(IndexOf(t.AB().A(), mesh.GetVertices())), - static_cast(IndexOf(t.AB().B(), mesh.GetVertices())), - static_cast(IndexOf(t.AC().B(), mesh.GetVertices()))); - } - - auto bounds = Delaunay::Shape::Bounds(mesh.GetPerimeter()); - const double bbox[6] = { bounds[0], bounds[1], bounds[2], bounds[3], 0., 0. }; - eRef.setBoundingBox(bbox); - - return true; -} -} // namespace io -} // namespace delaunay -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/delaunay/io/ImportDelaunayMesh.h b/smtk/extension/delaunay/io/ImportDelaunayMesh.h deleted file mode 100644 index 66191f42923703ac3364112c9a5252be65d594d0..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/io/ImportDelaunayMesh.h +++ /dev/null @@ -1,75 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_extension_delaunay_io_ImportDelaunayMesh_h -#define smtk_extension_delaunay_io_ImportDelaunayMesh_h - -#include "smtk/extension/delaunay/Exports.h" -//forward declarers for Manager and Meshresource -#include "smtk/PublicPointerDefs.h" - -namespace Delaunay -{ -namespace Mesh -{ -class Mesh; -} -} // namespace Delaunay - -namespace smtk -{ -namespace mesh -{ -class MeshSet; -} -} // namespace smtk - -namespace smtk -{ -namespace model -{ -class EntityRef; -} -} // namespace smtk - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ -namespace io -{ - -/**\brief Import a Delaunay mesh into smtk. - * - * This functor converts Delaunay Meshes into smtk::mesh::MeshSets or into - * smtk::model::Tessellations. - */ -class SMTKDELAUNAYEXT_EXPORT ImportDelaunayMesh -{ -public: - ImportDelaunayMesh() = default; - ImportDelaunayMesh(const ImportDelaunayMesh&) = delete; - ImportDelaunayMesh& operator=(const ImportDelaunayMesh&) = delete; - - //Import a Delaunay mesh into an existing meshresource. - smtk::mesh::MeshSet operator()(const Delaunay::Mesh::Mesh&, smtk::mesh::ResourcePtr) const; - - //Import a Delaunay mesh as a tessellation for an entity. - bool operator()(const Delaunay::Mesh::Mesh&, smtk::model::EntityRef&) const; -}; -} // namespace io -} // namespace delaunay -} // namespace extension -} // namespace smtk - -#endif diff --git a/smtk/extension/delaunay/operators/RegisterOperations.cxx b/smtk/extension/delaunay/operators/RegisterOperations.cxx deleted file mode 100644 index 61c13dcb8df9bb3d74351796bdcc459ac1cbe6f7..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/operators/RegisterOperations.cxx +++ /dev/null @@ -1,33 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/extension/delaunay/operators/RegisterOperations.h" - -#include "smtk/extension/delaunay/operators/TessellateFaces.h" -#include "smtk/extension/delaunay/operators/TriangulateFaces.h" - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ - -void registerOperations(smtk::operation::Manager::Ptr& operationManager) -{ - operationManager->registerOperation( - "smtk::extension::delaunay::TessellateFaces"); - operationManager->registerOperation( - "smtk::extension::delaunay::TriangulateFaces"); -} -} // namespace delaunay -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/delaunay/operators/RegisterOperations.h b/smtk/extension/delaunay/operators/RegisterOperations.h deleted file mode 100644 index 46601646a2252b36f3da627f46cad976a4276b67..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/operators/RegisterOperations.h +++ /dev/null @@ -1,28 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_extension_delaunay_RegisterOperations_h -#define smtk_extension_delaunay_RegisterOperations_h - -#include "smtk/extension/delaunay/Exports.h" - -#include "smtk/operation/Manager.h" - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ -SMTKDELAUNAYEXT_EXPORT void registerOperations(smtk::operation::Manager::Ptr&); -} -} // namespace extension -} // namespace smtk - -#endif diff --git a/smtk/extension/delaunay/operators/TessellateFaces.cxx b/smtk/extension/delaunay/operators/TessellateFaces.cxx deleted file mode 100644 index 93abc9f0a8ea764dbb8903b1f9f648549fc305d4..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/operators/TessellateFaces.cxx +++ /dev/null @@ -1,160 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/extension/delaunay/operators/TessellateFaces.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/extension/delaunay/io/ExportDelaunayMesh.h" -#include "smtk/extension/delaunay/io/ImportDelaunayMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/Face.h" -#include "smtk/model/FaceUse.h" -#include "smtk/model/Loop.h" - -#include "Discretization/ConstrainedDelaunayMesh.hh" -#include "Discretization/ExcisePolygon.hh" -#include "Mesh/Mesh.hh" -#include "Shape/Point.hh" -#include "Shape/Polygon.hh" -#include "Shape/PolygonUtilities.hh" -#include "Validation/IsValidPolygon.hh" - -#include "smtk/extension/delaunay/operators/TessellateFaces_xml.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ - -bool TessellateFaces::ableToOperate() -{ - auto associations = this->parameters()->associations(); - auto entities = - associations->as([](smtk::resource::PersistentObjectPtr obj) { - return smtk::model::EntityRef(std::dynamic_pointer_cast(obj)); - }); - - for (auto& eRef : entities) - { - if (!eRef.isValid() || !eRef.isFace() || !eRef.owningModel().isValid()) - { - return false; - } - } - - return smtk::operation::Operation::ableToOperate(); -} - -TessellateFaces::Result TessellateFaces::operateInternal() -{ - auto associations = this->parameters()->associations(); - auto faces = associations->as([](smtk::resource::PersistentObjectPtr obj) { - return smtk::model::Face(std::dynamic_pointer_cast(obj)); - }); - - bool validatePolygons = this->parameters()->findVoid("validate polygons")->isEnabled(); - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - for (auto& face : faces) - { - // get the face use for the face - smtk::model::FaceUse fu = face.positiveUse(); - - // check if we have an exterior loop - smtk::model::Loops exteriorLoops = fu.loops(); - if (exteriorLoops.empty()) - { - // if we don't have loops, there is nothing to mesh - smtkErrorMacro(this->log(), "No loops associated with this face."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // the first loop is the exterior loop - smtk::model::Loop exteriorLoop = exteriorLoops[0]; - - // make a polygon from the points in the loop - smtk::extension::delaunay::io::ExportDelaunayMesh exportToDelaunayMesh; - std::vector points = exportToDelaunayMesh(exteriorLoop); - - // make a polygon validator - Delaunay::Validation::IsValidPolygon isValidPolygon; - - Delaunay::Shape::Polygon p(points); - // if the orientation is not ccw, flip the orientation - if (Delaunay::Shape::Orientation(p) != 1) - { - p = Delaunay::Shape::Polygon(points.rbegin(), points.rend()); - } - - if (validatePolygons && !isValidPolygon(p)) - { - // the polygon is invalid, so we exit with failure - smtkErrorMacro(this->log(), "Outer boundary polygon is invalid."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // discretize the polygon - Delaunay::Discretization::ConstrainedDelaunayMesh discretize; - Delaunay::Mesh::Mesh mesh; - discretize(p, mesh); - - // then we excise each inner loop within the exterior loop - Delaunay::Discretization::ExcisePolygon excise; - for (auto& loop : exteriorLoop.containedLoops()) - { - std::vector points_sub = exportToDelaunayMesh(loop); - Delaunay::Shape::Polygon p_sub(points_sub); - // if the orientation is not ccw, flip the orientation - if (Delaunay::Shape::Orientation(p_sub) != 1) - { - p_sub = Delaunay::Shape::Polygon(points_sub.rbegin(), points_sub.rend()); - } - - if (validatePolygons && !isValidPolygon(p_sub)) - { - // the polygon is invalid, so we exit with failure - smtkErrorMacro(this->log(), "Inner boundary polygon is invalid."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - excise(p_sub, mesh); - } - - // Use the delaunay mesh to retessellate the face - smtk::extension::delaunay::io::ImportDelaunayMesh importFromDelaunayMesh; - importFromDelaunayMesh(mesh, face); - - smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); - modified->appendValue(face.component()); - - result->findComponent("tess_changed")->appendValue(face.component()); - } - - return result; -} - -const char* TessellateFaces::xmlDescription() const -{ - return TessellateFaces_xml; -} -} // namespace delaunay -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/delaunay/operators/TessellateFaces.h b/smtk/extension/delaunay/operators/TessellateFaces.h deleted file mode 100644 index c6f0618cc3534174f714561570f6862c54af44fa..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/operators/TessellateFaces.h +++ /dev/null @@ -1,45 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_extension_delaunay_TessellateFaces_h -#define smtk_extension_delaunay_TessellateFaces_h - -#include "smtk/extension/delaunay/Exports.h" -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ - -/**\brief Tessellate model faces using Delaunay. - * - * This operation updates the smtk::model::Tessellations associated with - * smtk::model::Faces using Delaunay. - */ -class SMTKDELAUNAYEXT_EXPORT TessellateFaces : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::extension::delaunay::TessellateFaces); - smtkCreateMacro(TessellateFaces); - smtkSharedFromThisMacro(smtk::operation::Operation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace delaunay -} // namespace extension -} // namespace smtk - -#endif diff --git a/smtk/extension/delaunay/operators/TessellateFaces.sbt b/smtk/extension/delaunay/operators/TessellateFaces.sbt deleted file mode 100644 index 7b297aa27680ec416465b1b09bddc3f28bbbe28a..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/operators/TessellateFaces.sbt +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - Tessellate model faces. - - Tessellate model faces using Delaunay. - - This operation updates the smtk::mesh::Tessellations associated with - smtk::mesh::Faces using Delaunay. The resulting tessellations are - composed only of the boundary points. - - - - The faces to tessellate. - - - - Ensure the polygons describing the - boundaries are valid before tessellating the faces. - - - - - - - - - - - - - - - - - - - - - diff --git a/smtk/extension/delaunay/operators/TriangulateFaces.cxx b/smtk/extension/delaunay/operators/TriangulateFaces.cxx deleted file mode 100644 index d061406e5d742a8f0913d6ad27b8dd4ee2f0d08d..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/operators/TriangulateFaces.cxx +++ /dev/null @@ -1,180 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/extension/delaunay/operators/TriangulateFaces.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/extension/delaunay/io/ExportDelaunayMesh.h" -#include "smtk/extension/delaunay/io/ImportDelaunayMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/Face.h" -#include "smtk/model/FaceUse.h" -#include "smtk/model/Loop.h" - -#include "Discretization/ConstrainedDelaunayMesh.hh" -#include "Discretization/ExcisePolygon.hh" -#include "Mesh/Mesh.hh" -#include "Shape/Point.hh" -#include "Shape/Polygon.hh" -#include "Shape/PolygonUtilities.hh" -#include "Validation/IsValidPolygon.hh" - -#include "smtk/extension/delaunay/operators/TriangulateFaces_xml.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ - -bool TriangulateFaces::ableToOperate() -{ - auto associations = this->parameters()->associations(); - auto entities = - associations->as([](smtk::resource::PersistentObjectPtr obj) { - return smtk::model::EntityRef(std::dynamic_pointer_cast(obj)); - }); - - for (auto& eRef : entities) - { - if (!eRef.isValid() || !eRef.isFace() || !eRef.owningModel().isValid()) - { - return false; - } - } - - return smtk::operation::Operation::ableToOperate(); -} - -TriangulateFaces::Result TriangulateFaces::operateInternal() -{ - auto associations = this->parameters()->associations(); - auto faces = associations->as([](smtk::resource::PersistentObjectPtr obj) { - return smtk::model::Face(std::dynamic_pointer_cast(obj)); - }); - - bool validatePolygons = this->parameters()->findVoid("validate polygons")->isEnabled(); - - // construct a meshresource and associate it with the face's model - smtk::model::Resource::Ptr resource = - std::dynamic_pointer_cast(faces[0].component()->resource()); - smtk::mesh::ResourcePtr meshresource = smtk::mesh::Resource::create(); - meshresource->setModelResource(faces[0].resource()); - meshresource->associateToModel(faces[0].model().entity()); - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - for (auto& face : faces) - { - // get the face use for the face - smtk::model::FaceUse fu = face.positiveUse(); - - // check if we have an exterior loop - smtk::model::Loops exteriorLoops = fu.loops(); - if (exteriorLoops.empty()) - { - // if we don't have loops, there is nothing to mesh - smtkErrorMacro(this->log(), "No loops associated with this face."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // the first loop is the exterior loop - smtk::model::Loop exteriorLoop = exteriorLoops[0]; - - // make a polygon from the points in the loop - smtk::extension::delaunay::io::ExportDelaunayMesh exportToDelaunayMesh; - std::vector points = exportToDelaunayMesh(exteriorLoop); - - // make a polygon validator - Delaunay::Validation::IsValidPolygon isValidPolygon; - - Delaunay::Shape::Polygon p(points); - // if the orientation is not ccw, flip the orientation - if (Delaunay::Shape::Orientation(p) != 1) - { - p = Delaunay::Shape::Polygon(points.rbegin(), points.rend()); - } - - if (validatePolygons && !isValidPolygon(p)) - { - // the polygon is invalid, so we exit with failure - smtkErrorMacro(this->log(), "Outer boundary polygon is invalid."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // discretize the polygon - Delaunay::Discretization::ConstrainedDelaunayMesh discretize; - Delaunay::Mesh::Mesh mesh; - discretize(p, mesh); - - // then we excise each inner loop within the exterior loop - Delaunay::Discretization::ExcisePolygon excise; - for (auto& loop : exteriorLoop.containedLoops()) - { - std::vector points_sub = exportToDelaunayMesh(loop); - Delaunay::Shape::Polygon p_sub(points_sub); - // if the orientation is not ccw, flip the orientation - if (Delaunay::Shape::Orientation(p_sub) != 1) - { - p_sub = Delaunay::Shape::Polygon(points_sub.rbegin(), points_sub.rend()); - } - - if (validatePolygons && !isValidPolygon(p_sub)) - { - // the polygon is invalid, so we exit with failure - smtkErrorMacro(this->log(), "Inner boundary polygon is invalid."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - excise(p_sub, mesh); - } - - // populate the meshresource - smtk::extension::delaunay::io::ImportDelaunayMesh importFromDelaunayMesh; - smtk::mesh::MeshSet meshSet = importFromDelaunayMesh(mesh, meshresource); - if (!meshSet.is_empty()) - { - meshresource->setAssociation(face, meshSet); - meshSet.setName(face.name()); - } - meshSet.mergeCoincidentContactPoints(); - - smtk::attribute::ResourceItem::Ptr meshresourceItem = result->findResource("meshresource"); - meshresourceItem->setValue(std::static_pointer_cast(meshresource)); - - // we flag the model that owns this face as modified so that a mesh - // meshresource for the entire model is placed in ModelBuilder's model - // tree. In the future, ModelBuilder should be able to handle meshes - // on model entities (rather than entire models). - smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); - modified->setValue(face.component()); - result->findComponent("mesh_created")->appendValue(face.owningModel().component()); - } - - return result; -} - -const char* TriangulateFaces::xmlDescription() const -{ - return TriangulateFaces_xml; -} -} // namespace delaunay -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/delaunay/operators/TriangulateFaces.h b/smtk/extension/delaunay/operators/TriangulateFaces.h deleted file mode 100644 index b9e964e74e9e4a0660b3813079df07ccdb0e6a62..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/operators/TriangulateFaces.h +++ /dev/null @@ -1,48 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_extension_delaunay_TriangulateFaces_h -#define smtk_extension_delaunay_TriangulateFaces_h - -#include "smtk/extension/delaunay/Exports.h" -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace extension -{ -namespace delaunay -{ - -/**\brief Triangulate model faces into meshes using Delaunay. - * - * This operation creates smtk::mesh::MeshSets associated with - * smtk::mesh::Faces using Delaunay. The MeshSets reside in the - * smtk::mesh::Resource with the same UUID as the Faces' model. If this - * resource does not yet exist during the construction of the meshes, it is - * created and populated with the MeshSets. - */ -class SMTKDELAUNAYEXT_EXPORT TriangulateFaces : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::extension::delaunay::TriangulateFaces); - smtkCreateMacro(TriangulateFaces); - smtkSharedFromThisMacro(smtk::operation::Operation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace delaunay -} // namespace extension -} // namespace smtk - -#endif diff --git a/smtk/extension/delaunay/operators/TriangulateFaces.sbt b/smtk/extension/delaunay/operators/TriangulateFaces.sbt deleted file mode 100644 index 3663d522cb51fb2fbf85c5589ca7276db8b2362d..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/operators/TriangulateFaces.sbt +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - Triangulate model faces. - - Triangulate model faces into a mesh using Delaunay. - - This operation creates smtk::mesh::MeshSets associated with - smtk::mesh::Faces using Delaunay. The MeshSets reside in a new - smtk::mesh::Resource associated with the faces' model. The - resulting triangulation is composed only of the boundary points. - - - - The faces to triangulate. - - - - Ensure the polygons describing the - boundaries are valid before triangulating the faces. - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/smtk/extension/delaunay/plugin/CMakeLists.txt b/smtk/extension/delaunay/plugin/CMakeLists.txt deleted file mode 100644 index 58b9a1104b8e5aa7cf6bf1b9981c51834df45d1e..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/plugin/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -smtk_add_plugin(smtkDelaunayPlugin - REGISTRAR smtk::extension::delaunay::Registrar - MANAGERS smtk::operation::Manager - PARAVIEW_PLUGIN_ARGS - VERSION "1.0") -target_link_libraries(smtkDelaunayPlugin - PRIVATE - smtkDelaunayExt) diff --git a/smtk/extension/delaunay/plugin/paraview.plugin b/smtk/extension/delaunay/plugin/paraview.plugin deleted file mode 100644 index 53bfdba55ed79b9093678d595fcc3830894f950c..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/plugin/paraview.plugin +++ /dev/null @@ -1,4 +0,0 @@ -NAME - smtkDelaunayPlugin -DESCRIPTION - SMTK Delaunay extention plugin for ParaView diff --git a/smtk/extension/delaunay/pybind11/CMakeLists.txt b/smtk/extension/delaunay/pybind11/CMakeLists.txt deleted file mode 100644 index c9958838e8a20781b4a057d4dac8d43154ceef94..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/pybind11/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -set(library_name "_smtkPybindExtensionDelaunay") -set(module_path "extension/delaunay") -set(build_path "${CMAKE_BINARY_DIR}/${SMTK_PYTHON_MODULEDIR}/smtk/${module_path}") -set(install_path "${SMTK_PYTHON_MODULEDIR}/smtk/${module_path}") - -pybind11_add_module(${library_name} PybindExtensionDelaunay.cxx) -target_include_directories(${library_name} PUBLIC - $ - ) -target_link_libraries(${library_name} LINK_PUBLIC smtkCore smtkDelaunayExt) -set_target_properties(${library_name} - PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${build_path}" - COMPILE_FLAGS ${SMTK_PYBIND11_FLAGS} - ) - -# Install library -install(TARGETS ${library_name} DESTINATION "${install_path}") - -# Create and install module __init__.py -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py" - "${build_path}/__init__.py" @ONLY - ) - -install( - FILES "${build_path}/__init__.py" - DESTINATION "${install_path}" - ) diff --git a/smtk/extension/delaunay/pybind11/PybindExtensionDelaunay.cxx b/smtk/extension/delaunay/pybind11/PybindExtensionDelaunay.cxx deleted file mode 100644 index 3f06902fd71a3647956544e31ea766a0b23b0874..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/pybind11/PybindExtensionDelaunay.cxx +++ /dev/null @@ -1,38 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include -SMTK_THIRDPARTY_POST_INCLUDE - -#include - -namespace py = pybind11; - -template -using PySharedPtrClass = py::class_, Args...>; - -#include "PybindRegistrar.h" -#include "PybindTessellateFaces.h" -#include "PybindTriangulateFaces.h" - -PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); - -PYBIND11_MODULE(_smtkPybindExtensionDelaunay, delaunay) -{ - delaunay.doc() = ""; - - py::class_< smtk::extension::delaunay::TessellateFaces, smtk::operation::XMLOperation > smtk_extension_delaunay_TessellateFaces = pybind11_init_smtk_extension_delaunay_TessellateFaces(delaunay); - py::class_< smtk::extension::delaunay::TriangulateFaces, smtk::operation::XMLOperation > smtk_extension_delaunay_TriangulateFaces = pybind11_init_smtk_extension_delaunay_TriangulateFaces(delaunay); - - py::class_< smtk::extension::delaunay::Registrar > smtk_extension_delaunay_Registrar = pybind11_init_smtk_extension_delaunay_Registrar(delaunay); -} diff --git a/smtk/extension/delaunay/pybind11/PybindRegistrar.h b/smtk/extension/delaunay/pybind11/PybindRegistrar.h deleted file mode 100644 index 0af4a2075988f500c4753640ee119331cbaa4967..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/pybind11/PybindRegistrar.h +++ /dev/null @@ -1,31 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_extension_delaunay_Registrar_h -#define pybind_smtk_extension_delaunay_Registrar_h - -#include - -#include "smtk/extension/delaunay/Registrar.h" - -namespace py = pybind11; - -inline py::class_< smtk::extension::delaunay::Registrar > pybind11_init_smtk_extension_delaunay_Registrar(py::module &m) -{ - py::class_< smtk::extension::delaunay::Registrar > instance(m, "Registrar"); - instance - .def(py::init<>()) - .def_static("registerTo", (void (*)(std::shared_ptr<::smtk::operation::Manager> const &)) &smtk::extension::delaunay::Registrar::registerTo) - .def_static("unregisterFrom", (void (*)(std::shared_ptr<::smtk::operation::Manager> const &)) &smtk::extension::delaunay::Registrar::unregisterFrom) - ; - return instance; -} - -#endif diff --git a/smtk/extension/delaunay/pybind11/PybindTessellateFaces.h b/smtk/extension/delaunay/pybind11/PybindTessellateFaces.h deleted file mode 100644 index e5450bed20f14f674e9979560d53423f68dad796..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/pybind11/PybindTessellateFaces.h +++ /dev/null @@ -1,31 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_extension_delaunay_TessellateFaces_h -#define pybind_smtk_extension_delaunay_TessellateFaces_h - -#include - -#include "smtk/extension/delaunay/operators/TessellateFaces.h" - -inline PySharedPtrClass< smtk::extension::delaunay::TessellateFaces, smtk::operation::XMLOperation > pybind11_init_smtk_extension_delaunay_TessellateFaces(py::module &m) -{ - PySharedPtrClass< smtk::extension::delaunay::TessellateFaces, smtk::operation::XMLOperation > instance(m, "TessellateFaces"); - instance - .def_static("create", (std::shared_ptr (*)()) &smtk::extension::delaunay::TessellateFaces::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::extension::delaunay::TessellateFaces::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::extension::delaunay::TessellateFaces::*)()) &smtk::extension::delaunay::TessellateFaces::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::extension::delaunay::TessellateFaces::*)() const) &smtk::extension::delaunay::TessellateFaces::shared_from_this) - .def("ableToOperate", &smtk::extension::delaunay::TessellateFaces::ableToOperate) - ; - return instance; -} - -#endif diff --git a/smtk/extension/delaunay/pybind11/PybindTriangulateFaces.h b/smtk/extension/delaunay/pybind11/PybindTriangulateFaces.h deleted file mode 100644 index 3d5630a1a99f55672d748d68a0dd7928247154dd..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/pybind11/PybindTriangulateFaces.h +++ /dev/null @@ -1,33 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_extension_delaunay_TriangulateFaces_h -#define pybind_smtk_extension_delaunay_TriangulateFaces_h - -#include - -#include "smtk/extension/delaunay/operators/TriangulateFaces.h" - -#include "smtk/operation/XMLOperation.h" - -inline PySharedPtrClass< smtk::extension::delaunay::TriangulateFaces, smtk::operation::XMLOperation > pybind11_init_smtk_extension_delaunay_TriangulateFaces(py::module &m) -{ - PySharedPtrClass< smtk::extension::delaunay::TriangulateFaces, smtk::operation::XMLOperation > instance(m, "TriangulateFaces"); - instance - .def_static("create", (std::shared_ptr (*)()) &smtk::extension::delaunay::TriangulateFaces::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::extension::delaunay::TriangulateFaces::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::extension::delaunay::TriangulateFaces::*)()) &smtk::extension::delaunay::TriangulateFaces::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::extension::delaunay::TriangulateFaces::*)() const) &smtk::extension::delaunay::TriangulateFaces::shared_from_this) - .def("ableToOperate", &smtk::extension::delaunay::TriangulateFaces::ableToOperate) - ; - return instance; -} - -#endif diff --git a/smtk/extension/delaunay/pybind11/__init__.py b/smtk/extension/delaunay/pybind11/__init__.py deleted file mode 100644 index 205c782a24153e341a1cf0334a0d42f3215e4f4c..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/pybind11/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - -from ._smtkPybindExtensionDelaunay import * diff --git a/smtk/extension/delaunay/testing/CMakeLists.txt b/smtk/extension/delaunay/testing/CMakeLists.txt deleted file mode 100644 index 83305da3a2914ab6d4dec88c168fc7037bd7553e..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/testing/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_subdirectory(cxx) - -if(SMTK_ENABLE_PYTHON_WRAPPING) - add_subdirectory(python) -endif() diff --git a/smtk/extension/delaunay/testing/cxx/CMakeLists.txt b/smtk/extension/delaunay/testing/cxx/CMakeLists.txt deleted file mode 100644 index fb4fe68c32c51020fe0b4d48d38b8847549f96fb..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/testing/cxx/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -#============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -#============================================================================= - -set(unit_tests -) - -set(unit_tests_which_require_data -) - -if(SMTK_ENABLE_POLYGON_SESSION) - list(APPEND unit_tests_which_require_data - UnitTestTriangulateFaces.cxx - UnitTestTessellateFaces.cxx - ) - list(APPEND extra_libs - smtkPolygonSession - ) -endif() - -smtk_unit_tests( - LABEL "ExtDelaunay" - SOURCES ${unit_tests} - SOURCES_REQUIRE_DATA ${unit_tests_which_require_data} - LIBRARIES - smtkCore - smtkDelaunayExt - smtkCoreModelTesting - ${extra_libs} - ${Boost_LIBRARIES} -) diff --git a/smtk/extension/delaunay/testing/cxx/UnitTestTessellateFaces.cxx b/smtk/extension/delaunay/testing/cxx/UnitTestTessellateFaces.cxx deleted file mode 100644 index 7a206b2580791acda7642dc5809900fe003cf109..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/testing/cxx/UnitTestTessellateFaces.cxx +++ /dev/null @@ -1,168 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" - -#include "smtk/session/polygon/Resource.h" -#include "smtk/session/polygon/operators/LegacyRead.h" - -#include "smtk/extension/delaunay/operators/TessellateFaces.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/testing/cxx/helpers.h" -#include "smtk/mesh/utility/ExtractTessellation.h" - -#include "smtk/model/Edge.h" -#include "smtk/model/EntityIterator.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/FaceUse.h" -#include "smtk/model/Loop.h" - -#include - -namespace -{ - -//SMTK_DATA_DIR and SMTK_SCRATCH_DIR are defined by cmake -std::string data_root = SMTK_DATA_DIR; -std::string scratch_root = SMTK_SCRATCH_DIR; - -void removeRefsWithoutTess(smtk::model::EntityRefs& ents) -{ - smtk::model::EntityIterator it; - it.traverse(ents.begin(), ents.end(), smtk::model::ITERATE_BARE); - std::vector withoutTess; - for (it.begin(); !it.isAtEnd(); ++it) - { - if (!it->hasTessellation()) - { - withoutTess.push_back(it.current()); - } - } - - typedef std::vector::const_iterator c_it; - for (c_it i = withoutTess.begin(); i < withoutTess.end(); ++i) - { - ents.erase(*i); - } -} -} // namespace - -int UnitTestTessellateFaces(int /*unused*/, char** const /*unused*/) -{ - smtk::session::polygon::Resource::Ptr resource; - - { - // Create an import operator - smtk::session::polygon::LegacyRead::Ptr readOp = smtk::session::polygon::LegacyRead::create(); - if (!readOp) - { - std::cerr << "No read operator\n"; - return 1; - } - - std::string file_path(data_root); - file_path += "/mesh/2d/boxWithHole.smtk"; - - std::ifstream file(file_path.c_str()); - if (file.good()) - { //just make sure the file exists - file.close(); - - readOp->parameters()->findFile("filename")->setValue(file_path); - smtk::session::polygon::LegacyRead::Result result = readOp->operate(); - if ( - result->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Could not read smtk model!\n"; - return 1; - } - - resource = smtk::dynamic_pointer_cast( - result->findResource("resourcesCreated")->value(0)); - } - } - - { - smtk::model::EntityRefs currentEnts = - resource->entitiesMatchingFlagsAs(smtk::model::FACE); - removeRefsWithoutTess(currentEnts); - if (currentEnts.empty()) - { - std::cerr << "No tessellation!" << std::endl; - return 1; - } - - // We only extract the first face - auto eRef = *currentEnts.begin(); - - const smtk::model::Face& face = eRef.as(); - - if (!face.isValid()) - { - std::cerr << "Face is invald\n"; - return 1; - } - - smtk::extension::delaunay::TessellateFaces::Ptr tessellateFacesOp = - smtk::extension::delaunay::TessellateFaces::create(); - if (!tessellateFacesOp) - { - std::cerr << "No tessellate faces operator\n"; - return 1; - } - - tessellateFacesOp->parameters()->associateEntity(face); - - if (!tessellateFacesOp->ableToOperate()) - { - std::cerr << "Tessellate faces operator cannot operate\n"; - return 1; - } - - smtk::extension::delaunay::TessellateFaces::Result result = tessellateFacesOp->operate(); - if ( - result->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Tessellate faces operator failed\n"; - return 1; - } - - smtk::model::Face tessellatedFace = - result->findComponent("tess_changed")->valueAs(); - if (face != tessellatedFace) - { - std::cerr << "Tessellate faces operator did something strange\n"; - return 1; - } - - const smtk::model::Tessellation* tess = tessellatedFace.hasTessellation(); - if (!tess) - { - std::cerr << "Tessellate faces operator did not create a tessellation\n"; - return 1; - } - - if (tess->coords().size() != 8 * 3 || tess->conn().size() != 8 * 4) - { - std::cerr << "Tessellate faces operator did something wrong\n"; - return 1; - } - } - - return 0; -} diff --git a/smtk/extension/delaunay/testing/cxx/UnitTestTriangulateFaces.cxx b/smtk/extension/delaunay/testing/cxx/UnitTestTriangulateFaces.cxx deleted file mode 100644 index 2165ca635e7118a34689dc99d0a1c49a086bbab1..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/testing/cxx/UnitTestTriangulateFaces.cxx +++ /dev/null @@ -1,169 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" - -#include "smtk/session/polygon/Resource.h" -#include "smtk/session/polygon/operators/LegacyRead.h" - -#include "smtk/extension/delaunay/operators/TriangulateFaces.h" - -#include "smtk/io/ExportMesh.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/testing/cxx/helpers.h" -#include "smtk/mesh/utility/ExtractTessellation.h" - -#include "smtk/model/Edge.h" -#include "smtk/model/EntityIterator.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/FaceUse.h" -#include "smtk/model/Loop.h" -#include "smtk/model/Resource.h" - -#include - -namespace -{ - -//SMTK_DATA_DIR and SMTK_SCRATCH_DIR are defined by cmake -std::string data_root = SMTK_DATA_DIR; -std::string scratch_root = SMTK_SCRATCH_DIR; - -void removeRefsWithoutTess(smtk::model::EntityRefs& ents) -{ - smtk::model::EntityIterator it; - it.traverse(ents.begin(), ents.end(), smtk::model::ITERATE_BARE); - std::vector withoutTess; - for (it.begin(); !it.isAtEnd(); ++it) - { - if (!it->hasTessellation()) - { - withoutTess.push_back(it.current()); - } - } - - typedef std::vector::const_iterator c_it; - for (c_it i = withoutTess.begin(); i < withoutTess.end(); ++i) - { - ents.erase(*i); - } -} -} // namespace - -int UnitTestTriangulateFaces(int /*unused*/, char** const /*unused*/) -{ - smtk::session::polygon::Resource::Ptr resource; - - { - // Create an import operator - smtk::session::polygon::LegacyRead::Ptr readOp = smtk::session::polygon::LegacyRead::create(); - if (!readOp) - { - std::cerr << "No read operator\n"; - return 1; - } - - std::string file_path(data_root); - file_path += "/mesh/2d/boxWithHole.smtk"; - - std::ifstream file(file_path.c_str()); - if (file.good()) - { //just make sure the file exists - file.close(); - - readOp->parameters()->findFile("filename")->setValue(file_path); - smtk::session::polygon::LegacyRead::Result result = readOp->operate(); - if ( - result->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Could not read smtk model!\n"; - return 1; - } - - resource = smtk::dynamic_pointer_cast( - result->findResource("resourcesCreated")->value(0)); - } - } - - { - smtk::model::EntityRefs currentEnts = - resource->entitiesMatchingFlagsAs(smtk::model::FACE); - removeRefsWithoutTess(currentEnts); - if (currentEnts.empty()) - { - std::cerr << "No tessellation!" << std::endl; - return 1; - } - - // We only extract the first face - auto eRef = *currentEnts.begin(); - - const smtk::model::Face& face = eRef.as(); - - if (!face.isValid()) - { - std::cerr << "Face is invald\n"; - return 1; - } - - smtk::extension::delaunay::TriangulateFaces::Ptr triangulateFacesOp = - smtk::extension::delaunay::TriangulateFaces::create(); - if (!triangulateFacesOp) - { - std::cerr << "No triangulate faces operator\n"; - return 1; - } - - triangulateFacesOp->parameters()->associateEntity(face); - - if (!triangulateFacesOp->ableToOperate()) - { - std::cerr << "Triangulate face operator cannot operate\n"; - return 1; - } - - smtk::extension::delaunay::TriangulateFaces::Result result = triangulateFacesOp->operate(); - if ( - result->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Triangulate face operator failed\n"; - return 1; - } - - smtk::model::Model meshedModel = - result->findComponent("mesh_created")->valueAs(); - - if (face.owningModel() != meshedModel) - { - std::cerr << "Triangulate face operator did something strange\n"; - return 1; - } - - smtk::attribute::ResourceItem::Ptr resourceItem = result->findResource("meshresource"); - smtk::mesh::ResourcePtr triangulatedFace = - std::dynamic_pointer_cast(resourceItem->value()); - - if (triangulatedFace->points().size() != 8 || triangulatedFace->cells().size() != 8) - { - std::cerr << "Triangulate faces operator did something wrong\n"; - return 1; - } - } - - return 0; -} diff --git a/smtk/extension/delaunay/testing/python/CMakeLists.txt b/smtk/extension/delaunay/testing/python/CMakeLists.txt deleted file mode 100644 index 568c0814031c4c3424176e9f7c8ef76aebb0e24b..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/testing/python/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -set(smtkDelaunayExtPythonDataTests) - -if (SMTK_ENABLE_POLYGON_SESSION) - set(smtkDelaunayExtPythonDataTests - ${smtkDelaunayExtPythonDataTests} - unitTestTessellateFaces - unitTestTriangulateFaces - ) -endif() - -if (SMTK_DATA_DIR) - foreach (test ${smtkDelaunayExtPythonDataTests}) - smtk_add_test_python(${test}Py ${test}.py - --data-dir=${SMTK_DATA_DIR}) - set_tests_properties(${test}Py PROPERTIES LABELS "ExtDelaunay") - endforeach() -endif() diff --git a/smtk/extension/delaunay/testing/python/unitTestTessellateFaces.py b/smtk/extension/delaunay/testing/python/unitTestTessellateFaces.py deleted file mode 100644 index 325e7b521588dec3fc1ca35032a3ebec55331964..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/testing/python/unitTestTessellateFaces.py +++ /dev/null @@ -1,60 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= -import os -import sys -import unittest -import smtk -import smtk.mesh -import smtk.model -import smtk.extension.delaunay -import smtk.session.polygon -import smtk.testing - - -class UnitTessellateFaces(smtk.testing.TestCase): - - def setUp(self): - # Set up the path to the test's input file - modelFile = os.path.join( - smtk.testing.DATA_DIR, 'mesh', '2d', 'boxWithHole.smtk') - - # Load the input file - loadOp = smtk.session.polygon.LegacyRead.create() - loadOp.parameters().find('filename').setValue(modelFile) - loadRes = loadOp.operate() - - # Access the resource - self.resource = smtk.model.Resource.CastTo( - loadRes.find('resourcesCreated').value()) - - def testMeshing2D(self): - face = self.resource.findEntitiesOfType(int(smtk.model.FACE))[0] - tessellateFace = smtk.extension.delaunay.TessellateFaces.create() - tessellateFace.parameters().associateEntity(face) - result = tessellateFace.operate() - tessellatedFace = face.hasTessellation() - assert (len(tessellatedFace.coords()) == 8 * 3) - assert (len(tessellatedFace.conn()) == 8 * 4) - - if self.interactive() and self.haveVTK() and self.haveVTKExtension(): - self.startRenderTest() - face.setFloatProperty('color', [0, 1, 0, 1]) - self.addModelToScene(face.model()) - cam = self.renderer.GetActiveCamera() - self.renderer.ResetCamera() - self.renderWindow.Render() - self.interact() - - -if __name__ == '__main__': - smtk.testing.process_arguments() - unittest.main() diff --git a/smtk/extension/delaunay/testing/python/unitTestTriangulateFaces.py b/smtk/extension/delaunay/testing/python/unitTestTriangulateFaces.py deleted file mode 100644 index 29446be6cbafe4fcdb7daf7ba8f1bd1b49438a0b..0000000000000000000000000000000000000000 --- a/smtk/extension/delaunay/testing/python/unitTestTriangulateFaces.py +++ /dev/null @@ -1,60 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= -import os -import sys -import unittest -import smtk -import smtk.mesh -import smtk.model -import smtk.extension.delaunay -import smtk.operation -import smtk.session.polygon -import smtk.testing - - -class UnitTriangulateFaces(smtk.testing.TestCase): - - def setUp(self): - # Set up the path to the test's input file - modelFile = os.path.join( - smtk.testing.DATA_DIR, 'mesh', '2d', 'boxWithHole.smtk') - - # Load the input file - loadOp = smtk.session.polygon.LegacyRead.create() - loadOp.parameters().find('filename').setValue(modelFile) - loadRes = loadOp.operate() - - # Access the resource - self.resource = smtk.model.Resource.CastTo( - loadRes.find('resourcesCreated').value()) - - def testMeshing2D(self): - face = self.resource.findEntitiesOfType(int(smtk.model.FACE))[0] - triangulateFace = smtk.extension.delaunay.TriangulateFaces.create() - triangulateFace.parameters().associateEntity(face) - result = triangulateFace.operate() - triangulatedFace = result.find("meshresource").value() - assert (triangulatedFace.points().size() == 8) - assert (triangulatedFace.cells().size() == 8) - - if self.interactive() and self.haveVTK() and self.haveVTKExtension(): - self.startRenderTest() - self.addMeshToScene(triangulatedFace.meshes()) - cam = self.renderer.GetActiveCamera() - self.renderer.ResetCamera() - self.renderWindow.Render() - self.interact() - - -if __name__ == '__main__': - smtk.testing.process_arguments() - unittest.main() diff --git a/smtk/extension/matplotlib/CMakeLists.txt b/smtk/extension/matplotlib/CMakeLists.txt deleted file mode 100644 index 24385f6edf76fe8754d14e291147751c36e0e4fc..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -set(source - Registrar.cxx - ) -set(headers - Registrar.h - ) -set(matplotlibPySrcs - __init__.py - render_mesh.py - ) - -set(matplotlib_pymodulefiles) - -set(matplotlib_pyxmlfiles) -# TODO consider updating to smtk_encode_file() if matplotlib is re-enabled. -smtk_pyoperation_xml( - "${CMAKE_CURRENT_SOURCE_DIR}/render_mesh.sbt" matplotlib_pyxmlfiles - ) - -foreach(pyfile ${matplotlibPySrcs}) - get_filename_component(filename ${pyfile} NAME) - file(RELATIVE_PATH relativedir ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/${pyfile}" - "${CMAKE_BINARY_DIR}/${SMTK_PYTHON_MODULEDIR}/${relativedir}/${filename}" @ONLY - ) - list(APPEND matplotlib_pymodulefiles - "${CMAKE_BINARY_DIR}/${SMTK_PYTHON_MODULEDIR}/${relativedir}/${filename}") -endforeach() - -foreach(pyfile ${matplotlib_pyxmlfiles}) - get_filename_component(filename ${pyfile} NAME) - file(RELATIVE_PATH relativefile ${PROJECT_BINARY_DIR} ${pyfile}) - configure_file( - "${pyfile}" - "${CMAKE_BINARY_DIR}/${SMTK_PYTHON_MODULEDIR}/${relativefile}" @ONLY - ) - list(APPEND matplotlib_pymodulefiles - "${CMAKE_BINARY_DIR}/${SMTK_PYTHON_MODULEDIR}/${relativefile}") -endforeach() - -file(RELATIVE_PATH relativedir ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) -install( - FILES ${matplotlib_pymodulefiles} - DESTINATION "${SMTK_PYTHON_MODULEDIR}/${relativedir}" - ) - -file(RELATIVE_PATH relativedir ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) -install( - FILES ${matplotlib_pymodulefiles} - DESTINATION "${SMTK_PYTHON_MODULEDIR}/${relativedir}" - ) - -add_library(smtkMatplotlibExt ${source}) -target_link_libraries(smtkMatplotlibExt - PRIVATE - smtkCore -) - -smtk_export_header(smtkMatplotlibExt Exports.h) - -smtk_install_library(smtkMatplotlibExt) - -if (SMTK_ENABLE_PARAVIEW_SUPPORT) - set_property(GLOBAL APPEND - PROPERTY _smtk_plugin_files "${CMAKE_CURRENT_SOURCE_DIR}/plugin/paraview.plugin") -endif() - -if (SMTK_ENABLE_TESTING) - add_subdirectory(testing) -endif() diff --git a/smtk/extension/matplotlib/Registrar.cxx b/smtk/extension/matplotlib/Registrar.cxx deleted file mode 100644 index 4fc44ede73678e548678634d7e89bba372aa7484..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/Registrar.cxx +++ /dev/null @@ -1,35 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/extension/matplotlib/Registrar.h" - -#include "smtk/operation/RegisterPythonOperations.h" - -namespace smtk -{ -namespace extension -{ -namespace matplotlib -{ - -void Registrar::registerTo(const smtk::operation::Manager::Ptr& operationManager) -{ - smtk::operation::registerPythonOperations( - operationManager, "smtk.extension.matplotlib.render_mesh"); -} - -void Registrar::unregisterFrom(const smtk::operation::Manager::Ptr& operationManager) -{ - operationManager->unregisterOperation("smtk.extension.matplotlib.render_mesh.render_mesh"); -} -} // namespace matplotlib -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/matplotlib/Registrar.h b/smtk/extension/matplotlib/Registrar.h deleted file mode 100644 index 2255648d0bdbdd20f36c066d6685c84b8c59d3f8..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/Registrar.h +++ /dev/null @@ -1,37 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_extension_matplotlib_Registrar_h -#define smtk_extension_matplotlib_Registrar_h - -#include "smtk/extension/matplotlib/Exports.h" - -#include "smtk/operation/Manager.h" -#include "smtk/operation/Registrar.h" -#include "smtk/session/mesh/Registrar.h" - -namespace smtk -{ -namespace extension -{ -namespace matplotlib -{ -class SMTKMATPLOTLIBEXT_EXPORT Registrar -{ -public: - using Dependencies = std::tuple; - - static void registerTo(const smtk::operation::Manager::Ptr&); - static void unregisterFrom(const smtk::operation::Manager::Ptr&); -}; -} // namespace matplotlib -} // namespace extension -} // namespace smtk - -#endif diff --git a/smtk/extension/matplotlib/__init__.py b/smtk/extension/matplotlib/__init__.py deleted file mode 100644 index 4b217cd501083a2573c3c5877b7c4a3036c999e2..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - -from . import render_mesh - -import sys -import inspect -import smtk -import smtk.operation - - -def registerOperations(operationManager): - for name, obj in inspect.getmembers(render_mesh): - if inspect.isclass(obj) and issubclass(obj, smtk.operation.Operation): - operationManager.registerOperation( - render_mesh.__name__, obj.__name__) diff --git a/smtk/extension/matplotlib/plugin/CMakeLists.txt b/smtk/extension/matplotlib/plugin/CMakeLists.txt deleted file mode 100644 index 70683a451ee871eeb50f8de5d099efcf742af818..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/plugin/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -smtk_add_plugin(smtkMatplotlibPlugin - REGISTRAR smtk::extension::matplotlib::Registrar - MANAGERS smtk::operation::Manager - PARAVIEW_PLUGIN_ARGS - VERSION 1.0) -target_link_libraries(smtkMatplotlibPlugin - PRIVATE - smtkMatplotlibExt) diff --git a/smtk/extension/matplotlib/plugin/paraview.plugin b/smtk/extension/matplotlib/plugin/paraview.plugin deleted file mode 100644 index 52827fca57c7078da08391a83394d4b7ec594703..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/plugin/paraview.plugin +++ /dev/null @@ -1,4 +0,0 @@ -NAME - smtkMatplotlibPlugin -DESCRIPTION - SMTK matplotlib plugin for ParaView diff --git a/smtk/extension/matplotlib/render_mesh.py b/smtk/extension/matplotlib/render_mesh.py deleted file mode 100644 index 10f3120775a3935cbcc49ed49ad201ea7302daad..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/render_mesh.py +++ /dev/null @@ -1,102 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - -""" render_mesh.py: - -Render a 2-dmensional mesh using matplotlib. - -""" -# use the 'sites' module to set up our path so we can find matplotlib -import site # nopep8 -site.main() # nopep8 - -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.tri as tri -import matplotlib - -import smtk.operation -import smtk.mesh -import smtk.io -import smtk.attribute -import smtk -from . import render_mesh_xml - - -class RenderMesh(smtk.operation.Operation): - - def __init__(self): - smtk.operation.Operation.__init__(self) - - def name(self): - return "render mesh" - - def operateInternal(self): - # Access the mesh and filename from the parameters - mesh = smtk.mesh.Component.CastTo( - self.parameters().associations().objectValue(0)).mesh() - filename = self.parameters().find('filename').value(0) - - # Collect point coordinates - coords = [] - - class GetPoints(smtk.mesh.PointForEach): - - def __init__(self): - smtk.mesh.PointForEach.__init__(self) - - def forPoints(self, pointIds, xyz, doModify): - for pId in range(pointIds.size()): - coords.insert(pId, [xyz[3 * pId + i] for i in range(3)]) - - getPoints = GetPoints() - smtk.mesh.for_each(mesh.points(), getPoints) - - # Collect triangles - tris = [] - - class GetTriangles(smtk.mesh.CellForEach): - - def __init__(self): - smtk.mesh.CellForEach.__init__(self, False) - - def forCell(self, cellId, cellType, numPoints): - if numPoints == 3: - tris.append( - [mesh.points().find(self.pointId(i)) for i in range(numPoints)]) - - getTriangles = GetTriangles() - smtk.mesh.for_each(mesh.cells(), getTriangles) - - # Construct a pyplot, populate it with the triangles and color it by the - # z-coordinate of the mesh - fig1, ax1 = plt.subplots() - ax1.set_aspect('equal') - tcf = ax1.tricontourf([c[0] for c in coords], [c[1] - for c in coords], tris, [c[2] for c in coords]) - fig1.colorbar(tcf) - plt.title('Mesh Elevation') - plt.xlabel('X (units)') - plt.ylabel('Y (units)') - - # Save the resulting image to the user-defined filename - plt.savefig(filename, bbox_inches='tight') - - # Return with success - result = self.createResult(smtk.operation.Operation.Outcome.SUCCEEDED) - return result - - def createSpecification(self): - spec = smtk.attribute.Resource.create() - reader = smtk.io.AttributeReader() - reader.readContents(spec, render_mesh_xml.description, self.log()) - return spec diff --git a/smtk/extension/matplotlib/render_mesh.sbt b/smtk/extension/matplotlib/render_mesh.sbt deleted file mode 100644 index 86d5fd18eee2bc3e6e05ec1e182d1d6a7f959ca2..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/render_mesh.sbt +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - Render a 2-dimensional mesh using matplotlib. - - - - - - - - - - - - - - diff --git a/smtk/extension/matplotlib/testing/CMakeLists.txt b/smtk/extension/matplotlib/testing/CMakeLists.txt deleted file mode 100644 index 230048877770881682dae035ffc0b405b7478129..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/testing/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(cxx) -add_subdirectory(python) diff --git a/smtk/extension/matplotlib/testing/cxx/CMakeLists.txt b/smtk/extension/matplotlib/testing/cxx/CMakeLists.txt deleted file mode 100644 index 0e5a31a88b4281806b0ca747d649c0cc00ac2e7b..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/testing/cxx/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -#============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -#============================================================================= - -set(unit_tests) -set(unit_tests_which_require_data) -set(additional_sources) - -set(external_libs ${Boost_LIBRARIES}) - -if (SMTK_ENABLE_VTK_SUPPORT) - list(APPEND unit_tests_which_require_data - RenderMesh.cxx) - list(APPEND additional_sources - smtkRegressionTestImage.cxx) -endif() - -smtk_unit_tests( - LABEL "VTK" - SOURCES ${unit_tests} - SOURCES_REQUIRE_DATA ${unit_tests_which_require_data} - EXTRA_SOURCES ${additional_sources} - LIBRARIES - smtkCore - smtkMatplotlibExt - ${external_libs} - VTK::CommonCore - VTK::CommonDataModel - VTK::InteractionStyle - VTK::IOImage - VTK::RenderingCore - VTK::RenderingOpenGL2 - VTK::TestingRendering -) - -# This is required in order to get VTK's object factories hooked up. -if (TARGET UnitTests_smtk_extension_matplotlib_testing_cxx) - vtk_module_autoinit( - TARGETS UnitTests_smtk_extension_matplotlib_testing_cxx - MODULES - VTK::CommonCore - VTK::CommonDataModel - VTK::RenderingCore - VTK::RenderingOpenGL2 - VTK::TestingRendering) -endif () diff --git a/smtk/extension/matplotlib/testing/cxx/RenderMesh.cxx b/smtk/extension/matplotlib/testing/cxx/RenderMesh.cxx deleted file mode 100644 index 72d8ea3fbec6b1e01446c33423d9f7e67aaaa3b5..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/testing/cxx/RenderMesh.cxx +++ /dev/null @@ -1,147 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" - -#include "smtk/common/PythonInterpreter.h" - -#include "smtk/extension/matplotlib/Registrar.h" - -#include "smtk/io/ReadMesh.h" - -#include "smtk/model/DefaultSession.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/operation/Operation.h" - -#include "smtk/plugin/Registry.h" - -#include -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include - -#include "smtkRegressionTestImage.h" -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} -} // namespace - -// Demonstrate/test the ability to call python SMTK operators within the C++ -// environment. -int RenderMesh(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register matplotlib operators to the operation manager - auto registry = - smtk::plugin::addToManagers(operationManager); - - // Access a 2-dimensional mesh with interesting z-features from the - // data directory - std::string input_path(data_root); - input_path += "/mesh/2d/warpedMesh.h5m"; - - smtk::mesh::ResourcePtr c = smtk::mesh::Resource::create(); - smtk::io::readMesh(input_path, c); - - if (!c || !c->isValid()) - { - std::cerr << "Could not read mesh from " << input_path << std::endl; - return 1; - } - - // Construct a "render mesh" operator - smtk::operation::Operation::Ptr op = - operationManager->create("smtk.extension.matplotlib.render_mesh.RenderMesh"); - - if (!op) - { - std::cerr << "Couldn't create \"render mesh\" operator" << std::endl; - return 1; - } - - // Set the mesh to be rendered - op->parameters()->associate(smtk::mesh::Component::create(c->meshes())); - - // Set the file path for the rendered image - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".png"; - op->parameters()->findFile("filename")->setValue(write_path); - - // Execute the operator - smtk::operation::Operation::Result result = op->operate(); - - // Confirm that the operator succeeded - if ( - result->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "render mesh operator failed\n"; - return 1; - } - - // Read the image - vtkSmartPointer reader = vtkSmartPointer::New(); - reader->SetFileName(write_path.c_str()); - - // Visualize - vtkSmartPointer actor = vtkSmartPointer::New(); - actor->GetMapper()->SetInputConnection(reader->GetOutputPort()); - - vtkSmartPointer renderer = vtkSmartPointer::New(); - renderer->AddActor(actor); - renderer->ResetCamera(); - - vtkSmartPointer renderWindow = vtkSmartPointer::New(); - renderWindow->AddRenderer(renderer); - - // Compare the resulting image with the baseline - if ( - smtkRegressionTestImage(renderWindow, 10., "matplotlib_rendered_mesh.png") != - vtkTesting::PASSED) - { - return 1; - } - - // Remove the generated file - cleanup(write_path); - - return 0; -} diff --git a/smtk/extension/matplotlib/testing/cxx/smtkRegressionTestImage.cxx b/smtk/extension/matplotlib/testing/cxx/smtkRegressionTestImage.cxx deleted file mode 100644 index fd05ec87986eb3ac85b1853d801a4d6662717366..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/testing/cxx/smtkRegressionTestImage.cxx +++ /dev/null @@ -1,52 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/matplotlib/testing/cxx/smtkRegressionTestImage.h" -#include - -// This function returns vtkTesting::PASSED on success -vtkIdType smtkRegressionTestImage( - vtkRenderWindow* rw, - const double thresh, - const std::string& fileName, - const std::string& fileType) -{ - // Append the testing temporary directory, the baseline image to the commandline arguments - std::vector args; - args.emplace_back("-V"); - std::string baselineDirectory(SMTK_DATA_DIR); - baselineDirectory = baselineDirectory + "/baseline/smtk/vtk/"; - std::string image = - baselineDirectory + vtksys::SystemTools::GetFilenameWithoutLastExtension(fileName) + fileType; - args.push_back(image); - args.emplace_back("-T"); - args.emplace_back(SMTK_SCRATCH_DIR); - - std::cout << "Commandline arguments passed to RegressionTestAndCaptureOutput:" << std::endl; - vtkNew testing; - for (std::vector::size_type i = 0; i < args.size(); ++i) - { - std::cout << args[i] << " "; - testing->AddArgument(args[i].c_str()); - } - std::cout << std::endl; - - if (testing->IsInteractiveModeSpecified()) - { - return vtkTesting::DO_INTERACTOR; - } - - if (testing->IsValidImageSpecified()) - { - testing->SetRenderWindow(rw); - return testing->RegressionTestAndCaptureOutput(thresh, cout); - } - return vtkTesting::NOT_RUN; -} diff --git a/smtk/extension/matplotlib/testing/cxx/smtkRegressionTestImage.h b/smtk/extension/matplotlib/testing/cxx/smtkRegressionTestImage.h deleted file mode 100644 index f37e4f7c0b6e2cc5a3b9f5b8c33f79d931da7a26..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/testing/cxx/smtkRegressionTestImage.h +++ /dev/null @@ -1,31 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtkRegressionTestImage_h -#define smtkRegressionTestImage_h - -#include "vtkNew.h" -#include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkRegressionTestImage.h" -#include "vtkRenderWindow.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderer.h" -#include -#include - -// This function returns 1 on success -vtkIdType smtkRegressionTestImage( - vtkRenderWindow* rw, - const double thresh, - const std::string& fileName, - const std::string& fileType = ".png"); - -#endif diff --git a/smtk/extension/matplotlib/testing/python/CMakeLists.txt b/smtk/extension/matplotlib/testing/python/CMakeLists.txt deleted file mode 100644 index 81d719cf8c507858819e290b894a0f6a7901ae7b..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/testing/python/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -set(smtkMatplotlibExtPythonDataTests - renderMesh -) - -if (SMTK_DATA_DIR) - foreach (test ${smtkMatplotlibExtPythonDataTests}) - smtk_add_test_python(${test}Py ${test}.py - --data-dir=${SMTK_DATA_DIR}) - set_tests_properties(${test}Py PROPERTIES LABELS "ExtMatplotlib") - endforeach() -endif() diff --git a/smtk/extension/matplotlib/testing/python/renderMesh.py b/smtk/extension/matplotlib/testing/python/renderMesh.py deleted file mode 100644 index 81de71d6064c9d69a8cd46586d96249c151c65c8..0000000000000000000000000000000000000000 --- a/smtk/extension/matplotlib/testing/python/renderMesh.py +++ /dev/null @@ -1,77 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= -import os -import sys -import unittest -import smtk -import smtk.io -import smtk.mesh -import smtk.model -import smtk.extension.matplotlib.render_mesh -import smtk.testing - - -class RenderMesh(smtk.testing.TestCase): - - def setUp(self): - - # Construct an operation manager - self.operationManager = smtk.operation.Manager.create() - - # Register matplotlib operations to the operation manager - smtk.extension.matplotlib.registerOperations(self.operationManager) - - # Set up the path to the test's input file - meshFile = os.path.join( - smtk.testing.DATA_DIR, 'mesh', '2d', 'warpedMesh.h5m') - - # Read in the mesh - self.meshResource = smtk.mesh.Resource.create() - smtk.io.readMesh(meshFile, self.meshResource) - - def testRenderMesh(self): - - # Create a "render mesh" operator - renderMesh = self.operationManager.createOperation( - 'smtk.extension.matplotlib.render_mesh.RenderMesh') - - if not renderMesh: - raise RuntimeError('Could not find operator \'render mesh\'') - - # Set the operator's parameters - renderMesh.parameters().associate( - smtk.mesh.Component.create(self.meshResource.meshes())) - - self.outFile = os.path.join( - smtk.testing.TEMP_DIR, str(smtk.common.UUID.random()) + '.png') - - renderMesh.parameters().find('filename').setValue(self.outFile) - - # Execute the operator - result = renderMesh.operate() - - if self.interactive() and self.haveVTK() and self.haveVTKExtension(): - import vtk - self.startRenderTest() - reader = vtk.vtkPNGReader() - reader.SetFileName(self.outFile) - reader.Update() - self.addImageToScene(reader) - cam = self.renderer.GetActiveCamera() - self.renderer.ResetCamera() - self.renderWindow.Render() - self.interact() - - -if __name__ == '__main__': - smtk.testing.process_arguments() - unittest.main() diff --git a/smtk/extension/paraview/CMakeLists.txt b/smtk/extension/paraview/CMakeLists.txt index a2821d2037a68254f1fbed67c4e6785133214309..8dd1690b0a78c08924a6966a8287e68e3832c7c2 100644 --- a/smtk/extension/paraview/CMakeLists.txt +++ b/smtk/extension/paraview/CMakeLists.txt @@ -3,7 +3,6 @@ ################################################################################ set(module_files "${CMAKE_CURRENT_SOURCE_DIR}/appcomponents/vtk.module" - "${CMAKE_CURRENT_SOURCE_DIR}/mesh/vtk.module" "${CMAKE_CURRENT_SOURCE_DIR}/model/vtk.module" "${CMAKE_CURRENT_SOURCE_DIR}/project/vtk.module" "${CMAKE_CURRENT_SOURCE_DIR}/server/vtk.module" @@ -42,7 +41,6 @@ if (TARGET ParaView::pqApplicationComponents) list(APPEND core_plugin_files appcomponents/plugin-core/paraview.plugin appcomponents/plugin-readers/paraview.plugin - mesh/plugin/paraview.plugin model/plugin/paraview.plugin project/plugin-core/paraview.plugin ) diff --git a/smtk/extension/paraview/appcomponents/GeometricVisibilityBadge.cxx b/smtk/extension/paraview/appcomponents/GeometricVisibilityBadge.cxx index 6dcde73f03d6fb7fd401dc3e60db93ec55d05ae7..169cdfe9463bc66d1413f75041db0a03313edf43 100644 --- a/smtk/extension/paraview/appcomponents/GeometricVisibilityBadge.cxx +++ b/smtk/extension/paraview/appcomponents/GeometricVisibilityBadge.cxx @@ -27,8 +27,6 @@ #include "smtk/view/icons/checkbox_visible_cpp.h" #include "smtk/common/Color.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" #include "smtk/model/AuxiliaryGeometry.h" #include "smtk/model/Entity.h" #include "smtk/model/EntityIterator.h" diff --git a/smtk/extension/paraview/appcomponents/VisibilityBadge.cxx b/smtk/extension/paraview/appcomponents/VisibilityBadge.cxx index daf4184ce92b25775222db6b4c1bcddc139057b6..2e637e1bf3dddf966b2260f311220a95b5e6f0ed 100644 --- a/smtk/extension/paraview/appcomponents/VisibilityBadge.cxx +++ b/smtk/extension/paraview/appcomponents/VisibilityBadge.cxx @@ -26,8 +26,6 @@ #include "smtk/extension/paraview/appcomponents/resources/pqEyeball_cpp.h" #include "smtk/common/Color.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" #include "smtk/model/AuxiliaryGeometry.h" #include "smtk/model/Entity.h" #include "smtk/model/EntityIterator.h" @@ -138,15 +136,6 @@ int UpdateVisibilityForFootprint( } } } - else if (auto meshComponent = std::dynamic_pointer_cast(comp)) - { - rval |= smap ? (smap->setVisibility(comp, visible != 0) ? 1 : 0) : 1; - if (rval) - { - visibleThings[comp->id()] = visible; - didUpdate = true; - } - } else if (comp) { auto resource = std::dynamic_pointer_cast(comp->resource()); @@ -280,11 +269,6 @@ bool VisibilityBadge::phraseVisibility(const DescriptivePhrase* phrase) const smtk::model::ResourcePtr modelRsrc = ent ? ent->modelResource() : std::dynamic_pointer_cast(rsrc); - smtk::mesh::ComponentPtr msh = std::dynamic_pointer_cast(comp); - smtk::mesh::ResourcePtr meshRsrc = msh - ? std::dynamic_pointer_cast(msh->resource()) - : std::dynamic_pointer_cast(rsrc); - smtk::geometry::ResourcePtr geomRsrc = std::dynamic_pointer_cast(rsrc); auto* smtkBehavior = pqSMTKBehavior::instance(); @@ -300,7 +284,7 @@ bool VisibilityBadge::phraseVisibility(const DescriptivePhrase* phrase) const return true; // pipeline hasn't been created yet; the default is visible. } - if (ent || msh) + if (ent) { auto valIt = m_visibleThings.find(comp->id()); if (valIt != m_visibleThings.end()) @@ -309,7 +293,7 @@ bool VisibilityBadge::phraseVisibility(const DescriptivePhrase* phrase) const } return true; // visibility is assumed if there is no entry. } - else if (modelRsrc || meshRsrc || (geomRsrc && !comp)) + else if (modelRsrc || (geomRsrc && !comp)) { auto* view = pqActiveObjects::instance().activeView(); auto* mapr = pvrc ? pvrc->getRepresentation(view) : nullptr; @@ -355,17 +339,12 @@ void VisibilityBadge::setPhraseVisibility(const DescriptivePhrase* phrase, int v smtk::model::ResourcePtr modelRsrc = ent ? ent->modelResource() : std::dynamic_pointer_cast(rsrc); - smtk::mesh::ComponentPtr msh = std::dynamic_pointer_cast(comp); - smtk::mesh::ResourcePtr meshRsrc = msh - ? std::dynamic_pointer_cast(msh->resource()) - : std::dynamic_pointer_cast(rsrc); - smtk::geometry::ResourcePtr geomRsrc = std::dynamic_pointer_cast(rsrc); if (smtkBehavior) { auto pvrc = smtkBehavior->getPVResource(rsrc); - if (ent || msh || (comp && geomRsrc)) + if (ent || (comp && geomRsrc)) { // Find the mapper in the active view for the related resource, then set the visibility. auto* view = pqActiveObjects::instance().activeView(); auto* mapr = pvrc ? pvrc->getRepresentation(view) : nullptr; diff --git a/smtk/extension/paraview/appcomponents/plugin-core/CMakeLists.txt b/smtk/extension/paraview/appcomponents/plugin-core/CMakeLists.txt index 0ef4e8e4f44c841eeb6b5e09ec9afbf381a36a3d..df399f79e6661695b54963c046b23a7ba683f822 100644 --- a/smtk/extension/paraview/appcomponents/plugin-core/CMakeLists.txt +++ b/smtk/extension/paraview/appcomponents/plugin-core/CMakeLists.txt @@ -64,7 +64,6 @@ target_link_libraries(smtkPQComponentsPlugin smtkPVServerExt smtkCore smtkQtExt - vtkSMTKMeshExt vtkSMTKSourceExt vtkSMTKOperationsExt ) diff --git a/smtk/extension/paraview/appcomponents/plugin-grouping/CMakeLists.txt b/smtk/extension/paraview/appcomponents/plugin-grouping/CMakeLists.txt index e762e371fbf1aa132302051ebfb886f1568eaabe..8671fdd492852c1e53ca8bda2c540ecf2265b9f8 100644 --- a/smtk/extension/paraview/appcomponents/plugin-grouping/CMakeLists.txt +++ b/smtk/extension/paraview/appcomponents/plugin-grouping/CMakeLists.txt @@ -35,7 +35,6 @@ target_link_libraries(smtkPQGroupingPlugin smtkPVServerExt smtkCore smtkQtExt - vtkSMTKMeshExt vtkSMTKSourceExt vtkSMTKOperationsExt ) diff --git a/smtk/extension/paraview/appcomponents/plugin-gui/CMakeLists.txt b/smtk/extension/paraview/appcomponents/plugin-gui/CMakeLists.txt index cd4c77d6bd02c9bba7ec5e695b1a799b8b20375d..7621be4b7b24496f72e0e611177b9f6e141523c8 100644 --- a/smtk/extension/paraview/appcomponents/plugin-gui/CMakeLists.txt +++ b/smtk/extension/paraview/appcomponents/plugin-gui/CMakeLists.txt @@ -78,7 +78,6 @@ target_link_libraries(smtkPQGuiComponentsPlugin smtkPVServerExt smtkCore smtkQtExt - vtkSMTKMeshExt vtkSMTKSourceExt vtkSMTKOperationsExt ) diff --git a/smtk/extension/paraview/appcomponents/plugin-legacy-operations/CMakeLists.txt b/smtk/extension/paraview/appcomponents/plugin-legacy-operations/CMakeLists.txt index bce3f10401ee32d8ece557fdbe0011eb156ab736..6186ee41f8a40d9d0c57b6fb206b86812844578b 100644 --- a/smtk/extension/paraview/appcomponents/plugin-legacy-operations/CMakeLists.txt +++ b/smtk/extension/paraview/appcomponents/plugin-legacy-operations/CMakeLists.txt @@ -30,7 +30,6 @@ target_link_libraries(smtkPQLegacyOperationsPlugin smtkPVServerExt smtkCore smtkQtExt - vtkSMTKMeshExt vtkSMTKSourceExt vtkSMTKOperationsExt ) diff --git a/smtk/extension/paraview/appcomponents/plugin-operations-panel/CMakeLists.txt b/smtk/extension/paraview/appcomponents/plugin-operations-panel/CMakeLists.txt index 0ad0a8cf0a304916b51b912a336a9c88ea27db22..fc08357d720c1783b220e92861340e3b021bc06b 100644 --- a/smtk/extension/paraview/appcomponents/plugin-operations-panel/CMakeLists.txt +++ b/smtk/extension/paraview/appcomponents/plugin-operations-panel/CMakeLists.txt @@ -39,7 +39,6 @@ target_link_libraries(smtkPQOperationsPanelPlugin smtkPVServerExt smtkCore smtkQtExt - vtkSMTKMeshExt vtkSMTKSourceExt vtkSMTKOperationsExt ) diff --git a/smtk/extension/paraview/appcomponents/plugin-readers/CMakeLists.txt b/smtk/extension/paraview/appcomponents/plugin-readers/CMakeLists.txt index 0d91126364b8c8cf24de5be537a9973830a09984..9ad855886dfcb1c430681c05ccaa2a53001d5fe4 100644 --- a/smtk/extension/paraview/appcomponents/plugin-readers/CMakeLists.txt +++ b/smtk/extension/paraview/appcomponents/plugin-readers/CMakeLists.txt @@ -51,7 +51,6 @@ target_link_libraries(smtkPQReadersPlugin smtkPVServerExt smtkCore smtkQtExt - vtkSMTKMeshExt vtkSMTKSourceExt vtkSMTKOperationsExt ) diff --git a/smtk/extension/paraview/appcomponents/pqSMTKResourceBrowser.cxx b/smtk/extension/paraview/appcomponents/pqSMTKResourceBrowser.cxx index 712dea47cff2cfd547b2f8e960ca6b4bc1acad62..47f048fb9b693215d0d3ddcf8d480ace96eb22c7 100644 --- a/smtk/extension/paraview/appcomponents/pqSMTKResourceBrowser.cxx +++ b/smtk/extension/paraview/appcomponents/pqSMTKResourceBrowser.cxx @@ -32,9 +32,6 @@ #include "smtk/model/EntityRef.h" #include "smtk/model/Resource.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - #include "smtk/resource/Manager.h" #include "smtk/resource/Resource.h" diff --git a/smtk/extension/paraview/appcomponents/pqSMTKSelectionFilterBehavior.cxx b/smtk/extension/paraview/appcomponents/pqSMTKSelectionFilterBehavior.cxx index 1a2b965f8d72812042e83b4d00f72c3a92f88089..87f5b7471608decdaddfb48f090c54a9318fcd67 100644 --- a/smtk/extension/paraview/appcomponents/pqSMTKSelectionFilterBehavior.cxx +++ b/smtk/extension/paraview/appcomponents/pqSMTKSelectionFilterBehavior.cxx @@ -21,8 +21,6 @@ #include "smtk/io/Logger.h" -#include "smtk/mesh/core/Component.h" - #include "smtk/model/Edge.h" #include "smtk/model/EntityRef.h" #include "smtk/model/Face.h" @@ -63,7 +61,7 @@ using namespace smtk; -#define NUM_ACTIONS 8 +#define NUM_ACTIONS 7 #define DEBUG_FILTER 0 @@ -109,14 +107,13 @@ pqSMTKSelectionFilterBehavior::pqSMTKSelectionFilterBehavior(QObject* parent) m_p = new pqInternal; m_p->Actions.setupUi(&m_p->ActionsOwner); - m_p->ActionArray[0] = m_p->Actions.actionSelnAcceptMeshSets; - m_p->ActionArray[1] = m_p->Actions.actionSelnAcceptModels; - m_p->ActionArray[2] = m_p->Actions.actionSelnAcceptModelVolumes; - m_p->ActionArray[3] = m_p->Actions.actionSelnAcceptModelFaces; - m_p->ActionArray[4] = m_p->Actions.actionSelnAcceptModelEdges; - m_p->ActionArray[5] = m_p->Actions.actionSelnAcceptModelVertices; - m_p->ActionArray[6] = m_p->Actions.actionSelnAcceptModelAuxGeoms; - m_p->ActionArray[7] = m_p->Actions.actionSelnAcceptModelInstances; + m_p->ActionArray[0] = m_p->Actions.actionSelnAcceptModels; + m_p->ActionArray[1] = m_p->Actions.actionSelnAcceptModelVolumes; + m_p->ActionArray[2] = m_p->Actions.actionSelnAcceptModelFaces; + m_p->ActionArray[3] = m_p->Actions.actionSelnAcceptModelEdges; + m_p->ActionArray[4] = m_p->Actions.actionSelnAcceptModelVertices; + m_p->ActionArray[5] = m_p->Actions.actionSelnAcceptModelAuxGeoms; + m_p->ActionArray[6] = m_p->Actions.actionSelnAcceptModelInstances; if (!s_selectionFilter) { @@ -183,14 +180,11 @@ void pqSMTKSelectionFilterBehavior::setSelection(smtk::view::SelectionPtr selnMg void pqSMTKSelectionFilterBehavior::onFilterChanged(QAction* a) { // Update all action toggle states to be consistent - bool acceptMesh = false; smtk::model::BitFlags modelFlags = 0; if ( - (a == m_p->Actions.actionSelnAcceptMeshSets && a->isChecked()) || (a == m_p->Actions.actionSelnAcceptModels && a->isChecked()) || (a == m_p->Actions.actionSelnAcceptModelVolumes && a->isChecked())) - { // model-volume and mesh-set selection do not allow other types to be selected at the same time. - acceptMesh = m_p->Actions.actionSelnAcceptMeshSets->isChecked(); + { // model-volume selection does not allow other types to be selected at the same time. // Force other model entity buttons off: for (int ii = 0; ii < NUM_ACTIONS; ++ii) { @@ -208,10 +202,8 @@ void pqSMTKSelectionFilterBehavior::onFilterChanged(QAction* a) (a == m_p->Actions.actionSelnAcceptModelAuxGeoms && a->isChecked()) || (a == m_p->Actions.actionSelnAcceptModelInstances && a->isChecked())) { - m_p->Actions.actionSelnAcceptMeshSets->setChecked(false); m_p->Actions.actionSelnAcceptModels->setChecked(false); m_p->Actions.actionSelnAcceptModelVolumes->setChecked(false); - acceptMesh = false; modelFlags = (m_p->Actions.actionSelnAcceptModelVertices->isChecked() ? smtk::model::VERTEX : smtk::model::NOTHING) | (m_p->Actions.actionSelnAcceptModelEdges->isChecked() ? smtk::model::EDGE @@ -225,7 +217,6 @@ void pqSMTKSelectionFilterBehavior::onFilterChanged(QAction* a) } else { // Something was turned off, which will not require us to deactivate any other buttons - acceptMesh = m_p->Actions.actionSelnAcceptMeshSets->isChecked(); modelFlags = (m_p->Actions.actionSelnAcceptModels->isChecked() ? smtk::model::MODEL_ENTITY : smtk::model::NOTHING) | (m_p->Actions.actionSelnAcceptModelVolumes->isChecked() ? smtk::model::VOLUME @@ -241,7 +232,6 @@ void pqSMTKSelectionFilterBehavior::onFilterChanged(QAction* a) } // Rebuild the selection filter m_modelFilterMask = modelFlags; - m_acceptMeshes = acceptMesh; this->installFilter(); } @@ -342,21 +332,12 @@ void pqSMTKSelectionFilterBehavior::installFilter() return; } - bool acceptMeshes = m_acceptMeshes; smtk::model::BitFlags modelFlags = m_modelFilterMask; - m_selection->setFilter([acceptMeshes, modelFlags]( + m_selection->setFilter([modelFlags]( smtk::resource::PersistentObjectPtr comp, int value, smtk::view::Selection::SelectionMap& suggestions) { - if (acceptMeshes) - { - auto mesh = std::dynamic_pointer_cast(comp); - if (mesh != nullptr) - { - return true; - } - } if (modelFlags) { auto modelEnt = dynamic_pointer_cast(comp); diff --git a/smtk/extension/paraview/appcomponents/pqSMTKSelectionFilterBehavior.h b/smtk/extension/paraview/appcomponents/pqSMTKSelectionFilterBehavior.h index cbd5b6c5c62c8235ab4b2f075208cf5760488aa3..272a408b2478e23f1b9b34e39f5f9088763e5c63 100644 --- a/smtk/extension/paraview/appcomponents/pqSMTKSelectionFilterBehavior.h +++ b/smtk/extension/paraview/appcomponents/pqSMTKSelectionFilterBehavior.h @@ -50,12 +50,11 @@ protected Q_SLOTS: virtual void unfilterSelectionOnServer(vtkSMSMTKWrapperProxy* mgr, pqServer* server); protected: - /// Install a filter on the selection using current flags (m_modelFilterMask and m_acceptMeshes). + /// Install a filter on the selection using current flags (m_modelFilterMask). void installFilter(); class pqInternal; pqInternal* m_p; - bool m_acceptMeshes; smtk::model::BitFlags m_modelFilterMask; smtk::view::SelectionPtr m_selection; diff --git a/smtk/extension/paraview/mesh/CMakeLists.txt b/smtk/extension/paraview/mesh/CMakeLists.txt deleted file mode 100644 index 2bc6ec5e6937396d5076380416be47a8f33b6e18..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -set(headers) -set(classes - Registrar -) - -set(pvMeshOps - VTKMeshCellSelection -) - -foreach (operator ${pvMeshOps}) - smtk_encode_file("${CMAKE_CURRENT_SOURCE_DIR}/${operator}.sbt" - HEADER_OUTPUT headerName) - list(APPEND classes ${operator}) - list(APPEND headers ${headerName}) -endforeach() -# since generated headers are in this directory, we can add them without a custom target - -vtk_module_add_module(smtkPVMeshExt - CLASSES ${classes} - HEADERS ${headers} - HEADERS_SUBDIR "smtk/extension/paraview/mesh") - -vtk_module_link(smtkPVMeshExt - PUBLIC - nlohmann_json - vtkSMTKMeshExt -) - -if (SMTK_ENABLE_TESTING) - add_subdirectory(testing) -endif () diff --git a/smtk/extension/paraview/mesh/Registrar.cxx b/smtk/extension/paraview/mesh/Registrar.cxx deleted file mode 100644 index 8a4d577f944b2bc62390e25f5f6e48a0002f9f2b..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/Registrar.cxx +++ /dev/null @@ -1,63 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/extension/paraview/mesh/Registrar.h" - -#include "smtk/extension/paraview/mesh/VTKMeshCellSelection.h" - -#include "smtk/extension/paraview/server/VTKSelectionResponderGroup.h" - -#include "smtk/operation/groups/InternalGroup.h" - -#include "smtk/mesh/core/Resource.h" -// #include "smtk/session/mesh/Resource.h" - -namespace smtk -{ -namespace extension -{ -namespace paraview -{ -namespace mesh -{ - -namespace -{ -using OperationList = std::tuple; -} - -void Registrar::registerTo(const smtk::operation::Manager::Ptr& operationManager) -{ - // Register operations - operationManager->registerOperations(); - - smtk::view::VTKSelectionResponderGroup responders(operationManager, nullptr); - responders.registerOperation(); - // responders.registerOperation(); - - smtk::operation::InternalGroup internal(operationManager); - internal.registerOperation(); -} - -void Registrar::unregisterFrom(const smtk::operation::Manager::Ptr& operationManager) -{ - smtk::view::VTKSelectionResponderGroup responders(operationManager, nullptr); - responders.unregisterOperation(); - - smtk::operation::InternalGroup internal(operationManager); - internal.unregisterOperation(); - - operationManager->unregisterOperations(); -} -} // namespace mesh -} // namespace paraview -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/paraview/mesh/Registrar.h b/smtk/extension/paraview/mesh/Registrar.h deleted file mode 100644 index ca4ace6e20ba98229cd98eb54e7eaddf4f0444d2..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/Registrar.h +++ /dev/null @@ -1,46 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_extension_paraview_mesh_Registrar_h -#define smtk_extension_paraview_mesh_Registrar_h -#ifndef __VTK_WRAP__ - -#include "smtk/extension/paraview/mesh/smtkPVMeshExtModule.h" - -#include "smtk/extension/vtk/mesh/Registrar.h" -#include "smtk/mesh/resource/Registrar.h" -#include "smtk/operation/Manager.h" -#include "smtk/operation/Registrar.h" -#include "smtk/resource/Manager.h" -#include "smtk/view/Registrar.h" - -namespace smtk -{ -namespace extension -{ -namespace paraview -{ -namespace mesh -{ - -class SMTKPVMESHEXT_EXPORT Registrar -{ -public: - using Dependencies = std::tuple; - - static void registerTo(const smtk::operation::Manager::Ptr&); - static void unregisterFrom(const smtk::operation::Manager::Ptr&); -}; -} // namespace mesh -} // namespace paraview -} // namespace extension -} // namespace smtk - -#endif // __VTK_WRAP__ -#endif // smtk_extension_paraview_mesh_Registrar_h diff --git a/smtk/extension/paraview/mesh/VTKMeshCellSelection.cxx b/smtk/extension/paraview/mesh/VTKMeshCellSelection.cxx deleted file mode 100644 index 4c81a2f54e28ccbd69c4034fe84e7030c282a773..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/VTKMeshCellSelection.cxx +++ /dev/null @@ -1,235 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/extension/paraview/mesh/VTKMeshCellSelection.h" -#include "smtk/extension/paraview/mesh/VTKMeshCellSelection_xml.h" - -#include "smtk/extension/vtk/io/mesh/MeshIOVTK.h" - -#include "smtk/extension/vtk/source/vtkResourceMultiBlockSource.h" - -#include "smtk/view/Selection.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/DeleteMesh.h" -#include "smtk/mesh/operators/SelectCells.h" -#include "smtk/mesh/resource/Selection.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/operation/Manager.h" -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/io/Logger.h" - -#include "vtkCellData.h" -#include "vtkCompositeDataIterator.h" -#include "vtkIdTypeArray.h" -#include "vtkInformation.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkPolyData.h" -#include "vtkSelection.h" -#include "vtkSelectionNode.h" -#include "vtkUnsignedIntArray.h" - -namespace smtk -{ -namespace view -{ - -VTKMeshCellSelection::VTKMeshCellSelection() = default; - -VTKMeshCellSelection::~VTKMeshCellSelection() = default; - -bool VTKMeshCellSelection::transcribeCellIdSelection(Result& result) -{ - bool didModify = false; - if (this->selectingBlocks()) - { - return didModify; - } - - auto assoc = this->parameters()->associations(); - smtk::resource::ResourcePtr resource = assoc->valueAs(); - // Currently, cell selection is only enabled for meshes and models that - // have mesh tessellations. - smtk::mesh::Resource::Ptr meshResource = - std::dynamic_pointer_cast(resource); - if (meshResource == nullptr) - { - smtk::model::Resource::Ptr modelResource = - std::dynamic_pointer_cast(resource); - if (modelResource) - { - meshResource = modelResource->meshTessellations(); - } - } - if (!resource) - { - smtkErrorMacro(smtk::io::Logger::instance(), "No associated resource for mesh selection."); - return false; - } - - auto selnMgr = this->smtkSelection(); - auto* selnBlock = this->vtkSelection(); - unsigned nn = selnBlock ? selnBlock->GetNumberOfNodes() : 0; - /* - std::cout - << "Selection input " << selnInput - << " client side " << selnThing - << " seln nodes " << nn - << " data thing " << dataThing << " " << dataThing->GetClassName() - << "\n"; - */ - for (unsigned ii = 0; ii < nn; ++ii) - { - auto* selnNode = selnBlock->GetNode(ii); - if (selnNode->GetContentType() == vtkSelectionNode::INDICES) - { - vtkInformation* selProperties = selnNode->GetProperties(); - - // Ids for the multiblocks selected - // - // TODO: handle meshsets from multiple processes (accessed using - // selProperties->Has(vtkSelectionNode::PROCESS_ID()) - std::map> selectedVTKCellsByMeshset; - - // Extract selected vtk composite index and cell ids - vtkIdTypeArray* idList = vtkIdTypeArray::SafeDownCast(selnNode->GetSelectionList()); - if (idList) - { - vtkIdType numIDs = idList->GetNumberOfTuples(); - vtkIdType composite_index = 0; - // The composite index corresponds to the block that contains the - // selected cell. - if (selProperties->Has(vtkSelectionNode::COMPOSITE_INDEX())) - { - composite_index = selProperties->Get(vtkSelectionNode::COMPOSITE_INDEX()); - } - - // The idList values correspond to the selected cells within the - // block. - for (vtkIdType cc = 0; cc < numIDs; cc++) - { - selectedVTKCellsByMeshset[composite_index].push_back(idList->GetValue(cc)); - } - } - - smtk::mesh::SelectCells::Ptr selectCells; - if (auto operationManager = this->manager()) - { - selectCells = operationManager->create(); - } - else - { - selectCells = smtk::mesh::SelectCells::create(); - } - - selectCells->parameters()->associate(meshResource); - - smtk::attribute::StringItem::Ptr cells = selectCells->parameters()->findString("cell ids"); - - // TODO: is there no way to access the appropriate dataset by index - // (as opposed to iterating the entire composite dataset)? - - std::set selection; - // For each block in the selected vtkMultiBlock... - vtkCompositeDataIterator* blockIterator = this->vtkData()->NewIterator(); - for (blockIterator->InitTraversal(); !blockIterator->IsDoneWithTraversal(); - blockIterator->GoToNextItem()) - { - // ...if the block index corresponds to the selected composite - // index... - auto selectedVTKCellsIt = - selectedVTKCellsByMeshset.find(blockIterator->GetCurrentFlatIndex()); - if (selectedVTKCellsIt != selectedVTKCellsByMeshset.end()) - { - // ...access the cell data corresponding to the mapping between - // VTK cells and SMTK cells. - std::vector& selectedVTKCells = selectedVTKCellsIt->second; - - // First we cast the dataset into something we can use. - vtkPolyData* vtkMeshSet = - vtkPolyData::SafeDownCast(blockIterator->GetCurrentDataObject()); - if (vtkMeshSet == nullptr) - { - continue; - } - - // Then we access the mapping between VTK cells and SMTK cells. - vtkIdTypeArray* cellHandles = - vtkIdTypeArray::SafeDownCast(vtkMeshSet->GetCellData()->GetScalars( - smtk::extension::vtk::io::mesh::MeshIOVTK::CellHandlesName)); - - if (cellHandles == nullptr) - { - continue; - } - - // Copy the mapped SMTK cells into a HandleRange. - for (unsigned& vtkCell : selectedVTKCells) - { - cells->appendValue(std::to_string(cellHandles->GetValue(vtkCell))); - } - } - } - - smtk::operation::Operation::Result selectionResult = selectCells->operate(this->childKey()); - smtk::attribute::ComponentItem::Ptr created = selectionResult->findComponent("created"); - selection.insert(created->value()); - result->findComponent("created")->appendValue(created->value()); - smtk::operation::MarkGeometry().markModified(created->value()); - - created->reset(); - - didModify |= selnMgr->modifySelection( - selection, - m_smtkSelectionSource, - m_smtkSelectionValue, - SelectionAction::FILTERED_ADD, - /* bitwise */ true, - /* notify */ false); - - // Clean up the block iterator, since we created it for the above - // traversal. - blockIterator->Delete(); - } - else - { - //std::cout << "Failing to convert due to unexpected selection node.\n"; - didModify = false; - break; - } - } - - return didModify; -} - -VTKMeshCellSelection::Result VTKMeshCellSelection::operateInternal() -{ - auto result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - bool worked = this->transcribeCellIdSelection(result); - if (!worked) - { - result->findInt("outcome")->setValue( - static_cast(smtk::operation::Operation::Outcome::FAILED)); - } - return result; -} - -const char* VTKMeshCellSelection::xmlDescription() const -{ - return VTKMeshCellSelection_xml; -} - -} //namespace view -} // namespace smtk diff --git a/smtk/extension/paraview/mesh/VTKMeshCellSelection.h b/smtk/extension/paraview/mesh/VTKMeshCellSelection.h deleted file mode 100644 index 4c71a74f61aa96054dccad1156343661ea63152a..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/VTKMeshCellSelection.h +++ /dev/null @@ -1,63 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_view_VTKMeshCellSelection_h -#define smtk_view_VTKMeshCellSelection_h -#ifndef __VTK_WRAP__ - -#include "smtk/extension/paraview/mesh/smtkPVMeshExtModule.h" // For export macro - -#include "smtk/extension/paraview/server/RespondToVTKSelection.h" - -namespace smtk -{ -namespace view -{ - -/**\brief An operation that handles cell selections on mesh resources. - * - * This operation, invoked with a vtkSelection dataset, creates a - * new meshset and adds it to the SMTK selection when VTK cell indices - * are provided. - */ -class SMTKPVMESHEXT_EXPORT VTKMeshCellSelection : public smtk::view::RespondToVTKSelection -{ -public: - using Result = smtk::operation::Operation::Result; - smtkTypeMacro(VTKMeshCellSelection); - smtkCreateMacro(VTKMeshCellSelection); - smtkSharedFromThisMacro(smtk::view::RespondToVTKSelection); - smtkSuperclassMacro(smtk::view::RespondToVTKSelection); - ~VTKMeshCellSelection() override; - -protected: - VTKMeshCellSelection(); - - /**\brief A convenience method that subclasses may use internally - * to handle VTK index selections. - * - * This will create meshsets and select them to match cells - * selected in VTK. - * - * Note that the selection is filtered. - */ - bool transcribeCellIdSelection(Result& result); - - /// Simply call transcribeCellIdSelection(). - Result operateInternal() override; - -private: - const char* xmlDescription() const override; -}; - -} //namespace view -} // namespace smtk - -#endif -#endif // smtk_view_VTKMeshCellSelection_h diff --git a/smtk/extension/paraview/mesh/VTKMeshCellSelection.sbt b/smtk/extension/paraview/mesh/VTKMeshCellSelection.sbt deleted file mode 100644 index c48b8855f246c9bbd8182a1447885ad9026794f0..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/VTKMeshCellSelection.sbt +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - Translate VTK cell-index selections on a mesh into an SMTK meshset selection. - - - - - - - - - - - - diff --git a/smtk/extension/paraview/mesh/plugin/CMakeLists.txt b/smtk/extension/paraview/mesh/plugin/CMakeLists.txt deleted file mode 100644 index 206775f2202f34236992e55f53514ba15eb34e63..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/plugin/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -get_property(smtk_vtk_modules GLOBAL - PROPERTY _smtk_vtk_extention_modules) - -smtk_add_plugin(smtkPVMeshExtPlugin - REGISTRAR - smtk::extension::paraview::mesh::Registrar - MANAGERS - smtk::geometry::Manager - smtk::operation::Manager - smtk::resource::query::Manager - smtk::view::Manager - PARAVIEW_PLUGIN_ARGS - VERSION 1.0 - REQUIRED_ON_SERVER - REQUIRED_ON_CLIENT - MODULES smtkPVMeshExt -) diff --git a/smtk/extension/paraview/mesh/plugin/paraview.plugin b/smtk/extension/paraview/mesh/plugin/paraview.plugin deleted file mode 100644 index 462978b94fd006853470a55440374b0436c7fab9..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/plugin/paraview.plugin +++ /dev/null @@ -1,14 +0,0 @@ -NAME - smtkPVMeshExtPlugin -DESCRIPTION - Server-side SMTK extension for ParaView that exposes base model operations. -REQUIRES_MODULES - VTK::CommonCore - VTK::CommonDataModel - VTK::CommonExecutionModel - VTK::CommonMath - VTK::CommonTransforms - VTK::RenderingCore - VTK::RenderingOpenGL2 - smtkPVMeshExt - smtkPVServerExt diff --git a/smtk/extension/paraview/mesh/testing/CMakeLists.txt b/smtk/extension/paraview/mesh/testing/CMakeLists.txt deleted file mode 100644 index 13df52af7d9aa9496e1a67c7567a44cd97557c28..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/testing/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(xml) diff --git a/smtk/extension/paraview/mesh/testing/xml/CMakeLists.txt b/smtk/extension/paraview/mesh/testing/xml/CMakeLists.txt deleted file mode 100644 index aefff7493980f86f006dd824a0438c2cecc162a7..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/testing/xml/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -set(TESTS_WITH_BASELINES - ${CMAKE_CURRENT_SOURCE_DIR}/MeshSelection.xml -) - -include(SMTKPVTestingMacros) - -#TODO: this should be set for the entire project's xml tests -set(MeshSelection_USES_DIRECT_DATA ON) - -if (SMTK_DATA_DIR) -smtk_add_client_tests( - #LABEL "MeshSession" - TEST_SCRIPTS ${TESTS_WITH_BASELINES} - LOAD_PLUGINS - smtkAttributePlugin - smtkResourcePlugin - smtkOperationPlugin - smtkGeometryPlugin - smtkViewPlugin - smtkMeshPlugin - smtkQtPlugin - smtkPVServerExtPlugin - smtkPQComponentsPlugin - smtkPQGuiComponentsPlugin - smtkPQReadersPlugin - smtkPVMeshExtPlugin - PLUGIN_PATHS - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - DATA_DIRECTORY ${PROJECT_SOURCE_DIR}/data - BASELINE_DIR ${PROJECT_SOURCE_DIR}/data/baseline/smtk/mesh - ) - - smtk_test_apply_sanitizer(pv.MeshSelection) -endif() diff --git a/smtk/extension/paraview/mesh/testing/xml/MeshSelection.xml b/smtk/extension/paraview/mesh/testing/xml/MeshSelection.xml deleted file mode 100644 index 2b3708376002a56c235508ed2b8ca3dd95e81b7d..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/testing/xml/MeshSelection.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/smtk/extension/paraview/mesh/vtk.module b/smtk/extension/paraview/mesh/vtk.module deleted file mode 100644 index 1c9d32b82803b486eb09bd58a369f2dbae9e353d..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/mesh/vtk.module +++ /dev/null @@ -1,18 +0,0 @@ -NAME - smtkPVMeshExt -DEPENDS - ParaView::RemotingViews - VTK::CommonCore - VTK::CommonExecutionModel - VTK::RenderingCore -PRIVATE_DEPENDS - ParaView::RemotingApplication - ParaView::RemotingServerManager - ParaView::VTKExtensionsExtraction - VTK::CommonDataModel - VTK::CommonMath - VTK::CommonTransforms - VTK::RenderingOpenGL2 - smtkPVServerExt - vtkSMTKSourceExt - vtkSMTKMeshExt diff --git a/smtk/extension/paraview/project/pqSMTKProjectBrowser.cxx b/smtk/extension/paraview/project/pqSMTKProjectBrowser.cxx index fc37c8520dc1d36986a292333e6d1816182de43e..1a9fda4c314da02c973bd75831a49e52fed4bc19 100644 --- a/smtk/extension/paraview/project/pqSMTKProjectBrowser.cxx +++ b/smtk/extension/paraview/project/pqSMTKProjectBrowser.cxx @@ -36,9 +36,6 @@ #include "smtk/model/EntityRef.h" #include "smtk/model/Resource.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - #include "smtk/resource/Manager.h" #include "smtk/resource/Resource.h" diff --git a/smtk/extension/paraview/project/testing/xml/CMakeLists.txt b/smtk/extension/paraview/project/testing/xml/CMakeLists.txt index 48c74ec648a940e7f5a5d02e2daa19bbc43f16bf..c957ad8f0f19d88846342b5b50753db5f9056a59 100644 --- a/smtk/extension/paraview/project/testing/xml/CMakeLists.txt +++ b/smtk/extension/paraview/project/testing/xml/CMakeLists.txt @@ -24,7 +24,6 @@ smtk_add_client_tests( smtkAttributePlugin smtkDefaultConfigurationPlugin smtkGeometryPlugin - smtkMeshPlugin smtkModelPlugin smtkOperationPlugin smtkProjectPlugin @@ -35,7 +34,6 @@ smtk_add_client_tests( smtkVTKOperationsPlugin # Load server-side plugins, esp. PVServerExt: - smtkPVMeshExtPlugin smtkPVModelExtPlugin smtkPVServerExtPlugin @@ -53,7 +51,6 @@ smtk_add_client_tests( $/.. $/.. $/.. - $/.. $/.. $/.. $/.. @@ -66,7 +63,6 @@ smtk_add_client_tests( $/.. $/.. $/.. - $/.. $/.. $/.. $/.. diff --git a/smtk/extension/paraview/server/Registrar.cxx b/smtk/extension/paraview/server/Registrar.cxx index 3178ccaf243f807742983e63c528cb3bc91829f5..196a50fd344dfe4acb101c8fe75b93ae8ae5306d 100644 --- a/smtk/extension/paraview/server/Registrar.cxx +++ b/smtk/extension/paraview/server/Registrar.cxx @@ -16,9 +16,6 @@ #include "smtk/operation/groups/InternalGroup.h" -#include "smtk/mesh/core/Resource.h" -// #include "smtk/session/mesh/Resource.h" - namespace smtk { namespace extension diff --git a/smtk/extension/paraview/server/Registrar.h b/smtk/extension/paraview/server/Registrar.h index 226c885277f72183bd184c36c473d2a37a81a9f5..33f99afe9775efa2e483c9b97d11da3ecacc7bb7 100644 --- a/smtk/extension/paraview/server/Registrar.h +++ b/smtk/extension/paraview/server/Registrar.h @@ -15,8 +15,6 @@ #include "smtk/attribute/Registrar.h" #include "smtk/extension/vtk/geometry/Registrar.h" -#include "smtk/extension/vtk/mesh/Registrar.h" -#include "smtk/mesh/resource/Registrar.h" #include "smtk/model/Registrar.h" #include "smtk/operation/Manager.h" #include "smtk/operation/Registrar.h" diff --git a/smtk/extension/paraview/server/testing/python/openSMTKFileInParaView.py.in b/smtk/extension/paraview/server/testing/python/openSMTKFileInParaView.py.in index d3e8ec71430dce5c10654b7d52550dd28b26e2a6..5c826b3e6d650e2aa98ac7c46a654982def83783 100644 --- a/smtk/extension/paraview/server/testing/python/openSMTKFileInParaView.py.in +++ b/smtk/extension/paraview/server/testing/python/openSMTKFileInParaView.py.in @@ -35,7 +35,6 @@ class OpenSMTKFileInParaView(smtk.testing.TestCase): pvsimple.LoadPlugin("$", True) pvsimple.LoadPlugin("$", True) pvsimple.LoadPlugin("$", True) - pvsimple.LoadPlugin("$", True) def testOpenSMTKFile(self): reader = pvsimple.OpenDataFile(os.path.join(smtk.testing.DATA_DIR, diff --git a/smtk/extension/paraview/server/vtk.module b/smtk/extension/paraview/server/vtk.module index df1e00be86564160c7194da107a63a137e274b09..fef142431dbeb02ea41ce9ec67e4f37b08af5d10 100644 --- a/smtk/extension/paraview/server/vtk.module +++ b/smtk/extension/paraview/server/vtk.module @@ -14,4 +14,3 @@ PRIVATE_DEPENDS VTK::CommonTransforms VTK::RenderingOpenGL2 vtkSMTKSourceExt - vtkSMTKMeshExt diff --git a/smtk/extension/pybind11/__init__.py.in b/smtk/extension/pybind11/__init__.py.in index fc267ac8f182c4a3f6de61c3acb4d75aa67d6fb2..2fe9fba54fcf892ea9225f0254e51c00a03d7d3a 100644 --- a/smtk/extension/pybind11/__init__.py.in +++ b/smtk/extension/pybind11/__init__.py.in @@ -15,9 +15,6 @@ _sessions = [] if @SMTK_VTK_SUPPORT_ENABLED@: _sessions.append("vtk") -if @SMTK_MATPLOTLIB_SUPPORT_ENABLED@: - _sessions.append("matplotlib") - if @SMTK_PARAVIEW_SUPPORT_ENABLED@: _sessions.append("paraview") diff --git a/smtk/extension/qt/qtCheckItemComboBox.cxx b/smtk/extension/qt/qtCheckItemComboBox.cxx index 8f4b06f8767ddadc188875d3b5151ccd8f7286fe..09f4c25639bd8032609fcdf4e4dc36cc84eeebc5 100644 --- a/smtk/extension/qt/qtCheckItemComboBox.cxx +++ b/smtk/extension/qt/qtCheckItemComboBox.cxx @@ -13,7 +13,6 @@ #include "smtk/attribute/ModelEntityItem.h" #include "smtk/attribute/ModelEntityItemDefinition.h" #include "smtk/attribute/VoidItem.h" -#include "smtk/mesh/core/Resource.h" #include "smtk/model/EntityRef.h" #include "smtk/model/Group.h" diff --git a/smtk/extension/qt/qtDescriptivePhraseModel.cxx b/smtk/extension/qt/qtDescriptivePhraseModel.cxx index 7c1f3c54ebfb0f3d1c2227e4d023631409cc5e85..97cdccab56a935ecda4ff2b0d89639082b36f65f 100644 --- a/smtk/extension/qt/qtDescriptivePhraseModel.cxx +++ b/smtk/extension/qt/qtDescriptivePhraseModel.cxx @@ -23,9 +23,6 @@ #include "smtk/model/Resource.h" #include "smtk/model/StringData.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - #include "smtk/attribute/Attribute.h" #include "smtk/attribute/ComponentItem.h" #include "smtk/attribute/Resource.h" diff --git a/smtk/extension/qt/qtDescriptivePhraseModel.h b/smtk/extension/qt/qtDescriptivePhraseModel.h index 2073473d174250aa2db8ad88e68bd5737dfb9c54..451583a94280fcb28a22d2f005be915b934fd769 100644 --- a/smtk/extension/qt/qtDescriptivePhraseModel.h +++ b/smtk/extension/qt/qtDescriptivePhraseModel.h @@ -31,7 +31,7 @@ namespace extension * * By calling setPhraseModel(), you identify the toplevel * description you wish to present; it may cover any set - * of model, mesh, and attribute resources. + * of model and attribute resources. * * The smtk::view::PhraseModel uses an smtk::view::SubphraseGenerator * instance to create a hierarchy of smtk::view::DescriptivePhrase diff --git a/smtk/extension/qt/qtGroupView.cxx b/smtk/extension/qt/qtGroupView.cxx index abb80133ca47a7727e58f349248af1acdebcf65c..732aec7a74b722e1a96058cb148ae6df0d465a77 100644 --- a/smtk/extension/qt/qtGroupView.cxx +++ b/smtk/extension/qt/qtGroupView.cxx @@ -53,7 +53,7 @@ public: QList m_ChildViews, m_TabbedViews; QList m_PageWidgets; QList m_PageIcons; - QList m_Labels; + QList m_Labels; qtGroupViewInternals::Style m_style{ TABBED }; std::vector m_activeViews; int m_currentTabSelected{ 0 }; @@ -634,7 +634,7 @@ void qtGroupView::addTileEntry(qtBaseView* child) area->widget()->layout()->addWidget(child->widget()); // For debugging. - // std::cout + // std::cerr // << "Adding " << child->widget()->objectName().toStdString() // << " to " << area->widget()->layout()->objectName().toStdString() << "\n"; } diff --git a/smtk/extension/qt/qtResourceBrowser.cxx b/smtk/extension/qt/qtResourceBrowser.cxx index 2261af639e6f7b6dde31a8b96e7cab72e86ef1eb..825597331edc8a337773328c756cfb87f81c43a7 100644 --- a/smtk/extension/qt/qtResourceBrowser.cxx +++ b/smtk/extension/qt/qtResourceBrowser.cxx @@ -28,9 +28,6 @@ #include "smtk/model/Entity.h" #include "smtk/model/Resource.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - #include "smtk/operation/Manager.h" #include "smtk/attribute/Attribute.h" diff --git a/smtk/extension/qt/testing/cxx/CMakeLists.txt b/smtk/extension/qt/testing/cxx/CMakeLists.txt index 8eff3abb97e311f2b9eabb9296528c3cd410c647..53365b48c75eb55b65ec8ad59ff6c60014b5d7bf 100644 --- a/smtk/extension/qt/testing/cxx/CMakeLists.txt +++ b/smtk/extension/qt/testing/cxx/CMakeLists.txt @@ -84,5 +84,4 @@ smtk_unit_tests( Qt5::Test ${Boost_LIBRARIES} Threads::Threads - MOAB ) diff --git a/smtk/extension/qt/testing/cxx/UnitTestOperationTypeModel.cxx b/smtk/extension/qt/testing/cxx/UnitTestOperationTypeModel.cxx index 92730695e0b68fb7c93e064b756b5fcb1973acd3..b29815af34e445289f6b31854288d846f2f47f4e 100644 --- a/smtk/extension/qt/testing/cxx/UnitTestOperationTypeModel.cxx +++ b/smtk/extension/qt/testing/cxx/UnitTestOperationTypeModel.cxx @@ -37,21 +37,6 @@ #include "smtk/attribute/operators/Dissociate.h" #include "smtk/attribute/operators/Export.h" #include "smtk/attribute/operators/Import.h" -#include "smtk/mesh/operators/DeleteMesh.h" -#include "smtk/mesh/operators/ElevateMesh.h" -#include "smtk/mesh/operators/Export.h" -#include "smtk/mesh/operators/ExtractAdjacency.h" -#include "smtk/mesh/operators/ExtractByDihedralAngle.h" -#include "smtk/mesh/operators/ExtractSkin.h" -#include "smtk/mesh/operators/Import.h" -#include "smtk/mesh/operators/InterpolateOntoMesh.h" -#include "smtk/mesh/operators/MergeCoincidentPoints.h" -#include "smtk/mesh/operators/PrintMeshInformation.h" -#include "smtk/mesh/operators/SelectCells.h" -#include "smtk/mesh/operators/SetMeshName.h" -#include "smtk/mesh/operators/Subtract.h" -#include "smtk/mesh/operators/Transform.h" -#include "smtk/mesh/operators/UndoElevateMesh.h" #include "smtk/model/operators/AddAuxiliaryGeometry.h" #include "smtk/model/operators/AddImage.h" #include "smtk/model/operators/CompositeAuxiliaryGeometry.h" @@ -144,21 +129,6 @@ int UnitTestOperationTypeModel(int argc, char** const argv) wrap(), wrap(), wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), wrap(), wrap(), wrap(), diff --git a/smtk/extension/vtk/CMakeLists.txt b/smtk/extension/vtk/CMakeLists.txt index 544b12b7c0198e68044877f61f47a51d0e7a8705..84d99ccc1e6916dbcfcbe05e73a8544550693b3e 100644 --- a/smtk/extension/vtk/CMakeLists.txt +++ b/smtk/extension/vtk/CMakeLists.txt @@ -1,7 +1,6 @@ set(module_files "${CMAKE_CURRENT_SOURCE_DIR}/filter/vtk.module" "${CMAKE_CURRENT_SOURCE_DIR}/geometry/vtk.module" - "${CMAKE_CURRENT_SOURCE_DIR}/mesh/vtk.module" "${CMAKE_CURRENT_SOURCE_DIR}/model/vtk.module" "${CMAKE_CURRENT_SOURCE_DIR}/operators/vtk.module" "${CMAKE_CURRENT_SOURCE_DIR}/source/vtk.module" diff --git a/smtk/extension/vtk/geometry/BoundingBox.cxx b/smtk/extension/vtk/geometry/BoundingBox.cxx index 9958fefbcfc59671580eac934099d20b56d31126..247e75fb69651c1a7c3a49d8bd1bb0b96c0fb04e 100644 --- a/smtk/extension/vtk/geometry/BoundingBox.cxx +++ b/smtk/extension/vtk/geometry/BoundingBox.cxx @@ -73,7 +73,7 @@ std::array BoundingBox::operator()( return returnValue; } -}; // namespace geometry +} // namespace geometry } // namespace vtk } // namespace extension } // namespace smtk diff --git a/smtk/extension/vtk/geometry/Registrar.cxx b/smtk/extension/vtk/geometry/Registrar.cxx index 124f2b9c0631da5fe9f3e48d23633053768db8b2..bd0b5cb2bdd66909bb3de07b7c912bb8c78f8845 100644 --- a/smtk/extension/vtk/geometry/Registrar.cxx +++ b/smtk/extension/vtk/geometry/Registrar.cxx @@ -15,8 +15,6 @@ #include "smtk/geometry/Generator.h" -#include "smtk/mesh/core/Resource.h" - #include "smtk/extension/vtk/geometry/BoundingBox.h" #include "smtk/extension/vtk/geometry/ClosestPoint.h" #include "smtk/extension/vtk/geometry/DistanceTo.h" diff --git a/smtk/extension/vtk/io/CMakeLists.txt b/smtk/extension/vtk/io/CMakeLists.txt index fb110931d1907a01e0d7d01f48c063bffcd2f9a5..bb986ff192ef761e5ef489943d19ad9265c3f750 100644 --- a/smtk/extension/vtk/io/CMakeLists.txt +++ b/smtk/extension/vtk/io/CMakeLists.txt @@ -4,11 +4,6 @@ set(headers) set(classes ImportAsVTKData RedirectOutput - mesh/ExportVTKData - mesh/ImportVTKData - mesh/MeshIOVTK - mesh/PointCloudFromVTKFile - mesh/StructuredGridFromVTKFile vtkLIDARPtsWriter # For terrain extraction vtkMedHelper vtkMedReader @@ -34,7 +29,6 @@ target_link_libraries(smtkIOVTK VTK::CommonCore VTK::IOCore LINK_PRIVATE - MOAB VTK::CommonDataModel VTK::CommonExecutionModel VTK::FiltersCore @@ -93,10 +87,6 @@ set(PROJECT_NAME SMTKVTKModules) smtk_install_library(smtkIOVTK) set(PROJECT_NAME "${PROJECT_NAME_save}") -if (SMTK_ENABLE_PYTHON_WRAPPING) - add_subdirectory(pybind11) -endif() - if (SMTK_ENABLE_TESTING) add_subdirectory(testing) endif() diff --git a/smtk/extension/vtk/io/mesh/ExportVTKData.cxx b/smtk/extension/vtk/io/mesh/ExportVTKData.cxx deleted file mode 100644 index eb8c49336554d112d04e51b0789cc4a70428fadf..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/mesh/ExportVTKData.cxx +++ /dev/null @@ -1,565 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#include "smtk/extension/vtk/io/mesh/ExportVTKData.h" -#include "smtk/extension/vtk/io/mesh/MeshIOVTK.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/CellTraits.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/ExtractMeshConstants.h" -#include "smtk/mesh/utility/ExtractTessellation.h" -#include "smtk/mesh/utility/Metrics.h" - -#include "vtkAOSDataArrayTemplate.h" -#include "vtkCell.h" -#include "vtkCellArray.h" -#include "vtkCellData.h" -#include "vtkDataArray.h" -#include "vtkDoubleArray.h" -#include "vtkIdTypeArray.h" -#include "vtkIntArray.h" -#include "vtkNew.h" -#include "vtkPointData.h" -#include "vtkPoints.h" -#include "vtkPolyData.h" -#include "vtkSmartPointer.h" -#include "vtkUnsignedCharArray.h" -#include "vtkUnstructuredGrid.h" -#include "vtkUnstructuredGridWriter.h" -#include "vtkXMLPolyDataReader.h" -#include "vtkXMLPolyDataWriter.h" -#include "vtkXMLUnstructuredGridReader.h" -#include "vtkXMLUnstructuredGridWriter.h" - -#include "vtksys/SystemTools.hxx" - -#include "moab/ReadUtilIface.hpp" - -#include "smtk/mesh/moab/CellTypeToType.h" -#include "smtk/mesh/moab/Interface.h" - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace io -{ -namespace mesh -{ - -ExportVTKData::ExportVTKData() = default; - -bool ExportVTKData::operator()( - const std::string& filename, - smtk::mesh::ResourcePtr resource, - std::string domainPropertyName) const -{ - // fail if the resource is empty - if (!resource || !resource->isValid()) - { - return false; - } - - return (*this)(filename, resource->meshes(), domainPropertyName); -} - -bool ExportVTKData::operator()( - const std::string& filename, - const smtk::mesh::MeshSet& meshset, - std::string domainPropertyName) const -{ - // fail if the meshset is empty - if (meshset.is_empty()) - { - return false; - } - - std::string extension = vtksys::SystemTools::GetFilenameLastExtension(filename); - - // Dispatch based on the file extension - if (extension == ".vtu") - { - vtkSmartPointer ug = vtkSmartPointer::New(); - this->operator()(meshset, ug, domainPropertyName); - vtkNew writer; - writer->SetFileName(filename.c_str()); - writer->SetInputData(ug); - writer->Write(); - return true; - } - else if (extension == ".vtp") - { - vtkSmartPointer pd = vtkSmartPointer::New(); - this->operator()(meshset, pd, domainPropertyName); - vtkNew writer; - writer->SetFileName(filename.c_str()); - writer->SetInputData(pd); - writer->Write(); - return true; - } - else if (extension == ".vtk") - { - vtkSmartPointer ug = vtkSmartPointer::New(); - this->operator()(meshset, ug, domainPropertyName); - vtkNew writer; - writer->SetFileName(filename.c_str()); - writer->SetInputData(ug); - writer->Write(); - return true; - } - - return false; -} - -namespace -{ - -// functions for allocation, transfer and deallocation when there is a type -// mismatch -template -void constructNewArrayIfNecessary(T*& /*unused*/, vtkIdType*& out, std::int64_t len) -{ - out = new vtkIdType[len]; -} - -template -void transferDataIfNecessary(T*& in, vtkIdType*& out, std::int64_t len) -{ - for (std::int64_t i = 0; i < len; i++) - { - out[i] = in[i]; - } -} - -template -void deleteOldArrayIfNecessary(T*& in, vtkIdType*& /*unused*/) -{ - delete[] in; -} -} // namespace - -void ExportVTKData::operator()( - const smtk::mesh::MeshSet& meshset, - vtkPolyData* pd, - std::string domainPropertyName) const -{ - // Determine the highest dimension - int dimension = smtk::mesh::utility::highestDimension(meshset); - - if (dimension < 0) - { - // We have been passed a meshset with no elements of dimension 3 or lower. - return; - } - - // To preserve the state of the mesh database, we track - // whether or not a new meshset was created to represent - // the 3d shell; if it was created, we delete it when we - // are finished with it. - bool shellCreated = false; - smtk::mesh::MeshSet toRender = (dimension == 3 ? meshset.extractShell(shellCreated) : meshset); - - smtk::mesh::CellSet cellset = - toRender.cells(static_cast(dimension == 3 ? 2 : dimension)); - - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //determine the allocation lengths - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - cellset, connectivityLength, numberOfCells, numberOfPoints); - - // add the number of cells to the connectivity length to get the length of - // VTK-style connectivity - connectivityLength += numberOfCells; - - //create raw data buffers to hold our data - double* pointsData = new double[3 * numberOfPoints]; - std::int64_t* connectivityData_ = new std::int64_t[connectivityLength]; - - //extract tessellation information - smtk::mesh::utility::PreAllocatedTessellation tess(connectivityData_, pointsData); - smtk::mesh::utility::extractTessellation(cellset, tess); - - vtkIdType* connectivityData; - { - constructNewArrayIfNecessary(connectivityData_, connectivityData, connectivityLength); - transferDataIfNecessary(connectivityData_, connectivityData, connectivityLength); - deleteOldArrayIfNecessary(connectivityData_, connectivityData); - } - - std::int64_t* cellHandles_ = new std::int64_t[numberOfCells]; - if (dimension == 3) - { - auto interface = meshset.resource()->interface(); - - const smtk::mesh::HandleRange& range = cellset.range(); - auto it = smtk::mesh::rangeElementsBegin(range); - auto end = smtk::mesh::rangeElementsEnd(range); - smtk::mesh::Handle parent; - int canonicalIndex; - for (std::size_t counter = 0; it != end; ++it, ++counter) - { - interface->canonicalIndex(*it, parent, canonicalIndex); - cellHandles_[counter] = parent; - } - } - else - { - const smtk::mesh::HandleRange& range = cellset.range(); - auto it = smtk::mesh::rangeElementsBegin(range); - auto end = smtk::mesh::rangeElementsEnd(range); - for (std::size_t counter = 0; it != end; ++it, ++counter) - { - cellHandles_[counter] = *it; - } - } - vtkIdType* cellHandles; - { - constructNewArrayIfNecessary(cellHandles_, cellHandles, numberOfCells); - transferDataIfNecessary(cellHandles_, cellHandles, numberOfCells); - deleteOldArrayIfNecessary(cellHandles_, cellHandles); - } - - std::int64_t* pointHandles_ = new std::int64_t[numberOfPoints]; - { - smtk::mesh::PointSet points = cellset.points(); - const smtk::mesh::HandleRange& range = points.range(); - - auto it = smtk::mesh::rangeElementsBegin(range); - auto end = smtk::mesh::rangeElementsEnd(range); - for (std::size_t counter = 0; it != end; ++it, ++counter) - { - pointHandles_[counter] = *it; - } - } - vtkIdType* pointHandles; - { - constructNewArrayIfNecessary(pointHandles_, pointHandles, numberOfPoints); - transferDataIfNecessary(pointHandles_, pointHandles, numberOfPoints); - deleteOldArrayIfNecessary(pointHandles_, pointHandles); - } - - // create vtk data arrays to hold our data - vtkNew pointsArray; - vtkNew connectivity; - - // transfer ownership of our raw data arrays to the vtk data arrays - pointsArray->SetNumberOfComponents(3); - pointsArray->SetArray( - pointsData, 3 * numberOfPoints, false, vtkDoubleArray::VTK_DATA_ARRAY_DELETE); - connectivity->SetArray( - connectivityData, connectivityLength, false, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE); - - vtkNew points; - points->SetData(pointsArray.GetPointer()); - pd->SetPoints(points.GetPointer()); - - vtkNew cells; - cells->SetCells(numberOfCells, connectivity.GetPointer()); - - if (dimension == 3 || dimension == 2) - { - pd->SetPolys(cells.GetPointer()); - } - else if (dimension == 1) - { - pd->SetLines(cells.GetPointer()); - } - else if (dimension == 0) - { - pd->SetVerts(cells.GetPointer()); - } - - vtkNew cellHandlesArray; - cellHandlesArray->SetName(smtk::extension::vtk::io::mesh::MeshIOVTK::CellHandlesName); - cellHandlesArray->SetArray( - cellHandles, numberOfCells, false, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE); - pd->GetCellData()->AddArray(cellHandlesArray.GetPointer()); - - vtkNew pointHandlesArray; - pointHandlesArray->SetName(smtk::extension::vtk::io::mesh::MeshIOVTK::PointHandlesName); - pointHandlesArray->SetArray( - pointHandles, numberOfPoints, false, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE); - pd->GetPointData()->AddArray(pointHandlesArray.GetPointer()); - - if (!domainPropertyName.empty()) - { - std::int64_t* cellData_ = new std::int64_t[numberOfCells]; - std::int64_t* pointData_ = new std::int64_t[numberOfPoints]; - - //extract mesh constant information - smtk::mesh::utility::PreAllocatedMeshConstants meshConstants(cellData_, pointData_); - smtk::mesh::utility::extractDomainMeshConstants(toRender, meshConstants); - - vtkIdType* cellData; - { - constructNewArrayIfNecessary(cellData_, cellData, numberOfCells); - transferDataIfNecessary(cellData_, cellData, numberOfCells); - deleteOldArrayIfNecessary(cellData_, cellData); - } - - vtkNew cellDataArray; - cellDataArray->SetName(domainPropertyName.c_str()); - cellDataArray->SetArray(cellData, numberOfCells, false, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE); - pd->GetCellData()->AddArray(cellDataArray.GetPointer()); - - vtkIdType* pointData; - { - constructNewArrayIfNecessary(pointData_, pointData, numberOfPoints); - transferDataIfNecessary(pointData_, pointData, numberOfPoints); - deleteOldArrayIfNecessary(pointData_, pointData); - } - - vtkNew pointDataArray; - pointDataArray->SetName(domainPropertyName.c_str()); - pointDataArray->SetArray( - pointData, numberOfPoints, false, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE); - pd->GetPointData()->AddArray(pointDataArray.GetPointer()); - } - - // CellFields and PointFields are easier than mesh constants because they are - // required to be set on all of the cells/points in the meshset. - { - std::set cellfields = - toRender.subset(static_cast(dimension)).cellFields(); - for (const auto& cellfield : cellfields) - { - if (cellfield.type() == smtk::mesh::FieldType::Double) - { - double* cellData = new double[cellfield.size() * cellfield.dimension()]; - cellfield.get(cellData); - - vtkNew cellDataArray; - cellDataArray->SetName(cellfield.name().c_str()); - cellDataArray->SetArray( - cellData, - cellfield.size() * cellfield.dimension(), - false, - vtkDoubleArray::VTK_DATA_ARRAY_DELETE); - cellDataArray->SetNumberOfComponents(static_cast(cellfield.dimension())); - pd->GetCellData()->AddArray(cellDataArray.GetPointer()); - } - else if (cellfield.type() == smtk::mesh::FieldType::Integer) - { - int* cellData = new int[cellfield.size() * cellfield.dimension()]; - cellfield.get(cellData); - - vtkNew cellDataArray; - cellDataArray->SetName(cellfield.name().c_str()); - cellDataArray->SetArray( - cellData, - cellfield.size() * cellfield.dimension(), - false, - vtkIntArray::VTK_DATA_ARRAY_DELETE); - cellDataArray->SetNumberOfComponents(static_cast(cellfield.dimension())); - pd->GetCellData()->AddArray(cellDataArray.GetPointer()); - } - } - - std::set pointfields = - toRender.subset(static_cast(dimension)).pointFields(); - for (const auto& pointfield : pointfields) - { - if (pointfield.type() == smtk::mesh::FieldType::Double) - { - double* pointData = new double[pointfield.size() * pointfield.dimension()]; - pointfield.get(pointData); - - vtkNew pointDataArray; - pointDataArray->SetName(pointfield.name().c_str()); - pointDataArray->SetArray( - pointData, - pointfield.size() * pointfield.dimension(), - false, - vtkDoubleArray::VTK_DATA_ARRAY_DELETE); - pointDataArray->SetNumberOfComponents(static_cast(pointfield.dimension())); - pd->GetPointData()->AddArray(pointDataArray.GetPointer()); - } - else if (pointfield.type() == smtk::mesh::FieldType::Integer) - { - int* pointData = new int[pointfield.size() * pointfield.dimension()]; - pointfield.get(pointData); - - vtkNew pointDataArray; - pointDataArray->SetName(pointfield.name().c_str()); - pointDataArray->SetArray( - pointData, - pointfield.size() * pointfield.dimension(), - false, - vtkIntArray::VTK_DATA_ARRAY_DELETE); - pointDataArray->SetNumberOfComponents(static_cast(pointfield.dimension())); - pd->GetPointData()->AddArray(pointDataArray.GetPointer()); - } - } - } - - if (shellCreated) - { - toRender.resource()->removeMeshes(toRender); - } -} - -void ExportVTKData::operator()( - const smtk::mesh::MeshSet& meshset, - vtkUnstructuredGrid* ug, - std::string domainPropertyName) const -{ - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //determine the allocation lengths - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - meshset, connectivityLength, numberOfCells, numberOfPoints); - - // add the number of cells to the connectivity length to get the length of - // VTK-style connectivity - connectivityLength += numberOfCells; - - //create raw data buffers to hold our data - double* pointsData = new double[3 * numberOfPoints]; - unsigned char* cellTypesData = new unsigned char[numberOfCells]; - std::int64_t* cellLocationsData_ = new std::int64_t[numberOfCells]; - std::int64_t* connectivityData_ = new std::int64_t[connectivityLength]; - - //extract tessellation information - smtk::mesh::utility::PreAllocatedTessellation tess( - connectivityData_, cellLocationsData_, cellTypesData, pointsData); - smtk::mesh::utility::extractTessellation(meshset, tess); - - vtkIdType* cellLocationsData; - { - constructNewArrayIfNecessary(cellLocationsData_, cellLocationsData, numberOfCells); - transferDataIfNecessary(cellLocationsData_, cellLocationsData, numberOfCells); - deleteOldArrayIfNecessary(cellLocationsData_, cellLocationsData); - } - - vtkIdType* connectivityData; - { - constructNewArrayIfNecessary(connectivityData_, connectivityData, connectivityLength); - transferDataIfNecessary(connectivityData_, connectivityData, connectivityLength); - deleteOldArrayIfNecessary(connectivityData_, connectivityData); - } - - // create vtk data arrays to hold our data - vtkNew pointsArray; - vtkNew cellTypes; - vtkNew cellLocations; - vtkNew connectivity; - - // transfer ownership of our raw data arrays to the vtk data arrays - pointsArray->SetNumberOfComponents(3); - pointsArray->SetArray( - pointsData, 3 * numberOfPoints, false, vtkDoubleArray::VTK_DATA_ARRAY_DELETE); - cellTypes->SetArray( - cellTypesData, numberOfCells, false, vtkUnsignedCharArray::VTK_DATA_ARRAY_DELETE); - cellLocations->SetArray( - cellLocationsData, numberOfCells, false, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE); - connectivity->SetArray( - connectivityData, connectivityLength, false, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE); - - vtkNew points; - points->SetData(pointsArray.GetPointer()); - - vtkNew cells; - cells->SetCells(numberOfCells, connectivity.GetPointer()); - - ug->SetPoints(points.GetPointer()); - ug->SetCells(cellTypes.GetPointer(), cellLocations.GetPointer(), cells.GetPointer()); - - if (!domainPropertyName.empty()) - { - std::int64_t* cellData_ = new std::int64_t[numberOfCells]; - std::int64_t* pointData_ = new std::int64_t[numberOfPoints]; - - //extract field information - smtk::mesh::utility::PreAllocatedMeshConstants meshConstants(cellData_, pointData_); - smtk::mesh::utility::extractDomainMeshConstants(meshset, meshConstants); - - vtkIdType* cellData; - { - constructNewArrayIfNecessary(cellData_, cellData, numberOfCells); - transferDataIfNecessary(cellData_, cellData, numberOfCells); - deleteOldArrayIfNecessary(cellData_, cellData); - } - - vtkNew cellDataArray; - cellDataArray->SetName(domainPropertyName.c_str()); - cellDataArray->SetArray(cellData, numberOfCells, false, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE); - ug->GetCellData()->AddArray(cellDataArray.GetPointer()); - - vtkIdType* pointData; - { - constructNewArrayIfNecessary(pointData_, pointData, numberOfPoints); - transferDataIfNecessary(pointData_, pointData, numberOfPoints); - deleteOldArrayIfNecessary(pointData_, pointData); - } - - vtkNew pointDataArray; - pointDataArray->SetName(domainPropertyName.c_str()); - pointDataArray->SetArray( - pointData, numberOfPoints, false, vtkIdTypeArray::VTK_DATA_ARRAY_DELETE); - ug->GetPointData()->AddArray(pointDataArray.GetPointer()); - } - - // CellFields and PointFields are easier than mesh constants because they are - // required to be set on all of the cells/points in the meshset. - { - std::set cellfields = meshset.cellFields(); - for (const auto& cellfield : cellfields) - { - double* cellData = new double[cellfield.size() * cellfield.dimension()]; - cellfield.get(cellData); - - vtkNew cellDataArray; - cellDataArray->SetName(cellfield.name().c_str()); - cellDataArray->SetArray( - cellData, - cellfield.size() * cellfield.dimension(), - false, - vtkDoubleArray::VTK_DATA_ARRAY_DELETE); - cellDataArray->SetNumberOfComponents(static_cast(cellfield.dimension())); - ug->GetCellData()->AddArray(cellDataArray.GetPointer()); - } - - std::set pointfields = meshset.pointFields(); - for (const auto& pointfield : pointfields) - { - double* pointData = new double[pointfield.size() * pointfield.dimension()]; - pointfield.get(pointData); - - vtkNew pointDataArray; - pointDataArray->SetName(pointfield.name().c_str()); - pointDataArray->SetArray( - pointData, - pointfield.size() * pointfield.dimension(), - false, - vtkDoubleArray::VTK_DATA_ARRAY_DELETE); - pointDataArray->SetNumberOfComponents(static_cast(pointfield.dimension())); - ug->GetPointData()->AddArray(pointDataArray.GetPointer()); - } - } -} -} // namespace mesh -} // namespace io -} // namespace vtk -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/vtk/io/mesh/ExportVTKData.h b/smtk/extension/vtk/io/mesh/ExportVTKData.h deleted file mode 100644 index 5f1bd4b6ea620e5e2db08d0c8a9e5976da27adfd..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/mesh/ExportVTKData.h +++ /dev/null @@ -1,86 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_extension_vtk_io_mesh_ExportVTKData_h -#define smtk_extension_vtk_io_mesh_ExportVTKData_h - -#include "smtk/extension/vtk/io/IOVTKExports.h" -//forward declarers for Manager and Resource -#include "smtk/PublicPointerDefs.h" - -#include - -//forward declare vtk classes -class vtkPolyData; -class vtkUnstructuredGrid; - -namespace smtk -{ -namespace mesh -{ -class MeshSet; -} -} // namespace smtk - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace io -{ -namespace mesh -{ - -//Export an smtk::mesh::resource to a VTK data set. -class SMTKIOVTK_EXPORT ExportVTKData -{ -public: - explicit ExportVTKData(); - - ExportVTKData(const ExportVTKData& other) = delete; - ExportVTKData& operator=(const ExportVTKData& other) = delete; - - //Export a resource as a VTK xml polydata or xml unstructured grid file - //(determined by the file name suffix .vtp or .vtu). - bool operator()( - const std::string& filename, - smtk::mesh::ResourcePtr resource, - std::string domainPropertyName) const; - - //Export a meshset as a VTK xml polydata or xml unstructured grid file - //(determined by the file name suffix .vtp or .vtu). - bool operator()( - const std::string& filename, - const smtk::mesh::MeshSet& meshset, - std::string domainPropertyName) const; - - //Export the highest dimension cells of a mesh set to polydata. If the highest - //dimension is Dims3, export its shell. - void operator()( - const smtk::mesh::MeshSet& meshset, - vtkPolyData* pd, - std::string domainPropertyName = std::string()) const; - - //Export a mesh set to an unstructured grid. - void operator()( - const smtk::mesh::MeshSet& meshset, - vtkUnstructuredGrid* ug, - std::string domainPropertyName = std::string()) const; -}; -} // namespace mesh -} // namespace io -} // namespace vtk -} // namespace extension -} // namespace smtk - -#endif //__smtk_extension_vtk_io_mesh_ExportVTKData_h diff --git a/smtk/extension/vtk/io/mesh/ImportVTKData.cxx b/smtk/extension/vtk/io/mesh/ImportVTKData.cxx deleted file mode 100644 index 2a3d9db6d1a14ea67e34fa665a3660cc42a55b51..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/mesh/ImportVTKData.cxx +++ /dev/null @@ -1,435 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#include "smtk/extension/vtk/io/mesh/ImportVTKData.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/CellTraits.h" -#include "smtk/mesh/core/FieldTypes.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/ExtractTessellation.h" - -#include "vtkAOSDataArrayTemplate.h" -#include "vtkCell.h" -#include "vtkCellArray.h" -#include "vtkCellData.h" -#include "vtkDataArray.h" -#include "vtkDataSet.h" -#include "vtkDoubleArray.h" -#include "vtkIdTypeArray.h" -#include "vtkImageData.h" -#include "vtkIntArray.h" -#include "vtkNew.h" -#include "vtkPointData.h" -#include "vtkPoints.h" -#include "vtkPolyData.h" -#include "vtkSmartPointer.h" -#include "vtkTriangleFilter.h" -#include "vtkUnsignedCharArray.h" -#include "vtkUnstructuredGrid.h" - -#include "vtksys/SystemTools.hxx" - -#include "moab/ReadUtilIface.hpp" - -#include "smtk/extension/vtk/io/ImportAsVTKData.h" - -#include "smtk/mesh/moab/CellTypeToType.h" -#include "smtk/mesh/moab/Interface.h" - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace io -{ -namespace mesh -{ -namespace -{ - -smtk::mesh::CellType vtkToSMTKCell(int t) -{ - smtk::mesh::CellType ctype = smtk::mesh::CellType_MAX; - switch (t) - { - case VTK_VERTEX: - ctype = smtk::mesh::Vertex; - break; - case VTK_LINE: - case VTK_QUADRATIC_EDGE: - case VTK_CUBIC_LINE: - case VTK_PARAMETRIC_CURVE: - case VTK_HIGHER_ORDER_EDGE: - case VTK_LAGRANGE_CURVE: - ctype = smtk::mesh::Line; - break; - case VTK_TRIANGLE: - case VTK_QUADRATIC_TRIANGLE: - case VTK_BIQUADRATIC_TRIANGLE: - case VTK_PARAMETRIC_TRI_SURFACE: - case VTK_HIGHER_ORDER_TRIANGLE: - case VTK_LAGRANGE_TRIANGLE: - ctype = smtk::mesh::Triangle; - break; - case VTK_QUAD: - case VTK_PIXEL: - case VTK_QUADRATIC_QUAD: - case VTK_BIQUADRATIC_QUAD: - case VTK_QUADRATIC_LINEAR_QUAD: - case VTK_PARAMETRIC_QUAD_SURFACE: - case VTK_HIGHER_ORDER_QUAD: - case VTK_LAGRANGE_QUADRILATERAL: - ctype = smtk::mesh::Quad; - break; - case VTK_POLYGON: - case VTK_QUADRATIC_POLYGON: - case VTK_HIGHER_ORDER_POLYGON: - ctype = smtk::mesh::Polygon; - break; - case VTK_TETRA: - case VTK_QUADRATIC_TETRA: - case VTK_PARAMETRIC_TETRA_REGION: - case VTK_HIGHER_ORDER_TETRAHEDRON: - case VTK_LAGRANGE_TETRAHEDRON: - ctype = smtk::mesh::Tetrahedron; - break; - case VTK_PYRAMID: - case VTK_QUADRATIC_PYRAMID: - case VTK_HIGHER_ORDER_PYRAMID: - case VTK_LAGRANGE_PYRAMID: - ctype = smtk::mesh::Pyramid; - break; - case VTK_WEDGE: - case VTK_QUADRATIC_WEDGE: - case VTK_QUADRATIC_LINEAR_WEDGE: - case VTK_BIQUADRATIC_QUADRATIC_WEDGE: - case VTK_HIGHER_ORDER_WEDGE: - case VTK_LAGRANGE_WEDGE: - ctype = smtk::mesh::Wedge; - break; - case VTK_HEXAHEDRON: - case VTK_VOXEL: - case VTK_QUADRATIC_HEXAHEDRON: - case VTK_TRIQUADRATIC_HEXAHEDRON: - case VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON: - case VTK_PARAMETRIC_HEX_REGION: - case VTK_HIGHER_ORDER_HEXAHEDRON: - case VTK_LAGRANGE_HEXAHEDRON: - ctype = smtk::mesh::Hexahedron; - break; - default: - ctype = smtk::mesh::CellType_MAX; - break; - } - return ctype; -} - -smtk::mesh::HandleRange convertVTKDataSet(vtkDataSet* dataset, smtk::mesh::ResourcePtr& resource) -{ - smtk::mesh::InterfacePtr iface = resource->interface(); - smtk::mesh::BufferedCellAllocatorPtr alloc = iface->bufferedCellAllocator(); - - smtk::mesh::HandleRange initRange = resource->cells().range(); - - if (!alloc->reserveNumberOfCoordinates(dataset->GetNumberOfPoints())) - { - return smtk::mesh::HandleRange(); - } - - //note this could become a performance bottleneck. If that occurs - //we will need to move to a template dispatch solution to handle floats, - //doubles, and vtk Mapped Arrays - double point[3]; - for (vtkIdType i = 0; i < dataset->GetNumberOfPoints(); ++i) - { - dataset->GetPoint(i, point); - alloc->setCoordinate(i, point); - } - - vtkNew pts; - for (vtkIdType i = 0; i < dataset->GetNumberOfCells(); ++i) - { - dataset->GetCellPoints(i, pts); - vtkIdType* ptPtr = pts->GetPointer(0); - auto cellType = dataset->GetCellType(i); - { - vtkIdType tmp; - if (cellType == VTK_PIXEL || cellType == VTK_VOXEL) - { - tmp = ptPtr[2]; - ptPtr[2] = ptPtr[3]; - ptPtr[3] = tmp; - if (cellType == VTK_VOXEL) - { - tmp = ptPtr[6]; - ptPtr[6] = ptPtr[7]; - ptPtr[7] = tmp; - } - } - } - alloc->addCell(vtkToSMTKCell(cellType), ptPtr, pts->GetNumberOfIds()); - } - if (!alloc->flush()) - { - return smtk::mesh::HandleRange(); - } - - return alloc->cells() - initRange; -} - -smtk::mesh::HandleRange convertDomain( - vtkCellData* cellData, - const smtk::mesh::InterfacePtr& iface, - const smtk::mesh::HandleRange& cells, - const std::string& materialPropertyName) -{ - if (cellData == nullptr) - { - //we have no information - return smtk::mesh::HandleRange(); - } - - vtkDataArray* materialData = cellData->GetArray(materialPropertyName.c_str()); - if (!materialData || materialData->GetNumberOfComponents() != 1) - { //needs to be a scalar array - return smtk::mesh::HandleRange(); - } - - if (materialData->GetNumberOfTuples() != static_cast(cells.size())) - { //we currently don't support applying material when - //we only loaded in some of the cells - return smtk::mesh::HandleRange(); - } - - std::map meshes; - //move each cell from the entire pool, into a range - //that represents that material mesh. This is slowish. - - vtkIdType index = 0; - for (auto i = smtk::mesh::rangeElementsBegin(cells); i != smtk::mesh::rangeElementsEnd(cells); - ++i, ++index) - { - const int currentMaterial = static_cast(materialData->GetTuple1(index)); - meshes[currentMaterial].insert(*i); - } - - smtk::mesh::HandleRange meshHandles; - typedef std::map::const_iterator map_cit; - for (map_cit i = meshes.begin(); i != meshes.end(); ++i) - { - smtk::mesh::Handle meshId; - const bool created = iface->createMesh(i->second, meshId); - if (created) - { - smtk::mesh::HandleRange meshHandlesForDomain; - meshHandlesForDomain.insert(meshId); - //assign a material id to the mesh - iface->setDomain(meshHandlesForDomain, smtk::mesh::Domain(i->first)); - meshHandles.insert(meshId); - } - } - - return meshHandles; -} -} // namespace - -ImportVTKData::ImportVTKData() = default; - -smtk::mesh::ResourcePtr ImportVTKData::operator()( - const std::string& filename, - const smtk::mesh::InterfacePtr& interface, - std::string materialPropertyName) const -{ - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(interface); - return this->operator()(filename, resource, materialPropertyName) ? resource - : smtk::mesh::ResourcePtr(); -} - -bool ImportVTKData::operator()( - const std::string& filename, - smtk::mesh::ResourcePtr resource, - std::string materialPropertyName) const -{ - ImportAsVTKData importAsVTKData; - auto data = importAsVTKData(filename); - if (auto* ugrid = vtkUnstructuredGrid::SafeDownCast(data.GetPointer())) - { - return this->operator()(ugrid, resource, materialPropertyName); - } - else if (auto* poly = vtkPolyData::SafeDownCast(data.GetPointer())) - { - // vtkPolyData can hold polylines, triangle strips, polygons and other - // hard-to-digest cells. These cells can be deconstructed into SMTK-friendly - // cells via the vtkTriangleFilter. - vtkNew triangleFilter; - triangleFilter->SetInputData(poly); - triangleFilter->Update(); - return this->operator()(triangleFilter->GetOutput(), resource, materialPropertyName); - } - else - { - return false; - } -} - -smtk::mesh::MeshSet ImportVTKData::operator()(vtkDataSet* dataset, smtk::mesh::ResourcePtr resource) - const -{ - //make sure we have a valid dataset - if (!dataset) - { - return smtk::mesh::MeshSet(); - } - else if (dataset->GetNumberOfPoints() == 0 || dataset->GetNumberOfCells() == 0) - { - //early terminate if the dataset is empty. - return smtk::mesh::MeshSet(); - } - - vtkPolyData* polydata = vtkPolyData::SafeDownCast(dataset); - if (polydata && polydata->NeedToBuildCells()) - { - polydata->BuildCells(); - } - smtk::mesh::HandleRange cells = convertVTKDataSet(dataset, resource); - - smtk::mesh::MeshSet meshset = resource->createMesh(smtk::mesh::CellSet(resource, cells)); - - resource->interface()->setModifiedState(false); - return meshset; -} - -bool ImportVTKData::operator()( - vtkDataSet* dataset, - smtk::mesh::ResourcePtr resource, - std::string materialPropertyName) const -{ - //make sure we have valid data - if (!dataset) - { - return false; - } - else if (dataset->GetNumberOfPoints() == 0 || dataset->GetNumberOfCells() == 0) - { - //early terminate if the dataset is empty. - return false; - } - - smtk::mesh::InterfacePtr iface = resource->interface(); - smtk::mesh::BufferedCellAllocatorPtr alloc = iface->bufferedCellAllocator(); - - vtkPolyData* polydata = vtkPolyData::SafeDownCast(dataset); - if (polydata && polydata->NeedToBuildCells()) - { - polydata->BuildCells(); - } - smtk::mesh::HandleRange cells = convertVTKDataSet(dataset, resource); - - smtk::mesh::MeshSet mesh; - - if (materialPropertyName.empty()) - { //if we don't have a material we create a single mesh - smtk::mesh::Handle vtkMeshHandle; - bool created = iface->createMesh(cells, vtkMeshHandle); - if (created) - { - smtk::mesh::HandleRange entities; - entities.insert(vtkMeshHandle); - mesh = smtk::mesh::MeshSet(resource->shared_from_this(), iface->getRoot(), entities); - } - } - else - { //make multiple meshes each one assigned a material value - smtk::mesh::HandleRange entities = - convertDomain(dataset->GetCellData(), iface, cells, materialPropertyName); - mesh = smtk::mesh::MeshSet(resource->shared_from_this(), iface->getRoot(), entities); - } - - // Now that we have a valid meshset, we add vtk cell & point data to it. - if (!mesh.is_empty()) - { - for (vtkIdType i = 0; i < dataset->GetCellData()->GetNumberOfArrays(); i++) - { - { - vtkDoubleArray* array = vtkDoubleArray::SafeDownCast(dataset->GetCellData()->GetArray(i)); - if (array != nullptr) - { - mesh.createCellField( - array->GetName(), - array->GetNumberOfComponents(), - smtk::mesh::FieldType::Double, - static_cast(array->GetVoidPointer(0))); - } - } - { - vtkIntArray* array = vtkIntArray::SafeDownCast(dataset->GetCellData()->GetArray(i)); - if (array != nullptr) - { - mesh.createCellField( - array->GetName(), - array->GetNumberOfComponents(), - smtk::mesh::FieldType::Integer, - static_cast(array->GetVoidPointer(0))); - } - } - } - - for (vtkIdType i = 0; i < dataset->GetPointData()->GetNumberOfArrays(); i++) - { - { - vtkDoubleArray* array = vtkDoubleArray::SafeDownCast(dataset->GetPointData()->GetArray(i)); - if (array != nullptr) - { - mesh.createPointField( - array->GetName(), - array->GetNumberOfComponents(), - smtk::mesh::FieldType::Double, - static_cast(array->GetVoidPointer(0))); - } - } - { - vtkIntArray* array = vtkIntArray::SafeDownCast(dataset->GetPointData()->GetArray(i)); - if (array != nullptr) - { - mesh.createPointField( - array->GetName(), - array->GetNumberOfComponents(), - smtk::mesh::FieldType::Integer, - static_cast(array->GetVoidPointer(0))); - } - } - } - } - iface->setModifiedState(false); - return !mesh.is_empty(); -} - -smtk::mesh::ResourcePtr ImportVTKData::operator()( - vtkDataSet* dataset, - const smtk::mesh::InterfacePtr& interface, - std::string materialPropertyName) const -{ - smtk::mesh::ResourcePtr c = smtk::mesh::Resource::create(interface); - return this->operator()(dataset, c, materialPropertyName) ? c : smtk::mesh::ResourcePtr(); -} -} // namespace mesh -} // namespace io -} // namespace vtk -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/vtk/io/mesh/ImportVTKData.h b/smtk/extension/vtk/io/mesh/ImportVTKData.h deleted file mode 100644 index ba0bb0b688ded01a2167c2602e8a5e5b835e7500..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/mesh/ImportVTKData.h +++ /dev/null @@ -1,93 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_extension_vtk_io_mesh_ImportVTKData_h -#define smtk_extension_vtk_io_mesh_ImportVTKData_h - -#include "smtk/PublicPointerDefs.h" -#include "smtk/extension/vtk/io/IOVTKExports.h" - -#include - -//forward declare vtk classes -class vtkDataSet; - -namespace smtk -{ -namespace mesh -{ -class MeshSet; -} -} // namespace smtk - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace io -{ -namespace mesh -{ - -//Import a VTK data set to a smtk::mesh::resource. -//Currently we only support creating a new database from a vtk data set. -class SMTKIOVTK_EXPORT ImportVTKData -{ -public: - explicit ImportVTKData(); - - ImportVTKData(const ImportVTKData& other) = delete; - ImportVTKData& operator=(const ImportVTKData& other) = delete; - - //Import a VTK dataset unstructured grid file (legacy or xml) as a - //resource. Optionally specify the cell property name to be used to split - //the mesh into muliple domains. - smtk::mesh::ResourcePtr operator()( - const std::string& filename, - const smtk::mesh::InterfacePtr& interface, - std::string domainPropertyName) const; - - //Import a VTK dataset or unstructured grid file (legacy or xml) into an - //existing resource. Optionally specify the cell property name to be used to - //split the mesh into muliple domains. - bool operator()( - const std::string& filename, - smtk::mesh::ResourcePtr resource, - std::string domainPropertyName) const; - - //Import a VTK dataset into an existing resource. Returns a meshset - //containing the newly created cells. - smtk::mesh::MeshSet operator()(vtkDataSet* dataset, smtk::mesh::ResourcePtr resource) const; - - //Import a VTK dataset into an existing resource and specify the - //cell property name to be used to split the mesh into muliple domains. - bool operator()( - vtkDataSet* dataset, - smtk::mesh::ResourcePtr resource, - std::string domainPropertyName) const; - - //Import a VTK dataset as a resource. - //Optionally specify the cell property name to be used to split - //the mesh into muliple domains. - smtk::mesh::ResourcePtr operator()( - vtkDataSet* dataset, - const smtk::mesh::InterfacePtr& interface, - std::string domainPropertyName = std::string()) const; -}; -} // namespace mesh -} // namespace io -} // namespace vtk -} // namespace extension -} // namespace smtk - -#endif //__smtk_extension_vtk_io_mesh_ImportVTKData_h diff --git a/smtk/extension/vtk/io/mesh/MeshIOVTK.cxx b/smtk/extension/vtk/io/mesh/MeshIOVTK.cxx deleted file mode 100644 index c517600214605077b00243054d927ace80161104..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/mesh/MeshIOVTK.cxx +++ /dev/null @@ -1,118 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/vtk/io/mesh/MeshIOVTK.h" - -#include "smtk/io/ExportMesh.h" -#include "smtk/io/ImportMesh.h" -#include "smtk/io/mesh/Format.h" -#include "smtk/io/mesh/MeshIO.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/extension/vtk/io/ImportAsVTKData.h" -#include "smtk/extension/vtk/io/mesh/ExportVTKData.h" -#include "smtk/extension/vtk/io/mesh/ImportVTKData.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace io -{ -namespace mesh -{ - -MeshIOVTK::MeshIOVTK() -{ - this->Formats.emplace_back( - "vtk unstructured grid", - std::vector({ ".vtu" }), - smtk::io::mesh::Format::Import | smtk::io::mesh::Format::Export); - this->Formats.emplace_back( - "vtk polydata", - std::vector({ ".vtp" }), - smtk::io::mesh::Format::Import | smtk::io::mesh::Format::Export); - this->Formats.emplace_back( - "vtk legacy", - std::vector({ ".vtk" }), - smtk::io::mesh::Format::Import | smtk::io::mesh::Format::Export); - smtk::extension::vtk::io::ImportAsVTKData import; - auto formats = import.fileFormats(); - for (auto& format : formats) - { - std::vector extensionVector; - extensionVector.reserve(format.Extensions.size()); - for (const auto& ext : format.Extensions) - { - extensionVector.emplace_back("." + ext); - } - this->Formats.emplace_back(format.Name, extensionVector, smtk::io::mesh::Format::Import); - } -} - -smtk::mesh::ResourcePtr MeshIOVTK::importMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - const std::string& domainPropertyName) const -{ - smtk::extension::vtk::io::mesh::ImportVTKData import; - return import(filePath, interface, domainPropertyName); -} - -bool MeshIOVTK::importMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - const std::string& domainPropertyName) const -{ - smtk::extension::vtk::io::mesh::ImportVTKData import; - return import(filePath, resource, domainPropertyName); -} - -bool MeshIOVTK::exportMesh(const std::string& filePath, smtk::mesh::ResourcePtr resource) const -{ - smtk::extension::vtk::io::mesh::ExportVTKData export_; - return export_(filePath, resource, ""); -} -} // namespace mesh -} // namespace io -} // namespace vtk -} // namespace extension -} // namespace smtk - -void smtk_extension_vtk_io_mesh_MeshIOVTK_AutoInit_Construct() -{ - smtk::io::ImportMesh::SupportedIOTypes().push_back( - smtk::io::mesh::MeshIOPtr(new smtk::extension::vtk::io::mesh::MeshIOVTK())); - smtk::io::ExportMesh::SupportedIOTypes().push_back( - smtk::io::mesh::MeshIOPtr(new smtk::extension::vtk::io::mesh::MeshIOVTK())); -} - -void smtk_extension_vtk_io_mesh_MeshIOVTK_AutoInit_Destruct() -{ - auto is_MeshIOVTK = [](const smtk::io::mesh::MeshIOPtr& meshIOPtr) { - return dynamic_cast(meshIOPtr.get()) != nullptr; - }; - - smtk::io::ImportMesh::SupportedIOTypes().erase(std::remove_if( - smtk::io::ImportMesh::SupportedIOTypes().begin(), - smtk::io::ImportMesh::SupportedIOTypes().end(), - is_MeshIOVTK)); - smtk::io::ExportMesh::SupportedIOTypes().erase(std::remove_if( - smtk::io::ExportMesh::SupportedIOTypes().begin(), - smtk::io::ExportMesh::SupportedIOTypes().end(), - is_MeshIOVTK)); -} - -smtkComponentInitMacro(smtk_extension_vtk_io_mesh_MeshIOVTK); diff --git a/smtk/extension/vtk/io/mesh/MeshIOVTK.h b/smtk/extension/vtk/io/mesh/MeshIOVTK.h deleted file mode 100644 index ecba57699192ee4d620617f36e8e1c68cbd6abb7..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/mesh/MeshIOVTK.h +++ /dev/null @@ -1,72 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_extensions_vtk_io_MeshIOVTK_h -#define smtk_extensions_vtk_io_MeshIOVTK_h - -#include "smtk/AutoInit.h" - -#include "smtk/PublicPointerDefs.h" -#include "smtk/extension/vtk/io/IOVTKExports.h" - -#include "smtk/io/mesh/MeshIO.h" - -#include -/**\brief Export an SMTK mesh to a file - * - */ - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace io -{ -namespace mesh -{ - -class SMTKIOVTK_EXPORT MeshIOVTK : public smtk::io::mesh::MeshIO -{ -public: - static constexpr const char* const CellHandlesName = "cell handles"; - static constexpr const char* const PointHandlesName = "point handles"; - - // smtkAutoInitComponentMacro(smtk_extension_vtk_io_MeshIOVTK) - MeshIOVTK(); - - //Load a vtk XML data file as a new resource into the given manager - //Returns an invalid resource that is NOT part of the manager if the - //file can't be loaded - smtk::mesh::ResourcePtr importMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - const std::string& domainPropertyName) const override; - - //Merge a vtk data file into an existing valid resource. - bool importMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - const std::string& domainPropertyName) const override; - - //Epxort a resource to a VTK XML unstructured grid or polydata. - bool exportMesh(const std::string& filePath, smtk::mesh::ResourcePtr resource) const override; -}; -} // namespace mesh -} // namespace io -} // namespace vtk -} // namespace extension -} // namespace smtk - -void SMTKIOVTK_EXPORT smtk_extension_vtk_io_mesh_MeshIOVTK_AutoInit_Construct(); -void SMTKIOVTK_EXPORT smtk_extension_vtk_io_mesh_MeshIOVTK_AutoInit_Destruct(); - -#endif diff --git a/smtk/extension/vtk/io/mesh/PointCloudFromVTKFile.cxx b/smtk/extension/vtk/io/mesh/PointCloudFromVTKFile.cxx deleted file mode 100644 index c018cbaad50d88def3a4a38975fd88e5e37ec703..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/mesh/PointCloudFromVTKFile.cxx +++ /dev/null @@ -1,90 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/vtk/io/mesh/PointCloudFromVTKFile.h" - -#include "smtk/extension/vtk/io/ImportAsVTKData.h" - -#include "smtk/model/AuxiliaryGeometry.h" - -#include "vtkDoubleArray.h" -#include "vtkFloatArray.h" -#include "vtkImageData.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkNew.h" -#include "vtkPointData.h" -#include "vtkPolyData.h" -#include "vtkUniformGrid.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -namespace -{ -bool registered = PointCloudFromVTKFile::registerClass(); -} - -bool PointCloudFromVTKFile::valid(const std::string& fileName) const -{ - smtk::extension::vtk::io::ImportAsVTKData importAsVTKData; - return importAsVTKData.valid(fileName); -} - -smtk::mesh::PointCloud PointCloudFromVTKFile::operator()(const std::string& fileName) -{ - smtk::extension::vtk::io::ImportAsVTKData importAsVTKData; - auto* externalData = vtkDataSet::SafeDownCast(importAsVTKData(fileName)); - if (!externalData) - { - // Something went wrong and we have no vtkDataSet. - throw std::invalid_argument("File cannot be read."); - } - - std::function(std::size_t)> coordinates = [&](std::size_t i) { - double pt[3]; - externalData->GetPoint(i, pt); - return std::array({ { pt[0], pt[1], 0. } }); - }; - - std::function data; - - // Check for elevation data. If it exists, use it. Otherwise, just use the - // z-coordinate of the data, - // TODO: no magic keywords! - vtkDataArray* elevationData = externalData->GetPointData()->GetScalars("Elevation"); - if (elevationData) - { - data = [=](std::size_t i) { return elevationData->GetTuple1(i); }; - } - else - { - data = [&](std::size_t i) { - double pt[3]; - externalData->GetPoint(i, pt); - return pt[2]; - }; - } - - std::function valid = [](std::size_t /*unused*/) { return true; }; - - return smtk::mesh::PointCloud(externalData->GetNumberOfPoints(), coordinates, data, valid); -} -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/vtk/io/mesh/PointCloudFromVTKFile.h b/smtk/extension/vtk/io/mesh/PointCloudFromVTKFile.h deleted file mode 100644 index bbf1464a92582e760eff619ef152675ea9fc4215..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/mesh/PointCloudFromVTKFile.h +++ /dev/null @@ -1,49 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_extensions_vtk_mesh_PointCloudFromVTK_h -#define smtk_extensions_vtk_mesh_PointCloudFromVTK_h - -#include "smtk/AutoInit.h" - -#include "smtk/PublicPointerDefs.h" -#include "smtk/extension/vtk/io/IOVTKExports.h" - -#include "smtk/common/Generator.h" -#include "smtk/mesh/interpolation/PointCloud.h" -#include "smtk/mesh/interpolation/PointCloudGenerator.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -/// A GeneratorType for creating PointClouds from VTK files. This class extends -/// smtk::mesh::PointCloudGenerator. -class SMTKIOVTK_EXPORT PointCloudFromVTKFile - : public smtk::common::GeneratorType -{ -public: - bool valid(const std::string& file) const override; - - smtk::mesh::PointCloud operator()(const std::string& file) override; -}; -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk - -#endif diff --git a/smtk/extension/vtk/io/mesh/StructuredGridFromVTKFile.cxx b/smtk/extension/vtk/io/mesh/StructuredGridFromVTKFile.cxx deleted file mode 100644 index c1e69eaa3eab58784b0f349ab6aeaf6aa59c61ef..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/mesh/StructuredGridFromVTKFile.cxx +++ /dev/null @@ -1,91 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/vtk/io/mesh/StructuredGridFromVTKFile.h" - -#include "smtk/extension/vtk/io/ImportAsVTKData.h" - -#include "smtk/model/AuxiliaryGeometry.h" - -#include "vtkDoubleArray.h" -#include "vtkFloatArray.h" -#include "vtkImageData.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkNew.h" -#include "vtkPointData.h" -#include "vtkPolyData.h" -#include "vtkUniformGrid.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -namespace -{ -bool registered = StructuredGridFromVTKFile::registerClass(); -} - -bool StructuredGridFromVTKFile::valid(const std::string& fileName) const -{ - smtk::extension::vtk::io::ImportAsVTKData importAsVTKData; - return importAsVTKData.valid(fileName); -} - -smtk::mesh::StructuredGrid StructuredGridFromVTKFile::operator()(const std::string& fileName) -{ - smtk::extension::vtk::io::ImportAsVTKData importAsVTKData; - auto* externalData = vtkDataSet::SafeDownCast(importAsVTKData(fileName)); - if (!externalData) - { - // Something went wrong and we have no vtkDataSet. - throw std::invalid_argument("File cannot be read."); - } - - smtk::mesh::StructuredGrid structuredgrid; - - if (vtkImageData* imageInput = vtkImageData::SafeDownCast(externalData)) - { - structuredgrid = smtk::mesh::StructuredGrid( - imageInput->GetExtent(), - imageInput->GetOrigin(), - imageInput->GetSpacing(), - [=](int i, int j) { return imageInput->GetScalarComponentAsDouble(i, j, 0, 0); }); - } - else if (vtkUniformGrid* gridInput = vtkUniformGrid::SafeDownCast(externalData)) - { - structuredgrid = smtk::mesh::StructuredGrid( - gridInput->GetExtent(), - gridInput->GetOrigin(), - gridInput->GetSpacing(), - [=](int i, int j) { return gridInput->GetScalarComponentAsDouble(i, j, 0, 0); }, - [=](int i, int j) { - int pos[3] = { i, j, 0 }; - return gridInput->IsPointVisible( - vtkStructuredData::ComputePointIdForExtent(gridInput->GetExtent(), pos)) != 0; - }); - } - else - { - throw std::invalid_argument("File does not contain structured data."); - } - - return structuredgrid; -} -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/vtk/io/mesh/StructuredGridFromVTKFile.h b/smtk/extension/vtk/io/mesh/StructuredGridFromVTKFile.h deleted file mode 100644 index ce7e8b8b83b1efc6d997991806a3a3fc5453286f..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/mesh/StructuredGridFromVTKFile.h +++ /dev/null @@ -1,50 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_extensions_vtk_io_mesh_StructuredGridFromVTKFile_h -#define smtk_extensions_vtk_io_mesh_StructuredGridFromVTKFile_h - -#include "smtk/AutoInit.h" - -#include "smtk/PublicPointerDefs.h" -#include "smtk/extension/vtk/io/IOVTKExports.h" - -#include "smtk/common/Generator.h" -#include "smtk/mesh/interpolation/StructuredGrid.h" -#include "smtk/mesh/interpolation/StructuredGridGenerator.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -/// A GeneratorType for creating StructuredGrids from VTK files. This class -/// extends smtk::mesh::StructuredGridGenerator. -class SMTKIOVTK_EXPORT StructuredGridFromVTKFile - : public smtk::common:: - GeneratorType -{ -public: - bool valid(const std::string&) const override; - - smtk::mesh::StructuredGrid operator()(const std::string&) override; -}; -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk - -#endif diff --git a/smtk/extension/vtk/io/pybind11/CMakeLists.txt b/smtk/extension/vtk/io/pybind11/CMakeLists.txt deleted file mode 100644 index 859923205b8039284e766efbc935c8969e5e053d..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/pybind11/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set(library_name "_smtkPybindIOVTK") -set(module_path "io/vtk") -set(build_path "${CMAKE_BINARY_DIR}/${SMTK_PYTHON_MODULEDIR}/smtk/${module_path}") -set(install_path "${SMTK_PYTHON_MODULEDIR}/smtk/${module_path}") - -pybind11_add_module(${library_name} PybindIOVTK.cxx) -target_include_directories(${library_name} PUBLIC - $ - ) -target_link_libraries(${library_name} LINK_PUBLIC smtkCore smtkIOVTK - VTK::CommonCore VTK::WrappingPythonCore ) -set_target_properties(${library_name} - PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${build_path}" - COMPILE_FLAGS ${SMTK_PYBIND11_FLAGS} - ) - -# Install library -install(TARGETS ${library_name} DESTINATION "${install_path}") - -# Create and install module __init__.py -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py" - "${build_path}/__init__.py" @ONLY - ) - -install( - FILES "${build_path}/__init__.py" - DESTINATION "${install_path}" - ) diff --git a/smtk/extension/vtk/io/pybind11/PybindExportVTKData.h b/smtk/extension/vtk/io/pybind11/PybindExportVTKData.h deleted file mode 100644 index d7eaacacdf7517c0bd0b3944dca96f092298d517..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/pybind11/PybindExportVTKData.h +++ /dev/null @@ -1,33 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_extension_vtk_io_mesh_ExportVTKData_h -#define pybind_smtk_extension_vtk_io_mesh_ExportVTKData_h - -#include - -#include "smtk/extension/vtk/io/mesh/ExportVTKData.h" - -namespace py = pybind11; - -inline py::class_< smtk::extension::vtk::io::mesh::ExportVTKData > pybind11_init_smtk_extension_vtk_io_mesh_ExportVTKData(py::module &m) -{ - py::class_< smtk::extension::vtk::io::mesh::ExportVTKData > instance(m, "ExportVTKData"); - instance - .def(py::init<>()) - .def("__call__", (bool (smtk::extension::vtk::io::mesh::ExportVTKData::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::std::string) const) &smtk::extension::vtk::io::mesh::ExportVTKData::operator(), py::arg("filename"), py::arg("resource"), py::arg("domainPropertyName") = "") - .def("__call__", (bool (smtk::extension::vtk::io::mesh::ExportVTKData::*)(::std::string const &, ::smtk::mesh::MeshSet const &, ::std::string) const) &smtk::extension::vtk::io::mesh::ExportVTKData::operator(), py::arg("filename"), py::arg("meshset"), py::arg("domainPropertyName") = "") - .def("__call__", [&](const smtk::extension::vtk::io::mesh::ExportVTKData& exportData, ::smtk::mesh::MeshSet const & ms, ::vtkDataSet* ds){ if (auto *pd = vtkPolyData::SafeDownCast(ds)){ exportData(ms, pd);} else if (auto *ug = vtkUnstructuredGrid::SafeDownCast(ds)){ exportData(ms, ug);}}) - .def("__call__", [&](const smtk::extension::vtk::io::mesh::ExportVTKData& exportData, ::smtk::mesh::MeshSet const & ms, ::vtkDataSet* ds, const std::string& domain){ if (auto *pd = vtkPolyData::SafeDownCast(ds)){ exportData(ms, pd, domain);} else if (auto *ug = vtkUnstructuredGrid::SafeDownCast(ds)){ exportData(ms, ug, domain);}}) - ; - return instance; -} - -#endif diff --git a/smtk/extension/vtk/io/pybind11/PybindIOVTK.cxx b/smtk/extension/vtk/io/pybind11/PybindIOVTK.cxx deleted file mode 100644 index f473a2ade73ce3bba11417f801011bfe973daff8..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/pybind11/PybindIOVTK.cxx +++ /dev/null @@ -1,56 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include -SMTK_THIRDPARTY_POST_INCLUDE - -#include - -namespace py = pybind11; - -template -using PySharedPtrClass = py::class_, Args...>; - -#include "vtkPolyData.h" -#include "vtkUnstructuredGrid.h" - -#include "smtk/extension/vtk/pybind11/PybindVTKTypeCaster.h" - -#include "PybindExportVTKData.h" -#include "PybindImportAsVTKData.h" -#include "PybindImportVTKData.h" -#include "PybindMeshIOVTK.h" - -#include "smtk/io/mesh/MeshIO.h" - -#include "smtk/extension/vtk/io/mesh/PointCloudFromVTKFile.h" -#include "smtk/extension/vtk/io/mesh/StructuredGridFromVTKFile.h" - -PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); - -PYBIND11_MODULE(_smtkPybindIOVTK, io) -{ - io.doc() = ""; - - // The order of these function calls is important! It was determined by - // comparing the dependencies of each of the wrapped objects. - py::class_< smtk::extension::vtk::io::mesh::ExportVTKData > smtk_extension_vtk_io_mesh_ExportVTKData = pybind11_init_smtk_extension_vtk_io_mesh_ExportVTKData(io); - py::class_< smtk::extension::vtk::io::mesh::ImportVTKData > smtk_extension_vtk_io_mesh_ImportVTKData = pybind11_init_smtk_extension_vtk_io_mesh_ImportVTKData(io); - PySharedPtrClass< smtk::extension::vtk::io::mesh::MeshIOVTK, smtk::io::mesh::MeshIO > smtk_extension_vtk_io_mesh_MeshIOVTK = pybind11_init_smtk_extension_vtk_io_mesh_MeshIOVTK(io); - py::class_ smtk_extension_vtk_io_ImportAsVTKData = pybind11_init_smtk_extension_vtk_io_ImportAsVTKData(io); - - bool pcRegistered = smtk::extension::vtk::mesh::PointCloudFromVTKFile::registerClass(); - (void)pcRegistered; - bool sgRegistered = smtk::extension::vtk::mesh::StructuredGridFromVTKFile::registerClass(); - (void)sgRegistered; -} diff --git a/smtk/extension/vtk/io/pybind11/PybindImportAsVTKData.h b/smtk/extension/vtk/io/pybind11/PybindImportAsVTKData.h deleted file mode 100644 index 5995e1224a48209974523fa46f44f3a3a45fd2ab..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/pybind11/PybindImportAsVTKData.h +++ /dev/null @@ -1,37 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_extension_vtk_io_ImportAsVTKData_h -#define pybind_smtk_extension_vtk_io_ImportAsVTKData_h - -#include - -#include "smtk/extension/vtk/io/IOVTKExports.h" - -#include "vtkSmartPointer.h" - -#include "smtk/extension/vtk/io/ImportAsVTKData.h" - -namespace py = pybind11; - -inline py::class_ pybind11_init_smtk_extension_vtk_io_ImportAsVTKData(py::module &m) -{ - py::class_< smtk::extension::vtk::io::ImportAsVTKData> instance(m, "ImportAsVTKData"); - instance - .def(py::init<>()) - .def(py::init<::smtk::extension::vtk::io::ImportAsVTKData const &>()) - .def("__call__", (vtkSmartPointer (smtk::extension::vtk::io::ImportAsVTKData::*)(::std::string const &)) &smtk::extension::vtk::io::ImportAsVTKData::operator()) - .def("deepcopy", (smtk::extension::vtk::io::ImportAsVTKData & (smtk::extension::vtk::io::ImportAsVTKData::*)(::smtk::extension::vtk::io::ImportAsVTKData const &)) &smtk::extension::vtk::io::ImportAsVTKData::operator=) - .def("valid", (bool (smtk::extension::vtk::io::ImportAsVTKData::*)(::std::string const&) const) &smtk::extension::vtk::io::ImportAsVTKData::valid, py::arg("file")) - ; - return instance; -} - -#endif diff --git a/smtk/extension/vtk/io/pybind11/PybindImportVTKData.h b/smtk/extension/vtk/io/pybind11/PybindImportVTKData.h deleted file mode 100644 index c1762340310a267df27c7d99beb504b89586af02..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/pybind11/PybindImportVTKData.h +++ /dev/null @@ -1,37 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_extension_vtk_io_mesh_ImportVTKData_h -#define pybind_smtk_extension_vtk_io_mesh_ImportVTKData_h - -#include - -#include "smtk/extension/vtk/io/mesh/ImportVTKData.h" - -#include "smtk/mesh/core/Resource.h" - -namespace py = pybind11; - -inline py::class_< smtk::extension::vtk::io::mesh::ImportVTKData > pybind11_init_smtk_extension_vtk_io_mesh_ImportVTKData(py::module &m) -{ - py::class_< smtk::extension::vtk::io::mesh::ImportVTKData > instance(m, "ImportVTKData"); - instance - .def(py::init<>()) - .def("__call__", (smtk::mesh::ResourcePtr (smtk::extension::vtk::io::mesh::ImportVTKData::*)(::std::string const &, const ::smtk::mesh::InterfacePtr &, ::std::string) const) &smtk::extension::vtk::io::mesh::ImportVTKData::operator()) - .def("__call__", (bool (smtk::extension::vtk::io::mesh::ImportVTKData::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::std::string) const) &smtk::extension::vtk::io::mesh::ImportVTKData::operator()) - .def("__call__", (smtk::mesh::MeshSet (smtk::extension::vtk::io::mesh::ImportVTKData::*)(::vtkDataSet *, ::smtk::mesh::ResourcePtr) const) &smtk::extension::vtk::io::mesh::ImportVTKData::operator()) - .def("__call__", (bool (smtk::extension::vtk::io::mesh::ImportVTKData::*)(::vtkDataSet *, ::smtk::mesh::ResourcePtr, ::std::string) const) &smtk::extension::vtk::io::mesh::ImportVTKData::operator()) - .def("__call__", (smtk::mesh::ResourcePtr (smtk::extension::vtk::io::mesh::ImportVTKData::*)(::vtkDataSet *, const ::smtk::mesh::InterfacePtr &, ::std::string) const) &smtk::extension::vtk::io::mesh::ImportVTKData::operator()) - .def("__call__", [&](const smtk::extension::vtk::io::mesh::ImportVTKData& importData, vtkDataSet *pd, const ::smtk::mesh::InterfacePtr& interface){ return importData(pd, interface); }) - ; - return instance; -} - -#endif diff --git a/smtk/extension/vtk/io/pybind11/PybindMeshIOVTK.h b/smtk/extension/vtk/io/pybind11/PybindMeshIOVTK.h deleted file mode 100644 index acc788d56a8189efa206466f0db34556edf823d1..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/pybind11/PybindMeshIOVTK.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_extension_vtk_io_mesh_MeshIOVTK_h -#define pybind_smtk_extension_vtk_io_mesh_MeshIOVTK_h - -#include - -#include "smtk/extension/vtk/io/mesh/MeshIOVTK.h" - -#include "smtk/io/mesh/MeshIO.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::extension::vtk::io::mesh::MeshIOVTK, smtk::io::mesh::MeshIO > pybind11_init_smtk_extension_vtk_io_mesh_MeshIOVTK(py::module &m) -{ - PySharedPtrClass< smtk::extension::vtk::io::mesh::MeshIOVTK, smtk::io::mesh::MeshIO > instance(m, "MeshIOVTK"); - instance - .def(py::init<>()) - .def(py::init<::smtk::extension::vtk::io::mesh::MeshIOVTK const &>()) - .def("deepcopy", (smtk::extension::vtk::io::mesh::MeshIOVTK & (smtk::extension::vtk::io::mesh::MeshIOVTK::*)(::smtk::extension::vtk::io::mesh::MeshIOVTK const &)) &smtk::extension::vtk::io::mesh::MeshIOVTK::operator=) - .def("importMesh", (smtk::mesh::ResourcePtr (smtk::extension::vtk::io::mesh::MeshIOVTK::*)(::std::string const &, const ::smtk::mesh::InterfacePtr &, ::std::string const &) const) &smtk::extension::vtk::io::mesh::MeshIOVTK::importMesh, py::arg("filePath"), py::arg("interface"), py::arg("domainPropertyName")) - .def("importMesh", (bool (smtk::extension::vtk::io::mesh::MeshIOVTK::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::std::string const &) const) &smtk::extension::vtk::io::mesh::MeshIOVTK::importMesh, py::arg("filePath"), py::arg("resource"), py::arg("domainPropertyName")) - .def("exportMesh", &smtk::extension::vtk::io::mesh::MeshIOVTK::exportMesh, py::arg("filePath"), py::arg("resource")) - ; - return instance; -} - -#endif diff --git a/smtk/extension/vtk/io/pybind11/__init__.py b/smtk/extension/vtk/io/pybind11/__init__.py deleted file mode 100644 index 50faebe115e54e71886ed5aaf7e5a97a705ef49d..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/pybind11/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - -from ._smtkPybindIOVTK import * diff --git a/smtk/extension/vtk/io/testing/CMakeLists.txt b/smtk/extension/vtk/io/testing/CMakeLists.txt index 83305da3a2914ab6d4dec88c168fc7037bd7553e..8e0b9300c35e379e4e9db9c2db7d2ca7931a71dc 100644 --- a/smtk/extension/vtk/io/testing/CMakeLists.txt +++ b/smtk/extension/vtk/io/testing/CMakeLists.txt @@ -1,5 +1 @@ add_subdirectory(cxx) - -if(SMTK_ENABLE_PYTHON_WRAPPING) - add_subdirectory(python) -endif() diff --git a/smtk/extension/vtk/io/testing/cxx/CMakeLists.txt b/smtk/extension/vtk/io/testing/cxx/CMakeLists.txt index bd8890b3528050513829ddbf91a93dde63cf52f9..ef39c435e7c2235b35fe86a42e77b8c48a1b649f 100644 --- a/smtk/extension/vtk/io/testing/cxx/CMakeLists.txt +++ b/smtk/extension/vtk/io/testing/cxx/CMakeLists.txt @@ -14,18 +14,10 @@ set(unit_tests UnitTestRedirectOutput.cxx ) -set(unit_tests_which_require_data - TestImportSTL.cxx - UnitTestImportExportVTKData.cxx - UnitTestMeshIOVTK.cxx - ImportExportMeshWithCellField.cxx - ) - set(unit_test_libs) smtk_unit_tests(LABELS "VTK" SOURCES ${unit_tests} - SOURCES_REQUIRE_DATA ${unit_tests_which_require_data} LIBRARIES smtkIOVTK smtkCoreModelTesting VTK::CommonComputationalGeometry VTK::CommonCore @@ -37,26 +29,3 @@ smtk_unit_tests(LABELS "VTK" ${unit_test_libs} # TODO: Use Boost:: imported targets ${Boost_LIBRARIES}) - -add_executable(MultiScaleConverter MultiScaleConverter.cxx) -target_link_libraries(MultiScaleConverter - LINK_PUBLIC smtkIOVTK - VTK::CommonComputationalGeometry - VTK::CommonCore - VTK::CommonDataModel - VTK::FiltersSources - VTK::IOXML - VTK::vtksys - LINK_PRIVATE MOAB) - -add_executable(SurfacePerMaterialExtraction SurfacePerMaterialExtraction.cxx) - -target_link_libraries(SurfacePerMaterialExtraction - LINK_PUBLIC smtkIOVTK - VTK::CommonComputationalGeometry - VTK::CommonCore - VTK::CommonDataModel - VTK::FiltersSources - VTK::IOXML - VTK::vtksys - LINK_PRIVATE MOAB) diff --git a/smtk/extension/vtk/io/testing/cxx/ImportExportMeshWithCellField.cxx b/smtk/extension/vtk/io/testing/cxx/ImportExportMeshWithCellField.cxx deleted file mode 100644 index 968f25eedaffac8cc7ffec806aa79d3fcd798a37..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/testing/cxx/ImportExportMeshWithCellField.cxx +++ /dev/null @@ -1,201 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/extension/vtk/io/mesh/ExportVTKData.h" -#include "smtk/extension/vtk/io/mesh/ImportVTKData.h" - -#include "smtk/io/ImportMesh.h" - -#include "smtk/model/DefaultSession.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "vtkNew.h" -#include "vtkPolyData.h" -#include "vtkSmartPointer.h" -#include "vtkXMLPolyDataReader.h" -#include "vtkXMLPolyDataWriter.h" - -#include -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -smtk::mesh::ResourcePtr load_mesh(const smtk::mesh::InterfacePtr& interface) -{ - std::string file_path(data_root); - file_path += "/mesh/2d/twoMeshes.h5m"; - - smtk::mesh::ResourcePtr c = smtk::io::importMesh(file_path, interface); - - return c; -} - -class SetCellField : public smtk::mesh::CellForEach -{ -private: - const std::function& m_dataGenerator; - smtk::mesh::CellField& m_cellField; - -public: - SetCellField( - const std::function& dataGenerator, - smtk::mesh::CellField& cf) - : smtk::mesh::CellForEach(true) - , m_dataGenerator(dataGenerator) - , m_cellField(cf) - { - } - - void forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType /*cellType*/, int numPts) - override - { - double xyz[3] = { 0., 0., 0. }; - for (int i = 0; i < numPts; i++) - { - xyz[0] += this->coordinates()[i * 3 + 0]; - xyz[1] += this->coordinates()[i * 3 + 1]; - xyz[2] += this->coordinates()[i * 3 + 2]; - } - for (int i = 0; i < 3; i++) - { - xyz[i] /= numPts; - } - double value = m_dataGenerator(xyz[0], xyz[1], xyz[2]); - smtk::mesh::HandleRange range; - range.insert(cellId); - m_cellField.set(range, &value); - } -}; - -class ValidateCellField : public smtk::mesh::CellForEach -{ -private: - const std::function& m_dataGenerator; - smtk::mesh::CellField& m_cellField; - const double EPSILON = 1.e-14; - -public: - ValidateCellField( - const std::function& dataGenerator, - smtk::mesh::CellField& cf) - : smtk::mesh::CellForEach(true) - , m_dataGenerator(dataGenerator) - , m_cellField(cf) - { - } - - void forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType /*cellType*/, int numPts) - override - { - double xyz[3] = { 0., 0., 0. }; - for (int i = 0; i < numPts; i++) - { - xyz[0] += this->coordinates()[i * 3 + 0]; - xyz[1] += this->coordinates()[i * 3 + 1]; - xyz[2] += this->coordinates()[i * 3 + 2]; - } - for (int i = 0; i < 3; i++) - { - xyz[i] /= numPts; - } - double expectedValue = m_dataGenerator(xyz[0], xyz[1], xyz[2]); - smtk::mesh::HandleRange range; - range.insert(cellId); - double value = 0.; - m_cellField.get(range, &value); - - test(std::abs(expectedValue - value) < EPSILON); - } -}; -} // namespace - -int ImportExportMeshWithCellField(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".vtp"; - - std::function euclideanDistance = - [](double x, double y, double z) { return std::sqrt(x * x + y * y + z * z); }; - - { - smtk::mesh::InterfacePtr interface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr c = load_mesh(interface); - smtk::mesh::MeshSet mesh = c->meshes(); - smtk::mesh::CellField distanceCellField = - mesh.createCellField("euclidean distance", 1, smtk::mesh::FieldType::Double); - - SetCellField setCellField(euclideanDistance, distanceCellField); - smtk::mesh::for_each(mesh.cells(), setCellField); - - smtk::extension::vtk::io::mesh::ExportVTKData exprt; - vtkSmartPointer pd = vtkSmartPointer::New(); - exprt(mesh, pd); - - vtkNew writer; - writer->SetFileName(write_path.c_str()); - writer->SetInputData(pd); - writer->Write(); - } - - { - vtkNew reader; - reader->SetFileName(write_path.c_str()); - reader->Update(); - - cleanup(write_path); - - smtk::extension::vtk::io::mesh::ImportVTKData imprt; - smtk::mesh::InterfacePtr interface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr c = imprt(reader->GetOutput(), interface); - smtk::mesh::MeshSet mesh = c->meshes(); - - smtk::mesh::CellField distanceCellField = mesh.cellField("euclidean distance"); - - ValidateCellField validateCellField(euclideanDistance, distanceCellField); - smtk::mesh::for_each(mesh.cells(), validateCellField); - } - - return 0; -} diff --git a/smtk/extension/vtk/io/testing/cxx/MultiScaleConverter.cxx b/smtk/extension/vtk/io/testing/cxx/MultiScaleConverter.cxx deleted file mode 100644 index 5050c5877043f0cd1e53d821c1be58689d3feef3..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/testing/cxx/MultiScaleConverter.cxx +++ /dev/null @@ -1,388 +0,0 @@ - -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/vtk/io/mesh/ImportVTKData.h" -#include "smtk/io/ImportMesh.h" -#include "smtk/io/WriteMesh.h" -#include "smtk/mesh/core/Resource.h" - -#include "vtkNew.h" -#include "vtkParametricBoy.h" -#include "vtkParametricFunctionSource.h" -#include "vtkPoints.h" -#include "vtkSmartPointer.h" -#include "vtkTetra.h" -#include "vtkUnstructuredGrid.h" -#include "vtkWedge.h" -#include "vtksys/SystemTools.hxx" - -#include "vtkXMLPolyDataReader.h" -#include "vtkXMLUnstructuredGridReader.h" - -namespace -{ - -template -vtkDataSet* readXMLFile(const std::string& fileName) -{ - vtkSmartPointer reader = vtkSmartPointer::New(); - reader->SetFileName(fileName.c_str()); - reader->Update(); - reader->GetOutput()->Register(reader); - return vtkDataSet::SafeDownCast(reader->GetOutput()); -} - -class Filter : public smtk::mesh::CellForEach -{ -public: - Filter() - : smtk::mesh::CellForEach(true) // needs coordinates - { - } - - smtk::mesh::HandleRange validPoints; -}; - -class CoolingPlateFilter : public Filter -{ - double yvalue; - double rvalue; - double origin[3]; - bool lessThan; - -public: - CoolingPlateFilter(double yval, double rval, const double* o, bool less = true) - : yvalue(yval) - , rvalue(rval) - , lessThan(less) - { - for (int i = 0; i < 3; ++i) - { - this->origin[i] = o[i]; - } - } - - void forCell(const smtk::mesh::Handle& /*cellId*/, smtk::mesh::CellType /*cellType*/, int numPts) - override - { - const std::vector& coords = this->coordinates(); - const smtk::mesh::Handle* const ptIds = this->pointIds(); - for (int i = 0; i < numPts; ++i) - { - const double r = sqrt( - (coords[(i * 3)] - this->origin[0]) * (coords[(i * 3)] - this->origin[0]) + - (coords[(i * 3) + 2] - this->origin[2]) * (coords[(i * 3) + 2] - this->origin[2])); - const double currValue[2] = { coords[(i * 3) + 1], r }; - //add in a small tolerance - - // if(currValue[0] >= (this->yvalue-0.002) && - // currValue[0] <= (this->yvalue+0.002) && - // ((this->lessThan && currValue[1]rvalue) || - // ((!this->lessThan) && currValue[1]>=this->rvalue))) - if (currValue[0] >= (this->yvalue - 0.002) && currValue[0] <= (this->yvalue + 0.002)) - { - if ( - (this->lessThan && (currValue[1] < this->rvalue)) || - ((!this->lessThan) && (currValue[1] >= this->rvalue))) - { - this->validPoints.insert(ptIds[i]); - } - } - } - } -}; - -class OuterEdgeFilter : public Filter -{ - double origin[3]; - double rmin; - -public: - OuterEdgeFilter(const double o[3], double r) - : rmin(r) - { - for (int i = 0; i < 3; i++) - { - this->origin[i] = o[i]; - } - } - - void forCell(const smtk::mesh::Handle& /*cellId*/, smtk::mesh::CellType /*cellType*/, int numPts) - override - { - const std::vector& coords = this->coordinates(); - const smtk::mesh::Handle* const ptIds = this->pointIds(); - - if (numPts < 3) - { - return; - } - - double v0[3]; // unit vector from origin to first point in cell - double v1[3]; // unit vector from first point to second point in cell - double v2[3]; // unit vector from first point to third point in cell - double normal[3]; // unit normal of cell - double len[3] = { 0., 0., 0. }; - - // compute v0,v1,v2 - for (int i = 0; i < 3; ++i) - { - v0[i] = coords[i] - this->origin[i]; - len[0] += v0[i] * v0[i]; - v1[i] = coords[3 + i] - coords[i]; - len[1] += v1[i] * v1[i]; - v2[i] = coords[6 + i] - coords[i]; - len[2] += v2[i] * v2[i]; - } - - for (int i = 0; i < 3; ++i) - { - len[i] = sqrt(len[i]); - } - - for (int i = 0; i < 3; ++i) - { - v0[i] /= len[0]; - v1[i] /= len[1]; - v2[i] /= len[2]; - } - - // compute normal - int i1, i2; - for (int i = 0; i < 3; ++i) - { - i1 = (i + 1) % 3; - i2 = (i + 2) % 3; - normal[i] = v1[i1] * v2[i2] - v1[i2] * v2[i1]; - } - - { - double mag = sqrt(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]); - - for (int i = 0; i < 3; ++i) - { - normal[i] /= mag; - } - } - - // reject any cells whose normal is not facing outwards - double dot = 0; - for (int i = 0; i < 3; ++i) - { - dot += v0[i] * normal[i]; - } - - if (fabs(dot) < .5) - { - return; - } - - for (int i = 0; i < numPts; ++i) - { - // reject any cells whose first coordinate is less than a distance - // from the axis of rotation - double r = sqrt(coords[3 * i] * coords[3 * i] + coords[3 * i + 2] * coords[3 * i + 2]); - if (r > rmin) - { - this->validPoints.insert(ptIds[i]); - } - } - } -}; - -int nextDirId = 0; - -bool labelIntersection( - const smtk::mesh::ResourcePtr& c, - const smtk::mesh::MeshSet& shell, - Filter& filter) -{ - //need to removing the verts cells from the query for now - //todo: filter needs to support vert cells - smtk::mesh::CellSet shellCells = shell.cells(); - - //extract the top cells - smtk::mesh::for_each(shellCells, filter); - smtk::mesh::CellSet filteredCells = smtk::mesh::CellSet(c, filter.validPoints); - - //for each material we iterate the meshsets - typedef std::vector DomainVecType; - typedef DomainVecType::const_iterator dom_cit; - - DomainVecType domains = c->domains(); - - //intersect the material and verts to find the verts of a given - //material that passed the filter. - //This verts than become a dirichlet set - for (dom_cit dom = domains.begin(); dom != domains.end(); ++dom) - { - smtk::mesh::MeshSet domainMeshes = c->meshes(*dom); - - //find all cells on the top of shell that share a vert in common - //with material volume - smtk::mesh::CellSet domainCells = domainMeshes.cells(); - smtk::mesh::CellSet contactCells = - smtk::mesh::point_intersect(domainCells, filteredCells, smtk::mesh::FullyContained); - if (!contactCells.is_empty()) - { - smtk::mesh::MeshSet contactD = c->createMesh(contactCells); - c->setDirichletOnMeshes(contactD, smtk::mesh::Dirichlet(nextDirId)); - nextDirId++; - } - } - - return true; -} - -void breakMaterialsByCellType(const smtk::mesh::ResourcePtr& c) -{ - //for each material we iterate the meshsets - typedef std::vector DomainVecType; - typedef DomainVecType::const_iterator mat_cit; - - DomainVecType domains = c->domains(); - - int domainsMade = 0; - for (mat_cit dom = domains.begin(); dom != domains.end(); ++dom) - { - smtk::mesh::MeshSet domainMeshes = c->meshes(*dom); - - //Iterate over all the different cell types, - //creating a single mesh for each cell type - for (int i = smtk::mesh::Line; i != smtk::mesh::CellType_MAX; ++i) - { - smtk::mesh::CellType ct = static_cast(i); - smtk::mesh::CellSet cells = domainMeshes.cells(ct); - if (!cells.is_empty()) - { - smtk::mesh::MeshSet ms = c->createMesh(cells); - const int v = (dom->value() * 100) + i; - c->setDomainOnMeshes(ms, smtk::mesh::Domain(v)); - domainsMade++; - } - } - - //now remove the original material mesh - c->removeMeshes(domainMeshes); - } -} - -template -smtk::mesh::ResourcePtr convert(vtkDataSetType* input, std::string material) -{ - smtk::extension::vtk::io::mesh::ImportVTKData imprt; - - //we convert the vtk data into a single mesh. - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(); - imprt(input, resource, material); - - if (!resource) - { - std::cerr << "unable to import the resource properly" << std::endl; - } - - return resource; -} - -void extractMaterials( - smtk::mesh::ResourcePtr c, - double radius, - double* origin, - std::string outputFile, - double* bounds) -{ - //extract the exterior-shell for all meshes. - smtk::mesh::MeshSet shell = c->meshes().extractShell(); - std::cout << "There are " << shell.size() << " shell mesh sets" << std::endl; - - //find the top and bottom of the shell and apply dirichlet properties - //to each section - if (bounds != nullptr) - { - const double ymin = bounds[2]; - { - CoolingPlateFilter filter2(ymin, radius, origin, true); - labelIntersection(c, shell, filter2); - } - - const double ymax = bounds[3]; - { - CoolingPlateFilter filter2(ymax, radius, origin, true); - labelIntersection(c, shell, filter2); - } - - const double center[3] = { 0., (ymax + ymin) * .5, 0. }; - const double rmin = (bounds[1] - bounds[0]) * .5 * .75; - { - OuterEdgeFilter filter(center, rmin); - labelIntersection(c, shell, filter); - } - } - - //take all meshes that have a material, and break them into a mesh per - //cell type. This is required since a block in exodus must be of - //a single cell type - breakMaterialsByCellType(c); - - std::cout << "number of domains: " << c->domains().size() << std::endl; - std::cout << "number of dirichlets: " << c->dirichlets().size() << std::endl; - - smtk::io::writeMesh(outputFile, c); -} -} // namespace - -int main(int argc, char* argv[]) -{ - std::string inputFileName(argc > 1 ? argv[1] : "mesh3D.vtu"); - std::string outputFileName(argc > 2 ? argv[2] : "mesh3D.exo"); - std::string materialName(argc > 3 ? argv[3] : std::string()); - double radius(argc > 4 ? atof(argv[4]) : -1.); - double origin[3] = { 0., 0., 0. }; - if (argc > 7) - { - for (int i = 0; i < 3; i++) - { - origin[i] = atof(argv[i + 5]); - } - } - - std::string extension = vtksys::SystemTools::GetFilenameLastExtension(inputFileName); - - // Dispatch based on the file extension - vtkDataSet* data; - double* bounds = nullptr; - smtk::mesh::ResourcePtr c; - if (extension == ".vtu") - { - data = readXMLFile(inputFileName); - c = convert(vtkUnstructuredGrid::SafeDownCast(data), materialName); - bounds = data->GetBounds(); - } - else if (extension == ".vtp") - { - data = readXMLFile(inputFileName); - c = convert(vtkPolyData::SafeDownCast(data), materialName); - bounds = data->GetBounds(); - } - else if (extension == ".h5m" || extension == ".exo") - { - c = smtk::mesh::Resource::create(); - smtk::io::importMesh(inputFileName, c); - } - - if (!c) - { - std::cerr << "failed to load the requested data" << std::endl; - return 1; - } - extractMaterials(c, radius, origin, outputFileName, bounds); - return 0; -} diff --git a/smtk/extension/vtk/io/testing/cxx/SurfacePerMaterialExtraction.cxx b/smtk/extension/vtk/io/testing/cxx/SurfacePerMaterialExtraction.cxx deleted file mode 100644 index 32d1a2c870a4a25854aab0c0fddc28fa78fab840..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/testing/cxx/SurfacePerMaterialExtraction.cxx +++ /dev/null @@ -1,219 +0,0 @@ - - -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/vtk/io/mesh/ImportVTKData.h" -#include "smtk/io/ImportMesh.h" -#include "smtk/io/WriteMesh.h" -#include "smtk/io/mesh/MeshIO.h" -#include "smtk/mesh/core/Resource.h" - -#include "vtkNew.h" -#include "vtkParametricBoy.h" -#include "vtkParametricFunctionSource.h" -#include "vtkPoints.h" -#include "vtkSmartPointer.h" -#include "vtkTetra.h" -#include "vtkUnstructuredGrid.h" -#include "vtkWedge.h" -#include "vtksys/SystemTools.hxx" - -#include "vtkXMLPolyDataReader.h" -#include "vtkXMLUnstructuredGridReader.h" - -namespace -{ - -template -vtkDataSet* readXMLFile(const std::string& fileName) -{ - vtkSmartPointer reader = vtkSmartPointer::New(); - reader->SetFileName(fileName.c_str()); - reader->Update(); - reader->GetOutput()->Register(reader); - return vtkDataSet::SafeDownCast(reader->GetOutput()); -} - -class ShellPerMesh : public smtk::mesh::MeshForEach -{ - int currentMaterialValue{ 0 }; - -public: - ShellPerMesh() = default; - - void forMesh(smtk::mesh::MeshSet& mesh) override - { - smtk::mesh::CellSet existingShellCells = mesh.cells(smtk::mesh::Dims2); - smtk::mesh::MeshSet shell = mesh; - if (existingShellCells.is_empty()) - { - shell = mesh.extractShell(); - } - else - { - shell = m_resource->createMesh(existingShellCells); - } - - smtk::mesh::Domain domain(currentMaterialValue++); - m_resource->setDomainOnMeshes(shell, domain); - } -}; - -void createShellPerMaterial(const smtk::mesh::ResourcePtr& c) -{ - //for each material we iterate the meshsets - typedef std::vector DomainVecType; - typedef DomainVecType::const_iterator dom_cit; - - DomainVecType domains = c->domains(); - - for (dom_cit dom = domains.begin(); dom != domains.end(); ++dom) - { - smtk::mesh::MeshSet domainMeshes = c->meshes(*dom); - smtk::mesh::MeshSet domainShell = domainMeshes.extractShell(); - c->setDomainOnMeshes(domainShell, *dom); - - c->removeMeshes(domainMeshes); - } -} - -void breakMaterialsByCellType(const smtk::mesh::ResourcePtr& c) -{ - //for each material we iterate the meshsets - typedef std::vector DomainVecType; - typedef DomainVecType::const_iterator dom_cit; - - DomainVecType domains = c->domains(); - - int domainsMade = 0; - for (dom_cit dom = domains.begin(); dom != domains.end(); ++dom) - { - smtk::mesh::MeshSet domainMeshes = c->meshes(*dom); - - //determine if we have mixed cell types for a given - //material - int numCellTypes = 0; - for (int i = smtk::mesh::Line; i != smtk::mesh::CellType_MAX; ++i) - { - smtk::mesh::CellType ct = static_cast(i); - smtk::mesh::CellSet cells = domainMeshes.cells(ct); - numCellTypes += cells.is_empty() ? 0 : 1; - } - - if (numCellTypes > 1) - { - //Iterate over all the different cell types, - //creating a single mesh for each cell type - for (int i = smtk::mesh::Line; i != smtk::mesh::CellType_MAX; ++i) - { - smtk::mesh::CellType ct = static_cast(i); - smtk::mesh::CellSet cells = domainMeshes.cells(ct); - if (!cells.is_empty()) - { - smtk::mesh::MeshSet ms = c->createMesh(cells); - const int v = (dom->value() * 100) + i; - c->setDomainOnMeshes(ms, smtk::mesh::Domain(v)); - domainsMade++; - } - } - //now remove the original material mesh - c->removeMeshes(domainMeshes); - } - } -} - -template -smtk::mesh::ResourcePtr convert(vtkDataSetType* input, std::string material) -{ - smtk::extension::vtk::io::mesh::ImportVTKData imprt; - - //we convert the vtk data into a single mesh. - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(); - imprt(input, resource, material); - - if (!resource) - { - std::cerr << "unable to import the resource properly" << std::endl; - } - - return resource; -} - -void extractSurfaces(smtk::mesh::ResourcePtr c, std::string outputFile) -{ - std::cout << "Info on input: " << std::endl; - std::cout << " volume mesh count: " << c->meshes(smtk::mesh::Dims3).size() << std::endl; - std::cout << " surface mesh count: " << c->meshes(smtk::mesh::Dims2).size() << std::endl; - std::cout << " material count: " << c->domains().size() << std::endl; - std::cout << " neumann count: " << c->dirichlets().size() << std::endl; - std::cout << " dirichlet count: " << c->neumanns().size() << std::endl; - - if (c->domains().empty()) - { //if no domains make a fake domain per volumetric mesh - ShellPerMesh spm; - smtk::mesh::MeshSet volMeshes = c->meshes(smtk::mesh::Dims3); - smtk::mesh::for_each(volMeshes, spm); - c->removeMeshes(volMeshes); - } - else - { - //create a shell per material - createShellPerMaterial(c); - } - - //take all meshes that have a material, and break them into a mesh per - //cell type. This is required since a block in exodus must be of - //a single cell type - breakMaterialsByCellType(c); - - std::cout << "number of domains in output: " << c->domains().size() << std::endl; - - smtk::io::writeMesh(outputFile, c, smtk::io::mesh::Subset::EntireResource); -} -} // namespace - -//MultiScaleConverter -//Another executalbe that is SurfacePerMaterial -int main(int argc, char* argv[]) -{ - std::string inputFileName(argc > 1 ? argv[1] : "mesh3D.vtu"); - std::string outputFileName(argc > 2 ? argv[2] : "mesh3D.exo"); - std::string materialName(argc > 3 ? argv[3] : std::string()); - - std::string extension = vtksys::SystemTools::GetFilenameLastExtension(inputFileName); - - // Dispatch based on the file extension - vtkDataSet* data; - smtk::mesh::ResourcePtr c; - if (extension == ".vtu") - { - data = readXMLFile(inputFileName); - c = convert(vtkUnstructuredGrid::SafeDownCast(data), materialName); - } - else if (extension == ".vtp") - { - data = readXMLFile(inputFileName); - c = convert(vtkPolyData::SafeDownCast(data), materialName); - } - else if (extension == ".h5m" || extension == ".exo") - { - c = smtk::mesh::Resource::create(); - smtk::io::importMesh(inputFileName, c); - } - - if (!c) - { - std::cerr << "failed to load the requested data" << std::endl; - return 1; - } - extractSurfaces(c, outputFileName); - return 0; -} diff --git a/smtk/extension/vtk/io/testing/cxx/TestImportSTL.cxx b/smtk/extension/vtk/io/testing/cxx/TestImportSTL.cxx deleted file mode 100644 index 96a869b9fa209e5240e5ce4e197f739105743327..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/testing/cxx/TestImportSTL.cxx +++ /dev/null @@ -1,45 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -void verify_import_stl() -{ - smtk::mesh::ResourcePtr c = smtk::mesh::Resource::create(); - - std::string file_path(data_root); - file_path += "/model/3d/stl/sphere.stl"; - - std::cout << "file_path: " << file_path << std::endl; - test(smtk::io::importMesh(file_path, c), "should be able to import stl file"); - test(!c->meshes().is_empty(), "aggregate meshset should be nonempty"); -} -} // namespace - -int TestImportSTL(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - verify_import_stl(); - - return 0; -} - -// This macro ensures the vtk io library is loaded into the executable -smtkComponentInitMacro(smtk_extension_vtk_io_mesh_MeshIOVTK) diff --git a/smtk/extension/vtk/io/testing/cxx/UnitTestImportExportVTKData.cxx b/smtk/extension/vtk/io/testing/cxx/UnitTestImportExportVTKData.cxx deleted file mode 100644 index 27ef2368cfbe2ef9676f92590555fa1bf974c5a1..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/testing/cxx/UnitTestImportExportVTKData.cxx +++ /dev/null @@ -1,259 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/vtk/io/mesh/ExportVTKData.h" -#include "smtk/extension/vtk/io/mesh/ImportVTKData.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "smtk/mesh/moab/Interface.h" - -#include "vtkAppendFilter.h" -#include "vtkCellIterator.h" -#include "vtkNew.h" -#include "vtkParametricBoy.h" -#include "vtkParametricFunctionSource.h" -#include "vtkPoints.h" -#include "vtkSmartPointer.h" -#include "vtkTetra.h" -#include "vtkUnstructuredGrid.h" -#include "vtkWedge.h" - -namespace -{ - -vtkSmartPointer make_EmptyPolyData() -{ - return vtkSmartPointer::New(); -} - -vtkSmartPointer make_TrianglePolyData() -{ - //use a vtk parametric source to construct polydata on the fly - vtkNew PB; - vtkNew PFS; - PFS->SetParametricFunction(PB.Get()); - - PFS->SetUResolution(400); - PFS->SetVResolution(500); - PFS->Update(); - - vtkSmartPointer result = vtkSmartPointer::New(); - - result->ShallowCopy(PFS->GetOutput()); - return result; -} - -vtkSmartPointer make_TriangleUGrid() -{ - //use a vtk parametric source to construct polydata on the fly - vtkNew PB; - vtkNew PFS; - PFS->SetParametricFunction(PB.Get()); - - PFS->SetUResolution(400); - PFS->SetVResolution(500); - PFS->Update(); - - vtkNew appendFilter; - appendFilter->AddInputData(PFS->GetOutput()); - appendFilter->Update(); - - vtkSmartPointer result = vtkSmartPointer::New(); - result->ShallowCopy(appendFilter->GetOutput()); - return result; -} - -vtkSmartPointer make_MixedVolUGrid() -{ - //manually create a mixed wedge and tet volume - vtkNew points; - // points->SetNumberOfPoints(8); - points->SetNumberOfPoints(7); - points->InsertPoint(0, 0, 1, 0); - points->InsertPoint(1, 0, 0, 0); - points->InsertPoint(2, 0, .5, .5); - points->InsertPoint(3, 1, 1, 0); - points->InsertPoint(4, 1, 0, 0); - points->InsertPoint(5, 1, .5, .5); - points->InsertPoint(6, .5, 1, 0); - // points->InsertPoint(7, .5, .5, 1); - - vtkNew aWedge; - aWedge->GetPointIds()->SetId(0, 0); - aWedge->GetPointIds()->SetId(1, 1); - aWedge->GetPointIds()->SetId(2, 2); - aWedge->GetPointIds()->SetId(3, 3); - aWedge->GetPointIds()->SetId(4, 4); - aWedge->GetPointIds()->SetId(5, 5); - - vtkNew aTetra; - aTetra->GetPointIds()->SetId(0, 0); - aTetra->GetPointIds()->SetId(1, 4); - aTetra->GetPointIds()->SetId(2, 6); - aTetra->GetPointIds()->SetId(3, 3); - - vtkSmartPointer result = vtkSmartPointer::New(); - result->SetPoints(points.GetPointer()); - result->Allocate(2); - result->InsertNextCell(aTetra->GetCellType(), aTetra->GetPointIds()); - result->InsertNextCell(aWedge->GetCellType(), aWedge->GetPointIds()); - - return result; -} - -double EPSILON = 1.e-6; - -void test_same_datasets(vtkDataSet* ds, vtkDataSet* ds2) -{ - test(ds->GetNumberOfPoints() == ds2->GetNumberOfPoints()); - test(ds->GetNumberOfCells() == ds2->GetNumberOfCells()); - - vtkCellIterator* it = ds->NewCellIterator(); - vtkCellIterator* it2 = ds2->NewCellIterator(); - it->InitTraversal(); - it2->InitTraversal(); - for (; !it->IsDoneWithTraversal() && !it2->IsDoneWithTraversal(); - it->GoToNextCell(), it2->GoToNextCell()) - { - test(it->GetCellType() == it2->GetCellType()); - test(it->GetNumberOfPoints() == it2->GetNumberOfPoints()); - vtkPoints* points = it->GetPoints(); - vtkPoints* points2 = it2->GetPoints(); - double xyz[3], xyz2[3]; - for (vtkIdType i = 0; i < points->GetNumberOfPoints(); i++) - { - points->GetPoint(i, xyz); - points2->GetPoint(i, xyz2); - for (vtkIdType j = 0; j < 3; j++) - { - test(fabs(xyz[j] - xyz2[j]) < EPSILON); - } - } - } - it->Delete(); - it2->Delete(); -} - -void verify_null_polydata() -{ - smtk::mesh::InterfacePtr interface = smtk::mesh::moab::make_interface(); - smtk::extension::vtk::io::mesh::ImportVTKData imprt; - - vtkPolyData* pd = nullptr; - smtk::mesh::ResourcePtr meshResource = imprt(pd, interface); - test(!meshResource, "resource should be invalid for a NULL poly data"); -} - -void verify_empty_polydata() -{ - smtk::mesh::InterfacePtr interface = smtk::mesh::moab::make_interface(); - smtk::extension::vtk::io::mesh::ImportVTKData imprt; - - smtk::mesh::ResourcePtr meshResource = imprt(make_EmptyPolyData(), interface); - test(!meshResource, "resource should invalid for empty poly data"); -} - -void verify_tri_polydata() -{ - smtk::mesh::InterfacePtr interface = smtk::mesh::moab::make_interface(); - smtk::extension::vtk::io::mesh::ImportVTKData imprt; - - vtkSmartPointer pd = make_TrianglePolyData(); - smtk::mesh::ResourcePtr meshResource = imprt(pd, interface); - test(meshResource && meshResource->isValid(), "resource should be valid"); - test(meshResource->numberOfMeshes() == 1, "resource should only have a single mesh"); - test(meshResource->cells().size() == static_cast(pd->GetNumberOfCells())); - - //this is a triangle pd so it is 2d only - smtk::mesh::MeshSet meshes = meshResource->meshes(smtk::mesh::Dims2); - test(meshes.size() == 1); - test(meshes.cells() == meshResource->cells()); - - smtk::mesh::MeshSet meshes1d = meshResource->meshes(smtk::mesh::Dims1); - test(meshes1d.size() == 0); - - smtk::extension::vtk::io::mesh::ExportVTKData exprt; - vtkSmartPointer pd2 = vtkSmartPointer::New(); - exprt(meshes, pd2); - test_same_datasets(pd, pd2); -} - -void verify_tri_ugrid() -{ - smtk::mesh::InterfacePtr interface = smtk::mesh::moab::make_interface(); - smtk::extension::vtk::io::mesh::ImportVTKData imprt; - - vtkSmartPointer ug = make_TriangleUGrid(); - smtk::mesh::ResourcePtr meshResource = imprt(ug, interface); - test(meshResource && meshResource->isValid(), "resource should be valid"); - test(meshResource->numberOfMeshes() == 1, "resource should only have a single mesh"); - test(meshResource->cells().size() == static_cast(ug->GetNumberOfCells())); - - //this is a triangle grid so it is 2d only - smtk::mesh::MeshSet meshes = meshResource->meshes(smtk::mesh::Dims2); - test(meshes.size() == 1); - test(meshes.cells() == meshResource->cells()); - - smtk::mesh::MeshSet meshes1d = meshResource->meshes(smtk::mesh::Dims1); - test(meshes1d.size() == 0); - - smtk::extension::vtk::io::mesh::ExportVTKData exprt; - vtkSmartPointer ug2 = vtkSmartPointer::New(); - exprt(meshes, ug2); - test_same_datasets(ug, ug2); -} - -void verify_mixed_cell_ugrid() -{ - smtk::mesh::InterfacePtr interface = smtk::mesh::moab::make_interface(); - smtk::extension::vtk::io::mesh::ImportVTKData imprt; - - vtkSmartPointer ug = make_MixedVolUGrid(); - smtk::mesh::ResourcePtr meshResource = imprt(ug, interface); - - std::cout << "number of cells: " << meshResource->cells().size() << std::endl; - std::cout << "number of cells ug: " << ug->GetNumberOfCells() << std::endl; - - test(meshResource && meshResource->isValid(), "resource should be valid"); - test(meshResource->numberOfMeshes() == 1, "resource should only have a single mesh"); - test( - meshResource->cells().size() == static_cast(ug->GetNumberOfCells()), - "number of cells in mesh don't match"); - - //this is a volume only grid - smtk::mesh::MeshSet meshes = meshResource->meshes(smtk::mesh::Dims3); - test(meshes.size() == 1); - test(meshes.cells() == meshResource->cells()); - - smtk::extension::vtk::io::mesh::ExportVTKData exprt; - vtkSmartPointer ug2 = vtkSmartPointer::New(); - exprt(meshResource->meshes(), ug2); - test_same_datasets(ug, ug2); -} -} // namespace - -int UnitTestImportExportVTKData(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - verify_null_polydata(); - - verify_empty_polydata(); - - verify_tri_polydata(); - - verify_tri_ugrid(); - - verify_mixed_cell_ugrid(); - - return 0; -} diff --git a/smtk/extension/vtk/io/testing/cxx/UnitTestMeshIOVTK.cxx b/smtk/extension/vtk/io/testing/cxx/UnitTestMeshIOVTK.cxx deleted file mode 100644 index 3c7ac66de72e373f825c48bbd2d02ef16fa6706d..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/testing/cxx/UnitTestMeshIOVTK.cxx +++ /dev/null @@ -1,55 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -void verify_import_unstructured_grid() -{ - smtk::mesh::ResourcePtr c = smtk::mesh::Resource::create(); - - std::string file_path(data_root); - file_path += "/mesh/3d/nickel_superalloy.vtu"; - - test(smtk::io::importMesh(file_path, c), "should be able to import unstructured grid"); -} - -void verify_import_polydata() -{ - smtk::mesh::ResourcePtr c = smtk::mesh::Resource::create(); - - std::string file_path(data_root); - file_path += "/scene/BasicScene_12_20_07/PolygonMesh_f8e612a9-876c-4145-9c74-ee6c39f2a157.vtp"; - - test(smtk::io::importMesh(file_path, c), "should be able to import polydata"); -} -} // namespace - -int UnitTestMeshIOVTK(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - verify_import_unstructured_grid(); - - verify_import_polydata(); - - return 0; -} - -// This macro ensures the vtk io library is loaded into the executable -smtkComponentInitMacro(smtk_extension_vtk_io_mesh_MeshIOVTK) diff --git a/smtk/extension/vtk/io/testing/python/CMakeLists.txt b/smtk/extension/vtk/io/testing/python/CMakeLists.txt deleted file mode 100644 index a6bf9fc5465971a081b374b048bbff370b6c03e8..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/testing/python/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -#============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -#============================================================================= - -set(smtkExtensionVTKIOPythonDataTests - MultiScaleConverter - unitImportExportVTKData -) - -if (SMTK_DATA_DIR) - foreach(test ${smtkExtensionVTKIOPythonDataTests}) - smtk_add_test_python(${test}Py ${test}.py - --data-dir=${SMTK_DATA_DIR} ) - set_tests_properties( ${test}Py PROPERTIES LABELS "IO" ) - endforeach() -endif() diff --git a/smtk/extension/vtk/io/testing/python/MultiScaleConverter.py b/smtk/extension/vtk/io/testing/python/MultiScaleConverter.py deleted file mode 100644 index 55379cb70c3cded3965673c0d963d013650c7fe9..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/testing/python/MultiScaleConverter.py +++ /dev/null @@ -1,220 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - - -import math -import os -import smtk -import smtk.io.vtk -import smtk.mesh -import sys -import smtk.testing -import vtk - - -def readXMLFile(fileName): - fn, fileExtension = os.path.splitext(fileName) - if fileExtension == '.vtu': - xmlReader = vtk.vtkXMLUnstructuredGridReader() - elif fileExtension == '.vtp': - xmlReader = vtk.vtkXMLPolyDataReader() - xmlReader.SetFileName(fileName) - xmlReader.Update() - return xmlReader.GetOutputDataObject(0) - - -class CoolingPlateFilter(smtk.mesh.CellForEach): - - def __init__(self, yval, rval, o, less): - smtk.mesh.CellForEach.__init__(self, True) - self.validPoints = list() - self.yvalue = yval - self.rvalue = rval - self.lessThan = less - self.origin = o - - def forCell(self, meshHandle, cellType, numPoints): - for i in range(0, numPoints): - r = math.sqrt((self.coordinates()[i * 3] - self.origin[0]) * - (self.coordinates()[i * 3] - self.origin[0]) + - (self.coordinates()[i * 3 + 2] - self.origin[2]) * - (self.coordinates()[i * 3 + 2] - self.origin[2])) - currValue = [self.coordinates()[(i * 3) + 1], r] - if currValue[0] >= (self.yvalue - 0.002) and \ - currValue[0] <= (self.yvalue + 0.002): - if (self.lessThan and (currValue[1] < self.rvalue)) or \ - ((not self.lessThan) and (currValue[1] >= self.rvalue)): - self.validPoints.append(self.pointId(i)) - - -class OuterEdgeFilter(smtk.mesh.CellForEach): - - def __init__(self, o, rmin): - smtk.mesh.CellForEach.__init__(self, True) - self.validPoints = list() - self.origin = o - self.rmin = rmin - - def forCell(self, meshHandle, cellType, numPoints): - if numPoints < 3: - return - - v0 = [0., 0., 0.] # unit vector from origin to first point in cell - v1 = [0., 0., 0.] - # unit vector from first point to second point in cell - v2 = [0., 0., 0.] - # unit vector from first point to third point in cell - normal = [0., 0., 0.] # unit normal of cell - length = [0., 0., 0.] - - # compute v0,v1,v2 - for i in range(0, 3): - v0[i] = self.coordinates()[i] - self.origin[i] - length[0] += v0[i] * v0[i] - v1[i] = self.coordinates()[3 + i] - self.coordinates()[i] - length[1] += v1[i] * v1[i] - v2[i] = self.coordinates()[6 + i] - self.coordinates()[i] - length[2] += v2[i] * v2[i] - - length = list(map(math.sqrt, length)) - - v0 = list(map(lambda x: x / length[0], v0)) - v1 = list(map(lambda x: x / length[1], v1)) - v2 = list(map(lambda x: x / length[2], v2)) - - # compute normal - for i in range(0, 3): - i1 = (i + 1) % 3 - i2 = (i + 2) % 3 - normal[i] = v1[i1] * v2[i2] - v1[i2] * v2[i1] - - mag = math.sqrt(normal[0] * normal[0] + - normal[1] * normal[1] + - normal[2] * normal[2]) - - normal = list(map(lambda x: x / mag, normal)) - - # reject any cells whose normal is facing up or down - if abs(normal[1]) > .995: - return - - # reject any cells whose normal is not facing outwards - if abs(sum(i[0] * i[1] for i in zip(v0, normal))) < .5: - return - - # reject any cells whose first coordinate is less than a distance - # from the axis of rotation - for i in range(0, numPoints): - r = math.sqrt(self.coordinates()[3 * i] * self.coordinates()[3 * i] + - self.coordinates()[3 * i + 2] * self.coordinates()[3 * i + 2]) - if r > self.rmin: - self.validPoints.append(self.pointId(i)) - - -def labelIntersection(c, shell, filter_): - shellCells = shell.cells() - - smtk.mesh.for_each(shellCells, filter_) - filteredCells = smtk.mesh.CellSet(c, filter_.validPoints) - - domains = c.domains() - - for dom in domains: - domainMeshes = c.meshes(dom) - - domainCells = domainMeshes.cells() - contactCells = smtk.mesh.point_intersect( - domainCells, filteredCells, smtk.mesh.FullyContained) - - if not contactCells.is_empty(): - contactD = c.createMesh(contactCells) - c.setDirichletOnMeshes(contactD, - smtk.mesh.Dirichlet( - labelIntersection.nextDirId)) - labelIntersection.nextDirId += 1 - - return True - - -labelIntersection.nextDirId = 0 - - -def breakMaterialsByCellType(c): - domains = c.domains() - - domainsMade = 0 - for dom in domains: - domainMeshes = c.meshes(dom) - - for ct in range(int(smtk.mesh.Line), int(smtk.mesh.CellType_MAX)): - cells = domainMeshes.cells(smtk.mesh.CellType(ct)) - if not cells.is_empty(): - ms = c.createMesh(cells) - v = (dom.value() * 100) + ct - c.setDomainOnMeshes(ms, smtk.mesh.Domain(v)) - domainsMade += 1 - - c.removeMeshes(domainMeshes) - - -def convert(inputFile, material): - cnvrt = smtk.io.vtk.ImportVTKData() - resource = smtk.mesh.Resource.create() - cnvrt(inputFile, resource, material) - return resource - - -def extractMaterials(c, radius, origin, outputFile, bounds): - shell = c.meshes().extractShell() - if shell.size() != 1: - raise RuntimeError('Shell # mismatch (%d vs 1)' % shell.size()) - - ymin = bounds[2] - filter_ = CoolingPlateFilter(ymin, radius, origin, True) - labelIntersection(c, shell, filter_) - - ymax = bounds[3] - filter_ = CoolingPlateFilter(ymax, radius, origin, True) - labelIntersection(c, shell, filter_) - - center = [origin[0], origin[1] + (ymax + ymin) * .5, origin[2]] - filter_ = OuterEdgeFilter(origin, radius * 2) - labelIntersection(c, shell, filter_) - - breakMaterialsByCellType(c) - - if len(c.domains()) != 5: - raise RuntimeError('Domain # mismatch (%d vs 5)' % len(c.domains())) - if len(c.dirichlets()) != 3: - raise RuntimeError('Dirichlet # mismatch (%d vs 3)' % - len(c.dirichlets())) - -# smtk.io.writeEntireResource(outputFile, c) - - -def test_multiscale_converter(): - inputFileName = smtk.testing.DATA_DIR + '/mesh/3d/nickel_superalloy.vtu' - outputFileName = 'mesh3D.exo' - materialName = 'ZoneIds' - radius = 1.2 - origin = [.02, 0., 0.] - - c = convert(inputFileName, materialName) - data = readXMLFile(inputFileName) - bounds = data.GetBounds() - - extractMaterials(c, radius, origin, outputFileName, bounds) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - test_multiscale_converter() diff --git a/smtk/extension/vtk/io/testing/python/unitImportExportVTKData.py b/smtk/extension/vtk/io/testing/python/unitImportExportVTKData.py deleted file mode 100644 index f31bff288cd2babfdff831587e02efd859ab6a97..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/io/testing/python/unitImportExportVTKData.py +++ /dev/null @@ -1,213 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - - -import smtk -import smtk.io.vtk -import smtk.mesh -import sys -import smtk.testing -import vtk - -import inspect - - -def make_EmptyPolyData(): - return vtk.vtkPolyData() - - -def make_TrianglePolyData(): - PB = vtk.vtkParametricBoy() - PFS = vtk.vtkParametricFunctionSource() - PFS.SetParametricFunction(PB) - - PFS.SetUResolution(400) - PFS.SetVResolution(500) - PFS.Update() - - result = vtk.vtkPolyData() - - result.ShallowCopy(PFS.GetOutput()) - return result - - -def make_TriangleUGrid(): - PB = vtk.vtkParametricBoy() - PFS = vtk.vtkParametricFunctionSource() - PFS.SetParametricFunction(PB) - - PFS.SetUResolution(400) - PFS.SetVResolution(500) - PFS.Update() - - appendFilter = vtk.vtkAppendFilter() - appendFilter.AddInputData(PFS.GetOutput()) - appendFilter.Update() - - result = vtk.vtkUnstructuredGrid() - - result.ShallowCopy(appendFilter.GetOutput()) - return result - - -def make_MixedVolUGrid(): - points = vtk.vtkPoints() - points.SetNumberOfPoints(7) - points.InsertPoint(0, 0, 1, 0) - points.InsertPoint(1, 0, 0, 0) - points.InsertPoint(2, 0, .5, .5) - points.InsertPoint(3, 1, 1, 0) - points.InsertPoint(4, 1, 0, 0) - points.InsertPoint(5, 1, .5, .5) - points.InsertPoint(6, .5, 1, 0) - - aWedge = vtk.vtkWedge() - aWedge.GetPointIds().SetId(0, 0) - aWedge.GetPointIds().SetId(1, 1) - aWedge.GetPointIds().SetId(2, 2) - aWedge.GetPointIds().SetId(3, 3) - aWedge.GetPointIds().SetId(4, 4) - aWedge.GetPointIds().SetId(5, 5) - - aTetra = vtk.vtkTetra() - aTetra.GetPointIds().SetId(0, 0) - aTetra.GetPointIds().SetId(1, 4) - aTetra.GetPointIds().SetId(2, 6) - aTetra.GetPointIds().SetId(3, 3) - - result = vtk.vtkUnstructuredGrid() - result.SetPoints(points) - result.Allocate(2) - result.InsertNextCell(aTetra.GetCellType(), aTetra.GetPointIds()) - result.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds()) - - return result - - -def test_same_datasets(ds, ds2): - EPSILON = 1.e-6 - assert (ds.GetNumberOfPoints() == ds2.GetNumberOfPoints()) - assert (ds.GetNumberOfCells() == ds2.GetNumberOfCells()) - - it = ds.NewCellIterator() - it2 = ds2.NewCellIterator() - it.InitTraversal() - it2.InitTraversal() - while True: - if it.IsDoneWithTraversal() or it2.IsDoneWithTraversal(): - break - assert (it.GetCellType() == it2.GetCellType()) - assert (it.GetNumberOfPoints() == it2.GetNumberOfPoints()) - points = it.GetPoints() - points2 = it2.GetPoints() - xyz = [0., 0., 0.] - xyz2 = [0., 0., 0.] - for i in range(points.GetNumberOfPoints()): - points.GetPoint(i, xyz) - points2.GetPoint(i, xyz2) - for j in range(3): - assert (abs(xyz[j] - xyz2[j]) < EPSILON) - it.GoToNextCell() - it2.GoToNextCell() - - -def verify_tri_polydata(): - imprt = smtk.io.vtk.ImportVTKData() - - pd = make_TrianglePolyData() - meshResource = smtk.mesh.Resource.create() - imprt(pd, meshResource) - - if meshResource == None or not meshResource.isValid(): - raise RuntimeError("resource should exist") - if meshResource.numberOfMeshes() != 1: - raise RuntimeError("resource should only have a single mesh") - if meshResource.cells().size() != pd.GetNumberOfCells(): - raise RuntimeError( - "resource and polydata should have the same number of cells") - - meshes = meshResource.meshes(smtk.mesh.Dims2) - if meshes.size() != 1: - raise RuntimeError("wrong number of meshes") - if meshes.cells() != meshResource.cells(): - raise RuntimeError("cell sets should match") - - meshes1d = meshResource.meshes(smtk.mesh.Dims1) - if meshes1d.size() != 0: - raise RuntimeError("number of 1d cells should be 0") - - exprt = smtk.io.vtk.ExportVTKData() - pd2 = vtk.vtkPolyData() - exprt(meshes, pd2) - test_same_datasets(pd, pd2) - - -def verify_tri_ugrid(): - imprt = smtk.io.vtk.ImportVTKData() - - ug = make_TriangleUGrid() - meshResource = smtk.mesh.Resource.create() - imprt(ug, meshResource) - - if meshResource == None or not meshResource.isValid(): - raise RuntimeError("resource should be valid") - if meshResource.numberOfMeshes() != 1: - raise RuntimeError("resource should only have a single mesh") - - meshes = meshResource.meshes(smtk.mesh.Dims2) - if meshes.size() != 1: - raise RuntimeError("wrong number of meshes") - if meshes.cells() != meshResource.cells(): - raise RuntimeError("cell sets should match") - - meshes1d = meshResource.meshes(smtk.mesh.Dims1) - if meshes1d.size() != 0: - raise RuntimeError("number of 1d cells should be 0") - - exprt = smtk.io.vtk.ExportVTKData() - ug2 = vtk.vtkUnstructuredGrid() - exprt(meshes, ug2) - test_same_datasets(ug, ug2) - - -def verify_mixed_cell_ugrid(): - imprt = smtk.io.vtk.ImportVTKData() - - ug = make_MixedVolUGrid() - meshResource = smtk.mesh.Resource.create() - imprt(ug, meshResource) - - if meshResource == None or not meshResource.isValid(): - raise RuntimeError("resource should be valid") - if meshResource.numberOfMeshes() != 1: - raise RuntimeError("resource should only have a single mesh") - if meshResource.cells().size() != ug.GetNumberOfCells(): - raise RuntimeError( - "resource and unsigned grid should have the same number of cells") - - meshes = meshResource.meshes(smtk.mesh.Dims3) - if meshes.size() != 1: - raise RuntimeError("wrong number of meshes") - if meshes.cells() != meshResource.cells(): - raise RuntimeError("cell sets should match") - - exprt = smtk.io.vtk.ExportVTKData() - ug2 = vtk.vtkUnstructuredGrid() - exprt(meshes, ug2) - test_same_datasets(ug, ug2) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - verify_tri_polydata() - verify_tri_ugrid() - verify_mixed_cell_ugrid() diff --git a/smtk/extension/vtk/mesh/CMakeLists.txt b/smtk/extension/vtk/mesh/CMakeLists.txt deleted file mode 100644 index 04ae1e88942bff4bd25be8bb0540ab2783ba0de3..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/mesh/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -set(classes - Geometry - Registrar) - -set(headers - RegisterVTKBackend.h) - -vtk_module_add_module(vtkSMTKMeshExt - CLASSES ${classes} - HEADERS ${headers} - HEADERS_SUBDIR "smtk/extension/vtk/mesh") - -vtk_module_link(vtkSMTKMeshExt - PUBLIC - smtkCore - smtkIOVTK - vtkSMTKSourceExt -) diff --git a/smtk/extension/vtk/mesh/Geometry.cxx b/smtk/extension/vtk/mesh/Geometry.cxx deleted file mode 100644 index cc40e6e54a8ff47161b2ba59e1adfaf421fdf894..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/mesh/Geometry.cxx +++ /dev/null @@ -1,117 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/extension/vtk/mesh/Geometry.h" - -#include "smtk/extension/vtk/io/mesh/ExportVTKData.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/geometry/Generator.h" - -#include -#include -#include -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -Geometry::Geometry(const std::shared_ptr& parent) - : m_parent(parent) -{ -} - -smtk::geometry::Resource::Ptr Geometry::resource() const -{ - return std::dynamic_pointer_cast(m_parent.lock()); -} - -void Geometry::queryGeometry(const smtk::resource::PersistentObject::Ptr& obj, CacheEntry& entry) - const -{ - // Access the mesh component - auto component = std::dynamic_pointer_cast(obj); - if (!component || !component->mesh().isValid()) - { - entry.m_generation = Invalid; - return; - } - - // Convert the meshset into a vtkPolyData - smtk::extension::vtk::io::mesh::ExportVTKData exportVTKData; - entry.m_geometry = vtkSmartPointer::New(); - - exportVTKData(component->mesh(), vtkPolyData::SafeDownCast(entry.m_geometry)); - - ++entry.m_generation; - - // If the object has color properties, apply them - if (component->properties().contains>("color")) - { - Geometry::addColorArray( - entry.m_geometry, component->properties().at>("color")); - } -} - -int Geometry::dimension(const smtk::resource::PersistentObject::Ptr& obj) const -{ - auto component = std::dynamic_pointer_cast(obj); - if (component && component->mesh().isValid()) - { - int highestDim = static_cast(smtk::mesh::utility::highestDimension(component->mesh())); - - // While the geometry may represent a 3-dimensional mesh, the geometric - // representation is always a vtkPolyData, which has highest dimension 2. - return (highestDim <= 2 ? highestDim : 2); - } - return 0; -} - -Geometry::Purpose Geometry::purpose(const smtk::resource::PersistentObject::Ptr&) const -{ - return Geometry::Surface; -} - -void Geometry::update() const -{ - // Do nothing. Operations in smtk mesh set content as needed. -} - -void Geometry::geometricBounds(const DataType& geom, BoundingBox& bbox) const -{ - auto* pset = vtkPointSet::SafeDownCast(geom); - if (pset) - { - pset->GetBounds(bbox.data()); - return; - } - auto* comp = vtkCompositeDataSet::SafeDownCast(geom); - if (comp) - { - comp->GetBounds(bbox.data()); - return; - } - - // Invalid bounding box: - bbox[0] = bbox[2] = bbox[4] = 0.0; - bbox[1] = bbox[3] = bbox[5] = -1.0; -} -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/vtk/mesh/Geometry.h b/smtk/extension/vtk/mesh/Geometry.h deleted file mode 100644 index 9198a45a195dc1d598eb2e6e7ff114ed20ddf658..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/mesh/Geometry.h +++ /dev/null @@ -1,61 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_extension_vtk_mesh_Geometry_h -#define smtk_extension_vtk_mesh_Geometry_h - -#include "smtk/extension/vtk/geometry/Geometry.h" -#include "smtk/extension/vtk/mesh/vtkSMTKMeshExtModule.h" - -#include "smtk/geometry/Cache.h" - -#include "smtk/PublicPointerDefs.h" - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -/**\brief A VTK geometry provider for smtk mesh resources. - * - */ -class VTKSMTKMESHEXT_EXPORT Geometry - : public smtk::geometry::Cache -{ -public: - using CacheBaseType = smtk::extension::vtk::geometry::Geometry; - smtkTypeMacro(smtk::extension::vtk::geometry::Geometry); - smtkSuperclassMacro(smtk::geometry::Cache); - using DataType = Superclass::DataType; - - Geometry(const std::shared_ptr& parent); - ~Geometry() override = default; - - smtk::geometry::Resource::Ptr resource() const override; - void queryGeometry(const smtk::resource::PersistentObject::Ptr& obj, CacheEntry& entry) - const override; - int dimension(const smtk::resource::PersistentObject::Ptr& obj) const override; - Purpose purpose(const smtk::resource::PersistentObject::Ptr& obj) const override; - void update() const override; - - void geometricBounds(const DataType&, BoundingBox& bbox) const override; - -protected: - std::weak_ptr m_parent; -}; -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk - -#endif diff --git a/smtk/extension/vtk/mesh/RegisterVTKBackend.h b/smtk/extension/vtk/mesh/RegisterVTKBackend.h deleted file mode 100644 index 1424197ac790ee4480d5d9955c53a88195fcad40..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/mesh/RegisterVTKBackend.h +++ /dev/null @@ -1,60 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_extension_vtk_mesh_RegisterVTKBackend_h -#define smtk_extension_vtk_mesh_RegisterVTKBackend_h -#ifndef __VTK_WRAP__ - -#include "smtk/extension/vtk/mesh/vtkSMTKMeshExtModule.h" - -#include "smtk/extension/vtk/geometry/Backend.h" -#include "smtk/extension/vtk/geometry/Registrar.h" -#include "smtk/extension/vtk/mesh/Geometry.h" -#include "smtk/geometry/Generator.h" -#include "smtk/geometry/Manager.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/resource/Registrar.h" - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -class VTKSMTKMESHEXT_EXPORT RegisterVTKBackend : public smtk::geometry::Supplier -{ -public: - bool valid(const smtk::geometry::Specification& in) const override - { - smtk::extension::vtk::geometry::Backend backend; - return std::get<1>(in).index() == backend.index(); - } - - GeometryPtr operator()(const smtk::geometry::Specification& in) override - { - auto rsrc = std::dynamic_pointer_cast(std::get<0>(in)); - if (rsrc) - { - auto* provider = new Geometry(rsrc); - return GeometryPtr(provider); - } - throw std::invalid_argument("Not a mesh resource."); - return nullptr; - } -}; -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk - -#endif // __VTK_WRAP__ -#endif // smtk_extension_vtk_mesh_RegisterVTKBackend_h diff --git a/smtk/extension/vtk/mesh/Registrar.cxx b/smtk/extension/vtk/mesh/Registrar.cxx deleted file mode 100644 index cf78293988c82840354fed59f56042ccde61f5a6..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/mesh/Registrar.cxx +++ /dev/null @@ -1,37 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/extension/vtk/mesh/Registrar.h" - -#include "smtk/extension/vtk/mesh/RegisterVTKBackend.h" - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ -void Registrar::registerTo(const smtk::geometry::Manager::Ptr& geometryManager) -{ - geometryManager->registerBackend(); - RegisterVTKBackend::registerClass(); -} - -void Registrar::unregisterFrom(const smtk::geometry::Manager::Ptr& geometryManager) -{ - geometryManager->unregisterBackend(); -} -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/vtk/mesh/Registrar.h b/smtk/extension/vtk/mesh/Registrar.h deleted file mode 100644 index 65f07716e6cda23cb980653ea429583566ac5c1b..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/mesh/Registrar.h +++ /dev/null @@ -1,43 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_extension_vtk_mesh_Registrar_h -#define smtk_extension_vtk_mesh_Registrar_h -#ifndef __VTK_WRAP__ - -#include "smtk/extension/vtk/mesh/vtkSMTKMeshExtModule.h" - -#include "smtk/extension/vtk/geometry/Registrar.h" -#include "smtk/geometry/Manager.h" -#include "smtk/mesh/resource/Registrar.h" - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -class VTKSMTKMESHEXT_EXPORT Registrar -{ -public: - using Dependencies = std::tuple; - - static void registerTo(const smtk::geometry::Manager::Ptr&); - static void unregisterFrom(const smtk::geometry::Manager::Ptr&); -}; -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk - -#endif // __VTK_WRAP__ -#endif // smtk_extension_vtk_mesh_Registrar_h diff --git a/smtk/extension/vtk/mesh/vtk.module b/smtk/extension/vtk/mesh/vtk.module deleted file mode 100644 index 6730accaa026dacada49f0a6cb6cb7e7998ada8c..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/mesh/vtk.module +++ /dev/null @@ -1,7 +0,0 @@ -NAME - vtkSMTKMeshExt -DEPENDS - VTK::CommonCore - VTK::CommonDataModel - VTK::FiltersGeometry - vtkSMTKGeometryExt diff --git a/smtk/extension/vtk/operators/testing/cxx/CMakeLists.txt b/smtk/extension/vtk/operators/testing/cxx/CMakeLists.txt index 961fdfa6f7f26f9139c7ddf73f14429351622932..db8526982676f0788de0ce675f6d2ce6fa71f37c 100644 --- a/smtk/extension/vtk/operators/testing/cxx/CMakeLists.txt +++ b/smtk/extension/vtk/operators/testing/cxx/CMakeLists.txt @@ -34,22 +34,3 @@ if (SMTK_DATA_DIR AND SMTK_ENABLE_POLYGON_SESSION) COMMAND DeleteSmtkCell2 ${SMTK_DATA_DIR}/model/2d/smtk/simple.smtk -T "${CMAKE_CURRENT_BINARY_DIR}" ) endif () - -if (SMTK_DATA_DIR) - # test of ExportFaceset operation (exporting geometry resource to STL file.) - add_executable(ExportFacesetTest ExportFacesetTest.cxx) - target_link_libraries(ExportFacesetTest - smtkCore - smtkMeshSession - vtkSMTKOperationsExt - vtkSMTKSourceExt - VTK::CommonCore - VTK::CommonDataModel - VTK::IOXML - VTK::IOGeometry - ) - add_test( - NAME ExportFacesetTest - COMMAND ExportFacesetTest -T "${CMAKE_CURRENT_BINARY_DIR}" - ) -endif () diff --git a/smtk/extension/vtk/operators/testing/cxx/DeleteSmtkCell.cxx b/smtk/extension/vtk/operators/testing/cxx/DeleteSmtkCell.cxx index 1bc0c65bd6f0904859472d63960ad3e887dde05d..a086607c591c0e8acfeabe40b1526039520c1344 100644 --- a/smtk/extension/vtk/operators/testing/cxx/DeleteSmtkCell.cxx +++ b/smtk/extension/vtk/operators/testing/cxx/DeleteSmtkCell.cxx @@ -29,8 +29,6 @@ #include "smtk/model/Tessellation.h" #include "smtk/model/operators/AddAuxiliaryGeometry.h" -#include "smtk/mesh/testing/cxx/helpers.h" - #include "smtk/operation/Registrar.h" #include "smtk/operation/operators/ReadResource.h" @@ -41,6 +39,8 @@ #include "smtk/session/polygon/operators/Delete.h" #include "smtk/session/polygon/operators/Import.h" +#include "smtk/common/testing/cxx/helpers.h" + #include "smtk/extension/vtk/source/vtkModelMultiBlockSource.h" #include "vtkActor.h" #include "vtkCamera.h" diff --git a/smtk/extension/vtk/operators/testing/cxx/DeleteSmtkCell2.cxx b/smtk/extension/vtk/operators/testing/cxx/DeleteSmtkCell2.cxx index 1e931ca28e690c13e7d0b6b5dfc9c5352e365f29..3fb26583aaf4afd0fa3621b6fddeae3f74da6d1c 100644 --- a/smtk/extension/vtk/operators/testing/cxx/DeleteSmtkCell2.cxx +++ b/smtk/extension/vtk/operators/testing/cxx/DeleteSmtkCell2.cxx @@ -39,7 +39,7 @@ #include "smtk/session/polygon/operators/Delete.h" #include "smtk/session/polygon/operators/Import.h" -#include "smtk/mesh/testing/cxx/helpers.h" +#include "smtk/common/testing/cxx/helpers.h" #include "smtk/extension/vtk/source/vtkModelMultiBlockSource.h" #include "vtkActor.h" diff --git a/smtk/extension/vtk/operators/testing/cxx/ExportFacesetTest.cxx b/smtk/extension/vtk/operators/testing/cxx/ExportFacesetTest.cxx deleted file mode 100644 index 9f9a9fa5ef04b990dc77305d6b3f2101460356b8..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/operators/testing/cxx/ExportFacesetTest.cxx +++ /dev/null @@ -1,171 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/extension/vtk/operators/ExportFaceset.h" -#include "smtk/extension/vtk/operators/Registrar.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "smtk/operation/Registrar.h" -#include "smtk/operation/operators/ReadResource.h" - -#include "smtk/plugin/Manager.txx" -#include "smtk/plugin/Registry.h" - -#include "smtk/session/mesh/Registrar.h" -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/Session.h" -#include "smtk/session/mesh/operators/CreateUniformGrid.h" - -#include "vtkNew.h" -#include "vtkOBJReader.h" -#include "vtkPLYReader.h" -#include "vtkPolyData.h" -#include "vtkSTLReader.h" -#include "vtkSmartPointer.h" - -smtk::resource::ResourcePtr ConstructGrid(smtk::operation::Manager::Ptr operationManager) -{ - smtk::operation::Operation::Ptr createGridOp = - operationManager->create(); - - if (!createGridOp) - { - std::cerr << "Couldn't create \"create uniform grid\" operator" << std::endl; - return nullptr; - } - - createGridOp->parameters()->findString("dimension")->setValue("3"); - createGridOp->parameters()->findDouble("size3d")->setValue(0, 2); - - createGridOp->parameters()->findInt("discretization3d")->setValue(0, 5); - createGridOp->parameters()->findInt("discretization3d")->setValue(1, 5); - createGridOp->parameters()->findInt("discretization3d")->setValue(2, 5); - - smtk::operation::Operation::Result createGridOpResult = createGridOp->operate(); - - if ( - createGridOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"create uniform grid\" operation failed\n"; - return nullptr; - } - return createGridOpResult->findResource("resourcesCreated")->value(0); -} - -void verifySTL(const std::string& filename, const int vertexCount, const int cellCount) -{ - auto fileExt = filename.substr(filename.size() - 4, 4); - std::for_each(fileExt.begin(), fileExt.end(), [](char& c) { c = std::tolower(c); }); - vtkSmartPointer reader; - if (fileExt == ".stl") - { - reader = vtkSmartPointer::New(); - } - else if (fileExt == ".obj") - { - reader = vtkSmartPointer::New(); - } - else if (fileExt == ".ply") - { - reader = vtkSmartPointer::New(); - } - reader->SetFileName(filename.c_str()); - reader->Update(); - auto* pd = reader->GetOutput(); - test(pd->GetNumberOfPoints() == vertexCount, "Vertex count mismatch"); - test(pd->GetNumberOfCells() == cellCount, "Cell count mismatch"); -} - -void runTest(const std::string gridVolumeFile) -{ - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - // Create a geometry manager - smtk::geometry::Manager::Ptr geometryManager = smtk::geometry::Manager::create(); - - smtk::plugin::Manager::instance()->registerPluginsTo(resourceManager); - smtk::plugin::Manager::instance()->registerPluginsTo(operationManager); - smtk::plugin::Manager::instance()->registerPluginsTo(geometryManager); - - auto operationRegistry = - smtk::plugin::addToManagers(operationManager); - auto geomRegistry = - smtk::plugin::addToManagers(operationManager); - auto meshRegistry = smtk::plugin::addToManagers( - resourceManager, operationManager, geometryManager); - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - smtk::geometry::ExportFaceset::Ptr exportOp = - operationManager->create(); - smtk::operation::Operation::Result exportOpResult; - - if (auto grid = ConstructGrid(operationManager)) - { - exportOp->parameters()->findFile("filename")->setValue(gridVolumeFile); - - // Export Volume component - auto volumeComponent = grid->filter("Volume"); - test(volumeComponent.size() == 1, "Cannot find the volume component in the input."); - - exportOp->parameters()->associate(*volumeComponent.begin()); - exportOpResult = exportOp->operate(); - - test( - exportOpResult->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "Export volume failed"); - - verifySTL(gridVolumeFile, 152, 300); - - // Export Face components - auto faceComponents = grid->filter("Face"); - test(faceComponents.size() == 6, "Cannot find the face components in the input."); - - int cnt = 0; - for (auto c = faceComponents.begin(); c != faceComponents.end(); ++c, ++cnt) - { - const std::string gridFaceFile = std::string("ExportFacesetTest-grid-face-") + - std::to_string(cnt) + std::string("-output.stl"); - auto operation = operationManager->create(); - operation->parameters()->findFile("filename")->setValue(gridFaceFile); - operation->parameters()->associate(*c); - auto result = operation->operate(); - test( - result->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "Export face failed"); - verifySTL(gridFaceFile, 36, 50); - } - } -} - -int main(/*int argc, char* argv[]*/) -{ - std::string gridVolumeFile = "ExportFacesetTest-grid-volume-output.stl"; - runTest(gridVolumeFile); - gridVolumeFile = "ExportFacesetTest-grid-volume-output.obj"; - runTest(gridVolumeFile); - gridVolumeFile = "ExportFacesetTest-grid-volume-output.ply"; - runTest(gridVolumeFile); - - return 0; -} diff --git a/smtk/extension/vtk/source/CMakeLists.txt b/smtk/extension/vtk/source/CMakeLists.txt index 040407f99ffc23339241f18d38db2353e69bca81..fb3b1f57620827a787d0d36b8324b4c02aab421c 100644 --- a/smtk/extension/vtk/source/CMakeLists.txt +++ b/smtk/extension/vtk/source/CMakeLists.txt @@ -1,9 +1,6 @@ set(classes ModelEntityPointLocator - PointCloudFromVTKAuxiliaryGeometry - SourceFromMesh SourceFromModel - StructuredGridFromVTKAuxiliaryGeometry vtkAttributeMultiBlockSource vtkCmbLayeredConeSource vtkConeFrustum diff --git a/smtk/extension/vtk/source/PointCloudFromVTKAuxiliaryGeometry.cxx b/smtk/extension/vtk/source/PointCloudFromVTKAuxiliaryGeometry.cxx deleted file mode 100644 index 67cc3624774f47fd6a57bc8da431b8c9e6733b93..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/source/PointCloudFromVTKAuxiliaryGeometry.cxx +++ /dev/null @@ -1,105 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/vtk/source/PointCloudFromVTKAuxiliaryGeometry.h" - -#include "smtk/extension/vtk/model/vtkAuxiliaryGeometryExtension.h" - -#include "smtk/model/AuxiliaryGeometry.h" - -#include "vtkDoubleArray.h" -#include "vtkFloatArray.h" -#include "vtkImageData.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkNew.h" -#include "vtkPointData.h" -#include "vtkPolyData.h" -#include "vtkUniformGrid.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -namespace -{ -bool registered = PointCloudFromVTKAuxiliaryGeometry::registerClass(); -} - -bool PointCloudFromVTKAuxiliaryGeometry::valid(const smtk::model::AuxiliaryGeometry& auxGeom) const -{ - auto loader = vtkAuxiliaryGeometryExtension::create(); - std::vector bbox(6); - - // TODO: why does canHandleAuxiliaryGeometry not take a const AuxiliaryGeometry? - smtk::model::AuxiliaryGeometry nonConstAuxGeom(auxGeom); - - return (loader && loader->canHandleAuxiliaryGeometry(nonConstAuxGeom, bbox)); -} - -smtk::mesh::PointCloud PointCloudFromVTKAuxiliaryGeometry::operator()( - const smtk::model::AuxiliaryGeometry& auxGeom) -{ - // Convert the auxiliary geometry from a file name to a vtkDataset - vtkDataSet* externalData = nullptr; - auto loader = vtkAuxiliaryGeometryExtension::create(); - std::vector bbox(6); - - smtk::model::AuxiliaryGeometry nonConstAuxGeom(auxGeom); - - if (loader && loader->canHandleAuxiliaryGeometry(nonConstAuxGeom, bbox)) - { - externalData = - vtkDataSet::SafeDownCast(vtkAuxiliaryGeometryExtension::fetchCachedGeometry(auxGeom)); - } - - if (!externalData) - { - // Something went wrong and we have no vtkDataSet. - throw std::invalid_argument("Auxiliary geometry cannot be read."); - } - - std::function(std::size_t)> coordinates = [=](std::size_t i) { - double pt[3]; - externalData->GetPoint(i, pt); - return std::array({ { pt[0], pt[1], 0. } }); - }; - - std::function data; - - // Check for elevation data. If it exists, use it. Otherwise, just use the - // z-coordinate of the data, - // TODO: no magic keywords! - vtkDataArray* elevationData = externalData->GetPointData()->GetScalars("Elevation"); - if (elevationData) - { - data = [=](std::size_t i) { return elevationData->GetTuple1(i); }; - } - else - { - data = [=](std::size_t i) { - double pt[3]; - externalData->GetPoint(i, pt); - return pt[2]; - }; - } - - return smtk::mesh::PointCloud(externalData->GetNumberOfPoints(), coordinates, data); -} -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/vtk/source/PointCloudFromVTKAuxiliaryGeometry.h b/smtk/extension/vtk/source/PointCloudFromVTKAuxiliaryGeometry.h deleted file mode 100644 index b5f7706a4d5665071c5f3306483269f2b7a161c1..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/source/PointCloudFromVTKAuxiliaryGeometry.h +++ /dev/null @@ -1,54 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_extensions_vtk_source_PointCloudFromVTK_h -#define smtk_extensions_vtk_source_PointCloudFromVTK_h -#ifndef __VTK_WRAP__ - -#include "smtk/AutoInit.h" - -#include "smtk/PublicPointerDefs.h" -#include "smtk/extension/vtk/source/vtkSMTKSourceExtModule.h" - -#include "smtk/common/Generator.h" -#include "smtk/mesh/interpolation/PointCloud.h" -#include "smtk/mesh/interpolation/PointCloudGenerator.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -/// A GeneratorType for creating PointClouds from VTK auxiliary geometry. This -/// class extends smtk::mesh::PointCloudGenerator. -class VTKSMTKSOURCEEXT_EXPORT PointCloudFromVTKAuxiliaryGeometry - : public smtk::common::GeneratorType< - smtk::model::AuxiliaryGeometry, - smtk::mesh::PointCloud, - PointCloudFromVTKAuxiliaryGeometry> -{ -public: - bool valid(const smtk::model::AuxiliaryGeometry& auxGeom) const override; - - smtk::mesh::PointCloud operator()(const smtk::model::AuxiliaryGeometry& auxGeom) override; -}; -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk - -#endif // __VTK_WRAP__ -#endif diff --git a/smtk/extension/vtk/source/SourceFromMesh.cxx b/smtk/extension/vtk/source/SourceFromMesh.cxx deleted file mode 100644 index 7e7b2e8f2f670cbf56134c53b947f0cb07533207..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/source/SourceFromMesh.cxx +++ /dev/null @@ -1,55 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/vtk/source/SourceFromMesh.h" -#include "smtk/extension/vtk/source/vtkResourceMultiBlockSource.h" - -#include "smtk/mesh/core/Resource.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace source -{ - -namespace -{ -bool registered = SourceFromMesh::registerClass(); -} - -bool SourceFromMesh::valid(const smtk::resource::ResourcePtr& resource) const -{ - return std::dynamic_pointer_cast(resource) != nullptr; -} - -vtkSmartPointer SourceFromMesh::operator()( - const smtk::resource::ResourcePtr& resource) -{ - auto meshResource = std::static_pointer_cast(resource); - - // The valid() call above should make certain that the static pointer cast - // will succeed. It doesn't hurt to be cautious, though. - assert(meshResource); - - // Create a vtkResourceMultiBlockSource for our mesh. - auto source = vtkSmartPointer::New(); - source->SetResource(meshResource); - - return source; -} -} // namespace source -} // namespace vtk -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/vtk/source/SourceFromMesh.h b/smtk/extension/vtk/source/SourceFromMesh.h deleted file mode 100644 index e552b1fcbd8d890ca2ae7012269063e1c58ef43d..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/source/SourceFromMesh.h +++ /dev/null @@ -1,48 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_extensions_vtk_source_SourceFromMesh_h -#define smtk_extensions_vtk_source_SourceFromMesh_h -#ifndef __VTK_WRAP__ - -#include "smtk/AutoInit.h" - -#include "smtk/PublicPointerDefs.h" -#include "smtk/extension/vtk/source/SourceGenerator.h" -#include "smtk/extension/vtk/source/vtkSMTKSourceExtModule.h" - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace source -{ - -/// A GeneratorType for creating vtkSmartPointers -/// using smtk::resource::Resources as the key. This class extends -/// smtk::extension::vtk::source::SourceGenerator. -class VTKSMTKSOURCEEXT_EXPORT SourceFromMesh - : public smtk::common:: - GeneratorType, SourceFromMesh> -{ -public: - bool valid(const smtk::resource::ResourcePtr&) const override; - - vtkSmartPointer operator()(const smtk::resource::ResourcePtr&) override; -}; -} // namespace source -} // namespace vtk -} // namespace extension -} // namespace smtk - -#endif // __VTK_WRAP__ -#endif diff --git a/smtk/extension/vtk/source/StructuredGridFromVTKAuxiliaryGeometry.cxx b/smtk/extension/vtk/source/StructuredGridFromVTKAuxiliaryGeometry.cxx deleted file mode 100644 index a8c46958a536252d28917a1b388f0c417cf725d6..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/source/StructuredGridFromVTKAuxiliaryGeometry.cxx +++ /dev/null @@ -1,109 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/vtk/source/StructuredGridFromVTKAuxiliaryGeometry.h" - -#include "smtk/extension/vtk/model/vtkAuxiliaryGeometryExtension.h" - -#include "smtk/model/AuxiliaryGeometry.h" - -#include "vtkDoubleArray.h" -#include "vtkFloatArray.h" -#include "vtkImageData.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkNew.h" -#include "vtkPointData.h" -#include "vtkPolyData.h" -#include "vtkUniformGrid.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -namespace -{ -bool registered = StructuredGridFromVTKAuxiliaryGeometry::registerClass(); -} - -bool StructuredGridFromVTKAuxiliaryGeometry::valid( - const smtk::model::AuxiliaryGeometry& auxGeom) const -{ - auto loader = vtkAuxiliaryGeometryExtension::create(); - std::vector bbox(6); - - // TODO: why does canHandleAuxiliaryGeometry not take a const AuxiliaryGeometry? - smtk::model::AuxiliaryGeometry nonConstAuxGeom(auxGeom); - - return (loader && loader->canHandleAuxiliaryGeometry(nonConstAuxGeom, bbox)); -} - -smtk::mesh::StructuredGrid StructuredGridFromVTKAuxiliaryGeometry::operator()( - const smtk::model::AuxiliaryGeometry& auxGeom) -{ - // Convert the auxiliary geometry from a file name to a vtkDataset - vtkDataSet* externalData = nullptr; - auto loader = vtkAuxiliaryGeometryExtension::create(); - std::vector bbox(6); - - smtk::model::AuxiliaryGeometry nonConstAuxGeom(auxGeom); - - if (loader && loader->canHandleAuxiliaryGeometry(nonConstAuxGeom, bbox)) - { - externalData = - vtkDataSet::SafeDownCast(vtkAuxiliaryGeometryExtension::fetchCachedGeometry(auxGeom)); - } - - if (!externalData) - { - // Something went wrong and we have no vtkDataSet. - throw std::invalid_argument("File cannot be read."); - } - - smtk::mesh::StructuredGrid structuredgrid; - - if (vtkImageData* imageInput = vtkImageData::SafeDownCast(externalData)) - { - structuredgrid = smtk::mesh::StructuredGrid( - imageInput->GetExtent(), - imageInput->GetOrigin(), - imageInput->GetSpacing(), - [=](int i, int j) { return imageInput->GetScalarComponentAsDouble(i, j, 0, 0); }); - } - else if (vtkUniformGrid* gridInput = vtkUniformGrid::SafeDownCast(externalData)) - { - structuredgrid = smtk::mesh::StructuredGrid( - gridInput->GetExtent(), - gridInput->GetOrigin(), - gridInput->GetSpacing(), - [=](int i, int j) { return gridInput->GetScalarComponentAsDouble(i, j, 0, 0); }, - [=](int i, int j) { - int pos[3] = { i, j, 0 }; - return gridInput->IsPointVisible( - vtkStructuredData::ComputePointIdForExtent(gridInput->GetExtent(), pos)) != 0; - }); - } - else - { - throw std::invalid_argument("File does not contain structured data."); - } - - return structuredgrid; -} -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk diff --git a/smtk/extension/vtk/source/StructuredGridFromVTKAuxiliaryGeometry.h b/smtk/extension/vtk/source/StructuredGridFromVTKAuxiliaryGeometry.h deleted file mode 100644 index 1bef66848abdbb2c2761e7cf04df40fb8c6add58..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/source/StructuredGridFromVTKAuxiliaryGeometry.h +++ /dev/null @@ -1,53 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_extensions_vtk_source_StructuredGridFromVTKAuxiliaryGeometry_h -#define smtk_extensions_vtk_source_StructuredGridFromVTKAuxiliaryGeometry_h -#ifndef __VTK_WRAP__ - -#include "smtk/AutoInit.h" - -#include "smtk/PublicPointerDefs.h" -#include "smtk/extension/vtk/source/vtkSMTKSourceExtModule.h" - -#include "smtk/mesh/interpolation/StructuredGrid.h" -#include "smtk/mesh/interpolation/StructuredGridGenerator.h" - -#include - -namespace smtk -{ -namespace extension -{ -namespace vtk -{ -namespace mesh -{ - -/// A GeneratorType for creating StructuredGrids from VTK auxiliary geometry. -/// This class extends smtk::mesh::StructuredGridGenerator. -class VTKSMTKSOURCEEXT_EXPORT StructuredGridFromVTKAuxiliaryGeometry - : public smtk::common::GeneratorType< - smtk::model::AuxiliaryGeometry, - smtk::mesh::StructuredGrid, - StructuredGridFromVTKAuxiliaryGeometry> -{ -public: - bool valid(const smtk::model::AuxiliaryGeometry&) const override; - - smtk::mesh::StructuredGrid operator()(const smtk::model::AuxiliaryGeometry&) override; -}; -} // namespace mesh -} // namespace vtk -} // namespace extension -} // namespace smtk - -#endif // __VTK_WRAP__ -#endif diff --git a/smtk/extension/vtk/source/pybind11/PybindVTKSourceFns.cxx b/smtk/extension/vtk/source/pybind11/PybindVTKSourceFns.cxx index eaf5e4d2b94aac768540a50cb70930f0152e1be4..9f1214706eef3d7875c9457aeb3e36de3de2ba56 100644 --- a/smtk/extension/vtk/source/pybind11/PybindVTKSourceFns.cxx +++ b/smtk/extension/vtk/source/pybind11/PybindVTKSourceFns.cxx @@ -24,15 +24,9 @@ SMTK_THIRDPARTY_POST_INCLUDE #include "smtk/extension/vtk/pybind11/PybindVTKTypeCaster.h" #include "smtk/extension/vtk/source/vtkResourceMultiBlockSource.h" #include "smtk/extension/vtk/source/vtkModelMultiBlockSource.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" #include "smtk/model/Entity.h" #include "smtk/model/Resource.h" -#include "smtk/extension/vtk/source/PointCloudFromVTKAuxiliaryGeometry.h" -#include "smtk/extension/vtk/source/StructuredGridFromVTKAuxiliaryGeometry.h" - - PYBIND11_MODULE(_smtkPybindVTKSourceFns, source) { source.doc() = ""; @@ -45,14 +39,7 @@ PYBIND11_MODULE(_smtkPybindVTKSourceFns, source) source.def("_vtkResourceMultiBlockSource_GetDataObjectUUID",[&](vtkInformation* info){ return vtkResourceMultiBlockSource::GetDataObjectUUID(info); }); source.def("_vtkResourceMultiBlockSource_SetDataObjectUUID",[&](vtkInformation* info, const smtk::common::UUID& id){ vtkResourceMultiBlockSource::SetDataObjectUUID(info, id); }); - source.def("_vtkResourceMultiBlockSource_GetComponent",[&](vtkResourceMultiBlockSource* obj, vtkInformation* info){ return std::dynamic_pointer_cast(obj->GetComponent(info)); }); + source.def("_vtkResourceMultiBlockSource_GetComponent",[&](vtkResourceMultiBlockSource* obj, vtkInformation* info){ return std::dynamic_pointer_cast(obj->GetComponent(info)); }); source.def("_vtkResourceMultiBlockSource_GetResource",[&](vtkResourceMultiBlockSource* obj){ obj->GetResource(); }); source.def("_vtkResourceMultiBlockSource_SetResource",[&](vtkResourceMultiBlockSource* obj, smtk::resource::ResourcePtr resource){ obj->SetResource(resource); }); - - bool pcRegistered = - smtk::extension::vtk::mesh::PointCloudFromVTKAuxiliaryGeometry::registerClass(); - (void)pcRegistered; - bool sgRegistered = - smtk::extension::vtk::mesh::StructuredGridFromVTKAuxiliaryGeometry::registerClass(); - (void)sgRegistered; } diff --git a/smtk/extension/vtk/source/testing/cxx/CMakeLists.txt b/smtk/extension/vtk/source/testing/cxx/CMakeLists.txt index 6786a55a28bb77540d5d21af114fb46cff5f6104..bebbd141c22e4321dec62bdd5989cf314776221e 100644 --- a/smtk/extension/vtk/source/testing/cxx/CMakeLists.txt +++ b/smtk/extension/vtk/source/testing/cxx/CMakeLists.txt @@ -49,35 +49,6 @@ target_link_libraries(displayMultiBlockModel VTK::TestingRendering ) -add_executable(displayMultiBlockMesh MACOSX_BUNDLE displayMultiBlockMesh.cxx) -list(APPEND additional_source_tests displayMultiBlockMesh) -target_link_libraries(displayMultiBlockMesh - smtkCore - vtkSMTKSourceExt - VTK::CommonCore - VTK::CommonDataModel - VTK::IOXML - VTK::InteractionStyle - VTK::RenderingCore - VTK::RenderingOpenGL2 - VTK::TestingRendering -) - -add_executable(displayModelToMesh MACOSX_BUNDLE displayModelToMesh.cxx) -list(APPEND additional_source_tests displayModelToMesh) -target_link_libraries(displayModelToMesh - smtkCore - vtkSMTKMeshExt - vtkSMTKSourceExt - VTK::CommonCore - VTK::CommonDataModel - VTK::IOXML - VTK::InteractionStyle - VTK::RenderingCore - VTK::RenderingOpenGL2 - VTK::TestingRendering -) - # Only run tests if the data directory exists if (SMTK_DATA_DIR) add_test( @@ -88,49 +59,6 @@ if (SMTK_DATA_DIR) -V "${SMTK_DATA_DIR}/baseline/smtk/vtk/test2D-with-colors.png" -T "${CMAKE_CURRENT_BINARY_DIR}" ) - - add_test( - NAME displayModelToMesh-simple - COMMAND - $ - "${SMTK_DATA_DIR}/model/3d/smtk/simple.json" - -V "${SMTK_DATA_DIR}/baseline/smtk/vtk/simple-Model2Mesh.png" - -T "${CMAKE_CURRENT_BINARY_DIR}" - ) - - if(MOAB_HAVE_HDF5) - add_test( - NAME displayMultiBlockMesh-twoassm - COMMAND - $ - "${SMTK_DATA_DIR}/mesh/3d/twoassm_out.h5m" - -V "${SMTK_DATA_DIR}/baseline/smtk/vtk/twoassm_out.png" - -T "${CMAKE_CURRENT_BINARY_DIR}" - ) - endif() - - if(SMTK_ENABLE_MESH_SESSION) - add_executable(displayAuxiliaryGeometry MACOSX_BUNDLE displayAuxiliaryGeometry.cxx) - list(APPEND additional_source_tests displayAuxiliaryGeometry) - target_link_libraries(displayAuxiliaryGeometry - smtkCore - smtkMeshSession - vtkSMTKSourceExt - VTK::IOXML - VTK::RenderingGL2PSOpenGL2 - VTK::TestingRendering - ) - - add_test( - NAME displayAuxiliaryGeometry - COMMAND - $ - "${SMTK_DATA_DIR}/model/3d/obj/cone.obj" - -V "${SMTK_DATA_DIR}/baseline/smtk/vtk/auxiliaryGeometry.png" - -T "${CMAKE_CURRENT_BINARY_DIR}" - ) - endif() - endif() vtk_module_autoinit( diff --git a/smtk/extension/vtk/source/testing/cxx/displayAuxiliaryGeometry.cxx b/smtk/extension/vtk/source/testing/cxx/displayAuxiliaryGeometry.cxx deleted file mode 100644 index 40dae6fd9778a9ea9f72f3e77d8e0dd0e5af11a7..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/source/testing/cxx/displayAuxiliaryGeometry.cxx +++ /dev/null @@ -1,208 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/session/mesh/Registrar.h" -#include "smtk/session/mesh/Session.h" -#include "smtk/session/mesh/operators/CreateUniformGrid.h" - -#include "smtk/common/testing/cxx/helpers.h" - -#include "smtk/model/CellEntity.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Group.h" -#include "smtk/model/Registrar.h" -#include "smtk/model/Resource.h" -#include "smtk/model/operators/AddAuxiliaryGeometry.h" - -#include "smtk/resource/Manager.h" - -#include "smtk/operation/Manager.h" - -#include "smtk/plugin/Registry.h" - -#include "smtk/extension/vtk/source/vtkModelMultiBlockSource.h" - -#include "vtkActor.h" -#include "vtkCamera.h" -#include "vtkCommand.h" -#include "vtkCompositePolyDataMapper.h" -#include "vtkDataSetAttributes.h" -#include "vtkInteractorStyleSwitch.h" -#include "vtkNew.h" -#include "vtkPlane.h" -#include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkRenderWindow.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderer.h" -#include "vtkSmartPointer.h" -#include "vtkStringArray.h" -#include "vtkXMLMultiBlockDataWriter.h" - -#include "vtkRegressionTestImage.h" - -// This macro ensures the vtk io library is loaded into the executable -smtkComponentInitMacro(smtk_extension_vtk_io_mesh_MeshIOVTK) - - namespace -{ - int VisualizeModel(smtk::model::Model model, int argc, char* argv[]) - { - vtkNew act; - vtkNew src; - vtkNew map; - vtkNew ren; - vtkNew win; - src->SetModelResource(model.resource()); - src->SetDefaultColor(1., 1., 0., 1.); - map->SetInputConnection(src->GetOutputPort()); - act->SetMapper(map.GetPointer()); - act->GetProperty()->SetPointSize(5); - act->GetProperty()->SetLineWidth(2); - - vtkNew camera; - camera->SetPosition(-1., -1., -2.); - camera->SetFocalPoint(0, 0, 0); - - ren->SetActiveCamera(camera.GetPointer()); - - win->AddRenderer(ren.GetPointer()); - ren->AddActor(act.GetPointer()); - - vtkRenderWindowInteractor* iac = win->MakeRenderWindowInteractor(); - vtkInteractorStyleSwitch::SafeDownCast(iac->GetInteractorStyle()) - ->SetCurrentStyleToTrackballCamera(); - win->SetInteractor(iac); - - win->Render(); - ren->ResetCamera(); - - int status = !vtkRegressionTestImage(win.GetPointer()); - return status; - } -} - -int main(int argc, char* argv[]) -{ - if (argc == 1) - { - std::cout << "Usage: displayAuxiliaryGeometry " << std::endl; - return 1; - } - - std::string auxiliaryGeometry; - - { - std::ifstream file; - file.open(argv[1]); - if (file.good()) - { - auxiliaryGeometry = std::string(argv[1]); - } - } - - if (auxiliaryGeometry.empty()) - { - std::cout << "Could not open file \"" << argv[1] << "\".\n\n"; - return 1; - } - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register model and mesh operators to the managers - auto modelRegistry = smtk::plugin::addToManagers(operationManager); - auto meshRegistry = - smtk::plugin::addToManagers(resourceManager, operationManager); - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - // Create a "create background domain" operator - smtk::operation::Operation::Ptr createBackgroundDomainOp = - operationManager->create(); - - if (!createBackgroundDomainOp) - { - std::cerr << "Couldn't create \"create uniform grid\" operator" << std::endl; - return 1; - } - - createBackgroundDomainOp->parameters()->findString("dimension")->setValue("2"); - createBackgroundDomainOp->parameters()->findDouble("size2d")->setValue(0, 2); - - createBackgroundDomainOp->parameters()->findInt("discretization2d")->setValue(0, 5); - createBackgroundDomainOp->parameters()->findInt("discretization2d")->setValue(1, 5); - - smtk::operation::Operation::Result createBackgroundDomainOpResult = - createBackgroundDomainOp->operate(); - - if ( - createBackgroundDomainOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"create uniform grid\" operator failed\n"; - return 1; - } - - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - createBackgroundDomainOpResult->findComponent("created")); - - smtk::model::Entity::Ptr model = - std::dynamic_pointer_cast(componentItem->value()); - - { - // Create an "add auxiliary geometry" operator - smtk::operation::Operation::Ptr addAuxiliaryGeometryOp = - operationManager->create(); - - if (!addAuxiliaryGeometryOp) - { - std::cerr << "Couldn't create \"add auxiliary geometry\" operator" << std::endl; - return 1; - } - - addAuxiliaryGeometryOp->parameters()->associateEntity(model); - addAuxiliaryGeometryOp->parameters()->findFile("url")->setValue(auxiliaryGeometry); - - addAuxiliaryGeometryOp->parameters()->findDouble("rotate")->setValue(0, 270.); - - addAuxiliaryGeometryOp->parameters()->findDouble("translate")->setValue(0, 1.); - addAuxiliaryGeometryOp->parameters()->findDouble("translate")->setValue(1, 1.); - - smtk::operation::Operation::Result addAuxiliaryGeometryOpResult = - addAuxiliaryGeometryOp->operate(); - - if ( - addAuxiliaryGeometryOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"add auxiliary geometry\" operator failed\n"; - return 1; - } - } - - return VisualizeModel(model->referenceAs(), argc, argv); -} diff --git a/smtk/extension/vtk/source/testing/cxx/displayModelToMesh.cxx b/smtk/extension/vtk/source/testing/cxx/displayModelToMesh.cxx deleted file mode 100644 index 26bcf49544f683e461be4fe36772c9196b4d479d..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/source/testing/cxx/displayModelToMesh.cxx +++ /dev/null @@ -1,154 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ModelToMesh.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "smtk/model/Resource.h" -#include "smtk/model/json/jsonResource.h" - -#include "vtkActor.h" -#include "vtkColorTransferFunction.h" -#include "vtkCommand.h" -#include "vtkCompositePolyDataMapper.h" -#include "vtkDataSetAttributes.h" -#include "vtkInteractorStyleSwitch.h" -#include "vtkNew.h" -#include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkRegressionTestImage.h" -#include "vtkRenderWindow.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderer.h" -#include "vtkSmartPointer.h" -#include "vtkStringArray.h" -#include "vtkXMLMultiBlockDataWriter.h" - -#include "smtk/extension/vtk/mesh/RegisterVTKBackend.h" -#include "smtk/extension/vtk/source/vtkResourceMultiBlockSource.h" - -using namespace smtk::model; -using namespace smtk::io; - -int main(int argc, char* argv[]) -{ - int debug = argc > 2 ? (argv[2][0] == '-' ? 0 : 1) : 0; - if (argc > 1) - { - std::ifstream file; - file.open(argv[1]); - if (!file.good()) - { - std::cout << "Could not open file \"" << argv[1] << "\".\n\n"; - return 1; - } - - std::string data((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); - - ResourcePtr resource = Resource::create(); - - nlohmann::json json = nlohmann::json::parse(data); - - smtk::model::from_json(json, resource); - for (auto& tessPair : json["tessellations"]) - { - smtk::common::UUID id = tessPair[0]; - smtk::model::Tessellation tess = tessPair[1]; - resource->setTessellation(id, tess); - } - - resource->assignDefaultNames(); - - bool status = true; - - int numModels = - static_cast(resource->entitiesMatchingFlagsAs(smtk::model::MODEL_ENTITY).size()); - std::cout << "Imported models into resource: " << numModels << std::endl; - if (numModels > 0) - { - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr c = convert(resource); - test(c->isValid(), "resource should be valid"); - - std::size_t numMeshes = c->numberOfMeshes(); - std::cout << "number of meshes: " << numMeshes << std::endl; - test(numMeshes != 0, "dataset once loaded should have more than zero meshes"); - - smtk::extension::vtk::mesh::RegisterVTKBackend::registerClass(); - - vtkNew act; - vtkNew src; - vtkNew map; - vtkNew ren; - vtkNew win; - src->SetResource(c); - if (debug) - { - win->SetMultiSamples(16); - } - else - { - win->SetMultiSamples(0); - } - map->SetInputConnection(src->GetOutputPort()); - /* - map->SetColorModeToMapScalars(); - map->SetScalarModeToUseCellData(); - map->SelectColorArray("vtkCompositeIndex"); - vtkSmartPointer< vtkColorTransferFunction > lut = - vtkSmartPointer< vtkColorTransferFunction >::New(); - // This creates a blue to red lut. - //double range[2]; - lut->AddHSVPoint(0,0.667,1,1); - lut->AddHSVPoint(55,0,1,1); - lut->SetColorSpaceToDiverging(); - lut->SetVectorModeToMagnitude(); - map->SetLookupTable(lut); - map->SetInterpolateScalarsBeforeMapping(1); - */ - act->SetMapper(map.GetPointer()); - act->GetProperty()->SetPointSize(5); - act->GetProperty()->SetLineWidth(2); - act->GetProperty()->SetEdgeVisibility(1); - act->GetProperty()->SetEdgeColor(0, 0, 0.5); - win->AddRenderer(ren.GetPointer()); - ren->AddActor(act.GetPointer()); - - vtkRenderWindowInteractor* iac = win->MakeRenderWindowInteractor(); - vtkInteractorStyleSwitch::SafeDownCast(iac->GetInteractorStyle()) - ->SetCurrentStyleToTrackballCamera(); - win->SetInteractor(iac); - /* - if (debug && argc > 3) - { - vtkNew wri; - wri->SetInputConnection(src->GetOutputPort()); - wri->SetFileName(argv[3]); - wri->Write(); - } - */ - win->Render(); - ren->ResetCamera(); - - status = !vtkRegressionTestImage(win.GetPointer()); - if (debug) - { - iac->Start(); - } - } - - return status; - } - - return 0; -} diff --git a/smtk/extension/vtk/source/testing/cxx/displayMultiBlockMesh.cxx b/smtk/extension/vtk/source/testing/cxx/displayMultiBlockMesh.cxx deleted file mode 100644 index e5de00942444fa25615e9cbc3a3b93c13851df62..0000000000000000000000000000000000000000 --- a/smtk/extension/vtk/source/testing/cxx/displayMultiBlockMesh.cxx +++ /dev/null @@ -1,114 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "vtkActor.h" -#include "vtkColorTransferFunction.h" -#include "vtkCommand.h" -#include "vtkCompositePolyDataMapper.h" -#include "vtkDataSetAttributes.h" -#include "vtkInteractorStyleSwitch.h" -#include "vtkNew.h" -#include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkRegressionTestImage.h" -#include "vtkRenderWindow.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderer.h" -#include "vtkSmartPointer.h" -#include "vtkStringArray.h" -#include "vtkXMLMultiBlockDataWriter.h" - -#include "smtk/extension/vtk/source/vtkResourceMultiBlockSource.h" - -int main(int argc, char* argv[]) -{ - int debug = argc > 2 ? (argv[2][0] == '-' ? 0 : 1) : 0; - if (argc > 1) - { - std::string file_path = argv[1]; - smtk::io::ImportMesh import; - smtk::mesh::ResourcePtr c = smtk::mesh::Resource::create(); - import(file_path, c); - test(c->isValid(), "resource should be valid"); - - std::size_t numMeshes = c->numberOfMeshes(); - std::cout << "number of meshes in twoassm_out is: " << numMeshes << std::endl; - test(numMeshes != 0, "dataset once loaded should have more than zero meshes"); - - vtkNew act; - vtkNew src; - vtkNew map; - vtkNew ren; - vtkNew win; - if (debug) - { - win->SetMultiSamples(16); - } - else - { - win->SetMultiSamples(0); - } - map->SetInputConnection(src->GetOutputPort()); - /* - map->SetColorModeToMapScalars(); - map->SetScalarModeToUseCellData(); - map->SelectColorArray("vtkCompositeIndex"); - vtkSmartPointer< vtkColorTransferFunction > lut = - vtkSmartPointer< vtkColorTransferFunction >::New(); - // This creates a blue to red lut. - //double range[2]; - lut->AddHSVPoint(0,0.667,1,1); - lut->AddHSVPoint(55,0,1,1); - lut->SetColorSpaceToDiverging(); - lut->SetVectorModeToMagnitude(); - map->SetLookupTable(lut); - map->SetInterpolateScalarsBeforeMapping(1); - */ - act->SetMapper(map.GetPointer()); - act->GetProperty()->SetPointSize(5); - act->GetProperty()->SetLineWidth(2); - act->GetProperty()->SetEdgeVisibility(1); - act->GetProperty()->SetEdgeColor(0, 0, 0.5); - win->AddRenderer(ren.GetPointer()); - ren->AddActor(act.GetPointer()); - - vtkRenderWindowInteractor* iac = win->MakeRenderWindowInteractor(); - vtkInteractorStyleSwitch::SafeDownCast(iac->GetInteractorStyle()) - ->SetCurrentStyleToTrackballCamera(); - win->SetInteractor(iac); - /* - if (debug && argc > 3) - { - vtkNew wri; - wri->SetInputConnection(src->GetOutputPort()); - wri->SetFileName(argv[3]); - wri->Write(); - } - */ - win->Render(); - ren->ResetCamera(); - - int status = !vtkRegressionTestImage(win.GetPointer()); - if (debug) - { - iac->Start(); - } - - return status; - } - - return 0; -} diff --git a/smtk/extension/vtk/source/testing/python/CMakeLists.txt b/smtk/extension/vtk/source/testing/python/CMakeLists.txt index ee4e9ed978d1b5fc95943bddaa95528d15b99eb2..b2a59ed35fc9a41baa19c7d22824596c3b8b461c 100644 --- a/smtk/extension/vtk/source/testing/python/CMakeLists.txt +++ b/smtk/extension/vtk/source/testing/python/CMakeLists.txt @@ -10,8 +10,8 @@ # #============================================================================= -# Our only test here requires the mesh session. -if (SMTK_ENABLE_MESH_SESSION) +# Our only test here requires the markup resource. +if (SMTK_MARKUP_SUPPORT_ENABLED) set(smtkExtensionVTKSourcePythonDataTests iterateMultiBlockModel ) diff --git a/smtk/extension/vtk/source/testing/python/iterateMultiBlockModel.py b/smtk/extension/vtk/source/testing/python/iterateMultiBlockModel.py index 6250535773df9ce4f87a7cb3759a21cfbb9e2eb8..747af43826898d912ad67129ce62a300244b37b5 100644 --- a/smtk/extension/vtk/source/testing/python/iterateMultiBlockModel.py +++ b/smtk/extension/vtk/source/testing/python/iterateMultiBlockModel.py @@ -15,9 +15,7 @@ import unittest import smtk import smtk.extension.vtk.source import smtk.io -import smtk.mesh -import smtk.model -import smtk.session.mesh +import smtk.markup import smtk.testing import vtk @@ -25,8 +23,8 @@ import vtk import math ''' - Construct a uniform grid as a mesh model, use it to seed a model multiblock - source, iterate the blocks of the output multiblock and access the model + Construct a markup resource with analytic shapes as components and + iterate the blocks of the output multiblock and access the model components using the blocks' metadata. ''' @@ -35,25 +33,30 @@ class IterateMultiBlockModel(smtk.testing.TestCase): def setUp(self): - # Construct a 'create uniform grid' operator - op = smtk.session.mesh.CreateUniformGrid.create() - - # Execute the operator and check its results - res = op.operate() - if res.find('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - raise RuntimeError + smtk.loadPlugins() + # smtk.mgrs = smtk.common.Managers.create() + # self.rsrcMgr = smtk.resource.Manager.create() + # self.operMgr = smtk.operation.Manager.create() + # self.geomMgr = smtk.geometry.Manager.create() + print(smtk.applicationContext()) + # Create a resource + rsrc = smtk.markup.Resource.create() + ss = smtk.markup.Component.CastTo(rsrc.createNodeOfType( + smtk.string.Token('smtk::markup::Sphere'))) + bb = smtk.markup.Component.CastTo( + rsrc.createNodeOfType(smtk.string.Token('smtk::markup::Box'))) + ss.setName('round thing') + bb.setName('cornery') # Access the resulting resource and model - self.resource = smtk.session.mesh.Resource.CastTo( - res.find('resourcesCreated').value(0)) - modelEntity = res.find('created').value(0) - self.model = smtk.model.Model( - modelEntity.modelResource(), modelEntity.id()) + self.resource = rsrc + self.sphere = ss + self.box = bb def testMultiBlockIteration(self): - mbs = smtk.extension.vtk.source.vtkModelMultiBlockSource() - mbs.SetModelResource(self.resource) + mbs = smtk.extension.vtk.source.vtkResourceMultiBlockSource() + mbs.SetResource(self.resource) mbs.Update() components = mbs.GetOutput().GetBlock(0) @@ -71,9 +74,9 @@ class IterateMultiBlockModel(smtk.testing.TestCase): it.GoToNextItem() geom = geometries[0] - expected_component_names = { - 'Domain', 'Lower X', 'Lower Y', 'Upper X', 'Upper Y'} + expected_component_names = {'round thing', 'cornery'} + print('names are ', component_names) if len(component_names.symmetric_difference(expected_component_names)) > 0: raise RuntimeError( "retrieved component names do not match expected values") diff --git a/smtk/extension/vtk/source/vtkModelMultiBlockSource.cxx b/smtk/extension/vtk/source/vtkModelMultiBlockSource.cxx index d5f4abfc57a7c3eb1d2a0041f2874423a961c9dd..5a310b22027f74769adc16708aadb62497ab6012 100644 --- a/smtk/extension/vtk/source/vtkModelMultiBlockSource.cxx +++ b/smtk/extension/vtk/source/vtkModelMultiBlockSource.cxx @@ -16,11 +16,6 @@ #include "smtk/extension/vtk/filter/vtkImageSpacingFlip.h" -#include "smtk/extension/vtk/io/mesh/ExportVTKData.h" - -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - #include "smtk/model/AuxiliaryGeometry.h" #include "smtk/model/Edge.h" #include "smtk/model/EdgeUse.h" @@ -373,13 +368,6 @@ vtkSmartPointer vtkModelMultiBlockSource::GenerateRepresentationF this->SetCachedData(entity.entity(), obj, sequence); return obj; } - else if (!entity.meshTessellation().is_empty()) - { - obj = this->GenerateRepresentationFromMeshTessellation(entity, genNormals); - entity.as().setIntegerProperty(SMTK_TESS_GEN_PROP, 1); - this->SetCachedData(entity.entity(), obj, sequence); - return obj; - } smtk::model::AuxiliaryGeometry aux(entity); std::string url; @@ -451,56 +439,6 @@ vtkSmartPointer vtkModelMultiBlockSource::GenerateRepresentationFro return pd; } -vtkSmartPointer vtkModelMultiBlockSource::GenerateRepresentationFromMeshTessellation( - const smtk::model::EntityRef& entity, - bool genNormals) -{ - vtkSmartPointer pd = vtkSmartPointer::New(); - if (!entity.isValid()) - { - return pd; - } - smtk::extension::vtk::io::mesh::ExportVTKData exportVTKData; - if (entity.dimension() == 3) - { - //To preserve the state of the mesh database, we track - //whether or not a new meshset was created to represent - //the 3d shell; if it was created, we delete it when we - //are finished with it. - bool created; - smtk::mesh::MeshSet shell = entity.meshTessellation().extractShell(created); - exportVTKData(shell, pd); - if (created) - { - entity.meshTessellation().resource()->removeMeshes(shell); - } - } - else - { - exportVTKData(entity.meshTessellation(), pd); - } - - AddColorWithDefault(pd, entity, this->DefaultColor); - if (this->AllowNormalGeneration && pd->GetPolys()->GetSize() > 0) - { - bool reallyNeedNormals = genNormals; - if (entity.hasIntegerProperty("generate normals")) - { // Allow per-entity setting to override per-model setting - const IntegerList& prop(entity.integerProperty("generate normals")); - reallyNeedNormals = (!prop.empty() && prop[0]); - } - if (reallyNeedNormals) - { - this->NormalGenerator->SetInputDataObject(pd); - this->NormalGenerator->Update(); - pd->ShallowCopy(this->NormalGenerator->GetOutput()); - } - } - - vtkModelMultiBlockSource::AddPointsAsAttribute(pd); - return pd; -} - /// Loop over the model generating blocks of polydata. void vtkModelMultiBlockSource::GenerateRepresentationFromModel( vtkPolyData* pd, diff --git a/smtk/geometry/CMakeLists.txt b/smtk/geometry/CMakeLists.txt index 9ce59608f7e15ff2cf6fe07e8440adebdae1f35e..18ff5d529ff693b77231e9c3393f2cb4f6c51ef2 100644 --- a/smtk/geometry/CMakeLists.txt +++ b/smtk/geometry/CMakeLists.txt @@ -3,6 +3,7 @@ set(geometrySrcs Registrar.cxx Resource.cxx Manager.cxx + queries/BoundingBox.cxx ) set(geometryHeaders diff --git a/smtk/mesh/interpolation/StructuredGridGenerator.cxx b/smtk/geometry/queries/BoundingBox.cxx similarity index 68% rename from smtk/mesh/interpolation/StructuredGridGenerator.cxx rename to smtk/geometry/queries/BoundingBox.cxx index 95d7bc09eb4fc26b6aa40daa53944dee547d7331..ef38aee98e2cc522fca7ecf814f013571c682c54 100644 --- a/smtk/mesh/interpolation/StructuredGridGenerator.cxx +++ b/smtk/geometry/queries/BoundingBox.cxx @@ -8,13 +8,17 @@ // PURPOSE. See the above copyright notice for more information. //========================================================================= -#include "smtk/mesh/interpolation/StructuredGridGenerator.h" +#include "smtk/geometry/queries/BoundingBox.h" namespace smtk { -namespace mesh +namespace geometry { -StructuredGridGenerator::~StructuredGridGenerator() = default; +std::array BoundingBox::operator()(const smtk::resource::PersistentObject::Ptr&) const +{ + return { { 1., 0., 1., 0., 1., 0. } }; } + +} // namespace geometry } // namespace smtk diff --git a/smtk/geometry/queries/BoundingBox.h b/smtk/geometry/queries/BoundingBox.h index 0d979bbccdd07a5e5edbd5cce110c2818b4f339c..e89628fead6ba911fd3bea368cb182a771224017 100644 --- a/smtk/geometry/queries/BoundingBox.h +++ b/smtk/geometry/queries/BoundingBox.h @@ -33,11 +33,6 @@ struct SMTKCORE_EXPORT BoundingBox virtual std::array operator()(const smtk::resource::PersistentObject::Ptr&) const = 0; }; -inline std::array BoundingBox::operator()( - const smtk::resource::PersistentObject::Ptr&) const -{ - return { { 1., 0., 1., 0., 1., 0. } }; -} } // namespace geometry } // namespace smtk diff --git a/smtk/io/CMakeLists.txt b/smtk/io/CMakeLists.txt index 4233dab3d1c33f6d5a6111ad9daa76bebecba185..ed033baed0afd03fece4e4afd9bc7aa97e2b4f82 100644 --- a/smtk/io/CMakeLists.txt +++ b/smtk/io/CMakeLists.txt @@ -7,7 +7,6 @@ set(ioSrcs json/jsonComponentSet.cxx json/jsonSelectionMap.cxx Logger.cxx - ModelToMesh.cxx TemplateInfo.cxx XmlDocV1Parser.cxx XmlDocV2Parser.cxx @@ -34,7 +33,6 @@ set(ioHeaders json/jsonComponentSet.h json/jsonSelectionMap.h Logger.h - ModelToMesh.h TemplateInfo.h XmlDocV1Parser.h XmlDocV2Parser.h @@ -54,28 +52,6 @@ set(ioHeaders XmlV8StringWriter.h ) -# mesh-related I/O -list(APPEND ioSrcs - ExportMesh.cxx - ImportMesh.cxx - ReadMesh.cxx - WriteMesh.cxx - mesh/Format.cxx - mesh/MeshIOMoab.cxx - mesh/MeshIOXMS.cxx -) - -list(APPEND ioHeaders - ExportMesh.h - ImportMesh.h - ReadMesh.h - WriteMesh.h - mesh/Format.h - mesh/MeshIO.h - mesh/MeshIOMoab.h - mesh/MeshIOXMS.h -) - #install the headers smtk_public_headers(smtkCore ${ioHeaders}) diff --git a/smtk/io/ExportMesh.cxx b/smtk/io/ExportMesh.cxx deleted file mode 100644 index dd7fd07e6f5ba468877423361975cfdad556fe9a..0000000000000000000000000000000000000000 --- a/smtk/io/ExportMesh.cxx +++ /dev/null @@ -1,116 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/io/ExportMesh.h" - -#include "smtk/io/mesh/MeshIOMoab.h" -#include "smtk/io/mesh/MeshIOXMS.h" - -#include "smtk/common/CompilerInformation.h" - -#include - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "boost/filesystem.hpp" -#include "boost/system/error_code.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -using namespace boost::filesystem; - -namespace smtk -{ -namespace io -{ - -ExportMesh::ExportMesh() = default; - -ExportMesh::~ExportMesh() = default; - -std::vector& ExportMesh::SupportedIOTypes() -{ - static std::vector supportedIOTypes; - if (supportedIOTypes.empty()) - { - supportedIOTypes.push_back(mesh::MeshIOPtr(new mesh::MeshIOXMS())); - supportedIOTypes.push_back(mesh::MeshIOPtr(new mesh::MeshIOMoab())); - } - return supportedIOTypes; -} - -bool ExportMesh::operator()(const std::string& filePath, smtk::mesh::ResourcePtr meshResource) const -{ - // Grab the file extension - boost::filesystem::path fpath(filePath); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - // Search for an appropriate exporter - for (auto&& exporter : smtk::io::ExportMesh::SupportedIOTypes()) - { - for (auto&& format : exporter->FileFormats()) - { - if ( - format.CanExport() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - // export the mesh resource - return exporter->exportMesh(filePath, meshResource); - } - } - } - return false; -} - -bool ExportMesh::operator()( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName) const -{ - // Grab the file extension - boost::filesystem::path fpath(filePath); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - // Search for an appropriate exporter - for (auto&& exporter : smtk::io::ExportMesh::SupportedIOTypes()) - { - for (auto&& format : exporter->FileFormats()) - { - if ( - format.CanExport() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - // export the mesh resource - return exporter->exportMesh(filePath, meshResource, resource, modelPropertyName); - } - } - } - return false; -} - -bool exportMesh(const std::string& filePath, smtk::mesh::ResourcePtr meshResource) -{ - ExportMesh exportM; - return exportM(filePath, meshResource); -} - -bool exportMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName) -{ - ExportMesh exportM; - return exportM(filePath, meshResource, resource, modelPropertyName); -} -} // namespace io -} // namespace smtk diff --git a/smtk/io/ExportMesh.h b/smtk/io/ExportMesh.h deleted file mode 100644 index da161c739cd6b66b8dbe61bfb8437b275cd2e491..0000000000000000000000000000000000000000 --- a/smtk/io/ExportMesh.h +++ /dev/null @@ -1,60 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_io_ExportMesh_h -#define smtk_io_ExportMesh_h - -#include "smtk/CoreExports.h" // For SMTKCORE_EXPORT macro. -#include "smtk/PublicPointerDefs.h" - -#include "smtk/io/mesh/MeshIO.h" - -#include -#include - -namespace smtk -{ -namespace io -{ - -/**\brief Export an entire SMTK mesh resource from a file, or just sub-sections - * - */ -class SMTKCORE_EXPORT ExportMesh -{ -public: - ExportMesh(); - ~ExportMesh(); - - ExportMesh& operator=(const ExportMesh&) = delete; - ExportMesh(const ExportMesh&) = delete; - - static std::vector& SupportedIOTypes(); - - bool operator()(const std::string& filePath, smtk::mesh::ResourcePtr meshResource) const; - bool operator()( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName) const; -}; - -SMTKCORE_EXPORT -bool exportMesh(const std::string& filePath, smtk::mesh::ResourcePtr meshResource); -SMTKCORE_EXPORT -bool exportMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName); -} // namespace io -} // namespace smtk - -#endif diff --git a/smtk/io/ImportMesh.cxx b/smtk/io/ImportMesh.cxx deleted file mode 100644 index e8d0e5263f83b8457b7256c667a4fe0e8b1c6747..0000000000000000000000000000000000000000 --- a/smtk/io/ImportMesh.cxx +++ /dev/null @@ -1,185 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/io/ImportMesh.h" - -#include "smtk/io/mesh/MeshIOMoab.h" -#include "smtk/io/mesh/MeshIOXMS.h" - -#include "smtk/common/CompilerInformation.h" - -#include -#include - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "boost/filesystem.hpp" -#include "boost/system/error_code.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -using namespace boost::filesystem; - -namespace smtk -{ -namespace io -{ - -ImportMesh::ImportMesh() = default; - -ImportMesh::~ImportMesh() = default; - -std::vector& ImportMesh::SupportedIOTypes() -{ - static std::vector supportedIOTypes; - if (supportedIOTypes.empty()) - { - supportedIOTypes.push_back(mesh::MeshIOPtr(new mesh::MeshIOXMS())); - supportedIOTypes.push_back(mesh::MeshIOPtr(new mesh::MeshIOMoab())); - } - return supportedIOTypes; -} - -bool ImportMesh::ExtensionIsSupported(const std::string& ext) -{ - for (auto& importer : smtk::io::ImportMesh::SupportedIOTypes()) - { - for (const auto& format : importer->FileFormats()) - { - if ( - format.CanImport() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - return true; - } - } - } - - return false; -} - -smtk::io::mesh::Format ImportMesh::fileFormat(const std::string& filePath) -{ - // Grab the file extension - boost::filesystem::path fpath(filePath); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - for (auto& importer : smtk::io::ImportMesh::SupportedIOTypes()) - { - for (const auto& format : importer->FileFormats()) - { - if ( - format.CanImport() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - return format; - } - } - } - - return smtk::io::mesh::Format(); -} - -smtk::mesh::ResourcePtr ImportMesh::operator()( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - std::string domainPropertyName) const -{ - // Grab the file extension - boost::filesystem::path fpath(filePath); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - // Search for an appropriate importer - for (auto&& importer : smtk::io::ImportMesh::SupportedIOTypes()) - { - for (auto&& format : importer->FileFormats()) - { - if ( - format.CanImport() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - // import the resource - return importer->importMesh(filePath, interface, domainPropertyName); - } - } - } - - return smtk::mesh::ResourcePtr(); -} - -bool ImportMesh::operator()( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - std::string domainPropertyName) const -{ - // Grab the file extension - boost::filesystem::path fpath(filePath); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - // Search for an appropriate importer - for (auto&& importer : smtk::io::ImportMesh::SupportedIOTypes()) - { - for (auto&& format : importer->FileFormats()) - { - if ( - format.CanImport() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - // import the resource - return importer->importMesh(filePath, resource, domainPropertyName); - } - } - } - return false; -} - -smtk::mesh::ResourcePtr importMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface) -{ - ImportMesh importM; - return importM(filePath, interface, std::string()); -} - -smtk::mesh::ResourcePtr importMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - const std::string& domainPropertyName) -{ - ImportMesh importM; - return importM(filePath, interface, domainPropertyName); -} - -bool importMesh(const std::string& filePath, smtk::mesh::ResourcePtr resource) -{ - ImportMesh importM; - return importM(filePath, resource, std::string()); -} - -bool importMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - const std::string& domainPropertyName) -{ - ImportMesh importM; - return importM(filePath, resource, domainPropertyName); -} - -smtk::io::mesh::Format meshFileFormat(const std::string& filePath) -{ - ImportMesh importM; - return importM.fileFormat(filePath); -} -} // namespace io -} // namespace smtk diff --git a/smtk/io/ImportMesh.h b/smtk/io/ImportMesh.h deleted file mode 100644 index b728f6cb0cdae1edf5667ded8eb11cfea3a32af3..0000000000000000000000000000000000000000 --- a/smtk/io/ImportMesh.h +++ /dev/null @@ -1,74 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_io_ImportMesh_h -#define smtk_io_ImportMesh_h - -#include "smtk/CoreExports.h" // For SMTKCORE_EXPORT macro. -#include "smtk/PublicPointerDefs.h" - -#include "smtk/io/mesh/MeshIO.h" - -#include -#include - -namespace smtk -{ -namespace io -{ - -/**\brief Import an entire SMTK mesh resource from a file, or just sub-sections - * - */ -class SMTKCORE_EXPORT ImportMesh -{ -public: - ImportMesh(); - ~ImportMesh(); - - ImportMesh& operator=(const ImportMesh&) = delete; - ImportMesh(const ImportMesh&) = delete; - - static std::vector& SupportedIOTypes(); - - static bool ExtensionIsSupported(const std::string& ext); - - //Load the domain sets from a moab data file as a new resource with the - //given interface. - smtk::mesh::ResourcePtr operator()( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - std::string domainPropertyName = std::string()) const; - bool operator()( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - std::string domainPropertyName = std::string()) const; - - //Return the file format selected to read the file at . - smtk::io::mesh::Format fileFormat(const std::string& filePath); -}; - -SMTKCORE_EXPORT smtk::mesh::ResourcePtr importMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface); -SMTKCORE_EXPORT smtk::mesh::ResourcePtr importMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - const std::string& domainPropertyName); -SMTKCORE_EXPORT bool importMesh(const std::string& filePath, smtk::mesh::ResourcePtr resource); -SMTKCORE_EXPORT bool importMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - const std::string& domainPropertyName); -SMTKCORE_EXPORT smtk::io::mesh::Format meshFileFormat(const std::string& filePath); -} // namespace io -} // namespace smtk - -#endif diff --git a/smtk/io/ModelToMesh.cxx b/smtk/io/ModelToMesh.cxx deleted file mode 100644 index b685ad4741a3ef7469bacc3f3b7f2247534d4558..0000000000000000000000000000000000000000 --- a/smtk/io/ModelToMesh.cxx +++ /dev/null @@ -1,564 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ModelToMesh.h" - -#include "smtk/mesh/core/Interface.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/CellEntity.h" -#include "smtk/model/EntityIterator.h" -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" -#include "smtk/model/Tessellation.h" -#include "smtk/model/Volume.h" - -#include - -namespace smtk -{ -namespace io -{ - -namespace detail -{ - -smtk::mesh::CellType tessToSMTKCell(smtk::model::Tessellation::size_type cell_shape) -{ - smtk::mesh::CellType ctype = smtk::mesh::CellType_MAX; - switch (cell_shape) - { - case smtk::model::TESS_VERTEX: - ctype = smtk::mesh::Vertex; - break; - case smtk::model::TESS_TRIANGLE: - ctype = smtk::mesh::Triangle; - break; - case smtk::model::TESS_QUAD: - ctype = smtk::mesh::Quad; - break; - case smtk::model::TESS_POLYGON: - ctype = smtk::mesh::Polygon; - break; - case smtk::model::TESS_POLYLINE: - ctype = smtk::mesh::Line; - break; - case smtk::model::TESS_POLYVERTEX: - default: - //Polyvertex and polyline are currently un supported by smtk mesh - ctype = smtk::mesh::CellType_MAX; - break; - } - return ctype; -} - -void removeOnesWithoutTess(smtk::model::EntityRefs& ents) -{ - smtk::model::EntityIterator it; - it.traverse(ents.begin(), ents.end(), smtk::model::ITERATE_BARE); - std::vector withoutTess; - for (it.begin(); !it.isAtEnd(); ++it) - { - if (!it->hasTessellation()) - { - withoutTess.push_back(it.current()); - } - } - - typedef std::vector::const_iterator c_it; - for (c_it i = withoutTess.begin(); i < withoutTess.end(); ++i) - { - ents.erase(*i); - } -} - -template -bool convert_vertices( - const smtk::model::EntityRefs& ents, - MappingType& mapping, - const smtk::mesh::AllocatorPtr& ialloc) -{ - //count the number of points in the tessellation so that we can properly - //allocate a single pool large enough for all the points - std::size_t numPointsToAlloc = 0; - smtk::model::EntityIterator it; - it.traverse(ents.begin(), ents.end(), smtk::model::ITERATE_BARE); - for (it.begin(); !it.isAtEnd(); ++it) - { - //we filtered out all ents without tess already, so this can't be null - const smtk::model::Tessellation* tess = it->hasTessellation(); - std::vector const& modelCoords = tess->coords(); - - //All tessellations are stored with x,y,z coordinates. - numPointsToAlloc += (modelCoords.size() / 3); - } - - std::vector meshCoords; - smtk::mesh::Handle firstVertHandle; - const bool pointsAllocated = - ialloc->allocatePoints(numPointsToAlloc, firstVertHandle, meshCoords); - if (!pointsAllocated) - { - return false; - } - - //iterate over the tessellation populating the mesh coordinates - std::size_t pos = 0; - it.traverse(ents.begin(), ents.end(), smtk::model::ITERATE_BARE); - for (it.begin(); !it.isAtEnd(); ++it) - { - //we filtered out all ents without tess already, so this can't be null - const smtk::model::Tessellation* tess = it->hasTessellation(); - std::vector const& modelCoords = tess->coords(); - - const std::size_t length = modelCoords.size(); - - //mark for this entity where in the global pool of points we can - //find the start of its coordinates, this will allow us to properly - //create the new connectivity for the mesh referencing the global - //point coordinate array - mapping[*it] = firstVertHandle + pos; - - for (std::size_t i = 0; i < length; i += 3, pos++) - { - meshCoords[0][pos] = modelCoords[i]; - meshCoords[1][pos] = modelCoords[i + 1]; - meshCoords[2][pos] = modelCoords[i + 2]; - } - } - - //return true if we have copied each coordinate from the tessellation - //into the mesh database. - return (pos == numPointsToAlloc); -} - -template -void convert_fixed_size_cell( - std::vector& cell_conn, - smtk::mesh::CellType cellType, - smtk::model::Tessellation::size_type numVerts, - std::vector& numCellsOfType, - std::vector& cellMBConn, - std::size_t global_coordinate_offset) -{ - std::size_t idx = numCellsOfType[cellType]++; - - smtk::mesh::Handle* currentConnLoc = cellMBConn[cellType].second + numVerts * idx; - for (int j = 0; j < numVerts; ++j) - { - //we need to fix the cell_conn to account for the fact that the - //values contained within are all relative to the tessellation and - //we need location based on the total sum of all tessellations. - //local position + ( total connectivity added before the tess ) should - //be correct. - currentConnLoc[j] = global_coordinate_offset + cell_conn[j]; - } -} - -template -void convert_vertex( - std::vector& /*unused*/, - smtk::mesh::CellType cellType, - smtk::model::Tessellation::size_type numVerts, - std::vector& numCellsOfType, - std::vector& cellMBConn, - std::size_t global_coordinate_offset) -{ - numCellsOfType[cellType]++; - - //get the list of vertex cells for this entity - smtk::mesh::HandleRange& currentCellids = cellMBConn[cellType].first; - - //instead of changing the connectivity like a normal cell, instead - //we modify the cell id list, as it is empty since no cells are allocated - //for vertices - //insert is inclusive on both ends - currentCellids.insert( - smtk::mesh::HandleInterval(global_coordinate_offset, global_coordinate_offset + numVerts - 1)); -} - -template -void convert_poly_line( - std::vector& cell_conn, - smtk::mesh::CellType cellType, - smtk::model::Tessellation::size_type numCellsInPolyCell, - std::vector& numCellsOfType, - std::vector& cellMBConn, - std::size_t global_coordinate_offset) -{ - //numVerts represents the number of verts in the tessellation, not - //the number of verts in the mesh cell - int previous_id = static_cast(numCellsOfType[cellType]); - numCellsOfType[cellType] += numCellsInPolyCell; - - int numVertsPerCell = smtk::mesh::verticesPerCell(cellType); - smtk::mesh::Handle* currentConnLoc = - cellMBConn[cellType].second + (numVertsPerCell * previous_id); - - int i = 0; - for (int j = 0; j < numCellsInPolyCell; ++j) - { - currentConnLoc[i] = global_coordinate_offset + cell_conn[j]; - currentConnLoc[i + 1] = global_coordinate_offset + cell_conn[j + 1]; - i += 2; - } -} - -template -std::map convert_cells( - const smtk::model::EntityRefs& ents, - MappingType& mapping, - const smtk::mesh::AllocatorPtr& ialloc) -{ - typedef smtk::model::Tessellation Tess; - - std::map newlyCreatedCells; - - smtk::model::EntityIterator it; - it.traverse(ents.begin(), ents.end(), smtk::model::ITERATE_BARE); - for (it.begin(); !it.isAtEnd(); ++it) - { - smtk::mesh::HandleRange cellsForThisEntity; - const smtk::model::EntityRef& refForThisEntity = it.current(); - - //we filtered out all ents without tess already, so this can't be null - const Tess* tess = it->hasTessellation(); - - // Convert the connectivity of this volume tessellation to a meshset. - // We make 2 passes through the tessellation: one to determine the - // allocation and another to create the cells. Note that each cell - // type must be put in a separate handle range. - // - // TODO: This does not handle triangle strips/fans, or polygons - Tess::size_type start_off; - std::vector numCellsOfType(smtk::mesh::CellType_MAX, 0); - for (start_off = tess->begin(); start_off != tess->end(); - start_off = tess->nextCellOffset(start_off)) - //from end means that we properly handle runs of the same cell type - { - Tess::size_type cell_type; - Tess::size_type numVertsPerCell = tess->numberOfCellVertices(start_off, &cell_type); - Tess::size_type cell_shape = Tess::cellShapeFromType(cell_type); - if ( - cell_shape == smtk::model::TESS_VERTEX || cell_shape == smtk::model::TESS_TRIANGLE || - cell_shape == smtk::model::TESS_QUAD) - { - numCellsOfType[tessToSMTKCell(cell_shape)]++; - } - else if (cell_shape == smtk::model::TESS_POLYLINE) - { - //In a polyline the number of cells is equal to one less than the - //number of points - numCellsOfType[tessToSMTKCell(cell_shape)] += numVertsPerCell - 1; - } - } - - // Allocate handles. - typedef std::pair HandleData; - HandleData blank; - blank.second = nullptr; - std::vector cellMBConn(smtk::mesh::CellType_MAX, blank); - std::vector::iterator allocIt = cellMBConn.begin(); - std::vector::iterator cellsOfTypeIt = numCellsOfType.begin(); - for (std::size_t ctype = 0; ctype != smtk::mesh::CellType_MAX; - ++ctype, ++cellsOfTypeIt, ++allocIt) - { - if (*cellsOfTypeIt <= 0) - continue; - - smtk::mesh::CellType cellType = static_cast(ctype); - int numVertsPerCell = smtk::mesh::verticesPerCell(cellType); - if (cellType == smtk::mesh::Vertex) - { - //In the moab/interface world vertices don't have explicit connectivity - //so we can't allocate cells. Instead we just explicitly add those - //points to the MeshSet - continue; - } - - if (!ialloc->allocateCells( - cellType, *cellsOfTypeIt, numVertsPerCell, allocIt->first, allocIt->second)) - { // error - std::cerr << "Could not allocate cells\n"; - } - } - - std::vector cell_conn; - numCellsOfType = std::vector(smtk::mesh::CellType_MAX, 0); - for (start_off = tess->begin(); start_off != tess->end(); - start_off = tess->nextCellOffset(start_off)) - { - //fetch the number of cell vertices, and the cell type in a single query - Tess::size_type cell_type; - Tess::size_type numVerts = tess->numberOfCellVertices(start_off, &cell_type); - Tess::size_type cell_shape = Tess::cellShapeFromType(cell_type); - - //convert from tess type to smtk cell type - const smtk::mesh::CellType cellType = tessToSMTKCell(cell_shape); - std::size_t global_coordinate_offset = mapping[*it]; - - cell_conn.reserve(numVerts); - tess->vertexIdsOfCell(start_off, cell_conn); - if (cell_shape == smtk::model::TESS_TRIANGLE || cell_shape == smtk::model::TESS_QUAD) - { - convert_fixed_size_cell( - cell_conn, cellType, numVerts, numCellsOfType, cellMBConn, global_coordinate_offset); - } - else if (cell_shape == smtk::model::TESS_VERTEX) - { - convert_vertex( - cell_conn, cellType, numVerts, numCellsOfType, cellMBConn, global_coordinate_offset); - } - else if (cell_shape == smtk::model::TESS_POLYLINE) - { - convert_poly_line( - cell_conn, - cellType, - (numVerts - 1), - numCellsOfType, - cellMBConn, - global_coordinate_offset); - } - - //this is horribly important. vertexIdsOfCell is implemented by using - //insert() and end() which means that it appends, and if we don't clear - //the vector we will append onto the end and have an vector that - //holds 2 triangles of connectivity ( than 3,4,5, etc). - //We also use clear, to reduce the number of memory allocation we require - cell_conn.clear(); - } - - allocIt = cellMBConn.begin(); - cellsOfTypeIt = numCellsOfType.begin(); - for (std::size_t ctype = 0; ctype != smtk::mesh::CellType_MAX; - ++ctype, ++cellsOfTypeIt, ++allocIt) - { - if (*cellsOfTypeIt <= 0) - continue; - - //update the connectivity as long as we aren't vertices - smtk::mesh::CellType cellType = static_cast(ctype); - smtk::mesh::HandleRange& currentCellids = allocIt->first; - if (cellType != smtk::mesh::Vertex) - { - int numVertsPerCell = smtk::mesh::verticesPerCell(cellType); - smtk::mesh::Handle* connectivity = allocIt->second; - ialloc->connectivityModified(currentCellids, numVertsPerCell, connectivity); - } - - //we need to add these cells to the range that represents all - //cells for this volume - cellsForThisEntity += currentCellids; - } - - //save all the cells of this volume - newlyCreatedCells.insert(std::make_pair(refForThisEntity, cellsForThisEntity)); - } - return newlyCreatedCells; -} - -/// Recursively find all the entities with tessellation -void find_entities_with_tessellation( - const smtk::model::EntityRef& root, - smtk::model::EntityRefs& tessEntities, - smtk::model::EntityRefs& touched) -{ - typedef smtk::model::EntityRefArray EntityRefArray; - EntityRefArray children = - (root.isModel() ? root.as().cellsAs() - : (root.isCellEntity() - ? root.as().boundingCellsAs() - : (root.isGroup() ? root.as().members() - : EntityRefArray()))); - - if (root.isModel()) - { - // Make sure sub-models and groups are handled. - EntityRefArray tmp; - tmp = root.as().submodelsAs(); - children.insert(children.end(), tmp.begin(), tmp.end()); - tmp = root.as().groupsAs(); - children.insert(children.end(), tmp.begin(), tmp.end()); - } - - for (EntityRefArray::const_iterator it = children.begin(); it != children.end(); ++it) - { - if (touched.find(*it) == touched.end()) - { - touched.insert(*it); - if (it->hasTessellation()) - { - tessEntities.insert(*it); - } - detail::find_entities_with_tessellation(*it, tessEntities, touched); - } - } -} -} //namespace detail - -ModelToMesh::ModelToMesh() = default; - -smtk::mesh::ResourcePtr ModelToMesh::operator()(const smtk::model::ResourcePtr& modelResource) const -{ - typedef smtk::model::EntityRefs EntityRefs; - typedef smtk::model::EntityTypeBits EntityTypeBits; - typedef std::map CoordinateOffsetMap; - - smtk::mesh::ResourcePtr nullResourcePtr; - if (!modelResource) - { - return nullResourcePtr; - } - - if (modelResource->tessellations().empty()) - { - //we have zero tesselations, we can't continue. This is an invalid model - return nullResourcePtr; - } - - //Create the mesh resource and extract the allocation interface from it - smtk::mesh::ResourcePtr meshResource = smtk::mesh::Resource::create(); - smtk::mesh::InterfacePtr iface = meshResource->interface(); - smtk::mesh::AllocatorPtr ialloc = iface->allocator(); - meshResource->setModelResource(modelResource); - - //We create a new mesh each for the Edge(s), Face(s) and Volume(s). - //the MODEL_ENTITY will be associated with the meshset that contains all - // meshes. - CoordinateOffsetMap coordinateLocationMapping; - - EntityTypeBits etypes[4] = { - smtk::model::VERTEX, smtk::model::EDGE, smtk::model::FACE, smtk::model::VOLUME - }; - for (int i = 0; i != 4; ++i) - { - //extract all the coordinates from every tessellation and make a single - //big pool - EntityTypeBits entType = etypes[i]; - EntityRefs currentEnts = modelResource->entitiesMatchingFlagsAs(entType); - detail::removeOnesWithoutTess(currentEnts); - detail::convert_vertices(currentEnts, coordinateLocationMapping, ialloc); - } - - //We need to iterate over each model i think here - //next we convert all volumes, faces, edges, and vertices that have tessellation - for (int i = 0; i != 4; ++i) - { - EntityTypeBits entType = etypes[i]; - EntityRefs currentEnts = modelResource->entitiesMatchingFlagsAs(entType); - detail::removeOnesWithoutTess(currentEnts); - if (!currentEnts.empty()) - { - //for each volume entity we need to create a range of handles - //that represent the cell ids for that volume. - std::map per_ent_cells = - detail::convert_cells(currentEnts, coordinateLocationMapping, ialloc); - - typedef std::map::const_iterator c_it; - for (c_it j = per_ent_cells.begin(); j != per_ent_cells.end(); ++j) - { - //now create a mesh from those cells - smtk::mesh::CellSet cellsForMesh(meshResource, j->second); - smtk::mesh::MeshSet ms = meshResource->createMesh(cellsForMesh); - meshResource->setAssociation(j->first, ms); - } - - EntityRefs currentModels = - modelResource->entitiesMatchingFlagsAs(smtk::model::MODEL_ENTITY); - if (!currentModels.empty()) - { - meshResource->associateToModel(currentModels.begin()->entity()); - } - } - } - - //Now merge all duplicate points inside the mesh resource - if (m_mergeDuplicates) - { - if (m_tolerance >= 0) - { - meshResource->meshes().mergeCoincidentContactPoints(m_tolerance); - } - else - { //allow the meshes api to specify the default - meshResource->meshes().mergeCoincidentContactPoints(); - } - } - - return meshResource; -} - -smtk::mesh::ResourcePtr ModelToMesh::operator()(const smtk::model::Model& model) const -{ - typedef smtk::model::EntityRefs EntityRefs; - typedef std::map CoordinateOffsetMap; - smtk::model::ResourcePtr modelResource = model.resource(); - smtk::mesh::ResourcePtr nullResourcePtr; - if (!modelResource) - { - return nullResourcePtr; - } - - if (modelResource->tessellations().empty()) - { - //we have zero tesselations, we can't continue. This is an invalid model - return nullResourcePtr; - } - - //Create the mesh resource and extract the allocation interface from it - smtk::mesh::ResourcePtr meshResource = smtk::mesh::Resource::create(); - smtk::mesh::InterfacePtr iface = meshResource->interface(); - smtk::mesh::AllocatorPtr ialloc = iface->allocator(); - meshResource->setModelResource(modelResource); - - //We create a new mesh each for the Edge(s), Face(s) and Volume(s). - //the MODEL_ENTITY will be associated with the meshset that contains all - // meshes. - CoordinateOffsetMap coordinateLocationMapping; - EntityRefs tessEntities, touched; - detail::find_entities_with_tessellation(model, tessEntities, touched); - if (!tessEntities.empty()) - { - detail::convert_vertices(tessEntities, coordinateLocationMapping, ialloc); - - //for each volumes, faces, edges, and vertices entity we need to create a range of handles - //that represent the cell ids for that volume. - std::map per_ent_cells = - detail::convert_cells(tessEntities, coordinateLocationMapping, ialloc); - - typedef std::map::const_iterator c_it; - for (c_it i = per_ent_cells.begin(); i != per_ent_cells.end(); ++i) - { - //now create a mesh from those cells - smtk::mesh::CellSet cellsForMesh(meshResource, i->second); - smtk::mesh::MeshSet ms = meshResource->createMesh(cellsForMesh); - meshResource->setAssociation(i->first, ms); - } - - meshResource->associateToModel(model.entity()); - } - - //Now merge all duplicate points inside the mesh resource - if (m_mergeDuplicates) - { - if (m_tolerance >= 0) - { - meshResource->meshes().mergeCoincidentContactPoints(m_tolerance); - } - else - { //allow the meshes api to specify the default - meshResource->meshes().mergeCoincidentContactPoints(); - } - } - - return meshResource; -} -} // namespace io -} // namespace smtk diff --git a/smtk/io/ModelToMesh.h b/smtk/io/ModelToMesh.h deleted file mode 100644 index 70e5980d8642d7b7622c15f890b434ebe1607638..0000000000000000000000000000000000000000 --- a/smtk/io/ModelToMesh.h +++ /dev/null @@ -1,52 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_io_ModelToMesh_h -#define smtk_io_ModelToMesh_h - -#include "smtk/CoreExports.h" // For SMTKCORE_EXPORT macro. -#include "smtk/PublicPointerDefs.h" - -namespace smtk -{ -namespace model -{ -class Model; -} - -namespace io -{ -class SMTKCORE_EXPORT ModelToMesh -{ -public: - //By default will merge duplicate elements, and will use the default tolerance - //specified by mergeCoincidentContactPoints - ModelToMesh(); - - //By default will merge duplicate elements - bool isMergingEnabled() const { return m_mergeDuplicates; } - void setIsMerging(bool m) { m_mergeDuplicates = m; } - - //Allow you to specify a custom tolerance for the merging of duplicate elements - double getMergeTolerance() const { return m_tolerance; } - void setMergeTolerance(double tol) { m_tolerance = tol; } - - //convert smtk::model::resource to a smtk::mesh::resource - smtk::mesh::ResourcePtr operator()(const smtk::model::ResourcePtr& modelResource) const; - //convert smtk::model to a smtk::mesh::resource - smtk::mesh::ResourcePtr operator()(const smtk::model::Model& model) const; - -private: - bool m_mergeDuplicates{ true }; - double m_tolerance{ -1 }; -}; -} // namespace io -} // namespace smtk - -#endif diff --git a/smtk/io/ReadMesh.cxx b/smtk/io/ReadMesh.cxx deleted file mode 100644 index 6cc5a1c68db3ccb118cba69c0bfe7dbb369da34d..0000000000000000000000000000000000000000 --- a/smtk/io/ReadMesh.cxx +++ /dev/null @@ -1,194 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/io/ReadMesh.h" - -#include "smtk/io/mesh/MeshIOMoab.h" -#include "smtk/io/mesh/MeshIOXMS.h" - -#include "smtk/common/CompilerInformation.h" - -#include "smtk/mesh/core/Resource.h" - -#include - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "boost/filesystem.hpp" -#include "boost/system/error_code.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -using namespace boost::filesystem; - -namespace smtk -{ -namespace io -{ - -ReadMesh::ReadMesh() = default; - -ReadMesh::~ReadMesh() = default; - -std::vector& ReadMesh::SupportedIOTypes() -{ - static std::vector supportedIOTypes; - if (supportedIOTypes.empty()) - { - supportedIOTypes.push_back(mesh::MeshIOPtr(new mesh::MeshIOXMS())); - supportedIOTypes.push_back(mesh::MeshIOPtr(new mesh::MeshIOMoab())); - } - return supportedIOTypes; -} - -bool ReadMesh::ExtensionIsSupported(const std::string& ext) -{ - for (auto& reader : smtk::io::ReadMesh::SupportedIOTypes()) - { - for (const auto& format : reader->FileFormats()) - { - if ( - format.CanRead() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - return true; - } - } - } - - return false; -} - -smtk::mesh::ResourcePtr ReadMesh::operator()( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - mesh::Subset subset) const -{ - // Grab the file extension - boost::filesystem::path fpath(filePath); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - smtk::mesh::ResourcePtr resource = nullptr; - - // Search for an appropriate reader - for (auto&& reader : smtk::io::ReadMesh::SupportedIOTypes()) - { - for (auto&& format : reader->FileFormats()) - { - if ( - format.CanRead() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - // read the resource - resource = reader->read(filePath, interface, subset); - break; - } - } - } - - if (!resource) - { - // create an invalid colection (i.e. one with an invalid id) - resource = smtk::mesh::Resource::create(); - resource->setId(smtk::common::UUID::null()); - resource->readLocation(filePath); - } - else - { - resource->readLocation(filePath); - } - - return resource; -} - -bool ReadMesh::operator()( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - mesh::Subset subset) const -{ - // Grab the file extension - boost::filesystem::path fpath(filePath); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - // Search for an appropriate reader - for (auto&& reader : smtk::io::ReadMesh::SupportedIOTypes()) - { - for (auto&& format : reader->FileFormats()) - { - if ( - format.CanRead() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - // read the resource - return reader->read(filePath, resource, subset); - } - } - } - return false; -} - -smtk::mesh::ResourcePtr readMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - mesh::Subset subset) -{ - ReadMesh read; - return read(filePath, interface, subset); -} -smtk::mesh::ResourcePtr readEntireResource( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface) -{ - return smtk::io::readMesh(filePath, interface, mesh::Subset::EntireResource); -} -smtk::mesh::ResourcePtr readDomain( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface) -{ - return smtk::io::readMesh(filePath, interface, mesh::Subset::OnlyDomain); -} -smtk::mesh::ResourcePtr readDirichlet( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface) -{ - return smtk::io::readMesh(filePath, interface, mesh::Subset::OnlyDirichlet); -} -smtk::mesh::ResourcePtr readNeumann( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface) -{ - return smtk::io::readMesh(filePath, interface, mesh::Subset::OnlyNeumann); -} - -bool readMesh(const std::string& filePath, smtk::mesh::ResourcePtr resource, mesh::Subset subset) -{ - ReadMesh read; - return read(filePath, resource, subset); -} -bool readEntireResource(const std::string& filePath, smtk::mesh::ResourcePtr resource) -{ - return smtk::io::readMesh(filePath, resource, mesh::Subset::EntireResource); -} -bool readDomain(const std::string& filePath, smtk::mesh::ResourcePtr resource) -{ - return smtk::io::readMesh(filePath, resource, mesh::Subset::OnlyDomain); -} -bool readDirichlet(const std::string& filePath, smtk::mesh::ResourcePtr resource) -{ - return smtk::io::readMesh(filePath, resource, mesh::Subset::OnlyDirichlet); -} -bool readNeumann(const std::string& filePath, smtk::mesh::ResourcePtr resource) -{ - return smtk::io::readMesh(filePath, resource, mesh::Subset::OnlyNeumann); -} -} // namespace io -} // namespace smtk diff --git a/smtk/io/ReadMesh.h b/smtk/io/ReadMesh.h deleted file mode 100644 index f873a377d6170258bfd73cf0d9632b0d4f6fa95f..0000000000000000000000000000000000000000 --- a/smtk/io/ReadMesh.h +++ /dev/null @@ -1,87 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_io_ReadMesh_h -#define smtk_io_ReadMesh_h - -#include "smtk/CoreExports.h" // For SMTKCORE_EXPORT macro. -#include "smtk/PublicPointerDefs.h" - -#include "smtk/io/mesh/MeshIO.h" - -#include -#include - -namespace smtk -{ -namespace io -{ - -/**\brief Read an entire SMTK mesh resource from a file, or just sub-sections - * - */ -class SMTKCORE_EXPORT ReadMesh -{ -public: - ReadMesh(); - ~ReadMesh(); - - ReadMesh& operator=(const ReadMesh&) = delete; - ReadMesh(const ReadMesh&) = delete; - - static std::vector& SupportedIOTypes(); - - static bool ExtensionIsSupported(const std::string& ext); - - //Load the domain sets from a moab data file as a new resource into the - //given manager. - smtk::mesh::ResourcePtr operator()( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - mesh::Subset subset = mesh::Subset::EntireResource) const; - bool operator()( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - mesh::Subset subset = mesh::Subset::EntireResource) const; -}; - -SMTKCORE_EXPORT smtk::mesh::ResourcePtr readMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - mesh::Subset subset = mesh::Subset::EntireResource); -// Explicit functions for each subset type -SMTKCORE_EXPORT smtk::mesh::ResourcePtr readEntireResource( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface); -SMTKCORE_EXPORT smtk::mesh::ResourcePtr readDomain( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface); -SMTKCORE_EXPORT smtk::mesh::ResourcePtr readDirichlet( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface); -SMTKCORE_EXPORT smtk::mesh::ResourcePtr readNeumann( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface); - -SMTKCORE_EXPORT bool readMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - mesh::Subset subset = mesh::Subset::EntireResource); -// Explicit functions for each subset type -SMTKCORE_EXPORT bool readEntireResource( - const std::string& filePath, - smtk::mesh::ResourcePtr resource); -SMTKCORE_EXPORT bool readDomain(const std::string& filePath, smtk::mesh::ResourcePtr resource); -SMTKCORE_EXPORT bool readDirichlet(const std::string& filePath, smtk::mesh::ResourcePtr resource); -SMTKCORE_EXPORT bool readNeumann(const std::string& filePath, smtk::mesh::ResourcePtr resource); -} // namespace io -} // namespace smtk - -#endif diff --git a/smtk/io/WriteMesh.cxx b/smtk/io/WriteMesh.cxx deleted file mode 100644 index a090baa44c25c03e87e93d889102ea8d900490c0..0000000000000000000000000000000000000000 --- a/smtk/io/WriteMesh.cxx +++ /dev/null @@ -1,149 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/io/WriteMesh.h" - -#include "smtk/io/mesh/MeshIOMoab.h" -#include "smtk/io/mesh/MeshIOXMS.h" - -#include "smtk/common/CompilerInformation.h" - -#include "smtk/mesh/core/Resource.h" - -#include - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "boost/filesystem.hpp" -#include "boost/system/error_code.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -using namespace boost::filesystem; - -namespace smtk -{ -namespace io -{ - -WriteMesh::WriteMesh() = default; - -WriteMesh::~WriteMesh() = default; - -std::vector& WriteMesh::SupportedIOTypes() -{ - static std::vector supportedIOTypes; - if (supportedIOTypes.empty()) - { - supportedIOTypes.push_back(mesh::MeshIOPtr(new mesh::MeshIOXMS())); - supportedIOTypes.push_back(mesh::MeshIOPtr(new mesh::MeshIOMoab())); - } - return supportedIOTypes; -} - -bool WriteMesh::operator()( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - mesh::Subset subset) const -{ - // Grab the file extension - boost::filesystem::path fpath(filePath); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - // Search for an appropriate writer - for (auto&& writer : smtk::io::WriteMesh::SupportedIOTypes()) - { - for (auto&& format : writer->FileFormats()) - { - if ( - format.CanWrite() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - // write the resource - return writer->write(filePath, resource, subset); - } - } - } - return false; -} - -bool WriteMesh::operator()(smtk::mesh::ResourcePtr resource, mesh::Subset subset) const -{ - // Grab the file extension - boost::filesystem::path fpath(resource->writeLocation().absolutePath()); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - // Search for an appropriate writer - for (auto&& writer : smtk::io::WriteMesh::SupportedIOTypes()) - { - for (auto&& format : writer->FileFormats()) - { - if ( - format.CanWrite() && - std::find(format.Extensions.begin(), format.Extensions.end(), ext) != - format.Extensions.end()) - { - // write the resource - return writer->write(resource, subset); - } - } - } - return false; -} - -bool writeMesh(const std::string& filePath, smtk::mesh::ResourcePtr resource, mesh::Subset subset) -{ - WriteMesh write; - return write(filePath, resource, subset); -} -bool writeEntireResource(const std::string& filePath, smtk::mesh::ResourcePtr resource) -{ - return smtk::io::writeMesh(filePath, resource, mesh::Subset::EntireResource); -} -bool writeDomain(const std::string& filePath, smtk::mesh::ResourcePtr resource) -{ - return smtk::io::writeMesh(filePath, resource, mesh::Subset::OnlyDomain); -} -bool writeDirichlet(const std::string& filePath, smtk::mesh::ResourcePtr resource) -{ - return smtk::io::writeMesh(filePath, resource, mesh::Subset::OnlyDirichlet); -} -bool writeNeumann(const std::string& filePath, smtk::mesh::ResourcePtr resource) -{ - return smtk::io::writeMesh(filePath, resource, mesh::Subset::OnlyNeumann); -} - -bool writeMesh(smtk::mesh::ResourcePtr resource, mesh::Subset subset) -{ - WriteMesh write; - return write(resource, subset); -} -bool writeEntireResource(smtk::mesh::ResourcePtr resource) -{ - WriteMesh write; - return smtk::io::writeMesh(resource, mesh::Subset::EntireResource); -} -bool writeDomain(smtk::mesh::ResourcePtr resource) -{ - WriteMesh write; - return smtk::io::writeMesh(resource, mesh::Subset::OnlyDomain); -} -bool writeDirichlet(smtk::mesh::ResourcePtr resource) -{ - WriteMesh write; - return smtk::io::writeMesh(resource, mesh::Subset::OnlyDirichlet); -} -bool writeNeumann(smtk::mesh::ResourcePtr resource) -{ - WriteMesh write; - return smtk::io::writeMesh(resource, mesh::Subset::OnlyNeumann); -} -} // namespace io -} // namespace smtk diff --git a/smtk/io/WriteMesh.h b/smtk/io/WriteMesh.h deleted file mode 100644 index 3af8c4fbfb49ced52028ef8efe1ef8bd40ec552d..0000000000000000000000000000000000000000 --- a/smtk/io/WriteMesh.h +++ /dev/null @@ -1,73 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_io_WriteMesh_h -#define smtk_io_WriteMesh_h - -#include "smtk/CoreExports.h" // For SMTKCORE_EXPORT macro. -#include "smtk/PublicPointerDefs.h" - -#include "smtk/io/mesh/MeshIO.h" - -#include -#include - -namespace smtk -{ -namespace io -{ - -/**\brief Write an entire SMTK mesh resource from a file, or just sub-sections - * - */ -class SMTKCORE_EXPORT WriteMesh -{ -public: - WriteMesh(); - ~WriteMesh(); - - WriteMesh& operator=(const WriteMesh&) = delete; - WriteMesh(const WriteMesh&) = delete; - - static std::vector& SupportedIOTypes(); - - bool operator()( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - mesh::Subset subset = mesh::Subset::EntireResource) const; - bool operator()( - smtk::mesh::ResourcePtr resource, - mesh::Subset subset = mesh::Subset::EntireResource) const; -}; - -SMTKCORE_EXPORT bool writeMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - mesh::Subset subset = mesh::Subset::EntireResource); -SMTKCORE_EXPORT bool writeEntireResource( - const std::string& filePath, - smtk::mesh::ResourcePtr resource); -// Explicit functions for each subset type -SMTKCORE_EXPORT bool writeDomain(const std::string& filePath, smtk::mesh::ResourcePtr resource); -SMTKCORE_EXPORT bool writeDirichlet(const std::string& filePath, smtk::mesh::ResourcePtr resource); -SMTKCORE_EXPORT bool writeNeumann(const std::string& filePath, smtk::mesh::ResourcePtr resource); - -SMTKCORE_EXPORT bool writeMesh( - smtk::mesh::ResourcePtr resource, - mesh::Subset subset = mesh::Subset::EntireResource); -// Explicit functions for each subset type -SMTKCORE_EXPORT bool writeEntireResource(smtk::mesh::ResourcePtr resource); -SMTKCORE_EXPORT bool writeDomain(smtk::mesh::ResourcePtr resource); -SMTKCORE_EXPORT bool writeDirichlet(smtk::mesh::ResourcePtr resource); -SMTKCORE_EXPORT bool writeNeumann(smtk::mesh::ResourcePtr resource); -} // namespace io -} // namespace smtk - -#endif diff --git a/smtk/io/XmlDocV2Parser.cxx b/smtk/io/XmlDocV2Parser.cxx index dfa469fd93452db05462b04980e39c4bd3d4df0c..4f7ca91577eff294150280df298729c1b53385d3 100644 --- a/smtk/io/XmlDocV2Parser.cxx +++ b/smtk/io/XmlDocV2Parser.cxx @@ -21,9 +21,6 @@ #include "smtk/attribute/FileItem.h" #include "smtk/attribute/FileItemDefinition.h" #include "smtk/attribute/StringItemDefinition.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/json/Interface.h" -#include "smtk/mesh/json/jsonHandleRange.h" #include "smtk/model/EntityRef.h" #include "smtk/model/Group.h" #include "smtk/model/Resource.h" @@ -407,35 +404,6 @@ void XmlDocV2Parser::processModelEntityItem(pugi::xml_node& node, attribute::Com } } -void XmlDocV2Parser::processMeshEntityDef( - pugi::xml_node& node, - attribute::ComponentItemDefinitionPtr idef) -{ - xml_node child; - xml_attribute xatt; - - idef->setAcceptsEntries(smtk::common::typeName(), "meshset", true); - - this->processItemDef(node, idef); - - xatt = node.attribute("NumberOfRequiredValues"); - if (xatt) - { - idef->setNumberOfRequiredValues(xatt.as_int()); - } - - xatt = node.attribute("Extensible"); - if (xatt) - { - idef->setIsExtensible(xatt.as_bool()); - xatt = node.attribute("MaxNumberOfValues"); - if (xatt) - { - idef->setMaxNumberOfValues(xatt.as_uint()); - } - } -} - void XmlDocV2Parser::processViews(xml_node& root) { xml_node views = root.child("Views"); diff --git a/smtk/io/XmlDocV2Parser.h b/smtk/io/XmlDocV2Parser.h index 4ea41c53b27f872e124abdc06cf878b801702c77..d162e39c74ca9e0a21d4c54cd501cdd57dfb9848 100644 --- a/smtk/io/XmlDocV2Parser.h +++ b/smtk/io/XmlDocV2Parser.h @@ -42,8 +42,6 @@ protected: void processFileDef(pugi::xml_node& node, smtk::attribute::FileItemDefinitionPtr idef) override; void processModelEntityItem(pugi::xml_node& node, smtk::attribute::ComponentItemPtr item) override; - void processMeshEntityDef(pugi::xml_node& node, smtk::attribute::ComponentItemDefinitionPtr idef) - override; void processStringDefAtts( pugi::xml_node& node, const smtk::attribute::StringItemDefinitionPtr& idef) override; diff --git a/smtk/io/XmlV2StringWriter.cxx b/smtk/io/XmlV2StringWriter.cxx index 1d4ddc516b2d91942cb679b99044471ddc8aa552..477020f7b3e351eee7823da0fc0ed3c5223870f8 100644 --- a/smtk/io/XmlV2StringWriter.cxx +++ b/smtk/io/XmlV2StringWriter.cxx @@ -37,9 +37,6 @@ #include "smtk/attribute/ValueItemDefinition.h" #include "smtk/view/Configuration.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/json/jsonHandleRange.h" - #include "smtk/model/Entity.h" #include "smtk/model/EntityRef.h" #include "smtk/model/Group.h" diff --git a/smtk/io/mesh/Format.cxx b/smtk/io/mesh/Format.cxx deleted file mode 100644 index 95292637378e3c3358efc496d624fa6859f32001..0000000000000000000000000000000000000000 --- a/smtk/io/mesh/Format.cxx +++ /dev/null @@ -1,26 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include - -namespace smtk -{ -namespace io -{ -namespace mesh -{ - -const Format::IOFlags Format::Import = IOFlags(0x1); -const Format::IOFlags Format::Export = IOFlags(0x2); -const Format::IOFlags Format::Read = IOFlags(0x4); -const Format::IOFlags Format::Write = IOFlags(0x8); -} // namespace mesh -} // namespace io -} // namespace smtk diff --git a/smtk/io/mesh/Format.h b/smtk/io/mesh/Format.h deleted file mode 100644 index c200504fe81b7a7fd8dd2ad992349d60cc6b7972..0000000000000000000000000000000000000000 --- a/smtk/io/mesh/Format.h +++ /dev/null @@ -1,81 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_io_Formats_h -#define smtk_io_Formats_h - -#include "smtk/CoreExports.h" // For SMTKCORE_EXPORT macro. -#include "smtk/common/CompilerInformation.h" - -#include -#include -#include - -#ifdef SMTK_MSVC -// Ignore symbol exposure warnings for STL classes. -#pragma warning(disable : 4251) -#endif - -/**\brief Mesh IO formats - * - */ - -namespace smtk -{ -namespace io -{ -namespace mesh -{ - -struct SMTKCORE_EXPORT Format -{ - typedef std::bitset<4> IOFlags; - - Format() - : Flags(IOFlags(0x0)) - { - } - Format(const std::string& name, IOFlags flags) - : Name(name) - , Flags(flags) - { - } - Format(const std::string& name, const std::vector& extensions, IOFlags flags) - : Name(name) - , Extensions(extensions) - , Flags(flags) - { - } - Format(const std::string& name, const std::string& extension, IOFlags flags) - : Name(name) - , Extensions(1, extension) - , Flags(flags) - { - } - - static const IOFlags Import; - static const IOFlags Export; - static const IOFlags Read; - static const IOFlags Write; - - bool CanImport() const { return (this->Flags & Import) == Import; } - bool CanExport() const { return (this->Flags & Export) == Export; } - bool CanRead() const { return (this->Flags & Read) == Read; } - bool CanWrite() const { return (this->Flags & Write) == Write; } - - std::string Name; - std::vector Extensions; - IOFlags Flags; -}; -} // namespace mesh -} // namespace io -} // namespace smtk - -#endif diff --git a/smtk/io/mesh/MeshIO.h b/smtk/io/mesh/MeshIO.h deleted file mode 100644 index e4e05e82b40d55a9caed0b8af9c285b473ac407f..0000000000000000000000000000000000000000 --- a/smtk/io/mesh/MeshIO.h +++ /dev/null @@ -1,93 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_io_MeshIO_h -#define smtk_io_MeshIO_h - -#include "smtk/CoreExports.h" // For SMTKCORE_EXPORT macro. -#include "smtk/PublicPointerDefs.h" - -#include "smtk/io/mesh/Format.h" - -#include - -namespace smtk -{ -namespace io -{ -/// Mesh IO -namespace mesh -{ - -/// Mesh subset types -enum class Subset : unsigned int -{ - EntireResource, - OnlyDomain, - OnlyDirichlet, - OnlyNeumann, -}; - -/**\brief Base class for mesh IO types - * - * Rather than make the interface for this class pure virtual, the methods - * default to doing nothing and are overridden in the derived classes. The - * possible actions are then recorded in the mesh Format, which can be queried - * at runtime. - */ - -class MeshIO; -typedef std::unique_ptr MeshIOPtr; - -class SMTKCORE_EXPORT MeshIO -{ -public: - virtual ~MeshIO() = default; - - virtual smtk::mesh::ResourcePtr - importMesh(const std::string&, const smtk::mesh::InterfacePtr&, const std::string&) const - { - return smtk::mesh::ResourcePtr(); - } - virtual bool importMesh(const std::string&, smtk::mesh::ResourcePtr, const std::string&) const - { - return false; - } - - virtual bool exportMesh(const std::string&, smtk::mesh::ResourcePtr) const { return false; } - virtual bool exportMesh( - const std::string&, - smtk::mesh::ResourcePtr, - smtk::model::ResourcePtr, - const std::string&) const - { - return false; - } - - virtual smtk::mesh::ResourcePtr read(const std::string&, const smtk::mesh::InterfacePtr&, Subset) - const - { - return smtk::mesh::ResourcePtr(); - } - virtual bool read(const std::string&, smtk::mesh::ResourcePtr, Subset) const { return false; } - - virtual bool write(const std::string&, smtk::mesh::ResourcePtr, Subset) const { return false; } - virtual bool write(smtk::mesh::ResourcePtr, Subset) const { return false; } - - const std::vector& FileFormats() const { return this->Formats; } - -protected: - std::vector Formats; -}; -} // namespace mesh -} // namespace io -} // namespace smtk - -#endif diff --git a/smtk/io/mesh/MeshIOMoab.cxx b/smtk/io/mesh/MeshIOMoab.cxx deleted file mode 100644 index d5ea5ae4d46c84e9094852a8ec051113146f4239..0000000000000000000000000000000000000000 --- a/smtk/io/mesh/MeshIOMoab.cxx +++ /dev/null @@ -1,168 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/mesh/MeshIOMoab.h" -#include "smtk/io/mesh/MeshIO.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/moab/Readers.h" -#include "smtk/mesh/moab/Writers.h" - -namespace smtk -{ -namespace io -{ -namespace mesh -{ - -MeshIOMoab::MeshIOMoab() -{ - this->Formats.emplace_back( - "MOAB File", - std::vector({ ".h5m", ".mhdf" }), - Format::Import | Format::Export | Format::Read | Format::Write); - this->Formats.emplace_back( - "Exodus File via MOAB", - std::vector({ ".ex2", ".exo", ".exoII", ".exo2", ".e", ".g", ".gen" }), - Format::Import | Format::Export | Format::Read | Format::Write); - this->Formats.emplace_back( - "SLAC File via MOAB", std::vector({ ".slac" }), Format::Import | Format::Export); - this->Formats.emplace_back( - "General Mesh Viewer", std::vector({ ".gmv" }), Format::Import | Format::Export); - this->Formats.emplace_back( - "ANSYS File", std::vector({ ".ans" }), Format::Import | Format::Export); - this->Formats.emplace_back( - "Gmsh File", std::vector({ ".msh", ".gmsh" }), Format::Import | Format::Export); -#ifdef MOAB_IMPORT_STL - // An update to MOAB's lastest master caused the stl importer to fail. Until - // this is fixed, we temporarily disable MOAB's stl reader (we still have - // VTK's stl reader, if VTK is enabled). - this->Formats.push_back(Format( - "Stereolithography File", - std::vector({ ".stl" }), - Format::Import | Format::Export)); -#endif - this->Formats.emplace_back( - "Wavefront OBJ File", std::vector({ ".obj" }), Format::Import | Format::Export); -} - -smtk::mesh::ResourcePtr MeshIOMoab::importMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - const std::string& /*unused*/) const -{ - return this->read(filePath, interface, Subset::EntireResource); -} - -bool MeshIOMoab::importMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr resource, - const std::string& /*unused*/) const -{ - return this->read(filePath, resource, Subset::EntireResource); -} - -bool MeshIOMoab::exportMesh(const std::string& filePath, smtk::mesh::ResourcePtr resource) const -{ - return this->write(filePath, resource, Subset::EntireResource); -} - -//TODO: -// bool MeshIOMoab::exportMesh( const std::string& filePath, -// smtk::mesh::ResourcePtr resource, -// smtk::model::ResourcePtr resource, -// const std::string& modelPropertyName ) const -// { - -// } - -smtk::mesh::ResourcePtr MeshIOMoab::read( - const std::string& filePath, - const smtk::mesh::InterfacePtr& /*unused*/, - Subset subset) const -{ - smtk::mesh::ResourcePtr resource; - - switch (subset) - { - case Subset::EntireResource: - resource = smtk::mesh::moab::read(filePath); - break; - case Subset::OnlyDomain: - resource = smtk::mesh::moab::read_domain(filePath); - break; - case Subset::OnlyDirichlet: - resource = smtk::mesh::moab::read_dirichlet(filePath); - break; - case Subset::OnlyNeumann: - resource = smtk::mesh::moab::read_neumann(filePath); - break; - default: - resource = smtk::mesh::Resource::create(); - } - return resource; -} - -bool MeshIOMoab::read(const std::string& filePath, smtk::mesh::ResourcePtr resource, Subset subset) - const -{ - bool result; - - switch (subset) - { - case Subset::EntireResource: - result = smtk::mesh::moab::import(filePath, resource); - break; - case Subset::OnlyDomain: - result = smtk::mesh::moab::import_domain(filePath, resource); - break; - case Subset::OnlyDirichlet: - result = smtk::mesh::moab::import_dirichlet(filePath, resource); - break; - case Subset::OnlyNeumann: - result = smtk::mesh::moab::import_neumann(filePath, resource); - break; - default: - result = false; - } - return result; -} - -bool MeshIOMoab::write(const std::string& filePath, smtk::mesh::ResourcePtr resource, Subset subset) - const -{ - switch (subset) - { - case Subset::EntireResource: - return smtk::mesh::moab::write(filePath, resource); - case Subset::OnlyDomain: - return smtk::mesh::moab::write_domain(filePath, resource); - case Subset::OnlyDirichlet: - return smtk::mesh::moab::write_dirichlet(filePath, resource); - case Subset::OnlyNeumann: - return smtk::mesh::moab::write_neumann(filePath, resource); - default: - return false; - } -} - -bool MeshIOMoab::write(smtk::mesh::ResourcePtr resource, Subset subset) const -{ - if (resource->writeLocation().empty()) - { //require a file location - return false; - } - - return this->write(resource->writeLocation().absolutePath(), resource, subset); -} -} // namespace mesh -} // namespace io -} // namespace smtk diff --git a/smtk/io/mesh/MeshIOMoab.h b/smtk/io/mesh/MeshIOMoab.h deleted file mode 100644 index 1f3152ffb7eff2a1a68021b0c32bffd802a9f98c..0000000000000000000000000000000000000000 --- a/smtk/io/mesh/MeshIOMoab.h +++ /dev/null @@ -1,82 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_io_MeshIOMoab_h -#define smtk_io_MeshIOMoab_h - -#include "smtk/CoreExports.h" // For SMTKCORE_EXPORT macro. -#include "smtk/PublicPointerDefs.h" - -#include "smtk/io/mesh/MeshIO.h" - -#include -/**\brief Export an SMTK mesh to a file - * - */ - -namespace smtk -{ -namespace io -{ -namespace mesh -{ - -class SMTKCORE_EXPORT MeshIOMoab : public MeshIO -{ -public: - MeshIOMoab(); - - //Load an entire moab data file as a new resource with the given interface. - //Returns an invalid resource if the file can't be loaded. The third - //parameter is a label with which the domain can be parsed, but it is not - //currently implemented for the moab interface - smtk::mesh::ResourcePtr importMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - const std::string&) const override; - - //Merge a moab data file into an existing valid resource. The third - //parameter is a label with which the domain can be parsed, but it is not - //currently implemented for the moab interface - bool importMesh(const std::string& filePath, smtk::mesh::ResourcePtr resource, const std::string&) - const override; - - //Exports the resource to file. Overwrites any existing content in the file - bool exportMesh(const std::string& filePath, smtk::mesh::ResourcePtr resource) const override; - - //TODO: - // bool exportMesh( const std::string& filePath, - // smtk::mesh::ResourcePtr meshResource, - // smtk::model::ResourcePtr modelResource, - // const std::string& modelPropertyName ) const - - //Load an entire moab data file as a new resource with the given interface. - //Returns an invalid resource if the file can't be loaded - smtk::mesh::ResourcePtr read( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - Subset s) const override; - - //Merge a moab data file into an existing valid resource. - bool read(const std::string& filePath, smtk::mesh::ResourcePtr resource, Subset s) const override; - - //Writes the resource to file. Overwrites any existing content in the file - bool write(const std::string& filePath, smtk::mesh::ResourcePtr resource, Subset s) - const override; - - //Writes the resource to the file specified by the resources data member - //writeLocation(). Overwrites any existing content in the file - bool write(smtk::mesh::ResourcePtr resource, Subset s) const override; -}; -} // namespace mesh -} // namespace io -} // namespace smtk - -#endif diff --git a/smtk/io/mesh/MeshIOXMS.cxx b/smtk/io/mesh/MeshIOXMS.cxx deleted file mode 100644 index f4a8ce3691565c71ec24dd2dbd9b1729c62f2886..0000000000000000000000000000000000000000 --- a/smtk/io/mesh/MeshIOXMS.cxx +++ /dev/null @@ -1,907 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/mesh/MeshIOXMS.h" -#include "smtk/io/mesh/MeshIO.h" - -#include "smtk/io/Logger.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/DimensionTypes.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/ExtractTessellation.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Resource.h" - -#include "smtk/Regex.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#define BOOST_FILESYSTEM_VERSION 3 -#include "boost/filesystem.hpp" -#include "boost/system/error_code.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include -#include -#include -#include - -namespace smtk -{ -namespace io -{ -namespace mesh -{ - -namespace -{ - -struct OpenFile -{ - OpenFile(const std::string& path) - : m_stream(path.c_str(), std::ios::out) - { - m_path = path; - m_canWrite = m_stream.is_open(); //verify file is open - m_deleteFile = true; - } - - ~OpenFile() - { - if (m_canWrite) - { - m_stream.close(); - - if (m_deleteFile) - { - std::remove(m_path.c_str()); - } - } - } - - void fileWritten(bool written) - { - //If the file was written, we don't need to delete it - m_deleteFile = !written; - } - - std::string m_path; - std::fstream m_stream; - bool m_canWrite; - bool m_deleteFile; -}; - -struct MeshByRegion -{ - MeshByRegion(const smtk::mesh::MeshSet& ms, int regionId, smtk::mesh::DimensionType dim) - : m_meshSet(ms) - , m_dim(dim) - , m_regionId(regionId) - { - } - - int region() const { return m_regionId; } - - //return number cells of the set dimension - std::size_t numCells() const { return m_meshSet.cells(m_dim).size(); } - - //return all the cells of a given type - smtk::mesh::CellSet cells(const smtk::mesh::CellType& type) const - { - return m_meshSet.cells(type); - } - - //return all the cells, restricted to the dimension passed in during - //the constructor - smtk::mesh::CellSet cells() const { return m_meshSet.cells(m_dim); } - - smtk::mesh::MeshSet m_meshSet; - smtk::mesh::DimensionType m_dim; - int m_regionId; -}; - -template -double find_sum(const U& conn, const T& points, std::size_t index, int nVerts) -{ - double sum = 0; - for (int j = 0; j < nVerts; ++j) - { - std::size_t c1 = conn[index + j]; - std::size_t c2 = conn[index + ((j + 1) % nVerts)]; - - double x1 = points[c1 * 3]; - double y1 = points[c1 * 3 + 1]; - - double x2 = points[c2 * 3]; - double y2 = points[c2 * 3 + 1]; - - sum += (x2 - x1) * (y2 + y1); - } - return sum; -} - -std::string to_CardType(smtk::mesh::CellType type) -{ - - if (type == smtk::mesh::Line) - { - return std::string("E2L"); - } - if (type == smtk::mesh::Triangle) - { - return std::string("E3T"); - } - else if (type == smtk::mesh::Quad) - { - return std::string("E4Q"); - } - else if (type == smtk::mesh::Tetrahedron) - { - return std::string("E4T"); - } - else if (type == smtk::mesh::Pyramid) - { - return std::string("E5P"); - } - else if (type == smtk::mesh::Wedge) - { - return std::string("E6W"); - } - else if (type == smtk::mesh::Hexahedron) - { - return std::string("E8H"); - } - return std::string("B4D"); -} - -class WriteCellsPerRegion -{ - smtk::mesh::PointSet m_PointSet; - std::ostream& m_Stream; - int m_CellId{ 1 }; //2dm/3dm requires id values to start at 1 - -public: - WriteCellsPerRegion(const smtk::mesh::PointSet& ps, std::ostream& stream) - : m_PointSet(ps) - , m_Stream(stream) - { - } - - void operator()(const MeshByRegion& mbr, const smtk::mesh::CellType& type) - { - smtk::mesh::CellSet cells = mbr.cells(type); - - //If we have zero cells, don't do anything - if (cells.is_empty()) - { - return; - } - - const int regionId = mbr.region(); - const int nVerts = smtk::mesh::verticesPerCell(type); - std::string cardType = to_CardType(type); - - if (type == smtk::mesh::Triangle || type == smtk::mesh::Quad) - { - this->writeCounterClockwise(cells, cardType, regionId, nVerts); - } - else - { - this->write(cells, cardType, regionId, nVerts); - } - } - - void - write(const smtk::mesh::CellSet& cells, const std::string& cardType, int regionId, int nVerts) - { - //Use the extractTessellation helpers to convert the connectivity - //to map properly to the PointSet that represents ALL points we are - //using, not just the points these cells are using - std::int64_t connectivityLen = cells.pointConnectivity().size(); - std::vector conn(connectivityLen); - - smtk::mesh::utility::PreAllocatedTessellation connectivityInfo(conn.data()); - connectivityInfo.disableVTKStyleConnectivity(true); - smtk::mesh::utility::extractTessellation(cells, m_PointSet, connectivityInfo); - - //now we just need to write out the cells - std::size_t nCells = cells.size(); - for (std::size_t i = 0; i < nCells; ++i) - { - m_Stream << cardType << " \t " << m_CellId++ << " "; - for (int j = 0; j < nVerts; ++j) - { - //We add 1, since the points are written out starting with index 1 - m_Stream << std::setw(8) << 1 + conn[nVerts * i + j] << " "; - } - m_Stream << std::setw(8) << regionId << std::endl; - } - } - - void writeCounterClockwise( - const smtk::mesh::CellSet& cells, - const std::string& cardType, - int regionId, - int nVerts) - { - //Use the extractTessellation helpers to convert the connectivity - //to map properly to the PointSet that represents ALL points we are - //using, not just the points these cells are using - std::int64_t connectivityLen = cells.pointConnectivity().size(); - std::int64_t pointLen = m_PointSet.size() * 3; - - std::vector conn(connectivityLen); - std::vector points(pointLen); - - smtk::mesh::utility::PreAllocatedTessellation connectivityInfo(conn.data(), points.data()); - connectivityInfo.disableVTKStyleConnectivity(true); - smtk::mesh::utility::extractTessellation(cells, m_PointSet, connectivityInfo); - - //when writing out a triangle or quad region the cell must be written - //in counter clockwise orientation. We are presuming that for 2d meshes - //the triangles are all planar, so we can use the shoelace formula - //to determine if the points are in clockwise order. - // https://en.wikipedia.org/wiki/Shoelace_formula - std::size_t nCells = cells.size(); - std::size_t cIndex = 0; - for (std::size_t i = 0; i < nCells; ++i, cIndex += nVerts) - { - - //determine if the triangle/quad is counterclockwise - //a positive sum denotes a clockwise winding - double sum = find_sum(conn, points, cIndex, nVerts); - if (sum > 0) - { //we have a clockwise cell that we need to reverse - std::reverse(&conn[cIndex], &conn[cIndex + nVerts]); - } - - //now that the connectivity is the correct order we can write it out - m_Stream << cardType << " \t " << m_CellId++ << " "; - for (int j = 0; j < nVerts; ++j) - { - //We add 1, since the points are written out starting with index 1 - m_Stream << std::setw(8) << 1 + conn[cIndex + j] << " "; - } - m_Stream << std::setw(8) << regionId << std::endl; - } - } -}; - -std::vector subsetByRegion( - smtk::mesh::ResourcePtr meshResource, - smtk::mesh::DimensionType type) -{ - std::vector meshesByModelRef; - smtk::mesh::MeshSet meshes = meshResource->meshes(type); - if (meshes.is_empty()) - { //if we have no meshes, stop - return meshesByModelRef; - } - - smtk::model::EntityRefArray modelIds; - meshes.modelEntities(modelIds); - - if (modelIds.size() <= 1) - { //explicitly done so that no model relationship is equal to everything - //being in the same region - meshesByModelRef.emplace_back(meshes, 1, type); - } - else - { - meshesByModelRef.reserve(modelIds.size()); - int region = 1; - - typedef smtk::model::EntityRefArray::const_iterator it; - for (it i = modelIds.begin(); i != modelIds.end(); ++i) - { - smtk::mesh::MeshSet subset = meshResource->findAssociatedMeshes(*i, type); - if (!subset.is_empty()) - { - meshesByModelRef.emplace_back(subset, region, type); - ++region; - } - } - } - return meshesByModelRef; -} - -std::vector subsetByModelProperty( - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName, - smtk::mesh::DimensionType type) -{ - std::vector meshesByModelRef; - smtk::mesh::MeshSet meshes = meshResource->meshes(type); - if (meshes.is_empty()) - { //if we have no meshes, stop - return meshesByModelRef; - } - - smtk::model::EntityRefArray modelIds; - meshes.modelEntities(modelIds); - - typedef smtk::model::EntityRefArray::const_iterator it; - for (it i = modelIds.begin(); i != modelIds.end(); ++i) - { - const smtk::model::IntegerList& values = - resource->integerProperty(i->entity(), modelPropertyName); - smtk::mesh::MeshSet subset = meshResource->findAssociatedMeshes(*i, type); - if (values.size() == 1 && !subset.is_empty()) - { //only accept model properties that have single values - //since that is what we think region id's should be - const int& region = values[0]; - meshesByModelRef.emplace_back(subset, region, type); - } - } - - return meshesByModelRef; -} - -smtk::mesh::PointSet pointsUsed(const std::vector& meshes) -{ - //make a single mesh that represents all the cells of a given dimension - smtk::mesh::CellSet cs = meshes[0].cells(); - const std::size_t size = meshes.size(); - for (std::size_t i = 1; i < size; ++i) - { - cs.append(meshes[i].cells()); - } - return cs.points(); -} - -bool write_dm( - const std::vector& meshes, - std::ostream& stream, - smtk::mesh::DimensionType type) -{ - smtk::mesh::PointSet pointSet = pointsUsed(meshes); - - //write the header block to the stream - if (type == smtk::mesh::Dims1) - { - stream << "MESH1D" << std::endl; - } - else if (type == smtk::mesh::Dims2) - { - stream << "MESH2D" << std::endl; - } - else if (type == smtk::mesh::Dims3) - { - stream << "MESH3D" << std::endl; - } - else - { //bad dimension bail! - return false; - } - - //write out some comment lines that contain - //info on the number of cells and points - const std::size_t numMeshes = meshes.size(); - std::size_t numPoints = pointSet.numberOfPoints(); - std::size_t numCells = 0; - for (std::size_t i = 0; i < numMeshes; ++i) - { - numCells += meshes[i].numCells(); - } - - stream << "#NELEM " << numCells << std::endl; - stream << "#NNODE " << numPoints << std::endl; - - //now that we have the meshes on a per region basis we can - //start to dump them to file - //we just need to: - //Determine all the cells that will - //1. Iterate the meshes - //2. For each mesh subset by cell type - //3. iterate the cells in each subtype - //4. dump out the points - WriteCellsPerRegion writer(pointSet, stream); - for (std::size_t i = 0; i < numMeshes; ++i) - { - const MeshByRegion& mbr = meshes[i]; - //subset the cells of the requested dimension by type - if (type == 2) - { - writer(mbr, smtk::mesh::Triangle); - writer(mbr, smtk::mesh::Quad); - } - else - { //we presume 3d - writer(mbr, smtk::mesh::Tetrahedron); - writer(mbr, smtk::mesh::Pyramid); - writer(mbr, smtk::mesh::Wedge); - writer(mbr, smtk::mesh::Hexahedron); - } - } - - //now that the cells have been written - //we do step 4. For step 4 we manual extract - //the points - - std::vector xyz(numPoints * 3); - pointSet.get(xyz.data()); //fill our buffer - - for (std::size_t i = 0; i < numPoints; ++i) - { - stream << "ND \t " << std::setw(8) << 1 + i << " " << std::fixed << std::setw(12) << xyz[3 * i] - << " " << std::setw(12) << xyz[(3 * i) + 1] << " " << std::setw(12) << xyz[(3 * i) + 2] - << std::endl; - } - - return true; -} - -bool write_dm( - smtk::mesh::ResourcePtr meshResource, - std::ostream& stream, - smtk::mesh::DimensionType type) -{ - if (!meshResource) - { //can't write out an empty mesh Resource - return false; - } - - std::vector meshes = subsetByRegion(meshResource, type); - if (meshes.empty()) - { //nothing to write out - return false; - } - - return write_dm(meshes, stream, type); -} - -bool write_dm( - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName, - std::ostream& stream, - smtk::mesh::DimensionType type) -{ - if (!meshResource) - { //can't write out an empty mesh Resource - return false; - } - - std::vector meshes = - subsetByModelProperty(meshResource, resource, modelPropertyName, type); - if (meshes.empty()) - { //nothing to write out - return false; - } - - return write_dm(meshes, stream, type); -} - -std::size_t computeNumberOfPoints(std::istream& stream) -{ - std::size_t nPts = 0; - std::size_t counter = 0; - bool fromComment = false; - - smtk::regex re("\\s+"); - - std::string line; - while (std::getline(stream, line)) - { - // .*dm files often have a commented out "NNODE" field. Other readers seem - // to key off of this commented value, so we do the same (even though we - // could just count nodes instead of depending on comment strings). - - // passing -1 as the submatch index parameter performs splitting - smtk::sregex_token_iterator first{ line.begin(), line.end(), re, -1 }; - if (*first == "#NNODE") - { - fromComment = true; - nPts = std::stoul(*(++first)); - break; - } - else if (*first == "ND") - { - ++counter; - std::size_t tmp = std::stoul(*(++first)); - nPts = (nPts < tmp ? tmp : nPts); - } - } - - // reset the stream to the beginning of the file - stream.clear(); - stream.seekg(0, std::istream::beg); - - if (!fromComment && counter != nPts) - { - smtkErrorMacro(smtk::io::Logger::instance(), "Unexpected number of points."); - } - assert(fromComment || counter == nPts); - - return nPts; -} - -bool readPoints(std::istream& stream, const smtk::mesh::BufferedCellAllocatorPtr& bcAllocator) -{ - std::string line; - - std::size_t nPts = computeNumberOfPoints(stream); - - bcAllocator->reserveNumberOfCoordinates(nPts); - - smtk::regex re("\\s+"); - - std::size_t index; - double xyz[3]; - while (std::getline(stream, line)) - { - // passing -1 as the submatch index parameter performs splitting - smtk::sregex_token_iterator first{ line.begin(), line.end(), re, -1 }, last; - if (*first == "ND") - { - // ensure that the file format is at least as long as we expect - // (ND ) - if (std::distance(first, last) < 5) - { - std::cout << "ERROR: points should have at least 5 fields." << std::endl; - return false; - } - - // access the point index and shift it from 1-based to 0-based indexing - index = std::stoul(*(++first)) - 1; - - // ensure that the index falls within the precomputed range of points - assert(index < nPts); - - // access the x, y and z coordiantes - for (std::size_t i = 0; i < 3; i++) - { - xyz[i] = std::stod(*(++first)); - } - - // set the coordinates - bcAllocator->setCoordinate(index, xyz); - } - } - - // reset the stream to the beginning of the file - stream.clear(); - stream.seekg(0, std::istream::beg); - - return true; -} - -smtk::mesh::CellType to_CellType(const std::string& type) -{ - - if (type == "E2L") - { - return smtk::mesh::Line; - } - if (type == "E3T") - { - return smtk::mesh::Triangle; - } - if (type == "E4Q") - { - return smtk::mesh::Quad; - } - if (type == "E4T") - { - return smtk::mesh::Tetrahedron; - } - if (type == "E5P") - { - return smtk::mesh::Pyramid; - } - if (type == "E6W") - { - return smtk::mesh::Wedge; - } - if (type == "E8H") - { - return smtk::mesh::Hexahedron; - } - return smtk::mesh::CellType_MAX; -} - -// Given a mesh Resource with multiple meshes for each domain, condense the -// meshsets so there is only one meshset per domain. -void condenseMeshsetsByDomain(smtk::mesh::ResourcePtr& meshResource) -{ - auto domains = meshResource->domains(); - for (auto& domain : domains) - { - auto meshForDomain = meshResource->domainMeshes(domain); - auto cellsForDomain = meshForDomain.cells(); - - // construct a mesh set from these cells - auto singleMeshForDomain = meshResource->createMesh(cellsForDomain); - - // set the domain on the mesh set - meshResource->setDomainOnMeshes(singleMeshForDomain, domain); - - for (std::size_t i = 0; i < meshForDomain.size(); i++) - { - meshResource->removeMeshes(meshForDomain.subset(i)); - } - } -} - -bool readCells( - std::istream& stream, - const smtk::mesh::BufferedCellAllocatorPtr& bcAllocator, - smtk::mesh::ResourcePtr& meshResource) -{ - smtk::regex re("\\s+"); - - std::string line; - std::vector connectivity; - smtk::mesh::HandleRange cellsWithMaterials = bcAllocator->cells(); - int currentMaterialId = -1; - int materialId; - - while (std::getline(stream, line)) - { - // passing -1 as the submatch index parameter performs splitting - smtk::sregex_token_iterator first{ line.begin(), line.end(), re, -1 }, last; - if (std::string(*first)[0] == 'E') - { - smtk::mesh::CellType type = to_CellType(*first); - if (type == smtk::mesh::CellType_MAX) - { - // Have we reached an "END" string? - if (*first == "END") - { - break; - } - std::cout << "ERROR: Unsupported cell type \"" << *first << "\"." << std::endl; - return false; - } - - std::size_t nVerticesPerCell = smtk::mesh::verticesPerCell(type); - - // ensure that the file format is at least as long as we expect - // (E#X ... ) - typedef std::iterator_traits::difference_type diff_type; - if (std::distance(first, last) < static_cast(nVerticesPerCell + 3)) - { - std::cout << "ERROR: cell type \"" << *first << "\" should have at least " - << nVerticesPerCell + 3 << " fields." << std::endl; - return false; - } - - connectivity.resize(nVerticesPerCell); - - // skip the cell index. - ++first; - - // access the x, y and z coordiantes - for (std::size_t i = 0; i < nVerticesPerCell; i++) - { - // access the point index and shift it from 1-based to 0-based indexing - connectivity[i] = std::stol(*(++first)) - 1; - } - - // access the cell's material id - materialId = std::stoi(*(++first)); - - // if it differs from the current material being parsed... - if (materialId != currentMaterialId) - { - // ...and this is not the first material encountered... - if (currentMaterialId != -1) - { - // ...flush the allocator - bcAllocator->flush(); - - // construct a cell set containing only the cells of this material type - smtk::mesh::CellSet cellsForMaterial( - meshResource, (bcAllocator->cells() - cellsWithMaterials)); - - // construct a mesh set from these cells - smtk::mesh::MeshSet meshForMaterial = meshResource->createMesh(cellsForMaterial); - - // set the domain on the mesh set - meshResource->setDomainOnMeshes(meshForMaterial, smtk::mesh::Domain(currentMaterialId)); - } - - // update the material id - currentMaterialId = materialId; - - // update the set of currently processed cells - cellsWithMaterials = bcAllocator->cells(); - } - - // add the cell - bcAllocator->addCell(type, connectivity.data()); - } - } - - // flush the allocator - bcAllocator->flush(); - - if (bcAllocator->cells().empty()) - { - std::cout << "ERROR: no cells." << std::endl; - return false; - } - - { - // for the last material, construct a cell set containing only the cells of - // this material type - smtk::mesh::CellSet cellsForMaterial(meshResource, (bcAllocator->cells() - cellsWithMaterials)); - - // construct a mesh set from these cells - smtk::mesh::MeshSet meshForMaterial = meshResource->createMesh(cellsForMaterial); - - // set the domain on the mesh set - meshResource->setDomainOnMeshes(meshForMaterial, smtk::mesh::Domain(currentMaterialId)); - } - - // When cells are not contiguous by domain in the file, multiple meshsets are - // created for each domain. Condense the meshsets so that there is one meshset - // per domain. - condenseMeshsetsByDomain(meshResource); - - return true; -} - -bool read_dm(std::istream& stream, smtk::mesh::ResourcePtr& meshResource) -{ - bool success = false; - - if (!meshResource) - { - return success; - } - - smtk::mesh::BufferedCellAllocatorPtr bcAllocator = - meshResource->interface()->bufferedCellAllocator(); - - success = readPoints(stream, bcAllocator); - if (!success) - { - return success; - } - - success = readCells(stream, bcAllocator, meshResource); - - return success; -} -} // namespace -MeshIOXMS::MeshIOXMS() -{ - this->Formats.emplace_back( - "xms 2d", std::vector({ ".2dm" }), Format::Import | Format::Export); - this->Formats.emplace_back( - "xms 3d", std::vector({ ".3dm" }), Format::Import | Format::Export); -} - -smtk::mesh::ResourcePtr MeshIOXMS::importMesh( - const std::string& filePath, - const smtk::mesh::InterfacePtr& interface, - const std::string& str) const -{ - smtk::mesh::ResourcePtr meshResource = smtk::mesh::Resource::create(interface); - if (MeshIOXMS::importMesh(filePath, meshResource, str)) - { - return meshResource; - } - - return smtk::mesh::ResourcePtr(); -} - -bool MeshIOXMS::importMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - const std::string& /*unused*/) const -{ - ::boost::filesystem::path path(filePath); - if (!::boost::filesystem::is_regular_file(path)) - { - return false; - } - std::ifstream ifs(filePath.c_str(), std::ifstream::in); - bool success = read_dm(ifs, meshResource); - meshResource->interface()->setModifiedState(false); - return success; -} - -bool MeshIOXMS::exportMesh( - std::ostream& stream, - smtk::mesh::ResourcePtr meshResource, - smtk::mesh::DimensionType dim) const -{ - return write_dm(meshResource, stream, dim); -} - -bool MeshIOXMS::exportMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - smtk::mesh::DimensionType dim) const -{ - bool result = false; - OpenFile of(filePath); - if (of.m_canWrite) - { - result = this->exportMesh(of.m_stream, meshResource, dim); - of.fileWritten(result); - } - return result; -} - -bool MeshIOXMS::exportMesh(const std::string& filePath, smtk::mesh::ResourcePtr meshResource) const -{ - // Grab the file extension - boost::filesystem::path fpath(filePath); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - if (ext == ".2dm") - { - return this->exportMesh(filePath, meshResource, smtk::mesh::Dims2); - } - else - { - return this->exportMesh(filePath, meshResource, smtk::mesh::Dims3); - } -} - -bool MeshIOXMS::exportMesh( - std::ostream& stream, - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName, - smtk::mesh::DimensionType dim) const -{ - return write_dm(meshResource, resource, modelPropertyName, stream, dim); -} - -bool MeshIOXMS::exportMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName, - smtk::mesh::DimensionType dim) const -{ - bool result = false; - OpenFile of(filePath); - if (of.m_canWrite) - { - result = this->exportMesh(of.m_stream, meshResource, resource, modelPropertyName, dim); - of.fileWritten(result); - } - return result; -} - -bool MeshIOXMS::exportMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName) const -{ - // Grab the file extension - boost::filesystem::path fpath(filePath); - std::string ext = fpath.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - if (ext == ".2dm") - { - return this->exportMesh(filePath, meshResource, resource, modelPropertyName, smtk::mesh::Dims2); - } - else - { - return this->exportMesh(filePath, meshResource, resource, modelPropertyName, smtk::mesh::Dims3); - } -} -} // namespace mesh -} // namespace io -} // namespace smtk diff --git a/smtk/io/mesh/MeshIOXMS.h b/smtk/io/mesh/MeshIOXMS.h deleted file mode 100644 index 4ef6c4e9bd42e96cc3b8627103f90586103ac6b9..0000000000000000000000000000000000000000 --- a/smtk/io/mesh/MeshIOXMS.h +++ /dev/null @@ -1,87 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_io_MeshIOXMS_h -#define smtk_io_MeshIOXMS_h - -#include "smtk/CoreExports.h" // For SMTKCORE_EXPORT macro. -#include "smtk/PublicPointerDefs.h" - -#include "smtk/io/mesh/MeshIO.h" - -#include "smtk/mesh/core/DimensionTypes.h" - -#include -#include -/**\brief Export a SMTK mesh to a file in the XMS format. - * - * - */ - -namespace smtk -{ -namespace io -{ -namespace mesh -{ - -class SMTKCORE_EXPORT MeshIOXMS : public MeshIO -{ -public: - MeshIOXMS(); - - smtk::mesh::ResourcePtr importMesh( - const std::string&, - const smtk::mesh::InterfacePtr&, - const std::string&) const override; - - bool importMesh(const std::string&, smtk::mesh::ResourcePtr, const std::string&) const override; - - //Returns True if and only if a file has been written to disk. - //Occurrences that can cause write to fail: - // Mesh resource is empty - // Mesh resource has no Triangles or Quads - bool exportMesh( - std::ostream& stream, - smtk::mesh::ResourcePtr meshResource, - smtk::mesh::DimensionType dim) const; - - bool exportMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - smtk::mesh::DimensionType dim) const; - - bool exportMesh(const std::string& filePath, smtk::mesh::ResourcePtr meshResource) const override; - - bool exportMesh( - std::ostream& stream, - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName, - smtk::mesh::DimensionType dim) const; - - bool exportMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName, - smtk::mesh::DimensionType dim) const; - - bool exportMesh( - const std::string& filePath, - smtk::mesh::ResourcePtr meshResource, - smtk::model::ResourcePtr resource, - const std::string& modelPropertyName) const override; -}; -} // namespace mesh -} // namespace io -} // namespace smtk - -#endif diff --git a/smtk/io/pybind11/PybindExportMesh.h b/smtk/io/pybind11/PybindExportMesh.h deleted file mode 100644 index 99734d0a1f4293f8abfcd6d548a3b5cb6f5e3f29..0000000000000000000000000000000000000000 --- a/smtk/io/pybind11/PybindExportMesh.h +++ /dev/null @@ -1,42 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_io_ExportMesh_h -#define pybind_smtk_io_ExportMesh_h - -#include - -#include "smtk/io/ExportMesh.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::io::ExportMesh > pybind11_init_smtk_io_ExportMesh(py::module &m) -{ - PySharedPtrClass< smtk::io::ExportMesh > instance(m, "ExportMesh"); - instance - .def(py::init<>()) - .def("__call__", (bool (smtk::io::ExportMesh::*)(::std::string const &, ::smtk::mesh::ResourcePtr) const) &smtk::io::ExportMesh::operator()) - .def("__call__", (bool (smtk::io::ExportMesh::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::model::ResourcePtr, ::std::string const &) const) &smtk::io::ExportMesh::operator()) - // .def_static("SupportedIOTypes", &smtk::io::ExportMesh::SupportedIOTypes) - ; - return instance; -} - -inline void pybind11_init__ZN4smtk2io10exportMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("exportMesh", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr)) &smtk::io::exportMesh, "", py::arg("filePath"), py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io10exportMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEENSA_INS_5model7ResourceEEES9_(py::module &m) -{ - m.def("exportMesh", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::model::ResourcePtr, ::std::string const &)) &smtk::io::exportMesh, "", py::arg("filePath"), py::arg("resource"), py::arg("resource"), py::arg("modelPropertyName")); -} - -#endif diff --git a/smtk/io/pybind11/PybindFormat.h b/smtk/io/pybind11/PybindFormat.h deleted file mode 100644 index 2110e865e2871bdc26b0c4bb3d750c4ecd0c7ecb..0000000000000000000000000000000000000000 --- a/smtk/io/pybind11/PybindFormat.h +++ /dev/null @@ -1,41 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_io_mesh_Format_h -#define pybind_smtk_io_mesh_Format_h - -#include - -#include "smtk/io/mesh/Format.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::io::mesh::Format > pybind11_init_smtk_io_mesh_Format(py::module &m) -{ - PySharedPtrClass< smtk::io::mesh::Format > instance(m, "Format"); - instance - .def(py::init<>()) - .def(py::init<::std::string const &, ::smtk::io::mesh::Format::IOFlags>()) - .def(py::init<::std::string const &, ::std::vector, std::allocator > > const &, ::smtk::io::mesh::Format::IOFlags>()) - .def(py::init<::std::string const &, ::std::string const &, ::smtk::io::mesh::Format::IOFlags>()) - .def(py::init<::smtk::io::mesh::Format const &>()) - .def("deepcopy", (smtk::io::mesh::Format & (smtk::io::mesh::Format::*)(::smtk::io::mesh::Format const &)) &smtk::io::mesh::Format::operator=) - .def("CanImport", &smtk::io::mesh::Format::CanImport) - .def("CanExport", &smtk::io::mesh::Format::CanExport) - .def("CanRead", &smtk::io::mesh::Format::CanRead) - .def("CanWrite", &smtk::io::mesh::Format::CanWrite) - .def_readwrite("Name", &smtk::io::mesh::Format::Name) - .def_readwrite("Extensions", &smtk::io::mesh::Format::Extensions) - .def_readwrite("Flags", &smtk::io::mesh::Format::Flags) - ; - return instance; -} - -#endif diff --git a/smtk/io/pybind11/PybindIO.cxx b/smtk/io/pybind11/PybindIO.cxx index b6cb687614dd1708d1094d8848935a905e21f235..e38de5860c0a00210231e4895661c1036b02f812 100644 --- a/smtk/io/pybind11/PybindIO.cxx +++ b/smtk/io/pybind11/PybindIO.cxx @@ -22,70 +22,20 @@ template using PySharedPtrClass = py::class_, Args...>; #include "smtk/common/pybind11/PybindUUIDTypeCaster.h" -#include "PybindFormat.h" -#include "PybindMeshIO.h" -#include "PybindMeshIOMoab.h" -#include "PybindMeshIOXMS.h" #include "PybindAttributeReader.h" #include "PybindAttributeWriter.h" -#include "PybindExportMesh.h" -#include "PybindImportMesh.h" #include "PybindLogger.h" -#include "PybindModelToMesh.h" -#include "PybindReadMesh.h" -#include "PybindWriteMesh.h" - -#include "smtk/mesh/core/Resource.h" PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); PYBIND11_MODULE(_smtkPybindIO, io) { io.doc() = ""; - py::module mesh = io.def_submodule("mesh", ""); // The order of these function calls is important! It was determined by // comparing the dependencies of each of the wrapped objects. - PySharedPtrClass< smtk::io::mesh::Format > smtk_io_mesh_Format = pybind11_init_smtk_io_mesh_Format(mesh); - PySharedPtrClass< smtk::io::mesh::MeshIO > smtk_io_mesh_MeshIO = pybind11_init_smtk_io_mesh_MeshIO(mesh); - pybind11_init_smtk_io_mesh_Subset(mesh); - PySharedPtrClass< smtk::io::mesh::MeshIOMoab > smtk_io_mesh_MeshIOMoab = pybind11_init_smtk_io_mesh_MeshIOMoab(mesh, smtk_io_mesh_MeshIO); - PySharedPtrClass< smtk::io::mesh::MeshIOXMS > smtk_io_mesh_MeshIOXMS = pybind11_init_smtk_io_mesh_MeshIOXMS(mesh, smtk_io_mesh_MeshIO); - PySharedPtrClass< smtk::io::AttributeReader > smtk_io_AttributeReader = pybind11_init_smtk_io_AttributeReader(io); PySharedPtrClass< smtk::io::AttributeWriter > smtk_io_AttributeWriter = pybind11_init_smtk_io_AttributeWriter(io); - PySharedPtrClass< smtk::io::ExportMesh > smtk_io_ExportMesh = pybind11_init_smtk_io_ExportMesh(io); - PySharedPtrClass< smtk::io::ImportMesh > smtk_io_ImportMesh = pybind11_init_smtk_io_ImportMesh(io); PySharedPtrClass< smtk::io::Logger > smtk_io_Logger = pybind11_init_smtk_io_Logger(io); - PySharedPtrClass< smtk::io::ModelToMesh > smtk_io_ModelToMesh = pybind11_init_smtk_io_ModelToMesh(io); - PySharedPtrClass< smtk::io::ReadMesh > smtk_io_ReadMesh = pybind11_init_smtk_io_ReadMesh(io); - PySharedPtrClass< smtk::io::WriteMesh > smtk_io_WriteMesh = pybind11_init_smtk_io_WriteMesh(io); - - pybind11_init__ZN4smtk2io10exportMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io10exportMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEENSA_INS_5model7ResourceEEES9_(io); - pybind11_init__ZN4smtk2io10importMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEE(io); - pybind11_init__ZN4smtk2io10importMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEES9_(io); - pybind11_init__ZN4smtk2io10importMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io10importMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEES9_(io); - pybind11_init__ZN4smtk2io13readDirichletERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEE(io); - pybind11_init__ZN4smtk2io13readDirichletERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io10readDomainERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEE(io); - pybind11_init__ZN4smtk2io10readDomainERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io20readEntireResourceERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEE(io); - pybind11_init__ZN4smtk2io20readEntireResourceERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io8readMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEENS0_4mesh6SubsetE(io); - pybind11_init__ZN4smtk2io8readMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEENS0_4mesh6SubsetE(io); - pybind11_init__ZN4smtk2io11readNeumannERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEE(io); - pybind11_init__ZN4smtk2io11readNeumannERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io14writeDirichletERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io14writeDirichletENSt3__110shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io11writeDomainERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io11writeDomainENSt3__110shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io21writeEntireResourceERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io21writeEntireResourceENSt3__110shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io9writeMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEENS0_4mesh6SubsetE(io); - pybind11_init__ZN4smtk2io9writeMeshENSt3__110shared_ptrINS_4mesh10ResourceEEENS0_4mesh6SubsetE(io); - pybind11_init__ZN4smtk2io12writeNeumannERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(io); - pybind11_init__ZN4smtk2io12writeNeumannENSt3__110shared_ptrINS_4mesh10ResourceEEE(io); } diff --git a/smtk/io/pybind11/PybindImportMesh.h b/smtk/io/pybind11/PybindImportMesh.h deleted file mode 100644 index 39ab9f2ffd1016f408c73e28d612466f2c024c2b..0000000000000000000000000000000000000000 --- a/smtk/io/pybind11/PybindImportMesh.h +++ /dev/null @@ -1,53 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_io_ImportMesh_h -#define pybind_smtk_io_ImportMesh_h - -#include -#include - -#include "smtk/io/ImportMesh.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::io::ImportMesh > pybind11_init_smtk_io_ImportMesh(py::module &m) -{ - PySharedPtrClass< smtk::io::ImportMesh > instance(m, "ImportMesh"); - instance - .def(py::init<>()) - .def_static("ExtensionIsSupported", &smtk::io::ImportMesh::ExtensionIsSupported) - .def("__call__", (smtk::mesh::ResourcePtr (smtk::io::ImportMesh::*)(::std::string const &, const ::smtk::mesh::InterfacePtr&, ::std::string) const) &smtk::io::ImportMesh::operator()) - .def("__call__", (bool (smtk::io::ImportMesh::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::std::string) const) &smtk::io::ImportMesh::operator()) - ; - return instance; -} - -inline void pybind11_init__ZN4smtk2io10importMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEE(py::module &m) -{ - m.def("importMesh", (smtk::mesh::ResourcePtr (*)(::std::string const &, const ::smtk::mesh::InterfacePtr&)) &smtk::io::importMesh, "", py::arg("filePath"), py::arg("interface")); -} - -inline void pybind11_init__ZN4smtk2io10importMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEES9_(py::module &m) -{ - m.def("importMesh", (smtk::mesh::ResourcePtr (*)(::std::string const &, const ::smtk::mesh::InterfacePtr&, ::std::string const &)) &smtk::io::importMesh, "", py::arg("filePath"), py::arg("interface"), py::arg("domainPropertyName")); -} - -inline void pybind11_init__ZN4smtk2io10importMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("importMesh", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr)) &smtk::io::importMesh, "", py::arg("filePath"), py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io10importMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEES9_(py::module &m) -{ - m.def("importMesh", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::std::string const &)) &smtk::io::importMesh, "", py::arg("filePath"), py::arg("resource"), py::arg("domainPropertyName")); -} - -#endif diff --git a/smtk/io/pybind11/PybindMeshIO.h b/smtk/io/pybind11/PybindMeshIO.h deleted file mode 100644 index 03cbd0f8e516f7667fac7a2e085af1c0616a2727..0000000000000000000000000000000000000000 --- a/smtk/io/pybind11/PybindMeshIO.h +++ /dev/null @@ -1,50 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_io_mesh_MeshIO_h -#define pybind_smtk_io_mesh_MeshIO_h - -#include - -#include "smtk/io/mesh/MeshIO.h" - -namespace py = pybind11; - -inline void pybind11_init_smtk_io_mesh_Subset(py::module &m) -{ - py::enum_(m, "Subset") - .value("EntireResource", smtk::io::mesh::Subset::EntireResource) - .value("OnlyDomain", smtk::io::mesh::Subset::OnlyDomain) - .value("OnlyDirichlet", smtk::io::mesh::Subset::OnlyDirichlet) - .value("OnlyNeumann", smtk::io::mesh::Subset::OnlyNeumann) - .export_values(); -} - -inline PySharedPtrClass< smtk::io::mesh::MeshIO > pybind11_init_smtk_io_mesh_MeshIO(py::module &m) -{ - PySharedPtrClass< smtk::io::mesh::MeshIO > instance(m, "MeshIO"); - instance - .def(py::init<>()) - .def(py::init<::smtk::io::mesh::MeshIO const &>()) - .def("deepcopy", (smtk::io::mesh::MeshIO & (smtk::io::mesh::MeshIO::*)(::smtk::io::mesh::MeshIO const &)) &smtk::io::mesh::MeshIO::operator=) - .def("importMesh", (smtk::mesh::ResourcePtr (smtk::io::mesh::MeshIO::*)(::std::string const &, const ::smtk::mesh::InterfacePtr &, ::std::string const &) const) &smtk::io::mesh::MeshIO::importMesh, py::arg("arg0"), py::arg("arg1"), py::arg("arg2")) - .def("importMesh", (bool (smtk::io::mesh::MeshIO::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::std::string const &) const) &smtk::io::mesh::MeshIO::importMesh, py::arg("arg0"), py::arg("arg1"), py::arg("arg2")) - .def("exportMesh", (bool (smtk::io::mesh::MeshIO::*)(::std::string const &, ::smtk::mesh::ResourcePtr) const) &smtk::io::mesh::MeshIO::exportMesh, py::arg("arg0"), py::arg("arg1")) - .def("exportMesh", (bool (smtk::io::mesh::MeshIO::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::model::ResourcePtr, ::std::string const &) const) &smtk::io::mesh::MeshIO::exportMesh, py::arg("arg0"), py::arg("arg1"), py::arg("arg2"), py::arg("arg3")) - .def("read", (smtk::mesh::ResourcePtr (smtk::io::mesh::MeshIO::*)(::std::string const &, const ::smtk::mesh::InterfacePtr &, ::smtk::io::mesh::Subset) const) &smtk::io::mesh::MeshIO::read, py::arg("arg0"), py::arg("arg1"), py::arg("arg2")) - .def("read", (bool (smtk::io::mesh::MeshIO::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset) const) &smtk::io::mesh::MeshIO::read, py::arg("arg0"), py::arg("arg1"), py::arg("arg2")) - .def("write", (bool (smtk::io::mesh::MeshIO::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset) const) &smtk::io::mesh::MeshIO::write, py::arg("arg0"), py::arg("arg1"), py::arg("arg2")) - .def("write", (bool (smtk::io::mesh::MeshIO::*)(::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset) const) &smtk::io::mesh::MeshIO::write, py::arg("arg0"), py::arg("arg1")) - .def("FileFormats", &smtk::io::mesh::MeshIO::FileFormats) - ; - return instance; -} - -#endif diff --git a/smtk/io/pybind11/PybindMeshIOMoab.h b/smtk/io/pybind11/PybindMeshIOMoab.h deleted file mode 100644 index 5a6397b755c63af45b4c51af7b27a506d62a8734..0000000000000000000000000000000000000000 --- a/smtk/io/pybind11/PybindMeshIOMoab.h +++ /dev/null @@ -1,38 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_io_mesh_MeshIOMoab_h -#define pybind_smtk_io_mesh_MeshIOMoab_h - -#include - -#include "smtk/io/mesh/MeshIOMoab.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::io::mesh::MeshIOMoab > pybind11_init_smtk_io_mesh_MeshIOMoab(py::module &m, PySharedPtrClass< smtk::io::mesh::MeshIO >& parent) -{ - PySharedPtrClass< smtk::io::mesh::MeshIOMoab > instance(m, "MeshIOMoab", parent); - instance - .def(py::init<>()) - .def(py::init<::smtk::io::mesh::MeshIOMoab const &>()) - .def("deepcopy", (smtk::io::mesh::MeshIOMoab & (smtk::io::mesh::MeshIOMoab::*)(::smtk::io::mesh::MeshIOMoab const &)) &smtk::io::mesh::MeshIOMoab::operator=) - .def("importMesh", (smtk::mesh::ResourcePtr (smtk::io::mesh::MeshIOMoab::*)(::std::string const &, const ::smtk::mesh::InterfacePtr &, ::std::string const &) const) &smtk::io::mesh::MeshIOMoab::importMesh, py::arg("filePath"), py::arg("interface"), py::arg("arg2")) - .def("importMesh", (bool (smtk::io::mesh::MeshIOMoab::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::std::string const &) const) &smtk::io::mesh::MeshIOMoab::importMesh, py::arg("filePath"), py::arg("resource"), py::arg("arg2")) - .def("exportMesh", &smtk::io::mesh::MeshIOMoab::exportMesh, py::arg("filePath"), py::arg("resource")) - .def("read", (smtk::mesh::ResourcePtr (smtk::io::mesh::MeshIOMoab::*)(::std::string const &, const ::smtk::mesh::InterfacePtr &, ::smtk::io::mesh::Subset) const) &smtk::io::mesh::MeshIOMoab::read, py::arg("filePath"), py::arg("interface"), py::arg("s")) - .def("read", (bool (smtk::io::mesh::MeshIOMoab::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset) const) &smtk::io::mesh::MeshIOMoab::read, py::arg("filePath"), py::arg("resource"), py::arg("s")) - .def("write", (bool (smtk::io::mesh::MeshIOMoab::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset) const) &smtk::io::mesh::MeshIOMoab::write, py::arg("filePath"), py::arg("resource"), py::arg("s")) - .def("write", (bool (smtk::io::mesh::MeshIOMoab::*)(::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset) const) &smtk::io::mesh::MeshIOMoab::write, py::arg("resource"), py::arg("s")) - ; - return instance; -} - -#endif diff --git a/smtk/io/pybind11/PybindMeshIOXMS.h b/smtk/io/pybind11/PybindMeshIOXMS.h deleted file mode 100644 index 8a6f89994798ff18c9982951606045f9c95a3efe..0000000000000000000000000000000000000000 --- a/smtk/io/pybind11/PybindMeshIOXMS.h +++ /dev/null @@ -1,37 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_io_mesh_MeshIOXMS_h -#define pybind_smtk_io_mesh_MeshIOXMS_h - -#include - -#include "smtk/io/mesh/MeshIOXMS.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::io::mesh::MeshIOXMS > pybind11_init_smtk_io_mesh_MeshIOXMS(py::module &m, PySharedPtrClass< smtk::io::mesh::MeshIO >& parent) -{ - PySharedPtrClass< smtk::io::mesh::MeshIOXMS > instance(m, "MeshIOXMS", parent); - instance - .def(py::init<>()) - .def(py::init<::smtk::io::mesh::MeshIOXMS const &>()) - .def("deepcopy", (smtk::io::mesh::MeshIOXMS & (smtk::io::mesh::MeshIOXMS::*)(::smtk::io::mesh::MeshIOXMS const &)) &smtk::io::mesh::MeshIOXMS::operator=) - .def("exportMesh", (bool (smtk::io::mesh::MeshIOXMS::*)(::std::ostream &, ::smtk::mesh::ResourcePtr, ::smtk::mesh::DimensionType) const) &smtk::io::mesh::MeshIOXMS::exportMesh, py::arg("stream"), py::arg("meshResource"), py::arg("dim")) - .def("exportMesh", (bool (smtk::io::mesh::MeshIOXMS::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::mesh::DimensionType) const) &smtk::io::mesh::MeshIOXMS::exportMesh, py::arg("filePath"), py::arg("meshResource"), py::arg("dim")) - .def("exportMesh", (bool (smtk::io::mesh::MeshIOXMS::*)(::std::string const &, ::smtk::mesh::ResourcePtr) const) &smtk::io::mesh::MeshIOXMS::exportMesh, py::arg("filePath"), py::arg("meshResource")) - .def("exportMesh", (bool (smtk::io::mesh::MeshIOXMS::*)(::std::ostream &, ::smtk::mesh::ResourcePtr, ::smtk::model::ResourcePtr, ::std::string const &, ::smtk::mesh::DimensionType) const) &smtk::io::mesh::MeshIOXMS::exportMesh, py::arg("stream"), py::arg("meshResource"), py::arg("resource"), py::arg("modelPropertyName"), py::arg("dim")) - .def("exportMesh", (bool (smtk::io::mesh::MeshIOXMS::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::model::ResourcePtr, ::std::string const &, ::smtk::mesh::DimensionType) const) &smtk::io::mesh::MeshIOXMS::exportMesh, py::arg("filePath"), py::arg("meshResource"), py::arg("resource"), py::arg("modelPropertyName"), py::arg("dim")) - .def("exportMesh", (bool (smtk::io::mesh::MeshIOXMS::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::model::ResourcePtr, ::std::string const &) const) &smtk::io::mesh::MeshIOXMS::exportMesh, py::arg("filePath"), py::arg("meshResource"), py::arg("resource"), py::arg("modelPropertyName")) - ; - return instance; -} - -#endif diff --git a/smtk/io/pybind11/PybindModelToMesh.h b/smtk/io/pybind11/PybindModelToMesh.h deleted file mode 100644 index 07426dd1e7970223339e060cf732a4f5382260aa..0000000000000000000000000000000000000000 --- a/smtk/io/pybind11/PybindModelToMesh.h +++ /dev/null @@ -1,37 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_io_ModelToMesh_h -#define pybind_smtk_io_ModelToMesh_h - -#include - -#include "smtk/io/ModelToMesh.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::io::ModelToMesh > pybind11_init_smtk_io_ModelToMesh(py::module &m) -{ - PySharedPtrClass< smtk::io::ModelToMesh > instance(m, "ModelToMesh"); - instance - .def(py::init<>()) - .def(py::init<::smtk::io::ModelToMesh const &>()) - .def("__call__", (smtk::mesh::ResourcePtr (smtk::io::ModelToMesh::*)(::smtk::model::ResourcePtr const &) const) &smtk::io::ModelToMesh::operator()) - .def("__call__", (smtk::mesh::ResourcePtr (smtk::io::ModelToMesh::*)(::smtk::model::Model const &) const) &smtk::io::ModelToMesh::operator()) - .def("deepcopy", (smtk::io::ModelToMesh & (smtk::io::ModelToMesh::*)(::smtk::io::ModelToMesh const &)) &smtk::io::ModelToMesh::operator=) - .def("isMergingEnabled", &smtk::io::ModelToMesh::isMergingEnabled) - .def("setIsMerging", &smtk::io::ModelToMesh::setIsMerging, py::arg("m")) - .def("getMergeTolerance", &smtk::io::ModelToMesh::getMergeTolerance) - .def("setMergeTolerance", &smtk::io::ModelToMesh::setMergeTolerance, py::arg("tol")) - ; - return instance; -} - -#endif diff --git a/smtk/io/pybind11/PybindReadMesh.h b/smtk/io/pybind11/PybindReadMesh.h deleted file mode 100644 index 1b7d3c5fee5a725dedac99afc09ce23e3b9d8740..0000000000000000000000000000000000000000 --- a/smtk/io/pybind11/PybindReadMesh.h +++ /dev/null @@ -1,83 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_io_ReadMesh_h -#define pybind_smtk_io_ReadMesh_h - -#include -#include - -#include "smtk/io/ReadMesh.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::io::ReadMesh > pybind11_init_smtk_io_ReadMesh(py::module &m) -{ - PySharedPtrClass< smtk::io::ReadMesh > instance(m, "ReadMesh"); - instance - .def(py::init<>()) - .def_static("ExtensionIsSupported", &smtk::io::ReadMesh::ExtensionIsSupported) - .def("__call__", (smtk::mesh::ResourcePtr (smtk::io::ReadMesh::*)(::std::string const &, const ::smtk::mesh::InterfacePtr&, ::smtk::io::mesh::Subset) const) &smtk::io::ReadMesh::operator()) - .def("__call__", (bool (smtk::io::ReadMesh::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset) const) &smtk::io::ReadMesh::operator()) - ; - return instance; -} - -inline void pybind11_init__ZN4smtk2io13readDirichletERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEE(py::module &m) -{ - m.def("readDirichlet", (smtk::mesh::ResourcePtr (*)(::std::string const &, const ::smtk::mesh::InterfacePtr&)) &smtk::io::readDirichlet, "", py::arg("filePath"), py::arg("interface")); -} - -inline void pybind11_init__ZN4smtk2io13readDirichletERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("readDirichlet", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr)) &smtk::io::readDirichlet, "", py::arg("filePath"), py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io10readDomainERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEE(py::module &m) -{ - m.def("readDomain", (smtk::mesh::ResourcePtr (*)(::std::string const &, const ::smtk::mesh::InterfacePtr&)) &smtk::io::readDomain, "", py::arg("filePath"), py::arg("interface")); -} - -inline void pybind11_init__ZN4smtk2io10readDomainERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("readDomain", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr)) &smtk::io::readDomain, "", py::arg("filePath"), py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io20readEntireResourceERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEE(py::module &m) -{ - m.def("readEntireResource", (smtk::mesh::ResourcePtr (*)(::std::string const &, const ::smtk::mesh::InterfacePtr&)) &smtk::io::readEntireResource, "", py::arg("filePath"), py::arg("interface")); -} - -inline void pybind11_init__ZN4smtk2io20readEntireResourceERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("readEntireResource", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr)) &smtk::io::readEntireResource, "", py::arg("filePath"), py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io8readMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEENS0_4mesh6SubsetE(py::module &m) -{ - m.def("readMesh", (smtk::mesh::ResourcePtr (*)(::std::string const &, const ::smtk::mesh::InterfacePtr&, ::smtk::io::mesh::Subset)) &smtk::io::readMesh, "", py::arg("filePath"), py::arg("interface"), py::arg("subset") = ::smtk::io::mesh::Subset::EntireResource); -} - -inline void pybind11_init__ZN4smtk2io8readMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEENS0_4mesh6SubsetE(py::module &m) -{ - m.def("readMesh", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset)) &smtk::io::readMesh, "", py::arg("filePath"), py::arg("resource"), py::arg("subset") = ::smtk::io::mesh::Subset::EntireResource); -} - -inline void pybind11_init__ZN4smtk2io11readNeumannERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh7InterfaceEEE(py::module &m) -{ - m.def("readNeumann", (smtk::mesh::ResourcePtr (*)(::std::string const &, const ::smtk::mesh::InterfacePtr&)) &smtk::io::readNeumann, "", py::arg("filePath"), py::arg("interface")); -} - -inline void pybind11_init__ZN4smtk2io11readNeumannERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("readNeumann", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr)) &smtk::io::readNeumann, "", py::arg("filePath"), py::arg("resource")); -} - -#endif diff --git a/smtk/io/pybind11/PybindWriteMesh.h b/smtk/io/pybind11/PybindWriteMesh.h deleted file mode 100644 index 7cc97da8a6650d43aaceb9a49dca0b9ec0754447..0000000000000000000000000000000000000000 --- a/smtk/io/pybind11/PybindWriteMesh.h +++ /dev/null @@ -1,81 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_io_WriteMesh_h -#define pybind_smtk_io_WriteMesh_h - -#include - -#include "smtk/io/WriteMesh.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::io::WriteMesh > pybind11_init_smtk_io_WriteMesh(py::module &m) -{ - PySharedPtrClass< smtk::io::WriteMesh > instance(m, "WriteMesh"); - instance - .def(py::init<>()) - .def("__call__", (bool (smtk::io::WriteMesh::*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset) const) &smtk::io::WriteMesh::operator()) - .def("__call__", (bool (smtk::io::WriteMesh::*)(::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset) const) &smtk::io::WriteMesh::operator()) - ; - return instance; -} - -inline void pybind11_init__ZN4smtk2io14writeDirichletERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("writeDirichlet", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr)) &smtk::io::writeDirichlet, "", py::arg("filePath"), py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io14writeDirichletENSt3__110shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("writeDirichlet", (bool (*)(::smtk::mesh::ResourcePtr)) &smtk::io::writeDirichlet, "", py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io11writeDomainERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("writeDomain", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr)) &smtk::io::writeDomain, "", py::arg("filePath"), py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io11writeDomainENSt3__110shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("writeDomain", (bool (*)(::smtk::mesh::ResourcePtr)) &smtk::io::writeDomain, "", py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io21writeEntireResourceERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("writeEntireResource", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr)) &smtk::io::writeEntireResource, "", py::arg("filePath"), py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io21writeEntireResourceENSt3__110shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("writeEntireResource", (bool (*)(::smtk::mesh::ResourcePtr)) &smtk::io::writeEntireResource, "", py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io9writeMeshERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEENS0_4mesh6SubsetE(py::module &m) -{ - m.def("writeMesh", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset)) &smtk::io::writeMesh, "", py::arg("filePath"), py::arg("resource"), py::arg("subset") = ::smtk::io::mesh::Subset::EntireResource); -} - -inline void pybind11_init__ZN4smtk2io9writeMeshENSt3__110shared_ptrINS_4mesh10ResourceEEENS0_4mesh6SubsetE(py::module &m) -{ - m.def("writeMesh", (bool (*)(::smtk::mesh::ResourcePtr, ::smtk::io::mesh::Subset)) &smtk::io::writeMesh, "", py::arg("resource"), py::arg("subset") = ::smtk::io::mesh::Subset::EntireResource); -} - -inline void pybind11_init__ZN4smtk2io12writeNeumannERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_10shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("writeNeumann", (bool (*)(::std::string const &, ::smtk::mesh::ResourcePtr)) &smtk::io::writeNeumann, "", py::arg("filePath"), py::arg("resource")); -} - -inline void pybind11_init__ZN4smtk2io12writeNeumannENSt3__110shared_ptrINS_4mesh10ResourceEEE(py::module &m) -{ - m.def("writeNeumann", (bool (*)(::smtk::mesh::ResourcePtr)) &smtk::io::writeNeumann, "", py::arg("resource")); -} - -#endif diff --git a/smtk/mesh/CMakeLists.txt b/smtk/mesh/CMakeLists.txt deleted file mode 100644 index 64c6d3423f1fc5c4482297a82fb10e94f78bb133..0000000000000000000000000000000000000000 --- a/smtk/mesh/CMakeLists.txt +++ /dev/null @@ -1,159 +0,0 @@ -# set up sources to build -set(meshSrcs - core/CellSet.cxx - core/CellField.cxx - core/CellTypes.cxx - core/Resource.cxx - core/Component.cxx - core/ForEachTypes.cxx - core/Handle.cxx - core/MeshSet.cxx - core/PointConnectivity.cxx - core/PointField.cxx - core/PointLocator.cxx - core/PointSet.cxx - core/QueryTypes.cxx - core/TypeSet.cxx - - interpolation/InverseDistanceWeighting.cxx - interpolation/PointCloudFromCSV.cxx - interpolation/PointCloudGenerator.cxx - interpolation/RadialAverage.cxx - interpolation/StructuredGridGenerator.cxx - - json/Interface.cxx - json/MeshInfo.cxx - json/jsonHandleRange.cxx - json/jsonMeshInfo.cxx - json/jsonResource.cxx - - moab/Allocator.cxx - moab/BufferedCellAllocator.cxx - moab/CellTypeToType.cxx - moab/ClosestPoint.cxx - moab/DistanceTo.cxx - moab/HandleRangeToRange.cxx - moab/IncrementalAllocator.cxx - moab/Interface.cxx - moab/ConnectivityStorage.cxx - moab/MergeMeshVertices.cxx - moab/ModelEntityPointLocator.cxx - moab/PointLocatorCache.cxx - moab/PointLocatorImpl.cxx - moab/RandomPoint.cxx - moab/Readers.cxx - moab/Writers.cxx - - resource/Registrar.cxx - resource/Selection.cxx - - utility/ApplyToMesh.cxx - utility/Create.cxx - utility/ExtractCanonicalIndices.cxx - utility/ExtractMeshConstants.cxx - utility/ExtractTessellation.cxx - utility/Metrics.cxx - utility/Reclassify.cxx - ) - -set(meshHeaders - core/CellSet.h - core/CellField.h - core/CellTraits.h - core/CellTypes.h - core/Resource.h - core/Component.h - core/DimensionTypes.h - core/FieldTypes.h - core/ForEachTypes.h - core/Handle.h - core/Interface.h - core/MeshSet.h - core/PointConnectivity.h - core/PointField.h - core/PointSet.h - core/QueryTypes.h - core/TypeSet.h - - core/queries/BoundingBox.h - - interpolation/InverseDistanceWeighting.h - interpolation/PointCloud.h - interpolation/PointCloudFromCSV.h - interpolation/PointCloudGenerator.h - interpolation/RadialAverage.h - interpolation/StructuredGrid.h - interpolation/StructuredGridGenerator.h - - #Limit the amount of headers for each backend we install. These should be - #implementation details users of smtk don't get access to ( outside the interface ) - json/Interface.h - json/MeshInfo.h - json/jsonHandleRange.h - json/jsonMeshInfo.h - json/jsonResource.h - - moab/HandleRangeToRange.h - moab/Interface.h - moab/ModelEntityPointLocator.h - - resource/Registrar.h - resource/Selection.h - - utility/ApplyToMesh.h - utility/Create.h - utility/ExtractCanonicalIndices.h - utility/ExtractMeshConstants.h - utility/ExtractTessellation.h - utility/Metrics.h - utility/Reclassify.h - ) -set(meshOperators - DeleteMesh - ElevateMesh - Export - ExtractAdjacency - ExtractByDihedralAngle - ExtractSkin - GenerateHotStartData - Import - InterpolateOntoMesh - MergeCoincidentPoints - PrintMeshInformation - Read - ReadResource - SelectCells - SetMeshName - Subtract - Transform - UndoElevateMesh - Write - WriteResource - ) - -# construct operator inputs -foreach (operator ${meshOperators}) - smtk_encode_file("${CMAKE_CURRENT_SOURCE_DIR}/operators/${operator}.sbt" - HEADER_OUTPUT headerName) - list(APPEND meshSrcs operators/${operator}.cxx) - list(APPEND meshHeaders operators/${operator}.h) - list(APPEND _meshDependencies ${headerName}) -endforeach() -add_custom_target(meshGenHeaders DEPENDS ${_meshDependencies}) -set(meshDependencies ${_meshDependencies} PARENT_SCOPE) - -#install the headers -smtk_public_headers(smtkCore ${meshHeaders}) - -if (SMTK_ENABLE_PARAVIEW_SUPPORT) - set_property(GLOBAL APPEND - PROPERTY _smtk_plugin_files "${CMAKE_CURRENT_SOURCE_DIR}/plugin/paraview.plugin") -endif() - -if (SMTK_ENABLE_PYTHON_WRAPPING) - add_subdirectory(pybind11) -endif() - -if(SMTK_ENABLE_TESTING) - add_subdirectory(testing) -endif() diff --git a/smtk/mesh/core/CellField.cxx b/smtk/mesh/core/CellField.cxx deleted file mode 100644 index 84cefccb448ecd08eb194fa42f1afd2fa0265f18..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/CellField.cxx +++ /dev/null @@ -1,163 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/core/Interface.h" - -#include - -namespace smtk -{ -namespace mesh -{ - -CellField::CellField() = default; - -CellField::CellField(const smtk::mesh::MeshSet& meshset, const std::string& name) - : m_name(name) - , m_meshset(meshset) -{ -} - -CellField::CellField(const smtk::mesh::CellField& other) = default; - -CellField::~CellField() = default; - -CellField& CellField::operator=(const CellField& other) = default; - -bool CellField::operator==(const CellField& other) const -{ - return m_name == other.m_name && m_meshset == other.m_meshset; -} - -bool CellField::operator!=(const CellField& other) const -{ - return !(*this == other); -} - -bool CellField::operator<(const CellField& other) const -{ - if (m_name == other.m_name) - { - return m_meshset < other.m_meshset; - } - return m_name < other.m_name; -} - -bool CellField::isValid() const -{ - if (m_name.empty() || m_meshset.resource() == nullptr) - { - return false; - } - - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return false; - } - - smtk::mesh::CellFieldTag dsTag(m_name); - return iface->hasCellField(m_meshset.range(), dsTag); -} - -std::size_t CellField::size() const -{ - return (this->isValid() ? m_meshset.cells().size() : 0); -} - -std::size_t CellField::dimension() const -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return 0; - } - - smtk::mesh::CellFieldTag dsTag(m_name); - return (iface->hasCellField(m_meshset.range(), dsTag) ? iface->getCellFieldDimension(dsTag) : 0); -} - -smtk::mesh::FieldType CellField::type() const -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return smtk::mesh::FieldType::MaxFieldType; - } - - smtk::mesh::CellFieldTag dsTag(m_name); - return ( - iface->hasCellField(m_meshset.range(), dsTag) ? iface->getCellFieldType(dsTag) - : smtk::mesh::FieldType::MaxFieldType); -} - -smtk::mesh::CellSet CellField::cells() const -{ - return m_meshset.cells(); -} - -bool CellField::get(const smtk::mesh::HandleRange& cellIds, void* values) const -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return false; - } - - if (!smtk::mesh::rangeContains(m_meshset.cells().range(), cellIds)) - { - return false; - } - - return iface->getField(cellIds, smtk::mesh::CellFieldTag(m_name), values); -} - -bool CellField::set(const smtk::mesh::HandleRange& cellIds, const void* const values) -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return false; - } - - if (!smtk::mesh::rangeContains(m_meshset.cells().range(), cellIds)) - { - return false; - } - - return iface->setField(cellIds, smtk::mesh::CellFieldTag(m_name), values); -} - -bool CellField::get(void* values) const -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return false; - } - - return iface->getCellField(m_meshset.range(), smtk::mesh::CellFieldTag(m_name), values); -} - -bool CellField::set(const void* const values) -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return false; - } - - return iface->setCellField(m_meshset.range(), smtk::mesh::CellFieldTag(m_name), values); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/CellField.h b/smtk/mesh/core/CellField.h deleted file mode 100644 index 84b9ec09b081e0aac8bff6cfc987f7735134accc..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/CellField.h +++ /dev/null @@ -1,158 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_CellField_h -#define smtk_mesh_core_CellField_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/FieldTypes.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/MeshSet.h" - -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ - -//Represents cell-centered floating-point data associated with a meshset. We -//represent the CellField with a unique name and a reference to the meshset. -class SMTKCORE_EXPORT CellField -{ -public: - //Default constructor generates an invalid CellField - CellField(); - - //Construct a CellField for meshset and unique name - CellField(const smtk::mesh::MeshSet& mesh, const std::string& name); - - //Copy Constructor required for rule of 3 - CellField(const CellField& other); - - //required to be in the cpp file as we hold a HandleRange - ~CellField(); - - //Copy assignment operator required for rule of 3 - CellField& operator=(const CellField& other); - - //Comparison operators so we can construct sets of CellFields - bool operator==(const CellField& other) const; - bool operator!=(const CellField& other) const; - bool operator<(const CellField& other) const; - - //Return the unique name associated with the dataset - std::string name() const { return m_name; } - - //Check if the dataset is represented in the mesh database - bool isValid() const; - - //Return the number of data tuples. - std::size_t size() const; - - //Return the number of components in each data tuple - std::size_t dimension() const; - - //Return the field type - smtk::mesh::FieldType type() const; - - //Return the meshset associated with the dataset - const smtk::mesh::MeshSet& meshset() const { return m_meshset; } - - //Return the cells associated with the dataset - smtk::mesh::CellSet cells() const; - - //Get the data associated with all of the cells in the meshset and return - //a success flag. must be at least - //sizeof(type()) * cellIds.size() * dimension() in size. - bool get(const smtk::mesh::HandleRange& cellIds, void* values) const; - - //Set the data associated with all of the cells in the meshset and return - //a success flag. must be at least - //sizeof(type()) * cellIds.size() * dimension() in size. - bool set(const smtk::mesh::HandleRange& cellIds, const void* values); - - //Get the data associated with all of the cells in the meshset and return - //a success flag. must be at least - //sizeof(type()) * cellIds.size() * dimension() in size. - bool get(void* values) const; - - //Set the data associated with all of the cells in the meshset and return - //a success flag. must be at least - //sizeof(type()) * cellIds.size() * dimension() in size. - bool set(const void* values); - - //Convenience method for accessing field data. - template - std::vector get() const - { - if (type() != FieldTypeFor::type) - { - return std::vector(); - } - std::vector values(size() * dimension()); - if (!get(values.data())) - { - return std::vector(); - } - return values; - } - - //Convenience method for accessing field data. - template - std::vector get(const smtk::mesh::HandleRange& cellIds) const - { - if (type() != FieldTypeFor::type) - { - return std::vector(); - } - std::vector values(cellIds.size() * dimension()); - if (!get(cellIds, values.data())) - { - return std::vector(); - } - return values; - } - - //Convenience method for setting field data. - template - bool set(const std::vector& values) - { - if (type() != FieldTypeFor::type) - { - return false; - } - return set(values.data()); - } - - //Convenience method for setting field data. - template - bool set(const smtk::mesh::HandleRange& cellIds, const std::vector& values) - { - if (type() != FieldTypeFor::type) - { - return false; - } - return set(cellIds, values.data()); - } - -private: - std::string m_name; - smtk::mesh::MeshSet m_meshset; -}; - -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/CellSet.cxx b/smtk/mesh/core/CellSet.cxx deleted file mode 100644 index 342e092657b0f337d3d089bbe913943f82caf063..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/CellSet.cxx +++ /dev/null @@ -1,218 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/core/Interface.h" - -namespace smtk -{ -namespace mesh -{ - -CellSet::CellSet(const smtk::mesh::ResourcePtr& parent, const smtk::mesh::HandleRange& range) - : m_parent(parent) - , m_range(range) -{ -} - -CellSet::CellSet(const smtk::mesh::ConstResourcePtr& parent, const smtk::mesh::HandleRange& range) - : m_parent(std::const_pointer_cast(parent)) - , m_range(range) -{ -} - -CellSet::CellSet( - const smtk::mesh::ResourcePtr& parent, - const std::vector& cellIds) - : m_parent(parent) -{ - for (const auto& cellId : cellIds) - { - m_range.insert(cellId); - } -} - -CellSet::CellSet(const smtk::mesh::ResourcePtr& parent, const std::set& cellIds) - : m_parent(parent) -{ - for (const auto& cellId : cellIds) - { - m_range.insert(cellId); - } -} - -CellSet::CellSet(const smtk::mesh::CellSet& other) = default; - -CellSet::~CellSet() = default; - -CellSet& CellSet::operator=(const CellSet& other) -{ - m_parent = other.m_parent; - m_range = other.m_range; - return *this; -} - -bool CellSet::operator==(const CellSet& other) const -{ - return m_parent == other.m_parent && - //empty is a fast way to check for easy mismatching ranges - m_range.empty() == other.m_range.empty() && m_range == other.m_range; -} - -bool CellSet::operator!=(const CellSet& other) const -{ - return !(*this == other); -} - -bool CellSet::append(const CellSet& other) -{ - const bool can_append = m_parent == other.m_parent; - if (can_append) - { - m_range += other.m_range; - } - return can_append; -} - -bool CellSet::is_empty() const -{ - return m_range.empty(); -} - -std::size_t CellSet::size() const -{ - return m_range.size(); -} - -smtk::mesh::TypeSet CellSet::types() const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->computeTypes(m_range); -} - -smtk::mesh::PointSet CellSet::points(bool boundary_only) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange range = iface->getPoints(m_range, boundary_only); - return smtk::mesh::PointSet(m_parent, range); -} - -smtk::mesh::PointSet CellSet::points(std::size_t position) const -{ - smtk::mesh::HandleRange singleIndex; - singleIndex.insert(smtk::mesh::rangeElement(m_range, position)); - - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange range = iface->getPoints(singleIndex); - return smtk::mesh::PointSet(m_parent, range); -} - -smtk::mesh::PointConnectivity CellSet::pointConnectivity() const -{ - return smtk::mesh::PointConnectivity(m_parent, m_range); -} - -smtk::mesh::PointConnectivity CellSet::pointConnectivity(std::size_t position) const -{ - smtk::mesh::HandleRange singleIndex; - singleIndex.insert(smtk::mesh::rangeElement(m_range, position)); - return smtk::mesh::PointConnectivity(m_parent, singleIndex); -} - -/**\brief Get the parent resource that this meshset belongs to. - * - */ -const smtk::mesh::ResourcePtr& CellSet::resource() const -{ - return m_parent; -} - -//intersect two mesh sets, placing the results in the return mesh set -CellSet set_intersect(const CellSet& a, const CellSet& b) -{ - if (a.m_parent != b.m_parent) - { //return an empty CellSet if the resources don't match - return smtk::mesh::CellSet(a.m_parent, smtk::mesh::HandleRange()); - } - - smtk::mesh::HandleRange result = a.m_range & b.m_range; - return smtk::mesh::CellSet(a.m_parent, result); -} - -//subtract mesh b from a, placing the results in the return mesh set -CellSet set_difference(const CellSet& a, const CellSet& b) -{ - if (a.m_parent != b.m_parent) - { //return an empty CellSet if the resources don't match - return smtk::mesh::CellSet(a.m_parent, smtk::mesh::HandleRange()); - } - - smtk::mesh::HandleRange result = a.m_range - b.m_range; - return smtk::mesh::CellSet(a.m_parent, result); -} - -//union two mesh sets, placing the results in the return mesh set -CellSet set_union(const CellSet& a, const CellSet& b) -{ - if (a.m_parent != b.m_parent) - { //return an empty CellSet if the resources don't match - return smtk::mesh::CellSet(a.m_parent, smtk::mesh::HandleRange()); - } - - smtk::mesh::HandleRange result = a.m_range | b.m_range; - return smtk::mesh::CellSet(a.m_parent, result); -} - -//intersect two cell sets at the point id level, all cells from b which -//share points with cells in a are placed in the resulting CellSet. -CellSet point_intersect(const CellSet& a, const CellSet& b, ContainmentType t) -{ - if (a.m_parent != b.m_parent) - { //return an empty CellSet if the resources don't match - return smtk::mesh::CellSet(a.m_parent, smtk::mesh::HandleRange()); - } - - const smtk::mesh::InterfacePtr& iface = a.m_parent->interface(); - smtk::mesh::PointConnectivity pc(b.m_parent, b.m_range); - - smtk::mesh::HandleRange result = iface->pointIntersect(a.m_range, b.m_range, pc, t); - - return smtk::mesh::CellSet(a.m_parent, result); -} - -//subtract two cell sets at the point id level, all cells from b whose -//points are not used by cells from a are placed in the resulting CellSet. -CellSet point_difference(const CellSet& a, const CellSet& b, ContainmentType t) -{ - if (a.m_parent != b.m_parent) - { //return an empty CellSet if the resources don't match - return smtk::mesh::CellSet(a.m_parent, smtk::mesh::HandleRange()); - } - - const smtk::mesh::InterfacePtr& iface = a.m_parent->interface(); - smtk::mesh::PointConnectivity pc(b.m_parent, b.m_range); - - smtk::mesh::HandleRange result = iface->pointDifference(a.m_range, b.m_range, pc, t); - - return smtk::mesh::CellSet(a.m_parent, result); -} - -SMTKCORE_EXPORT void for_each(const CellSet& a, CellForEach& filter) -{ - smtk::mesh::PointConnectivity pc(a.m_parent, a.m_range); - const smtk::mesh::InterfacePtr& iface = a.m_parent->interface(); - - filter.resource(a.m_parent); - iface->cellForEach(a.m_range, pc, filter); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/CellSet.h b/smtk/mesh/core/CellSet.h deleted file mode 100644 index f26fe60d1a565496fe4d8ed27126904a1e3c6b3f..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/CellSet.h +++ /dev/null @@ -1,153 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_CellSet_h -#define smtk_mesh_core_CellSet_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/DimensionTypes.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/PointConnectivity.h" -#include "smtk/mesh/core/PointSet.h" -#include "smtk/mesh/core/QueryTypes.h" -#include "smtk/mesh/core/TypeSet.h" - -#include - -namespace smtk -{ -namespace mesh -{ - -//Represents a collection of cells that have been constructed by a Resource -//We represent the collection of cells by range of cell id entities. CellSets -//are a fairly lightweight representation, that are meant to be subdivided -//intersected, etc to generate the subset of cells the caller is interested in. -//To get the actual Cell / Geometric information you need to use the -//points() calls on a CellSet -//Note CellSets aren't stored in the actual database, they are just local -//views of the data. If you need to save a CellSet you will need to create -//a new MeshSet using Resource::createMesh. -class SMTKCORE_EXPORT CellSet -{ - friend SMTKCORE_EXPORT CellSet set_intersect(const CellSet& a, const CellSet& b); - friend SMTKCORE_EXPORT CellSet set_difference(const CellSet& a, const CellSet& b); - friend SMTKCORE_EXPORT CellSet set_union(const CellSet& a, const CellSet& b); - friend SMTKCORE_EXPORT CellSet - point_intersect(const CellSet& a, const CellSet& b, ContainmentType t); - friend SMTKCORE_EXPORT CellSet - point_difference(const CellSet& a, const CellSet& b, ContainmentType t); - friend SMTKCORE_EXPORT void for_each(const CellSet& a, CellForEach& filter); - friend class Resource; //required for creation of new meshes -public: - //construct a CellSet that represents an arbitrary unknown subset of cells that - //are children of the handle. - CellSet(const smtk::mesh::ResourcePtr& parent, const smtk::mesh::HandleRange& range); - CellSet(const smtk::mesh::ConstResourcePtr& parent, const smtk::mesh::HandleRange& range); - - //construct a CellSet that represents an arbitrary unknown subset of cells that - //are children of the handle via an explicit vector of cell ids. While this - //method is inefficient, it is useful for the python bindings where - //is converted to a list. - CellSet(const smtk::mesh::ResourcePtr& parent, const std::vector& cellIds); - - //construct a CellSet that represents an arbitrary unknown subset of cells that - //are children of the handle via an explicit set of cell ids. This constructor - //is preferred over the variant that takes a std::vector. - CellSet(const smtk::mesh::ResourcePtr& parent, const std::set& cellIds); - - //Copy Constructor required for rule of 3 - CellSet(const CellSet& other); - - //required to be in the cpp file as we hold a HandleRange - ~CellSet(); - - //Copy assignment operator required for rule of 3 - CellSet& operator=(const CellSet& other); - bool operator==(const CellSet& other) const; - bool operator!=(const CellSet& other) const; - - //append another CellSet to this CellSet, if the resource - //pointers don't match the append will return false - bool append(const CellSet& other); - - bool is_empty() const; - std::size_t size() const; - - smtk::mesh::TypeSet types() const; - //all points of the cellset; if boundary_only is true then higher-order points - //are omitted. - smtk::mesh::PointSet points(bool boundary_only = false) const; - smtk::mesh::PointConnectivity pointConnectivity() const; //all connectivity info for all cells - - //get the points for a single cell - smtk::mesh::PointSet points(std::size_t) const; - //get the connectivity for a single cell - smtk::mesh::PointConnectivity pointConnectivity(std::size_t) const; - - //get the underlying HandleRange that this CellSet represents - const smtk::mesh::HandleRange& range() const { return m_range; } - - //get the underlying resource that this CellSet belongs to - const smtk::mesh::ResourcePtr& resource() const; - -private: - smtk::mesh::ResourcePtr m_parent; - smtk::mesh::HandleRange m_range; //range of cell ids -}; - -//Function that provide set operations on CellSets - -//intersect two cell sets, placing the results in the return cell set. -//This does cell Id level intersection, if you want to intersect -//based on shared points you want to use point_intersect -//Note: If the cellsets come from different resources the result will -//always be empty -SMTKCORE_EXPORT CellSet set_intersect(const CellSet& a, const CellSet& b); - -//subtract cell b from a, placing the results in the return cell set. -//This does cell Id level difference, if you want to subtract -//based on shared points you want to use point_difference -//Note: If the cellsets come from different resources the result will -//always be empty -SMTKCORE_EXPORT CellSet set_difference(const CellSet& a, const CellSet& b); - -//union two cell sets, placing the results in the return cell set -//Note: If the cellsets come from different resources the result will -//always be empty -SMTKCORE_EXPORT CellSet set_union(const CellSet& a, const CellSet& b); - -//intersect two cell sets at the point id level, all cells from b which -//share points with cells in a are placed in the resulting CellSet. -//Currently the two options are Partial Contained and Fully Contained, -//with the former meaning at least 1 point per cell needs to be -//in set 1 to be contained in the result, while the latter requires all points -//per cell. -//Note: If the cellsets come from different resources the result will -//always be empty -SMTKCORE_EXPORT CellSet point_intersect(const CellSet& a, const CellSet& b, ContainmentType t); - -//subtract two cell sets at the point id level, all cells from b whose -//points are not used by cells from a are placed in the resulting CellSet. -//Currently the two options are Partial Contained and Fully Contained, -//with the former meaning at least 1 point per cell causes it to be removed, -//while the latter requires all points per cell. -//Note: If the cellsets come from different resources the result will -//always be empty -SMTKCORE_EXPORT CellSet point_difference(const CellSet& a, const CellSet& b, ContainmentType t); - -//apply a for_each cell operator on all cells of a given set. -SMTKCORE_EXPORT void for_each(const CellSet& a, CellForEach& filter); -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/CellTraits.h b/smtk/mesh/core/CellTraits.h deleted file mode 100644 index 06810cdc9f5668d27531713ede0091eac6c66c86..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/CellTraits.h +++ /dev/null @@ -1,295 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_CellTraits_h -#define smtk_mesh_core_CellTraits_h - -#include "smtk/mesh/core/CellTypes.h" - -namespace smtk -{ -namespace mesh -{ - -template -struct CellTopologicalDimensionsTag -{ -}; - -//these need to be comparable. so we use an integer type -struct CellFixedPointNumberTag -{ - const static int Type = 1; -}; //e.g line,triangle,hex -struct CellVariablePointNumberTag -{ - const static int Type = 2; -}; //e.g. polygon - -/// The templated CellTraits struct provides the basic high level information -/// about cells such as: -/// -/// TopologicalDimensionsTag: Defines the topological dimensions of the -// cell type. 3 for polyhedra, 2 for polygons, 1 for lines, 0 for points. -// -// PointNumberTag: Defines if the number of points for this cell type -// is fixed at compile time or runtime -// -// Use bool fixedPointSize() const to return if the cell of this type -// has a fixed number of points at runtime -// -// Use int dimension() const to return the dimensionality of this cell type -// at runtime -// -template -struct CellTraits; - -template<> -struct CellTraits -{ - const static int NUM_VERTICES = 8; - const static int TOPOLOGICAL_DIMENSIONS = 3; - - typedef smtk::mesh::CellHexahedron CellType; - typedef smtk::mesh::CellFixedPointNumberTag PointNumberTag; - typedef smtk::mesh::CellTopologicalDimensionsTag<3> TopologicalDimensionsTag; - - //return if this cell type has a compile time fixed number of cells - bool fixedPointSize() const { return true; } - - //return the dimensionality of this cell type - int dimension() const { return TOPOLOGICAL_DIMENSIONS; } -}; - -template<> -struct CellTraits -{ - const static int NUM_VERTICES = 2; - const static int TOPOLOGICAL_DIMENSIONS = 1; - - typedef smtk::mesh::CellLine CellType; - typedef smtk::mesh::CellFixedPointNumberTag PointNumberTag; - typedef smtk::mesh::CellTopologicalDimensionsTag<1> TopologicalDimensionsTag; - - //return if this cell type has a compile time fixed number of cells - bool fixedPointSize() const { return true; } - - //return the dimensionality of this cell type - int dimension() const { return TOPOLOGICAL_DIMENSIONS; } -}; - -template<> -struct CellTraits -{ - const static int NUM_VERTICES = -1; - const static int TOPOLOGICAL_DIMENSIONS = 2; - - typedef smtk::mesh::CellPolygon CellType; - typedef smtk::mesh::CellVariablePointNumberTag PointNumberTag; - typedef smtk::mesh::CellTopologicalDimensionsTag<2> TopologicalDimensionsTag; - - //return if this cell type has a compile time fixed number of cells - bool fixedPointSize() const { return false; } - - //return the dimensionality of this cell type - int dimension() const { return TOPOLOGICAL_DIMENSIONS; } -}; - -template<> -struct CellTraits -{ - const static int NUM_VERTICES = 5; - const static int TOPOLOGICAL_DIMENSIONS = 3; - - typedef smtk::mesh::CellPyramid CellType; - typedef smtk::mesh::CellFixedPointNumberTag PointNumberTag; - typedef smtk::mesh::CellTopologicalDimensionsTag<4> TopologicalDimensionsTag; - - //return if this cell type has a compile time fixed number of cells - bool fixedPointSize() const { return true; } - - //return the dimensionality of this cell type - int dimension() const { return TOPOLOGICAL_DIMENSIONS; } -}; - -template<> -struct CellTraits -{ - const static int NUM_VERTICES = 4; - const static int TOPOLOGICAL_DIMENSIONS = 2; - - typedef smtk::mesh::CellQuad CellType; - typedef smtk::mesh::CellFixedPointNumberTag PointNumberTag; - typedef smtk::mesh::CellTopologicalDimensionsTag<2> TopologicalDimensionsTag; - - //return if this cell type has a compile time fixed number of cells - bool fixedPointSize() const { return true; } - - //return the dimensionality of this cell type - int dimension() const { return TOPOLOGICAL_DIMENSIONS; } -}; - -template<> -struct CellTraits -{ - const static int NUM_VERTICES = 4; - const static int TOPOLOGICAL_DIMENSIONS = 3; - - typedef smtk::mesh::CellTetrahedron CellType; - typedef smtk::mesh::CellFixedPointNumberTag PointNumberTag; - typedef smtk::mesh::CellTopologicalDimensionsTag<3> TopologicalDimensionsTag; - - //return if this cell type has a compile time fixed number of cells - bool fixedPointSize() const { return true; } - - //return the dimensionality of this cell type - int dimension() const { return TOPOLOGICAL_DIMENSIONS; } -}; - -template<> -struct CellTraits -{ - const static int NUM_VERTICES = 3; - const static int TOPOLOGICAL_DIMENSIONS = 2; - - typedef smtk::mesh::CellTriangle CellType; - typedef smtk::mesh::CellFixedPointNumberTag PointNumberTag; - typedef smtk::mesh::CellTopologicalDimensionsTag<2> TopologicalDimensionsTag; - - //return if this cell type has a compile time fixed number of cells - bool fixedPointSize() const { return true; } - - //return the dimensionality of this cell type - int dimension() const { return TOPOLOGICAL_DIMENSIONS; } -}; - -template<> -struct CellTraits -{ - const static int NUM_VERTICES = 1; - const static int TOPOLOGICAL_DIMENSIONS = 0; - - typedef smtk::mesh::CellVertex CellType; - typedef smtk::mesh::CellFixedPointNumberTag PointNumberTag; - typedef smtk::mesh::CellTopologicalDimensionsTag<0> TopologicalDimensionsTag; - - //return if this cell type has a compile time fixed number of cells - bool fixedPointSize() const { return true; } - - //return the dimensionality of this cell type - int dimension() const { return TOPOLOGICAL_DIMENSIONS; } -}; - -template<> -struct CellTraits -{ - const static int NUM_VERTICES = 6; - const static int TOPOLOGICAL_DIMENSIONS = 3; - - typedef smtk::mesh::CellWedge CellType; - typedef smtk::mesh::CellFixedPointNumberTag PointNumberTag; - typedef smtk::mesh::CellTopologicalDimensionsTag<3> TopologicalDimensionsTag; - - //return if this cell type has a compile time fixed number of cells - bool fixedPointSize() const { return true; } - - //return the dimensionality of this cell type - int dimension() const { return TOPOLOGICAL_DIMENSIONS; } -}; - -template -struct CellEnumToType; - -template<> -struct CellEnumToType -{ - typedef smtk::mesh::CellHexahedron CellType; - typedef CellTraits Traits; -}; - -template<> -struct CellEnumToType -{ - typedef smtk::mesh::CellLine CellType; - typedef CellTraits Traits; -}; - -template<> -struct CellEnumToType -{ - typedef smtk::mesh::CellPolygon CellType; - typedef CellTraits Traits; -}; - -template<> -struct CellEnumToType -{ - typedef smtk::mesh::CellPyramid CellType; - typedef CellTraits Traits; -}; - -template<> -struct CellEnumToType -{ - typedef smtk::mesh::CellQuad CellType; - typedef CellTraits Traits; -}; - -template<> -struct CellEnumToType -{ - typedef smtk::mesh::CellTetrahedron CellType; - typedef CellTraits Traits; -}; - -template<> -struct CellEnumToType -{ - typedef smtk::mesh::CellTriangle CellType; - typedef CellTraits Traits; -}; - -template<> -struct CellEnumToType -{ - typedef smtk::mesh::CellVertex CellType; - typedef CellTraits Traits; -}; - -template<> -struct CellEnumToType -{ - typedef smtk::mesh::CellWedge CellType; - typedef CellTraits Traits; -}; - -#define smtkMeshCellEnumToTypeMacroCase(cellEnum, call) \ - case cellEnum: \ - { \ - static const int CellEnumValue = cellEnum; \ - typedef smtk::mesh::CellEnumToType::Traits CellTraits; \ - call; \ - } \ - break; - -#define smtkMeshCellEnumToTypeMacro(call) \ - smtkMeshCellEnumToTypeMacroCase(smtk::mesh::Vertex, call); \ - smtkMeshCellEnumToTypeMacroCase(smtk::mesh::Line, call); \ - smtkMeshCellEnumToTypeMacroCase(smtk::mesh::Triangle, call); \ - smtkMeshCellEnumToTypeMacroCase(smtk::mesh::Quad, call); \ - smtkMeshCellEnumToTypeMacroCase(smtk::mesh::Polygon, call); \ - smtkMeshCellEnumToTypeMacroCase(smtk::mesh::Tetrahedron, call); \ - smtkMeshCellEnumToTypeMacroCase(smtk::mesh::Pyramid, call); \ - smtkMeshCellEnumToTypeMacroCase(smtk::mesh::Wedge, call); \ - smtkMeshCellEnumToTypeMacroCase(smtk::mesh::Hexahedron, call); -} // namespace mesh -} // namespace smtk - -#endif //__smtk_mesh_CellTraits_h diff --git a/smtk/mesh/core/CellTypes.cxx b/smtk/mesh/core/CellTypes.cxx deleted file mode 100644 index e180026d85917fd88ae5999f4993a0f748a694d6..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/CellTypes.cxx +++ /dev/null @@ -1,48 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/core/CellTypes.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Return the number of vertices that define a cell of this type (or -1). - * - */ -int verticesPerCell(CellType ctype) -{ - static int verticesByType[CellType_MAX] = { 1, 2, 3, 4, -1, 4, 5, 6, 8 }; - return ctype >= 0 && ctype <= CellType_MAX ? verticesByType[ctype] : -1; -} - -/**\brief Return the name of the mesh cell type. - * - * If the \a flag value is non-zero, return the plural form of the name. - */ -std::string cellTypeSummary(CellType ctype, int flag) -{ - static const char* cellTypeNamesSingular[CellType_MAX + 1] = { - "vertex", "line", "triangle", "quad", "polygon", - "tetrahedron", "pyramid", "wedge", "hexahedron", - "invalid" // CellType_MAX - }; - static const char* cellTypeNamesPlural[CellType_MAX + 1] = { - "vertices", "lines", "triangles", "quads", "polygons", - "tetrahedra", "pyramids", "wedges", "hexahedra", - "invalid" // CellType_MAX - }; - return ctype >= 0 && ctype <= CellType_MAX - ? (flag ? cellTypeNamesPlural[ctype] : cellTypeNamesSingular[ctype]) - : cellTypeNamesSingular[CellType_MAX]; -} - -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/CellTypes.h b/smtk/mesh/core/CellTypes.h deleted file mode 100644 index 3519324c45dfaa4a88e5d948c6ecd2338f9d3c07..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/CellTypes.h +++ /dev/null @@ -1,92 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_CellTypes_h -#define smtk_mesh_core_CellTypes_h - -#include "smtk/CoreExports.h" - -#include -#include - -namespace smtk -{ -namespace mesh -{ - -/**\brief Enum types used for querying the interface. - * - * When changing this enum, be sure to update verticesPerCell() - * and cellTypeName()! - */ -enum CellType -{ - Vertex = 0, - Line = 1, - Triangle = 2, - Quad = 3, - Polygon = 4, - Tetrahedron = 5, - Pyramid = 6, - Wedge = 7, - Hexahedron = 8, - CellType_MAX = 9 -}; - -SMTKCORE_EXPORT int verticesPerCell(CellType ctype); -SMTKCORE_EXPORT std::string cellTypeSummary(CellType ctype, int flag = 0); - -//Need a basic blitter for cell queries, mainly used by -//TypeSet -typedef std::bitset CellTypes; - -//concrete types that you can cast the enum to by using CellTraits.h -//useful when you need to template code based on the cell type -struct CellVertex -{ - static const CellType CellEnum = Vertex; -}; -struct CellLine -{ - static const CellType CellEnum = Line; -}; -struct CellTriangle -{ - static const CellType CellEnum = Triangle; -}; -struct CellQuad -{ - static const CellType CellEnum = Quad; -}; -struct CellPolygon -{ - static const CellType CellEnum = Polygon; -}; -struct CellTetrahedron -{ - static const CellType CellEnum = Tetrahedron; -}; -struct CellPyramid -{ - static const CellType CellEnum = Pyramid; -}; -struct CellWedge -{ - static const CellType CellEnum = Wedge; -}; -struct CellHexahedron -{ - static const CellType CellEnum = Hexahedron; -}; - -} // namespace mesh -} // namespace smtk - -#endif //__smtk_mesh_core_CellTypes_h diff --git a/smtk/mesh/core/Component.cxx b/smtk/mesh/core/Component.cxx deleted file mode 100644 index 687ac1670ce4e459bb4775bcd39130b983d9cb74..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/Component.cxx +++ /dev/null @@ -1,174 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/Component.h" - -#include "smtk/common/UUIDGenerator.h" - -#include "smtk/mesh/core/Resource.h" - -namespace smtk -{ -namespace mesh -{ - -Component::Component(const smtk::mesh::ResourcePtr& resource, const smtk::common::UUID& id) - : m_resource(resource) - , m_id(id) -{ -} - -Component::Component(const smtk::mesh::MeshSet& meshset) - : Component(meshset.resource(), meshset.id()) -{ -} - -bool Component::operator==(const Component& other) const -{ - return mesh() == other.mesh(); -} - -bool Component::operator!=(const Component& other) const -{ - return mesh() != other.mesh(); -} - -bool Component::operator<(const Component& other) const -{ - return mesh() < other.mesh(); -} - -std::shared_ptr Component::create( - const smtk::mesh::ResourcePtr& resource, - const smtk::common::UUID& id) -{ - // If the mesh resource is invalid, return an invalid component - if (resource == nullptr) - { - return std::shared_ptr(); - } - - // Attempt to find a preexisting component associated with the incident id - auto idAndComponent = resource->m_componentMap.find(id); - if (idAndComponent != resource->m_componentMap.end()) - { - // If one is found, return the stored component - return idAndComponent->second; - } - - // If no preexisting component exists, we need to create one. - - // First, confirm there is a meshset associated with the incident id - smtk::mesh::MeshSet meshset; - { - const smtk::mesh::InterfacePtr& iface = resource->interface(); - smtk::mesh::Handle handle; - smtk::mesh::HandleRange entities; - if (!iface->findById(iface->getRoot(), id, handle)) - { - // If the id is not associated with a meshset, return an invalid - // component. - return std::shared_ptr(); - } - } - - // Create a new component to represent the existing meshset - std::shared_ptr shared(new Component(resource, id)); - - // Store the component in the resource's component map - auto ptr = std::static_pointer_cast(shared->shared_from_this()); - resource->m_componentMap[id] = ptr; - - return ptr; -} - -std::shared_ptr Component::create(const smtk::mesh::MeshSet& meshset) -{ - // If the meshset is invalid, return an invalid component - if (!meshset.isValid()) - { - return std::shared_ptr(); - } - - // If the meshset has an invalid id, we know it isn't stored in the - // resource's component map. Generate an id for the meshset and create a new - // component to represent it. - if (meshset.id().isNull()) - { - const_cast(meshset).setId( - smtk::common::UUIDGenerator::instance().random()); - } - else - { - // Attempt to find a preexisting component associated with the incident - // meshset - const auto& resource = meshset.resource(); - auto idAndComponent = resource->m_componentMap.find(meshset.id()); - if (idAndComponent != resource->m_componentMap.end()) - { - return idAndComponent->second; - } - } - - // Create a new component to represent the existing meshset - std::shared_ptr shared(new Component(meshset)); - - // Store the component in the resource's component map - auto ptr = std::static_pointer_cast(shared->shared_from_this()); - meshset.resource()->m_componentMap[meshset.id()] = ptr; - - return ptr; -} - -const smtk::resource::ResourcePtr Component::resource() const -{ - return std::static_pointer_cast(m_resource.lock()); -} - -std::string Component::name() const -{ - auto mesh = this->mesh(); - return (mesh.isValid() ? mesh.name() : ""); -} - -const smtk::mesh::MeshSet Component::mesh() const -{ - if (auto resource = m_resource.lock()) - { - const smtk::mesh::InterfacePtr& iface = resource->interface(); - smtk::mesh::Handle handle; - smtk::mesh::HandleRange entities; - if (iface->findById(iface->getRoot(), m_id, handle)) - { - entities.insert(handle); - return smtk::mesh::MeshSet(resource, iface->getRoot(), entities); - } - } - return smtk::mesh::MeshSet(); -} - -smtk::mesh::MeshSet Component::mesh() -{ - if (auto resource = m_resource.lock()) - { - const smtk::mesh::InterfacePtr& iface = resource->interface(); - smtk::mesh::Handle handle; - smtk::mesh::HandleRange entities; - if (iface->findById(iface->getRoot(), m_id, handle)) - { - entities.insert(handle); - return smtk::mesh::MeshSet(resource, iface->getRoot(), entities); - } - } - - return smtk::mesh::MeshSet(); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/Component.h b/smtk/mesh/core/Component.h deleted file mode 100644 index 90a6a4aad72815b65911bec433e276ab75d2360e..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/Component.h +++ /dev/null @@ -1,91 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_Component_h -#define smtk_mesh_Component_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" -#include "smtk/TupleTraits.h" - -#include "smtk/resource/Component.h" - -namespace smtk -{ -namespace mesh -{ -class Component; -class MeshSet; -class Resource; - -typedef std::vector ComponentList; -typedef std::set Components; - -/// A lightweight object for representing meshset information as a resource -/// component. This is useful for constructing links between meshsets and other -/// resources/components and for representing meshsets within smtk's attribute -/// system. -class SMTKCORE_EXPORT Component : public smtk::resource::Component -{ -protected: - Component(const smtk::mesh::ResourcePtr&, const smtk::common::UUID&); - Component(const smtk::mesh::MeshSet&); - -public: - smtkTypeMacro(Component); - smtkSuperclassMacro(smtk::resource::Component); - smtkSharedFromThisMacro(smtk::resource::PersistentObject); - - // Comparison operators - bool operator==(const Component&) const; - bool operator!=(const Component&) const; - bool operator<(const Component&) const; - - /// Construct a mesh component corresponding to a meshset from the input - /// resource and id. No checking is performed that the resource has a - /// meshset with this id; if this is the case, the resolved mesh() will return - /// a default-constructed (and invalid) mesh. - static std::shared_ptr create( - const smtk::mesh::ResourcePtr&, - const smtk::common::UUID&); - - /// Construct a mesh component correpsonding to the input meshset. - static std::shared_ptr create(const smtk::mesh::MeshSet&); - - /// Access the component's resource. - const smtk::resource::ResourcePtr resource() const override; - - /// Access the component's id. - const smtk::common::UUID& id() const override { return m_id; } - - /// Set the component's id. No checking is performed that the resource has a - /// meshset with this id; if this is the case, the resolved mesh() will return - /// a default-constructed (and invalid) mesh. - bool setId(const smtk::common::UUID& myID) override - { - m_id = myID; - return true; - } - - std::string name() const override; - - /// Access the meshset represented by this component. - virtual const smtk::mesh::MeshSet mesh() const; - virtual smtk::mesh::MeshSet mesh(); - -private: - std::weak_ptr m_resource; - smtk::common::UUID m_id; -}; - -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/DimensionTypes.h b/smtk/mesh/core/DimensionTypes.h deleted file mode 100644 index fda65b172c99e5cd75ec624fa7ba893c1510a2f4..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/DimensionTypes.h +++ /dev/null @@ -1,35 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_DimensionTypes_h -#define smtk_mesh_core_DimensionTypes_h - -#include - -namespace smtk -{ -namespace mesh -{ - -enum DimensionType -{ - Dims0 = 0, - Dims1 = 1, - Dims2 = 2, - Dims3 = 3, - DimensionType_MAX = 4 -}; - -//Need a basic blitter for dims queries -typedef std::bitset DimensionTypes; -} // namespace mesh -} // namespace smtk - -#endif //__smtk_mesh_core_DimensionTypes_h diff --git a/smtk/mesh/core/FieldTypes.h b/smtk/mesh/core/FieldTypes.h deleted file mode 100644 index df91a44340e95462fa3e8d5c922e381816ee50ce..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/FieldTypes.h +++ /dev/null @@ -1,46 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_FieldTypes_h -#define smtk_mesh_core_FieldTypes_h - -namespace smtk -{ -namespace mesh -{ - -enum class FieldType -{ - Integer, - Double, - MaxFieldType -}; - -template -struct FieldTypeFor -{ - static constexpr FieldType type = FieldType::MaxFieldType; -}; - -template<> -struct FieldTypeFor -{ - static constexpr FieldType type = FieldType::Double; -}; - -template<> -struct FieldTypeFor -{ - static constexpr FieldType type = FieldType::Integer; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/ForEachTypes.cxx b/smtk/mesh/core/ForEachTypes.cxx deleted file mode 100644 index 34a7af93862df574cebf954bf9b5715142381081..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/ForEachTypes.cxx +++ /dev/null @@ -1,29 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/core/ForEachTypes.h" - -namespace smtk -{ -namespace mesh -{ - -MeshForEach::~MeshForEach() = default; - -CellForEach::CellForEach(bool wantCoordinates) - : m_wantsCoordinates(wantCoordinates) -{ -} - -CellForEach::~CellForEach() = default; - -PointForEach::~PointForEach() = default; - -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/ForEachTypes.h b/smtk/mesh/core/ForEachTypes.h deleted file mode 100644 index 69aa6194d4a6f451287bd95fee9e225f04b4bbb3..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/ForEachTypes.h +++ /dev/null @@ -1,106 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_ForEachTypes_h -#define smtk_mesh_core_ForEachTypes_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/Handle.h" - -namespace smtk -{ -namespace mesh -{ - -//forward declare of CellSet and MeshSet -class CellSet; -class MeshSet; - -class SMTKCORE_EXPORT MeshForEach -{ -public: - virtual ~MeshForEach(); - - virtual void forMesh(smtk::mesh::MeshSet& singleMesh) = 0; - - smtk::mesh::ResourcePtr m_resource; -}; - -class SMTKCORE_EXPORT CellForEach -{ -public: - CellForEach(bool wantCoordinates = true); - - virtual ~CellForEach(); - - virtual void - forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType cellType, int numPointIds) = 0; - - //returns true if the CellForEach visitor wants its coordinates member - //variable filled - bool wantsCoordinates() const { return m_wantsCoordinates; } - - const smtk::mesh::Handle* pointIds() const { return m_pointIds; } - - smtk::mesh::Handle pointId(int index) const { return m_pointIds[index]; } - - const std::vector& coordinates() const { return *m_coords; } - - smtk::mesh::ResourcePtr resource() const { return m_resource; } - - //Set the coords for the visitor. This should be only be called by - //smtk::mesh::Interface implementations - void coordinates(std::vector* coords) { m_coords = coords; } - - //Set the pointIds for the visitor. This should be only be called by - //smtk::mesh::Interface implementations - void pointIds(const smtk::mesh::Handle* ptIds) { m_pointIds = ptIds; } - - //Set the resource() for the visitor. This should be only be called by - //smtk::mesh::Interface implementations - void resource(smtk::mesh::ResourcePtr r) { m_resource = r; } - -private: - smtk::mesh::ResourcePtr m_resource; - const smtk::mesh::Handle* m_pointIds{ nullptr }; - std::vector* m_coords{ nullptr }; - bool m_wantsCoordinates; -}; - -class SMTKCORE_EXPORT PointForEach -{ -public: - virtual ~PointForEach(); - - // PointForEach allows read access to the point ids and coordinates and write - // access to the coordinates ( x, y, z ) it is iterating. This is different - // than Cell and Mesh iteration which are read only. - // - // If the forPoints needs to modify the coordinates, you have to explicitly - // set coordinatesModified to be true, otherwise the modified coordinates will - // be ignored. - // - // Note: by default coordinatesModified is set to false - // - // - virtual void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& coordinatesModified) = 0; - - smtk::mesh::ResourcePtr m_resource; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/Handle.cxx b/smtk/mesh/core/Handle.cxx deleted file mode 100644 index 43783acb26354a5a6be5306624f517bcfb64413d..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/Handle.cxx +++ /dev/null @@ -1,102 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/Handle.h" - -namespace smtk -{ -namespace mesh -{ - -const_element_iterator rangeElementsBegin(const HandleRange& range) -{ - return boost::icl::elements_begin(range); -} - -const_element_iterator rangeElementsEnd(const HandleRange& range) -{ - return boost::icl::elements_end(range); -} - -Handle rangeElement(const HandleRange& range, std::size_t i) -{ - return *std::next(boost::icl::elements_begin(range), i); -} - -bool rangeContains(const HandleRange& range, Handle i) -{ - return boost::icl::contains(range, i); -} - -bool rangeContains(const HandleRange& range, const HandleInterval& i) -{ - return boost::icl::contains(range, i); -} - -bool rangeContains(const HandleRange& super, const HandleRange& sub) -{ - return boost::icl::contains(super, sub); -} - -std::size_t rangeIndex(const HandleRange& range, Handle i) -{ - std::size_t index = 0; - - HandleRange::const_iterator interval = range.find(i); - for (HandleRange::const_iterator it = range.begin(); it != interval; ++it) - { - index += (it->upper() - it->lower()) + 1; - } - - index += i - interval->lower(); - - return index; -} - -std::size_t rangeIntervalCount(const HandleRange& range) -{ - return boost::icl::interval_count(range); -} - -bool rangesEqual(const HandleRange& lhs, const HandleRange& rhs) -{ - if (smtk::mesh::rangeIntervalCount(lhs) != smtk::mesh::rangeIntervalCount(rhs)) - { - return false; - } - - auto i = lhs.begin(); - auto j = rhs.begin(); - for (; i != lhs.end(); ++i, ++j) - { - if (i->lower() != j->lower() || i->upper() != j->upper()) - { - return false; - } - } - return true; -} -} // namespace mesh -} // namespace smtk - -std::ostream& operator<<(std::ostream& os, const smtk::mesh::HandleRange& range) -{ - os << "["; - for (auto interval : range) - { - os << interval << ","; - } - if (!range.empty()) - { - os << '\b'; - } - os << "]"; - return os; -} diff --git a/smtk/mesh/core/Handle.h b/smtk/mesh/core/Handle.h deleted file mode 100644 index 2653ffeb8980178ac59d6b75bd3801c627bbe8ea..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/Handle.h +++ /dev/null @@ -1,82 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_Handle_h -#define smtk_mesh_core_Handle_h - -#include "smtk/CoreExports.h" - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include -SMTK_THIRDPARTY_POST_INCLUDE - -#include -#include - -namespace smtk -{ -namespace mesh -{ -typedef std::ptrdiff_t EntityId; -typedef std::size_t Handle; -} // namespace mesh -} // namespace smtk - -// TODO: use extern template declaration to prevent consuming libraries from -// generating these template specializations. -template class SMTKCORE_EXPORT boost::icl::closed_interval; -template class SMTKCORE_EXPORT boost::icl:: - interval_set>; - -namespace smtk -{ -namespace mesh -{ -typedef boost::icl::closed_interval HandleInterval; -typedef boost::icl::interval_set HandleRange; - -typedef decltype(boost::icl::elements_begin( - std::declval())) const_element_iterator; - -/// Return an iterator to the first element in the range -SMTKCORE_EXPORT const_element_iterator rangeElementsBegin(const HandleRange&); - -/// Return an iterator to the last element in the range -SMTKCORE_EXPORT const_element_iterator rangeElementsEnd(const HandleRange&); - -/// Given a handle range and an index \a i, return the i-th handle in the range -SMTKCORE_EXPORT Handle rangeElement(const HandleRange&, std::size_t); - -/// Return true if the handle is contained within the handle range -SMTKCORE_EXPORT bool rangeContains(const HandleRange&, Handle); - -/// Return true if the handle interval is contained within the handle range -SMTKCORE_EXPORT bool rangeContains(const HandleRange&, const HandleInterval&); - -/// Return true if the second handle range is contained within the first -/// handle range -SMTKCORE_EXPORT bool rangeContains(const HandleRange& super, const HandleRange& sub); - -/// Return the element index of a handle value -SMTKCORE_EXPORT std::size_t rangeIndex(const HandleRange&, Handle); - -/// Return the number of intervals in the range -SMTKCORE_EXPORT std::size_t rangeIntervalCount(const HandleRange&); - -/// Determine whether two ranges are equal -SMTKCORE_EXPORT bool rangesEqual(const HandleRange&, const HandleRange&); -} // namespace mesh -} // namespace smtk - -SMTKCORE_EXPORT std::ostream& operator<<(std::ostream&, const smtk::mesh::HandleRange&); - -#endif diff --git a/smtk/mesh/core/Interface.h b/smtk/mesh/core/Interface.h deleted file mode 100644 index 16f93378542c108db52e8fc008877b91cc9bde2d..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/Interface.h +++ /dev/null @@ -1,590 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_mesh_core_Interface_h -#define smtk_mesh_core_Interface_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/CellTraits.h" -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/DimensionTypes.h" -#include "smtk/mesh/core/FieldTypes.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/TypeSet.h" - -#include -#include - -namespace smtk -{ -namespace mesh -{ - -//forward declare classes we use -class ContainsFunctor; -class PointConnectivity; - -class SMTKCORE_EXPORT Allocator -{ -public: - virtual ~Allocator() = default; - - virtual bool allocatePoints( - std::size_t numPointsToAlloc, - smtk::mesh::Handle& firstVertexHandle, - std::vector& coordinateMemory) = 0; - - virtual bool allocateCells( - smtk::mesh::CellType cellType, - std::size_t numCellsToAlloc, - int numVertsPerCell, - smtk::mesh::HandleRange& createdCellIds, - smtk::mesh::Handle*& connectivityArray) = 0; - - template - bool allocateCells( - std::size_t numCellsToAlloc, - smtk::mesh::HandleRange& createdCellIds, - smtk::mesh::Handle*& connectivityArray) - { - typedef typename smtk::mesh::CellEnumToType::Traits Traits; - smtk::mesh::CellType cellType = static_cast(CellType); - - return this->allocateCells( - cellType, numCellsToAlloc, Traits::NUM_VERTICES, createdCellIds, connectivityArray); - } - - virtual bool connectivityModified( - const smtk::mesh::HandleRange& cellsToUpdate, - int numVertsPerCell, - const smtk::mesh::Handle* connectivityArray) = 0; -}; - -// BufferedCellAllocator allows for the allocation of meshes by -// 1. reserving memory for all of your points -// 2. filling your points and cell connectivities by point index. -// Point indices are assumed to be contiguous with first index at 0. -class SMTKCORE_EXPORT BufferedCellAllocator -{ -public: - BufferedCellAllocator() = default; - - virtual ~BufferedCellAllocator() = default; - - virtual bool reserveNumberOfCoordinates(std::size_t nCoordinates) = 0; - virtual bool setCoordinate(std::size_t coord, double* xyz) = 0; - - virtual bool - addCell(smtk::mesh::CellType ctype, long long int* pointIds, std::size_t nCoordinates = 0) = 0; - virtual bool - addCell(smtk::mesh::CellType ctype, long int* pointIds, std::size_t nCoordinates = 0) = 0; - virtual bool addCell(smtk::mesh::CellType ctype, int* pointIds, std::size_t nCoordinates = 0) = 0; - - virtual bool flush() = 0; - - virtual smtk::mesh::HandleRange cells() = 0; - - bool setCoordinate(std::size_t coord, double x, double y, double z) - { - double xyz[3] = { x, y, z }; - return this->setCoordinate(coord, xyz); - } - bool setCoordinate(std::size_t coord, float* xyz) - { - return this->setCoordinate(coord, xyz[0], xyz[1], xyz[2]); - } - bool setCoordinate(std::size_t coord, float x, float y, float z) - { - double xyz[3] = { x, y, z }; - return this->setCoordinate(coord, xyz); - } - - bool isValid() const { return m_validState; } - -protected: - bool m_validState{ false }; -}; - -// IncrementalAllocator allows for the allocation of meshes by incrementally -// filling your points and cell connectivities by point index. This allocator is -// the least efficient for storage and data retrieval, but provides the most -// flexible API. -class SMTKCORE_EXPORT IncrementalAllocator -{ -public: - IncrementalAllocator() = default; - - virtual ~IncrementalAllocator() = default; - - virtual std::size_t addCoordinate(double* xyz) = 0; - virtual bool setCoordinate(std::size_t coord, double* xyz) = 0; - - virtual bool - addCell(smtk::mesh::CellType ctype, long long int* pointIds, std::size_t nCoordinates = 0) = 0; - virtual bool - addCell(smtk::mesh::CellType ctype, long int* pointIds, std::size_t nCoordinates = 0) = 0; - virtual bool addCell(smtk::mesh::CellType ctype, int* pointIds, std::size_t nCoordinates = 0) = 0; - - virtual bool flush() = 0; - - virtual smtk::mesh::HandleRange cells() = 0; - - std::size_t addCoordinate(double x, double y, double z) - { - double xyz[3] = { x, y, z }; - return this->addCoordinate(xyz); - } - std::size_t addCoordinate(float* xyz) { return this->addCoordinate(xyz[0], xyz[1], xyz[2]); } - std::size_t addCoordinate(float x, float y, float z) - { - double xyz[3] = { x, y, z }; - return this->addCoordinate(xyz); - } - - bool setCoordinate(std::size_t coord, double x, double y, double z) - { - double xyz[3] = { x, y, z }; - return this->setCoordinate(coord, xyz); - } - bool setCoordinate(std::size_t coord, float* xyz) - { - return this->setCoordinate(coord, xyz[0], xyz[1], xyz[2]); - } - bool setCoordinate(std::size_t coord, float x, float y, float z) - { - double xyz[3] = { x, y, z }; - return this->setCoordinate(coord, xyz); - } - - virtual bool isValid() const = 0; -}; - -class SMTKCORE_EXPORT ConnectivityStorage -{ -public: - virtual ~ConnectivityStorage() = default; - - //struct that holds the required information to compute what is the - //current cell when we are iterating. - struct IterationState - { - IterationState() = default; - std::size_t whichConnectivityVector{ 0 }; - std::size_t ptrOffsetInVector{ 0 }; - }; - - virtual void initTraversal(IterationState& state) = 0; - - virtual bool fetchNextCell( - IterationState& state, - smtk::mesh::CellType& cellType, - int& numPts, - const smtk::mesh::Handle*& points) = 0; - - virtual bool equal(ConnectivityStorage* other) const = 0; - - virtual std::size_t cellSize() const = 0; - - virtual std::size_t vertSize() const = 0; -}; - -class SMTKCORE_EXPORT PointLocatorImpl -{ -public: - //copy of vector on return, ugggh. - struct Results - { - Results() = default; - - std::vector pointIds; - std::vector sqDistances; - std::vector x_s, y_s, z_s; - bool want_sqDistances{ false }; - bool want_Coordinates{ false }; - }; - - virtual ~PointLocatorImpl() = default; - - //returns all the point ids that are inside the locator - virtual smtk::mesh::HandleRange range() const = 0; - - virtual void - locatePointsWithinRadius(double x, double y, double z, double radius, Results& results) = 0; -}; - -class SMTKCORE_EXPORT Interface -{ -public: - Interface() = default; - - virtual ~Interface() = default; - - //get back a string that contains the pretty name for the interface class. - //Requirements: The string must be all lower-case. - //For example, the moab interface would return "moab" - virtual std::string name() const = 0; - - //returns if the underlying data has been modified since the mesh was loaded - //from disk. If the mesh has no underlying file, it will always be considered - //modified. Once the mesh is written to disk, we will reset the modified - //flag. - virtual bool isModified() const = 0; - - //get back a lightweight interface around allocating memory into the given - //interface. This is generally used to create new coordinates or cells that - //are than assigned to an existing mesh or new mesh. - // - //If the current interface is read-only, the AllocatorPtr that is returned - //will be nullptr. - // - //Note: Merely fetching a valid allocator will mark the resource as - //modified. This is done instead of on a per-allocation basis so that - //modification state changes don't impact performance. - virtual smtk::mesh::AllocatorPtr allocator() = 0; - - //get back a lightweight interface around incrementally allocating memory into - //the given interface. This is generally used to create new coordinates or - //cells that are than assigned to an existing mesh or new mesh. - // - //If the current interface is read-only, the BufferedCellAllocatorPtr that is - //returned will be nullptr. - // - //Note: Merely fetching a valid allocator will mark the resource as - //modified. This is done instead of on a per-allocation basis so that - //modification state changes don't impact performance. - virtual smtk::mesh::BufferedCellAllocatorPtr bufferedCellAllocator() = 0; - - //get back a lightweight interface around incrementally allocating memory into - //the given interface. This is generally used to create new coordinates or - //cells that are than assigned to an existing mesh or new mesh. - // - //If the current interface is read-only, the IncrementalAllocatorPtr that is - //returned will be nullptr. - // - //Note: Merely fetching a valid allocator will mark the resource as - //modified. This is done instead of on a per-allocation basis so that - //modification state changes don't impact performance. - virtual smtk::mesh::IncrementalAllocatorPtr incrementalAllocator() = 0; - - //get back an efficient storage mechanism for a range of cells point - //connectivity. This allows for efficient iteration of cell connectivity, and - //conversion to other formats - virtual smtk::mesh::ConnectivityStoragePtr connectivityStorage( - const smtk::mesh::HandleRange& cells) = 0; - - //get back an efficient point locator for a range of points - //This allows for efficient point locator on a per interface basis. - virtual smtk::mesh::PointLocatorImplPtr pointLocator(const smtk::mesh::HandleRange& points) = 0; - virtual smtk::mesh::PointLocatorImplPtr pointLocator( - std::size_t numPoints, - const std::function(std::size_t)>& coordinates) = 0; - - virtual smtk::mesh::Handle getRoot() const = 0; - - virtual void registerQueries(smtk::mesh::Resource&) const = 0; - - //creates a mesh with that contains the input cells. - //the mesh will have the root as its parent. - //Will fail if the HandleRange is empty or doesn't contain valid - //cell handles. - //Note: Will mark the interface as modified when successful - virtual bool createMesh(const smtk::mesh::HandleRange& cells, smtk::mesh::Handle& meshHandle) = 0; - - //the number of meshes that are children of this mesh. - virtual std::size_t numMeshes(smtk::mesh::Handle handle) const = 0; - - virtual smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle) const = 0; - - virtual smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle, int dimension) const = 0; - - //find all entity sets that have this exact name tag - virtual smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle, const std::string& name) - const = 0; - - //find all entity sets that have this exact domain tag - virtual smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Domain& domain) const = 0; - - //find all entity sets that have this exact dirichlet tag - virtual smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Dirichlet& dirichlet) const = 0; - - //find all entity sets that have this exact neumann tag - virtual smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Neumann& neumann) const = 0; - - //get all cells held by this range - virtual smtk::mesh::HandleRange getCells(const smtk::mesh::HandleRange& meshsets) const = 0; - - //get all cells held by this range handle of a given cell type - virtual smtk::mesh::HandleRange getCells( - const smtk::mesh::HandleRange& meshsets, - smtk::mesh::CellType cellType) const = 0; - - //get all cells held by this range handle of a given cell type(s) - virtual smtk::mesh::HandleRange getCells( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellTypes& cellTypes) const = 0; - - //get all cells held by this range handle of a given dimension - virtual smtk::mesh::HandleRange getCells( - const smtk::mesh::HandleRange& meshsets, - smtk::mesh::DimensionType dim) const = 0; - - //get all points held by this range of handle of a given dimension. If - //boundary_only is set to true, ignore the higher order points of the - //cells - virtual smtk::mesh::HandleRange getPoints( - const smtk::mesh::HandleRange& cells, - bool boundary_only = false) const = 0; - - //get all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - virtual bool getCoordinates(const smtk::mesh::HandleRange& points, double* xyz) const = 0; - - //get all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - //Floats are not how we store the coordinates internally, so asking for - //the coordinates in such a manner could cause data inaccuracies to appear - //so generally this is only used if you fully understand the input domain - virtual bool getCoordinates(const smtk::mesh::HandleRange& points, float* xyz) const = 0; - - //set all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - virtual bool setCoordinates(const smtk::mesh::HandleRange& points, const double* xyz) = 0; - - //set all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - virtual bool setCoordinates(const smtk::mesh::HandleRange& points, const float* xyz) = 0; - - virtual std::string name(const smtk::mesh::Handle& meshset) const = 0; - virtual bool setName(const smtk::mesh::Handle& meshset, const std::string& name) = 0; - - virtual std::vector computeNames(const smtk::mesh::HandleRange& meshsets) const = 0; - - virtual std::vector computeDomainValues( - const smtk::mesh::HandleRange& meshsets) const = 0; - - virtual std::vector computeDirichletValues( - const smtk::mesh::HandleRange& meshsets) const = 0; - - virtual std::vector computeNeumannValues( - const smtk::mesh::HandleRange& meshsets) const = 0; - - virtual smtk::common::UUIDArray computeModelEntities( - const smtk::mesh::HandleRange& meshsets) const = 0; - - virtual smtk::mesh::TypeSet computeTypes(const smtk::mesh::HandleRange& range) const = 0; - - //compute the cells that make the shell/skin of the set of meshes - virtual bool computeShell(const smtk::mesh::HandleRange& meshes, smtk::mesh::HandleRange& shell) - const = 0; - - //compute adjacencies of a given dimension, creating them if necessary - virtual bool computeAdjacenciesOfDimension( - const smtk::mesh::HandleRange& meshes, - int dimension, - smtk::mesh::HandleRange& adj) const = 0; - - //given a handle to a cell, return its parent handle and canonical index. - virtual bool - canonicalIndex(const smtk::mesh::Handle& cell, smtk::mesh::Handle& parent, int& index) const = 0; - - //merge any duplicate points used by the cells that have been passed - //Note: Will mark the interface as modified when successful - virtual bool mergeCoincidentContactPoints( - const smtk::mesh::HandleRange& meshes, - double tolerance) = 0; - - //given a handle to a cell, return its dimension-equivalent neighbors. - virtual smtk::mesh::HandleRange neighbors(const smtk::mesh::Handle& cell) const = 0; - - // Note: Will mark the interface as modified when successful - virtual bool setDomain(const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Domain& domain) - const = 0; - - // Note: Will mark the interface as modified when successful - virtual bool setDirichlet( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::Dirichlet& dirichlet) const = 0; - - // Note: Will mark the interface as modified when successful - virtual bool setNeumann( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::Neumann& neumann) const = 0; - - virtual bool setId(const smtk::mesh::Handle& meshset, const smtk::common::UUID& id) const = 0; - - virtual smtk::common::UUID getId(const smtk::mesh::Handle& meshset) const = 0; - - virtual bool findById( - const smtk::mesh::Handle& root, - const smtk::common::UUID& id, - smtk::mesh::Handle& meshset) const = 0; - - // Specify for a given sets of handles what the associated model entity is. - // This allows for a model region, face, or edge to be associated with a - // given set of meshes. - // Note: Only MeshSets can have associations applied. Other elements will cause - // undefined behavior - // Note: Will mark the interface as modified when successful - virtual bool setAssociation( - const smtk::common::UUID& modelUUID, - const smtk::mesh::HandleRange& meshsets) const = 0; - - // For a given handle root, find all meshsets that have an association to - // the given model uuid - virtual smtk::mesh::HandleRange findAssociations( - const smtk::mesh::Handle& root, - const smtk::common::UUID& modelUUID) const = 0; - - // Specify the model uuid that the root of this interface is associated too - // This represents generally is the MODEL_ENTITY that owns all associations - // with this interface - // Note: Will mark the interface as modified when successful - virtual bool setRootAssociation(const smtk::common::UUID& modelUUID) const = 0; - - virtual smtk::common::UUID rootAssociation() const = 0; - - virtual bool createCellField( - const smtk::mesh::HandleRange& meshsets, - const std::string& name, - std::size_t dimension, - const smtk::mesh::FieldType& type, - const void* data) = 0; - - virtual int getCellFieldDimension(const smtk::mesh::CellFieldTag& cfTag) const = 0; - - virtual smtk::mesh::FieldType getCellFieldType(const smtk::mesh::CellFieldTag& cfTag) const = 0; - - virtual smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::CellFieldTag& cfTag) const = 0; - - virtual bool hasCellField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellFieldTag& cfTag) const = 0; - - virtual bool getCellField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellFieldTag& cfTag, - void* data) const = 0; - - virtual bool setCellField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellFieldTag& cfTag, - const void* data) = 0; - - virtual bool getField( - const smtk::mesh::HandleRange& cells, - const smtk::mesh::CellFieldTag& cfTag, - void* data) const = 0; - - virtual bool setField( - const smtk::mesh::HandleRange& cells, - const smtk::mesh::CellFieldTag& cfTag, - const void* data) = 0; - - virtual std::set computeCellFieldTags( - const smtk::mesh::Handle& handle) const = 0; - - virtual bool deleteCellField( - const smtk::mesh::CellFieldTag& dsTag, - const smtk::mesh::HandleRange& meshsets) = 0; - - virtual bool createPointField( - const smtk::mesh::HandleRange& meshsets, - const std::string& name, - std::size_t dimension, - const smtk::mesh::FieldType& type, - const void* data) = 0; - - virtual int getPointFieldDimension(const smtk::mesh::PointFieldTag& pfTag) const = 0; - - virtual smtk::mesh::FieldType getPointFieldType(const smtk::mesh::PointFieldTag& pfTag) const = 0; - - virtual smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::PointFieldTag& pfTag) const = 0; - - virtual bool hasPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag) const = 0; - - virtual bool getPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag, - void* data) const = 0; - - virtual bool setPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag, - const void* data) = 0; - - virtual bool getField( - const smtk::mesh::HandleRange& points, - const smtk::mesh::PointFieldTag& pfTag, - void* data) const = 0; - - virtual bool setField( - const smtk::mesh::HandleRange& points, - const smtk::mesh::PointFieldTag& pfTag, - const void* data) = 0; - - virtual std::set computePointFieldTags( - const smtk::mesh::Handle& handle) const = 0; - - virtual bool deletePointField( - const smtk::mesh::PointFieldTag& dsTag, - const smtk::mesh::HandleRange& meshsets) = 0; - - virtual smtk::mesh::HandleRange pointIntersect( - const smtk::mesh::HandleRange& a, - const smtk::mesh::HandleRange& b, - smtk::mesh::PointConnectivity& bpc, - smtk::mesh::ContainmentType containmentType) const = 0; - - virtual smtk::mesh::HandleRange pointDifference( - const smtk::mesh::HandleRange& a, - const smtk::mesh::HandleRange& b, - smtk::mesh::PointConnectivity& bpc, - smtk::mesh::ContainmentType containmentType) const = 0; - - virtual void pointForEach(const HandleRange& points, smtk::mesh::PointForEach& filter) const = 0; - - virtual void cellForEach( - const HandleRange& cells, - smtk::mesh::PointConnectivity& a, - smtk::mesh::CellForEach& filter) const = 0; - - virtual void meshForEach(const HandleRange& meshes, smtk::mesh::MeshForEach& filter) const = 0; - - //The handles must be all mesh or cell elements. Mixed ranges wil - //not be deleted and will return false. Empty ranges will be ignored - //and return true. - //When deleting meshes if the range contains the root handle (getRoot()) the - //request will fail, nothing will be deleted, and we will return false. - //Note: Will mark the interface as modified when successful - virtual bool deleteHandles(const smtk::mesh::HandleRange& toDel) = 0; - - //Manually modify the modified state. This is only done to set the modified - //state to be proper after serialization / deserialization. - virtual void setModifiedState(bool state) = 0; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/MeshSet.cxx b/smtk/mesh/core/MeshSet.cxx deleted file mode 100644 index 33c2a945f66a0a386f43d59a71ce12fd3a8e7607..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/MeshSet.cxx +++ /dev/null @@ -1,666 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/core/Interface.h" - -#include - -namespace smtk -{ -namespace mesh -{ - -MeshSet::MeshSet() = default; - -MeshSet::MeshSet(const smtk::mesh::ResourcePtr& parent, smtk::mesh::Handle handle) -{ - m_parent = parent; - m_handle = handle; - - const smtk::mesh::InterfacePtr& iface = parent->interface(); - //range of entity sets - m_range = iface->getMeshsets(handle); -} - -MeshSet::MeshSet(const smtk::mesh::ConstResourcePtr& parent, smtk::mesh::Handle handle) -{ - m_parent = std::const_pointer_cast(parent); - m_handle = handle; - - const smtk::mesh::InterfacePtr& iface = parent->interface(); - //range of entity sets - m_range = iface->getMeshsets(handle); -} - -MeshSet::MeshSet( - const smtk::mesh::ResourcePtr& parent, - smtk::mesh::Handle handle, - const smtk::mesh::HandleRange& range) - : m_parent(parent) - , m_handle(handle) - , m_range(range) //range of entity sets -{ -} - -MeshSet::MeshSet( - const smtk::mesh::ConstResourcePtr& parent, - smtk::mesh::Handle handle, - const smtk::mesh::HandleRange& range) - : m_parent(std::const_pointer_cast(parent)) - , m_handle(handle) - , m_range(range) //range of entity sets -{ -} - -MeshSet::MeshSet(const smtk::mesh::MeshSet& other) - : m_parent(other.m_parent) - , m_handle(other.m_handle) - , m_range(other.m_range) -{ -} - -MeshSet::~MeshSet() = default; - -MeshSet& MeshSet::operator=(const MeshSet& other) -{ - m_parent = other.m_parent; - m_handle = other.m_handle; - m_range = other.m_range; - return *this; -} - -bool MeshSet::operator==(const MeshSet& other) const -{ - return m_parent == other.m_parent && m_handle == other.m_handle && - //empty is a fast way to check for easy mismatching ranges - m_range.empty() == other.m_range.empty() && m_range == other.m_range; -} - -bool MeshSet::operator!=(const MeshSet& other) const -{ - return !(*this == other); -} - -bool MeshSet::operator<(const MeshSet& other) const -{ - const std::size_t myLen = m_range.size(); - const std::size_t otherLen = other.size(); - - //only when the number of elements in the two meshsets are equal do - //we need to do a complex less than comparison - if (myLen == otherLen) - { - //next we look at psize which is the number of pairs inside the range - const std::size_t myPLen = smtk::mesh::rangeIntervalCount(m_range); - const std::size_t otherPLen = smtk::mesh::rangeIntervalCount(other.m_range); - - if (myPLen == otherPLen) - { - //we now have two handle ranges with same number of values, and - //the same number of pairs. Now we need - - auto i = m_range.begin(); - auto j = other.m_range.begin(); - for (; i != m_range.end(); ++i, ++j) - { - if (i->lower() != j->lower()) - { - return i->lower() < j->lower(); - } - else if (i->upper() != j->upper()) - { - return i->upper() < j->upper(); - } - } - //we looped over the entire set and everything was equal, so therefore - //we must compare parents. - - if (m_parent && other.m_parent) - { //If and only if the two parents exist can we safely compare - //the uuids of the parents - return m_parent->entity() < other.m_parent->entity(); - } - else - { - //Return true when we have a non null parent - return !!m_parent; - } - } - - //prefer less pair sets over more pair sets for less than operator - return myPLen < otherPLen; - } - - //prefer smaller lengths over larger for less than operator - return myLen < otherLen; -} - -bool MeshSet::append(const MeshSet& other) -{ - if (!m_parent) - { - m_parent = other.m_parent; - } - const bool can_append = m_parent == other.m_parent; - if (can_append) - { - m_range += other.m_range; - } - return can_append; -} - -bool MeshSet::isValid() const -{ - // A valid meshset has a valid resource and is a member of the resource. - smtk::mesh::ResourcePtr resource = this->resource(); - if (!resource) - { - return false; - } - return !set_intersect(*this, resource->meshes()).is_empty(); -} - -bool MeshSet::is_empty() const -{ - return m_range.empty(); -} - -std::string MeshSet::name() const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - if (m_range.size() == 1) - { - return iface->name(smtk::mesh::rangeElement(m_range, 0)); - } - else - { - return iface->name(m_handle); - } -} - -bool MeshSet::setName(const std::string& name) -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - if (m_range.size() == 1) - { - return iface->setName(smtk::mesh::rangeElement(m_range, 0), name); - } - else - { - return iface->setName(m_handle, name); - } -} - -std::size_t MeshSet::size() const -{ - return m_range.size(); -} - -std::vector MeshSet::domains() const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->computeDomainValues(m_range); -} - -std::vector MeshSet::dirichlets() const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->computeDirichletValues(m_range); -} - -std::vector MeshSet::neumanns() const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->computeNeumannValues(m_range); -} - -bool MeshSet::setDomain(const smtk::mesh::Domain& d) -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->setDomain(m_range, d); -} - -bool MeshSet::setDirichlet(const smtk::mesh::Dirichlet& d) -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->setDirichlet(m_range, d); -} - -bool MeshSet::setNeumann(const smtk::mesh::Neumann& n) -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->setNeumann(m_range, n); -} - -/**\brief Return the meshset's UUID. - * - */ -const smtk::common::UUID& MeshSet::id() const -{ - if (!m_id) - { - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - if (m_range.size() == 1) - { - m_id = iface->getId(smtk::mesh::rangeElement(m_range, 0)); - } - else - { - m_id = iface->getId(m_handle); - } - } - return m_id; -} - -/**\brief Set the meshset's UUID. - * - */ -void MeshSet::setId(const smtk::common::UUID& id) -{ - m_id = id; - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - if (m_range.size() == 1) - { - iface->setId(smtk::mesh::rangeElement(m_range, 0), id); - } - else - { - iface->setId(m_handle, id); - } -} - -/**\brief Return an array of model entity UUIDs associated with meshset members. - * - */ -smtk::common::UUIDArray MeshSet::modelEntityIds() const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->computeModelEntities(m_range); -} - -/**\brief Return the model entities associated with meshset members. - * - * warning Note that the parent resource of this meshset must have - * its model resource set to a valid value or the result will - * be an array of invalid entries. - */ -bool MeshSet::modelEntities(smtk::model::EntityRefArray& array) const -{ - smtk::model::ResourcePtr resource = m_parent->modelResource(); - smtk::common::UUIDArray uids = this->modelEntityIds(); - for (smtk::common::UUIDArray::const_iterator it = uids.begin(); it != uids.end(); ++it) - array.emplace_back(resource, *it); - return (resource != nullptr); -} - -/**\brief Set the model entity for each meshset member to \a ent. - * - */ -bool MeshSet::setModelEntity(const smtk::model::EntityRef& ent) -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->setAssociation(ent.entity(), m_range); -} - -/**\brief Set the model entity for each meshset member to \a ent. - * - */ -bool MeshSet::setModelEntityId(const smtk::common::UUID& id) -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->setAssociation(id, m_range); -} - -/**\brief Get the parent resource that this meshset belongs to. - * - */ -const smtk::mesh::ResourcePtr& MeshSet::resource() const -{ - return m_parent; -} - -std::vector MeshSet::names() const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->computeNames(m_range); -} - -smtk::mesh::TypeSet MeshSet::types() const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->computeTypes(m_range); -} - -smtk::mesh::CellSet MeshSet::cells() const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange range = iface->getCells(m_range); - return smtk::mesh::CellSet(m_parent, range); -} - -smtk::mesh::PointSet MeshSet::points(bool boundary_only) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange cells = iface->getCells(m_range); - smtk::mesh::HandleRange range = iface->getPoints(cells, boundary_only); - return smtk::mesh::PointSet(m_parent, range); -} - -smtk::mesh::PointConnectivity MeshSet::pointConnectivity() const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange range = iface->getCells(m_range); - return smtk::mesh::PointConnectivity(m_parent, range); -} - -smtk::mesh::CellSet MeshSet::cells(smtk::mesh::CellType cellType) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange range = iface->getCells(m_range, cellType); - return smtk::mesh::CellSet(m_parent, range); -} - -smtk::mesh::CellSet MeshSet::cells(smtk::mesh::CellTypes cellTypes) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange range = iface->getCells(m_range, cellTypes); - return smtk::mesh::CellSet(m_parent, range); -} - -smtk::mesh::CellSet MeshSet::cells(smtk::mesh::DimensionType dim) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange range = iface->getCells(m_range, dim); - return smtk::mesh::CellSet(m_parent, range); -} - -smtk::mesh::MeshSet MeshSet::subset(smtk::mesh::DimensionType dim) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange dimMeshes = iface->getMeshsets(m_handle, dim); - //intersect our mesh id with those of a given dimension to find the subset - return smtk::mesh::MeshSet(m_parent, m_handle, (dimMeshes & m_range)); -} - -smtk::mesh::MeshSet MeshSet::subset(const smtk::mesh::Domain& d) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange dMeshes = iface->getMeshsets(m_handle, d); - //intersect our mesh id with those of a given dimension to find the subset - return smtk::mesh::MeshSet(m_parent, m_handle, (dMeshes & m_range)); -} - -smtk::mesh::MeshSet MeshSet::subset(const smtk::mesh::Dirichlet& d) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange dMeshes = iface->getMeshsets(m_handle, d); - //intersect our mesh id with those of a given dimension to find the subset - return smtk::mesh::MeshSet(m_parent, m_handle, (dMeshes & m_range)); -} - -smtk::mesh::MeshSet MeshSet::subset(const smtk::mesh::Neumann& n) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - smtk::mesh::HandleRange nMeshes = iface->getMeshsets(m_handle, n); - //intersect our mesh id with those of a given dimension to find the subset - return smtk::mesh::MeshSet(m_parent, m_handle, (nMeshes & m_range)); -} - -smtk::mesh::MeshSet MeshSet::subset(std::size_t ith) const -{ - smtk::mesh::HandleRange singleHandleRange; - if (!m_range.empty() && ith < m_range.size()) - { - singleHandleRange.insert(smtk::mesh::rangeElement(m_range, ith)); - } - smtk::mesh::MeshSet singleMesh(m_parent, m_handle, singleHandleRange); - return singleMesh; -} - -smtk::mesh::MeshSet MeshSet::extractShell() const -{ - bool created; - return this->extractShell(created); -} - -smtk::mesh::MeshSet MeshSet::extractShell(bool& created) const -{ - created = false; - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - - smtk::mesh::HandleRange entities; - smtk::mesh::HandleRange cells; - const bool shellExtracted = iface->computeShell(m_range, cells); - if (shellExtracted) - { - smtk::mesh::Handle meshSetHandle; - //create a mesh for these cells since they don't have a meshset currently - created = iface->createMesh(cells, meshSetHandle); - if (created) - { - entities.insert(meshSetHandle); - } - } - return smtk::mesh::MeshSet(m_parent, m_handle, entities); -} - -smtk::mesh::MeshSet MeshSet::extractAdjacenciesOfDimension(int dimension) const -{ - bool created; - return this->extractAdjacenciesOfDimension(dimension, created); -} - -smtk::mesh::MeshSet MeshSet::extractAdjacenciesOfDimension(int dimension, bool& created) const -{ - created = false; - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - - smtk::mesh::HandleRange entities; - smtk::mesh::HandleRange cells; - const bool adjacenciesExtracted = iface->computeAdjacenciesOfDimension(m_range, dimension, cells); - if (adjacenciesExtracted) - { - smtk::mesh::Handle meshSetHandle; - //create a mesh for these cells since they don't have a meshset currently - created = iface->createMesh(cells, meshSetHandle); - if (created) - { - entities.insert(meshSetHandle); - } - } - return smtk::mesh::MeshSet(m_parent, m_handle, entities); -} - -bool MeshSet::mergeCoincidentContactPoints(double tolerance) -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->mergeCoincidentContactPoints(m_range, tolerance); -} - -smtk::mesh::CellField MeshSet::createCellField( - const std::string& name, - int dimension, - const smtk::mesh::FieldType& type, - const void* const data) -{ - if (name.empty() || dimension <= 0) - { - // CellFields must be named and have dimension higher than zero. - return CellField(); - } - - const smtk::mesh::InterfacePtr& iface = this->resource()->interface(); - if (!iface) - { - return CellField(); - } - - bool success; - if (data != nullptr) - { - success = iface->createCellField(m_range, name, dimension, type, data); - } - else - { - std::vector tmp(this->cells().size() * dimension, 0.); - success = iface->createCellField(m_range, name, dimension, type, tmp.data()); - } - return success ? CellField(*this, name) : CellField(); -} - -smtk::mesh::CellField MeshSet::cellField(const std::string& name) const -{ - return CellField(*this, name); -} - -std::set MeshSet::cellFields() const -{ - std::set cellfields; - - const smtk::mesh::InterfacePtr& iface = this->resource()->interface(); - if (!iface) - { - return cellfields; - } - - std::set tags = iface->computeCellFieldTags(m_handle); - for (const auto& tag : tags) - { - if (iface->hasCellField(this->range(), tag)) - { - cellfields.insert(CellField(*this, tag.name())); - } - } - - return cellfields; -} - -bool MeshSet::removeCellField(smtk::mesh::CellField cellfield) -{ - const smtk::mesh::InterfacePtr& iface = this->resource()->interface(); - - return iface->deleteCellField(CellFieldTag(cellfield.name()), m_range); -} - -smtk::mesh::PointField MeshSet::createPointField( - const std::string& name, - int dimension, - const smtk::mesh::FieldType& type, - const void* const data) -{ - if (name.empty() || dimension <= 0) - { - // PointFields must be named and have dimension higher than zero. - return PointField(); - } - - const smtk::mesh::InterfacePtr& iface = this->resource()->interface(); - if (!iface) - { - return PointField(); - } - - bool success; - if (data != nullptr) - { - success = iface->createPointField(m_range, name, dimension, type, data); - } - else - { - std::vector tmp(this->points().size() * dimension, 0.); - success = iface->createPointField(m_range, name, dimension, type, tmp.data()); - } - return success ? PointField(*this, name) : PointField(); -} - -smtk::mesh::PointField MeshSet::pointField(const std::string& name) const -{ - return PointField(*this, name); -} - -std::set MeshSet::pointFields() const -{ - std::set pointfields; - - const smtk::mesh::InterfacePtr& iface = this->resource()->interface(); - if (!iface) - { - return pointfields; - } - - std::set tags = iface->computePointFieldTags(m_handle); - for (const auto& tag : tags) - { - if (iface->hasPointField(this->range(), tag)) - { - pointfields.insert(PointField(*this, tag.name())); - } - } - - return pointfields; -} - -bool MeshSet::removePointField(smtk::mesh::PointField pointfield) -{ - const smtk::mesh::InterfacePtr& iface = this->resource()->interface(); - - return iface->deletePointField(PointFieldTag(pointfield.name()), m_range); -} - -//intersect two mesh sets, placing the results in the return mesh set -MeshSet set_intersect(const MeshSet& a, const MeshSet& b) -{ - if (a.m_parent != b.m_parent) - { //return an empty MeshSet if the resources don't match - return smtk::mesh::MeshSet(a.m_parent, a.m_handle, smtk::mesh::HandleRange()); - } - - smtk::mesh::HandleRange result = a.m_range & b.m_range; - return smtk::mesh::MeshSet(a.m_parent, a.m_handle, result); -} - -//subtract mesh b from a, placing the results in the return mesh set -MeshSet set_difference(const MeshSet& a, const MeshSet& b) -{ - if (a.m_parent != b.m_parent) - { //return an empty MeshSet if the resources don't match - return smtk::mesh::MeshSet(a.m_parent, a.m_handle, smtk::mesh::HandleRange()); - } - - smtk::mesh::HandleRange result = a.m_range - b.m_range; - return smtk::mesh::MeshSet(a.m_parent, a.m_handle, result); -} - -//union two mesh sets, placing the results in the return mesh set -MeshSet set_union(const MeshSet& a, const MeshSet& b) -{ - if (a.m_parent != b.m_parent) - { //return an empty MeshSet if the resources don't match - return smtk::mesh::MeshSet(a.m_parent, a.m_handle, smtk::mesh::HandleRange()); - } - - smtk::mesh::HandleRange result = a.m_range | b.m_range; - return smtk::mesh::MeshSet(a.m_parent, a.m_handle, result); -} - -SMTKCORE_EXPORT void for_each(const MeshSet& a, MeshForEach& filter) -{ - const smtk::mesh::InterfacePtr& iface = a.m_parent->interface(); - - filter.m_resource = a.m_parent; - iface->meshForEach(a.m_range, filter); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/MeshSet.h b/smtk/mesh/core/MeshSet.h deleted file mode 100644 index 48ec61c8b14c7fe6bc31287f44b6817c73d7a48c..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/MeshSet.h +++ /dev/null @@ -1,263 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_MeshSet_h -#define smtk_mesh_core_MeshSet_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/PointSet.h" -#include "smtk/mesh/core/QueryTypes.h" -#include "smtk/mesh/core/TypeSet.h" - -#include "smtk/model/EntityRef.h" - -#include "smtk/common/UUID.h" - -namespace smtk -{ -namespace mesh -{ -class CellField; -class Component; -class PointField; - -typedef std::vector MeshList; -typedef std::set MeshSets; - -//Represents a collection of meshes that have been constructed by a Resource -//We represent the collection of meshes by holding onto the parent entity -//and a vector/range of mesh entities -class SMTKCORE_EXPORT MeshSet -{ - friend SMTKCORE_EXPORT MeshSet set_intersect(const MeshSet& a, const MeshSet& b); - friend SMTKCORE_EXPORT MeshSet set_difference(const MeshSet& a, const MeshSet& b); - friend SMTKCORE_EXPORT MeshSet set_union(const MeshSet& a, const MeshSet& b); - friend SMTKCORE_EXPORT void for_each(const MeshSet& a, MeshForEach& filter); - friend class Resource; //required for deletion of meshes -public: - //default constructor generates an invalid MeshSet - MeshSet(); - - //construct a MeshSet that represents all meshes that are children - //of the handle - MeshSet(const smtk::mesh::ResourcePtr& parent, smtk::mesh::Handle handle); - MeshSet(const smtk::mesh::ConstResourcePtr& parent, smtk::mesh::Handle handle); - - //construct a MeshSet that represents an arbitrary unkown subset meshes that - //are children of the handle. - MeshSet( - const smtk::mesh::ResourcePtr& parent, - smtk::mesh::Handle handle, - const smtk::mesh::HandleRange& range); - MeshSet( - const smtk::mesh::ConstResourcePtr& parent, - smtk::mesh::Handle handle, - const smtk::mesh::HandleRange& range); - - //Copy Constructor required for rule of 3 - MeshSet(const MeshSet& other); - - //required to be in the cpp file as we hold a HandleRange - ~MeshSet(); - - //Copy assignment operator required for rule of 3 - MeshSet& operator=(const MeshSet& other); - - //Comparison operators - bool operator==(const MeshSet& other) const; - bool operator!=(const MeshSet& other) const; - bool operator<(const MeshSet& other) const; - - //append another MeshSet to this MeshSet. - //If both MeshSets have valid parent pointers they must be to the same parent - //for the append to occur. - //If the lhs MeshSet parent is nullptr and the rhs parent isn't we will copy - //the rhs parent to be the lhs parent. - //This is done so the following works: - // - // smtk::mesh::MeshSet ms; - // for( int i=0; i < size; ++i ) { ms.append( query.meshes() ) } - bool append(const MeshSet& other); - - //determine if the given MeshSet is valid. - bool isValid() const; - - bool is_empty() const; - - //set/get the name of this meshset - std::string name() const; - bool setName(const std::string&); - - //number of meshes - std::size_t size() const; - - //get all the current domains, dirichlet, neumanns for all meshes in this meshset - std::vector domains() const; - std::vector dirichlets() const; - std::vector neumanns() const; - - //set the domainl, dirichlet, or neumanns for all meshes in this meshset - bool setDomain(const smtk::mesh::Domain& d); - bool setDirichlet(const smtk::mesh::Dirichlet& d); - bool setNeumann(const smtk::mesh::Neumann& n); - - const smtk::common::UUID& id() const; - void setId(const smtk::common::UUID&); - smtk::common::UUIDArray modelEntityIds() const; - - //append the passed EntityRefArray with the model entities associated with - //this meshset, and return true on success. If the MeshSet's parent resource - //does not have its ModelManager set, this method will fail even though - //modelEntityIds() will still be valid. - bool modelEntities(smtk::model::EntityRefArray&) const; - bool setModelEntityId(const smtk::common::UUID&); - bool setModelEntity(const smtk::model::EntityRef&); - - std::vector names() const; - smtk::mesh::TypeSet types() const; - smtk::mesh::CellSet cells() const; //all cells of the meshset - //all points of the meshset; if boundary_only is true then higher-order points - //are omitted. - smtk::mesh::PointSet points(bool boundary_only = false) const; - smtk::mesh::PointConnectivity pointConnectivity() - const; //all point connectivity info for all cells - - //we should be able to extract the points or cells of the meshes. - smtk::mesh::CellSet cells(smtk::mesh::CellType cellType) const; - smtk::mesh::CellSet cells(smtk::mesh::CellTypes cTypes) const; - smtk::mesh::CellSet cells(smtk::mesh::DimensionType dim) const; - - //subset this MeshSet by a dimension, or a property such as - //Domain, Dirichlet, or Neumann - smtk::mesh::MeshSet subset(smtk::mesh::DimensionType dim) const; - smtk::mesh::MeshSet subset(const smtk::mesh::Domain& d) const; - smtk::mesh::MeshSet subset(const smtk::mesh::Dirichlet& d) const; - smtk::mesh::MeshSet subset(const smtk::mesh::Neumann& n) const; - - //subset this MeshSet given an index into entity sets (m_range) - smtk::mesh::MeshSet subset(std::size_t ith) const; - - //Extract the shell ( exterior (D-1)-dimensional elements ) of this set of - //meshes. This operation might create new cells if no shell already exists - //for the given meshset. If not already present, the resulting meshset will - //be added to the database so that the shell is saved. - //Will return an empty set when no shell can be found - smtk::mesh::MeshSet extractShell() const; - - //Extract the shell ( exterior (D-1)-dimensional elements ) of this set of - //meshes. This operation might create new cells if no shell already exists - //for the given meshset. The input field is set to reflect - //whether or not the resulting meshset is added to the database. - //Will return an empty set when no shell can be found - smtk::mesh::MeshSet extractShell(bool& created) const; - - //Extract the adjacency cells of this set of meshes for a given dimension. - //This operation might create new cells if they do not already exist - //for the given meshset. The resulting meshset will be added to the - //database so that the adjacencies are saved. - //Will return an empty set when no adjacencies can be found - smtk::mesh::MeshSet extractAdjacenciesOfDimension(int dimension) const; - - //Extract the adjacency cells of this set of meshes for a given dimension. - //This operation might create new cells if they do not already exist - //for the given meshset. The input field is set to reflect - //whether or not the resulting meshset is added to the database. - //Will return an empty set when no adjacencies can be found - smtk::mesh::MeshSet extractAdjacenciesOfDimension(int dimension, bool& created) const; - - //Merge all duplicate points contained within this meshset. - //Will return true when any points have been merged - //Will cause any existing PointConnectivity and PointSet's to become - //invalid, and using them will cause any undefined behavior - bool mergeCoincidentContactPoints(double tolerance = 1.0e-6); - - //Create a new cell field with the given name, dimension and data. The number - //of values in must be the # of cells in the meshset multiplied by the - //dimension of the cell field. - smtk::mesh::CellField createCellField( - const std::string& name, - int dimension, - const smtk::mesh::FieldType& type, - const void* field = nullptr); - smtk::mesh::CellField cellField(const std::string& name) const; - std::set cellFields() const; - //Remove the dataset from this meshset. - bool removeCellField(smtk::mesh::CellField cellfield); - - //Create a new point field with the given name, dimension and data. The number - //of values in must be the # of points in the meshset multiplied by the - //dimension of the point field. - smtk::mesh::PointField createPointField( - const std::string& name, - int dimension, - const smtk::mesh::FieldType& type, - const void* field = nullptr); - smtk::mesh::PointField pointField(const std::string& name) const; - std::set pointFields() const; - //Remove the dataset from this meshset. - bool removePointField(smtk::mesh::PointField pointfield); - - //get the underlying HandleRange that this MeshSet represents - const smtk::mesh::HandleRange& range() const { return m_range; } - - //get the underlying resource that this MeshSet belongs to - const smtk::mesh::ResourcePtr& resource() const; - -private: - friend std::shared_ptr Component::create( - const ResourcePtr&, - const smtk::common::UUID&); - friend std::shared_ptr Component::create(const MeshSet&); - - smtk::mesh::ResourcePtr m_parent; - smtk::mesh::Handle m_handle{}; - smtk::mesh::HandleRange m_range; //range of entity sets - mutable smtk::common::UUID m_id; -}; - -//Function that provide set operations on MeshSets - -//intersect two mesh sets, placing the results in the return mesh set. The -//intersection is done at the mesh id level, not at the cell id, or at -//the point usage level. If you need to find the result of a cell id intersection -//you should use CellSet. If you need to find the result of a intersection -//based on the shared points you want to use CellSet and the point_intersect -//call. -//Note: If the meshsets come from different resources the result will -//always be empty -SMTKCORE_EXPORT MeshSet set_intersect(const MeshSet& a, const MeshSet& b); - -//subtract two mesh sets, placing the results in the return mesh set. The -//difference is done at the mesh id level, not at the cell id, or at -//the point usage level. If you need to find the result of a cell id subtraction -//you should use CellSet. If you need to find the result of a difference -//based on the shared points you want to use CellSet and the point_difference -//call. -//Note: If the meshsets come from different resources the result will -//always be empty -SMTKCORE_EXPORT MeshSet set_difference(const MeshSet& a, const MeshSet& b); - -//union two mesh sets, placing the results in the return mesh set -//Note: If the meshsets come from different resources the result will -//always be empty -SMTKCORE_EXPORT MeshSet set_union(const MeshSet& a, const MeshSet& b); - -//apply a for_each mesh operator on all meshes of a given set. -SMTKCORE_EXPORT void for_each(const MeshSet& a, MeshForEach& filter); - -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/PointConnectivity.cxx b/smtk/mesh/core/PointConnectivity.cxx deleted file mode 100644 index 2c1b0a423150ed6c05e7f9ada6c85adef86381c4..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/PointConnectivity.cxx +++ /dev/null @@ -1,91 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/PointConnectivity.h" -#include "smtk/mesh/core/Resource.h" - -namespace smtk -{ -namespace mesh -{ - -PointConnectivity::PointConnectivity( - const smtk::mesh::ResourcePtr& parent, - const smtk::mesh::HandleRange& range) - : m_parent(parent) - , m_connectivity(parent->interface()->connectivityStorage(range)) -{ -} - -PointConnectivity::PointConnectivity(const smtk::mesh::PointConnectivity& other) - : m_parent(other.m_parent) - , m_connectivity(other.m_connectivity) -{ -} - -PointConnectivity::~PointConnectivity() = default; - -PointConnectivity& PointConnectivity::operator=(const PointConnectivity& other) -{ - m_parent = other.m_parent; - m_connectivity = other.m_connectivity; - return *this; -} - -bool PointConnectivity::operator==(const PointConnectivity& other) const -{ - return m_parent == other.m_parent && m_connectivity->equal(other.m_connectivity.get()); -} - -bool PointConnectivity::operator!=(const PointConnectivity& other) const -{ - return !(*this == other); -} - -std::size_t PointConnectivity::size() const -{ - return m_connectivity->vertSize(); -} - -std::size_t PointConnectivity::numberOfCells() const -{ - return m_connectivity->cellSize(); -} - -bool PointConnectivity::is_empty() const -{ - return m_connectivity->cellSize() == 0; -} - -void PointConnectivity::initCellTraversal() -{ - //we store the iteration of the traversal inside ourselves not inside - //the connectivity. The primary reason for this is that the connectivity - //can be shared between multiple instance of connectivity, but each one - //should be able to iterate over the shared data - - m_connectivity->initTraversal(m_iteratorLocation); -} - -bool PointConnectivity::fetchNextCell(int& numPts, const smtk::mesh::Handle*& points) -{ - smtk::mesh::CellType cellType; - return m_connectivity->fetchNextCell(m_iteratorLocation, cellType, numPts, points); -} - -bool PointConnectivity::fetchNextCell( - smtk::mesh::CellType& cellType, - int& numPts, - const smtk::mesh::Handle*& points) -{ - return m_connectivity->fetchNextCell(m_iteratorLocation, cellType, numPts, points); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/PointConnectivity.h b/smtk/mesh/core/PointConnectivity.h deleted file mode 100644 index 5d870cb428df9362c96f5ffb7a24c90434a3a1ae..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/PointConnectivity.h +++ /dev/null @@ -1,87 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_PointConnectivity_h -#define smtk_mesh_core_PointConnectivity_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/Interface.h" - -namespace smtk -{ -namespace mesh -{ - -//PointConnectivity is the mapping of a cell's id to a set of point ids that -//represent that cells physical location. We need to answer how in the long -//run we are going to be able to get exact locations of the point ids -//that PointConnectivity returns -class SMTKCORE_EXPORT PointConnectivity -{ - //in the future I am expecting we will need a custom iterator - //time to dig into boost::iterator_facade. - // typedef ContainerType::const_iterator const_iterator; - // typedef ContainerType::iterator iterator; -public: - typedef smtk::mesh::Handle value_type; - typedef value_type& reference; - typedef const value_type& const_reference; - - PointConnectivity(const smtk::mesh::ResourcePtr& parent, const smtk::mesh::HandleRange& range); - - //Copy Constructor required for rule of 3 - PointConnectivity(const PointConnectivity& other); - - //required to be in the cpp file as we hold a HandleRange - ~PointConnectivity(); - - //Copy assignment operator required for rule of 3 - PointConnectivity& operator=(const PointConnectivity& other); - bool operator==(const PointConnectivity& other) const; - bool operator!=(const PointConnectivity& other) const; - - //Get the total number of vertices's in the connectivity - std::size_t size() const; - - //Get the number of cells in the array - std::size_t numberOfCells() const; - - bool is_empty() const; - - //start cell traversal of the vertices - void initCellTraversal(); - - //fetch the number of points and the handle to the points - //of the cell. - //The pointer that is returned must not be deleted. - //The pointer returned should be treated as a read only pointer - bool fetchNextCell(int& numPts, const smtk::mesh::Handle*& points); - - //fetch the cell type, the number of points and the handle to the points - //of the cell. - //The pointer that is returned must not be deleted. - //The pointer returned should be treated as a read only pointer - bool - fetchNextCell(smtk::mesh::CellType& cellType, int& numPts, const smtk::mesh::Handle*& points); - -private: - smtk::mesh::ResourcePtr m_parent; - - smtk::mesh::ConnectivityStoragePtr m_connectivity; - smtk::mesh::ConnectivityStorage::IterationState m_iteratorLocation; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/PointField.cxx b/smtk/mesh/core/PointField.cxx deleted file mode 100644 index 19178568cc5baa73fbd2d87c9b4636ed5600f2df..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/PointField.cxx +++ /dev/null @@ -1,164 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/core/Interface.h" - -#include - -namespace smtk -{ -namespace mesh -{ - -PointField::PointField() = default; - -PointField::PointField(const smtk::mesh::MeshSet& meshset, const std::string& name) - : m_name(name) - , m_meshset(meshset) -{ -} - -PointField::PointField(const smtk::mesh::PointField& other) = default; - -PointField::~PointField() = default; - -PointField& PointField::operator=(const PointField& other) = default; - -bool PointField::operator==(const PointField& other) const -{ - return m_name == other.m_name && m_meshset == other.m_meshset; -} - -bool PointField::operator!=(const PointField& other) const -{ - return !(*this == other); -} - -bool PointField::operator<(const PointField& other) const -{ - if (m_name == other.m_name) - { - return m_meshset < other.m_meshset; - } - return m_name < other.m_name; -} - -bool PointField::isValid() const -{ - if (m_name.empty() || m_meshset.resource() == nullptr) - { - return false; - } - - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return false; - } - - smtk::mesh::PointFieldTag dsTag(m_name); - return iface->hasPointField(m_meshset.range(), dsTag); -} - -std::size_t PointField::size() const -{ - return (this->isValid() ? m_meshset.points().size() : 0); -} - -std::size_t PointField::dimension() const -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return 0; - } - - smtk::mesh::PointFieldTag dsTag(m_name); - return ( - iface->hasPointField(m_meshset.range(), dsTag) ? iface->getPointFieldDimension(dsTag) : 0); -} - -smtk::mesh::FieldType PointField::type() const -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return smtk::mesh::FieldType::MaxFieldType; - } - - smtk::mesh::PointFieldTag dsTag(m_name); - return ( - iface->hasPointField(m_meshset.range(), dsTag) ? iface->getPointFieldType(dsTag) - : smtk::mesh::FieldType::MaxFieldType); -} - -smtk::mesh::PointSet PointField::points() const -{ - return m_meshset.points(); -} - -bool PointField::get(const smtk::mesh::HandleRange& pointIds, void* values) const -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return false; - } - - if (!smtk::mesh::rangeContains(m_meshset.points().range(), pointIds)) - { - return false; - } - - return iface->getField(pointIds, smtk::mesh::PointFieldTag(m_name), values); -} - -bool PointField::set(const smtk::mesh::HandleRange& pointIds, const void* const values) -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return false; - } - - if (!smtk::mesh::rangeContains(m_meshset.points().range(), pointIds)) - { - return false; - } - - return iface->setField(pointIds, smtk::mesh::PointFieldTag(m_name), values); -} - -bool PointField::get(void* values) const -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return false; - } - - return iface->getPointField(m_meshset.range(), smtk::mesh::PointFieldTag(m_name), values); -} - -bool PointField::set(const void* const values) -{ - const smtk::mesh::InterfacePtr& iface = m_meshset.resource()->interface(); - if (!iface) - { - return false; - } - - return iface->setPointField(m_meshset.range(), smtk::mesh::PointFieldTag(m_name), values); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/PointField.h b/smtk/mesh/core/PointField.h deleted file mode 100644 index d5820ef6cbed4899846e58dac26c0ed8e2b93e32..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/PointField.h +++ /dev/null @@ -1,157 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_PointField_h -#define smtk_mesh_core_PointField_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/MeshSet.h" - -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ - -//Represents point-centered floating-point data associated with a meshset. We -//represent the PointField with a unique name and a reference to the meshset. -class SMTKCORE_EXPORT PointField -{ -public: - //Default constructor generates an invalid PointField - PointField(); - - //Construct a PointField for meshset and unique name - PointField(const smtk::mesh::MeshSet& mesh, const std::string& name); - - //Copy Constructor required for rule of 3 - PointField(const PointField& other); - - //required to be in the cpp file as we hold a HandleRange - ~PointField(); - - //Copy assignment operator required for rule of 3 - PointField& operator=(const PointField& other); - - //Comparison operators so we can construct sets of PointFields - bool operator==(const PointField& other) const; - bool operator!=(const PointField& other) const; - bool operator<(const PointField& other) const; - - //Return the unique name associated with the dataset - std::string name() const { return m_name; } - - //Check if the dataset is represented in the mesh database - bool isValid() const; - - //Return the number of data tuples. - std::size_t size() const; - - //Return the number of components in each data tuple - std::size_t dimension() const; - - //Return the field type - smtk::mesh::FieldType type() const; - - //Return the meshset associated with the dataset - const smtk::mesh::MeshSet& meshset() const { return m_meshset; } - - //Return the points associated with the dataset - smtk::mesh::PointSet points() const; - - //Get the data associated with all of the cells in the meshset and return - //a success flag. must be at least - //sizeof(type()) * cellIds.size() * dimension() in size. - bool get(const smtk::mesh::HandleRange& cellIds, void* values) const; - - //Set the data associated with all of the cells in the meshset and return - //a success flag. must be at least - //sizeof(type()) * cellIds.size() * dimension() in size. - bool set(const smtk::mesh::HandleRange& cellIds, const void* values); - - //Get the data associated with all of the cells in the meshset and return - //a success flag. must be at least - //sizeof(type()) * cellIds.size() * dimension() in size. - bool get(void* values) const; - - //Set the data associated with all of the cells in the meshset and return - //a success flag. must be at least - //sizeof(type()) * cellIds.size() * dimension() in size. - bool set(const void* values); - - //Convenience method for accessing field data. - template - std::vector get() const - { - if (type() != FieldTypeFor::type) - { - return std::vector(); - } - std::vector values(size() * dimension()); - if (!get(values.data())) - { - return std::vector(); - } - return values; - } - - //Convenience method for accessing field data. - template - std::vector get(const smtk::mesh::HandleRange& cellIds) const - { - if (type() != FieldTypeFor::type) - { - return std::vector(); - } - std::vector values(cellIds.size() * dimension()); - if (!get(cellIds, values.data())) - { - return std::vector(); - } - return values; - } - - //Convenience method for setting field data. - template - bool set(const std::vector& values) - { - if (type() != FieldTypeFor::type) - { - return false; - } - return set(values.data()); - } - - //Convenience method for setting field data. - template - bool set(const smtk::mesh::HandleRange& cellIds, const std::vector& values) - { - if (type() != FieldTypeFor::type) - { - return false; - } - return set(cellIds, values.data()); - } - -private: - std::string m_name; - smtk::mesh::MeshSet m_meshset; -}; - -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/PointLocator.cxx b/smtk/mesh/core/PointLocator.cxx deleted file mode 100644 index 255adcbe0e51060aaf15021947c262c48c67ea4e..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/PointLocator.cxx +++ /dev/null @@ -1,42 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/PointLocator.h" -#include "smtk/mesh/core/Resource.h" - -namespace smtk -{ -namespace mesh -{ - -PointLocator::PointLocator(const smtk::mesh::PointSet& ps) - : m_locator(ps.resource()->interface()->pointLocator(ps.range())) -{ -} - -PointLocator::PointLocator( - const smtk::mesh::ResourcePtr resource, - std::size_t numPoints, - const std::function(std::size_t)>& coordinates) - : m_locator(resource->interface()->pointLocator(numPoints, coordinates)) -{ -} - -smtk::mesh::HandleRange PointLocator::range() const -{ - return m_locator->range(); -} - -void PointLocator::find(double x, double y, double z, double radius, LocatorResults& results) -{ - m_locator->locatePointsWithinRadius(x, y, z, radius, results); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/PointLocator.h b/smtk/mesh/core/PointLocator.h deleted file mode 100644 index b4f6a46b76fa6481e163b4e35cde7476b929bce4..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/PointLocator.h +++ /dev/null @@ -1,96 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_PointLocator_h -#define smtk_mesh_core_PointLocator_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/Interface.h" -#include "smtk/mesh/core/PointSet.h" - -#include - -namespace smtk -{ -namespace mesh -{ - -//PointLocator facilitates searching for points in 3D. -//Currently the class has a fairly narrow API as we are still iterating -//what features are required by a smtk::mesh::PointLocator -// -// -// -class SMTKCORE_EXPORT PointLocator -{ -public: - typedef smtk::mesh::PointLocatorImpl::Results LocatorResults; - - //Construct a point locator given an existing set of points - //These are the points you will be searching against - PointLocator(const smtk::mesh::PointSet& ps); - - //Construct a point locator given a coordinate generating function. - //Based on the backend these points maybe be added to the resource for - //duration of the PointLocator - PointLocator( - smtk::mesh::ResourcePtr resource, - std::size_t numPoints, - const std::function(std::size_t)>& coordinates); - PointLocator( - const smtk::mesh::ResourcePtr resource, - std::size_t numPoints, - const double* const xyzs) - : PointLocator(resource, numPoints, [&](std::size_t i) { - return std::array({ { xyzs[3 * i], xyzs[3 * i + 1], xyzs[3 * i + 2] } }); - }) - { - } - PointLocator( - const smtk::mesh::ResourcePtr resource, - std::size_t numPoints, - const float* const xyzs) - : PointLocator(resource, numPoints, [&](std::size_t i) { - return std::array({ { static_cast(xyzs[3 * i]), - static_cast(xyzs[3 * i + 1]), - static_cast(xyzs[3 * i + 2]) } }); - }) - { - } - - //returns all the point ids that are inside the locator - smtk::mesh::HandleRange range() const; - - //Find the set of points that are within the radius of a single point. - // - //See smtk/mesh/core/Interface.h for the full implementation of Results - //but the basics are: - // - // - //struct Results - // { - // smtk::mesh::HandleRange pointIds; - // std::vector sqDistances; - // std::vector x_s, y_s, z_s; - // bool want_sqDistances; - // bool want_Coordinates; - // }; - // - void find(double x, double y, double z, double radius, LocatorResults& results); - -private: - smtk::mesh::PointLocatorImplPtr m_locator; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/PointSet.cxx b/smtk/mesh/core/PointSet.cxx deleted file mode 100644 index 50f194e8161146ff600487e45f8d1efcde19cd12..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/PointSet.cxx +++ /dev/null @@ -1,215 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/PointSet.h" - -#include "smtk/mesh/core/Interface.h" -#include "smtk/mesh/core/Resource.h" - -namespace smtk -{ -namespace mesh -{ - -PointSet::PointSet(const smtk::mesh::ResourcePtr& parent, const smtk::mesh::HandleRange& points) - : m_parent(parent) - , m_points(points) -{ -} - -PointSet::PointSet( - const smtk::mesh::ConstResourcePtr& parent, - const smtk::mesh::HandleRange& points) - : m_parent(std::const_pointer_cast(parent)) - , m_points(points) -{ -} - -PointSet::PointSet( - const smtk::mesh::ResourcePtr& parent, - const std::vector& points) - : m_parent(parent) -{ - for (const auto& point : points) - { - m_points.insert(point); - } -} - -PointSet::PointSet( - const smtk::mesh::ResourcePtr& parent, - const std::set& points) - : m_parent(parent) -{ - for (const auto& point : points) - { - m_points.insert(point); - } -} - -PointSet::PointSet(const smtk::mesh::PointSet& other) = default; - -PointSet::~PointSet() = default; - -PointSet& PointSet::operator=(const PointSet& other) -{ - m_parent = other.m_parent; - m_points = other.m_points; - return *this; -} - -bool PointSet::operator==(const PointSet& other) const -{ - return m_parent == other.m_parent && m_points == other.m_points; -} - -bool PointSet::operator!=(const PointSet& other) const -{ - return !(*this == other); -} - -bool PointSet::is_empty() const -{ - return m_points.empty(); -} - -std::size_t PointSet::size() const -{ - return m_points.size(); -} - -std::size_t PointSet::numberOfPoints() const -{ - return m_points.size(); -} - -bool PointSet::contains(const smtk::mesh::Handle& pointId) const -{ - return m_points.find(pointId) != m_points.end(); -} - -std::size_t PointSet::find(const smtk::mesh::Handle& pointId) const -{ - return smtk::mesh::rangeIndex(m_points, pointId); -} - -bool PointSet::get(double* xyz) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->getCoordinates(m_points, xyz); -} - -bool PointSet::get(std::vector& xyz) const -{ - const std::size_t size = this->numberOfPoints(); - xyz.resize(size * 3); - - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->getCoordinates(m_points, xyz.data()); -} - -bool PointSet::get(float* xyz) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->getCoordinates(m_points, xyz); -} - -bool PointSet::get(std::vector& xyz) const -{ - const std::size_t size = this->numberOfPoints(); - xyz.resize(size * 3); - - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->getCoordinates(m_points, xyz.data()); -} - -bool PointSet::set(const double* const xyz) const -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->setCoordinates(m_points, xyz); -} - -bool PointSet::set(const std::vector& xyz) const -{ - if (xyz.size() < this->numberOfPoints() * 3) - { - return false; - } - - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->setCoordinates(m_points, xyz.data()); -} - -bool PointSet::set(const float* const xyz) -{ - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->setCoordinates(m_points, xyz); -} - -bool PointSet::set(const std::vector& xyz) -{ - if (xyz.size() < this->numberOfPoints() * 3) - { - return false; - } - - const smtk::mesh::InterfacePtr& iface = m_parent->interface(); - return iface->setCoordinates(m_points, xyz.data()); -} - -/**\brief Get the parent resource that this meshset belongs to. - * - */ -const smtk::mesh::ResourcePtr& PointSet::resource() const -{ - return m_parent; -} - -PointSet set_intersect(const PointSet& a, const PointSet& b) -{ - if (a.m_parent != b.m_parent) - { //return an empty PointSet if the resources don't match - return smtk::mesh::PointSet(a.m_parent, smtk::mesh::HandleRange()); - } - - smtk::mesh::HandleRange result = a.m_points & b.m_points; - return smtk::mesh::PointSet(a.m_parent, result); -} - -PointSet set_difference(const PointSet& a, const PointSet& b) -{ - if (a.m_parent != b.m_parent) - { //return an empty PointSet if the resources don't match - return smtk::mesh::PointSet(a.m_parent, smtk::mesh::HandleRange()); - } - - smtk::mesh::HandleRange result = a.m_points - b.m_points; - return smtk::mesh::PointSet(a.m_parent, result); -} - -PointSet set_union(const PointSet& a, const PointSet& b) -{ - if (a.m_parent != b.m_parent) - { //return an empty PointSet if the resources don't match - return smtk::mesh::PointSet(a.m_parent, smtk::mesh::HandleRange()); - } - - smtk::mesh::HandleRange result = a.m_points | b.m_points; - return smtk::mesh::PointSet(a.m_parent, result); -} - -void for_each(const PointSet& a, PointForEach& filter) -{ - const smtk::mesh::InterfacePtr& iface = a.m_parent->interface(); - filter.m_resource = a.m_parent; - iface->pointForEach(a.m_points, filter); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/PointSet.h b/smtk/mesh/core/PointSet.h deleted file mode 100644 index 5e10b3947a46a456ffe642b5e19bf2c66dc2736c..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/PointSet.h +++ /dev/null @@ -1,147 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_PointSet_h -#define smtk_mesh_core_PointSet_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/QueryTypes.h" - -namespace smtk -{ -namespace mesh -{ - -//forward declare -class PointLocator; - -class SMTKCORE_EXPORT PointSet -{ - friend SMTKCORE_EXPORT PointSet set_intersect(const PointSet& a, const PointSet& b); - friend SMTKCORE_EXPORT PointSet set_difference(const PointSet& a, const PointSet& b); - friend SMTKCORE_EXPORT PointSet set_union(const PointSet& a, const PointSet& b); - friend SMTKCORE_EXPORT void for_each(const PointSet& a, PointForEach& filter); - -public: - PointSet(const smtk::mesh::ResourcePtr& parent, const smtk::mesh::HandleRange& points); - PointSet(const smtk::mesh::ConstResourcePtr& parent, const smtk::mesh::HandleRange& points); - - //construct a PointSet that represents an arbitrary unknown subset of points - //that are children of the handle via an explicit vector of point ids. While - //this method is inefficient, it is useful for the python bindings where - // is converted to a list. - PointSet(const smtk::mesh::ResourcePtr& parent, const std::vector& points); - - //construct a PointSet that represents an arbitrary unknown subset of points - //that are children of the handle via an explicit set of point ids. This - //constructor is preferred over the variant that takes a std::vector. - PointSet(const smtk::mesh::ResourcePtr& parent, const std::set& points); - - //Copy Constructor required for rule of 3 - PointSet(const PointSet& other); - - //required to be in the cpp file as we hold a HandleRange - ~PointSet(); - - //Copy assignment operator required for rule of 3 - PointSet& operator=(const PointSet& other); - bool operator==(const PointSet& other) const; - bool operator!=(const PointSet& other) const; - - bool is_empty() const; - std::size_t size() const; - - //Get the number of points in the array - std::size_t numberOfPoints() const; - - //returns true if the point set contains a given point id - bool contains(const smtk::mesh::Handle& pointId) const; - - //returns the index in this point set for the given point id - std::size_t find(const smtk::mesh::Handle& pointId) const; - - //Get all the point coordinates and store them in the passed in std::vector - bool get(std::vector& xyz) const; - - //Set all the point coordinates to the values from the input std::vector - bool set(const std::vector& xyz) const; - - // Skipping the following: - // double*, and float* they are not nicely wrapped so the length is unknown - // std::vector& skipped since python uses doubles not floats - - //Get all the point coordinates and store them in a pre-allocated buffer - bool get(double* xyz) const; - - //Get all the point coordinates and store them in a pre-allocated buffer - //Floats are not how we store the coordinates internally, so asking for - //the coordinates in such a manner could cause data inaccuracies to appear - //so generally this is only used if you fully understand the input domain - bool get(float* xyz) const; - - //Get all the point coordinates and store them in a std::vector - //Floats are not how we store the coordinates internally, so asking for - //the coordinates in such a manner could cause data inaccuracies to appear - //so generally this is only used if you fully understand the input domain - bool get(std::vector& xyz) const; - - //Set all the point coordinates from the pre-allocated buffer. The - //buffer is required to have a length of size*3. - bool set(const double* xyz) const; - - //Set all the point coordinates from the pre-allocated buffer. The - //buffer is required to have a length of size*3. - bool set(const float* xyz); - - //Set all the point coordinates from the pre-allocated buffer. The - //buffer is required to have a length of size*3. - bool set(const std::vector& xyz); - - //get the underlying HandleRange that this PointSet represents - const smtk::mesh::HandleRange& range() const { return m_points; } - - //get the underlying resource that this PointSet belongs to - const smtk::mesh::ResourcePtr& resource() const; - -private: - smtk::mesh::ResourcePtr m_parent; - smtk::mesh::HandleRange m_points; -}; - -//intersect two set of points, placing the results in the return points object. -//This uses a point id based comparison, so points that have duplicate -//coordinates but different id's are considered to not intersect -//Note: If the points come from different resources the result will -//always be empty -SMTKCORE_EXPORT PointSet set_intersect(const PointSet& a, const PointSet& b); - -//subtract points b from a, placing the results in the return points object. -//This uses a point id based comparison, so points that have duplicate -//coordinates but different id's are considered to not intersect -//Note: If the points come from different resources the result will -//always be empty -SMTKCORE_EXPORT PointSet set_difference(const PointSet& a, const PointSet& b); - -//union two set of points, placing the results in the return points object. -//This uses a point id based comparison, so points that have duplicate -//coordinates but different id's are considered to not intersect -//Note: If the points come from different resources the result will -//always be empty -SMTKCORE_EXPORT PointSet set_union(const PointSet& a, const PointSet& b); - -//apply a for_each point operator on each point in a container. -SMTKCORE_EXPORT void for_each(const PointSet& a, PointForEach& filter); -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/QueryTypes.cxx b/smtk/mesh/core/QueryTypes.cxx deleted file mode 100644 index 1c2f8364d6e7b245997750d3d99545af8c1c7348..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/QueryTypes.cxx +++ /dev/null @@ -1,20 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/QueryTypes.h" - -namespace smtk -{ -namespace mesh -{ - -template class OpaqueTag<16>; -} -} // namespace smtk diff --git a/smtk/mesh/core/QueryTypes.h b/smtk/mesh/core/QueryTypes.h deleted file mode 100644 index 76c21599a34e7dc718e26c1697480f861195cf88..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/QueryTypes.h +++ /dev/null @@ -1,197 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_QueryTypes_h -#define smtk_mesh_core_QueryTypes_h - -//Query Types is a convenience header, whose goal is to make it easier -//for users to query a manager -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/DimensionTypes.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/Handle.h" - -#include "smtk/common/UUID.h" - -namespace smtk -{ -namespace mesh -{ - -class SMTKCORE_EXPORT IntegerTag -{ -public: - explicit IntegerTag(int value) - : m_value(value) - { - } - - int value() const { return m_value; } - - //custom operators to make comparing tags easy - bool operator<(const IntegerTag& other) const { return m_value < other.m_value; } - bool operator==(const IntegerTag& other) const { return m_value == other.m_value; } - bool operator!=(const IntegerTag& other) const { return m_value != other.m_value; } - -private: - int m_value; -}; - -class SMTKCORE_EXPORT Domain : public IntegerTag -{ -public: - explicit Domain(int value) - : IntegerTag(value) - { - } -}; - -class SMTKCORE_EXPORT Dirichlet : public IntegerTag -{ -public: - explicit Dirichlet(int value) - : IntegerTag(value) - { - } -}; - -class SMTKCORE_EXPORT Neumann : public IntegerTag -{ -public: - explicit Neumann(int value) - : IntegerTag(value) - { - } -}; - -template -class SMTKCORE_EXPORT OpaqueTag -{ -public: - explicit OpaqueTag(const unsigned char* value) - : m_value(value, value + S) - { - } - - static int size() { return S; } - - const unsigned char* value() const { return m_value.data(); } - - //custom operators to make comparing tags easy - bool operator<(const OpaqueTag& other) const - { - for (int i = 0; i < S; ++i) - if (m_value < other.m_value) - return true; - else if (m_value > other.m_value) - return false; - return false; - } - bool operator==(const OpaqueTag& other) const - { - for (int i = 0; i < S; ++i) - if (m_value != other.m_value) - return false; - return true; - } - bool operator!=(const OpaqueTag& other) const - { - for (int i = 0; i < S; ++i) - if (m_value != other.m_value) - return true; - return false; - } - -private: - std::vector m_value; -}; - -class SMTKCORE_EXPORT UUIDTag : public OpaqueTag -{ -public: - explicit UUIDTag(const smtk::common::UUID& value) - : OpaqueTag(value.begin()) - { - } - - smtk::common::UUID uuid() const - { - return smtk::common::UUID(this->value(), this->value() + smtk::common::UUID::SIZE); - } -}; - -class SMTKCORE_EXPORT Id : public UUIDTag -{ -public: - explicit Id(const smtk::common::UUID& value) - : UUIDTag(value) - { - } -}; - -class SMTKCORE_EXPORT Model : public UUIDTag -{ -public: - explicit Model(const smtk::common::UUID& value) - : UUIDTag(value) - { - } -}; - -class SMTKCORE_EXPORT CellFieldTag -{ -public: - explicit CellFieldTag(const std::string& name) - : m_name(name) - { - } - - //custom operators to make comparing tags easy - bool operator<(const CellFieldTag& other) const { return m_name < other.m_name; } - bool operator==(const CellFieldTag& other) const { return m_name == other.m_name; } - bool operator!=(const CellFieldTag& other) const { return m_name != other.m_name; } - - std::string name() const { return m_name; } - -private: - std::string m_name; -}; - -class SMTKCORE_EXPORT PointFieldTag -{ -public: - explicit PointFieldTag(const std::string& name) - : m_name(name) - { - } - - //custom operators to make comparing tags easy - bool operator<(const PointFieldTag& other) const { return m_name < other.m_name; } - bool operator==(const PointFieldTag& other) const { return m_name == other.m_name; } - bool operator!=(const PointFieldTag& other) const { return m_name != other.m_name; } - - std::string name() const { return m_name; } - -private: - std::string m_name; -}; - -enum ContainmentType -{ - PartiallyContained = 1, - FullyContained = 2 -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/Resource.cxx b/smtk/mesh/core/Resource.cxx deleted file mode 100644 index 3ab3fbefd68a6e69f1a25e2902daf76f8db00a8c..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/Resource.cxx +++ /dev/null @@ -1,662 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/core/Component.h" - -#include "smtk/mesh/core/queries/BoundingBox.h" - -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/common/UUIDGenerator.h" -#include "smtk/model/EntityIterator.h" - -namespace smtk -{ -namespace mesh -{ - -class Resource::InternalImpl -{ -public: - InternalImpl() - : Interface(smtk::mesh::moab::make_interface()) - { - } - - InternalImpl(smtk::mesh::InterfacePtr interface) - : Interface(interface) - { - } - - [[nodiscard]] const smtk::mesh::InterfacePtr& mesh_iface() const { return this->Interface; } - - [[nodiscard]] smtk::mesh::Handle mesh_root_handle() const { return this->Interface->getRoot(); } - -private: - smtk::mesh::InterfacePtr Interface; -}; - -namespace -{ -typedef std::tuple QueryList; -} - -Resource::Resource() - : Superclass(smtk::common::UUIDGenerator::instance().random()) - , m_internals(new InternalImpl()) -{ - queries().registerQueries(); - m_internals->mesh_iface()->registerQueries(*this); -} - -Resource::Resource(const smtk::common::UUID& resourceID) - : smtk::resource::DerivedFrom(resourceID) - , m_internals(new InternalImpl()) -{ - queries().registerQueries(); - m_internals->mesh_iface()->registerQueries(*this); -} - -Resource::Resource(smtk::mesh::InterfacePtr interface) - : smtk::resource::DerivedFrom( - smtk::common::UUIDGenerator::instance().random()) - , m_internals(new InternalImpl(interface)) -{ - queries().registerQueries(); - interface->registerQueries(*this); -} - -Resource::Resource(const smtk::common::UUID& resourceID, smtk::mesh::InterfacePtr interface) - : smtk::resource::DerivedFrom(resourceID) - , m_internals(new InternalImpl(interface)) -{ - queries().registerQueries(); - interface->registerQueries(*this); -} - -Resource::~Resource() -{ - // Our interface query caches should be flushed before our interface goes out - // of scope. - queries().caches().clear(); - - delete m_internals; -} - -smtk::resource::ComponentPtr Resource::find(const smtk::common::UUID& compId) const -{ - return std::static_pointer_cast( - Component::create(std::const_pointer_cast(shared_from_this()), compId)); -} - -std::function Resource::queryOperation( - const std::string& queryString) const -{ - // TODO - (void)queryString; - return [](const resource::Component& /*unused*/) { return true; }; -} - -// visit all components in the resource. -void Resource::visit(smtk::resource::Component::Visitor& visitor) const -{ - class Visit : public smtk::mesh::MeshForEach - { - public: - Visit(smtk::resource::Component::Visitor& visitor) - : m_visitor(visitor) - { - } - - void forMesh(smtk::mesh::MeshSet& mesh) override - { - m_visitor(smtk::mesh::Component::create(mesh)); - } - - private: - smtk::resource::Component::Visitor& m_visitor; - }; - - Visit visit_(visitor); - - smtk::mesh::for_each(this->meshes(), visit_); -} - -const smtk::mesh::InterfacePtr& Resource::interface() const -{ - return m_internals->mesh_iface(); -} - -void Resource::swapInterfaces(smtk::mesh::ResourcePtr& other) -{ - smtk::mesh::Resource::InternalImpl* temp = other->m_internals; - other->m_internals = m_internals; - m_internals = temp; -} - -bool Resource::isValid() const -{ - //make sure we have a valid uuid, and that our internals are valid - return !this->id().isNull(); -} - -bool Resource::isModified() const -{ - //make sure we have a valid uuid, and that our internals are valid - return this->interface()->isModified(); -} - -const smtk::common::FileLocation& Resource::readLocation() const -{ - return m_readLocation; -} - -void Resource::readLocation(const smtk::common::FileLocation& n) -{ - m_readLocation = n; - //if the write location hasn't been set, update it to be the read location - if (m_writeLocation.empty()) - { - m_writeLocation = n; - } -} - -const smtk::common::FileLocation& Resource::writeLocation() const -{ - return m_writeLocation; -} - -void Resource::writeLocation(const smtk::common::FileLocation& n) -{ - m_writeLocation = n; -} - -void Resource::clearReadWriteLocations() -{ - m_readLocation.clear(); - m_writeLocation.clear(); -} - -std::string Resource::interfaceName() const -{ - return this->interface()->name(); -} - -const smtk::common::UUID Resource::entity() const -{ - return this->id(); -} - -std::size_t Resource::numberOfMeshes() const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - return iface->numMeshes(m_internals->mesh_root_handle()); -} - -smtk::mesh::TypeSet Resource::types() const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - return iface->computeTypes(iface->getMeshsets(handle)); -} - -smtk::mesh::CellSet Resource::cells() const -{ - smtk::mesh::MeshSet ms(this->shared_from_this(), m_internals->mesh_root_handle()); - return ms.cells(); -} - -smtk::mesh::PointSet Resource::points() const -{ - smtk::mesh::MeshSet ms(this->shared_from_this(), m_internals->mesh_root_handle()); - return ms.points(); -} - -smtk::mesh::PointConnectivity Resource::pointConnectivity() const -{ - smtk::mesh::MeshSet ms(this->shared_from_this(), m_internals->mesh_root_handle()); - return ms.pointConnectivity(); -} - -void Resource::assignDefaultNames() -{ - smtk::resource::Component::Visitor nameAssigner = - [this](const smtk::resource::Component::Ptr& comp) { - auto mset = comp ? comp->as() : nullptr; - if (!mset || !mset->name().empty()) - { - return; - } - - // Keep generating names until we find an unused one. - std::string nameToTry; - do - { - m_nameCounter++; - std::ostringstream namer; - namer << "mesh " << m_nameCounter; - nameToTry = namer.str(); - } while (this->meshes(nameToTry).isValid()); - mset->mesh().setName(nameToTry); - }; - this->visit(nameAssigner); -} - -smtk::mesh::MeshSet Resource::meshes() const -{ - return smtk::mesh::MeshSet(this->shared_from_this(), m_internals->mesh_root_handle()); -} - -std::vector Resource::meshNames() const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - smtk::mesh::HandleRange entities = iface->getMeshsets(handle); - return iface->computeNames(entities); -} - -smtk::mesh::MeshSet Resource::meshes(smtk::mesh::DimensionType dim) const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - const int dim_value = static_cast(dim); - - smtk::mesh::HandleRange entities = iface->getMeshsets(handle, dim_value); - return smtk::mesh::MeshSet(this->shared_from_this(), m_internals->mesh_root_handle(), entities); -} - -smtk::mesh::MeshSet Resource::meshes(const std::string& name) const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - smtk::mesh::HandleRange entities = iface->getMeshsets(handle, name); - return smtk::mesh::MeshSet(this->shared_from_this(), m_internals->mesh_root_handle(), entities); -} - -smtk::mesh::MeshSet Resource::meshes(const smtk::mesh::Domain& d) const -{ - return this->domainMeshes(d); -} - -smtk::mesh::MeshSet Resource::meshes(const smtk::mesh::Dirichlet& d) const -{ - return this->dirichletMeshes(d); -} - -smtk::mesh::MeshSet Resource::meshes(const smtk::mesh::Neumann& n) const -{ - return this->neumannMeshes(n); -} - -smtk::mesh::CellSet Resource::cells(smtk::mesh::CellType cellType) const -{ - smtk::mesh::MeshSet ms(this->shared_from_this(), m_internals->mesh_root_handle()); - return ms.cells(cellType); -} - -smtk::mesh::CellSet Resource::cells(smtk::mesh::CellTypes cellTypes) const -{ - smtk::mesh::MeshSet ms(this->shared_from_this(), m_internals->mesh_root_handle()); - return ms.cells(cellTypes); -} - -smtk::mesh::CellSet Resource::cells(smtk::mesh::DimensionType dim) const -{ - smtk::mesh::MeshSet ms(this->shared_from_this(), m_internals->mesh_root_handle()); - return ms.cells(dim); -} - -bool Resource::classifyTo(const smtk::model::ResourcePtr& resource) -{ - smtk::model::ResourcePtr currentResource = this->classifiedTo(); - if (currentResource != nullptr) - { - this->links().removeLinksTo( - std::static_pointer_cast(currentResource), ClassificationRole); - } - return this->links() - .addLinkTo( - std::static_pointer_cast(resource), ClassificationRole) - .first != smtk::common::UUID::null(); -} - -smtk::model::ResourcePtr Resource::classifiedTo() const -{ - auto classifiedObjects = this->links().linkedTo(ClassificationRole); - return ( - !classifiedObjects.empty() - ? std::dynamic_pointer_cast(*classifiedObjects.begin()) - : smtk::model::ResourcePtr()); -} - -smtk::mesh::TypeSet Resource::findAssociatedTypes(const smtk::model::EntityRef& eref) const -{ - return this->findAssociatedMeshes(eref).types(); -} - -smtk::mesh::MeshSet Resource::findAssociatedMeshes(const smtk::model::EntityRef& eref) const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - return smtk::mesh::MeshSet( - this->shared_from_this(), handle, iface->findAssociations(handle, eref.entity())); -} - -smtk::mesh::MeshSet Resource::findAssociatedMeshes( - const smtk::model::EntityRef& eref, - smtk::mesh::DimensionType dim) const -{ - smtk::mesh::MeshSet unfiltered = this->findAssociatedMeshes(eref); - return unfiltered.subset(dim); -} - -smtk::mesh::CellSet Resource::findAssociatedCells(const smtk::model::EntityRef& eref) const -{ - smtk::mesh::MeshSet ms = this->findAssociatedMeshes(eref); - return ms.cells(); -} - -smtk::mesh::CellSet Resource::findAssociatedCells( - const smtk::model::EntityRef& eref, - smtk::mesh::CellType cellType) const -{ - smtk::mesh::MeshSet ms = this->findAssociatedMeshes(eref); - return ms.cells(cellType); -} - -smtk::mesh::CellSet Resource::findAssociatedCells( - const smtk::model::EntityRef& eref, - smtk::mesh::DimensionType dim) const -{ - smtk::mesh::MeshSet ms = this->findAssociatedMeshes(eref, dim); - return ms.cells(); -} - -smtk::mesh::TypeSet Resource::findAssociatedTypes(const smtk::common::UUID& id) const -{ - return this->findAssociatedMeshes(id).types(); -} - -smtk::mesh::MeshSet Resource::findAssociatedMeshes(const smtk::common::UUID& id) const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - return smtk::mesh::MeshSet(this->shared_from_this(), handle, iface->findAssociations(handle, id)); -} - -smtk::mesh::MeshSet Resource::findAssociatedMeshes( - const smtk::common::UUID& id, - smtk::mesh::DimensionType dim) const -{ - smtk::mesh::MeshSet unfiltered = this->findAssociatedMeshes(id); - return unfiltered.subset(dim); -} - -smtk::mesh::CellSet Resource::findAssociatedCells(const smtk::common::UUID& id) const -{ - smtk::mesh::MeshSet ms = this->findAssociatedMeshes(id); - return ms.cells(); -} - -smtk::mesh::CellSet Resource::findAssociatedCells( - const smtk::common::UUID& id, - smtk::mesh::CellType cellType) const -{ - smtk::mesh::MeshSet ms = this->findAssociatedMeshes(id); - return ms.cells(cellType); -} - -smtk::mesh::CellSet Resource::findAssociatedCells( - const smtk::common::UUID& id, - smtk::mesh::DimensionType dim) const -{ - smtk::mesh::MeshSet ms = this->findAssociatedMeshes(id, dim); - return ms.cells(); -} - -smtk::mesh::TypeSet Resource::findAssociatedTypes(smtk::model::EntityIterator& refIt) const -{ - return this->findAssociatedMeshes(refIt).types(); -} - -smtk::mesh::MeshSet Resource::findAssociatedMeshes(smtk::model::EntityIterator& refIt) const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - smtk::mesh::HandleRange range; - for (refIt.begin(); !refIt.isAtEnd(); ++refIt) - { - range = range | iface->findAssociations(handle, (*refIt).entity()); - } - - return smtk::mesh::MeshSet(this->shared_from_this(), handle, range); -} - -smtk::mesh::MeshSet Resource::findAssociatedMeshes( - smtk::model::EntityIterator& refIt, - smtk::mesh::DimensionType dim) const -{ - smtk::mesh::MeshSet unfiltered = this->findAssociatedMeshes(refIt); - return unfiltered.subset(dim); -} - -smtk::mesh::CellSet Resource::findAssociatedCells(smtk::model::EntityIterator& refIt) const -{ - smtk::mesh::MeshSet ms = this->findAssociatedMeshes(refIt); - return ms.cells(); -} - -smtk::mesh::CellSet Resource::findAssociatedCells( - smtk::model::EntityIterator& refIt, - smtk::mesh::CellType cellType) const -{ - smtk::mesh::MeshSet ms = this->findAssociatedMeshes(refIt); - return ms.cells(cellType); -} - -smtk::mesh::CellSet Resource::findAssociatedCells( - smtk::model::EntityIterator& refIt, - smtk::mesh::DimensionType dim) const -{ - smtk::mesh::MeshSet ms = this->findAssociatedMeshes(refIt, dim); - return ms.cells(); -} - -bool Resource::setAssociation( - const smtk::model::EntityRef& eref, - const smtk::mesh::MeshSet& meshset) -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - // This causes the eref to become a meshset with the tag MODEL; - // then all meshsets in m_range become child meshsets of eref: - return iface->setAssociation(eref.entity(), meshset.m_range); -} - -bool Resource::hasAssociations() const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - smtk::mesh::HandleRange entities = iface->getMeshsets(handle); - - smtk::common::UUIDArray associations = iface->computeModelEntities(entities); - return !associations.empty(); -} - -bool Resource::associateToModel(const smtk::common::UUID& uuid) -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - - //before we associate this model make sure we are not already associated - //to this model UUID. This is needed so that we are serializing/de-serializing - //meshes we don't set the modify bit to true, when we re-associate to the model - //and already had that info - if (iface->rootAssociation() != uuid) - { - return iface->setRootAssociation(uuid); - } - return true; -} - -bool Resource::isAssociatedToModel() const -{ - return this->associatedModel() != smtk::common::UUID::null(); -} - -smtk::common::UUID Resource::associatedModel() const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - return iface->rootAssociation(); -} - -smtk::mesh::MeshSet Resource::createMesh( - const smtk::mesh::CellSet& cells, - const smtk::common::UUID& uuid) -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - - smtk::mesh::HandleRange entities; - if (cells.m_parent == this->shared_from_this()) - { - smtk::mesh::Handle meshSetHandle; - const bool meshCreated = iface->createMesh(cells.range(), meshSetHandle); - if (meshCreated) - { - entities.insert(meshSetHandle); - if (uuid) - { - iface->setId(meshSetHandle, uuid); - } - else - { - iface->setId(meshSetHandle, smtk::common::UUIDGenerator::instance().random()); - } - } - } - return smtk::mesh::MeshSet(this->shared_from_this(), m_internals->mesh_root_handle(), entities); -} - -bool Resource::removeMeshes(const smtk::mesh::MeshSet& meshesToDelete) -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - if (meshesToDelete.m_parent == this->shared_from_this()) - { - //When deleting a MeshSet we need to find all cells that - //are not used by any other mesh. - - //find all other meshes - smtk::mesh::MeshSet all_OtherMeshes = - smtk::mesh::set_difference(this->meshes(), meshesToDelete); - - //now find the cells that are only used by the mesh we are about to delete. - smtk::mesh::CellSet cellsToDelete = - smtk::mesh::set_difference(meshesToDelete.cells(), all_OtherMeshes.cells()); - //delete our mesh and cells that aren't used by any one else - const bool deletedMeshes = iface->deleteHandles(meshesToDelete.m_range); - const bool deletedCells = iface->deleteHandles(cellsToDelete.range()); - return deletedMeshes && deletedCells; - } - return false; -} - -std::vector Resource::domains() const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - smtk::mesh::HandleRange entities = iface->getMeshsets(handle); - return iface->computeDomainValues(entities); -} - -smtk::mesh::MeshSet Resource::domainMeshes(const smtk::mesh::Domain& d) const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - smtk::mesh::HandleRange entities = iface->getMeshsets(handle, d); - return smtk::mesh::MeshSet(this->shared_from_this(), m_internals->mesh_root_handle(), entities); -} - -bool Resource::setDomainOnMeshes(const smtk::mesh::MeshSet& meshes, const smtk::mesh::Domain& d) -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - if (meshes.m_parent == this->shared_from_this()) - { - return iface->setDomain(meshes.m_range, d); - } - return false; -} - -std::vector Resource::dirichlets() const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - smtk::mesh::HandleRange entities = iface->getMeshsets(handle); - return iface->computeDirichletValues(entities); -} - -smtk::mesh::MeshSet Resource::dirichletMeshes(const smtk::mesh::Dirichlet& d) const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - smtk::mesh::HandleRange entities = iface->getMeshsets(handle, d); - return smtk::mesh::MeshSet(this->shared_from_this(), m_internals->mesh_root_handle(), entities); -} - -bool Resource::setDirichletOnMeshes( - const smtk::mesh::MeshSet& meshes, - const smtk::mesh::Dirichlet& d) -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - if (meshes.m_parent == this->shared_from_this()) - { - return iface->setDirichlet(meshes.m_range, d); - } - return false; -} - -std::vector Resource::neumanns() const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - smtk::mesh::HandleRange entities = iface->getMeshsets(handle); - return iface->computeNeumannValues(entities); -} - -smtk::mesh::MeshSet Resource::neumannMeshes(const smtk::mesh::Neumann& n) const -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle = m_internals->mesh_root_handle(); - - smtk::mesh::HandleRange entities = iface->getMeshsets(handle, n); - return smtk::mesh::MeshSet(this->shared_from_this(), m_internals->mesh_root_handle(), entities); -} - -bool Resource::setNeumannOnMeshes(const smtk::mesh::MeshSet& meshes, const smtk::mesh::Neumann& n) -{ - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - if (meshes.m_parent == this->shared_from_this()) - { - return iface->setNeumann(meshes.m_range, n); - } - return false; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/Resource.h b/smtk/mesh/core/Resource.h deleted file mode 100644 index f7e9dd502f7ca0c5f4c6c3d9a86b4f47ac8dc826..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/Resource.h +++ /dev/null @@ -1,351 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_Resource_h -#define smtk_mesh_core_Resource_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" -#include "smtk/SharedFromThis.h" - -#include "smtk/common/FileLocation.h" -#include "smtk/common/UUID.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/Interface.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/PointConnectivity.h" -#include "smtk/mesh/core/QueryTypes.h" -#include "smtk/mesh/core/TypeSet.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Model.h" -#include "smtk/model/Resource.h" - -#include "smtk/geometry/Resource.h" - -#include "smtk/resource/DerivedFrom.h" - -#include - -namespace smtk -{ -//forward declare friends -namespace io -{ -class ReadMesh; -} -namespace model -{ -class EntityIterator; -} -namespace mesh -{ - -//Flyweight interface around a moab database of meshes. -class SMTKCORE_EXPORT Resource - : public smtk::resource::DerivedFrom -{ - //default constructor generates an invalid resource - Resource(); - - //Construct a resource with the default interface. - Resource(const smtk::common::UUID& resourceID); - - //Construct a valid resource that has an associated interface - Resource(smtk::mesh::InterfacePtr interface); - - //Construct a valid resource that has an associated interface - Resource(const smtk::common::UUID& resourceID, smtk::mesh::InterfacePtr interface); - -public: - smtkTypeMacro(smtk::mesh::Resource); - smtkSuperclassMacro(smtk::resource::DerivedFrom); - smtkSharedPtrCreateMacro(smtk::resource::PersistentObject); - - Resource(const Resource& other) = delete; - Resource& operator=(const Resource& other) = delete; - - // typedef referring to the parent resource. - typedef smtk::geometry::Resource ParentResource; - - /// A mesh resource may be classified to a model, indicating the mesh set - /// discretizes the linked model component. - static constexpr smtk::resource::Links::RoleType ClassificationRole = -3; - static constexpr smtk::resource::Links::RoleType classificationRole() - { - return Resource::ClassificationRole; - } - - static smtk::shared_ptr create(const smtk::common::UUID& resourceID) - { - smtk::shared_ptr shared(new Resource(resourceID)); - return smtk::static_pointer_cast(shared); - } - - static smtk::shared_ptr create(smtk::mesh::InterfacePtr interface) - { - smtk::shared_ptr shared(new Resource(interface)); - return smtk::static_pointer_cast(shared); - } - - static smtk::shared_ptr create( - const smtk::common::UUID& resourceID, - smtk::mesh::InterfacePtr interface) - { - smtk::shared_ptr shared(new Resource(resourceID, interface)); - return smtk::static_pointer_cast(shared); - } - - ~Resource() override; - - resource::ComponentPtr find(const common::UUID& compId) const override; - std::function queryOperation(const std::string&) const override; - - // visit all components in a resource. - void visit(resource::Component::Visitor& v) const override; - - //determine if the given Resource is valid. - bool isValid() const; - - //determine if the Resource has been modified. Being Modified means that - //the version we would write out to disk would differ from the version that - //we loaded from disk. If a resource started as in-memory it - //is considered modified once it is not empty. - //Every time the resource is saved to disk, the Modified flag will be - //reset to false. - bool isModified() const; - - //get the file that this resource was created from - //will return an empty FileLocation if this resource wasn't read from file - const smtk::common::FileLocation& readLocation() const; - - //set the file that this resource should be saved to. - //By default this is set to be the same as the readLocation() - void writeLocation(const smtk::common::FileLocation& path); - void writeLocation(const std::string& path) - { - this->writeLocation(smtk::common::FileLocation(path)); - } - const smtk::common::FileLocation& writeLocation() const; - - //clear both the read and write locations for the resource. This - //is generally done when de-serializing a resource and the read and write - //locations are going to be deleted by the calling code. - void clearReadWriteLocations(); - - //get a string the identifies the interface type of the resource - // valid types are: - // "moab" - // "json" - //Note: all names will be all lower-case - std::string interfaceName() const; - - //fetch the entity id for this uuid - const smtk::common::UUID entity() const; - - std::size_t numberOfMeshes() const; - - //Queries on the full Resource - smtk::mesh::TypeSet types() const; - smtk::mesh::MeshSet meshes() const; //all meshes - smtk::mesh::CellSet cells() const; //all cells - smtk::mesh::PointSet points() const; //all points - - //todo: - //find all cells of a given dimension that are attached to ? - //smtk::mesh::CellSet connectivity( smtk::mesh::DimensionType dim ); - - smtk::mesh::PointConnectivity pointConnectivity() - const; //all point connectivity info for all cells - - /// Assign a machine-generated name to any mesh component that does not have a user-assigned name. - void assignDefaultNames(); - - //For any mesh set that has a name we return that name. It is possible - //that the we have un-named mesh sets. - std::vector meshNames() const; - - //Find all meshes that have at least one cell of the given type. - //This means that you can get back meshes of mixed dimension - //type. - smtk::mesh::MeshSet meshes(smtk::mesh::DimensionType dim) const; - smtk::mesh::MeshSet meshes(const smtk::mesh::Domain& d) const; - smtk::mesh::MeshSet meshes(const smtk::mesh::Dirichlet& d) const; - smtk::mesh::MeshSet meshes(const smtk::mesh::Neumann& n) const; - smtk::mesh::MeshSet meshes(const std::string& name) const; - - //find a cells of a given type or a resource of types - smtk::mesh::CellSet cells(smtk::mesh::CellType cellType) const; - smtk::mesh::CellSet cells(smtk::mesh::CellTypes cellTypes) const; - smtk::mesh::CellSet cells(smtk::mesh::DimensionType dim) const; - - bool classifyTo(const smtk::model::ResourcePtr&); - smtk::model::ResourcePtr classifiedTo() const; - - // Queries by a model Cursor - smtk::mesh::TypeSet findAssociatedTypes(const smtk::model::EntityRef& eref) const; - smtk::mesh::MeshSet findAssociatedMeshes(const smtk::model::EntityRef& eref) const; - smtk::mesh::MeshSet findAssociatedMeshes( - const smtk::model::EntityRef& eref, - smtk::mesh::DimensionType dim) const; - smtk::mesh::CellSet findAssociatedCells(const smtk::model::EntityRef& eref) const; - smtk::mesh::CellSet findAssociatedCells( - const smtk::model::EntityRef& eref, - smtk::mesh::CellType cellType) const; - smtk::mesh::CellSet findAssociatedCells( - const smtk::model::EntityRef& eref, - smtk::mesh::DimensionType dim) const; - - smtk::mesh::TypeSet findAssociatedTypes(const smtk::common::UUID& id) const; - smtk::mesh::MeshSet findAssociatedMeshes(const smtk::common::UUID& id) const; - smtk::mesh::MeshSet findAssociatedMeshes( - const smtk::common::UUID& id, - smtk::mesh::DimensionType dim) const; - smtk::mesh::CellSet findAssociatedCells(const smtk::common::UUID& id) const; - smtk::mesh::CellSet findAssociatedCells( - const smtk::common::UUID& id, - smtk::mesh::CellType cellType) const; - smtk::mesh::CellSet findAssociatedCells( - const smtk::common::UUID& id, - smtk::mesh::DimensionType dim) const; - - smtk::mesh::TypeSet findAssociatedTypes(smtk::model::EntityIterator& refIt) const; - smtk::mesh::MeshSet findAssociatedMeshes(smtk::model::EntityIterator& refIt) const; - smtk::mesh::MeshSet findAssociatedMeshes( - smtk::model::EntityIterator& refIt, - smtk::mesh::DimensionType dim) const; - smtk::mesh::CellSet findAssociatedCells(smtk::model::EntityIterator& refIt) const; - smtk::mesh::CellSet findAssociatedCells( - smtk::model::EntityIterator& refIt, - smtk::mesh::CellType cellType) const; - smtk::mesh::CellSet findAssociatedCells( - smtk::model::EntityIterator& refIt, - smtk::mesh::DimensionType dim) const; - - bool setAssociation(const smtk::model::EntityRef& eref, const smtk::mesh::MeshSet& meshset); - - //determine if this resource has any associations to a model - bool hasAssociations() const; - - // Associate a model to the resource. - //While a resource can be associated to just a model UUID, it is necessary - //to also call setModelResource() to facilitate calls that return associated - //EntityRefs, rather than just UUIDs. - bool associateToModel(const smtk::common::UUID& uuid); - - // Find if the resource has an associated model - bool isAssociatedToModel() const; - - // Return the uuid of the associated model - smtk::common::UUID associatedModel() const; - - // Construction of new meshes - //given a resource of existing cells make a new Mesh inside the underlying interface - //Return that Mesh as a MeshSet with a size of 1. The CellSet could - //be the result of appending/intersecting,difference of other CellSets. - //Adding a CellSet that is part of a different resource will fail, and - //we will return an empty MeshSet. - //Asking to create a MeshSet from a CellSet that is empty will fail, and - //we will return an empty MeshSet. - smtk::mesh::MeshSet createMesh( - const smtk::mesh::CellSet& cells, - const smtk::common::UUID& uuid = smtk::common::UUID::null()); - - // Deletion of Items - //given a resource of meshes this will delete all meshes and any cell or vert - //that is not referenced by any other mesh - //This will invalidate any smtk::mesh::MeshSet that contains a reference to - //one of the meshes that has been deleted. - bool removeMeshes(const smtk::mesh::MeshSet& meshesToDelete); - - // Domain Queries - //get all the current domains - std::vector domains() const; - - //get the meshes with a given domain value. If no meshes have - //this domain value the result will be empty - smtk::mesh::MeshSet domainMeshes(const smtk::mesh::Domain& m) const; - - //Assign a given domain to a resource of meshes. Overwrites - //any existing domain value - bool setDomainOnMeshes(const smtk::mesh::MeshSet& meshes, const smtk::mesh::Domain& m); - - // Dirichlet Queries - //get all the current dirichlet on the points of the mesh - std::vector dirichlets() const; - - //get the meshes with a given dirichlet value. If no meshes have - //this dirichlet value the result will be empty. - //Generally Dirichlet meshes only contain vertices - smtk::mesh::MeshSet dirichletMeshes(const smtk::mesh::Dirichlet& d) const; - - //Assign a given dirichlet to a resource of meshes. Overwrites - //any existing dirichlet value - //Generally Dirichlet meshes only contain vertices - bool setDirichletOnMeshes(const smtk::mesh::MeshSet& meshes, const smtk::mesh::Dirichlet& d); - - // Neumann Queries - //get all the current dirichlet on the points of the mesh - std::vector neumanns() const; - - //get the meshes with a given neumann value. If no meshes have - //this material value the result will be empty. - smtk::mesh::MeshSet neumannMeshes(const smtk::mesh::Neumann& n) const; - - //Assign a given neumann to a resource of meshes. Overwrites - //any existing neumann value - //Generally Neumann meshes only contain vertices - bool setNeumannOnMeshes(const smtk::mesh::MeshSet& meshes, const smtk::mesh::Neumann& n); - - const smtk::mesh::InterfacePtr& interface() const; - - void setModelResource(smtk::model::ResourcePtr resource) { m_modelResource = resource; } - smtk::model::ResourcePtr modelResource() const { return m_modelResource.lock(); } - -private: - //Sets the location that this resource was loaded from - void readLocation(const std::string& path) - { - this->readLocation(smtk::common::FileLocation(path)); - } - void readLocation(const smtk::common::FileLocation& path); - - //Swap the internal interfaces between this Resource and another Resource - //this is how we can easily update a resource that has already been - //loaded with a newer version from disk - void swapInterfaces(smtk::mesh::ResourcePtr& other); - - friend class smtk::io::ReadMesh; - - smtk::common::FileLocation m_readLocation; - smtk::common::FileLocation m_writeLocation; - - smtk::model::WeakResourcePtr m_modelResource; - - int m_nameCounter{ -1 }; - - friend std::shared_ptr Component::create( - const ResourcePtr&, - const smtk::common::UUID&); - friend std::shared_ptr Component::create(const MeshSet&); - std::map m_componentMap; - - //holds a reference to the specific backend interface - class InternalImpl; - smtk::mesh::Resource::InternalImpl* m_internals; -}; - -} // namespace mesh -} // namespace smtk - -#endif // smtk_mesh_core_Resource_h diff --git a/smtk/mesh/core/TypeSet.cxx b/smtk/mesh/core/TypeSet.cxx deleted file mode 100644 index 2112370856ca420e5a52faf5b66b2996ececc665..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/TypeSet.cxx +++ /dev/null @@ -1,94 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/TypeSet.h" - -#include - -namespace -{ -smtk::mesh::DimensionTypes make_dim_types(const smtk::mesh::CellTypes& ctypes) -{ - using namespace smtk::mesh; - DimensionTypes dtype; - dtype[Dims0] = ctypes[Vertex]; //only have Dims0 if we have Vertex - dtype[Dims1] = ctypes[Line]; //only have Dims1 if we have Line - //only have Dims2 if we have Triangle, Quad or Polygon - dtype[Dims2] = ctypes[Triangle] || ctypes[Quad] || ctypes[Polygon]; - //The rest determine our Dims3 value - dtype[Dims3] = ctypes[Tetrahedron] || ctypes[Pyramid] || ctypes[Wedge] || ctypes[Hexahedron]; - return dtype; -} -} // namespace - -namespace smtk -{ -namespace mesh -{ - -TypeSet::TypeSet() = default; - -TypeSet::TypeSet(smtk::mesh::CellTypes ctypes, bool hasM, bool hasC) - : m_cellTypes(ctypes) - , m_dimTypes(make_dim_types(ctypes)) - , m_hasMesh(hasM) - , m_hasCell(hasC) -{ -} - -bool TypeSet::operator==(const TypeSet& other) const -{ - //m_dimTypes are derived from m_cellTypes so we only need to compare - //m_cellTypes and m_hasMesh, Cell, Point - return ( - m_cellTypes == other.m_cellTypes && m_hasMesh == other.m_hasMesh && - m_hasCell == other.m_hasCell); -} - -bool TypeSet::operator!=(const TypeSet& other) const -{ - return !(*this == other); -} - -bool TypeSet::hasMeshes() const -{ - return m_hasMesh; -} - -bool TypeSet::hasCells() const -{ - return m_hasCell; -} - -bool TypeSet::hasDimension(smtk::mesh::DimensionType dt) const -{ - return m_dimTypes[dt]; -} - -bool TypeSet::hasCell(smtk::mesh::CellType ct) const -{ - assert(ct != smtk::mesh::CellType_MAX); - return m_cellTypes[ct]; -} - -TypeSet& TypeSet::operator+=(const TypeSet& other) -{ - // Bitwise-OR of types. - for (std::size_t i = 0; i < CellType_MAX; ++i) - m_cellTypes[i] = m_cellTypes[i] || other.cellTypes()[i]; - - // Update bulk information about meshset contents - m_hasMesh |= other.hasMeshes(); - m_hasCell |= other.hasCells(); - - return *this; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/core/TypeSet.h b/smtk/mesh/core/TypeSet.h deleted file mode 100644 index d1103364e0c5932251875745ce4eb0231e8d1f35..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/TypeSet.h +++ /dev/null @@ -1,60 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_core_TypeSet_h -#define smtk_mesh_core_TypeSet_h - -//TypeSet is a helper class whose goal is to make it easier to determine -//what kind of information you would extract from a resource given an -//association -#include "smtk/CoreExports.h" -#include "smtk/mesh/core/QueryTypes.h" - -namespace smtk -{ -namespace mesh -{ - -class SMTKCORE_EXPORT TypeSet -{ -public: - //construct an empty TypeSet - TypeSet(); - - //dimensions are inferred by what cell types are enabled - TypeSet(smtk::mesh::CellTypes ctypes, bool hasM, bool hasC); - - bool operator==(const TypeSet& other) const; - bool operator!=(const TypeSet& other) const; - - bool hasMeshes() const; - bool hasCells() const; - - //Dimension is related fully to the cell types that are passed in. - //What this means is that we don't consider having points ( coordinates ) - //a reason to mark a dim of 0 to true, that only happens if you have - //Vertex cell types - bool hasDimension(smtk::mesh::DimensionType dt) const; - bool hasCell(smtk::mesh::CellType ct) const; - - const smtk::mesh::CellTypes& cellTypes() const { return m_cellTypes; } - - TypeSet& operator+=(const TypeSet& other); - -private: - smtk::mesh::CellTypes m_cellTypes; - smtk::mesh::DimensionTypes m_dimTypes; - bool m_hasMesh{ false }; - bool m_hasCell{ false }; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/core/queries/BoundingBox.h b/smtk/mesh/core/queries/BoundingBox.h deleted file mode 100644 index a4e963b85044ac8e87cdb68f3bce6bfc8b264d71..0000000000000000000000000000000000000000 --- a/smtk/mesh/core/queries/BoundingBox.h +++ /dev/null @@ -1,52 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_BoundingBox_h -#define smtk_mesh_BoundingBox_h - -#include "smtk/CoreExports.h" - -#include "smtk/geometry/queries/BoundingBox.h" - -#include "smtk/mesh/utility/Metrics.h" - -namespace smtk -{ -namespace mesh -{ -/**\brief An API for computing the bounding box for a geometric resource - * or component. - */ -struct SMTKCORE_EXPORT BoundingBox - : public smtk::resource::query::DerivedFrom -{ - std::array operator()(const smtk::resource::PersistentObjectPtr& object) const override - { - smtk::mesh::Resource::Ptr meshResource = - std::dynamic_pointer_cast(object); - if (meshResource) - { - return utility::extent(meshResource->meshes()); - } - - smtk::mesh::Component::Ptr meshComponent = - std::dynamic_pointer_cast(object); - if (meshComponent) - { - return utility::extent(meshComponent->mesh()); - } - - return this->Parent::operator()(object); - } -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/interpolation/InverseDistanceWeighting.cxx b/smtk/mesh/interpolation/InverseDistanceWeighting.cxx deleted file mode 100644 index 830e9b0a5fd264c05571b30ef0d5e184b65a44d8..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/InverseDistanceWeighting.cxx +++ /dev/null @@ -1,153 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "InverseDistanceWeighting.h" - -#include "smtk/mesh/interpolation/PointCloud.h" -#include "smtk/mesh/interpolation/StructuredGrid.h" - -#include -#include - -namespace -{ -// We use inverse distance weighting via Shepard's method, implmented below. -const double EPSILON = 1.e-10; - -double euclideanDistance(const std::array& p1, const std::array& p2) -{ - std::array diff = { { p1[0] - p2[0], p1[1] - p2[1], p1[2] - p2[2] } }; - return std::sqrt(diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]); -} - -class InverseDistanceWeightingForPointCloud -{ -public: - InverseDistanceWeightingForPointCloud( - const smtk::mesh::PointCloud& pointcloud, - double power, - std::function prefilter) - : m_pointcloud(pointcloud) - , m_power(power) - , m_prefilter(prefilter) - { - } - - // Return the interpolated value at

as a weighted sum of the sources - double operator()(const std::array& p) const - { - double d = 0., w = 0., num = 0., denom = 0.; - for (std::size_t i = 0; i < m_pointcloud.size(); i++) - { - if (m_pointcloud.containsIndex(i)) - { - d = euclideanDistance(p, m_pointcloud.coordinates()(i)); - // If d is zero, then return the value associated with the source point. - if (d < EPSILON) - { - return m_pointcloud.data()(i); - } - // Otherwise, sum the contribution from each point. - w = std::pow(d, -1. * m_power); - num += w * m_pointcloud.data()(i); - denom += w; - } - } - - return num / denom; - } - -private: - const smtk::mesh::PointCloud m_pointcloud; - double m_power; - std::function m_prefilter; -}; - -class InverseDistanceWeightingForStructuredGrid -{ -public: - InverseDistanceWeightingForStructuredGrid( - const smtk::mesh::StructuredGrid& structuredgrid, - double power, - std::function prefilter) - : m_structuredgrid(structuredgrid) - , m_power(power) - , m_prefilter(prefilter) - { - } - - // Return the interpolated value at

as a weighted sum of the sources - double operator()(const std::array& p) const - { - double d = 0., w = 0., num = 0., denom = 0.; - for (int i = m_structuredgrid.m_extent[0]; i < m_structuredgrid.m_extent[1]; i++) - { - for (int j = m_structuredgrid.m_extent[2]; j < m_structuredgrid.m_extent[3]; j++) - { - if (m_structuredgrid.containsIndex(i, j)) - { - std::array pij = { - { (m_structuredgrid.m_origin[0] + - (i - m_structuredgrid.m_extent[0]) * m_structuredgrid.m_spacing[0]), - (m_structuredgrid.m_origin[1] + - (j - m_structuredgrid.m_extent[2]) * m_structuredgrid.m_spacing[1]), - 0. } - }; - - double value = m_structuredgrid.data()(i, j); - if (m_prefilter(value)) - { - d = euclideanDistance(p, pij); - // If d is zero, then return the value associated with the source point. - if (d < EPSILON) - { - return value; - } - // Otherwise, sum the contribution from each point. - w = std::pow(d, -1. * m_power); - num += w * value; - denom += w; - } - } - } - } - - return num / denom; - } - -private: - const smtk::mesh::StructuredGrid m_structuredgrid; - double m_power; - std::function m_prefilter; -}; -} // namespace - -namespace smtk -{ -namespace mesh -{ - -InverseDistanceWeighting::InverseDistanceWeighting( - const PointCloud& pointcloud, - double power, - std::function prefilter) - : m_function(InverseDistanceWeightingForPointCloud(pointcloud, power, prefilter)) -{ -} - -InverseDistanceWeighting::InverseDistanceWeighting( - const StructuredGrid& structuredgrid, - double power, - std::function prefilter) - : m_function(InverseDistanceWeightingForStructuredGrid(structuredgrid, power, prefilter)) -{ -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/interpolation/InverseDistanceWeighting.h b/smtk/mesh/interpolation/InverseDistanceWeighting.h deleted file mode 100644 index 7a9d6eb86e450bccdc196c9306fceef098491824..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/InverseDistanceWeighting.h +++ /dev/null @@ -1,57 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_InverseDistanceWeighting_h -#define smtk_mesh_InverseDistanceWeighting_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include -#include - -namespace smtk -{ -namespace mesh -{ - -class PointCloud; -class StructuredGrid; - -/**\brief A functor that converts an external data set into a continuous field - via inverse distance weighting. - - Given an external data set of either structured or unstructured data, this - functor is a continuous function from R^3->R whose values are computed as the - inverse distance weights of the data set. Shepard's method is used to perform - the computation. Values from the input data set can be masked using the - prefilter functor. - */ -class SMTKCORE_EXPORT InverseDistanceWeighting -{ -public: - InverseDistanceWeighting( - const PointCloud& pointcloud, - double power = 1., - std::function prefilter = [](double) { return true; }); - InverseDistanceWeighting( - const StructuredGrid& structuredgrid, - double power = 1., - std::function prefilter = [](double) { return true; }); - - double operator()(std::array x) const { return m_function(x); } - -private: - std::function)> m_function; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/interpolation/PointCloud.h b/smtk/mesh/interpolation/PointCloud.h deleted file mode 100644 index 4161de03bd47af91643255b06ae3b734bdeca4b7..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/PointCloud.h +++ /dev/null @@ -1,166 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_PointCloud_h -#define smtk_mesh_PointCloud_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ - -/**\brief A wrapper for point cloud data. - - This class is a facade for describing external data sets that consist of - unstructured points and associated scalar values. While there is convenience - API for converting arrays of coordinates and data into this format, the - general use of this class is to pass it a size \a nPoints and two functors - \a coordinates and \a data. \a coordinates is an I->R^3 function for accessing - the ith coordinate of the data set, and \a data is an I->R function for - accessing the scalar value associated with the ith point. - */ -class SMTKCORE_EXPORT PointCloud -{ -public: - PointCloud( - std::size_t nPoints, - const std::function(std::size_t)>& coordinates, - const std::function& data, - const std::function& valid) - : m_size(nPoints) - , m_coordinates(coordinates) - , m_data(data) - , m_valid(valid) - { - } - - /// Returns an invalid PointCloud. - PointCloud() - : PointCloud( - 0, - [](std::size_t) { - double nan = std::numeric_limits::quiet_NaN(); - return std::array({ { nan, nan, nan } }); - }, - [](std::size_t) { return std::numeric_limits::quiet_NaN(); }, - [](std::size_t) { return false; }) - { - } - - /// Constructs a PointCloud with no blanking (all points are considered valid). - PointCloud( - std::size_t nPoints, - const std::function(std::size_t)>& coordinates, - const std::function& data) - : m_size(nPoints) - , m_coordinates(coordinates) - , m_data(data) - , m_valid([](std::size_t) { return true; }) - { - } - - /// Constructs a PointCloud from arrays of coordinates and data. The arrays - /// must remain in scope for the lifetime of the PointCloud. - PointCloud(std::size_t nPoints, const double* const coordinates, const double* const data) - : PointCloud( - nPoints, - [=](std::size_t i) { - return std::array( - { { coordinates[3 * i], coordinates[3 * i + 1], coordinates[3 * i + 2] } }); - }, - [=](std::size_t i) { return data[i]; }, - [](std::size_t) { return true; }) - { - } - - /// Constructs a PointCloud from arrays of coordinates and data. The arrays - /// must remain in scope for the lifetime of the PointCloud. - PointCloud(std::size_t nPoints, const float* const coordinates, const float* const data) - : PointCloud( - nPoints, - [=](std::size_t i) { - return std::array( - { { coordinates[3 * i], coordinates[3 * i + 1], coordinates[3 * i + 2] } }); - }, - [=](std::size_t i) { return data[i]; }, - [](std::size_t) { return true; }) - { - } - -private: - struct Coordinates - { - Coordinates(std::vector coords) - : m_coordinates(std::move(coords)) - { - } - - std::array operator()(std::size_t i) const - { - return std::array( - { { m_coordinates[3 * i], m_coordinates[3 * i + 1], m_coordinates[3 * i + 2] } }); - } - - const std::vector m_coordinates; - }; - - struct Data - { - Data(std::vector data) - : m_data(std::move(data)) - { - } - - double operator()(std::size_t i) const { return m_data[i]; } - - const std::vector m_data; - }; - -public: - /// Constructs a PointCloud from vectors of coordinates and data. - PointCloud(std::vector&& coordinates, std::vector&& data) - : PointCloud(data.size(), Coordinates(coordinates), Data(data), [](std::size_t) { - return true; - }) - { - } - - virtual ~PointCloud() = default; - - std::size_t size() const { return m_size; } - - const std::function(std::size_t)>& coordinates() const - { - return m_coordinates; - } - const std::function& data() const { return m_data; } - - /// Given an index into the structured data, determine whether or not the point - /// is valid. - bool containsIndex(std::size_t i) const { return m_valid(i); } - -protected: - std::size_t m_size; - std::function(std::size_t)> m_coordinates; - std::function m_data; - std::function m_valid; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/interpolation/PointCloudFromCSV.cxx b/smtk/mesh/interpolation/PointCloudFromCSV.cxx deleted file mode 100644 index 280d8e6dc0d6059833a1c8a7c732dd7275866216..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/PointCloudFromCSV.cxx +++ /dev/null @@ -1,74 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/interpolation/PointCloudFromCSV.h" - -#include "smtk/common/CompilerInformation.h" -#include "smtk/common/Paths.h" - -#include "smtk/Regex.h" - -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ - -namespace -{ -bool registered = PointCloudFromCSV::registerClass(); -} - -bool PointCloudFromCSV::valid(const std::string& fileName) const -{ - // For now, let's assume that the .csv suffix is a sufficient check. - return smtk::common::Paths::extension(fileName) == ".csv"; -} - -smtk::mesh::PointCloud PointCloudFromCSV::operator()(const std::string& fileName) -{ - std::vector coordinates; - std::vector values; - - std::ifstream infile(fileName.c_str()); - if (!infile.good()) - { - throw std::invalid_argument("File cannot be read."); - } - std::string line; - smtk::regex re(","); - while (std::getline(infile, line)) - { - // Passing -1 as the submatch index parameter performs splitting - smtk::sregex_token_iterator first{ line.begin(), line.end(), re, -1 }, last; - - // We are looking for (x, y, z, value), but we will also accept - // (x, y, value). So, we must have at least 3 components. - std::size_t dist = std::distance(first, last); - if (dist < 3) - { - throw std::invalid_argument("File does not contain enough parameters."); - } - - coordinates.push_back(std::stod(*(first++))); - coordinates.push_back(std::stod(*(first++))); - coordinates.push_back(dist == 4 ? std::stod(*(first++)) : 0.); - values.push_back(std::stod(*(first++))); - } - - infile.close(); - - return smtk::mesh::PointCloud(std::move(coordinates), std::move(values)); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/interpolation/PointCloudFromCSV.h b/smtk/mesh/interpolation/PointCloudFromCSV.h deleted file mode 100644 index 8c431f52be2f1c0a1fc9363a54b14eea843e845f..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/PointCloudFromCSV.h +++ /dev/null @@ -1,40 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_PointCloudFromCSV_h -#define smtk_mesh_PointCloudFromCSV_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/common/Generator.h" -#include "smtk/mesh/interpolation/PointCloud.h" - -#include - -namespace smtk -{ -namespace mesh -{ - -/// A GeneratorType for creating PointClouds from CSV files. This class extends -/// smtk::mesh::PointCloudGenerator. -class SMTKCORE_EXPORT PointCloudFromCSV - : public smtk::common::GeneratorType -{ -public: - bool valid(const std::string& file) const override; - - smtk::mesh::PointCloud operator()(const std::string& file) override; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/interpolation/PointCloudGenerator.cxx b/smtk/mesh/interpolation/PointCloudGenerator.cxx deleted file mode 100644 index 7e4e339eac0105e3779e90f6d64adfa167b61f58..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/PointCloudGenerator.cxx +++ /dev/null @@ -1,20 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/interpolation/PointCloudGenerator.h" - -namespace smtk -{ -namespace mesh -{ - -PointCloudGenerator::~PointCloudGenerator() = default; -} -} // namespace smtk diff --git a/smtk/mesh/interpolation/PointCloudGenerator.h b/smtk/mesh/interpolation/PointCloudGenerator.h deleted file mode 100644 index c5120c0b9ab94c590952e31a2c06aad056131a9d..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/PointCloudGenerator.h +++ /dev/null @@ -1,53 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_PointCloudGenerator_h -#define smtk_mesh_PointCloudGenerator_h - -#include "smtk/CoreExports.h" -#include "smtk/common/Generator.h" -#include "smtk/mesh/interpolation/PointCloud.h" - -#include - -template class SMTKCORE_EXPORT smtk::common::Generator; -template class SMTKCORE_EXPORT - smtk::common::Generator; - -namespace smtk -{ -namespace model -{ -class AuxiliaryGeometry; -} - -/// A generator for PointClouds. PointCloudGenerator accepts as input (a) a -/// string describing a data file or (b) an auxiliary geometry instance. This -/// class is extended by classes that inherit from GeneratorType (see -/// smtk::common::Generator). -namespace mesh -{ - -class SMTKCORE_EXPORT PointCloudGenerator - : public smtk::common::Generator - , public smtk::common::Generator -{ -public: - using smtk::common::Generator::operator(); - using smtk::common::Generator::valid; - using smtk::common::Generator::operator(); - using smtk::common::Generator::valid; - - ~PointCloudGenerator() override; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/interpolation/RadialAverage.cxx b/smtk/mesh/interpolation/RadialAverage.cxx deleted file mode 100644 index 54cfb0bc48514e4030c1f71154297db0a5f0976f..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/RadialAverage.cxx +++ /dev/null @@ -1,216 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "RadialAverage.h" - -#include "smtk/mesh/core/PointLocator.h" -#include "smtk/mesh/core/PointSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/interpolation/PointCloud.h" -#include "smtk/mesh/interpolation/StructuredGrid.h" - -#include -#include - -namespace -{ -struct RadialAverageForPointCloud -{ - RadialAverageForPointCloud( - smtk::mesh::ResourcePtr resource, - const smtk::mesh::PointCloud& pointcloud, - double radius, - std::function prefilter) - : m_pointcloud(pointcloud) - , m_radius(radius) - , m_prefilter(prefilter) - , m_locator(resource, pointcloud.size(), pointcloud.coordinates()) - { - } - - double operator()(std::array x) - { - smtk::mesh::PointLocator::LocatorResults results; - m_locator.find(x[0], x[1], 0.0, m_radius, results); - - double sum = 0; - std::size_t numPointsInRadius = 0; - for (auto i : results.pointIds) - { - if (m_pointcloud.containsIndex(i)) - { - double value = m_pointcloud.data()(i); - if (m_prefilter(value)) - { - sum += value; - ++numPointsInRadius; - } - } - } - - if (numPointsInRadius == 0) - { - return std::numeric_limits::quiet_NaN(); - } - else - { - return sum / numPointsInRadius; - } - } - - const smtk::mesh::PointCloud m_pointcloud; - double m_radius; - std::function m_prefilter; - smtk::mesh::PointLocator m_locator; -}; - -struct RadialAverageForStructuredGrid -{ - typedef std::pair Coord; - - RadialAverageForStructuredGrid( - const smtk::mesh::StructuredGrid& structuredgrid, - double radius, - std::function prefilter) - : m_structuredgrid(structuredgrid) - , m_radius2(radius * radius) - , m_prefilter(prefilter) - { - m_discreteRadius[0] = - std::abs(static_cast(std::round(radius / m_structuredgrid.m_spacing[0]))); - m_discreteRadius[1] = - std::abs(static_cast(std::round(radius / m_structuredgrid.m_spacing[1]))); - - m_limits[0] = m_structuredgrid.m_origin[0]; - m_limits[1] = m_structuredgrid.m_origin[0] + - (m_structuredgrid.m_extent[1] - m_structuredgrid.m_extent[0]) * m_structuredgrid.m_spacing[0]; - if (m_limits[0] > m_limits[1]) - { - std::swap(m_limits[0], m_limits[1]); - } - m_limits[2] = m_structuredgrid.m_origin[1]; - m_limits[3] = m_structuredgrid.m_origin[1] + - (m_structuredgrid.m_extent[3] - m_structuredgrid.m_extent[2]) * m_structuredgrid.m_spacing[1]; - if (m_limits[2] > m_limits[3]) - { - std::swap(m_limits[2], m_limits[3]); - } - } - - double operator()(std::array x) - { - if (x[0] < m_limits[0] || x[0] > m_limits[1] || x[1] < m_limits[2] || x[1] > m_limits[3]) - { - // this point is outside of our data range - return std::numeric_limits::quiet_NaN(); - } - - // (ix,iy) represents the closest point in the grid to the query point - int ix = static_cast(std::round( - m_structuredgrid.m_extent[0] + - ((x[0] - m_structuredgrid.m_origin[0]) / m_structuredgrid.m_spacing[0]))); - int iy = static_cast(std::round( - m_structuredgrid.m_extent[2] + - ((x[1] - m_structuredgrid.m_origin[1]) / m_structuredgrid.m_spacing[1]))); - - // Since we allow for different spacing in x and y, our circle maps to an - // ellipse with axes in the x and y dimensions of m_discreteRadius[0] and - // m_discreteRadius[1], respectively, in discrete space. To integrate this - // ellipse, we sweep across the y dimension; for each discrete step in y, - // we compute the extrema in x and sum the results at each coordinate. - double sum = 0.; - std::size_t nCoords = 0; - int i_extrema[2]; - for (int j = iy - m_discreteRadius[1]; j < iy + m_discreteRadius[1]; j++) - { - if (j < m_structuredgrid.m_extent[2] || j > m_structuredgrid.m_extent[3]) - { - continue; - } - - int halfChord = int(m_discreteRadius[0] * sin(acos(double(j - iy) / m_discreteRadius[1]))); - i_extrema[0] = ix - halfChord; - i_extrema[1] = ix + halfChord; - - if (i_extrema[0] < m_structuredgrid.m_extent[0]) - { - i_extrema[0] = m_structuredgrid.m_extent[0]; - } - if (i_extrema[1] > m_structuredgrid.m_extent[1]) - { - i_extrema[1] = m_structuredgrid.m_extent[1]; - } - - // We perform an unweighted average to maintain parity with the - // unstructured grid version of this operator - for (int i = i_extrema[0]; i < i_extrema[1]; i++) - { - if (m_structuredgrid.containsIndex(i, j)) - { - double value = m_structuredgrid.data()(i, j); - if (m_prefilter(value)) - { - sum += value; - nCoords++; - } - } - } - } - if (nCoords == 0) - { - if (m_structuredgrid.containsIndex(ix, iy)) - { - sum = m_structuredgrid.data()(ix, iy); - } - else - { - sum = std::numeric_limits::quiet_NaN(); - } - } - else - { - sum /= nCoords; - } - - return sum; - } - - const smtk::mesh::StructuredGrid m_structuredgrid; - double m_radius2; - std::function m_prefilter; - int m_discreteRadius[2]; - double m_limits[4]; -}; -} // namespace - -namespace smtk -{ -namespace mesh -{ - -RadialAverage::RadialAverage( - smtk::mesh::ResourcePtr resource, - const PointCloud& pointcloud, - double radius, - std::function prefilter) - : m_function(RadialAverageForPointCloud(resource, pointcloud, radius, prefilter)) -{ -} - -RadialAverage::RadialAverage( - const StructuredGrid& structuredgrid, - double radius, - std::function prefilter) - : m_function(RadialAverageForStructuredGrid(structuredgrid, radius, prefilter)) -{ -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/interpolation/RadialAverage.h b/smtk/mesh/interpolation/RadialAverage.h deleted file mode 100644 index a493bd636f09b7450df6ab5d270f3d5258bf66ec..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/RadialAverage.h +++ /dev/null @@ -1,58 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_RadialAverage_h -#define smtk_mesh_RadialAverage_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include -#include - -namespace smtk -{ -namespace mesh -{ - -class PointCloud; -class StructuredGrid; - -/**\brief A functor that converts an external data set into a continuous field - via radial averaging. - - Given an external data set of either structured or unstructured data, this - functor is a continuous function from R^3->R whose values are computed as the - average of the points in the data set within a cylinder of radius \a radius - axis-aligned with the z axis and centered at the input point. Values from the - input data set can be masked using the prefilter functor. - */ -class SMTKCORE_EXPORT RadialAverage -{ -public: - RadialAverage( - ResourcePtr collection, - const PointCloud&, - double radius, - std::function prefilter = [](double) { return true; }); - RadialAverage( - const StructuredGrid&, - double radius, - std::function prefilter = [](double) { return true; }); - - double operator()(std::array x) const { return m_function(x); } - -private: - std::function)> m_function; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/interpolation/StructuredGrid.h b/smtk/mesh/interpolation/StructuredGrid.h deleted file mode 100644 index 1920e13bd8693efd088d30de5efabf5e48860a68..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/StructuredGrid.h +++ /dev/null @@ -1,105 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_StructuredGrid_h -#define smtk_mesh_StructuredGrid_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ - -/**\brief A wrapper for structured data. - - This class is a facade for describing external two-dimensional data sets that - consist of a structured grid of points and associated scalar values. The user - must assign an index extent, origin and spacing, as well as an I^2->R - function describing the scalar value associated with index (i,j). - Additionally, an I^2->bool function can be passed to the class to denote cell - validity, facilitating blanking. - */ -class StructuredGrid -{ -public: - StructuredGrid() - : m_data([](int, int) { return std::numeric_limits::quiet_NaN(); }) - , m_valid([](int, int) { return false; }) - { - for (int i = 0; i < 4; i++) - { - m_extent[i] = 0; - } - for (int i = 0; i < 2; i++) - { - m_origin[i] = m_spacing[i] = std::numeric_limits::quiet_NaN(); - } - } - - StructuredGrid( - const int extent[4], - const double origin[2], - const double spacing[2], - const std::function& data, - const std::function& valid) - : m_data(data) - , m_valid(valid) - { - for (int i = 0; i < 4; i++) - { - m_extent[i] = extent[i]; - } - for (int i = 0; i < 2; i++) - { - m_origin[i] = origin[i]; - m_spacing[i] = spacing[i]; - } - } - - StructuredGrid( - const int extent[4], - const double origin[2], - const double spacing[2], - const std::function& data) - : StructuredGrid(extent, origin, spacing, data, [](int, int) { return true; }) - { - } - - // Given indices into the structured data, determine whether or not the cell - // is valid. - bool containsIndex(int ix, int iy) const - { - return (ix >= m_extent[0] && ix <= m_extent[1] && iy >= m_extent[2] && iy <= m_extent[3]) && - m_valid(ix, iy); - } - - const std::function& data() const { return m_data; } - const std::function& valid() const { return m_valid; } - - std::size_t size() const { return (m_extent[1] - m_extent[0]) * (m_extent[3] - m_extent[2]); } - - std::array m_extent; // [istart, iend, jstart, jend] - std::array m_origin; // location of pixel index (0,0) - std::array m_spacing; // i, j pixel spacing - -private: - std::function m_data; - std::function m_valid; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/interpolation/StructuredGridGenerator.h b/smtk/mesh/interpolation/StructuredGridGenerator.h deleted file mode 100644 index 2e939f3d5976a9a8f087494fa05def5ac45165d4..0000000000000000000000000000000000000000 --- a/smtk/mesh/interpolation/StructuredGridGenerator.h +++ /dev/null @@ -1,53 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_StructuredGridGenerator_h -#define smtk_mesh_StructuredGridGenerator_h - -#include "smtk/CoreExports.h" -#include "smtk/common/Generator.h" -#include "smtk/mesh/interpolation/StructuredGrid.h" - -#include - -template class SMTKCORE_EXPORT smtk::common::Generator; -template class SMTKCORE_EXPORT - smtk::common::Generator; - -namespace smtk -{ -namespace model -{ -class AuxiliaryGeometry; -} - -/// A generator for StructuredGrids. StructuredGridGenerator accepts as input -/// (a) a string describing a data file or (b) an auxiliary geometry instance. -/// This class is extended by classes that inherit from GeneratorType (see -/// smtk::common::Generator). -namespace mesh -{ - -class SMTKCORE_EXPORT StructuredGridGenerator - : public smtk::common::Generator - , public smtk::common::Generator -{ -public: - using smtk::common::Generator::operator(); - using smtk::common::Generator::valid; - using smtk::common::Generator::operator(); - using smtk::common::Generator::valid; - - ~StructuredGridGenerator() override; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/json/Interface.cxx b/smtk/mesh/json/Interface.cxx deleted file mode 100644 index d5eb98710b56b97f4e41382b8ae81d2a10cec3b3..0000000000000000000000000000000000000000 --- a/smtk/mesh/json/Interface.cxx +++ /dev/null @@ -1,839 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/mesh/json/Interface.h" - -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/QueryTypes.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/moab/CellTypeToType.h" -#include "smtk/mesh/moab/HandleRangeToRange.h" - -#include -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ -namespace json -{ - -//construct an empty interface instance -smtk::mesh::json::InterfacePtr make_interface() -{ - return std::make_shared(); -} - -Interface::Interface() - : m_associated_model(smtk::common::UUID::null()) -{ -} - -Interface::Interface(const std::vector& info) - : m_meshInfo(info) - , m_associated_model(smtk::common::UUID::null()) -{ -} - -Interface::~Interface() = default; - -bool Interface::isModified() const -{ - return m_modified; -} - -void Interface::addMeshes(const std::vector& info) -{ - m_meshInfo.insert(m_meshInfo.end(), info.begin(), info.end()); -} - -smtk::mesh::AllocatorPtr Interface::allocator() -{ - return smtk::mesh::AllocatorPtr(); -} - -smtk::mesh::BufferedCellAllocatorPtr Interface::bufferedCellAllocator() -{ - return smtk::mesh::BufferedCellAllocatorPtr(); -} - -smtk::mesh::IncrementalAllocatorPtr Interface::incrementalAllocator() -{ - return smtk::mesh::IncrementalAllocatorPtr(); -} - -smtk::mesh::ConnectivityStoragePtr Interface::connectivityStorage( - const smtk::mesh::HandleRange& /*cells*/) -{ - return smtk::mesh::ConnectivityStoragePtr(); -} - -smtk::mesh::PointLocatorImplPtr Interface::pointLocator(const smtk::mesh::HandleRange& /*points*/) -{ - return smtk::mesh::PointLocatorImplPtr(); -} - -smtk::mesh::PointLocatorImplPtr Interface::pointLocator( - std::size_t /*numPoints*/, - const std::function(std::size_t)>& /*coordinates*/) -{ - return smtk::mesh::PointLocatorImplPtr(); -} - -void Interface::registerQueries(smtk::mesh::Resource&) const {} - -smtk::mesh::Handle Interface::getRoot() const -{ - return smtk::mesh::Handle(0); -} - -bool Interface::createMesh( - const smtk::mesh::HandleRange& /*cells*/, - smtk::mesh::Handle& /*meshHandle*/) -{ - //this interface can't create new meshes - return false; -} - -std::size_t Interface::numMeshes(smtk::mesh::Handle handle) const -{ - if (handle != this->getRoot()) - { - return 0; - } - return m_meshInfo.size(); -} - -smtk::mesh::HandleRange Interface::getMeshsets(smtk::mesh::Handle handle) const -{ - if (handle != this->getRoot()) - { - return smtk::mesh::HandleRange(); - } - - smtk::mesh::HandleRange meshes; - MeshInfoVecType::const_iterator i; - for (i = m_meshInfo.begin(); i != m_meshInfo.end(); ++i) - { - meshes.insert(i->mesh()); - } - return meshes; -} - -smtk::mesh::HandleRange Interface::getMeshsets(smtk::mesh::Handle handle, int dimension) const -{ - if (handle != this->getRoot()) - { - return smtk::mesh::HandleRange(); - } - - const smtk::mesh::DimensionType dim = static_cast(dimension); - - smtk::mesh::HandleRange meshes; - MeshInfoVecType::const_iterator i; - for (i = m_meshInfo.begin(); i != m_meshInfo.end(); ++i) - { - if (i->types().hasDimension(dim)) - { - meshes.insert(i->mesh()); - } - } - return meshes; -} - -//find all entity sets that have this exact name tag -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle /*handle*/, - const std::string& /*name*/) const -{ - return smtk::mesh::HandleRange(); -} - -//find all entity sets that have this exact name tag -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Domain& domain) const -{ - if (handle != this->getRoot()) - { - return smtk::mesh::HandleRange(); - } - - smtk::mesh::HandleRange meshes; - MeshInfoVecType::const_iterator i; - for (i = m_meshInfo.begin(); i != m_meshInfo.end(); ++i) - { - if (i->has(domain)) - { - meshes.insert(i->mesh()); - } - } - return meshes; -} - -//find all entity sets that have this exact name tag -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Dirichlet& dirichlet) const -{ - if (handle != this->getRoot()) - { - return smtk::mesh::HandleRange(); - } - - smtk::mesh::HandleRange meshes; - MeshInfoVecType::const_iterator i; - for (i = m_meshInfo.begin(); i != m_meshInfo.end(); ++i) - { - if (i->has(dirichlet)) - { - meshes.insert(i->mesh()); - } - } - return meshes; -} - -//find all entity sets that have this exact name tag -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Neumann& neumann) const -{ - if (handle != this->getRoot()) - { - return smtk::mesh::HandleRange(); - } - - smtk::mesh::HandleRange meshes; - MeshInfoVecType::const_iterator i; - for (i = m_meshInfo.begin(); i != m_meshInfo.end(); ++i) - { - if (i->has(neumann)) - { - meshes.insert(i->mesh()); - } - } - return meshes; -} - -//get all cells held by this range -smtk::mesh::HandleRange Interface::getCells(const HandleRange& meshsets) const -{ - smtk::mesh::HandleRange cells; - for (auto i = smtk::mesh::rangeElementsBegin(meshsets); - i != smtk::mesh::rangeElementsEnd(meshsets); - ++i) - { - MeshInfoVecType::const_iterator m = this->find(*i); - if (m != m_meshInfo.end()) - { - cells += m->cells(); - } - } - return cells; -} - -//get all cells held by this range handle of a given cell type -smtk::mesh::HandleRange Interface::getCells( - const HandleRange& meshsets, - smtk::mesh::CellType cellType) const -{ - smtk::mesh::HandleRange cells; - for (auto i = smtk::mesh::rangeElementsBegin(meshsets); - i != smtk::mesh::rangeElementsEnd(meshsets); - ++i) - { - MeshInfoVecType::const_iterator m = this->find(*i); - if (m != m_meshInfo.end()) - { - cells += m->cells(cellType); - } - } - return cells; -} - -//get all cells held by this range handle of a given cell type(s) -smtk::mesh::HandleRange Interface::getCells( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellTypes& cellTypes) const -{ - smtk::mesh::HandleRange cells; - for (auto i = smtk::mesh::rangeElementsBegin(meshsets); - i != smtk::mesh::rangeElementsEnd(meshsets); - ++i) - { - MeshInfoVecType::const_iterator m = this->find(*i); - if (m != m_meshInfo.end()) - { - cells += m->cells(cellTypes); - } - } - return cells; -} - -//get all cells held by this range handle of a given dimension -smtk::mesh::HandleRange Interface::getCells( - const smtk::mesh::HandleRange& meshsets, - smtk::mesh::DimensionType dim) const -{ - smtk::mesh::HandleRange cells; - for (auto i = smtk::mesh::rangeElementsBegin(meshsets); - i != smtk::mesh::rangeElementsEnd(meshsets); - ++i) - { - MeshInfoVecType::const_iterator m = this->find(*i); - if (m != m_meshInfo.end()) - { - cells += m->cells(dim); - } - } - return cells; -} - -//get all points held by this range handle -smtk::mesh::HandleRange Interface::getPoints( - const smtk::mesh::HandleRange& cells, - bool boundary_only) const -{ - // We don't support modifying operations via the JSON interface (like meshset - // construction, point merging, etc.); in keeping with this paradigm, the only - // point ranges that can be queried are unions of points associated with mesh - // sets that have already been computed using an alternate backend (e.g. - // Moab). Any queries involving cells that are not the union of cell sets - // contained within the meshInfo vector yield a null return value. This is - // sufficient for relaying server-side information about points to the client. - - (void)boundary_only; - - smtk::mesh::HandleRange points; - smtk::mesh::HandleRange cellsToVisit = cells; - for (const auto& m : m_meshInfo) - { - if (smtk::mesh::rangeContains(cellsToVisit, m.cells())) - { - points += m.points(); - cellsToVisit = cellsToVisit - m.cells(); - } - } - return cellsToVisit.empty() ? points : smtk::mesh::HandleRange(); -} - -bool Interface::getCoordinates(const smtk::mesh::HandleRange& /*points*/, double* /*xyz*/) const -{ - return false; -} - -bool Interface::getCoordinates(const smtk::mesh::HandleRange& /*points*/, float* /*xyz*/) const -{ - return false; -} - -bool Interface::setCoordinates( - const smtk::mesh::HandleRange& /*points*/, - const double* const /*xyz*/) -{ - return false; -} - -bool Interface::setCoordinates( - const smtk::mesh::HandleRange& /*points*/, - const float* const /*xyz*/) -{ - return false; -} - -std::string Interface::name(const smtk::mesh::Handle& /*meshset*/) const -{ - //TODO - return std::string(); -} - -bool Interface::setName(const smtk::mesh::Handle& /*meshset*/, const std::string& /*name*/) -{ - return false; -} - -std::vector Interface::computeNames(const smtk::mesh::HandleRange& /*meshsets*/) const -{ - return std::vector(); -} - -std::vector Interface::computeDomainValues( - const smtk::mesh::HandleRange& meshsets) const -{ - std::set domains; - for (auto i = smtk::mesh::rangeElementsBegin(meshsets); - i != smtk::mesh::rangeElementsEnd(meshsets); - ++i) - { - MeshInfoVecType::const_iterator m = this->find(*i); - const std::vector& t = m->domains(); - domains.insert(t.begin(), t.end()); - } - - //return a vector of all the unique domains we have - return std::vector(domains.begin(), domains.end()); -} - -std::vector Interface::computeDirichletValues( - const smtk::mesh::HandleRange& meshsets) const -{ - std::set boundary; - for (auto i = smtk::mesh::rangeElementsBegin(meshsets); - i != smtk::mesh::rangeElementsEnd(meshsets); - ++i) - { - MeshInfoVecType::const_iterator m = this->find(*i); - const std::vector& t = m->dirichlets(); - boundary.insert(t.begin(), t.end()); - } - - //return a vector of all the unique Dirichlet we have - return std::vector(boundary.begin(), boundary.end()); -} - -std::vector Interface::computeNeumannValues( - const smtk::mesh::HandleRange& meshsets) const -{ - std::set boundary; - for (auto i = smtk::mesh::rangeElementsBegin(meshsets); - i != smtk::mesh::rangeElementsEnd(meshsets); - ++i) - { - MeshInfoVecType::const_iterator m = this->find(*i); - const std::vector& t = m->neumanns(); - boundary.insert(t.begin(), t.end()); - } - - //return a vector of all the unique Neumann we have - return std::vector(boundary.begin(), boundary.end()); -} - -/**\brief Return the set of all UUIDs set on all entities in the meshsets. - * - */ -smtk::common::UUIDArray Interface::computeModelEntities( - const smtk::mesh::HandleRange& meshsets) const -{ - smtk::common::UUIDArray uuids; - for (auto i = smtk::mesh::rangeElementsBegin(meshsets); - i != smtk::mesh::rangeElementsEnd(meshsets); - ++i) - { - MeshInfoVecType::const_iterator m = this->find(*i); - if (m == m_meshInfo.end()) - continue; - const smtk::common::UUIDArray& t = m->modelUUIDS(); - if (!t.empty()) - { - uuids.insert(uuids.end(), t.begin(), t.end()); - } - } - return uuids; -} - -smtk::mesh::TypeSet Interface::computeTypes(const smtk::mesh::HandleRange& range) const -{ - typedef ::smtk::mesh::CellType CellEnum; - - ::moab::Range moabRange = smtk::mesh::moab::smtkToMOABRange(range); - - ::moab::Range meshes = moabRange.subset_by_type(::moab::MBENTITYSET); - ::moab::Range cells = ::moab::subtract(moabRange, meshes); - - smtk::mesh::TypeSet result; - for (::moab::Range::const_iterator i = meshes.begin(); i != meshes.end(); ++i) - { - MeshInfoVecType::const_iterator m = this->find(*i); - result += m->types(); - } - - smtk::mesh::CellTypes ctypes; - - //compute the type of the cells if we have any - if (!cells.empty()) - { - for (std::size_t i = 0; i < ctypes.size(); ++i) - { - //now we need to convert from CellEnum to MoabType - const CellEnum ce = static_cast(i); - const ::moab::EntityType moabEType = - static_cast<::moab::EntityType>(smtk::mesh::moab::smtkToMOABCell(ce)); - - //if num_of_type is greater than zero we have cells of that type - if (cells.num_of_type(moabEType) > 0) - { - ctypes[ce] = true; - } - } - } - - const bool hasM = !(meshes.empty()); - const bool hasC = ctypes.any(); - smtk::mesh::TypeSet cellResult(ctypes, hasM, hasC); - - result += cellResult; - return result; -} - -bool Interface::computeShell( - const smtk::mesh::HandleRange& /*meshes*/, - smtk::mesh::HandleRange& /*shell*/) const -{ - return false; -} - -bool Interface::computeAdjacenciesOfDimension( - const smtk::mesh::HandleRange& /*meshes*/, - int /*dimension*/, - smtk::mesh::HandleRange& /*adj*/) const -{ - return false; -} - -bool Interface::canonicalIndex( - const smtk::mesh::Handle& /*cell*/, - smtk::mesh::Handle& /*parent*/, - int& /*index*/) const -{ - return false; -} - -bool Interface::mergeCoincidentContactPoints( - const smtk::mesh::HandleRange& /*meshes*/, - double /*tolerance*/) -{ - return false; -} - -smtk::mesh::HandleRange Interface::neighbors(const smtk::mesh::Handle& cellId) const -{ - (void)cellId; - return smtk::mesh::HandleRange(); -} - -bool Interface::setDomain( - const smtk::mesh::HandleRange& /*meshsets*/, - const smtk::mesh::Domain& /*domain*/) const -{ - return false; -} - -bool Interface::setDirichlet( - const smtk::mesh::HandleRange& /*meshsets*/, - const smtk::mesh::Dirichlet& /*dirichlet*/) const -{ - return false; -} - -bool Interface::setNeumann( - const smtk::mesh::HandleRange& /*meshsets*/, - const smtk::mesh::Neumann& /*neumann*/) const -{ - return false; -} - -bool Interface::setId(const smtk::mesh::Handle& /*meshset*/, const smtk::common::UUID& /*id*/) const -{ - return false; -} - -smtk::common::UUID Interface::getId(const smtk::mesh::Handle& meshset) const -{ - smtk::mesh::HandleRange meshes; - MeshInfoVecType::const_iterator i; - for (i = m_meshInfo.begin(); i != m_meshInfo.end(); ++i) - { - if (i->mesh() == meshset) - { - return i->id(); - } - } - return smtk::common::UUID::null(); -} - -bool Interface::findById( - const smtk::mesh::Handle& /*root*/, - const smtk::common::UUID& id, - smtk::mesh::Handle& meshset) const -{ - smtk::mesh::HandleRange meshes; - MeshInfoVecType::const_iterator i; - for (i = m_meshInfo.begin(); i != m_meshInfo.end(); ++i) - { - if (i->id() == id) - { - meshset = i->mesh(); - return true; - } - } - return false; -} - -/**\brief Set the model entity assigned to each meshset member to \a ent. - */ -bool Interface::setAssociation( - const smtk::common::UUID& /*modelUUID*/, - const smtk::mesh::HandleRange& /*meshsets*/) const -{ - return false; -} - -/**\brief Find mesh entities associated with the given model entity. - * - */ -smtk::mesh::HandleRange Interface::findAssociations( - const smtk::mesh::Handle& /*root*/, - const smtk::common::UUID& modelUUID) const -{ - smtk::mesh::HandleRange result; - if (!modelUUID) - return result; - - smtk::mesh::HandleRange meshes; - MeshInfoVecType::const_iterator i; - for (i = m_meshInfo.begin(); i != m_meshInfo.end(); ++i) - { - const smtk::common::UUIDArray& uuids = i->modelUUIDS(); - const bool contains = std::find(uuids.begin(), uuids.end(), modelUUID) != uuids.end(); - if (contains) - { - meshes.insert(i->mesh()); - } - } - return meshes; -} - -/**\brief Set the model entity assigned to the root of this interface. - */ -bool Interface::setRootAssociation(const smtk::common::UUID& modelUUID) const -{ - m_associated_model = modelUUID; - return true; -} - -/**\brief Get the model entity assigned to the root of this interface. - */ -smtk::common::UUID Interface::rootAssociation() const -{ - return m_associated_model; -} - -bool Interface::createCellField( - const smtk::mesh::HandleRange& /*meshsets*/, - const std::string& /*name*/, - std::size_t /*dimension*/, - const smtk::mesh::FieldType& /*type*/, - const void* /*data*/) -{ - return false; -} - -int Interface::getCellFieldDimension(const smtk::mesh::CellFieldTag& /*cfTag*/) const -{ - return 0; -} - -smtk::mesh::FieldType Interface::getCellFieldType(const smtk::mesh::CellFieldTag& /*cfTag*/) const -{ - return smtk::mesh::FieldType::MaxFieldType; -} - -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle /*handle*/, - const smtk::mesh::CellFieldTag& /*cfTag*/) const -{ - return smtk::mesh::HandleRange(); -} - -bool Interface::hasCellField( - const smtk::mesh::HandleRange& /*meshsets*/, - const smtk::mesh::CellFieldTag& /*cfTag*/) const -{ - return false; -} - -bool Interface::getCellField( - const smtk::mesh::HandleRange& /*meshsets*/, - const smtk::mesh::CellFieldTag& /*cfTag*/, - void* /*data*/) const -{ - return false; -} - -bool Interface::setCellField( - const smtk::mesh::HandleRange& /*meshsets*/, - const smtk::mesh::CellFieldTag& /*cfTag*/, - const void* const /*data*/) -{ - return false; -} - -bool Interface::getField( - const smtk::mesh::HandleRange& /*cells*/, - const smtk::mesh::CellFieldTag& /*cfTag*/, - void* /*data*/) const -{ - return false; -} - -bool Interface::setField( - const smtk::mesh::HandleRange& /*cells*/, - const smtk::mesh::CellFieldTag& /*cfTag*/, - const void* const /*data*/) -{ - return false; -} - -std::set Interface::computeCellFieldTags( - const smtk::mesh::Handle& /*handle*/) const -{ - return std::set(); -} - -bool Interface::deleteCellField( - const smtk::mesh::CellFieldTag& /*dsTag*/, - const smtk::mesh::HandleRange& /*meshsets*/) -{ - return false; -} - -bool Interface::createPointField( - const smtk::mesh::HandleRange& /*meshsets*/, - const std::string& /*name*/, - std::size_t /*dimension*/, - const smtk::mesh::FieldType& /*type*/, - const void* /*data*/) -{ - return false; -} - -int Interface::getPointFieldDimension(const smtk::mesh::PointFieldTag& /*pfTag*/) const -{ - return 0; -} - -smtk::mesh::FieldType Interface::getPointFieldType(const smtk::mesh::PointFieldTag& /*pfTag*/) const -{ - return smtk::mesh::FieldType::MaxFieldType; -} - -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle /*handle*/, - const smtk::mesh::PointFieldTag& /*pfTag*/) const -{ - return smtk::mesh::HandleRange(); -} - -bool Interface::hasPointField( - const smtk::mesh::HandleRange& /*meshsets*/, - const smtk::mesh::PointFieldTag& /*pfTag*/) const -{ - return false; -} - -bool Interface::getPointField( - const smtk::mesh::HandleRange& /*meshsets*/, - const smtk::mesh::PointFieldTag& /*pfTag*/, - void* /*data*/) const -{ - return false; -} - -bool Interface::setPointField( - const smtk::mesh::HandleRange& /*meshsets*/, - const smtk::mesh::PointFieldTag& /*pfTag*/, - const void* /*data*/) -{ - return false; -} - -bool Interface::getField( - const smtk::mesh::HandleRange& /*points*/, - const smtk::mesh::PointFieldTag& /*pfTag*/, - void* /*data*/) const -{ - return false; -} - -bool Interface::setField( - const smtk::mesh::HandleRange& /*points*/, - const smtk::mesh::PointFieldTag& /*pfTag*/, - const void* /*data*/) -{ - return false; -} - -std::set Interface::computePointFieldTags( - const smtk::mesh::Handle& /*handle*/) const -{ - return std::set(); -} - -bool Interface::deletePointField( - const smtk::mesh::PointFieldTag& /*dsTag*/, - const smtk::mesh::HandleRange& /*meshsets*/) -{ - return false; -} - -smtk::mesh::HandleRange Interface::pointIntersect( - const smtk::mesh::HandleRange& /*a*/, - const smtk::mesh::HandleRange& /*b*/, - smtk::mesh::PointConnectivity& /*bpc*/, - smtk::mesh::ContainmentType /*containmentType*/) const -{ - return smtk::mesh::HandleRange(); -} - -smtk::mesh::HandleRange Interface::pointDifference( - const smtk::mesh::HandleRange& /*a*/, - const smtk::mesh::HandleRange& /*b*/, - smtk::mesh::PointConnectivity& /*bpc*/, - smtk::mesh::ContainmentType /*containmentType*/) const -{ - return smtk::mesh::HandleRange(); -} - -void Interface::pointForEach(const HandleRange& /*points*/, smtk::mesh::PointForEach& /*filter*/) - const -{ -} - -void Interface::cellForEach( - const HandleRange& /*cells*/, - smtk::mesh::PointConnectivity& /*a*/, - smtk::mesh::CellForEach& /*filter*/) const -{ -} - -void Interface::meshForEach( - const smtk::mesh::HandleRange& /*meshes*/, - smtk::mesh::MeshForEach& /*filter*/) const -{ -} - -bool Interface::deleteHandles(const smtk::mesh::HandleRange& /*toDel*/) -{ - return false; -} - -Interface::MeshInfoVecType::const_iterator Interface::find(smtk::mesh::Handle handle) const -{ - MeshInfoVecType::const_iterator result = std::find(m_meshInfo.begin(), m_meshInfo.end(), handle); - return result; -} -} // namespace json -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/json/Interface.h b/smtk/mesh/json/Interface.h deleted file mode 100644 index dcde6246f9a47c4af8ce7bce2c247506fd237e24..0000000000000000000000000000000000000000 --- a/smtk/mesh/json/Interface.h +++ /dev/null @@ -1,389 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_mesh_json_Interface_h -#define smtk_mesh_json_Interface_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/DimensionTypes.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/Interface.h" -#include "smtk/mesh/core/TypeSet.h" - -#include "smtk/mesh/json/MeshInfo.h" - -#include - -namespace smtk -{ -namespace mesh -{ -namespace json -{ -//construct an empty interface instance -SMTKCORE_EXPORT -smtk::mesh::json::InterfacePtr make_interface(); - -/// Concrete implementation for json serialization -class SMTKCORE_EXPORT Interface : public smtk::mesh::Interface -{ -public: - Interface(); - - Interface(const std::vector& info); - - ~Interface() override; - - //returns if the underlying data has been modified since the mesh was loaded - //from disk. If the mesh has no underlying file, it will always be considered - //modified. Once the mesh is written to disk, we will reset the modified - //flag. - bool isModified() const override; - - //get back a string that contains the pretty name for the interface class. - //Requirements: The string must be all lower-case. - std::string name() const override { return std::string("json"); } - - //Add more meshes to the Interface - void addMeshes(const std::vector& info); - - //get back a lightweight interface around allocating memory into the given - //interface. This is generally used to create new coordinates or cells that - //are than assigned to an existing mesh or new mesh - // - //If the current interface is read-only, the AllocatorPtr that is returned - //will be nullptr. - // - //Note: Merely fetching a valid allocator will mark the resource as - //modified. This is done instead of on a per-allocation basis so that - //modification state changes don't impact performance. - smtk::mesh::AllocatorPtr allocator() override; - - //get back a lightweight interface around incrementally allocating memory into - //the given interface. This is generally used to create new coordinates or - //cells that are than assigned to an existing mesh or new mesh. - // - //If the current interface is read-only, the BufferedCellAllocatorPtr that is - //returned will be nullptr. - // - //Note: Merely fetching a valid allocator will mark the resource as - //modified. This is done instead of on a per-allocation basis so that - //modification state changes don't impact performance. - smtk::mesh::BufferedCellAllocatorPtr bufferedCellAllocator() override; - - //get back a lightweight interface around incrementally allocating memory into - //the given interface. This is generally used to create new coordinates or - //cells that are than assigned to an existing mesh or new mesh. - // - //If the current interface is read-only, the IncrementalAllocatorPtr that is - //returned will be nullptr. - // - //Note: Merely fetching a valid allocator will mark the resource as - //modified. This is done instead of on a per-allocation basis so that - //modification state changes don't impact performance. - smtk::mesh::IncrementalAllocatorPtr incrementalAllocator() override; - - //get back an efficient storage mechanism for a range of cells point - //connectivity. This allows for efficient iteration of cell connectivity, and - //conversion to other formats - smtk::mesh::ConnectivityStoragePtr connectivityStorage( - const smtk::mesh::HandleRange& cells) override; - - //get back an efficient point locator for a range of points - //This allows for efficient point locator on a per interface basis. - smtk::mesh::PointLocatorImplPtr pointLocator(const smtk::mesh::HandleRange& points) override; - smtk::mesh::PointLocatorImplPtr pointLocator( - std::size_t numPoints, - const std::function(std::size_t)>& coordinates) override; - - smtk::mesh::Handle getRoot() const override; - - void registerQueries(smtk::mesh::Resource&) const override; - - //creates a mesh with that contains the input cells. - //the mesh will have the root as its parent. - //The mesh will be tagged with the GEOM_DIMENSION tag with a value that is - //equal to highest dimension of cell inside - //Will fail if the HandleRange is empty or doesn't contain valid - //cell handles. - bool createMesh(const smtk::mesh::HandleRange& cells, smtk::mesh::Handle& meshHandle) override; - - std::size_t numMeshes(smtk::mesh::Handle handle) const override; - - smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle) const override; - - smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle, int dimension) const override; - - //find all entity sets that have this exact name tag - smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle, const std::string& name) - const override; - - //find all entity sets that have this exact domain tag - smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle, const smtk::mesh::Domain& domain) - const override; - - //find all entity sets that have this exact dirichlet tag - smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Dirichlet& dirichlet) const override; - - //find all entity sets that have this exact neumann tag - smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle, const smtk::mesh::Neumann& neumann) - const override; - - //get all cells held by this range - smtk::mesh::HandleRange getCells(const smtk::mesh::HandleRange& meshsets) const override; - - //get all cells held by this range handle of a given cell type - smtk::mesh::HandleRange getCells( - const smtk::mesh::HandleRange& meshsets, - smtk::mesh::CellType cellType) const override; - - //get all cells held by this range handle of a given cell type(s) - smtk::mesh::HandleRange getCells( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellTypes& cellTypes) const override; - - //get all cells held by this range handle of a given dimension - smtk::mesh::HandleRange getCells( - const smtk::mesh::HandleRange& meshsets, - smtk::mesh::DimensionType dim) const override; - - //get all points held by this range of handle of a given dimension. If - //boundary_only is set to true, ignore the higher order points of the - //cells - smtk::mesh::HandleRange getPoints( - const smtk::mesh::HandleRange& cells, - bool boundary_only = false) const override; - - //get all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - //Floats are not how we store the coordinates internally, so asking for - //the coordinates in such a manner could cause data inaccuracies to appear - //so generally this is only used if you fully understand the input domain - bool getCoordinates(const smtk::mesh::HandleRange& points, double* xyz) const override; - - //get all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - bool getCoordinates(const smtk::mesh::HandleRange& points, float* xyz) const override; - - //set all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - bool setCoordinates(const smtk::mesh::HandleRange& points, const double* xyz) override; - - //set all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - bool setCoordinates(const smtk::mesh::HandleRange& points, const float* xyz) override; - - std::vector computeNames(const smtk::mesh::HandleRange& meshsets) const override; - - std::string name(const smtk::mesh::Handle& meshset) const override; - bool setName(const smtk::mesh::Handle& meshset, const std::string& name) override; - - std::vector computeDomainValues( - const smtk::mesh::HandleRange& meshsets) const override; - - std::vector computeDirichletValues( - const smtk::mesh::HandleRange& meshsets) const override; - - std::vector computeNeumannValues( - const smtk::mesh::HandleRange& meshsets) const override; - - smtk::common::UUIDArray computeModelEntities( - const smtk::mesh::HandleRange& meshsets) const override; - - smtk::mesh::TypeSet computeTypes(const smtk::mesh::HandleRange& range) const override; - - //compute the cells that make the shell/skin of the set of meshes - bool computeShell(const smtk::mesh::HandleRange& meshes, smtk::mesh::HandleRange& shell) - const override; - - //compute adjacencies of a given dimension, creating them if necessary - bool computeAdjacenciesOfDimension( - const smtk::mesh::HandleRange& meshes, - int dimension, - smtk::mesh::HandleRange& adj) const override; - - //given a handle to a cell, return its parent handle and canonical index. - bool canonicalIndex(const smtk::mesh::Handle& cell, smtk::mesh::Handle& parent, int& index) - const override; - - //given a handle to a cell, return its dimension-equivalent neighbors. - smtk::mesh::HandleRange neighbors(const smtk::mesh::Handle& cell) const override; - - //merge any duplicate points used by the cells that have been passed - bool mergeCoincidentContactPoints(const smtk::mesh::HandleRange& meshes, double tolerance) - override; - - bool setDomain(const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Domain& domain) - const override; - - bool setDirichlet(const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Dirichlet& dirichlet) - const override; - - bool setNeumann(const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Neumann& neumann) - const override; - - bool setId(const smtk::mesh::Handle& meshset, const smtk::common::UUID& id) const override; - - smtk::common::UUID getId(const smtk::mesh::Handle& meshset) const override; - - bool findById( - const smtk::mesh::Handle& root, - const smtk::common::UUID& id, - smtk::mesh::Handle& meshset) const override; - - bool setAssociation(const smtk::common::UUID& modelUUID, const smtk::mesh::HandleRange& meshsets) - const override; - - smtk::mesh::HandleRange findAssociations( - const smtk::mesh::Handle& root, - const smtk::common::UUID& modelUUID) const override; - - bool setRootAssociation(const smtk::common::UUID& modelUUID) const override; - - smtk::common::UUID rootAssociation() const override; - - bool createCellField( - const smtk::mesh::HandleRange& meshsets, - const std::string& name, - std::size_t dimension, - const smtk::mesh::FieldType& type, - const void* data) override; - - int getCellFieldDimension(const smtk::mesh::CellFieldTag& cfTag) const override; - smtk::mesh::FieldType getCellFieldType(const smtk::mesh::CellFieldTag& pfTag) const override; - - smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::CellFieldTag& cfTag) const override; - - bool hasCellField(const smtk::mesh::HandleRange& meshsets, const smtk::mesh::CellFieldTag& cfTag) - const override; - - bool getCellField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellFieldTag& cfTag, - void* data) const override; - - bool setCellField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellFieldTag& cfTag, - const void* data) override; - - bool getField( - const smtk::mesh::HandleRange& cells, - const smtk::mesh::CellFieldTag& cfTag, - void* data) const override; - - bool setField( - const smtk::mesh::HandleRange& cells, - const smtk::mesh::CellFieldTag& cfTag, - const void* data) override; - - std::set computeCellFieldTags( - const smtk::mesh::Handle& handle) const override; - - bool deleteCellField( - const smtk::mesh::CellFieldTag& cfTag, - const smtk::mesh::HandleRange& meshsets) override; - - bool createPointField( - const smtk::mesh::HandleRange& meshsets, - const std::string& name, - std::size_t dimension, - const smtk::mesh::FieldType& type, - const void* data) override; - - int getPointFieldDimension(const smtk::mesh::PointFieldTag& pfTag) const override; - smtk::mesh::FieldType getPointFieldType(const smtk::mesh::PointFieldTag& pfTag) const override; - - smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::PointFieldTag& pfTag) const override; - - bool hasPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag) const override; - - bool getPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag, - void* data) const override; - - bool setPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag, - const void* data) override; - - bool getField( - const smtk::mesh::HandleRange& points, - const smtk::mesh::PointFieldTag& pfTag, - void* data) const override; - - bool setField( - const smtk::mesh::HandleRange& points, - const smtk::mesh::PointFieldTag& pfTag, - const void* data) override; - - std::set computePointFieldTags( - const smtk::mesh::Handle& handle) const override; - - bool deletePointField( - const smtk::mesh::PointFieldTag& pfTag, - const smtk::mesh::HandleRange& meshsets) override; - - smtk::mesh::HandleRange pointIntersect( - const smtk::mesh::HandleRange& a, - const smtk::mesh::HandleRange& b, - smtk::mesh::PointConnectivity& bpc, - smtk::mesh::ContainmentType t) const override; - - smtk::mesh::HandleRange pointDifference( - const smtk::mesh::HandleRange& a, - const smtk::mesh::HandleRange& b, - smtk::mesh::PointConnectivity& bpc, - smtk::mesh::ContainmentType t) const override; - - void pointForEach(const HandleRange& points, smtk::mesh::PointForEach& filter) const override; - - void cellForEach( - const HandleRange& cells, - smtk::mesh::PointConnectivity& pc, - smtk::mesh::CellForEach& filter) const override; - - void meshForEach(const HandleRange& meshes, smtk::mesh::MeshForEach& filter) const override; - - bool deleteHandles(const smtk::mesh::HandleRange& toDel) override; - - void setModifiedState(bool state) override { m_modified = state; } - -private: - typedef std::vector MeshInfoVecType; - - MeshInfoVecType::const_iterator find(smtk::mesh::Handle handle) const; - - std::vector m_meshInfo; - - //this is ugly, but as this is the only state we have I am going to roll - //with it. If we start adding more member variables, we should offload it - //all to an internal class - mutable smtk::common::UUID m_associated_model; - mutable bool m_modified{ false }; -}; -} // namespace json -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/json/MeshInfo.cxx b/smtk/mesh/json/MeshInfo.cxx deleted file mode 100644 index 0f9448ccbcf36e31d7b7996e1e0a03c60856f2ac..0000000000000000000000000000000000000000 --- a/smtk/mesh/json/MeshInfo.cxx +++ /dev/null @@ -1,99 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/mesh/json/MeshInfo.h" - -#include "smtk/mesh/moab/CellTypeToType.h" -#include "smtk/mesh/moab/HandleRangeToRange.h" - -namespace smtk -{ -namespace mesh -{ -namespace json -{ - -MeshInfo::MeshInfo() = default; - -MeshInfo::MeshInfo( - smtk::mesh::Handle meshId, - const smtk::common::UUID& uuid, - const smtk::mesh::HandleRange& cells, - const smtk::mesh::HandleRange& points, - smtk::mesh::TypeSet types) - : m_mesh(meshId) - , m_uuid(uuid) - , m_cells(cells) - , m_points(points) - , m_types(types) -{ -} - -smtk::mesh::HandleRange MeshInfo::cells() const -{ - return m_cells; -} - -smtk::mesh::HandleRange MeshInfo::cells(smtk::mesh::CellType cellType) const -{ - const int moabCellType = smtk::mesh::moab::smtkToMOABCell(cellType); - return smtk::mesh::moab::moabToSMTKRange( - smtk::mesh::moab::smtkToMOABRange(m_cells).subset_by_type( - static_cast<::moab::EntityType>(moabCellType))); -} - -smtk::mesh::HandleRange MeshInfo::cells(const smtk::mesh::CellTypes& cellTypes) const -{ - smtk::mesh::HandleRange entitiesCells; - for (int i = static_cast(cellTypes.size() - 1); i >= 0; --i) - { - //skip all cell types we don't have - if (!cellTypes[i]) - { - continue; - } - - smtk::mesh::CellType currentCellType = static_cast(i); - - smtk::mesh::HandleRange cellEnts = this->cells(currentCellType); - entitiesCells += cellEnts; - } - return entitiesCells; -} - -smtk::mesh::HandleRange MeshInfo::cells(smtk::mesh::DimensionType dim) const -{ - return smtk::mesh::moab::moabToSMTKRange( - smtk::mesh::moab::smtkToMOABRange(m_cells).subset_by_dimension(static_cast(dim))); -} - -smtk::mesh::HandleRange MeshInfo::points() const -{ - return m_points; -} - -bool MeshInfo::has(const smtk::mesh::Domain& d) const -{ - return std::find(m_domains.begin(), m_domains.end(), d) != m_domains.end(); -} - -bool MeshInfo::has(const smtk::mesh::Dirichlet& bc) const -{ - return std::find(m_dirichlets.begin(), m_dirichlets.end(), bc) != m_dirichlets.end(); -} - -bool MeshInfo::has(const smtk::mesh::Neumann& bc) const -{ - return std::find(m_neumanns.begin(), m_neumanns.end(), bc) != m_neumanns.end(); -} -} // namespace json -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/json/MeshInfo.h b/smtk/mesh/json/MeshInfo.h deleted file mode 100644 index e3a89151659c2cf75ccdc62c5bc6b43356b3f8e7..0000000000000000000000000000000000000000 --- a/smtk/mesh/json/MeshInfo.h +++ /dev/null @@ -1,86 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_mesh_json_MeshInfo_h -#define smtk_mesh_json_MeshInfo_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/DimensionTypes.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/TypeSet.h" - -namespace smtk -{ -namespace mesh -{ -namespace json -{ - -class SMTKCORE_EXPORT MeshInfo -{ -public: - MeshInfo(); - - MeshInfo( - smtk::mesh::Handle meshId, - const smtk::common::UUID& uuid, - const smtk::mesh::HandleRange& cells, - const smtk::mesh::HandleRange& points, - smtk::mesh::TypeSet types); - - smtk::mesh::Handle mesh() const { return m_mesh; } - - smtk::mesh::TypeSet types() const { return m_types; } - - smtk::mesh::HandleRange cells() const; - smtk::mesh::HandleRange cells(smtk::mesh::CellType cellType) const; - smtk::mesh::HandleRange cells(const smtk::mesh::CellTypes& cellTypes) const; - smtk::mesh::HandleRange cells(smtk::mesh::DimensionType dim) const; - - smtk::mesh::HandleRange points() const; - - bool has(const smtk::mesh::Domain& d) const; - bool has(const smtk::mesh::Dirichlet& bc) const; - bool has(const smtk::mesh::Neumann& bc) const; - - const std::vector& domains() const { return m_domains; } - const std::vector& dirichlets() const { return m_dirichlets; } - const std::vector& neumanns() const { return m_neumanns; } - const smtk::common::UUIDArray& modelUUIDS() const { return m_uuids; } - const smtk::common::UUID& id() const { return m_uuid; } - - void set(const std::vector& ds) { m_domains = ds; } - void set(const std::vector& bcs) { m_dirichlets = bcs; } - void set(const std::vector& bcs) { m_neumanns = bcs; } - void set(const smtk::common::UUIDArray& array) { m_uuids = array; } - - bool operator==(const smtk::mesh::Handle& other) const { return other == m_mesh; } - -private: - smtk::mesh::Handle m_mesh; - smtk::common::UUID m_uuid; - smtk::mesh::HandleRange m_cells; - smtk::mesh::HandleRange m_points; - smtk::mesh::TypeSet m_types; - - std::vector m_domains; - std::vector m_dirichlets; - std::vector m_neumanns; - smtk::common::UUIDArray m_uuids; -}; -} // namespace json -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/json/jsonHandleRange.cxx b/smtk/mesh/json/jsonHandleRange.cxx deleted file mode 100644 index d9695d6d9738dd15b3ca22260174edb196744aeb..0000000000000000000000000000000000000000 --- a/smtk/mesh/json/jsonHandleRange.cxx +++ /dev/null @@ -1,42 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/json/jsonHandleRange.h" - -namespace smtk -{ -namespace mesh -{ -using nlohmann::json; - -void to_json(nlohmann::json& j, const smtk::mesh::HandleRange& handleRange) -{ - for (const auto& handleInterval : handleRange) - { - j.push_back(std::make_pair(handleInterval.lower(), handleInterval.upper())); - } -} - -void from_json(const nlohmann::json& j, smtk::mesh::HandleRange& handleRange) -{ - if (j.is_null()) - { - return; - } - - std::pair handlePair; - - for (const auto& jsonHandleInterval : j) - { - handlePair = jsonHandleInterval.get>(); - handleRange.insert(handleRange.end(), HandleInterval(handlePair.first, handlePair.second)); - } -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/json/jsonHandleRange.h b/smtk/mesh/json/jsonHandleRange.h deleted file mode 100644 index 23dea0c8b9e447f71fca87a52ec4db98edab62f5..0000000000000000000000000000000000000000 --- a/smtk/mesh/json/jsonHandleRange.h +++ /dev/null @@ -1,44 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_json_jsonHandleRange_h -#define smtk_mesh_json_jsonHandleRange_h - -#include "smtk/CoreExports.h" - -#include "smtk/mesh/core/Handle.h" - -#include "nlohmann/json.hpp" - -// Define how resources are serialized. -namespace smtk -{ -namespace mesh -{ -SMTKCORE_EXPORT void to_json(nlohmann::json&, const smtk::mesh::HandleRange&); - -SMTKCORE_EXPORT void from_json(const nlohmann::json&, smtk::mesh::HandleRange&); -} // namespace mesh -} // namespace smtk - -namespace nlohmann -{ -template<> -struct adl_serializer -{ - static void to_json(json& j, const smtk::mesh::HandleRange& opt) { smtk::mesh::to_json(j, opt); } - - static void from_json(const json& j, smtk::mesh::HandleRange& opt) - { - smtk::mesh::from_json(j, opt); - } -}; -} // namespace nlohmann - -#endif diff --git a/smtk/mesh/json/jsonMeshInfo.cxx b/smtk/mesh/json/jsonMeshInfo.cxx deleted file mode 100644 index 55d164811b55d0a0c1f096a335fa6a36a55b6faa..0000000000000000000000000000000000000000 --- a/smtk/mesh/json/jsonMeshInfo.cxx +++ /dev/null @@ -1,161 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/json/jsonMeshInfo.h" - -#include "smtk/common/json/jsonUUID.h" - -#include "smtk/mesh/core/QueryTypes.h" -#include "smtk/mesh/json/MeshInfo.h" -#include "smtk/mesh/json/jsonHandleRange.h" - -namespace -{ -const std::string dirName = "dirichlet"; -const std::string neumName = "neumann"; -} // namespace - -namespace smtk -{ -namespace mesh -{ -namespace json -{ -void to_json(nlohmann::json& /*j*/, const std::vector& /*meshInfos*/) -{ - // smtk::mesh::HandleRange meshIds; - // for (auto& meshInfo : meshInfos) - // { - // meshIds.insert(meshInfo.mesh()); - // } - - // j["meshIds"] = meshIds; - - // nlohmann::json meshes_json; - // for (auto& meshInfo : meshInfos) - // { - // nlohmann::json mesh_json; - // mesh_json["cells"] = meshInfo.cells(); - // mesh_json["points"] = meshInfo.points(); - - // mesh_json["id"] = meshInfo.id(); - // mesh_json["modelEntityIds"] = meshInfo.modelUUIDS(); - - // std::vector domainValues; - // if (meshInfo.domains().empty() == false) - // { - // for (std::size_t i = 0; i < meshInfo.domains().size(); i++) - // { - // domainValues.push_back(meshInfo.domains().at(i).value()); - // } - // } - // mesh_json["domains"] = domainValues; - - // nlohmann::json bcs_json; - // for (auto& bc : meshInfo.dirichlets()) - // { - // nlohmann::json bc_json; - // bc_json["type"] = dirName; - // bc_json["value"] = bc.value(); - // bcs_json.push_back(bc_json); - // } - // for (auto& bc : meshInfo.neumanns()) - // { - // nlohmann::json bc_json; - // bc_json["type"] = neumName; - // bc_json["value"] = bc.value(); - // bcs_json.push_back(bc_json); - // } - - // mesh_json["boundary_conditions"] = bcs_json; - - // meshes_json.push_back(mesh_json); - // } - - // j["meshes"] = meshes_json; -} - -void from_json(const nlohmann::json& /*j*/, std::vector& /*meshInfos*/) -{ - //extract the ids of all the meshes and make it a smtk::mesh::Handle - - // smtk::mesh::HandleRange meshIds = j.at("meshIds"); - - // nlohmann::json meshes_json = j.at("meshes"); - - // auto meshIdIter = smtk::mesh::rangeElementsBegin(meshIds); - // for (nlohmann::json::iterator mesh_json_it = meshes_json.begin(); - // mesh_json_it != meshes_json.end(); ++mesh_json_it, ++meshIdIter) - // { - // nlohmann::json mesh_json = *mesh_json_it; - - // //get the Typeset from the json - // std::string cell_bit_types = mesh_json.at("cell_types"); - // smtk::mesh::TypeSet types(smtk::mesh::CellTypes(cell_bit_types), false, true); - - // //get the points and cells of the mesh - // smtk::mesh::HandleRange cells = mesh_json.at("cells"); - // smtk::mesh::HandleRange points = mesh_json.at("points"); - - // //get the uuid of the mesh - // smtk::common::UUID id = mesh_json.at("id"); - - // //get any model entity ids that are associated to this mesh - // smtk::common::UUIDArray modelEnts = mesh_json.at("modelEntityIds"); - - // std::vector domains; - // std::vector domainValues = mesh_json.at("domains"); - // for (auto domainValue : domainValues) - // { - // domains.push_back(smtk::mesh::Domain(domainValue)); - // } - - // std::vector dirichlets; - // std::vector neumanns; - - // for (auto& bc : mesh_json.at("boundary_conditions")) - // { - // std::string bcType = bc.at("type"); - // int value = bc.at("value"); - - // if (bcType == dirName) - // { - // dirichlets.push_back(smtk::mesh::Dirichlet(value)); - // } - // else if (bcType == neumName) - // { - // neumanns.push_back(smtk::mesh::Neumann(value)); - // } - // } - - // smtk::mesh::json::MeshInfo meshInfo(*meshIdIter, id, cells, points, types); - // //specify the optional parts of the mesh info - // if (!modelEnts.empty()) - // { - // meshInfo.set(modelEnts); - // } - // if (!domains.empty()) - // { - // meshInfo.set(domains); - // } - // if (!dirichlets.empty()) - // { - // meshInfo.set(dirichlets); - // } - // if (!neumanns.empty()) - // { - // meshInfo.set(neumanns); - // } - - // meshInfos.push_back(meshInfo); - // } -} -} // namespace json -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/json/jsonMeshInfo.h b/smtk/mesh/json/jsonMeshInfo.h deleted file mode 100644 index f5115f03fec41a3260875b3703db0634f415215d..0000000000000000000000000000000000000000 --- a/smtk/mesh/json/jsonMeshInfo.h +++ /dev/null @@ -1,32 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_json_jsonMeshInfo_h -#define smtk_mesh_json_jsonMeshInfo_h - -#include "nlohmann/json.hpp" - -#include - -namespace smtk -{ -namespace mesh -{ -namespace json -{ -class MeshInfo; - -void to_json(nlohmann::json&, const std::vector&); - -void from_json(const nlohmann::json&, std::vector&); -} // namespace json -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/json/jsonResource.cxx b/smtk/mesh/json/jsonResource.cxx deleted file mode 100644 index 4487a9d322427683c96889cda583d20edf420a9d..0000000000000000000000000000000000000000 --- a/smtk/mesh/json/jsonResource.cxx +++ /dev/null @@ -1,158 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/json/jsonResource.h" - -// NOTE: If you forget to include jsonUUID.h, everything compiles and runs -// correctly in debug mode, but UUID serialization breaks down in release -// mode. My guess is that an nlohmann template specialization for UUIDs -// needs to exist before it is first called; otherwise, a symbol is -// generated for UUIDs and its use is continued in favor of the explicit -// one encountered afterwards. -#include "smtk/common/json/jsonUUID.h" - -#include "smtk/mesh/json/Interface.h" -#include "smtk/mesh/json/jsonHandleRange.h" -#include "smtk/mesh/json/jsonMeshInfo.h" - -#include "smtk/mesh/core/ForEachTypes.h" - -#include "smtk/resource/json/jsonResource.h" - -namespace -{ -const std::string dirName = "dirichlet"; -const std::string neumName = "neumann"; - -class ForMeshset : public smtk::mesh::MeshForEach -{ -public: - ForMeshset(nlohmann::json& j) - : m_json(j) - { - } - - void write( - const smtk::mesh::MeshSet& mesh, - nlohmann::json& j, - bool writeMeshes, - bool writeCellAndPoints) - { - j["cell_types"] = mesh.types().cellTypes().to_string(); - - //needs to be by value since cells() will go out out of scope, and - //we don't want a reference to a stack object that has gone out of scope - if (writeMeshes) - { - j["meshIds"] = mesh.range(); - } - - if (writeCellAndPoints) - { - j["cells"] = mesh.cells().range(); - j["points"] = mesh.points().range(); - } - - j["id"] = mesh.id(); - j["modelEntityIds"] = mesh.modelEntityIds(); - - std::vector domainValues; - for (auto& domain : mesh.domains()) - { - domainValues.push_back(domain.value()); - } - j["domains"] = domainValues; - - nlohmann::json bcs_json; - - std::vector dirichlets = mesh.dirichlets(); - for (std::size_t i = 0; i < dirichlets.size(); ++i) - { - nlohmann::json bc_json; - bc_json["type"] = dirName; - bc_json["value"] = dirichlets[i].value(); - bcs_json.push_back(bc_json); - } - std::vector neumanns = mesh.neumanns(); - for (std::size_t i = 0; i < neumanns.size(); ++i) - { - nlohmann::json bc_json; - bc_json["type"] = neumName; - bc_json["value"] = neumanns[i].value(); - bcs_json.push_back(bc_json); - } - - j["boundary_conditions"] = bcs_json; - } - - void forMesh(smtk::mesh::MeshSet& mesh) override - { - nlohmann::json j; - - const bool writeMeshes = false; - const bool writeCellAndPoints = true; - this->write(mesh, j, writeMeshes, writeCellAndPoints); - - m_json.push_back(j); - } - -private: - nlohmann::json& m_json; -}; -} // namespace - -namespace smtk -{ -namespace mesh -{ -void to_json(nlohmann::json& j, const ResourcePtr& resource) -{ - smtk::resource::to_json(j, smtk::static_pointer_cast(resource)); - - ForMeshset addInfoAboutResource(j); - const bool writeMeshes = true; - const bool writeCellAndPoints = false; - - nlohmann::json info_json; - addInfoAboutResource.write(resource->meshes(), info_json, writeMeshes, writeCellAndPoints); - j["info"] = info_json; - - //now walk through each meshset and dump all the info related to it. - nlohmann::json meshes_json; - - smtk::mesh::MeshSet meshes = resource->meshes(); - ForMeshset perMeshExportToJson(meshes_json); - smtk::mesh::for_each(meshes, perMeshExportToJson); - - j["meshes"] = meshes_json; -} - -void from_json(const nlohmann::json& j, ResourcePtr& resource) -{ - if (!resource) - { - // It's derived class's responsibility to create a valid mresource - return; - } - - auto temp = std::static_pointer_cast(resource); - smtk::resource::from_json(j, temp); - - std::vector meshInfos = j; - - smtk::mesh::json::InterfacePtr interface = - smtk::dynamic_pointer_cast(resource->interface()); - - if (interface) - { - interface->addMeshes(meshInfos); - } -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/json/jsonResource.h b/smtk/mesh/json/jsonResource.h deleted file mode 100644 index 5ff4cffee8f0cb55f996a0057745c4a685a820d2..0000000000000000000000000000000000000000 --- a/smtk/mesh/json/jsonResource.h +++ /dev/null @@ -1,27 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_json_jsonResource_h -#define smtk_mesh_json_jsonResource_h - -#include "smtk/mesh/core/Resource.h" - -#include "nlohmann/json.hpp" - -namespace smtk -{ -namespace mesh -{ -SMTKCORE_EXPORT void to_json(nlohmann::json&, const ResourcePtr&); - -SMTKCORE_EXPORT void from_json(const nlohmann::json&, ResourcePtr&); -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/Allocator.cxx b/smtk/mesh/moab/Allocator.cxx deleted file mode 100644 index 22b982503af2d72a4576be2ceaf2ff832a74ce24..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/Allocator.cxx +++ /dev/null @@ -1,122 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/mesh/moab/Allocator.h" -#include "smtk/mesh/moab/CellTypeToType.h" - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/Interface.hpp" -#include "moab/ReadUtilIface.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -Allocator::Allocator(::moab::Interface* interface) -{ - if (interface) - { - interface->query_interface(m_rface); - } -} - -Allocator::~Allocator() -{ - //don't de-allocate the Interface that created us, really manages this - //memory - m_rface = nullptr; -} - -bool Allocator::allocatePoints( - std::size_t numPointsToAlloc, - smtk::mesh::Handle& firstVertexHandle, - std::vector& coordinateMemory) -{ - if (m_rface == nullptr) - { - return false; - } - ::moab::ErrorCode err; - err = m_rface->get_node_coords( - 3, //x,y,z - static_cast(numPointsToAlloc), - 0, //preferred_start_id - firstVertexHandle, - coordinateMemory); - return err == ::moab::MB_SUCCESS; -} - -bool Allocator::allocateCells( - smtk::mesh::CellType cellType, - std::size_t numCellsToAlloc, - int numVertsPerCell, - smtk::mesh::HandleRange& createdCellIds, - smtk::mesh::Handle*& connectivityArray) -{ - if (m_rface == nullptr) - { - return false; - } - ::moab::ErrorCode err; - smtk::mesh::Handle startHandle; - - const int moabCellType = smtk::mesh::moab::smtkToMOABCell(cellType); - - err = m_rface->get_element_connect( - static_cast(numCellsToAlloc), - numVertsPerCell, - static_cast<::moab::EntityType>(moabCellType), - 0, //preferred_start_id - startHandle, - connectivityArray); - - createdCellIds = smtk::mesh::HandleRange( - smtk::mesh::HandleInterval(startHandle, startHandle + numCellsToAlloc - 1)); - return err == ::moab::MB_SUCCESS; -} - -bool Allocator::connectivityModified( - const smtk::mesh::HandleRange& cellsToUpdate, - int numVertsPerCell, - const smtk::mesh::Handle* connectivityArray) -{ - return this->connectivityModified( - smtk::mesh::rangeElement(cellsToUpdate, 0), - static_cast(cellsToUpdate.size()), - numVertsPerCell, - connectivityArray); -} - -bool Allocator::connectivityModified( - smtk::mesh::Handle firstCellToUpdate, - int numberOfCellsToUpdate, - int numVertsPerCell, - const smtk::mesh::Handle* connectivityArray) -{ - if (m_rface == nullptr) - { - return false; - } - - ::moab::ErrorCode err; - err = m_rface->update_adjacencies( - firstCellToUpdate, numberOfCellsToUpdate, numVertsPerCell, connectivityArray); - return err == ::moab::MB_SUCCESS; -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/Allocator.h b/smtk/mesh/moab/Allocator.h deleted file mode 100644 index c91aef336e8a472179c78060f1f794f144b7563c..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/Allocator.h +++ /dev/null @@ -1,74 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_mesh_moab_Allocator_h -#define smtk_mesh_moab_Allocator_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/moab/Interface.h" - -namespace moab -{ -class ReadUtilIface; -} - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -class SMTKCORE_EXPORT Allocator : public smtk::mesh::Allocator -{ -public: - Allocator(::moab::Interface* interface); - - ~Allocator() override; - - Allocator(const Allocator& other) = delete; - Allocator& operator=(const Allocator& other) = delete; - - bool allocatePoints( - std::size_t numPointsToAlloc, - smtk::mesh::Handle& firstVertexHandle, - std::vector& coordinateMemory) override; - - bool allocateCells( - smtk::mesh::CellType cellType, - std::size_t numCellsToAlloc, - int numVertsPerCell, - smtk::mesh::HandleRange& createdCellIds, - smtk::mesh::Handle*& connectivityArray) override; - - bool connectivityModified( - const smtk::mesh::HandleRange& cellsToUpdate, - int numVertsPerCell, - const smtk::mesh::Handle* connectivityArray) override; - -protected: - bool connectivityModified( - smtk::mesh::Handle firstCellToUpdate, - int numberOfCellsToUpdate, - int numVertsPerCell, - const smtk::mesh::Handle* connectivityArray); - -private: - //holds a reference to the real moab interface - ::moab::ReadUtilIface* m_rface = nullptr; -}; -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/BufferedCellAllocator.cxx b/smtk/mesh/moab/BufferedCellAllocator.cxx deleted file mode 100644 index f26d746aa5d1dabafaeae78deb06da7f28e0ed16..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/BufferedCellAllocator.cxx +++ /dev/null @@ -1,163 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/mesh/moab/BufferedCellAllocator.h" -#include "smtk/mesh/moab/CellTypeToType.h" -#include "smtk/mesh/moab/HandleRangeToRange.h" - -#include "smtk/mesh/core/CellTypes.h" - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/Interface.hpp" -#include "moab/ReadUtilIface.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -BufferedCellAllocator::BufferedCellAllocator(::moab::Interface* interface) - : Allocator(interface) -{ -} - -BufferedCellAllocator::~BufferedCellAllocator() -{ - this->flush(); -} - -bool BufferedCellAllocator::reserveNumberOfCoordinates(std::size_t nCoordinates) -{ - // Can only reserve coordinates once - if (m_nCoordinates != 0) - { - return false; - } - - m_validState = this->allocatePoints(nCoordinates, m_firstCoordinate, m_coordinateMemory); - - if (m_validState) - { - m_nCoordinates = nCoordinates; - } - - return m_validState; -} - -bool BufferedCellAllocator::setCoordinate(std::size_t coord, double* xyz) -{ - if (!m_validState) - { - return false; - } - assert(coord < m_nCoordinates); - - m_coordinateMemory[0][coord] = xyz[0]; - m_coordinateMemory[1][coord] = xyz[1]; - m_coordinateMemory[2][coord] = xyz[2]; - - return m_validState; -} - -bool BufferedCellAllocator::flush() -{ - if (!m_validState) - { - return false; - } - - if (m_localConnectivity.empty()) - { - return true; - } - - if (m_activeCellType == smtk::mesh::CellType_MAX) - { - return false; - } - - if (m_activeCellType == smtk::mesh::Vertex) - { - // In the moab/interface world vertices don't have explicit connectivity - // so we can't allocate cells. Instead we just explicitly add those - // points to the cells range - for (auto&& ptCoordinate : m_localConnectivity) - { - m_cells.insert(m_firstCoordinate + ptCoordinate); - } - - m_localConnectivity.clear(); - - return m_validState; - } - - // only convert cells smtk mesh supports - smtk::mesh::HandleRange cellsCreatedForThisType; - - // need to convert from smtk cell type to moab cell type - ::moab::EntityHandle* startOfConnectivityArray = nullptr; - - m_validState = this->allocateCells( - m_activeCellType, - m_localConnectivity.size() / m_nCoords, - m_nCoords, - cellsCreatedForThisType, - startOfConnectivityArray); - - if (m_validState) - { - // now that we have the chunk allocated need to fill it - // we do this by iterating the cells - for (std::size_t i = 0; i < m_localConnectivity.size(); ++i) - { - startOfConnectivityArray[i] = m_firstCoordinate + m_localConnectivity[i]; - } - - // notify database that we have written to connectivity, that way - // it can properly update adjacencies and other database info - this->connectivityModified( - m_cells.front(), static_cast(m_cells.size()), m_nCoords, startOfConnectivityArray); - - // insert these cells back into the range - auto it = cellsCreatedForThisType.begin(); - m_cells.insert(it->lower(), it->upper()); - } - - m_localConnectivity.clear(); - - return m_validState; -} - -smtk::mesh::HandleRange BufferedCellAllocator::cells() -{ - return moabToSMTKRange(m_cells); -} - -void BufferedCellAllocator::clear() -{ - m_firstCoordinate = 0; - m_nCoordinates = 0; - m_coordinateMemory.clear(); - m_activeCellType = smtk::mesh::CellType_MAX; - m_nCoords = 0; - m_localConnectivity.clear(); - m_cells.clear(); -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/BufferedCellAllocator.h b/smtk/mesh/moab/BufferedCellAllocator.h deleted file mode 100644 index 3dcb6669c3d515846d2edeb33e5fe09fb5804e90..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/BufferedCellAllocator.h +++ /dev/null @@ -1,123 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_mesh_moab_BufferedCellAllocator_h -#define smtk_mesh_moab_BufferedCellAllocator_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/moab/Allocator.h" -#include "smtk/mesh/moab/Interface.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/EntityHandle.hpp" -#include "moab/Range.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include -#include - -namespace moab -{ -class ReadUtilIface; -} - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -class SMTKCORE_EXPORT BufferedCellAllocator - : public smtk::mesh::BufferedCellAllocator - , protected smtk::mesh::moab::Allocator -{ -public: - BufferedCellAllocator(::moab::Interface* interface); - - ~BufferedCellAllocator() override; - - BufferedCellAllocator(const BufferedCellAllocator& other) = delete; - BufferedCellAllocator& operator=(const BufferedCellAllocator& other) = delete; - - bool reserveNumberOfCoordinates(std::size_t nCoordinates) override; - bool setCoordinate(std::size_t coord, double* xyz) override; - - bool addCell(smtk::mesh::CellType ctype, long long int* pointIds, std::size_t nCoordinates = 0) - override - { - return this->addCell(ctype, pointIds, nCoordinates); - } - bool addCell(smtk::mesh::CellType ctype, long int* pointIds, std::size_t nCoordinates = 0) - override - { - return this->addCell(ctype, pointIds, nCoordinates); - } - bool addCell(smtk::mesh::CellType ctype, int* pointIds, std::size_t nCoordinates = 0) override - { - return this->addCell(ctype, pointIds, nCoordinates); - } - - bool flush() override; - - smtk::mesh::HandleRange cells() override; - - void clear(); - -protected: - template - bool addCell(smtk::mesh::CellType ctype, IntegerType* pointIds, std::int64_t nCoordinates); - - ::moab::EntityHandle m_firstCoordinate{ 0 }; - std::size_t m_nCoordinates{ 0 }; - std::vector m_coordinateMemory; - smtk::mesh::CellType m_activeCellType{ smtk::mesh::CellType_MAX }; - int m_nCoords{ 0 }; - std::vector m_localConnectivity; - ::moab::Range m_cells; -}; - -template -bool BufferedCellAllocator::addCell( - smtk::mesh::CellType ctype, - IntegerType* pointIds, - std::int64_t nCoordinates) -{ - if (!m_validState) - { - return false; - } - - if (ctype != m_activeCellType || (nCoordinates != 0 && nCoordinates != m_nCoords)) - { - m_validState = this->flush(); - m_activeCellType = ctype; - m_nCoords = - nCoordinates != 0 ? static_cast(nCoordinates) : smtk::mesh::verticesPerCell(ctype); - } - - assert(m_activeCellType != smtk::mesh::CellType_MAX); - assert(m_nCoords > 0); - - for (std::int64_t i = 0; i < m_nCoords; i++) - { - m_localConnectivity.push_back(pointIds[i]); - } - - return m_validState; -} -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/CellTypeToType.cxx b/smtk/mesh/moab/CellTypeToType.cxx deleted file mode 100644 index ff441ca90ea4a456cab871146b160f5bed078577..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/CellTypeToType.cxx +++ /dev/null @@ -1,108 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/EntityType.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include "smtk/mesh/moab/CellTypeToType.h" - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -smtk::mesh::CellType moabToSMTKCell(int t) -{ - ::moab::EntityType et = static_cast<::moab::EntityType>(t); - smtk::mesh::CellType ctype = smtk::mesh::CellType_MAX; - switch (et) - { - case ::moab::MBVERTEX: - ctype = smtk::mesh::Vertex; - break; - case ::moab::MBEDGE: - ctype = smtk::mesh::Line; - break; - case ::moab::MBTRI: - ctype = smtk::mesh::Triangle; - break; - case ::moab::MBQUAD: - ctype = smtk::mesh::Quad; - break; - case ::moab::MBPOLYGON: - ctype = smtk::mesh::Polygon; - break; - case ::moab::MBTET: - ctype = smtk::mesh::Tetrahedron; - break; - case ::moab::MBPYRAMID: - ctype = smtk::mesh::Pyramid; - break; - case ::moab::MBPRISM: - ctype = smtk::mesh::Wedge; - break; - case ::moab::MBHEX: - ctype = smtk::mesh::Hexahedron; - break; - default: - ctype = smtk::mesh::CellType_MAX; - break; - } - return ctype; -} - -int smtkToMOABCell(smtk::mesh::CellType t) -{ - ::moab::EntityType ctype = ::moab::MBMAXTYPE; - switch (t) - { - case smtk::mesh::Vertex: - ctype = ::moab::MBVERTEX; - break; - case smtk::mesh::Line: - ctype = ::moab::MBEDGE; - break; - case smtk::mesh::Triangle: - ctype = ::moab::MBTRI; - break; - case smtk::mesh::Quad: - ctype = ::moab::MBQUAD; - break; - case smtk::mesh::Polygon: - ctype = ::moab::MBPOLYGON; - break; - case smtk::mesh::Tetrahedron: - ctype = ::moab::MBTET; - break; - case smtk::mesh::Pyramid: - ctype = ::moab::MBPYRAMID; - break; - case smtk::mesh::Wedge: - ctype = ::moab::MBPRISM; - break; - case smtk::mesh::Hexahedron: - ctype = ::moab::MBHEX; - break; - default: - ctype = ::moab::MBMAXTYPE; - break; - } - return ctype; -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/CellTypeToType.h b/smtk/mesh/moab/CellTypeToType.h deleted file mode 100644 index 28cb7ba435895a9c8a77ebb9fbb76fc6f3e3a02a..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/CellTypeToType.h +++ /dev/null @@ -1,35 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#ifndef smtk_mesh_moab_CellTypeToType_h -#define smtk_mesh_moab_CellTypeToType_h - -#include "smtk/mesh/core/CellTypes.h" - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -//these aren't exported as they are private functions that only -//smtk::mesh should call - -smtk::mesh::CellType moabToSMTKCell(int t); - -int smtkToMOABCell(smtk::mesh::CellType t); -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif // smtk_mesh_moab_CellTypeToType_h diff --git a/smtk/mesh/moab/ClosestPoint.cxx b/smtk/mesh/moab/ClosestPoint.cxx deleted file mode 100644 index f7a2fedb673932233ac00dc92488b409a934d401..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/ClosestPoint.cxx +++ /dev/null @@ -1,117 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/moab/ClosestPoint.h" - -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/moab/HandleRangeToRange.h" -#include "smtk/mesh/moab/Interface.h" -#include "smtk/mesh/moab/PointLocatorCache.h" - -#include - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ -std::array ClosestPoint::operator()( - const smtk::resource::Component::Ptr& component, - const std::array& point) const -{ - auto meshComponent = std::dynamic_pointer_cast(component); - if (meshComponent) - { - return operator()(meshComponent->mesh(), point); - } - - auto modelComponent = std::dynamic_pointer_cast(component); - if (modelComponent) - { - return operator()( - modelComponent->referenceAs().meshTessellation(), point); - } - - return this->Parent::operator()(component, point); -} - -std::array ClosestPoint::operator()( - const smtk::mesh::MeshSet& meshset, - const std::array& point) const -{ - static constexpr const double nan = std::numeric_limits::quiet_NaN(); - std::array returnValue{ { nan, nan, nan } }; - - // If the entity has a mesh tessellation, and the mesh backend is moab, and - // the tessellation has triangles... - if ( - meshset.isValid() && meshset.resource()->interfaceName() == "moab" && - meshset.types().hasCell(smtk::mesh::Triangle)) - { - PointLocatorCache& pointLocatorCache = meshset.resource()->queries().cache(); - - //...then we can use Moab's AdaptiveKDTree to find closest points. - const smtk::mesh::moab::InterfacePtr& interface = - std::static_pointer_cast(meshset.resource()->interface()); - - auto search = pointLocatorCache.m_caches.find(meshset.id()); - if (search == pointLocatorCache.m_caches.end()) - { - // This option restricts the KD tree from subdividing too much - ::moab::FileOptions treeOptions("MAX_DEPTH=13"); - - search = - pointLocatorCache.m_caches - .emplace( - meshset.id(), - std::make_unique( - interface->moabInterface(), smtkToMOABRange(meshset.cells().range()), &treeOptions)) - .first; - } - - ::moab::EntityHandle triangleOut; - - // Identify the nearest point and the associated triangle - search->second->m_tree.closest_triangle( - search->second->m_treeRootSet, point.data(), returnValue.data(), triangleOut); - - // ...access the three vertices of the nearest triangle - ::moab::Range connectivity; - interface->moabInterface()->get_connectivity(&triangleOut, 1, connectivity); - std::array coords; - interface->moabInterface()->get_coords(connectivity, coords.data()); - - // Compute the squared distance betwen the source point and the vertex - std::array dist2 = { { 0., 0., 0. } }; - for (std::size_t j = 0; j < 3; j++) - { - for (std::size_t k = 0; k < 3; k++) - { - double tmp = coords[3 * j + k] - point[k]; - dist2[j] += tmp * tmp; - } - } - - // Assign the closest point to the coordinates of the closest vertex - std::size_t index = std::distance(dist2.begin(), std::min_element(dist2.begin(), dist2.end())); - for (std::size_t j = 0; j < 3; j++) - { - returnValue[j] = coords[3 * index + j]; - } - } - - return returnValue; -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/ClosestPoint.h b/smtk/mesh/moab/ClosestPoint.h deleted file mode 100644 index 63d412fe5761c741ec6cbf4fceba2a47513ee3f5..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/ClosestPoint.h +++ /dev/null @@ -1,48 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_moab_ClosestPoint_h -#define smtk_mesh_moab_ClosestPoint_h - -#include "smtk/CoreExports.h" - -#include "smtk/geometry/queries/ClosestPoint.h" - -#include "smtk/mesh/core/MeshSet.h" - -#include "smtk/resource/Component.h" - -#include - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -/**\brief An API for computing a the closest point on a geometric resource - * component to an input point. The returned value represents a tessellation or - * model vertex; no interpolation is performed. - */ -struct SMTKCORE_EXPORT ClosestPoint - : public smtk::resource::query::DerivedFrom -{ - std::array operator()( - const smtk::resource::Component::Ptr&, - const std::array&) const override; - - std::array operator()(const smtk::mesh::MeshSet&, const std::array&) const; -}; -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/ConnectivityStorage.cxx b/smtk/mesh/moab/ConnectivityStorage.cxx deleted file mode 100644 index 24108a6335d23a701977a479573a283b5a9f6dac..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/ConnectivityStorage.cxx +++ /dev/null @@ -1,234 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/moab/ConnectivityStorage.h" -#include "smtk/mesh/moab/CellTypeToType.h" -#include "smtk/mesh/moab/HandleRangeToRange.h" -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/Interface.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#ifndef NDEBUG -#include -#endif - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -ConnectivityStorage::ConnectivityStorage( - ::moab::Interface* iface, - const smtk::mesh::HandleRange& cells) -{ - std::size_t cellCount = 0; - std::size_t vertCount = 0; - - ::moab::Range moabCells = smtkToMOABRange(cells); - - ::moab::Range::const_iterator cells_current = moabCells.begin(); - ::moab::Range::const_iterator cells_end = moabCells.end(); - - //We allocate VertConnectivityStorage once before we insert any vertices - //this gaurentees that all of the ConnectivityStartPositions pointers - //into our storage are valid. Otherwise the realloc's will cause - //pointer invalidation - const std::size_t numVerts = moabCells.num_of_type(::moab::MBVERTEX); - this->VertConnectivityStorage.reserve(numVerts); - - //first find all vertices. Vertices are a special case - //where they are their own connectivity. Moab orders - //the vertices first so, if cells_current isnt a vertice - //we have none - while (cells_current != cells_end && iface->type_from_handle(*cells_current) == ::moab::MBVERTEX) - { - - ::moab::Range::iterator verts_start = cells_current.start_of_block(); - ::moab::Range::iterator verts_end = cells_current.end_of_block(); - - const int numVertsPerCell = 1; - const int numCellsInSubRange = static_cast(std::distance(verts_start, verts_end + 1)); - - //add to the VertConnectivityStorage the ids of the vertices in this - //range - std::copy(verts_start, verts_end + 1, std::back_inserter(this->VertConnectivityStorage)); - - smtk::mesh::Handle* connectivity = &(this->VertConnectivityStorage[vertCount]); - this->ConnectivityStartPositions.push_back(connectivity); - this->ConnectivityArraysLengths.push_back(numCellsInSubRange); - this->ConnectivityVertsPerCell.push_back(numVertsPerCell); - this->ConnectivityTypePerCell.push_back(smtk::mesh::Vertex); - - //increment our iterator - cells_current += static_cast(numCellsInSubRange); - - //increment our num cells and verts counters - cellCount += static_cast(numCellsInSubRange); - vertCount += static_cast(numCellsInSubRange * numVertsPerCell); - } - - while (cells_current != cells_end) - { - ::moab::EntityHandle* connectivity; - int numVertsPerCell = 0, numCellsInSubRange = 0; - - ::moab::ErrorCode result = iface->connect_iterate( - cells_current, moabCells.end(), connectivity, numVertsPerCell, numCellsInSubRange); - - if (result == ::moab::MB_SUCCESS) - { - this->ConnectivityStartPositions.push_back(connectivity); - this->ConnectivityArraysLengths.push_back(numCellsInSubRange); - this->ConnectivityVertsPerCell.push_back(numVertsPerCell); - - //fetch the current cell type for this block - ::moab::EntityType moabCellType = iface->type_from_handle(*cells_current); - this->ConnectivityTypePerCell.push_back( - smtk::mesh::moab::moabToSMTKCell(static_cast(moabCellType))); - - //increment our iterator - cells_current += static_cast(numCellsInSubRange); - - //increment our num cells and verts counters - cellCount += static_cast(numCellsInSubRange); - vertCount += static_cast(numCellsInSubRange * numVertsPerCell); - } - else - { -//we shouldn't presume all ids coming in have connectivity. In theory -//if we are passed spectral elements we will get back no connectivity. -//the same goes for vertices -#ifndef NDEBUG - std::cerr << "Passed range that contained non cell ids" << std::endl; - std::cerr << "Handle ids " << *cells_current.start_of_block() << " to " - << *cells_current.end_of_block() << "are not cell ids" << std::endl; -#endif - - //increment our iterator to skip all these bad ids - cells_current = cells_current.end_of_block(); - ++cells_current; - } - } - - this->NumberOfCells = cellCount; - this->NumberOfVerts = vertCount; -} - -ConnectivityStorage::~ConnectivityStorage() = default; - -void ConnectivityStorage::initTraversal(smtk::mesh::ConnectivityStorage::IterationState& state) -{ - state.whichConnectivityVector = 0; - state.ptrOffsetInVector = 0; -} - -bool ConnectivityStorage::fetchNextCell( - smtk::mesh::ConnectivityStorage::IterationState& state, - smtk::mesh::CellType& cellType, - int& numPts, - const smtk::mesh::Handle*& points) -{ - if (state.whichConnectivityVector >= this->ConnectivityVertsPerCell.size()) - { //we have iterated passed the end of connectivity pointers - return false; - } - - const std::size_t index = state.whichConnectivityVector; - const std::size_t ptr = state.ptrOffsetInVector; - - cellType = this->ConnectivityTypePerCell[index]; - numPts = this->ConnectivityVertsPerCell[index]; - points = &this->ConnectivityStartPositions[index][ptr]; - - //now determine if we can safely increment - const std::size_t currentArrayLength = - this->ConnectivityArraysLengths[index] * this->ConnectivityVertsPerCell[index]; - - //check the last position we are accessing with this fetch - //to properly determine this is the last cell that is valid - if (ptr + numPts >= currentArrayLength) - { - //move to the next vector - ++state.whichConnectivityVector; - state.ptrOffsetInVector = 0; - } - else - { - state.ptrOffsetInVector += numPts; - } - return true; -} - -bool ConnectivityStorage::equal(smtk::mesh::ConnectivityStorage* base_other) const -{ - if (this == base_other) - { - return true; - } - if (!base_other) - { - return false; - } - - smtk::mesh::moab::ConnectivityStorage* other = - dynamic_cast(base_other); - if (!other) - { - return false; - } - - //two quick checks that can confirm two items aren't equal - if (this->NumberOfCells != other->NumberOfCells) - { - return false; - } - - if (this->ConnectivityStartPositions.size() != other->ConnectivityStartPositions.size()) - { - return false; - } - - //now we know that both sets have the same number of moab pointers - //and the total number of cells are the same. So we just have too - //iterate the handles and the array lengths and confirm they all match. - //in theory you could have equal start positions but different lengths - //that both sum up to the same total num cells. - - typedef std::vector::const_iterator hc_it; - typedef std::vector::const_iterator ic_it; - - const hc_it this_end = this->ConnectivityStartPositions.end(); - - hc_it this_ptr = this->ConnectivityStartPositions.begin(); - hc_it other_ptr = other->ConnectivityStartPositions.begin(); - - ic_it this_len = this->ConnectivityArraysLengths.begin(); - ic_it other_len = other->ConnectivityArraysLengths.begin(); - - while (this_ptr != this_end && *this_ptr == *other_ptr && *this_len == *other_len) - { - ++this_ptr; - ++other_ptr; - ++this_len; - ++other_len; - } - - //if we are at the end that means the resources match - return this_ptr == this_end; -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/ConnectivityStorage.h b/smtk/mesh/moab/ConnectivityStorage.h deleted file mode 100644 index 75e727f7e0ba5d6254b354ac2d96662ce421a8bc..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/ConnectivityStorage.h +++ /dev/null @@ -1,65 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_moab_ConnectivityStorage_h -#define smtk_mesh_moab_ConnectivityStorage_h - -#include "smtk/PublicPointerDefs.h" -#include "smtk/mesh/core/Handle.h" - -#include "smtk/mesh/moab/Interface.h" - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -class SMTKCORE_EXPORT ConnectivityStorage : public smtk::mesh::ConnectivityStorage -{ -public: - ConnectivityStorage(::moab::Interface* interface, const smtk::mesh::HandleRange& cells); - - ~ConnectivityStorage() override; - - ConnectivityStorage(const ConnectivityStorage& other) = delete; - ConnectivityStorage& operator=(const ConnectivityStorage& other) = delete; - - void initTraversal(smtk::mesh::ConnectivityStorage::IterationState& state) override; - - bool fetchNextCell( - smtk::mesh::ConnectivityStorage::IterationState& state, - smtk::mesh::CellType& cellType, - int& numPts, - const smtk::mesh::Handle*& points) override; - - bool equal(smtk::mesh::ConnectivityStorage* other) const override; - - std::size_t cellSize() const override { return NumberOfCells; } - - std::size_t vertSize() const override { return NumberOfVerts; } - -private: - std::vector ConnectivityStartPositions; - std::vector ConnectivityArraysLengths; - std::vector ConnectivityVertsPerCell; - std::vector ConnectivityTypePerCell; - std::size_t NumberOfCells{ 0 }; - std::size_t NumberOfVerts{ 0 }; - - //moab vertices don't have connectivity so we create our own - std::vector VertConnectivityStorage; -}; -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/DistanceTo.cxx b/smtk/mesh/moab/DistanceTo.cxx deleted file mode 100644 index c202b42043c203249f9261633abb09eaf761eef8..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/DistanceTo.cxx +++ /dev/null @@ -1,102 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/moab/DistanceTo.h" - -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/moab/HandleRangeToRange.h" -#include "smtk/mesh/moab/Interface.h" -#include "smtk/mesh/moab/PointLocatorCache.h" - -#include - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ -std::pair> DistanceTo::operator()( - const smtk::resource::Component::Ptr& component, - const std::array& point) const -{ - auto meshComponent = std::dynamic_pointer_cast(component); - if (meshComponent) - { - return operator()(meshComponent->mesh(), point); - } - - auto modelComponent = std::dynamic_pointer_cast(component); - if (modelComponent) - { - return operator()( - modelComponent->referenceAs().meshTessellation(), point); - } - - return this->Parent::operator()(component, point); -} - -std::pair> DistanceTo::operator()( - const smtk::mesh::MeshSet& meshset, - const std::array& point) const -{ - static constexpr const double nan = std::numeric_limits::quiet_NaN(); - std::pair> returnValue(nan, { { nan, nan, nan } }); - - // If the entity has a mesh tessellation, and the mesh backend is moab, and - // the tessellation has triangles... - if ( - meshset.isValid() && meshset.resource()->interfaceName() == "moab" && - meshset.types().hasCell(smtk::mesh::Triangle)) - { - PointLocatorCache& pointLocatorCache = meshset.resource()->queries().cache(); - - //...then we can use Moab's AdaptiveKDTree to find closest points. - const smtk::mesh::moab::InterfacePtr& interface = - std::static_pointer_cast(meshset.resource()->interface()); - - auto search = pointLocatorCache.m_caches.find(meshset.id()); - if (search == pointLocatorCache.m_caches.end()) - { - // This option restricts the KD tree from subdividing too much - ::moab::FileOptions treeOptions("MAX_DEPTH=13"); - - search = - pointLocatorCache.m_caches - .emplace( - meshset.id(), - std::make_unique( - interface->moabInterface(), smtkToMOABRange(meshset.cells().range()), &treeOptions)) - .first; - } - - ::moab::EntityHandle triangleOut; - - // Identify the nearest point and the associated triangle - // cacheForIndex->m_tree.closest_triangle( - // cacheForIndex->m_treeRootSet, point.data(), &returnValue.second[0], triangleOut); - search->second->m_tree.closest_triangle( - search->second->m_treeRootSet, point.data(), returnValue.second.data(), triangleOut); - - returnValue.first = 0.; - for (int i = 0; i < 3; i++) - { - returnValue.first += (point[i] - returnValue.second[i]) * (point[i] - returnValue.second[i]); - } - returnValue.first = sqrt(returnValue.first); - } - - return returnValue; -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/DistanceTo.h b/smtk/mesh/moab/DistanceTo.h deleted file mode 100644 index 8012dd84102a9ab616d7f57a22ea075dc7f6b736..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/DistanceTo.h +++ /dev/null @@ -1,53 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_moab_DistanceTo_h -#define smtk_mesh_moab_DistanceTo_h - -#include "smtk/CoreExports.h" - -#include "smtk/geometry/queries/DistanceTo.h" - -#include "smtk/mesh/core/MeshSet.h" - -#include "smtk/resource/Component.h" - -#include -#include - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -/**\brief An API for computing the shortest distance between an input point and - * a geometric resource component. The location of the point on the component - * is also returned. This query differs from ClosestPoint in that the returned - * point does not need to be explicitly contained within the geometric - * representation. - */ -struct SMTKCORE_EXPORT DistanceTo - : public smtk::resource::query::DerivedFrom -{ - std::pair> operator()( - const smtk::resource::Component::Ptr&, - const std::array&) const override; - - std::pair> operator()( - const smtk::mesh::MeshSet&, - const std::array&) const; -}; -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/HandleRangeToRange.cxx b/smtk/mesh/moab/HandleRangeToRange.cxx deleted file mode 100644 index 940d336d83dfab64874466457ff0bf7c4ae161b1..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/HandleRangeToRange.cxx +++ /dev/null @@ -1,46 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#include "smtk/mesh/moab/HandleRangeToRange.h" - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -smtk::mesh::HandleRange moabToSMTKRange(const ::moab::Range& range) -{ - smtk::mesh::HandleRange handleRange; - for (::moab::Range::pair_iterator it = range.begin(); it != range.end(); ++it) - { - handleRange.add(handleRange.end(), HandleInterval(it->first, it->second)); - } - return handleRange; -} - -::moab::Range smtkToMOABRange(const smtk::mesh::HandleRange& handleRange) -{ - ::moab::Range range; - - // As per the advice in Moab's Range.hpp documentation, we insert ranges from - // largest to smallest. - for (auto it = handleRange.rbegin(); it != handleRange.rend(); ++it) - { - range.insert(range.begin(), it->lower(), it->upper()); - } - return range; -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/HandleRangeToRange.h b/smtk/mesh/moab/HandleRangeToRange.h deleted file mode 100644 index 0a374cebab4e1630e3fd36be408d4e6361b609c2..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/HandleRangeToRange.h +++ /dev/null @@ -1,44 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#ifndef smtk_mesh_moab_HandleRangeToRange_h -#define smtk_mesh_moab_HandleRangeToRange_h - -#include "smtk/CoreExports.h" - -#include "smtk/mesh/core/Handle.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/EntityHandle.hpp" -#include "moab/Range.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -//these aren't exported as they are private functions that only -//smtk::mesh should call - -SMTKCORE_EXPORT -smtk::mesh::HandleRange moabToSMTKRange(const ::moab::Range&); - -SMTKCORE_EXPORT -::moab::Range smtkToMOABRange(const smtk::mesh::HandleRange&); -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/IncrementalAllocator.cxx b/smtk/mesh/moab/IncrementalAllocator.cxx deleted file mode 100644 index 39d17168fcf52820d32546bbb70fd403a09329e1..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/IncrementalAllocator.cxx +++ /dev/null @@ -1,131 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/mesh/moab/IncrementalAllocator.h" -#include "smtk/mesh/moab/CellTypeToType.h" - -#include "smtk/mesh/core/CellTypes.h" - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/Interface.hpp" -#include "moab/ReadUtilIface.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include - -namespace -{ -// must be a power of two -const std::size_t StartingAllocation = 64; // (1<<6) -} // namespace - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -IncrementalAllocator::IncrementalAllocator(::moab::Interface* interface) - : BufferedCellAllocator(interface) -{ -} - -void IncrementalAllocator::initialize() -{ - if (m_nCoordinates == 0) - { - this->IncrementalAllocator::allocateCoordinates(StartingAllocation); - } -} - -bool IncrementalAllocator::allocateCoordinates(std::size_t nCoordinates) -{ - m_validState = this->BufferedCellAllocator::allocatePoints( - nCoordinates, m_firstCoordinate, m_coordinateMemory); - - if (m_validState) - { - m_nCoordinates += nCoordinates; - } - - m_coordinateMemories.push_back(m_coordinateMemory); - - return m_validState; -} - -std::size_t IncrementalAllocator::addCoordinate(double* xyz) -{ - if (!m_validState) - { - return false; - } - - if (m_nCoordinates <= m_index) - { - this->IncrementalAllocator::allocateCoordinates(m_nCoordinates); - if (!m_validState) - { - return m_index; - } - } - - m_validState = this->IncrementalAllocator::setCoordinate(m_index, xyz); - - return m_index++; -} - -bool IncrementalAllocator::setCoordinate(std::size_t coord, double* xyz) -{ - if (!m_validState) - { - return false; - } - - if (coord >= m_nCoordinates) - { - return false; - } - - // Coordinates are allocated using a memory doubling scheme, and we need to - // figure out - // (a) , the chunk of allocated memory in which resides, and - // (b) , or starting index for chunck . - // We do this by performing successive integer divisions by two (c >>= 1) - // while keeping track of the number of divisions we have performed (++exp) - // and by performing successive integer doublings of our offset by two - // (offset <<= 1). - - std::size_t exp = 0; - std::size_t offset = StartingAllocation >> 1; - - for (std::size_t c = coord; c >= StartingAllocation; c >>= 1) - { - ++exp; - offset <<= 1; - } - - if (exp > 0) - { - coord -= offset; - } - - m_coordinateMemories[exp][0][coord] = xyz[0]; - m_coordinateMemories[exp][1][coord] = xyz[1]; - m_coordinateMemories[exp][2][coord] = xyz[2]; - - return m_validState; -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/IncrementalAllocator.h b/smtk/mesh/moab/IncrementalAllocator.h deleted file mode 100644 index c2b62e6186ef29d84c14073a15232f964ada674c..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/IncrementalAllocator.h +++ /dev/null @@ -1,87 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_mesh_moab_IncrementalAllocator_h -#define smtk_mesh_moab_IncrementalAllocator_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/moab/BufferedCellAllocator.h" -#include "smtk/mesh/moab/Interface.h" - -#include - -#include - -namespace moab -{ -class ReadUtilIface; -} - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -class SMTKCORE_EXPORT IncrementalAllocator - : public smtk::mesh::IncrementalAllocator - , protected smtk::mesh::moab::BufferedCellAllocator -{ -public: - IncrementalAllocator(::moab::Interface* interface); - - ~IncrementalAllocator() override = default; - - IncrementalAllocator(const IncrementalAllocator& other) = delete; - IncrementalAllocator& operator=(const IncrementalAllocator& other) = delete; - - std::size_t addCoordinate(double* xyz) override; - bool setCoordinate(std::size_t coord, double* xyz) override; - - bool addCell(smtk::mesh::CellType ctype, long long int* pointIds, std::size_t nCoordinates = 0) - override - { - return BufferedCellAllocator::addCell(ctype, pointIds, nCoordinates); - } - bool addCell(smtk::mesh::CellType ctype, long int* pointIds, std::size_t nCoordinates = 0) - override - { - return BufferedCellAllocator::addCell(ctype, pointIds, nCoordinates); - } - bool addCell(smtk::mesh::CellType ctype, int* pointIds, std::size_t nCoordinates = 0) override - { - return BufferedCellAllocator::addCell(ctype, pointIds, nCoordinates); - } - - bool flush() override { return BufferedCellAllocator::flush(); } - - smtk::mesh::HandleRange cells() override { return BufferedCellAllocator::cells(); } - - bool isValid() const override { return BufferedCellAllocator::isValid(); } - -protected: - bool allocateCoordinates(std::size_t nCoordinates); - - friend class Interface; - void initialize(); - -private: - std::size_t m_index{ 0 }; - std::vector> m_coordinateMemories; -}; -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/Interface.cxx b/smtk/mesh/moab/Interface.cxx deleted file mode 100644 index 34ae5c7cf83f7818e9aaa9bc6df7c4f9d66985d0..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/Interface.cxx +++ /dev/null @@ -1,2301 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/QueryTypes.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/moab/Allocator.h" -#include "smtk/mesh/moab/BufferedCellAllocator.h" -#include "smtk/mesh/moab/CellTypeToType.h" -#include "smtk/mesh/moab/ClosestPoint.h" -#include "smtk/mesh/moab/ConnectivityStorage.h" -#include "smtk/mesh/moab/DistanceTo.h" -#include "smtk/mesh/moab/HandleRangeToRange.h" -#include "smtk/mesh/moab/IncrementalAllocator.h" -#include "smtk/mesh/moab/MergeMeshVertices.h" -#include "smtk/mesh/moab/PointLocatorImpl.h" -#include "smtk/mesh/moab/RandomPoint.h" - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/Core.hpp" -#include "moab/FileOptions.hpp" -#include "moab/Interface.hpp" - -#include "moab/ErrorHandler.hpp" -#include "moab/ReaderIface.hpp" -#include "moab/Skinner.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#define BEING_INCLUDED_BY_INTERFACE_CXX -//required to go after moab includes -#include "smtk/mesh/moab/Tags.h" -#undef BEING_USED_BY_INTERFACE_CXX - -#include -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -namespace detail -{ -smtk::mesh::HandleRange vectorToHandleRange(std::vector<::moab::EntityHandle>& vresult) -{ - smtk::mesh::HandleRange resulting_range; - const std::size_t size = vresult.size(); - for (std::size_t i = 0; i < size;) - { - std::size_t j; - for (j = i + 1; j < size && vresult[j] == 1 + vresult[j - 1]; j++) - ; - //empty for loop - resulting_range.insert( - resulting_range.end(), smtk::mesh::HandleInterval(vresult[i], vresult[i] + (j - i - 1))); - i = j; - } - return resulting_range; -} - -template -std::vector -computeDenseIntTagValues(U tag, const ::moab::Range& meshsets, ::moab::Interface* iface) -{ - std::vector result; - - //fetch all entities with the given tag - ::moab::Range entitiesWithTag; - iface->get_entities_by_type_and_tag( - iface->get_root_set(), ::moab::MBENTITYSET, tag.moabTagPtr(), nullptr, 1, entitiesWithTag); - - //we have all entity sets that have the this tag - //now we need to find the subset that is part of our - //HandleRange - entitiesWithTag = ::moab::intersect(entitiesWithTag, meshsets); - - //return early if nothing has the tag. - //this also makes it safer to derefence the std vector below - if (entitiesWithTag.empty()) - { - return result; - } - - //allocate a vector large enough to hold the tag values for every element - std::vector tag_values; - tag_values.resize(entitiesWithTag.size()); - void* tag_v_ptr = tag_values.data(); - - //fetch the tag for each item in the range in bulk - iface->tag_get_data(tag.moabTag(), entitiesWithTag, tag_v_ptr); - - //find and remove duplicates - std::sort(tag_values.begin(), tag_values.end()); - tag_values.erase(std::unique(tag_values.begin(), tag_values.end()), tag_values.end()); - - //for each tag value convert it to a type T, where T is an - //IntTag from smtk::mesh - result.reserve(tag_values.size()); - typedef std::vector::const_iterator cit; - for (cit i = tag_values.begin(); i != tag_values.end(); ++i) - { - result.push_back(T(*i)); - } - return result; -} - -template -T computeDenseOpaqueTagValues(U tag, const ::moab::Range& meshsets, ::moab::Interface* iface) -{ - T result; - - // Fetch all entities with the given tag - ::moab::Range entitiesWithTag; - iface->get_entities_by_type_and_tag( - iface->get_root_set(), ::moab::MBENTITYSET, tag.moabTagPtr(), nullptr, 1, entitiesWithTag); - - // We have all entity sets that have the this tag; now we need - // to find the subset that is part of our HandleRange. - entitiesWithTag = ::moab::intersect(entitiesWithTag, meshsets); - - // Return early if nothing has the tag. - // This also makes it safer to derefence the std vector below - if (entitiesWithTag.empty()) - return result; - - std::vector tag_values; - tag_values.resize(entitiesWithTag.size() * tag.size()); - void* tag_v_ptr = tag_values.data(); - - // Fetch the tag for each item in the range in bulk - iface->tag_get_data(tag.moabTag(), entitiesWithTag, tag_v_ptr); - - // For each tag value convert it to a value type for the - // output container T. - typedef std::vector::const_iterator cit; - for (cit i = tag_values.begin(); i != tag_values.end(); i += tag.size()) - { - result.push_back(typename T::value_type(&(*i), &(*i) + tag.size())); - } - return result; -} - -template -T computeDenseOpaqueTagValue(U tag, const smtk::mesh::Handle& handle, ::moab::Interface* iface) -{ - std::vector tag_values; - tag_values.resize(tag.size()); - void* tag_v_ptr = tag_values.data(); - - // Fetch the tag for each item in the range in bulk - ::moab::ErrorCode rval = iface->tag_get_data(tag.moabTag(), &handle, 1, tag_v_ptr); - - T result; - if (rval == ::moab::MB_SUCCESS) - { - std::vector::const_iterator i = tag_values.begin(); - result = T(&(*i), &(*i) + tag.size()); - } - return result; -} - -template -bool setDenseTagValues(T tag, const ::moab::Range& handles, ::moab::Interface* iface) -{ - //create a vector the same value so we can assign a tag - std::vector values; - values.resize(handles.size(), tag.value()); - const void* tag_v_ptr = values.data(); - - ::moab::ErrorCode rval = iface->tag_set_data(tag.moabTag(), handles, tag_v_ptr); - return (rval == ::moab::MB_SUCCESS); -} - -template -bool setDenseOpaqueTagValues(T tag, const ::moab::Range& handles, ::moab::Interface* iface) -{ - //create a vector the same value so we can assign a tag - std::vector values; - values.resize(handles.size() * tag.size()); - for (std::size_t i = 0; i < handles.size(); ++i) - memcpy(&values[i * tag.size()], tag.value(), tag.size()); - const void* tag_v_ptr = values.data(); - - ::moab::ErrorCode rval = iface->tag_set_data(tag.moabTag(), handles, tag_v_ptr); - return (rval == ::moab::MB_SUCCESS); -} - -template -bool setDenseOpaqueTagValue(T tag, const smtk::mesh::Handle& handle, ::moab::Interface* iface) -{ - //create a vector the same value so we can assign a tag - std::vector values; - values.resize(tag.size()); - memcpy(values.data(), tag.value(), tag.size()); - const void* tag_v_ptr = values.data(); - - ::moab::ErrorCode rval = iface->tag_set_data(tag.moabTag(), &handle, 1, tag_v_ptr); - return (rval == ::moab::MB_SUCCESS); -} - -} // namespace detail - -//construct an empty interface instance -smtk::mesh::moab::InterfacePtr make_interface() -{ - //Core is a fully implemented moab::Interface - return std::make_shared(); -} - -//Given a smtk::mesh Interface convert it to a smtk::mesh::moab interface -smtk::mesh::moab::InterfacePtr extract_interface(const smtk::mesh::ResourcePtr& c) -{ - return smtk::dynamic_pointer_cast(c->interface()); -} - -//Given a smtk::mesh Interface convert it to a smtk::mesh::moab interface, and than -//extract the raw moab interface pointer from that -::moab::Interface* extract_moab_interface(const smtk::mesh::InterfacePtr& iface) -{ - smtk::mesh::moab::Interface* mi = dynamic_cast(iface.get()); - return (mi == nullptr) ? nullptr : mi->moabInterface(); -} - -Interface::Interface() - : m_iface(new ::moab::Core()) -{ - m_alloc = std::make_shared(m_iface.get()); - m_bcAlloc = std::make_shared(m_iface.get()); - m_iAlloc = std::make_shared(m_iface.get()); - - // Moab has become increasingly verbose. For now, let's make it quiet. - // - // TODO: pipe moab messaging through SMTK's messaging (perhaps with some - // filtering) - ::moab::MBErrorHandler_Finalize(); -} - -Interface::~Interface() = default; - -bool Interface::isModified() const -{ - return m_modified; -} - -smtk::mesh::AllocatorPtr Interface::allocator() -{ - //mark us as modified as the caller is going to add something to the database - m_modified = true; - return m_alloc; -} - -smtk::mesh::BufferedCellAllocatorPtr Interface::bufferedCellAllocator() -{ - //mark us as modified as the caller is going to add something to the database - m_modified = true; - std::static_pointer_cast(m_bcAlloc)->clear(); - return m_bcAlloc; -} - -smtk::mesh::IncrementalAllocatorPtr Interface::incrementalAllocator() -{ - //mark us as modified as the caller is going to add something to the database - m_modified = true; - static_cast(m_iAlloc.get())->initialize(); - return m_iAlloc; -} - -smtk::mesh::ConnectivityStoragePtr Interface::connectivityStorage( - const smtk::mesh::HandleRange& cells) -{ - //make boost shared_ptr - smtk::mesh::ConnectivityStoragePtr cs( - new smtk::mesh::moab::ConnectivityStorage(m_iface.get(), cells)); - return cs; -} - -smtk::mesh::PointLocatorImplPtr Interface::pointLocator(const smtk::mesh::HandleRange& points) -{ - return smtk::mesh::PointLocatorImplPtr( - new smtk::mesh::moab::PointLocatorImpl(m_iface.get(), smtkToMOABRange(points))); -} - -smtk::mesh::PointLocatorImplPtr Interface::pointLocator( - std::size_t numPoints, - const std::function(std::size_t)>& coordinates) -{ - if (numPoints == 0) - { - return smtk::mesh::PointLocatorImplPtr(); - } - return smtk::mesh::PointLocatorImplPtr( - new smtk::mesh::moab::PointLocatorImpl(m_iface.get(), numPoints, coordinates)); -} - -smtk::mesh::Handle Interface::getRoot() const -{ - return m_iface->get_root_set(); -} - -void Interface::registerQueries(smtk::mesh::Resource& resource) const -{ - resource.queries().registerQuery(); - resource.queries().registerQuery(); - resource.queries().registerQuery(); -} - -bool Interface::createMesh(const smtk::mesh::HandleRange& cells, smtk::mesh::Handle& meshHandle) -{ - if (cells.empty()) - { - return false; - } - - ::moab::Range moabCells = smtkToMOABRange(cells); - - //make sure the cells are actually cells instead of meshsets. - //we currently don't want this allow adding sub meshsets - if (moabCells.num_of_type(::moab::MBENTITYSET) != 0) - { - return false; - } - - const unsigned int options = 0; - ::moab::ErrorCode rval = m_iface->create_meshset(options, meshHandle); - if (rval == ::moab::MB_SUCCESS) - { - m_iface->add_entities(meshHandle, moabCells); - m_iface->add_parent_child(m_iface->get_root_set(), meshHandle); - - int dimension = 4; - bool hasDim = false; - while (!hasDim && dimension >= 0) - { - //by starting at 4 and decrementing we don't need to branch - //on hasDim to see if we need to decrement at the end of - //the while loop - --dimension; - - //iterate the entities and find the higest dimension of cell. - //once that is found add a geom sparse tag to the mesh - hasDim = (moabCells.num_of_dimension(dimension) > 0); - } - - //add the dim tag - tag::QueryDimTag dimTag(dimension, this->moabInterface()); - m_iface->tag_set_data(dimTag.moabTag(), &meshHandle, 1, dimTag.moabTagValuePtr()); - } - - if (rval == ::moab::MB_SUCCESS) - { - m_modified = true; - return true; - } - return false; -} - -std::size_t Interface::numMeshes(smtk::mesh::Handle handle) const -{ - int num_ents = 0; - m_iface->get_number_entities_by_type(handle, ::moab::MBENTITYSET, num_ents); - return static_cast(num_ents); -} - -smtk::mesh::HandleRange Interface::getMeshsets(smtk::mesh::Handle handle) const - -{ - ::moab::Range range; - m_iface->get_entities_by_type(handle, ::moab::MBENTITYSET, range); - return moabToSMTKRange(range); -} - -smtk::mesh::HandleRange Interface::getMeshsets(smtk::mesh::Handle handle, int dimension) const - -{ - typedef std::vector<::moab::EntityHandle>::const_iterator it; - - //use a vector since we are going to do single element iteration, and - //removal. - std::vector<::moab::EntityHandle> all_ents; - std::vector<::moab::EntityHandle> matching_ents; - m_iface->get_entities_by_type(handle, ::moab::MBENTITYSET, all_ents); - - //add all meshsets that have at least a single cell of the given dimension - for (it i = all_ents.begin(); i != all_ents.end(); ++i) - { - ::moab::Range cells_of_given_dim; - m_iface->get_entities_by_dimension(*i, dimension, cells_of_given_dim); - if (!cells_of_given_dim.empty()) - { - matching_ents.push_back(*i); - } - } - return detail::vectorToHandleRange(matching_ents); -} - -//find all entity sets that have this exact name tag -smtk::mesh::HandleRange Interface::getMeshsets(smtk::mesh::Handle handle, const std::string& name) - const - -{ - typedef std::vector<::moab::EntityHandle>::const_iterator it; - - //use a vector since we are going to do single element iteration, and - //removal. - std::vector<::moab::EntityHandle> all_ents; - std::vector<::moab::EntityHandle> matching_ents; - m_iface->get_entities_by_type(handle, ::moab::MBENTITYSET, all_ents); - - //see which ones have a a matching name, and if so add it - //we don't use get_entities_by_type_and_tag as it doesn't - //seem to work with name tags - tag::QueryNameTag query_name(this->moabInterface()); - for (it i = all_ents.begin(); i != all_ents.end(); ++i) - { - const bool has_name = query_name.fetch_name(*i); - if (has_name && (name == query_name.current_name())) - { //has a matching name - matching_ents.push_back(*i); - } - } - return detail::vectorToHandleRange(matching_ents); -} - -//find all entity sets that have this exact name tag -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Domain& domain) const - -{ - tag::QueryMaterialTag mtag(domain.value(), this->moabInterface()); - - ::moab::Range result; - ::moab::ErrorCode rval; - rval = m_iface->get_entities_by_type_and_tag( - handle, ::moab::MBENTITYSET, mtag.moabTagPtr(), mtag.moabTagValuePtr(), 1, result); - if (rval != ::moab::MB_SUCCESS) - { - result.clear(); - } - return moabToSMTKRange(result); -} - -//find all entity sets that have this exact name tag -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Dirichlet& dirichlet) const - -{ - tag::QueryDirichletTag dtag(dirichlet.value(), this->moabInterface()); - - ::moab::Range result; - ::moab::ErrorCode rval; - rval = m_iface->get_entities_by_type_and_tag( - handle, ::moab::MBENTITYSET, dtag.moabTagPtr(), dtag.moabTagValuePtr(), 1, result); - if (rval != ::moab::MB_SUCCESS) - { - result.clear(); - } - return moabToSMTKRange(result); -} - -//find all entity sets that have this exact name tag -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Neumann& neumann) const - -{ - tag::QueryNeumannTag ntag(neumann.value(), this->moabInterface()); - - ::moab::Range result; - ::moab::ErrorCode rval; - rval = m_iface->get_entities_by_type_and_tag( - handle, ::moab::MBENTITYSET, ntag.moabTagPtr(), ntag.moabTagValuePtr(), 1, result); - if (rval != ::moab::MB_SUCCESS) - { - result.clear(); - } - return moabToSMTKRange(result); -} - -//get all cells held by this range -smtk::mesh::HandleRange Interface::getCells(const smtk::mesh::HandleRange& meshsets) const - -{ - // get all non-meshset entities in meshset, including in contained meshsets - ::moab::Range entitiesCells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_handle appends to the range given - m_iface->get_entities_by_handle(*i, entitiesCells, true); - } - return moabToSMTKRange(entitiesCells); -} - -//get all cells held by this range handle of a given cell type -smtk::mesh::HandleRange Interface::getCells( - const smtk::mesh::HandleRange& meshsets, - smtk::mesh::CellType cellType) const -{ - int moabCellType = smtk::mesh::moab::smtkToMOABCell(cellType); - - ::moab::Range entitiesCells; - - // get all non-meshset entities in meshset of a given cell type - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_type appends to the range given - m_iface->get_entities_by_type( - *i, static_cast<::moab::EntityType>(moabCellType), entitiesCells, true); - } - - return moabToSMTKRange(entitiesCells); -} - -//get all cells held by this range handle of a given cell type(s) -smtk::mesh::HandleRange Interface::getCells( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellTypes& cellTypes) const - -{ - const std::size_t cellTypesToFind = cellTypes.count(); - if (cellTypesToFind == cellTypes.size()) - { //if all the cellTypes are enabled we should just use get_cells - //all() method can't be used as it was added in C++11 - return this->getCells(meshsets); - } - else if (cellTypesToFind == 0) - { - return smtk::mesh::HandleRange(); - } - - //we now search from highest cell type to lowest cell type adding everything - //to the range. The reason for this is that ranges perform best when inserting - //from high to low values - smtk::mesh::HandleRange entitiesCells; - for (int i = static_cast((cellTypes.size() - 1)); i >= 0; --i) - { - //skip all cell types we don't have - if (!cellTypes[i]) - { - continue; - } - - smtk::mesh::CellType currentCellType = static_cast(i); - - smtk::mesh::HandleRange cellEnts = this->getCells(meshsets, currentCellType); - - entitiesCells += cellEnts; - } - - return entitiesCells; -} - -//get all cells held by this range handle of a given dimension -smtk::mesh::HandleRange Interface::getCells( - const smtk::mesh::HandleRange& meshsets, - smtk::mesh::DimensionType dim) const - -{ - const int dimension = static_cast(dim); - - //get all non-meshset entities of a given dimension - ::moab::Range entitiesCells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_dimension appends to the range given - m_iface->get_entities_by_dimension(*i, dimension, entitiesCells, true); - } - return moabToSMTKRange(entitiesCells); -} - -//get all cells held by this range handle of a given dimension -smtk::mesh::HandleRange Interface::getPoints( - const smtk::mesh::HandleRange& cells, - bool boundary_only) const - -{ - ::moab::Range moabCells = smtkToMOABRange(cells); - ::moab::Range pointIds; - m_iface->get_connectivity(moabCells, pointIds, boundary_only); - return moabToSMTKRange(pointIds); -} - -bool Interface::getCoordinates(const smtk::mesh::HandleRange& points, double* xyz) const - -{ - if (points.empty()) - { - return false; - } - - m_iface->get_coords(smtkToMOABRange(points), xyz); - return true; -} - -namespace -{ -class GetCoords : public smtk::mesh::PointForEach -{ -public: - std::size_t xyz_index{ 0 }; - float* m_xyz; - GetCoords(float* xyz) - : m_xyz(xyz) - { - } - - void forPoints( - const smtk::mesh::HandleRange& /*pointIds*/, - std::vector& xyz, - bool& /*coordinatesModified*/) override - { - //use local variable instead of member to help locality - std::size_t index = xyz_index; - for (std::vector::const_iterator i = xyz.begin(); i != xyz.end(); ++i) - { - m_xyz[index++] = static_cast(*i); - } - this->xyz_index = index; - } -}; -} // namespace - -bool Interface::getCoordinates(const smtk::mesh::HandleRange& points, float* xyz) const - -{ - if (points.empty()) - { - return false; - } - - //requires that for_each is serial - GetCoords functor(xyz); - this->pointForEach(points, functor); - return true; -} - -bool Interface::setCoordinates(const smtk::mesh::HandleRange& points, const double* const xyz) - -{ - if (points.empty()) - { - return false; - } - - m_iface->set_coords(smtkToMOABRange(points), xyz); - return true; -} - -namespace -{ -class SetCoords : public smtk::mesh::PointForEach -{ -public: - std::size_t xyz_index{ 0 }; - const float* const m_xyz; - SetCoords(const float* const xyz) - : m_xyz(xyz) - { - } - - void forPoints( - const smtk::mesh::HandleRange& /*pointIds*/, - std::vector& xyz, - bool& coordinatesModified) override - { - coordinatesModified = true; - //use local variable instead of member to help locality - std::size_t index = this->xyz_index; - for (std::vector::iterator i = xyz.begin(); i != xyz.end(); ++i) - { - *i = static_cast(m_xyz[index++]); - } - this->xyz_index = index; - } -}; -} // namespace - -bool Interface::setCoordinates(const smtk::mesh::HandleRange& points, const float* const xyz) - -{ - //requires that for_each is serial - SetCoords functor(xyz); - this->pointForEach(points, functor); - return false; -} - -std::string Interface::name(const smtk::mesh::Handle& meshset) const -{ - //construct a name tag query helper class - tag::QueryNameTag query_name(this->moabInterface()); - - if (query_name.fetch_name(meshset)) - { - return std::string(query_name.current_name()); - } - - return std::string(); -} - -bool Interface::setName(const smtk::mesh::Handle& meshset, const std::string& name) -{ - //construct a name tag query helper class - tag::QueryNameTag query_name(this->moabInterface()); - - return query_name.set_name(meshset, name); -} - -std::vector Interface::computeNames(const smtk::mesh::HandleRange& meshsets) const -{ - //construct a name tag query helper class - tag::QueryNameTag query_name(this->moabInterface()); - - std::set unique_names; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - const bool has_name = query_name.fetch_name(*i); - if (has_name) - { - unique_names.insert(std::string(query_name.current_name())); - } - } - //return a vector of the unique names - return std::vector(unique_names.begin(), unique_names.end()); -} - -std::vector Interface::computeDomainValues( - const smtk::mesh::HandleRange& meshsets) const -{ - tag::QueryMaterialTag mtag(0, this->moabInterface()); - return detail::computeDenseIntTagValues( - mtag, smtkToMOABRange(meshsets), this->moabInterface()); -} - -std::vector Interface::computeDirichletValues( - const smtk::mesh::HandleRange& meshsets) const -{ - tag::QueryDirichletTag dtag(0, this->moabInterface()); - return detail::computeDenseIntTagValues( - dtag, smtkToMOABRange(meshsets), this->moabInterface()); -} - -std::vector Interface::computeNeumannValues( - const smtk::mesh::HandleRange& meshsets) const -{ - tag::QueryNeumannTag ntag(0, this->moabInterface()); - return detail::computeDenseIntTagValues( - ntag, smtkToMOABRange(meshsets), this->moabInterface()); -} - -/**\brief Return the set of all UUIDs set on all entities in the meshsets. - * - */ -smtk::common::UUIDArray Interface::computeModelEntities( - const smtk::mesh::HandleRange& meshsets) const -{ - tag::QueryEntRefTag mtag(this->moabInterface()); - return detail::computeDenseOpaqueTagValues( - mtag, smtkToMOABRange(meshsets), this->moabInterface()); -} - -smtk::mesh::TypeSet Interface::computeTypes(const smtk::mesh::HandleRange& range) const -{ - typedef ::moab::Range::const_iterator cit; - typedef ::smtk::mesh::CellType CellEnum; - - ::moab::Range moabRange = smtkToMOABRange(range); - ::moab::Range meshes = moabRange.subset_by_type(::moab::MBENTITYSET); - ::moab::Range cells = ::moab::subtract(moabRange, meshes); - - smtk::mesh::CellTypes ctypes; - - //compute the type of the meshes, I don't want to try and extract the range - //of cells for all the meshes, as that could be large - for (cit m = meshes.begin(); m != meshes.end(); ++m) - { - const ::moab::EntityHandle& currentHandle = *m; - for (std::size_t i = 0; i < ctypes.size(); ++i) - { - const CellEnum ce = static_cast(i); - const ::moab::EntityType moabEType = - static_cast<::moab::EntityType>(smtk::mesh::moab::smtkToMOABCell(ce)); - - //some of the cell types that smtk supports moab doesn't support - //so we can't query on those. - int num = 0; - m_iface->get_number_entities_by_type( - currentHandle, static_cast<::moab::EntityType>(moabEType), num, true); - if (num > 0) - { - ctypes[ce] = true; - } - } - } - - //compute the type of the cells if we have any - if (!cells.empty()) - { - for (std::size_t i = 0; i < ctypes.size(); ++i) - { - //now we need to convert from CellEnum to MoabType - const CellEnum ce = static_cast(i); - const ::moab::EntityType moabEType = - static_cast<::moab::EntityType>(smtk::mesh::moab::smtkToMOABCell(ce)); - - //if num_of_type is greater than zero we have cells of that type - if (cells.num_of_type(moabEType) > 0) - { - ctypes[ce] = true; - } - } - } - - const bool hasM = !(meshes.empty()); - const bool hasC = ctypes.any(); - return smtk::mesh::TypeSet(ctypes, hasM, hasC); -} - -bool Interface::computeShell(const smtk::mesh::HandleRange& meshes, smtk::mesh::HandleRange& shell) - const -{ - //step 1 get all the highest dimension cells for the meshes - ::moab::Range cells; - int dimension = 4; - bool hasCells = false; - while (!hasCells && dimension >= 0) - { - --dimension; - // get all non-meshset entities in meshset of a given cell type - for (auto i = boost::icl::elements_begin(meshes); i != boost::icl::elements_end(meshes); ++i) - { - //get_entities_by_dimension appends to the range given - m_iface->get_entities_by_dimension(*i, dimension, cells, true); - } - hasCells = !cells.empty(); - } - - if (!hasCells) - { - return false; - } - - int skinDim = dimension - 1; - - //We need to first create the adjacencies from the requested dimension to the - //dimension of the skin. The first step is create all the adjacencies from - //the desired dimension to the skin dimension - ::moab::Range allAdj; - this->moabInterface()->get_adjacencies(cells, skinDim, true, allAdj); - - ::moab::Skinner skinner(this->moabInterface()); - ::moab::Range moabShell; - ::moab::ErrorCode rval = skinner.find_skin(this->getRoot(), cells, skinDim, moabShell); - - if (rval != ::moab::MB_SUCCESS) - { - //if the skin extraction failed remove all cells we created - this->moabInterface()->delete_entities(allAdj); - } - else - { - shell = moabToSMTKRange(moabShell); - //remove any cell created by computing the adjacencies that isn't part - //of the skin. This is done to keep the memory utilization low - ::moab::Range unusedCells = ::moab::subtract(allAdj, moabShell); - this->moabInterface()->delete_entities(unusedCells); - } - - return (rval == ::moab::MB_SUCCESS); -} - -bool Interface::computeAdjacenciesOfDimension( - const smtk::mesh::HandleRange& meshes, - int dimension, - smtk::mesh::HandleRange& adj) const -{ - if (dimension < smtk::mesh::Dims0 || dimension >= smtk::mesh::DimensionType_MAX) - { - return false; - } - - ::moab::Range cells; - for (auto i = boost::icl::elements_begin(meshes); i != boost::icl::elements_end(meshes); ++i) - { - //get_entities_by_handle appends to the range given - m_iface->get_entities_by_handle(*i, cells, true); - } - - ::moab::Range moabAdj; - ::moab::ErrorCode rval = this->moabInterface()->get_adjacencies( - cells, dimension, true, moabAdj, ::moab::Interface::UNION); - adj = moabToSMTKRange(moabAdj); - - return (rval == ::moab::MB_SUCCESS); -} - -bool Interface::canonicalIndex( - const smtk::mesh::Handle& cellId, - smtk::mesh::Handle& parent, - int& canonicalIndex) const -{ - // Access the cell's parent cell - std::vector<::moab::EntityHandle> adjacencies; - m_iface->get_adjacencies( - &cellId, 1, m_iface->dimension_from_handle(cellId) + 1, false, adjacencies); - - // Exit early if the cell's parent was not found - if (adjacencies.empty()) - { - return false; - } - - // Assign the parent handle - parent = adjacencies[0]; - - // Access the cell's "side number" (the canonical ordering information side - // number) - int sense, offset; - ::moab::ErrorCode rval = m_iface->side_number(parent, cellId, canonicalIndex, sense, offset); - return (rval == ::moab::MB_SUCCESS); -} - -bool Interface::mergeCoincidentContactPoints( - const smtk::mesh::HandleRange& meshes, - double tolerance) -{ - if (meshes.empty()) - { - //I can't see a reason why we should consider a merge of nothing to be a - //failure. So we return true. - return true; - } - - //we want to merge the contact points for all dimensions - //of the meshes, not just the highest dimension i expect - smtk::mesh::moab::MergeMeshVertices meshmerger(this->moabInterface()); - ::moab::ErrorCode rval = meshmerger.merge_entities(smtkToMOABRange(meshes), tolerance); - if (rval == ::moab::MB_SUCCESS) - { - m_modified = true; - return true; - } - return false; -} - -smtk::mesh::HandleRange Interface::neighbors(const smtk::mesh::Handle& cellId) const -{ - int dimension = m_iface->dimension_from_handle(cellId); - - // Access the cell's boundaries - std::vector<::moab::EntityHandle> adjacencies; - m_iface->get_adjacencies(&cellId, 1, dimension - 1, true, adjacencies); - - // Exit early if the cell's boundaries were not found - if (adjacencies.empty()) - { - return smtk::mesh::HandleRange(); - } - - std::vector<::moab::EntityHandle> neighbors; - m_iface->get_adjacencies( - adjacencies.data(), - static_cast(adjacencies.size()), - dimension, - true, - neighbors, - ::moab::Core::UNION); - - smtk::mesh::HandleRange neighborsRange; - for (auto& neighbor : neighbors) - { - neighborsRange.insert(neighbor); - } - neighborsRange.erase(cellId); - - return neighborsRange; -} - -bool Interface::setDomain(const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Domain& domain) - const -{ - if (meshsets.empty()) - { - return true; - } - - tag::QueryMaterialTag mtag(domain.value(), this->moabInterface()); - bool tagged = detail::setDenseTagValues(mtag, smtkToMOABRange(meshsets), this->moabInterface()); - if (tagged) - { - m_modified = true; - } - return tagged; -} - -bool Interface::setDirichlet( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::Dirichlet& dirichlet) const -{ - if (meshsets.empty()) - { - return true; - } - - tag::QueryDirichletTag dtag(dirichlet.value(), this->moabInterface()); - - //get all non-meshset entities of a given dimension - ::moab::Range cells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_dimension appends to the range given - m_iface->get_entities_by_dimension(*i, static_cast(smtk::mesh::Dims0), cells, true); - } - - bool cellsTagged = detail::setDenseTagValues(dtag, cells, this->moabInterface()); - bool meshesTagged = - detail::setDenseTagValues(dtag, smtkToMOABRange(meshsets), this->moabInterface()); - - const bool tagged = cellsTagged && meshesTagged; - if (tagged) - { - m_modified = true; - } - return tagged; -} - -bool Interface::setNeumann( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::Neumann& neumann) const -{ - if (meshsets.empty()) - { - return true; - } - - tag::QueryNeumannTag ntag(neumann.value(), this->moabInterface()); - - //step 0 tag the meshsets - bool tagged = detail::setDenseTagValues(ntag, smtkToMOABRange(meshsets), this->moabInterface()); - - //step 1 find the highest dimension cells for the meshes. - int dimension = 4; - bool hasCells = false; - while (!hasCells && dimension >= 0) - { - ::moab::Range cells; - --dimension; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); - ++i) - { - m_iface->get_entities_by_dimension(*i, dimension, cells, true); - } - hasCells = !cells.empty(); - } - - //step 2 apply the neumann property to all cells for dimension that is 1 lower - //since that would be the boundary dimension - if (hasCells && dimension > 0) - { - ::moab::Range cells; - --dimension; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); - ++i) - { - m_iface->get_entities_by_dimension(*i, dimension, cells, true); - } - tagged = tagged && detail::setDenseTagValues(ntag, cells, this->moabInterface()); - } - - if (tagged) - { - m_modified = true; - } - return tagged; -} - -/**\brief Set the id for a meshset to \a id. - */ -bool Interface::setId(const smtk::mesh::Handle& meshset, const smtk::common::UUID& id) const -{ - if (!id) - { - return false; - } - - tag::QueryIdTag mtag(id, this->moabInterface()); - - //Tag the meshsets - bool tagged = detail::setDenseOpaqueTagValue(mtag, meshset, this->moabInterface()); - if (tagged) - { - m_modified = true; - } - return tagged; -} - -/**\brief Get the id for a meshset. - */ -smtk::common::UUID Interface::getId(const smtk::mesh::Handle& meshset) const -{ - tag::QueryIdTag mtag(this->moabInterface()); - return detail::computeDenseOpaqueTagValue( - mtag, meshset, this->moabInterface()); -} - -/**\brief Find a mesh entity using its id. - * - */ -bool Interface::findById( - const smtk::mesh::Handle& root, - const smtk::common::UUID& id, - smtk::mesh::Handle& meshset) const -{ - if (!id) - { - return false; - } - - ::moab::Range result; - - tag::QueryIdTag mtag(id, this->moabInterface()); - - ::moab::ErrorCode rval; - - rval = m_iface->get_entities_by_type_and_tag( - root, ::moab::MBENTITYSET, mtag.moabTagPtr(), mtag.moabTagValuePtr(), 1, result); - - if (rval != ::moab::MB_SUCCESS || result.size() != 1) - { - // The above call does not check the root if it has the tag value. Let's do - // that before we give up. - smtk::common::UUID rootId = - detail::computeDenseOpaqueTagValue(mtag, root, this->moabInterface()); - if (rootId != smtk::common::UUID::null()) - { - meshset = root; - return true; - } - - return false; - } - meshset = *result.begin(); - return true; -} - -/**\brief Set the model entity assigned to each meshset member to \a ent. - */ -bool Interface::setAssociation( - const smtk::common::UUID& modelUUID, - const smtk::mesh::HandleRange& range) const -{ - if (range.empty() || !modelUUID) - { //if empty range or invalid uuid - return false; - } - - tag::QueryEntRefTag mtag(modelUUID, this->moabInterface()); - - //Tag the meshsets - bool tagged = - detail::setDenseOpaqueTagValues(mtag, smtkToMOABRange(range), this->moabInterface()); - if (tagged) - { - m_modified = true; - } - return tagged; -} - -/**\brief Find mesh entities associated with the given model entity. - * - */ -smtk::mesh::HandleRange Interface::findAssociations( - const smtk::mesh::Handle& root, - const smtk::common::UUID& modelUUID) const -{ - ::moab::Range result; - if (!modelUUID) - { - return smtk::mesh::HandleRange(); - } - - tag::QueryEntRefTag mtag(modelUUID, this->moabInterface()); - - ::moab::ErrorCode rval; - rval = m_iface->get_entities_by_type_and_tag( - root, ::moab::MBENTITYSET, mtag.moabTagPtr(), mtag.moabTagValuePtr(), 1, result); - if (rval != ::moab::MB_SUCCESS) - { - result.clear(); - } - return moabToSMTKRange(result); -} - -// brief Set the model entity assigned to the root of this interface. -// -bool Interface::setRootAssociation(const smtk::common::UUID& modelUUID) const -{ - if (!modelUUID) - { - return false; - } - - smtk::mesh::Handle root = m_iface->get_root_set(); - tag::QueryRootModelEntTag mtag(modelUUID, this->moabInterface()); - - //Tag the root - bool tagged = detail::setDenseOpaqueTagValue(mtag, root, this->moabInterface()); - if (tagged) - { - m_modified = true; - } - return tagged; -} - -/// brief Get the model entity assigned to the root of this interface. -// -smtk::common::UUID Interface::rootAssociation() const -{ - //first we need to verify that we have a ROOT_MODEL tag first - std::vector<::moab::Tag> tag_handles; - smtk::mesh::Handle root = m_iface->get_root_set(); - m_iface->tag_get_tags_on_entity(root, tag_handles); - - if (!tag_handles.empty()) - { - tag::QueryRootModelEntTag mtag(this->moabInterface()); - return detail::computeDenseOpaqueTagValue( - mtag, root, this->moabInterface()); - } - return smtk::common::UUID::null(); -} - -//create a data set named with doubles for each cell in -//, and populate it with -bool Interface::createCellField( - const smtk::mesh::HandleRange& meshsets, - const std::string& name, - std::size_t dimension, - const smtk::mesh::FieldType& type, - const void* data) -{ - if (meshsets.empty()) - { - // If there are no meshsets, then we return with failure - return false; - } - - // We first construct the data set for the cells associated with the meshsets. - ::moab::Range cells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_handle appends to the range given - m_iface->get_entities_by_handle(*i, cells, true); - } - - if (cells.empty()) - { - // If there are no cells, then there we return with failure. - return false; - } - // The double tag is used to associate double-valued data with the cells - tag::QueryFieldTag dtag( - name.c_str(), - static_cast(dimension), - (type == smtk::mesh::FieldType::Integer ? ::moab::MB_TYPE_INTEGER : ::moab::MB_TYPE_DOUBLE), - this->moabInterface()); - if (dtag.state() != ::moab::MB_SUCCESS && dtag.state() != ::moab::MB_ALREADY_ALLOCATED) - { - return false; - } - - ::moab::ErrorCode rval = m_iface->tag_set_data(dtag.moabTag(), cells, data); - bool tagged = (rval == ::moab::MB_SUCCESS); - - if (tagged) - { - // We successfully constructed the data set associated with the cells. Now we mark the meshset - // as having the associated dataset. For this, we use a bit tag to simply denote the dataset's - // existence. - ::moab::Range moabMeshsets = smtkToMOABRange(meshsets); - tag::QueryCellFieldTag btag(name.c_str(), this->moabInterface()); - bool* boolean_tag_values = new bool[moabMeshsets.size()]; - memset(boolean_tag_values, true, moabMeshsets.size()); - rval = m_iface->tag_set_data(btag.moabTag(), moabMeshsets, boolean_tag_values); - assert(rval == ::moab::MB_SUCCESS); - - auto tags = this->computeCellFieldTags(*moabMeshsets.begin()); - - delete[] boolean_tag_values; - - m_modified = true; - } - return tagged; -} - -//get the dimension of a dataset. -int Interface::getCellFieldDimension(const smtk::mesh::CellFieldTag& cfTag) const -{ - ::moab::Tag tag; - std::string dTagName = cfTag.name() + std::string("_"); - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), tag); - if (rval != ::moab::MB_SUCCESS) - { - return 0; - } - int dimension = 0; - m_iface->tag_get_length(tag, dimension); - - return dimension; -} - -//get the type of a dataset. -smtk::mesh::FieldType Interface::getCellFieldType(const smtk::mesh::CellFieldTag& cfTag) const -{ - ::moab::Tag tag; - std::string dTagName = cfTag.name() + std::string("_"); - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), tag); - if (rval != ::moab::MB_SUCCESS) - { - return smtk::mesh::FieldType::MaxFieldType; - } - ::moab::DataType type; - m_iface->tag_get_data_type(tag, type); - - if (type == ::moab::MB_TYPE_DOUBLE) - { - return smtk::mesh::FieldType::Double; - } - else if (type == ::moab::MB_TYPE_INTEGER) - { - return smtk::mesh::FieldType::Integer; - } - else - { - return smtk::mesh::FieldType::MaxFieldType; - } -} - -//find all mesh sets that have this data set -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::CellFieldTag& cfTag) const -{ - // First access the tag associated with - ::moab::Tag tag; - std::string name = std::string("c_") + cfTag.name(); - ::moab::ErrorCode rval = m_iface->tag_get_handle(name.c_str(), tag); - if (rval != ::moab::MB_SUCCESS) - { - return smtk::mesh::HandleRange(); - } - - ::moab::Range result; - - rval = - m_iface->get_entities_by_type_and_tag(handle, ::moab::MBENTITYSET, &tag, nullptr, 1, result); - if (rval != ::moab::MB_SUCCESS) - { - result.clear(); - } - return moabToSMTKRange(result); -} - -bool Interface::hasCellField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellFieldTag& cfTag) const -{ - if (meshsets.empty()) - { - // If there are no meshsets, then we return with failure - return false; - } - - ::moab::Range moabMeshsets = smtkToMOABRange(meshsets); - - ::moab::Tag moab_tag; - std::string name = std::string("c_") + cfTag.name(); - ::moab::ErrorCode rval = m_iface->tag_get_handle(name.c_str(), moab_tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - //fetch all entities with the given tag - ::moab::Range entitiesWithTag; - bool flagValue = true; - void* flagPtr = &flagValue; - m_iface->get_entities_by_type_and_tag( - m_iface->get_root_set(), ::moab::MBENTITYSET, &moab_tag, &flagPtr, 1, entitiesWithTag); - - return ::moab::intersect(entitiesWithTag, moabMeshsets) == moabMeshsets; -} - -bool Interface::getCellField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellFieldTag& cfTag, - void* field) const -{ - if (meshsets.empty()) - { - // If there are no meshsets, then we return with failure - return false; - } - - ::moab::Range cells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_handle appends to the range given - m_iface->get_entities_by_handle(*i, cells, true); - } - - std::string dTagName = cfTag.name() + std::string("_"); - - ::moab::Tag moab_tag; - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), moab_tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - rval = m_iface->tag_get_data(moab_tag, cells, field); - return (rval == ::moab::MB_SUCCESS); -} - -bool Interface::setCellField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellFieldTag& cfTag, - const void* const field) -{ - if (meshsets.empty()) - { - // If there are no meshsets, then we return with failure - return false; - } - - ::moab::Range cells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_handle appends to the range given - m_iface->get_entities_by_handle(*i, cells, true); - } - - std::string dTagName = cfTag.name() + std::string("_"); - - ::moab::Tag moab_tag; - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), moab_tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - rval = m_iface->tag_set_data(moab_tag, cells, field); - - m_modified = (rval == ::moab::MB_SUCCESS); - return m_modified; -} - -bool Interface::getField( - const smtk::mesh::HandleRange& cells, - const smtk::mesh::CellFieldTag& cfTag, - void* field) const -{ - if (cells.empty()) - { - // If there are no cells, then there we return with failure. - return false; - } - - std::string dTagName = cfTag.name() + std::string("_"); - - ::moab::Tag moab_tag; - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), moab_tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - rval = m_iface->tag_get_data(moab_tag, smtkToMOABRange(cells), field); - return (rval == ::moab::MB_SUCCESS); -} - -bool Interface::setField( - const smtk::mesh::HandleRange& cells, - const smtk::mesh::CellFieldTag& cfTag, - const void* const field) -{ - if (cells.empty()) - { - // If there are no cells, then there we return with failure. - return false; - } - - std::string dTagName = cfTag.name() + std::string("_"); - - ::moab::Tag moab_tag; - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), moab_tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - rval = m_iface->tag_set_data(moab_tag, smtkToMOABRange(cells), field); - - m_modified = (rval == ::moab::MB_SUCCESS); - return m_modified; -} - -std::set Interface::computeCellFieldTags( - const smtk::mesh::Handle& handle) const -{ - std::set cellFieldTags; - - // first collect all tag handles - std::vector<::moab::Tag> moab_tag_handles; - m_iface->tag_get_tags(moab_tag_handles); - - for (auto& tag : moab_tag_handles) - { - // then filter them by type - ::moab::DataType data_type; - m_iface->tag_get_data_type(tag, data_type); - if (data_type == ::moab::MB_TYPE_BIT) - { - // then check if there are tagged instances under our handle - ::moab::Range range; - ::moab::ErrorCode rval = - m_iface->get_entities_by_type_and_tag(handle, ::moab::MBENTITYSET, &tag, nullptr, 1, range); - if (rval == ::moab::MB_SUCCESS && !range.empty()) - { - std::string name; - m_iface->tag_get_name(tag, name); - cellFieldTags.insert(smtk::mesh::CellFieldTag(name.substr(2))); - } - } - } - - return cellFieldTags; -} - -bool Interface::deleteCellField( - const smtk::mesh::CellFieldTag& cfTag, - const smtk::mesh::HandleRange& meshsets) -{ - if (meshsets.empty()) - { - return true; - } - - ::moab::Range cells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - m_iface->get_entities_by_handle(*i, cells, true); - } - - if (cells.empty()) - { - // If there are no cells, then there we return with failure. - return true; - } - - // Access the tag associated with the cellsets - std::string dTagName = cfTag.name() + std::string("_"); - ::moab::Tag dTag; - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), dTag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - // Delete the data from the cellsets - rval = m_iface->tag_delete_data(dTag, cells); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - // Access the tag associated with the meshsets - ::moab::Tag tag; - std::string name = std::string("c_") + cfTag.name(); - rval = m_iface->tag_get_handle(name.c_str(), tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - // Delete the data flag from the meshsets - rval = m_iface->tag_delete_data(tag, smtkToMOABRange(meshsets)); - return rval == ::moab::MB_SUCCESS; -} - -//create a data set named with doubles for each point in -//, and populate it with -bool Interface::createPointField( - const smtk::mesh::HandleRange& meshsets, - const std::string& name, - std::size_t dimension, - const smtk::mesh::FieldType& type, - const void* data) -{ - if (meshsets.empty()) - { - // If there are no meshsets, then we return with failure - return false; - } - - // We first construct the data set for the points associated with the meshsets. - ::moab::Range cells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_handle appends to the range given - m_iface->get_entities_by_handle(*i, cells, true); - } - - ::moab::Range points; - m_iface->get_connectivity(cells, points, false); - - if (points.empty()) - { - // If there are no points, then there we return with failure. - return false; - } - // The double tag is used to associate double-valued data with the points - tag::QueryFieldTag dtag( - name.c_str(), - static_cast(dimension), - (type == smtk::mesh::FieldType::Integer ? ::moab::MB_TYPE_INTEGER : ::moab::MB_TYPE_DOUBLE), - this->moabInterface()); - if (dtag.state() != ::moab::MB_SUCCESS && dtag.state() != ::moab::MB_ALREADY_ALLOCATED) - { - return false; - } - - ::moab::ErrorCode rval = m_iface->tag_set_data(dtag.moabTag(), points, data); - bool tagged = (rval == ::moab::MB_SUCCESS); - - if (tagged) - { - // We successfully constructed the data set associated with the points. Now we mark the meshset - // as having the associated dataset. For this, we use a bit tag to simply denote the dataset's - // existence. - tag::QueryPointFieldTag btag(name.c_str(), this->moabInterface()); - ::moab::Range moabMeshsets = smtkToMOABRange(meshsets); - bool* boolean_tag_values = new bool[moabMeshsets.size()]; - memset(boolean_tag_values, true, moabMeshsets.size()); - rval = m_iface->tag_set_data(btag.moabTag(), moabMeshsets, boolean_tag_values); - assert(rval == ::moab::MB_SUCCESS); - - auto tags = this->computePointFieldTags(*moabMeshsets.begin()); - - delete[] boolean_tag_values; - - m_modified = true; - } - return tagged; -} - -//get the dimension of a dataset. -int Interface::getPointFieldDimension(const smtk::mesh::PointFieldTag& pfTag) const -{ - ::moab::Tag tag; - std::string dTagName = pfTag.name() + std::string("_"); - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), tag); - if (rval != ::moab::MB_SUCCESS) - { - return 0; - } - int dimension = 0; - m_iface->tag_get_length(tag, dimension); - - return dimension; -} - -//get the type of a dataset. -smtk::mesh::FieldType Interface::getPointFieldType(const smtk::mesh::PointFieldTag& pfTag) const -{ - ::moab::Tag tag; - std::string dTagName = pfTag.name() + std::string("_"); - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), tag); - if (rval != ::moab::MB_SUCCESS) - { - return smtk::mesh::FieldType::MaxFieldType; - } - ::moab::DataType type; - m_iface->tag_get_data_type(tag, type); - - if (type == ::moab::MB_TYPE_DOUBLE) - { - return smtk::mesh::FieldType::Double; - } - else if (type == ::moab::MB_TYPE_INTEGER) - { - return smtk::mesh::FieldType::Integer; - } - else - { - return smtk::mesh::FieldType::MaxFieldType; - } -} - -//find all mesh sets that have this data set -smtk::mesh::HandleRange Interface::getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::PointFieldTag& pfTag) const -{ - // First access the tag associated with - ::moab::Tag tag; - std::string name = std::string("p_") + pfTag.name(); - ::moab::ErrorCode rval = m_iface->tag_get_handle(name.c_str(), tag); - if (rval != ::moab::MB_SUCCESS) - { - return smtk::mesh::HandleRange(); - } - - ::moab::Range result; - - rval = - m_iface->get_entities_by_type_and_tag(handle, ::moab::MBENTITYSET, &tag, nullptr, 1, result); - if (rval != ::moab::MB_SUCCESS) - { - result.clear(); - } - return moabToSMTKRange(result); -} - -bool Interface::hasPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag) const -{ - if (meshsets.empty()) - { - // If there are no meshsets, then we return with failure - return false; - } - - ::moab::Tag moab_tag; - std::string name = std::string("p_") + pfTag.name(); - ::moab::ErrorCode rval = m_iface->tag_get_handle(name.c_str(), moab_tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - //fetch all entities with the given tag - ::moab::Range entitiesWithTag; - bool flagValue = true; - void* flagPtr = &flagValue; - m_iface->get_entities_by_type_and_tag( - m_iface->get_root_set(), ::moab::MBENTITYSET, &moab_tag, &flagPtr, 1, entitiesWithTag); - - ::moab::Range moabMeshsets = smtkToMOABRange(meshsets); - return ::moab::intersect(entitiesWithTag, moabMeshsets) == moabMeshsets; -} - -bool Interface::getPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag, - void* field) const -{ - if (meshsets.empty()) - { - // If there are no meshsets, then we return with failure - return false; - } - - ::moab::Range cells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_handle appends to the range given - m_iface->get_entities_by_handle(*i, cells, true); - } - - ::moab::Range points; - m_iface->get_connectivity(cells, points, false); - - std::string dTagName = pfTag.name() + std::string("_"); - - ::moab::Tag moab_tag; - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), moab_tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - rval = m_iface->tag_get_data(moab_tag, points, field); - return (rval == ::moab::MB_SUCCESS); -} - -bool Interface::setPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag, - const void* const field) -{ - if (meshsets.empty()) - { - // If there are no meshsets, then we return with failure - return false; - } - - ::moab::Range cells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_handle appends to the range given - m_iface->get_entities_by_handle(*i, cells, true); - } - - ::moab::Range points; - m_iface->get_connectivity(cells, points, false); - - std::string dTagName = pfTag.name() + std::string("_"); - - ::moab::Tag moab_tag; - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), moab_tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - rval = m_iface->tag_set_data(moab_tag, points, field); - - m_modified = (rval == ::moab::MB_SUCCESS); - return m_modified; -} - -bool Interface::getField( - const smtk::mesh::HandleRange& points, - const smtk::mesh::PointFieldTag& pfTag, - void* field) const -{ - if (points.empty()) - { - // If there are no points, then there we return with failure. - return false; - } - - std::string dTagName = pfTag.name() + std::string("_"); - - ::moab::Tag moab_tag; - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), moab_tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - rval = m_iface->tag_get_data(moab_tag, smtkToMOABRange(points), field); - return (rval == ::moab::MB_SUCCESS); -} - -bool Interface::setField( - const smtk::mesh::HandleRange& points, - const smtk::mesh::PointFieldTag& pfTag, - const void* const field) -{ - if (points.empty()) - { - // If there are no points, then there we return with failure. - return false; - } - - std::string dTagName = pfTag.name() + std::string("_"); - - ::moab::Tag moab_tag; - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), moab_tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - rval = m_iface->tag_set_data(moab_tag, smtkToMOABRange(points), field); - - m_modified = (rval == ::moab::MB_SUCCESS); - return m_modified; -} - -std::set Interface::computePointFieldTags( - const smtk::mesh::Handle& handle) const -{ - std::set pointFieldTags; - - // first collect all tag handles - std::vector<::moab::Tag> moab_tag_handles; - m_iface->tag_get_tags(moab_tag_handles); - - for (auto& tag : moab_tag_handles) - { - // then filter them by type - ::moab::DataType data_type; - m_iface->tag_get_data_type(tag, data_type); - if (data_type == ::moab::MB_TYPE_BIT) - { - // then check if there are tagged instances under our handle - ::moab::Range range; - ::moab::ErrorCode rval = - m_iface->get_entities_by_type_and_tag(handle, ::moab::MBENTITYSET, &tag, nullptr, 1, range); - if (rval == ::moab::MB_SUCCESS && !range.empty()) - { - std::string name; - m_iface->tag_get_name(tag, name); - pointFieldTags.insert(smtk::mesh::PointFieldTag(name.substr(2))); - } - } - } - - return pointFieldTags; -} - -bool Interface::deletePointField( - const smtk::mesh::PointFieldTag& pfTag, - const smtk::mesh::HandleRange& meshsets) -{ - if (meshsets.empty()) - { - return true; - } - - ::moab::Range cells; - for (auto i = boost::icl::elements_begin(meshsets); i != boost::icl::elements_end(meshsets); ++i) - { - //get_entities_by_handle appends to the range given - m_iface->get_entities_by_handle(*i, cells, true); - } - - ::moab::Range points; - m_iface->get_connectivity(cells, points, false); - - if (points.empty()) - { - // If there are no points, then there we return with failure. - return true; - } - - // Access the tag associated with the pointsets - std::string dTagName = pfTag.name() + std::string("_"); - ::moab::Tag dTag; - ::moab::ErrorCode rval = m_iface->tag_get_handle(dTagName.c_str(), dTag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - // Delete the data from the pointsets - rval = m_iface->tag_delete_data(dTag, points); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - // Access the tag associated with the meshsets - ::moab::Tag tag; - std::string name = std::string("p_") + pfTag.name(); - rval = m_iface->tag_get_handle(name.c_str(), tag); - if (rval != ::moab::MB_SUCCESS) - { - return false; - } - - // Delete the data flag from the meshsets - rval = m_iface->tag_delete_data(tag, smtkToMOABRange(meshsets)); - return rval == ::moab::MB_SUCCESS; -} - -smtk::mesh::HandleRange Interface::pointIntersect( - const smtk::mesh::HandleRange& a_, - const smtk::mesh::HandleRange& b, - smtk::mesh::PointConnectivity& bpc, - smtk::mesh::ContainmentType containmentType) const -{ - if (a_.empty() || b.empty()) - { //the intersection with nothing is nothing - return smtk::mesh::HandleRange(); - } - - ::moab::Range a = smtkToMOABRange(a_); - - //first get all the points of a - ::moab::Range a_points = a.subset_by_type(::moab::MBVERTEX); - m_iface->get_connectivity(a, a_points); - - if (a_points.empty()) - { - return smtk::mesh::HandleRange(); - } - - std::vector<::moab::EntityHandle> vresult; - if (!bpc.is_empty()) - { - int size = 0; - const smtk::mesh::Handle* connectivity; - bpc.initCellTraversal(); - for (auto i = boost::icl::elements_begin(b); i != boost::icl::elements_end(b); ++i) - { - const bool validCell = bpc.fetchNextCell(size, connectivity); - if (validCell) - { - bool exitCondition = (containmentType == smtk::mesh::PartiallyContained); - bool contains = !exitCondition; - for (int j = 0; j < size && contains != exitCondition; ++j) - { - contains = (a_points.find(connectivity[j]) != a_points.end()); - } - - if (contains) - { - vresult.push_back(*i); - } - } - } - } - return detail::vectorToHandleRange(vresult); -} - -smtk::mesh::HandleRange Interface::pointDifference( - const smtk::mesh::HandleRange& a_, - const smtk::mesh::HandleRange& b, - smtk::mesh::PointConnectivity& bpc, - smtk::mesh::ContainmentType containmentType) const -{ - if (a_.empty() || b.empty()) - { //the intersection with nothing is nothing - return smtk::mesh::HandleRange(); - } - - ::moab::Range a = smtkToMOABRange(a_); - - //first get all the points of a - ::moab::Range a_points = a.subset_by_type(::moab::MBVERTEX); - m_iface->get_connectivity(a, a_points); - - if (a_points.empty()) - { - return smtk::mesh::HandleRange(); - } - - std::vector<::moab::EntityHandle> vresult; - if (!bpc.is_empty()) - { - int size = 0; - const smtk::mesh::Handle* connectivity; - bpc.initCellTraversal(); - for (auto i = boost::icl::elements_begin(b); i != boost::icl::elements_end(b); ++i) - { - const bool validCell = bpc.fetchNextCell(size, connectivity); - if (validCell) - { - bool exitCondition = (containmentType == smtk::mesh::PartiallyContained); - bool contains = !exitCondition; - for (int j = 0; j < size && contains != exitCondition; ++j) - { - contains = (a_points.find(connectivity[j]) != a_points.end()); - } - - if (!contains) - { - vresult.push_back(*i); - } - } - } - } - return detail::vectorToHandleRange(vresult); -} - -void Interface::callPointForEach( - const HandleRange& points, - std::vector& coords, - smtk::mesh::PointForEach& filter) const -{ - ::moab::Range moabPoints = smtkToMOABRange(points); - - //fetch all the coordinates - m_iface->get_coords(moabPoints, coords.data()); - - //call the filter for the rest of the points - bool shouldBeSaved = false; - filter.forPoints(points, coords, shouldBeSaved); - if (shouldBeSaved) - { - m_iface->set_coords(moabPoints, coords.data()); - } - return; -} - -namespace -{ -const std::size_t numPointsPerCall = 65536; //selected so that buffer is ~1MB -} - -void Interface::pointForEach(const HandleRange& points, smtk::mesh::PointForEach& filter) const -{ - HandleRange pts = points; - std::vector coords; - pointForEachRecursive(pts, coords, filter); -} - -void Interface::pointForEachRecursive( - HandleRange& points, - std::vector& coords, - smtk::mesh::PointForEach& filter) const -{ - // If there are no points to call, return early - if (points.empty()) - { - return; - } - - HandleRange::const_iterator it = points.begin(); - - Handle begin = it->lower(); - std::size_t size = 0; - - Handle lastLower; - HandleRange pts; - - // Iterate the intervals in the range to find the interval that contains the - // -th point. - do - { - lastLower = it->lower(); - Handle end = it->upper(); - size += (end - lastLower + 1); - if (size < numPointsPerCall) - { - pts.insert(pts.end(), HandleInterval(lastLower, end)); - } - else - { - break; - } - } while (++it != points.end()); - - // If the number of points is fewer than , then we operate - // on the entire points array. We do not perform this check earlier as it is - // an O[n] operation where n = number of intervals. We absorb that cost into - // the loop this algorithm uses to find the partitioning point. - if (it == points.end()) - { - if (coords.empty()) - { - coords.resize(3 * size); - } - callPointForEach(points, coords, filter); - return; - } - - if (coords.empty()) - { - coords.resize(3 * numPointsPerCall); - } - - Handle partition = lastLower + numPointsPerCall - 1; - - pts.insert(pts.end(), HandleInterval(lastLower, partition)); - callPointForEach(pts, coords, filter); - - // Construct a range containing a single interval from the first Handle to - // the partitioning Handle. The proceeding set operations are O[m log(n)] - // where m is the number of intervals in this range, so it is more efficient - // to be less accurate here. - HandleRange toSubtract; - toSubtract.insert(HandleInterval(begin, partition)); - - points -= toSubtract; - - pointForEachRecursive(points, coords, filter); -} - -void Interface::cellForEach( - const HandleRange& cells, - smtk::mesh::PointConnectivity& pc, - smtk::mesh::CellForEach& filter) const -{ - if (!pc.is_empty()) - { - smtk::mesh::CellType cellType; - int size = 0; - const smtk::mesh::Handle* points; - - auto currentCell = boost::icl::elements_begin(cells); - if (filter.wantsCoordinates()) - { - std::vector coords; - for (pc.initCellTraversal(); pc.fetchNextCell(cellType, size, points); ++currentCell) - { - coords.resize(size * 3); - - //query to grab the coordinates for these points - m_iface->get_coords(points, size, coords.data()); - //call the custom filter - filter.pointIds(points); - filter.coordinates(&coords); - filter.forCell(*currentCell, cellType, size); - } - } - else - { //don't extract the coords - for (pc.initCellTraversal(); pc.fetchNextCell(cellType, size, points); ++currentCell) - { - filter.pointIds(points); - //call the custom filter - filter.forCell(*currentCell, cellType, size); - } - } - } - return; -} - -void Interface::meshForEach(const smtk::mesh::HandleRange& meshes, smtk::mesh::MeshForEach& filter) - const -{ - if (!meshes.empty()) - { - for (auto i = boost::icl::elements_begin(meshes); i != boost::icl::elements_end(meshes); ++i) - { - - smtk::mesh::HandleRange singleHandle; - singleHandle += *i; - smtk::mesh::MeshSet singleMesh(filter.m_resource, *i, singleHandle); - - //call the custom filter - filter.forMesh(singleMesh); - } - } - return; -} - -bool Interface::deleteHandles(const smtk::mesh::HandleRange& toDel) -{ - //step 1. verify HandleRange isnt empty - if (toDel.empty()) - { - return true; - } - - ::moab::Range moabToDel = smtkToMOABRange(toDel); - - //step 2. verify HandleRange doesn't contain root Handle - if (moabToDel.front() == this->getRoot()) - { - //Ranges are always sorted, and the root is always id 0 - return false; - } - - //step 3. verify HandleRange is either all entity sets or cells/verts - //this could be a performance bottleneck since we are using size - bool isDeleted = false; - if (moabToDel.all_of_type(::moab::MBENTITYSET)) - { - //first remove any model entity relation-ship these meshes have - tag::QueryEntRefTag mtag(this->moabInterface()); - m_iface->tag_delete_data(mtag.moabTag(), moabToDel); - - //we are all moab entity sets, fine to delete - const ::moab::ErrorCode rval = m_iface->delete_entities(moabToDel); - isDeleted = (rval == ::moab::MB_SUCCESS); - } - else if (moabToDel.num_of_type(::moab::MBENTITYSET) == 0) - { - //first remove any model entity relation-ship these cells have - tag::QueryEntRefTag mtag(this->moabInterface()); - m_iface->tag_delete_data(mtag.moabTag(), moabToDel); - - //for now we are going to avoid deleting any vertex - ::moab::Range vertCells = moabToDel.subset_by_dimension(0); - ::moab::Range otherCells = ::moab::subtract(moabToDel, vertCells); - - //we have zero entity sets so we must be all cells/coords - const ::moab::ErrorCode rval = m_iface->delete_entities(otherCells); - - //we don't delete the vertices, as those can't be explicitly deleted - //instead they are deleted when the mesh goes away - return (rval == ::moab::MB_SUCCESS); - } - if (isDeleted) - { - m_modified = true; - } - return isDeleted; -} - -::moab::Interface* Interface::moabInterface() const -{ - return m_iface.get(); -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/Interface.h b/smtk/mesh/moab/Interface.h deleted file mode 100644 index 0bbd375825288f2387dab5e6ef3290b8c48a909f..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/Interface.h +++ /dev/null @@ -1,406 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#ifndef smtk_mesh_moab_Interface_h -#define smtk_mesh_moab_Interface_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/DimensionTypes.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/Interface.h" -#include "smtk/mesh/core/TypeSet.h" - -#include - -namespace moab -{ -class Interface; -} - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ -//construct an empty interface instance, this is properly connected -//to a moab database -SMTKCORE_EXPORT -smtk::mesh::moab::InterfacePtr make_interface(); - -//Given a smtk::mesh Resource extract the underlying smtk::mesh::moab interface -//from it. This requires that the resource was created with the proper interface -//to begin with. -smtk::mesh::moab::InterfacePtr extract_interface(const smtk::mesh::ResourcePtr& c); - -//Given a smtk::mesh Interface convert it to a smtk::mesh::moab interface, and than -//extract the raw moab interface pointer from that -SMTKCORE_EXPORT -::moab::Interface* extract_moab_interface(const smtk::mesh::InterfacePtr& iface); - -class SMTKCORE_EXPORT Interface : public smtk::mesh::Interface -{ -public: - Interface(); - - ~Interface() override; - - //get back a string that contains the pretty name for the interface class. - //Requirements: The string must be all lower-case. - std::string name() const override { return std::string("moab"); } - - //returns if the underlying data has been modified since the mesh was loaded - //from disk. If the mesh has no underlying file, it will always be considered - //modified. Once the mesh is written to disk, we will reset the modified - //flag. - bool isModified() const override; - - //get back a lightweight interface around allocating memory into the given - //interface. This is generally used to create new coordinates or cells that - //are than assigned to an existing mesh or new mesh - // - //If the current interface is read-only, the AllocatorPtr that is returned - //will be nullptr. - // - //Note: Merely fetching a valid allocator will mark the resource as - //modified. This is done instead of on a per-allocation basis so that - //modification state changes don't impact performance. - smtk::mesh::AllocatorPtr allocator() override; - - //get back a lightweight interface around incrementally allocating memory into - //the given interface. This is generally used to create new coordinates or - //cells that are than assigned to an existing mesh or new mesh. - // - //If the current interface is read-only, the BufferedCellAllocatorPtr that is - //returned will be nullptr. - // - //Note: Merely fetching a valid allocator will mark the resource as - //modified. This is done instead of on a per-allocation basis so that - //modification state changes don't impact performance. - smtk::mesh::BufferedCellAllocatorPtr bufferedCellAllocator() override; - - //get back a lightweight interface around incrementally allocating memory into - //the given interface. This is generally used to create new coordinates or - //cells that are than assigned to an existing mesh or new mesh. - // - //If the current interface is read-only, the IncrementalAllocatorPtr that is - //returned will be nullptr. - // - //Note: Merely fetching a valid allocator will mark the resource as - //modified. This is done instead of on a per-allocation basis so that - //modification state changes don't impact performance. - smtk::mesh::IncrementalAllocatorPtr incrementalAllocator() override; - - //get back an efficient storage mechanism for a range of cells point - //connectivity. This allows for efficient iteration of cell connectivity, and - //conversion to other formats - smtk::mesh::ConnectivityStoragePtr connectivityStorage( - const smtk::mesh::HandleRange& cells) override; - - //get back an efficient point locator for a range of points - //This allows for efficient point locator on a per interface basis. - smtk::mesh::PointLocatorImplPtr pointLocator(const smtk::mesh::HandleRange& points) override; - smtk::mesh::PointLocatorImplPtr pointLocator( - std::size_t numPoints, - const std::function(std::size_t)>& coordinates) override; - - smtk::mesh::Handle getRoot() const override; - - void registerQueries(smtk::mesh::Resource&) const override; - - //creates a mesh with that contains the input cells. - //the mesh will have the root as its parent. - //The mesh will be tagged with the GEOM_DIMENSION tag with a value that is - //equal to highest dimension of cell inside - //Will fail if the HandleRange is empty or doesn't contain valid - //cell handles. - //Note: Will mark the interface as modified when successful - bool createMesh(const smtk::mesh::HandleRange& cells, smtk::mesh::Handle& meshHandle) override; - - std::size_t numMeshes(smtk::mesh::Handle handle) const override; - - smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle) const override; - - smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle, int dimension) const override; - - //find all entity sets that have this exact name tag - smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle, const std::string& name) - const override; - - //find all entity sets that have this exact domain tag - smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle, const smtk::mesh::Domain& domain) - const override; - - //find all entity sets that have this exact dirichlet tag - smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::Dirichlet& dirichlet) const override; - - //find all entity sets that have this exact neumann tag - smtk::mesh::HandleRange getMeshsets(smtk::mesh::Handle handle, const smtk::mesh::Neumann& neumann) - const override; - - //get all cells held by this range - smtk::mesh::HandleRange getCells(const smtk::mesh::HandleRange& meshsets) const override; - - //get all cells held by this range handle of a given cell type - smtk::mesh::HandleRange getCells( - const smtk::mesh::HandleRange& meshsets, - smtk::mesh::CellType cellType) const override; - - //get all cells held by this range handle of a given cell type(s) - smtk::mesh::HandleRange getCells( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellTypes& cellTypes) const override; - - //get all cells held by this range handle of a given dimension - smtk::mesh::HandleRange getCells( - const smtk::mesh::HandleRange& meshsets, - smtk::mesh::DimensionType dim) const override; - - //get all points held by this range of handle of a given dimension. If - //boundary_only is set to true, ignore the higher order points of the - //cells - smtk::mesh::HandleRange getPoints( - const smtk::mesh::HandleRange& cells, - bool boundary_only = false) const override; - - //get all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - //Floats are not how we store the coordinates internally, so asking for - //the coordinates in such a manner could cause data inaccuracies to appear - //so generally this is only used if you fully understand the input domain - bool getCoordinates(const smtk::mesh::HandleRange& points, double* xyz) const override; - - //get all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - bool getCoordinates(const smtk::mesh::HandleRange& points, float* xyz) const override; - - //set all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - bool setCoordinates(const smtk::mesh::HandleRange& points, const double* xyz) override; - - //set all the coordinates for the points in this range - //xyz needs to be allocated to 3*points.size() - bool setCoordinates(const smtk::mesh::HandleRange& points, const float* xyz) override; - - std::string name(const smtk::mesh::Handle& meshset) const override; - bool setName(const smtk::mesh::Handle& meshset, const std::string& name) override; - - std::vector computeNames(const smtk::mesh::HandleRange& meshsets) const override; - - std::vector computeDomainValues( - const smtk::mesh::HandleRange& meshsets) const override; - - std::vector computeDirichletValues( - const smtk::mesh::HandleRange& meshsets) const override; - - std::vector computeNeumannValues( - const smtk::mesh::HandleRange& meshsets) const override; - - smtk::common::UUIDArray computeModelEntities( - const smtk::mesh::HandleRange& meshsets) const override; - - smtk::mesh::TypeSet computeTypes(const smtk::mesh::HandleRange& range) const override; - - //compute the cells that make the shell/skin of the set of meshes - bool computeShell(const smtk::mesh::HandleRange& meshes, smtk::mesh::HandleRange& shell) - const override; - - //compute adjacencies of a given dimension, creating them if necessary - bool computeAdjacenciesOfDimension( - const smtk::mesh::HandleRange& meshes, - int dimension, - smtk::mesh::HandleRange& adj) const override; - - //given a handle to a cell, return its parent handle and canonical index. - bool canonicalIndex(const smtk::mesh::Handle& cell, smtk::mesh::Handle& parent, int& index) - const override; - - //merge any duplicate points used by the cells that have been passed - //Note: Will mark the interface as modified when successful - bool mergeCoincidentContactPoints(const smtk::mesh::HandleRange& meshes, double tolerance) - override; - - //given a handle to a cell, return its dimension-equivalent neighbors. - smtk::mesh::HandleRange neighbors(const smtk::mesh::Handle& cell) const override; - - bool setDomain(const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Domain& domain) - const override; - - bool setDirichlet(const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Dirichlet& dirichlet) - const override; - - bool setNeumann(const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Neumann& neumann) - const override; - - bool setId(const smtk::mesh::Handle& meshset, const smtk::common::UUID& id) const override; - - smtk::common::UUID getId(const smtk::mesh::Handle& meshset) const override; - - bool findById( - const smtk::mesh::Handle& root, - const smtk::common::UUID& id, - smtk::mesh::Handle& meshset) const override; - - bool setAssociation(const smtk::common::UUID& modelUUID, const smtk::mesh::HandleRange& range) - const override; - - smtk::mesh::HandleRange findAssociations( - const smtk::mesh::Handle& root, - const smtk::common::UUID& modelUUID) const override; - - bool setRootAssociation(const smtk::common::UUID& modelUUID) const override; - - smtk::common::UUID rootAssociation() const override; - - bool createCellField( - const smtk::mesh::HandleRange& meshsets, - const std::string& name, - std::size_t dimension, - const smtk::mesh::FieldType& type, - const void* data) override; - - int getCellFieldDimension(const smtk::mesh::CellFieldTag& cfTag) const override; - smtk::mesh::FieldType getCellFieldType(const smtk::mesh::CellFieldTag& pfTag) const override; - - smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::CellFieldTag& cfTag) const override; - - bool hasCellField(const smtk::mesh::HandleRange& meshsets, const smtk::mesh::CellFieldTag& cfTag) - const override; - - bool getCellField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellFieldTag& cfTag, - void* data) const override; - - bool getField( - const smtk::mesh::HandleRange& cells, - const smtk::mesh::CellFieldTag& cfTag, - void* data) const override; - - bool setField( - const smtk::mesh::HandleRange& cells, - const smtk::mesh::CellFieldTag& cfTag, - const void* data) override; - - bool setCellField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::CellFieldTag& cfTag, - const void* data) override; - - std::set computeCellFieldTags( - const smtk::mesh::Handle& handle) const override; - - bool deleteCellField( - const smtk::mesh::CellFieldTag& cfTag, - const smtk::mesh::HandleRange& meshsets) override; - - bool createPointField( - const smtk::mesh::HandleRange& meshsets, - const std::string& name, - std::size_t dimension, - const smtk::mesh::FieldType& type, - const void* data) override; - - int getPointFieldDimension(const smtk::mesh::PointFieldTag& pfTag) const override; - smtk::mesh::FieldType getPointFieldType(const smtk::mesh::PointFieldTag& pfTag) const override; - - smtk::mesh::HandleRange getMeshsets( - smtk::mesh::Handle handle, - const smtk::mesh::PointFieldTag& pfTag) const override; - - bool hasPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag) const override; - - bool getPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag, - void* data) const override; - - bool getField( - const smtk::mesh::HandleRange& points, - const smtk::mesh::PointFieldTag& pfTag, - void* data) const override; - - bool setField( - const smtk::mesh::HandleRange& points, - const smtk::mesh::PointFieldTag& pfTag, - const void* data) override; - - bool setPointField( - const smtk::mesh::HandleRange& meshsets, - const smtk::mesh::PointFieldTag& pfTag, - const void* data) override; - - std::set computePointFieldTags( - const smtk::mesh::Handle& handle) const override; - - bool deletePointField( - const smtk::mesh::PointFieldTag& pfTag, - const smtk::mesh::HandleRange& meshsets) override; - - smtk::mesh::HandleRange pointIntersect( - const smtk::mesh::HandleRange& a, - const smtk::mesh::HandleRange& b, - smtk::mesh::PointConnectivity& bpc, - smtk::mesh::ContainmentType containmentType) const override; - - smtk::mesh::HandleRange pointDifference( - const smtk::mesh::HandleRange& a, - const smtk::mesh::HandleRange& b, - smtk::mesh::PointConnectivity& bpc, - smtk::mesh::ContainmentType containmentType) const override; - - void pointForEach(const HandleRange& points, smtk::mesh::PointForEach& filter) const override; - - void cellForEach( - const HandleRange& cells, - smtk::mesh::PointConnectivity& pc, - smtk::mesh::CellForEach& filter) const override; - - void meshForEach(const HandleRange& meshes, smtk::mesh::MeshForEach& filter) const override; - - bool deleteHandles(const smtk::mesh::HandleRange& toDel) override; - - ::moab::Interface* moabInterface() const; - - void setModifiedState(bool state) override { m_modified = state; } - -private: - void callPointForEach( - const HandleRange& points, - std::vector& coords, - smtk::mesh::PointForEach& filter) const; - - void pointForEachRecursive( - HandleRange& points, - std::vector& coords, - smtk::mesh::PointForEach& filter) const; - - //holds a reference to the real moab interface - smtk::shared_ptr<::moab::Interface> m_iface; - smtk::mesh::AllocatorPtr m_alloc; - smtk::mesh::BufferedCellAllocatorPtr m_bcAlloc; - smtk::mesh::IncrementalAllocatorPtr m_iAlloc; - mutable bool m_modified{ false }; -}; -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/MergeMeshVertices.cxx b/smtk/mesh/moab/MergeMeshVertices.cxx deleted file mode 100644 index 745247379c59da25c6a95bc0e69ed51f321c98be..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/MergeMeshVertices.cxx +++ /dev/null @@ -1,496 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/mesh/moab/MergeMeshVertices.h" - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -MergeMeshVertices::MergeMeshVertices(::moab::Interface* iface) - : mbImpl(iface) -{ -} - -MergeMeshVertices::~MergeMeshVertices() -{ - if (mbMergeTag) - { - mbImpl->tag_delete(mbMergeTag); - } -} - -::moab::ErrorCode MergeMeshVertices::merge_entities( - const ::moab::Range& meshsets, - const double merge_tol) -{ - using ::moab::AdaptiveKDTree; - using ::moab::EntityHandle; - using ::moab::ErrorCode; - using ::moab::MB_SUCCESS; - using ::moab::MB_TAG_DENSE; - using ::moab::MB_TAG_EXCL; - using ::moab::MB_TYPE_HANDLE; - using ::moab::MBENTITYSET; - using ::moab::MBVERTEX; - using ::moab::Range; - - ErrorCode rval; - - EntityHandle def_val = 0; - rval = mbImpl->tag_get_handle( - "__merge_tag", 1, MB_TYPE_HANDLE, mbMergeTag, MB_TAG_DENSE | MB_TAG_EXCL, &def_val); - if (MB_SUCCESS != rval) - { - return rval; - } - - // get all entities; - // get all vertices connected - // build a kdtree - // find merged to - mergeTol = merge_tol; - mergeTolSq = merge_tol * merge_tol; - - // get all vertices for the meshsets - Range entities; - for (Range::const_iterator i = meshsets.begin(); i != meshsets.end(); ++i) - { - Range tmp; - rval = mbImpl->get_entities_by_handle(*i, tmp, /*recursive*/ true); - if (MB_SUCCESS != rval) - { - return rval; - } - entities.insert(tmp.begin(), tmp.end()); - } - - Range verts; - rval = mbImpl->get_connectivity(entities, verts); - - if (MB_SUCCESS != rval) - { - return rval; - } - - // build a kd tree with the vertices - AdaptiveKDTree kd(mbImpl); - EntityHandle tree_root; - rval = kd.build_tree(verts, &tree_root); - if (MB_SUCCESS != rval) - { - return rval; - } - - // find matching vertices, mark them - rval = find_merged_to(tree_root, kd, mbMergeTag); - if (MB_SUCCESS != rval) - { - return rval; - } - - if (!deadEnts.empty()) - { - rval = map_dead_to_alive(mbMergeTag); - if (MB_SUCCESS != rval) - { - return rval; - } - - //before we delete any elements, we need to update the connectivity of elements - //that use the dead vertices - this->update_connectivity(); - - //Any meshset that explicitly has a deleted vertex needs to have the - //the replacement vertex added back to it. - rval = correct_vertex_merge(meshsets); - if (MB_SUCCESS != rval) - { - return rval; - } - } - - rval = merge_higher_dimensions(entities); - if (MB_SUCCESS != rval) - { - return rval; - } - - return MB_SUCCESS; -} - -::moab::ErrorCode MergeMeshVertices::find_merged_to( - ::moab::EntityHandle& tree_root, - ::moab::AdaptiveKDTree& tree, - ::moab::Tag merged_to) -{ - - using ::moab::AdaptiveKDTree; - using ::moab::AdaptiveKDTreeIter; - using ::moab::CartVect; - using ::moab::EntityHandle; - using ::moab::ErrorCode; - using ::moab::MB_ENTITY_NOT_FOUND; - using ::moab::MB_SUCCESS; - using ::moab::MB_TAG_DENSE; - using ::moab::MB_TAG_EXCL; - using ::moab::MB_TYPE_HANDLE; - using ::moab::MBENTITYSET; - using ::moab::MBVERTEX; - using ::moab::Range; - - AdaptiveKDTreeIter iter; - - // evaluate vertices in this leaf - Range leaf_range, leaf_range2; - std::vector sorted_leaves; - std::vector coords; - std::vector merge_tag_val, leaves_out; - - ErrorCode result = tree.get_tree_iterator(tree_root, iter); - if (MB_SUCCESS != result) - return result; - while (result == MB_SUCCESS) - { - sorted_leaves.push_back(iter.handle()); - result = iter.step(); - } - if (result != MB_ENTITY_NOT_FOUND) - return result; - std::sort(sorted_leaves.begin(), sorted_leaves.end()); - - std::vector::iterator it; - for (it = sorted_leaves.begin(); it != sorted_leaves.end(); ++it) - { - - leaf_range.clear(); - result = mbImpl->get_entities_by_handle(*it, leaf_range); - if (MB_SUCCESS != result) - return result; - coords.resize(3 * leaf_range.size()); - merge_tag_val.resize(leaf_range.size()); - result = mbImpl->get_coords(leaf_range, coords.data()); - if (MB_SUCCESS != result) - return result; - result = mbImpl->tag_get_data(merged_to, leaf_range, merge_tag_val.data()); - if (MB_SUCCESS != result) - return result; - Range::iterator rit; - std::size_t i; - bool inleaf_merged, outleaf_merged = false; - std::size_t lr_size = leaf_range.size(); - - for (i = 0, rit = leaf_range.begin(); i != lr_size; rit++, i++) - { - if (0 != merge_tag_val[i]) - continue; - CartVect from(&coords[3 * i]); - inleaf_merged = false; - - // check close-by leaves too - leaves_out.clear(); - result = tree.distance_search( - from.array(), mergeTol, leaves_out, mergeTol, 1.0e-6, nullptr, nullptr, &tree_root); - leaf_range2.clear(); - for (std::vector::iterator vit = leaves_out.begin(); vit != leaves_out.end(); - vit++) - { - if (*vit > *it) - { // if we haven't visited this leaf yet in the outer loop - result = mbImpl->get_entities_by_handle(*vit, leaf_range2, ::moab::Interface::UNION); - if (MB_SUCCESS != result) - return result; - } - } - if (!leaf_range2.empty()) - { - coords.resize(3 * (lr_size + leaf_range2.size())); - merge_tag_val.resize(lr_size + leaf_range2.size()); - result = mbImpl->get_coords(leaf_range2, &coords[3 * lr_size]); - if (MB_SUCCESS != result) - return result; - result = mbImpl->tag_get_data(merged_to, leaf_range2, &merge_tag_val[lr_size]); - if (MB_SUCCESS != result) - return result; - outleaf_merged = false; - } - - // check other verts in this leaf - for (std::size_t j = i + 1; j < merge_tag_val.size(); j++) - { - EntityHandle to_ent = j >= lr_size ? leaf_range2[j - lr_size] : leaf_range[j]; - - if (*rit == to_ent) - continue; - - //needs to be less than/equal too so that points are resolved - //even when the tolerance is zero. Otherwise exact matches are - //considered to be not the same - const double distSq = (from - CartVect(&coords[3 * j])).length_squared(); - if (distSq <= mergeTolSq) - { - merge_tag_val[j] = *rit; - if (j < lr_size) - { - inleaf_merged = true; - } - else - { - outleaf_merged = true; - } - deadEnts.insert(to_ent); - } - } - if (outleaf_merged) - { - result = mbImpl->tag_set_data(merged_to, leaf_range2, &merge_tag_val[leaf_range.size()]); - if (MB_SUCCESS != result) - return result; - outleaf_merged = false; - } - if (inleaf_merged) - { - result = mbImpl->tag_set_data(merged_to, leaf_range, merge_tag_val.data()); - if (MB_SUCCESS != result) - return result; - } - } - } - return MB_SUCCESS; -} - -::moab::ErrorCode MergeMeshVertices::map_dead_to_alive(::moab::Tag merged_to) -{ - using ::moab::EntityHandle; - using ::moab::ErrorCode; - using ::moab::MB_FAILURE; - using ::moab::MB_SUCCESS; - using ::moab::MBVERTEX; - using ::moab::Range; - - // we start with an empty range of vertices that are "merged to" - // they are used (eventually) for higher dim entities - mergedToVertices.clear(); - ErrorCode result; - if (deadEnts.empty()) - { - return MB_SUCCESS; //nothing to merge carry on with the program - } - - if (mbImpl->type_from_handle(*deadEnts.rbegin()) != MBVERTEX) - return MB_FAILURE; - std::vector merge_tag_val(deadEnts.size()); - result = mbImpl->tag_get_data(merged_to, deadEnts, merge_tag_val.data()); - if (MB_SUCCESS != result) - return result; - - //first build up the mapping from dead to new vertices - Range::iterator rit; - std::size_t i; - for (rit = deadEnts.begin(), i = 0; rit != deadEnts.end(); rit++, i++) - { - assert(merge_tag_val[i]); - if (MBVERTEX == mbImpl->type_from_handle(merge_tag_val[i])) - { - mergedToVertices.insert(merge_tag_val[i]); - mappingFromDeadToAlive[*rit] = static_cast(merge_tag_val[i]); - } - } - - return MB_SUCCESS; -} - -//now before we delete the entities, -//we need to make sure that any mesh that is losing an explicit vertex -//has it replaced with the merged vertex, this isn't handled by perform_merge -//as it only does dim > 0 -::moab::ErrorCode MergeMeshVertices::correct_vertex_merge(const ::moab::Range& meshsets) -{ - using ::moab::EntityHandle; - using ::moab::ErrorCode; - using ::moab::MB_FAILURE; - using ::moab::MB_SUCCESS; - using ::moab::MBVERTEX; - using ::moab::Range; - - for (Range::const_iterator i = meshsets.begin(); i != meshsets.end(); ++i) - { - Range entitiesVerts; - mbImpl->get_entities_by_dimension(*i, 0 /*dimension*/, entitiesVerts, /*recursive*/ true); - - //determine if we have a vert which is going deleted - Range vertsToDelete = ::moab::intersect(deadEnts, entitiesVerts); - if (!vertsToDelete.empty()) - { - Range::iterator rit; - std::size_t j; - for (rit = vertsToDelete.begin(), j = 0; rit != vertsToDelete.end(); rit++, j++) - { - //now we add these entities to the new meshset - EntityHandle t = mappingFromDeadToAlive[*rit]; - mbImpl->add_entities(*i, &t, 1); - } - mbImpl->remove_entities(*i, vertsToDelete); - } - } - - return MB_SUCCESS; -} - -//Update the connectivity of the cells that used one or more of the -//soon to be dead points -::moab::ErrorCode MergeMeshVertices::update_connectivity() -{ - using ::moab::EntityHandle; - using ::moab::ErrorCode; - using ::moab::MB_FAILURE; - using ::moab::MB_SUCCESS; - using ::moab::MBVERTEX; - using ::moab::Range; - - ErrorCode result; - - for (int dim = 1; dim <= 3; dim++) - { - Range entsToUpdate; - result = mbImpl->get_adjacencies(deadEnts, dim, false, entsToUpdate, ::moab::Interface::UNION); - - if (MB_SUCCESS != result) - { - return result; - } - - //get the connectivity for all the deadEnts - Range::iterator iter = entsToUpdate.begin(); - Range::iterator end = entsToUpdate.end(); - while (iter != end) - { - int numCellsInSubRange = 0; - int verts_per_ent = 0; - EntityHandle* connectivity = nullptr; - result = mbImpl->connect_iterate(iter, end, connectivity, verts_per_ent, numCellsInSubRange); - if (MB_SUCCESS != result) - { - return result; - } - - //now we can iterate the connectivity, fixing it up as needed - std::size_t index = 0; - for (int i = 0; i < numCellsInSubRange; ++i, ++iter) - { - for (int j = 0; j < verts_per_ent; ++j, ++index) - { - typedef std::map<::moab::EntityHandle, ::moab::EntityHandle> MapType; - MapType::const_iterator pos = mappingFromDeadToAlive.find(connectivity[index]); - if (pos != mappingFromDeadToAlive.end()) - { - //when we update the connectivity array we also need to update - //the adjacencies table. This makes sure that quick lookups - //are aware of the merging of points - mbImpl->remove_adjacencies(*iter, connectivity + index, 1); - connectivity[index] = pos->second; - mbImpl->add_adjacencies(*iter, connectivity + index, 1, true); - } - } - } - } - } - - return MB_SUCCESS; -} - -//Determine which higher dimensional entities should be merged -::moab::ErrorCode MergeMeshVertices::merge_higher_dimensions(::moab::Range& elems) -{ - using ::moab::EntityHandle; - using ::moab::ErrorCode; - using ::moab::MB_FAILURE; - using ::moab::MB_SUCCESS; - using ::moab::MBVERTEX; - using ::moab::Range; - - // apply a different strategy - // look at the vertices that were merged to, earlier, and find all entities adjacent to them - // elems (input) are used just for initial connectivity - ErrorCode result; - Range verts; - result = mbImpl->get_connectivity(elems, verts); - verts.merge(elems.subset_by_dimension(0)); //don't forget these - if (MB_SUCCESS != result) - return result; - - // all higher dim entities that will be merged will be connected to the vertices that were - // merged earlier; we will look at these vertices only - Range vertsOfInterest = intersect(this->mergedToVertices, verts); - //Go through each dimension - Range possibleEntsToMerge, conn, matches, moreDeadEnts; - - for (int dim = 1; dim < 3; dim++) - { - moreDeadEnts.clear(); - possibleEntsToMerge.clear(); - result = mbImpl->get_adjacencies( - vertsOfInterest, dim, false, possibleEntsToMerge, ::moab::Interface::UNION); - if (MB_SUCCESS != result) - return result; - //Go through each possible entity and see if it shares vertices with another entity of same dimension - for (Range::iterator pit = possibleEntsToMerge.begin(); pit != possibleEntsToMerge.end(); pit++) - { - EntityHandle eh = *pit; //possible entity to be matched - conn.clear(); - //Get the vertices connected to it in a range - if (mbImpl->type_from_handle(eh) != MBVERTEX) - { - result = mbImpl->get_connectivity(&eh, 1, conn); - } - else - { - conn.insert(eh); - result = MB_SUCCESS; - } - - if (MB_SUCCESS != result) - return result; - matches.clear(); - // now retrieve all entities connected to all conn vertices - result = mbImpl->get_adjacencies(conn, dim, false, matches, ::moab::Interface::INTERSECT); - if (MB_SUCCESS != result) - return result; - if (matches.size() > 1) - { - for (Range::iterator matchIt = matches.begin(); matchIt != matches.end(); matchIt++) - { - EntityHandle to_remove = *matchIt; - if (to_remove != eh) - { - moreDeadEnts.insert(to_remove); - result = mbImpl->merge_entities(eh, to_remove, false, false); - if (result != MB_SUCCESS) - return result; - possibleEntsToMerge.erase(to_remove); - } - } - } - } - //Delete the entities of dimension dim - result = mbImpl->delete_entities(moreDeadEnts); - if (result != MB_SUCCESS) - return result; - } - return MB_SUCCESS; -} - -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/MergeMeshVertices.h b/smtk/mesh/moab/MergeMeshVertices.h deleted file mode 100644 index b4a0b327eb9b0ad0aaae0973c451b8902cd13ddb..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/MergeMeshVertices.h +++ /dev/null @@ -1,88 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#ifndef smtk_mesh_moab_MergeMeshVertices_h -#define smtk_mesh_moab_MergeMeshVertices_h - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/AdaptiveKDTree.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include "smtk/mesh/core/Handle.h" - -#include - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -class MergeMeshVertices -{ -public: - MergeMeshVertices(::moab::Interface* iface); - - ~MergeMeshVertices(); - - ::moab::ErrorCode merge_entities(const ::moab::Range& meshsets, double merge_tol = 1.0e-6); - -private: - //- given a kdtree, set tag on vertices in leaf nodes with vertices - //- to which they should be merged - ::moab::ErrorCode find_merged_to( - ::moab::EntityHandle& tree_root, - ::moab::AdaptiveKDTree& tree, - ::moab::Tag merged_to); - - //- fill mappingFromDeadToAlive - ::moab::ErrorCode map_dead_to_alive(::moab::Tag merged_to); - - //- delete the deadEnts - ::moab::ErrorCode delete_dead_entities(::moab::Tag merged_to); - - //- correct any occurrences of vertices inside a mesh being deleted and - // the replacement vertex not already being an entity of that mesh - ::moab::ErrorCode correct_vertex_merge(const ::moab::Range& meshsets); - - //Update the connectivity of the cells that used one or more of the - //soon to be dead points - ::moab::ErrorCode update_connectivity(); - - //Identify higher dimension to be merged - ::moab::ErrorCode merge_higher_dimensions(::moab::Range& elems); - - ::moab::Interface* mbImpl; - - //- the tag pointing to the entity to which an entity will be merged - ::moab::Tag mbMergeTag; - - //- entities which will go away after the merge - ::moab::Range deadEnts; - - // vertices that were merged with other vertices, and were left in the database - ::moab::Range mergedToVertices; - - // mapping from deadEnts to vertices that we are keeping - std::map<::moab::EntityHandle, ::moab::EntityHandle> mappingFromDeadToAlive; - - double mergeTol, mergeTolSq; -}; - -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/ModelEntityPointLocator.cxx b/smtk/mesh/moab/ModelEntityPointLocator.cxx deleted file mode 100644 index 572b55506335e11410ccdacdd8521e5e2c89eee7..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/ModelEntityPointLocator.cxx +++ /dev/null @@ -1,275 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/moab/ModelEntityPointLocator.h" - -#include "smtk/AutoInit.h" - -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/core/TypeSet.h" - -#include "smtk/mesh/moab/HandleRangeToRange.h" -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/model/EntityRef.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/AdaptiveKDTree.hpp" -#include "moab/BoundBox.hpp" -#include "moab/CartVect.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include -#include -#include - -#ifndef M_PI -#define M_PI 3.14159265358979323846264338327950288 -#endif - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ -ModelEntityPointLocator::ModelEntityPointLocator() = default; - -ModelEntityPointLocator::~ModelEntityPointLocator() = default; - -bool ModelEntityPointLocator::closestPointOn( - const smtk::model::EntityRef& entity, - std::vector& closestPoints, - const std::vector& sourcePoints, - bool snapToPoint) -{ - // Attempt to access the entity's mesh tessellation - smtk::mesh::MeshSet meshTessellation = entity.meshTessellation(); - - // If the entity has a mesh tessellation, and the mesh backend is moab, and - // the tessellation has triangles... - if ( - meshTessellation.isValid() && meshTessellation.resource()->interfaceName() == "moab" && - meshTessellation.types().hasCell(smtk::mesh::Triangle)) - { - //...then we can use Moab's AdaptiveKDTree to find closest points. - const smtk::mesh::moab::InterfacePtr& interface = - std::static_pointer_cast( - meshTessellation.resource()->interface()); - - // This option restricts the KD tree from subdividing too much - ::moab::FileOptions treeOptions("MAX_DEPTH=13"); - - // Construct an AdaptiveKDTree - ::moab::EntityHandle treeRootSet; - ::moab::AdaptiveKDTree tree( - interface->moabInterface(), - smtkToMOABRange(meshTessellation.cells().range()), - &treeRootSet, - &treeOptions); - - // Prepare the output for its points - closestPoints.resize(sourcePoints.size()); - - // For each point, query the tree for the nearest point. - ::moab::EntityHandle triangleOut; - for (std::size_t i = 0; i < sourcePoints.size(); i += 3) - { - // Identify the nearest point and the associated triangle - tree.closest_triangle(treeRootSet, &sourcePoints[i], &closestPoints[i], triangleOut); - - // If point snapping is selected... - if (snapToPoint) - { - // ...access the three vertices of the nearest triangle - ::moab::Range connectivity; - interface->moabInterface()->get_connectivity(&triangleOut, 1, connectivity); - std::array coords; - interface->moabInterface()->get_coords(connectivity, coords.data()); - - // Compute the squared distance betwen the source point and the vertex - std::array dist2 = { { 0., 0., 0. } }; - for (std::size_t j = 0; j < 3; j++) - { - for (std::size_t k = 0; k < 3; k++) - { - double tmp = coords[3 * j + k] - sourcePoints[i + k]; - dist2[j] += tmp * tmp; - } - } - - // Assign the closest point to the coordinates of the closest vertex - std::size_t index = - std::distance(dist2.begin(), std::min_element(dist2.begin(), dist2.end())); - for (std::size_t j = 0; j < 3; j++) - { - closestPoints[i + j] = coords[3 * index + j]; - } - } - } - return true; - } - return false; -} - -bool ModelEntityPointLocator::randomPoint( - const smtk::model::EntityRef& entity, - const std::size_t nPoints, - std::vector& points, - const std::size_t seed) -{ - // Select random points on an entity based on the following: - // - // J. A. Detwiler, R. Henning, R. A. Johnson, M. G. Marino. "A Generic Surface - // Sampler for Monte Carlo Simulations." IEEE Trans.Nucl.Sci.55:2329-2333,2008 - // https://arxiv.org/abs/0802.2960 - // - // Here's the ansatz: - // 1. Compute a bounding sphere of radius R and origin O around the geometry - // 2. Randomly select a point D on the bounding sphere - // 3. Compute a disk of radius R through point D and tangent to the bounding - // sphere - // 4. Select a random point P on this disk - // 5. Shoot a ray from P with direction (\hat{\vec{O} - \vec{D}}) through the - // geometry - // 6. If there are multiple intersections along this ray, randomly select one - // of the intersection points - - // Attempt to access the entity's mesh tessellation - smtk::mesh::MeshSet meshTessellation = entity.meshTessellation(); - - // If the entity has a mesh tessellation, and the mesh backend is moab, and - // the tessellation has triangles... - if ( - meshTessellation.isValid() && meshTessellation.resource()->interfaceName() == "moab" && - meshTessellation.types().hasCell(smtk::mesh::Triangle)) - { - //...then we can use Moab's AdaptiveKDTree to find closest points. - const smtk::mesh::moab::InterfacePtr& interface = - std::static_pointer_cast( - meshTessellation.resource()->interface()); - - // This option restricts the KD tree from subdividing too much - ::moab::FileOptions treeOptions("MAX_DEPTH=13"); - - // Construct an AdaptiveKDTree - ::moab::EntityHandle treeRootSet; - ::moab::AdaptiveKDTree tree( - interface->moabInterface(), - smtkToMOABRange(meshTessellation.cells().range()), - &treeRootSet, - &treeOptions); - - // Prepare the output for its points - points.resize(3 * nPoints); - - // Get the bounding box for the tree - ::moab::BoundBox box; - tree.get_bounding_box(box); - - // Get the diameter and radius of the bounding sphere for the tree - const double diameter = box.diagonal_length(); - const double radius = diameter / 2.; - - // Get the origin of the bounding sphere for the tree - ::moab::CartVect origin; - box.compute_center(origin); - - // Create a RNG to sample points on the unit line - std::mt19937 mt(static_cast(seed)); - std::uniform_real_distribution dist(0., 1.0); - - // Moab's ray intersection algorithm requires a tolerance. So, here it is. - const double tolerance = 1.e-8; - - std::size_t nComputed = 0; - while (nComputed < nPoints) - { - // Select a random point on the surface of our bounding sphere - double theta = M_PI * dist(mt); - double phi = 2. * M_PI * dist(mt); - - double sinTheta = std::sin(theta); - double cosTheta = std::cos(theta); - double sinPhi = std::sin(phi); - double cosPhi = std::cos(phi); - - const std::array dUnit = { sinTheta * cosPhi, sinTheta * sinPhi, cosTheta }; - const std::array d = { radius * dUnit[0], radius * dUnit[1], radius * dUnit[2] }; - - // Construct a pair of orthonormal vectors tangent to the sphere at the - // above random point - double sinThetaPlusPiOver2 = std::sin(theta + M_PI / 2.); - double cosThetaPlusPiOver2 = std::cos(theta + M_PI / 2.); - double sinPhiPlusPiOver2 = std::sin(phi + M_PI / 2.); - double cosPhiPlusPiOver2 = std::cos(phi + M_PI / 2.); - - const std::array tangent1 = { sinThetaPlusPiOver2 * cosPhi, - sinThetaPlusPiOver2 * sinPhi, - cosThetaPlusPiOver2 }; - const std::array tangent2 = { sinTheta * cosPhiPlusPiOver2, - sinTheta * sinPhiPlusPiOver2, - cosTheta }; - - // Construct a random point on a disk with radius equal to the radius of - // our bounding sphere - double bMag = radius * std::sqrt(dist(mt)); - double theta2 = 2. * M_PI * dist(mt); - - double sinTheta2 = std::sin(theta2); - double cosTheta2 = std::cos(theta2); - - const std::array b = { bMag * cosTheta2, bMag * sinTheta2 }; - - // Superimpose the second random point onto the tangent plane of our - // bounding sphere, and offset the point according to the bounding - // sphere's origin. - std::array p = d; - for (unsigned int i = 0; i < 3; i++) - { - p[i] += b[0] * tangent1[i] + b[1] * tangent2[i] + origin[i]; - } - - // Finally, the ray trajectory is simply the negative unit d vector - std::array dir = { -dUnit[0], -dUnit[1], -dUnit[2] }; - - // Compute the intersection of our ray and the surface - std::vector<::moab::EntityHandle> trianglesOut; - std::vector distanceOut; - tree.ray_intersect_triangles( - treeRootSet, tolerance, dir.data(), p.data(), trianglesOut, distanceOut, 0, diameter); - - if (!distanceOut.empty()) - { - // We randomly select which intersection site to use as our sample point - std::size_t index = static_cast(distanceOut.size() * dist(mt)); - for (std::size_t i = 0; i < 3; i++) - { - points[3 * nComputed + i] = p[i] + distanceOut[index] * dir[i]; - } - ++nComputed; - } - } - - return true; - } - return false; -} -} // namespace moab -} // namespace mesh -} // namespace smtk - -smtkDeclareExtension( - SMTKCORE_EXPORT, - moab_model_entity_point_locator, - smtk::mesh::moab::ModelEntityPointLocator); - -smtkComponentInitMacro(smtk_moab_model_entity_point_locator_extension); diff --git a/smtk/mesh/moab/ModelEntityPointLocator.h b/smtk/mesh/moab/ModelEntityPointLocator.h deleted file mode 100644 index 746e2d48738776bb365f82104166efb511916984..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/ModelEntityPointLocator.h +++ /dev/null @@ -1,57 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_moab_ModelEntityPointLocator_h -#define smtk_mesh_moab_ModelEntityPointLocator_h - -#include "smtk/model/PointLocatorExtension.h" - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -/**\brief A class that provides point-location based on entities' associated meshsets. - */ -class SMTKCORE_EXPORT ModelEntityPointLocator : public smtk::model::PointLocatorExtension -{ -public: - smtkTypeMacro(smtk::mesh::moab::ModelEntityPointLocator); - smtkCreateMacro(smtk::common::Extension); - smtkSuperclassMacro(smtk::model::PointLocatorExtension); - ~ModelEntityPointLocator() override; - - /// Overwrites \a closestPoints with points on \a entity closest to \a sourcePoints. - bool closestPointOn( - const smtk::model::EntityRef& entity, - std::vector& closestPoints, - const std::vector& sourcePoints, - bool snapToPoint) override; - - // A random surface sampling algorithm based on the following: - // - // J. A. Detwiler, R. Henning, R. A. Johnson, M. G. Marino. "A Generic Surface - // Sampler for Monte Carlo Simulations." IEEE Trans.Nucl.Sci.55:2329-2333,2008. - // https://arxiv.org/abs/0802.2960 - bool randomPoint( - const smtk::model::EntityRef& entity, - std::size_t nPoints, - std::vector& points, - std::size_t seed) override; - -protected: - ModelEntityPointLocator(); -}; -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/PointLocatorCache.cxx b/smtk/mesh/moab/PointLocatorCache.cxx deleted file mode 100644 index 4e96cbfe9567b673ab535eff5877b687ec9d0eee..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/PointLocatorCache.cxx +++ /dev/null @@ -1,38 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/moab/PointLocatorCache.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -void PointLocatorCache::synchronize( - const smtk::operation::Operation&, - const smtk::operation::Operation::Result& result) -{ - for (const auto& component : - { result->findComponent("expunged"), result->findComponent("modified") }) - { - for (std::size_t i = 0; i < component->numberOfValues(); ++i) - { - m_caches.erase(component->value(i)->id()); - } - } -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/PointLocatorCache.h b/smtk/mesh/moab/PointLocatorCache.h deleted file mode 100644 index 3924e67b8899458f4fbf11e551b2e19830ebb075..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/PointLocatorCache.h +++ /dev/null @@ -1,73 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_moab_PointLocatorCache_h -#define smtk_mesh_moab_PointLocatorCache_h - -#include "smtk/CoreExports.h" - -#include "smtk/operation/queries/SynchronizedCache.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/AdaptiveKDTree.hpp" -#include "moab/BoundBox.hpp" -#include "moab/CartVect.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -struct SMTKCORE_EXPORT PointLocatorCache : public smtk::operation::SynchronizedCache -{ - struct CacheForIndex - { - CacheForIndex( - ::moab::Interface* interface, - const ::moab::Range& range, - ::moab::FileOptions* fileOptions) - : m_interface(interface) - , m_tree(m_interface, range, &m_treeRootSet, fileOptions) - { - } - - ::moab::Interface* m_interface; - ::moab::EntityHandle m_treeRootSet; - ::moab::AdaptiveKDTree m_tree; - }; - - PointLocatorCache() = default; - ~PointLocatorCache() override = default; - PointLocatorCache(const PointLocatorCache&) = delete; - PointLocatorCache(PointLocatorCache&& rhs) noexcept - : m_caches(std::move(rhs.m_caches)) - { - } - - PointLocatorCache& operator=(const PointLocatorCache&) = delete; - PointLocatorCache& operator=(PointLocatorCache&& rhs) noexcept - { - m_caches = std::move(rhs.m_caches); - return *this; - } - - void synchronize(const smtk::operation::Operation&, const smtk::operation::Operation::Result&) - override; - - std::unordered_map> m_caches; -}; -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/PointLocatorImpl.cxx b/smtk/mesh/moab/PointLocatorImpl.cxx deleted file mode 100644 index 795aac167193722afc9f651f6c7a6b96a36539dc..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/PointLocatorImpl.cxx +++ /dev/null @@ -1,255 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/moab/PointLocatorImpl.h" -#include "moab/FileOptions.hpp" -#include "smtk/mesh/moab/HandleRangeToRange.h" -#include "smtk/mesh/moab/Interface.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/AdaptiveKDTree.hpp" -#include "moab/ReadUtilIface.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include -#include - -namespace -{ -smtk::mesh::Handle create_point_mesh( - ::moab::Interface* iface, - std::size_t numPoints, - const std::function(std::size_t)>& coordinates, - ::moab::Range& points) -{ - ::moab::ReadUtilIface* alloc; - iface->query_interface(alloc); - - //allocate enough space for out points - smtk::mesh::Handle firstId; - std::vector coords; - alloc->get_node_coords( - 3, //x,y,z - static_cast(numPoints), - 0, //preferred_start_id - firstId, - coords); - - //copy the points into the resource - for (std::size_t i = 0; i < numPoints; ++i) - { - std::array x = coordinates(i); - for (std::size_t j = 0; j < 3; ++j) - { - coords[j][i] = x[j]; - } - } - points.insert(firstId, firstId + numPoints - 1); - - smtk::mesh::Handle meshHandle; - const unsigned int options = 0; - ::moab::ErrorCode rval = iface->create_meshset(options, meshHandle); - if (rval == ::moab::MB_SUCCESS) - { - iface->add_entities(meshHandle, points); - iface->add_parent_child(iface->get_root_set(), meshHandle); - } - return meshHandle; -} -} // namespace - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -PointLocatorImpl::PointLocatorImpl(::moab::Interface* interface, const ::moab::Range& points) - : m_interface(interface) - , m_meshOwningPoints() - , m_deletePoints(false) - , m_tree(interface, points) -{ -} - -PointLocatorImpl::PointLocatorImpl( - ::moab::Interface* interface, - std::size_t numPoints, - const std::function(std::size_t)>& coordinates) - : m_interface(interface) - , m_meshOwningPoints() - , m_deletePoints(true) - , m_tree(interface) -{ - ::moab::Range points; - m_meshOwningPoints = - create_point_mesh(interface, static_cast(numPoints), coordinates, points); - // hacker solution to speed up the bathymetry Operation - ::moab::FileOptions treeOptions("MAX_DEPTH=13"); - m_tree.build_tree(points, nullptr, &treeOptions); -} - -PointLocatorImpl::~PointLocatorImpl() -{ - m_tree.reset_tree(); - if (m_deletePoints) - { - //we don't delete the vertices, as those can't be explicitly deleted - //instead they are deleted when the mesh goes away - m_interface->delete_entities(&m_meshOwningPoints, 1); - } -} - -smtk::mesh::HandleRange PointLocatorImpl::range() const -{ - ::moab::Range entities; - m_interface->get_entities_by_handle(m_meshOwningPoints, entities); - return moabToSMTKRange(entities); -} - -namespace -{ - -template -void reserve_space(std::vector& container, std::size_t size) -{ - container.reserve(size); -} - -template<> -void reserve_space(std::vector& /*unused*/, std::size_t /*unused*/) -{ -} - -template -void add_to(std::vector& container, double value) -{ - container.push_back(value); -} - -template<> -void add_to(std::vector& /*unused*/, double /*unused*/) -{ -} - -template -void find_valid_points( - const double x, - const double y, - const double z, - const double sqRadius, - const ::moab::Range& points, - const std::vector& x_locs, - const std::vector& y_locs, - const std::vector& z_locs, - std::size_t pointIdOffset, - smtk::mesh::PointLocatorImpl::Results& results) -{ - - const std::size_t numPoints = points.size(); - - ::moab::Range::const_iterator ptIter = points.begin(); - std::vector ptId_temp; - - //clear any existing data from the arrays - results.pointIds.clear(); - results.sqDistances.clear(); - results.x_s.clear(); - results.y_s.clear(); - results.z_s.clear(); - - results.pointIds.reserve(numPoints); - reserve_space(results.sqDistances, numPoints); - reserve_space(results.x_s, numPoints); - reserve_space(results.y_s, numPoints); - reserve_space(results.z_s, numPoints); - - for (std::size_t i = 0; i < numPoints; ++i, ++ptIter) - { - const double sqLen = (x - x_locs[i]) * (x - x_locs[i]) + (y - y_locs[i]) * (y - y_locs[i]) + - (z - z_locs[i]) * (z - z_locs[i]); - - if (sqLen <= sqRadius) - { - results.pointIds.push_back(static_cast(*ptIter) - pointIdOffset); - add_to(results.sqDistances, sqLen); - add_to(results.x_s, x_locs[i]); - add_to(results.y_s, y_locs[i]); - add_to(results.z_s, z_locs[i]); - } - } -} -} // namespace - -void PointLocatorImpl::locatePointsWithinRadius( - double x, - double y, - double z, - double radius, - Results& results) -{ - std::vector<::moab::EntityHandle> leaves; - double xyz[3] = { x, y, z }; - m_tree.distance_search(xyz, radius, leaves); - - if (leaves.empty()) - { - return; - } - - //now we need to get all the points from the leaves, and do a finer - //comparison on which ones are within distance of the input point - ::moab::Range points; - for (std::size_t i = 0; i < leaves.size(); ++i) - { - m_interface->get_entities_by_dimension(leaves[i], 0, points); - } - - const double sqRadius = radius * radius; - const std::size_t numPoints = points.size(); - std::vector x_locs(numPoints), y_locs(numPoints), z_locs(numPoints); - m_interface->get_coords(points, x_locs.data(), y_locs.data(), z_locs.data()); - - //now iterate and compute distances. We use a templated version of - //find_valid_points so that we generate 4 versions of the algorithm that - //each are optimal for what the caller wants saved. This means that we - //don't have to take 2 extra branches inside the tight loop - const bool wantDistance = results.want_sqDistances; - const bool wantCoords = results.want_Coordinates; - - ::moab::Range entities; - m_interface->get_entities_by_handle(m_meshOwningPoints, entities); - ::moab::EntityHandle firstCell = entities[0]; - - if (wantDistance && wantCoords) - { - find_valid_points( - x, y, z, sqRadius, points, x_locs, y_locs, z_locs, firstCell, results); - } - else if (wantDistance) - { - find_valid_points( - x, y, z, sqRadius, points, x_locs, y_locs, z_locs, firstCell, results); - } - else if (wantCoords) - { - find_valid_points( - x, y, z, sqRadius, points, x_locs, y_locs, z_locs, firstCell, results); - } - else - { - find_valid_points( - x, y, z, sqRadius, points, x_locs, y_locs, z_locs, firstCell, results); - } -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/PointLocatorImpl.h b/smtk/mesh/moab/PointLocatorImpl.h deleted file mode 100644 index d9650ae42fb5ad1cfdc8822ae0860d66435561c4..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/PointLocatorImpl.h +++ /dev/null @@ -1,60 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_moab_PointLocatorImpl_h -#define smtk_mesh_moab_PointLocatorImpl_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/AdaptiveKDTree.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -class SMTKCORE_EXPORT PointLocatorImpl : public smtk::mesh::PointLocatorImpl -{ -public: - PointLocatorImpl(::moab::Interface* interface, const ::moab::Range& points); - - PointLocatorImpl( - ::moab::Interface* interface, - std::size_t numPoints, - const std::function(std::size_t)>& coordinates); - - ~PointLocatorImpl() override; - - smtk::mesh::HandleRange range() const override; - - //returns the set of points that are within the radius of a single point - void locatePointsWithinRadius(double x, double y, double z, double radius, Results& results) - override; - -private: - ::moab::Interface* m_interface; - smtk::mesh::Handle m_meshOwningPoints; - bool m_deletePoints; - ::moab::AdaptiveKDTree m_tree; -}; -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/RandomPoint.cxx b/smtk/mesh/moab/RandomPoint.cxx deleted file mode 100644 index 90d44bbaa48e588519a566ccd9d57061e3154a72..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/RandomPoint.cxx +++ /dev/null @@ -1,228 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/moab/RandomPoint.h" - -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/moab/HandleRangeToRange.h" -#include "smtk/mesh/moab/Interface.h" -#include "smtk/mesh/moab/PointLocatorCache.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/AdaptiveKDTree.hpp" -#include "moab/BoundBox.hpp" -#include "moab/CartVect.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include -#include -#include - -#ifndef M_PI -#define M_PI 3.14159265358979323846264338327950288 -#endif - -namespace -{ -struct MersenneTwisterCache : public smtk::resource::query::Cache -{ - MersenneTwisterCache() - : mt(0) - { - } - std::size_t seed{ 0 }; - std::mt19937 mt; -}; -} // namespace - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ -std::array RandomPoint::operator()(const smtk::resource::Component::Ptr& component) const -{ - auto meshComponent = std::dynamic_pointer_cast(component); - if (meshComponent) - { - return operator()(meshComponent->mesh()); - } - - auto modelComponent = std::dynamic_pointer_cast(component); - if (modelComponent) - { - return operator()(modelComponent->referenceAs().meshTessellation()); - } - - return this->Parent::operator()(component); -} - -std::array RandomPoint::operator()(const smtk::mesh::MeshSet& meshset) const -{ - // Select random points on an entity based on the following: - // - // J. A. Detwiler, R. Henning, R. A. Johnson, M. G. Marino. "A Generic Surface - // Sampler for Monte Carlo Simulations." IEEE Trans.Nucl.Sci.55:2329-2333,2008 - // https://arxiv.org/abs/0802.2960 - // - // Here's the ansatz: - // 1. Compute a bounding sphere of radius R and origin O around the geometry - // 2. Randomly select a point D on the bounding sphere - // 3. Compute a disk of radius R through point D and tangent to the bounding - // sphere - // 4. Select a random point P on this disk - // 5. Shoot a ray from P with direction (\hat{\vec{O} - \vec{D}}) through the - // geometry - // 6. If there are multiple intersections along this ray, randomly select one - // of the intersection points - - static constexpr const double nan = std::numeric_limits::quiet_NaN(); - std::array returnValue{ { nan, nan, nan } }; - - // If the entity has a mesh tessellation, and the mesh backend is moab, and - // the tessellation has triangles... - if ( - meshset.isValid() && meshset.resource()->interfaceName() == "moab" && - meshset.types().hasCell(smtk::mesh::Triangle)) - { - //...then we can use Moab's AdaptiveKDTree to find closest points. - const smtk::mesh::moab::InterfacePtr& interface = - std::static_pointer_cast(meshset.resource()->interface()); - - PointLocatorCache& pointLocatorCache = meshset.resource()->queries().cache(); - - auto search = pointLocatorCache.m_caches.find(meshset.id()); - if (search == pointLocatorCache.m_caches.end()) - { - // This option restricts the KD tree from subdividing too much - ::moab::FileOptions treeOptions("MAX_DEPTH=13"); - - search = - pointLocatorCache.m_caches - .emplace( - meshset.id(), - std::make_unique( - interface->moabInterface(), smtkToMOABRange(meshset.cells().range()), &treeOptions)) - .first; - } - - ::moab::AdaptiveKDTree& tree = search->second->m_tree; - - // Get the bounding box for the tree - ::moab::BoundBox box; - tree.get_bounding_box(box); - - // Get the diameter and radius of the bounding sphere for the tree - const double diameter = box.diagonal_length(); - const double radius = diameter / 2.; - - // Get the origin of the bounding sphere for the tree - ::moab::CartVect origin; - box.compute_center(origin); - - // Create a RNG to sample points on the unit line - MersenneTwisterCache& mersenneTwisterCache = - meshset.resource()->queries().cache(); - std::mt19937& mt = mersenneTwisterCache.mt; - if (m_seed != mersenneTwisterCache.seed) - { - mersenneTwisterCache.seed = m_seed; - mersenneTwisterCache.mt.seed(static_cast(m_seed)); - } - - std::uniform_real_distribution dist(0., 1.0); - - // Moab's ray intersection algorithm requires a tolerance. So, here it is. - const double tolerance = 1.e-8; - - bool computed = false; - do - { - // Select a random point on the surface of our bounding sphere - double theta = M_PI * dist(mt); - double phi = 2. * M_PI * dist(mt); - - double sinTheta = std::sin(theta); - double cosTheta = std::cos(theta); - double sinPhi = std::sin(phi); - double cosPhi = std::cos(phi); - - const std::array dUnit = { sinTheta * cosPhi, sinTheta * sinPhi, cosTheta }; - const std::array d = { radius * dUnit[0], radius * dUnit[1], radius * dUnit[2] }; - - // Construct a pair of orthonormal vectors tangent to the sphere at the - // above random point - double sinThetaPlusPiOver2 = std::sin(theta + M_PI / 2.); - double cosThetaPlusPiOver2 = std::cos(theta + M_PI / 2.); - double sinPhiPlusPiOver2 = std::sin(phi + M_PI / 2.); - double cosPhiPlusPiOver2 = std::cos(phi + M_PI / 2.); - - const std::array tangent1 = { sinThetaPlusPiOver2 * cosPhi, - sinThetaPlusPiOver2 * sinPhi, - cosThetaPlusPiOver2 }; - const std::array tangent2 = { sinTheta * cosPhiPlusPiOver2, - sinTheta * sinPhiPlusPiOver2, - cosTheta }; - - // Construct a random point on a disk with radius equal to the radius of - // our bounding sphere - double bMag = radius * std::sqrt(dist(mt)); - double theta2 = 2. * M_PI * dist(mt); - - double sinTheta2 = std::sin(theta2); - double cosTheta2 = std::cos(theta2); - - const std::array b = { bMag * cosTheta2, bMag * sinTheta2 }; - - // Superimpose the second random point onto the tangent plane of our - // bounding sphere, and offset the point according to the bounding - // sphere's origin. - std::array p = d; - for (unsigned int i = 0; i < 3; i++) - { - p[i] += b[0] * tangent1[i] + b[1] * tangent2[i] + origin[i]; - } - - // Finally, the ray trajectory is simply the negative unit d vector - std::array dir = { -dUnit[0], -dUnit[1], -dUnit[2] }; - - // Compute the intersection of our ray and the surface - std::vector<::moab::EntityHandle> trianglesOut; - std::vector distanceOut; - tree.ray_intersect_triangles( - search->second->m_treeRootSet, - tolerance, - dir.data(), - p.data(), - trianglesOut, - distanceOut, - 0, - diameter); - - if (!distanceOut.empty()) - { - // We randomly select which intersection site to use as our sample point - std::size_t index = static_cast(distanceOut.size() * dist(mt)); - for (std::size_t i = 0; i < 3; i++) - { - returnValue[i] = p[i] + distanceOut[index] * dir[i]; - } - computed = true; - } - } while (!computed); - } - return returnValue; -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/RandomPoint.h b/smtk/mesh/moab/RandomPoint.h deleted file mode 100644 index 2acc91358864089d6f4439f481d2f83b72e69e9f..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/RandomPoint.h +++ /dev/null @@ -1,51 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_moab_RandomPoint_h -#define smtk_mesh_moab_RandomPoint_h - -#include "smtk/CoreExports.h" - -#include "smtk/geometry/queries/RandomPoint.h" - -#include "smtk/mesh/core/MeshSet.h" - -#include "smtk/resource/Component.h" - -#include - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -/**\brief An API for computing a random point on a geometric resource component. - */ -struct SMTKCORE_EXPORT RandomPoint - : public smtk::resource::query::DerivedFrom -{ - RandomPoint() = default; - - std::array operator()(const smtk::resource::Component::Ptr&) const override; - - std::array operator()(const smtk::mesh::MeshSet&) const; - - void seed(std::size_t seed) override { m_seed = seed; } - -private: - std::size_t m_seed{ 0 }; -}; -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/Readers.cxx b/smtk/mesh/moab/Readers.cxx deleted file mode 100644 index 5cdbee773d0655b3dacdea5791ef6a89ee9a7d88..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/Readers.cxx +++ /dev/null @@ -1,222 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/mesh/moab/Readers.h" -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/Core.hpp" -#include "moab/FileOptions.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -namespace -{ - -smtk::mesh::ResourcePtr verifyAndMake(const smtk::mesh::moab::InterfacePtr interface) -{ - if (!interface) - { - //create an invalid colection (i.e. one with an invalid id) - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(); - resource->setId(smtk::common::UUID::null()); - return resource; - } - //make a moab specific mesh resource - return smtk::mesh::Resource::create(interface); -} - -template -bool is_valid(const T& t) -{ - return (!!t && t->isValid()); -} - -bool moab_load( - const smtk::mesh::moab::InterfacePtr& interface, - const std::string& path, - const char* subset_name_to_load) -{ - //currently the moab::interface doesn't allow loading a subset of a file - //if you don't know any tag values. Our current workaround is to cast - //to a Core and query for all the tag values, and pass those as the - //ones we want to load. If we get back no tag values and we wanted - //to load a subset we fail. - ::moab::Interface* m_iface = interface->moabInterface(); - ::moab::Core* core = dynamic_cast<::moab::Core*>(m_iface); - if (!core) - { - return false; - } - - //when we have no subset to load tag_values is empty and - //dereferencing an empty std::vector is undefined behavior - std::vector tag_values; - int* tag_values_ptr = nullptr; - int num_tag_values = 0; - - //if we have a have subset to load, we need to consider have zero values - //for that tag to be a failure to load, and not to load in the entire file - if (subset_name_to_load) - { - ::moab::ErrorCode tag_err = core->serial_read_tag( - path.c_str(), - subset_name_to_load, - nullptr, //options - tag_values); - - //this file has no mesh sets that match the given tag so we should - //fail as trying to load now will bring in the entire mesh, which is wrong - if (tag_err != ::moab::MB_SUCCESS || tag_values.empty()) - { - return false; - } - - tag_values_ptr = tag_values.data(); - num_tag_values = static_cast(tag_values.size()); - } - - ::moab::ErrorCode err = m_iface->load_file( - path.c_str(), - nullptr, //file set to append to - nullptr, //options - subset_name_to_load, - tag_values_ptr, - num_tag_values); -#ifndef NDEBUG - if (err != ::moab::MB_SUCCESS) - { - std::string msg; - m_iface->get_last_error(msg); - std::cerr << msg << std::endl; - std::cerr << "failed to load file: " << path << std::endl; - } -#endif - - //moab has a concept of "reverse meshes" that are mesh sets that span the same - //cells and points as an extant mesh set, but are tagged by "NEUSET_SENSE". - //In smtk we handle this concept at the model level, so we filter out meshsets - // of this type here. - { - ::moab::Range sense_sets; - ::moab::Tag sense_tag; - m_iface->tag_get_handle("NEUSET_SENSE", 1, ::moab::MB_TYPE_INTEGER, sense_tag); - m_iface->get_entities_by_type_and_tag( - 0, ::moab::MBENTITYSET, &sense_tag, nullptr, 1, sense_sets, ::moab::Interface::UNION); - m_iface->delete_entities(sense_sets); - } - - const bool readFromDisk = (err == ::moab::MB_SUCCESS); - if (readFromDisk) - { //if we are loaded from file, we clear the modified flag - interface->setModifiedState(false); - } - - return err == ::moab::MB_SUCCESS; -} - -//requires that interface is not a null shared ptr -smtk::mesh::moab::InterfacePtr load_file( - smtk::mesh::moab::InterfacePtr interface, - const std::string& path, - const char* tag_name = nullptr) -{ - const bool loaded = moab_load(interface, path, tag_name); - if (!loaded) - { - //if we have gotten to here we failed to load so we need to return a - //null shared_ptr to mark this as failed - interface.reset(); - } - return interface; -} - -//requires that interface is not a null shared ptr -bool append_file( - const smtk::mesh::moab::InterfacePtr& interface, - const std::string& path, - const char* tag_name = nullptr) -{ - return moab_load(interface, path, tag_name); -} -} // namespace - -//construct an interface to a given file. will load all meshes inside the -//file -smtk::mesh::ResourcePtr read(const std::string& path) -{ - return verifyAndMake(load_file(smtk::mesh::moab::make_interface(), path)); -} - -//construct an interface to a given file. will load all meshes inside the -//file -smtk::mesh::ResourcePtr read_domain(const std::string& path) -{ - const std::string tag("MATERIAL_SET"); - return verifyAndMake(load_file(smtk::mesh::moab::make_interface(), path, tag.c_str())); -} - -//construct an interface to a given file. will load all meshes inside the -//file -smtk::mesh::ResourcePtr read_neumann(const std::string& path) -{ - //Core is a fully implemented moab::Interface - const std::string tag("NEUMANN_SET"); - return verifyAndMake(load_file(smtk::mesh::moab::make_interface(), path, tag.c_str())); -} - -//construct an interface to a given file. will load all meshes inside the -//file -smtk::mesh::ResourcePtr read_dirichlet(const std::string& path) -{ - const std::string tag("DIRICHLET_SET"); - return verifyAndMake(load_file(smtk::mesh::moab::make_interface(), path, tag.c_str())); -} - -//Import everything in a file into an existing resource -bool import(const std::string& path, const smtk::mesh::ResourcePtr& c) -{ - return is_valid(c) && append_file(smtk::mesh::moab::extract_interface(c), path); -} - -//Import all the domain sets in a file into an existing resource -bool import_domain(const std::string& path, const smtk::mesh::ResourcePtr& c) -{ - const std::string tag("MATERIAL_SET"); - return is_valid(c) && append_file(smtk::mesh::moab::extract_interface(c), path, tag.c_str()); -} - -//Import all the neumann sets in a file into an existing resource -bool import_neumann(const std::string& path, const smtk::mesh::ResourcePtr& c) -{ - const std::string tag("NEUMANN_SET"); - return is_valid(c) && append_file(smtk::mesh::moab::extract_interface(c), path, tag.c_str()); -} - -//Import all the dirichlet sets in a file into an existing resource -bool import_dirichlet(const std::string& path, const smtk::mesh::ResourcePtr& c) -{ - const std::string tag("DIRICHLET_SET"); - return is_valid(c) && append_file(smtk::mesh::moab::extract_interface(c), path, tag.c_str()); -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/Readers.h b/smtk/mesh/moab/Readers.h deleted file mode 100644 index 3c408e8c09cbde86ae35207f53c2db801a47c5c8..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/Readers.h +++ /dev/null @@ -1,59 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#ifndef smtk_mesh_moab_Readers_h -#define smtk_mesh_moab_Readers_h - -#include "smtk/PublicPointerDefs.h" - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -//construct an interface to a given file. will load all meshes inside the -//file. If the file given fails to load we will return a invalid resource -smtk::mesh::ResourcePtr read(const std::string& path); - -//construct an interface to a given file. will load only meshes which are in -//the material set. -//file. If the file given fails to load we will return a invalid resource -smtk::mesh::ResourcePtr read_domain(const std::string& path); - -//construct an interface to a given file. will load only meshes which are in -//the neumann set. -//file. If the file given fails to load we will return a invalid resource -smtk::mesh::ResourcePtr read_neumann(const std::string& path); - -//construct an interface to a given file. will load only meshes which are in -//the dirichlet set. -//file. If the file given fails to load we will return a invalid resource -smtk::mesh::ResourcePtr read_dirichlet(const std::string& path); - -//Import everything in a file into an existing resource. -bool import(const std::string& path, const smtk::mesh::ResourcePtr& resource); - -//Import all the material sets in a file into an existing resource -bool import_domain(const std::string& path, const smtk::mesh::ResourcePtr& resource); - -//Import all the neumann sets in a file into an existing resource -bool import_neumann(const std::string& path, const smtk::mesh::ResourcePtr& resource); - -//Import all the dirichlet sets in a file into an existing resource -bool import_dirichlet(const std::string& path, const smtk::mesh::ResourcePtr& resource); -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/Tags.h b/smtk/mesh/moab/Tags.h deleted file mode 100644 index 8e09221c677f9ae4f93431dd13499c6b40a772b3..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/Tags.h +++ /dev/null @@ -1,354 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#ifndef smtk_mesh_moab_Tags_h -#define smtk_mesh_moab_Tags_h - -#ifndef BEING_INCLUDED_BY_INTERFACE_CXX -#error This file can only be included by smtk::mesh::moab::Interface -#endif - -#include "smtk/common/UUID.h" - -#include "MBTagConventions.hpp" - -#include // for memcpy (opaque tags) - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ -namespace tag -{ - -//these classes should only be included by Interface.cxx - -class QueryNameTag -{ - ::moab::Interface* m_iface; - ::moab::Tag m_tag; - char m_tagData[32]; //same length as NAME_TAG_SIZE -public: -//disable warning about elements of array 'm_tagData' will be default initialized -//this is only a warning on msvc, since previously it was broken and wouldn't -//default initialize member arrays -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4351) -#endif - QueryNameTag(::moab::Interface* iface) - : m_iface(iface) - { - //populate our tag - m_iface->tag_get_handle( - NAME_TAG_NAME, - NAME_TAG_SIZE, - ::moab::MB_TYPE_OPAQUE, - m_tag, - ::moab::MB_TAG_SPARSE | ::moab::MB_TAG_CREAT); - } -//reset our warnings to the original level -#ifdef _MSC_VER -#pragma warning(pop) -#endif - - bool fetch_name(const smtk::mesh::Handle& entity) - { - if (!m_tag) - { - return false; - } - - ::moab::ErrorCode rval = m_iface->tag_get_data(m_tag, &entity, 1, &m_tagData); - return (rval == ::moab::MB_SUCCESS); - } - - bool set_name(const smtk::mesh::Handle& entity, const std::string& name) - { - if (!m_tag) - { - return false; - } - - strcpy(m_tagData, name.substr(0, 32).c_str()); - - ::moab::ErrorCode rval = m_iface->tag_set_data(m_tag, &entity, 1, &m_tagData); - return (rval == ::moab::MB_SUCCESS); - } - - const char* current_name() const { return m_tagData; } -}; - -class QueryIntTag -{ - ::moab::Interface* m_iface; - ::moab::TagInfo* m_tag; - std::string m_tag_name; - int m_value; - void const* tag_v_ptr; - -public: - QueryIntTag(const char* name, int value, ::moab::Interface* iface) - { - m_iface = iface; - m_tag_name = std::string(name); - m_value = value; - - //populate our tag - ::moab::Tag moab_tag; - m_iface->tag_get_handle(m_tag_name.c_str(), 1, ::moab::MB_TYPE_INTEGER, moab_tag); - - m_tag = moab_tag; - //get the memory location of m_value - this->tag_v_ptr = &m_value; - } - - ::moab::TagInfo* moabTag() { return m_tag; } - - ::moab::TagInfo* const* moabTagPtr() { return &m_tag; } - const void* const* moabTagValuePtr() const { return &this->tag_v_ptr; } - - int size() const { return 1; } - int value() const { return m_value; } -}; - -class QueryMaterialTag : public QueryIntTag -{ -public: - QueryMaterialTag(int v, ::moab::Interface* iface) - : QueryIntTag("MATERIAL_SET", v, iface) - { - } -}; - -class QueryDirichletTag : public QueryIntTag -{ -public: - QueryDirichletTag(int v, ::moab::Interface* iface) - : QueryIntTag("DIRICHLET_SET", v, iface) - { - } -}; - -class QueryNeumannTag : public QueryIntTag -{ -public: - QueryNeumannTag(int v, ::moab::Interface* iface) - : QueryIntTag("NEUMANN_SET", v, iface) - { - } -}; - -class QueryDimTag : public QueryIntTag -{ -public: - QueryDimTag(int v, ::moab::Interface* iface) - : QueryIntTag("GEOM_DIMENSION", v, iface) - { - } -}; - -/// A base class for queries on tags that store opaque data values. -template -class QueryOpaqueTag -{ - ::moab::Interface* m_iface; - ::moab::TagInfo* m_tag; - std::string m_tag_name; - char m_value[Sz]; - void const* tag_v_ptr; - -public: - QueryOpaqueTag(const char* name, const char* value, ::moab::Interface* iface) - { - m_iface = iface; - m_tag_name = std::string(name); - memcpy(m_value, value, Sz); - - //populate our tag - ::moab::Tag moab_tag; - m_iface->tag_get_handle( - m_tag_name.c_str(), - Sz, - ::moab::MB_TYPE_OPAQUE, - moab_tag, - ::moab::MB_TAG_BYTES | ::moab::MB_TAG_CREAT | ::moab::MB_TAG_SPARSE); - - m_tag = moab_tag; - //get the memory location of m_value - this->tag_v_ptr = &m_value; - } - - ::moab::TagInfo* moabTag() { return m_tag; } - - ::moab::TagInfo* const* moabTagPtr() { return &m_tag; } - const void* const* moabTagValuePtr() const { return &this->tag_v_ptr; } - - int size() const { return Sz; } - const char* value() const { return m_value; } -}; - -class QueryIdTag : public QueryOpaqueTag -{ -public: - QueryIdTag(::moab::Interface* iface) - : QueryOpaqueTag("ID", reinterpret_cast(smtk::common::UUID::null().begin()), iface) - { - } - QueryIdTag(const smtk::common::UUID& v, ::moab::Interface* iface) - : QueryOpaqueTag("ID", reinterpret_cast(v.begin()), iface) - { - } - smtk::common::UUID uuid() const - { - return smtk::common::UUID( - reinterpret_cast(this->value()), - reinterpret_cast(this->value()) + smtk::common::UUID::SIZE); - } -}; - -class QueryEntRefTag : public QueryOpaqueTag -{ -public: - QueryEntRefTag(::moab::Interface* iface) - : QueryOpaqueTag( - "ENT_REF", - reinterpret_cast(smtk::common::UUID::null().begin()), - iface) - { - } - QueryEntRefTag(const smtk::common::UUID& v, ::moab::Interface* iface) - : QueryOpaqueTag("ENT_REF", reinterpret_cast(v.begin()), iface) - { - } - smtk::common::UUID uuid() const - { - return smtk::common::UUID( - reinterpret_cast(this->value()), - reinterpret_cast(this->value()) + smtk::common::UUID::SIZE); - } -}; - -class QueryRootModelEntTag : public QueryOpaqueTag -{ -public: - QueryRootModelEntTag(::moab::Interface* iface) - : QueryOpaqueTag( - "ROOT_MODEL_ENT", - reinterpret_cast(smtk::common::UUID::null().begin()), - iface) - { - } - QueryRootModelEntTag(const smtk::common::UUID& v, ::moab::Interface* iface) - : QueryOpaqueTag("ROOT_MODEL_ENT", reinterpret_cast(v.begin()), iface) - { - } - smtk::common::UUID uuid() const - { - return smtk::common::UUID( - reinterpret_cast(this->value()), - reinterpret_cast(this->value()) + smtk::common::UUID::SIZE); - } -}; - -class QueryBitTag -{ - ::moab::Interface* m_iface; - ::moab::TagInfo* m_tag; - std::string m_tag_name; - -public: - QueryBitTag(const char* name, ::moab::Interface* iface) - { - m_iface = iface; - m_tag_name = std::string(name); - - //populate our tag - ::moab::Tag moab_tag; - m_iface->tag_get_handle( - m_tag_name.c_str(), - 1, - ::moab::MB_TYPE_BIT, - moab_tag, - ::moab::MB_TAG_BYTES | ::moab::MB_TAG_CREAT | ::moab::MB_TAG_SPARSE); - - m_tag = moab_tag; - } - - ::moab::TagInfo* moabTag() { return m_tag; } - - ::moab::TagInfo* const* moabTagPtr() { return &m_tag; } - - int size() const { return 1; } -}; - -class QueryCellFieldTag : public QueryBitTag -{ -public: - QueryCellFieldTag(const char* name, ::moab::Interface* iface) - : QueryBitTag(std::string(std::string("c_") + std::string(name)).c_str(), iface) - { - } -}; - -class QueryPointFieldTag : public QueryBitTag -{ -public: - QueryPointFieldTag(const char* name, ::moab::Interface* iface) - : QueryBitTag(std::string(std::string("p_") + std::string(name)).c_str(), iface) - { - } -}; - -class QueryFieldTag -{ - ::moab::Interface* m_iface; - ::moab::TagInfo* m_tag; - ::moab::ErrorCode m_state; - std::string m_tag_name; - int m_size; - ::moab::DataType m_type; - -public: - QueryFieldTag(const char* name, int size, ::moab::DataType type, ::moab::Interface* iface) - { - m_iface = iface; - m_tag_name = std::string(name) + std::string("_"); - m_size = size; - m_type = type; - - //populate our tag - ::moab::Tag moab_tag; - m_state = m_iface->tag_get_handle( - m_tag_name.c_str(), m_size, m_type, moab_tag, ::moab::MB_TAG_CREAT | ::moab::MB_TAG_DENSE); - m_tag = moab_tag; - } - - ::moab::TagInfo* moabTag() { return m_tag; } - - ::moab::TagInfo* const* moabTagPtr() { return &m_tag; } - - ::moab::ErrorCode state() { return m_state; } - - int size() const { return m_size; } - - ::moab::DataType type() const { return m_type; } -}; - -} // namespace tag -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/moab/Writers.cxx b/smtk/mesh/moab/Writers.cxx deleted file mode 100644 index bef6d1730710b4653f2e5b65857646456bb8ea05..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/Writers.cxx +++ /dev/null @@ -1,152 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/mesh/moab/Writers.h" -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/core/Resource.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "moab/Interface.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -namespace -{ -template -bool is_valid(const T& t) -{ - return (!!t && t->isValid()); -} - -bool moab_write( - const smtk::mesh::moab::InterfacePtr& interface, - const std::string& path, - const char* subset_name_to_write) -{ - ::moab::Interface* m_iface = interface->moabInterface(); - ::moab::ErrorCode err = ::moab::MB_FAILURE; - - if (subset_name_to_write) - { - //if we are writing out a subset we first need to find the model - //entities with the given tag - ::moab::Tag subsetTag; - //all our tags are a single integer value - m_iface->tag_get_handle(subset_name_to_write, 1, ::moab::MB_TYPE_INTEGER, subsetTag); - - ::moab::Range setsToSave; - m_iface->get_entities_by_type_and_tag( - m_iface->get_root_set(), - ::moab::MBENTITYSET, - &subsetTag, - nullptr, - 1, - setsToSave, - ::moab::Interface::UNION); - - if (setsToSave.empty()) - { -#ifndef NDEBUG - std::cerr << "failed to write file: " << path - << " no entities with tag: " << subset_name_to_write << std::endl; -#endif - return false; - } - - ::moab::Range entsToSave; - for (::moab::Range::const_iterator i = setsToSave.begin(); i != setsToSave.end(); ++i) - { - m_iface->get_entities_by_handle(*i, entsToSave); - } - - ::moab::Range entitiesToSave = setsToSave; - entitiesToSave.merge(entsToSave); - entitiesToSave.insert(0); - - //write out just the subset. We let the file extension the user specified - //determine what writer to use. - err = m_iface->write_file( - path.c_str(), - nullptr, //explicit writer type - nullptr, //options - entitiesToSave); - } - else - { - //write out everything. We let the file extension the user specified - //determine what writer to use. - err = m_iface->write_file(path.c_str()); - } - -#ifndef NDEBUG - if (err != ::moab::MB_SUCCESS) - { - std::string msg; - m_iface->get_last_error(msg); - std::cerr << msg << std::endl; - std::cerr << "failed to write file: " << path << std::endl; - } -#endif - - const bool written = (err == ::moab::MB_SUCCESS); - if (written) - { //if we have written to file, we clear the modified flag - interface->setModifiedState(false); - } - return written; -} - -//requires that interface is not a null shared ptr -bool write_file( - const smtk::mesh::moab::InterfacePtr& interface, - const std::string& path, - const char* tag_name = nullptr) -{ //tag_name which is nullptr loads in all meshes - return moab_write(interface, path, tag_name); -} -} // namespace - -//Write everything in a file into an existing resource. -bool write(const std::string& path, const smtk::mesh::ResourcePtr& r) -{ - return is_valid(r) && write_file(smtk::mesh::moab::extract_interface(r), path); -} - -//Write all the domain sets in a file into an existing resource -bool write_domain(const std::string& path, const smtk::mesh::ResourcePtr& r) -{ - const std::string tag("MATERIAL_SET"); - return is_valid(r) && write_file(smtk::mesh::moab::extract_interface(r), path, tag.c_str()); -} - -//Write all the neumann sets in a file into an existing resource -bool write_neumann(const std::string& path, const smtk::mesh::ResourcePtr& r) -{ - const std::string tag("NEUMANN_SET"); - return is_valid(r) && write_file(smtk::mesh::moab::extract_interface(r), path, tag.c_str()); -} - -//Write all the dirichlet sets in a file into an existing resource -bool write_dirichlet(const std::string& path, const smtk::mesh::ResourcePtr& r) -{ - const std::string tag("DIRICHLET_SET"); - return is_valid(r) && write_file(smtk::mesh::moab::extract_interface(r), path, tag.c_str()); -} -} // namespace moab -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/moab/Writers.h b/smtk/mesh/moab/Writers.h deleted file mode 100644 index f5d22e08d6cf0046f6d4f64531fc87503cde0b37..0000000000000000000000000000000000000000 --- a/smtk/mesh/moab/Writers.h +++ /dev/null @@ -1,40 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#ifndef smtk_mesh_moab_Writers_h -#define smtk_mesh_moab_Writers_h - -#include "smtk/PublicPointerDefs.h" - -namespace smtk -{ -namespace mesh -{ -namespace moab -{ - -//Write everything in a file into an existing resource. -bool write(const std::string& path, const smtk::mesh::ResourcePtr& c); - -//Write all the domain sets in a file into an existing resource -bool write_domain(const std::string& path, const smtk::mesh::ResourcePtr& c); - -//Write all the neumann sets in a file into an existing resource -bool write_neumann(const std::string& path, const smtk::mesh::ResourcePtr& c); - -//Write all the dirichlet sets in a file into an existing resource -bool write_dirichlet(const std::string& path, const smtk::mesh::ResourcePtr& c); -} // namespace moab -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/operators/DeleteMesh.cxx b/smtk/mesh/operators/DeleteMesh.cxx deleted file mode 100644 index 7a6f98adee984a8e8aa2f2d28e01fdb02d248c2c..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/DeleteMesh.cxx +++ /dev/null @@ -1,76 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/operators/DeleteMesh.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/Session.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/IntItem.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/mesh/operators/DeleteMesh_xml.h" - -namespace smtk -{ -namespace mesh -{ - -DeleteMesh::DeleteMesh() = default; - -smtk::mesh::DeleteMesh::Result DeleteMesh::operateInternal() -{ - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - bool allRemoved = true; - for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) - { - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); - smtk::mesh::MeshSet meshset = meshComponent->mesh(); - bool removed = meshset.resource()->removeMeshes(meshset); - - if (removed) - { - result->findComponent("expunged")->appendValue(meshComponent); - smtk::operation::MarkGeometry().erase(meshComponent); - } - - allRemoved &= removed; - } - - if (!allRemoved) - { - result->findInt("outcome")->setValue( - 0, static_cast(smtk::operation::Operation::Outcome::FAILED)); - } - return result; -} - -const char* DeleteMesh::xmlDescription() const -{ - return DeleteMesh_xml; -} - -void DeleteMesh::generateSummary(smtk::operation::Operation::Result& result) -{ - if (!m_suppressOutput) - { - smtk::operation::Operation::generateSummary(result); - } -} - -} //namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/DeleteMesh.h b/smtk/mesh/operators/DeleteMesh.h deleted file mode 100644 index a8fcd8055ecbc53ddb5f784aac15463bf9a4edff..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/DeleteMesh.h +++ /dev/null @@ -1,45 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_DeleteMesh_h -#define smtk_mesh_DeleteMesh_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Delete a mesh. - */ -class SMTKCORE_EXPORT DeleteMesh : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::DeleteMesh); - smtkCreateMacro(DeleteMesh); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - - void suppressOutput(bool choice) { m_suppressOutput = choice; } - -protected: - DeleteMesh(); - Result operateInternal() override; - const char* xmlDescription() const override; - - void generateSummary(smtk::operation::Operation::Result&) override; - - bool m_suppressOutput{ false }; -}; - -} //namespace mesh -} // namespace smtk - -#endif // smtk_mesh_DeleteMesh_h diff --git a/smtk/mesh/operators/DeleteMesh.sbt b/smtk/mesh/operators/DeleteMesh.sbt deleted file mode 100644 index 18d8806dcdce1a384e8ac441613939ee4330b0e4..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/DeleteMesh.sbt +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - Remove a mesh from the model instance. - - - <p>Remove a mesh from the model instance. - <p>This operator removes meshes from the application's - memory. It does not remove meshes from disk. - - - - - - - - - - diff --git a/smtk/mesh/operators/ElevateMesh.cxx b/smtk/mesh/operators/ElevateMesh.cxx deleted file mode 100644 index 7c34ccdb3a5de978313b48fc910f743b29742ee0..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ElevateMesh.cxx +++ /dev/null @@ -1,404 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/ElevateMesh.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ReferenceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/interpolation/InverseDistanceWeighting.h" -#include "smtk/mesh/interpolation/PointCloud.h" -#include "smtk/mesh/interpolation/PointCloudGenerator.h" -#include "smtk/mesh/interpolation/RadialAverage.h" -#include "smtk/mesh/interpolation/StructuredGrid.h" -#include "smtk/mesh/interpolation/StructuredGridGenerator.h" - -#include "smtk/mesh/operators/ElevateMesh_xml.h" -#include "smtk/mesh/utility/ApplyToMesh.h" - -#include "smtk/model/AuxiliaryGeometry.h" -#include "smtk/model/Resource.h" -#include "smtk/model/Session.h" - -#include "smtk/operation/MarkGeometry.h" - -#include -#include -#include -#include -#include -#include - -namespace -{ -template -std::function)> radialAverageFrom( - const InputType& input, - double radius, - const std::function& prefilter, - const smtk::mesh::InterfacePtr& interface) -{ - std::function)> radialAverage; - { - // Let's start by trying to make a structured grid, since they can be a - // subset of point clouds. - smtk::mesh::StructuredGridGenerator sgg; - smtk::mesh::StructuredGrid structuredgrid = sgg(input); - if (structuredgrid.size() > 0) - { - radialAverage = smtk::mesh::RadialAverage(structuredgrid, radius, prefilter); - } - } - - if (!radialAverage) - { - // Next, we try to make a point cloud from our data. - smtk::mesh::PointCloudGenerator pcg; - smtk::mesh::PointCloud pointcloud = pcg(input); - if (pointcloud.size() > 0) - { - radialAverage = smtk::mesh::RadialAverage( - smtk::mesh::Resource::create(interface), pointcloud, radius, prefilter); - } - } - - return radialAverage; -} - -template -std::function)> inverseDistanceWeightingFrom( - const InputType& input, - double power, - const std::function& prefilter) -{ - std::function)> idw; - { - // Let's start by trying to make a structured grid, since they can be a - // subset of point clouds. - smtk::mesh::StructuredGridGenerator sgg; - smtk::mesh::StructuredGrid structuredgrid = sgg(input); - if (structuredgrid.size() > 0) - { - idw = smtk::mesh::InverseDistanceWeighting(structuredgrid, power, prefilter); - } - } - - if (!idw) - { - // Next, we try to make a point cloud from our data. - smtk::mesh::PointCloudGenerator pcg; - smtk::mesh::PointCloud pointcloud = pcg(input); - if (pointcloud.size() > 0) - { - idw = smtk::mesh::InverseDistanceWeighting(pointcloud, power, prefilter); - } - } - - return idw; -} -} // namespace - -namespace smtk -{ -namespace mesh -{ - -bool ElevateMesh::ableToOperate() -{ - return this->Superclass::ableToOperate(); -} - -ElevateMesh::Result ElevateMesh::operateInternal() -{ - // Access the string describing the input data type - smtk::attribute::StringItem::Ptr inputDataItem = this->parameters()->findString("input data"); - - // Access the mesh to elevate - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - smtk::mesh::MeshSet meshset = meshItem->valueAs()->mesh(); - const smtk::mesh::Resource::Ptr& resource = meshset.resource(); - - // Access the string describing the interpolation scheme - smtk::attribute::StringItem::Ptr interpolationSchemeItem = - this->parameters()->findString("interpolation scheme"); - - // Access the radius parameter - smtk::attribute::DoubleItem::Ptr radiusItem = this->parameters()->findDouble("radius"); - - // Access the string describing external point treatment - smtk::attribute::StringItem::Ptr externalPointItem = - this->parameters()->findString("external point values"); - - // Access the power parameter - smtk::attribute::DoubleItem::Ptr powerItem = this->parameters()->findDouble("power"); - - // Construct a prefilter for the input data - std::function prefilter = [](double /*unused*/) { return true; }; - { - // Access the input filter parameter group - smtk::attribute::GroupItem::Ptr inputFilterItem = this->parameters()->findGroup("input filter"); - - if (inputFilterItem) - { - // Access the min threshold parameter - smtk::attribute::DoubleItem::Ptr minThresholdItem = - inputFilterItem->findAs("min threshold"); - - // Access the max threshold parameter - smtk::attribute::DoubleItem::Ptr maxThresholdItem = - inputFilterItem->findAs("max threshold"); - - if ( - minThresholdItem && minThresholdItem->isEnabled() && maxThresholdItem && - maxThresholdItem->isEnabled()) - { - double minThreshold = minThresholdItem->value(); - double maxThreshold = maxThresholdItem->value(); - prefilter = [=](double d) { return d >= minThreshold && d <= maxThreshold; }; - } - else if (minThresholdItem && minThresholdItem->isEnabled()) - { - double minThreshold = minThresholdItem->value(); - prefilter = [=](double d) { return d >= minThreshold; }; - } - else if (maxThresholdItem && maxThresholdItem->isEnabled()) - { - double maxThreshold = maxThresholdItem->value(); - prefilter = [=](double d) { return d <= maxThreshold; }; - } - } - } - - // Construct a function that takes an input point and returns a value - // according to the average of the locus of points in the external data that, - // when projected onto the x-y plane, are within a radius of the input - std::function)> interpolation; - - if (inputDataItem->value() == "auxiliary geometry") - { - // Access the external data to use in determining elevation values - auto auxGeoItem = this->parameters()->findComponent("auxiliary geometry"); - - // Get the auxiliary geometry - smtk::model::AuxiliaryGeometry auxGeo = auxGeoItem->valueAs(); - - if (interpolationSchemeItem->value() == "radial average") - { - // Compute the radial average function - interpolation = radialAverageFrom( - auxGeo, radiusItem->value(), prefilter, resource->interface()); - } - else if (interpolationSchemeItem->value() == "inverse distance weighting") - { - // Compute the inverse distance weighting function - interpolation = inverseDistanceWeightingFrom( - auxGeo, powerItem->value(), prefilter); - } - - if (!interpolation) - { - smtkErrorMacro(this->log(), "Could not convert auxiliary geometry."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - else if (inputDataItem->value() == "ptsfile") - { - // Get the file name - std::string fileName = this->parameters()->findFile("ptsfile")->value(); - - if (interpolationSchemeItem->value() == "radial average") - { - // Compute the radial average function - interpolation = radialAverageFrom( - fileName, radiusItem->value(), prefilter, resource->interface()); - } - else if (interpolationSchemeItem->value() == "inverse distance weighting") - { - // Compute the inverse distance weighting function - interpolation = - inverseDistanceWeightingFrom(fileName, powerItem->value(), prefilter); - } - - if (!interpolation) - { - smtkErrorMacro(this->log(), "Could not read file."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - else if (inputDataItem->value() == "points") - { - // Access the interpolation points - smtk::attribute::GroupItem::Ptr interpolationPointsItem = - this->parameters()->findGroup("points"); - - // Construct containers for our source points - std::vector sourceCoordinates; - std::vector sourceValues; - - for (std::size_t i = 0; i < interpolationPointsItem->numberOfGroups(); i++) - { - smtk::attribute::DoubleItemPtr pointItem = - smtk::dynamic_pointer_cast( - interpolationPointsItem->item(i, 0)); - for (std::size_t j = 0; j < 3; j++) - { - sourceCoordinates.push_back(pointItem->value(j)); - } - sourceValues.push_back(pointItem->value(3)); - } - - smtk::mesh::PointCloud pointcloud(std::move(sourceCoordinates), std::move(sourceValues)); - - if (interpolationSchemeItem->value() == "radial average") - { - interpolation = smtk::mesh::RadialAverage( - smtk::mesh::Resource::create(resource->interface()), pointcloud, radiusItem->value()); - } - else if (interpolationSchemeItem->value() == "inverse distance weighting") - { - // Compute the inverse distance weighting function - interpolation = smtk::mesh::InverseDistanceWeighting(pointcloud, powerItem->value()); - } - - if (!interpolation) - { - smtkErrorMacro(this->log(), "Could not read points."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - else - { - smtkErrorMacro(this->log(), "Unrecognized input type."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Construct a function that clips its input according to the input parameters - std::function postProcess = [](double input) { return input; }; - { - // Access the output filter parameter group - smtk::attribute::GroupItem::Ptr outputFilterItem = - this->parameters()->findGroup("output filter"); - - if (outputFilterItem) - { - // Access the min elevation parameter - smtk::attribute::DoubleItem::Ptr minElevationItem = - outputFilterItem->findAs("min elevation"); - - // Access the max elevation parameter - smtk::attribute::DoubleItem::Ptr maxElevationItem = - outputFilterItem->findAs("max elevation"); - - if ( - minElevationItem && minElevationItem->isEnabled() && maxElevationItem && - maxElevationItem->isEnabled()) - { - double minElevation = minElevationItem->value(); - double maxElevation = maxElevationItem->value(); - postProcess = [=](double input) { - return ( - input < minElevation ? minElevation : (input > maxElevation ? maxElevation : input)); - }; - } - else if (minElevationItem && minElevationItem->isEnabled()) - { - double minElevation = minElevationItem->value(); - postProcess = [=](double input) { return (input < minElevation ? minElevation : input); }; - } - else if (maxElevationItem && maxElevationItem->isEnabled()) - { - double maxElevation = maxElevationItem->value(); - postProcess = [=](double input) { return (input > maxElevation ? maxElevation : input); }; - } - } - } - - // Add a conditional function for dealing with points that were rejected by the interpolator. - std::function)> externalDataPoint = [](std::array xyz) { - return xyz[2]; - }; - if (interpolationSchemeItem->value() == "radial average") - { - if (externalPointItem->value() == "set to NaN") - { - externalDataPoint = [](std::array /*unused*/) { - return std::numeric_limits::quiet_NaN(); - }; - } - else if (externalPointItem->value() == "set to value") - { - double externalPointValue = this->parameters()->findDouble("external point value")->value(); - externalDataPoint = [=](std::array /*unused*/) { return externalPointValue; }; - } - } - - // Combine the radial average function with the elevation clipping function. - std::function(std::array)> fn = [&](std::array x) { - double z = postProcess(interpolation(x)); - if (std::isnan(z)) - { - z = externalDataPoint(x); - } - - return std::array({ { x[0], x[1], z } }); - }; - - // Access the attribute associated with the modified meshes - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with the modified model - smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); - - // Mark the modified mesh components to update their representative geometry - smtk::operation::MarkGeometry markGeometry(resource); - - // apply the interpolator to the meshes and populate the result attributes - for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) - { - auto meshComponent = meshItem->valueAs(i); - auto mesh = meshComponent->mesh(); - - smtk::mesh::utility::applyWarp(fn, mesh, true); - - modified->appendValue(meshComponent); - markGeometry.markModified(meshComponent); - - smtk::model::EntityRefArray entities; - bool entitiesAreValid = mesh.modelEntities(entities); - if (entitiesAreValid && !entities.empty()) - { - smtk::model::Model model = entities[0].owningModel(); - modified->appendValue(model.component()); - smtk::operation::MarkGeometry().markModified(model.component()); - } - } - - return result; -} - -const char* ElevateMesh::xmlDescription() const -{ - return ElevateMesh_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/ElevateMesh.h b/smtk/mesh/operators/ElevateMesh.h deleted file mode 100644 index 5c080c97c5fea5cf63298f6a4d99e98112e189d6..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ElevateMesh.h +++ /dev/null @@ -1,46 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_operators_ElevateMesh_h -#define smtk_mesh_operators_ElevateMesh_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief A class for modifying the z-coordinates of a mesh's nodes according - to an interpolated data set. - - Given a data set of either structured or unstructured data, an interpolation - scheme and input mesh, the z-coordinate of each point in the input mesh is - set to the interpolated values in the external data set. The resulting mesh - deformation can be undone by subsequently applying the "Undo Elevate" filter, - returning the mesh nodes to their original positions. - */ -class SMTKCORE_EXPORT ElevateMesh : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::ElevateMesh); - smtkCreateMacro(ElevateMesh); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace smtk - -#endif // smtk_mesh_operators_ElevateMesh_h diff --git a/smtk/mesh/operators/ElevateMesh.sbt b/smtk/mesh/operators/ElevateMesh.sbt deleted file mode 100644 index 425b7723ba3bb6283c13b8c8a8054ff30b8416ae..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ElevateMesh.sbt +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - - - Modify the z-coordinates a mesh's nodes according to an external data set. - - - <p>Modify the z-coordinates a mesh's nodes according to an - external data set. - <p>This operator accepts as input a mesh and an external - data set, and it computes new z-coordinates at each mesh node - as a radial average of the scalar values in the external data set. - - - - - - - - - - - The input data (coordinates and scalar values) to use for elevation. - - An input data set is required to elevate a mesh. It can be - an auxiliary geometry, an input file, or a collection of - coordinates and scalar values. - - - - - - - An external data set whose values determine the mesh nodes' elevations. - - - - - - A file describing a data set whose values determine the mesh nodes' elevations. - - - - - - Input data filter options. - - - Options to filter input data prior to interpolation. - - - - - - Input data less than this value will be ignored. - - - - Input data greater than this value will be ignored. - - - - - - - - The points and their scalar values to interpolate. - - An implicit function is described by interpolating points - and their associated scalar value. - - - - - - - - - - - - - - - - - auxiliary geometry - - auxiliary geometry - input filter - - - - ptsfile - - ptsfile - input filter - - - - points - - points - - - - - - - - The interpolation scheme to apply to the input data - - The scalar values from the input data must be interpolated - onto the nodes of the mesh. Currently, the supported - techniques are Radial Average (unweighted average of all - points within a cylinder of a given radius from a mesh - node) and Inverse Distance Weighting (weighted average of - all the points in the data set according to the distance - between the datapoint and the mesh node). - - - - - - The radius used to identify a point locus for computing elevation. - - The radius used to identify a point locus for computing - elevation. - - For each node in the input mesh, a corresponding point - locus whose positions projected onto the x-y plane are - within a radius of the node is used to compute a new - elevation value. - - When the interpolating data is unstructured, then - it is possible to find a point within the bounding box of the - interpolating data where there are no data points within the search - circle. In that case, the algorithm will return the - External Point Value. - - When the interpolating data is a grid, the query point - is first snapped to the nearest grid point, and the radius is then - used to acquire additional points for averaging. If there are no - points within the search circle, the value associated with the - original point to which the query point was snapped is returned. - - - - - - Treatment for points in the mesh that fall outside of the range of the dataset. - - - Treatment for points in the mesh that fall outside of the - range of the dataset. - - When the interpolating data is unstructured, then - it is possible to find a point within the bounding box of the - interpolating data where there are no data points within the search - circle. In that case, the algorithm will return a value - according to this condition. - - - - - The z-coordinate of every point outside of the data set will be assigned this value - 0. - - - - - - - left unchanged - - - set to value - - external point value - - - - set to NaN - - - - - - - The weighting power used to interpolate source points. - - The weighting power used to interpolate source points. - - The inverse distance value is exponentiated by - this unitless value when computing weighting coefficients. - - 1. - - - - - - - radial average - - radius - external point values - - - - inverse distance weighting - - power - - - - - - - - - Ignore input data that falls outside of a given range. - - - A range (minimum and maximum value) for input scalar - data. Input data values that fall outside of this - range will be omitted from the interpolation calculation. - - - - - - Lower limit to the resulting mesh's elevation range. - 0.0 - - - - Upper limit to the resulting mesh's elevation range. - 0.0 - - - - - - - - - - - - - - - - - - - diff --git a/smtk/mesh/operators/Export.cxx b/smtk/mesh/operators/Export.cxx deleted file mode 100644 index d00146280e250abf10a96732dc69fac92b7ef020..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Export.cxx +++ /dev/null @@ -1,172 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/Export.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/Definition.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/FileItemDefinition.h" -#include "smtk/attribute/Resource.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/ExportMesh.h" -#include "smtk/io/mesh/MeshIO.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/Export_xml.h" - -#include "smtk/model/Resource.h" -#include "smtk/model/Session.h" - -#include -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} -} // namespace - -namespace smtk -{ -namespace mesh -{ - -bool Export::ableToOperate() -{ - return this->Superclass::ableToOperate(); -} - -Export::Result Export::operateInternal() -{ - std::string outputfile = this->parameters()->findFile("filename")->value(); - - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - - // for multiple meshes, we suffix the file name root with ascending integers - std::string root = outputfile.substr(0, outputfile.find_last_of('.')); - std::string ext = outputfile.substr(outputfile.find_last_of('.')); - int index = 0; - - std::vector generatedFiles; - - for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) - { - smtk::mesh::ResourcePtr resource = meshItem->valueAs(i); - bool fileExportSuccess = false; - - if (resource) - { - if (meshItem->numberOfValues() > 1) - { - std::stringstream s; - s << root << "_" << index << ext; - outputfile = s.str(); - } - - smtk::io::ExportMesh exportMesh; - fileExportSuccess = exportMesh(outputfile, resource); - - if (fileExportSuccess) - { - ++index; - generatedFiles.push_back(outputfile); - } - } - - if (!fileExportSuccess) - { - for (auto&& file : generatedFiles) - { - cleanup(file); - } - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - - return this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); -} - -Export::Specification Export::createSpecification() -{ - Specification spec = this->smtk::operation::XMLOperation::createSpecification(); - auto exportDef = spec->findDefinition("export"); - - std::vector fileItemDefinitions; - auto fileItemDefinitionFilter = [](smtk::attribute::FileItemDefinition::Ptr ptr) { - return ptr->name() == "filename"; - }; - exportDef->filterItemDefinitions(fileItemDefinitions, fileItemDefinitionFilter); - - assert(fileItemDefinitions.size() == 1); - - std::stringstream fileFilters; - bool firstFormat = true; - for (auto& ioType : smtk::io::ExportMesh::SupportedIOTypes()) - { - for (const auto& format : ioType->FileFormats()) - { - if (format.CanExport()) - { - if (firstFormat) - { - firstFormat = false; - } - else - { - fileFilters << ";;"; - } - - fileFilters << format.Name << "("; - bool first = true; - for (const auto& ext : format.Extensions) - { - if (first) - { - first = false; - } - else - { - fileFilters << " "; - } - fileFilters << "*" << ext; - } - fileFilters << ")"; - } - } - } - fileItemDefinitions[0]->setFileFilters(fileFilters.str()); - return spec; -} - -const char* Export::xmlDescription() const -{ - return Export_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/Export.h b/smtk/mesh/operators/Export.h deleted file mode 100644 index ef8b51d2e2304b552385a8cbead9f50b1e69688d..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Export.h +++ /dev/null @@ -1,41 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_Export_h -#define smtk_mesh_Export_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief A class for writing meshes to file. - */ -class SMTKCORE_EXPORT Export : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::Export); - smtkCreateMacro(Export); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - Specification createSpecification() override; - const char* xmlDescription() const override; -}; - -} // namespace mesh -} // namespace smtk - -#endif // smtk_mesh_Export_h diff --git a/smtk/mesh/operators/Export.sbt b/smtk/mesh/operators/Export.sbt deleted file mode 100644 index a5c6712beaed9544c0d5157ee061ecfe0cccd702..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Export.sbt +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - Export a mesh to disk. - - - <p>Export a mesh to disk. - <p>This operator creates a file representing the - selected mesh and saves it to disk. The created file is - readable by this application, but the resulting - mesh is not guaranteed to contain all of the information from - the original mesh. - - - - - - - - - - - - - - - diff --git a/smtk/mesh/operators/ExtractAdjacency.cxx b/smtk/mesh/operators/ExtractAdjacency.cxx deleted file mode 100644 index 2e23db7833de3ca6533115da74ea65876338bdff..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ExtractAdjacency.cxx +++ /dev/null @@ -1,95 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/operators/ExtractAdjacency.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/DimensionTypes.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/mesh/operators/ExtractAdjacency_xml.h" - -namespace smtk -{ -namespace mesh -{ - -smtk::mesh::ExtractAdjacency::Result ExtractAdjacency::operateInternal() -{ - // Access the meshset - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(); - smtk::mesh::MeshSet meshset = meshComponent->mesh(); - - // Access the dimension of the requested adjacency mesh - smtk::attribute::StringItem::Ptr nameItem = this->parameters()->findString("dimension"); - smtk::mesh::DimensionType dimension = smtk::mesh::DimensionType_MAX; - if (nameItem->value() == "0") - { - dimension = smtk::mesh::Dims0; - } - else if (nameItem->value() == "1") - { - dimension = smtk::mesh::Dims1; - } - else if (nameItem->value() == "2") - { - dimension = smtk::mesh::Dims2; - } - else if (nameItem->value() == "3") - { - dimension = smtk::mesh::Dims3; - } - - // Extract the adjacency mesh - smtk::mesh::MeshSet adjacencies = meshset.extractAdjacenciesOfDimension(dimension); - - if (adjacencies.is_empty()) - { - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - adjacencies.setName(meshset.name() + " (adjacency)"); - - smtk::mesh::Component::Ptr adjacencyComponent = smtk::mesh::Component::create(adjacencies); - - if (adjacencyComponent == nullptr) - { - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Create a new result - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with modified components - result->findComponent("created")->appendValue(adjacencyComponent); - - // Mark the created component as having a modified geometry so it will be - // propertly rendered - smtk::operation::MarkGeometry().markModified(adjacencyComponent); - - // Return with success - return result; -} - -const char* ExtractAdjacency::xmlDescription() const -{ - return ExtractAdjacency_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/ExtractAdjacency.h b/smtk/mesh/operators/ExtractAdjacency.h deleted file mode 100644 index 8c236beed0aea6abb42bc06d068408c93ed34bb4..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ExtractAdjacency.h +++ /dev/null @@ -1,39 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_ExtractAdjacency_h -#define smtk_mesh_ExtractAdjacency_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Extract a mesh's adjacency mesh. - - The user can select the dimension of the returned adjacency mesh. - */ -class SMTKCORE_EXPORT ExtractAdjacency : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::ExtractAdjacency); - smtkCreateMacro(ExtractAdjacency); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/operators/ExtractAdjacency.sbt b/smtk/mesh/operators/ExtractAdjacency.sbt deleted file mode 100644 index 61acb6364602eee7620756158431abaa89168830..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ExtractAdjacency.sbt +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - Extract a mesh's adjacency mesh. - - - <p>Extract a mesh's adjacency mesh. - <p>The user can select the dimension of the returned adjacency mesh. - - - - - - - - Dimension of the adjacency mesh - - 0 - 1 - 2 - 3 - - - - - - - - - - - - diff --git a/smtk/mesh/operators/ExtractByDihedralAngle.cxx b/smtk/mesh/operators/ExtractByDihedralAngle.cxx deleted file mode 100644 index 3087f5a7b5677811c1669045a5862e932bea3675..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ExtractByDihedralAngle.cxx +++ /dev/null @@ -1,252 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/operators/ExtractByDihedralAngle.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/IntItem.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/mesh/operators/ExtractByDihedralAngle_xml.h" - -#include - -#ifndef M_PI -#define M_PI 3.14159265358979323846264338327950288 -#endif - -namespace smtk -{ -namespace mesh -{ - -namespace -{ -typedef std::unordered_map> NormalsMap; - -// For each cell, compute the cell's normal and add it to the map. -class ComputeNormals : public smtk::mesh::CellForEach -{ -public: - ComputeNormals(NormalsMap& normsMap) - : smtk::mesh::CellForEach(true) - , m_normalsMap(normsMap) - { - } - - std::array unitNormal() - { - const double* p0 = this->coordinates().data(); - const double* p1 = this->coordinates().data() + 3; - const double* p2 = this->coordinates().data() + 6; - - std::array v1 = { p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2] }; - std::array v2 = { p2[0] - p0[0], p2[1] - p0[1], p2[2] - p0[2] }; - - std::array n = { v1[1] * v2[2] - v1[2] * v2[1], - v1[2] * v2[0] - v1[0] * v2[2], - v1[0] * v2[1] - v1[1] * v2[0] }; - - double magnitude = sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); - for (std::size_t i = 0; i < n.size(); i++) - { - n[i] /= magnitude; - } - - return n; - } - - void forCell( - const smtk::mesh::Handle& cellId, - smtk::mesh::CellType /*cellType*/, - int /*numPointIds*/) override - { - m_normalsMap[cellId] = this->unitNormal(); - } - -protected: - NormalsMap& m_normalsMap; -}; - -// For each cell, check if the cell has a neighbor that (a) is in the normals -// map and (b) whose dihedral angle with said neighbor is less than a user- -// defined value. If so, add the cell to the list of new cells. -class ExtendByDihedralAngle : public ComputeNormals -{ -public: - ExtendByDihedralAngle(NormalsMap& normsMap, const InterfacePtr& iface, double angle) - : ComputeNormals(normsMap) - , m_interface(iface) - , m_cosDihedralAngle(std::cos(M_PI * angle / 180.)) - { - } - - [[nodiscard]] smtk::mesh::HandleRange newCellHandles() const { return m_newCells; } - - void clear() { m_newCells.clear(); } - - void forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType /*unused*/, int nPoints) - override - { - (void)nPoints; - assert(nPoints == 3); - std::array normal = this->unitNormal(); - smtk::mesh::HandleRange neighborCells = m_interface->neighbors(cellId); - for (auto i = smtk::mesh::rangeElementsBegin(neighborCells); - i != smtk::mesh::rangeElementsEnd(neighborCells); - ++i) - { - auto it = m_normalsMap.find(*i); - if (it != m_normalsMap.end()) - { - double dot = - normal[0] * it->second[0] + normal[1] * it->second[1] + normal[2] * it->second[2]; - if (dot > m_cosDihedralAngle) - { - m_normalsMap[cellId] = normal; - m_newCells.insert(cellId); - break; - } - } - } - } - -private: - const InterfacePtr& m_interface; - double m_cosDihedralAngle; - smtk::mesh::HandleRange m_newCells; -}; -} // namespace - -bool ExtractByDihedralAngle::ableToOperate() -{ - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(); - smtk::mesh::MeshSet meshset = meshComponent->mesh(); - - // Ensure that we are dealing with a triangle mesh. - CellTypes triangles; - triangles[smtk::mesh::Triangle] = true; - return meshset.types().cellTypes() == triangles; -} - -smtk::mesh::ExtractByDihedralAngle::Result ExtractByDihedralAngle::operateInternal() -{ - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(); - smtk::mesh::MeshSet meshset = meshComponent->mesh(); - - if (!meshset.isValid()) - { - this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - const smtk::mesh::Resource::Ptr& resource = meshset.resource(); - - smtk::mesh::MeshSet surfaceMesh = resource->meshes(); - - // For 2-dimensional mesh selections within a 3-dimensional mesh, we must take - // care to restrict our algorithm to the surface mesh. - bool shellCreated; - if (smtk::mesh::utility::highestDimension(surfaceMesh) == smtk::mesh::Dims3) - { - surfaceMesh = resource->meshes().extractShell(shellCreated); - } - - // Access the dihedral angle. - double dihedralAngle = this->parameters()->findDouble("dihedral angle")->value(); - - // The range of all cells to extract as a new meshset - smtk::mesh::HandleRange cells = meshset.cells().range(); - - // The range of cells to extract that were added during the most recent - // iteration - smtk::mesh::HandleRange newCells = cells; - - NormalsMap normalsMap; - - // Start by computing normals for the seed cells. - ComputeNormals computeNormals(normalsMap); - smtk::mesh::for_each(smtk::mesh::CellSet(resource, cells), computeNormals); - - ExtendByDihedralAngle extendByDihedralAngle(normalsMap, resource->interface(), dihedralAngle); - - do - { - extendByDihedralAngle.clear(); - - // The cells to test for inclusion in the extraction set - smtk::mesh::HandleRange toCheck; - - // Compute the next layer of neighbors to check for inclusion in the - // extraction set - for (auto i = smtk::mesh::rangeElementsBegin(newCells); - i != smtk::mesh::rangeElementsEnd(newCells); - ++i) - { - // Take the intersection of the cell's neighbors with the surface mesh. - toCheck += (resource->interface()->neighbors(*i) & surfaceMesh.cells().range()); - } - toCheck -= cells; - - // If there are no more cells to check, we are done - if (toCheck.empty()) - { - break; - } - - // Check the next layer of neighbors - smtk::mesh::for_each(smtk::mesh::CellSet(resource, toCheck), extendByDihedralAngle); - - // Access the newest set of cells - newCells = extendByDihedralAngle.newCellHandles(); - - // Include the newest set of cells in the overall range of cells to extract - cells += newCells; - } while (!newCells.empty()); - - // If a shell was created to facilitate the algorithm, remove it. - if (shellCreated) - { - resource->removeMeshes(surfaceMesh); - } - - smtk::mesh::MeshSet createdMesh = resource->createMesh(smtk::mesh::CellSet(resource, cells)); - createdMesh.setName("extracted"); - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - auto created = smtk::mesh::Component::create(createdMesh); - result->findComponent("created")->appendValue(created); - - // Mark the created component as having a modified geometry so it will be - // propertly rendered - smtk::operation::MarkGeometry().markModified(created); - - return result; -} - -const char* ExtractByDihedralAngle::xmlDescription() const -{ - return ExtractByDihedralAngle_xml; -} - -} //namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/ExtractByDihedralAngle.h b/smtk/mesh/operators/ExtractByDihedralAngle.h deleted file mode 100644 index b18369b68ab46c512fc8598163f42c1c1fe4cf33..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ExtractByDihedralAngle.h +++ /dev/null @@ -1,41 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_ExtractByDihedralAngle_h -#define smtk_mesh_ExtractByDihedralAngle_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Extract mesh subset by accepting all neighboring facets that meet the - selected meshset with a dihedral angle less than a given value. - */ -class SMTKCORE_EXPORT ExtractByDihedralAngle : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::ExtractByDihedralAngle); - smtkCreateMacro(ExtractByDihedralAngle); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; - -} //namespace mesh -} // namespace smtk - -#endif // smtk_mesh_ExtractByDihedralAngle_h diff --git a/smtk/mesh/operators/ExtractByDihedralAngle.sbt b/smtk/mesh/operators/ExtractByDihedralAngle.sbt deleted file mode 100644 index 0e08334957a07fb8e25113995bd0f710fd6c8bba..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ExtractByDihedralAngle.sbt +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - Extract mesh subset by accepting all neighboring facets that - meet the selected meshset with a dihedral angle less than a - given value. - - - - - The maximum accepted angle (in degrees) between the normals of two adjacent faces. - - 30.0 - - 0. - 180. - - - - - - - - - - - - diff --git a/smtk/mesh/operators/ExtractSkin.cxx b/smtk/mesh/operators/ExtractSkin.cxx deleted file mode 100644 index 5a82c46801cb5e42c5baf3f1845cb952a4fbd5ae..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ExtractSkin.cxx +++ /dev/null @@ -1,75 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/operators/ExtractSkin.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/DimensionTypes.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/mesh/operators/ExtractSkin_xml.h" - -namespace smtk -{ -namespace mesh -{ - -smtk::mesh::ExtractSkin::Result ExtractSkin::operateInternal() -{ - // Access the meshset - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(); - smtk::mesh::MeshSet meshset = meshComponent->mesh(); - - // Extract the skin - smtk::mesh::MeshSet skin = meshset.extractShell(); - - if (skin.is_empty()) - { - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - skin.setName(meshset.name() + " (skin)"); - - smtk::mesh::Component::Ptr skinComponent = smtk::mesh::Component::create(skin); - - if (skinComponent == nullptr) - { - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Create a new result - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with modified components - result->findComponent("created")->appendValue(skinComponent); - - // Mark the created component as having a modified geometry so it will be - // propertly rendered - smtk::operation::MarkGeometry().markModified(skinComponent); - - // Return with success - return result; -} - -const char* ExtractSkin::xmlDescription() const -{ - return ExtractSkin_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/ExtractSkin.h b/smtk/mesh/operators/ExtractSkin.h deleted file mode 100644 index 5b701251c7dbb872972f315fe8662d85e8975e8b..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ExtractSkin.h +++ /dev/null @@ -1,37 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_ExtractSkin_h -#define smtk_mesh_ExtractSkin_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Extract a mesh's skin. - */ -class SMTKCORE_EXPORT ExtractSkin : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::ExtractSkin); - smtkCreateMacro(ExtractSkin); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/operators/ExtractSkin.sbt b/smtk/mesh/operators/ExtractSkin.sbt deleted file mode 100644 index d573d575c81d3949a909061fadce2e5fbe18fdf4..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ExtractSkin.sbt +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - Extract a mesh's skin. - - - <p>Extract a mesh's skin. - <p>Cells may be created during this process. - - - - - - - - - - - - - diff --git a/smtk/mesh/operators/GenerateHotStartData.cxx b/smtk/mesh/operators/GenerateHotStartData.cxx deleted file mode 100644 index 1a922fad36cfb4a6c6dc86717a9a8537a0846e46..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/GenerateHotStartData.cxx +++ /dev/null @@ -1,312 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/GenerateHotStartData.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/operators/GenerateHotStartData_xml.h" - -#include "smtk/mesh/interpolation/InverseDistanceWeighting.h" -#include "smtk/mesh/interpolation/PointCloud.h" - -#include "smtk/mesh/utility/ApplyToMesh.h" - -#include "smtk/model/Resource.h" -#include "smtk/model/Session.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/Regex.h" - -#include -#include -#include -#include -#include -#include - -namespace -{ -// A key that corresponds to the .sbt file's values for output field type. -enum -{ - CELL_FIELD = 0, - POINT_FIELD = 1 -}; - -bool readCSVFile( - const std::string& fileName, - std::vector& coordinates, - std::vector& values) -{ - std::ifstream infile(fileName.c_str()); - if (!infile.good()) - { - return false; - } - std::string line; - smtk::regex re(","); - while (std::getline(infile, line)) - { - // passing -1 as the submatch index parameter performs splitting - smtk::sregex_token_iterator first{ line.begin(), line.end(), re, -1 }, last; - - // Se are looking for (x, y, value). So, we must have at least 3 - // components. - if (std::distance(first, last) < 3) - { - return false; - } - - coordinates.push_back(std::stod(*(first++))); - coordinates.push_back(std::stod(*(first++))); - coordinates.push_back(0.); - values.push_back(std::stod(*(first++))); - } - - infile.close(); - return true; -} - -// Compute the bounding box of a point cloud -std::array bounds(const smtk::mesh::PointCloud& pc) -{ - std::array b = { { std::numeric_limits::max(), - std::numeric_limits::lowest(), - std::numeric_limits::max(), - std::numeric_limits::lowest(), - std::numeric_limits::max(), - std::numeric_limits::lowest() } }; - - for (std::size_t i = 0; i < pc.size(); i++) - { - auto coord = pc.coordinates()(i); - for (std::size_t dim = 0; dim < 3; dim++) - { - if (coord[dim] < b[2 * dim]) - { - b[2 * dim] = coord[dim]; - } - if (coord[dim] > b[2 * dim + 1]) - { - b[2 * dim + 1] = coord[dim]; - } - } - } - - return b; -} - -// Compute the bounding box of a mesh set -std::array bounds(smtk::mesh::MeshSet ms) -{ - std::array b = { { std::numeric_limits::max(), - std::numeric_limits::lowest(), - std::numeric_limits::max(), - std::numeric_limits::lowest(), - std::numeric_limits::max(), - std::numeric_limits::lowest() } }; - - class Extent : public smtk::mesh::PointForEach - { - public: - Extent() - { - m_values[0] = m_values[2] = m_values[4] = std::numeric_limits::max(); - m_values[1] = m_values[3] = m_values[5] = std::numeric_limits::lowest(); - } - - void forPoints( - const smtk::mesh::HandleRange& /*pointIds*/, - std::vector& xyz, - bool& /*coordinatesModified*/) override - { - for (std::size_t i = 0; i < xyz.size(); i += 3) - { - for (std::size_t j = 0; j < 3; j++) - { - if (xyz[i + j] < m_values[2 * j]) - { - m_values[2 * j] = xyz[i + j]; - } - if (xyz[i + j] > m_values[2 * j + 1]) - { - m_values[2 * j + 1] = xyz[i + j]; - } - } - } - } - - double m_values[6]; - }; - - Extent extent; - smtk::mesh::for_each(ms.points(), extent); - for (std::size_t i = 0; i < 6; i++) - { - b[i] = extent.m_values[i]; - } - return b; -} -} // namespace - -namespace smtk -{ -namespace mesh -{ - -bool GenerateHotStartData::ableToOperate() -{ - return this->Superclass::ableToOperate(); -} - -GenerateHotStartData::Result GenerateHotStartData::operateInternal() -{ - // Access the mesh to elevate - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - - // Access the data set type - smtk::attribute::StringItem::Ptr typeItem = this->parameters()->findString("dstype"); - - // Access the interpolation points - smtk::attribute::GroupItem::Ptr interpolationPointsItem = this->parameters()->findGroup("points"); - - // Access the interpolation power parameter - smtk::attribute::DoubleItem::Ptr powerItem = this->parameters()->findDouble("power"); - - // Construct containers for our source points - std::vector sourceCoordinates; - std::vector sourceValues; - - // Access the points CSV file name, if it is enabled - smtk::attribute::FileItem::Ptr ptsFileItem = this->parameters()->findFile("ptsfile"); - if (ptsFileItem->isEnabled()) - { - bool success = readCSVFile(ptsFileItem->value(0), sourceCoordinates, sourceValues); - if (!success) - { - smtkErrorMacro(this->log(), "Could not read CSV file."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - - for (std::size_t i = 0; i < interpolationPointsItem->numberOfGroups(); i++) - { - smtk::attribute::DoubleItemPtr pointItem = - smtk::dynamic_pointer_cast(interpolationPointsItem->item(i, 0)); - for (std::size_t j = 0; j < 2; j++) - { - sourceCoordinates.push_back(pointItem->value(j)); - } - sourceCoordinates.push_back(0.); - sourceValues.push_back(pointItem->value(2)); - } - - // Construct a point cloud from our source points - smtk::mesh::PointCloud pointcloud(std::move(sourceCoordinates), std::move(sourceValues)); - - // Check if any meshes extend beyond the bounds of our interpolation point cloud, - // and warn if they do. - std::array pc_bounds = bounds(pointcloud); - bool meshIsContainedByPointCloud = true; - for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) - { - smtk::mesh::MeshSet mesh = meshItem->valueAs(i)->mesh(); - std::array mesh_bounds = bounds(mesh); - - for (std::size_t j = 0; j < 3; j++) - { - if (mesh_bounds[2 * j] < pc_bounds[2 * j] || mesh_bounds[2 * j + 1] > pc_bounds[2 * j + 1]) - { - meshIsContainedByPointCloud = false; - } - } - } - - if (!meshIsContainedByPointCloud) - { - std::stringstream s; - s << "Input mesh extends beyond the interpolation point cloud."; - smtkWarningMacro(this->log(), s.str()); - } - - // Construct an instance of our interpolator and set its parameters - smtk::mesh::InverseDistanceWeighting interpolator(pointcloud, powerItem->value()); - - // Construct a result object to hold our output - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with the modified model - smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); - - std::function)> fn; - std::string name; - - if (typeItem->value() == "Initial Depth") - { - name = "ioh"; - fn = [&](std::array x) { return interpolator(x); }; - } - else if (typeItem->value() == "Initial Concentration") - { - name = "icon 1"; - fn = [&](std::array x) { return interpolator(x); }; - } - else if (typeItem->value() == "Initial Water Surface Elevation") - { - name = "ioh"; - fn = [&](std::array x) { return interpolator(x) - x[2]; }; - } - else - { - smtkErrorMacro(this->log(), "Unsupported data type."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // apply the interpolator to the meshes and populate the result attributes - for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) - { - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); - smtk::mesh::MeshSet mesh = meshComponent->mesh(); - smtk::mesh::utility::applyScalarPointField(fn, name, mesh); - - modified->appendValue(meshComponent); - smtk::operation::MarkGeometry().markModified(meshComponent); - - smtk::model::EntityRefArray entities; - bool entitiesAreValid = mesh.modelEntities(entities); - if (entitiesAreValid && !entities.empty()) - { - smtk::model::Model model = entities[0].owningModel(); - modified->appendValue(model.component()); - smtk::operation::MarkGeometry().markModified(model.component()); - } - } - - return result; -} - -const char* GenerateHotStartData::xmlDescription() const -{ - return GenerateHotStartData_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/GenerateHotStartData.h b/smtk/mesh/operators/GenerateHotStartData.h deleted file mode 100644 index 600f5af806f939bda68cc7c5881e83f70648bb3f..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/GenerateHotStartData.h +++ /dev/null @@ -1,47 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_operators_GenerateHotStartData_h -#define smtk_mesh_operators_GenerateHotStartData_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief A class for generating hot start data for AdH. - - This class performs the same actions as InterpolateOntoMesh, with the - following differences: - 1) the API is tweaked to apply directly to AdH's use case - 2) only point data can be generated - 3) when computing initial water surface elevation, the z-coordinate of each - point is subtracted from the interpolated data, resulting in a value that - represents the water level above ground (as opposed to a baseline value) - */ -class SMTKCORE_EXPORT GenerateHotStartData : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::GenerateHotStartData); - smtkCreateMacro(GenerateHotStartData); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace smtk - -#endif // smtk_mesh_operators_GenerateHotStartData_h diff --git a/smtk/mesh/operators/GenerateHotStartData.sbt b/smtk/mesh/operators/GenerateHotStartData.sbt deleted file mode 100644 index 7941b502a2ae492b7a74790c9918206c8a1ea629..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/GenerateHotStartData.sbt +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - Create a field on mesh nodes/elements from - interpolated 2-dimensional data. - - - <p>Create a field on mesh nodes/elements from - interpolated 2-dimensional data. - <p>This operator accepts as input two-dimensional points - with associated scalar values, and interpolates these values - onto either the points or the cells of the mesh. The input - points can be inserted manually or read from a CSV file. - - - - - - - - - The name of the data set. - - Initial Depth - Initial Concentration - Initial Water Surface Elevation - - - - - - - - The points and their scalar values to interpolate. - - An implicit function is described by interpolating points - and their associated scalar value. - - - - - - - - - - - - - - The weighting power used to interpolate - source points. - - The weighting power used to interpolate source points. - - The operator uses Shepard's method to interpolate between - points. The inverse distance value is exponentiated by - this unitless value when computing weighting coefficients. - - 1. - - - - - - - - - - - - diff --git a/smtk/mesh/operators/Import.cxx b/smtk/mesh/operators/Import.cxx deleted file mode 100644 index c70371e7e0791b7faa253a95d906edac47d1fb9a..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Import.cxx +++ /dev/null @@ -1,148 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/Import.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/Definition.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/FileItemDefinition.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/Resource.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/io/ImportMesh.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/operators/Import_xml.h" - -namespace -{ -class AddMeshToResult : public smtk::mesh::MeshForEach -{ -public: - AddMeshToResult(smtk::mesh::Import::Result& result) - : m_result(result) - { - } - - void forMesh(smtk::mesh::MeshSet& mesh) override - { - m_result->findComponent("created")->appendValue(smtk::mesh::Component::create(mesh)); - } - -private: - smtk::mesh::Import::Result& m_result; -}; -} // namespace - -namespace smtk -{ -namespace mesh -{ - -Import::Result Import::operateInternal() -{ - // Get the import file name - smtk::attribute::FileItem::Ptr filePathItem = this->parameters()->findFile("filename"); - std::string filePath = filePathItem->value(); - - // Get the subset value - smtk::attribute::StringItem::Ptr labelItem = this->parameters()->findString("label"); - std::string label = labelItem->value(); - - auto resource = smtk::mesh::Resource::create(); - bool success = smtk::io::importMesh(filePath, resource, label); - - if (!success) - { - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - auto result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - AddMeshToResult addMeshToResult(result); - - smtk::mesh::for_each(resource->meshes(), addMeshToResult); - - auto assignNames = this->parameters()->findVoid("assign default names"); - if (assignNames && assignNames->isEnabled()) - { - resource->assignDefaultNames(); - } - - result->findResource("resourcesCreated")->appendValue(resource); - - return result; -} - -Import::Specification Import::createSpecification() -{ - Specification spec = this->smtk::operation::XMLOperation::createSpecification(); - auto importDef = spec->findDefinition("import"); - - std::vector fileItemDefinitions; - auto fileItemDefinitionFilter = [](smtk::attribute::FileItemDefinition::Ptr ptr) { - return ptr->name() == "filename"; - }; - importDef->filterItemDefinitions(fileItemDefinitions, fileItemDefinitionFilter); - - assert(fileItemDefinitions.size() == 1); - - std::stringstream fileFilters; - bool firstFormat = true; - for (auto& ioType : smtk::io::ImportMesh::SupportedIOTypes()) - { - for (const auto& format : ioType->FileFormats()) - { - if (format.CanImport()) - { - if (firstFormat) - { - firstFormat = false; - } - else - { - fileFilters << ";;"; - } - - fileFilters << format.Name << "("; - bool first = true; - for (const auto& ext : format.Extensions) - { - if (first) - { - first = false; - } - else - { - fileFilters << " "; - } - fileFilters << "*" << ext; - } - fileFilters << ")"; - } - } - } - fileItemDefinitions[0]->setFileFilters(fileFilters.str()); - return spec; -} - -const char* Import::xmlDescription() const -{ - return Import_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/Import.h b/smtk/mesh/operators/Import.h deleted file mode 100644 index ddd00f1f170ae19b18ed521e875c8f0e60575470..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Import.h +++ /dev/null @@ -1,42 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_Import_h -#define smtk_mesh_Import_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Import an smtk mesh file. - * - * Here and throughout SMTK, we use the terms read/write to describe - * serialization of native SMTK files, while the terms import/export describe - * transcription from/to a different format. - */ -class SMTKCORE_EXPORT Import : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::Import); - smtkCreateMacro(Import); - smtkSharedFromThisMacro(smtk::operation::Operation); - -protected: - Result operateInternal() override; - Specification createSpecification() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/operators/Import.sbt b/smtk/mesh/operators/Import.sbt deleted file mode 100644 index 16c273af906a7bcccf632a15dee9b662b2c48737..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Import.sbt +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - Upon importing, assign names to meshes that have no name already. - - - - - - - - - - diff --git a/smtk/mesh/operators/InterpolateOntoMesh.cxx b/smtk/mesh/operators/InterpolateOntoMesh.cxx deleted file mode 100644 index 7c48c88a3b9ce919598ab09b3ce930a6736860f1..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/InterpolateOntoMesh.cxx +++ /dev/null @@ -1,419 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/InterpolateOntoMesh.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/InterpolateOntoMesh_xml.h" - -#include "smtk/mesh/interpolation/InverseDistanceWeighting.h" -#include "smtk/mesh/interpolation/PointCloud.h" -#include "smtk/mesh/interpolation/PointCloudGenerator.h" -#include "smtk/mesh/interpolation/RadialAverage.h" -#include "smtk/mesh/interpolation/StructuredGrid.h" -#include "smtk/mesh/interpolation/StructuredGridGenerator.h" - -#include "smtk/mesh/utility/ApplyToMesh.h" - -#include "smtk/model/AuxiliaryGeometry.h" -#include "smtk/model/Resource.h" -#include "smtk/model/Session.h" - -#include "smtk/operation/MarkGeometry.h" - -#include -#include -#include -#include -#include -#include - -namespace -{ -// A key that corresponds to the .sbt file's values for output field type. -enum -{ - CELL_FIELD = 0, - POINT_FIELD = 1 -}; - -template -std::function)> radialAverageFrom( - const InputType& input, - double radius, - const std::function& prefilter, - const smtk::mesh::InterfacePtr& interface) -{ - std::function)> radialAverage; - { - // Let's start by trying to make a structured grid, since they can be a - // subset of point clouds. - smtk::mesh::StructuredGridGenerator sgg; - smtk::mesh::StructuredGrid structuredgrid = sgg(input); - if (structuredgrid.size() > 0) - { - radialAverage = smtk::mesh::RadialAverage(structuredgrid, radius, prefilter); - } - } - - if (!radialAverage) - { - // Next, we try to make a point cloud from our data. - smtk::mesh::PointCloudGenerator pcg; - smtk::mesh::PointCloud pointcloud = pcg(input); - if (pointcloud.size() > 0) - { - radialAverage = smtk::mesh::RadialAverage( - smtk::mesh::Resource::create(interface), pointcloud, radius, prefilter); - } - } - - return radialAverage; -} - -template -std::function)> inverseDistanceWeightingFrom( - const InputType& input, - double power, - const std::function& prefilter) -{ - std::function)> idw; - { - // Let's start by trying to make a structured grid, since they can be a - // subset of point clouds. - smtk::mesh::StructuredGridGenerator sgg; - smtk::mesh::StructuredGrid structuredgrid = sgg(input); - if (structuredgrid.size() > 0) - { - idw = smtk::mesh::InverseDistanceWeighting(structuredgrid, power, prefilter); - } - } - - if (!idw) - { - // Next, we try to make a point cloud from our data. - smtk::mesh::PointCloudGenerator pcg; - smtk::mesh::PointCloud pointcloud = pcg(input); - if (pointcloud.size() > 0) - { - idw = smtk::mesh::InverseDistanceWeighting(pointcloud, power, prefilter); - } - } - - return idw; -} -} // namespace - -namespace smtk -{ -namespace mesh -{ - -bool InterpolateOntoMesh::ableToOperate() -{ - return this->Superclass::ableToOperate(); -} - -InterpolateOntoMesh::Result InterpolateOntoMesh::operateInternal() -{ - // Access the string describing the input data type - smtk::attribute::StringItem::Ptr inputDataItem = this->parameters()->findString("input data"); - - // Access the mesh to elevate - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - smtk::mesh::MeshSet meshset = meshItem->valueAs()->mesh(); - const smtk::mesh::Resource::Ptr& resource = meshset.resource(); - - // Access the string describing the interpolation scheme - smtk::attribute::StringItem::Ptr interpolationSchemeItem = - this->parameters()->findString("interpolation scheme"); - - // Access the radius parameter - smtk::attribute::DoubleItem::Ptr radiusItem = this->parameters()->findDouble("radius"); - - // Access the string describing external point treatment - smtk::attribute::StringItem::Ptr externalPointItem = - this->parameters()->findString("external point values"); - - // Access the power parameter - smtk::attribute::DoubleItem::Ptr powerItem = this->parameters()->findDouble("power"); - - // Access the data set name - smtk::attribute::StringItem::Ptr nameItem = this->parameters()->findString("dsname"); - - // Access the output interpolation Field type - smtk::attribute::IntItem::Ptr modeItem = this->parameters()->findInt("interpmode"); - - // Construct a prefilter for the input data - std::function prefilter = [](double /*unused*/) { return true; }; - { - // Access the input filter parameter group - smtk::attribute::GroupItem::Ptr inputFilterItem = this->parameters()->findGroup("input filter"); - - if (inputFilterItem) - { - // Access the min threshold parameter - smtk::attribute::DoubleItem::Ptr minThresholdItem = - inputFilterItem->findAs("min threshold"); - - // Access the max threshold parameter - smtk::attribute::DoubleItem::Ptr maxThresholdItem = - inputFilterItem->findAs("max threshold"); - - if ( - minThresholdItem && minThresholdItem->isEnabled() && maxThresholdItem && - maxThresholdItem->isEnabled()) - { - double minThreshold = minThresholdItem->value(); - double maxThreshold = maxThresholdItem->value(); - prefilter = [=](double d) { return d >= minThreshold && d <= maxThreshold; }; - } - else if (minThresholdItem && minThresholdItem->isEnabled()) - { - double minThreshold = minThresholdItem->value(); - prefilter = [=](double d) { return d >= minThreshold; }; - } - else if (maxThresholdItem && maxThresholdItem->isEnabled()) - { - double maxThreshold = maxThresholdItem->value(); - prefilter = [=](double d) { return d <= maxThreshold; }; - } - } - } - - // Construct a function that takes an input point and returns a value - // according to the average of the locus of points in the external data that, - // when projected onto the x-y plane, are within a radius of the input - std::function)> interpolation; - - if (inputDataItem->value() == "auxiliary geometry") - { - // Access the external data to use in determining value values - auto auxGeoItem = this->parameters()->findComponent("auxiliary geometry"); - - // Get the auxiliary geometry - smtk::model::AuxiliaryGeometry auxGeo = auxGeoItem->valueAs(); - - if (interpolationSchemeItem->value() == "radial average") - { - // Compute the radial average function - interpolation = radialAverageFrom( - auxGeo, radiusItem->value(), prefilter, resource->interface()); - } - else if (interpolationSchemeItem->value() == "inverse distance weighting") - { - // Compute the inverse distance weighting function - interpolation = inverseDistanceWeightingFrom( - auxGeo, powerItem->value(), prefilter); - } - - if (!interpolation) - { - smtkErrorMacro(this->log(), "Could not convert auxiliary geometry."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - else if (inputDataItem->value() == "ptsfile") - { - // Get the file name - std::string fileName = this->parameters()->findFile("ptsfile")->value(); - - if (interpolationSchemeItem->value() == "radial average") - { - // Compute the radial average function - interpolation = radialAverageFrom( - fileName, radiusItem->value(), prefilter, resource->interface()); - } - else if (interpolationSchemeItem->value() == "inverse distance weighting") - { - // Compute the inverse distance weighting function - interpolation = - inverseDistanceWeightingFrom(fileName, powerItem->value(), prefilter); - } - - if (!interpolation) - { - smtkErrorMacro(this->log(), "Could not read file."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - else if (inputDataItem->value() == "points") - { - // Access the interpolation points - smtk::attribute::GroupItem::Ptr interpolationPointsItem = - this->parameters()->findGroup("points"); - - // Construct containers for our source points - std::vector sourceCoordinates; - std::vector sourceValues; - - for (std::size_t i = 0; i < interpolationPointsItem->numberOfGroups(); i++) - { - smtk::attribute::DoubleItemPtr pointItem = - smtk::dynamic_pointer_cast( - interpolationPointsItem->item(i, 0)); - for (std::size_t j = 0; j < 3; j++) - { - sourceCoordinates.push_back(pointItem->value(j)); - } - sourceValues.push_back(pointItem->value(3)); - } - - smtk::mesh::PointCloud pointcloud(std::move(sourceCoordinates), std::move(sourceValues)); - - if (interpolationSchemeItem->value() == "radial average") - { - interpolation = smtk::mesh::RadialAverage( - smtk::mesh::Resource::create(resource->interface()), pointcloud, radiusItem->value()); - } - else if (interpolationSchemeItem->value() == "inverse distance weighting") - { - // Compute the inverse distance weighting function - interpolation = smtk::mesh::InverseDistanceWeighting(pointcloud, powerItem->value()); - } - - if (!interpolation) - { - smtkErrorMacro(this->log(), "Could not read points."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - else - { - smtkErrorMacro(this->log(), "Unrecognized input type."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Construct a function that clips its input according to the input parameters - std::function postProcess = [](double input) { return input; }; - { - // Access the output filter parameter group - smtk::attribute::GroupItem::Ptr outputFilterItem = - this->parameters()->findGroup("output filter"); - - if (outputFilterItem) - { - // Access the min value parameter - smtk::attribute::DoubleItem::Ptr minValueItem = - outputFilterItem->findAs("min value"); - - // Access the max value parameter - smtk::attribute::DoubleItem::Ptr maxValueItem = - outputFilterItem->findAs("max value"); - - if (minValueItem && minValueItem->isEnabled() && maxValueItem && maxValueItem->isEnabled()) - { - double minValue = minValueItem->value(); - double maxValue = maxValueItem->value(); - postProcess = [=](double input) { - return (input < minValue ? minValue : (input > maxValue ? maxValue : input)); - }; - } - else if (minValueItem && minValueItem->isEnabled()) - { - double minValue = minValueItem->value(); - postProcess = [=](double input) { return (input < minValue ? minValue : input); }; - } - else if (maxValueItem && maxValueItem->isEnabled()) - { - double maxValue = maxValueItem->value(); - postProcess = [=](double input) { return (input > maxValue ? maxValue : input); }; - } - } - } - - // Add a conditional function for dealing with points that were rejected by the interpolator. - std::function)> externalDataPoint = [](std::array xyz) { - return xyz[2]; - }; - if (interpolationSchemeItem->value() == "radial average") - { - if (externalPointItem->value() == "set to NaN") - { - externalDataPoint = [](std::array /*unused*/) { - return std::numeric_limits::quiet_NaN(); - }; - } - else if (externalPointItem->value() == "set to value") - { - double externalPointValue = this->parameters()->findDouble("external point value")->value(); - externalDataPoint = [=](std::array /*unused*/) { return externalPointValue; }; - } - } - - // Access the attribute associated with the modified meshes - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with the modified model - smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); - - // Mark the modified mesh components to update their representative geometry - smtk::operation::MarkGeometry markGeometry(resource); - - std::function)> fn = [&](std::array x) { - double f_x = postProcess(interpolation(x)); - if (std::isnan(f_x)) - { - f_x = externalDataPoint(x); - } - - return f_x; - }; - - // apply the interpolator to the meshes and populate the result attributes - for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) - { - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); - smtk::mesh::MeshSet mesh = meshComponent->mesh(); - - if (modeItem->value(0) == CELL_FIELD) - { - smtk::mesh::utility::applyScalarCellField(fn, nameItem->value(), mesh); - } - else - { - smtk::mesh::utility::applyScalarPointField(fn, nameItem->value(), mesh); - } - - modified->appendValue(meshComponent); - markGeometry.markModified(meshComponent); - - smtk::model::EntityRefArray entities; - bool entitiesAreValid = mesh.modelEntities(entities); - if (entitiesAreValid && !entities.empty()) - { - smtk::model::Model model = entities[0].owningModel(); - modified->appendValue(model.component()); - smtk::operation::MarkGeometry().markModified(model.component()); - } - } - - return result; -} - -const char* InterpolateOntoMesh::xmlDescription() const -{ - return InterpolateOntoMesh_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/InterpolateOntoMesh.h b/smtk/mesh/operators/InterpolateOntoMesh.h deleted file mode 100644 index 9c9424c41c6499a28b01c12a0f0ea74027cf83e7..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/InterpolateOntoMesh.h +++ /dev/null @@ -1,39 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_operators_InterpolateOntoMesh_h -#define smtk_mesh_operators_InterpolateOntoMesh_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief A class for generating a mesh data set from interpolation points. - */ -class SMTKCORE_EXPORT InterpolateOntoMesh : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::InterpolateOntoMesh); - smtkCreateMacro(InterpolateOntoMesh); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace smtk - -#endif // smtk_mesh_operators_InterpolateOntoMesh_h diff --git a/smtk/mesh/operators/InterpolateOntoMesh.sbt b/smtk/mesh/operators/InterpolateOntoMesh.sbt deleted file mode 100644 index 7ff5c587a7cfd96dbc2c72aa2fb3b16a48fc3f45..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/InterpolateOntoMesh.sbt +++ /dev/null @@ -1,285 +0,0 @@ - - - - - - - - - Create a field on mesh nodes/elements from interpolated 3-dimensional data. - - - <p>Create a field on mesh nodes/elements from interpolated 3-dimensional data. - <p>This operator accepts as input three-dimensional points - with associated scalar values; it interpolates these values - onto either the points or the cells of the mesh using - Shepard's method for interpolation. The input points can be - inserted manually or read from a CSV file. - - - - - - - - - - - The input data (coordinates and scalar values) to use for interpolation. - - An input data set is required to elevate a mesh. It can be - an auxiliary geometry, an input file, or a collection of - coordinates and scalar values. - - - - - - - An external data set whose values determine the interpolated values. - - - - - - A file describing a data set whose values determine the interpolated values. - - - - - - Input data filter options. - - - Options to filter input data prior to interpolation. - - - - - - Input data less than this value will be ignored. - - - - Input data greater than this value will be ignored. - - - - - - - - The points and their scalar values to interpolate. - - An implicit function is described by interpolating points - and their associated scalar value. - - - - - - - - - - - - - - - - - auxiliary geometry - - auxiliary geometry - input filter - - - - ptsfile - - ptsfile - input filter - - - - points - - points - - - - - - - - The interpolation scheme to apply to the input data - - The scalar values from the input data must be interpolated - onto the nodes of the mesh. Currently, the supported - techniques are Radial Average (unweighted average of all - points within a cylinder of a given radius from a mesh - node) and Inverse Distance Weighting (weighted average of - all the points in the data set according to the distance - between the datapoint and the mesh node). - - - - - - The radius used to identify a point locus for computing values. - - The radius used to identify a point locus for computing - values. - - For each node in the input mesh, a corresponding point - locus whose positions projected onto the x-y plane are - within a radius of the node is used to compute a new - value. - - When the interpolating data is unstructured, then - it is possible to find a point within the bounding box of the - interpolating data where there are no data points within the search - circle. In that case, the algorithm will return the - External Point Value. - - When the interpolating data is a grid, the query point - is first snapped to the nearest grid point, and the radius is then - used to acquire additional points for averaging. If there are no - points within the search circle, the value associated with the - original point to which the query point was snapped is returned. - - - - - - Treatment for points in the mesh that fall outside of the range of the dataset. - - - Treatment for points in the mesh that fall outside of the - range of the dataset. - - When the interpolating data is unstructured, then - it is possible to find a point within the bounding box of the - interpolating data where there are no data points within the search - circle. In that case, the algorithm will return a value - according to this condition. - - - - - The z-coordinate of every point outside of the data set will be assigned this value - 0. - - - - - - - left unchanged - - - set to value - - external point value - - - - set to NaN - - - - - - - The weighting power used to interpolate source points. - - The weighting power used to interpolate source points. - - The inverse distance value is exponentiated by - this unitless value when computing weighting coefficients. - - 1. - - - - - - - radial average - - radius - external point values - - - - inverse distance weighting - - power - - - - - - - - - Ignore input data that falls outside of a given range. - - - A range (minimum and maximum value) for input scalar - data. Input data values that fall outside of this - range will be omitted from the interpolation calculation. - - - - - - Lower limit to the resulting mesh's value range. - 0.0 - - - - Upper limit to the resulting mesh's value range. - 0.0 - - - - - - - - The name of the generated data set. - - - - Interpolate the data as cell-centered or point-centered on the mesh. - - 0 - 1 - - - - - - - - - - - - - - - - - diff --git a/smtk/mesh/operators/MergeCoincidentPoints.cxx b/smtk/mesh/operators/MergeCoincidentPoints.cxx deleted file mode 100644 index edcc8d97bd6caeec2589ec88efa3dd5579096aa8..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/MergeCoincidentPoints.cxx +++ /dev/null @@ -1,63 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/operators/MergeCoincidentPoints.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/mesh/operators/MergeCoincidentPoints_xml.h" - -namespace smtk -{ -namespace mesh -{ - -smtk::mesh::MergeCoincidentPoints::Result MergeCoincidentPoints::operateInternal() -{ - // Access the tolerance. - double tolerance = this->parameters()->findDouble("tolerance")->value(); - - // Access the meshset - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(); - smtk::mesh::MeshSet meshset = meshComponent->mesh(); - - // Set the name of the meshset - bool success = meshset.mergeCoincidentContactPoints(tolerance); - - if (!success) - { - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Create a new result - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with modified components - result->findComponent("modified")->appendValue(meshComponent); - - // Return with success - return result; -} - -const char* MergeCoincidentPoints::xmlDescription() const -{ - return MergeCoincidentPoints_xml; -} - -} //namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/MergeCoincidentPoints.h b/smtk/mesh/operators/MergeCoincidentPoints.h deleted file mode 100644 index 8187ac4e4b662c61b50899efb497fc543fcf05ac..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/MergeCoincidentPoints.h +++ /dev/null @@ -1,38 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_MergeCoincidentPoints_h -#define smtk_mesh_MergeCoincidentPoints_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Merge coincident points in a meshset. - */ -class SMTKCORE_EXPORT MergeCoincidentPoints : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::MergeCoincidentPoints); - smtkCreateMacro(MergeCoincidentPoints); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; - -} //namespace mesh -} // namespace smtk - -#endif // smtk_mesh_MergeCoincidentPoints_h diff --git a/smtk/mesh/operators/MergeCoincidentPoints.sbt b/smtk/mesh/operators/MergeCoincidentPoints.sbt deleted file mode 100644 index 74ecfddaf5e2f12ec564f79f507bb6b50b431080..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/MergeCoincidentPoints.sbt +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - The maximum distance between two points concidered to be coincident. - - 1.e-6 - - 0. - - - - - Merge coincident points. - - - <p>Merge coincident points. - <p>This operator merges points that are less than a - user-defined tolerance from each other. - - - - - - - - - - diff --git a/smtk/mesh/operators/PrintMeshInformation.cxx b/smtk/mesh/operators/PrintMeshInformation.cxx deleted file mode 100644 index 466918b983a92d49963ca7c0fa2adff59fe30837..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/PrintMeshInformation.cxx +++ /dev/null @@ -1,71 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/operators/PrintMeshInformation.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/Session.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/IntItem.h" - -#include "smtk/mesh/operators/PrintMeshInformation_xml.h" - -namespace smtk -{ -namespace mesh -{ - -smtk::mesh::PrintMeshInformation::Result PrintMeshInformation::operateInternal() -{ - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - - for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) - { - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); - smtk::mesh::MeshSet meshset = meshComponent->mesh(); - - smtkInfoMacro( - this->log(), - "Mesh Component <" << meshComponent->id() << ">\n" - << " name: " << meshset.name() - << "\n" - " # meshes: " - << meshset.size() - << "\n" - " # cells: " - << meshset.cells().size() - << "\n" - " # points: " - << meshset.points().size() - << "\n" - " # domains: " - << meshset.domains().size() - << "\n" - " # dirichlets: " - << meshset.dirichlets().size() - << "\n" - " # neumanns: " - << meshset.neumanns().size()); - } - - return this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); -} - -const char* PrintMeshInformation::xmlDescription() const -{ - return PrintMeshInformation_xml; -} - -} //namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/PrintMeshInformation.h b/smtk/mesh/operators/PrintMeshInformation.h deleted file mode 100644 index 92dd50905227427da453c8fdbb8f694955568e50..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/PrintMeshInformation.h +++ /dev/null @@ -1,38 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_PrintMeshInformation_h -#define smtk_mesh_PrintMeshInformation_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Delete a mesh. - */ -class SMTKCORE_EXPORT PrintMeshInformation : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::PrintMeshInformation); - smtkCreateMacro(PrintMeshInformation); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; - -} //namespace mesh -} // namespace smtk - -#endif // smtk_mesh_PrintMeshInformation_h diff --git a/smtk/mesh/operators/PrintMeshInformation.sbt b/smtk/mesh/operators/PrintMeshInformation.sbt deleted file mode 100644 index d3e3c69638cb5d469ba1ccf307710ecd5ea4a59c..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/PrintMeshInformation.sbt +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - Print mesh information to output. - - - - - - - - - - diff --git a/smtk/mesh/operators/Read.cxx b/smtk/mesh/operators/Read.cxx deleted file mode 100644 index 4f5a27965b1b3dbd2de762a14f8d2d9a06a0be21..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Read.cxx +++ /dev/null @@ -1,164 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/Read.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/Definition.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/FileItemDefinition.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/Resource.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/ReadMesh.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/operators/Read_xml.h" - -#include "smtk/common/CompilerInformation.h" - -/// @cond dox_ignore -SMTK_THIRDPARTY_PRE_INCLUDE -#include "nlohmann/json.hpp" -SMTK_THIRDPARTY_POST_INCLUDE -/// @endcond - -#include - -namespace -{ -/// Internal \p smtk::mesh::Read utility -class AddMeshToResult : public smtk::mesh::MeshForEach -{ -public: - AddMeshToResult(smtk::mesh::Read::Result& result) - : m_result(result) - { - } - - void forMesh(smtk::mesh::MeshSet& mesh) override - { - m_result->findComponent("created")->appendValue(smtk::mesh::Component::create(mesh)); - } - -private: - smtk::mesh::Read::Result& m_result; -}; -} // namespace - -namespace smtk -{ -namespace mesh -{ - -Read::Result Read::operateInternal() -{ - // Get the read file name - smtk::attribute::FileItem::Ptr filePathItem = this->parameters()->findFile("filename"); - std::string filePath = filePathItem->value(); - - // Get the subset value - smtk::attribute::IntItem::Ptr subsetItem = this->parameters()->findInt("subset"); - smtk::io::mesh::Subset subset = static_cast(subsetItem->value()); - - auto resource = smtk::mesh::Resource::create(); - bool success = smtk::io::readMesh(filePath, resource, subset); - - if (!success) - { - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - auto result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - AddMeshToResult addMeshToResult(result); - - smtk::mesh::for_each(resource->meshes(), addMeshToResult); - - result->findResource("resourcesCreated")->appendValue(resource); - - return result; -} - -Read::Specification Read::createSpecification() -{ - Specification spec = this->smtk::operation::XMLOperation::createSpecification(); - auto importDef = spec->findDefinition("read"); - - std::vector fileItemDefinitions; - auto fileItemDefinitionFilter = [](smtk::attribute::FileItemDefinition::Ptr ptr) { - return ptr->name() == "filename"; - }; - importDef->filterItemDefinitions(fileItemDefinitions, fileItemDefinitionFilter); - - assert(fileItemDefinitions.size() == 1); - - std::stringstream fileFilters; - bool firstFormat = true; - for (auto& ioType : smtk::io::ReadMesh::SupportedIOTypes()) - { - for (const auto& format : ioType->FileFormats()) - { - if (format.CanImport()) - { - if (firstFormat) - { - firstFormat = false; - } - else - { - fileFilters << ";;"; - } - - fileFilters << format.Name << "("; - bool first = true; - for (const auto& ext : format.Extensions) - { - if (first) - { - first = false; - } - else - { - fileFilters << " "; - } - fileFilters << "*" << ext; - } - fileFilters << ")"; - } - } - } - fileItemDefinitions[0]->setFileFilters(fileFilters.str()); - return spec; -} - -void Read::markModifiedResources(Read::Result& res) -{ - auto resourceItem = res->findResource("resourcesCreated"); - for (auto rit = resourceItem->begin(); rit != resourceItem->end(); ++rit) - { - auto resource = std::dynamic_pointer_cast(*rit); - - // Set the resource as unmodified from its persistent (i.e. on-disk) state - resource->setClean(true); - } -} - -const char* Read::xmlDescription() const -{ - return Read_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/Read.h b/smtk/mesh/operators/Read.h deleted file mode 100644 index 3bb09a1197f4b6ae54395bba220a818ef4ecedef..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Read.h +++ /dev/null @@ -1,43 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_Read_h -#define smtk_mesh_Read_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Read an smtk mesh file. - * - * Here and throughout SMTK, we use the terms read/write to describe - * serialization of native SMTK files, while the terms import/export describe - * transcription from/to a different format. - */ -class SMTKCORE_EXPORT Read : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::Read); - smtkCreateMacro(Read); - smtkSharedFromThisMacro(smtk::operation::Operation); - -protected: - Result operateInternal() override; - Specification createSpecification() override; - const char* xmlDescription() const override; - void markModifiedResources(Result&) override; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/operators/Read.sbt b/smtk/mesh/operators/Read.sbt deleted file mode 100644 index 7cc85d0bdc113bb2f013c431168bc7b6dfa1a50b..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Read.sbt +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - Subset of the mesh to load - - 0 - 1 - 2 - 3 - - - - - - - - - - diff --git a/smtk/mesh/operators/ReadResource.cxx b/smtk/mesh/operators/ReadResource.cxx deleted file mode 100644 index 412499ce88105f93c24aad895a4208ffb46d97d9..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ReadResource.cxx +++ /dev/null @@ -1,152 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/ReadResource.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/common/Archive.h" -#include "smtk/common/CompilerInformation.h" -#include "smtk/common/FileLocation.h" -#include "smtk/common/Paths.h" - -#include "smtk/io/ReadMesh.h" - -#include "smtk/mesh/json/jsonResource.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/operators/Read.h" -#include "smtk/mesh/operators/ReadResource_xml.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "nlohmann/json.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include - -namespace smtk -{ -namespace mesh -{ - -ReadResource::Result ReadResource::operateInternal() -{ - std::string filename = this->parameters()->findFile("filename")->value(); - - std::ifstream file; - - smtk::common::Archive archive(filename); - if (!archive.contents().empty()) - { - std::string smtkFilename = "index.json"; - - archive.get(smtkFilename, file); - } - else - { - file.open(filename); - } - - if (!file.good()) - { - smtkErrorMacro(log(), "Cannot read file \"" << filename << "\"."); - file.close(); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - nlohmann::json j; - try - { - j = nlohmann::json::parse(file); - } - catch (...) - { - smtkErrorMacro(log(), "Cannot parse file \"" << filename << "\"."); - file.close(); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - file.close(); - - std::string meshFilename = j.at("Mesh URL"); - - smtk::common::FileLocation meshFileLocation; - if (!archive.contents().empty()) - { - meshFileLocation = archive.location(meshFilename); - } - else - { - auto refDirectory = smtk::common::Paths::directory(filename); - meshFileLocation = smtk::common::FileLocation(meshFilename, refDirectory); - } - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(); - smtk::mesh::from_json(j, resource); - bool success = read(meshFileLocation.absolutePath(), resource); - if (!success) - { - smtkErrorMacro(log(), "Cannot read mesh file \"" << meshFileLocation.absolutePath() << "\"."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - resource->setLocation(filename); - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - { - smtk::attribute::ResourceItem::Ptr created = result->findResource("resourcesCreated"); - created->appendValue(resource); - } - - return result; -} - -const char* ReadResource::xmlDescription() const -{ - return ReadResource_xml; -} - -void ReadResource::markModifiedResources(ReadResource::Result& res) -{ - auto resourceItem = res->findResource("resourcesCreated"); - for (auto rit = resourceItem->begin(); rit != resourceItem->end(); ++rit) - { - if (rit.isSet()) - { - auto resource = std::dynamic_pointer_cast(*rit); - - // Set the resource as unmodified from its persistent (i.e. on-disk) state - resource->setClean(true); - } - } -} - -smtk::resource::ResourcePtr read( - const std::string& filename, - const std::shared_ptr& managers) -{ - (void)managers; - ReadResource::Ptr read = ReadResource::create(); - read->parameters()->findFile("filename")->setValue(filename); - ReadResource::Result result = read->operate(); - if (result->findInt("outcome")->value() != static_cast(ReadResource::Outcome::SUCCEEDED)) - { - return smtk::resource::ResourcePtr(); - } - return result->findResource("resourcesCreated")->value(); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/ReadResource.h b/smtk/mesh/operators/ReadResource.h deleted file mode 100644 index df6dce0ec1b9cdbd6ff1dd428023d49a82614e71..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ReadResource.h +++ /dev/null @@ -1,42 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_ReadResource_h -#define smtk_mesh_ReadResource_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Read an smtk mesh resource. - */ -class SMTKCORE_EXPORT ReadResource : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::ReadResource); - smtkCreateMacro(ReadResource); - smtkSharedFromThisMacro(smtk::operation::Operation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; - void markModifiedResources(Result&) override; -}; - -SMTKCORE_EXPORT smtk::resource::ResourcePtr read( - const std::string&, - const std::shared_ptr&); -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/operators/ReadResource.sbt b/smtk/mesh/operators/ReadResource.sbt deleted file mode 100644 index 6d116bb657a2803c8a8c7128ab7dd397cc928803..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/ReadResource.sbt +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/smtk/mesh/operators/SelectCells.cxx b/smtk/mesh/operators/SelectCells.cxx deleted file mode 100644 index c95816250699085037a042cfc6534943fd7bc8a6..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/SelectCells.cxx +++ /dev/null @@ -1,81 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/SelectCells.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/Definition.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/Resource.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/SelectCells_xml.h" -#include "smtk/mesh/resource/Selection.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/operation/Manager.h" - -namespace smtk -{ -namespace mesh -{ - -SelectCells::Result SelectCells::operateInternal() -{ - // Access the mesh resource. - smtk::attribute::ReferenceItem::Ptr resourceItem = this->parameters()->associations(); - smtk::mesh::ResourcePtr resource = resourceItem->valueAs(); - - // Access the selected cell ids. - smtk::mesh::HandleRange cells; - { - smtk::attribute::StringItem::Ptr cellIdsItem = this->parameters()->findString("cell ids"); - for (auto cellIt = cellIdsItem->begin(); cellIt != cellIdsItem->end(); ++cellIt) - { - cells.insert(std::stoll(*cellIt)); - } - } - - // Construct a CellSet from the HandleRange. - smtk::mesh::CellSet cellset(resource, cells); - - // Construct a mesh Selection from the cellset. - smtk::mesh::Selection::Ptr meshSelection = - smtk::mesh::Selection::create(cellset, this->m_manager); - - // Access the selection's mesh (this registers the mesh with the underlying - // resource) - (void)meshSelection->mesh(); - - // Create a new result - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with created components - result->findComponent("created")->appendValue(meshSelection); - smtk::operation::MarkGeometry().markModified(meshSelection); - - // Return with success - return result; -} - -void SelectCells::generateSummary(Operation::Result& /*unused*/) {} - -const char* SelectCells::xmlDescription() const -{ - return SelectCells_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/SelectCells.h b/smtk/mesh/operators/SelectCells.h deleted file mode 100644 index 92f44a41424b403d36fc6b523de1fa11275adf1e..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/SelectCells.h +++ /dev/null @@ -1,39 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_SelectCells_h -#define smtk_mesh_SelectCells_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Construct a mesh selection from a mesh resource and a list of cell ids - */ -class SMTKCORE_EXPORT SelectCells : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::SelectCells); - smtkCreateMacro(SelectCells); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - - void generateSummary(Result&) override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/operators/SelectCells.sbt b/smtk/mesh/operators/SelectCells.sbt deleted file mode 100644 index e773d714b6c35afb1d2c241b5fd3512fdd9d405a..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/SelectCells.sbt +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - Construct a mesh selection from a mesh resource and a list of - cell ids. - - - - - - - - - - - - - - - diff --git a/smtk/mesh/operators/SetMeshName.cxx b/smtk/mesh/operators/SetMeshName.cxx deleted file mode 100644 index deeb1a0e2117932f93b525dda4fb4af3e3241826..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/SetMeshName.cxx +++ /dev/null @@ -1,62 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/operators/SetMeshName.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/mesh/operators/SetMeshName_xml.h" - -namespace smtk -{ -namespace mesh -{ - -smtk::mesh::SetMeshName::Result SetMeshName::operateInternal() -{ - // Access the name to use when renaming the meshset - smtk::attribute::StringItem::Ptr nameItem = this->parameters()->findString("name"); - - // Access the meshset to rename - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(); - smtk::mesh::MeshSet meshset = meshComponent->mesh(); - - // Set the name of the meshset - bool success = meshset.setName(nameItem->value()); - - if (!success) - { - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Create a new result - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with modified components - result->findComponent("modified")->appendValue(meshComponent); - - // Return with success - return result; -} - -const char* SetMeshName::xmlDescription() const -{ - return SetMeshName_xml; -} - -} //namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/SetMeshName.h b/smtk/mesh/operators/SetMeshName.h deleted file mode 100644 index e0d7b5469b7efe7cd3aeb2e6c66f05d3e9b9c4f5..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/SetMeshName.h +++ /dev/null @@ -1,38 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_SetMeshName_h -#define smtk_mesh_SetMeshName_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Set the name of a meshset. - */ -class SMTKCORE_EXPORT SetMeshName : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::SetMeshName); - smtkCreateMacro(SetMeshName); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; - -} //namespace mesh -} // namespace smtk - -#endif // smtk_mesh_SetMeshName_h diff --git a/smtk/mesh/operators/SetMeshName.sbt b/smtk/mesh/operators/SetMeshName.sbt deleted file mode 100644 index 02129e0ca3b265e1586ce60a9b90ea2d444184d2..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/SetMeshName.sbt +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - Set a mesh name. - - - <p>Set a mesh name. - <p>This operator sets the name of a meshset. - - - - - - - - - - diff --git a/smtk/mesh/operators/Subtract.cxx b/smtk/mesh/operators/Subtract.cxx deleted file mode 100644 index 157c11c17f95bd6c50c7c6efa1ae067eb0c8d6d3..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Subtract.cxx +++ /dev/null @@ -1,74 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/operators/Subtract.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/mesh/operators/Subtract_xml.h" - -namespace smtk -{ -namespace mesh -{ - -smtk::mesh::Subtract::Result Subtract::operateInternal() -{ - // Access the minuend and its resource - smtk::mesh::MeshSet minuend = - this->parameters()->associations()->valueAs()->mesh(); - const smtk::mesh::Resource::Ptr& resource = minuend.resource(); - - // Access the subtrahends - smtk::attribute::ComponentItemPtr subtrahends = this->parameters()->findComponent("subtrahend"); - - // For each subtrahend, subtract it from the minuend - smtk::mesh::HandleRange differenceRange = minuend.cells().range(); - for (std::size_t i = 0; i < subtrahends->numberOfValues(); ++i) - { - differenceRange -= subtrahends->valueAs(i)->mesh().cells().range(); - } - - // Create a new result - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - smtk::mesh::MeshSet difference = - resource->createMesh(smtk::mesh::CellSet(resource, differenceRange)); - difference.setName("difference"); - - smtk::mesh::Component::Ptr differenceComponent = smtk::mesh::Component::create(difference); - - // Access the attribute associated with modified components - result->findComponent("created")->appendValue(differenceComponent); - - // Mark the minuend and difference as having a modified geometry. - smtk::operation::MarkGeometry().markModified( - this->parameters()->associations()->valueAs()); - smtk::operation::MarkGeometry().markModified(differenceComponent); - - // Return with success - return result; -} - -const char* Subtract::xmlDescription() const -{ - return Subtract_xml; -} - -} //namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/Subtract.h b/smtk/mesh/operators/Subtract.h deleted file mode 100644 index 82983cdb451e2a77776d1df1db713e56350e1889..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Subtract.h +++ /dev/null @@ -1,38 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_Subtract_h -#define smtk_mesh_Subtract_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Subtract one meshset from another. - */ -class SMTKCORE_EXPORT Subtract : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::Subtract); - smtkCreateMacro(Subtract); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; - -} //namespace mesh -} // namespace smtk - -#endif // smtk_mesh_Subtract_h diff --git a/smtk/mesh/operators/Subtract.sbt b/smtk/mesh/operators/Subtract.sbt deleted file mode 100644 index ff42e345cdb3f54fc6672f3fbe7654d00eb788ea..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Subtract.sbt +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - The meshset from which meshsets are subtracted. - - - - - - - The meshsets being subtracted. - - - - - Subtract meshsets from a meshset. - - - <p>Subtract meshsets from a meshset. - <p>This operator performs a set subtraction on the - components of meshsets. - - - - - - - - - - diff --git a/smtk/mesh/operators/Transform.cxx b/smtk/mesh/operators/Transform.cxx deleted file mode 100644 index cc9cedf5bf8ff8dc6022c4580c691773b115a99b..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Transform.cxx +++ /dev/null @@ -1,167 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/mesh/operators/Transform.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/ApplyToMesh.h" - -#include "smtk/model/Session.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/mesh/operators/Transform_xml.h" - -#include - -#ifndef M_PI -#define M_PI 3.14159265358979323846264338327950288 -#endif - -namespace smtk -{ -namespace mesh -{ - -smtk::mesh::Transform::Result Transform::operateInternal() -{ - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - - // Access the scale parameters - smtk::attribute::DoubleItem::Ptr scaleItem = this->parameters()->findDouble("scale"); - std::array scale = { scaleItem->value(0), scaleItem->value(1), scaleItem->value(2) }; - - // Access the rotate parameters - smtk::attribute::DoubleItem::Ptr rotateItem = this->parameters()->findDouble("rotate"); - std::array rotate = { rotateItem->value(0), - rotateItem->value(1), - rotateItem->value(2) }; - double cosTheta = cos(rotate[0] * M_PI / 180.); - double sinTheta = sin(rotate[0] * M_PI / 180.); - double cosPhi = cos(rotate[1] * M_PI / 180.); - double sinPhi = sin(rotate[1] * M_PI / 180.); - double cosPsi = cos(rotate[2] * M_PI / 180.); - double sinPsi = sin(rotate[2] * M_PI / 180.); - - // Access the translate parameters - smtk::attribute::DoubleItem::Ptr translateItem = this->parameters()->findDouble("translate"); - std::array translate = { translateItem->value(0), - translateItem->value(1), - translateItem->value(2) }; - - auto transformFn = [=](std::array p) { - for (std::size_t i = 0; i < 3; i++) - { - p[i] *= scale[i]; - } - - // From https://en.wikipedia.org/wiki/Euler_angles#Intrinsic_rotations : - // VTK uses Tait-Bryan Y_1 X_2 Z_3 angles to store orientation; - // This is the corresponding direction cosine matrix (DCM) for - // theta = X, phi = Y, psi = Z: - - std::array tmp = { 0., 0., 0. }; - - std::array, 3> R_x = { - { { 1., 0., 0. }, { 0., cosTheta, -sinTheta }, { 0., sinTheta, cosTheta } } - }; - for (std::size_t i = 0; i < 3; i++) - { - for (std::size_t j = 0; j < 3; j++) - { - tmp[i] += R_x[i][j] * p[j]; - } - } - p = tmp; - tmp = { 0., 0., 0. }; - - std::array, 3> R_y = { - { { cosPhi, 0., sinPhi }, { 0., 1., 0. }, { -sinPhi, 0., cosPhi } } - }; - for (std::size_t i = 0; i < 3; i++) - { - for (std::size_t j = 0; j < 3; j++) - { - tmp[i] += R_y[i][j] * p[j]; - } - } - p = tmp; - tmp = { 0., 0., 0. }; - - std::array, 3> R_z = { - { { cosPsi, -sinPsi, 0. }, { sinPsi, cosPsi, 0. }, { 0., 0., 1. } } - }; - for (std::size_t i = 0; i < 3; i++) - { - for (std::size_t j = 0; j < 3; j++) - { - tmp[i] += R_z[i][j] * p[j]; - } - } - p = tmp; - tmp = { 0., 0., 0. }; - - for (std::size_t i = 0; i < 3; i++) - { - p[i] += translate[i]; - } - - return p; - }; - - // Access the attribute associated with the modified meshes - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with the modified model - smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); - - // apply the interpolator to the meshes and populate the result attributes - for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) - { - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); - smtk::mesh::MeshSet mesh = meshComponent->mesh(); - - bool success = smtk::mesh::utility::applyWarp(transformFn, mesh); - - if (!success) - { - smtkErrorMacro(this->log(), "Transform failed."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - modified->appendValue(meshComponent); - smtk::operation::MarkGeometry().markModified(meshComponent); - - smtk::model::EntityRefArray entities; - bool entitiesAreValid = mesh.modelEntities(entities); - if (entitiesAreValid && !entities.empty()) - { - smtk::model::Model model = entities[0].owningModel(); - modified->appendValue(model.component()); - smtk::operation::MarkGeometry().markModified(model.component()); - } - } - - return result; -} - -const char* Transform::xmlDescription() const -{ - return Transform_xml; -} - -} //namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/Transform.h b/smtk/mesh/operators/Transform.h deleted file mode 100644 index bf1f0511fdb4ee0bacb65af930eb80e98dc8cfac..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Transform.h +++ /dev/null @@ -1,38 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_Transform_h -#define smtk_mesh_Transform_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Transform a mesh. - */ -class SMTKCORE_EXPORT Transform : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::Transform); - smtkCreateMacro(Transform); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; - -} //namespace mesh -} // namespace smtk - -#endif // smtk_mesh_Transform_h diff --git a/smtk/mesh/operators/Transform.sbt b/smtk/mesh/operators/Transform.sbt deleted file mode 100644 index 4c5ded0abaaf97dc45c1e28e66f05436cdc6ebdb..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Transform.sbt +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - Transform a mesh. - - - - - - - - - Translate mesh? If so, specify a vector. - - Enabling this item allows you to specify a vector to add to each original point - of the mesh. - Translation is applied after scaling and rotation; - therefore the vector is not modified by the specifed scaling and rotation (if any). - - 0, 0, 0 - - - - Scale mesh? If so, specify a scale factor for each axis. - - - Enabling this item allows you to specify a scale factor per axis for the - mesh. - Scaling is performed about the origin before rotation and translation. - - 1, 1, 1 - - - - Rotate mesh? If so, specify angles about each axis in degrees. - - - Enabling this item allows you to specify angles (in degrees) about which to rotate - the mesh. Angles are specified about the origin and rotation is applied - before translation. - - 0, 0, 0 - - - - - - - - - - - - - - - - - - - - - diff --git a/smtk/mesh/operators/UndoElevateMesh.cxx b/smtk/mesh/operators/UndoElevateMesh.cxx deleted file mode 100644 index ffa01e295b8eaef3652fb4571575f074c8331f2f..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/UndoElevateMesh.cxx +++ /dev/null @@ -1,105 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/UndoElevateMesh.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" - -#include "smtk/io/Logger.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/operators/UndoElevateMesh_xml.h" -#include "smtk/mesh/utility/ApplyToMesh.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/model/Model.h" - -namespace smtk -{ -namespace mesh -{ - -bool UndoElevateMesh::ableToOperate() -{ - if (!this->Superclass::ableToOperate()) - { - return false; - } - - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - if (!meshItem || meshItem->numberOfValues() == 0) - { - return false; - } - - for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) - { - smtk::mesh::MeshSet mesh = meshItem->valueAs(i)->mesh(); - smtk::mesh::PointField prior = mesh.pointField("_prior"); - if (!prior.isValid()) - { - return false; - } - } - - return true; -} - -UndoElevateMesh::Result UndoElevateMesh::operateInternal() -{ - // Access the mesh - smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); - - // Access the attribute associated with the modified meshes - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with the modified model - smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); - - // apply the interpolator to the meshes and populate the result attributes - for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) - { - smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); - smtk::mesh::MeshSet mesh = meshComponent->mesh(); - - bool success = smtk::mesh::utility::undoWarp(mesh); - - if (!success) - { - smtkErrorMacro(this->log(), "Undo elevate failed."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - modified->appendValue(meshComponent); - smtk::operation::MarkGeometry().markModified(meshComponent); - - smtk::model::EntityRefArray entities; - bool entitiesAreValid = mesh.modelEntities(entities); - if (entitiesAreValid && !entities.empty()) - { - smtk::model::Model model = entities[0].owningModel(); - modified->appendValue(model.component()); - smtk::operation::MarkGeometry().markModified(model.component()); - } - } - - return result; -} - -const char* UndoElevateMesh::xmlDescription() const -{ - return UndoElevateMesh_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/UndoElevateMesh.h b/smtk/mesh/operators/UndoElevateMesh.h deleted file mode 100644 index 9f6875b3aab727fddb32272287d95771ee5086c0..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/UndoElevateMesh.h +++ /dev/null @@ -1,43 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_operators_UndoElevateMesh_h -#define smtk_mesh_operators_UndoElevateMesh_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief A class for reversing the results of operators that elevate a mesh. - - Operations that use the methods defined in ApplyToMesh to deform a mesh's - coordinates can optionally cache the original unelevated coordinate values. - This operator then reverts the deformation performed by these operators. - */ -class SMTKCORE_EXPORT UndoElevateMesh : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::UndoElevateMesh); - smtkCreateMacro(UndoElevateMesh); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace smtk - -#endif // smtk_mesh_operators_UndoElevateMesh_h diff --git a/smtk/mesh/operators/UndoElevateMesh.sbt b/smtk/mesh/operators/UndoElevateMesh.sbt deleted file mode 100644 index 8009ea9e844bfe55873deef4ec0b5f8a9a9464ea..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/UndoElevateMesh.sbt +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - Restore a mesh to its unelevated state. - - - <p>Restore a mesh to its unelevated state. - <p>Some operators can distort a mesh's coordinates - (e.g. Mesh - Elevate). This operator removes the elevateing - applied by these operators. - - - - - - - - - - - - diff --git a/smtk/mesh/operators/Write.cxx b/smtk/mesh/operators/Write.cxx deleted file mode 100644 index 991b41853664da2cbe333649de4c3e4726d31e1f..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Write.cxx +++ /dev/null @@ -1,188 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/Write.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/Definition.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/FileItemDefinition.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/Resource.h" -#include "smtk/attribute/ResourceItem.h" - -#include "smtk/io/WriteMesh.h" -#include "smtk/io/mesh/MeshIO.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/Write_xml.h" - -#include "smtk/model/Resource.h" -#include "smtk/model/Session.h" - -#include -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} -} // namespace - -namespace smtk -{ -namespace mesh -{ - -bool Write::ableToOperate() -{ - return this->Superclass::ableToOperate(); -} - -Write::Result Write::operateInternal() -{ - std::string outputfile = this->parameters()->findFile("filename")->value(); - - smtk::io::mesh::Subset componentToWrite = - static_cast(this->parameters()->findInt("write-component")->value()); - - smtk::attribute::ReferenceItem::Ptr resourceItem = this->parameters()->associations(); - - // for multiple meshes, we suffix the file name root with ascending integers - std::string root = outputfile.substr(0, outputfile.find_last_of('.')); - std::string ext = outputfile.substr(outputfile.find_last_of('.')); - int index = 0; - - std::vector generatedFiles; - - for (std::size_t i = 0; i < resourceItem->numberOfValues(); i++) - { - smtk::mesh::ResourcePtr resource = resourceItem->valueAs(i); - bool fileWriteSuccess = false; - - if (resource) - { - if (resourceItem->numberOfValues() > 1) - { - std::stringstream s; - s << root << "_" << index << ext; - outputfile = s.str(); - } - - smtk::io::WriteMesh write; - fileWriteSuccess = write(outputfile, resource, componentToWrite); - - if (fileWriteSuccess) - { - ++index; - generatedFiles.push_back(outputfile); - } - } - - if (!fileWriteSuccess) - { - for (auto&& file : generatedFiles) - { - cleanup(file); - } - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - return result; -} - -Write::Specification Write::createSpecification() -{ - Specification spec = this->smtk::operation::XMLOperation::createSpecification(); - auto writeDef = spec->findDefinition("write"); - - std::vector fileItemDefinitions; - auto fileItemDefinitionFilter = [](smtk::attribute::FileItemDefinition::Ptr ptr) { - return ptr->name() == "filename"; - }; - writeDef->filterItemDefinitions(fileItemDefinitions, fileItemDefinitionFilter); - - assert(fileItemDefinitions.size() == 1); - - std::stringstream fileFilters; - bool firstFormat = true; - for (auto& ioType : smtk::io::WriteMesh::SupportedIOTypes()) - { - for (const auto& format : ioType->FileFormats()) - { - if (format.CanWrite()) - { - if (firstFormat) - { - firstFormat = false; - } - else - { - fileFilters << ";;"; - } - - fileFilters << format.Name << "("; - bool first = true; - for (const auto& ext : format.Extensions) - { - if (first) - { - first = false; - } - else - { - fileFilters << " "; - } - fileFilters << "*" << ext; - } - fileFilters << ")"; - } - } - } - fileItemDefinitions[0]->setFileFilters(fileFilters.str()); - return spec; -} - -void Write::markModifiedResources(Write::Result& /*unused*/) -{ - auto resourceItem = this->parameters()->associations(); - for (auto rit = resourceItem->begin(); rit != resourceItem->end(); ++rit) - { - auto resource = std::dynamic_pointer_cast(*rit); - - // Set the resource as unmodified from its persistent (i.e. on-disk) state - resource->setClean(true); - } -} - -const char* Write::xmlDescription() const -{ - return Write_xml; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/Write.h b/smtk/mesh/operators/Write.h deleted file mode 100644 index 9345e6c94eca220914574af3f27ca75bad03b4fe..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Write.h +++ /dev/null @@ -1,42 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_Write_h -#define smtk_mesh_Write_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief A class for writing meshes to file. - */ -class SMTKCORE_EXPORT Write : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::Write); - smtkCreateMacro(Write); - smtkSharedFromThisMacro(smtk::operation::Operation); - smtkSuperclassMacro(smtk::operation::XMLOperation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - Specification createSpecification() override; - const char* xmlDescription() const override; - void markModifiedResources(Result&) override; -}; - -} // namespace mesh -} // namespace smtk - -#endif // smtk_mesh_Write_h diff --git a/smtk/mesh/operators/Write.sbt b/smtk/mesh/operators/Write.sbt deleted file mode 100644 index 27b22b45f8ae33ea5647056d4b24eff4873bdf29..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/Write.sbt +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - Write a mesh to disk. - - - <p>Write a mesh to disk. - <p>This operator creates a file representing the - selected mesh and saves it to disk. The created file is - readable by this application, and the resulting - mesh is guaranteed to contain all of the information from - the original mesh. - - - - - - - - - - 0 - 1 - 2 - 3 - - - - - - - - - diff --git a/smtk/mesh/operators/WriteResource.cxx b/smtk/mesh/operators/WriteResource.cxx deleted file mode 100644 index 80bc351b4b29574750a813a45a29f8a60f7d794f..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/WriteResource.cxx +++ /dev/null @@ -1,225 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/operators/WriteResource.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/common/Archive.h" -#include "smtk/common/CompilerInformation.h" -#include "smtk/common/Paths.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/WriteResource_xml.h" - -#include "smtk/mesh/operators/Write.h" - -#include "smtk/mesh/json/jsonResource.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "nlohmann/json.hpp" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -SMTK_THIRDPARTY_POST_INCLUDE - -#include - -using namespace smtk::model; - -namespace smtk -{ -namespace mesh -{ - -bool WriteResource::ableToOperate() -{ - if (!this->smtk::operation::XMLOperation::ableToOperate()) - { - return false; - } - - if (this->parameters()->associations()->numberOfValues() < 1) - { - return false; - } - - return true; -} - -WriteResource::Result WriteResource::operateInternal() -{ - auto resourceItem = this->parameters()->associations(); - - smtk::mesh::Resource::Ptr resource = - std::dynamic_pointer_cast(resourceItem->value()); - - // Serialize resource into a set of JSON records: - nlohmann::json j = resource; - if (j.is_null()) - { - smtkErrorMacro(log(), "Unable to serialize mesh to json object."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Check if the mesh files are to be archived into a single file - auto archive = this->parameters()->findVoid("archive"); - if (archive && archive->isEnabled()) - { - boost::filesystem::path smtkFilename("index.json"); - boost::filesystem::path meshFilename("mesh.h5m"); - - boost::filesystem::path temp = - boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); - if (!boost::filesystem::create_directories(temp)) - { - smtkErrorMacro(this->log(), "Failed to create a temporary directory."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - boost::filesystem::path tmpsmtkPath = temp / smtkFilename; - boost::filesystem::path tmpMeshPath = temp / meshFilename; - j["Mesh URL"] = meshFilename.string(); - - // Write the smtk index - { - std::ofstream file(tmpsmtkPath.string()); - if (!file.good()) - { - smtkErrorMacro(log(), "Unable to open \"" << tmpsmtkPath.string() << "\" for writing."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - file << j.dump(2); - file.close(); - } - - // Write the mesh file - { - // Create a write operator - smtk::mesh::Write::Ptr writeOp = smtk::mesh::Write::create(); - writeOp->parameters()->findFile("filename")->setValue(tmpMeshPath.string()); - - // Set the entity association - writeOp->parameters()->associate(resource); - - // Execute the operation - smtk::operation::Operation::Result writeOpResult = writeOp->operate(this->childKey()); - - // Test for success - if ( - writeOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - smtkErrorMacro(log(), "Unable to write mesh to \"" << tmpMeshPath.string() << "\"."); - ::boost::filesystem::remove_all(temp); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - - // Populate an archive with the smtk index and mesh file - { - smtk::common::Archive archive(resource->location()); - archive.insert(tmpsmtkPath.string(), smtkFilename.string()); - archive.insert(tmpMeshPath.string(), meshFilename.string()); - if (!archive.archive()) - { - smtkErrorMacro(log(), "Unable to archive files to \"" + resource->location() + "\"."); - ::boost::filesystem::remove_all(temp); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - - // Clean up temporary files. - { - ::boost::filesystem::remove_all(temp); - } - - return this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - } - else - { - std::string meshFilename = smtk::common::Paths::stem(resource->location()) + ".h5m"; - std::string meshPath = smtk::common::Paths::replaceExtension(resource->location(), ".h5m"); - - j["Mesh URL"] = meshFilename; - - { - std::ofstream file(resource->location()); - if (!file.good()) - { - smtkErrorMacro(log(), "Unable to open \"" << resource->location() << "\" for writing."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - file << j.dump(2); - file.close(); - } - - // Create a write operator - smtk::mesh::Write::Ptr writeOp = smtk::mesh::Write::create(); - writeOp->parameters()->findFile("filename")->setValue(meshPath); - - // Set the entity association - writeOp->parameters()->associate(resource); - - // Execute the operation - smtk::operation::Operation::Result writeOpResult = writeOp->operate(this->childKey()); - - // Test for success - if ( - writeOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - smtkErrorMacro(log(), "Unable to write files to \"" + meshPath + "\"."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Add the mesh file to the result's list of additional files - auto result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - result->findFile("additional files")->appendValue(meshPath); - - return result; - } -} - -const char* WriteResource::xmlDescription() const -{ - return WriteResource_xml; -} - -void WriteResource::markModifiedResources(WriteResource::Result& /*unused*/) -{ - auto resourceItem = this->parameters()->associations(); - for (auto rit = resourceItem->begin(); rit != resourceItem->end(); ++rit) - { - auto resource = std::dynamic_pointer_cast(*rit); - - // Set the resource as unmodified from its persistent (i.e. on-disk) state - resource->setClean(true); - } -} - -bool write( - const smtk::resource::ResourcePtr& resource, - const std::shared_ptr& managers) -{ - (void)managers; - WriteResource::Ptr write = WriteResource::create(); - write->parameters()->associate(resource); - WriteResource::Result result = write->operate(); - return ( - result->findInt("outcome")->value() == static_cast(WriteResource::Outcome::SUCCEEDED)); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/operators/WriteResource.h b/smtk/mesh/operators/WriteResource.h deleted file mode 100644 index 4410128b00d573ebb685e8b7099354d8ffb141d9..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/WriteResource.h +++ /dev/null @@ -1,44 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_WriteResource_h -#define smtk_mesh_WriteResource_h - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace mesh -{ - -/**\brief Write an smtk mesh file. - */ -class SMTKCORE_EXPORT WriteResource : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::mesh::WriteResource); - smtkCreateMacro(WriteResource); - smtkSharedFromThisMacro(smtk::operation::Operation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; - void markModifiedResources(Result&) override; -}; - -SMTKCORE_EXPORT bool write( - const smtk::resource::ResourcePtr&, - const std::shared_ptr&); -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/operators/WriteResource.sbt b/smtk/mesh/operators/WriteResource.sbt deleted file mode 100644 index 96a255eaceeae2826947ca43e93cbb29998a20e1..0000000000000000000000000000000000000000 --- a/smtk/mesh/operators/WriteResource.sbt +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - Archive all related files into a single archive. - - - - - - - - - - - - - - - diff --git a/smtk/mesh/plugin/CMakeLists.txt b/smtk/mesh/plugin/CMakeLists.txt deleted file mode 100644 index 6ef2012825839bed6a6bc2b62ce846e4965e9f4c..0000000000000000000000000000000000000000 --- a/smtk/mesh/plugin/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -smtk_add_plugin(smtkMeshPlugin - REGISTRAR smtk::mesh::Registrar - REGISTRAR_HEADER smtk/mesh/resource/Registrar.h - MANAGERS smtk::operation::Manager - smtk::resource::Manager - PARAVIEW_PLUGIN_ARGS - VERSION 1.0) diff --git a/smtk/mesh/plugin/paraview.plugin b/smtk/mesh/plugin/paraview.plugin deleted file mode 100644 index c08d5b9aa60c28b316419d514a161aa5879f4d94..0000000000000000000000000000000000000000 --- a/smtk/mesh/plugin/paraview.plugin +++ /dev/null @@ -1,4 +0,0 @@ -NAME - smtkMeshPlugin -DESCRIPTION - SMTK mesh plugin for ParaView diff --git a/smtk/mesh/pybind11/CMakeLists.txt b/smtk/mesh/pybind11/CMakeLists.txt deleted file mode 100644 index 9d1a4e124f3b9311d77edc9b3b1bfa1944ee3ff9..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set(library_name "_smtkPybindMesh") -set(module_path "mesh") -set(build_path "${CMAKE_BINARY_DIR}/${SMTK_PYTHON_MODULEDIR}/smtk/${module_path}") -set(install_path "${SMTK_PYTHON_MODULEDIR}/smtk/${module_path}") - -pybind11_add_module(${library_name} PybindMesh.cxx) -target_include_directories(${library_name} PUBLIC - $ - ) -target_link_libraries(${library_name} LINK_PUBLIC smtkCore) -set_target_properties(${library_name} - PROPERTIES - CXX_VISIBILITY_PRESET hidden - COMPILE_FLAGS ${SMTK_PYBIND11_FLAGS} - LIBRARY_OUTPUT_DIRECTORY "${build_path}" - ) - -# Install library -install(TARGETS ${library_name} DESTINATION "${install_path}") - -# Create and install module __init__.py -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py" - "${build_path}/__init__.py" @ONLY - ) - -install( - FILES "${build_path}/__init__.py" - DESTINATION "${install_path}" - ) diff --git a/smtk/mesh/pybind11/PybindApplyToMesh.h b/smtk/mesh/pybind11/PybindApplyToMesh.h deleted file mode 100644 index f3e00bc4015c3a51002919c9cc2426e4099d9ad6..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindApplyToMesh.h +++ /dev/null @@ -1,52 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_utility_ApplyToMesh_h -#define pybind_smtk_mesh_utility_ApplyToMesh_h - -#include -#include -#include - -#include "smtk/mesh/utility/ApplyToMesh.h" - -namespace py = pybind11; - -inline void pybind11_init_smtk_mesh_utility_applyScalarCellField(py::module &m) -{ - m.def("applyScalarCellField", &smtk::mesh::utility::applyScalarCellField, "", py::arg("arg0"), py::arg("name"), py::arg("ms")); -} - -inline void pybind11_init_smtk_mesh_utility_applyScalarPointField(py::module &m) -{ - m.def("applyScalarPointField", &smtk::mesh::utility::applyScalarPointField, "", py::arg("arg0"), py::arg("name"), py::arg("ms")); -} - -inline void pybind11_init_smtk_mesh_utility_applyVectorCellField(py::module &m) -{ - m.def("applyVectorCellField", &smtk::mesh::utility::applyVectorCellField, "", py::arg("arg0"), py::arg("name"), py::arg("ms")); -} - -inline void pybind11_init_smtk_mesh_utility_applyVectorPointField(py::module &m) -{ - m.def("applyVectorPointField", &smtk::mesh::utility::applyVectorPointField, "", py::arg("arg0"), py::arg("name"), py::arg("ms")); -} - -inline void pybind11_init_smtk_mesh_utility_applyWarp(py::module &m) -{ - m.def("applyWarp", &smtk::mesh::utility::applyWarp, "", py::arg("arg0"), py::arg("ms"), py::arg("storePriorCoordinates") = false); -} - -inline void pybind11_init_smtk_mesh_utility_undoWarp(py::module &m) -{ - m.def("undoWarp", &smtk::mesh::utility::undoWarp, "", py::arg("ms")); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindCellField.h b/smtk/mesh/pybind11/PybindCellField.h deleted file mode 100644 index fee0fa53d301dd8c62b11df22223df5613ee7d54..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindCellField.h +++ /dev/null @@ -1,54 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_CellField_h -#define pybind_smtk_mesh_CellField_h - -#include -#include - -#include "smtk/mesh/core/CellField.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/MeshSet.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::CellField > pybind11_init_smtk_mesh_CellField(py::module &m) -{ - PySharedPtrClass< smtk::mesh::CellField > instance(m, "CellField"); - instance - .def(py::init<>()) - .def(py::init<::smtk::mesh::MeshSet const &, ::std::string const &>()) - .def(py::init<::smtk::mesh::CellField const &>()) - .def("__ne__", (bool (smtk::mesh::CellField::*)(::smtk::mesh::CellField const &) const) &smtk::mesh::CellField::operator!=) - .def("__lt__", (bool (smtk::mesh::CellField::*)(::smtk::mesh::CellField const &) const) &smtk::mesh::CellField::operator<) - .def("deepcopy", (smtk::mesh::CellField & (smtk::mesh::CellField::*)(::smtk::mesh::CellField const &)) &smtk::mesh::CellField::operator=) - .def("__eq__", (bool (smtk::mesh::CellField::*)(::smtk::mesh::CellField const &) const) &smtk::mesh::CellField::operator==) - .def("cells", &smtk::mesh::CellField::cells) - .def("dimension", &smtk::mesh::CellField::dimension) - .def("type", &smtk::mesh::CellField::type) - .def("_get_double", [](smtk::mesh::CellField& cf) { std::vector tmp(cf.size() * cf.dimension()); cf.get(tmp.data()); return tmp; }) - .def("_get_double", [](smtk::mesh::CellField& cf, const smtk::mesh::HandleRange& cellIds){ std::vector tmp(cellIds.size() * cf.dimension()); cf.get(cellIds, tmp.data()); return tmp; }) - .def("_get_int", [](smtk::mesh::CellField& cf) { std::vector tmp(cf.size() * cf.dimension()); cf.get(tmp.data()); return tmp; }) - .def("_get_int", [](smtk::mesh::CellField& cf, const smtk::mesh::HandleRange& cellIds) { std::vector tmp(cellIds.size() * cf.dimension()); cf.get(cellIds, tmp.data()); return tmp; }) - .def("isValid", &smtk::mesh::CellField::isValid) - .def("meshset", &smtk::mesh::CellField::meshset) - .def("name", &smtk::mesh::CellField::name) - .def("set", [](smtk::mesh::CellField& cf, const std::vector& data) { return cf.set(data.data()); }) - .def("set", [](smtk::mesh::CellField& cf, const smtk::mesh::HandleRange& cellIds, const std::vector& data) { return cf.set(cellIds, data.data()); }) - .def("set", [](smtk::mesh::CellField& cf, const std::vector& data) { return cf.set(data.data()); }) - .def("set", [](smtk::mesh::CellField& cf, const smtk::mesh::HandleRange& cellIds, const std::vector& data) { return cf.set(cellIds, data.data()); }) - .def("size", &smtk::mesh::CellField::size) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindCellSet.h b/smtk/mesh/pybind11/PybindCellSet.h deleted file mode 100644 index c5fd9d1c51f679713e9e1f98e9dae39cf5ce54d7..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindCellSet.h +++ /dev/null @@ -1,76 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_CellSet_h -#define pybind_smtk_mesh_CellSet_h - -#include - -#include "smtk/mesh/core/CellSet.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::CellSet > pybind11_init_smtk_mesh_CellSet(py::module &m) -{ - PySharedPtrClass< smtk::mesh::CellSet > instance(m, "CellSet"); - instance - .def(py::init<::smtk::mesh::ResourcePtr const &, ::smtk::mesh::HandleRange const &>()) - .def(py::init<::smtk::mesh::ConstResourcePtr const &, ::smtk::mesh::HandleRange const &>()) - .def(py::init<::smtk::mesh::ResourcePtr const &, ::std::vector > const &>()) - .def(py::init<::smtk::mesh::ResourcePtr const &, ::std::set, std::allocator > const &>()) - .def(py::init<::smtk::mesh::CellSet const &>()) - .def("__ne__", (bool (smtk::mesh::CellSet::*)(::smtk::mesh::CellSet const &) const) &smtk::mesh::CellSet::operator!=) - .def("deepcopy", (smtk::mesh::CellSet & (smtk::mesh::CellSet::*)(::smtk::mesh::CellSet const &)) &smtk::mesh::CellSet::operator=) - .def("__eq__", (bool (smtk::mesh::CellSet::*)(::smtk::mesh::CellSet const &) const) &smtk::mesh::CellSet::operator==) - .def("append", &smtk::mesh::CellSet::append, py::arg("other")) - .def("resource", &smtk::mesh::CellSet::resource) - .def("is_empty", &smtk::mesh::CellSet::is_empty) - .def("pointConnectivity", (smtk::mesh::PointConnectivity (smtk::mesh::CellSet::*)() const) &smtk::mesh::CellSet::pointConnectivity) - .def("pointConnectivity", (smtk::mesh::PointConnectivity (smtk::mesh::CellSet::*)(::size_t) const) &smtk::mesh::CellSet::pointConnectivity, py::arg("arg0")) - .def("points", (smtk::mesh::PointSet (smtk::mesh::CellSet::*)(bool) const) &smtk::mesh::CellSet::points, py::arg("boundary_only") = false) - .def("points", (smtk::mesh::PointSet (smtk::mesh::CellSet::*)(::size_t) const) &smtk::mesh::CellSet::points, py::arg("arg0")) - .def("range", &smtk::mesh::CellSet::range) - .def("size", &smtk::mesh::CellSet::size) - .def("types", &smtk::mesh::CellSet::types) - ; - return instance; -} - -inline void pybind11_init_smtk_mesh_cell_for_each(py::module &m) -{ - m.def("for_each", (void (*)(const smtk::mesh::CellSet&, smtk::mesh::CellForEach&)) &smtk::mesh::for_each, "", py::arg("a"), py::arg("filter")); -} - -inline void pybind11_init_smtk_mesh_cell_point_difference(py::module &m) -{ - m.def("point_difference", (smtk::mesh::CellSet (*)(const smtk::mesh::CellSet&, const smtk::mesh::CellSet&, smtk::mesh::ContainmentType)) &smtk::mesh::point_difference, "", py::arg("a"), py::arg("b"), py::arg("t")); -} - -inline void pybind11_init_smtk_mesh_cell_point_intersect(py::module &m) -{ - m.def("point_intersect", (smtk::mesh::CellSet (*)(const smtk::mesh::CellSet&, const smtk::mesh::CellSet&, smtk::mesh::ContainmentType)) &smtk::mesh::point_intersect, "", py::arg("a"), py::arg("b"), py::arg("t")); -} - -inline void pybind11_init_smtk_mesh_cell_set_difference(py::module &m) -{ - m.def("set_difference", (smtk::mesh::CellSet (*)(const smtk::mesh::CellSet&, const smtk::mesh::CellSet&)) &smtk::mesh::set_difference, "", py::arg("a"), py::arg("b")); -} - -inline void pybind11_init_smtk_mesh_cell_set_intersect(py::module &m) -{ - m.def("set_intersect", (smtk::mesh::CellSet (*)(const smtk::mesh::CellSet&, const smtk::mesh::CellSet&)) &smtk::mesh::set_intersect, "", py::arg("a"), py::arg("b")); -} - -inline void pybind11_init_smtk_mesh_cell_set_union(py::module &m) -{ - m.def("set_union", (smtk::mesh::CellSet (*)(const smtk::mesh::CellSet&, const smtk::mesh::CellSet&)) &smtk::mesh::set_union, "", py::arg("a"), py::arg("b")); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindCellTypes.h b/smtk/mesh/pybind11/PybindCellTypes.h deleted file mode 100644 index 7e043222861f2dcd5fd6bd9b55e1b2db415240a8..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindCellTypes.h +++ /dev/null @@ -1,47 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_CellTypes_h -#define pybind_smtk_mesh_CellTypes_h - -#include - -#include "smtk/mesh/core/CellTraits.h" -#include "smtk/mesh/core/CellTypes.h" - -namespace py = pybind11; - -inline void pybind11_init_smtk_mesh_CellType(py::module &m) -{ - py::enum_(m, "CellType") - .value("Vertex", smtk::mesh::CellType::Vertex) - .value("Line", smtk::mesh::CellType::Line) - .value("Triangle", smtk::mesh::CellType::Triangle) - .value("Quad", smtk::mesh::CellType::Quad) - .value("Polygon", smtk::mesh::CellType::Polygon) - .value("Tetrahedron", smtk::mesh::CellType::Tetrahedron) - .value("Pyramid", smtk::mesh::CellType::Pyramid) - .value("Wedge", smtk::mesh::CellType::Wedge) - .value("Hexahedron", smtk::mesh::CellType::Hexahedron) - .value("CellType_MAX", smtk::mesh::CellType::CellType_MAX) - .export_values(); -} - -inline void pybind11_init_smtk_mesh_verticesPerCell(py::module &m) -{ - m.def("verticesPerCell", &smtk::mesh::verticesPerCell, "", py::arg("ctype")); -} - -inline void pybind11_init_smtk_mesh_cellTypeSummary(py::module &m) -{ - m.def("cellTypeSummary", &smtk::mesh::cellTypeSummary, "", py::arg("ctype"), py::arg("flag") = 0); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindComponent.h b/smtk/mesh/pybind11/PybindComponent.h deleted file mode 100644 index 9a96618c1c8e6e14da1097b33a276032b22c0dc3..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindComponent.h +++ /dev/null @@ -1,44 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_Component_h -#define pybind_smtk_mesh_Component_h - -#include - -#include "smtk/mesh/core/Component.h" - -#include "smtk/common/UUID.h" -#include "smtk/common/pybind11/PybindUUIDTypeCaster.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/resource/Component.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::Component, smtk::resource::Component > pybind11_init_smtk_mesh_Component(py::module &m) -{ - PySharedPtrClass< smtk::mesh::Component, smtk::resource::Component > instance(m, "Component"); - instance - .def(py::init<::smtk::mesh::Component const &>()) - .def("deepcopy", (smtk::mesh::Component & (smtk::mesh::Component::*)(::smtk::mesh::Component const &)) &smtk::mesh::Component::operator=) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Component::*)()) &smtk::mesh::Component::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Component::*)() const) &smtk::mesh::Component::shared_from_this) - .def_static("create", (std::shared_ptr (*)(const smtk::mesh::ResourcePtr&, const smtk::common::UUID&)) &smtk::mesh::Component::create, py::arg("resource"), py::arg("id")) - .def_static("create", (std::shared_ptr (*)(const smtk::mesh::MeshSet&)) &smtk::mesh::Component::create, py::arg("meshset")) - .def("resource", &smtk::mesh::Component::resource) - .def("mesh", (smtk::mesh::MeshSet (smtk::mesh::Component::*)()) &smtk::mesh::Component::mesh) - .def_static("CastTo", [](const std::shared_ptr i) { - return std::dynamic_pointer_cast(i); - }) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindDeleteMesh.h b/smtk/mesh/pybind11/PybindDeleteMesh.h deleted file mode 100644 index 8623beca0b4f3d3db81b85196a7026685bbb0c13..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindDeleteMesh.h +++ /dev/null @@ -1,35 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_operators_DeleteMesh_h -#define pybind_smtk_mesh_operators_DeleteMesh_h - -#include - -#include "smtk/mesh/operators/DeleteMesh.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::DeleteMesh, smtk::operation::XMLOperation > pybind11_init_smtk_mesh_DeleteMesh(py::module &m) -{ - PySharedPtrClass< smtk::mesh::DeleteMesh, smtk::operation::XMLOperation > instance(m, "DeleteMesh"); - instance - .def("ableToOperate", &smtk::mesh::DeleteMesh::ableToOperate) - .def_static("create", (std::shared_ptr (*)()) &smtk::mesh::DeleteMesh::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::mesh::DeleteMesh::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::DeleteMesh::*)() const) &smtk::mesh::DeleteMesh::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::DeleteMesh::*)()) &smtk::mesh::DeleteMesh::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindDimensionTypes.h b/smtk/mesh/pybind11/PybindDimensionTypes.h deleted file mode 100644 index 795642eaf9a263e3bfd6f23b00dd69bd6f0495c5..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindDimensionTypes.h +++ /dev/null @@ -1,31 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_DimensionTypes_h -#define pybind_smtk_mesh_DimensionTypes_h - -#include - -#include "smtk/mesh/core/DimensionTypes.h" - -namespace py = pybind11; - -inline void pybind11_init_smtk_mesh_DimensionType(py::module &m) -{ - py::enum_(m, "DimensionType") - .value("Dims0", smtk::mesh::DimensionType::Dims0) - .value("Dims1", smtk::mesh::DimensionType::Dims1) - .value("Dims2", smtk::mesh::DimensionType::Dims2) - .value("Dims3", smtk::mesh::DimensionType::Dims3) - .value("DimensionType_MAX", smtk::mesh::DimensionType::DimensionType_MAX) - .export_values(); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindElevateMesh.h b/smtk/mesh/pybind11/PybindElevateMesh.h deleted file mode 100644 index e8548545d0a26d666fbdbbd74f3b03d94cc38dce..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindElevateMesh.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_operators_ElevateMesh_h -#define pybind_smtk_mesh_operators_ElevateMesh_h - -#include - -#include "smtk/mesh/operators/ElevateMesh.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::ElevateMesh, smtk::operation::XMLOperation > pybind11_init_smtk_mesh_ElevateMesh(py::module &m) -{ - PySharedPtrClass< smtk::mesh::ElevateMesh, smtk::operation::XMLOperation > instance(m, "ElevateMesh"); - instance - .def(py::init<>()) - .def("ableToOperate", &smtk::mesh::ElevateMesh::ableToOperate) - .def_static("create", (std::shared_ptr (*)()) &smtk::mesh::ElevateMesh::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::mesh::ElevateMesh::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::ElevateMesh::*)() const) &smtk::mesh::ElevateMesh::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::ElevateMesh::*)()) &smtk::mesh::ElevateMesh::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindExport.h b/smtk/mesh/pybind11/PybindExport.h deleted file mode 100644 index c9d7cde222829cef88d2dce6fdbfe40c5a8e7246..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindExport.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_operators_Export_h -#define pybind_smtk_mesh_operators_Export_h - -#include - -#include "smtk/mesh/operators/Export.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::Export, smtk::operation::XMLOperation > pybind11_init_smtk_mesh_Export(py::module &m) -{ - PySharedPtrClass< smtk::mesh::Export, smtk::operation::XMLOperation > instance(m, "Export"); - instance - .def(py::init<>()) - .def("ableToOperate", &smtk::mesh::Export::ableToOperate) - .def_static("create", (std::shared_ptr (*)()) &smtk::mesh::Export::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::mesh::Export::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Export::*)() const) &smtk::mesh::Export::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Export::*)()) &smtk::mesh::Export::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindExtractCanonicalIndices.h b/smtk/mesh/pybind11/PybindExtractCanonicalIndices.h deleted file mode 100644 index cdc19e8e3adc02729536b75df3f6039b0e8f0686..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindExtractCanonicalIndices.h +++ /dev/null @@ -1,51 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_ExtractCanonicalIndices_h -#define pybind_smtk_mesh_ExtractCanonicalIndices_h - -#include - -#include "smtk/mesh/utility/ExtractCanonicalIndices.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::utility::PreAllocatedCanonicalIndices > pybind11_init_smtk_mesh_PreAllocatedCanonicalIndices(py::module &m) -{ - PySharedPtrClass< smtk::mesh::utility::PreAllocatedCanonicalIndices > instance(m, "PreAllocatedCanonicalIndices"); - instance - .def(py::init<::smtk::mesh::utility::PreAllocatedCanonicalIndices const &>()) - .def(py::init<::int64_t *, ::int64_t *>()) - .def("deepcopy", (smtk::mesh::utility::PreAllocatedCanonicalIndices & (smtk::mesh::utility::PreAllocatedCanonicalIndices::*)(::smtk::mesh::utility::PreAllocatedCanonicalIndices const &)) &smtk::mesh::utility::PreAllocatedCanonicalIndices::operator=) - .def_static("determineAllocationLengths", &smtk::mesh::utility::PreAllocatedCanonicalIndices::determineAllocationLengths, py::arg("ms"), py::arg("numberOfCells")) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::utility::CanonicalIndices > pybind11_init_smtk_mesh_CanonicalIndices(py::module &m) -{ - PySharedPtrClass< smtk::mesh::utility::CanonicalIndices > instance(m, "CanonicalIndices"); - instance - .def(py::init<::smtk::mesh::utility::CanonicalIndices const &>()) - .def(py::init<>()) - .def("deepcopy", (smtk::mesh::utility::CanonicalIndices & (smtk::mesh::utility::CanonicalIndices::*)(::smtk::mesh::utility::CanonicalIndices const &)) &smtk::mesh::utility::CanonicalIndices::operator=) - .def("referenceCellIndices", &smtk::mesh::utility::CanonicalIndices::referenceCellIndices) - .def("canonicalIndices", &smtk::mesh::utility::CanonicalIndices::canonicalIndices) - .def("extract", (void (smtk::mesh::utility::CanonicalIndices::*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::MeshSet const &)) &smtk::mesh::utility::CanonicalIndices::extract, py::arg("ms"), py::arg("reference_ms")) - ; - return instance; -} - -inline void pybind11_init__extractCanonicalIndices(py::module &m) -{ - m.def("extractCanonicalIndices", (void (*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::MeshSet const &, ::smtk::mesh::utility::PreAllocatedCanonicalIndices &)) &smtk::mesh::utility::extractCanonicalIndices, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2")); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindExtractMeshConstants.h b/smtk/mesh/pybind11/PybindExtractMeshConstants.h deleted file mode 100644 index 8fbd226a9e012db204a816f3c6a83821e8737f70..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindExtractMeshConstants.h +++ /dev/null @@ -1,81 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_ExtractMeshConstants_h -#define pybind_smtk_mesh_ExtractMeshConstants_h - -#include - -#include "smtk/mesh/utility/ExtractMeshConstants.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::utility::PreAllocatedMeshConstants > pybind11_init_smtk_mesh_PreAllocatedMeshConstants(py::module &m) -{ - PySharedPtrClass< smtk::mesh::utility::PreAllocatedMeshConstants > instance(m, "PreAllocatedMeshConstants"); - instance - .def(py::init<::smtk::mesh::utility::PreAllocatedMeshConstants const &>()) - .def(py::init<::int64_t *, ::int64_t *>()) - .def("deepcopy", (smtk::mesh::utility::PreAllocatedMeshConstants & (smtk::mesh::utility::PreAllocatedMeshConstants::*)(::smtk::mesh::utility::PreAllocatedMeshConstants const &)) &smtk::mesh::utility::PreAllocatedMeshConstants::operator=) - .def_static("determineAllocationLengths", &smtk::mesh::utility::PreAllocatedMeshConstants::determineAllocationLengths, py::arg("ms"), py::arg("numberOfCells"), py::arg("numberOfPoints")) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::utility::MeshConstants > pybind11_init_smtk_mesh_MeshConstants(py::module &m) -{ - PySharedPtrClass< smtk::mesh::utility::MeshConstants > instance(m, "MeshConstants"); - instance - .def(py::init<::smtk::mesh::utility::MeshConstants const &>()) - .def(py::init<>()) - .def("deepcopy", (smtk::mesh::utility::MeshConstants & (smtk::mesh::utility::MeshConstants::*)(::smtk::mesh::utility::MeshConstants const &)) &smtk::mesh::utility::MeshConstants::operator=) - .def("cellData", &smtk::mesh::utility::MeshConstants::cellData) - .def("extractDirichlet", (void (smtk::mesh::utility::MeshConstants::*)(::smtk::mesh::MeshSet const &)) &smtk::mesh::utility::MeshConstants::extractDirichlet, py::arg("ms")) - .def("extractDirichlet", (void (smtk::mesh::utility::MeshConstants::*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::PointSet const &)) &smtk::mesh::utility::MeshConstants::extractDirichlet, py::arg("cs"), py::arg("ps")) - .def("extractDomain", (void (smtk::mesh::utility::MeshConstants::*)(::smtk::mesh::MeshSet const &)) &smtk::mesh::utility::MeshConstants::extractDomain, py::arg("ms")) - .def("extractDomain", (void (smtk::mesh::utility::MeshConstants::*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::PointSet const &)) &smtk::mesh::utility::MeshConstants::extractDomain, py::arg("cs"), py::arg("ps")) - .def("extractNeumann", (void (smtk::mesh::utility::MeshConstants::*)(::smtk::mesh::MeshSet const &)) &smtk::mesh::utility::MeshConstants::extractNeumann, py::arg("ms")) - .def("extractNeumann", (void (smtk::mesh::utility::MeshConstants::*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::PointSet const &)) &smtk::mesh::utility::MeshConstants::extractNeumann, py::arg("cs"), py::arg("ps")) - .def("pointData", &smtk::mesh::utility::MeshConstants::pointData) - ; - return instance; -} - -inline void pybind11_init__ZN4smtk4mesh21extractDirichletMeshConstantsERKNS0_7MeshSetERNS0_17PreAllocatedMeshConstantsE(py::module &m) -{ - m.def("extractDirichletMeshConstants", (void (*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::utility::PreAllocatedMeshConstants &)) &smtk::mesh::utility::extractDirichletMeshConstants, "", py::arg("arg0"), py::arg("arg1")); -} - -inline void pybind11_init__ZN4smtk4mesh21extractDirichletMeshConstantsERKNS0_7MeshSetERKNS0_8PointSetERNS0_17PreAllocatedMeshConstantsE(py::module &m) -{ - m.def("extractDirichletMeshConstants", (void (*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::PointSet const &, ::smtk::mesh::utility::PreAllocatedMeshConstants &)) &smtk::mesh::utility::extractDirichletMeshConstants, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2")); -} - -inline void pybind11_init__ZN4smtk4mesh18extractDomainMeshConstantsERKNS0_7MeshSetERNS0_17PreAllocatedMeshConstantsE(py::module &m) -{ - m.def("extractDomainMeshConstants", (void (*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::utility::PreAllocatedMeshConstants &)) &smtk::mesh::utility::extractDomainMeshConstants, "", py::arg("arg0"), py::arg("arg1")); -} - -inline void pybind11_init__ZN4smtk4mesh18extractDomainMeshConstantsERKNS0_7MeshSetERKNS0_8PointSetERNS0_17PreAllocatedMeshConstantsE(py::module &m) -{ - m.def("extractDomainMeshConstants", (void (*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::PointSet const &, ::smtk::mesh::utility::PreAllocatedMeshConstants &)) &smtk::mesh::utility::extractDomainMeshConstants, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2")); -} - -inline void pybind11_init__ZN4smtk4mesh19extractNeumannMeshConstantsERKNS0_7MeshSetERNS0_17PreAllocatedMeshConstantsE(py::module &m) -{ - m.def("extractNeumannMeshConstants", (void (*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::utility::PreAllocatedMeshConstants &)) &smtk::mesh::utility::extractNeumannMeshConstants, "", py::arg("arg0"), py::arg("arg1")); -} - -inline void pybind11_init__ZN4smtk4mesh19extractNeumannMeshConstantsERKNS0_7MeshSetERKNS0_8PointSetERNS0_17PreAllocatedMeshConstantsE(py::module &m) -{ - m.def("extractNeumannMeshConstants", (void (*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::PointSet const &, ::smtk::mesh::utility::PreAllocatedMeshConstants &)) &smtk::mesh::utility::extractNeumannMeshConstants, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2")); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindExtractTessellation.h b/smtk/mesh/pybind11/PybindExtractTessellation.h deleted file mode 100644 index 69467fdcfc7cf5c43939eaf4684a1fab8ea3a2f3..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindExtractTessellation.h +++ /dev/null @@ -1,129 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_ExtractTessellation_h -#define pybind_smtk_mesh_ExtractTessellation_h - -#include - -#include "smtk/mesh/utility/ExtractTessellation.h" - -#include "smtk/model/EdgeUse.h" -#include "smtk/model/Loop.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::utility::PreAllocatedTessellation > pybind11_init_smtk_mesh_PreAllocatedTessellation(py::module &m) -{ - PySharedPtrClass< smtk::mesh::utility::PreAllocatedTessellation > instance(m, "PreAllocatedTessellation"); - instance - .def(py::init<::smtk::mesh::utility::PreAllocatedTessellation const &>()) - .def(py::init<::int64_t *>()) - .def(py::init<::int64_t *, float *>()) - .def(py::init<::int64_t *, double *>()) - .def(py::init<::int64_t *, ::int64_t *, unsigned char *>()) - .def(py::init<::int64_t *, ::int64_t *, unsigned char *, float *>()) - .def(py::init<::int64_t *, ::int64_t *, unsigned char *, double *>()) - .def("deepcopy", (smtk::mesh::utility::PreAllocatedTessellation & (smtk::mesh::utility::PreAllocatedTessellation::*)(::smtk::mesh::utility::PreAllocatedTessellation const &)) &smtk::mesh::utility::PreAllocatedTessellation::operator=) - .def_static("determineAllocationLengths", (void (*)(::smtk::mesh::MeshSet const &, ::int64_t &, ::int64_t &, ::int64_t &)) &smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths, py::arg("ms"), py::arg("connectivityLength"), py::arg("numberOfCells"), py::arg("numberOfPoints")) - .def_static("determineAllocationLengths", (void (*)(::smtk::mesh::CellSet const &, ::int64_t &, ::int64_t &, ::int64_t &)) &smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths, py::arg("cs"), py::arg("connectivityLength"), py::arg("numberOfCells"), py::arg("numberOfPoints")) - .def_static("determineAllocationLengths", (void (*)(::smtk::model::EntityRef const &, ::smtk::mesh::ResourcePtr const &, ::int64_t &, ::int64_t &, ::int64_t &)) &smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths, py::arg("eRef"), py::arg("c"), py::arg("connectivityLength"), py::arg("numberOfCells"), py::arg("numberOfPoints")) - .def_static("determineAllocationLengths", (void (*)(::smtk::model::Loop const &, ::smtk::mesh::ResourcePtr const &, ::int64_t &, ::int64_t &, ::int64_t &)) &smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths, py::arg("loop"), py::arg("c"), py::arg("connectivityLength"), py::arg("numberOfCells"), py::arg("numberOfPoints")) - .def("disableVTKCellTypes", &smtk::mesh::utility::PreAllocatedTessellation::disableVTKCellTypes, py::arg("disable")) - .def("disableVTKStyleConnectivity", &smtk::mesh::utility::PreAllocatedTessellation::disableVTKStyleConnectivity, py::arg("disable")) - .def("hasCellLocations", &smtk::mesh::utility::PreAllocatedTessellation::hasCellLocations) - .def("hasCellTypes", &smtk::mesh::utility::PreAllocatedTessellation::hasCellTypes) - .def("hasConnectivity", &smtk::mesh::utility::PreAllocatedTessellation::hasConnectivity) - .def("hasDoublePoints", &smtk::mesh::utility::PreAllocatedTessellation::hasDoublePoints) - .def("hasFloatPoints", &smtk::mesh::utility::PreAllocatedTessellation::hasFloatPoints) - .def("useVTKCellTypes", &smtk::mesh::utility::PreAllocatedTessellation::useVTKCellTypes) - .def("useVTKConnectivity", &smtk::mesh::utility::PreAllocatedTessellation::useVTKConnectivity) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::utility::Tessellation > pybind11_init_smtk_mesh_Tessellation(py::module &m) -{ - PySharedPtrClass< smtk::mesh::utility::Tessellation > instance(m, "Tessellation"); - instance - .def(py::init<::smtk::mesh::utility::Tessellation const &>()) - .def(py::init<>()) - .def(py::init()) - .def("deepcopy", (smtk::mesh::utility::Tessellation & (smtk::mesh::utility::Tessellation::*)(::smtk::mesh::utility::Tessellation const &)) &smtk::mesh::utility::Tessellation::operator=) - .def("cellLocations", &smtk::mesh::utility::Tessellation::cellLocations) - .def("cellTypes", &smtk::mesh::utility::Tessellation::cellTypes) - .def("connectivity", &smtk::mesh::utility::Tessellation::connectivity) - .def("extract", (void (smtk::mesh::utility::Tessellation::*)(::smtk::mesh::MeshSet const &)) &smtk::mesh::utility::Tessellation::extract, py::arg("ms")) - .def("extract", (void (smtk::mesh::utility::Tessellation::*)(::smtk::mesh::CellSet const &)) &smtk::mesh::utility::Tessellation::extract, py::arg("cs")) - .def("extract", (void (smtk::mesh::utility::Tessellation::*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::PointSet const &)) &smtk::mesh::utility::Tessellation::extract, py::arg("cs"), py::arg("ps")) - .def("extract", (void (smtk::mesh::utility::Tessellation::*)(::smtk::mesh::CellSet const &, ::smtk::mesh::PointSet const &)) &smtk::mesh::utility::Tessellation::extract, py::arg("cs"), py::arg("ps")) - .def("points", &smtk::mesh::utility::Tessellation::points) - .def("useVTKCellTypes", &smtk::mesh::utility::Tessellation::useVTKCellTypes) - .def("useVTKConnectivity", &smtk::mesh::utility::Tessellation::useVTKConnectivity) - ; - return instance; -} - -inline void pybind11_init__ZN4smtk4mesh26extractOrderedTessellationERKNS_5model4EdgeERKNSt3__110shared_ptrINS0_10ResourceEEERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractOrderedTessellation", (void (*)(::smtk::model::EdgeUse const &, ::smtk::mesh::ResourcePtr const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractOrderedTessellation, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2")); -} - -inline void pybind11_init__ZN4smtk4mesh26extractOrderedTessellationERKNS_5model4LoopERKNSt3__110shared_ptrINS0_10ResourceEEERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractOrderedTessellation", (void (*)(::smtk::model::Loop const &, ::smtk::mesh::ResourcePtr const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractOrderedTessellation, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2")); -} - -inline void pybind11_init__ZN4smtk4mesh26extractOrderedTessellationERKNS_5model4EdgeERKNSt3__110shared_ptrINS0_10ResourceEEERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractOrderedTessellation", (void (*)(::smtk::model::EdgeUse const &, ::smtk::mesh::ResourcePtr const &, ::smtk::mesh::PointSet const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractOrderedTessellation, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2"), py::arg("arg3")); -} - -inline void pybind11_init__ZN4smtk4mesh26extractOrderedTessellationERKNS_5model4LoopERKNSt3__110shared_ptrINS0_10ResourceEEERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractOrderedTessellation", (void (*)(::smtk::model::Loop const &, ::smtk::mesh::ResourcePtr const &, ::smtk::mesh::PointSet const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractOrderedTessellation, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2"), py::arg("arg3")); -} - -inline void pybind11_init__ZN4smtk4mesh19extractTessellationERKNS0_7MeshSetERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractTessellation", (void (*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractTessellation, "", py::arg("arg0"), py::arg("arg1")); -} - -inline void pybind11_init__ZN4smtk4mesh19extractTessellationERKNS0_7CellSetERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractTessellation", (void (*)(::smtk::mesh::CellSet const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractTessellation, "", py::arg("arg0"), py::arg("arg1")); -} - -inline void pybind11_init__ZN4smtk4mesh19extractTessellationERKNS_5model9EntityRefERKNSt3__110shared_ptrINS0_10ResourceEEERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractTessellation", (void (*)(::smtk::model::EntityRef const &, ::smtk::mesh::ResourcePtr const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractTessellation, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2")); -} - -inline void pybind11_init__ZN4smtk4mesh19extractTessellationERKNS0_7MeshSetERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractTessellation", (void (*)(::smtk::mesh::MeshSet const &, ::smtk::mesh::PointSet const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractTessellation, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2")); -} - -inline void pybind11_init__ZN4smtk4mesh19extractTessellationERKNS0_7CellSetERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractTessellation", (void (*)(::smtk::mesh::CellSet const &, ::smtk::mesh::PointSet const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractTessellation, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2")); -} - -inline void pybind11_init__ZN4smtk4mesh19extractTessellationERNS0_17PointConnectivityERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractTessellation", (void (*)(::smtk::mesh::PointConnectivity &, ::smtk::mesh::PointSet const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractTessellation, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2")); -} - -inline void pybind11_init__ZN4smtk4mesh19extractTessellationERKNS_5model9EntityRefERKNSt3__110shared_ptrINS0_10ResourceEEERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(py::module &m) -{ - m.def("extractTessellation", (void (*)(::smtk::model::EntityRef const &, ::smtk::mesh::ResourcePtr const &, ::smtk::mesh::PointSet const &, ::smtk::mesh::utility::PreAllocatedTessellation &)) &smtk::mesh::utility::extractTessellation, "", py::arg("arg0"), py::arg("arg1"), py::arg("arg2"), py::arg("arg3")); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindFieldTypes.h b/smtk/mesh/pybind11/PybindFieldTypes.h deleted file mode 100644 index 8ecd0f056d4b78f7ce6e11d32722ca799b7aa675..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindFieldTypes.h +++ /dev/null @@ -1,29 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_FieldTypes_h -#define pybind_smtk_mesh_FieldTypes_h - -#include - -#include "smtk/mesh/core/FieldTypes.h" - -namespace py = pybind11; - -inline void pybind11_init_smtk_mesh_FieldType(py::module &m) -{ - py::enum_(m, "FieldType") - .value("Integer", smtk::mesh::FieldType::Integer) - .value("Double", smtk::mesh::FieldType::Double) - .value("FieldType_MAX", smtk::mesh::FieldType::MaxFieldType) - .export_values(); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindForEachTypes.h b/smtk/mesh/pybind11/PybindForEachTypes.h deleted file mode 100644 index a6468123fb7c87c8c47e1ed13d86215f7d01c59f..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindForEachTypes.h +++ /dev/null @@ -1,103 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_ForEachTypes_h -#define pybind_smtk_mesh_ForEachTypes_h - -#include -#include - -#include "smtk/mesh/core/ForEachTypes.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/core/MeshSet.h" - -namespace py = pybind11; - -class PyMeshForEach : public smtk::mesh::MeshForEach -{ -public: - using smtk::mesh::MeshForEach::MeshForEach; - void forMesh(smtk::mesh::MeshSet& singleMesh) override - { - PYBIND11_OVERLOAD_PURE(void, smtk::mesh::MeshForEach, forMesh, singleMesh); - } -}; - -class PyCellForEach : public smtk::mesh::CellForEach -{ -public: - using smtk::mesh::CellForEach::CellForEach; - void forCell(const smtk::mesh::Handle& cellId, - smtk::mesh::CellType cellType, - int numPointIds) override - { - PYBIND11_OVERLOAD_PURE(void, smtk::mesh::CellForEach, forCell, cellId, cellType, numPointIds); - } -}; - -class PyPointForEach : public smtk::mesh::PointForEach -{ -public: - using smtk::mesh::PointForEach::PointForEach; - void forPoints(const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& coordinatesModified) override - { - PYBIND11_OVERLOAD_PURE(void, smtk::mesh::PointForEach, forPoints, pointIds, xyz, coordinatesModified); - } -}; - -inline PySharedPtrClass< smtk::mesh::MeshForEach > pybind11_init_smtk_mesh_MeshForEach(py::module &m) -{ - py::class_, PyMeshForEach > instance(m, "MeshForEach"); - instance - .def(py::init<>()) - .def("deepcopy", (smtk::mesh::MeshForEach & (smtk::mesh::MeshForEach::*)(::smtk::mesh::MeshForEach const &)) &smtk::mesh::MeshForEach::operator=) - .def("forMesh", &smtk::mesh::MeshForEach::forMesh, py::arg("singleMesh")) - .def_readwrite("m_resource", &smtk::mesh::MeshForEach::m_resource) - ; - - return instance; -} - -inline PySharedPtrClass< smtk::mesh::CellForEach > pybind11_init_smtk_mesh_CellForEach(py::module &m) -{ - py::class_, PyCellForEach > instance(m, "CellForEach"); - instance - .def(py::init<>()) - .def(py::init()) - .def("deepcopy", (smtk::mesh::CellForEach & (smtk::mesh::CellForEach::*)(::smtk::mesh::CellForEach const &)) &smtk::mesh::CellForEach::operator=) - .def("resource", (smtk::mesh::ResourcePtr (smtk::mesh::CellForEach::*)() const) &smtk::mesh::CellForEach::resource) - .def("resource", (void (smtk::mesh::CellForEach::*)(::smtk::mesh::ResourcePtr)) &smtk::mesh::CellForEach::resource, py::arg("c")) - .def("coordinates", (std::vector > const & (smtk::mesh::CellForEach::*)() const) &smtk::mesh::CellForEach::coordinates) - .def("coordinates", (void (smtk::mesh::CellForEach::*)(::std::vector > *)) &smtk::mesh::CellForEach::coordinates, py::arg("coords")) - .def("forCell", &smtk::mesh::CellForEach::forCell, py::arg("cellId"), py::arg("cellType"), py::arg("numPointIds")) - .def("pointId", &smtk::mesh::CellForEach::pointId, py::arg("index")) - .def("pointIds", (smtk::mesh::Handle const * (smtk::mesh::CellForEach::*)() const) &smtk::mesh::CellForEach::pointIds) - .def("pointIds", (void (smtk::mesh::CellForEach::*)(::smtk::mesh::Handle const *)) &smtk::mesh::CellForEach::pointIds, py::arg("ptIds")) - .def("wantsCoordinates", &smtk::mesh::CellForEach::wantsCoordinates) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::PointForEach > pybind11_init_smtk_mesh_PointForEach(py::module &m) -{ - py::class_, PyPointForEach > instance(m, "PointForEach"); - instance - .def(py::init<>()) - .def("deepcopy", (smtk::mesh::PointForEach & (smtk::mesh::PointForEach::*)(::smtk::mesh::PointForEach const &)) &smtk::mesh::PointForEach::operator=) - .def("forPoints", &smtk::mesh::PointForEach::forPoints, py::arg("pointIds"), py::arg("xyz"), py::arg("coordinatesModified")) - .def_readwrite("m_resource", &smtk::mesh::PointForEach::m_resource) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindHandle.h b/smtk/mesh/pybind11/PybindHandle.h deleted file mode 100644 index 81abedc15d0aa6203e1001acd761eaaa85896d64..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindHandle.h +++ /dev/null @@ -1,103 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_core_Handle_h -#define pybind_smtk_mesh_core_Handle_h - -#include - -#include "smtk/mesh/core/Handle.h" - -namespace py = pybind11; - -inline py::class_< smtk::mesh::HandleInterval > pybind11_init_HandleInterval(py::module &m) -{ - py::class_< smtk::mesh::HandleInterval > instance(m, "HandleInterval"); - instance - .def(py::init()) - .def(py::init<>()) - .def(py::init()) - .def(py::init()) - .def("deepcopy", (smtk::mesh::HandleInterval & (smtk::mesh::HandleInterval::*)(smtk::mesh::HandleInterval const &)) &smtk::mesh::HandleInterval::operator=) - .def("first", &smtk::mesh::HandleInterval::first) - .def("last", &smtk::mesh::HandleInterval::last) - .def("lower", &smtk::mesh::HandleInterval::lower) - .def("upper", &smtk::mesh::HandleInterval::upper) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::const_element_iterator > pybind11_init_const_element_iterator(py::module &m) -{ - PySharedPtrClass< smtk::mesh::const_element_iterator > instance(m, "const_element_iterator"); - instance - .def(py::init<>()) - .def(py::init()) - .def("deepcopy", (smtk::mesh::const_element_iterator & (smtk::mesh::const_element_iterator::*)(::smtk::mesh::const_element_iterator const &)) &smtk::mesh::const_element_iterator::operator=) - ; - return instance; -} - -inline py::class_< smtk::mesh::HandleRange > pybind11_init_HandleRange(py::module &m) -{ - py::class_< smtk::mesh::HandleRange > instance(m, "HandleRange"); - instance - .def(py::init<>()) - .def(py::init()) - .def(py::init()) - .def(py::init()) - .def("__repr__", [](smtk::mesh::HandleRange& range){ std::stringstream s; s << range; return s.str(); }) - .def("begin", [](smtk::mesh::HandleRange& range){ return range.begin(); }) - .def("deepcopy", (smtk::mesh::HandleRange & (smtk::mesh::HandleRange::*)(smtk::mesh::HandleRange)) &smtk::mesh::HandleRange::operator=) - .def("elements_begin", [](smtk::mesh::HandleRange& range){ return smtk::mesh::rangeElementsBegin(range); }) - .def("elements_end", [](smtk::mesh::HandleRange& range){ return smtk::mesh::rangeElementsEnd(range); }) - .def("end", [](smtk::mesh::HandleRange& range){ return range.end(); }) - .def("size", &smtk::mesh::HandleRange::size) - ; - return instance; -} - -inline void pybind11_init_smtk_mesh_rangeElementsBegin(py::module &m) -{ - m.def("rangeElementsBegin", &smtk::mesh::rangeElementsBegin, "", py::arg("arg0")); -} - -inline void pybind11_init_smtk_mesh_rangeElementsEnd(py::module &m) -{ - m.def("rangeElementsEnd", &smtk::mesh::rangeElementsEnd, "", py::arg("arg0")); -} - -inline void pybind11_init_smtk_mesh_rangeElement(py::module &m) -{ - m.def("rangeElement", &smtk::mesh::rangeElement, "", py::arg("arg0"), py::arg("arg1")); -} - -inline void pybind11_init_smtk_mesh_rangeContains(py::module &m) -{ - m.def("rangeContains", (bool (*)(smtk::mesh::HandleRange const &, smtk::mesh::Handle)) &smtk::mesh::rangeContains, "", py::arg("arg0"), py::arg("arg1")); - m.def("rangeContains", (bool (*)(smtk::mesh::HandleRange const &, smtk::mesh::HandleRange const &)) &smtk::mesh::rangeContains, "", py::arg("super"), py::arg("sub")); -} - -inline void pybind11_init_smtk_mesh_rangeIndex(py::module &m) -{ - m.def("rangeIndex", &smtk::mesh::rangeIndex, "", py::arg("arg0"), py::arg("arg1")); -} - -inline void pybind11_init_smtk_mesh_rangeIntervalCount(py::module &m) -{ - m.def("rangeIntervalCount", &smtk::mesh::rangeIntervalCount, "", py::arg("arg0")); -} - -inline void pybind11_init_smtk_mesh_rangesEqual(py::module &m) -{ - m.def("rangesEqual", &smtk::mesh::rangesEqual, "", py::arg("arg0"), py::arg("arg1")); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindImport.h b/smtk/mesh/pybind11/PybindImport.h deleted file mode 100644 index 2fe8a437ac2224aa72a0d635e8ac2799f16a158c..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindImport.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_operators_Import_h -#define pybind_smtk_mesh_operators_Import_h - -#include - -#include "smtk/mesh/operators/Import.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::Import, smtk::operation::XMLOperation > pybind11_init_smtk_mesh_Import(py::module &m) -{ - PySharedPtrClass< smtk::mesh::Import, smtk::operation::XMLOperation > instance(m, "Import"); - instance - .def(py::init<>()) - .def("ableToOperate", &smtk::mesh::Import::ableToOperate) - .def_static("create", (std::shared_ptr (*)()) &smtk::mesh::Import::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::mesh::Import::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Import::*)() const) &smtk::mesh::Import::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Import::*)()) &smtk::mesh::Import::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindInterface.h b/smtk/mesh/pybind11/PybindInterface.h deleted file mode 100644 index 6ab40fb659f488dc4304d388b7844a29808290d5..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindInterface.h +++ /dev/null @@ -1,203 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_Interface_h -#define pybind_smtk_mesh_Interface_h - -#include - -#include "smtk/mesh/core/Interface.h" - -#include "smtk/common/UUID.h" -#include "smtk/common/pybind11/PybindUUIDTypeCaster.h" -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/PointConnectivity.h" -#include "smtk/mesh/core/TypeSet.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::Allocator > pybind11_init_smtk_mesh_Allocator(py::module &m) -{ - PySharedPtrClass< smtk::mesh::Allocator > instance(m, "Allocator"); - instance - .def("deepcopy", (smtk::mesh::Allocator & (smtk::mesh::Allocator::*)(::smtk::mesh::Allocator const &)) &smtk::mesh::Allocator::operator=) - // .def("allocateCells", &smtk::mesh::Allocator::allocateCells, py::arg("cellType"), py::arg("numCellsToAlloc"), py::arg("numVertsPerCell"), py::arg("createdCellIds"), py::arg("connectivityArray")) - .def("allocatePoints", &smtk::mesh::Allocator::allocatePoints, py::arg("numPointsToAlloc"), py::arg("firstVertexHandle"), py::arg("coordinateMemory")) - .def("connectivityModified", &smtk::mesh::Allocator::connectivityModified, py::arg("cellsToUpdate"), py::arg("numVertsPerCell"), py::arg("connectivityArray")) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::BufferedCellAllocator > pybind11_init_smtk_mesh_BufferedCellAllocator(py::module &m) -{ - PySharedPtrClass< smtk::mesh::BufferedCellAllocator > instance(m, "BufferedCellAllocator"); - instance - .def("deepcopy", (smtk::mesh::BufferedCellAllocator & (smtk::mesh::BufferedCellAllocator::*)(::smtk::mesh::BufferedCellAllocator const &)) &smtk::mesh::BufferedCellAllocator::operator=) - .def("addCell", (bool (smtk::mesh::BufferedCellAllocator::*)(::smtk::mesh::CellType, long long int *, ::size_t)) &smtk::mesh::BufferedCellAllocator::addCell, py::arg("ctype"), py::arg("pointIds"), py::arg("nCoordinates") = 0) - .def("addCell", (bool (smtk::mesh::BufferedCellAllocator::*)(::smtk::mesh::CellType, long int *, ::size_t)) &smtk::mesh::BufferedCellAllocator::addCell, py::arg("ctype"), py::arg("pointIds"), py::arg("nCoordinates") = 0) - .def("addCell", (bool (smtk::mesh::BufferedCellAllocator::*)(::smtk::mesh::CellType, int *, ::size_t)) &smtk::mesh::BufferedCellAllocator::addCell, py::arg("ctype"), py::arg("pointIds"), py::arg("nCoordinates") = 0) - .def("cells", &smtk::mesh::BufferedCellAllocator::cells) - .def("flush", &smtk::mesh::BufferedCellAllocator::flush) - .def("isValid", &smtk::mesh::BufferedCellAllocator::isValid) - .def("reserveNumberOfCoordinates", &smtk::mesh::BufferedCellAllocator::reserveNumberOfCoordinates, py::arg("nCoordinates")) - .def("setCoordinate", (bool (smtk::mesh::BufferedCellAllocator::*)(::size_t, double *)) &smtk::mesh::BufferedCellAllocator::setCoordinate, py::arg("coord"), py::arg("xyz")) - .def("setCoordinate", (bool (smtk::mesh::BufferedCellAllocator::*)(::size_t, double, double, double)) &smtk::mesh::BufferedCellAllocator::setCoordinate, py::arg("coord"), py::arg("x"), py::arg("y"), py::arg("z")) - .def("setCoordinate", (bool (smtk::mesh::BufferedCellAllocator::*)(::size_t, float *)) &smtk::mesh::BufferedCellAllocator::setCoordinate, py::arg("coord"), py::arg("xyz")) - .def("setCoordinate", (bool (smtk::mesh::BufferedCellAllocator::*)(::size_t, float, float, float)) &smtk::mesh::BufferedCellAllocator::setCoordinate, py::arg("coord"), py::arg("x"), py::arg("y"), py::arg("z")) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::ConnectivityStorage > pybind11_init_smtk_mesh_ConnectivityStorage(py::module &m) -{ - PySharedPtrClass< smtk::mesh::ConnectivityStorage > instance(m, "ConnectivityStorage"); - instance - .def("deepcopy", (smtk::mesh::ConnectivityStorage & (smtk::mesh::ConnectivityStorage::*)(::smtk::mesh::ConnectivityStorage const &)) &smtk::mesh::ConnectivityStorage::operator=) - .def("cellSize", &smtk::mesh::ConnectivityStorage::cellSize) - .def("equal", &smtk::mesh::ConnectivityStorage::equal, py::arg("other")) - // .def("fetchNextCell", &smtk::mesh::ConnectivityStorage::fetchNextCell, py::arg("state"), py::arg("cellType"), py::arg("numPts"), py::arg("points")) - .def("initTraversal", &smtk::mesh::ConnectivityStorage::initTraversal, py::arg("state")) - .def("vertSize", &smtk::mesh::ConnectivityStorage::vertSize) - ; - py::class_< smtk::mesh::ConnectivityStorage::IterationState >(instance, "IterationState") - .def(py::init<>()) - .def(py::init<::smtk::mesh::ConnectivityStorage::IterationState const &>()) - .def("deepcopy", (smtk::mesh::ConnectivityStorage::IterationState & (smtk::mesh::ConnectivityStorage::IterationState::*)(::smtk::mesh::ConnectivityStorage::IterationState const &)) &smtk::mesh::ConnectivityStorage::IterationState::operator=) - .def_readwrite("whichConnectivityVector", &smtk::mesh::ConnectivityStorage::IterationState::whichConnectivityVector) - .def_readwrite("ptrOffsetInVector", &smtk::mesh::ConnectivityStorage::IterationState::ptrOffsetInVector) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::IncrementalAllocator > pybind11_init_smtk_mesh_IncrementalAllocator(py::module &m) -{ - PySharedPtrClass< smtk::mesh::IncrementalAllocator > instance(m, "IncrementalAllocator"); - instance - .def("deepcopy", (smtk::mesh::IncrementalAllocator & (smtk::mesh::IncrementalAllocator::*)(::smtk::mesh::IncrementalAllocator const &)) &smtk::mesh::IncrementalAllocator::operator=) - .def("addCell", (bool (smtk::mesh::IncrementalAllocator::*)(::smtk::mesh::CellType, long long int *, ::size_t)) &smtk::mesh::IncrementalAllocator::addCell, py::arg("ctype"), py::arg("pointIds"), py::arg("nCoordinates") = 0) - .def("addCell", (bool (smtk::mesh::IncrementalAllocator::*)(::smtk::mesh::CellType, long int *, ::size_t)) &smtk::mesh::IncrementalAllocator::addCell, py::arg("ctype"), py::arg("pointIds"), py::arg("nCoordinates") = 0) - .def("addCell", (bool (smtk::mesh::IncrementalAllocator::*)(::smtk::mesh::CellType, int *, ::size_t)) &smtk::mesh::IncrementalAllocator::addCell, py::arg("ctype"), py::arg("pointIds"), py::arg("nCoordinates") = 0) - .def("addCoordinate", (size_t (smtk::mesh::IncrementalAllocator::*)(double *)) &smtk::mesh::IncrementalAllocator::addCoordinate, py::arg("xyz")) - .def("addCoordinate", (size_t (smtk::mesh::IncrementalAllocator::*)(double, double, double)) &smtk::mesh::IncrementalAllocator::addCoordinate, py::arg("x"), py::arg("y"), py::arg("z")) - .def("addCoordinate", (size_t (smtk::mesh::IncrementalAllocator::*)(float *)) &smtk::mesh::IncrementalAllocator::addCoordinate, py::arg("xyz")) - .def("addCoordinate", (size_t (smtk::mesh::IncrementalAllocator::*)(float, float, float)) &smtk::mesh::IncrementalAllocator::addCoordinate, py::arg("x"), py::arg("y"), py::arg("z")) - .def("cells", &smtk::mesh::IncrementalAllocator::cells) - .def("flush", &smtk::mesh::IncrementalAllocator::flush) - .def("isValid", &smtk::mesh::IncrementalAllocator::isValid) - .def("setCoordinate", (bool (smtk::mesh::IncrementalAllocator::*)(::size_t, double *)) &smtk::mesh::IncrementalAllocator::setCoordinate, py::arg("coord"), py::arg("xyz")) - .def("setCoordinate", (bool (smtk::mesh::IncrementalAllocator::*)(::size_t, double, double, double)) &smtk::mesh::IncrementalAllocator::setCoordinate, py::arg("coord"), py::arg("x"), py::arg("y"), py::arg("z")) - .def("setCoordinate", (bool (smtk::mesh::IncrementalAllocator::*)(::size_t, float *)) &smtk::mesh::IncrementalAllocator::setCoordinate, py::arg("coord"), py::arg("xyz")) - .def("setCoordinate", (bool (smtk::mesh::IncrementalAllocator::*)(::size_t, float, float, float)) &smtk::mesh::IncrementalAllocator::setCoordinate, py::arg("coord"), py::arg("x"), py::arg("y"), py::arg("z")) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::Interface > pybind11_init_smtk_mesh_Interface(py::module &m) -{ - PySharedPtrClass< smtk::mesh::Interface > instance(m, "Interface"); - instance - .def("deepcopy", (smtk::mesh::Interface & (smtk::mesh::Interface::*)(::smtk::mesh::Interface const &)) &smtk::mesh::Interface::operator=) - .def("allocator", &smtk::mesh::Interface::allocator) - .def("bufferedCellAllocator", &smtk::mesh::Interface::bufferedCellAllocator) - .def("cellForEach", &smtk::mesh::Interface::cellForEach, py::arg("cells"), py::arg("a"), py::arg("filter")) - .def("computeCellFieldTags", &smtk::mesh::Interface::computeCellFieldTags, py::arg("handle")) - .def("computePointFieldTags", &smtk::mesh::Interface::computePointFieldTags, py::arg("handle")) - .def("computeDirichletValues", &smtk::mesh::Interface::computeDirichletValues, py::arg("meshsets")) - .def("computeDomainValues", &smtk::mesh::Interface::computeDomainValues, py::arg("meshsets")) - .def("computeModelEntities", &smtk::mesh::Interface::computeModelEntities, py::arg("meshsets")) - .def("computeNames", &smtk::mesh::Interface::computeNames, py::arg("meshsets")) - .def("computeNeumannValues", &smtk::mesh::Interface::computeNeumannValues, py::arg("meshsets")) - .def("computeShell", &smtk::mesh::Interface::computeShell, py::arg("meshes"), py::arg("shell")) - .def("computeTypes", &smtk::mesh::Interface::computeTypes, py::arg("range")) - .def("connectivityStorage", &smtk::mesh::Interface::connectivityStorage, py::arg("cells")) - .def("createCellField", &smtk::mesh::Interface::createCellField, py::arg("meshsets"), py::arg("name"), py::arg("dimension"), py::arg("type"), py::arg("field")) - .def("createPointField", &smtk::mesh::Interface::createPointField, py::arg("meshsets"), py::arg("name"), py::arg("dimension"), py::arg("type"), py::arg("field")) - .def("createMesh", &smtk::mesh::Interface::createMesh, py::arg("cells"), py::arg("meshHandle")) - .def("deleteCellField", &smtk::mesh::Interface::deleteCellField, py::arg("cfTag"), py::arg("meshsets")) - .def("deletePointField", &smtk::mesh::Interface::deletePointField, py::arg("cfTag"), py::arg("meshsets")) - .def("deleteHandles", &smtk::mesh::Interface::deleteHandles, py::arg("toDel")) - .def("findAssociations", &smtk::mesh::Interface::findAssociations, py::arg("root"), py::arg("modelUUID")) - .def("getCells", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::HandleRange const &) const) &smtk::mesh::Interface::getCells, py::arg("meshsets")) - .def("getCells", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::HandleRange const &, ::smtk::mesh::CellType) const) &smtk::mesh::Interface::getCells, py::arg("meshsets"), py::arg("cellType")) - .def("getCells", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::HandleRange const &, ::smtk::mesh::CellTypes const &) const) &smtk::mesh::Interface::getCells, py::arg("meshsets"), py::arg("cellTypes")) - .def("getCells", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::HandleRange const &, ::smtk::mesh::DimensionType) const) &smtk::mesh::Interface::getCells, py::arg("meshsets"), py::arg("dim")) - .def("getCoordinates", (bool (smtk::mesh::Interface::*)(::smtk::mesh::HandleRange const &, double *) const) &smtk::mesh::Interface::getCoordinates, py::arg("points"), py::arg("xyz")) - .def("getCoordinates", (bool (smtk::mesh::Interface::*)(::smtk::mesh::HandleRange const &, float *) const) &smtk::mesh::Interface::getCoordinates, py::arg("points"), py::arg("xyz")) - .def("getField", (bool (smtk::mesh::Interface::*)(const smtk::mesh::HandleRange&, const smtk::mesh::CellFieldTag&, void*) const) &smtk::mesh::Interface::getField, py::arg("cells"), py::arg("cfTag"), py::arg("field")) - .def("getField", (bool (smtk::mesh::Interface::*)(const smtk::mesh::HandleRange&, const smtk::mesh::PointFieldTag&, void*) const) &smtk::mesh::Interface::getField, py::arg("points"), py::arg("pfTag"), py::arg("field")) - .def("getCellField", &smtk::mesh::Interface::getCellField, py::arg("meshsets"), py::arg("cfTag"), py::arg("field")) - .def("getCellFieldDimension", &smtk::mesh::Interface::getCellFieldDimension, py::arg("cfTag")) - .def("getMeshsets", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::Handle) const) &smtk::mesh::Interface::getMeshsets, py::arg("handle")) - .def("getMeshsets", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::Handle, int) const) &smtk::mesh::Interface::getMeshsets, py::arg("handle"), py::arg("dimension")) - .def("getMeshsets", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::Handle, ::std::string const &) const) &smtk::mesh::Interface::getMeshsets, py::arg("handle"), py::arg("name")) - .def("getMeshsets", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::Handle, ::smtk::mesh::Domain const &) const) &smtk::mesh::Interface::getMeshsets, py::arg("handle"), py::arg("domain")) - .def("getMeshsets", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::Handle, ::smtk::mesh::Dirichlet const &) const) &smtk::mesh::Interface::getMeshsets, py::arg("handle"), py::arg("dirichlet")) - .def("getMeshsets", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::Handle, ::smtk::mesh::Neumann const &) const) &smtk::mesh::Interface::getMeshsets, py::arg("handle"), py::arg("neumann")) - .def("getMeshsets", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::Handle, ::smtk::mesh::CellFieldTag const &) const) &smtk::mesh::Interface::getMeshsets, py::arg("handle"), py::arg("cfTag")) - .def("getMeshsets", (smtk::mesh::HandleRange (smtk::mesh::Interface::*)(::smtk::mesh::Handle, ::smtk::mesh::PointFieldTag const &) const) &smtk::mesh::Interface::getMeshsets, py::arg("handle"), py::arg("pfTag")) - .def("getPointField", &smtk::mesh::Interface::getPointField, py::arg("meshsets"), py::arg("cfTag"), py::arg("field")) - .def("getPointFieldDimension", &smtk::mesh::Interface::getPointFieldDimension, py::arg("cfTag")) - .def("getPoints", &smtk::mesh::Interface::getPoints, py::arg("cells"), py::arg("boundary_only") = false) - .def("getRoot", &smtk::mesh::Interface::getRoot) - .def("hasCellField", &smtk::mesh::Interface::hasCellField, py::arg("meshsets"), py::arg("cfTag")) - .def("hasPointField", &smtk::mesh::Interface::hasPointField, py::arg("meshsets"), py::arg("cfTag")) - .def("incrementalAllocator", &smtk::mesh::Interface::incrementalAllocator) - .def("isModified", &smtk::mesh::Interface::isModified) - .def("mergeCoincidentContactPoints", &smtk::mesh::Interface::mergeCoincidentContactPoints, py::arg("meshes"), py::arg("tolerance")) - .def("meshForEach", &smtk::mesh::Interface::meshForEach, py::arg("meshes"), py::arg("filter")) - .def("name", (std::string (smtk::mesh::Interface::*)() const) &smtk::mesh::Interface::name) - .def("numMeshes", &smtk::mesh::Interface::numMeshes, py::arg("handle")) - .def("pointDifference", &smtk::mesh::Interface::pointDifference, py::arg("a"), py::arg("b"), py::arg("bpc"), py::arg("containsFunctor")) - .def("pointForEach", &smtk::mesh::Interface::pointForEach, py::arg("points"), py::arg("filter")) - .def("pointIntersect", &smtk::mesh::Interface::pointIntersect, py::arg("a"), py::arg("b"), py::arg("bpc"), py::arg("containsFunctor")) - .def("pointLocator", (smtk::mesh::PointLocatorImplPtr (smtk::mesh::Interface::*)(::smtk::mesh::HandleRange const &)) &smtk::mesh::Interface::pointLocator, py::arg("points")) - .def("pointLocator", (smtk::mesh::PointLocatorImplPtr (smtk::mesh::Interface::*)(::size_t, const std::function(::size_t)>&)) &smtk::mesh::Interface::pointLocator, py::arg("numPoints"), py::arg("coordinates")) - .def("rootAssociation", &smtk::mesh::Interface::rootAssociation) - .def("setAssociation", &smtk::mesh::Interface::setAssociation, py::arg("modelUUID"), py::arg("meshsets")) - .def("setCoordinates", (bool (smtk::mesh::Interface::*)(::smtk::mesh::HandleRange const &, double const * const)) &smtk::mesh::Interface::setCoordinates, py::arg("points"), py::arg("xyz")) - .def("setCoordinates", (bool (smtk::mesh::Interface::*)(::smtk::mesh::HandleRange const &, float const * const)) &smtk::mesh::Interface::setCoordinates, py::arg("points"), py::arg("xyz")) - .def("setField", (bool (smtk::mesh::Interface::*)(const smtk::mesh::HandleRange&, const smtk::mesh::PointFieldTag&, const void* const)) &smtk::mesh::Interface::setField, py::arg("points"), py::arg("pfTag"), py::arg("field")) - .def("setField", (bool (smtk::mesh::Interface::*)(const smtk::mesh::HandleRange&, const smtk::mesh::CellFieldTag&, const void* const)) &smtk::mesh::Interface::setField, py::arg("points"), py::arg("pfTag"), py::arg("field")) - .def("setCellField", &smtk::mesh::Interface::setCellField, py::arg("meshsets"), py::arg("cfTag"), py::arg("field")) - .def("setDirichlet", &smtk::mesh::Interface::setDirichlet, py::arg("meshsets"), py::arg("dirichlet")) - .def("setDomain", &smtk::mesh::Interface::setDomain, py::arg("meshsets"), py::arg("domain")) - .def("setModifiedState", &smtk::mesh::Interface::setModifiedState, py::arg("state")) - .def("setNeumann", &smtk::mesh::Interface::setNeumann, py::arg("meshsets"), py::arg("neumann")) - .def("setPointField", &smtk::mesh::Interface::setPointField, py::arg("meshsets"), py::arg("pfTag"), py::arg("field")) - .def("setRootAssociation", &smtk::mesh::Interface::setRootAssociation, py::arg("modelUUID")) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::PointLocatorImpl > pybind11_init_smtk_mesh_PointLocatorImpl(py::module &m) -{ - PySharedPtrClass< smtk::mesh::PointLocatorImpl > instance(m, "PointLocatorImpl"); - instance - .def("deepcopy", (smtk::mesh::PointLocatorImpl & (smtk::mesh::PointLocatorImpl::*)(::smtk::mesh::PointLocatorImpl const &)) &smtk::mesh::PointLocatorImpl::operator=) - .def("locatePointsWithinRadius", &smtk::mesh::PointLocatorImpl::locatePointsWithinRadius, py::arg("x"), py::arg("y"), py::arg("z"), py::arg("radius"), py::arg("results")) - .def("range", &smtk::mesh::PointLocatorImpl::range) - ; - py::class_< smtk::mesh::PointLocatorImpl::Results >(instance, "Results") - .def(py::init<>()) - .def(py::init<::smtk::mesh::PointLocatorImpl::Results const &>()) - .def("deepcopy", (smtk::mesh::PointLocatorImpl::Results & (smtk::mesh::PointLocatorImpl::Results::*)(::smtk::mesh::PointLocatorImpl::Results const &)) &smtk::mesh::PointLocatorImpl::Results::operator=) - .def_readwrite("pointIds", &smtk::mesh::PointLocatorImpl::Results::pointIds) - .def_readwrite("sqDistances", &smtk::mesh::PointLocatorImpl::Results::sqDistances) - .def_readwrite("x_s", &smtk::mesh::PointLocatorImpl::Results::x_s) - .def_readwrite("y_s", &smtk::mesh::PointLocatorImpl::Results::y_s) - .def_readwrite("z_s", &smtk::mesh::PointLocatorImpl::Results::z_s) - .def_readwrite("want_sqDistances", &smtk::mesh::PointLocatorImpl::Results::want_sqDistances) - .def_readwrite("want_Coordinates", &smtk::mesh::PointLocatorImpl::Results::want_Coordinates) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindInterpolateOntoMesh.h b/smtk/mesh/pybind11/PybindInterpolateOntoMesh.h deleted file mode 100644 index e6374ac9b978365897c69c63dbb28b0f6e7aa247..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindInterpolateOntoMesh.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_operators_InterpolateOntoMesh_h -#define pybind_smtk_mesh_operators_InterpolateOntoMesh_h - -#include - -#include "smtk/mesh/operators/InterpolateOntoMesh.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::InterpolateOntoMesh, smtk::operation::XMLOperation > pybind11_init_smtk_mesh_InterpolateOntoMesh(py::module &m) -{ - PySharedPtrClass< smtk::mesh::InterpolateOntoMesh, smtk::operation::XMLOperation > instance(m, "InterpolateOntoMesh"); - instance - .def(py::init<>()) - .def("ableToOperate", &smtk::mesh::InterpolateOntoMesh::ableToOperate) - .def_static("create", (std::shared_ptr (*)()) &smtk::mesh::InterpolateOntoMesh::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::mesh::InterpolateOntoMesh::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::InterpolateOntoMesh::*)() const) &smtk::mesh::InterpolateOntoMesh::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::InterpolateOntoMesh::*)()) &smtk::mesh::InterpolateOntoMesh::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindMesh.cxx b/smtk/mesh/pybind11/PybindMesh.cxx deleted file mode 100644 index 82d58b1e4b41302b239a2514a3e6fe17cb2f372d..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindMesh.cxx +++ /dev/null @@ -1,192 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include -#include -SMTK_THIRDPARTY_POST_INCLUDE - -#include - -namespace py = pybind11; - -template -using PySharedPtrClass = py::class_, Args...>; - -#include "PybindApplyToMesh.h" -#include "PybindCellField.h" -#include "PybindCellSet.h" -#include "PybindCellTypes.h" -#include "PybindResource.h" -#include "PybindComponent.h" -#include "PybindDimensionTypes.h" -#include "PybindExtractCanonicalIndices.h" -#include "PybindExtractMeshConstants.h" -#include "PybindExtractTessellation.h" -#include "PybindFieldTypes.h" -#include "PybindForEachTypes.h" -#include "PybindHandle.h" -#include "PybindInterface.h" -#include "PybindMeshSet.h" -#include "PybindMetrics.h" -#include "PybindPointField.h" -#include "PybindPointConnectivity.h" -#include "PybindPointLocator.h" -#include "PybindPointSet.h" -#include "PybindQueryTypes.h" -#include "PybindReclassify.h" -#include "PybindSelection.h" -#include "PybindTypeSet.h" - -#include "PybindPointCloud.h" -#include "PybindPointCloudGenerator.h" -#include "PybindStructuredGrid.h" -#include "PybindStructuredGridGenerator.h" - -#include "PybindDeleteMesh.h" -#include "PybindElevateMesh.h" -#include "PybindExport.h" -#include "PybindImport.h" -#include "PybindInterpolateOntoMesh.h" -#include "PybindRead.h" -#include "PybindWrite.h" - -#include "PybindRegistrar.h" - -#include "smtk/mesh/interpolation/PointCloudFromCSV.h" - -#include "smtk/operation/XMLOperation.h" - -PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); - -PYBIND11_MODULE(_smtkPybindMesh, mesh) -{ - mesh.doc() = ""; - - py::module::import("smtk.resource"); - py::module::import("smtk.model"); - - // The order of these function calls is important! It was determined by - // comparing the dependencies of each of the wrapped objects. - py::class_< smtk::mesh::HandleInterval > smtk_mesh_HandleInterval = pybind11_init_HandleInterval(mesh); - PySharedPtrClass< smtk::mesh::const_element_iterator > smtk_mesh_const_element_iterator = pybind11_init_const_element_iterator(mesh); - py::class_< smtk::mesh::HandleRange > smtk_mesh_HandleRange = pybind11_init_HandleRange(mesh); - - PySharedPtrClass< smtk::mesh::Allocator > smtk_mesh_Allocator = pybind11_init_smtk_mesh_Allocator(mesh); - PySharedPtrClass< smtk::mesh::BufferedCellAllocator > smtk_mesh_BufferedCellAllocator = pybind11_init_smtk_mesh_BufferedCellAllocator(mesh); - PySharedPtrClass< smtk::mesh::IncrementalAllocator > smtk_mesh_IncrementalAllocator = pybind11_init_smtk_mesh_IncrementalAllocator(mesh); - pybind11_init_smtk_mesh_DimensionType(mesh); - pybind11_init_smtk_mesh_FieldType(mesh); - PySharedPtrClass< smtk::mesh::CellForEach > smtk_mesh_CellForEach = pybind11_init_smtk_mesh_CellForEach(mesh); - PySharedPtrClass< smtk::mesh::CellSet > smtk_mesh_CellSet = pybind11_init_smtk_mesh_CellSet(mesh); - PySharedPtrClass< smtk::mesh::Resource> smtk_mesh_Resource = pybind11_init_smtk_mesh_Resource(mesh); - PySharedPtrClass< smtk::mesh::ConnectivityStorage > smtk_mesh_ConnectivityStorage = pybind11_init_smtk_mesh_ConnectivityStorage(mesh); - PySharedPtrClass< smtk::mesh::CellField > smtk_mesh_CellField = pybind11_init_smtk_mesh_CellField(mesh); - PySharedPtrClass< smtk::mesh::CellField > smtk_mesh_PointField = pybind11_init_smtk_mesh_PointField(mesh); - PySharedPtrClass< smtk::mesh::utility::CanonicalIndices > smtk_mesh_CanonicalIndices = pybind11_init_smtk_mesh_CanonicalIndices(mesh); - PySharedPtrClass< smtk::mesh::utility::MeshConstants > smtk_mesh_MeshConstants = pybind11_init_smtk_mesh_MeshConstants(mesh); - PySharedPtrClass< smtk::mesh::IntegerTag > smtk_mesh_IntegerTag = pybind11_init_smtk_mesh_IntegerTag(mesh); - PySharedPtrClass< smtk::mesh::Interface > smtk_mesh_Interface = pybind11_init_smtk_mesh_Interface(mesh); - PySharedPtrClass< smtk::mesh::MeshForEach > smtk_mesh_MeshForEach = pybind11_init_smtk_mesh_MeshForEach(mesh); - PySharedPtrClass< smtk::mesh::MeshSet > smtk_mesh_MeshSet = pybind11_init_smtk_mesh_MeshSet(mesh); - PySharedPtrClass< smtk::mesh::OpaqueTag<16> > smtk_mesh_OpaqueTag_16_ = pybind11_init_smtk_mesh_OpaqueTag_16_(mesh); - PySharedPtrClass< smtk::mesh::PointConnectivity > smtk_mesh_PointConnectivity = pybind11_init_smtk_mesh_PointConnectivity(mesh); - PySharedPtrClass< smtk::mesh::PointForEach > smtk_mesh_PointForEach = pybind11_init_smtk_mesh_PointForEach(mesh); - PySharedPtrClass< smtk::mesh::PointLocator > smtk_mesh_PointLocator = pybind11_init_smtk_mesh_PointLocator(mesh); - PySharedPtrClass< smtk::mesh::PointLocatorImpl > smtk_mesh_PointLocatorImpl = pybind11_init_smtk_mesh_PointLocatorImpl(mesh); - PySharedPtrClass< smtk::mesh::PointSet > smtk_mesh_PointSet = pybind11_init_smtk_mesh_PointSet(mesh); - PySharedPtrClass< smtk::mesh::utility::PreAllocatedCanonicalIndices > smtk_mesh_PreAllocatedCanonicalIndices = pybind11_init_smtk_mesh_PreAllocatedCanonicalIndices(mesh); - PySharedPtrClass< smtk::mesh::utility::PreAllocatedMeshConstants > smtk_mesh_PreAllocatedMeshConstants = pybind11_init_smtk_mesh_PreAllocatedMeshConstants(mesh); - PySharedPtrClass< smtk::mesh::utility::PreAllocatedTessellation > smtk_mesh_PreAllocatedTessellation = pybind11_init_smtk_mesh_PreAllocatedTessellation(mesh); - PySharedPtrClass< smtk::mesh::utility::Tessellation > smtk_mesh_Tessellation = pybind11_init_smtk_mesh_Tessellation(mesh); - PySharedPtrClass< smtk::mesh::TypeSet > smtk_mesh_TypeSet = pybind11_init_smtk_mesh_TypeSet(mesh); - - pybind11_init_smtk_mesh_rangeElementsBegin(mesh); - pybind11_init_smtk_mesh_rangeElementsEnd(mesh); - pybind11_init_smtk_mesh_rangeElement(mesh); - pybind11_init_smtk_mesh_rangeContains(mesh); - pybind11_init_smtk_mesh_rangeIndex(mesh); - pybind11_init_smtk_mesh_rangeIntervalCount(mesh); - pybind11_init_smtk_mesh_rangesEqual(mesh); - pybind11_init_smtk_mesh_CellType(mesh); - pybind11_init_smtk_mesh_ContainmentType(mesh); - pybind11_init_smtk_mesh_cellTypeSummary(mesh); - pybind11_init__extractCanonicalIndices(mesh); - pybind11_init__ZN4smtk4mesh21extractDirichletMeshConstantsERKNS0_7MeshSetERNS0_17PreAllocatedMeshConstantsE(mesh); - pybind11_init__ZN4smtk4mesh21extractDirichletMeshConstantsERKNS0_7MeshSetERKNS0_8PointSetERNS0_17PreAllocatedMeshConstantsE(mesh); - pybind11_init__ZN4smtk4mesh18extractDomainMeshConstantsERKNS0_7MeshSetERNS0_17PreAllocatedMeshConstantsE(mesh); - pybind11_init__ZN4smtk4mesh18extractDomainMeshConstantsERKNS0_7MeshSetERKNS0_8PointSetERNS0_17PreAllocatedMeshConstantsE(mesh); - pybind11_init__ZN4smtk4mesh19extractNeumannMeshConstantsERKNS0_7MeshSetERNS0_17PreAllocatedMeshConstantsE(mesh); - pybind11_init__ZN4smtk4mesh19extractNeumannMeshConstantsERKNS0_7MeshSetERKNS0_8PointSetERNS0_17PreAllocatedMeshConstantsE(mesh); - pybind11_init__ZN4smtk4mesh26extractOrderedTessellationERKNS_5model4EdgeERKNSt3__110shared_ptrINS0_10ResourceEEERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init__ZN4smtk4mesh26extractOrderedTessellationERKNS_5model4LoopERKNSt3__110shared_ptrINS0_10ResourceEEERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init__ZN4smtk4mesh26extractOrderedTessellationERKNS_5model4EdgeERKNSt3__110shared_ptrINS0_10ResourceEEERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init__ZN4smtk4mesh26extractOrderedTessellationERKNS_5model4LoopERKNSt3__110shared_ptrINS0_10ResourceEEERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init__ZN4smtk4mesh19extractTessellationERKNS0_7MeshSetERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init__ZN4smtk4mesh19extractTessellationERKNS0_7CellSetERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init__ZN4smtk4mesh19extractTessellationERKNS_5model9EntityRefERKNSt3__110shared_ptrINS0_10ResourceEEERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init__ZN4smtk4mesh19extractTessellationERKNS0_7MeshSetERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init__ZN4smtk4mesh19extractTessellationERKNS0_7CellSetERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init__ZN4smtk4mesh19extractTessellationERNS0_17PointConnectivityERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init__ZN4smtk4mesh19extractTessellationERKNS_5model9EntityRefERKNSt3__110shared_ptrINS0_10ResourceEEERKNS0_8PointSetERNS0_24PreAllocatedTessellationE(mesh); - pybind11_init_smtk_mesh_metrics(mesh); - pybind11_init_smtk_mesh_utility_applyScalarCellField(mesh); - pybind11_init_smtk_mesh_utility_applyScalarPointField(mesh); - pybind11_init_smtk_mesh_utility_applyVectorCellField(mesh); - pybind11_init_smtk_mesh_utility_applyVectorPointField(mesh); - pybind11_init_smtk_mesh_utility_applyWarp(mesh); - pybind11_init_smtk_mesh_utility_undoWarp(mesh); - pybind11_init_smtk_mesh_cell_for_each(mesh); - pybind11_init_smtk_mesh_mesh_for_each(mesh); - pybind11_init_smtk_mesh_point_for_each(mesh); - pybind11_init_smtk_mesh_fuse(mesh); - pybind11_init_smtk_mesh_make_disjoint(mesh); - pybind11_init_smtk_mesh_merge(mesh); - pybind11_init_smtk_mesh_cell_point_difference(mesh); - pybind11_init_smtk_mesh_cell_point_intersect(mesh); - pybind11_init_smtk_mesh_cell_set_difference(mesh); - pybind11_init_smtk_mesh_mesh_set_difference(mesh); - pybind11_init_smtk_mesh_point_set_difference(mesh); - pybind11_init_smtk_mesh_cell_set_intersect(mesh); - pybind11_init_smtk_mesh_mesh_set_intersect(mesh); - pybind11_init_smtk_mesh_point_set_intersect(mesh); - pybind11_init_smtk_mesh_cell_set_union(mesh); - pybind11_init_smtk_mesh_mesh_set_union(mesh); - pybind11_init_smtk_mesh_point_set_union(mesh); - pybind11_init_smtk_mesh_split(mesh); - pybind11_init_smtk_mesh_verticesPerCell(mesh); - PySharedPtrClass< smtk::mesh::Dirichlet > smtk_mesh_Dirichlet = pybind11_init_smtk_mesh_Dirichlet(mesh, smtk_mesh_IntegerTag); - PySharedPtrClass< smtk::mesh::Domain > smtk_mesh_Domain = pybind11_init_smtk_mesh_Domain(mesh, smtk_mesh_IntegerTag); - PySharedPtrClass< smtk::mesh::Neumann > smtk_mesh_Neumann = pybind11_init_smtk_mesh_Neumann(mesh, smtk_mesh_IntegerTag); - PySharedPtrClass< smtk::mesh::UUIDTag > smtk_mesh_UUIDTag = pybind11_init_smtk_mesh_UUIDTag(mesh, smtk_mesh_OpaqueTag_16_); - PySharedPtrClass< smtk::mesh::Model > smtk_mesh_Model = pybind11_init_smtk_mesh_Model(mesh, smtk_mesh_UUIDTag); - PySharedPtrClass< smtk::mesh::Component > smtk_mesh_Component = pybind11_init_smtk_mesh_Component(mesh); - PySharedPtrClass< smtk::mesh::Selection > smtk_mesh_Selection = pybind11_init_smtk_mesh_Selection(mesh); - - PySharedPtrClass< smtk::mesh::DeleteMesh, smtk::operation::XMLOperation > smtk_mesh_DeleteMesh = pybind11_init_smtk_mesh_DeleteMesh(mesh); - PySharedPtrClass< smtk::mesh::ElevateMesh, smtk::operation::XMLOperation > smtk_mesh_ElevateMesh = pybind11_init_smtk_mesh_ElevateMesh(mesh); - PySharedPtrClass< smtk::mesh::Export, smtk::operation::XMLOperation > smtk_mesh_Export = pybind11_init_smtk_mesh_Export(mesh); - PySharedPtrClass< smtk::mesh::InterpolateOntoMesh, smtk::operation::XMLOperation > smtk_mesh_InterpolateOntoMesh = pybind11_init_smtk_mesh_InterpolateOntoMesh(mesh); - PySharedPtrClass< smtk::mesh::Import, smtk::operation::XMLOperation > smtk_mesh_Import = pybind11_init_smtk_mesh_Import(mesh); - PySharedPtrClass< smtk::mesh::Read, smtk::operation::XMLOperation > smtk_mesh_Read = pybind11_init_smtk_mesh_Read(mesh); - PySharedPtrClass< smtk::mesh::Write, smtk::operation::XMLOperation > smtk_mesh_Write = pybind11_init_smtk_mesh_Write(mesh); - - py::class_< smtk::mesh::PointCloud > smtk_mesh_PointCloud = pybind11_init_smtk_mesh_PointCloud(mesh); - py::class_< smtk::mesh::StructuredGrid > smtk_mesh_StructuredGrid = pybind11_init_smtk_mesh_StructuredGrid(mesh); - py::class_< smtk::mesh::PointCloudGenerator > smtk_mesh_PointCloudGenerator = pybind11_init_smtk_mesh_PointCloudGenerator(mesh); - py::class_< smtk::mesh::StructuredGridGenerator > smtk_mesh_StructuredGridGenerator = pybind11_init_smtk_mesh_StructuredGridGenerator(mesh); - - py::class_< smtk::mesh::Registrar > smtk_mesh_Registrar = pybind11_init_smtk_mesh_Registrar(mesh); - - bool pcRegistered = smtk::mesh::PointCloudFromCSV::registerClass(); - (void)pcRegistered; -} diff --git a/smtk/mesh/pybind11/PybindMeshSet.h b/smtk/mesh/pybind11/PybindMeshSet.h deleted file mode 100644 index 5e3e7128b7f9b532a0d8ff3b5fed7f6d2b9dc7e7..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindMeshSet.h +++ /dev/null @@ -1,118 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_MeshSet_h -#define pybind_smtk_mesh_MeshSet_h - -#include - -#include "smtk/mesh/core/MeshSet.h" - -#include "smtk/common/UUID.h" -#include "smtk/common/pybind11/PybindUUIDTypeCaster.h" -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/CellTypes.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/PointConnectivity.h" -#include "smtk/mesh/core/PointSet.h" -#include "smtk/mesh/core/TypeSet.h" -#include "smtk/model/EntityRef.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::MeshSet > pybind11_init_smtk_mesh_MeshSet(py::module &m) -{ - PySharedPtrClass< smtk::mesh::MeshSet > instance(m, "MeshSet"); - instance - .def(py::init<>()) - .def(py::init<::smtk::mesh::ResourcePtr const &, ::smtk::mesh::Handle>()) - .def(py::init<::smtk::mesh::ConstResourcePtr const &, ::smtk::mesh::Handle>()) - .def(py::init<::smtk::mesh::ResourcePtr const &, ::smtk::mesh::Handle, ::smtk::mesh::HandleRange const &>()) - .def(py::init<::smtk::mesh::ConstResourcePtr const &, ::smtk::mesh::Handle, ::smtk::mesh::HandleRange const &>()) - .def(py::init<::smtk::mesh::MeshSet const &>()) - .def("__ne__", (bool (smtk::mesh::MeshSet::*)(::smtk::mesh::MeshSet const &) const) &smtk::mesh::MeshSet::operator!=) - .def("__lt__", (bool (smtk::mesh::MeshSet::*)(::smtk::mesh::MeshSet const &) const) &smtk::mesh::MeshSet::operator<) - .def("deepcopy", (smtk::mesh::MeshSet & (smtk::mesh::MeshSet::*)(::smtk::mesh::MeshSet const &)) &smtk::mesh::MeshSet::operator=) - .def("__eq__", (bool (smtk::mesh::MeshSet::*)(::smtk::mesh::MeshSet const &) const) &smtk::mesh::MeshSet::operator==) - .def("append", &smtk::mesh::MeshSet::append, py::arg("other")) - .def("cells", (smtk::mesh::CellSet (smtk::mesh::MeshSet::*)() const) &smtk::mesh::MeshSet::cells) - .def("cells", (smtk::mesh::CellSet (smtk::mesh::MeshSet::*)(::smtk::mesh::CellType) const) &smtk::mesh::MeshSet::cells, py::arg("cellType")) - .def("cells", (smtk::mesh::CellSet (smtk::mesh::MeshSet::*)(::smtk::mesh::CellTypes) const) &smtk::mesh::MeshSet::cells, py::arg("cTypes")) - .def("cells", (smtk::mesh::CellSet (smtk::mesh::MeshSet::*)(::smtk::mesh::DimensionType) const) &smtk::mesh::MeshSet::cells, py::arg("dim")) - .def("resource", &smtk::mesh::MeshSet::resource) - .def("createCellField", [](smtk::mesh::MeshSet& ms, const std::string& name, int dimension, const std::vector& data){ return ms.createCellField(name, dimension, smtk::mesh::FieldType::Double, data.data()); }, py::arg("name"), py::arg("dimension"), py::arg("field")) - .def("createCellField", [](smtk::mesh::MeshSet& ms, const std::string& name, int dimension, const std::vector& data){ return ms.createCellField(name, dimension, smtk::mesh::FieldType::Integer, data.data()); }, py::arg("name"), py::arg("dimension"), py::arg("field")) - .def("createCellField", [](smtk::mesh::MeshSet& ms, const std::string& name, int dimension, const smtk::mesh::FieldType& type){ return ms.createCellField(name, dimension, type); }, py::arg("name"), py::arg("dimension"), py::arg("type")) - .def("cellField", &smtk::mesh::MeshSet::cellField, py::arg("name")) - .def("cellFields", [](smtk::mesh::MeshSet const& ms) { std::vector tmp; auto fields = ms.cellFields(); tmp.reserve(fields.size()); tmp.insert(tmp.begin(), fields.begin(), fields.end()); return tmp; }) - .def("createPointField", [](smtk::mesh::MeshSet& ms, const std::string& name, int dimension, const std::vector& data){ return ms.createPointField(name, dimension, smtk::mesh::FieldType::Double, data.data()); }, py::arg("name"), py::arg("dimension"), py::arg("field")) - .def("createPointField", [](smtk::mesh::MeshSet& ms, const std::string& name, int dimension, const std::vector& data){ return ms.createPointField(name, dimension, smtk::mesh::FieldType::Integer, data.data()); }, py::arg("name"), py::arg("dimension"), py::arg("field")) - .def("createPointField", [](smtk::mesh::MeshSet& ms, const std::string& name, int dimension, const smtk::mesh::FieldType& type){ return ms.createPointField(name, dimension, type); }, py::arg("name"), py::arg("dimension"), py::arg("type")) - .def("pointField", &smtk::mesh::MeshSet::pointField, py::arg("name")) - .def("pointFields", [](smtk::mesh::MeshSet const& ms) { std::vector tmp; auto fields = ms.pointFields(); tmp.reserve(fields.size()); tmp.insert(tmp.begin(), fields.begin(), fields.end()); return tmp; }) - .def("dirichlets", &smtk::mesh::MeshSet::dirichlets) - .def("domains", &smtk::mesh::MeshSet::domains) - .def("extractShell", (smtk::mesh::MeshSet (smtk::mesh::MeshSet::*)() const) &smtk::mesh::MeshSet::extractShell) - .def("extractAdjacenciesOfDimension", (smtk::mesh::MeshSet (smtk::mesh::MeshSet::*)(int) const) &smtk::mesh::MeshSet::extractAdjacenciesOfDimension) - .def("id", &smtk::mesh::MeshSet::id) - .def("is_empty", &smtk::mesh::MeshSet::is_empty) - .def("mergeCoincidentContactPoints", &smtk::mesh::MeshSet::mergeCoincidentContactPoints, py::arg("tolerance") = 9.9999999999999995E-7) - .def("modelEntities", (bool (smtk::mesh::MeshSet::*)(smtk::model::EntityRefArray&)) &smtk::mesh::MeshSet::modelEntities, py::arg("arg0")) - .def("modelEntities", [](const smtk::mesh::MeshSet& ms){ smtk::model::EntityRefArray refs; ms.modelEntities(refs); return refs; }) - .def("modelEntityIds", &smtk::mesh::MeshSet::modelEntityIds) - .def("name", &smtk::mesh::MeshSet::name) - .def("names", &smtk::mesh::MeshSet::names) - .def("neumanns", &smtk::mesh::MeshSet::neumanns) - .def("pointConnectivity", &smtk::mesh::MeshSet::pointConnectivity) - .def("points", &smtk::mesh::MeshSet::points, py::arg("boundary_only") = false) - .def("range", &smtk::mesh::MeshSet::range) - .def("removeCellField", &smtk::mesh::MeshSet::removeCellField, py::arg("cellfield")) - .def("removePointField", &smtk::mesh::MeshSet::removePointField, py::arg("pointfield")) - .def("setDirichlet", &smtk::mesh::MeshSet::setDirichlet, py::arg("d")) - .def("setDomain", &smtk::mesh::MeshSet::setDomain, py::arg("d")) - .def("setModelEntity", &smtk::mesh::MeshSet::setModelEntity, py::arg("arg0")) - .def("setModelEntityId", &smtk::mesh::MeshSet::setModelEntityId, py::arg("arg0")) - .def("setName", &smtk::mesh::MeshSet::setName) - .def("setNeumann", &smtk::mesh::MeshSet::setNeumann, py::arg("n")) - .def("size", &smtk::mesh::MeshSet::size) - .def("subset", (smtk::mesh::MeshSet (smtk::mesh::MeshSet::*)(::smtk::mesh::DimensionType) const) &smtk::mesh::MeshSet::subset, py::arg("dim")) - .def("subset", (smtk::mesh::MeshSet (smtk::mesh::MeshSet::*)(::smtk::mesh::Domain const &) const) &smtk::mesh::MeshSet::subset, py::arg("d")) - .def("subset", (smtk::mesh::MeshSet (smtk::mesh::MeshSet::*)(::smtk::mesh::Dirichlet const &) const) &smtk::mesh::MeshSet::subset, py::arg("d")) - .def("subset", (smtk::mesh::MeshSet (smtk::mesh::MeshSet::*)(::smtk::mesh::Neumann const &) const) &smtk::mesh::MeshSet::subset, py::arg("n")) - .def("subset", (smtk::mesh::MeshSet (smtk::mesh::MeshSet::*)(::size_t) const) &smtk::mesh::MeshSet::subset, py::arg("ith")) - .def("types", &smtk::mesh::MeshSet::types) - ; - return instance; -} - -inline void pybind11_init_smtk_mesh_mesh_for_each(py::module &m) -{ - m.def("for_each", (void (*)(const smtk::mesh::MeshSet&, smtk::mesh::MeshForEach&)) &smtk::mesh::for_each, "", py::arg("a"), py::arg("filter")); -} - -inline void pybind11_init_smtk_mesh_mesh_set_difference(py::module &m) -{ - m.def("set_difference", (smtk::mesh::MeshSet (*)(const smtk::mesh::MeshSet&, const smtk::mesh::MeshSet&)) &smtk::mesh::set_difference, "", py::arg("a"), py::arg("b")); -} - -inline void pybind11_init_smtk_mesh_mesh_set_intersect(py::module &m) -{ - m.def("set_intersect", (smtk::mesh::MeshSet (*)(const smtk::mesh::MeshSet&, const smtk::mesh::MeshSet&)) &smtk::mesh::set_intersect, "", py::arg("a"), py::arg("b")); -} - -inline void pybind11_init_smtk_mesh_mesh_set_union(py::module &m) -{ - m.def("set_union", (smtk::mesh::MeshSet (*)(const smtk::mesh::MeshSet&, const smtk::mesh::MeshSet&)) &smtk::mesh::set_union, "", py::arg("a"), py::arg("b")); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindMetrics.h b/smtk/mesh/pybind11/PybindMetrics.h deleted file mode 100644 index 3546bb3a4f38e28510ec84262cf54fa626a63e5f..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindMetrics.h +++ /dev/null @@ -1,29 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_Metrics_h -#define pybind_smtk_mesh_Metrics_h - -#include -#include - -#include "smtk/mesh/utility/Metrics.h" - -namespace py = pybind11; - - -inline void pybind11_init_smtk_mesh_metrics(py::module &m) -{ - m.def("extent", &smtk::mesh::utility::extent); - m.def("highestDimension", &smtk::mesh::utility::highestDimension); - m.def("eulerCharacteristic", &smtk::mesh::utility::eulerCharacteristic); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindPointCloud.h b/smtk/mesh/pybind11/PybindPointCloud.h deleted file mode 100644 index 3495af77f3005e96ec27a64d8e423818cab58c61..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindPointCloud.h +++ /dev/null @@ -1,38 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_interpolation_PointCloud_h -#define pybind_smtk_mesh_interpolation_PointCloud_h - -#include - -#include "smtk/mesh/interpolation/PointCloud.h" - -namespace py = pybind11; - -inline py::class_< smtk::mesh::PointCloud > pybind11_init_smtk_mesh_PointCloud(py::module &m) -{ - py::class_< smtk::mesh::PointCloud > instance(m, "PointCloud"); - instance - .def(py::init<::size_t, ::std::function (unsigned long)> const &, ::std::function const &, ::std::function const &>()) - .def(py::init<>()) - .def(py::init<::size_t, ::std::function (unsigned long)> const &, ::std::function const &>()) - .def(py::init<::size_t, double const * const, double const * const>()) - .def(py::init<::size_t, float const * const, float const * const>()) - .def(py::init<::smtk::mesh::PointCloud const &>()) - .def("deepcopy", (smtk::mesh::PointCloud & (smtk::mesh::PointCloud::*)(::smtk::mesh::PointCloud const &)) &smtk::mesh::PointCloud::operator=) - .def("size", &smtk::mesh::PointCloud::size) - .def("coordinates", &smtk::mesh::PointCloud::coordinates) - .def("data", &smtk::mesh::PointCloud::data) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindPointCloudGenerator.h b/smtk/mesh/pybind11/PybindPointCloudGenerator.h deleted file mode 100644 index c318004bae56915c69950ff59eace100606eb626..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindPointCloudGenerator.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_PointCloudGenerator_h -#define pybind_smtk_mesh_PointCloudGenerator_h - -#include - -#include "smtk/mesh/interpolation/PointCloudGenerator.h" -#include "smtk/model/AuxiliaryGeometry.h" - -namespace py = pybind11; - -inline py::class_ pybind11_init_smtk_mesh_PointCloudGenerator(py::module &m) -{ - py::class_ instance(m, "PointCloudGenerator"); - instance - .def(py::init<>()) - .def(py::init()) - .def("__call__", (smtk::mesh::PointCloud (smtk::mesh::PointCloudGenerator::*)(smtk::model::AuxiliaryGeometry const &)) &smtk::mesh::PointCloudGenerator::operator()) - .def("__call__", (smtk::mesh::PointCloud (smtk::mesh::PointCloudGenerator::*)(::std::string const &)) &smtk::mesh::PointCloudGenerator::operator()) - .def("deepcopy", (smtk::mesh::PointCloudGenerator & (smtk::mesh::PointCloudGenerator::*)(smtk::mesh::PointCloudGenerator const &)) &smtk::mesh::PointCloudGenerator::operator=) - .def("valid", (bool (smtk::mesh::PointCloudGenerator::*)(::std::string const&) const) &smtk::mesh::PointCloudGenerator::valid, py::arg("file")) - .def("valid", (bool (smtk::mesh::PointCloudGenerator::*)(smtk::model::AuxiliaryGeometry const&) const) &smtk::mesh::PointCloudGenerator::valid, py::arg("auxGeom")) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindPointConnectivity.h b/smtk/mesh/pybind11/PybindPointConnectivity.h deleted file mode 100644 index 4738bf2c65df814b7072e72460db48e7386204ef..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindPointConnectivity.h +++ /dev/null @@ -1,39 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_PointConnectivity_h -#define pybind_smtk_mesh_PointConnectivity_h - -#include - -#include "smtk/mesh/core/PointConnectivity.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::PointConnectivity > pybind11_init_smtk_mesh_PointConnectivity(py::module &m) -{ - PySharedPtrClass< smtk::mesh::PointConnectivity > instance(m, "PointConnectivity"); - instance - .def(py::init<::smtk::mesh::ResourcePtr const &, ::smtk::mesh::HandleRange const &>()) - .def(py::init<::smtk::mesh::PointConnectivity const &>()) - .def("__ne__", (bool (smtk::mesh::PointConnectivity::*)(::smtk::mesh::PointConnectivity const &) const) &smtk::mesh::PointConnectivity::operator!=) - .def("deepcopy", (smtk::mesh::PointConnectivity & (smtk::mesh::PointConnectivity::*)(::smtk::mesh::PointConnectivity const &)) &smtk::mesh::PointConnectivity::operator=) - .def("__eq__", (bool (smtk::mesh::PointConnectivity::*)(::smtk::mesh::PointConnectivity const &) const) &smtk::mesh::PointConnectivity::operator==) - // .def("fetchNextCell", (bool (smtk::mesh::PointConnectivity::*)(int &, ::smtk::mesh::Handle const * &)) &smtk::mesh::PointConnectivity::fetchNextCell, py::arg("numPts"), py::arg("points")) - // .def("fetchNextCell", (bool (smtk::mesh::PointConnectivity::*)(::smtk::mesh::CellType &, int &, ::smtk::mesh::Handle const * &)) &smtk::mesh::PointConnectivity::fetchNextCell, py::arg("cellType"), py::arg("numPts"), py::arg("points")) - .def("initCellTraversal", &smtk::mesh::PointConnectivity::initCellTraversal) - .def("is_empty", &smtk::mesh::PointConnectivity::is_empty) - .def("numberOfCells", &smtk::mesh::PointConnectivity::numberOfCells) - .def("size", &smtk::mesh::PointConnectivity::size) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindPointField.h b/smtk/mesh/pybind11/PybindPointField.h deleted file mode 100644 index b19dfcbab6f6ba320ce21bed6e0a2bff9d2643b9..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindPointField.h +++ /dev/null @@ -1,53 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_PointField_h -#define pybind_smtk_mesh_PointField_h - -#include - -#include "smtk/mesh/core/PointField.h" - -#include "smtk/mesh/core/PointSet.h" -#include "smtk/mesh/core/MeshSet.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::PointField > pybind11_init_smtk_mesh_PointField(py::module &m) -{ - PySharedPtrClass< smtk::mesh::PointField > instance(m, "PointField"); - instance - .def(py::init<>()) - .def(py::init<::smtk::mesh::MeshSet const &, ::std::string const &>()) - .def(py::init<::smtk::mesh::PointField const &>()) - .def("__ne__", (bool (smtk::mesh::PointField::*)(::smtk::mesh::PointField const &) const) &smtk::mesh::PointField::operator!=) - .def("__lt__", (bool (smtk::mesh::PointField::*)(::smtk::mesh::PointField const &) const) &smtk::mesh::PointField::operator<) - .def("deepcopy", (smtk::mesh::PointField & (smtk::mesh::PointField::*)(::smtk::mesh::PointField const &)) &smtk::mesh::PointField::operator=) - .def("__eq__", (bool (smtk::mesh::PointField::*)(::smtk::mesh::PointField const &) const) &smtk::mesh::PointField::operator==) - .def("points", &smtk::mesh::PointField::points) - .def("dimension", &smtk::mesh::PointField::dimension) - .def("type", &smtk::mesh::PointField::type) - .def("_get_double", [](smtk::mesh::PointField& pf) { std::vector tmp(pf.size() * pf.dimension()); pf.get(tmp.data()); return tmp; }) - .def("_get_double", [](smtk::mesh::PointField& pf, const smtk::mesh::HandleRange& cellIds) { std::vector tmp(cellIds.size() * pf.dimension()); pf.get(cellIds, tmp.data()); return tmp; }) - .def("_get_int", [](smtk::mesh::PointField& pf) { std::vector tmp(pf.size() * pf.dimension()); pf.get(tmp.data()); return tmp; }) - .def("_get_int", [](smtk::mesh::PointField& pf, const smtk::mesh::HandleRange& cellIds) { std::vector tmp(cellIds.size() * pf.dimension()); pf.get(cellIds, tmp.data()); return tmp; }) - .def("isValid", &smtk::mesh::PointField::isValid) - .def("meshset", &smtk::mesh::PointField::meshset) - .def("name", &smtk::mesh::PointField::name) - .def("_set_double", [](smtk::mesh::PointField& pf, const std::vector& data) { return pf.set(data.data()); }) - .def("_set_double", [](smtk::mesh::PointField& pf, const smtk::mesh::HandleRange& cellIds, const std::vector& data) { return pf.set(cellIds, data.data()); }) - .def("_set_int", [](smtk::mesh::PointField& pf, const std::vector& data) { return pf.set(data.data()); }) - .def("_set_int", [](smtk::mesh::PointField& pf, const smtk::mesh::HandleRange& cellIds, const std::vector& data) { return pf.set(cellIds, data.data()); }) - .def("size", &smtk::mesh::PointField::size) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindPointLocator.h b/smtk/mesh/pybind11/PybindPointLocator.h deleted file mode 100644 index 8fbdebaf126e91669103254dd0de1d61195b4b67..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindPointLocator.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_PointLocator_h -#define pybind_smtk_mesh_PointLocator_h - -#include - -#include "smtk/mesh/core/PointLocator.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::PointLocator > pybind11_init_smtk_mesh_PointLocator(py::module &m) -{ - PySharedPtrClass< smtk::mesh::PointLocator > instance(m, "PointLocator"); - instance - .def(py::init<::smtk::mesh::PointLocator const &>()) - .def(py::init<::smtk::mesh::PointSet const &>()) - .def(py::init<::smtk::mesh::ResourcePtr const, ::size_t, const std::function(::size_t)>&>()) - .def(py::init<::smtk::mesh::ResourcePtr const, ::size_t, double const * const>()) - .def(py::init<::smtk::mesh::ResourcePtr const, ::size_t, float const * const>()) - .def("deepcopy", (smtk::mesh::PointLocator & (smtk::mesh::PointLocator::*)(::smtk::mesh::PointLocator const &)) &smtk::mesh::PointLocator::operator=) - .def("find", &smtk::mesh::PointLocator::find, py::arg("x"), py::arg("y"), py::arg("z"), py::arg("radius"), py::arg("results")) - .def("range", &smtk::mesh::PointLocator::range) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindPointSet.h b/smtk/mesh/pybind11/PybindPointSet.h deleted file mode 100644 index e03120f2e0bf1f27e9798459b591f2af2f458c5a..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindPointSet.h +++ /dev/null @@ -1,72 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_PointSet_h -#define pybind_smtk_mesh_PointSet_h - -#include -#include - -#include "smtk/mesh/core/PointSet.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::PointSet > pybind11_init_smtk_mesh_PointSet(py::module &m) -{ - PySharedPtrClass< smtk::mesh::PointSet > instance(m, "PointSet"); - instance - .def(py::init<::smtk::mesh::ResourcePtr const &, ::smtk::mesh::HandleRange const &>()) - .def(py::init<::smtk::mesh::ConstResourcePtr const &, ::smtk::mesh::HandleRange const &>()) - .def(py::init<::smtk::mesh::ResourcePtr const &, ::std::vector > const &>()) - .def(py::init<::smtk::mesh::ResourcePtr const &, ::std::set, std::allocator > const &>()) - .def(py::init<::smtk::mesh::PointSet const &>()) - .def("__ne__", (bool (smtk::mesh::PointSet::*)(::smtk::mesh::PointSet const &) const) &smtk::mesh::PointSet::operator!=) - .def("deepcopy", (smtk::mesh::PointSet & (smtk::mesh::PointSet::*)(::smtk::mesh::PointSet const &)) &smtk::mesh::PointSet::operator=) - .def("__eq__", (bool (smtk::mesh::PointSet::*)(::smtk::mesh::PointSet const &) const) &smtk::mesh::PointSet::operator==) - .def("resource", &smtk::mesh::PointSet::resource) - .def("contains", &smtk::mesh::PointSet::contains, py::arg("pointId")) - .def("find", &smtk::mesh::PointSet::find, py::arg("pointId")) - .def("get", (bool (smtk::mesh::PointSet::*)(::std::vector > &) const) &smtk::mesh::PointSet::get, py::arg("xyz")) - .def("get", (bool (smtk::mesh::PointSet::*)(double *) const) &smtk::mesh::PointSet::get, py::arg("xyz")) - .def("get", (bool (smtk::mesh::PointSet::*)(float *) const) &smtk::mesh::PointSet::get, py::arg("xyz")) - .def("get", (bool (smtk::mesh::PointSet::*)(::std::vector > &) const) &smtk::mesh::PointSet::get, py::arg("xyz")) - .def("is_empty", &smtk::mesh::PointSet::is_empty) - .def("numberOfPoints", &smtk::mesh::PointSet::numberOfPoints) - .def("range", &smtk::mesh::PointSet::range) - .def("set", (bool (smtk::mesh::PointSet::*)(::std::vector > const &) const) &smtk::mesh::PointSet::set, py::arg("xyz")) - .def("set", (bool (smtk::mesh::PointSet::*)(double const * const) const) &smtk::mesh::PointSet::set, py::arg("xyz")) - .def("set", (bool (smtk::mesh::PointSet::*)(float const * const)) &smtk::mesh::PointSet::set, py::arg("xyz")) - .def("set", (bool (smtk::mesh::PointSet::*)(::std::vector > const &)) &smtk::mesh::PointSet::set, py::arg("xyz")) - .def("size", &smtk::mesh::PointSet::size) - ; - return instance; -} - -inline void pybind11_init_smtk_mesh_point_for_each(py::module &m) -{ - m.def("for_each", (void (*)(const smtk::mesh::PointSet&, smtk::mesh::PointForEach&)) &smtk::mesh::for_each, "", py::arg("a"), py::arg("filter")); -} - -inline void pybind11_init_smtk_mesh_point_set_difference(py::module &m) -{ - m.def("set_difference", (smtk::mesh::PointSet (*)(const smtk::mesh::PointSet&, const smtk::mesh::PointSet&)) &smtk::mesh::set_difference, "", py::arg("a"), py::arg("b")); -} - -inline void pybind11_init_smtk_mesh_point_set_intersect(py::module &m) -{ - m.def("set_intersect", (smtk::mesh::PointSet (*)(const smtk::mesh::PointSet&, const smtk::mesh::PointSet&)) &smtk::mesh::set_intersect, "", py::arg("a"), py::arg("b")); -} - -inline void pybind11_init_smtk_mesh_point_set_union(py::module &m) -{ - m.def("set_union", (smtk::mesh::PointSet (*)(const smtk::mesh::PointSet&, const smtk::mesh::PointSet&)) &smtk::mesh::set_union, "", py::arg("a"), py::arg("b")); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindQueryTypes.h b/smtk/mesh/pybind11/PybindQueryTypes.h deleted file mode 100644 index 615691be08593c798ce7347618b093a08bbdeb13..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindQueryTypes.h +++ /dev/null @@ -1,115 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_QueryTypes_h -#define pybind_smtk_mesh_QueryTypes_h - -#include - -#include "smtk/mesh/core/QueryTypes.h" - -namespace py = pybind11; - -inline void pybind11_init_smtk_mesh_ContainmentType(py::module &m) -{ - py::enum_(m, "ContainmentType") - .value("PartiallyContained", smtk::mesh::ContainmentType::PartiallyContained) - .value("FullyContained", smtk::mesh::ContainmentType::FullyContained) - .export_values(); -} - -inline PySharedPtrClass< smtk::mesh::Dirichlet > pybind11_init_smtk_mesh_Dirichlet(py::module &m, PySharedPtrClass< smtk::mesh::IntegerTag >& parent) -{ - PySharedPtrClass< smtk::mesh::Dirichlet > instance(m, "Dirichlet", parent); - instance - .def(py::init<::smtk::mesh::Dirichlet const &>()) - .def(py::init()) - .def("deepcopy", (smtk::mesh::Dirichlet & (smtk::mesh::Dirichlet::*)(::smtk::mesh::Dirichlet const &)) &smtk::mesh::Dirichlet::operator=) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::Domain > pybind11_init_smtk_mesh_Domain(py::module &m, PySharedPtrClass< smtk::mesh::IntegerTag >& parent) -{ - PySharedPtrClass< smtk::mesh::Domain > instance(m, "Domain", parent); - instance - .def(py::init<::smtk::mesh::Domain const &>()) - .def(py::init()) - .def("deepcopy", (smtk::mesh::Domain & (smtk::mesh::Domain::*)(::smtk::mesh::Domain const &)) &smtk::mesh::Domain::operator=) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::IntegerTag > pybind11_init_smtk_mesh_IntegerTag(py::module &m) -{ - PySharedPtrClass< smtk::mesh::IntegerTag > instance(m, "IntegerTag"); - instance - .def(py::init<::smtk::mesh::IntegerTag const &>()) - .def(py::init()) - .def("__ne__", (bool (smtk::mesh::IntegerTag::*)(::smtk::mesh::IntegerTag const &) const) &smtk::mesh::IntegerTag::operator!=) - .def("__lt__", (bool (smtk::mesh::IntegerTag::*)(::smtk::mesh::IntegerTag const &) const) &smtk::mesh::IntegerTag::operator<) - .def("deepcopy", (smtk::mesh::IntegerTag & (smtk::mesh::IntegerTag::*)(::smtk::mesh::IntegerTag const &)) &smtk::mesh::IntegerTag::operator=) - .def("__eq__", (bool (smtk::mesh::IntegerTag::*)(::smtk::mesh::IntegerTag const &) const) &smtk::mesh::IntegerTag::operator==) - .def("value", &smtk::mesh::IntegerTag::value) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::Model > pybind11_init_smtk_mesh_Model(py::module &m, PySharedPtrClass< smtk::mesh::UUIDTag >& parent) -{ - PySharedPtrClass< smtk::mesh::Model > instance(m, "Model", parent); - instance - .def(py::init<::smtk::mesh::Model const &>()) - .def(py::init<::smtk::common::UUID const &>()) - .def("deepcopy", (smtk::mesh::Model & (smtk::mesh::Model::*)(::smtk::mesh::Model const &)) &smtk::mesh::Model::operator=) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::Neumann > pybind11_init_smtk_mesh_Neumann(py::module &m, PySharedPtrClass< smtk::mesh::IntegerTag >& parent) -{ - PySharedPtrClass< smtk::mesh::Neumann > instance(m, "Neumann", parent); - instance - .def(py::init<::smtk::mesh::Neumann const &>()) - .def(py::init()) - .def("deepcopy", (smtk::mesh::Neumann & (smtk::mesh::Neumann::*)(::smtk::mesh::Neumann const &)) &smtk::mesh::Neumann::operator=) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::OpaqueTag<16> > pybind11_init_smtk_mesh_OpaqueTag_16_(py::module &m) -{ - PySharedPtrClass< smtk::mesh::OpaqueTag<16> > instance(m, "OpaqueTag_16_"); - instance - .def(py::init<::smtk::mesh::OpaqueTag<16> const &>()) - .def(py::init()) - .def("__ne__", (bool (smtk::mesh::OpaqueTag<16>::*)(::smtk::mesh::OpaqueTag<16> const &) const) &smtk::mesh::OpaqueTag<16>::operator!=) - .def("__lt__", (bool (smtk::mesh::OpaqueTag<16>::*)(::smtk::mesh::OpaqueTag<16> const &) const) &smtk::mesh::OpaqueTag<16>::operator<) - .def("deepcopy", (smtk::mesh::OpaqueTag<16> & (smtk::mesh::OpaqueTag<16>::*)(::smtk::mesh::OpaqueTag<16> const &)) &smtk::mesh::OpaqueTag<16>::operator=) - .def("__eq__", (bool (smtk::mesh::OpaqueTag<16>::*)(::smtk::mesh::OpaqueTag<16> const &) const) &smtk::mesh::OpaqueTag<16>::operator==) - .def_static("size", &smtk::mesh::OpaqueTag<16>::size) - .def("value", &smtk::mesh::OpaqueTag<16>::value) - ; - return instance; -} - -inline PySharedPtrClass< smtk::mesh::UUIDTag > pybind11_init_smtk_mesh_UUIDTag(py::module &m, PySharedPtrClass< smtk::mesh::OpaqueTag<16> >& parent) -{ - PySharedPtrClass< smtk::mesh::UUIDTag > instance(m, "UUIDTag", parent); - instance - .def(py::init<::smtk::mesh::UUIDTag const &>()) - .def(py::init<::smtk::common::UUID const &>()) - .def("deepcopy", (smtk::mesh::UUIDTag & (smtk::mesh::UUIDTag::*)(::smtk::mesh::UUIDTag const &)) &smtk::mesh::UUIDTag::operator=) - .def("uuid", &smtk::mesh::UUIDTag::uuid) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindRead.h b/smtk/mesh/pybind11/PybindRead.h deleted file mode 100644 index 55054d38d367f7cb8c15e94af513d76a25a7031e..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindRead.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_operators_Read_h -#define pybind_smtk_mesh_operators_Read_h - -#include - -#include "smtk/mesh/operators/Read.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::Read, smtk::operation::XMLOperation > pybind11_init_smtk_mesh_Read(py::module &m) -{ - PySharedPtrClass< smtk::mesh::Read, smtk::operation::XMLOperation > instance(m, "Read"); - instance - .def(py::init<>()) - .def("ableToOperate", &smtk::mesh::Read::ableToOperate) - .def_static("create", (std::shared_ptr (*)()) &smtk::mesh::Read::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::mesh::Read::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Read::*)() const) &smtk::mesh::Read::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Read::*)()) &smtk::mesh::Read::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindReclassify.h b/smtk/mesh/pybind11/PybindReclassify.h deleted file mode 100644 index f51379c4165ae67e0aedb7b563cfe266886cbe2f..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindReclassify.h +++ /dev/null @@ -1,40 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_Reclassify_h -#define pybind_smtk_mesh_Reclassify_h - -#include - -#include "smtk/mesh/utility/Reclassify.h" - -namespace py = pybind11; - -inline void pybind11_init_smtk_mesh_split(py::module &m) -{ - m.def("split", &smtk::mesh::utility::split, "", py::arg("arg0"), py::arg("orignalEdge"), py::arg("newEdge"), py::arg("promotedVertex")); -} - -inline void pybind11_init_smtk_mesh_merge(py::module &m) -{ - m.def("merge", &smtk::mesh::utility::merge, "", py::arg("arg0"), py::arg("toRemoveVert"), py::arg("toRemoveEdge"), py::arg("toAddTo")); -} - -inline void pybind11_init_smtk_mesh_make_disjoint(py::module &m) -{ - m.def("make_disjoint", &smtk::mesh::utility::make_disjoint, "", py::arg("arg0"), py::arg("a"), py::arg("b"), py::arg("modelAssoc")); -} - -inline void pybind11_init_smtk_mesh_fuse(py::module &m) -{ - m.def("fuse", &smtk::mesh::utility::fuse, "", py::arg("arg0"), py::arg("toRemove"), py::arg("toAddTo"), py::arg("assoc")); -} - -#endif diff --git a/smtk/mesh/pybind11/PybindRegistrar.h b/smtk/mesh/pybind11/PybindRegistrar.h deleted file mode 100644 index 9caf211d489105d07ab6e2598b982285015c1b97..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindRegistrar.h +++ /dev/null @@ -1,33 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_Registrar_h -#define pybind_smtk_mesh_Registrar_h - -#include - -#include "smtk/mesh/resource/Registrar.h" - -namespace py = pybind11; - -inline py::class_< smtk::mesh::Registrar > pybind11_init_smtk_mesh_Registrar(py::module &m) -{ - py::class_< smtk::mesh::Registrar > instance(m, "Registrar"); - instance - .def(py::init<>()) - .def_static("registerTo", (void (*)(std::shared_ptr<::smtk::resource::Manager> const &)) &smtk::mesh::Registrar::registerTo) - .def_static("unregisterFrom", (void (*)(std::shared_ptr<::smtk::resource::Manager> const &)) &smtk::mesh::Registrar::unregisterFrom) - .def_static("registerTo", (void (*)(std::shared_ptr<::smtk::operation::Manager> const &)) &smtk::mesh::Registrar::registerTo) - .def_static("unregisterFrom", (void (*)(std::shared_ptr<::smtk::operation::Manager> const &)) &smtk::mesh::Registrar::unregisterFrom) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindResource.h b/smtk/mesh/pybind11/PybindResource.h deleted file mode 100644 index 2ef4975549e6d97a29705759694099a83dbefbbc..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindResource.h +++ /dev/null @@ -1,101 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_Resource_h -#define pybind_smtk_mesh_Resource_h - -#include - -#include "smtk/mesh/core/Resource.h" -#include "smtk/resource/Resource.h" - -#include "smtk/common/UUID.h" - -#include "smtk/model/EntityIterator.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::Resource> pybind11_init_smtk_mesh_Resource(py::module &m) -{ - PySharedPtrClass< smtk::mesh::Resource, smtk::resource::Resource > instance(m, "Resource"); - instance - .def_property("modelResource", &smtk::mesh::Resource::modelResource, &smtk::mesh::Resource::setModelResource) - .def("associateToModel", &smtk::mesh::Resource::associateToModel, py::arg("uuid")) - .def("associatedModel", &smtk::mesh::Resource::associatedModel) - .def("cells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)() const) &smtk::mesh::Resource::cells) - .def("cells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::mesh::CellType) const) &smtk::mesh::Resource::cells, py::arg("cellType")) - .def("cells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::mesh::CellTypes) const) &smtk::mesh::Resource::cells, py::arg("cellTypes")) - .def("cells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::mesh::DimensionType) const) &smtk::mesh::Resource::cells, py::arg("dim")) - .def("classifiedTo", &smtk::mesh::Resource::classifiedTo) - .def("classifyTo", &smtk::mesh::Resource::classifyTo) - .def("clearReadWriteLocations", &smtk::mesh::Resource::clearReadWriteLocations) - .def_static("create", (std::shared_ptr (*)()) &smtk::mesh::Resource::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::mesh::Resource::create, py::arg("ref")) - .def("createMesh", &smtk::mesh::Resource::createMesh, py::arg("cells"), py::arg("uuid") = smtk::common::UUID::null()) - .def("dirichletMeshes", &smtk::mesh::Resource::dirichletMeshes, py::arg("d")) - .def("dirichlets", &smtk::mesh::Resource::dirichlets) - .def("domainMeshes", &smtk::mesh::Resource::domainMeshes, py::arg("m")) - .def("domains", &smtk::mesh::Resource::domains) - .def("entity", &smtk::mesh::Resource::entity) - .def("findAssociatedCells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::model::EntityRef const &) const) &smtk::mesh::Resource::findAssociatedCells, py::arg("eref")) - .def("findAssociatedCells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::model::EntityRef const &, ::smtk::mesh::CellType) const) &smtk::mesh::Resource::findAssociatedCells, py::arg("eref"), py::arg("cellType")) - .def("findAssociatedCells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::model::EntityRef const &, ::smtk::mesh::DimensionType) const) &smtk::mesh::Resource::findAssociatedCells, py::arg("eref"), py::arg("dim")) - .def("findAssociatedCells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::common::UUID const &) const) &smtk::mesh::Resource::findAssociatedCells, py::arg("id")) - .def("findAssociatedCells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::common::UUID const &, ::smtk::mesh::CellType) const) &smtk::mesh::Resource::findAssociatedCells, py::arg("id"), py::arg("cellType")) - .def("findAssociatedCells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::common::UUID const &, ::smtk::mesh::DimensionType) const) &smtk::mesh::Resource::findAssociatedCells, py::arg("id"), py::arg("dim")) - .def("findAssociatedCells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::model::EntityIterator &) const) &smtk::mesh::Resource::findAssociatedCells, py::arg("refIt")) - .def("findAssociatedCells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::model::EntityIterator &, ::smtk::mesh::CellType) const) &smtk::mesh::Resource::findAssociatedCells, py::arg("refIt"), py::arg("cellType")) - .def("findAssociatedCells", (smtk::mesh::CellSet (smtk::mesh::Resource::*)(::smtk::model::EntityIterator &, ::smtk::mesh::DimensionType) const) &smtk::mesh::Resource::findAssociatedCells, py::arg("refIt"), py::arg("dim")) - .def("findAssociatedMeshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::smtk::model::EntityRef const &) const) &smtk::mesh::Resource::findAssociatedMeshes, py::arg("eref")) - .def("findAssociatedMeshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::smtk::model::EntityRef const &, ::smtk::mesh::DimensionType) const) &smtk::mesh::Resource::findAssociatedMeshes, py::arg("eref"), py::arg("dim")) - .def("findAssociatedMeshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::smtk::common::UUID const &) const) &smtk::mesh::Resource::findAssociatedMeshes, py::arg("id")) - .def("findAssociatedMeshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::smtk::common::UUID const &, ::smtk::mesh::DimensionType) const) &smtk::mesh::Resource::findAssociatedMeshes, py::arg("id"), py::arg("dim")) - .def("findAssociatedMeshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::smtk::model::EntityIterator &) const) &smtk::mesh::Resource::findAssociatedMeshes, py::arg("refIt")) - .def("findAssociatedMeshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::smtk::model::EntityIterator &, ::smtk::mesh::DimensionType) const) &smtk::mesh::Resource::findAssociatedMeshes, py::arg("refIt"), py::arg("dim")) - .def("findAssociatedTypes", (smtk::mesh::TypeSet (smtk::mesh::Resource::*)(::smtk::model::EntityRef const &) const) &smtk::mesh::Resource::findAssociatedTypes, py::arg("eref")) - .def("findAssociatedTypes", (smtk::mesh::TypeSet (smtk::mesh::Resource::*)(::smtk::common::UUID const &) const) &smtk::mesh::Resource::findAssociatedTypes, py::arg("id")) - .def("findAssociatedTypes", (smtk::mesh::TypeSet (smtk::mesh::Resource::*)(::smtk::model::EntityIterator &) const) &smtk::mesh::Resource::findAssociatedTypes, py::arg("refIt")) - .def("hasAssociations", &smtk::mesh::Resource::hasAssociations) - .def("interface", &smtk::mesh::Resource::interface) - .def("interfaceName", &smtk::mesh::Resource::interfaceName) - .def("isAssociatedToModel", &smtk::mesh::Resource::isAssociatedToModel) - .def("isModified", &smtk::mesh::Resource::isModified) - .def("isValid", &smtk::mesh::Resource::isValid) - .def("meshNames", &smtk::mesh::Resource::meshNames) - .def("meshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)() const) &smtk::mesh::Resource::meshes) - .def("meshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::smtk::mesh::DimensionType) const) &smtk::mesh::Resource::meshes, py::arg("dim")) - .def("meshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::smtk::mesh::Domain const &) const) &smtk::mesh::Resource::meshes, py::arg("d")) - .def("meshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::smtk::mesh::Dirichlet const &) const) &smtk::mesh::Resource::meshes, py::arg("d")) - .def("meshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::smtk::mesh::Neumann const &) const) &smtk::mesh::Resource::meshes, py::arg("n")) - .def("meshes", (smtk::mesh::MeshSet (smtk::mesh::Resource::*)(::std::string const &) const) &smtk::mesh::Resource::meshes, py::arg("name")) - .def("neumannMeshes", &smtk::mesh::Resource::neumannMeshes, py::arg("n")) - .def("neumanns", &smtk::mesh::Resource::neumanns) - .def("numberOfMeshes", &smtk::mesh::Resource::numberOfMeshes) - .def("pointConnectivity", &smtk::mesh::Resource::pointConnectivity) - .def("points", &smtk::mesh::Resource::points) - .def("readLocation", (const smtk::common::FileLocation& (smtk::mesh::Resource::*)() const) &smtk::mesh::Resource::readLocation) - .def("removeMeshes", &smtk::mesh::Resource::removeMeshes, py::arg("meshesToDelete")) - .def("setAssociation", &smtk::mesh::Resource::setAssociation, py::arg("eref"), py::arg("meshset")) - .def("setDirichletOnMeshes", &smtk::mesh::Resource::setDirichletOnMeshes, py::arg("meshes"), py::arg("d")) - .def("setDomainOnMeshes", &smtk::mesh::Resource::setDomainOnMeshes, py::arg("meshes"), py::arg("m")) - .def("setNeumannOnMeshes", &smtk::mesh::Resource::setNeumannOnMeshes, py::arg("meshes"), py::arg("n")) - .def("types", &smtk::mesh::Resource::types) - .def("writeLocation", (void (smtk::mesh::Resource::*)(::smtk::common::FileLocation const &)) &smtk::mesh::Resource::writeLocation, py::arg("path")) - .def("writeLocation", (void (smtk::mesh::Resource::*)(::std::string const &)) &smtk::mesh::Resource::writeLocation, py::arg("path")) - .def("writeLocation", (smtk::common::FileLocation const & (smtk::mesh::Resource::*)() const) &smtk::mesh::Resource::writeLocation) - .def_static("classificationRole", &smtk::mesh::Resource::classificationRole) - .def_static("CastTo", [](const std::shared_ptr i) { - return std::dynamic_pointer_cast(i); - }) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindSelection.h b/smtk/mesh/pybind11/PybindSelection.h deleted file mode 100644 index 9e27d6c560f7486eafc2bdcc8e5cfa0a5f0b6cfe..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindSelection.h +++ /dev/null @@ -1,39 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_Selection_h -#define pybind_smtk_mesh_Selection_h - -#include - -#include "smtk/mesh/resource/Selection.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::Selection, smtk::mesh::Component > pybind11_init_smtk_mesh_Selection(py::module &m) -{ - PySharedPtrClass< smtk::mesh::Selection, smtk::mesh::Component > instance(m, "Selection"); - instance - .def(py::init<::smtk::mesh::Selection const &>()) - .def("deepcopy", (smtk::mesh::Selection & (smtk::mesh::Selection::*)(::smtk::mesh::Selection const &)) &smtk::mesh::Selection::operator=) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Selection::*)()) &smtk::mesh::Selection::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Selection::*)() const) &smtk::mesh::Selection::shared_from_this) - .def_static("create", (std::shared_ptr (*)(const smtk::mesh::CellSet&)) &smtk::mesh::Selection::create, py::arg("cellset")) - .def_static("CastTo", [](const std::shared_ptr i) { - return std::dynamic_pointer_cast(i); - }) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindStructuredGrid.h b/smtk/mesh/pybind11/PybindStructuredGrid.h deleted file mode 100644 index 731928cc49763a3e6dd34211ecb9b639cb21688a..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindStructuredGrid.h +++ /dev/null @@ -1,39 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_interpolation_StructuredGrid_h -#define pybind_smtk_mesh_interpolation_StructuredGrid_h - -#include - -#include "smtk/mesh/interpolation/StructuredGrid.h" - -namespace py = pybind11; - -inline py::class_< smtk::mesh::StructuredGrid > pybind11_init_smtk_mesh_StructuredGrid(py::module &m) -{ - py::class_< smtk::mesh::StructuredGrid > instance(m, "StructuredGrid"); - instance - .def(py::init<>()) - .def(py::init const &, ::std::function const &>()) - .def(py::init const &>()) - .def(py::init<::smtk::mesh::StructuredGrid const &>()) - .def("deepcopy", (smtk::mesh::StructuredGrid & (smtk::mesh::StructuredGrid::*)(::smtk::mesh::StructuredGrid const &)) &smtk::mesh::StructuredGrid::operator=) - .def("containsIndex", &smtk::mesh::StructuredGrid::containsIndex, py::arg("ix"), py::arg("iy")) - .def("data", &smtk::mesh::StructuredGrid::data) - .def("size", &smtk::mesh::StructuredGrid::size) - .def_readwrite("m_extent", &smtk::mesh::StructuredGrid::m_extent) - .def_readwrite("m_origin", &smtk::mesh::StructuredGrid::m_origin) - .def_readwrite("m_spacing", &smtk::mesh::StructuredGrid::m_spacing) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindStructuredGridGenerator.h b/smtk/mesh/pybind11/PybindStructuredGridGenerator.h deleted file mode 100644 index d32364b5e183198eb7c91988b9b6d534f1ad8996..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindStructuredGridGenerator.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_StructuredGridGenerator_h -#define pybind_smtk_mesh_StructuredGridGenerator_h - -#include - -#include "smtk/mesh/interpolation/StructuredGridGenerator.h" -#include "smtk/model/AuxiliaryGeometry.h" - -namespace py = pybind11; - -inline py::class_ pybind11_init_smtk_mesh_StructuredGridGenerator(py::module &m) -{ - py::class_ instance(m, "StructuredGridGenerator"); - instance - .def(py::init<>()) - .def(py::init()) - .def("__call__", (smtk::mesh::StructuredGrid (smtk::mesh::StructuredGridGenerator::*)(smtk::model::AuxiliaryGeometry const &)) &smtk::mesh::StructuredGridGenerator::operator()) - .def("__call__", (smtk::mesh::StructuredGrid (smtk::mesh::StructuredGridGenerator::*)(::std::string const &)) &smtk::mesh::StructuredGridGenerator::operator()) - .def("deepcopy", (smtk::mesh::StructuredGridGenerator & (smtk::mesh::StructuredGridGenerator::*)(smtk::mesh::StructuredGridGenerator const &)) &smtk::mesh::StructuredGridGenerator::operator=) - .def("valid", (bool (smtk::mesh::StructuredGridGenerator::*)(::std::string const&) const) &smtk::mesh::StructuredGridGenerator::valid, py::arg("file")) - .def("valid", (bool (smtk::mesh::StructuredGridGenerator::*)(smtk::model::AuxiliaryGeometry const&) const) &smtk::mesh::StructuredGridGenerator::valid, py::arg("auxGeom")) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindTypeSet.h b/smtk/mesh/pybind11/PybindTypeSet.h deleted file mode 100644 index 371b03f5c0cc981884a1da5cbf622720646eee2b..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindTypeSet.h +++ /dev/null @@ -1,39 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_TypeSet_h -#define pybind_smtk_mesh_TypeSet_h - -#include - -#include "smtk/mesh/core/TypeSet.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::TypeSet > pybind11_init_smtk_mesh_TypeSet(py::module &m) -{ - PySharedPtrClass< smtk::mesh::TypeSet > instance(m, "TypeSet"); - instance - .def(py::init<::smtk::mesh::TypeSet const &>()) - .def(py::init<>()) - .def(py::init<::smtk::mesh::CellTypes, bool, bool>()) - .def("__ne__", (bool (smtk::mesh::TypeSet::*)(::smtk::mesh::TypeSet const &) const) &smtk::mesh::TypeSet::operator!=) - .def("deepcopy", (smtk::mesh::TypeSet & (smtk::mesh::TypeSet::*)(::smtk::mesh::TypeSet const &)) &smtk::mesh::TypeSet::operator=) - .def("__eq__", (bool (smtk::mesh::TypeSet::*)(::smtk::mesh::TypeSet const &) const) &smtk::mesh::TypeSet::operator==) - .def("cellTypes", &smtk::mesh::TypeSet::cellTypes) - .def("hasCell", &smtk::mesh::TypeSet::hasCell, py::arg("ct")) - .def("hasCells", &smtk::mesh::TypeSet::hasCells) - .def("hasDimension", &smtk::mesh::TypeSet::hasDimension, py::arg("dt")) - .def("hasMeshes", &smtk::mesh::TypeSet::hasMeshes) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/PybindWrite.h b/smtk/mesh/pybind11/PybindWrite.h deleted file mode 100644 index cfde610355e3b0e49dc334772c0783d5df00b102..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/PybindWrite.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_mesh_operators_Write_h -#define pybind_smtk_mesh_operators_Write_h - -#include - -#include "smtk/mesh/operators/Write.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::mesh::Write, smtk::operation::XMLOperation > pybind11_init_smtk_mesh_Write(py::module &m) -{ - PySharedPtrClass< smtk::mesh::Write, smtk::operation::XMLOperation > instance(m, "Write"); - instance - .def(py::init<>()) - .def("ableToOperate", &smtk::mesh::Write::ableToOperate) - .def_static("create", (std::shared_ptr (*)()) &smtk::mesh::Write::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::mesh::Write::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Write::*)() const) &smtk::mesh::Write::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::mesh::Write::*)()) &smtk::mesh::Write::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/mesh/pybind11/__init__.py b/smtk/mesh/pybind11/__init__.py deleted file mode 100644 index 92f193b235457ad1ff3509567284a181bb3acf8e..0000000000000000000000000000000000000000 --- a/smtk/mesh/pybind11/__init__.py +++ /dev/null @@ -1,30 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - -from ._smtkPybindMesh import * - - -def _get(self, handleRange=None): - if handleRange is None: - if self.type() == FieldType.Double: - return self._get_double() - if self.type() == FieldType.Integer: - return self._get_int() - else: - if self.type() == FieldType.Double: - return self._get_double(handleRange) - if self.type() == FieldType.Integer: - return self._get_int(handleRange) - - -CellField.get = _get -PointField.get = _get diff --git a/smtk/mesh/resource/Registrar.cxx b/smtk/mesh/resource/Registrar.cxx deleted file mode 100644 index fb3da56bc40cc4f538d98b266d57d28965a8e67d..0000000000000000000000000000000000000000 --- a/smtk/mesh/resource/Registrar.cxx +++ /dev/null @@ -1,127 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/mesh/resource/Registrar.h" - -#include "smtk/io/ReadMesh.h" -#include "smtk/io/WriteMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/operators/DeleteMesh.h" -#include "smtk/mesh/operators/ElevateMesh.h" -#include "smtk/mesh/operators/Export.h" -#include "smtk/mesh/operators/ExtractAdjacency.h" -#include "smtk/mesh/operators/ExtractByDihedralAngle.h" -#include "smtk/mesh/operators/ExtractSkin.h" -#include "smtk/mesh/operators/GenerateHotStartData.h" -#include "smtk/mesh/operators/Import.h" -#include "smtk/mesh/operators/InterpolateOntoMesh.h" -#include "smtk/mesh/operators/MergeCoincidentPoints.h" -#include "smtk/mesh/operators/PrintMeshInformation.h" -#include "smtk/mesh/operators/Read.h" -#include "smtk/mesh/operators/ReadResource.h" -#include "smtk/mesh/operators/SelectCells.h" -#include "smtk/mesh/operators/SetMeshName.h" -#include "smtk/mesh/operators/Subtract.h" -#include "smtk/mesh/operators/Transform.h" -#include "smtk/mesh/operators/UndoElevateMesh.h" -#include "smtk/mesh/operators/Write.h" -#include "smtk/mesh/operators/WriteResource.h" - -#include "smtk/operation/groups/DeleterGroup.h" -#include "smtk/operation/groups/ExporterGroup.h" -#include "smtk/operation/groups/ImporterGroup.h" -#include "smtk/operation/groups/InternalGroup.h" -#include "smtk/operation/groups/NamingGroup.h" -#include "smtk/operation/groups/ReaderGroup.h" -#include "smtk/operation/groups/WriterGroup.h" - -namespace smtk -{ -namespace mesh -{ -namespace -{ -typedef std::tuple< - DeleteMesh, - ElevateMesh, - Export, - ExtractAdjacency, - ExtractByDihedralAngle, - ExtractSkin, - GenerateHotStartData, - Import, - InterpolateOntoMesh, - MergeCoincidentPoints, - PrintMeshInformation, - Read, - ReadResource, - SelectCells, - SetMeshName, - Subtract, - Transform, - UndoElevateMesh, - Write, - WriteResource> - OperationList; -} - -void Registrar::registerTo(const smtk::operation::Manager::Ptr& operationManager) -{ - operationManager->registerOperations(); - - smtk::operation::ImporterGroup(operationManager) - .registerOperation(); - - smtk::operation::ExporterGroup(operationManager) - .registerOperation(); - - smtk::operation::ReaderGroup(operationManager) - .registerOperation(); - - smtk::operation::WriterGroup(operationManager) - .registerOperation(); - - smtk::operation::DeleterGroup(operationManager).registerOperation(); - - smtk::operation::NamingGroup(operationManager) - .registerOperation(); - - smtk::operation::InternalGroup(operationManager).registerOperation(); -} - -void Registrar::unregisterFrom(const smtk::operation::Manager::Ptr& operationManager) -{ - smtk::operation::ImporterGroup(operationManager).unregisterOperation(); - - smtk::operation::ExporterGroup(operationManager).unregisterOperation(); - - smtk::operation::ReaderGroup(operationManager).unregisterOperation(); - - smtk::operation::WriterGroup(operationManager).unregisterOperation(); - - smtk::operation::DeleterGroup(operationManager).unregisterOperation(); - - operationManager->unregisterOperations(); -} - -void Registrar::registerTo(const smtk::resource::Manager::Ptr& resourceManager) -{ - resourceManager->registerResource(read, write); -} - -void Registrar::unregisterFrom(const smtk::resource::Manager::Ptr& resourceManager) -{ - resourceManager->unregisterResource(); -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/resource/Registrar.h b/smtk/mesh/resource/Registrar.h deleted file mode 100644 index 5b0652d440f8954a21b9cceb9a6c6b02384e921b..0000000000000000000000000000000000000000 --- a/smtk/mesh/resource/Registrar.h +++ /dev/null @@ -1,34 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_mesh_Registrar_h -#define smtk_mesh_Registrar_h - -#include "smtk/CoreExports.h" - -#include "smtk/operation/Manager.h" -#include "smtk/resource/Manager.h" - -namespace smtk -{ -namespace mesh -{ -class SMTKCORE_EXPORT Registrar -{ -public: - static void registerTo(const smtk::operation::Manager::Ptr&); - static void unregisterFrom(const smtk::operation::Manager::Ptr&); - - static void registerTo(const smtk::resource::Manager::Ptr&); - static void unregisterFrom(const smtk::resource::Manager::Ptr&); -}; -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/resource/Selection.cxx b/smtk/mesh/resource/Selection.cxx deleted file mode 100644 index 905e011b33bf345eb99a25ee0b097065d25d9eb1..0000000000000000000000000000000000000000 --- a/smtk/mesh/resource/Selection.cxx +++ /dev/null @@ -1,142 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/resource/Selection.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/Definition.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" - -#include "smtk/common/UUIDGenerator.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/DeleteMesh.h" - -#include "smtk/operation/Manager.h" - -namespace -{ -class SelectionContainer -{ -public: - SelectionContainer( - const std::shared_ptr& component, - const std::weak_ptr& weakManager) - : m_selection(std::static_pointer_cast(component->shared_from_this())) - , m_weakManager(weakManager) - { - } - - SelectionContainer(const std::shared_ptr& component) - : SelectionContainer(component, std::weak_ptr()) - { - } - - ~SelectionContainer() - { - { - smtk::mesh::DeleteMesh::Ptr deleteMesh; - if (auto operationManager = m_weakManager.lock()) - { - deleteMesh = operationManager->create(); - deleteMesh->parameters()->associate(m_selection); - deleteMesh->suppressOutput(true); - operationManager->launchers()(deleteMesh); - } - else - { - deleteMesh = smtk::mesh::DeleteMesh::create(); - deleteMesh->parameters()->associate(m_selection); - deleteMesh->suppressOutput(true); - deleteMesh->operate(); - } - } - } - - [[nodiscard]] const std::shared_ptr& selection() const - { - return m_selection; - } - -private: - std::shared_ptr m_selection; - std::weak_ptr m_weakManager; -}; -} // namespace - -namespace smtk -{ -namespace mesh -{ - -Selection::Selection(const smtk::mesh::CellSet& cellset) - : Component(cellset.resource(), smtk::common::UUIDGenerator::instance().random()) - , m_cells(cellset.range()) -{ -} - -Selection::~Selection() = default; - -std::shared_ptr Selection::create(const smtk::mesh::CellSet& cellset) -{ - return create(cellset, std::weak_ptr()); -} - -std::shared_ptr Selection::create( - const smtk::mesh::CellSet& cellset, - const std::weak_ptr& weakManager) -{ - std::shared_ptr tmp(new Selection(cellset)); - std::shared_ptr selectionContainer(new SelectionContainer(tmp, weakManager)); - - std::shared_ptr shared( - selectionContainer, selectionContainer->selection().get()); - - return std::static_pointer_cast(shared); -} - -std::string Selection::name() const -{ - return "selection"; -} - -const smtk::mesh::MeshSet Selection::mesh() const -{ - smtk::mesh::MeshSet meshSet = Component::mesh(); - if (!meshSet.isValid()) - { - if ( - smtk::mesh::Resource::Ptr resource = - std::dynamic_pointer_cast(this->resource())) - { - return resource->createMesh(smtk::mesh::CellSet(resource, m_cells), this->id()); - } - } - return meshSet; -} - -smtk::mesh::MeshSet Selection::mesh() -{ - smtk::mesh::MeshSet meshSet = Component::mesh(); - if (!meshSet.isValid()) - { - if ( - smtk::mesh::Resource::Ptr resource = - std::dynamic_pointer_cast(this->resource())) - { - return resource->createMesh(smtk::mesh::CellSet(resource, m_cells), this->id()); - } - } - return meshSet; -} -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/resource/Selection.h b/smtk/mesh/resource/Selection.h deleted file mode 100644 index ded7bcf51591e4da7035e86180f9eced2c0f10d3..0000000000000000000000000000000000000000 --- a/smtk/mesh/resource/Selection.h +++ /dev/null @@ -1,59 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_Selection_h -#define smtk_mesh_Selection_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" -#include "smtk/TupleTraits.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/Component.h" - -namespace smtk -{ -namespace mesh -{ - -/// A lightweight object for representing meshset information as a transient -/// resource component. -class SMTKCORE_EXPORT Selection : public smtk::mesh::Component -{ -public: - smtkTypeMacro(Selection); - smtkSharedFromThisMacro(smtk::resource::Component); - - Selection(const smtk::mesh::CellSet&); - ~Selection() override; - - static std::shared_ptr create(const smtk::mesh::CellSet&); - static std::shared_ptr create( - const smtk::mesh::CellSet&, - const std::weak_ptr&); - - /// Access the meshset represented by this component. - const smtk::mesh::MeshSet mesh() const override; - smtk::mesh::MeshSet mesh() override; - - std::string name() const override; - -private: - // Modify the access level of links to prevent their explicit use. - Links& links() override { return smtk::resource::Component::links(); } - const Links& links() const override { return smtk::resource::Component::links(); } - - smtk::mesh::HandleRange m_cells; -}; - -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/testing/CMakeLists.txt b/smtk/mesh/testing/CMakeLists.txt deleted file mode 100644 index 18e1bdc4052807fce5d5e75f29732b823757e263..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ - -add_subdirectory(cxx) - -if(SMTK_ENABLE_PYTHON_WRAPPING) - add_subdirectory(python) -endif() diff --git a/smtk/mesh/testing/cxx/CMakeLists.txt b/smtk/mesh/testing/cxx/CMakeLists.txt deleted file mode 100644 index ec39dd36e020bbd64b34a6606e5302aef1efa503..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/CMakeLists.txt +++ /dev/null @@ -1,153 +0,0 @@ -#============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -#============================================================================= - -set(unit_tests - UnitTestAllocator.cxx - UnitTestCellTypes.cxx - UnitTestResource.cxx - UnitTestBufferedCellAllocator.cxx - UnitTestIncrementalAllocator.cxx - UnitTestIntervals.cxx - UnitTestModelToMesh3D.cxx - UnitTestQueryTypes.cxx - UnitTestTypeSet.cxx -) - -set(unit_tests_which_require_data - TestTransform.cxx - UnitTestAddFileToResource.cxx - UnitTestCellSet.cxx - UnitTestCreateMesh.cxx - UnitTestCellField.cxx - UnitTestExportMesh2DM.cxx - UnitTestExportMesh3DM.cxx - UnitTestExtractCanonicalIndices.cxx - UnitTestExtractMeshConstants.cxx - UnitTestExtractTessellation.cxx - UnitTestExtractTessellationOfModel.cxx - - UnitTestLoadMesh.cxx - UnitTestMergeContactPoints.cxx - UnitTestMeshMetrics.cxx - UnitTestMeshSet.cxx - UnitTestModelToMesh2D.cxx - UnitTestPointConnectivity.cxx - UnitTestPointField.cxx - UnitTestPointLocator.cxx - UnitTestPointSet.cxx - UnitTestReadWriteMeshResource.cxx - UnitTestReclassifyEdges.cxx - UnitTestRemoveMeshes.cxx - UnitTestTypeSetFromData.cxx - UnitTestWriteMesh.cxx -) - -set(extra_libs) -if(SMTK_ENABLE_VTK_SUPPORT) - list(APPEND unit_tests_which_require_data - UnitTestExportMeshVTK.cxx - ) - list(APPEND extra_libs - smtkIOVTK - ) -endif() - -if(SMTK_ENABLE_MESH_SESSION) - list(APPEND unit_tests_which_require_data - TestSamplePointsOnSurface.cxx - TestSnapPointsToSurface.cxx - ) - if (SMTK_ENABLE_VTK_SUPPORT) - list(APPEND unit_tests_which_require_data - TestElevateMesh.cxx - ) - if (SMTK_ENABLE_GDAL_SUPPORT) - list(APPEND unit_tests_which_require_data - TestElevateMeshOnStructuredGrid.cxx - ) - endif() - if (SMTK_ENABLE_UNSTABLE_TESTS) - list(APPEND unit_tests_which_require_data - TestExtractByDihedralAngle.cxx - TestSubtract.cxx - ) - endif() - list(APPEND extra_libs - smtkIOVTK - vtkSMTKSourceExt - VTK::IOXML - ) - endif() - list(APPEND extra_libs - smtkMeshSession - ) -endif() - -if (extra_libs) - list(REMOVE_DUPLICATES extra_libs) -endif() - -smtk_unit_tests( - LABEL "Mesh" - SOURCES ${unit_tests} - SOURCES_REQUIRE_DATA ${unit_tests_which_require_data} - LIBRARIES - smtkCore - smtkCoreModelTesting - ${extra_libs} - ${Boost_LIBRARIES} -) - -add_executable(TestGenerateHotStartData TestGenerateHotStartData.cxx) -target_compile_definitions(TestGenerateHotStartData PRIVATE "SMTK_SCRATCH_DIR=\"${CMAKE_BINARY_DIR}/Testing/Temporary\"") -target_link_libraries(TestGenerateHotStartData smtkCore ${Boost_LIBRARIES}) - -add_executable(TestInterpolateOntoMesh TestInterpolateOntoMesh.cxx) -target_compile_definitions(TestInterpolateOntoMesh PRIVATE "SMTK_SCRATCH_DIR=\"${CMAKE_BINARY_DIR}/Testing/Temporary\"") -target_link_libraries(TestInterpolateOntoMesh smtkCore ${Boost_LIBRARIES}) - -add_executable(TestWarpMesh TestWarpMesh.cxx) -target_compile_definitions(TestWarpMesh PRIVATE "SMTK_SCRATCH_DIR=\"${CMAKE_BINARY_DIR}/Testing/Temporary\"") -target_link_libraries(TestWarpMesh smtkCore ${Boost_LIBRARIES}) - -if (SMTK_DATA_DIR) - add_test(NAME TestGenerateHotStartData - COMMAND $ - "${SMTK_DATA_DIR}/model/2d/smtk/test2D.json") - set_tests_properties(TestGenerateHotStartData PROPERTIES LABELS "Mesh") - add_test(NAME TestGenerateHotStartDataCSV - COMMAND $ - "${SMTK_DATA_DIR}/model/2d/smtk/test2D.json" 1) - set_tests_properties(TestGenerateHotStartDataCSV PROPERTIES LABELS "Mesh") - add_test(NAME TestInterpolateOntoMeshCells - COMMAND $ - "${SMTK_DATA_DIR}/model/2d/smtk/test2D.json") - set_tests_properties(TestInterpolateOntoMeshCells PROPERTIES LABELS "Mesh") - add_test(NAME TestInterpolateOntoMeshPoints - COMMAND $ - "${SMTK_DATA_DIR}/model/2d/smtk/test2D.json" 0) - set_tests_properties(TestInterpolateOntoMeshPoints PROPERTIES LABELS "Mesh") - add_test(NAME TestInterpolateOntoMeshCellsCSV - COMMAND $ - "${SMTK_DATA_DIR}/model/2d/smtk/test2D.json" 0 1) - set_tests_properties(TestInterpolateOntoMeshCellsCSV PROPERTIES LABELS "Mesh") - add_test(NAME TestInterpolateOntoMeshPointsCSV - COMMAND $ - "${SMTK_DATA_DIR}/model/2d/smtk/test2D.json" 1 1) - set_tests_properties(TestInterpolateOntoMeshPointsCSV PROPERTIES LABELS "Mesh") - add_test(NAME TestWarpMesh - COMMAND $ - "${SMTK_DATA_DIR}/model/2d/smtk/test2D.json" 0) - add_test(NAME TestWarpMeshCSV - COMMAND $ - "${SMTK_DATA_DIR}/model/2d/smtk/test2D.json" 1) -endif() diff --git a/smtk/mesh/testing/cxx/TestElevateMesh.cxx b/smtk/mesh/testing/cxx/TestElevateMesh.cxx deleted file mode 100644 index de508ac5540ed6c74d98cd51c0010b7e56fa5648..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/TestElevateMesh.cxx +++ /dev/null @@ -1,297 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ModelEntityItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/extension/vtk/source/PointCloudFromVTKAuxiliaryGeometry.h" -#include "smtk/extension/vtk/source/StructuredGridFromVTKAuxiliaryGeometry.h" - -#include "smtk/io/ExportMesh.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/ElevateMesh.h" -#include "smtk/mesh/operators/UndoElevateMesh.h" -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" -#include "smtk/model/Tessellation.h" -#include "smtk/model/operators/AddAuxiliaryGeometry.h" - -#include "vtkActor.h" -#include "vtkCamera.h" -#include "vtkCommand.h" -#include "vtkCompositePolyDataMapper.h" -#include "vtkDataSetAttributes.h" -#include "vtkInteractorStyleSwitch.h" -#include "vtkNew.h" -#include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkRenderWindow.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderer.h" -#include "vtkSmartPointer.h" -#include "vtkStringArray.h" -#include "vtkXMLMultiBlockDataWriter.h" - -#include - -namespace -{ -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -bool pcRegistered = smtk::extension::vtk::mesh::PointCloudFromVTKAuxiliaryGeometry::registerClass(); -bool sgRegistered = - smtk::extension::vtk::mesh::StructuredGridFromVTKAuxiliaryGeometry::registerClass(); - -class ValidatePoints : public smtk::mesh::PointForEach -{ -public: - ValidatePoints(std::size_t nBins, double min, double max) - : m_min(min) - , m_max(max) - { - m_hist.resize(nBins, 0); - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& /*coordinatesModified*/) override - { - int counter = 0; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i, counter += 3) - { - std::size_t bin = xyz[counter + 2] < m_min ? 0 - : xyz[counter + 2] > m_max - ? m_hist.size() - 1 - : static_cast((xyz[counter + 2] - m_min) / (m_max - m_min) * m_hist.size()); - ++m_hist[bin]; - } - } - - [[nodiscard]] const std::vector& histogram() const { return m_hist; } - -private: - std::vector m_hist; - double m_min; - double m_max; -}; -} // namespace - -using namespace smtk::model; - -int TestElevateMesh(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - smtk::operation::Operation::Ptr importOp = smtk::session::mesh::Import::create(); - - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - { - std::string file_path(data_root); - file_path += "/mesh/2d/Simple.2dm"; - importOp->parameters()->findFile("filename")->setValue(file_path); - std::cout << "Importing " << file_path << "\n"; - } - - smtk::operation::Operation::Result importOpResult = importOp->operate(); - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - - // Retrieve the resulting resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - // Access the generated resource - smtk::session::mesh::Resource::Ptr resource = - std::dynamic_pointer_cast(resourceItem->value()); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - smtk::model::Entity::Ptr model = - std::dynamic_pointer_cast(componentItem->value()); - - smtk::model::Model model2dm = model->referenceAs(); - - auto meshedFaceItem = importOpResult->findComponent("mesh_created"); - - if (!meshedFaceItem || !meshedFaceItem->isValid()) - { - std::cerr << "No associated mesh!\n"; - return 1; - } - - smtk::model::Face meshedFace = meshedFaceItem->valueAs(); - - auto resources = std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - smtk::mesh::ResourcePtr meshResource = resource->resource(); - - smtk::mesh::MeshSet mesh = meshResource->meshes(); - - if (!model2dm.isValid()) - { - std::cerr << "Reading model file failed!\n"; - return 1; - } - - // add auxiliary geometry - auto auxGeoOp = smtk::model::AddAuxiliaryGeometry::create(); - - { - std::string file_path(data_root); - file_path += "/mesh/2d/SimpleBathy.vtu"; - auxGeoOp->parameters()->findFile("url")->setValue(file_path); - } - - auxGeoOp->parameters()->associateEntity(model2dm); - smtk::operation::Operation::Result auxGeoOpResult = auxGeoOp->operate(); - if ( - auxGeoOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Add auxiliary geometry failed!\n"; - return 1; - } - - // Retrieve the resulting auxiliary geometry item - smtk::attribute::ComponentItemPtr auxGeoItem = - std::dynamic_pointer_cast( - auxGeoOpResult->findComponent("created")); - - // Access the generated auxiliary geometry - smtk::model::Entity::Ptr auxGeo = - std::dynamic_pointer_cast(auxGeoItem->value()); - - smtk::model::AuxiliaryGeometry auxGeo2dm = auxGeo->referenceAs(); - if (!auxGeo2dm.isValid()) - { - std::cerr << "Auxiliary geometry is not valid!\n"; - return 1; - } - - { - // create the elevate mesh operator - std::cout << "Creating elevate mesh operator\n"; - auto elevateMesh = smtk::mesh::ElevateMesh::create(); - if (!elevateMesh) - { - std::cerr << "No Elevate Mesh operator!\n"; - return 1; - } - - // set input values for the elevate mesh operator - elevateMesh->parameters()->associate(smtk::mesh::Component::create(mesh)); - elevateMesh->parameters()->findString("input data")->setToDefault(); - elevateMesh->parameters()->findComponent("auxiliary geometry")->setValue(auxGeo2dm.component()); - elevateMesh->parameters()->findString("interpolation scheme")->setToDefault(); - elevateMesh->parameters()->findDouble("radius")->setValue(7.); - - if (!elevateMesh->ableToOperate()) - { - std::cerr << "Elevate mesh operator could not operate\n"; - return 1; - } - - smtk::operation::Operation::Result bathyResult = elevateMesh->operate(); - if ( - bathyResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Elevate mesh operator failed\n"; - std::cerr << elevateMesh->log().convertToString() << "\n"; - return 1; - } - } - - // histogram elevated coordinate values - { - ValidatePoints validatePoints(3, .2, .35); - smtk::mesh::for_each(mesh.points(), validatePoints); - std::size_t valid[3] = { 1, 2, 2 }; - - for (std::size_t bin = 0; bin < 3; bin++) - { - test(validatePoints.histogram()[bin] == valid[bin]); - } - } - - { - // create the undo elevate mesh operator - std::cout << "Creating undo elevate mesh operator\n"; - auto undoElevateMesh = smtk::mesh::UndoElevateMesh::create(); - if (!undoElevateMesh) - { - std::cerr << "No Undo Elevate Mesh operator!\n"; - return 1; - } - - undoElevateMesh->parameters()->associate(smtk::mesh::Component::create(mesh)); - - smtk::operation::Operation::Result result = undoElevateMesh->operate(); - if ( - result->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Undo elevate mesh operator failed\n"; - return 1; - } - } - - // histogram unelevated coordinate values - { - ValidatePoints validatePoints(3, .2, .35); - smtk::mesh::for_each(mesh.points(), validatePoints); - std::size_t valid[3] = { 5, 0, 0 }; - - for (std::size_t bin = 0; bin < 3; bin++) - { - test(validatePoints.histogram()[bin] == valid[bin]); - } - } - - return 0; -} diff --git a/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx b/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx deleted file mode 100644 index 5c55dd2f8efbc6ed29561b09ac25591961f06667..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx +++ /dev/null @@ -1,302 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ModelEntityItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/extension/vtk/source/PointCloudFromVTKAuxiliaryGeometry.h" -#include "smtk/extension/vtk/source/StructuredGridFromVTKAuxiliaryGeometry.h" - -#include "smtk/io/ExportMesh.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/ElevateMesh.h" -#include "smtk/mesh/operators/UndoElevateMesh.h" -#include "smtk/mesh/testing/cxx/helpers.h" -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" -#include "smtk/model/Tessellation.h" -#include "smtk/model/operators/AddAuxiliaryGeometry.h" - -#include "smtk/operation/Manager.h" - -#include "vtkActor.h" -#include "vtkCamera.h" -#include "vtkCommand.h" -#include "vtkCompositePolyDataMapper.h" -#include "vtkDataSetAttributes.h" -#include "vtkInteractorStyleSwitch.h" -#include "vtkNew.h" -#include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkRenderWindow.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderer.h" -#include "vtkSmartPointer.h" -#include "vtkStringArray.h" -#include "vtkXMLMultiBlockDataWriter.h" - -#include - -namespace -{ -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -bool pcRegistered = smtk::extension::vtk::mesh::PointCloudFromVTKAuxiliaryGeometry::registerClass(); -bool sgRegistered = - smtk::extension::vtk::mesh::StructuredGridFromVTKAuxiliaryGeometry::registerClass(); - -class ValidatePoints : public smtk::mesh::PointForEach -{ -public: - ValidatePoints(std::size_t nBins, int coord, double min, double max) - : m_coord(coord) - , m_min(min) - , m_max(max) - { - m_hist.resize(nBins, 0); - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& /*coordinatesModified*/) override - { - int counter = 0; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i, counter += 3) - { - std::size_t bin = xyz[counter + m_coord] < m_min ? 0 - : xyz[counter + m_coord] >= m_max - ? m_hist.size() - 1 - : static_cast( - (xyz[counter + m_coord] - m_min) / (m_max - m_min) * m_hist.size()); - ++m_hist[bin]; - } - } - - const std::vector& histogram() const { return m_hist; } - -private: - std::vector m_hist; - int m_coord; - double m_min; - double m_max; -}; -} // namespace - -using namespace smtk::model; - -int TestElevateMeshOnStructuredGrid(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - auto importOp = smtk::session::mesh::Import::create(); - - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - std::string importFilePath(data_root); - importFilePath += "/mesh/2d/testSurfaceEdgesSmall.2dm"; - - importOp->parameters()->findFile("filename")->setValue(importFilePath); - importOp->parameters()->findVoid("construct hierarchy")->setIsEnabled(false); - - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - - // Retrieve the resulting resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - // Access the generated resource - smtk::session::mesh::Resource::Ptr resource = - std::dynamic_pointer_cast(resourceItem->value()); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - smtk::model::Entity::Ptr modelEntity = - std::dynamic_pointer_cast(componentItem->value()); - - smtk::model::Model model = modelEntity->referenceAs(); - - if (!model.isValid()) - { - std::cerr << "Import operator returned an invalid model\n"; - return 1; - } - - smtk::mesh::ResourcePtr meshResource = resource->resource(); - smtk::mesh::MeshSet mesh = meshResource->meshes(); - - // add auxiliary geometry - auto auxGeoOp = smtk::model::AddAuxiliaryGeometry::create(); - - { - std::string file_path(data_root); - file_path += "/image/tiff/testSurfaceEdgesSmall.tiff"; - auxGeoOp->parameters()->findFile("url")->setValue(file_path); - } - auxGeoOp->parameters()->associateEntity(model); - - smtk::operation::Operation::Result auxGeoOpResult = auxGeoOp->operate(); - - if ( - auxGeoOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Add auxiliary geometry failed!\n"; - return 1; - } - - // Retrieve the resulting auxiliary geometry item - smtk::attribute::ComponentItemPtr auxGeoItem = - std::dynamic_pointer_cast( - auxGeoOpResult->findComponent("created")); - - // Access the generated auxiliary geometry - smtk::model::Entity::Ptr auxGeoEntity = - std::dynamic_pointer_cast(auxGeoItem->value()); - - smtk::model::AuxiliaryGeometry auxGeo = - auxGeoEntity->referenceAs(); - - if (!auxGeo.isValid()) - { - std::cerr << "Auxiliary geometry is not valid!\n"; - return 1; - } - - { - // create the elevate mesh operator - std::cout << "Creating elevate mesh operator\n"; - auto elevateMesh = smtk::mesh::ElevateMesh::create(); - if (!elevateMesh) - { - std::cerr << "No Elevate Mesh operator!\n"; - return 1; - } - - // set input values for the elevate mesh operator - elevateMesh->parameters()->associate(smtk::mesh::Component::create(mesh)); - elevateMesh->parameters()->findString("input data")->setToDefault(); - elevateMesh->parameters()->findComponent("auxiliary geometry")->setValue(auxGeo.component()); - elevateMesh->parameters()->findString("interpolation scheme")->setToDefault(); - elevateMesh->parameters()->findDouble("radius")->setValue(7.); - elevateMesh->parameters()->findString("external point values")->setValue("set to value"); - elevateMesh->parameters()->findDouble("external point value")->setValue(-1.); - - smtk::operation::Operation::Result bathyResult = elevateMesh->operate(); - if ( - bathyResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Elevate mesh operator failed\n"; - return 1; - } - } - - ValidatePoints validatePointsX(10, 0, 0., 250.); - smtk::mesh::for_each(mesh.points(), validatePointsX); - - // histogram elevated coordinate values - { - ValidatePoints validatePointsZ(10, 2, 190., 250.); - smtk::mesh::for_each(mesh.points(), validatePointsZ); - std::size_t valid[10] = { 127, 13, 8, 17, 27, 18, 24, 12, 24, 524 }; - - for (std::size_t bin = 0; bin < 10; bin++) - { - test(validatePointsZ.histogram()[bin] == valid[bin]); - } - } - - { - // create the undo elevate mesh operator - std::cout << "Creating undo elevate mesh operator\n"; - auto undoElevateMesh = smtk::mesh::UndoElevateMesh::create(); - if (!undoElevateMesh) - { - std::cerr << "No Undo Elevate Mesh operator!\n"; - return 1; - } - - undoElevateMesh->parameters()->associate(smtk::mesh::Component::create(mesh)); - - smtk::operation::Operation::Result result = undoElevateMesh->operate(); - if ( - result->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Undo elevate mesh operator failed\n"; - return 1; - } - } - - ValidatePoints validatePointsXFlat(10, 0, 0., 250.); - smtk::mesh::for_each(mesh.points(), validatePointsXFlat); - for (std::size_t bin = 0; bin < 10; bin++) - { - test(validatePointsX.histogram()[bin] == validatePointsXFlat.histogram()[bin]); - } - - // histogram unelevated coordinate values - { - ValidatePoints validatePointsZ(10, 2, 190., 250.); - smtk::mesh::for_each(mesh.points(), validatePointsZ); - - std::size_t nNonzeroBins = 0; - for (std::size_t bin = 0; bin < 10; bin++) - { - if (validatePointsZ.histogram()[bin] != 0) - { - nNonzeroBins++; - } - } - test(nNonzeroBins == 1); - } - - return 0; -} diff --git a/smtk/mesh/testing/cxx/TestExtractByDihedralAngle.cxx b/smtk/mesh/testing/cxx/TestExtractByDihedralAngle.cxx deleted file mode 100644 index 514f85e60abba904c39e222e61f3e116760b4b52..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/TestExtractByDihedralAngle.cxx +++ /dev/null @@ -1,172 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/UUID.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/ModelToMesh.h" -#include "smtk/io/ReadMesh.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/ExtractByDihedralAngle.h" -#include "smtk/mesh/operators/ExtractSkin.h" -#include "smtk/mesh/operators/Import.h" -#include "smtk/mesh/resource/Selection.h" -#include "smtk/mesh/utility/Create.h" - -#include "smtk/common/testing/cxx/helpers.h" - -namespace -{ -// SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -// A numerical tolerance -const double epsilon = 1.e-8; -} // namespace - -// Import a tetrahedralized cube, extract its shell, select a cell on the shell -// to run ExtractByDihedralAngle, check that the points in the resulting -// extraction are coplanar. -int TestExtractByDihedralAngle(int, char*[]) -{ - // Import a tetrahedralized cube - smtk::mesh::Resource::Ptr resource; - { - smtk::operation::Operation::Ptr importOp = smtk::mesh::Import::create(); - - test(importOp != nullptr, "No import operator"); - - { - std::string file_path(data_root); - file_path += "/mesh/3d/cube.exo"; - importOp->parameters()->findFile("filename")->setValue(file_path); - } - - smtk::operation::Operation::Result importOpResult = importOp->operate(); - test( - importOpResult->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "Import operator failed"); - - // Retrieve the resulting resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - // Access the generated resource - resource = std::dynamic_pointer_cast(resourceItem->value()); - } - - // Extract the tetrahedra cube's shell and remove its tetrahedra - { - smtk::mesh::MeshSet tetrahedra = resource->meshes(); - smtk::operation::Operation::Ptr extractSkin = smtk::mesh::ExtractSkin::create(); - extractSkin->parameters()->associate(smtk::mesh::Component::create(tetrahedra)); - smtk::operation::Operation::Result result = extractSkin->operate(); - test( - result->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "Extract skin failed"); - - auto trianglesComponent = - std::dynamic_pointer_cast(result->findComponent("created")->value()); - smtk::mesh::MeshSet triangles = trianglesComponent->mesh(); - - resource->removeMeshes(tetrahedra); - - test(resource->meshes().size() == 1); - } - - // Run ExtractByDihedralAngle using the first triangle cell as input - { - smtk::mesh::HandleRange firstCell; - firstCell.insert(*(smtk::mesh::rangeElementsBegin(resource->meshes().cells().range()))); - - smtk::mesh::CellSet cellset(resource, firstCell); - - smtk::operation::Operation::Ptr extractByDihedralAngle = - smtk::mesh::ExtractByDihedralAngle::create(); - - // Create a mesh selection - smtk::mesh::Selection::Ptr selection = smtk::mesh::Selection::create(cellset); - extractByDihedralAngle->parameters()->associate(selection); - extractByDihedralAngle->operate(); - } - - // Test that the points in the extracted mesh all lie in a plane - { - // Test that there are only two meshsets (the temporary meshset should have - // been removed) - test(resource->meshes().size() == 2); - - // The extracted mesh is the meshset with fewer cells - smtk::mesh::MeshSet extractedMesh = resource->meshes(); - for (std::size_t i = 0; i < resource->meshes().size(); i++) - { - if (resource->meshes().subset(i).cells().size() < extractedMesh.cells().size()) - { - extractedMesh = resource->meshes().subset(i); - } - } - - // Check that there are enough points in the extracted meshset to test for - // coplanarity - test(extractedMesh.points().size() > 3); - - // Access the extracted point coordinates - std::vector points(3 * extractedMesh.points().size()); - extractedMesh.points().get(points); - - // Construct a point on the plane and the plane's normal - std::array p0 = { points[0], points[1], points[2] }; - std::array p1 = { points[3], points[4], points[5] }; - std::array p2 = { points[6], points[7], points[8] }; - - std::array v1 = { p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2] }; - std::array v2 = { p2[0] - p0[0], p2[1] - p0[1], p2[2] - p0[2] }; - - std::array n = { v1[1] * v2[2] - v1[2] * v2[1], - v1[2] * v2[0] - v1[0] * v2[2], - v1[0] * v2[1] - v1[1] * v2[0] }; - - double magnitude = sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); - for (std::size_t i = 0; i < n.size(); i++) - { - n[i] /= magnitude; - } - - // For each subsequent point, check that the point lies on the plane - // described by and - for (std::size_t i = 3; i < extractedMesh.points().size(); i++) - { - double* p = &points[3 * i]; - - std::array v = { p[0] - p0[0], p[1] - p0[1], p[2] - p0[2] }; - - double dot = v[0] * n[0] + v[1] * n[1] + v[2] * n[2]; - - test(fabs(dot) < epsilon, "Extracted point does not lie in the plane"); - } - } - - return 0; -} diff --git a/smtk/mesh/testing/cxx/TestGenerateHotStartData.cxx b/smtk/mesh/testing/cxx/TestGenerateHotStartData.cxx deleted file mode 100644 index 04f53086cf8ff7b522526b25af50253b42d1a03b..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/TestGenerateHotStartData.cxx +++ /dev/null @@ -1,292 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/UUID.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/ModelToMesh.h" -#include "smtk/io/ReadMesh.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/GenerateHotStartData.h" - -#include "smtk/model/Resource.h" -#include "smtk/model/json/jsonResource.h" -#include "smtk/model/json/jsonTessellation.h" - -#include -#include -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ -std::string write_root = SMTK_SCRATCH_DIR; - -void create_simple_mesh_model(smtk::model::ResourcePtr resource, std::string file_path) -{ - std::ifstream file(file_path.c_str()); - - std::string json_str((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); - nlohmann::json json = nlohmann::json::parse(json_str); - - smtk::model::from_json(json, resource); - for (auto& tessPair : json["tessellations"]) - { - smtk::common::UUID id = tessPair[0]; - smtk::model::Tessellation tess = tessPair[1]; - resource->setTessellation(id, tess); - } - - resource->assignDefaultNames(); - - file.close(); -} - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -class HistogramFieldData -{ -public: - HistogramFieldData(std::size_t nBins, double min, double max) - : m_min(min) - , m_max(max) - { - m_hist.resize(nBins, 0); - } - - [[nodiscard]] const std::vector& histogram() const { return m_hist; } - -protected: - std::vector m_hist; - double m_min; - double m_max; -}; - -class HistogramPointFieldData - : public smtk::mesh::PointForEach - , public HistogramFieldData -{ -public: - HistogramPointFieldData(std::size_t nBins, double min, double max, smtk::mesh::PointField& pf) - : HistogramFieldData(nBins, min, max) - , m_pointField(pf) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& /*xyz*/, - bool& /*coordinatesModified*/) override - { - std::vector values(pointIds.size()); - m_pointField.get(pointIds, values.data()); - for (auto& value : values) - { - std::size_t bin = static_cast((value - m_min) / (m_max - m_min) * m_hist.size()); - - ++m_hist[bin]; - } - } - -protected: - smtk::mesh::PointField& m_pointField; -}; -} // namespace - -// Load in a model, convert it to a mesh, and construct a dataset for that mesh -// using interpolation points. Then, histogram the values of the mesh cells -// and compare the histogram to expected values. - -int main(int argc, char* argv[]) -{ - if (argc == 1) - { - std::cout << "Must provide input file as argument" << std::endl; - return 1; - } - - std::ifstream file; - file.open(argv[1]); - if (!file.good()) - { - std::cout << "Could not open file \"" << argv[1] << "\".\n\n"; - return 1; - } - - // Create a model resource - smtk::model::ResourcePtr resource = smtk::model::Resource::create(); - - // Load in the model - create_simple_mesh_model(resource, std::string(argv[1])); - - // Convert it to a mesh - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr meshResource = convert(resource); - - // Create a "Generate Hotstart Data" operator - smtk::operation::Operation::Ptr generateHotStartDataOp = - smtk::mesh::GenerateHotStartData::create(); - if (!generateHotStartDataOp) - { - std::cerr << "No \"generate hotstart data\" operator\n"; - return 1; - } - - // Set the operator's data set type - bool valueSet = generateHotStartDataOp->parameters()->findString("dstype")->setToDefault(); - - if (!valueSet) - { - std::cerr << "Failed to set data set type on operator\n"; - return 1; - } - - // Set the operator's input mesh - smtk::mesh::MeshSet mesh = meshResource->meshes(); - valueSet = generateHotStartDataOp->parameters()->associate(smtk::mesh::Component::create(mesh)); - - if (!valueSet) - { - std::cerr << "Failed to set mesh value on operator\n"; - return 1; - } - - // Set the operator's input power - smtk::attribute::DoubleItemPtr power = generateHotStartDataOp->parameters()->findDouble("power"); - - if (!power) - { - std::cerr << "Failed to set power value on operator\n"; - return 1; - } - - power->setValue(2.); - - // Set the operator's input points - std::size_t numberOfPoints = 4; - double pointData[4][3] = { - { -1., -1., 0. }, { -1., 6., 25. }, { 10., -1., 50. }, { 10., 6., 40. } - }; - - bool fromCSV = false; - if (argc > 2) - { - fromCSV = std::atoi(argv[2]) == 1; - } - - std::string write_path; - if (fromCSV) - { - write_path = std::string(write_root + "/" + smtk::common::UUID::random().toString() + ".csv"); - std::ofstream outfile(write_path.c_str()); - for (std::size_t i = 0; i < 4; i++) - { - outfile << pointData[i][0] << "," << pointData[i][1] << "," << pointData[i][2] << std::endl; - } - outfile.close(); - - smtk::attribute::FileItemPtr ptsFile = - generateHotStartDataOp->parameters()->findFile("ptsfile"); - if (!ptsFile) - { - std::cerr << "No \"ptsfile\" item in parameters\n"; - cleanup(write_path); - return 1; - } - - ptsFile->setIsEnabled(true); - ptsFile->setValue(write_path); - } - else - { - // Set the operator's input points - smtk::attribute::GroupItemPtr points = - generateHotStartDataOp->parameters()->findGroup("points"); - - if (!points) - { - std::cerr << "No \"points\" item in parameters\n"; - return 1; - } - - points->setNumberOfGroups(numberOfPoints); - for (std::size_t i = 0; i < numberOfPoints; i++) - { - for (std::size_t j = 0; j < 3; j++) - { - smtk::dynamic_pointer_cast(points->item(i, 0)) - ->setValue(j, pointData[i][j]); - } - } - } - - // Execute "generate hotstart data" operator... - smtk::operation::Operation::Result generateHotStartDataOpResult = - generateHotStartDataOp->operate(); - - // ...delete the generated points file... - if (fromCSV) - { - cleanup(write_path); - } - - // ...and test the results for success. - if ( - generateHotStartDataOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"generate hotstart data\" operator failed\n"; - return 1; - } - - // Histogram the resulting points and compare against expected values. - std::vector histogram; - smtk::mesh::PointField pointField = meshResource->meshes().pointField("ioh"); - HistogramPointFieldData histogramPointFieldData(10, -.01, 50.01, pointField); - smtk::mesh::for_each(mesh.points(), histogramPointFieldData); - histogram = histogramPointFieldData.histogram(); - - std::array expected = { { 0, 1, 3, 1, 3, 4, 9, 5, 4, 2 } }; - - std::size_t counter = 0; - for (auto& bin : histogram) - { - if (bin != expected[counter++]) - { - std::cerr << "\"generate hotstart data\" operator produced unexpected results\n"; - return 1; - } - } - return 0; -} diff --git a/smtk/mesh/testing/cxx/TestInterpolateOntoMesh.cxx b/smtk/mesh/testing/cxx/TestInterpolateOntoMesh.cxx deleted file mode 100644 index fee7e3f81d9d315e98f6179c414229b13b9dfb6b..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/TestInterpolateOntoMesh.cxx +++ /dev/null @@ -1,357 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/UUID.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/ModelToMesh.h" -#include "smtk/io/ReadMesh.h" - -#include "smtk/model/DefaultSession.h" -#include "smtk/model/json/jsonResource.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/InterpolateOntoMesh.h" - -#include "smtk/model/Resource.h" - -#include -#include -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ -std::string write_root = SMTK_SCRATCH_DIR; - -void create_simple_mesh_model(smtk::model::ResourcePtr resource, std::string file_path) -{ - std::ifstream file(file_path.c_str()); - - std::string json_str((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); - nlohmann::json json = nlohmann::json::parse(json_str); - - smtk::model::from_json(json, resource); - for (auto& tessPair : json["tessellations"]) - { - smtk::common::UUID id = tessPair[0]; - smtk::model::Tessellation tess = tessPair[1]; - resource->setTessellation(id, tess); - } - - resource->assignDefaultNames(); - - file.close(); -} - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -class HistogramFieldData -{ -public: - HistogramFieldData(std::size_t nBins, double min, double max) - : m_min(min) - , m_max(max) - { - m_hist.resize(nBins, 0); - } - - [[nodiscard]] const std::vector& histogram() const { return m_hist; } - -protected: - std::vector m_hist; - double m_min; - double m_max; -}; - -class HistogramCellFieldData - : public smtk::mesh::CellForEach - , public HistogramFieldData -{ -public: - HistogramCellFieldData(std::size_t nBins, double min, double max, smtk::mesh::CellField& cf) - : smtk::mesh::CellForEach(false) - , HistogramFieldData(nBins, min, max) - , m_cellField(cf) - { - } - - void forCell( - const smtk::mesh::Handle& cellId, - smtk::mesh::CellType /*cellType*/, - int /*numPointIds*/) override - { - smtk::mesh::HandleRange range; - range.insert(cellId); - double value = 0.; - m_cellField.get(range, &value); - std::size_t bin = static_cast((value - m_min) / (m_max - m_min) * m_hist.size()); - ++m_hist[bin]; - } - -protected: - smtk::mesh::CellField& m_cellField; -}; - -class HistogramPointFieldData - : public smtk::mesh::PointForEach - , public HistogramFieldData -{ -public: - HistogramPointFieldData(std::size_t nBins, double min, double max, smtk::mesh::PointField& pf) - : HistogramFieldData(nBins, min, max) - , m_pointField(pf) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& /*xyz*/, - bool& /*coordinatesModified*/) override - { - std::vector values(pointIds.size()); - m_pointField.get(pointIds, values.data()); - for (auto& value : values) - { - std::size_t bin = static_cast((value - m_min) / (m_max - m_min) * m_hist.size()); - - ++m_hist[bin]; - } - } - -protected: - smtk::mesh::PointField& m_pointField; -}; -} // namespace - -// Load in a model, convert it to a mesh, and construct a dataset for that mesh -// using interpolation points. Then, histogram the values of the mesh cells -// and compare the histogram to expected values. - -int main(int argc, char* argv[]) -{ - if (argc == 1) - { - std::cout << "Must provide input file as argument" << std::endl; - return 1; - } - - std::ifstream file; - file.open(argv[1]); - if (!file.good()) - { - std::cout << "Could not open file \"" << argv[1] << "\".\n\n"; - return 1; - } - - // Create a model resource - smtk::model::ResourcePtr resource = smtk::model::Resource::create(); - - // Load in the model - create_simple_mesh_model(resource, std::string(argv[1])); - - // Convert it to a mesh - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr meshResource = convert(resource); - - // Create an "Interpolate Onto Mesh" operator - smtk::operation::Operation::Ptr interpolateOntoMeshOp = smtk::mesh::InterpolateOntoMesh::create(); - if (!interpolateOntoMeshOp) - { - std::cerr << "No \"interpolate onto mesh\" operator\n"; - return 1; - } - - // Set the operator's data set name - bool valueSet = interpolateOntoMeshOp->parameters()->findString("dsname")->setValue("my field"); - - if (!valueSet) - { - std::cerr << "Failed to set data set name on operator\n"; - return 1; - } - - // Set the operator's input mesh - smtk::mesh::MeshSet mesh = meshResource->meshes(); - valueSet = interpolateOntoMeshOp->parameters()->associate(smtk::mesh::Component::create(mesh)); - - if (!valueSet) - { - std::cerr << "Failed to set mesh value on operator\n"; - return 1; - } - - interpolateOntoMeshOp->parameters() - ->findString("interpolation scheme") - ->setValue("inverse distance weighting"); - - // Set the operator's input power - smtk::attribute::DoubleItemPtr power = interpolateOntoMeshOp->parameters()->findDouble("power"); - - if (!power) - { - std::cerr << "Failed to set power value on operator\n"; - return 1; - } - - power->setValue(2.); - - bool interpolateToPoints = false; - if (argc > 2) - { - interpolateToPoints = std::atoi(argv[2]) == 1; - } - - smtk::attribute::IntItemPtr interpMode = - interpolateOntoMeshOp->parameters()->findInt("interpmode"); - - if (!interpMode) - { - std::cerr << "Failed to set interpolation mode on operator\n"; - return 1; - } - - interpMode->setValue(interpolateToPoints ? 1 : 0); - - // Set the operator's input points - std::size_t numberOfPoints = 4; - double pointData[4][4] = { - { -1., -1., 0., 0. }, { -1., 6., 0., 25. }, { 10., -1., 0., 50. }, { 10., 6., 0., 40. } - }; - - bool fromCSV = false; - if (argc > 3) - { - fromCSV = std::atoi(argv[3]) == 1; - } - - std::string write_path; - if (fromCSV) - { - write_path = std::string(write_root + "/" + smtk::common::UUID::random().toString() + ".csv"); - std::ofstream outfile(write_path.c_str()); - for (std::size_t i = 0; i < 4; i++) - { - outfile << pointData[i][0] << "," << pointData[i][1] << "," << pointData[i][2] << "," - << pointData[i][3] << std::endl; - } - outfile.close(); - - interpolateOntoMeshOp->parameters()->findString("input data")->setValue("ptsfile"); - smtk::attribute::FileItemPtr ptsFile = interpolateOntoMeshOp->parameters()->findFile("ptsfile"); - if (!ptsFile) - { - std::cerr << "No \"ptsfile\" item in parameters\n"; - cleanup(write_path); - return 1; - } - - ptsFile->setIsEnabled(true); - ptsFile->setValue(write_path); - } - else - { - interpolateOntoMeshOp->parameters()->findString("input data")->setValue("points"); - - // Set the operator's input points - smtk::attribute::GroupItemPtr points = interpolateOntoMeshOp->parameters()->findGroup("points"); - - if (!points) - { - std::cerr << "No \"points\" item in parameters\n"; - return 1; - } - - points->setNumberOfGroups(numberOfPoints); - for (std::size_t i = 0; i < numberOfPoints; i++) - { - for (std::size_t j = 0; j < 4; j++) - { - smtk::dynamic_pointer_cast(points->item(i, 0)) - ->setValue(j, pointData[i][j]); - } - } - } - - // Execute "Interpolate Onto Mesh" operator... - smtk::operation::Operation::Result interpolateOntoMeshOpResult = interpolateOntoMeshOp->operate(); - - // ...delete the generated points file... - if (fromCSV) - { - cleanup(write_path); - } - - // ...and test the results for success. - if ( - interpolateOntoMeshOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"interpolate onto mesh\" operator failed\n"; - return 1; - } - - // Histogram the resulting points and compare against expected values. - std::vector histogram; - if (interpolateToPoints) - { - smtk::mesh::PointField pointField = meshResource->meshes().pointField("my field"); - HistogramPointFieldData histogramPointFieldData(10, -.01, 50.01, pointField); - smtk::mesh::for_each(mesh.points(), histogramPointFieldData); - histogram = histogramPointFieldData.histogram(); - } - else - { - smtk::mesh::CellField cellField = meshResource->meshes().cellField("my field"); - HistogramCellFieldData histogramCellFieldData(10, -.01, 50.01, cellField); - smtk::mesh::for_each(mesh.cells(), histogramCellFieldData); - histogram = histogramCellFieldData.histogram(); - } - - std::array expectedForCells = { { 0, 1, 4, 6, 9, 14, 20, 18, 9, 3 } }; - std::array expectedForPoints = { { 0, 1, 3, 1, 3, 4, 9, 5, 4, 2 } }; - std::array& expected = - interpolateToPoints ? expectedForPoints : expectedForCells; - - std::size_t counter = 0; - for (auto& bin : histogram) - { - if (bin != expected[counter++]) - { - std::cerr << "\"interpolate onto mesh\" operator produced unexpected results\n"; - return 1; - } - } - - return 0; -} diff --git a/smtk/mesh/testing/cxx/TestSamplePointsOnSurface.cxx b/smtk/mesh/testing/cxx/TestSamplePointsOnSurface.cxx deleted file mode 100644 index b496de4c39f84808269fe84dac3cfd0b8c4f29ea..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/TestSamplePointsOnSurface.cxx +++ /dev/null @@ -1,217 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Instance.h" -#include "smtk/model/Model.h" -#include "smtk/model/operators/AddAuxiliaryGeometry.h" -#include "smtk/model/operators/CreateInstances.h" - -#include "smtk/operation/Manager.h" - -namespace -{ -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -} // namespace - -using namespace smtk::model; - -// Import a triangulated terrain as a mesh model, add an auxiliary geometry as -// a glyph prototype, and create a bunch of glyph instances that are sampled on -// the surface of the terrain. -int TestSamplePointsOnSurface(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - auto importOp = smtk::session::mesh::Import::create(); - - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - std::string importFilePath(data_root); - importFilePath += "/mesh/3d/terrain.exo"; - - importOp->parameters()->findFile("filename")->setValue(importFilePath); - importOp->parameters()->findVoid("construct hierarchy")->setIsEnabled(false); - - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - - // Retrieve the resulting resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - // Access the generated resource - smtk::session::mesh::Resource::Ptr resource = - std::dynamic_pointer_cast(resourceItem->value()); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - smtk::model::Entity::Ptr modelEntity = - std::dynamic_pointer_cast(componentItem->value()); - - smtk::model::Model model = modelEntity->referenceAs(); - - if (!model.isValid()) - { - std::cerr << "Import operator returned an invalid model\n"; - return 1; - } - - // Access all of the model's faces - smtk::model::EntityRefs currentEnts = - resource->entitiesMatchingFlagsAs(smtk::model::FACE); - if (currentEnts.empty()) - { - std::cerr << "No faces!" << std::endl; - return 1; - } - - // Grab the top face (known to be named "Element Block 13") - smtk::model::EntityRef eRef; - for (const auto& e : currentEnts) - { - if (e.name() == "Element Block 13") - { - eRef = e; - } - } - - const smtk::model::Face& face = eRef.as(); - - if (!face.isValid()) - { - std::cerr << "Face is invald\n"; - return 1; - } - - // add auxiliary geometry - auto auxGeoOp = smtk::model::AddAuxiliaryGeometry::create(); - - { - std::string file_path(data_root); - file_path += "/model/3d/obj/cone.obj"; - auxGeoOp->parameters()->findFile("url")->setValue(file_path); - } - auxGeoOp->parameters()->associateEntity(model); - - smtk::operation::Operation::Result auxGeoOpResult = auxGeoOp->operate(); - - if ( - auxGeoOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Add auxiliary geometry failed!\n"; - return 1; - } - - // Retrieve the resulting auxiliary geometry item - smtk::attribute::ComponentItemPtr auxGeoItem = - std::dynamic_pointer_cast( - auxGeoOpResult->findComponent("created")); - - // Access the generated auxiliary geometry - smtk::model::Entity::Ptr auxGeoEntity = - std::dynamic_pointer_cast(auxGeoItem->value()); - - smtk::model::AuxiliaryGeometry auxGeo = - auxGeoEntity->referenceAs(); - - if (!auxGeo.isValid()) - { - std::cerr << "Auxiliary geometry is not valid!\n"; - return 1; - } - - { - // create the create instances operation - auto createInstances = smtk::model::CreateInstances::create(); - if (!createInstances) - { - std::cerr << "No \"Create Instances\" operation!\n"; - return 1; - } - - // set input values for the create instances operation - createInstances->parameters()->associate(auxGeoEntity); - createInstances->parameters()->findString("placement rule")->setDiscreteIndex(2); - createInstances->parameters()->findComponent("surface")->setValue(face.component()); - createInstances->parameters()->findInt("sample size")->setValue(10); - createInstances->parameters()->findString("snap to entity")->setIsEnabled(false); - - smtk::operation::Operation::Result result = createInstances->operate(); - if ( - result->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Create Instances operation failed\n"; - return 1; - } - } - - // Iterate over the coordinates of the instances to ensure that their - // coordinates snapped to the model surface, which is below the box where - // random points were seeded. - smtk::model::EntityRefs instances = - resource->entitiesMatchingFlagsAs(smtk::model::INSTANCE_ENTITY); - if (instances.empty()) - { - std::cerr << "No instances!" << std::endl; - return 1; - } - - std::cout << "There are " << instances.size() << " instances" << std::endl; - - for (const auto& instance : instances) - { - const std::vector& coords = instance.hasTessellation()->coords(); - for (std::size_t i = 0; i < coords.size(); i += 3) - { - { - std::cout << "coordinate " << i / 3 << " = (" << coords[i] << ", " << coords[i + 1] << ", " - << coords[i + 2] << ")" << std::endl; - } - } - } - - return 0; -} diff --git a/smtk/mesh/testing/cxx/TestSnapPointsToSurface.cxx b/smtk/mesh/testing/cxx/TestSnapPointsToSurface.cxx deleted file mode 100644 index 4a947b8e653ddf711c8386d83e42ab62f19987be..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/TestSnapPointsToSurface.cxx +++ /dev/null @@ -1,231 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Instance.h" -#include "smtk/model/Model.h" -#include "smtk/model/operators/AddAuxiliaryGeometry.h" -#include "smtk/model/operators/CreateInstances.h" - -#include "smtk/operation/Manager.h" - -namespace -{ -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -} // namespace - -using namespace smtk::model; - -// Import a triangulated terrain as a mesh model, add an auxiliary geometry as -// a glyph prototype, and create a bunch of glyph instances that are snapped to -// the surface of the terrain. Finally, check that all of the points (that were -// seeded above a certain z value) fall below their initial z value. -int TestSnapPointsToSurface(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - auto importOp = smtk::session::mesh::Import::create(); - - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - std::string importFilePath(data_root); - importFilePath += "/mesh/3d/terrain.exo"; - - importOp->parameters()->findFile("filename")->setValue(importFilePath); - importOp->parameters()->findVoid("construct hierarchy")->setIsEnabled(false); - - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - - // Retrieve the resulting resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - // Access the generated resource - smtk::session::mesh::Resource::Ptr resource = - std::dynamic_pointer_cast(resourceItem->value()); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - smtk::model::Entity::Ptr modelEntity = - std::dynamic_pointer_cast(componentItem->value()); - - smtk::model::Model model = modelEntity->referenceAs(); - - if (!model.isValid()) - { - std::cerr << "Import operator returned an invalid model\n"; - return 1; - } - - // Access all of the model's faces - smtk::model::EntityRefs currentEnts = - resource->entitiesMatchingFlagsAs(smtk::model::FACE); - if (currentEnts.empty()) - { - std::cerr << "No faces!" << std::endl; - return 1; - } - - // Grab the top face (known to be named "Element Block 13") - smtk::model::EntityRef eRef; - for (const auto& e : currentEnts) - { - if (e.name() == "Element Block 13") - { - eRef = e; - } - } - - const smtk::model::Face& face = eRef.as(); - - if (!face.isValid()) - { - std::cerr << "Face is invald\n"; - return 1; - } - - // add auxiliary geometry - auto auxGeoOp = smtk::model::AddAuxiliaryGeometry::create(); - - { - std::string file_path(data_root); - file_path += "/model/3d/obj/cone.obj"; - auxGeoOp->parameters()->findFile("url")->setValue(file_path); - } - auxGeoOp->parameters()->associateEntity(model); - - smtk::operation::Operation::Result auxGeoOpResult = auxGeoOp->operate(); - - if ( - auxGeoOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Add auxiliary geometry failed!\n"; - return 1; - } - - // Retrieve the resulting auxiliary geometry item - smtk::attribute::ComponentItemPtr auxGeoItem = - std::dynamic_pointer_cast( - auxGeoOpResult->findComponent("created")); - - // Access the generated auxiliary geometry - smtk::model::Entity::Ptr auxGeoEntity = - std::dynamic_pointer_cast(auxGeoItem->value()); - - smtk::model::AuxiliaryGeometry auxGeo = - auxGeoEntity->referenceAs(); - - if (!auxGeo.isValid()) - { - std::cerr << "Auxiliary geometry is not valid!\n"; - return 1; - } - - { - // create the create instances operation - auto createInstances = smtk::model::CreateInstances::create(); - if (!createInstances) - { - std::cerr << "No \"Create Instances\" operation!\n"; - return 1; - } - - // set input values for the create instances operation - createInstances->parameters()->associate(auxGeoEntity); - createInstances->parameters()->findString("placement rule")->setDiscreteIndex(1); - auto xAxis = std::dynamic_pointer_cast( - createInstances->parameters()->findGroup("volume of interest")->item(0, 0)); - xAxis->setValue(0, 57.); - xAxis->setValue(1, 60.); - auto yAxis = std::dynamic_pointer_cast( - createInstances->parameters()->findGroup("volume of interest")->item(1, 0)); - yAxis->setValue(0, 2.); - yAxis->setValue(1, 5.); - auto zAxis = std::dynamic_pointer_cast( - createInstances->parameters()->findGroup("volume of interest")->item(2, 0)); - zAxis->setValue(0, 0.1); - zAxis->setValue(1, 0.2); - createInstances->parameters()->findInt("sample size")->setValue(10); - createInstances->parameters()->findString("snap to entity")->setIsEnabled(true); - createInstances->parameters()->findString("snap to entity")->setDiscreteIndex(1); - createInstances->parameters()->findComponent("entity")->setValue(face.component()); - - smtk::operation::Operation::Result result = createInstances->operate(); - if ( - result->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Create Instances operation failed\n"; - return 1; - } - } - - // Iterate over the coordinates of the instances to ensure that their - // coordinates snapped to the model surface, which is below the box where - // random points were seeded. - smtk::model::EntityRefs instances = - resource->entitiesMatchingFlagsAs(smtk::model::INSTANCE_ENTITY); - if (instances.empty()) - { - std::cerr << "No instances!" << std::endl; - return 1; - } - - for (const auto& instance : instances) - { - const std::vector& coords = instance.hasTessellation()->coords(); - for (std::size_t i = 2; i < coords.size(); i += 3) - { - if (coords[i] >= 0.1) - { - std::cerr << "coordinate " << i / 3 << " (" << coords[i - 2] << ", " << coords[i - 1] - << ", " << coords[i] << ") did not snap" << std::endl; - return 1; - } - } - } - - return 0; -} diff --git a/smtk/mesh/testing/cxx/TestSubtract.cxx b/smtk/mesh/testing/cxx/TestSubtract.cxx deleted file mode 100644 index f04ff1aa9e8ba1530034853c2ebb050e8bde6384..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/TestSubtract.cxx +++ /dev/null @@ -1,156 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/UUID.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/ModelToMesh.h" -#include "smtk/io/ReadMesh.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/ExtractByDihedralAngle.h" -#include "smtk/mesh/operators/ExtractSkin.h" -#include "smtk/mesh/operators/Import.h" -#include "smtk/mesh/operators/Subtract.h" -#include "smtk/mesh/resource/Selection.h" -#include "smtk/mesh/utility/Create.h" - -#include "smtk/common/testing/cxx/helpers.h" - -namespace -{ -// SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -// A numerical tolerance -const double epsilon = 1.e-8; -} // namespace - -// Import a tetrahedralized cube, extract its shell, select a cell on the shell -// to run ExtractByDihedralAngle, subtract the result from the shell, check that -// the subtraction was successful. -int TestSubtract(int, char*[]) -{ - // Import a tetrahedralized cube - smtk::mesh::Resource::Ptr resource; - { - smtk::operation::Operation::Ptr importOp = smtk::mesh::Import::create(); - - test(importOp != nullptr, "No import operator"); - - { - std::string file_path(data_root); - file_path += "/mesh/3d/cube.exo"; - importOp->parameters()->findFile("filename")->setValue(file_path); - } - - smtk::operation::Operation::Result importOpResult = importOp->operate(); - test( - importOpResult->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "Import operator failed"); - - // Retrieve the resulting resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - // Access the generated resource - resource = std::dynamic_pointer_cast(resourceItem->value()); - } - - // Extract the tetrahedra cube's shell and remove its tetrahedra - smtk::mesh::Component::Ptr shell; - { - smtk::mesh::MeshSet tetrahedra = resource->meshes(); - smtk::operation::Operation::Ptr extractSkin = smtk::mesh::ExtractSkin::create(); - extractSkin->parameters()->associate(smtk::mesh::Component::create(tetrahedra)); - smtk::operation::Operation::Result result = extractSkin->operate(); - test( - result->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "Extract skin failed"); - - shell = - std::dynamic_pointer_cast(result->findComponent("created")->value()); - - resource->removeMeshes(tetrahedra); - - test(resource->meshes().size() == 1); - } - - // Run ExtractByDihedralAngle using the first triangle cell as input - smtk::mesh::Component::Ptr extracted; - { - smtk::mesh::HandleRange firstCell; - firstCell.insert(*(smtk::mesh::rangeElementsBegin(resource->meshes().cells().range()))); - - smtk::mesh::CellSet cellset(resource, firstCell); - - smtk::operation::Operation::Ptr extractByDihedralAngle = - smtk::mesh::ExtractByDihedralAngle::create(); - - // Create a mesh selection - smtk::mesh::Selection::Ptr selection = smtk::mesh::Selection::create(cellset); - extractByDihedralAngle->parameters()->associate(selection); - - smtk::operation::Operation::Result result = extractByDihedralAngle->operate(); - test( - result->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "Extract by dihedral angle failed"); - - extracted = - std::dynamic_pointer_cast(result->findComponent("created")->value()); - } - - // Subtract the selection from the shell - smtk::mesh::Component::Ptr differenceMesh; - { - smtk::operation::Operation::Ptr subtract = smtk::mesh::Subtract::create(); - subtract->parameters()->associate(shell); - subtract->parameters()->findComponent("subtrahend")->setValue(extracted); - - smtk::operation::Operation::Result result = subtract->operate(); - test( - result->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "subtract failed"); - - differenceMesh = - std::dynamic_pointer_cast(result->findComponent("created")->value()); - } - - smtk::mesh::HandleRange minuend = shell->mesh().cells().range(); - smtk::mesh::HandleRange subtrahend = extracted->mesh().cells().range(); - smtk::mesh::HandleRange difference = differenceMesh->mesh().cells().range(); - - // Ensure that none of the ranges are empty - test(!minuend.empty() && !subtrahend.empty() && !difference.empty()); - - // Ensure that the subtrahend and difference have no intersection - test((subtrahend & difference).empty()); - - // Ensure that the sum of the subtrahend and difference is the minuend - test(smtk::mesh::rangesEqual(minuend, subtrahend + difference)); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/TestTransform.cxx b/smtk/mesh/testing/cxx/TestTransform.cxx deleted file mode 100644 index 4f75d192f063c63647314ac1458311297209a582..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/TestTransform.cxx +++ /dev/null @@ -1,99 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/UUID.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/geometry/queries/BoundingBox.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/Import.h" -#include "smtk/mesh/operators/Transform.h" -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/common/testing/cxx/helpers.h" - -namespace -{ -// SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -// A numerical tolerance -const double epsilon = 1.e-8; -} // namespace - -// Import a tetrahedralized cube, compute its extent, transform the cube and -// compare the new extent with the original one.. -int TestTransform(int, char*[]) -{ - // Import a tetrahedralized cube - smtk::mesh::Resource::Ptr resource; - { - smtk::operation::Operation::Ptr importOp = smtk::mesh::Import::create(); - - test(importOp != nullptr, "No import operator"); - - { - std::string file_path(data_root); - file_path += "/mesh/3d/cube.exo"; - importOp->parameters()->findFile("filename")->setValue(file_path); - } - - smtk::operation::Operation::Result importOpResult = importOp->operate(); - test( - importOpResult->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "Import operator failed"); - - // Retrieve the resulting resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - // Access the generated resource - resource = std::dynamic_pointer_cast(resourceItem->value()); - } - - auto& boundingBox = resource->queries().get(); - std::array extent = boundingBox(resource); - - { - smtk::operation::Operation::Ptr transform = smtk::mesh::Transform::create(); - transform->parameters()->associate(smtk::mesh::Component::create(resource->meshes())); - transform->parameters()->findDouble("scale")->setValue(1, 2.); - - smtk::operation::Operation::Result result = transform->operate(); - test( - result->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "transform failed"); - } - - std::array newExtent = smtk::mesh::utility::extent(resource->meshes()); - - // Ensure that the extent doubled in the y direction - test(fabs(extent[0] - newExtent[0]) < epsilon); - test(fabs(extent[1] - newExtent[1]) < epsilon); - test(fabs(2. * extent[2] - newExtent[2]) < epsilon); - test(fabs(2. * extent[3] - newExtent[3]) < epsilon); - test(fabs(extent[4] - newExtent[4]) < epsilon); - test(fabs(extent[5] - newExtent[5]) < epsilon); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/TestWarpMesh.cxx b/smtk/mesh/testing/cxx/TestWarpMesh.cxx deleted file mode 100644 index ded2781521cb4d2ac90a99ad4f3b669677d10fd8..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/TestWarpMesh.cxx +++ /dev/null @@ -1,273 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/UUID.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/ModelToMesh.h" -#include "smtk/io/ReadMesh.h" - -#include "smtk/model/DefaultSession.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/ElevateMesh.h" - -#include "smtk/model/Resource.h" -#include "smtk/model/json/jsonResource.h" - -#include -#include -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ -std::string write_root = SMTK_SCRATCH_DIR; - -void create_simple_mesh_model(smtk::model::ResourcePtr resource, std::string file_path) -{ - std::ifstream file(file_path.c_str()); - - std::string json_str((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); - nlohmann::json json = nlohmann::json::parse(json_str); - - smtk::model::from_json(json, resource); - for (auto& tessPair : json["tessellations"]) - { - smtk::common::UUID id = tessPair[0]; - smtk::model::Tessellation tess = tessPair[1]; - resource->setTessellation(id, tess); - } - - resource->assignDefaultNames(); - - file.close(); -} - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -class HistogramZCoordinates : public smtk::mesh::PointForEach -{ -public: - HistogramZCoordinates(std::size_t nBins, double min, double max) - : m_min(min) - , m_max(max) - { - m_hist.resize(nBins, 0); - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& /*coordinatesModified*/) override - { - std::size_t counter = 0; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i, counter += 3) - { - std::size_t bin = - static_cast((xyz[counter + 2] - m_min) / (m_max - m_min) * m_hist.size()); - ++m_hist[bin]; - } - } - - [[nodiscard]] const std::vector& histogram() const { return m_hist; } - -protected: - std::vector m_hist; - double m_min; - double m_max; -}; -} // namespace - -// Load in a model, convert it to a mesh, and construct a dataset for that mesh -// using interpolation points. Then, histogram the values of the mesh cells -// and compare the histogram to expected values. - -int main(int argc, char* argv[]) -{ - if (argc == 1) - { - std::cout << "Must provide input file as argument" << std::endl; - return 1; - } - - std::ifstream file; - file.open(argv[1]); - if (!file.good()) - { - std::cout << "Could not open file \"" << argv[1] << "\".\n\n"; - return 1; - } - - // Create a model resource - smtk::model::ResourcePtr resource = smtk::model::Resource::create(); - - // Load in the model - create_simple_mesh_model(resource, std::string(argv[1])); - - // Convert it to a mesh - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr meshResource = convert(resource); - - // Create an "Elevate Mesh" operator - smtk::operation::Operation::Ptr elevateMeshOp = smtk::mesh::ElevateMesh::create(); - if (!elevateMeshOp) - { - std::cerr << "No \"elevate mesh\" operator\n"; - return 1; - } - - // Set the operator's input mesh - smtk::mesh::MeshSet mesh = meshResource->meshes(); - bool valueSet = elevateMeshOp->parameters()->associate(smtk::mesh::Component::create(mesh)); - - if (!valueSet) - { - std::cerr << "Failed to set mesh value on operator\n"; - return 1; - } - - elevateMeshOp->parameters() - ->findString("interpolation scheme") - ->setValue("inverse distance weighting"); - - // Set the operator's input power - smtk::attribute::DoubleItemPtr power = elevateMeshOp->parameters()->findDouble("power"); - - if (!power) - { - std::cerr << "Failed to set power value on operator\n"; - return 1; - } - - power->setValue(2.); - - // Set the operator's input points - std::size_t numberOfPoints = 4; - double pointData[4][4] = { - { -1., -1., 0., 0. }, { -1., 6., 0., 25. }, { 10., -1., 0., 50. }, { 10., 6., 0., 40. } - }; - - bool fromCSV = false; - if (argc > 2) - { - fromCSV = std::atoi(argv[2]) == 1; - } - - std::string write_path; - if (fromCSV) - { - write_path = std::string(write_root + "/" + smtk::common::UUID::random().toString() + ".csv"); - std::ofstream outfile(write_path.c_str()); - for (std::size_t i = 0; i < 4; i++) - { - outfile << pointData[i][0] << "," << pointData[i][1] << "," << pointData[i][2] << "," - << pointData[i][3] << std::endl; - } - outfile.close(); - - elevateMeshOp->parameters()->findString("input data")->setValue("ptsfile"); - smtk::attribute::FileItemPtr ptsFile = elevateMeshOp->parameters()->findFile("ptsfile"); - if (!ptsFile) - { - std::cerr << "No \"ptsfile\" item in parameters\n"; - cleanup(write_path); - return 1; - } - - ptsFile->setIsEnabled(true); - ptsFile->setValue(write_path); - } - else - { - elevateMeshOp->parameters()->findString("input data")->setValue("points"); - - // Set the operator's input points - smtk::attribute::GroupItemPtr points = elevateMeshOp->parameters()->findGroup("points"); - - if (!points) - { - std::cerr << "No \"points\" item in parameters\n"; - return 1; - } - - points->setNumberOfGroups(numberOfPoints); - for (std::size_t i = 0; i < numberOfPoints; i++) - { - for (std::size_t j = 0; j < 4; j++) - { - smtk::dynamic_pointer_cast(points->item(i, 0)) - ->setValue(j, pointData[i][j]); - } - } - } - - // Execute "Elevate Mesh" operator... - smtk::operation::Operation::Result elevateMeshOpResult = elevateMeshOp->operate(); - - // ...delete the generated points file... - if (fromCSV) - { - cleanup(write_path); - } - - // ...and test the results for success. - if ( - elevateMeshOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"elevate mesh\" operator failed\n"; - return 1; - } - - // Histogram the resulting points and compare against expected values. - std::vector histogram; - HistogramZCoordinates histogramZCoordinates(10, -.01, 50.01); - smtk::mesh::for_each(mesh.points(), histogramZCoordinates); - histogram = histogramZCoordinates.histogram(); - - std::array expected = { { 0, 1, 3, 1, 3, 4, 9, 5, 4, 2 } }; - - std::size_t counter = 0; - for (auto& bin : histogram) - { - if (bin != expected[counter++]) - { - std::cerr << "\"elevate mesh\" operator produced unexpected results\n"; - return 1; - } - } - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestAddFileToResource.cxx b/smtk/mesh/testing/cxx/UnitTestAddFileToResource.cxx deleted file mode 100644 index 50a49a9e5748b36bd0ae912648e74204433bb4d7..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestAddFileToResource.cxx +++ /dev/null @@ -1,233 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ReadMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -std::string first_mesh_path() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/64bricks_12ktet.h5m"; - return file_path; -} - -std::string second_mesh_path() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - return file_path; -} - -void verify_cant_append_to_null_resource() -{ - smtk::mesh::ResourcePtr null_resource_ptr; - bool result = smtk::io::readMesh(first_mesh_path(), null_resource_ptr); - test(!result, "read into a null resource should fail"); -} - -void verify_append_to_valid_empty_resource() -{ - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(); - - bool result = smtk::io::readMesh(second_mesh_path(), resource); - test(result, "read of self into self should work"); - test(resource->isValid(), "resource should be valid"); - - std::size_t numMeshes = resource->numberOfMeshes(); - test(numMeshes != 0); -} - -void verify_append_self_to_self() -{ - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(first_mesh_path(), mr); - test(mr->isValid(), "resource should be valid"); - - std::size_t origNumMeshes = mr->numberOfMeshes(); - test(origNumMeshes != 0); - - //append the mesh back onto itself - bool result = read(first_mesh_path(), mr); - test(result, "read of self into self should work"); - test(mr->isValid(), "resource should be valid"); - - //verify the size has doubled - std::size_t newNumMeshes = mr->numberOfMeshes(); - test(newNumMeshes == 2 * origNumMeshes); -} - -void verify_append_subsection_of_self() -{ - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(first_mesh_path(), mr); - test(mr->isValid(), "resource should be valid"); - std::size_t firstNumMesh = mr->numberOfMeshes(); - test(firstNumMesh != 0); - - //now load the second mesh into a different manager and get the size - //this can be used to verify that the append resource has the proper size - std::size_t secondNumMesh = 0; - { - smtk::mesh::ResourcePtr mr1 = - read(first_mesh_path(), mr->interface(), smtk::io::mesh::Subset::OnlyNeumann); - test(mr1->isValid(), "second resource load should be valid"); - secondNumMesh = mr1->numberOfMeshes(); - test(secondNumMesh != 0); - } - //now append a second file and verify the number of meshes is correct - bool result = read(first_mesh_path(), mr, smtk::io::mesh::Subset::OnlyNeumann); - test(result, "read into a valid resource should work"); - test(mr->isValid(), "resource after read should still be valid"); - - std::size_t newNumMeshes = mr->numberOfMeshes(); - test(newNumMeshes == firstNumMesh + secondNumMesh); -} - -void verify_cant_append_mismatched_data() -{ - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(first_mesh_path(), mr); - test(mr->isValid(), "resource should be valid"); - std::size_t firstNumMesh = mr->numberOfMeshes(); - test(firstNumMesh != 0); - - //now append a second file which has different vertices and verify that fails - bool result = read(second_mesh_path(), mr); - test(!result, "read of a second mesh that has different vertices should fail"); -} - -void verify_append_dirichlet_to_neumann() -{ - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(first_mesh_path(), mr, smtk::io::mesh::Subset::OnlyNeumann); - test(mr->isValid(), "resource should be valid"); - std::size_t firstNumMesh = mr->numberOfMeshes(); - test(firstNumMesh != 0); - - //now load the second mesh into a different manager and get the size - //this can be used to verify that the append resource has the proper size - std::size_t secondNumMesh = 0; - { - smtk::mesh::ResourcePtr mr1 = - read(first_mesh_path(), mr->interface(), smtk::io::mesh::Subset::OnlyDirichlet); - test(mr1->isValid(), "second resource load should be valid"); - secondNumMesh = mr1->numberOfMeshes(); - test(secondNumMesh != 0); - } - //now append a second file and verify the number of meshes is correct - bool result = read(first_mesh_path(), mr, smtk::io::mesh::Subset::OnlyDirichlet); - test(result, "import into a valid resource should work"); - test(mr->isValid(), "resource after import should still be valid"); - - std::size_t newNumMeshes = mr->numberOfMeshes(); - test(newNumMeshes == firstNumMesh + secondNumMesh); -} - -void verify_append_neumann_to_dirichlet() -{ - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(first_mesh_path(), mr, smtk::io::mesh::Subset::OnlyDirichlet); - test(mr->isValid(), "resource should be valid"); - std::size_t firstNumMesh = mr->numberOfMeshes(); - test(firstNumMesh != 0); - - //now load the second mesh into a different manager and get the size - //this can be used to verify that the append resource has the proper size - std::size_t secondNumMesh = 0; - { - smtk::mesh::ResourcePtr mr1 = - read(first_mesh_path(), mr->interface(), smtk::io::mesh::Subset::OnlyNeumann); - test(mr1->isValid(), "second resource load should be valid"); - secondNumMesh = mr1->numberOfMeshes(); - test(secondNumMesh != 0); - } - //now append a second file and verify the number of meshes is correct - bool result = read(first_mesh_path(), mr, smtk::io::mesh::Subset::OnlyNeumann); - test(result, "import into a valid resource should work"); - test(mr->isValid(), "resource after import should still be valid"); - - std::size_t newNumMeshes = mr->numberOfMeshes(); - test(newNumMeshes == firstNumMesh + secondNumMesh); -} - -void verify_append_domain_to_dirichlet() -{ - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(first_mesh_path(), mr, smtk::io::mesh::Subset::OnlyDirichlet); - test(mr->isValid(), "resource should be valid"); - std::size_t firstNumMesh = mr->numberOfMeshes(); - test(firstNumMesh != 0); - - //now load the second mesh into a different manager and get the size - //this can be used to verify that the append resource has the proper size - std::size_t secondNumMesh = 0; - { - smtk::mesh::ResourcePtr mr1 = - read(first_mesh_path(), mr->interface(), smtk::io::mesh::Subset::OnlyDomain); - test(mr1->isValid(), "expected domains in this file"); - secondNumMesh = mr1->numberOfMeshes(); - test(secondNumMesh != 0); - } - - //now append a second file and verify the number of meshes is correct - bool result = read(first_mesh_path(), mr, smtk::io::mesh::Subset::OnlyDomain); - test(result, "import into a valid resource should work"); - test(mr->isValid(), "resource after import should still be valid"); - - std::size_t newNumMeshes = mr->numberOfMeshes(); - test(newNumMeshes == firstNumMesh + secondNumMesh); -} -} // namespace - -int UnitTestAddFileToResource(int /*unused*/, char** const /*unused*/) -{ - //append into a resource that had failed to load previously - verify_cant_append_to_null_resource(); - - //given a valid empty resource append a mesh into the resource - verify_append_to_valid_empty_resource(); - - //append a subsection of a mesh into a resource that had loaded - //all of the same mesh before - verify_append_subsection_of_self(); - - //append the mesh that was already loaded previously to the same resource - verify_append_self_to_self(); - - //you cant append together two mesh files that have different vertices's - //since that why cause a geometrimr inconsistency - verify_cant_append_mismatched_data(); - - //attempt to append Dirichlet to a resource that only has Neumman - verify_append_dirichlet_to_neumann(); - - //attempt to append Neumman set to a resource that only has Dirichlet - verify_append_neumann_to_dirichlet(); - - //attempt to append domain set to a resource that only has Dirichlet - verify_append_domain_to_dirichlet(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestAllocator.cxx b/smtk/mesh/testing/cxx/UnitTestAllocator.cxx deleted file mode 100644 index 4ab104e90dfe2a067b2475dbaeafadf72814fad4..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestAllocator.cxx +++ /dev/null @@ -1,72 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/json/Interface.h" -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -void verify_moab_allocator_creation() -{ - smtk::mesh::InterfacePtr iface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - //at this point extract the allocator from json and verify that it - //is NOT null - smtk::mesh::AllocatorPtr allocator = resource->interface()->allocator(); - test(!!allocator, "moab allocator should be valid"); - - //verify that is modified is true - test(resource->isModified(), "resource should be modified once the allocator is accessed"); -} - -void verify_json_allocator_creation() -{ - smtk::mesh::InterfacePtr iface = smtk::mesh::json::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - //at this point extract the allocator from json and verify that it - //is null - smtk::mesh::AllocatorPtr allocator = resource->interface()->allocator(); - test(!allocator, "json allocator should be nullptr"); - - //verify that is modified is true - test(!resource->isModified(), "resource shouldn't be modified"); -} -} // namespace - -int UnitTestAllocator(int /*unused*/, char** const /*unused*/) -{ - verify_moab_allocator_creation(); - verify_json_allocator_creation(); - - //we need to verify simple allocation of: - //points - //1D cells - //2D cells - //3D cells - - //verify that you get errors when allocation cells of 0D - - //show how to add explicit points to a MeshSet - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestBufferedCellAllocator.cxx b/smtk/mesh/testing/cxx/UnitTestBufferedCellAllocator.cxx deleted file mode 100644 index 8b0244b6d38dd1402ff460570a84d0a893f495ac..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestBufferedCellAllocator.cxx +++ /dev/null @@ -1,273 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/json/Interface.h" -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ -double pts[9][3] = { { 0., 0., 0. }, { 1., 0., 0. }, { 1., 1., 0. }, { 0., 1., 0. }, { 0., 0., 1. }, - { 1., 0., 1. }, { 1., 1., 1. }, { 0., 1., 1. }, { .5, -.5, 0. } }; - -double* vertex[1] = { pts[0] }; -double* line[2] = { pts[0], pts[1] }; -double* triangle[3] = { pts[0], pts[1], pts[2] }; -double* quad[4] = { pts[0], pts[1], pts[2], pts[3] }; -double* polygon[5] = { pts[0], pts[1], pts[2], pts[3], pts[8] }; -double* tetrahedron[4] = { pts[0], pts[1], pts[2], pts[4] }; -double* pyramid[5] = { pts[0], pts[1], pts[2], pts[3], pts[4] }; -double* wedge[6] = { pts[0], pts[1], pts[2], pts[4], pts[5], pts[6] }; -double* hexahedron[8] = { pts[0], pts[1], pts[2], pts[3], pts[4], pts[5], pts[6], pts[7] }; - -double** cellPoints[9] = { vertex, line, triangle, quad, polygon, - tetrahedron, pyramid, wedge, hexahedron }; - -void verify_moab_buffered_cell_allocator_creation() -{ - smtk::mesh::InterfacePtr iface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - //at this point extract the allocator from json and verify that it - //is NOT null - smtk::mesh::BufferedCellAllocatorPtr allocator = resource->interface()->bufferedCellAllocator(); - test(!!allocator, "moab buffered cell allocator should be valid"); - - //verify that is modified is true - test( - resource->isModified(), - "resource should be modified once the buffered cell allocator is accessed"); -} - -void verify_json_buffered_cell_allocator_creation() -{ - smtk::mesh::InterfacePtr iface = smtk::mesh::json::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - //at this point extract the allocator from json and verify that it - //is null - smtk::mesh::BufferedCellAllocatorPtr allocator = resource->interface()->bufferedCellAllocator(); - test(!allocator, "json incremental allocator should be nullptr"); - - //verify that is modified is true - test(!resource->isModified(), "resource shouldn't be modified"); -} - -void verify_moab_buffered_cell_allocator_cell(smtk::mesh::CellType cellType) -{ - // Allocate a cell of type . - - smtk::mesh::InterfacePtr iface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - smtk::mesh::BufferedCellAllocatorPtr allocator = resource->interface()->bufferedCellAllocator(); - - // Grab the number of vertices for the cell type being tested - std::size_t nVerticesPerCell = - (cellType == smtk::mesh::Polygon ? 5 : smtk::mesh::verticesPerCell(cellType)); - - test(!allocator->isValid()); - - // Reserve the vertices - test(allocator->reserveNumberOfCoordinates(nVerticesPerCell)); - - test(allocator->isValid()); - - std::vector connectivity(nVerticesPerCell); - // fill the vertices and remember the connectivity - for (std::size_t i = 0; i < nVerticesPerCell; i++) - { - test(allocator->setCoordinate(i, cellPoints[cellType][i])); - connectivity[i] = static_cast(i); - } - - // Add a cell using the cell type and connectivity - test(allocator->addCell(cellType, connectivity.data(), nVerticesPerCell)); - - // Finalize the addition of cells - test(allocator->flush()); - - test(allocator->cells().size() == 1); - - smtk::mesh::MeshSet mesh = - resource->createMesh(smtk::mesh::CellSet(resource, allocator->cells())); - - test(mesh.points().size() == nVerticesPerCell); -} - -void verify_moab_buffered_cell_allocator_validity(smtk::mesh::CellType cellType) -{ - // Allocate a cell of type , ensuring that the allocator returns the - // proper success and validity variables along the way. - - smtk::mesh::InterfacePtr iface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - smtk::mesh::BufferedCellAllocatorPtr allocator = resource->interface()->bufferedCellAllocator(); - test(!allocator->isValid()); - test(allocator->cells().empty()); - - // Try to add a coordinate before allocating for it (should fail) - test(!allocator->setCoordinate(0, cellPoints[cellType][0])); - test(!allocator->isValid()); - - // Flush before initializing anything (should fail) - test(!allocator->flush()); - test(!allocator->isValid()); - - // Grab the number of vertices for the cell type being tested - std::size_t nVerticesPerCell = - (cellType == smtk::mesh::Polygon ? 5 : smtk::mesh::verticesPerCell(cellType)); - - // Try to add a cell before allocating vertices (should fail) - std::vector connectivity(nVerticesPerCell); - for (std::size_t i = 0; i < nVerticesPerCell; i++) - { - connectivity[i] = static_cast(i); - } - test(!allocator->addCell(cellType, connectivity.data(), nVerticesPerCell)); - test(!allocator->isValid()); - - // Reserve the coordinates (should succeed) - test(allocator->reserveNumberOfCoordinates(nVerticesPerCell)); - test(allocator->isValid()); - - // Reserve coordinates again (should fail but not alter the validity of the - // allocator) - test(!allocator->reserveNumberOfCoordinates(nVerticesPerCell + 1)); - test(allocator->isValid()); - - // Flush with coordinates allocated but no cells added (should succeed) - test(allocator->flush()); - test(allocator->isValid()); - - // Add a cell before defining vertices (should succeed but not add anything - // until the allocator is flushed) - test(allocator->addCell(cellType, connectivity.data(), nVerticesPerCell)); - test(allocator->cells().empty()); - - // fill the vertices and remember the connectivity (should succeed) - for (std::size_t i = 0; i < nVerticesPerCell; i++) - { - test(allocator->setCoordinate(i, cellPoints[cellType][i])); - } - - // Finalize the addition of cells (should succeed) - test(allocator->flush()); - test(allocator->isValid()); - - test(allocator->cells().size() == 1); - - smtk::mesh::MeshSet mesh = - resource->createMesh(smtk::mesh::CellSet(resource, allocator->cells())); - - test(mesh.points().size() == nVerticesPerCell); -} - -void verify_moab_buffered_cell_allocator_cells() -{ - // Allocate one of each type of cell. - - smtk::mesh::InterfacePtr iface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - smtk::mesh::BufferedCellAllocatorPtr allocator = resource->interface()->bufferedCellAllocator(); - - // First, we must allocate the number of points needed for all of the cells. - std::size_t nVertices = 0; - - for (int cellType = smtk::mesh::Vertex; cellType != smtk::mesh::CellType_MAX; ++cellType) - { - std::size_t nVerticesPerCell = - (cellType == smtk::mesh::Polygon - ? 5 - : smtk::mesh::verticesPerCell(smtk::mesh::CellType(cellType))); - - nVertices += nVerticesPerCell; - } - - test(allocator->reserveNumberOfCoordinates(nVertices)); - - // Now that all of the points are allocated, we can incrementally add cells - // and fill the point values in any order we want. Note that it is definitely - // preferable to allocate like cells in sequence, however. - - std::size_t pointCounter = 0; - - for (int cellType = smtk::mesh::Vertex; cellType != smtk::mesh::CellType_MAX; ++cellType) - { - std::size_t nVerticesPerCell = - (cellType == smtk::mesh::Polygon - ? 5 - : smtk::mesh::verticesPerCell(smtk::mesh::CellType(cellType))); - std::vector connectivity(nVerticesPerCell); - - // Fill the vertices for each cell and record its connectivity. To prevent - // overlapping, we offset cell vertices by 2 * unit cell length. - for (std::size_t i = 0; i < nVerticesPerCell; i++) - { - double xyz[3]; - for (int j = 0; j < 3; j++) - { - xyz[j] = cellPoints[cellType][i][j]; - } - xyz[0] += 2. * cellType; - test(allocator->setCoordinate(pointCounter, xyz)); - connectivity[i] = static_cast(pointCounter); - pointCounter++; - } - test(allocator->addCell(smtk::mesh::CellType(cellType), connectivity.data(), nVerticesPerCell)); - } - - test(allocator->flush()); - - test(allocator->cells().size() == 9); - - smtk::mesh::MeshSet mesh = - resource->createMesh(smtk::mesh::CellSet(resource, allocator->cells())); - - test(mesh.points().size() == nVertices); -} -} // namespace - -int UnitTestBufferedCellAllocator(int /*unused*/, char** const /*unused*/) -{ - verify_moab_buffered_cell_allocator_creation(); - verify_json_buffered_cell_allocator_creation(); - - for (int cellType = smtk::mesh::Vertex; cellType != smtk::mesh::CellType_MAX; ++cellType) - { - smtk::mesh::CellType ct = smtk::mesh::CellType(cellType); - verify_moab_buffered_cell_allocator_validity(ct); - verify_moab_buffered_cell_allocator_cell(ct); - } - - verify_moab_buffered_cell_allocator_cells(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestCellField.cxx b/smtk/mesh/testing/cxx/UnitTestCellField.cxx deleted file mode 100644 index 653dfb86d542286dc96016303af369ce5b18d9fd..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestCellField.cxx +++ /dev/null @@ -1,375 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" -#include "smtk/io/ReadMesh.h" -#include "smtk/io/WriteMesh.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -#include - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -smtk::mesh::ResourcePtr load_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/2d/twoMeshes.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - return mr; -} - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -void verify_partial_cellfields() -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - smtk::mesh::MeshSet mesh = mr->meshes(smtk::mesh::Dims2); - smtk::mesh::MeshSet one = mesh.subset(0); - smtk::mesh::MeshSet two = mesh.subset(1); - - std::vector fieldValues(mesh.cells().size()); - for (std::size_t i = 0; i < fieldValues.size(); i++) - { - fieldValues[i] = static_cast(i); - } - mesh.createCellField("field data", 1, smtk::mesh::FieldType::Double, fieldValues.data()); - - std::vector fieldValuesForCellField1(one.cells().size() * 2); - for (std::size_t i = 0; i < fieldValuesForCellField1.size(); i++) - { - fieldValuesForCellField1[i] = static_cast(i); - } - one.createCellField( - "field data for set 1", 2, smtk::mesh::FieldType::Double, fieldValuesForCellField1.data()); - - std::vector fieldValuesForCellField2(two.cells().size() * 3); - for (std::size_t i = 0; i < fieldValuesForCellField2.size(); i++) - { - fieldValuesForCellField2[i] = static_cast(i); - } - two.createCellField( - "field data for set 2", 3, smtk::mesh::FieldType::Double, fieldValuesForCellField2.data()); - - { - std::set cellfields = mesh.cellFields(); - for (const auto& cellfield : cellfields) - { - std::cout << "\"" << cellfield.name() << "\" " << cellfield.dimension() << " " - << cellfield.size() << std::endl; - std::vector retrievedFieldValues(cellfield.size() * cellfield.dimension(), -1.); - cellfield.get(retrievedFieldValues.data()); - for (std::size_t i = 0; i < retrievedFieldValues.size(); i++) - { - test(fieldValues[i] == retrievedFieldValues[i]); - } - } - } - - std::vector cellfieldnames; - { - std::set cellfields = one.cellFields(); - for (const auto& cellfield : cellfields) - { - std::cout << "\"" << cellfield.name() << "\" " << cellfield.dimension() << std::endl; - cellfieldnames.push_back(cellfield.name()); - std::vector retrievedFieldValues(one.cells().size() * cellfield.dimension(), -1.); - cellfield.get(retrievedFieldValues.data()); - for (std::size_t i = 0; i < retrievedFieldValues.size(); i++) - { - test(fieldValuesForCellField1[i] == retrievedFieldValues[i]); - } - } - - for (auto& cellfieldname : cellfieldnames) - { - smtk::mesh::CellField cellfield(one, cellfieldname); - test(one.removeCellField(cellfield)); - test(cellfield.size() == 0); - test(cellfield.dimension() == 0); - } - } - - { - std::set cellfields = one.cellFields(); - test(cellfields.empty()); - } - - { - std::set cellfields = two.cellFields(); - test(cellfields.size() == 2); - for (const auto& cellfield : cellfields) - { - std::cout << "\"" << cellfield.name() << "\" " << cellfield.dimension() << " " - << cellfield.size() << std::endl; - } - } -} - -void verify_duplicate_cellfields() -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - smtk::mesh::MeshSet mesh = mr->meshes(smtk::mesh::Dims2); - smtk::mesh::MeshSet one = mesh.subset(0); - smtk::mesh::MeshSet two = mesh.subset(1); - - // Construct a cell field of dimension 1 for all of . - std::vector fieldValues(mesh.cells().size()); - for (std::size_t i = 0; i < fieldValues.size(); i++) - { - fieldValues[i] = static_cast(i); - } - auto cf = - mesh.createCellField("field data", 1, smtk::mesh::FieldType::Double, fieldValues.data()); - test(cf.isValid()); - - // Try to construct a cell field with the same dimension and name for a subset - // of (should succeed and change the values of the field for the cells - // in ). - std::vector fieldValuesForCellField1(one.cells().size()); - for (std::size_t i = 0; i < fieldValuesForCellField1.size(); i++) - { - fieldValuesForCellField1[i] = static_cast(i) * 2; - } - auto cf1 = one.createCellField( - "field data", 1, smtk::mesh::FieldType::Double, fieldValuesForCellField1.data()); - test(cf1.isValid()); - - // Verify that the field values have been updated to the new values. - { - std::set cellfields = mesh.cellFields(); - for (const auto& cellfield : cellfields) - { - std::cout << "\"" << cellfield.name() << "\" " << cellfield.dimension() << " " - << cellfield.size() << std::endl; - std::vector retrievedFieldValues(cellfield.size() * cellfield.dimension(), -1.); - cellfield.get(retrievedFieldValues.data()); - for (std::size_t i = 0; i < retrievedFieldValues.size(); i++) - { - if (i < fieldValuesForCellField1.size()) - { - test(fieldValuesForCellField1[i] == retrievedFieldValues[i]); - } - else - { - test(fieldValues[i] == retrievedFieldValues[i]); - } - } - } - } - - // Try to construct a cell field with a different dimension and the same name - // for a subset of (should fail). - std::vector fieldValuesForCellField2(two.cells().size() * 3); - for (std::size_t i = 0; i < fieldValuesForCellField2.size(); i++) - { - fieldValuesForCellField2[i] = static_cast(i); - } - auto cf2 = two.createCellField( - "field data", 3, smtk::mesh::FieldType::Double, fieldValuesForCellField2.data()); - test(!cf2.isValid()); - - // Try again, but change the name (should succeed). - cf2 = two.createCellField( - "field data 2", 3, smtk::mesh::FieldType::Double, fieldValuesForCellField2.data()); - test(cf2.isValid()); -} - -class SetCellData : public smtk::mesh::CellForEach -{ -private: - const std::function& m_dataGenerator; - smtk::mesh::CellField& m_cellfield; - -public: - SetCellData( - const std::function& dataGenerator, - smtk::mesh::CellField& ds) - : smtk::mesh::CellForEach(true) - , m_dataGenerator(dataGenerator) - , m_cellfield(ds) - { - } - - void forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType /*cellType*/, int numPts) - override - { - double xyz[3] = { 0., 0., 0. }; - for (int i = 0; i < numPts; i++) - { - xyz[0] += this->coordinates()[i * 3 + 0]; - xyz[1] += this->coordinates()[i * 3 + 1]; - xyz[2] += this->coordinates()[i * 3 + 2]; - } - for (int i = 0; i < 3; i++) - { - xyz[i] /= numPts; - } - double value = m_dataGenerator(xyz[0], xyz[1], xyz[2]); - smtk::mesh::HandleRange range; - range.insert(cellId); - m_cellfield.set(range, &value); - } -}; - -class ValidateCellData : public smtk::mesh::CellForEach -{ -private: - const std::function& m_dataGenerator; - smtk::mesh::CellField& m_cellfield; - const double EPSILON = 1.e-14; - -public: - ValidateCellData( - const std::function& dataGenerator, - smtk::mesh::CellField& ds) - : smtk::mesh::CellForEach(true) - , m_dataGenerator(dataGenerator) - , m_cellfield(ds) - { - } - - void forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType /*cellType*/, int numPts) - override - { - double xyz[3] = { 0., 0., 0. }; - for (int i = 0; i < numPts; i++) - { - xyz[0] += this->coordinates()[i * 3 + 0]; - xyz[1] += this->coordinates()[i * 3 + 1]; - xyz[2] += this->coordinates()[i * 3 + 2]; - } - for (int i = 0; i < 3; i++) - { - xyz[i] /= numPts; - } - double expectedValue = m_dataGenerator(xyz[0], xyz[1], xyz[2]); - smtk::mesh::HandleRange range; - range.insert(cellId); - double value = 0.; - m_cellfield.get(range, &value); - - test(std::abs(expectedValue - value) < EPSILON); - } -}; - -void verify_incremental_data_assignment() -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - smtk::mesh::MeshSet mesh = mr->meshes(); - std::function euclideanDistance = - [](double x, double y, double z) { return std::sqrt(x * x + y * y + z * z); }; - smtk::mesh::CellField distanceCellField = - mesh.createCellField("euclidean distance", 1, smtk::mesh::FieldType::Double); - - { - SetCellData setCellData(euclideanDistance, distanceCellField); - smtk::mesh::for_each(mesh.cells(), setCellData); - } - - { - ValidateCellData validateCellData(euclideanDistance, distanceCellField); - smtk::mesh::for_each(mesh.cells(), validateCellData); - } -} - -void verify_cellfield_persistency() -{ - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - std::vector fieldValues; - { - smtk::mesh::ResourcePtr mr = load_mesh(); - - smtk::mesh::MeshSet mesh = mr->meshes(smtk::mesh::Dims2); - smtk::mesh::MeshSet one = mesh.subset(0); - - fieldValues.resize(one.cells().size()); - for (std::size_t i = 0; i < fieldValues.size(); i++) - { - fieldValues[i] = static_cast(i); - } - one.createCellField("field data", 1, smtk::mesh::FieldType::Double, fieldValues.data()); - - //write out the mesh. - smtk::io::WriteMesh write; - bool result = write(write_path, mr); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out a valid hdf5 resource"); - } - } - - { - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(write_path, mr); - - //remove the file from disk - cleanup(write_path); - - { - smtk::mesh::MeshSet mesh = mr->meshes(smtk::mesh::Dims2); - smtk::mesh::MeshSet two = mesh.subset(0); - - smtk::mesh::CellField cellfield = *two.cellFields().begin(); - std::vector retrievedFieldValues(cellfield.size() * cellfield.dimension(), 0.); - cellfield.get(retrievedFieldValues.data()); - - test(retrievedFieldValues.size() == fieldValues.size()); - - for (std::size_t i = 0; i < retrievedFieldValues.size(); i++) - { - test(fieldValues[i] == retrievedFieldValues[i]); - } - } - } -} -} // namespace - -int UnitTestCellField(int /*unused*/, char** const /*unused*/) -{ - verify_partial_cellfields(); - verify_duplicate_cellfields(); - verify_incremental_data_assignment(); - verify_cellfield_persistency(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestCellSet.cxx b/smtk/mesh/testing/cxx/UnitTestCellSet.cxx deleted file mode 100644 index 39bc1d4e3400d585440792a2a4e3e28b11f3ebb0..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestCellSet.cxx +++ /dev/null @@ -1,635 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -smtk::mesh::ResourcePtr load_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - return mr; -} - -void verify_constructors(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet all_meshes = mr->meshes(); - - smtk::mesh::CellSet all_cells_from_ms = all_meshes.cells(); - const smtk::mesh::CellSet& copy_of_all_cells(all_cells_from_ms); - - test(!all_cells_from_ms.is_empty()); - test(all_cells_from_ms.size() != 0); - test(all_cells_from_ms.size() == copy_of_all_cells.size()); - - smtk::mesh::CellSet zeroDim = mr->cells(smtk::mesh::Dims0); - smtk::mesh::CellSet equalToZeroDim = copy_of_all_cells; - equalToZeroDim = zeroDim; //test assignment operator - test(equalToZeroDim.size() == zeroDim.size()); - test(!equalToZeroDim.is_empty()); -} - -void verify_subsets(const smtk::mesh::ResourcePtr& mr) -{ - std::vector mesh_names = mr->meshNames(); - - test(!mesh_names.empty(), "There are no meshes in the resource."); - - smtk::mesh::MeshSet ms = mr->meshes(mesh_names[0]); - smtk::mesh::CellSet ps = ms.cells(); - - smtk::mesh::HandleRange range; - - std::set set; - std::vector vec; - - for (smtk::mesh::HandleRange::iterator iter = ps.range().begin(); iter != ps.range().end(); - ++iter) - { - range.insert(smtk::mesh::HandleInterval(iter->lower(), iter->upper() - 1)); - for (smtk::mesh::Handle i = iter->lower(); i < iter->upper(); ++i) - { - set.insert(i); - vec.push_back(i); - } - } - - smtk::mesh::CellSet ps2(mr, range); - smtk::mesh::CellSet ps3(mr, set); - smtk::mesh::CellSet ps4(mr, vec); - smtk::mesh::CellSet ps5(std::const_pointer_cast(mr), range); - - test(ps != ps2); - test(ps2 == ps3); - test(ps3 == ps4); - test(ps4 == ps5); -} - -void verify_empty(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet no_mesh = mr->meshes("bad name string"); - - smtk::mesh::CellSet no_cells_a = no_mesh.cells(); - smtk::mesh::CellSet no_cells_b = no_mesh.cells(smtk::mesh::Hexahedron); - smtk::mesh::CellSet no_cells_c = no_mesh.cells(smtk::mesh::Dims2); - smtk::mesh::CellSet no_cells_d = no_mesh.cells(smtk::mesh::CellTypes()); - - test(no_cells_a.is_empty()); - test(no_cells_b.is_empty()); - test(no_cells_c.is_empty()); - test(no_cells_d.is_empty()); - - test(no_cells_a.size() == 0); - test(no_cells_b.size() == 0); - test(no_cells_c.size() == 0); - test(no_cells_d.size() == 0); -} - -void verify_comparisons(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::CellSet zeroDim = mr->cells(smtk::mesh::Dims0); - smtk::mesh::CellSet oneDim = mr->cells(smtk::mesh::Dims1); - - test(zeroDim == zeroDim); - test(!(zeroDim != zeroDim)); - test(oneDim != zeroDim); - test(!(oneDim == zeroDim)); - - const smtk::mesh::CellSet& zeroDim_a(zeroDim); - test(zeroDim_a == zeroDim); - - smtk::mesh::CellSet oneDim_b = zeroDim_a; - oneDim_b = oneDim; //test assignment operator - test(oneDim_b == oneDim); - - test(zeroDim_a != oneDim_b); -} - -void verify_typeset(const smtk::mesh::ResourcePtr& mr) -{ - //verify that empty cell set has empty type set - { - smtk::mesh::CellTypes no_cell_types; - smtk::mesh::CellSet emptyCellSet = mr->cells(no_cell_types); - smtk::mesh::TypeSet noTypes = emptyCellSet.types(); - - test(noTypes.cellTypes() == no_cell_types); - test(!noTypes.hasMeshes()); - test(!noTypes.hasCells()); - } - - //verify that if we get all cells from the resource the type set is correct - { - smtk::mesh::TypeSet all_types = mr->types(); - smtk::mesh::CellSet allCells = mr->cells(all_types.cellTypes()); - smtk::mesh::TypeSet allCellsTypes = allCells.types(); - - test(allCellsTypes.cellTypes() == all_types.cellTypes()); - test(!allCellsTypes.hasMeshes()); - test(allCellsTypes.hasCells()); - } - - //verify typeset work on dimension cell queries and cell type queries - //is handled by the methods verify_cell_count_by_dim and - //verify_cell_count_by_type -} - -void verify_all_cells(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet all_meshes = mr->meshes(); - smtk::mesh::CellSet all_cells_from_collec = mr->cells(); - smtk::mesh::CellSet all_cells_from_ms = all_meshes.cells(); - - test(!all_cells_from_collec.is_empty()); - test(!all_cells_from_ms.is_empty()); - - test(all_cells_from_collec.size() != 0); - test(all_cells_from_ms.size() != 0); - - test(all_cells_from_collec.size() == all_cells_from_ms.size()); - test(all_cells_from_collec == all_cells_from_ms); -} - -void verify_cell_count_by_type(smtk::mesh::MeshSet ms) -{ - //verify that all cells size is equal to the vector of cellsets where - //each element is a cell type. - std::vector all_cell_types; - smtk::mesh::TypeSet all_typeset; - - for (int i = 0; i < smtk::mesh::CellType_MAX; ++i) - { - smtk::mesh::CellType cellType = static_cast(i); - smtk::mesh::CellSet cells = ms.cells(cellType); - all_cell_types.push_back(cells); - - //verify that the cells typeset is correct - smtk::mesh::TypeSet types = cells.types(); - test(!types.hasMeshes()); - test(types.hasCells() == (!cells.is_empty())); - if (!cells.is_empty()) - { //only do these tests if we have anything in the cellset - test(types.hasCell(cellType)); - } - all_typeset += types; - } - - std::size_t sum = 0; - for (std::size_t i = 0; i < all_cell_types.size(); ++i) - { - sum += all_cell_types[i].size(); - } - test(ms.cells().size() == sum); - test(ms.types().cellTypes() == all_typeset.cellTypes()); -} - -void verify_cell_count_by_dim(smtk::mesh::MeshSet ms) -{ - //verify that all cells size is equal to the vector of cellsets where - //each element is a cell type. - std::vector all_cell_types; - smtk::mesh::TypeSet all_typeset; - - for (int i = 0; i < smtk::mesh::DimensionType_MAX; ++i) - { - smtk::mesh::DimensionType dimType = static_cast(i); - smtk::mesh::CellSet cells = ms.cells(dimType); - all_cell_types.push_back(cells); - - //verify that the cells typeset is correct - smtk::mesh::TypeSet types = cells.types(); - test(!types.hasMeshes()); - test(types.hasCells() == (!cells.is_empty())); - if (!cells.is_empty()) - { //only do these tests if we have anything in the cellset - test(types.hasDimension(dimType)); - } - all_typeset += types; - } - - std::size_t sum = 0; - for (std::size_t i = 0; i < all_cell_types.size(); ++i) - { - sum += all_cell_types[i].size(); - } - test(ms.cells().size() == sum); - test(ms.types().cellTypes() == all_typeset.cellTypes()); -} - -void verify_cells_by_type(const smtk::mesh::ResourcePtr& mr) -{ - //1. verify that all cells size is equal to the vector of cellsets where - //each element is a cell type. - smtk::mesh::CellSet all_cells = mr->cells(); - smtk::mesh::MeshSet all_meshes = mr->meshes(); - - std::vector all_cell_types; - smtk::mesh::CellSet all_cells_appended = all_meshes.cells(smtk::mesh::Vertex); - for (int i = 0; i < smtk::mesh::CellType_MAX; ++i) - { - smtk::mesh::CellType cellType = static_cast(i); - all_cell_types.push_back(mr->cells(cellType)); - all_cells_appended.append(all_meshes.cells(cellType)); - } - test(all_cells_appended == all_cells); - - std::size_t sum = 0; - for (std::size_t i = 0; i < all_cell_types.size(); ++i) - { - sum += all_cell_types[i].size(); - - //should be a no-op verifies append doesn't double add - all_cells_appended.append(all_cell_types[i]); - } - - test(all_cells.size() == sum); - test(all_cells_appended == all_cells); - - //2. Verify that for each cell type in associated types the related index - //in the array has cells - - smtk::mesh::TypeSet types = all_cells.types(); - for (int i = 0; i < smtk::mesh::CellType_MAX; ++i) - { - //verify that if the resource has a cell, we also return - smtk::mesh::CellType ct = static_cast(i); - test(types.hasCell(ct) != all_cell_types[i].is_empty()); - } - - //now verify certain mesh subset - verify_cell_count_by_type(mr->meshes()); - verify_cell_count_by_dim(mr->meshes()); - - verify_cell_count_by_type(mr->meshes(smtk::mesh::Dims1)); - verify_cell_count_by_type(mr->meshes(smtk::mesh::Dims2)); - verify_cell_count_by_type(mr->meshes(smtk::mesh::Dims3)); - - verify_cell_count_by_dim(mr->meshes(smtk::mesh::Dims1)); - verify_cell_count_by_dim(mr->meshes(smtk::mesh::Dims2)); - verify_cell_count_by_dim(mr->meshes(smtk::mesh::Dims3)); -} - -void verify_cells_by_types(const smtk::mesh::ResourcePtr& mr) -{ - - //verify that empty typeset returns nothing - smtk::mesh::CellTypes no_cell_types; - smtk::mesh::CellSet no_associatedCells = mr->cells(no_cell_types); - test(no_associatedCells.is_empty()); //should be empty - - //1. verify that when we query based on types everything works properly - //when from a Resource - smtk::mesh::TypeSet types = mr->types(); - smtk::mesh::CellSet associatedCells = mr->cells(types.cellTypes()); - test(!associatedCells.is_empty()); //can't be false - - //verify cellTypes returns the same number of cells as asking for all cells - test(associatedCells.size() == mr->cells().size()); - test(associatedCells == mr->cells()); -} - -void verify_cells_by_dim(const smtk::mesh::ResourcePtr& mr) -{ - - //simple verification that the types are the same - smtk::mesh::MeshSet all_meshes = mr->meshes(); - - smtk::mesh::CellSet zeroDim = mr->cells(smtk::mesh::Dims0); - smtk::mesh::CellSet oneDim = mr->cells(smtk::mesh::Dims1); - smtk::mesh::CellSet twoDim = mr->cells(smtk::mesh::Dims2); - smtk::mesh::CellSet threeDim = mr->cells(smtk::mesh::Dims3); - - //fm = from meshset - smtk::mesh::CellSet fm_zeroDim = all_meshes.cells(smtk::mesh::Dims0); - smtk::mesh::CellSet fm_oneDim = all_meshes.cells(smtk::mesh::Dims1); - smtk::mesh::CellSet fm_twoDim = all_meshes.cells(smtk::mesh::Dims2); - smtk::mesh::CellSet fm_threeDim = all_meshes.cells(smtk::mesh::Dims3); - - test(zeroDim == fm_zeroDim); - test(oneDim == fm_oneDim); - test(twoDim == fm_twoDim); - test(threeDim == fm_threeDim); -} - -void verify_cellset_intersect(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet no_meshes = mr->meshes("bad name string"); - smtk::mesh::MeshSet all_meshes = mr->meshes(); - smtk::mesh::CellSet all_cells = mr->cells(); - - { //intersection of self should produce self - smtk::mesh::CellSet result = smtk::mesh::set_intersect(all_cells, all_cells); - test(result == all_cells, "Intersection of self should produce self"); - } - - { //intersection with nothing should produce nothing - smtk::mesh::CellSet no_cells = no_meshes.cells(); - smtk::mesh::CellSet result = smtk::mesh::set_intersect(all_cells, no_cells); - test(result == no_cells, "Intersection with nothing should produce nothing"); - } - - //construct empty meshset - smtk::mesh::CellSet all_dims = no_meshes.cells(); - for (int i = 0; i < smtk::mesh::DimensionType_MAX; ++i) - { - smtk::mesh::DimensionType d(static_cast(i)); - smtk::mesh::CellSet cellsWithDim = all_meshes.cells(d); - - //all_dims shouldn't already hold anything from cellsWithDim - smtk::mesh::CellSet intersect_result = smtk::mesh::set_intersect(all_dims, cellsWithDim); - test(intersect_result.size() == 0); - - all_dims.append(cellsWithDim); - } - - //verify that the size of the intersection + size of difference - //equal size - smtk::mesh::CellSet intersect_result = smtk::mesh::set_intersect(all_cells, all_dims); - - smtk::mesh::CellSet difference_result = smtk::mesh::set_difference(all_cells, all_dims); - - const std::size_t summed_size = intersect_result.size() + difference_result.size(); - test( - summed_size == all_cells.size(), "Size of intersect + difference needs to be the same as total\ - number of unique items"); -} - -void verify_cellset_union(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet all_meshes = mr->meshes(); - smtk::mesh::CellSet all_cells = mr->cells(); - - { //union with self produces self - smtk::mesh::CellSet result = smtk::mesh::set_union(all_cells, all_cells); - test(result == all_cells, "Union of self should produce self"); - } - - { //union with nothing should produce self - smtk::mesh::MeshSet no_meshes = mr->meshes("bad name string"); - smtk::mesh::CellSet no_cells = no_meshes.cells(); - smtk::mesh::CellSet result = smtk::mesh::set_union(all_cells, no_cells); - test(result == all_cells, "Union with nothing should produce self"); - } - - //construct empty meshset(s) - smtk::mesh::CellSet all_dims = mr->meshes("bad name string").cells(); - smtk::mesh::CellSet append_output = all_dims; - //verify that append and union produce the same result - for (int i = 0; i < smtk::mesh::DimensionType_MAX; ++i) - { - smtk::mesh::DimensionType d(static_cast(i)); - all_dims = smtk::mesh::set_union(all_dims, mr->cells(d)); - append_output.append(all_meshes.cells(d)); - } - - test(all_dims == append_output, "Result of union should be the same as append"); - - { - smtk::mesh::CellSet result = smtk::mesh::set_union(all_cells, all_dims); - smtk::mesh::CellSet result2 = all_cells; - result2.append(all_dims); - test(result == result2); - } -} - -void verify_cellset_subtract(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::CellSet all_cells = mr->cells(); - - { //subtract of self should produce empty - smtk::mesh::CellSet result = smtk::mesh::set_difference(all_cells, all_cells); - test(result.size() == 0, "Subtraction of self should produce nothing"); - test(result != all_cells, "Subtraction of self should produce nothing"); - } - - { //subtract with nothing should produce self - smtk::mesh::CellSet no_cells = mr->meshes("bad name string").cells(); - smtk::mesh::CellSet result = smtk::mesh::set_difference(all_cells, no_cells); - test(result == all_cells, "Subtraction with nothing should produce self"); - } - - { //subtract with something from nothing should produce nothing - smtk::mesh::CellSet no_cells = mr->meshes("bad name string").cells(); - smtk::mesh::CellSet result = smtk::mesh::set_difference(no_cells, all_cells); - test(result == no_cells, "Subtraction of something from nothing should nothing"); - } - - //construct empty meshset - smtk::mesh::CellSet all_dims = mr->meshes("bad name string").cells(); - for (int i = 0; i < smtk::mesh::DimensionType_MAX; ++i) - { - smtk::mesh::DimensionType d(static_cast(i)); - all_dims.append(mr->cells(d)); - } - - std::size_t size_difference = all_cells.size() - all_dims.size(); - smtk::mesh::CellSet non_dim_meshes = smtk::mesh::set_difference(all_cells, all_dims); - test(non_dim_meshes.size() == size_difference, "subtract of two meshes produced wrong size"); -} - -void verify_cellset_point_intersect(const smtk::mesh::ResourcePtr& mr) -{ - using namespace smtk::mesh; - - smtk::mesh::CellSet twoDim = mr->cells(smtk::mesh::Dims2); - smtk::mesh::CellSet threeDim = mr->cells(smtk::mesh::Dims3); - - //First test partial containment - { - smtk::mesh::CellSet result = - smtk::mesh::point_intersect(threeDim, threeDim, PartiallyContained); - test(result == threeDim, "intersection of self should produce self "); - } - - { - smtk::mesh::CellSet result = smtk::mesh::point_intersect(threeDim, twoDim, PartiallyContained); - test(result.size() != 0, "we should have partial containment between 2d and 3d"); - } - - { - smtk::mesh::CellSet result = smtk::mesh::point_intersect(twoDim, threeDim, PartiallyContained); - test(result.size() != 0, "we should have partial containment between 3d and 2d"); - } - - //Next test full containment - { - smtk::mesh::CellSet result = smtk::mesh::point_intersect(threeDim, threeDim, FullyContained); - test(result == threeDim, "intersection of self should produce self "); - } - - { - smtk::mesh::CellSet result = smtk::mesh::point_intersect(threeDim, twoDim, FullyContained); - test(result.size() != 0, "we should have partial containment between 2d and 3d"); - } - - { - smtk::mesh::CellSet result = smtk::mesh::point_intersect(twoDim, threeDim, FullyContained); - test(result.size() == 0, "we should have no threeDim elements fully covered by 2d"); - } -} - -void verify_cellset_point_difference(const smtk::mesh::ResourcePtr& mr) -{ - using namespace smtk::mesh; - - smtk::mesh::CellSet twoDim = mr->cells(smtk::mesh::Dims2); - smtk::mesh::CellSet threeDim = mr->cells(smtk::mesh::Dims3); - - //First test partial containment - { - smtk::mesh::CellSet result = - smtk::mesh::point_difference(threeDim, threeDim, PartiallyContained); - test(result.size() == 0, "difference of self should produce nothing "); - } - - { - smtk::mesh::CellSet result = smtk::mesh::point_difference(threeDim, twoDim, PartiallyContained); - test(result.size() == 0, "all points in the 2d cells should be used by a 3d cell"); - } - - { - smtk::mesh::CellSet result = smtk::mesh::point_difference(twoDim, threeDim, PartiallyContained); - test(result.size() != 0, "every 3d cell has a point used by a 2d cell?"); - } - - //Next test full containment - { - smtk::mesh::CellSet result = smtk::mesh::point_difference(threeDim, threeDim, FullyContained); - test(result.size() == 0, "difference of self should produce nothing "); - } - - { - smtk::mesh::CellSet result = smtk::mesh::point_difference(threeDim, twoDim, FullyContained); - test(result.size() == 0, "all points in the 2d cells should be used by a 3d cell"); - } - - { - smtk::mesh::CellSet result = smtk::mesh::point_difference(twoDim, threeDim, FullyContained); - test(result.size() != 0, "not all points in the 3d cells should be used by 2d cell's"); - } -} - -class CountCells : public smtk::mesh::CellForEach -{ - //keep the range of points we have seen so we can verify that we - //seen all the cells that we expect to be given - smtk::mesh::HandleRange pointsSeen; - - //keep the range of cells we have seen so we can verify that we - //seen all the cells that we expect to be given - smtk::mesh::HandleRange cellsSeen; - - //keep track of all the cell types we have been passed - smtk::mesh::CellTypes cellTypesSeen; - - //keep a physical count of number of cells so that we can verify we - //don't iterate over a cell more than once - int numCellsVisited{ 0 }; - - //total number of points seen, relates to the total size of the connectivity - //array for this cellset - int numPointsSeen{ 0 }; - -public: - CountCells() = default; - - void forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType cellType, int numPts) override - { - this->cellsSeen.insert(cellId); - this->numCellsVisited++; - this->numPointsSeen += numPts; - this->pointsSeen.insert( - smtk::mesh::HandleInterval(*this->pointIds(), *(this->pointIds() + numPts - 1))); - this->cellTypesSeen[static_cast(cellType)] = true; - } - - [[nodiscard]] int numberOCellsVisited() const { return numCellsVisited; } - [[nodiscard]] int numberOPointsSeen() const { return numPointsSeen; } - - [[nodiscard]] smtk::mesh::HandleRange points() const { return pointsSeen; } - [[nodiscard]] smtk::mesh::HandleRange cells() const { return cellsSeen; } - - [[nodiscard]] smtk::mesh::CellTypes cellTypes() const { return cellTypesSeen; } -}; - -void verify_cellset_for_each(const smtk::mesh::ResourcePtr& mr) -{ - CountCells functor; - smtk::mesh::MeshSet volMeshes = mr->meshes(smtk::mesh::Dims3); - smtk::mesh::for_each(volMeshes.cells(), functor); - - test(static_cast(functor.numberOCellsVisited()) == volMeshes.cells().size()); - test( - static_cast(functor.numberOPointsSeen()) == volMeshes.pointConnectivity().size()); - - smtk::mesh::PointConnectivity pc = volMeshes.pointConnectivity(); - pc.initCellTraversal(); - - int numPts; - int numPointsSeen = 0; - smtk::mesh::HandleRange pointsFromConnectivity; - const smtk::mesh::Handle* points; - while (pc.fetchNextCell(numPts, points)) - { - numPointsSeen += numPts; - pointsFromConnectivity.insert(smtk::mesh::HandleInterval(*points, *(points + numPts - 1))); - } - - //verify that point connectivity iteration and cell for_each visit - //all the same cells, and we also see all the points - test(volMeshes.cells() == smtk::mesh::CellSet(mr, functor.cells())); - test(pointsFromConnectivity == functor.points()); - test(numPointsSeen == functor.numberOPointsSeen()); - - //verify that the cell types that are reported are only 3D cells. - smtk::mesh::TypeSet typeSet(functor.cellTypes(), false, true); - test(!typeSet.hasDimension(smtk::mesh::Dims1)); - test(!typeSet.hasDimension(smtk::mesh::Dims2)); - test(typeSet.hasDimension(smtk::mesh::Dims3)); -} -} // namespace - -int UnitTestCellSet(int /*unused*/, char** const /*unused*/) -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - verify_constructors(mr); - verify_subsets(mr); - verify_empty(mr); - verify_comparisons(mr); - verify_typeset(mr); - verify_all_cells(mr); - verify_cells_by_type(mr); - verify_cells_by_types(mr); - verify_cells_by_dim(mr); - verify_cellset_intersect(mr); - verify_cellset_union(mr); - verify_cellset_subtract(mr); - - verify_cellset_point_intersect(mr); - verify_cellset_point_difference(mr); - - verify_cellset_for_each(mr); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestCellTypes.cxx b/smtk/mesh/testing/cxx/UnitTestCellTypes.cxx deleted file mode 100644 index c42a3a4bb1adcb8fbafd0fb68d4c893167166132..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestCellTypes.cxx +++ /dev/null @@ -1,206 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/CellTraits.h" -#include "smtk/mesh/core/CellTypes.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "smtk/common/CompilerInformation.h" - -#if defined(SMTK_CLANG) || (defined(__GNUC__) && (__GNUC__ > 5 && __GNUC_MINOR__ > 0)) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wtautological-compare" -#endif - -namespace -{ - -struct verify_cell_attributes -{ - template - void operator()(CellType type) - { - (void)type; - smtk::mesh::CellTraits traits; - this->verify(traits); - } - - void operator()(smtk::mesh::CellType cellEnum) - { - //this is the issue transferring from an enum type to a concrete - //type by using a macroed switch statement - switch (cellEnum) - { - smtkMeshCellEnumToTypeMacro(this->verify(CellTraits())); - case smtk::mesh::CellType_MAX: - break; - } - } - - void verify(smtk::mesh::CellTraits traits) - { - // XXX(clang-tidy): Use `traits` to access the static data for test consistency. - // NOLINTNEXTLINE(readability-static-accessed-through-instance) - test(traits.NUM_VERTICES == 8, "CellHexahedron Trait reports wrong number of points"); - test( - traits.fixedPointSize() == smtk::mesh::CellFixedPointNumberTag::Type, - "CellHexahedron Traits reports fixedPointSize() incorrectly"); - test(traits.dimension() == 3, "CellHexahedron Trait reports wrong dimension"); - - //now verify the enum logic is correct - typedef smtk::mesh::CellTraits TraitsType; - test( - TraitsType::CellType::CellEnum == smtk::mesh::CellHexahedron::CellEnum, - "CellEnum from the traits isn't correct"); - } - void verify(smtk::mesh::CellTraits traits) - { - // XXX(clang-tidy): Use `traits` to access the static data for test consistency. - // NOLINTNEXTLINE(readability-static-accessed-through-instance) - test(traits.NUM_VERTICES == 2, "CellLine Trait reports wrong number of points"); - test( - traits.fixedPointSize() == smtk::mesh::CellFixedPointNumberTag::Type, - "CellLine Traits reports fixedPointSize() incorrectly"); - test(traits.dimension() == 1, "CellLine Trait reports wrong dimension"); - - //now verify the enum logic is correct - typedef smtk::mesh::CellTraits TraitsType; - test( - TraitsType::CellType::CellEnum == smtk::mesh::CellLine::CellEnum, - "CellEnum from the traits isn't correct"); - } - void verify(smtk::mesh::CellTraits traits) - { - // XXX(clang-tidy): Use `traits` to access the static data for test consistency. - // NOLINTNEXTLINE(readability-static-accessed-through-instance) - test(traits.NUM_VERTICES == -1, "CellPolygon Trait reports wrong number of points"); - test( - traits.fixedPointSize() != smtk::mesh::CellFixedPointNumberTag::Type, - "CellPolygon Traits reports fixedPointSize() incorrectly"); - test(traits.dimension() == 2, "CellPolygon Trait reports wrong dimension"); - - //now verify the enum logic is correct - typedef smtk::mesh::CellTraits TraitsType; - test( - TraitsType::CellType::CellEnum == smtk::mesh::CellPolygon::CellEnum, - "CellEnum from the traits isn't correct"); - } - void verify(smtk::mesh::CellTraits traits) - { - // XXX(clang-tidy): Use `traits` to access the static data for test consistency. - // NOLINTNEXTLINE(readability-static-accessed-through-instance) - test(traits.NUM_VERTICES == 5, "CellPyramid Trait reports wrong number of points"); - test( - traits.fixedPointSize() == smtk::mesh::CellFixedPointNumberTag::Type, - "CellPyramid Traits reports fixedPointSize() incorrectly"); - test(traits.dimension() == 3, "CellPyramid Trait reports wrong dimension"); - - //now verify the enum logic is correct - typedef smtk::mesh::CellTraits TraitsType; - test( - TraitsType::CellType::CellEnum == smtk::mesh::CellPyramid::CellEnum, - "CellEnum from the traits isn't correct"); - } - void verify(smtk::mesh::CellTraits traits) - { - // XXX(clang-tidy): Use `traits` to access the static data for test consistency. - // NOLINTNEXTLINE(readability-static-accessed-through-instance) - test(traits.NUM_VERTICES == 4, "CellQuad Trait reports wrong number of points"); - test( - traits.fixedPointSize() == smtk::mesh::CellFixedPointNumberTag::Type, - "CellQuad Traits reports fixedPointSize() incorrectly"); - test(traits.dimension() == 2, "CellQuad Trait reports wrong dimension"); - - //now verify the enum logic is correct - typedef smtk::mesh::CellTraits TraitsType; - test( - TraitsType::CellType::CellEnum == smtk::mesh::CellQuad::CellEnum, - "CellEnum from the traits isn't correct"); - } - void verify(smtk::mesh::CellTraits traits) - { - // XXX(clang-tidy): Use `traits` to access the static data for test consistency. - // NOLINTNEXTLINE(readability-static-accessed-through-instance) - test(traits.NUM_VERTICES == 4, "CellTetrahedron Trait reports wrong number of points"); - test( - traits.fixedPointSize() == smtk::mesh::CellFixedPointNumberTag::Type, - "CellTetrahedron Traits reports fixedPointSize() incorrectly"); - test(traits.dimension() == 3, "CellTetrahedron Trait reports wrong dimension"); - - //now verify the enum logic is correct - typedef smtk::mesh::CellTraits TraitsType; - test( - TraitsType::CellType::CellEnum == smtk::mesh::CellTetrahedron::CellEnum, - "CellEnum from the traits isn't correct"); - } - void verify(smtk::mesh::CellTraits traits) - { - // XXX(clang-tidy): Use `traits` to access the static data for test consistency. - // NOLINTNEXTLINE(readability-static-accessed-through-instance) - test(traits.NUM_VERTICES == 3, "CellTriangle Trait reports wrong number of points"); - test( - traits.fixedPointSize() == smtk::mesh::CellFixedPointNumberTag::Type, - "CellTriangle Traits reports fixedPointSize() incorrectly"); - test(traits.dimension() == 2, "CellTriangle Trait reports wrong dimension"); - - //now verify the enum logic is correct - typedef smtk::mesh::CellTraits TraitsType; - test( - TraitsType::CellType::CellEnum == smtk::mesh::CellTriangle::CellEnum, - "CellEnum from the traits isn't correct"); - } - void verify(smtk::mesh::CellTraits traits) - { - // XXX(clang-tidy): Use `traits` to access the static data for test consistency. - // NOLINTNEXTLINE(readability-static-accessed-through-instance) - test(traits.NUM_VERTICES == 1, "CellVertex Trait reports wrong number of points"); - test( - traits.fixedPointSize() == smtk::mesh::CellFixedPointNumberTag::Type, - "CellVertex Traits reports fixedPointSize() incorrectly"); - test(traits.dimension() == 0, "CellVertex Trait reports wrong dimension"); - - //now verify the enum logic is correct - typedef smtk::mesh::CellTraits TraitsType; - test( - TraitsType::CellType::CellEnum == smtk::mesh::CellVertex::CellEnum, - "CellEnum from the traits isn't correct"); - } - void verify(smtk::mesh::CellTraits traits) - { - // XXX(clang-tidy): Use `traits` to access the static data for test consistency. - // NOLINTNEXTLINE(readability-static-accessed-through-instance) - test(traits.NUM_VERTICES == 6, "CellWedge Trait reports wrong number of points"); - test( - traits.fixedPointSize() == smtk::mesh::CellFixedPointNumberTag::Type, - "CellWedge Traits reports fixedPointSize() incorrectly"); - test(traits.dimension() == 3, "CellWedge Trait reports wrong dimension"); - - //now verify the enum logic is correct - typedef smtk::mesh::CellTraits TraitsType; - test( - TraitsType::CellType::CellEnum == smtk::mesh::CellWedge::CellEnum, - "CellEnum from the traits isn't correct"); - } -}; - -#ifndef _MSC_VER -#pragma GCC diagnostic pop -#endif -} // namespace - -int UnitTestCellTypes(int /*unused*/, char** const /*unused*/) -{ - std::cout << "verify_cell_attributes" << std::endl; - smtk::mesh::testing::TryAllCells(verify_cell_attributes()); - smtk::mesh::testing::TryAllCellEnums(verify_cell_attributes()); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestCreateMesh.cxx b/smtk/mesh/testing/cxx/UnitTestCreateMesh.cxx deleted file mode 100644 index 7b3c2b155ed4cf449eaf7a324de8ca758ef30cbd..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestCreateMesh.cxx +++ /dev/null @@ -1,177 +0,0 @@ - -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -smtk::mesh::ResourcePtr load_mesh(const smtk::mesh::InterfacePtr& interface) -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::io::importMesh(file_path, interface); - test(mr->isValid(), "resource should be valid"); - - return mr; -} - -void cleanup(const smtk::mesh::ResourcePtr& mr, smtk::mesh::MeshSet meshset) -{ - smtk::mesh::MeshSet allMeshes = mr->meshes(); - - const bool is_part_of_resource = smtk::mesh::set_intersect(allMeshes, meshset).is_empty(); - if (is_part_of_resource) - { - test(mr->removeMeshes(meshset)); - } -} - -void verify_create_empty_mesh(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numMeshesBeforeCreation = mr->numberOfMeshes(); - - smtk::mesh::CellSet emptyCellSet = smtk::mesh::CellSet(mr, smtk::mesh::HandleRange()); - smtk::mesh::MeshSet result = mr->createMesh(emptyCellSet); - - test(result.is_empty(), "empty cellset should create empty meshset"); - test( - numMeshesBeforeCreation == mr->numberOfMeshes(), - "the number of meshes shouldn't change when adding an empty mesh"); -} - -void verify_create_mesh_with_cells_from_other_resource(const smtk::mesh::ResourcePtr& mr) -{ - //make another resource inside the manager - smtk::mesh::ResourcePtr othermr = load_mesh(mr->interface()); - - const std::size_t numMeshesBeforeCreation = mr->numberOfMeshes(); - - smtk::mesh::CellSet cellsFromOtherMesh = othermr->cells(); - smtk::mesh::MeshSet result = mr->createMesh(cellsFromOtherMesh); - - test(result.is_empty(), "cellset from different resource should create empty meshset"); - test(numMeshesBeforeCreation == mr->numberOfMeshes()); -} - -void verify_create_mesh(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numMeshesBeforeCreation = mr->numberOfMeshes(); - - smtk::mesh::CellSet allNonVolumeCells = - smtk::mesh::set_difference(mr->cells(), mr->cells(smtk::mesh::Dims3)); - smtk::mesh::MeshSet result = mr->createMesh(allNonVolumeCells); - - test(result.size() == 1, "valid cellset should create meshset with single mesh"); - test((numMeshesBeforeCreation + 1) == mr->numberOfMeshes()); - - test(result.cells().size() == allNonVolumeCells.size()); - test(result.cells() == allNonVolumeCells); - - cleanup(mr, result); -} - -void verify_create_mesh_num_meshes(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numMeshesBeforeCreation = mr->numberOfMeshes(); - - //validate that for each mesh we create the numberOfMeshes is correct - std::vector results; - for (int i = 0; i < 3; ++i) - { - smtk::mesh::DimensionType dt = static_cast(i); - results.push_back(mr->createMesh(mr->cells(dt))); - } - test((numMeshesBeforeCreation + 3) == mr->numberOfMeshes()); - - for (std::size_t i = 0; i < results.size(); ++i) - { - cleanup(mr, results[i]); - } -} - -void verify_create_mesh_updated_mesh_queries(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numMeshesBeforeCreation = mr->numberOfMeshes(); - - smtk::mesh::CellSet allNonVolumeCells = - smtk::mesh::set_difference(mr->cells(), mr->cells(smtk::mesh::Dims3)); - smtk::mesh::MeshSet result = mr->createMesh(allNonVolumeCells); - - test((numMeshesBeforeCreation + 1) == mr->numberOfMeshes()); - - //The meshset returned from create should entirely be contained within - //all the meshes in the resource - smtk::mesh::MeshSet intersect = smtk::mesh::set_intersect(mr->meshes(), result); - test(intersect == result); - - //The meshset returned from create should entirely be contained within - //all the meshes that have 2d cells - intersect = smtk::mesh::set_intersect(mr->meshes(smtk::mesh::Dims2), result); - test(intersect == result); - - cleanup(mr, result); -} - -void verify_create_mesh_num_cells(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numCellsBeforeCreation = mr->cells().size(); - - smtk::mesh::CellSet allNonVolumeCells = - smtk::mesh::set_difference(mr->cells(), mr->cells(smtk::mesh::Dims3)); - smtk::mesh::MeshSet result = mr->createMesh(allNonVolumeCells); - - test(result.size() == 1, "valid cellset should create meshset with single mesh"); - test(numCellsBeforeCreation == mr->cells().size()); - - cleanup(mr, result); -} - -void verify_create_mesh_marks_modified() -{ - //verify that a resource loaded from file is not marked as modified - smtk::mesh::ResourcePtr mr = load_mesh(smtk::mesh::moab::make_interface()); - test(!mr->isModified(), "resource loaded from disk shouldn't be modified"); - - //verify that creating a mesh does mark update modify flag - verify_create_mesh(mr); - test(mr->isModified(), "resource should be marked as modified now"); -} -} // namespace - -int UnitTestCreateMesh(int /*unused*/, char** const /*unused*/) -{ - smtk::mesh::ResourcePtr mr = load_mesh(smtk::mesh::moab::make_interface()); - - verify_create_empty_mesh(mr); - verify_create_mesh_with_cells_from_other_resource(mr); - - verify_create_mesh(mr); - - verify_create_mesh_num_meshes(mr); - verify_create_mesh_updated_mesh_queries(mr); - - verify_create_mesh_num_cells(mr); - - verify_create_mesh_marks_modified(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestExportMesh2DM.cxx b/smtk/mesh/testing/cxx/UnitTestExportMesh2DM.cxx deleted file mode 100644 index 0cdbccf833e56fdac8a270705c906d01610a3e07..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestExportMesh2DM.cxx +++ /dev/null @@ -1,120 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/UUID.h" -#include "smtk/io/ExportMesh.h" -#include "smtk/io/ImportMesh.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -void verify_write_empty_resource() -{ - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".2dm"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - test(mr->isValid(), "empty resource is empty"); - - const bool result = smtk::io::exportMesh(write_path, mr); - - //before we verify if the write was good, first remove the output file - cleanup(write_path); - test(!result, "nothing to write for an empty resource"); -} - -void verify_write_null_resource() -{ - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".2dm"; - - //use a null resource ptr - smtk::mesh::ResourcePtr mr; - - const bool result = smtk::io::exportMesh(write_path, mr); - - //before we verify if the write was good, first remove the output file - cleanup(write_path); - - test(!result, "Can't save null resource to disk"); -} - -void verify_read_write_valid_resource() -{ - bool result = false; - - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".2dm"; - - { - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - test(!mr->isModified(), "loaded resource should be marked as not modifed"); - - //extract a surface mesh, and write that out - mr->meshes(smtk::mesh::Dims3).extractShell(); - test(mr->isModified(), "extractShell should mark the resource as modified"); - - if (!smtk::io::exportMesh(write_path, mr)) - { - test(result, "failed to properly write out a valid 2dm file"); - } - } - - { - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(write_path, mr); - cleanup(write_path); - - test(mr && mr->isValid(), "resource should be valid"); - test(!mr->isModified(), "loaded resource should be marked as not modifed"); - - test(mr->meshes().size() == 1, "resource should have 1 mesh"); - test(mr->cells().size() == 660, "resource should have 660 cells"); - test(mr->points().size() == 662, "resource should have 662 points"); - } -} -} // namespace - -int UnitTestExportMesh2DM(int /*unused*/, char** const /*unused*/) -{ - verify_write_empty_resource(); - verify_write_null_resource(); - verify_read_write_valid_resource(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestExportMesh3DM.cxx b/smtk/mesh/testing/cxx/UnitTestExportMesh3DM.cxx deleted file mode 100644 index af7652aa6d8c1e4f6ba4d38f102dd3fcf6024e98..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestExportMesh3DM.cxx +++ /dev/null @@ -1,103 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/UUID.h" -#include "smtk/io/ExportMesh.h" -#include "smtk/io/ImportMesh.h" -#include "smtk/io/ReadMesh.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -void verify_write_empty_resource() -{ - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".3dm"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - test(mr->isValid(), "empty resource is empty"); - - const bool result = smtk::io::exportMesh(write_path, mr); - - //before we verify if the write was good, first remove the output file - cleanup(write_path); - test(!result, "nothing to write for an empty resource"); -} - -void verify_write_null_resource() -{ - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".3dm"; - - //use a null resource ptr - smtk::mesh::ResourcePtr mr; - - const bool result = smtk::io::exportMesh(write_path, mr); - - //before we verify if the write was good, first remove the output file - cleanup(write_path); - - test(!result, "Can't save null resource to disk"); -} - -void verify_write_valid_resource() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".3dm"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::readMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - //export the volume elements - const bool result = smtk::io::exportMesh(write_path, mr); - cleanup(write_path); - - if (!result) - { - test(result, "failed to properly write out a valid 3dm file"); - } -} -} // namespace - -int UnitTestExportMesh3DM(int /*unused*/, char** const /*unused*/) -{ - verify_write_empty_resource(); - verify_write_null_resource(); - verify_write_valid_resource(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestExportMeshVTK.cxx b/smtk/mesh/testing/cxx/UnitTestExportMeshVTK.cxx deleted file mode 100644 index 5f5cd9db5d15caa169dd10db997ca2701075db42..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestExportMeshVTK.cxx +++ /dev/null @@ -1,129 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/UUID.h" -#include "smtk/io/ExportMesh.h" -#include "smtk/io/ImportMesh.h" -#include "smtk/io/ReadMesh.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -#include "smtk/AutoInit.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -void verify_write_empty_resource() -{ - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".vtk"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - test(mr->isValid(), "empty resource is empty"); - - const bool result = smtk::io::exportMesh(write_path, mr); - - //before we verify if the write was good, first remove the output file - cleanup(write_path); - test(!result, "nothing to write for an empty resource"); -} - -void verify_write_null_resource() -{ - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".vtk"; - - //use a null resource ptr - smtk::mesh::ResourcePtr mr; - - const bool result = smtk::io::exportMesh(write_path, mr); - - //before we verify if the write was good, first remove the output file - cleanup(write_path); - - test(!result, "Can't save null resource to disk"); -} - -void verify_read_write_valid_resource() -{ - bool result = false; - - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".vtk"; - - std::size_t ncells = 0; - std::size_t npoints = 0; - - { - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - test(!mr->isModified(), "loaded resource should be marked as not modifed"); - - //extract a surface mesh, and write that out - mr->meshes(smtk::mesh::Dims3).extractShell(); - test(mr->isModified(), "extractShell should mark the resource as modified"); - - if (!smtk::io::exportMesh(write_path, mr)) - { - test(result, "failed to properly write out a valid vtk file"); - } - ncells = mr->cells().size(); - npoints = mr->points().size(); - } - - { - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(write_path, mr); - cleanup(write_path); - - test(mr && mr->isValid(), "resource should be valid"); - test(!mr->isModified(), "loaded resource should be marked as not modifed"); - - test(mr->meshes().size() == 1, "resource should have 1 mesh"); - test(mr->cells().size() == ncells, "resource has incorrect # of cells"); - test(mr->points().size() == npoints, "resource has incorrect # of points"); - } -} -} // namespace - -int UnitTestExportMeshVTK(int /*unused*/, char** const /*unused*/) -{ - smtkComponentInitMacro(smtk_extension_vtk_io_mesh_MeshIOVTK); - verify_write_empty_resource(); - verify_write_null_resource(); - verify_read_write_valid_resource(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestExtractCanonicalIndices.cxx b/smtk/mesh/testing/cxx/UnitTestExtractCanonicalIndices.cxx deleted file mode 100644 index f580901b24a41e3e21a9b9365eea0d5436095de4..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestExtractCanonicalIndices.cxx +++ /dev/null @@ -1,83 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/utility/ExtractCanonicalIndices.h" - -#include "smtk/common/UUID.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/ModelToMesh.h" -#include "smtk/io/ReadMesh.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/utility/Create.h" - -#include "smtk/common/testing/cxx/helpers.h" - -#include -#include - -int UnitTestExtractCanonicalIndices(int /*unused*/, char* /*unused*/[]) -{ - // Create a new mesh mesh resource - smtk::mesh::ResourcePtr meshResource = smtk::mesh::Resource::create(); - - // Construct a uniform grid - std::array discretization = { { 2, 2, 2 } }; - std::function(std::array)> transform = - [](std::array x) { return x; }; - auto meshes = smtk::mesh::utility::createUniformGrid(meshResource, discretization, transform); - - std::array validReferenceCellIndices = { 0, 1, 2, 3, 0, 1, 4, 5, 0, 2, 4, 6, - 4, 5, 6, 7, 2, 3, 6, 7, 1, 3, 5, 7 }; - - std::array validCanonicalIndices = { 4, 4, 4, 4, 0, 0, 0, 0, 3, 3, 3, 3, - 5, 5, 5, 5, 2, 2, 2, 2, 1, 1, 1, 1 }; - - // Loop over the surface meshsets - for (int i = 1; i < 7; i++) - { - // Construct the arrays to hold reference cell indices and canonical indices - std::int64_t numberOfCells; - smtk::mesh::utility::PreAllocatedCanonicalIndices::determineAllocationLengths( - meshes[i], numberOfCells); - std::vector referenceCellIndices(numberOfCells); - std::vector canonicalIndices(numberOfCells); - - smtk::mesh::utility::PreAllocatedCanonicalIndices indices( - referenceCellIndices.data(), canonicalIndices.data()); - - smtk::mesh::utility::extractCanonicalIndices(meshes[i], meshes[0], indices); - - smtkTest( - std::equal( - referenceCellIndices.begin(), - referenceCellIndices.end(), - validReferenceCellIndices.begin() + (i - 1) * 4), - "Incorrect reference cell indices."); - smtkTest( - std::equal( - canonicalIndices.begin(), - canonicalIndices.end(), - validCanonicalIndices.begin() + (i - 1) * 4), - "Invalid canonical indices."); - } - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestExtractMeshConstants.cxx b/smtk/mesh/testing/cxx/UnitTestExtractMeshConstants.cxx deleted file mode 100644 index 9fddc1a44173480225623af4d647f99c3b0ab4fb..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestExtractMeshConstants.cxx +++ /dev/null @@ -1,196 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/ExtractMeshConstants.h" - -#include "smtk/io/ReadMesh.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -#include - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -std::string mesh_path() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/64bricks_12ktet.h5m"; - return file_path; -} - -class SubdivideMesh : public smtk::mesh::MeshForEach -{ -public: - SubdivideMesh(const std::vector& order) - : m_order(order) - { - } - - void forMesh(smtk::mesh::MeshSet& mesh) override - { - std::size_t i = m_index++ % m_order.size(); - if (i != 0) - { - mesh.setDomain(smtk::mesh::Domain(static_cast(i))); - } - } - -private: - const std::vector& m_order; - std::size_t m_index{ 0 }; -}; - -class ValidateCells : public smtk::mesh::CellForEach -{ -public: - ValidateCells( - const std::vector& cellsByDomain, - const std::vector& domains, - const std::int64_t* domainAssignments, - const smtk::mesh::HandleRange cellRange) - : m_cellsByDomain(cellsByDomain) - , m_domains(domains) - , m_domainAssignments(domainAssignments) - , m_cellRange(cellRange) - { - } - - void forCell( - const smtk::mesh::Handle& cellId, - smtk::mesh::CellType /*cellType*/, - int /*numPointIds*/) override - { - // default to the value for unlabeled domains - std::int64_t domainValue = -1; - - for (std::size_t i = 0; i < m_cellsByDomain.size(); ++i) - { - if (m_cellsByDomain[i].range().find(cellId) != m_cellsByDomain[i].range().end()) - { - domainValue = m_domains[i].value(); - break; - } - } - - test(m_domainAssignments[m_index++] == domainValue); - } - - const std::vector& m_cellsByDomain; - const std::vector& m_domains; - const std::int64_t* m_domainAssignments; - const smtk::mesh::HandleRange m_cellRange; - std::size_t m_index{ 0 }; -}; - -class ValidatePoints : public smtk::mesh::PointForEach -{ -public: - ValidatePoints( - const std::vector& pointsByDomain, - const std::vector& domains, - const std::int64_t* domainAssignments, - const smtk::mesh::HandleRange pointRange) - : m_pointsByDomain(pointsByDomain) - , m_domains(domains) - , m_domainAssignments(domainAssignments) - , m_pointRange(pointRange) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& /*xyz*/, - bool& /*coordinatesModified*/) override - { - for (auto point = pointIds.begin(); point != pointIds.end(); ++point) - { - // default to the value for unlabeled domains - std::int64_t domainValue = -1; - - for (std::size_t i = 0; i < m_pointsByDomain.size(); ++i) - { - if (m_pointsByDomain[i].range().find(*point) != m_pointsByDomain[i].range().end()) - { - domainValue = m_domains[i].value(); - break; - } - } - test(m_domainAssignments[m_index++] == domainValue); - } - } - - const std::vector& m_pointsByDomain; - const std::vector& m_domains; - const std::int64_t* m_domainAssignments; - const smtk::mesh::HandleRange m_pointRange; - std::size_t m_index{ 0 }; -}; - -void verify_extract_domain() -{ - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(mesh_path(), mr, smtk::io::mesh::Subset::OnlyNeumann); - test(mr->isValid(), "resource should be valid"); - - smtk::mesh::MeshSet meshes = mr->meshes(); - - test(!meshes.is_empty()); - - // some random order to assign domains - std::vector order = { 1, 2, 3, 4, 3, 5 }; - - SubdivideMesh subdivideMesh(order); - smtk::mesh::for_each(meshes, subdivideMesh); - - std::int64_t numberOfCells; - std::int64_t numberOfPoints; - - smtk::mesh::utility::PreAllocatedMeshConstants::determineAllocationLengths( - meshes, numberOfCells, numberOfPoints); - - std::int64_t* cells = new std::int64_t[numberOfCells]; - std::int64_t* points = new std::int64_t[numberOfPoints]; - - smtk::mesh::utility::PreAllocatedMeshConstants meshConstants(cells, points); - smtk::mesh::utility::extractDomainMeshConstants(meshes, meshConstants); - - std::vector domains = meshes.domains(); - std::vector cellsByDomain; - std::vector pointsByDomain; - for (auto&& domain : domains) - { - cellsByDomain.push_back(meshes.subset(domain).cells()); - pointsByDomain.push_back(meshes.subset(domain).points()); - } - - ValidateCells validateCells(cellsByDomain, domains, cells, meshes.cells().range()); - smtk::mesh::for_each(meshes.cells(), validateCells); - - ValidatePoints validatePoints(pointsByDomain, domains, points, meshes.points().range()); - smtk::mesh::for_each(meshes.points(), validatePoints); - - delete[] cells; - delete[] points; -} -} // namespace - -int UnitTestExtractMeshConstants(int /*unused*/, char** const /*unused*/) -{ - verify_extract_domain(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestExtractTessellation.cxx b/smtk/mesh/testing/cxx/UnitTestExtractTessellation.cxx deleted file mode 100644 index 3d5f82b08589d0f5f51f0c530f34abc1ece78e58..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestExtractTessellation.cxx +++ /dev/null @@ -1,486 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/ExtractTessellation.h" - -#include "smtk/io/ImportMesh.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -class VerifyCells : public smtk::mesh::CellForEach -{ - smtk::mesh::HandleRange m_cells; - smtk::mesh::PointSet m_points; - const std::vector& m_conn; - const std::vector& m_locations; - const std::vector& m_types; - - std::size_t m_currentIndex{ 0 }; - std::int64_t m_currentLocation{ 0 }; - - bool m_is_vtk; - -public: - VerifyCells( - const smtk::mesh::CellSet& cells, - const std::vector& conn, - const std::vector& locations, - const std::vector& types, - bool is_vtk_conn) - : m_points(cells.points()) - , m_conn(conn) - , m_locations(locations) - , m_types(types) - , m_is_vtk(is_vtk_conn) - { - } - - void forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType cellType, int numPts) override - { - m_cells.insert(cellId); - //verify the offset is in the correct location - std::int64_t offset = m_locations[m_currentIndex]; - test(offset == m_currentLocation); - if (m_is_vtk) - { - //the connectivity at offset should hold the number of points - test(m_conn[offset] == numPts); - m_currentLocation++; - offset++; - } - else - { - //verify the types match when doing smtk types - test(m_types[m_currentIndex] == static_cast(cellType)); - } - - //verify the points ids are mapped properly - for (int i = 0; i < numPts; ++i) - { - test(static_cast(m_conn[offset + i]) == m_points.find(this->pointIds()[i])); - } - - m_currentIndex++; - m_currentLocation += numPts; - } - - [[nodiscard]] smtk::mesh::CellSet cells(smtk::mesh::ResourcePtr mr) const - { - return smtk::mesh::CellSet(mr, m_cells); - } -}; - -template -class VerifyPoints : public smtk::mesh::PointForEach -{ - const std::vector& m_points; - std::size_t m_currentIndex{ 0 }; - -public: - VerifyPoints(const std::vector& points) - : smtk::mesh::PointForEach() - , m_points(points) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& coordinatesModified) override - { - coordinatesModified = false; //we are not modifying the coords - - std::size_t offset = 0; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i) - { - //iterate the range of coords / point ids - test(m_points[m_currentIndex] == static_cast(xyz[offset])); - test(m_points[m_currentIndex + 1] == static_cast(xyz[offset + 1])); - test(m_points[m_currentIndex + 2] == static_cast(xyz[offset + 2])); - m_currentIndex += 3; - offset += 3; - } - } -}; - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -smtk::mesh::ResourcePtr load_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/sixth_hexflatcore.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - return mr; -} - -void verify_constructors(const smtk::mesh::ResourcePtr& mr) -{ - - smtk::mesh::MeshSet ms = mr->meshes(); - - //construct tessellation object that only wants connectivity info - { - std::vector conn(1); //size doesn't matter right now - - smtk::mesh::utility::PreAllocatedTessellation tess(conn.data()); - - test(tess.hasConnectivity()); - test(!tess.hasCellLocations()); - test(!tess.hasCellTypes()); - test(!tess.hasDoublePoints()); - test(!tess.hasFloatPoints()); - - test(tess.useVTKConnectivity()); - tess.disableVTKStyleConnectivity(true); - test(!tess.useVTKConnectivity()); - - test(tess.useVTKCellTypes()); - tess.disableVTKCellTypes(true); - test(!tess.useVTKCellTypes()); - } - - //construct tessellation object that only wants connectivity info and points - { - std::vector conn(1); //size doesn't matter right now - std::vector fpoints(1); //size doesn't matter right now - - smtk::mesh::utility::PreAllocatedTessellation ftess(conn.data(), fpoints.data()); - - test(ftess.hasConnectivity()); - test(!ftess.hasCellLocations()); - test(!ftess.hasCellTypes()); - test(!ftess.hasDoublePoints()); - test(ftess.hasFloatPoints()); - test(ftess.useVTKConnectivity()); - test(ftess.useVTKCellTypes()); - - //now test with doubles - std::vector dpoints(1); //size doesn't matter right now - smtk::mesh::utility::PreAllocatedTessellation dtess(conn.data(), dpoints.data()); - - test(dtess.hasConnectivity()); - test(!dtess.hasCellLocations()); - test(!dtess.hasCellTypes()); - test(dtess.hasDoublePoints()); - test(!dtess.hasFloatPoints()); - test(dtess.useVTKConnectivity()); - test(dtess.useVTKCellTypes()); - } - - //construct tessellation object that only wants connectivity info, cell types - //and cell locations bust doesnt want points - { - std::vector conn(1); //size doesn't matter right now - std::vector locations(1); //size doesn't matter right now - std::vector types(1); //size doesn't matter right now - - smtk::mesh::utility::PreAllocatedTessellation tess(conn.data(), locations.data(), types.data()); - - test(tess.hasConnectivity()); - test(tess.hasCellLocations()); - test(tess.hasCellTypes()); - test(!tess.hasDoublePoints()); - test(!tess.hasFloatPoints()); - test(tess.useVTKConnectivity()); - test(tess.useVTKCellTypes()); - } - - //construct tessellation object that wants everything - { - std::vector conn(1); //size doesn't matter right now - std::vector locations(1); //size doesn't matter right now - std::vector types(1); //size doesn't matter right now - std::vector fpoints(1); //size doesn't matter right now - - smtk::mesh::utility::PreAllocatedTessellation ftess( - conn.data(), locations.data(), types.data(), fpoints.data()); - - test(ftess.hasConnectivity()); - test(ftess.hasCellLocations()); - test(ftess.hasCellTypes()); - test(!ftess.hasDoublePoints()); - test(ftess.hasFloatPoints()); - test(ftess.useVTKConnectivity()); - test(ftess.useVTKCellTypes()); - - //now test with doubles - std::vector dpoints(1); //size doesn't matter right now - smtk::mesh::utility::PreAllocatedTessellation dtess( - conn.data(), locations.data(), types.data(), dpoints.data()); - - test(dtess.hasConnectivity()); - test(dtess.hasCellLocations()); - test(dtess.hasCellTypes()); - test(dtess.hasDoublePoints()); - test(!dtess.hasFloatPoints()); - test(dtess.useVTKConnectivity()); - test(dtess.useVTKCellTypes()); - } -} - -void verify_alloc_lengths_meshset(const smtk::mesh::ResourcePtr& mr) -{ - - smtk::mesh::MeshSet all_meshes = mr->meshes(); - smtk::mesh::MeshSet mesh3d = mr->meshes(smtk::mesh::Dims3); - smtk::mesh::MeshSet mesh2d = mr->meshes(smtk::mesh::Dims2); - - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - all_meshes, connectivityLength, numberOfCells, numberOfPoints); - - test(connectivityLength != -1); - test(numberOfCells != -1); - test(numberOfPoints != -1); - - test(static_cast(connectivityLength) == all_meshes.pointConnectivity().size()); - test(static_cast(numberOfCells) == all_meshes.cells().size()); - test(static_cast(numberOfPoints) == all_meshes.points().size()); - - //Now try asking only for 3d cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - mesh3d, connectivityLength, numberOfCells, numberOfPoints); - - test(static_cast(connectivityLength) == mesh3d.pointConnectivity().size()); - test(static_cast(numberOfCells) == mesh3d.cells().size()); - test(static_cast(numberOfPoints) == mesh3d.points().size()); - - //Now try asking only for 2d cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - mesh2d, connectivityLength, numberOfCells, numberOfPoints); - - test(static_cast(connectivityLength) == mesh2d.pointConnectivity().size()); - test(static_cast(numberOfCells) == mesh2d.cells().size()); - test(static_cast(numberOfPoints) == mesh2d.points().size()); -} - -void verify_alloc_lengths_cellset(const smtk::mesh::ResourcePtr& mr) -{ - - smtk::mesh::CellSet all_cells = mr->cells(); - smtk::mesh::CellSet cells3d = mr->cells(smtk::mesh::Dims3); - smtk::mesh::CellSet cells2d = mr->cells(smtk::mesh::Dims2); - - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - all_cells, connectivityLength, numberOfCells, numberOfPoints); - - test(connectivityLength != -1); - test(numberOfCells != -1); - test(numberOfPoints != -1); - - test(static_cast(connectivityLength) == all_cells.pointConnectivity().size()); - test(static_cast(numberOfCells) == all_cells.size()); - test(static_cast(numberOfPoints) == all_cells.points().size()); - - //Now try asking only for 3d cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - cells3d, connectivityLength, numberOfCells, numberOfPoints); - - test(static_cast(connectivityLength) == cells3d.pointConnectivity().size()); - test(static_cast(numberOfCells) == cells3d.size()); - test(static_cast(numberOfPoints) == cells3d.points().size()); - - //Now try asking only for 2d cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - cells2d, connectivityLength, numberOfCells, numberOfPoints); - - test(static_cast(connectivityLength) == cells2d.pointConnectivity().size()); - test(static_cast(numberOfCells) == cells2d.size()); - test(static_cast(numberOfPoints) == cells2d.points().size()); -} - -void verify_extract_packed_single_type(const smtk::mesh::ResourcePtr& mr) -{ - - smtk::mesh::MeshSet all_meshes = mr->meshes(); - smtk::mesh::CellSet quads = mr->cells(smtk::mesh::Quad); - - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - quads, connectivityLength, numberOfCells, numberOfPoints); - - std::vector conn(connectivityLength); - std::vector fpoints(numberOfPoints * 3); - - smtk::mesh::utility::PreAllocatedTessellation ftess(conn.data(), fpoints.data()); - - ftess.disableVTKStyleConnectivity(true); - ftess.disableVTKCellTypes(true); - // smtk::mesh::utility::extractTessellation(quads, ftess); - smtk::mesh::utility::extractTessellation(quads, ftess); - - //lets iterate the points and make sure they all match - VerifyPoints vp(fpoints); - smtk::mesh::for_each(quads.points(), vp); -} - -void verify_extract_only_connectivity_and_types(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::CellSet cells3d = mr->cells(smtk::mesh::Dims3); - - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - cells3d, connectivityLength, numberOfCells, numberOfPoints); - - std::vector conn(connectivityLength); - std::vector locations(numberOfCells); - std::vector types(numberOfCells); - - smtk::mesh::utility::PreAllocatedTessellation tess(conn.data(), locations.data(), types.data()); - - tess.disableVTKStyleConnectivity(true); - tess.disableVTKCellTypes(true); - smtk::mesh::utility::extractTessellation(cells3d, tess); - - //lets iterate the cells, and verify that the extraction matches - //what we see when we iterate - VerifyCells vc(cells3d, conn, locations, types, false); - smtk::mesh::for_each(cells3d, vc); - test(vc.cells(mr) == cells3d); -} - -void verify_extract_all_to_vtk(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::CellSet cells3d = mr->cells(smtk::mesh::Dims3); - - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - cells3d, connectivityLength, numberOfCells, numberOfPoints); - - std::vector conn(connectivityLength + numberOfCells); - std::vector locations(numberOfCells); - std::vector types(numberOfCells); - std::vector dpoints(numberOfPoints * 3); - - smtk::mesh::utility::PreAllocatedTessellation tess( - conn.data(), locations.data(), types.data(), dpoints.data()); - - smtk::mesh::utility::extractTessellation(cells3d, tess); - - //lets iterate the cells, and verify that the extraction matches - //what we see when we iterate - VerifyCells vc(cells3d, conn, locations, types, true); - smtk::mesh::for_each(cells3d, vc); - test(vc.cells(mr) == cells3d); - - //lets iterate the points and make sure they all match - VerifyPoints vp(dpoints); - smtk::mesh::for_each(cells3d.points(), vp); -} - -void verify_extract_only_connectivity_to_vtk(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::CellSet cells2d = mr->cells(smtk::mesh::Dims2); - - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - cells2d, connectivityLength, numberOfCells, numberOfPoints); - - std::vector conn(connectivityLength + numberOfCells); - std::vector locations(numberOfCells); - std::vector types(numberOfCells); - - smtk::mesh::utility::PreAllocatedTessellation tess(conn.data(), locations.data(), types.data()); - - smtk::mesh::utility::extractTessellation(cells2d, tess); - - //lets iterate the cells, and verify that the extraction matches - //what we see when we iterate - VerifyCells vc(cells2d, conn, locations, types, true); - smtk::mesh::for_each(cells2d, vc); - test(vc.cells(mr) == cells2d); -} - -void verify_extract_volume_meshes_by_global_points_to_vtk(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::CellSet cells = mr->cells(smtk::mesh::Dims1); - cells.append(mr->cells(smtk::mesh::Dims2)); - - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - cells, connectivityLength, numberOfCells, numberOfPoints); - - std::vector conn(connectivityLength + numberOfCells); - std::vector locations(numberOfCells); - std::vector types(numberOfCells); - - smtk::mesh::utility::PreAllocatedTessellation tess(conn.data(), locations.data(), types.data()); - - //extract in releation to the points of all the meshes - smtk::mesh::utility::extractTessellation(cells, mr->points(), tess); - - // //lets iterate the cells, and verify that the extraction matches - // //what we see when we iterate - VerifyCells vc(mr->cells(), conn, locations, types, true); - smtk::mesh::for_each(cells, vc); - test(vc.cells(mr) == cells); -} -} // namespace - -int UnitTestExtractTessellation(int /*unused*/, char** const /*unused*/) -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - verify_constructors(mr); - - verify_alloc_lengths_meshset(mr); - verify_alloc_lengths_cellset(mr); - - verify_extract_packed_single_type(mr); - verify_extract_only_connectivity_and_types(mr); - - verify_extract_all_to_vtk(mr); - verify_extract_only_connectivity_to_vtk(mr); - - verify_extract_volume_meshes_by_global_points_to_vtk(mr); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestExtractTessellationOfModel.cxx b/smtk/mesh/testing/cxx/UnitTestExtractTessellationOfModel.cxx deleted file mode 100644 index a725224f87d143dc006ca53947d61698e3096596..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestExtractTessellationOfModel.cxx +++ /dev/null @@ -1,288 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/ExtractTessellation.h" - -#include "smtk/model/EntityIterator.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/json/jsonResource.h" - -#include "smtk/io/ModelToMesh.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" - -#include - -namespace -{ - -class VerifyCells : public smtk::mesh::CellForEach -{ - smtk::mesh::HandleRange m_cells; - smtk::mesh::PointSet m_points; - const std::vector& m_conn; - const std::vector& m_locations; - const std::vector& m_types; - - std::size_t m_currentIndex{ 0 }; - std::int64_t m_currentLocation{ 0 }; - - bool m_is_vtk; - -public: - VerifyCells( - const smtk::mesh::CellSet& cells, - const std::vector& conn, - const std::vector& locations, - const std::vector& types, - bool is_vtk_conn) - : m_points(cells.points()) - , m_conn(conn) - , m_locations(locations) - , m_types(types) - , m_is_vtk(is_vtk_conn) - { - } - - void forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType cellType, int numPts) override - { - m_cells.insert(cellId); - //verify the offset is in the correct location - std::int64_t offset = m_locations[m_currentIndex]; - test(offset == m_currentLocation); - if (m_is_vtk) - { - //the connectivity at offset should hold the number of points - test(m_conn[offset] == numPts); - m_currentLocation++; - offset++; - } - else - { - //verify the types match when doing smtk types - test(m_types[m_currentIndex] == static_cast(cellType)); - } - - //verify the points ids are mapped properly - for (int i = 0; i < numPts; ++i) - { - test(static_cast(m_conn[offset + i]) == m_points.find(this->pointIds()[i])); - } - - m_currentIndex++; - m_currentLocation += numPts; - } - - [[nodiscard]] smtk::mesh::CellSet cells(smtk::mesh::ResourcePtr mr) const - { - return smtk::mesh::CellSet(mr, m_cells); - } -}; - -template -class VerifyPoints : public smtk::mesh::PointForEach -{ - const std::vector& m_points; - std::size_t m_currentIndex{ 0 }; - -public: - VerifyPoints(const std::vector& points) - : smtk::mesh::PointForEach() - , m_points(points) - { - } - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& coordinatesModified) override - { - coordinatesModified = false; //we are not modifying the coords - - typedef smtk::mesh::HandleRange::const_iterator c_it; - std::size_t offset = 0; - for (c_it i = pointIds.begin(); i != pointIds.end(); ++i) - { - //iterate the range of coords / point ids - test(m_points[m_currentIndex] == static_cast(xyz[offset])); - test(m_points[m_currentIndex + 1] == static_cast(xyz[offset + 1])); - test(m_points[m_currentIndex + 2] == static_cast(xyz[offset + 2])); - m_currentIndex += 3; - offset += 3; - } - } -}; - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -void create_simple_mesh_model(smtk::model::ResourcePtr resource) -{ - std::string file_path(data_root); - file_path += "/model/2d/smtk/test2D.json"; - - std::ifstream file(file_path.c_str()); - - std::string json_str((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); - nlohmann::json json = nlohmann::json::parse(json_str); - - smtk::model::from_json(json, resource); - for (auto& tessPair : json["tessellations"]) - { - smtk::common::UUID id = tessPair[0]; - smtk::model::Tessellation tess = tessPair[1]; - resource->setTessellation(id, tess); - } - - resource->assignDefaultNames(); - - file.close(); -} - -void verify_alloc_lengths_entityref( - const smtk::model::EntityRef& eRef, - const smtk::mesh::ResourcePtr& mr) -{ - - smtk::mesh::MeshSet mesh = mr->findAssociatedMeshes(eRef); - - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - eRef, mr, connectivityLength, numberOfCells, numberOfPoints); - - test(connectivityLength != -1); - test(numberOfCells != -1); - test(numberOfPoints != -1); - - test(static_cast(connectivityLength) == mesh.pointConnectivity().size()); - test(static_cast(numberOfCells) == mesh.cells().size()); - test(static_cast(numberOfPoints) == mesh.points().size()); -} - -void verify_extract(const smtk::model::EntityRef& eRef, const smtk::mesh::ResourcePtr& mr) -{ - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - eRef, mr, connectivityLength, numberOfCells, numberOfPoints); - - std::vector conn(connectivityLength); - std::vector fpoints(numberOfPoints * 3); - - smtk::mesh::utility::PreAllocatedTessellation ftess(conn.data(), fpoints.data()); - - ftess.disableVTKStyleConnectivity(true); - ftess.disableVTKCellTypes(true); - smtk::mesh::utility::extractTessellation(eRef, mr, ftess); - - //lets iterate the points and make sure they all match - smtk::mesh::CellSet cells = mr->findAssociatedCells(eRef); - VerifyPoints vp(fpoints); - smtk::mesh::for_each(cells.points(), vp); -} - -void verify_extract_volume_meshes_by_global_points_to_vtk( - const smtk::model::EntityRef& eRef, - const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::CellSet cells = mr->findAssociatedCells(eRef); - - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - //query for all cells - smtk::mesh::utility::PreAllocatedTessellation::determineAllocationLengths( - eRef, mr, connectivityLength, numberOfCells, numberOfPoints); - - std::vector conn(connectivityLength + numberOfCells); - std::vector locations(numberOfCells); - std::vector types(numberOfCells); - - smtk::mesh::utility::PreAllocatedTessellation tess(conn.data(), locations.data(), types.data()); - - //extract in releation to the points of all the meshes - smtk::mesh::utility::extractTessellation(eRef, mr, mr->points(), tess); - - // //lets iterate the cells, and verify that the extraction matches - // //what we see when we iterate - VerifyCells vc(mr->cells(), conn, locations, types, true); - smtk::mesh::for_each(cells, vc); - test(vc.cells(mr) == cells); -} - -void removeOnesWithoutTess(smtk::model::EntityRefs& ents) -{ - smtk::model::EntityIterator it; - it.traverse(ents.begin(), ents.end(), smtk::model::ITERATE_BARE); - std::vector withoutTess; - for (it.begin(); !it.isAtEnd(); ++it) - { - if (!it->hasTessellation()) - { - withoutTess.push_back(it.current()); - } - } - - typedef std::vector::const_iterator c_it; - for (c_it i = withoutTess.begin(); i < withoutTess.end(); ++i) - { - ents.erase(*i); - } -} -} // namespace - -int UnitTestExtractTessellationOfModel(int /*unused*/, char** const /*unused*/) -{ - // Somehow grab an EntityRef with an associated tessellation - smtk::model::EntityRef eRef; - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_mesh_model(modelResource); - - smtk::io::ModelToMesh convert; - convert.setIsMerging(false); - smtk::mesh::ResourcePtr mr = convert(modelResource); - - typedef smtk::model::EntityRefs EntityRefs; - typedef smtk::model::EntityTypeBits EntityTypeBits; - - EntityTypeBits etypes[4] = { - smtk::model::VERTEX, smtk::model::EDGE, smtk::model::FACE, smtk::model::VOLUME - }; - for (int i = 0; i != 4; ++i) - { - //extract all the coordinates from every tessellation and make a single - //big pool - EntityTypeBits entType = etypes[i]; - EntityRefs currentEnts = modelResource->entitiesMatchingFlagsAs(entType); - removeOnesWithoutTess(currentEnts); - if (!currentEnts.empty()) - { - eRef = *currentEnts.begin(); - verify_alloc_lengths_entityref(eRef, mr); - verify_extract(eRef, mr); - verify_extract_volume_meshes_by_global_points_to_vtk(eRef, mr); - } - } - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestIncrementalAllocator.cxx b/smtk/mesh/testing/cxx/UnitTestIncrementalAllocator.cxx deleted file mode 100644 index 428fe7738c622fdc60fac12435046dc0976bb76f..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestIncrementalAllocator.cxx +++ /dev/null @@ -1,245 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/json/Interface.h" -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ -double pts[9][3] = { { 0., 0., 0. }, { 1., 0., 0. }, { 1., 1., 0. }, { 0., 1., 0. }, { 0., 0., 1. }, - { 1., 0., 1. }, { 1., 1., 1. }, { 0., 1., 1. }, { .5, -.5, 0. } }; - -double* vertex[1] = { pts[0] }; -double* line[2] = { pts[0], pts[1] }; -double* triangle[3] = { pts[0], pts[1], pts[2] }; -double* quad[4] = { pts[0], pts[1], pts[2], pts[3] }; -double* polygon[5] = { pts[0], pts[1], pts[2], pts[3], pts[8] }; -double* tetrahedron[4] = { pts[0], pts[1], pts[2], pts[4] }; -double* pyramid[5] = { pts[0], pts[1], pts[2], pts[3], pts[4] }; -double* wedge[6] = { pts[0], pts[1], pts[2], pts[4], pts[5], pts[6] }; -double* hexahedron[8] = { pts[0], pts[1], pts[2], pts[3], pts[4], pts[5], pts[6], pts[7] }; - -double** cellPoints[9] = { vertex, line, triangle, quad, polygon, - tetrahedron, pyramid, wedge, hexahedron }; - -void verify_moab_incremental_allocator_creation() -{ - smtk::mesh::InterfacePtr iface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - //at this point extract the allocator from json and verify that it - //is NOT null - smtk::mesh::IncrementalAllocatorPtr allocator = resource->interface()->incrementalAllocator(); - test(!!allocator, "moab buffered cell allocator should be valid"); - - //verify that is modified is true - test( - resource->isModified(), - "resource should be modified once the buffered cell allocator is accessed"); -} - -void verify_json_incremental_allocator_creation() -{ - smtk::mesh::InterfacePtr iface = smtk::mesh::json::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - //at this point extract the allocator from json and verify that it - //is null - smtk::mesh::IncrementalAllocatorPtr allocator = resource->interface()->incrementalAllocator(); - test(!allocator, "json incremental allocator should be nullptr"); - - //verify that is modified is true - test(!resource->isModified(), "resource shouldn't be modified"); -} - -void verify_moab_incremental_allocator_cell(smtk::mesh::CellType cellType) -{ - // Allocate a cell of type . - - smtk::mesh::InterfacePtr iface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - smtk::mesh::IncrementalAllocatorPtr allocator = resource->interface()->incrementalAllocator(); - - // Grab the number of vertices for the cell type being tested - std::size_t nVerticesPerCell = - (cellType == smtk::mesh::Polygon ? 5 : smtk::mesh::verticesPerCell(cellType)); - - test(allocator->isValid()); - - std::vector connectivity(nVerticesPerCell); - // fill the vertices and remember the connectivity - for (std::size_t i = 0; i < nVerticesPerCell; i++) - { - connectivity[i] = static_cast(allocator->addCoordinate(cellPoints[cellType][i])); - test(allocator->isValid()); - } - - // Add a cell using the cell type and connectivity - test(allocator->addCell(cellType, connectivity.data(), nVerticesPerCell)); - - // Finalize the addition of cells - test(allocator->flush()); - - test(allocator->cells().size() == 1); - - smtk::mesh::MeshSet mesh = - resource->createMesh(smtk::mesh::CellSet(resource, allocator->cells())); - - test(mesh.points().size() == nVerticesPerCell); -} - -void verify_moab_incremental_allocator_validity(smtk::mesh::CellType cellType) -{ - // Allocate a cell of type , ensuring that the allocator returns the - // proper success and validity variables along the way. - - smtk::mesh::InterfacePtr iface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - smtk::mesh::IncrementalAllocatorPtr allocator = resource->interface()->incrementalAllocator(); - test(allocator->isValid()); - test(allocator->cells().empty()); - - // Grab the number of vertices for the cell type being tested - std::size_t nVerticesPerCell = - (cellType == smtk::mesh::Polygon ? 5 : smtk::mesh::verticesPerCell(cellType)); - - // Try to add a cell before allocating vertices (should succeed) - std::vector connectivity(nVerticesPerCell); - for (std::size_t i = 0; i < nVerticesPerCell; i++) - { - connectivity[i] = static_cast(i); - } - test(allocator->addCell(cellType, connectivity.data(), nVerticesPerCell)); - test(allocator->isValid()); - - // Flush with coordinates allocated but no cells added (should succeed) - test(allocator->flush()); - test(allocator->isValid()); - - // fill the vertices and remember the connectivity (should succeed) - for (std::size_t i = 0; i < nVerticesPerCell; i++) - { - test( - static_cast(connectivity[i]) == - allocator->addCoordinate(cellPoints[cellType][i])); - } - - // Finalize the addition of cells (should succeed) - test(allocator->flush()); - test(allocator->cells().size() == 1); - test(allocator->isValid()); - - smtk::mesh::MeshSet mesh = - resource->createMesh(smtk::mesh::CellSet(resource, allocator->cells())); - - test(mesh.points().size() == nVerticesPerCell); -} - -void verify_moab_incremental_allocator_cells() -{ - // Allocate one of each type of cell. - - smtk::mesh::InterfacePtr iface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be modified"); - - smtk::mesh::IncrementalAllocatorPtr allocator = resource->interface()->incrementalAllocator(); - - // First, we must allocate the number of points needed for all of the cells. - std::size_t nVertices = 0; - - for (int cellType = smtk::mesh::Vertex; cellType != smtk::mesh::CellType_MAX; ++cellType) - { - std::size_t nVerticesPerCell = - (cellType == smtk::mesh::Polygon - ? 5 - : smtk::mesh::verticesPerCell(smtk::mesh::CellType(cellType))); - - nVertices += nVerticesPerCell; - } - - // We incrementally add cells and points in any order we want. Note that it - // is definitely preferable to allocate like cells in sequence, however. - - int pointCounter = 0; - - for (int cellType = smtk::mesh::Vertex; cellType != smtk::mesh::CellType_MAX; ++cellType) - { - std::size_t nVerticesPerCell = - (cellType == smtk::mesh::Polygon - ? 5 - : smtk::mesh::verticesPerCell(smtk::mesh::CellType(cellType))); - std::vector connectivity(nVerticesPerCell); - - // Fill the vertices for each cell and record its connectivity. To prevent - // overlapping, we offset cell vertices by 2 * unit cell length. - for (std::size_t i = 0; i < nVerticesPerCell; i++) - { - double xyz[3]; - for (int j = 0; j < 3; j++) - { - xyz[j] = cellPoints[cellType][i][j]; - } - xyz[0] += 2. * cellType; - connectivity[i] = static_cast(allocator->addCoordinate(xyz)); - test(pointCounter == connectivity[i]); - pointCounter++; - } - test(allocator->addCell(smtk::mesh::CellType(cellType), connectivity.data(), nVerticesPerCell)); - } - - test(allocator->flush()); - - test(allocator->cells().size() == 9); - - smtk::mesh::MeshSet mesh = - resource->createMesh(smtk::mesh::CellSet(resource, allocator->cells())); - - test(mesh.points().size() == nVertices); -} -} // namespace - -int UnitTestIncrementalAllocator(int /*unused*/, char** const /*unused*/) -{ - verify_moab_incremental_allocator_creation(); - verify_json_incremental_allocator_creation(); - - for (int cellType = smtk::mesh::Vertex; cellType != smtk::mesh::CellType_MAX; ++cellType) - { - smtk::mesh::CellType ct = smtk::mesh::CellType(cellType); - verify_moab_incremental_allocator_validity(ct); - verify_moab_incremental_allocator_cell(ct); - break; - } - - verify_moab_incremental_allocator_cells(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestIntervals.cxx b/smtk/mesh/testing/cxx/UnitTestIntervals.cxx deleted file mode 100644 index 4b632c33496e967d326ca91f0ab2e421112d3865..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestIntervals.cxx +++ /dev/null @@ -1,61 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include -#include - -#include "smtk/mesh/core/Handle.h" - -#include "smtk/mesh/json/jsonHandleRange.h" - -using nlohmann::json; - -int UnitTestIntervals(int /*unused*/, char** const /*unused*/) -{ - using namespace smtk::mesh; - - HandleInterval interval(6, 8); - - HandleRange range1; - range1.insert(2); - range1.insert(3); - range1.insert(interval); - - HandleRange range2; - range2.insert(12); - range2.insert(5); - - std::cout << "range 1: " << range1 << std::endl; - std::cout << "range 2: " << range2 << std::endl; - std::cout << "range 1 - range 2: " << (range1 - range2) << std::endl; - std::cout << "range 2 - range 1: " << (range2 - range1) << std::endl; - std::cout << "union(range 1, range 2): " << (range1 | range2) << std::endl; - std::cout << "intersection(range 1, range 2): " << (range1 & range2) << std::endl; - std::cout << "range 1 size: " << range1.size() << std::endl; - std::cout << "range 1 interval count: " << rangeIntervalCount(range1) << std::endl; - std::cout << "range 1 empty: " << range1.empty() << std::endl; - std::cout << "range 1 - 3: " << (range1 - Handle(3)) << std::endl; - std::cout << "range 1 - (3,4): " << (range1 - HandleInterval(3, 4)) << std::endl; - std::cout << "range 1 contains 3: " << rangeContains(range1, Handle(3)) << std::endl; - std::cout << "range 1 contains (2,4): " << rangeContains(range1, HandleInterval(2, 4)) - << std::endl; - std::cout << "range 1 contains (0,4): " << rangeContains(range1, HandleInterval(0, 4)) - << std::endl; - std::cout << "(range 1)[0]: " << rangeElement(range1, 0) << std::endl; - std::cout << "(range 1)[3]: " << rangeElement(range1, 4) << std::endl; - - nlohmann::json j = range1; - std::cout << j.dump() << std::endl; - - HandleRange range3 = j; - std::cout << range3 << std::endl; - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestLoadMesh.cxx b/smtk/mesh/testing/cxx/UnitTestLoadMesh.cxx deleted file mode 100644 index 20d1a0a17bd7f57efaa15bd6b9b02d2b44624c05..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestLoadMesh.cxx +++ /dev/null @@ -1,147 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" -#include "smtk/io/ReadMesh.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -void verify_load_valid_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - std::size_t numMeshes = mr->numberOfMeshes(); - std::cout << "number of meshes in twoassm_out is: " << numMeshes << std::endl; - test(numMeshes != 0, "dataset once loaded should have more than zero meshes"); - test(numMeshes == 53, "dataset once loaded should have 53 meshes"); -} - -void verify_load_writeLocation() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::InterfacePtr interface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr mr = read(file_path, interface); - test(mr->isValid(), "resource should be valid"); - - test(mr->readLocation() == file_path, "resource readLocation is wrong"); - test(mr->writeLocation() == file_path, "resource default writeLocation is wrong"); -} - -void verify_load_multiple_meshes() -{ - std::string first_file_path(data_root), second_file_path(data_root); - first_file_path += "/mesh/3d/twoassm_out.h5m"; - second_file_path += "/mesh/3d/64bricks_12ktet.h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr c1 = smtk::mesh::Resource::create(); - read(first_file_path, c1); - smtk::mesh::ResourcePtr c2 = smtk::mesh::Resource::create(); - read(second_file_path, c2); - - test(c1->isValid(), "resource should be valid"); - test(c2->isValid(), "resource should be valid"); - - //verify the size of twoassm - { - std::size_t numMeshes = c1->numberOfMeshes(); - std::cout << "number of meshes in twoassm_out is: " << numMeshes << std::endl; - test(numMeshes != 0, "dataset once loaded should have more than zero meshes"); - test(numMeshes == 53, "dataset once loaded should have 53 meshes"); - } - - //verify the size of 64bricks - { - std::size_t numMeshes = c2->numberOfMeshes(); - std::cout << "number of meshes in 64bricks_12ktet is: " << numMeshes << std::endl; - test(numMeshes != 0, "dataset once loaded should have more than zero meshes"); - test(numMeshes == 800, "dataset once loaded should have 800 meshes"); - } -} - -void verify_load_same_mesh_multiple_times() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/64bricks_12ktet.h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr c1 = smtk::mesh::Resource::create(); - read(file_path, c1); - test(c1->isValid(), "resource should be valid"); - - //load the same mesh a second time and confirm that is valid - smtk::mesh::ResourcePtr c2 = smtk::mesh::Resource::create(); - read(file_path, c2); - test(c2->isValid(), "resource should be valid"); -} - -void verify_load_onlyNeumann() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/64bricks_12ktet.h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr, smtk::io::mesh::Subset::OnlyNeumann); - test(mr->isValid(), "resource should be valid"); - - std::size_t numMeshes = mr->numberOfMeshes(); - std::cout << "number of neumann meshes in 64bricks_12ktet is: " << numMeshes << std::endl; - test(numMeshes == 221, "dataset once loaded should have 221 meshes"); -} - -void verify_load_onlyDirichlet() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/64bricks_12ktet.h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr, smtk::io::mesh::Subset::OnlyDirichlet); - test(mr->isValid(), "resource should be valid"); - - std::size_t numMeshes = mr->numberOfMeshes(); - std::cout << "number of dirichlet meshes in 64bricks_12ktet is: " << numMeshes << std::endl; - test(numMeshes == 221, "dataset once loaded should have 221 meshes"); -} -} // namespace - -int UnitTestLoadMesh(int /*unused*/, char** const /*unused*/) -{ - verify_load_valid_mesh(); - verify_load_writeLocation(); - - verify_load_multiple_meshes(); - - verify_load_same_mesh_multiple_times(); - - verify_load_onlyNeumann(); - verify_load_onlyDirichlet(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestMergeContactPoints.cxx b/smtk/mesh/testing/cxx/UnitTestMergeContactPoints.cxx deleted file mode 100644 index 8edbe23f4367e444f1966f0fb8eb60b662b79f0c..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestMergeContactPoints.cxx +++ /dev/null @@ -1,262 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/UUID.h" - -#include "smtk/io/ModelToMesh.h" -#include "smtk/io/WriteMesh.h" - -#include "smtk/io/ImportMesh.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/EntityIterator.h" -#include "smtk/model/Resource.h" -#include "smtk/model/Volume.h" -#include "smtk/model/json/jsonResource.h" -#include "smtk/model/json/jsonTessellation.h" - -#include "smtk/mesh/testing/cxx/helpers.h" -#include "smtk/model/testing/cxx/helpers.h" - -#include -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -void create_simple_mesh_model(smtk::model::ResourcePtr resource) -{ - std::string file_path(data_root); - file_path += "/model/2d/smtk/test2D.json"; - - std::ifstream file(file_path.c_str()); - - std::string json_str((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); - nlohmann::json json = nlohmann::json::parse(json_str); - - smtk::model::from_json(json, resource); - for (auto& tessPair : json["tessellations"]) - { - smtk::common::UUID id = tessPair[0]; - smtk::model::Tessellation tess = tessPair[1]; - resource->setTessellation(id, tess); - } - - resource->assignDefaultNames(); - - file.close(); -} - -smtk::mesh::MeshSet -make_MeshPoint(smtk::mesh::ResourcePtr meshResource, double x, double y, double z) -{ - smtk::mesh::InterfacePtr interface = meshResource->interface(); - smtk::mesh::AllocatorPtr allocator = interface->allocator(); - - smtk::mesh::Handle vertexHandle; - std::vector coords; - allocator->allocatePoints(1, vertexHandle, coords); - - coords[0][0] = x; - coords[1][0] = y; - coords[2][0] = z; - - smtk::mesh::HandleRange meshCells; - meshCells.insert(vertexHandle); - - smtk::mesh::CellSet cellsForMesh(meshResource, meshCells); - smtk::mesh::MeshSet result = meshResource->createMesh(cellsForMesh); - - return result; -} - -void verify_simple_merge() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_mesh_model(modelResource); - - smtk::io::ModelToMesh convert; - convert.setIsMerging(false); - smtk::mesh::ResourcePtr mr = convert(modelResource); - test(mr->isValid(), "resouce should be valid"); - - //make sure merging points works properly - smtk::mesh::PointSet points = mr->points(); - - test(points.size() == 88, "Should be exactly 88 points in the original mesh"); - - mr->meshes().mergeCoincidentContactPoints(); - - points = mr->points(); - test(points.size() == 32, "After merging of identical points we should have 32"); - - //verify that after merging points we haven't deleted any of the cells - //that represent a model vert - smtk::mesh::CellSet vert_cells = mr->cells(smtk::mesh::Dims0); - test(vert_cells.size() == 7); -} - -void verify_complex_merge() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_mesh_model(modelResource); - - smtk::io::ModelToMesh convert; - convert.setIsMerging(false); - smtk::mesh::ResourcePtr mr = convert(modelResource); - test(mr->isValid(), "meshResource should be valid"); - - //add multiple new mesh points - smtk::mesh::MeshSet newMeshPoint1 = make_MeshPoint(mr, 0.0, 2.0, 0.0); - smtk::mesh::MeshSet newMeshPoint2 = make_MeshPoint(mr, 1.0, 0.0, 0.0); - smtk::mesh::MeshSet newMeshPoint3 = make_MeshPoint(mr, 3.0, 0.0, 0.0); - smtk::mesh::MeshSet newMeshPoint4 = make_MeshPoint(mr, 0.0, 2.0, 0.0); - - //make sure merging points works properly - smtk::mesh::PointSet points = mr->points(); - test(points.size() == 92, "should be 92 points before merge"); - - //failing to merge this point into the other points - mr->meshes().mergeCoincidentContactPoints(); - - points = mr->points(); - test(mr->points().size() == 32, "After merging of identical points we should have 32"); - - //verify the all the points merged properly - std::vector p(3); - - newMeshPoint1.points().get(p.data()); - test(p[0] == 0.0); - test(p[1] == 2.0); - test(p[2] == 0.0); - - newMeshPoint2.points().get(p.data()); - test(p[0] == 1.0); - test(p[1] == 0.0); - test(p[2] == 0.0); - - newMeshPoint3.points().get(p.data()); - test(p[0] == 3.0); - test(p[1] == 0.0); - test(p[2] == 0.0); - - newMeshPoint4.points().get(p.data()); - test(p[0] == 0.0); - test(p[1] == 2.0); - test(p[2] == 0.0); -} - -void verify_write_valid_meshResource_hdf5_after_merge() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_mesh_model(modelResource); - - smtk::io::ModelToMesh convert; - convert.setIsMerging(false); - smtk::mesh::ResourcePtr mr = convert(modelResource); - test(mr->isValid(), "resource should be valid"); - - //make sure merging points works properly - smtk::mesh::PointSet points = mr->points(); - - test(points.size() == 88, "Should be exactly 88 points in the original mesh"); - - //add multiple new mesh points - smtk::mesh::MeshSet newMeshPoint1 = make_MeshPoint(mr, 0.0, 2.0, 0.0); - smtk::mesh::MeshSet newMeshPoint2 = make_MeshPoint(mr, 1.0, 0.0, 0.0); - smtk::mesh::MeshSet newMeshPoint3 = make_MeshPoint(mr, 3.0, 0.0, 0.0); - smtk::mesh::MeshSet newMeshPoint4 = make_MeshPoint(mr, 0.0, 2.0, 0.0); - - points = mr->points(); - test(mr->points().size() == 92, "Should be exactly 92 points before merge"); - test(mr->meshes(smtk::mesh::Dims0).size() == 11, "Should have 11 vertices before merge"); - - smtk::mesh::CellSet vert_cells = mr->cells(smtk::mesh::Dims0); - test(vert_cells.size() == 11, "Should have 11 vertex cells before merge"); - - mr->meshes().mergeCoincidentContactPoints(); - - points = mr->points(); - test(points.size() == 32, "After merging of identical points we should have 32"); - - //verify that after merging points we haven't deleted any of the cells - //that represent a model vert - test(mr->meshes(smtk::mesh::Dims0).size() == 11, "Should have 11 vertices after merge"); - - vert_cells = mr->cells(smtk::mesh::Dims0); - test(vert_cells.size() == 9, "Should have 9 vertex cells after merge"); - - // write out the resource after mergeCoincidentContactPoints() - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - //write out the mesh. - bool result = smtk::io::writeMesh(write_path, mr); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out a valid hdf5 resource"); - } - - //reload the written file and verify the number of meshes are the same as the - //input mesh - smtk::mesh::ResourcePtr mr1 = smtk::mesh::Resource::create(); - smtk::io::importMesh(write_path, mr1); - - //remove the file from disk - cleanup(write_path); - - //verify the meshes - test(mr1->isValid(), "resource should be valid"); - test(mr1->name() == mr->name()); - test(mr1->types() == mr->types()); - - test(mr->meshes(smtk::mesh::Dims2).size() == 4, "Should have 4 faces in saved resource"); - test(mr->meshes(smtk::mesh::Dims1).size() == 10, "Should have 10 edges in saved resource"); - test(mr->meshes(smtk::mesh::Dims0).size() == 11, "Should have 11 vertices in saved resource"); - - vert_cells = mr->cells(smtk::mesh::Dims0); - test(vert_cells.size() == 9, "Should have 9 vertex cells in saved resource"); - - points = mr1->points(); - test(points.size() == 32, "Should have 32 points in saved resource"); -} -} // namespace - -int UnitTestMergeContactPoints(int /*unused*/, char** const /*unused*/) -{ - verify_simple_merge(); - verify_complex_merge(); - verify_write_valid_meshResource_hdf5_after_merge(); - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestMeshMetrics.cxx b/smtk/mesh/testing/cxx/UnitTestMeshMetrics.cxx deleted file mode 100644 index aff2efd5ba8d400809ee1d805e143a4516735802..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestMeshMetrics.cxx +++ /dev/null @@ -1,61 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/IntItem.h" - -#include "smtk/io/ExportMesh.h" -#include "smtk/io/ImportMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -void verify_eulerCharacteristic_cube() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/cube.exo"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - test(smtk::mesh::utility::eulerCharacteristic(mr->meshes().extractShell()) == 2); - test(smtk::mesh::utility::eulerCharacteristic(mr->meshes()) == 1); -} - -void verify_eulerCharacteristic_cubeWithHole() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/cube_with_hole.exo"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - test(smtk::mesh::utility::eulerCharacteristic(mr->meshes().extractShell()) == 0); -} -} // namespace - -int UnitTestMeshMetrics(int /*unused*/, char** const /*unused*/) -{ - verify_eulerCharacteristic_cube(); - verify_eulerCharacteristic_cubeWithHole(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestMeshSet.cxx b/smtk/mesh/testing/cxx/UnitTestMeshSet.cxx deleted file mode 100644 index 80ef6f1165ba337b38b45c15481e29fe28b32ce9..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestMeshSet.cxx +++ /dev/null @@ -1,511 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/ImportMesh.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/operators/SetMeshName.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -smtk::mesh::ResourcePtr load_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - return mr; -} - -void verify_num_meshes(const smtk::mesh::ResourcePtr& mr) -{ - std::size_t numMeshes = mr->numberOfMeshes(); - - test(numMeshes != 0, "dataset once loaded should have more than zero meshes"); - test(numMeshes == 53, "dataset once loaded should have 53 meshes"); - - smtk::mesh::MeshSet all_meshes = mr->meshes(); - test(numMeshes == all_meshes.size()); - test(!all_meshes.is_empty()); - test(all_meshes.isValid()); -} - -void verify_constructors(const smtk::mesh::ResourcePtr& mr) -{ - std::vector mesh_names = mr->meshNames(); - - smtk::mesh::MeshSet ms = mr->meshes(mesh_names[0]); - - const smtk::mesh::MeshSet& ms2(ms); - smtk::mesh::MeshSet ms3 = mr->meshes("bad_name"); - test(ms3.is_empty()); - test(!ms3.isValid()); - test(ms3.size() == 0); - - test(ms.size() == ms2.size()); - test(ms.size() != ms3.size()); - - ms3 = ms; //test assignment operator - test(ms.size() == ms3.size()); - - test(!ms.is_empty()); - test(!ms2.is_empty()); - test(!ms3.is_empty()); -} - -void verify_comparisons(const smtk::mesh::ResourcePtr& mr) -{ - std::vector mesh_names = mr->meshNames(); - - smtk::mesh::MeshSet one = mr->meshes(mesh_names[0]); - smtk::mesh::MeshSet two = mr->meshes(mesh_names[1]); - - test(one == one); - test(!(one != one)); - test(two != one); - test(!(two == one)); - - const smtk::mesh::MeshSet& one_a(one); - test(one_a == one); - - smtk::mesh::MeshSet two_b = one_a; - two_b = two; //test assignment operator - test(two_b == two); - - test(one_a != two_b); -} - -void verify_typeset(const smtk::mesh::ResourcePtr& mr) -{ - //verify that empty meshset set has empty type set - { - smtk::mesh::CellTypes no_cell_types; - smtk::mesh::MeshSet emptyMeshSet = mr->meshes("bad name string"); - smtk::mesh::TypeSet noTypes = emptyMeshSet.types(); - - test(noTypes.cellTypes() == no_cell_types); - test(!noTypes.hasMeshes()); - test(!noTypes.hasCells()); - } - - //verify that if we get all cells from the resource the type set is correct - { - smtk::mesh::TypeSet all_types = mr->types(); - smtk::mesh::MeshSet allMeshes = mr->meshes(); - smtk::mesh::TypeSet allMeshesTypes = allMeshes.types(); - - test(allMeshesTypes.hasMeshes()); - test(allMeshesTypes.hasCells()); - test(allMeshesTypes.cellTypes() == all_types.cellTypes()); - test(allMeshesTypes == all_types); - } -} - -void verify_mesh_by_name(const smtk::mesh::ResourcePtr& mr) -{ - std::vector mesh_names = mr->meshNames(); - std::size_t collec_numMeshes = mr->numberOfMeshes(); - - //while we can't state that every mesh will have a name, we do know - //that at least 1 will have a name - test(collec_numMeshes >= mesh_names.size()); - test(!mesh_names.empty()); - - //now iterate over all the mesh_name and verify we can - //get a valid meshset out of it - typedef std::vector::const_iterator it; - std::size_t numMeshesWithNames = 0; - for (it i = mesh_names.begin(); i != mesh_names.end(); ++i) - { - std::cout << "Looking for mesh: " << *i << std::endl; - smtk::mesh::MeshSet ms = mr->meshes(*i); - test(ms.size() != 0); - numMeshesWithNames += ms.size(); - } - - test( - collec_numMeshes >= numMeshesWithNames, - "Number of meshes with names should be less than total number of meshes"); -} - -void verify_meshset_by_dim(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet all_meshes = mr->meshes(); - - //verify that the meshset given back from the resource is the same size - //as the number of meshes in the entire dataset - std::size_t collec_numMeshes = mr->numberOfMeshes(); - std::size_t size = all_meshes.size(); - test(size == collec_numMeshes); - - //query for all meshsets of dimension 0, 1, 2, and 3 - smtk::mesh::MeshSet all_dims; - std::size_t numMeshesFoundByDimCalls = 0; - for (int i = 0; i < 4; ++i) - { - smtk::mesh::DimensionType d(static_cast(i)); - smtk::mesh::MeshSet meshesWithDim = mr->meshes(d); - numMeshesFoundByDimCalls += meshesWithDim.size(); - all_dims.append(meshesWithDim); - } - - //since a mesh can have multiple dimensions numMeshesFoundByDimCalls - //is larger than all_meshes.size - test(all_meshes.size() <= numMeshesFoundByDimCalls); - - //all_dims and all_meshes should be the same - test(all_dims == all_meshes); -} - -void verify_meshset_of_only_a_dim(const smtk::mesh::ResourcePtr& mr) -{ - //verify that we can extract a meshset whose cells are all of the same - //dimension. without any complications - - smtk::mesh::MeshSet meshesWithDim3 = mr->meshes(smtk::mesh::Dims3); - smtk::mesh::MeshSet otherMeshes = mr->meshes(smtk::mesh::Dims2); - otherMeshes.append(mr->meshes(smtk::mesh::Dims1)); - - //meshesWithOnlyDim3 will contain meshsets that are pure 3d cells - smtk::mesh::MeshSet meshesWithOnlyDim3 = smtk::mesh::set_difference(meshesWithDim3, otherMeshes); - - //verify that we have zero cells of 1 or 2 dim - test(meshesWithOnlyDim3.cells(smtk::mesh::Dims0).is_empty()); - test(meshesWithOnlyDim3.cells(smtk::mesh::Dims1).is_empty()); - test(meshesWithOnlyDim3.cells(smtk::mesh::Dims2).is_empty()); - test(!meshesWithOnlyDim3.cells(smtk::mesh::Dims3).is_empty()); - - //verify that the associated types comes back to properly - smtk::mesh::TypeSet types = meshesWithOnlyDim3.types(); - test(types.hasMeshes()); - test(types.hasCells()); - - test(!types.hasDimension(smtk::mesh::Dims0)); - test(!types.hasDimension(smtk::mesh::Dims1)); - test(!types.hasDimension(smtk::mesh::Dims2)); - test(types.hasDimension(smtk::mesh::Dims3)); - - test(!types.hasCell(smtk::mesh::Vertex)); - test(!types.hasCell(smtk::mesh::Line)); - test(!types.hasCell(smtk::mesh::Triangle)); - test(!types.hasCell(smtk::mesh::Quad)); - test(!types.hasCell(smtk::mesh::Polygon)); - test(!types.hasCell(smtk::mesh::Tetrahedron)); - test(!types.hasCell(smtk::mesh::Pyramid)); - test(!types.hasCell(smtk::mesh::Wedge)); - test(types.hasCell(smtk::mesh::Hexahedron)); -} - -void verify_meshset_subset_dim(const smtk::mesh::ResourcePtr& mr) -{ - //verify that we can subset by dimension - smtk::mesh::MeshSet allMeshes = mr->meshes(); - - test(allMeshes.subset(smtk::mesh::Dims3) == mr->meshes(smtk::mesh::Dims3)); - test(allMeshes.subset(smtk::mesh::Dims2) == mr->meshes(smtk::mesh::Dims2)); - test(allMeshes.subset(smtk::mesh::Dims1) == mr->meshes(smtk::mesh::Dims1)); - test(allMeshes.subset(smtk::mesh::Dims0) == mr->meshes(smtk::mesh::Dims0)); -} - -template -void verify_subset_tag( - const smtk::mesh::ResourcePtr& mr, - smtk::mesh::MeshSet allMeshes, - std::vector tag_values) -{ - for (std::size_t i = 0; i < tag_values.size(); ++i) - { - test(allMeshes.subset(tag_values[i]) == mr->meshes(tag_values[i])); - } -} - -void verify_meshset_subset_tag(const smtk::mesh::ResourcePtr& mr) -{ - //verify that we can extract a sub meshset based on the tags - //inside a meshet. - smtk::mesh::MeshSet allMeshes = mr->meshes(); - - //verify the lengths before we check the size of each - //tag - test(allMeshes.domains().size() == mr->domains().size()); - test(allMeshes.dirichlets().size() == mr->dirichlets().size()); - test(allMeshes.neumanns().size() == mr->neumanns().size()); - - //domains - verify_subset_tag(mr, allMeshes, mr->domains()); - - //dirichlets - verify_subset_tag(mr, allMeshes, mr->dirichlets()); - - //neumann - verify_subset_tag(mr, allMeshes, mr->neumanns()); -} - -void verify_meshset_add_tags(const smtk::mesh::ResourcePtr& mr) -{ - //verify that we can add tags to a meshset - smtk::mesh::MeshSet allMeshes = mr->meshes(); - - smtk::mesh::MeshSet verts = allMeshes.subset(smtk::mesh::Dims0); - const bool applied = verts.setDirichlet(smtk::mesh::Dirichlet(42)); - const std::size_t numDirValues = mr->dirichlets().size(); - - test(applied, "didn't apply the dirichlet property"); - test(numDirValues > 0, "should have more than zero dirichlet sets"); -} - -void verify_meshset_intersect(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet all_meshes = mr->meshes(); - - { //intersection of self should produce self - smtk::mesh::MeshSet result = smtk::mesh::set_intersect(all_meshes, all_meshes); - test(result == all_meshes, "Intersection of self should produce self"); - } - - { //intersection with nothing should produce nothing - smtk::mesh::MeshSet no_meshes = mr->meshes("bad name string"); - smtk::mesh::MeshSet result = smtk::mesh::set_intersect(all_meshes, no_meshes); - test(result == no_meshes, "Intersection with nothing should produce nothing"); - } - - //find meshes that have volume elements - smtk::mesh::MeshSet volumeMeshes = mr->meshes(smtk::mesh::Dims3); - - //verify that the size of the intersection + size of difference - //equal size - smtk::mesh::MeshSet intersect_result = smtk::mesh::set_intersect(all_meshes, volumeMeshes); - - smtk::mesh::MeshSet difference_result = smtk::mesh::set_difference(all_meshes, volumeMeshes); - - const std::size_t summed_size = intersect_result.size() + difference_result.size(); - test( - summed_size == all_meshes.size(), "Size of intersect + difference needs to be the same as total\ - number of unique items"); -} - -void verify_meshset_union(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet all_meshes = mr->meshes(); - - { //union with self produces self - smtk::mesh::MeshSet result = smtk::mesh::set_union(all_meshes, all_meshes); - test(result == all_meshes, "Union of self should produce self"); - } - - { //union with nothing should produce self - smtk::mesh::MeshSet no_meshes = mr->meshes("bad name string"); - smtk::mesh::MeshSet result = smtk::mesh::set_union(all_meshes, no_meshes); - test(result == all_meshes, "Union with nothing should produce self"); - } - - //construct empty meshset(s) - smtk::mesh::MeshSet all_dims = mr->meshes("bad name string"); - smtk::mesh::MeshSet append_output; - //verify that append and union produce the same result - for (int i = 0; i < 4; ++i) - { - smtk::mesh::DimensionType d(static_cast(i)); - all_dims = smtk::mesh::set_union(all_dims, mr->meshes(d)); - append_output.append(mr->meshes(d)); - } - - test(all_dims == append_output, "Result of union should be the same as append"); - - { - smtk::mesh::MeshSet result = smtk::mesh::set_union(all_meshes, all_dims); - smtk::mesh::MeshSet result2 = all_meshes; - result2.append(all_dims); - test(result == result2); - } -} - -void verify_meshset_subtract(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet all_meshes = mr->meshes(); - - { //subtract of self should produce empty - smtk::mesh::MeshSet result = smtk::mesh::set_difference(all_meshes, all_meshes); - test(result.size() == 0, "Subtraction of self should produce nothing"); - test(result != all_meshes, "Subtraction of self should produce nothing"); - } - - { //subtract with nothing should produce self - smtk::mesh::MeshSet no_meshes = mr->meshes("bad name string"); - smtk::mesh::MeshSet result = smtk::mesh::set_difference(all_meshes, no_meshes); - test(result == all_meshes, "Subtraction with nothing should produce self"); - } - - { //subtract with something from nothing should produce nothing - smtk::mesh::MeshSet no_meshes = mr->meshes("bad name string"); - smtk::mesh::MeshSet result = smtk::mesh::set_difference(no_meshes, all_meshes); - test(result == no_meshes, "Subtraction of something from nothing should nothing"); - } - - //find meshes that have volume elements - smtk::mesh::MeshSet volumeMeshes = mr->meshes(smtk::mesh::Dims3); - - std::size_t size_difference = all_meshes.size() - volumeMeshes.size(); - smtk::mesh::MeshSet non_dim_meshes = smtk::mesh::set_difference(all_meshes, volumeMeshes); - test(non_dim_meshes.size() == size_difference, "subtract of two meshes produced wrong size"); -} - -class CountMeshesAndCells : public smtk::mesh::MeshForEach -{ - //keep the range of cells we have seen so we can verify that we - //seen all the cells that we expect to be given - smtk::mesh::CellSet cellsSeen; - //keep a physical count of number of meshes so that we can verify we - //don't iterate over a mesh more than once - int numMeshesIteratedOver{ 0 }; - -public: - CountMeshesAndCells(smtk::mesh::ResourcePtr resource) - : cellsSeen(resource->meshes("InvalidName").cells()) - - { - } - - void forMesh(smtk::mesh::MeshSet& mesh) override - { - this->numMeshesIteratedOver++; - this->cellsSeen.append(mesh.cells()); - } - - [[nodiscard]] int numberOfMeshesVisited() const { return numMeshesIteratedOver; } - - [[nodiscard]] smtk::mesh::CellSet cells() const { return cellsSeen; } -}; - -void verify_meshset_for_each(const smtk::mesh::ResourcePtr& mr) -{ - CountMeshesAndCells functor(mr); - smtk::mesh::MeshSet volMeshes = mr->meshes(smtk::mesh::Dims3); - smtk::mesh::for_each(volMeshes, functor); - - test(static_cast(functor.numberOfMeshesVisited()) == volMeshes.size()); - test(functor.cells() == volMeshes.cells()); -} - -void verify_meshset_visit(const smtk::mesh::ResourcePtr& mr) -{ - std::size_t numMeshesIteratedOver = 0; - smtk::resource::Component::Visitor countMeshesAndCells = - [&](const smtk::resource::ComponentPtr& component) { - auto meshComponent = std::dynamic_pointer_cast(component); - numMeshesIteratedOver++; - }; - - mr->visit(countMeshesAndCells); - - test(numMeshesIteratedOver == mr->meshes().size()); -} - -void verify_meshset_set_names(const smtk::mesh::ResourcePtr& mr) -{ - std::size_t numMeshesIteratedOver = 0; - smtk::resource::Component::Visitor setMeshNames = - [&](const smtk::resource::ComponentPtr& component) { - auto meshComponent = std::dynamic_pointer_cast(component); - std::stringstream s; - s << "meshset " << numMeshesIteratedOver; - meshComponent->mesh().setName(s.str()); - numMeshesIteratedOver++; - }; - - mr->visit(setMeshNames); - - numMeshesIteratedOver = 0; - smtk::resource::Component::Visitor checkMeshNames = - [&](const smtk::resource::ComponentPtr& component) { - auto meshComponent = std::dynamic_pointer_cast(component); - std::stringstream s; - s << "meshset " << numMeshesIteratedOver; - test(meshComponent->name() == s.str()); - numMeshesIteratedOver++; - }; - - mr->visit(checkMeshNames); -} - -void verify_meshset_set_name_op(const smtk::mesh::ResourcePtr& mr) -{ - std::size_t numMeshesIteratedOver = 0; - smtk::resource::Component::Visitor setMeshNames = - [&](const smtk::resource::ComponentPtr& component) { - auto meshComponent = std::dynamic_pointer_cast(component); - std::stringstream s; - s << "my_meshset " << numMeshesIteratedOver; - smtk::mesh::SetMeshName::Ptr setMeshNameOp = smtk::mesh::SetMeshName::create(); - setMeshNameOp->parameters()->associate(meshComponent); - setMeshNameOp->parameters()->findString("name")->setValue(s.str()); - auto result = setMeshNameOp->operate(); - test( - result->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)); - numMeshesIteratedOver++; - }; - - mr->visit(setMeshNames); - - numMeshesIteratedOver = 0; - smtk::resource::Component::Visitor checkMeshNames = - [&](const smtk::resource::ComponentPtr& component) { - auto meshComponent = std::dynamic_pointer_cast(component); - std::stringstream s; - s << "my_meshset " << numMeshesIteratedOver; - test(meshComponent->name() == s.str()); - numMeshesIteratedOver++; - }; - - mr->visit(checkMeshNames); -} -} // namespace - -int UnitTestMeshSet(int /*unused*/, char** const /*unused*/) -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - verify_num_meshes(mr); - verify_constructors(mr); - verify_comparisons(mr); - verify_typeset(mr); - verify_mesh_by_name(mr); - verify_meshset_by_dim(mr); - verify_meshset_of_only_a_dim(mr); - verify_meshset_subset_dim(mr); - verify_meshset_subset_tag(mr); - verify_meshset_add_tags(mr); - verify_meshset_intersect(mr); - verify_meshset_union(mr); - verify_meshset_subtract(mr); - - verify_meshset_for_each(mr); - verify_meshset_visit(mr); - verify_meshset_set_names(mr); - verify_meshset_set_name_op(mr); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestModelToMesh2D.cxx b/smtk/mesh/testing/cxx/UnitTestModelToMesh2D.cxx deleted file mode 100644 index 1f5147f2cb2980834d1cad9ea268b36cc357a48a..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestModelToMesh2D.cxx +++ /dev/null @@ -1,149 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ModelToMesh.h" -#include "smtk/io/WriteMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/EntityIterator.h" -#include "smtk/model/Resource.h" -#include "smtk/model/Volume.h" -#include "smtk/model/json/jsonResource.h" -#include "smtk/model/json/jsonTessellation.h" - -#include "smtk/mesh/testing/cxx/helpers.h" -#include "smtk/model/testing/cxx/helpers.h" - -#include -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -void create_simple_mesh_model(smtk::model::ResourcePtr resource) -{ - std::string file_path(data_root); - file_path += "/model/2d/smtk/test2D.json"; - - std::ifstream file(file_path.c_str()); - - std::string json_str((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); - nlohmann::json json = nlohmann::json::parse(json_str); - - smtk::model::from_json(json, resource); - for (auto& tessPair : json["tessellations"]) - { - smtk::common::UUID id = tessPair[0]; - smtk::model::Tessellation tess = tessPair[1]; - resource->setTessellation(id, tess); - } - - resource->assignDefaultNames(); - - file.close(); -} - -void verify_empty_model() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr meshResource = convert(modelResource); - test(!meshResource, "mesh resource should be invalid for an empty model"); -} - -void verify_model_association() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_mesh_model(modelResource); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr meshResource = convert(modelResource); - - //we need to verify that the mesh resource is now has an associated model - test(meshResource->hasAssociations(), "mesh resource should have associations"); - test( - (meshResource->associatedModel() != smtk::common::UUID()), - "mesh resource should be associated to a real model"); - test((meshResource->isAssociatedToModel()), "mesh resource should be associated to a real model"); - - //verify the MODEL_ENTITY is correct - smtk::model::EntityRefs currentModels = - modelResource->entitiesMatchingFlagsAs(smtk::model::MODEL_ENTITY); - if (!currentModels.empty()) - { //presuming only a single model in the model resource - test( - (meshResource->associatedModel() == currentModels.begin()->entity()), - "mesh resource associated model should match model resource"); - } -} - -void verify_cell_conversion() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_mesh_model(modelResource); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr meshResource = convert(modelResource); - test(meshResource->isValid(), "mesh resource should be valid"); - test(meshResource->numberOfMeshes() == 21, "mesh resource should have a mesh per tet"); - - //confirm that we have the proper number of volume cells - smtk::mesh::CellSet tri_cells = meshResource->cells(smtk::mesh::Dims2); - test(tri_cells.size() == 45); - - smtk::mesh::CellSet edge_cells = meshResource->cells(smtk::mesh::Dims1); - test(edge_cells.size() == 32); - - smtk::mesh::CellSet vert_cells = meshResource->cells(smtk::mesh::Dims0); - test(vert_cells.size() == 7); -} - -void verify_vertex_conversion() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_mesh_model(modelResource); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr meshResource = convert(modelResource); - test(meshResource->isValid(), "mesh resource should be valid"); - test(meshResource->numberOfMeshes() == 21, "mesh resource should have a mesh per tet"); - - //make sure the merging points from ModelToMesh works properly - smtk::mesh::PointSet points = meshResource->points(); - test(points.size() == 32, "We should have 32 points"); - - //verify that after merging points we haven't deleted any of the cells - //that represent a model vert - smtk::mesh::CellSet vert_cells = meshResource->cells(smtk::mesh::Dims0); - test(vert_cells.size() == 7); -} -} // namespace - -int UnitTestModelToMesh2D(int /*unused*/, char** const /*unused*/) -{ - verify_empty_model(); - verify_model_association(); - verify_cell_conversion(); - verify_vertex_conversion(); - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestModelToMesh3D.cxx b/smtk/mesh/testing/cxx/UnitTestModelToMesh3D.cxx deleted file mode 100644 index c342580a82d127d247904bbcb72647f288fac8ab..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestModelToMesh3D.cxx +++ /dev/null @@ -1,371 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ModelToMesh.h" -#include "smtk/io/WriteMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/EntityIterator.h" -#include "smtk/model/Resource.h" -#include "smtk/model/Volume.h" - -#include "smtk/mesh/testing/cxx/helpers.h" -#include "smtk/model/testing/cxx/helpers.h" - -#include - -namespace -{ - -class CountCells : public smtk::mesh::CellForEach -{ - //keep the range of points we have seen so we can verify that we - //seen all the cells that we expect to be given - smtk::mesh::HandleRange pointsSeen; - - //keep a physical count of number of cells so that we can verify we - //don't iterate over a cell more than once - int numCellsVisited{ 0 }; - - //total number of points seen, relates to the total size of the connectivity - //array for this cellset - int numPointsSeen{ 0 }; - -public: - CountCells() = default; - - void forCell(const smtk::mesh::Handle& cellId, smtk::mesh::CellType cellType, int numPts) override - { - (void)cellId; - (void)cellType; - this->numCellsVisited++; - this->numPointsSeen += numPts; - this->pointsSeen.insert( - smtk::mesh::HandleInterval(*this->pointIds(), *(this->pointIds() + numPts - 1))); - } - - [[nodiscard]] int numberOCellsVisited() const { return numCellsVisited; } - [[nodiscard]] int numberOPointsSeen() const { return numPointsSeen; } - - [[nodiscard]] smtk::mesh::HandleRange points() const { return pointsSeen; } -}; - -std::size_t numTetsInModel = 4; - -void create_simple_model(smtk::model::ResourcePtr resource) -{ - using namespace smtk::model::testing; - - smtk::model::SessionPtr session = smtk::model::Session::create(); - smtk::model::SessionRef sess(resource, session); - smtk::model::Model model = resource->addModel(); - - for (std::size_t i = 0; i < numTetsInModel; ++i) - { - smtk::common::UUIDArray uids = createTet(resource); - model.addCell(smtk::model::Volume(resource, uids[21])); - } - model.setSession(sess); - resource->assignDefaultNames(); -} - -void verify_empty_model() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr mr = convert(modelResource); - test(!mr, "mesh resource should be invalid for an empty model"); -} - -void verify_model_association() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_model(modelResource); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr mr = convert(modelResource); - - //we need to verify that the mesh resource is now has an associated model - test(mr->hasAssociations(), "mesh resource should have associations"); - test( - (mr->associatedModel() != smtk::common::UUID()), - "mesh resource should be associated to a real model"); - test((mr->isAssociatedToModel()), "mesh resource should be associated to a real model"); - test(mr->isModified(), "A mesh created in memory with no file is considered modified"); - - //verify the MODEL_ENTITY is correct - smtk::model::EntityRefs currentModels = - modelResource->entitiesMatchingFlagsAs(smtk::model::MODEL_ENTITY); - if (!currentModels.empty()) - { //presuming only a single model in the model resource - test( - (mr->associatedModel() == currentModels.begin()->entity()), - "mesh resource associated model should match model resource"); - } -} - -template -void testFindAssociations( - smtk::mesh::ResourcePtr mr, - smtk::model::EntityIterator& it, - std::size_t correct) -{ - std::size_t numNonEmpty = 0; - numNonEmpty = 0; - for (it.begin(); !it.isAtEnd(); ++it) - { - smtk::mesh::MeshSet entMesh = - mr->findAssociatedMeshes(*it, static_cast(Dim)); - if (entMesh.size()) - { - ++numNonEmpty; - std::cout << " " << it->entity().toString() << " " << entMesh.size() << " sets " - << entMesh.cells().size() << " cells" - << " " << it->flagSummary(0) << "\n"; - } - /* - test( - (tess && tess->begin() != tess->end() && entMesh.size()) || - ((!tess || tess->begin() == tess->end()) && !entMesh.size()), - "Model and mesh do not agree."); - */ - } - std::ostringstream msg; - msg << "Expected " << (correct ? 1 : 0) << " non-empty meshset of dimension " << Dim - << " per test tetrahedron."; - test(numNonEmpty == correct, msg.str()); -} - -template<> -void testFindAssociations<-1>( - smtk::mesh::ResourcePtr mr, - smtk::model::EntityIterator& it, - std::size_t correct) -{ - std::size_t numNonEmpty = 0; - for (it.begin(); !it.isAtEnd(); ++it) - { - smtk::mesh::MeshSet entMesh = mr->findAssociatedMeshes(*it); - const smtk::model::Tessellation* tess = it->hasTessellation(); - if (entMesh.size()) - std::cout << " " << it->entity().toString() << " " << entMesh.size() << " sets " - << entMesh.cells().size() << " cells" - << " " << it->flagSummary(0) << "\n"; - /* - */ - test( - (tess && tess->begin() != tess->end() && entMesh.size()) || - ((!tess || tess->begin() == tess->end()) && !entMesh.size()), - "Model and mesh do not agree."); - if (entMesh.size()) - ++numNonEmpty; - } - test(numNonEmpty == correct, "Expected a non-empty meshset per test tetrahedron."); -} - -template -void testFindAssociationsByRef( - smtk::mesh::ResourcePtr mr, - smtk::model::EntityIterator& it, - std::size_t correct) -{ - smtk::mesh::MeshSet entMesh = - mr->findAssociatedMeshes(it, static_cast(Dim)); - smtk::mesh::CellSet entCells = - mr->findAssociatedCells(it, static_cast(Dim)); - - test(entMesh.cells() == entCells, "Expected mesh cellset to be the same as queried cellset."); - - std::ostringstream msg; - msg << "Expected " << !entMesh.is_empty() << " non-empty meshset of dimension " << Dim - << " for all tetrahedra."; - test(entMesh.size() == correct, msg.str()); -} - -template<> -void testFindAssociationsByRef<-1>( - smtk::mesh::ResourcePtr mr, - smtk::model::EntityIterator& it, - std::size_t correct) -{ - smtk::mesh::MeshSet entMesh = mr->findAssociatedMeshes(it); - smtk::mesh::CellSet entCells = mr->findAssociatedCells(it); - smtk::mesh::TypeSet entTypes = mr->findAssociatedTypes(it); - const smtk::model::Tessellation* tess = it->hasTessellation(); - (void)tess; - - test(entMesh.cells() == entCells, "Expected mesh cellset to be the same as queried cellset."); - - test(entMesh.types() == entTypes, "Expected mesh typeset to be the same as queried typeset."); - - test(entMesh.size() == correct, "Expected a non-empty meshset for all tetrahedra."); -} - -void verify_cell_conversion() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_model(modelResource); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr mr = convert(modelResource); - test(mr->isValid(), "mesh resource should be valid"); - test(mr->numberOfMeshes() == numTetsInModel, "mesh resource should have a mesh per tet"); - - //confirm that we have the proper number of volume cells - smtk::mesh::CellSet tri_cells = mr->cells(smtk::mesh::Dims2); - test(tri_cells.size() == (numTetsInModel * 10)); - - smtk::mesh::CellSet edge_cells = mr->cells(smtk::mesh::Dims1); - test(edge_cells.size() == 0); - - smtk::mesh::CellSet vert_cells = mr->cells(smtk::mesh::Dims0); - test(vert_cells.size() == 0); - - // verify that we get a non-empty mesh set association back for some cells - smtk::model::EntityIterator it; - smtk::model::EntityRefs models = - modelResource->entitiesMatchingFlagsAs(smtk::model::MODEL_ENTITY); - it.traverse(models.begin(), models.end(), smtk::model::ITERATE_MODELS); - std::cout << "All associations:\n"; - testFindAssociations<-1>(mr, it, numTetsInModel); - std::cout << "Dim 0 associations:\n"; - testFindAssociations<0>(mr, it, 0); - std::cout << "Dim 1 associations:\n"; - testFindAssociations<1>(mr, it, 0); - std::cout << "Dim 2 associations:\n"; - testFindAssociations<2>(mr, it, numTetsInModel); - std::cout << "Dim 3 associations:\n"; - testFindAssociations<3>(mr, it, 0); - - { - it.traverse(models.begin(), models.end(), smtk::model::ITERATE_MODELS); - std::cout << "All associations:\n"; - testFindAssociationsByRef<-1>(mr, it, numTetsInModel); - std::cout << "Dim 0 associations:\n"; - testFindAssociationsByRef<0>(mr, it, 0); - std::cout << "Dim 1 associations:\n"; - testFindAssociationsByRef<1>(mr, it, 0); - std::cout << "Dim 2 associations:\n"; - testFindAssociationsByRef<2>(mr, it, numTetsInModel); - std::cout << "Dim 3 associations:\n"; - testFindAssociationsByRef<3>(mr, it, 0); - } - - { - std::cout << "Querying an empty mesh resource:\n"; - it.traverse(models.begin(), models.end(), smtk::model::ITERATE_MODELS); - std::cout << "All associations:\n"; - smtk::mesh::ResourcePtr emptyResource = smtk::mesh::Resource::create(); - testFindAssociationsByRef<-1>(emptyResource, it, 0); - } - - std::cout << "Find type info of first cell:\n"; - if (!models.empty()) - { - smtk::model::CellEntities cells = models.begin()->as().cells(); - if (!cells.empty()) - { - smtk::mesh::TypeSet meshedTypes = mr->findAssociatedTypes(cells[0]); - smtk::mesh::CellTypes cellTypes = meshedTypes.cellTypes(); - - //the model we have been given only has triangles, and while those - //triangles has physical coordinates we don't model each of those coordinates - //as an explicit cell vertex. That is why we only expect to find triangle - //cells in the following check - std::cout << " Cell " << cells[0].name() << "\n"; - static bool expected[smtk::mesh::CellType_MAX] = { false, false, true, false, false, - false, false, false, false }; - for (int i = 0; i < smtk::mesh::CellType_MAX; ++i) - { - smtk::mesh::CellType ct = static_cast(i); - std::cout << " Has mesh items of type " << cellTypeSummary(ct) << "? " - << (cellTypes[ct] ? "Y" : "N") << "\n"; - if (cellTypes[ct] != expected[ct]) - { - std::ostringstream msg; - msg << (expected[i] ? "Expected" : "Did not expect") << " this cell to have mesh " - << cellTypeSummary(ct, 1); - std::cout << " " << msg.str() << "\n"; - test(cellTypes[ct] == expected[ct], msg.str()); - } - } - } - } - - std::cout << "Entity lookup via reverse classification\n"; - smtk::model::EntityRefArray ents; - bool entsAreValid = mr->meshes().modelEntities(ents); - test(entsAreValid, "Expected valid entity refs."); - test(ents.size() == numTetsInModel, "Expected 1 tetrahedron per model."); - for (smtk::model::EntityRefArray::iterator eit = ents.begin(); eit != ents.end(); ++eit) - { - std::cout << " " << eit->name() << " (" << eit->flagSummary(0) << ")\n"; - } -} - -void verify_vertex_conversion() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_model(modelResource); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr mr = convert(modelResource); - test(mr->isValid(), "mesh resource should be valid"); - test(mr->numberOfMeshes() == numTetsInModel, "mesh resource should have a mesh per tet"); - - smtk::mesh::PointSet points = mr->points(); - test(points.size() == 7, "After merging of identical points we should have 7"); -} - -void verify_cell_have_points() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_model(modelResource); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr mr = convert(modelResource); - smtk::mesh::MeshSet triMeshes = mr->meshes(smtk::mesh::Dims2); - - CountCells functor; - smtk::mesh::for_each(triMeshes.cells(), functor); - - test( - functor.numberOCellsVisited() == static_cast(triMeshes.cells().size()), - "Mismatch in number of cells visited."); - test( - functor.numberOPointsSeen() == static_cast(triMeshes.pointConnectivity().size()), - "Mismatch in number of points seen."); - - //currently no two cells are sharing vertices. - test( - functor.numberOCellsVisited() == static_cast(numTetsInModel * 10), - "Number of cells not proportional to number of tets."); - test( - functor.numberOPointsSeen() == static_cast(numTetsInModel * 10 * 3), - "Number of points not proportional to number of tets."); -} -} // namespace - -int UnitTestModelToMesh3D(int /*unused*/, char** const /*unused*/) -{ - verify_empty_model(); - verify_model_association(); - verify_cell_conversion(); - verify_vertex_conversion(); - verify_cell_have_points(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestPointConnectivity.cxx b/smtk/mesh/testing/cxx/UnitTestPointConnectivity.cxx deleted file mode 100644 index 7cdf1f4145ad8de675444fd94d6a3587c9d41725..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestPointConnectivity.cxx +++ /dev/null @@ -1,261 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/core/TypeSet.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -smtk::mesh::ResourcePtr load_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - return mr; -} - -void verify_constructors(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet all_meshes = mr->meshes(); - - smtk::mesh::PointConnectivity all_cells_from_ms = all_meshes.pointConnectivity(); - const smtk::mesh::PointConnectivity& copy_of_all_cells(all_cells_from_ms); - - test(!all_cells_from_ms.is_empty()); - test(all_cells_from_ms.size() != 0); - test(all_cells_from_ms.size() == copy_of_all_cells.size()); - - //The connectivity of the zeroth dimension is itself - smtk::mesh::PointConnectivity zeroDim = mr->cells(smtk::mesh::Dims0).pointConnectivity(); - smtk::mesh::PointConnectivity equalToZeroDim = copy_of_all_cells; - equalToZeroDim = zeroDim; //test assignment operator - test(equalToZeroDim.size() == zeroDim.size()); - test(equalToZeroDim.numberOfCells() == zeroDim.numberOfCells()); - test(equalToZeroDim.size() == zeroDim.size()); - test(equalToZeroDim.size() == mr->cells(smtk::mesh::Dims0).size()); - - //The connectivity of the first dimension - smtk::mesh::PointConnectivity oneDim = mr->cells(smtk::mesh::Dims1).pointConnectivity(); - smtk::mesh::PointConnectivity equalToOneDim = copy_of_all_cells; - equalToOneDim = oneDim; //test assignment operator - test(equalToOneDim.numberOfCells() == oneDim.numberOfCells()); - test(equalToOneDim.size() != oneDim.numberOfCells()); - test(!equalToOneDim.is_empty()); -} - -void verify_empty(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet no_mesh = mr->meshes("bad name string"); - - smtk::mesh::PointConnectivity no_cells_a = no_mesh.pointConnectivity(); - smtk::mesh::PointConnectivity no_cells_b = - no_mesh.cells(smtk::mesh::Hexahedron).pointConnectivity(); - smtk::mesh::PointConnectivity no_cells_c = no_mesh.cells(smtk::mesh::Dims2).pointConnectivity(); - smtk::mesh::PointConnectivity no_cells_d = - no_mesh.cells(smtk::mesh::CellTypes()).pointConnectivity(); - - test(no_cells_a.is_empty()); - test(no_cells_b.is_empty()); - test(no_cells_c.is_empty()); - test(no_cells_d.is_empty()); - - test(no_cells_a.size() == 0); - test(no_cells_b.size() == 0); - test(no_cells_c.size() == 0); - test(no_cells_d.size() == 0); - - test(no_cells_a.numberOfCells() == 0); - test(no_cells_b.numberOfCells() == 0); - test(no_cells_c.numberOfCells() == 0); - test(no_cells_d.numberOfCells() == 0); -} - -void verify_all_connecitivity(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet all_meshes = mr->meshes(); - smtk::mesh::PointConnectivity all_cells_from_collec = mr->pointConnectivity(); - smtk::mesh::PointConnectivity all_cells_from_ms = all_meshes.pointConnectivity(); - - test(!all_cells_from_collec.is_empty()); - test(!all_cells_from_ms.is_empty()); - - test(all_cells_from_collec.size() != 0); - test(all_cells_from_ms.size() != 0); - - test(all_cells_from_collec.size() == all_cells_from_ms.size()); -} - -void verify_simple_equiv(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::PointConnectivity twoDim = mr->cells(smtk::mesh::Dims2).pointConnectivity(); - smtk::mesh::PointConnectivity oneDim = mr->cells(smtk::mesh::Dims1).pointConnectivity(); - - test(twoDim == twoDim); - test(!(twoDim != twoDim)); - test(oneDim != twoDim); - test(!(oneDim == twoDim)); - - const smtk::mesh::PointConnectivity& twoDim_a(twoDim); - test(twoDim_a == twoDim); - - smtk::mesh::PointConnectivity oneDim_b = twoDim_a; - oneDim_b = oneDim; //test assignment operator - test(oneDim_b == oneDim); - - test(twoDim_a != oneDim_b); -} - -void verify_complex_equiv(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::PointConnectivity twoDim = mr->cells(smtk::mesh::Dims2).pointConnectivity(); - smtk::mesh::PointConnectivity twoDimV2 = mr->cells(smtk::mesh::Dims2).pointConnectivity(); - test(twoDim == twoDimV2); - - smtk::mesh::CellTypes ctypes_only_2d(std::string("000011100")); - smtk::mesh::PointConnectivity twoDim_from_ctype = mr->cells(ctypes_only_2d).pointConnectivity(); - test(twoDim == twoDim_from_ctype); - - smtk::mesh::MeshSet meshes = mr->meshes(); - test(twoDim != meshes.pointConnectivity()); - test(twoDim == meshes.cells(smtk::mesh::Dims2).pointConnectivity()); - test(twoDim == meshes.cells(ctypes_only_2d).pointConnectivity()); - - //now try by appending multiple CellSets together to form - - smtk::mesh::CellSet cs_tri = meshes.cells(smtk::mesh::Triangle); - smtk::mesh::CellSet cs_qua = meshes.cells(smtk::mesh::Quad); - smtk::mesh::CellSet cs_pol = meshes.cells(smtk::mesh::Polygon); - - smtk::mesh::CellSet cs_all(cs_tri); - cs_all.append(cs_qua); - cs_all.append(cs_pol); - test(twoDim == cs_all.pointConnectivity()); - - //try appending the same cells twice and verify the connectivity is the same - cs_all.append(cs_qua); - cs_all.append(cs_pol); - test(twoDim == cs_all.pointConnectivity()); -} - -void verify_iteration(const smtk::mesh::ResourcePtr& mr) -{ - - //fetch all 2d cells. - //grab the number of cells, and total size. - //iterate all the cells and count how many we visit and sum the length - //verify all number match - smtk::mesh::PointConnectivity twoDim = mr->cells(smtk::mesh::Dims2).pointConnectivity(); - - const std::size_t reportedNumCells = twoDim.numberOfCells(); - const std::size_t reportedNumVerts = twoDim.size(); - - std::size_t actualNumCells = 0; - std::size_t actualNumVerts = 0; - - smtk::mesh::CellType cellType; - smtk::mesh::CellTypes allCellTypesSeen; - - int size = 0; - const smtk::mesh::Handle* points; - for (twoDim.initCellTraversal(); twoDim.fetchNextCell(cellType, size, points);) - { - ++actualNumCells; - actualNumVerts += static_cast(size); - - allCellTypesSeen[cellType] = true; - // mr->debugDump( points ); - } - smtk::mesh::TypeSet typeSet(allCellTypesSeen, false, true); - - //verify that the cell types that are reported are only 2D cells. - test(!typeSet.hasDimension(smtk::mesh::Dims1)); - test(typeSet.hasDimension(smtk::mesh::Dims2)); - test(!typeSet.hasDimension(smtk::mesh::Dims3)); - - test(reportedNumCells == actualNumCells); - test(reportedNumVerts == actualNumVerts); -} - -void verify_shared_iteration(const smtk::mesh::ResourcePtr& mr) -{ - - //fetch all 2d cells. - //make a copy of the connectivity - //reset iteration on both objects - //using the copy iterate over 10 cells - - //verify we iterate over all cells with the original - //verify we iterate over the rest of the cells with the copy - - //this shows that the iterator info isn't stored in the shared_ptr between - //the two connectivity objects, but is unique for both. - smtk::mesh::PointConnectivity twoDim = mr->cells(smtk::mesh::Dims2).pointConnectivity(); - smtk::mesh::PointConnectivity twoDimCopy = twoDim; - - const std::size_t reportedNumCells = twoDim.numberOfCells(); - const std::size_t reportedNumVerts = twoDim.size(); - - twoDim.initCellTraversal(); - twoDimCopy.initCellTraversal(); - - int size = 0; - const smtk::mesh::Handle* points; - for (int i = 0; i < 10; twoDimCopy.fetchNextCell(size, points), ++i) - ; - - std::size_t actualNumCells = 0; - std::size_t actualNumVerts = 0; - while (twoDim.fetchNextCell(size, points)) - { - ++actualNumCells; - actualNumVerts += static_cast(size); - } - - //this verifies that twoDim isn't using the iterator state from twoDimCopy - test(reportedNumCells == actualNumCells); - test(reportedNumVerts == actualNumVerts); - - //make sure the iterator on twoDimCopy keeps going - for (std::size_t i = 10; i < reportedNumCells; ++i) - { - //if we iterate too far this will through an exception - test(twoDimCopy.fetchNextCell(size, points)); - } -} -} // namespace - -int UnitTestPointConnectivity(int /*unused*/, char** const /*unused*/) -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - verify_constructors(mr); - verify_empty(mr); - - verify_all_connecitivity(mr); - - verify_simple_equiv(mr); - verify_complex_equiv(mr); - - verify_iteration(mr); - verify_shared_iteration(mr); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestPointField.cxx b/smtk/mesh/testing/cxx/UnitTestPointField.cxx deleted file mode 100644 index aac5fd3791819b8fab6c01d7fa941245be6abb80..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestPointField.cxx +++ /dev/null @@ -1,367 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" -#include "smtk/io/ReadMesh.h" -#include "smtk/io/WriteMesh.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -#include - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -smtk::mesh::ResourcePtr load_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/2d/twoMeshes.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - return mr; -} - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -void verify_partial_pointfields() -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - smtk::mesh::MeshSet mesh = mr->meshes(smtk::mesh::Dims2); - smtk::mesh::MeshSet one = mesh.subset(0); - smtk::mesh::MeshSet two = mesh.subset(1); - - std::vector fieldValues(mesh.points().size()); - for (std::size_t i = 0; i < fieldValues.size(); i++) - { - fieldValues[i] = static_cast(i); - } - mesh.createPointField("field data", 1, smtk::mesh::FieldType::Double, fieldValues.data()); - - std::vector fieldValuesForPointField1(one.points().size() * 2); - for (std::size_t i = 0; i < fieldValuesForPointField1.size(); i++) - { - fieldValuesForPointField1[i] = static_cast(i); - } - one.createPointField( - "field data for set 1", 2, smtk::mesh::FieldType::Double, fieldValuesForPointField1.data()); - - std::vector fieldValuesForPointField2(two.points().size() * 3); - for (std::size_t i = 0; i < fieldValuesForPointField2.size(); i++) - { - fieldValuesForPointField2[i] = static_cast(i); - } - two.createPointField( - "field data for set 2", 3, smtk::mesh::FieldType::Double, fieldValuesForPointField2.data()); - - { - std::set pointfields = mesh.pointFields(); - for (const auto& pointfield : pointfields) - { - std::cout << "\"" << pointfield.name() << "\" " << pointfield.dimension() << " " - << pointfield.size() << std::endl; - std::vector retrievedFieldValues(pointfield.size() * pointfield.dimension(), -1.); - pointfield.get(retrievedFieldValues.data()); - for (std::size_t i = 0; i < retrievedFieldValues.size(); i++) - { - test(fieldValues[i] == retrievedFieldValues[i]); - } - } - } - - std::vector pointfieldnames; - { - std::set pointfields = one.pointFields(); - for (const auto& pointfield : pointfields) - { - std::cout << "\"" << pointfield.name() << "\" " << pointfield.dimension() << std::endl; - pointfieldnames.push_back(pointfield.name()); - std::vector retrievedFieldValues(one.points().size() * pointfield.dimension(), -1.); - pointfield.get(retrievedFieldValues.data()); - for (std::size_t i = 0; i < retrievedFieldValues.size(); i++) - { - test(fieldValuesForPointField1[i] == retrievedFieldValues[i]); - } - } - - for (auto& pointfieldname : pointfieldnames) - { - smtk::mesh::PointField pointfield(one, pointfieldname); - test(one.removePointField(pointfield)); - test(pointfield.size() == 0); - test(pointfield.dimension() == 0); - } - } - - { - std::set pointfields = one.pointFields(); - test(pointfields.empty()); - } - - { - std::set pointfields = two.pointFields(); - test(pointfields.size() == 2); - for (const auto& pointfield : pointfields) - { - std::cout << "\"" << pointfield.name() << "\" " << pointfield.dimension() << " " - << pointfield.size() << std::endl; - } - } -} - -void verify_duplicate_pointfields() -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - smtk::mesh::MeshSet mesh = mr->meshes(smtk::mesh::Dims2); - smtk::mesh::MeshSet one = mesh.subset(0); - smtk::mesh::MeshSet two = mesh.subset(1); - - // Construct a point field of dimension 1 for all of . - std::vector fieldValues(mesh.points().size()); - for (std::size_t i = 0; i < fieldValues.size(); i++) - { - fieldValues[i] = static_cast(i); - } - auto cf = - mesh.createPointField("field data", 1, smtk::mesh::FieldType::Double, fieldValues.data()); - test(cf.isValid()); - - // Try to construct a point field with the same dimension and name for a - // subset of (should succeed and change the values of the field for - // the points in ). - std::vector fieldValuesForPointField1(one.points().size()); - for (std::size_t i = 0; i < fieldValuesForPointField1.size(); i++) - { - fieldValuesForPointField1[i] = static_cast(i) * 2; - } - auto cf1 = one.createPointField( - "field data", 1, smtk::mesh::FieldType::Double, fieldValuesForPointField1.data()); - test(cf1.isValid()); - - // Verify that the field values have been updated to the new values. - { - std::set pointfields = mesh.pointFields(); - for (const auto& pointfield : pointfields) - { - std::cout << "\"" << pointfield.name() << "\" " << pointfield.dimension() << " " - << pointfield.size() << std::endl; - std::vector retrievedFieldValues(pointfield.size() * pointfield.dimension(), -1.); - pointfield.get(retrievedFieldValues.data()); - for (std::size_t i = 0; i < retrievedFieldValues.size(); i++) - { - if (i < fieldValuesForPointField1.size()) - { - test(fieldValuesForPointField1[i] == retrievedFieldValues[i]); - } - else - { - test(fieldValues[i] == retrievedFieldValues[i]); - } - } - } - } - - // Try to construct a point field with a different dimension and the same name - // for a subset of (should fail). - std::vector fieldValuesForPointField2(two.points().size() * 3); - for (std::size_t i = 0; i < fieldValuesForPointField2.size(); i++) - { - fieldValuesForPointField2[i] = static_cast(i); - } - auto cf2 = two.createPointField( - "field data", 3, smtk::mesh::FieldType::Double, fieldValuesForPointField2.data()); - test(!cf2.isValid()); - - // Try again, but change the name (should succeed). - cf2 = two.createPointField( - "field data 2", 3, smtk::mesh::FieldType::Double, fieldValuesForPointField2.data()); - test(cf2.isValid()); -} - -class SetPointData : public smtk::mesh::PointForEach -{ -private: - const std::function& m_dataGenerator; - smtk::mesh::PointField& m_pointfield; - -public: - SetPointData( - const std::function& dataGenerator, - smtk::mesh::PointField& ds) - : m_dataGenerator(dataGenerator) - , m_pointfield(ds) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& /*coordinatesModified*/) override - { - std::size_t counter = 0; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i) - { - double value = m_dataGenerator(xyz[counter + 0], xyz[counter + 1], xyz[counter + 2]); - counter += 3; - smtk::mesh::HandleRange range; - range.insert(*i); - m_pointfield.set(range, &value); - } - } -}; - -class ValidatePointData : public smtk::mesh::PointForEach -{ -private: - const std::function& m_dataGenerator; - smtk::mesh::PointField& m_pointfield; - const double EPSILON = 1.e-14; - -public: - ValidatePointData( - const std::function& dataGenerator, - smtk::mesh::PointField& ds) - : m_dataGenerator(dataGenerator) - , m_pointfield(ds) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& /*coordinatesModified*/) override - { - std::size_t counter = 0; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i) - { - double expectedValue = m_dataGenerator(xyz[counter + 0], xyz[counter + 1], xyz[counter + 2]); - counter += 3; - smtk::mesh::HandleRange range; - range.insert(*i); - double value = 0.; - m_pointfield.get(range, &value); - test(std::abs(expectedValue - value) < EPSILON); - } - } -}; - -void verify_incremental_data_assignment() -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - smtk::mesh::MeshSet mesh = mr->meshes(); - std::function euclideanDistance = - [](double x, double y, double z) { return std::sqrt(x * x + y * y + z * z); }; - smtk::mesh::PointField distancePointField = - mesh.createPointField("euclidean distance", 1, smtk::mesh::FieldType::Double); - - { - SetPointData setPointData(euclideanDistance, distancePointField); - smtk::mesh::for_each(mesh.points(), setPointData); - } - - { - ValidatePointData validatePointData(euclideanDistance, distancePointField); - smtk::mesh::for_each(mesh.points(), validatePointData); - } -} - -void verify_pointfield_persistency() -{ - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - std::vector fieldValues; - { - smtk::mesh::ResourcePtr mr = load_mesh(); - - smtk::mesh::MeshSet mesh = mr->meshes(smtk::mesh::Dims2); - smtk::mesh::MeshSet one = mesh.subset(0); - - fieldValues.resize(one.points().size()); - for (std::size_t i = 0; i < fieldValues.size(); i++) - { - fieldValues[i] = static_cast(i); - } - one.createPointField("field data", 1, smtk::mesh::FieldType::Double, fieldValues.data()); - - //write out the mesh. - smtk::io::WriteMesh write; - bool result = write(write_path, mr); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out a valid hdf5 resource"); - } - } - - { - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(write_path, mr); - - //remove the file from disk - cleanup(write_path); - - { - smtk::mesh::MeshSet mesh = mr->meshes(smtk::mesh::Dims2); - smtk::mesh::MeshSet two = mesh.subset(0); - - smtk::mesh::PointField pointfield = *two.pointFields().begin(); - std::vector retrievedFieldValues(pointfield.size() * pointfield.dimension(), 0.); - pointfield.get(retrievedFieldValues.data()); - - test(retrievedFieldValues.size() == fieldValues.size()); - - for (std::size_t i = 0; i < retrievedFieldValues.size(); i++) - { - test(fieldValues[i] == retrievedFieldValues[i]); - } - } - } -} -} // namespace - -int UnitTestPointField(int /*unused*/, char** const /*unused*/) -{ - verify_partial_pointfields(); - verify_duplicate_pointfields(); - verify_incremental_data_assignment(); - verify_pointfield_persistency(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestPointLocator.cxx b/smtk/mesh/testing/cxx/UnitTestPointLocator.cxx deleted file mode 100644 index 3a2df4cb51f78b1ceadb209353a7418a0ddd199c..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestPointLocator.cxx +++ /dev/null @@ -1,134 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/PointLocator.h" - -#include "smtk/io/ImportMesh.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -smtk::mesh::ResourcePtr load_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - return mr; -} - -void verify_empty_locator(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::PointSet emptyPoints = mr->meshes("bad_name").points(); - test(emptyPoints.is_empty()); - test(emptyPoints.size() == 0); - - smtk::mesh::PointLocator locator1(emptyPoints); - - double* xyzs = nullptr; - std::size_t numPoints = 0; - smtk::mesh::PointLocator locator2(mr, numPoints, xyzs); -} - -void verify_raw_ptr_constructors(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t initialNumPoints = mr->points().size(); - - double d_xyzs[6] = { 400.0, 40.0, 0.02, 100.0, 150.0, 0.0 }; - float f_xyzs[6] = { -400.0f, 400.0f, 0.0f, 100.0f, -150.0f, 0.0f }; - std::size_t numPoints = 2; - - { //test raw double pointer - smtk::mesh::PointLocator locator2(mr, numPoints, d_xyzs); - test((mr->points().size() == initialNumPoints + numPoints)); - } - test((mr->points().size() == initialNumPoints)); - { //test raw float pointer - smtk::mesh::PointLocator locator2(mr, numPoints, f_xyzs); - test((mr->points().size() == initialNumPoints + numPoints)); - } - test((mr->points().size() == initialNumPoints)); -} - -class FindsSelf : public smtk::mesh::PointForEach -{ - smtk::mesh::PointLocator m_locator; - -public: - FindsSelf(const smtk::mesh::PointLocator& pl) - : m_locator(pl) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& coordinatesModified) override - { - //verify the coordinates and the number of points match - test((xyz.size() == (pointIds.size() * 3))); - coordinatesModified = false; //we are not modifying the coords - - std::size_t index = 0; - smtk::mesh::PointLocator::LocatorResults results; - results.want_Coordinates = true; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i) - { - m_locator.find(xyz[3 * index], xyz[3 * index + 1], xyz[3 * index + 2], 0.0, results); - - test((results.x_s.size() == results.pointIds.size())); - test((results.y_s.size() == results.pointIds.size())); - test((results.z_s.size() == results.pointIds.size())); - test(results.sqDistances.empty()); //since we didn't ask for them - - //should only return a single point as inside a radius of 0.0. So verify - //the Id and coordinates are the same - test((results.pointIds.size() == 1)); - test((results.pointIds[0] == index)); - test((xyz[3 * index] == results.x_s[0])); - test((xyz[3 * index + 1] == results.y_s[0])); - test((xyz[3 * index + 2] == results.z_s[0])); - } - } -}; - -void verify_points_find_themselves(const smtk::mesh::ResourcePtr& mr) -{ - //construct a point locator for all points in the mesh - smtk::mesh::PointLocator locator(mr->points()); - - //now verify that each point can locate it self with the locator - FindsSelf functor(locator); - smtk::mesh::for_each(mr->points(), functor); -} -} // namespace - -int UnitTestPointLocator(int /*unused*/, char** const /*unused*/) -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - verify_empty_locator(mr); - verify_raw_ptr_constructors(mr); - - verify_points_find_themselves(mr); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestPointSet.cxx b/smtk/mesh/testing/cxx/UnitTestPointSet.cxx deleted file mode 100644 index 2059d8af110e847356d8ab7d3667249a7cd9070a..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestPointSet.cxx +++ /dev/null @@ -1,476 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -smtk::mesh::ResourcePtr load_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - return mr; -} - -void verify_constructors(const smtk::mesh::ResourcePtr& mr) -{ - std::vector mesh_names = mr->meshNames(); - - smtk::mesh::MeshSet ms = mr->meshes(mesh_names[0]); - smtk::mesh::PointSet ps = ms.points(); - - const smtk::mesh::PointSet& ps2(ps); - smtk::mesh::PointSet ps3 = mr->meshes("bad_name").points(); - test(ps3.is_empty()); - test(ps3.size() == 0); - - test(ps.size() == ps2.size()); - test(ps.size() != ps3.size()); - - ps3 = ps; //test assignment operator - test(ps.size() == ps3.size()); - - test(!ps.is_empty()); - test(!ps2.is_empty()); - test(!ps3.is_empty()); -} - -void verify_subsets(const smtk::mesh::ResourcePtr& mr) -{ - std::vector mesh_names = mr->meshNames(); - - smtk::mesh::MeshSet ms = mr->meshes(mesh_names[0]); - smtk::mesh::PointSet ps = ms.points(); - - smtk::mesh::HandleRange range; - - std::set set; - std::vector vec; - - for (smtk::mesh::HandleRange::iterator iter = ps.range().begin(); iter != ps.range().end(); - ++iter) - { - range.insert(smtk::mesh::HandleInterval(iter->lower(), iter->upper() - 1)); - for (smtk::mesh::Handle i = iter->lower(); i < iter->upper(); ++i) - { - set.insert(i); - vec.push_back(i); - } - } - - smtk::mesh::PointSet ps2(mr, range); - smtk::mesh::PointSet ps3(mr, set); - smtk::mesh::PointSet ps4(mr, vec); - smtk::mesh::PointSet ps5(std::const_pointer_cast(mr), range); - - test(ps != ps2, "point sets should not be equal"); - test(ps2 == ps3, "point sets should be equal"); - test(ps3 == ps4, "point sets should be equal"); - test(ps4 == ps5, "point sets should be equal"); -} - -void verify_comparisons(const smtk::mesh::ResourcePtr& mr) -{ - std::vector mesh_names = mr->meshNames(); - - smtk::mesh::PointSet one = mr->meshes(mesh_names[0]).points(); - smtk::mesh::PointSet two = mr->meshes(mesh_names[1]).points(); - - test(one == one); - test(!(one != one)); - test(two != one); - test(!(two == one)); - - const smtk::mesh::PointSet& one_a(one); - test(one_a == one); - - smtk::mesh::PointSet two_b = one_a; - two_b = two; //test assignment operator - test(two_b == two); - - test(one_a != two_b); -} - -void verify_contains(const smtk::mesh::ResourcePtr& mr) -{ - //need to verify that point_set contains actually works - //I think we should grab the point connectivity from a cell set and - //verify that each point id in the point connectivity returns true - - smtk::mesh::CellSet hexs = mr->cells(smtk::mesh::Hexahedron); - smtk::mesh::PointSet hexPoints = hexs.points(); - smtk::mesh::PointConnectivity hexConn = hexs.pointConnectivity(); - - smtk::mesh::CellType cellType; - int size = 0; - const smtk::mesh::Handle* points; - for (hexConn.initCellTraversal(); hexConn.fetchNextCell(cellType, size, points);) - { - for (int i = 0; i < size; ++i) - { - const bool contains = hexPoints.contains(points[i]); - test(contains); - } - } -} - -void verify_find(const smtk::mesh::ResourcePtr& mr) -{ - //need to verify that point_set contains actually works - //I think we should grab the point connectivity from a cell set and - //verify that each point id find return a value between 0 and (size()-1) - smtk::mesh::CellSet hexs = mr->cells(smtk::mesh::Hexahedron); - smtk::mesh::PointSet hexPoints = hexs.points(); - smtk::mesh::PointConnectivity hexConn = hexs.pointConnectivity(); - - smtk::mesh::CellType cellType; - int size = 0; - const smtk::mesh::Handle* points; - for (hexConn.initCellTraversal(); hexConn.fetchNextCell(cellType, size, points);) - { - for (int i = 0; i < size; ++i) - { - const std::size_t loc = hexPoints.find(points[i]); - test(loc < hexPoints.size()); - } - } -} - -void verify_get(const smtk::mesh::ResourcePtr& mr) -{ - //this is really hard to test currently as we only have bulk gets() on - //points. So for now we are just going to make sure the function doesn't - //crash - smtk::mesh::PointSet all_points = mr->points(); - const std::size_t numCoords = 3 * all_points.size(); - - std::vector coords(numCoords); - all_points.get(coords.data()); - - for (int i = 0; i < smtk::mesh::CellType_MAX; ++i) - { - smtk::mesh::CellType cellType = static_cast(i); - smtk::mesh::CellSet cells = mr->cells(cellType); - - test(cells.points().get(coords.data()) != cells.is_empty()); - } -} - -void verify_float_get(const smtk::mesh::ResourcePtr& mr) -{ - - //this is really hard to test currently as we only have bulk gets() on - //points. So for now we are just going to make sure the function doesn't - //crash - smtk::mesh::PointSet all_points = mr->points(); - const std::size_t numCoords = 3 * all_points.size(); - - std::vector coords(numCoords); - all_points.get(coords.data()); - - for (int i = 0; i < smtk::mesh::CellType_MAX; ++i) - { - smtk::mesh::CellType cellType = static_cast(i); - smtk::mesh::CellSet cells = mr->cells(cellType); - - test(cells.points().get(coords.data()) != cells.is_empty()); - } -} - -void verify_set(const smtk::mesh::ResourcePtr& mr) -{ - - //current plan, is to fetch all the points, mark all the Y values - //as zero, and set that back onto the data, and than finally verify - //those values by getting again - smtk::mesh::PointSet all_points = mr->points(); - const std::size_t numCoords = 3 * all_points.size(); - - std::vector coords(numCoords); - all_points.get(coords.data()); //now test the double* interface - - //flatten in the Y ( and store a copy of the original Y values, so we can roll back ) - std::vector original_y(all_points.size()); - for (std::size_t i = 0, yi = 0; i < coords.size(); i += 3, ++yi) - { - original_y[yi] = coords[i + 1]; - coords[i + 1] = 0.0; - } - all_points.set(coords); //push the new point coords - - all_points.get(coords); //now test the std::vector interface - for (std::size_t i = 0; i < coords.size(); i += 3) - { - test((coords[i + 1] == 0.0)); - } - - //now reset the Y values to original values - for (std::size_t i = 0, yi = 0; i < coords.size(); i += 3, ++yi) - { - coords[i + 1] = original_y[yi]; - } - all_points.set(coords); //roll back to original points -} - -void verify_float_set(const smtk::mesh::ResourcePtr& mr) -{ - - //current plan, is to fetch all the points, mark all the Y values - //as zero, and set that back onto the data, and than finally verify - //those values by getting again - smtk::mesh::PointSet all_points = mr->points(); - const std::size_t numCoords = 3 * all_points.size(); - - std::vector coords(numCoords); - all_points.get(coords.data()); //now test the float* interface - - //flatten in the Y ( and store a copy of the original Y values, so we can roll back ) - std::vector original_y(all_points.size()); - for (std::size_t i = 0, yi = 0; i < coords.size(); i += 3, ++yi) - { - original_y[yi] = coords[i + 1]; - coords[i + 1] = 0.0f; - } - all_points.set(coords); //push the new point coords - - all_points.get(coords); //now test the std::vector interface - for (std::size_t i = 0; i < coords.size(); i += 3) - { - test((coords[i + 1] == 0.0f)); - } - - //now reset the Y values to original values - for (std::size_t i = 0, yi = 0; i < coords.size(); i += 3, ++yi) - { - coords[i + 1] = original_y[yi]; - } - all_points.set(coords); //roll back to original points -} - -void verify_pointset_intersect(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::PointSet all_points = mr->points(); - - { //intersection of self should produce self - smtk::mesh::PointSet result = smtk::mesh::set_intersect(all_points, all_points); - test(result == all_points, "Intersection of self should produce self"); - } - - { //intersection with nothing should produce nothing - smtk::mesh::PointSet no_points = mr->meshes("bad name string").points(); - smtk::mesh::PointSet result = smtk::mesh::set_intersect(all_points, no_points); - test(result == no_points, "Intersection with nothing should produce nothing"); - } - - //find meshes that have volume elements - smtk::mesh::PointSet volumePoints = mr->meshes(smtk::mesh::Dims3).points(); - - //verify that the size of the intersection + size of difference - //equal size - smtk::mesh::PointSet intersect_result = smtk::mesh::set_intersect(all_points, volumePoints); - - smtk::mesh::PointSet difference_result = smtk::mesh::set_difference(all_points, volumePoints); - - const std::size_t summed_size = intersect_result.size() + difference_result.size(); - test( - summed_size == all_points.size(), "Size of intersect + difference needs to be the same as total\ - number of unique items"); -} - -void verify_pointset_union(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::PointSet all_points = mr->points(); - - { //union with self produces self - smtk::mesh::PointSet result = smtk::mesh::set_union(all_points, all_points); - test(result == all_points, "Union of self should produce self"); - } - - { //union with nothing should produce self - smtk::mesh::PointSet no_points = mr->meshes("bad name string").points(); - smtk::mesh::PointSet result = smtk::mesh::set_union(all_points, no_points); - test(result == all_points, "Union with nothing should produce self"); - } - - //construct empty meshset(s) - smtk::mesh::PointSet union_output = mr->meshes("bad name string").points(); - //verify that append and union produce the same result - for (int i = 0; i < 4; ++i) - { - smtk::mesh::DimensionType d(static_cast(i)); - union_output = smtk::mesh::set_union(union_output, mr->meshes(d).points()); - } - - test(union_output == all_points, "Result of union should be the same as all_points"); -} - -void verify_pointset_subtract(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::PointSet all_points = mr->points(); - - { //subtract of self should produce empty - smtk::mesh::PointSet result = smtk::mesh::set_difference(all_points, all_points); - test(result.size() == 0, "Subtraction of self should produce nothing"); - test(result != all_points, "Subtraction of self should produce nothing"); - } - - { //subtract with nothing should produce self - smtk::mesh::PointSet no_points = mr->meshes("bad name string").points(); - smtk::mesh::PointSet result = smtk::mesh::set_difference(all_points, no_points); - test(result == all_points, "Subtraction with nothing should produce self"); - } - - { //subtract with something from nothing should produce nothing - smtk::mesh::PointSet no_points = mr->meshes("bad name string").points(); - smtk::mesh::PointSet result = smtk::mesh::set_difference(no_points, all_points); - test(result == no_points, "Subtraction of something from nothing should nothing"); - } - - //find meshes that have volume elements - smtk::mesh::PointSet volumePoints = mr->meshes(smtk::mesh::Dims3).points(); - - std::size_t size_difference = all_points.size() - volumePoints.size(); - smtk::mesh::PointSet non_dim_meshes = smtk::mesh::set_difference(all_points, volumePoints); - test(non_dim_meshes.size() == size_difference, "subtract of two meshes produced wrong size"); -} - -class CountPoints : public smtk::mesh::PointForEach -{ - //keep a physical count of number of ponts so that we can verify we - //don't iterate over a point more than once - int numPointsIteratedOver{ 0 }; - -public: - CountPoints(smtk::mesh::ResourcePtr /*unused*/) {} - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& coordinatesModified) override - { - //verify the coordinates and the number of points match - test((xyz.size() == (pointIds.size() * 3))); - - coordinatesModified = false; //we are not modifying the coords - - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i) - { //we could just increment by size of pointIds, but I want - //to have an example of how to do iteration over the point ids - this->numPointsIteratedOver++; - } - } - - [[nodiscard]] int numberOfPointsVisited() const { return numPointsIteratedOver; } -}; - -void verify_pointset_for_each_read(const smtk::mesh::ResourcePtr& mr) -{ - CountPoints functor(mr); - smtk::mesh::MeshSet volMeshes = mr->meshes(smtk::mesh::Dims3); - smtk::mesh::for_each(volMeshes.points(), functor); - test(static_cast(functor.numberOfPointsVisited()) == volMeshes.points().size()); -} - -class FlattenZ : public smtk::mesh::PointForEach -{ -public: - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& coordinatesModified) override - { - //verify the coordinates and the number of points match - test((xyz.size() == (pointIds.size() * 3))); - - //we are modifying the coords, so signal that the modifications are saved - coordinatesModified = true; - - for (std::size_t offset = 0; offset < xyz.size(); offset += 3) - { - //make all Z values 0.0 - xyz[offset + 2] = 0.0; - } - } -}; - -class VerifyZ : public smtk::mesh::PointForEach -{ -public: - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& coordinatesModified) override - { - (void)coordinatesModified; - - //verify the coordinates and the number of points match - test((xyz.size() == (pointIds.size() * 3))); - - for (std::size_t offset = 0; offset < xyz.size(); offset += 3) - { - //make all Z values 0.0 - test((xyz[offset + 2] == 0.0)); - } - } -}; - -void verify_pointset_for_each_modify(const smtk::mesh::ResourcePtr& mr) -{ - //first modify all the points to have 0 for the z value - smtk::mesh::MeshSet volMeshes = mr->meshes(smtk::mesh::Dims3); - FlattenZ functorA; - smtk::mesh::for_each(volMeshes.points(), functorA); - - //now verify that the points all have a z-value of 0 - VerifyZ functorB; - smtk::mesh::for_each(volMeshes.points(), functorB); -} -} // namespace - -int UnitTestPointSet(int /*unused*/, char** const /*unused*/) -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - verify_constructors(mr); - verify_subsets(mr); - verify_comparisons(mr); - - verify_contains(mr); - verify_find(mr); - - verify_get(mr); - verify_float_get(mr); - - verify_set(mr); - verify_float_set(mr); - - verify_pointset_intersect(mr); - verify_pointset_union(mr); - verify_pointset_subtract(mr); - - verify_pointset_for_each_read(mr); - verify_pointset_for_each_modify(mr); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestQueryTypes.cxx b/smtk/mesh/testing/cxx/UnitTestQueryTypes.cxx deleted file mode 100644 index 51a751b9eef327fcff2b2c6893085138f5ffac82..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestQueryTypes.cxx +++ /dev/null @@ -1,136 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/QueryTypes.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -struct verify_all_off_cell_types -{ - smtk::mesh::CellTypes ctypes; - //initialize the cellTypes for this struct to be all off - verify_all_off_cell_types() = default; - - void operator()(smtk::mesh::CellType cellEnum) - { //this operator will be called for each CellType, so verify that - //the struct 's ctypes bit is turned off for the given type - test(!ctypes[cellEnum], "This cell type should be off"); - } -}; - -struct verify_all_on_cell_types -{ - smtk::mesh::CellTypes ctypes; - verify_all_on_cell_types() - : ctypes(1023) //(2**10) -1 - { //initialize the cellTypes for this struct to be all off - } - - void operator()(smtk::mesh::CellType cellEnum) - { //this operator will be called for each CellType, so verify that - //the struct 's ctypes bit is turned off for the given type - test(ctypes[cellEnum], "This cell type should be off"); - } -}; - -void verify_dims_value() -{ - test(smtk::mesh::Dims0 == 0, "Dims0 enum value has changed"); - test(smtk::mesh::Dims1 == 1, "Dims1 enum value has changed"); - test(smtk::mesh::Dims2 == 2, "Dims2 enum value has changed"); - test(smtk::mesh::Dims3 == 3, "Dims3 enum value has changed"); -} - -void verify_CellTypes_usage() -{ - //verify that the empty construct, string constructor and - //bitwise contstructor all work - smtk::mesh::testing::TryAllCellEnums(verify_all_off_cell_types()); - smtk::mesh::testing::TryAllCellEnums(verify_all_on_cell_types()); - - //verify the string constructors - smtk::mesh::CellTypes ctypes_only_line(std::string("10")); - smtk::mesh::CellTypes ctypes_only_2d(std::string("000011100")); - - test(!ctypes_only_line[smtk::mesh::Vertex]); - test(ctypes_only_line[smtk::mesh::Line]); - test(!ctypes_only_line[smtk::mesh::Triangle]); - test(!ctypes_only_line[smtk::mesh::Quad]); - - test(!ctypes_only_2d[smtk::mesh::Vertex]); - test(!ctypes_only_2d[smtk::mesh::Line]); - test(ctypes_only_2d[smtk::mesh::Triangle]); - test(ctypes_only_2d[smtk::mesh::Quad]); - test(ctypes_only_2d[smtk::mesh::Polygon]); - test(!ctypes_only_2d[smtk::mesh::Tetrahedron]); - test(!ctypes_only_2d[smtk::mesh::Pyramid]); - test(!ctypes_only_2d[smtk::mesh::Wedge]); - test(!ctypes_only_2d[smtk::mesh::Hexahedron]); - - //verify the long long constructors - smtk::mesh::CellTypes ctypes_only_3d(992); - smtk::mesh::CellTypes ctypes_only_1d(2); - - test(!ctypes_only_3d[smtk::mesh::Vertex]); - test(!ctypes_only_3d[smtk::mesh::Line]); - test(!ctypes_only_3d[smtk::mesh::Triangle]); - test(!ctypes_only_3d[smtk::mesh::Quad]); - test(!ctypes_only_3d[smtk::mesh::Polygon]); - test(ctypes_only_3d[smtk::mesh::Tetrahedron]); - test(ctypes_only_3d[smtk::mesh::Pyramid]); - test(ctypes_only_3d[smtk::mesh::Wedge]); - test(ctypes_only_3d[smtk::mesh::Hexahedron]); - - test(!ctypes_only_1d[smtk::mesh::Vertex]); - test(ctypes_only_1d[smtk::mesh::Line]); - test(!ctypes_only_1d[smtk::mesh::Triangle]); - test(!ctypes_only_1d[smtk::mesh::Quad]); -} - -void verify_DimsType_usage() -{ - smtk::mesh::DimensionTypes dtypes_all_off; - smtk::mesh::DimensionTypes dtypes_all_on(std::string("1111")); - smtk::mesh::DimensionTypes dtypes_2d_only(4); - smtk::mesh::DimensionTypes dtypes_3d_only(std::string("1000")); - - test(!dtypes_all_off[smtk::mesh::Dims0]); - test(!dtypes_all_off[smtk::mesh::Dims1]); - test(!dtypes_all_off[smtk::mesh::Dims2]); - test(!dtypes_all_off[smtk::mesh::Dims3]); - - test(dtypes_all_on[smtk::mesh::Dims0]); - test(dtypes_all_on[smtk::mesh::Dims1]); - test(dtypes_all_on[smtk::mesh::Dims2]); - test(dtypes_all_on[smtk::mesh::Dims3]); - - test(!dtypes_2d_only[smtk::mesh::Dims0]); - test(!dtypes_2d_only[smtk::mesh::Dims1]); - test(dtypes_2d_only[smtk::mesh::Dims2]); - test(!dtypes_2d_only[smtk::mesh::Dims3]); - - test(!dtypes_3d_only[smtk::mesh::Dims0]); - test(!dtypes_3d_only[smtk::mesh::Dims1]); - test(!dtypes_3d_only[smtk::mesh::Dims2]); - test(dtypes_3d_only[smtk::mesh::Dims3]); -} -} // namespace - -int UnitTestQueryTypes(int /*unused*/, char** const /*unused*/) -{ - verify_dims_value(); - verify_CellTypes_usage(); - verify_DimsType_usage(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestReadWriteMeshResource.cxx b/smtk/mesh/testing/cxx/UnitTestReadWriteMeshResource.cxx deleted file mode 100644 index e81f2d0aeddfae53b1a117c023760437f357b16c..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestReadWriteMeshResource.cxx +++ /dev/null @@ -1,112 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ReferenceItem.h" -#include "smtk/attribute/ResourceItem.h" - -#include "smtk/common/Paths.h" - -#include "smtk/io/ReadMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/operators/ReadResource.h" -#include "smtk/mesh/operators/WriteResource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} -} // namespace - -int UnitTestReadWriteMeshResource(int /*unused*/, char** const /*unused*/) -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".smtk"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr); - test(mr->isValid(), "resource should be valid"); - test(!mr->isModified(), "resource shouldn't be marked as modified"); - - mr->setLocation(write_path); - - //write out the mesh. - auto writeOp = smtk::mesh::WriteResource::create(); - test(writeOp != nullptr, "failed to create write resource operation"); - test(writeOp->parameters() != nullptr, "failed to access write resource operation parameters"); - test( - writeOp->parameters()->associate(mr), - "failed to associate mesh resource to write resource operation"); - auto result = writeOp->operate(); - test( - result->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "write resource operation failed to operate"); - - auto readOp = smtk::mesh::ReadResource::create(); - test(readOp != nullptr, "failed to create read resource operation"); - test(readOp->parameters() != nullptr, "failed to access read resource operation parameters"); - test( - readOp->parameters()->findFile("filename")->setValue(write_path), - "failed to set file path for read resource operation"); - result = readOp->operate(); - test( - result->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "read resource operation failed to operate"); - - //reload the written file and verify the number of meshes are the same as the - //input mesh - smtk::mesh::ResourcePtr mr1 = std::dynamic_pointer_cast( - result->findResource("resourcesCreated")->value()); - test(mr1 != nullptr, "could not access read resource operation result"); - - //remove the files from disk - std::string meshFilename = smtk::common::Paths::directory(mr->location()) + "/" + - smtk::common::Paths::stem(mr->location()) + ".h5m"; - cleanup(write_path); - cleanup(meshFilename); - - //verify the meshes - test(mr1->isValid(), "resource should be valid"); - test(mr1->name() == mr->name()); - test(mr1->numberOfMeshes() == mr->numberOfMeshes()); - test(mr1->types() == mr->types()); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestReclassifyEdges.cxx b/smtk/mesh/testing/cxx/UnitTestReclassifyEdges.cxx deleted file mode 100644 index 8d728baf834ae9686007a6cf64787b06462f4aec..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestReclassifyEdges.cxx +++ /dev/null @@ -1,248 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ModelToMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/Reclassify.h" - -#include "smtk/model/EntityIterator.h" -#include "smtk/model/Face.h" -#include "smtk/model/Resource.h" -#include "smtk/model/Volume.h" -#include "smtk/model/json/jsonResource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" -#include "smtk/model/testing/cxx/helpers.h" - -#include -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -void create_simple_2d_model(smtk::model::ResourcePtr resource) -{ - std::string file_path(data_root); - file_path += "/model/2d/smtk/test2D.json"; - - std::ifstream file(file_path.c_str()); - - std::string json_str((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); - nlohmann::json json = nlohmann::json::parse(json_str); - - smtk::model::from_json(json, resource); - for (auto& tessPair : json["tessellations"]) - { - smtk::common::UUID id = tessPair[0]; - smtk::model::Tessellation tess = tessPair[1]; - resource->setTessellation(id, tess); - } - - resource->assignDefaultNames(); - - file.close(); -} - -void add_model_edge_and_vert( - smtk::model::ResourcePtr modelResource, - smtk::model::Edge& oe, - smtk::model::Edge& ne, - smtk::model::Vertex& nv) -{ - //verify that we only have a single model, that allows the subsequent logic - //to be valid - smtk::model::Models models = - modelResource->entitiesMatchingFlagsAs(smtk::model::MODEL_ENTITY); - test(models.size() == 1, "should only have a single model"); - smtk::model::Model& model = models[0]; - - //we need to find the edge whose vertices are: - // {3, 0, 0} - // {3, 5, 0} - //and whose tessellation has 5 points ( length of 15 ) - // - // because we are going to add a new model vertex at - // {0, 2, 0} - // and create a new edge - // - smtk::model::EntityRefs edges = - modelResource->entitiesMatchingFlagsAs(smtk::model::EDGE); - smtk::model::EntityIterator it; - it.traverse(edges.begin(), edges.end()); - for (it.begin(); !it.isAtEnd(); ++it) - { - smtk::model::Edge edge(modelResource, it->entity()); - smtk::model::Vertices verts = edge.vertices(); - - if (verts.size() != 2) - { //not the edge you are looking for - continue; - } - - smtk::model::Vertex v1(modelResource, verts[0].entity()); - smtk::model::Vertex v2(modelResource, verts[1].entity()); - - double* cv1 = v1.coordinates(); - double* cv2 = v2.coordinates(); - const smtk::model::Tessellation* tess = edge.gotMesh(); - - if ( - cv1[0] == 3.0 && cv1[1] == 0.0 && cv2[0] == 3.0 && cv2[1] == 5.0 && - tess->coords().size() == 15) - { - //mark this edge as our original edge - oe = edge; - - //create the new vertex - nv = modelResource->addVertex(); - model.addCell(nv); - - //vertex tess - smtk::model::Tessellation vertTess; - vertTess.addCoords(0, 2, 0); - vertTess.addPoint(0); - modelResource->setTessellationAndBoundingBox(nv.entity(), vertTess); - - ne = modelResource->addEdge(); - model.addCell(ne); - - //edge tess - smtk::model::Tessellation edgeTess; - edgeTess.addCoords(0, 2, 0); - edgeTess.addCoords(1, 0, 0); - edgeTess.addCoords(3, 0, 0); - edgeTess.addLine(0, 1); - edgeTess.addLine(1, 2); - modelResource->setTessellationAndBoundingBox(ne.entity(), edgeTess); - - break; - } - } -} - -struct xyz_view -{ - double* m_ptr{ nullptr }; - - xyz_view() = default; - xyz_view(double* ptr) - : m_ptr(ptr) - { - } - - //ignore z as our dataset is all axis aligned - bool operator<(const xyz_view& r) const - { - return m_ptr[0] != r.m_ptr[0] ? (m_ptr[0] < r.m_ptr[0]) : (m_ptr[1] < r.m_ptr[1]); - } -}; - -void all_points_are_valid(smtk::mesh::ResourcePtr meshResource) -{ - //no two points should be identical, that is our litmus test - //we know that we can't have duplicate points because - smtk::mesh::PointSet ps = meshResource->points(); - std::vector points(ps.size() * 3); - ps.get(points.data()); - - std::set unique_xyz; - for (std::size_t i = 0; i < ps.size(); ++i) - { - unique_xyz.insert(xyz_view(points.data() + i * 3)); - } - - test((ps.size() == unique_xyz.size()), "sizes should match"); -} - -void verify_split() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_2d_model(modelResource); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr mr = convert(modelResource); - - test(mr->isValid(), "mesh resource should be valid"); - test(mr->numberOfMeshes() == 21, "mesh resource should have 21 mesh elements"); - test(mr->points().size() == 32, "should have 32 points"); - test(mr->cells(smtk::mesh::Dims0).size() == 7, "should have 7 vertex cells"); - test(mr->cells(smtk::mesh::Dims1).size() == 32, "should have 32 edge cells"); - all_points_are_valid(mr); - - //we need to split the model first. - //this is done by manually doing the following. - //create a new model edge and model vertex - smtk::model::Edge originalEdge; - smtk::model::Edge newEdge; - smtk::model::Vertex promotedVertex; - add_model_edge_and_vert(modelResource, originalEdge, newEdge, promotedVertex); - - bool valid = smtk::mesh::utility::split(mr, originalEdge, newEdge, promotedVertex); - test(valid, "split should pass"); - - all_points_are_valid(mr); - test(mr->points().size() == 32, "should still have 32 points after split"); - test(mr->numberOfMeshes() == 23, "mesh resource should have 23 mesh elements after split"); - test(mr->cells(smtk::mesh::Dims0).size() == 8, "should now have 8 vertex cells"); - test(mr->cells(smtk::mesh::Dims1).size() == 32, "should have 32 edge cells"); -} - -void verify_merge() -{ - smtk::model::ResourcePtr modelResource = smtk::model::Resource::create(); - - create_simple_2d_model(modelResource); - - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr mr = convert(modelResource); - test(mr->isValid(), "mesh resource should be valid"); - test(mr->numberOfMeshes() == 21, "mesh resource should have 21 mesh elements"); - test(mr->points().size() == 32, "should have 32 points before split and merge"); - all_points_are_valid(mr); - - //we need to split the model first. - //this is done by manually doing the following. - //create a new model edge and model vertex - smtk::model::Edge originalEdge; - smtk::model::Edge newEdge; - smtk::model::Vertex promotedVertex; - add_model_edge_and_vert(modelResource, originalEdge, newEdge, promotedVertex); - - bool svalid = smtk::mesh::utility::split(mr, originalEdge, newEdge, promotedVertex); - test(svalid, "split should pass"); - bool mvalid = smtk::mesh::utility::merge(mr, promotedVertex, newEdge, originalEdge); - test(mvalid, "merge should pass"); - - all_points_are_valid(mr); - test(mr->points().size() == 32, "should have 32 points after split&merge"); - test(mr->numberOfMeshes() == 21, "mesh resource should have 23 mesh elements after split"); - test(mr->cells(smtk::mesh::Dims0).size() == 7, "should now have 7 vertex cells"); - test(mr->cells(smtk::mesh::Dims1).size() == 32, "should have 32 edge cells"); -} -} // namespace - -int UnitTestReclassifyEdges(int /*unused*/, char** const /*unused*/) -{ - verify_split(); - verify_merge(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestRemoveMeshes.cxx b/smtk/mesh/testing/cxx/UnitTestRemoveMeshes.cxx deleted file mode 100644 index 028d5af5212135cd03f01a7657931b91727859bb..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestRemoveMeshes.cxx +++ /dev/null @@ -1,273 +0,0 @@ - -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/model/EntityRef.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -smtk::mesh::ResourcePtr load_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "mesh resource should be valid"); - - return mr; -} - -void reset(const smtk::mesh::ResourcePtr& mr) -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - //reset the mesh by re-importing the file. - smtk::io::importMesh(file_path, mr); -} - -void verify_remove_empty_mesh(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numMeshesBeforeRemoval = mr->numberOfMeshes(); - - smtk::mesh::MeshSet emptyMeshSet(mr, 0, smtk::mesh::HandleRange()); - - const bool result = mr->removeMeshes(emptyMeshSet); - - test(result, "delete nothing is always true"); - test(!mr->isModified(), "deleting nothing should not change the modify flag"); - - test( - numMeshesBeforeRemoval == mr->numberOfMeshes(), - "deleting no meshes shouldn't modify number of meshes"); -} - -void verify_remove_mesh_from_other_resource(const smtk::mesh::ResourcePtr& mr) -{ - //make another mesh resource - smtk::mesh::ResourcePtr othermr = load_mesh(); - - const std::size_t numMeshesBeforeRemoval = mr->numberOfMeshes(); - const std::size_t numCellsBeforeRemoval = mr->cells().size(); - - smtk::mesh::MeshSet meshesFromOtherResource = othermr->meshes(); - const bool result = mr->removeMeshes(meshesFromOtherResource); - - test(!result, "can't remove meshes from the incorrect mesh resource"); - test(!mr->isModified(), "shouldn't be modified after an invalid removal"); - test(numMeshesBeforeRemoval == mr->numberOfMeshes()); - test(numCellsBeforeRemoval == mr->cells().size()); -} - -void verify_remove_invalid_meshes(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numMeshesBeforeRemoval = mr->numberOfMeshes(); - const std::size_t numCellsBeforeRemoval = mr->cells().size(); - - //roughly estimate the number of handles being used by the implemenation. - //this is numCells + 8 * numCells + numMeshes. The 8 * numCells is a standin - //for number of verts - const std::size_t numHandlesUsed = (mr->cells().size() * 9) + mr->numberOfMeshes(); - smtk::mesh::HandleRange invalidRange; - invalidRange.insert(smtk::mesh::HandleInterval(numHandlesUsed + 10, numHandlesUsed + 40)); - smtk::mesh::MeshSet invalidMeshIds = smtk::mesh::MeshSet(mr, 0, invalidRange); - - const bool result = mr->removeMeshes(invalidMeshIds); - - test(result, "deletion of non-existent cells, is equal to deleting an empty mesh"); - test(numMeshesBeforeRemoval == mr->numberOfMeshes()); - test(numCellsBeforeRemoval == mr->cells().size()); -} - -void verify_remove_already_removed_meshes(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numMeshesBeforeRemoval = mr->numberOfMeshes(); - const std::size_t numCellsBeforeRemoval = mr->cells().size(); - - //create a new mesh to be removed. - smtk::mesh::CellSet allNonVolumeCells = - smtk::mesh::set_difference(mr->cells(), mr->cells(smtk::mesh::Dims3)); - smtk::mesh::MeshSet newMesh = mr->createMesh(allNonVolumeCells); - - //while it is a meshset it should only have a single value - test(newMesh.size() == 1); - - const bool removedFirstTime = mr->removeMeshes(newMesh); - test(removedFirstTime, "should have no problem removing these meshes"); - - const bool removedSecondTime = mr->removeMeshes(newMesh); - test(!removedSecondTime, "should not be able to remove the same mesh twice"); - - test(numMeshesBeforeRemoval == mr->numberOfMeshes()); - test(numCellsBeforeRemoval == mr->cells().size()); - - reset(mr); -} - -void verify_remove_single_mesh(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numMeshesBeforeRemoval = mr->numberOfMeshes(); - const std::size_t numCellsBeforeRemoval = mr->cells().size(); - - //create a new mesh to be removed. - smtk::mesh::CellSet allNonVolumeCells = - smtk::mesh::set_difference(mr->cells(), mr->cells(smtk::mesh::Dims3)); - smtk::mesh::MeshSet newMesh = mr->createMesh(allNonVolumeCells); - - //while it is a meshset it should only have a single value - test(newMesh.size() == 1); - - const bool result = mr->removeMeshes(newMesh); - - test(result, "should have no problem removing these meshes"); - test(mr->isModified(), "should be modified after a valid removal"); - test(numMeshesBeforeRemoval == mr->numberOfMeshes()); - test(numCellsBeforeRemoval == mr->cells().size()); - - reset(mr); -} - -void verify_remove_multiple_meshes(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numMeshesBeforeRemoval = mr->numberOfMeshes(); - const std::size_t numCellsBeforeRemoval = mr->cells().size(); - - //create a new mesh to be removed. - smtk::mesh::CellSet allNonVolumeCells = - smtk::mesh::set_difference(mr->cells(), mr->cells(smtk::mesh::Dims3)); - smtk::mesh::MeshSet newMeshes = mr->createMesh(allNonVolumeCells); - - //create a second new mesh to be removed. - smtk::mesh::CellSet allVolumeCells = mr->cells(smtk::mesh::Dims3); - newMeshes.append(mr->createMesh(allVolumeCells)); - - //the meshset that we are deleting should have two elements - test(newMeshes.size() == 2); - - const bool result = mr->removeMeshes(newMeshes); - - test(result, "should have no problem removing these meshes"); - test(mr->isModified(), "should be modified after a valid removal"); - test(numMeshesBeforeRemoval == mr->numberOfMeshes()); - test(numCellsBeforeRemoval == mr->cells().size()); - - reset(mr); -} - -void verify_remove_all_meshes(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::MeshSet allMeshes = mr->meshes(); - const bool result = mr->removeMeshes(allMeshes); - - test(result, "deleted everything is always true"); - - test(0 == mr->numberOfMeshes(), "deleting all meshes should result in zero meshes"); - test(0 == mr->cells().size(), "deleting all meshes should result in zero cells"); - - test(mr->isModified(), "should be modified after a valid removal"); - - reset(mr); -} - -void verify_remove_meshes_removes_unused_cells(const smtk::mesh::ResourcePtr& mr) -{ - const std::size_t numMeshesBeforeRemoval = mr->numberOfMeshes(); - const std::size_t numCellsBeforeRemoval = mr->cells().size(); - - //find a grouping of meshes that are the only users of cells - //remove those meshes, and verify that those cells are deleted. - smtk::mesh::MeshSet meshesWithDim3 = mr->meshes(smtk::mesh::Dims3); - smtk::mesh::MeshSet otherMeshes = mr->meshes(smtk::mesh::Dims2); - otherMeshes.append(mr->meshes(smtk::mesh::Dims1)); - - //meshesWithOnlyDim3 will contain meshsets that are pure 3d cells - smtk::mesh::MeshSet onlyVolumeMeshes = smtk::mesh::set_difference(meshesWithDim3, otherMeshes); - - const std::size_t numVolumeMeshes = onlyVolumeMeshes.size(); - const std::size_t numVolumeCells = onlyVolumeMeshes.cells().size(); - - const bool result = mr->removeMeshes(onlyVolumeMeshes); - - test(result, "deleting all volume only meshes should work"); - test(mr->isModified(), "should be modified after a valid removal"); - - const std::size_t expectedNumberOfMeshes = numMeshesBeforeRemoval - numVolumeMeshes; - const std::size_t expectedNumberOfCells = numCellsBeforeRemoval - numVolumeCells; - - test(expectedNumberOfMeshes == mr->numberOfMeshes()); - test(expectedNumberOfCells == mr->cells().size()); - - reset(mr); -} - -void verify_remove_verts_with_model_association(const smtk::mesh::ResourcePtr& mr) -{ - //make a mesh that only holds verts - std::size_t num_meshes = mr->meshes().size(); - std::size_t num_cells = mr->cells().size(); - - smtk::mesh::CellSet vertCells = mr->cells(smtk::mesh::Dims0); - smtk::mesh::MeshSet vertMesh = mr->createMesh(vertCells); - - test((num_meshes == mr->meshes().size() - 1), ""); - test((num_cells == (mr->cells().size())), ""); - - //add a model association to the vert mesh - smtk::common::UUID entity = smtk::common::UUID::random(); - smtk::model::EntityRef eref; - eref.setEntity(entity); - mr->setAssociation(eref, vertMesh); - - //verify we have an association - std::size_t numAssoc = mr->findAssociatedMeshes(eref).size(); - test(numAssoc == 1, ""); - - bool removed = mr->removeMeshes(vertMesh); - - //verify the association is removed - numAssoc = mr->findAssociatedMeshes(eref).size(); - test(numAssoc == 0, ""); - - test(removed, "should be able to remove mesh of just verts"); - test((num_meshes == mr->meshes().size()), ""); - test((num_cells == mr->cells().size()), ""); - - reset(mr); -} -} // namespace - -int UnitTestRemoveMeshes(int /*unused*/, char** const /*unused*/) -{ - smtk::mesh::ResourcePtr mr = load_mesh(); - - verify_remove_empty_mesh(mr); - verify_remove_mesh_from_other_resource(mr); - verify_remove_invalid_meshes(mr); - verify_remove_already_removed_meshes(mr); - - verify_remove_single_mesh(mr); - verify_remove_multiple_meshes(mr); - - verify_remove_all_meshes(mr); - verify_remove_meshes_removes_unused_cells(mr); - - verify_remove_verts_with_model_association(mr); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestResource.cxx b/smtk/mesh/testing/cxx/UnitTestResource.cxx deleted file mode 100644 index 1b18c67f8418eaab65ca86cc4006e49f2658f1d5..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestResource.cxx +++ /dev/null @@ -1,111 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/json/Interface.h" -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -void verify_valid_constructor() -{ - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(); - - test(resource->isValid(), "resource should be valid"); - test(!resource->isModified(), "resource shouldn't be marked as modified"); - - smtk::common::UUID uid = resource->entity(); - test((uid != smtk::common::UUID::null()), "resource uuid should be valid"); - - //verify the name - test(resource->name().empty()); - resource->setName("example"); - test((resource->name() == std::string("example"))); - - //verify the interface name - test(!resource->interfaceName().empty()); - - //verify the read and write location - test((resource->readLocation() == std::string())); - test((resource->writeLocation() == std::string())); -} - -void verify_resource_info_moab() -{ - smtk::mesh::InterfacePtr iface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - - smtk::common::UUID uid = resource->entity(); - test((uid != smtk::common::UUID::null()), "resource uuid should be valid"); - - //verify the name - test(resource->name().empty()); - resource->setName("example"); - test((resource->name() == std::string("example"))); - - //verify the interface name - test(!resource->interfaceName().empty()); - test((resource->interfaceName() == std::string("moab"))); - - //verify the read and write location - test((resource->readLocation() == std::string())); - test((resource->writeLocation() == std::string())); - - //set and check read/write location - resource->writeLocation("foo"); - test((resource->readLocation() == std::string())); - test((resource->writeLocation() == std::string("foo"))); -} - -void verify_resource_info_json() -{ - smtk::mesh::InterfacePtr iface = smtk::mesh::json::make_interface(); - smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(iface); - - test(resource->isValid(), "resource should be valid"); - - smtk::common::UUID uid = resource->entity(); - test((uid != smtk::common::UUID::null()), "resource uuid should be valid"); - - //verify the name - test(resource->name().empty()); - resource->setName("example"); - test((resource->name() == std::string("example"))); - - //verify the interface name - test(!resource->interfaceName().empty()); - test((resource->interfaceName() == std::string("json"))); - - //verify the read and write location - test((resource->readLocation() == std::string())); - test((resource->writeLocation() == std::string())); - - //set and check read/write location - resource->writeLocation("foo"); - test((resource->readLocation() == std::string())); - test((resource->writeLocation() == std::string("foo"))); -} -} // namespace - -int UnitTestResource(int /*unused*/, char** const /*unused*/) -{ - verify_valid_constructor(); - - verify_resource_info_moab(); - verify_resource_info_json(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestTypeSet.cxx b/smtk/mesh/testing/cxx/UnitTestTypeSet.cxx deleted file mode 100644 index 261e8849f73e0fb5216395fe5dafacbfcf089d0b..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestTypeSet.cxx +++ /dev/null @@ -1,119 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/core/TypeSet.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -void verify_basic_typeset() -{ - smtk::mesh::TypeSet t_set; - test(!t_set.hasMeshes()); - test(!t_set.hasCells()); - - //verify all cell types are zero - for (int i = 0; i < smtk::mesh::CellType_MAX; ++i) - { - test(!t_set.hasCell(static_cast(i))); - } - - //verify all dim types are zero - for (int i = 0; i < 3; ++i) - { - test(!t_set.hasDimension(static_cast(i))); - } -} - -void verify_typeset_constructors() -{ - //just verify that all the copy constructors work - smtk::mesh::TypeSet t_set(smtk::mesh::CellTypes(), false, true); //has cells only - smtk::mesh::TypeSet t_set2(t_set); - smtk::mesh::TypeSet t_set3 = t_set2; - - test(!t_set3.hasMeshes()); - test(t_set3.hasCells()); - - //verify all cell types are zero - for (int i = 0; i < smtk::mesh::CellType_MAX; ++i) - { - test(!t_set.hasCell(static_cast(i))); - } - - //verify all dim types are zero - for (int i = 0; i < 3; ++i) - { - test(!t_set.hasDimension(static_cast(i))); - } -} - -void verify_typeset_cellTypes() -{ - //now verify a typeset with a couple things set - smtk::mesh::TypeSet t_set( - smtk::mesh::CellTypes(std::string("11100")), //triangle,quad,polygon - false, - true); //has cells only - - const smtk::mesh::CellTypes correct_types(std::string("11100")); - - test(correct_types == t_set.cellTypes()); -} - -void verify_typeset_with_cells_and_dims() -{ - //now verify a typeset with a couple things set - smtk::mesh::TypeSet t_set( - smtk::mesh::CellTypes(std::string("11100")), //triangle,quad,polygon - false, - true); //has cells only - - test(!t_set.hasMeshes()); - test(t_set.hasCells()); - - //verify all only 2d cells are valid - for (int i = 0; i < smtk::mesh::CellType_MAX; ++i) - { - bool expected_result = false; - smtk::mesh::CellType currentCellType = static_cast(i); - if (currentCellType >= smtk::mesh::Triangle && currentCellType <= smtk::mesh::Polygon) - { - expected_result = true; - } - - const bool result = t_set.hasCell(currentCellType); - test(result == expected_result); - } - - //verify only 2d only is true - test(!t_set.hasDimension(smtk::mesh::Dims0)); - test(!t_set.hasDimension(smtk::mesh::Dims1)); - test(t_set.hasDimension(smtk::mesh::Dims2)); - test(!t_set.hasDimension(smtk::mesh::Dims3)); -} -} // namespace - -int UnitTestTypeSet(int /*unused*/, char** const /*unused*/) -{ - //first lets test the very basic interactions. - verify_basic_typeset(); - - verify_typeset_constructors(); - verify_typeset_cellTypes(); - verify_typeset_with_cells_and_dims(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestTypeSetFromData.cxx b/smtk/mesh/testing/cxx/UnitTestTypeSetFromData.cxx deleted file mode 100644 index eb1eb3ad0e5f8f1120cffa56b98d8260f9e7e6b4..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestTypeSetFromData.cxx +++ /dev/null @@ -1,158 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/io/ImportMesh.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -smtk::mesh::ResourcePtr load_hex_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - return mr; -} - -smtk::mesh::ResourcePtr load_tet_mesh() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/64bricks_12ktet.h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - smtk::io::importMesh(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - return mr; -} - -void verify_hex_typeset_queries(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::TypeSet types = mr->types(); - - //to begin with TypeSet will only look at the fairly basic information - test(types.hasCells(), "This resource should have cells"); - test(types.hasMeshes(), "This resource should have meshes"); - - //now lets make sure we get the correct result for the dimensions - //that this resource has - - //correct dims - test(types.hasDimension(smtk::mesh::Dims0)); - test(types.hasDimension(smtk::mesh::Dims1)); - test(types.hasDimension(smtk::mesh::Dims2)); - test(types.hasDimension(smtk::mesh::Dims3)); - - //now lets make sure we get the correct result for the type of cells - //that this resource holds: - // vertex, lines, quads, hexs - test(types.hasCell(smtk::mesh::Vertex)); - - test(types.hasCell(smtk::mesh::Line)); - - test(!types.hasCell(smtk::mesh::Triangle)); - test(types.hasCell(smtk::mesh::Quad)); - test(!types.hasCell(smtk::mesh::Polygon)); - - test(!types.hasCell(smtk::mesh::Tetrahedron)); - test(!types.hasCell(smtk::mesh::Pyramid)); - test(!types.hasCell(smtk::mesh::Wedge)); - test(types.hasCell(smtk::mesh::Hexahedron)); - - smtk::mesh::MeshSet hexs = mr->meshes(smtk::mesh::Dims3); - smtk::mesh::TypeSet hexTypes = hexs.types(); - - test(hexTypes.hasMeshes()); - test(hexTypes.hasCell(smtk::mesh::Hexahedron)); - test(hexTypes.hasDimension(smtk::mesh::Dims3)); - test(!hexTypes.hasDimension(smtk::mesh::Dims2)); - test(!hexTypes.hasDimension(smtk::mesh::Dims1)); - test(!hexTypes.hasDimension(smtk::mesh::Dims0)); -} - -void verify_tet_typeset_queries(const smtk::mesh::ResourcePtr& mr) -{ - smtk::mesh::TypeSet types = mr->types(); - - //to begin with TypeSet will only look at the fairly basic information - test(types.hasCells(), "This resource should have cells"); - test(types.hasMeshes(), "This resource should have meshes"); - - //now lets make sure we get the correct result for the dimensions - //that this resource has - - //correct dims - test(types.hasDimension(smtk::mesh::Dims0)); - test(types.hasDimension(smtk::mesh::Dims1)); - test(types.hasDimension(smtk::mesh::Dims2)); - test(types.hasDimension(smtk::mesh::Dims3)); - - //now lets make sure we get the correct result for the type of cells - //that this resource holds: - // vertex, lines, triangles, tets - test(types.hasCell(smtk::mesh::Vertex)); - - test(types.hasCell(smtk::mesh::Line)); - - test(types.hasCell(smtk::mesh::Triangle)); - test(!types.hasCell(smtk::mesh::Quad)); - test(!types.hasCell(smtk::mesh::Polygon)); - - test(types.hasCell(smtk::mesh::Tetrahedron)); - test(!types.hasCell(smtk::mesh::Pyramid)); - test(!types.hasCell(smtk::mesh::Wedge)); - test(!types.hasCell(smtk::mesh::Hexahedron)); - - //Unlike the hex mesh, the tet mesh has all the cell types mixed - //into a single meshset, so when we ask for meshsets with cells of - //dimension 3 it also has cells of other dimensions - smtk::mesh::MeshSet tets = mr->meshes(smtk::mesh::Dims3); - smtk::mesh::TypeSet tetTypes = tets.types(); - - test(tetTypes.hasMeshes()); - test(tetTypes.hasCell(smtk::mesh::Tetrahedron)); - test(tetTypes.hasDimension(smtk::mesh::Dims3)); - test(tetTypes.hasDimension(smtk::mesh::Dims2)); - test(tetTypes.hasDimension(smtk::mesh::Dims1)); - test(tetTypes.hasDimension(smtk::mesh::Dims0)); - - //extract only the tet cells from the mixed type meshset - smtk::mesh::CellSet tetCells = tets.cells(smtk::mesh::Dims3); - smtk::mesh::TypeSet tetCTypes = tetCells.types(); - - test(!tetCTypes.hasMeshes()); - test(tetCTypes.hasCell(smtk::mesh::Tetrahedron)); - test(tetCTypes.hasDimension(smtk::mesh::Dims3)); - test(!tetCTypes.hasDimension(smtk::mesh::Dims2)); - test(!tetCTypes.hasDimension(smtk::mesh::Dims1)); - test(!tetCTypes.hasDimension(smtk::mesh::Dims0)); -} -} // namespace - -int UnitTestTypeSetFromData(int /*unused*/, char** const /*unused*/) -{ - smtk::mesh::ResourcePtr hexMeshResource = load_hex_mesh(); - verify_hex_typeset_queries(hexMeshResource); - - smtk::mesh::ResourcePtr tetMeshResource = load_tet_mesh(); - verify_tet_typeset_queries(tetMeshResource); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/UnitTestWriteMesh.cxx b/smtk/mesh/testing/cxx/UnitTestWriteMesh.cxx deleted file mode 100644 index 363610ab5c670570425fd08ac794f5c919e77c8b..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/UnitTestWriteMesh.cxx +++ /dev/null @@ -1,488 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ReferenceItem.h" - -#include "smtk/common/UUID.h" - -#include "smtk/io/ReadMesh.h" -#include "smtk/io/WriteMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/moab/Interface.h" - -#include "smtk/mesh/operators/Write.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ - -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -void verify_write_empty_resource() -{ - std::string file_path(data_root); - file_path += "/mesh/output.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - test(mr->isValid(), "empty resource is empty"); - - smtk::io::WriteMesh write; - bool result = write(write_path, mr); - - //before we verify if the write was good, first remove the output file - cleanup(write_path); - test(result, "Wrote empty resource to disk"); -} - -void verify_write_null_resource() -{ - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - //use a null resource ptr - smtk::mesh::ResourcePtr mr; - - smtk::io::WriteMesh write; - bool result = write(write_path, mr); - - //before we verify if the write was good, first remove the output file - cleanup(write_path); - - test(!result, "Can't save null resource to disk"); -} - -void verify_write_valid_resource_hdf5() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr); - test(mr->isValid(), "resource should be valid"); - test(!mr->isModified(), "resource shouldn't be marked as modified"); - - //write out the mesh. - smtk::io::WriteMesh write; - bool result = write(write_path, mr); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out a valid hdf5 resource"); - } - - //reload the written file and verify the number of meshes are the same as the - //input mesh - smtk::mesh::ResourcePtr mr1 = smtk::mesh::Resource::create(); - read(write_path, mr1); - test(!mr1->isModified(), "resource shouldn't be marked as modified"); - - //remove the file from disk - cleanup(write_path); - - //verify the meshes - test(mr1->isValid(), "resource should be valid"); - test(mr1->name() == mr->name()); - test(mr1->numberOfMeshes() == mr->numberOfMeshes()); - test(mr1->types() == mr->types()); -} - -void verify_write_valid_resource_exodus() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".exo"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - //write out the mesh. - smtk::io::WriteMesh write; - bool result = write(write_path, mr); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out a valid exodus resource"); - } - - //When exporting as an exodus file we only write out the volume elements - //so that is what we should verify are the same - smtk::mesh::ResourcePtr mr1 = smtk::mesh::Resource::create(); - read(write_path, mr1); - - //remove the file from disk - cleanup(write_path); - - //verify the meshes - test(mr1->isValid(), "resource should be valid"); - test(mr1->name() == mr->name()); - - test(mr1->meshes(smtk::mesh::Dims3).size() == mr->meshes(smtk::mesh::Dims3).size()); - test(mr1->cells(smtk::mesh::Dims3).size() == mr->cells(smtk::mesh::Dims3).size()); -} - -void verify_write_valid_resource_using_write_path() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - smtk::mesh::InterfacePtr interface = smtk::mesh::moab::make_interface(); - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = read(file_path, interface); - test(mr->isValid(), "resource should be valid"); - - test(mr->readLocation() == file_path, "readLocation should match file_path"); - - mr->writeLocation(write_path); - test(mr->writeLocation() == write_path, "writeLocation should match write_path"); - test(!mr->isModified(), "changing write path shouldn't change modified flag"); - - //write out the mesh. - smtk::io::WriteMesh write; - bool result = write(mr); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out a valid hdf5 resource"); - } - - //reload the written file and verify the number of meshes are the same as the - //input mesh - smtk::mesh::ResourcePtr mr1 = smtk::mesh::Resource::create(); - read(write_path, mr1); - - //remove the file from disk - cleanup(write_path); - - //verify the meshes - test(mr1->isValid(), "resource should be valid"); - test(mr1->name() == mr->name()); - test(mr1->numberOfMeshes() == mr->numberOfMeshes()); - test(mr1->types() == mr->types()); -} - -void verify_write_valid_resource_using_functions() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - smtk::mesh::InterfacePtr interface = smtk::mesh::moab::make_interface(); - smtk::mesh::ResourcePtr mr = smtk::io::readMesh(file_path, interface); - test(mr->isValid(), "resource should be valid"); - - test(mr->readLocation() == file_path, "readLocation should match file_path"); - - mr->writeLocation(write_path); - test(mr->writeLocation() == write_path, "writeLocation should match write_path"); - test(!mr->isModified(), "changing write path shouldn't change modified flag"); - - //write out the mesh. - bool result = smtk::io::writeMesh(mr); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out a valid hdf5 resource"); - } - - //reload the written file and verify the number of meshes are the same as the - //input mesh - smtk::mesh::ResourcePtr mr1 = smtk::mesh::Resource::create(); - smtk::io::readMesh(write_path, mr1); - - //remove the file from disk - cleanup(write_path); - - //verify the meshes - test(mr1->isValid(), "resource should be valid"); - test(mr1->name() == mr->name()); - test(mr1->numberOfMeshes() == mr->numberOfMeshes()); - test(mr1->types() == mr->types()); -} - -void verify_write_onlyDomain() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/64bricks_12ktet.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - //write out the mesh. - smtk::io::WriteMesh write; - bool result = write(write_path, mr, smtk::io::mesh::Subset::OnlyDomain); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out only Material"); - } - - //reload the written file and verify the number of meshes are the same as the - //input mesh - smtk::mesh::ResourcePtr mr1 = smtk::mesh::Resource::create(); - read(write_path, mr1); - smtk::mesh::ResourcePtr mr2 = smtk::mesh::Resource::create(); - read(file_path, mr2, smtk::io::mesh::Subset::OnlyDomain); - - // remove the file from disk - cleanup(write_path); - - // //verify the meshes - test(mr1->isValid(), "resource should be valid"); - test(mr1->name() == mr2->name()); - //need to dig into why we are getting a meshset on extraction that is not - //part of the set - test(mr1->cells().size() == mr2->cells().size()); - test(mr1->pointConnectivity().size() == mr2->pointConnectivity().size()); - test(mr1->types() == mr2->types()); -} - -void verify_write_onlyNeumann() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/64bricks_12ktet.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - //write out the mesh. - smtk::io::WriteMesh write; - bool result = write(write_path, mr, smtk::io::mesh::Subset::OnlyNeumann); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out only Neumann"); - } - - //reload the written file and verify the number of meshes are the same as the - //input mesh - smtk::mesh::ResourcePtr mr1 = smtk::mesh::Resource::create(); - read(write_path, mr1); - smtk::mesh::ResourcePtr mr2 = smtk::mesh::Resource::create(); - read(file_path, mr2, smtk::io::mesh::Subset::OnlyNeumann); - - // remove the file from disk - cleanup(write_path); - - // //verify the meshes - test(mr1->isValid(), "resource should be valid"); - test(mr1->name() == mr2->name()); - //need to dig into why we are getting a meshset on extraction that is not - //part of the set - test(mr1->numberOfMeshes() + 1 == mr2->numberOfMeshes()); - test(mr1->cells().size() == mr2->cells().size()); - test(mr1->pointConnectivity().size() == mr2->pointConnectivity().size()); - test(mr1->types() == mr2->types()); -} - -void verify_write_onlyDirichlet() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/64bricks_12ktet.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr); - test(mr->isValid(), "resource should be valid"); - - //write out the mesh. - smtk::io::WriteMesh write; - bool result = write(write_path, mr, smtk::io::mesh::Subset::OnlyDirichlet); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out only Dirichlet"); - } - - //reload the written file and verify the number of meshes are the same as the - //input mesh - smtk::mesh::ResourcePtr mr1 = smtk::mesh::Resource::create(); - read(write_path, mr1); - smtk::mesh::ResourcePtr mr2 = smtk::mesh::Resource::create(); - read(file_path, mr2, smtk::io::mesh::Subset::OnlyDirichlet); - - //remove the file from disk - cleanup(write_path); - - //verify the meshes - test(mr1->isValid(), "resource should be valid"); - test(mr1->name() == mr2->name()); - //need to dig into why we are getting a meshset on extraction that is not - //part of the set - test(mr1->numberOfMeshes() + 1 == mr2->numberOfMeshes()); - test(mr1->cells().size() == mr2->cells().size()); - test(mr1->pointConnectivity().size() == mr2->pointConnectivity().size()); - test(mr1->types() == mr2->types()); -} - -void verify_write_clears_modified_flag() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/64bricks_12ktet.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr); - test(mr->isValid(), "resource should be valid"); - test(!mr->isModified(), "resource loaded from disk shouldn't be modified"); - - smtk::mesh::MeshSet meshes3D = mr->meshes(smtk::mesh::Dims3); - smtk::mesh::MeshSet shell = meshes3D.extractShell(); - test(mr->isModified(), "extracting the shell should mark the resource as modified"); - - //write out the mesh. - smtk::io::WriteMesh write; - bool result = write(write_path, mr); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out the mesh"); - } - - test(!mr->isModified(), "after a write the resource should not be modified"); - - //now remove the shell, and verify the mesh is again marked as modified - mr->removeMeshes(shell); - test(mr->isModified(), "after mesh removal the resource should be modified"); - - //write out the mesh again - result = write(write_path, mr); - if (!result) - { - cleanup(write_path); - test(result, "failed to properly write out the mesh"); - } - test(!mr->isModified(), "after a write the resource should not be modified"); - - //remove the file from disk - cleanup(write_path); -} - -void verify_write_operation() -{ - std::string file_path(data_root); - file_path += "/mesh/3d/twoassm_out.h5m"; - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr mr = smtk::mesh::Resource::create(); - read(file_path, mr); - test(mr->isValid(), "resource should be valid"); - test(!mr->isModified(), "resource shouldn't be marked as modified"); - - //write out the mesh. - auto writeOp = smtk::mesh::Write::create(); - test(writeOp != nullptr, "failed to create write operation"); - test(writeOp->parameters() != nullptr, "failed to access write operation parameters"); - test( - writeOp->parameters()->associate(mr), "failed to associate mesh resource to write operation"); - test( - writeOp->parameters()->findFile("filename")->setValue(write_path), - "failed to set file path for write operation"); - auto result = writeOp->operate(); - test( - result->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "write operation failed to operate"); - - //reload the written file and verify the number of meshes are the same as the - //input mesh - smtk::mesh::ResourcePtr mr1 = smtk::mesh::Resource::create(); - read(write_path, mr1); - test(!mr1->isModified(), "resource shouldn't be marked as modified"); - - //remove the file from disk - cleanup(write_path); - - //verify the meshes - test(mr1->isValid(), "resource should be valid"); - test(mr1->name() == mr->name()); - test(mr1->numberOfMeshes() == mr->numberOfMeshes()); - test(mr1->types() == mr->types()); -} -} // namespace - -int UnitTestWriteMesh(int /*unused*/, char** const /*unused*/) -{ - verify_write_empty_resource(); - verify_write_null_resource(); - - verify_write_valid_resource_hdf5(); - verify_write_valid_resource_exodus(); - verify_write_valid_resource_using_write_path(); - verify_write_valid_resource_using_functions(); - - verify_write_onlyDomain(); - verify_write_onlyNeumann(); - verify_write_onlyDirichlet(); - - verify_write_clears_modified_flag(); - - verify_write_operation(); - - return 0; -} diff --git a/smtk/mesh/testing/cxx/helpers.h b/smtk/mesh/testing/cxx/helpers.h deleted file mode 100644 index 75792bed4149c9d30ea4089bbf5928ba9a2daa2f..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/cxx/helpers.h +++ /dev/null @@ -1,210 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= - -#ifndef smtk_mesh_testing_cxx_helpers_h -#define smtk_mesh_testing_cxx_helpers_h - -#include "smtk/mesh/core/CellTraits.h" - -#include "smtk/common/testing/cxx/helpers.h" -#include - -namespace smtk -{ -namespace mesh -{ -namespace testing -{ - -struct Testing -{ - template - struct InternalPrintOnInvoke - { - InternalPrintOnInvoke(FunctionType function, std::string toprint) - : Function(function) - , ToPrint(toprint) - { - } - template - void operator()(T t) - { - std::cout << this->ToPrint << std::endl; - this->Function(t); - } - - private: - FunctionType Function; - std::string ToPrint; - }; - - struct CellCheckAll - { - template - void operator()(Tag t, Functor function) const - { - function(t); - } - }; - - struct CellCheckFixedTypes - { - template - void operator()(Tag t, Functor function) const - { - this->Do(typename smtk::mesh::CellTraits::PointNumberTag(), t, function); - } - - private: - template - void Do(Tag, T, const Functor&) const - { - } - - template - void Do(smtk::mesh::CellFixedPointNumberTag, Tag t, Functor function) const - { - function(t); - } - }; -}; - -/// Runs templated \p function on all the cell tags defined in smtk::mesh. This is -/// helpful to test templated functions that should work on all cell types. -/// If the function is supposed to work on some subset of cell types, then \p -/// check can be set to restrict the types used. This Testing class contains -/// several helpful check functors. -/// -template -static void TryAllCells(FunctionType function, CheckType check) -{ - check( - smtk::mesh::CellHexahedron(), - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellHexahedron ******************")); - - check( - smtk::mesh::CellLine(), - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellLine *****************")); - - check( - smtk::mesh::CellPolygon(), - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellPolygon *******************")); - - check( - smtk::mesh::CellPyramid(), - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellPyramid ***************")); - - check( - smtk::mesh::CellQuad(), - Testing::InternalPrintOnInvoke(function, "*** smtk::mesh::CellQuad **********")); - - check( - smtk::mesh::CellTetrahedron(), - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellTetrahedron **********")); - - check( - smtk::mesh::CellTriangle(), - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellTriangle *************")); - - check( - smtk::mesh::CellVertex(), - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellVertex ************")); - - check( - smtk::mesh::CellWedge(), - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellWedge ******************")); -} - -/// Runs templated \p function on all the cell tags defined in smtk::mesh. This is -/// helpful to test templated functions that should work on all cell types. -/// If the function is supposed to work on some subset of cell types, then \p -/// check can be set to restrict the types used. This Testing class contains -/// several helpful check functors. -/// -template -static void TryAllCellEnums(FunctionType function, CheckType check) -{ - check( - smtk::mesh::Hexahedron, - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellHexahedron ******************")); - - check( - smtk::mesh::Line, - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellLine *****************")); - - check( - smtk::mesh::Polygon, - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellPolygon *******************")); - - check( - smtk::mesh::Pyramid, - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellPyramid ***************")); - - check( - smtk::mesh::Quad, - Testing::InternalPrintOnInvoke(function, "*** smtk::mesh::CellQuad **********")); - - check( - smtk::mesh::Tetrahedron, - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellTetrahedron **********")); - - check( - smtk::mesh::Triangle, - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellTriangle *************")); - - check( - smtk::mesh::Vertex, - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellVertex ************")); - - check( - smtk::mesh::Wedge, - Testing::InternalPrintOnInvoke( - function, "*** smtk::mesh::CellWedge ******************")); -} - -template -static void TryAllCells(FunctionType function) -{ - TryAllCells(function, Testing::CellCheckAll()); -} - -template -static void TryAllCellEnums(FunctionType function) -{ - TryAllCellEnums(function, Testing::CellCheckAll()); -} - -template -static void TryFIXEDCells(FunctionType function) -{ - TryAllCells(function, Testing::CellCheckFixedTypes()); -} -} // namespace testing -} // namespace mesh -} // namespace smtk - -#endif //__smtk_mesh_testing_cxx_helpers_h diff --git a/smtk/mesh/testing/python/CMakeLists.txt b/smtk/mesh/testing/python/CMakeLists.txt deleted file mode 100644 index 8d1594ef00134b8f2ea02d49a05473764fdb1a25..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ - - -# tests that require SMTK_DATA_DIR -set(smtkMeshPythonDataTests - extractTessellation - cellField - meshMetrics - pointField - simple - iterateMesh -) - -if(SMTK_ENABLE_MESH_SESSION AND SMTK_ENABLE_VTK_SUPPORT) - list(APPEND smtkMeshPythonDataTests - snapPointsToSurface - ) - if (SMTK_ENABLE_GDAL_SUPPORT) - list(APPEND smtkMeshPythonDataTests - elevateMeshOnStructuredGrid - ) - endif() -endif() - -#only run these tests if we have a valid data directory and we have a moab -#built with hdf5 -if (SMTK_DATA_DIR) - foreach (test ${smtkMeshPythonDataTests}) - smtk_add_test_python(${test}Py ${test}.py - --data-dir=${SMTK_DATA_DIR} ) - set_tests_properties( ${test}Py PROPERTIES LABELS "Mesh" ) - endforeach() -endif() - -#if (SMTK_ENABLE_POLYGON_SESSION) -# add_executable(testRuntimePyOperation TestRuntimePyOperation.cxx) -# target_compile_definitions(testRuntimePyOperation PRIVATE "SMTK_DATA_DIR=\"${SMTK_DATA_DIR}\"") -# target_link_libraries(testRuntimePyOperation smtkCore smtkDelaunayExt smtkPolygonSession ${Boost_LIBRARIES}) -# add_test(NAME testMyElevateMesh -# COMMAND $ -# "${CMAKE_CURRENT_SOURCE_DIR}/my_elevate_mesh.py") -# set_tests_properties(testMyElevateMesh PROPERTIES LABELS "Mesh" ENVIRONMENT PYTHONDONTWRITEBYTECODE=1) -#endif() diff --git a/smtk/mesh/testing/python/TestRuntimePyOperation.cxx b/smtk/mesh/testing/python/TestRuntimePyOperation.cxx deleted file mode 100644 index 311872eee0237e92df2db4d749df7d05f43b52e6..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/TestRuntimePyOperation.cxx +++ /dev/null @@ -1,239 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ModelEntityItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/session/polygon/Operation.h" -#include "smtk/session/polygon/Session.h" - -#include "smtk/common/PythonInterpreter.h" - -#include "smtk/io/ExportMesh.h" - -#include "smtk/model/EntityIterator.h" -#include "smtk/model/EntityPhrase.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" -#include "smtk/model/Resource.h" -#include "smtk/model/SimpleModelSubphrases.h" -#include "smtk/model/Tessellation.h" - -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include - -namespace -{ -//SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; - -void removeRefsWithoutTess(smtk::model::EntityRefs& ents) -{ - smtk::model::EntityIterator it; - it.traverse(ents.begin(), ents.end(), smtk::model::ITERATE_BARE); - std::vector withoutTess; - for (it.begin(); !it.isAtEnd(); ++it) - { - if (!it->hasTessellation()) - { - withoutTess.push_back(it.current()); - } - } - - typedef std::vector::const_iterator c_it; - for (c_it i = withoutTess.begin(); i < withoutTess.end(); ++i) - { - ents.erase(*i); - } -} - -class ValidatePoints : public smtk::mesh::PointForEach -{ -public: - ValidatePoints(std::size_t nBins, double min, double max) - : m_min(min) - , m_max(max) - { - m_hist.resize(nBins, 0); - } - - void forPoints(const smtk::mesh::HandleRange& pointIds, std::vector& xyz, bool&) override - { - typedef smtk::mesh::HandleRange::const_iterator c_it; - int counter = 0; - for (c_it i = pointIds.begin(); i != pointIds.end(); ++i, counter += 3) - { - std::size_t bin = xyz[counter + 2] < m_min ? 0 - : xyz[counter + 2] > m_max - ? m_hist.size() - 1 - : static_cast((xyz[counter + 2] - m_min) / (m_max - m_min) * m_hist.size()); - ++m_hist[bin]; - } - } - - const std::vector& histogram() const { return m_hist; } - -private: - std::vector m_hist; - double m_min; - double m_max; -}; -} // namespace - -int main(int argc, char* argv[]) -{ - if (argc == 1) - { - std::cout << "TestRuntimePyOperation " << std::endl; - return 1; - } - - ::boost::filesystem::path path(argv[1]); - if (!::boost::filesystem::is_regular_file(path)) - { - std::cout << "Cannot find " << argv[1] << std::endl; - return 1; - } - - smtk::model::ResourcePtr resource = smtk::model::Resource::create(); - smtk::mesh::ManagerPtr meshManager = resource->meshes(); - - std::cout << "Available sessions\n"; - smtk::model::StringList sessions = resource->sessionTypeNames(); - for (smtk::model::StringList::iterator it = sessions.begin(); it != sessions.end(); ++it) - std::cout << " " << *it << "\n"; - std::cout << "\n"; - - smtk::session::polygon::Session::Ptr session = smtk::session::polygon::Session::create(); - resource->registerSession(session); - - std::cout << "Available operators\n"; - smtk::model::StringList opnames = session->operatorNames(); - for (smtk::model::StringList::iterator it = opnames.begin(); it != opnames.end(); ++it) - std::cout << " " << *it << "\n"; - std::cout << "\n"; - - { - smtk::operation::Operation::Ptr op = session->op("import python operator"); - - op->findFile("filename")->setValue(::boost::filesystem::absolute(path).string().c_str()); - - smtk::operation::OperationResult result = op->operate(); - if (result->findInt("outcome")->value() != smtk::operation::Operation::OPERATION_SUCCEEDED) - { - std::cerr << "Could not load smtk model!\n"; - return 1; - } - } - - smtk::model::Model model; - { - std::string file_path(data_root); - file_path += "/mesh/2d/boxWithHole.smtk"; - - std::ifstream file(file_path.c_str()); - if (file.good()) - { //just make sure the file exists - file.close(); - - smtk::operation::Operation::Ptr op = session->op("load smtk model"); - - op->findFile("filename")->setValue(file_path.c_str()); - smtk::operation::OperationResult result = op->operate(); - if (result->findInt("outcome")->value() != smtk::operation::Operation::OPERATION_SUCCEEDED) - { - std::cerr << "Could not load smtk model!\n"; - return 1; - } - model = result->findModelEntity("mesh_created")->value(); - } - } - - smtk::mesh::ResourcePtr meshResource; - { - smtk::model::EntityRefs currentEnts = - resource->entitiesMatchingFlagsAs(smtk::model::FACE); - removeRefsWithoutTess(currentEnts); - // We only extract the first face - smtk::model::EntityRef eRef = *currentEnts.begin(); - - const smtk::model::Face& face = eRef.as(); - - if (!face.isValid()) - { - std::cerr << "Face is invald\n"; - return 1; - } - - smtk::operation::OperationPtr triangulateFace = session->op("triangulate faces"); - if (!triangulateFace) - { - std::cerr << "No triangulate face operator\n"; - return 1; - } - triangulateFace->specification()->associateEntity(face); - smtk::operation::OperationResult result = triangulateFace->operate(); - auto associatedResources = meshManager->associatedCollections(face); - meshResource = associatedResources[0]; - } - - // histogram non-elevated coordinate values - { - ValidatePoints validatePoints(5, -1., 1.); - smtk::mesh::for_each(meshResource->meshes().points(), validatePoints); - std::size_t valid[5] = { 0, 0, 8, 0, 0 }; - - for (std::size_t bin = 0; bin < 5; bin++) - { - test(validatePoints.histogram()[bin] == valid[bin]); - } - } - - { - smtk::operation::Operation::Ptr op = session->op("my elevate mesh"); - - op->findMesh("mesh")->setValue(meshResource->meshes()); - smtk::operation::OperationResult result = op->operate(); - if (result->findInt("outcome")->value() != smtk::operation::Operation::OPERATION_SUCCEEDED) - { - std::cerr << "Could not run \"my elevate mesh\"!\n"; - return 1; - } - } - - // histogram elevated coordinate values - { - ValidatePoints validatePoints(5, -1., 1.); - smtk::mesh::for_each(meshResource->meshes().points(), validatePoints); - std::size_t valid[5] = { 2, 0, 4, 0, 2 }; - - for (std::size_t bin = 0; bin < 5; bin++) - { - test(validatePoints.histogram()[bin] == valid[bin]); - } - } - - return 0; -} - -smtkComponentInitMacro(smtk_delaunay_triangulate_faces_operator); diff --git a/smtk/mesh/testing/python/cellField.py b/smtk/mesh/testing/python/cellField.py deleted file mode 100644 index 1a0a7eb8df04c42c89462f355b70adf6e6a5748b..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/cellField.py +++ /dev/null @@ -1,71 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - -import os -import smtk -import smtk.common -import smtk.io -import smtk.mesh -import smtk.testing -import sys - - -def test_create_cell_field(): - - # Load the mesh file - mesh_path = os.path.join(smtk.testing.DATA_DIR, 'mesh', '2d/twoMeshes.h5m') - c = smtk.mesh.Resource.create() - smtk.io.importMesh(mesh_path, c) - if not c.isValid(): - raise RuntimeError("Failed to read valid mesh") - - mesh = c.meshes() - field = [i for i in range(c.meshes().cells().size())] - mesh.createCellField('cell field', 1, field) - - write_path = '' - write_path = os.path.join(smtk.testing.TEMP_DIR, - str(smtk.common.UUID.random()) + ".h5m") - - smtk.io.exportMesh(write_path, c) - return write_path - - -def test_read_cell_field(mesh_path): - - # Load the mesh file - c = smtk.mesh.Resource.create() - smtk.io.importMesh(mesh_path, c) - if not c.isValid(): - raise RuntimeError("Failed to read back valid mesh") - - mesh = c.meshes() - cellfields = mesh.cellFields() - - if not cellfields: - raise RuntimeError("No cell fields associated with the mesh") - - cellfield = next(iter(cellfields)) - data = cellfield.get() - - for i in range(cellfield.size()): - if i != data[i]: - raise RuntimeError( - "cell field was not correctly saved and retrieved") - - os.remove(mesh_path) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - resource_url = test_create_cell_field() - test_read_cell_field(resource_url) diff --git a/smtk/mesh/testing/python/elevateMeshOnStructuredGrid.py b/smtk/mesh/testing/python/elevateMeshOnStructuredGrid.py deleted file mode 100644 index f9dc6e173f6646cd0ed7b8a4ddfe8c40ec82829b..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/elevateMeshOnStructuredGrid.py +++ /dev/null @@ -1,174 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= -import os -import sys -import unittest -import smtk -import smtk.extension.vtk.source -import smtk.mesh -import smtk.model -import smtk.session.mesh -import smtk.testing -import smtk.io.vtk - -import math - - -class ValidatePoints(smtk.mesh.PointForEach): - - """ - Histogram the z-coordinates of the points in the mesh. - """ - - def __init__(self, nBins, coord, minVal, maxVal): - smtk.mesh.PointForEach.__init__(self) - self.hist = [0] * nBins - self.coord = coord - self.minVal = minVal - self.maxVal = maxVal - - def forPoints(self, pointIds, xyz, doModify): - counter = 0 - nPts = pointIds.size() - for i in range(nPts): - binNo = int((xyz[counter + self.coord] - self.minVal) / - (self.maxVal - self.minVal) * len(self.hist)) - if binNo < 0: - binNo = 0 - elif binNo >= len(self.hist) - 1: - binNo = len(self.hist) - 1 - self.hist[binNo] = self.hist[binNo] + 1 - counter += 3 - - -class ElevateMeshOnStructuredGrid(smtk.testing.TestCase): - - def setUp(self): - - # Construct an import operator - op = smtk.session.mesh.Import.create() - - # Set the import operators parameters - fname = op.parameters().find('filename') - fname.setValue(os.path.join( - smtk.testing.DATA_DIR, 'mesh', '2d', 'testSurfaceEdgesSmall.2dm')) - - # We don't need to construct the BREP hierarchy for this model - op.parameters().find('construct hierarchy').setIsEnabled(False) - - # Execute the operator and check its results - res = op.operate() - if res.find('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - raise RuntimeError - - # Access the resulting resource and model - self.resource = smtk.session.mesh.Resource.CastTo( - res.find('resourcesCreated').value(0)) - modelEntity = res.find('created').value(0) - self.model = smtk.model.Model( - modelEntity.modelResource(), modelEntity.id()) - - # Access the mesh set from the resource that comprises the model - self.mesh = self.resource.resource().meshes() - - # Import auxiliary geometry describing the elevation for the mesh - op = smtk.model.AddAuxiliaryGeometry.create() - - # Auxiliary geometry requires a model association - op.parameters().associateEntity(self.model) - - # Set the location of the auxiliary data file - fname = op.parameters().find('url') - fname.setValue(os.path.join( - smtk.testing.DATA_DIR, 'image', 'tiff', 'testSurfaceEdgesSmall.tiff')) - - # Execute the operator and check its results - res = op.operate() - if res.find('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - raise RuntimeError - - # Access the resulting auxiliary geometry - self.auxGeo = res.find("created").value() - - def testMeshing2D(self): - - # Create an "elevate mesh" operator - op = smtk.mesh.ElevateMesh.create() - - # Set the input data to look for auxiliary geometry - op.parameters().find("input data").setToDefault() - - # Set the auxiliary geometry - op.parameters().find("auxiliary geometry").setValue( - smtk.model.AuxiliaryGeometry(self.auxGeo.modelResource(), self.auxGeo.id()).component()) - - # Set a threshold range for the input data - # inputFilter = op.parameters().find("input filter") - # inputFilter.find("min threshold").setIsEnabled(True) - # inputFilter.find("min threshold").setValue(-5.) - # inputFilter.find("max threshold").setIsEnabled(True) - # inputFilter.find("max threshold").setValue(2.) - - # Set the interpolation scheme to be radial average - op.parameters().find("interpolation scheme").setToDefault() - - # Set the radial average - op.parameters().find("radius").setValue(7.) - - # For points that fall outside of our dataset, do not change their - # z-coordinates - op.parameters().find("external point values").setValue("set to value") - op.parameters().find("external point value").setValue(-1.) - - # Set the mesh - op.parameters().associate(smtk.mesh.Component.create(self.mesh)) - - # Clamp the elevation values between -/+ 2 - outputFilter = op.parameters().find("output filter") - outputFilter.find("min elevation").setIsEnabled(True) - outputFilter.find("min elevation").setValue(0.) - outputFilter.find("max elevation").setIsEnabled(True) - outputFilter.find("max elevation").setValue(250.) - - # Execute the operator and check its results - res = op.operate() - if res.find('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - raise RuntimeError - - # check the z bounds of the mesh to confirm that clamping was - # successful - extent = smtk.mesh.extent(self.mesh) - if extent[4] < -1. or extent[5] > 250.: - print('unexpected mesh extent', extent) - raise RuntimeError - - validatePointsX = ValidatePoints(10, 0, 0., 250.) - smtk.mesh.for_each(self.mesh.points(), validatePointsX) - - # Construct a histogram of the z-coordinates of the mesh points and - # compare it to an expected set of values - validatePoints = ValidatePoints(10, 2, 190., 250.) - smtk.mesh.for_each(self.mesh.points(), validatePoints) - # print(validatePoints.hist) - - expected = [127, 13, 8, 17, 27, 18, 24, 12, 24, 524] - - for i in range(10): - if validatePoints.hist[i] != expected[i]: - print('Expected {:1} but got {:2} at {:3}.'.format( - expected[i], validatePoints.hist[i], i)) - raise ValueError - - -if __name__ == '__main__': - smtk.testing.process_arguments() - unittest.main() diff --git a/smtk/mesh/testing/python/extractTessellation.py b/smtk/mesh/testing/python/extractTessellation.py deleted file mode 100644 index 753c38b8fc216ac1859927ea1725b48847767f44..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/extractTessellation.py +++ /dev/null @@ -1,48 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - -import os -import smtk -import smtk.io -import smtk.mesh -import smtk.testing -import sys - - -def test_file_load(): - - # Load the mesh file - print('data_dir', smtk.testing.DATA_DIR) - mesh_path = os.path.join(smtk.testing.DATA_DIR, - 'mesh', '3d/sixth_hexflatcore.h5m') - c = smtk.mesh.Resource.create() - smtk.io.importMesh(mesh_path, c) - if not c.isValid(): - raise RuntimeError("Failed to read valid mesh") - print(c) - print(c.numberOfMeshes()) - - # tasks - # 0. Generate a shell for the entire mesh - meshes = c.meshes() - shell = meshes.extractShell() - if not (shell.cells().size() > 0): - raise RuntimeError("Extract Shell failed") - - # 1. extract the tessellation of the shell - tess = smtk.mesh.Tessellation() - tess.extract(shell) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - test_file_load() diff --git a/smtk/mesh/testing/python/iterateMesh.py b/smtk/mesh/testing/python/iterateMesh.py deleted file mode 100644 index 93f053b42bf660eb90d1e33c080f902f60ddee7a..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/iterateMesh.py +++ /dev/null @@ -1,99 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - - -import os -import smtk -import smtk.io -import smtk.mesh -import smtk.testing -import sys - - -class MeshVisitor(smtk.mesh.MeshForEach): - - def __init__(self): - smtk.mesh.MeshForEach.__init__(self) - self.count = 0 - - def forMesh(self, singleMesh): - self.count += 1 - - -class CellVisitor(smtk.mesh.CellForEach): - - def __init__(self): - smtk.mesh.CellForEach.__init__(self, True) - self.count = 0 - - def forCell(self, cellId, cellType, numPoints): - self.count += 1 - - # show how to access the point ids of the cell - pts = [] - for i in range(0, numPoints): - pts.append(self.pointId(i)) - - # verify we have the correct number - # of coordinates - numCoords = len(self.coordinates()) - if not (numCoords == numPoints * 3): - # mark the cell invalid if numCoords - # is wrong - self.count -= 1 - - -class PointVisitor(smtk.mesh.PointForEach): - - def __init__(self): - smtk.mesh.PointForEach.__init__(self) - self.count = 0 - - def forPoints(self, pointIds, xyz, doModify): - self.count += pointIds.size() - # x,y,z is the physical location of the point - pass - - -def test_file_load(): - - # Load the mesh file - print('data_dir', smtk.testing.DATA_DIR) - mesh_path = os.path.join(smtk.testing.DATA_DIR, - 'mesh', '3d/sixth_hexflatcore.h5m') - mr = smtk.mesh.Resource.create() - smtk.io.importMesh(mesh_path, mr) - if not mr.isValid(): - raise RuntimeError("Failed to read valid mesh") - - # 1. iterate meshes - meshVisitor = MeshVisitor() - smtk.mesh.for_each(mr.meshes(), meshVisitor) - if not (meshVisitor.count == mr.meshes().size()): - raise RuntimeError("Python MeshForEach didn't visit each mesh") - - # 2. iterate cells - cellVisitor = CellVisitor() - smtk.mesh.for_each(mr.cells(), cellVisitor) - if not (cellVisitor.count == mr.cells().size()): - raise RuntimeError("Python CellVisitor didn't visit each cell") - - # 3. iterate points - pointVisitor = PointVisitor() - smtk.mesh.for_each(mr.points(), pointVisitor) - if not (pointVisitor.count == mr.points().size()): - raise RuntimeError("Python PointForEach didn't visit each point") - - -if __name__ == '__main__': - smtk.testing.process_arguments() - test_file_load() diff --git a/smtk/mesh/testing/python/meshMetrics.py b/smtk/mesh/testing/python/meshMetrics.py deleted file mode 100644 index 953c4903a06b154e5c00d4d3c90990806fdefede..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/meshMetrics.py +++ /dev/null @@ -1,50 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - - -import os -import smtk -import smtk.io -import smtk.mesh -import smtk.testing -import sys - - -def test_mesh_metrics(): - # Load the mesh file - print('data_dir', smtk.testing.DATA_DIR) - mesh_path = os.path.join(smtk.testing.DATA_DIR, - 'mesh', '3d/cube_with_hole.exo') - mr = smtk.mesh.Resource.create() - mr.setName('foo') - smtk.io.importMesh(mesh_path, mr) - if not mr.isValid(): - raise RuntimeError("Failed to read valid mesh") - - ext = smtk.mesh.extent(mr.meshes()) - tolerance = 1.e-8 - for i in range(0, 6): - if i % 2 == 0: - assert (abs(ext[i] + .5) < tolerance) - else: - assert (abs(ext[i] - .5) < tolerance) - - dim = smtk.mesh.highestDimension(mr.meshes()) - assert (dim == smtk.mesh.Dims3) - - euler_characteristic = smtk.mesh.eulerCharacteristic(mr.meshes()) - assert (euler_characteristic == 0) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - test_mesh_metrics() diff --git a/smtk/mesh/testing/python/my_elevate_mesh.py b/smtk/mesh/testing/python/my_elevate_mesh.py deleted file mode 100644 index 8c6ea95cd305a3d4bb19ec5baec0f1f443adde4b..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/my_elevate_mesh.py +++ /dev/null @@ -1,97 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - -""" my_elevate_mesh.py: - -An example of a runtime-loadable python operator. - -""" -import smtk -import smtk.mesh -import smtk.model - -import math - - -@smtk.model.operator("my elevate mesh", smtk.model.Session) -class MyElevateMesh(smtk.model.Operation): - - def __init__(self): - smtk.model.Operation.__init__(self) - - def name(self): - return "my elevate mesh" - - def className(self): - return self.__name__ - - @staticmethod - def description(): - descr = ''' - - - - - Demonstrate how to write a python operator. - - - - - - - - - - - - - ''' - return descr - - def operateInternal(self): - # Access the mesh and filename from the specification - mesh = self.specification().findMesh('mesh').value(0) - - # Compute the extent of the mesh - extent = smtk.mesh.extent(mesh) - - # Construct a function that takes in an array of three coordinates and - # returns an array of three coordinates. - def sinusoid(xyz): - return [xyz[0], xyz[1], - math.sin(2. * math.pi * (xyz[0] - extent[0]) / (extent[1] - extent[0])) * - math.sin(2. * math.pi * (xyz[1] - extent[2]) / (extent[3] - extent[2]))] - - # Warp the mesh nodes according to the above function. Each node - # coordinate triplet is filtered through the function, and its values - # are replaced by the function's output. - smtk.mesh.applyWarp(sinusoid, mesh) - - result = self.createResult(smtk.model.OPERATION_SUCCEEDED) - - # We have modified the mesh by warping the z coordinates of its nodes. - # We therefore must mark the mesh as having been modified. - modified_meshes = result.findMesh("mesh_modified") - modified_meshes.setValue(mesh) - - # The mesh we modified may be used as a model entity's tessellation. If - # so, we must mark the entity as having a modified tessellation. - modified_entities = result.findModelEntity("modified") - changed_tess = result.findModelEntity("tess_changed") - - entities = mesh.modelEntities() - if len(entities) != 0: - model = entities[0].owningModel() - modified_entities.appendValue(model) - changed_tess.appendValue(model) - - return result diff --git a/smtk/mesh/testing/python/pointField.py b/smtk/mesh/testing/python/pointField.py deleted file mode 100644 index 094cb9e8336fa45d9b0ee749759999bbe7330c2c..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/pointField.py +++ /dev/null @@ -1,71 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - -import os -import smtk -import smtk.common -import smtk.io -import smtk.mesh -import smtk.testing -import sys - - -def test_create_point_field(): - - # Load the mesh file - mesh_path = os.path.join(smtk.testing.DATA_DIR, 'mesh', '2d/twoMeshes.h5m') - c = smtk.mesh.Resource.create() - smtk.io.importMesh(mesh_path, c) - if not c.isValid(): - raise RuntimeError("Failed to read valid mesh") - - mesh = c.meshes() - field = [i for i in range(c.meshes().points().size())] - mesh.createPointField('point field', 1, field) - - write_path = '' - write_path = os.path.join(smtk.testing.TEMP_DIR, - str(smtk.common.UUID.random()) + ".h5m") - - smtk.io.exportMesh(write_path, c) - return write_path - - -def test_read_point_field(mesh_path): - - # Load the mesh file - c = smtk.mesh.Resource.create() - smtk.io.importMesh(mesh_path, c) - if not c.isValid(): - raise RuntimeError("Failed to read back valid mesh") - - mesh = c.meshes() - pointfields = mesh.pointFields() - - if not pointfields: - raise RuntimeError("No point fields associated with the mesh") - - pointfield = next(iter(pointfields)) - data = pointfield.get() - - for i in range(pointfield.size()): - if i != data[i]: - raise RuntimeError( - "point field was not correctly saved and retrieved") - - os.remove(mesh_path) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - resource_url = test_create_point_field() - test_read_point_field(resource_url) diff --git a/smtk/mesh/testing/python/simple.py b/smtk/mesh/testing/python/simple.py deleted file mode 100644 index b5f216dcc9de0bb0f063957f1f9c2a11eef7c879..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/simple.py +++ /dev/null @@ -1,51 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= - -import os -import smtk -import smtk.io -import smtk.mesh -import smtk.testing -import sys - - -def test_file_load(): - - # Load the mesh file - print('data_dir', smtk.testing.DATA_DIR) - mesh_path = os.path.join(smtk.testing.DATA_DIR, - 'mesh', '3d/sixth_hexflatcore.h5m') - mr = smtk.mesh.Resource.create() - smtk.io.importMesh(mesh_path, mr) - if not mr.isValid(): - raise RuntimeError("Failed to read valid mesh") - print(mr) - print(mr.numberOfMeshes()) - - # now dump some very basic info about the resource - print(mr.meshes().size()) - print(mr.cells().size()) - print(mr.points().size()) - - # now dump some very basic info about all the meshes - m = mr.meshes() - print('info on all meshes') - print(len(m.domains())) - print(len(m.dirichlets())) - print(len(m.neumanns())) - print(m.cells().size()) - print(m.points().size()) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - test_file_load() diff --git a/smtk/mesh/testing/python/snapPointsToSurface.py b/smtk/mesh/testing/python/snapPointsToSurface.py deleted file mode 100644 index dfeaed65f9d2563b60cae7a50ccd50a2e0744400..0000000000000000000000000000000000000000 --- a/smtk/mesh/testing/python/snapPointsToSurface.py +++ /dev/null @@ -1,126 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= -import os -import sys -import unittest -import smtk -import smtk.extension.vtk.source -import smtk.io -import smtk.mesh -import smtk.model -import smtk.session.mesh -import smtk.testing - -import math - -''' - Import a triangulated terrain as a mesh model, add an auxiliary geometry as - a glyph prototype, and create a bunch of glyph instances that are snapped to - the surface of the terrain. Finally, check that all of the points (that were - seeded above a certain z value) fall below their initial z value. -''' - - -class SnapPointsToSurface(smtk.testing.TestCase): - - def setUp(self): - - # Construct an import operator - op = smtk.session.mesh.Import.create() - - # Set the import operators parameters - fname = op.parameters().find('filename') - fname.setValue(os.path.join( - smtk.testing.DATA_DIR, 'mesh', '3d', 'terrain.exo')) - - # We don't need to construct the BREP hierarchy for this model - op.parameters().find('construct hierarchy').setIsEnabled(False) - - # Execute the operator and check its results - res = op.operate() - if res.find('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - raise RuntimeError - - # Access the resulting resource and model - self.resource = smtk.session.mesh.Resource.CastTo( - res.find('resourcesCreated').value(0)) - modelEntity = res.find('created').value(0) - self.model = smtk.model.Model( - modelEntity.modelResource(), modelEntity.id()) - - # Grab the top face (known to be named "Element Block 13") - self.face = None - for f in self.resource.findEntitiesOfType(int(smtk.model.FACE)): - if f.name() == 'Element Block 13': - self.face = f - break - - if not self.face: - raise Exception('Could not find top face') - - # Import auxiliary geometry describing the elevation for the mesh - op = smtk.model.AddAuxiliaryGeometry.create() - - # Auxiliary geometry requires a model association - op.parameters().associateEntity(self.model) - - # Set the location of the auxiliary data file - fname = op.parameters().find('url') - fname.setValue(os.path.join( - smtk.testing.DATA_DIR, 'model', '3d', 'obj', 'cone.obj')) - - # Execute the operator and check its results - res = op.operate() - if res.find('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - raise RuntimeError - - # Access the resulting auxiliary geometry - self.auxGeo = res.find("created").value() - - def testInstancePlacement(self): - - # Create an "Create Instances" operator - op = smtk.model.CreateInstances.create() - - # Create several instances above the model and snap them to the top - # surface - op.parameters().associate(self.auxGeo) - op.parameters().find('placement rule').setDiscreteIndex(1) - op.parameters().find('volume of interest').item(0, 0).setValue(0, 57.) - op.parameters().find('volume of interest').item(0, 0).setValue(1, 60.) - op.parameters().find('volume of interest').item(1, 0).setValue(0, 2.) - op.parameters().find('volume of interest').item(1, 0).setValue(1, 5.) - op.parameters().find('volume of interest').item(2, 0).setValue(0, 0.1) - op.parameters().find('volume of interest').item(2, 0).setValue(1, 0.2) - op.parameters().find('sample size').setValue(10) - op.parameters().find('snap to entity').setIsEnabled(True) - op.parameters().find('snap to entity').setDiscreteIndex(1) - op.parameters().find('entity').setValue(self.face.component()) - - res = op.operate() - - if res.find('outcome').value() != int(smtk.operation.Operation.Outcome.SUCCEEDED): - raise Exception('"Create Instances" operator failed') - - # Iterate over the coordinates of the instances to ensure that their - # coordinates snapped to the model surface, which is below the box where - # random points were seeded. - for instance in self.resource.findEntitiesOfType(int(smtk.model.INSTANCE_ENTITY)): - coords = instance.hasTessellation().coords() - for counter, coord in enumerate(coords): - if counter % 3 is 2 and coord >= 0.1: - raise Exception('coordinate %d did not snap' % counter / 3) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - unittest.main() diff --git a/smtk/mesh/utility/ApplyToMesh.cxx b/smtk/mesh/utility/ApplyToMesh.cxx deleted file mode 100644 index 40f39ac1ada65d9e2dcc95679116f5aa3df2e11b..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/ApplyToMesh.cxx +++ /dev/null @@ -1,364 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/utility/ApplyToMesh.h" - -#include "smtk/mesh/core/CellField.h" -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/FieldTypes.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/core/PointSet.h" - -#include -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -namespace -{ -class WarpPoints : public smtk::mesh::PointForEach -{ - const std::function(std::array)>& m_mapping; - -public: - WarpPoints(const std::function(std::array)>& mapping) - : m_mapping(mapping) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& coordinatesModified) override - { - std::size_t offset = 0; - std::array x, f_x; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i, offset += 3) - { - std::copy(xyz.data() + offset, xyz.data() + offset + 3, x.data()); - f_x = m_mapping(x); - std::copy(std::begin(f_x), std::end(f_x), xyz.data() + offset); - } - coordinatesModified = true; //mark we are going to modify the points - } -}; - -class StoreAndWarpPoints : public smtk::mesh::PointForEach -{ - const std::function(std::array)>& m_mapping; - std::vector m_data; - -public: - StoreAndWarpPoints( - const std::function(std::array)>& mapping, - std::size_t nPoints) - : m_mapping(mapping) - , m_data(3 * nPoints) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& coordinatesModified) override - { - std::size_t offset = 0; - std::array x, f_x; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i, offset += 3) - { - std::copy(xyz.data() + offset, xyz.data() + offset + 3, x.data()); - - std::copy(std::begin(x), std::end(x), m_data.data() + offset); - - f_x = m_mapping(x); - std::copy(std::begin(f_x), std::end(f_x), xyz.data() + offset); - } - coordinatesModified = true; //mark we are going to modify the points - } - - [[nodiscard]] const std::vector& data() const { return m_data; } -}; - -class UndoWarpPoints : public smtk::mesh::PointForEach -{ - std::vector m_data; - -public: - UndoWarpPoints() = default; - - void forPoints( - const smtk::mesh::HandleRange& /*pointIds*/, - std::vector& xyz, - bool& coordinatesModified) override - { - xyz = m_data; - coordinatesModified = true; - } - - std::vector& data() { return m_data; } -}; -} // namespace - -bool applyWarp( - const std::function(std::array)>& f, - smtk::mesh::MeshSet& ms, - bool storePriorCoordinates) -{ - if (storePriorCoordinates) - { - StoreAndWarpPoints warp(f, ms.points().size()); - smtk::mesh::for_each(ms.points(), warp); - return ms.createPointField("_prior", 3, smtk::mesh::FieldType::Double, warp.data().data()) - .isValid(); - } - else - { - WarpPoints warp(f); - smtk::mesh::for_each(ms.points(), warp); - return true; - } -} - -bool undoWarp(smtk::mesh::MeshSet& ms) -{ - smtk::mesh::PointField pointfield = ms.pointField("_prior"); - if (!pointfield.isValid()) - { - return false; - } - - UndoWarpPoints undoWarp; - undoWarp.data().resize(pointfield.size() * pointfield.dimension()); - pointfield.get(undoWarp.data().data()); - smtk::mesh::for_each(ms.points(), undoWarp); - return ms.removePointField(pointfield); -} - -namespace -{ -class ScalarPointField : public smtk::mesh::PointForEach -{ -private: - const std::function)>& m_mapping; - std::vector m_data; - std::size_t m_counter{ 0 }; - -public: - ScalarPointField(const std::function)>& mapping, std::size_t nPoints) - : m_mapping(mapping) - , m_data(nPoints) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& /*coordinatesModified*/) override - { - // The internal provides access to the the point field in - // sequence. The local provides access to the coordinates of - // the points currently being iterated. The iterator provides access to - // the memory space of the points (we currently use it for iteration). - std::size_t xyzCounter = 0; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i, xyzCounter += 3) - { - m_data[m_counter++] = m_mapping( - std::array({ { xyz[xyzCounter], xyz[xyzCounter + 1], xyz[xyzCounter + 2] } })); - } - } - - [[nodiscard]] const std::vector& data() const { return m_data; } -}; -} // namespace - -bool applyScalarPointField( - const std::function)>& f, - const std::string& name, - smtk::mesh::MeshSet& ms) -{ - ScalarPointField scalarPointField(f, ms.points().size()); - smtk::mesh::for_each(ms.points(), scalarPointField); - return ms.createPointField(name, 1, smtk::mesh::FieldType::Double, scalarPointField.data().data()) - .isValid(); -} - -namespace -{ -class ScalarCellField : public smtk::mesh::CellForEach -{ -private: - const std::function)>& m_mapping; - std::vector m_data; - std::size_t m_counter{ 0 }; - -public: - ScalarCellField(const std::function)>& mapping, std::size_t nCells) - : smtk::mesh::CellForEach(true) - , m_mapping(mapping) - , m_data(nCells) - { - } - - void forCell(const smtk::mesh::Handle& /*cellId*/, smtk::mesh::CellType /*cellType*/, int nPts) - override - { - double xyz[3] = { 0., 0., 0. }; - for (int i = 0; i < 3 * nPts; i += 3) - { - xyz[0] += this->coordinates()[i]; - xyz[1] += this->coordinates()[i + 1]; - xyz[2] += this->coordinates()[i + 2]; - } - for (int i = 0; i < 3; i++) - { - xyz[i] /= nPts; - } - m_data[m_counter++] = m_mapping(std::array({ { xyz[0], xyz[1], xyz[2] } })); - } - - [[nodiscard]] const std::vector& data() const { return m_data; } -}; -} // namespace - -bool applyScalarCellField( - const std::function)>& f, - const std::string& name, - smtk::mesh::MeshSet& ms) -{ - ScalarCellField scalarCellField(f, ms.cells().size()); - smtk::mesh::for_each(ms.cells(), scalarCellField); - return ms.createCellField(name, 1, smtk::mesh::FieldType::Double, scalarCellField.data().data()) - .isValid(); -} - -namespace -{ -class VectorPointField : public smtk::mesh::PointForEach -{ -private: - const std::function(std::array)>& m_mapping; - std::vector m_data; - std::size_t m_counter{ 0 }; - -public: - VectorPointField( - const std::function(std::array)>& mapping, - std::size_t nPoints) - : m_mapping(mapping) - , m_data(3 * nPoints) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& xyz, - bool& /*coordinatesModified*/) override - { - // The internal provides access to the the point field in - // sequence. The local provides access to the coordinates of - // the points currently being iterated. The iterator provides access to - // the memory space of the points (we currently use it for iteration). - std::size_t xyzCounter = 0; - std::array x, f_x; - for (auto i = smtk::mesh::rangeElementsBegin(pointIds); - i != smtk::mesh::rangeElementsEnd(pointIds); - ++i, xyzCounter += 3) - { - std::copy(xyz.data() + xyzCounter, xyz.data() + xyzCounter + 3, x.data()); - f_x = m_mapping(x); - std::copy(std::begin(f_x), std::end(f_x), m_data.data() + m_counter); - m_counter += 3; - } - } - - [[nodiscard]] const std::vector& data() const { return m_data; } -}; -} // namespace - -bool applyVectorPointField( - const std::function(std::array)>& f, - const std::string& name, - smtk::mesh::MeshSet& ms) -{ - VectorPointField vectorPointField(f, ms.points().size()); - smtk::mesh::for_each(ms.points(), vectorPointField); - return ms.createPointField(name, 3, smtk::mesh::FieldType::Double, vectorPointField.data().data()) - .isValid(); -} - -namespace -{ -class VectorCellField : public smtk::mesh::CellForEach -{ -private: - const std::function(std::array)>& m_mapping; - std::vector m_data; - std::size_t m_counter{ 0 }; - -public: - VectorCellField( - const std::function(std::array)>& mapping, - std::size_t nCells) - : smtk::mesh::CellForEach(true) - , m_mapping(mapping) - , m_data(3 * nCells) - { - } - - void forCell(const smtk::mesh::Handle& /*cellId*/, smtk::mesh::CellType /*cellType*/, int nPts) - override - { - std::array x = { { 0., 0., 0. } }, f_x; - for (int i = 0; i < 3 * nPts; i += 3) - { - x[0] += this->coordinates()[i]; - x[1] += this->coordinates()[i + 1]; - x[2] += this->coordinates()[i + 2]; - } - for (int i = 0; i < 3; i++) - { - x[i] /= nPts; - } - f_x = m_mapping(x); - std::copy(std::begin(f_x), std::end(f_x), m_data.data() + m_counter); - m_counter += 3; - } - - [[nodiscard]] const std::vector& data() const { return m_data; } -}; -} // namespace - -bool applyVectorCellField( - const std::function(std::array)>& f, - const std::string& name, - smtk::mesh::MeshSet& ms) -{ - VectorCellField vectorCellField(f, ms.cells().size()); - smtk::mesh::for_each(ms.cells(), vectorCellField); - return ms.createCellField(name, 3, smtk::mesh::FieldType::Double, vectorCellField.data().data()) - .isValid(); -} -} // namespace utility -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/utility/ApplyToMesh.h b/smtk/mesh/utility/ApplyToMesh.h deleted file mode 100644 index 3bbe95a13a1d662f52299cb6d822e7326ba2c67a..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/ApplyToMesh.h +++ /dev/null @@ -1,75 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_utility_ApplyToMesh_h -#define smtk_mesh_utility_ApplyToMesh_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/MeshSet.h" - -#include - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -// deform each point in a meshset according to an R^3->R^3 mapping. -SMTKCORE_EXPORT -bool applyWarp( - const std::function(std::array)>&, - smtk::mesh::MeshSet& ms, - bool storePriorCoordinates = false); - -// if prior coordinates were stored during applyWarp, undoWarp resets the -// coordinates to their original values. -SMTKCORE_EXPORT -bool undoWarp(smtk::mesh::MeshSet& ms); - -// construct a named scalar field defined at each point in a meshset according -// to an R^3->R mapping. -SMTKCORE_EXPORT -bool applyScalarPointField( - const std::function)>&, - const std::string& name, - smtk::mesh::MeshSet& ms); - -// construct a named scalar field defined at each cell centroid in a meshset -// according to an R^3->R mapping. -SMTKCORE_EXPORT -bool applyScalarCellField( - const std::function)>&, - const std::string& name, - smtk::mesh::MeshSet& ms); - -// construct a named vector field defined at each point in a meshset according -// to an R^3->R^3 mapping. -SMTKCORE_EXPORT -bool applyVectorPointField( - const std::function(std::array)>&, - const std::string& name, - smtk::mesh::MeshSet& ms); - -// construct a named vector field defined at each cell centroid in a meshset -// according to an R^3->R^3 mapping. -SMTKCORE_EXPORT -bool applyVectorCellField( - const std::function(std::array)>&, - const std::string& name, - smtk::mesh::MeshSet& ms); -} // namespace utility -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/utility/Create.cxx b/smtk/mesh/utility/Create.cxx deleted file mode 100644 index 24838e8831275b5b5c32be744574691045aa5dc3..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/Create.cxx +++ /dev/null @@ -1,312 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/utility/Create.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/Interface.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/PointSet.h" -#include "smtk/mesh/core/Resource.h" - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -std::array createUniformGrid( - smtk::mesh::ResourcePtr resource, - const std::array& discretization, - const std::function(std::array)>& transform) -{ - // We start by constructing a mesh allocator object. - smtk::mesh::AllocatorPtr allocator = resource->interface()->allocator(); - - // Allocate the memory for our points. The resulting memory layout is the - // 3 x N array "coordinates". - std::size_t numberOfPoints = - (discretization[0] + 1) * (discretization[1] + 1) * (discretization[2] + 1); - smtk::mesh::Handle verticesBegin = 0; - std::vector coordinates; - allocator->allocatePoints(numberOfPoints, verticesBegin, coordinates); - - // Next, allocate the memory for our 3D cells. - std::size_t numberOfCells = discretization[0] * discretization[1] * discretization[2]; - smtk::mesh::HandleRange createdCellIds; - smtk::mesh::Handle* connectivity; - allocator->allocateCells(numberOfCells, createdCellIds, connectivity); - - // Finally, allocate the memory for our 2D faces. We could have the mesh - // interface construct these programmatically by accessing the shell of the - // created 3D mesh and filtering based on the orientation of the unit - // normals or point coordinates, but it is pretty easy to manually construct - // the faces of a rectilinear grid. Also, this approach reduces the number of - // computations we need to make. - std::array numberOfCellsForFaces; - std::array createdCellIdsForFaces; - std::array connectivityForFaces; - std::array connectivityIndexForFaces; - for (int i = 0; i < 6; i++) - { - numberOfCellsForFaces[i] = discretization[(i + 1) % 3] * discretization[(i + 2) % 3]; - allocator->allocateCells( - numberOfCellsForFaces[i], createdCellIdsForFaces[i], connectivityForFaces[i]); - connectivityIndexForFaces[i] = 0; - } - - // Map to convert hexahedral indices to quad indices for identifying the - // faces of a hexahedron as x-min, y-min, z-min, x-max, y-max, z-max. - static const std::size_t hexToQuad[6][4] = { { 0, 3, 2, 1 }, { 0, 1, 5, 4 }, { 0, 4, 7, 3 }, - { 4, 5, 6, 7 }, { 3, 7, 6, 2 }, { 1, 2, 6, 5 } }; - std::size_t coordinateCounter = 0; - std::size_t cellCounter = 0; - std::array xyz; - std::array transformed; - std::array step = { - { 1. / discretization[0], 1. / discretization[1], 1. / discretization[2] } - }; - for (std::size_t i = 0; i <= discretization[0]; i++) - { - xyz[0] = i * step[0]; - for (std::size_t j = 0; j <= discretization[1]; j++) - { - xyz[1] = j * step[1]; - for (std::size_t k = 0; k <= discretization[2]; k++) - { - xyz[2] = k * step[2]; - - transformed = transform(xyz); - - coordinates[0][coordinateCounter] = transformed[0]; - coordinates[1][coordinateCounter] = transformed[1]; - coordinates[2][coordinateCounter] = transformed[2]; - - // We are looping over the point coordinates. They run from 0 through - // N, where N is the number of cells on a side. We can use the same - // loop to construct our cell connectivities by skipping the final - // iteration along each principal axis. - if (i != discretization[0] && j != discretization[1] && k != discretization[2]) - { - std::size_t connectivityIndex = - smtk::mesh::CellTraits::NUM_VERTICES * cellCounter; - std::size_t firstVert = verticesBegin + coordinateCounter; - connectivity[connectivityIndex + 0] = firstVert; - connectivity[connectivityIndex + 1] = firstVert + 1; - connectivity[connectivityIndex + 2] = firstVert + discretization[2] + 2; - connectivity[connectivityIndex + 3] = firstVert + discretization[2] + 1; - std::size_t tmp = (discretization[1] + 1) * (discretization[2] + 1); - connectivity[connectivityIndex + 4] = firstVert + tmp; - connectivity[connectivityIndex + 5] = firstVert + tmp + 1; - connectivity[connectivityIndex + 6] = firstVert + discretization[2] + tmp + 2; - connectivity[connectivityIndex + 7] = firstVert + discretization[2] + tmp + 1; - -#define ASSIGN_CONNECTIVITY_FOR_FACE(faceId) \ - do \ - { \ - for (std::size_t m = 0; m < smtk::mesh::CellTraits::NUM_VERTICES; m++) \ - { \ - connectivityForFaces[faceId][connectivityIndexForFaces[faceId]++] = \ - connectivity[connectivityIndex + hexToQuad[faceId][m]]; \ - } \ - } while (0) - - if (i == 0) - ASSIGN_CONNECTIVITY_FOR_FACE(0); - if (j == 0) - ASSIGN_CONNECTIVITY_FOR_FACE(1); - if (k == 0) - ASSIGN_CONNECTIVITY_FOR_FACE(2); - if (i == (discretization[0] - 1)) - ASSIGN_CONNECTIVITY_FOR_FACE(3); - if (j == (discretization[1] - 1)) - ASSIGN_CONNECTIVITY_FOR_FACE(4); - if (k == (discretization[2] - 1)) - ASSIGN_CONNECTIVITY_FOR_FACE(5); -#undef ASSIGN_CONNECTIVITY_FOR_FACE - - ++cellCounter; - } - ++coordinateCounter; - } - } - } - - std::array constructedMeshSets; - - // We have filled in the connectivity array, so we must now notify the - // allocator that we have modified the connectivity array. - allocator->connectivityModified( - createdCellIds, smtk::mesh::CellTraits::NUM_VERTICES, connectivity); - - // Construct a cell set corresponding to the hexahedral cells identified by - // the connectivity array we just created. - smtk::mesh::CellSet cellsForMesh(resource, createdCellIds); - - // Construct a mesh set corresponding to the cell set we just created. - constructedMeshSets[0] = resource->createMesh(cellsForMesh); - - for (std::size_t i = 0; i < 6; i++) - { - // We have filled in the connectivity array, so we must now notify the - // allocator that we have modified the connectivity array. - allocator->connectivityModified( - createdCellIdsForFaces[i], - smtk::mesh::CellTraits::NUM_VERTICES, - connectivityForFaces[i]); - - // Construct a cell set corresponding to the quadrilateral cells identified - // by the connectivity array we just created. - smtk::mesh::CellSet cellsForMeshFace(resource, createdCellIdsForFaces[i]); - - // Construct a mesh set corresponding to the cell set we just created. - constructedMeshSets[i + 1] = resource->createMesh(cellsForMeshFace); - } - - return constructedMeshSets; -} - -std::array createUniformGrid( - smtk::mesh::ResourcePtr resource, - const std::array& discretization, - const std::function(std::array)>& transform) -{ - // We start by constructing a mesh allocator object. - smtk::mesh::AllocatorPtr allocator = resource->interface()->allocator(); - - // Allocate the memory for our points. The resulting memory layout is the - // 3 x N array "coordinates". - std::size_t numberOfPoints = (discretization[0] + 1) * (discretization[1] + 1); - smtk::mesh::Handle verticesBegin = 0; - std::vector coordinates; - allocator->allocatePoints(numberOfPoints, verticesBegin, coordinates); - - // Next, allocate the memory for our 2D cells. - std::size_t numberOfCells = discretization[0] * discretization[1]; - smtk::mesh::HandleRange createdCellIds; - smtk::mesh::Handle* connectivity; - allocator->allocateCells(numberOfCells, createdCellIds, connectivity); - - // Finally, allocate the memory for our 1D edges. We could have the mesh - // interface construct these programmatically by accessing the shell of the - // created 2D mesh and filtering based on the orientation of the unit - // normals or point coordinates, but it is pretty easy to manually construct - // the faces of a rectilinear grid. Also, this approach reduces the number of - // computations we need to make. - std::array numberOfCellsForEdges; - std::array createdCellIdsForEdges; - std::array connectivityForEdges; - std::array connectivityIndexForEdges; - for (std::size_t i = 0; i < 4; i++) - { - numberOfCellsForEdges[i] = discretization[(i + 1) % 2]; - allocator->allocateCells( - numberOfCellsForEdges[i], createdCellIdsForEdges[i], connectivityForEdges[i]); - connectivityIndexForEdges[i] = 0; - } - - // Map to convert quadrilateral indices to line indices for identifying the - // edges of a quadrilateral as x-min, y-min, x-max, y-max. - static const std::size_t quadToLine[4][2] = { { 0, 1 }, { 3, 0 }, { 2, 3 }, { 1, 2 } }; - std::size_t coordinateCounter = 0; - std::size_t cellCounter = 0; - std::array xyz = { { 0., 0., 0. } }; - std::array transformed; - std::array step = { { 1. / discretization[0], 1. / discretization[1] } }; - for (std::size_t i = 0; i <= discretization[0]; i++) - { - xyz[0] = i * step[0]; - for (std::size_t j = 0; j <= discretization[1]; j++) - { - xyz[1] = j * step[1]; - - transformed = transform(xyz); - - coordinates[0][coordinateCounter] = transformed[0]; - coordinates[1][coordinateCounter] = transformed[1]; - coordinates[2][coordinateCounter] = transformed[2]; - - // We are looping over the point coordinates. They run from 0 through - // N, where N is the number of cells on a side. We can use the same - // loop to construct our cell connectivities by skipping the final - // iteration along each principal axis. - if (i != discretization[0] && j != discretization[1]) - { - std::size_t connectivityIndex = - smtk::mesh::CellTraits::NUM_VERTICES * cellCounter; - std::size_t firstVert = verticesBegin + coordinateCounter; - connectivity[connectivityIndex + 0] = firstVert; - connectivity[connectivityIndex + 1] = firstVert + 1; - connectivity[connectivityIndex + 2] = firstVert + discretization[1] + 2; - connectivity[connectivityIndex + 3] = firstVert + discretization[1] + 1; - -#define ASSIGN_CONNECTIVITY_FOR_EDGE(edgeId) \ - do \ - { \ - for (std::size_t m = 0; m < smtk::mesh::CellTraits::NUM_VERTICES; m++) \ - { \ - connectivityForEdges[edgeId][connectivityIndexForEdges[edgeId]++] = \ - connectivity[connectivityIndex + quadToLine[edgeId][m]]; \ - } \ - } while (0) - - if (i == 0) - ASSIGN_CONNECTIVITY_FOR_EDGE(0); - if (j == 0) - ASSIGN_CONNECTIVITY_FOR_EDGE(1); - if (i == (discretization[0] - 1)) - ASSIGN_CONNECTIVITY_FOR_EDGE(2); - if (j == (discretization[1] - 1)) - ASSIGN_CONNECTIVITY_FOR_EDGE(3); -#undef ASSIGN_CONNECTIVITY_FOR_EDGE - - ++cellCounter; - } - ++coordinateCounter; - } - } - - std::array constructedMeshSets; - - // We have filled in the connectivity array, so we must now notify the - // allocator that we have modified the connectivity array. - allocator->connectivityModified( - createdCellIds, smtk::mesh::CellTraits::NUM_VERTICES, connectivity); - - // Construct a cell set corresponding to the quadrilateral cells identified by - // the connectivity array we just created. - smtk::mesh::CellSet cellsForMesh(resource, createdCellIds); - - // Construct a mesh set corresponding to the cell set we just created. - constructedMeshSets[0] = resource->createMesh(cellsForMesh); - - for (std::size_t i = 0; i < 4; i++) - { - // We have filled in the connectivity array, so we must now notify the - // allocator that we have modified the connectivity array. - allocator->connectivityModified( - createdCellIdsForEdges[i], - smtk::mesh::CellTraits::NUM_VERTICES, - connectivityForEdges[i]); - - // Construct a cell set corresponding to the line cells identified by the - // connectivity array we just created. - smtk::mesh::CellSet cellsForMeshFace(resource, createdCellIdsForEdges[i]); - - // Construct a mesh set corresponding to the cell set we just created. - constructedMeshSets[i + 1] = resource->createMesh(cellsForMeshFace); - } - - return constructedMeshSets; -} -} // namespace utility -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/utility/Create.h b/smtk/mesh/utility/Create.h deleted file mode 100644 index 1ac1c1126437dc37f42e3c51cb75eb529fe0c7c7..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/Create.h +++ /dev/null @@ -1,54 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_utility_Create_h -#define smtk_mesh_utility_Create_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -// construct a 3-dimensional hexahedral grid discretized along each principal -// axis according to and with points transformed from the unit -// cube (0, 0, 0) to (1, 1, 1) according to an R^3->R^3 mapping . -// Return the meshsets corresponding to volume, x-min, y-min, z-min, x-max, -// y-max, z-max, in that order. -SMTKCORE_EXPORT -std::array createUniformGrid( - smtk::mesh::ResourcePtr, - const std::array& discretization, - const std::function(std::array)>& transform); - -// construct a 2-dimensional quadrilateral grid discretized along each principal -// axis according to and with points transformed from the unit -// square (0, 0, 0) to (1, 1, 0) according to an R^3->R^3 mapping . -// Return the meshsets corresponding to area, x-min, y-min, x-max, y-max, in -// that order. -SMTKCORE_EXPORT -std::array createUniformGrid( - smtk::mesh::ResourcePtr, - const std::array& discretization, - const std::function(std::array)>& transform); -} // namespace utility -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/utility/ExtractCanonicalIndices.cxx b/smtk/mesh/utility/ExtractCanonicalIndices.cxx deleted file mode 100644 index de3af99003818bf0309f935273002b73dffa99db..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/ExtractCanonicalIndices.cxx +++ /dev/null @@ -1,131 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/utility/ExtractCanonicalIndices.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/CellTraits.h" -#include "smtk/mesh/core/Handle.h" -#include "smtk/mesh/core/Interface.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/Metrics.h" - -#include -#include -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -void PreAllocatedCanonicalIndices::determineAllocationLengths( - const smtk::mesh::MeshSet& ms, - std::int64_t& numberOfCells) -{ - numberOfCells = ms.cells().size(); -} - -PreAllocatedCanonicalIndices::PreAllocatedCanonicalIndices( - std::int64_t* referenceCellIndices, - std::int64_t* canonicalIndices) - : m_referenceCellIndices(referenceCellIndices) - , m_canonicalIndices(canonicalIndices) -{ -} - -void CanonicalIndices::extract( - const smtk::mesh::MeshSet& ms, - const smtk::mesh::MeshSet& referenceMS) -{ - //determine the lengths - std::int64_t numberOfCells = -1; - - PreAllocatedCanonicalIndices::determineAllocationLengths(ms, numberOfCells); - m_referenceCellIndices.resize(numberOfCells); - m_canonicalIndices.resize(numberOfCells); - - PreAllocatedCanonicalIndices field(m_referenceCellIndices.data(), m_canonicalIndices.data()); - - extractCanonicalIndices(ms, referenceMS, field); -} - -void extractCanonicalIndices( - const smtk::mesh::MeshSet& ms, - const smtk::mesh::MeshSet& referenceMS, - PreAllocatedCanonicalIndices& field) -{ - // Check that the mesh sets come from the same resource. - if (ms.resource() != referenceMS.resource()) - { - return; - } - - // Construct a map between the cell handles in that are adjacent - // to the cells in and their indices. - std::unordered_map cellMap; - - { - // may have a lot of cells. We don't need to add each one to - // our cell map, though. We only need the ones that are reference cells for - // the cells in . To determine which cells to use, we first extract the - // higher-dimension adjacencies of . - int dimension = static_cast(smtk::mesh::utility::highestDimension(ms)) + 1; - - bool adjacencyMeshCreated = false; - smtk::mesh::MeshSet adjacencyMesh = - ms.extractAdjacenciesOfDimension(dimension, adjacencyMeshCreated); - smtk::mesh::CellSet adjacencies = adjacencyMesh.cells(); - - // We then iterate over each of our reference cells, incrementing a counter - // as we go. - smtk::mesh::CellSet referenceCells = referenceMS.cells(); - auto it = rangeElementsBegin(referenceCells.range()); - auto end = rangeElementsEnd(referenceCells.range()); - for (std::size_t counter = 0; it != end; ++it, ++counter) - { - // If the cell is an adjacency of , add it to the map. - if (rangeContains(adjacencies.range(), *it)) - { - cellMap[*it] = counter; - } - } - - if (adjacencyMeshCreated) - { - ms.resource()->removeMeshes(adjacencyMesh); - } - } - - // Now that our cell map is constructed, we iterate over the cells in and - // identify the canonical index for each cell. - auto interface = ms.resource()->interface(); - smtk::mesh::CellSet cells = ms.cells(); - auto it = rangeElementsBegin(cells.range()); - auto end = rangeElementsEnd(cells.range()); - - smtk::mesh::Handle parent; - int canonicalIndex; - for (std::size_t counter = 0; it != end; ++it, ++counter) - { - interface->canonicalIndex(*it, parent, canonicalIndex); - field.m_referenceCellIndices[counter] = cellMap[parent]; - field.m_canonicalIndices[counter] = static_cast(canonicalIndex); - } -} -} // namespace utility -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/utility/ExtractCanonicalIndices.h b/smtk/mesh/utility/ExtractCanonicalIndices.h deleted file mode 100644 index bf0e738e1c41c96e99381c9db7fab325ef96324b..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/ExtractCanonicalIndices.h +++ /dev/null @@ -1,80 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_utility_ExtractCanonicalIndices_h -#define smtk_mesh_utility_ExtractCanonicalIndices_h - -#include - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/MeshSet.h" - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -class SMTKCORE_EXPORT PreAllocatedCanonicalIndices -{ - -public: - static void determineAllocationLengths( - const smtk::mesh::MeshSet& ms, - std::int64_t& numberOfCells); - - PreAllocatedCanonicalIndices(std::int64_t* referenceCellIndices, std::int64_t* canonicalIndices); - -private: - friend SMTKCORE_EXPORT void extractCanonicalIndices( - const smtk::mesh::MeshSet&, - const smtk::mesh::MeshSet&, - PreAllocatedCanonicalIndices&); - - std::int64_t* m_referenceCellIndices; - std::int64_t* m_canonicalIndices; -}; - -// Given a meshset (typically a boundary mesh) and a reference meshset, for each -// cell in the meshset compute the cell's parent index (integral value as -// determined when extracting the reference meshset's tessellation) and the -// canonical index of the cell as defined in Tautges, Timothy J. "Canonical -// numbering systems for finite-element codes." International Journal for -// Numerical Methods in Biomedical Engineering 26.12 (2010): 1559-1572. -class SMTKCORE_EXPORT CanonicalIndices -{ -public: - CanonicalIndices() = default; - - // Assume the cells in are of the same dimension - void extract(const smtk::mesh::MeshSet& ms, const smtk::mesh::MeshSet& referenceMS); - - //use these methods to gain access to the fields after extraction - const std::vector& referenceCellIndices() const { return m_referenceCellIndices; } - const std::vector& canonicalIndices() const { return m_canonicalIndices; } - -private: - std::vector m_referenceCellIndices; - std::vector m_canonicalIndices; -}; - -//Don't wrap these for python, instead python should use the CanonicalIndices class and -//the extract method - -SMTKCORE_EXPORT void extractCanonicalIndices( - const smtk::mesh::MeshSet&, - const smtk::mesh::MeshSet&, - PreAllocatedCanonicalIndices&); -} // namespace utility -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/utility/ExtractMeshConstants.cxx b/smtk/mesh/utility/ExtractMeshConstants.cxx deleted file mode 100644 index b769ffea4e70560db29faebb7f7926226755b019..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/ExtractMeshConstants.cxx +++ /dev/null @@ -1,343 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/utility/ExtractMeshConstants.h" - -#include "smtk/mesh/core/PointConnectivity.h" -#include "smtk/mesh/core/PointSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/utility/ExtractTessellation.h" - -#include "smtk/model/Edge.h" -#include "smtk/model/EdgeUse.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Loop.h" -#include "smtk/model/Vertex.h" - -#include -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -void PreAllocatedMeshConstants::determineAllocationLengths( - const smtk::mesh::MeshSet& ms, - std::int64_t& numberOfCells, - std::int64_t& numberOfPoints) -{ - std::int64_t connectivityLength; - PreAllocatedTessellation::determineAllocationLengths( - ms.cells(), connectivityLength, numberOfCells, numberOfPoints); -} - -PreAllocatedMeshConstants::PreAllocatedMeshConstants( - std::int64_t* cellMeshConstants, - std::int64_t* pointMeshConstants) - : m_cellMeshConstants(cellMeshConstants) - , m_pointMeshConstants(pointMeshConstants) -{ -} - -template -void MeshConstants::extract(const smtk::mesh::MeshSet& ms, const smtk::mesh::PointSet& ps) -{ - //determine the lengths - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - PreAllocatedMeshConstants::determineAllocationLengths(ms, numberOfCells, numberOfPoints); - m_cellData.resize(numberOfCells); - //since the input PointSet can contain more points that the computed number, - //set numberOfPoints to the PointSet size. - numberOfPoints = ps.size(); - m_pointData.resize(numberOfPoints); - - PreAllocatedMeshConstants field(m_cellData.data(), m_pointData.data()); - - extractMeshConstants(ms, ps, field); -} - -template void MeshConstants::extract( - const smtk::mesh::MeshSet& ms, - const smtk::mesh::PointSet& ps); -template void MeshConstants::extract( - const smtk::mesh::MeshSet& ms, - const smtk::mesh::PointSet& ps); -template void MeshConstants::extract( - const smtk::mesh::MeshSet& ms, - const smtk::mesh::PointSet& ps); - -void MeshConstants::extractDirichlet(const smtk::mesh::MeshSet& ms) -{ - this->extract(ms, ms.points()); -} - -void MeshConstants::extractNeumann(const smtk::mesh::MeshSet& ms) -{ - this->extract(ms, ms.points()); -} - -void MeshConstants::extractDomain(const smtk::mesh::MeshSet& ms) -{ - this->extract(ms, ms.points()); -} - -void MeshConstants::extractDirichlet(const smtk::mesh::MeshSet& ms, const smtk::mesh::PointSet& ps) -{ - this->extract(ms, ps); -} - -void MeshConstants::extractNeumann(const smtk::mesh::MeshSet& ms, const smtk::mesh::PointSet& ps) -{ - this->extract(ms, ps); -} - -void MeshConstants::extractDomain(const smtk::mesh::MeshSet& ms, const smtk::mesh::PointSet& ps) -{ - this->extract(ms, ps); -} - -namespace -{ -void QueryTags(const smtk::mesh::MeshSet& ms, std::vector& tags) -{ - tags = ms.dirichlets(); -} - -void QueryTags(const smtk::mesh::MeshSet& ms, std::vector& tags) -{ - tags = ms.neumanns(); -} - -void QueryTags(const smtk::mesh::MeshSet& ms, std::vector& tags) -{ - tags = ms.domains(); -} - -template -struct TaggedRangeForQuery -{ - TaggedRangeForQuery(QueryTag tag, std::pair range) - : m_tag(tag) - , m_range(range) - { - } - - friend bool operator<(const TaggedRangeForQuery& left, const TaggedRangeForQuery& right) - { - return left.m_range.first < right.m_range.first; - } - - QueryTag m_tag; - std::pair m_range; -}; -} // namespace - -template -void extractMeshConstants( - const smtk::mesh::MeshSet& ms, - const smtk::mesh::PointSet& ps, - PreAllocatedMeshConstants& field) -{ - // We need to preserve the internal ordering of the cells and points in - // MeshSet . So, we first separate into discrete submeshes for each - // unique tag. We then add a "null" tag with a unique integer value to denote - // the absense of a tag. Then, we loop over each submesh and extract - // contiguous cell and point ranges. We then sort these contiguous ranges. - // Finally, we assign tag values to our cell and point fields according to - // each contiguous block. - - typedef TaggedRangeForQuery TaggedRange; - - // and hold the tag for a contiguous cell/point - // range, and the start and end indices (inclusive) of the range. - std::vector cellRanges; - std::vector pointRanges; - - // holds the tag and discrete submesh for each unique tag. - std::vector> meshes; - - // holds the unique tags - std::vector tags; - QueryTags(ms, tags); - - // We add a "null" tag to denote cells/points that are not tagged. The null - // tag is assigned to the mesh elements that are not associated with any tag, - // so we loop over the existing subsets and remove them from the original - // mesh. - smtk::mesh::MeshSet nullSet = ms; - meshes.reserve(tags.size()); - for (auto&& tag : tags) - { - smtk::mesh::MeshSet subset = ms.subset(tag); - meshes.push_back(std::make_pair(tag, subset)); - nullSet = set_difference(nullSet, subset); - } - - // We need an unused value to assign our null tag. We start with -1, and - // increment until we find an unused value. - int nullValue = -1; - while (true) - { - bool foundUniqueValue = true; - for (auto&& subset : meshes) - { - if (subset.first.value() == nullValue) - { - foundUniqueValue = false; - break; - } - } - if (foundUniqueValue) - { - break; - } - ++nullValue; - } - - // Now that our null tag and null set are constructed, we add them as a pair - // to our meshes array. - meshes.push_back(std::make_pair(QueryTag(nullValue), nullSet)); - - // From here, it is assumed that forms a complete partition (i.e. no - // overlaps, no missing elements) of our original meshset. To guard against - // this assumption, we continuously extract our subcells/subpoints from the - // original cells/points, ensuring there is no overlap. We loop over our - // partition and extract contiguous cell/point ranges associated with each - // tag. This data is used to populate and . - - // and are kept intact because they are used as references - // for indexing - smtk::mesh::CellSet cells = ms.cells(); - const smtk::mesh::PointSet& points = ps; - - // and are contininually diminished to - // ensure that no overlapping cells or points are double-counted - smtk::mesh::CellSet remainingCells = cells; - smtk::mesh::PointSet remainingPoints = points; - - cellRanges.reserve(meshes.size()); - pointRanges.reserve(meshes.size()); - for (auto&& subset : meshes) - { - smtk::mesh::CellSet subcells = set_intersect(remainingCells, subset.second.cells()); - smtk::mesh::PointSet subpoints = set_intersect(remainingPoints, subset.second.points()); - for (auto range = subcells.range().begin(); range != subcells.range().end(); ++range) - { - cellRanges.push_back(TaggedRange( - subset.first, - std::make_pair( - rangeIndex(cells.range(), range->lower()), rangeIndex(cells.range(), range->upper())))); - } - - for (auto range = subpoints.range().begin(); range != subpoints.range().end(); ++range) - { - pointRanges.push_back(TaggedRange( - subset.first, - std::make_pair( - rangeIndex(points.range(), range->lower()), rangeIndex(points.range(), range->upper())))); - } - - remainingCells = set_difference(remainingCells, subcells); - remainingPoints = set_difference(remainingPoints, subpoints); - } - - // Since each range is contiguous and represents a partition of the underlying - // cells/points of the input meshset, we use as a sort function a comparator - // between the first indices of each range. - std::sort(cellRanges.begin(), cellRanges.end()); - std::sort(pointRanges.begin(), pointRanges.end()); - - // Finally, we assign our tag value to contiguous blocks of our cell/point - // field arrays. - std::size_t cellRangeStart = 0; - for (auto&& range : cellRanges) - { - std::size_t span = range.m_range.second - range.m_range.first + 1; - std::fill( - &field.m_cellMeshConstants[cellRangeStart], - &field.m_cellMeshConstants[cellRangeStart] + span, - range.m_tag.value()); - cellRangeStart += span; - } - - std::size_t pointRangeStart = 0; - for (auto&& range : pointRanges) - { - std::size_t span = range.m_range.second - range.m_range.first + 1; - std::fill( - &field.m_pointMeshConstants[pointRangeStart], - &field.m_pointMeshConstants[pointRangeStart] + span, - range.m_tag.value()); - pointRangeStart += span; - } -} - -template void extractMeshConstants( - const smtk::mesh::MeshSet&, - const smtk::mesh::PointSet&, - PreAllocatedMeshConstants&); -template void extractMeshConstants( - const smtk::mesh::MeshSet&, - const smtk::mesh::PointSet&, - PreAllocatedMeshConstants&); -template void extractMeshConstants( - const smtk::mesh::MeshSet&, - const smtk::mesh::PointSet&, - PreAllocatedMeshConstants&); - -void extractDirichletMeshConstants(const smtk::mesh::MeshSet& ms, PreAllocatedMeshConstants& field) -{ - extractMeshConstants(ms, ms.points(), field); -} - -void extractNeumannMeshConstants(const smtk::mesh::MeshSet& ms, PreAllocatedMeshConstants& field) -{ - extractMeshConstants(ms, ms.points(), field); -} - -void extractDomainMeshConstants(const smtk::mesh::MeshSet& ms, PreAllocatedMeshConstants& field) -{ - extractMeshConstants(ms, ms.points(), field); -} - -void extractDirichletMeshConstants( - const smtk::mesh::MeshSet& ms, - const smtk::mesh::PointSet& ps, - PreAllocatedMeshConstants& field) -{ - extractMeshConstants(ms, ps, field); -} - -void extractNeumannMeshConstants( - const smtk::mesh::MeshSet& ms, - const smtk::mesh::PointSet& ps, - PreAllocatedMeshConstants& field) -{ - extractMeshConstants(ms, ps, field); -} - -void extractDomainMeshConstants( - const smtk::mesh::MeshSet& ms, - const smtk::mesh::PointSet& ps, - PreAllocatedMeshConstants& field) -{ - extractMeshConstants(ms, ps, field); -} -} // namespace utility -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/utility/ExtractMeshConstants.h b/smtk/mesh/utility/ExtractMeshConstants.h deleted file mode 100644 index 49efc95c264cb2b97a5d1b88eb0eb0d10649ec6d..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/ExtractMeshConstants.h +++ /dev/null @@ -1,119 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_utility_ExtractMeshConstants_h -#define smtk_mesh_utility_ExtractMeshConstants_h - -#include - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/MeshSet.h" - -namespace smtk -{ -namespace model -{ -class EntityRef; -class Loop; -} // namespace model -namespace mesh -{ -namespace utility -{ - -class SMTKCORE_EXPORT PreAllocatedMeshConstants -{ - -public: - static void determineAllocationLengths( - const smtk::mesh::MeshSet& ms, - std::int64_t& numberOfCells, - std::int64_t& numberOfPoints); - - PreAllocatedMeshConstants(std::int64_t* cellMeshConstants, std::int64_t* pointMeshConstants); - -private: - template - friend SMTKCORE_EXPORT void extractMeshConstants( - const smtk::mesh::MeshSet&, - const smtk::mesh::PointSet&, - PreAllocatedMeshConstants&); - - std::int64_t* m_cellMeshConstants; - std::int64_t* m_pointMeshConstants; -}; - -class SMTKCORE_EXPORT MeshConstants -{ -public: - MeshConstants() = default; - - //This class self allocates all the memory needed to extract tessellation - //and auto extract the tessellation based on the MeshSet you pass in - void extractDirichlet(const smtk::mesh::MeshSet& ms); - void extractNeumann(const smtk::mesh::MeshSet& ms); - void extractDomain(const smtk::mesh::MeshSet& ms); - - void extractDirichlet(const smtk::mesh::MeshSet& cs, const smtk::mesh::PointSet& ps); - void extractNeumann(const smtk::mesh::MeshSet& cs, const smtk::mesh::PointSet& ps); - void extractDomain(const smtk::mesh::MeshSet& cs, const smtk::mesh::PointSet& ps); - - //use these methods to gain access to the field after extraction - const std::vector& cellData() const { return m_cellData; } - const std::vector& pointData() const { return m_pointData; } - -private: - template - void extract(const smtk::mesh::MeshSet& ms, const smtk::mesh::PointSet& ps); - - std::vector m_cellData; - std::vector m_pointData; -}; - -//Don't wrap these for python, instead python should use the MeshConstants class and -//the extract method - -SMTKCORE_EXPORT void extractDirichletMeshConstants( - const smtk::mesh::MeshSet&, - PreAllocatedMeshConstants&); -SMTKCORE_EXPORT void extractNeumannMeshConstants( - const smtk::mesh::MeshSet&, - PreAllocatedMeshConstants&); -SMTKCORE_EXPORT void extractDomainMeshConstants( - const smtk::mesh::MeshSet&, - PreAllocatedMeshConstants&); - -//Extract MeshConstants with respect to another PointSet instead of the PointSet -//contained by the meshset. This is useful if you are sharing a single -//PointSet among multiple MeshConstantss. -SMTKCORE_EXPORT void extractDirichletMeshConstants( - const smtk::mesh::MeshSet&, - const smtk::mesh::PointSet&, - PreAllocatedMeshConstants&); -SMTKCORE_EXPORT void extractNeumannMeshConstants( - const smtk::mesh::MeshSet&, - const smtk::mesh::PointSet&, - PreAllocatedMeshConstants&); -SMTKCORE_EXPORT void extractDomainMeshConstants( - const smtk::mesh::MeshSet&, - const smtk::mesh::PointSet&, - PreAllocatedMeshConstants&); - -template -// NOLINTNEXTLINE(readability-redundant-declaration) -SMTKCORE_EXPORT void extractMeshConstants( - const smtk::mesh::MeshSet&, - const smtk::mesh::PointSet&, - PreAllocatedMeshConstants&); -} // namespace utility -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/utility/ExtractTessellation.cxx b/smtk/mesh/utility/ExtractTessellation.cxx deleted file mode 100644 index 7337edab4f31c212bd003064cc7ec99c8db3e585..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/ExtractTessellation.cxx +++ /dev/null @@ -1,735 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/utility/ExtractTessellation.h" - -#include "smtk/mesh/core/PointConnectivity.h" -#include "smtk/mesh/core/PointSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/Edge.h" -#include "smtk/model/EdgeUse.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Loop.h" -#include "smtk/model/Vertex.h" - -#include -#include -#include - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -namespace detail -{ - -inline unsigned char smtkToSMTKCell(smtk::mesh::CellType t, int numPts) -{ - (void)numPts; - return t; -} - -inline unsigned char smtkToVTKCell(smtk::mesh::CellType t, int numPts) -{ - unsigned char ctype = 0; //VTK_EMPTY_CELL - switch (t) - { - case smtk::mesh::Vertex: - ctype = 1; //VTK_VERTEX - break; - case smtk::mesh::Line: - ctype = (numPts == 2 ? 3 : 68); //VTK_LINE or VTK_LAGRANGE_CURVE - break; - case smtk::mesh::Triangle: - ctype = (numPts == 3 ? 5 : 69); //VTK_TRIANGLE or VTK_LAGRANGE_TRIANGLE - break; - case smtk::mesh::Quad: - ctype = (numPts == 4 ? 9 : 70); //VTK_QUAD or VTK_LAGRANGE_QUADRILATERAL - break; - case smtk::mesh::Polygon: - ctype = 7; //VTK_POLYGON - break; - case smtk::mesh::Tetrahedron: - ctype = (numPts == 4 ? 10 : 71); //VTK_TETRA or VTK_LAGRANGE_TETRAHEDRON - break; - case smtk::mesh::Pyramid: - ctype = (numPts == 5 ? 14 : 74); //VTK_PYRAMID or VTK_LAGRANGE_PYRAMID - break; - case smtk::mesh::Wedge: - ctype = (numPts == 6 ? 13 : 75); //VTK_WEDGE or VTK_LAGRANGE_WEDGE - break; - case smtk::mesh::Hexahedron: - ctype = (numPts == 8 ? 12 : 72); //VTK_HEXAHEDRON or VTK_LAGRANGE_HEXAHEDRON - break; - default: - ctype = 0; //VTK_EMPTY_CELL - break; - } - return ctype; -} - -inline std::size_t smtkToSMTKLocation(const std::size_t& location, int numPts) -{ - return location + numPts; -} - -inline std::size_t smtkToVTKLocation(const std::size_t& location, int numPts) -{ - return location + numPts + 1; -} - -inline std::size_t smtkToSMTKConn(std::int64_t& /*unused*/, std::size_t index, int /*unused*/) -{ - //do nothing as we aren't storing the length of each cell in the connectivity - //array - return index; -} - -inline std::size_t smtkToVTKConn(std::int64_t& conn, std::size_t index, int numPts) -{ - //store the length of the cell in the connectivity array - conn = numPts; - return index + 1; -} - -} //namespace detail - -void PreAllocatedTessellation::determineAllocationLengths( - const smtk::mesh::MeshSet& ms, - std::int64_t& connectivityLength, - std::int64_t& numberOfCells, - std::int64_t& numberOfPoints) - -{ - determineAllocationLengths(ms.cells(), connectivityLength, numberOfCells, numberOfPoints); -} - -void PreAllocatedTessellation::determineAllocationLengths( - const smtk::mesh::CellSet& cs, - std::int64_t& connectivityLength, - std::int64_t& numberOfCells, - std::int64_t& numberOfPoints) - -{ - connectivityLength = cs.pointConnectivity().size(); - numberOfCells = cs.size(); - numberOfPoints = cs.points().size(); -} - -void PreAllocatedTessellation::determineAllocationLengths( - const smtk::model::EntityRef& eRef, - const smtk::mesh::ResourcePtr& c, - std::int64_t& connectivityLength, - std::int64_t& numberOfCells, - std::int64_t& numberOfPoints) - -{ - determineAllocationLengths( - c->findAssociatedCells(eRef), connectivityLength, numberOfCells, numberOfPoints); -} - -void PreAllocatedTessellation::determineAllocationLengths( - const smtk::model::Loop& loop, - const smtk::mesh::ResourcePtr& c, - std::int64_t& connectivityLength, - std::int64_t& numberOfCells, - std::int64_t& numberOfPoints) - -{ - smtk::mesh::HandleRange cellRange; - smtk::mesh::CellSet cells(c, cellRange); - - // Grab the edge uses from the loop. - smtk::model::EdgeUses euses = loop.edgeUses(); - - // Loop over the edge uses - for (auto eu = euses.crbegin(); eu != euses.crend(); ++eu) - { - // Collect the cells associated with the edge connected to the edge use - cells = set_union(cells, c->findAssociatedCells(eu->edge())); - } - - determineAllocationLengths(cells, connectivityLength, numberOfCells, numberOfPoints); -} - -PreAllocatedTessellation::PreAllocatedTessellation(std::int64_t* connectivity) - : m_connectivity(connectivity) - , m_cellLocations(nullptr) - , m_cellTypes(nullptr) - , m_dpoints(nullptr) - , m_fpoints(nullptr) - , m_useVTKConnectivity(true) - , m_useVTKCellTypes(true) -{ -} - -PreAllocatedTessellation::PreAllocatedTessellation(std::int64_t* connectivity, float* points) - : m_connectivity(connectivity) - , m_cellLocations(nullptr) - , m_cellTypes(nullptr) - , m_dpoints(nullptr) - , m_fpoints(points) - , m_useVTKConnectivity(true) - , m_useVTKCellTypes(true) -{ -} - -PreAllocatedTessellation::PreAllocatedTessellation(std::int64_t* connectivity, double* points) - : m_connectivity(connectivity) - , m_cellLocations(nullptr) - , m_cellTypes(nullptr) - , m_dpoints(points) - , m_fpoints(nullptr) - , m_useVTKConnectivity(true) - , m_useVTKCellTypes(true) -{ -} - -PreAllocatedTessellation::PreAllocatedTessellation( - std::int64_t* connectivity, - std::int64_t* cellLocations, - unsigned char* cellTypes) - : m_connectivity(connectivity) - , m_cellLocations(cellLocations) - , m_cellTypes(cellTypes) - , m_dpoints(nullptr) - , m_fpoints(nullptr) - , m_useVTKConnectivity(true) - , m_useVTKCellTypes(true) -{ -} - -PreAllocatedTessellation::PreAllocatedTessellation( - std::int64_t* connectivity, - std::int64_t* cellLocations, - unsigned char* cellTypes, - float* points) - : m_connectivity(connectivity) - , m_cellLocations(cellLocations) - , m_cellTypes(cellTypes) - , m_dpoints(nullptr) - , m_fpoints(points) - , m_useVTKConnectivity(true) - , m_useVTKCellTypes(true) -{ -} - -PreAllocatedTessellation::PreAllocatedTessellation( - std::int64_t* connectivity, - std::int64_t* cellLocations, - unsigned char* cellTypes, - double* points) - : m_connectivity(connectivity) - , m_cellLocations(cellLocations) - , m_cellTypes(cellTypes) - , m_dpoints(points) - , m_fpoints(nullptr) - , m_useVTKConnectivity(true) - , m_useVTKCellTypes(true) -{ -} - -Tessellation::Tessellation() = default; - -Tessellation::Tessellation(bool useVTKConnectivity, bool useVTKCellTypes) - : m_useVTKConnectivity(useVTKConnectivity) - , m_useVTKCellTypes(useVTKCellTypes) -{ -} - -void Tessellation::extract(const smtk::mesh::MeshSet& ms) -{ - this->extract(ms.cells(), ms.points()); -} - -void Tessellation::extract(const smtk::mesh::CellSet& cs) -{ - this->extract(cs, cs.points()); -} - -void Tessellation::extract(const smtk::mesh::MeshSet& ms, const smtk::mesh::PointSet& ps) -{ - this->extract(ms.cells(), ps); -} - -void Tessellation::extract(const smtk::mesh::CellSet& cs, const smtk::mesh::PointSet& ps) -{ - //determine the lengths - std::int64_t connectivityLength = -1; - std::int64_t numberOfCells = -1; - std::int64_t numberOfPoints = -1; - - PreAllocatedTessellation::determineAllocationLengths( - cs, connectivityLength, numberOfCells, numberOfPoints); - //handle vtk style connectivity - if (this->useVTKConnectivity()) - { - connectivityLength += numberOfCells; - } - - m_connectivity.resize(connectivityLength); - m_cellLocations.resize(numberOfCells); - m_cellTypes.resize(numberOfCells); - //since the input PointSet can contain more points that the computed number, - //set numberOfPoints to the PointSet size. - numberOfPoints = ps.size(); - m_points.resize(numberOfPoints * 3); - - PreAllocatedTessellation tess( - m_connectivity.data(), m_cellLocations.data(), m_cellTypes.data(), m_points.data()); - - //set the vtk connectivity and cell types flags properly - const bool disableVTKConn = !this->useVTKConnectivity(); - const bool disableVTKCellTypes = !this->useVTKCellTypes(); - tess.disableVTKStyleConnectivity(disableVTKConn); - tess.disableVTKCellTypes(disableVTKCellTypes); - - extractTessellation(cs, ps, tess); -} - -void extractTessellation(const smtk::mesh::MeshSet& ms, PreAllocatedTessellation& tess) -{ - extractTessellation(ms.cells(), ms.points(), tess); -} - -void extractTessellation(const smtk::mesh::CellSet& cs, PreAllocatedTessellation& tess) -{ - extractTessellation(cs, cs.points(), tess); -} - -void extractTessellation( - const smtk::model::EntityRef& eRef, - const smtk::mesh::ResourcePtr& c, - PreAllocatedTessellation& tess) -{ - CellSet cs = c->findAssociatedCells(eRef); - extractTessellation(cs, cs.points(), tess); -} - -void extractTessellation( - const smtk::mesh::MeshSet& ms, - const smtk::mesh::PointSet& ps, - PreAllocatedTessellation& tess) -{ - extractTessellation(ms.cells(), ps, tess); -} - -void extractTessellation( - const smtk::mesh::CellSet& cs, - const smtk::mesh::PointSet& ps, - PreAllocatedTessellation& tess) -{ - smtk::mesh::PointConnectivity pc = cs.pointConnectivity(); - extractTessellation(pc, ps, tess); -} - -template -void extractTessellationInternal( - PointConnectivity& pc, - const smtk::mesh::PointSet& ps, - PreAllocatedTessellation& tess) -{ - //we need to detect what options of tesselation the user has enabled. - const bool fetch_cellLocations = tess.m_cellLocations != nullptr; - const bool fetch_fPoints = tess.m_fpoints != nullptr; - const bool fetch_dPoints = tess.m_dpoints != nullptr; - - //we need to determine what version of this function we are actually - //using. This is fairly important as we don't want to branch within the - //tight loop. To complicate the matter we also have to determine if - //we are using VTK style connectivity or a compacted connectivity format. - - //determine the function pointer to use for the connectivity array - std::size_t (*addCellLen)(std::int64_t& conn, std::size_t index, int numPts) = - detail::smtkToSMTKConn; - if (tess.m_useVTKConnectivity) - { - addCellLen = detail::smtkToVTKConn; - } - - //construct a map to better search for point ids - std::unordered_map pointMap; - auto it = smtk::mesh::rangeElementsBegin(ps.range()); - auto end = smtk::mesh::rangeElementsEnd(ps.range()); - for (std::size_t counter = 0; it != end; ++it, ++counter) - { - pointMap[*it] = counter; - } - - int numPts = 0; - const smtk::mesh::Handle* pointIds; - std::size_t conn_index = 0; - smtk::mesh::CellType ctype; - if (fetch_cellLocations) - { - //determine the function pointer to use for the cell type conversion - unsigned char (*convertCellTypeFunction)(smtk::mesh::CellType t, int numPts) = - detail::smtkToSMTKCell; - if (tess.m_useVTKCellTypes) - { - convertCellTypeFunction = detail::smtkToVTKCell; - } - - //Issue we haven't handled the VTK syst - std::size_t index = 0; - for (pc.initCellTraversal(); pc.fetchNextCell(ctype, numPts, pointIds); - ++index, conn_index += numPts) - { - //first we mark the current cell location this is done before addCellLen as that - //will modify conn_index - tess.m_cellLocations[index] = conn_index; - - conn_index = addCellLen(*(tess.m_connectivity + conn_index), conn_index, numPts); - - for (int i = 0; i < numPts; ++i) - { - //determine the proper index for the point id. the point id value is - //based off the global point id, and we need to transform it to a - //relative id based of the pointset that was passed in - tess.m_connectivity[conn_index + i] = pointMap[pointIds[i]]; - } - - tess.m_cellTypes[index] = convertCellTypeFunction(ctype, numPts); - } - } - else - { - for (pc.initCellTraversal(); pc.fetchNextCell(ctype, numPts, pointIds); conn_index += numPts) - { - conn_index = addCellLen(*(tess.m_connectivity + conn_index), conn_index, numPts); - - for (int i = 0; i < numPts; ++i) - { - //determine the proper index for the point id. the point id value is - //based off the global point id, and we need to transform it to a - //relative id based of the pointset that was passed in - tess.m_connectivity[conn_index + i] = pointMap[pointIds[i]]; - } - } - } - - //we now have to read in the points if requested - if (fetch_dPoints) - { - ps.get(tess.m_dpoints); - } - else if (fetch_fPoints) - { - ps.get(tess.m_fpoints); - } -} - -void extractTessellation( - smtk::mesh::PointConnectivity& pc, - const smtk::mesh::PointSet& ps, - PreAllocatedTessellation& tess) -{ - extractTessellationInternal(pc, ps, tess); -} - -void extractTessellation( - const smtk::model::EntityRef& eRef, - const smtk::mesh::ResourcePtr& c, - const smtk::mesh::PointSet& ps, - PreAllocatedTessellation& tess) -{ - extractTessellation(c->findAssociatedCells(eRef), ps, tess); -} - -namespace -{ -// A Link is simply a pair of vertex ids. -struct Link -{ - [[nodiscard]] const smtk::mesh::Handle& first() const { return this->Handles[0]; } - [[nodiscard]] const smtk::mesh::Handle& second() const { return this->Handles[1]; } - - smtk::mesh::Handle Handles[2]; -}; - -// A Chain is a list of Links, allowing for O[1] prepending, appending and -// joining. -typedef std::deque Chain; - -// An OrderedEdge is a list of Chains that supports the addition of links and -// the merging of chains. -struct OrderedEdge -{ - OrderedEdge() - : MergeLimit(std::numeric_limits::max()) - { - } - - // When a link is inserted, we check to see if it can be prepended or - // appended to any extant chains. If it can, we add it to the appropriate - // chain in the correct orientation. Otherwise, it seeds a new Chain. If - // the number of Chains exceeds the user-defined Merge Limit, the Chains - // are merged. - void insert_link(Link& l) - { - if (this->Chains.size() >= this->MergeLimit) - { - this->merge_chains(); - } - - // link (a,b) - for (auto& c : this->Chains) - { - if (l.second() == c.front().first()) - { - // (a,b) -> (b,...) - c.push_front(l); - return; - } - else if (l.first() == c.back().second()) - { - // (...,a) <- (a,b) - c.push_back(l); - return; - } - } - Chain c(1, l); - this->Chains.push_back(c); - } - - // merge_chains consists of two loops over our Chains. For each Chain c1, - // we cycle through the subsequent Chains in the list to see if they can be - // appended or prepended to c1. Once all possible connections have been made - // to c1, we move to the next chain. If all Links are present, the outer - // loop will execute exactly one iteration. Otherwise, Chain fragments are - // merged, ensuring the fewest possible number of Chains remain. - void merge_chains() - { - for (auto c1 = this->Chains.begin(); c1 != Chains.end();) - { - const std::size_t c1_size = c1->size(); - auto c2 = c1; - for (++c2; c2 != Chains.end(); ++c2) - { - if (c2->empty()) - { - continue; - } - - // chain c1 looks like (a,...,b) - if (c1->front().first() == c2->back().second()) - { - // (...,a) -> (a,...,b) - c1->insert( - c1->begin(), std::make_move_iterator(c2->begin()), std::make_move_iterator(c2->end())); - c2->clear(); - } - else if (c2->front().first() == c1->back().second()) - { - // (a,...,b) <- (b,...) - c1->insert( - c1->end(), std::make_move_iterator(c2->begin()), std::make_move_iterator(c2->end())); - c2->clear(); - } - } - if (c1->size() == c1_size) - { - ++c1; - } - } - - // Erase the empty chains. - for (auto c1 = this->Chains.begin(); c1 != Chains.end();) - { - if (c1->empty()) - { - c1 = this->Chains.erase(c1); - } - else - { - ++c1; - } - } - } - - std::deque Chains; - std::size_t MergeLimit; -}; - -class OrderedConnectivity -{ -public: - OrderedConnectivity(const std::deque& chains) - : Chains(chains) - { - } - - void initCellTraversal() - { - this->WhichConnectivityVector = this->Chains.begin(); - if (this->WhichConnectivityVector != this->Chains.end()) - { - this->WhichLink = (*this->WhichConnectivityVector).begin(); - } - } - - bool fetchNextCell(smtk::mesh::CellType& cellType, int& numPts, const smtk::mesh::Handle*& points) - { - // IterationState tracks connectivity by indices. We have lists though, - // so we keep their indices and our iterators in lockstep. We probably - // don't need to update the state at all, since our storage is not - // accessible externally. - - numPts = 0; - - // We start by ensuring our connectivity vector is valid. - if (this->WhichConnectivityVector == this->Chains.end()) - { - return false; - } - - // We then increment our offset in the connectivity vector and check that - // it is still valid - if (++this->WhichLink == this->WhichConnectivityVector->end()) - { - if (++this->WhichConnectivityVector == this->Chains.end()) - { - return false; - } - this->WhichLink = this->WhichConnectivityVector->begin(); - } - - // Now our connectivity iterators and indices are all in the right place. - cellType = smtk::mesh::Line; - numPts = 2; - points = this->WhichLink->Handles; - - return true; - } - -private: - const std::deque& Chains; - std::deque::const_iterator WhichConnectivityVector; - Chain::const_iterator WhichLink; -}; - -template -void extractOrderedTessellation( - const OneDimensionalEntities& oneDimEntities, - const smtk::mesh::ResourcePtr& c, - const smtk::mesh::PointSet& ps, - PreAllocatedTessellation& tess) -{ - // Assuming that the lines that make up a loop are oriented but not ordered, - // extractOrderedTessellation() takes an iterable collection of 1-dimensional - // model entities and orders the output lines before extracting the - // tessellation. - - OrderedEdge orderedEdge; - Link link; - - for (auto ent = oneDimEntities.cbegin(); ent != oneDimEntities.cend(); ++ent) - { - // Grab the orientation of the entity - int orientation = ent->orientation(); - - // Collect the cells associated with the edge connected to the edge use - CellSet cs = c->findAssociatedCells(*ent); - - // Retrieve its point connectivity array - smtk::mesh::PointConnectivity pc = cs.pointConnectivity(); - - int numPts = 0; - const smtk::mesh::Handle* pointIds; - // For large lists of cells, have the loop collapse its chain fragments - // periodically during insertion. - if (pc.numberOfCells() > 20) - { - orderedEdge.MergeLimit = static_cast(std::sqrt(pc.numberOfCells())); - } - // For each line segment in our edge... - for (pc.initCellTraversal(); pc.fetchNextCell(numPts, pointIds);) - { - // ... we construct a link and add it to our ordered loop. - if (orientation == 1) - { - link.Handles[0] = ps.find(pointIds[0]); - link.Handles[1] = ps.find(pointIds[1]); - } - else - { - link.Handles[0] = ps.find(pointIds[1]); - link.Handles[1] = ps.find(pointIds[0]); - } - orderedEdge.insert_link(link); - } - orderedEdge.merge_chains(); - } - - // Create our own PointConnectivity using our ordered edge - OrderedConnectivity orderedPC(orderedEdge.Chains); - - extractTessellationInternal(orderedPC, ps, tess); -} -} // namespace - -void extractOrderedTessellation( - const smtk::model::EdgeUse& edgeUse, - const smtk::mesh::ResourcePtr& c, - PreAllocatedTessellation& tess) -{ - // Collect the cells associated with the edge - smtk::mesh::CellSet cells = c->findAssociatedCells(edgeUse.edge()); - extractOrderedTessellation(edgeUse, c, cells.points(), tess); -} - -void extractOrderedTessellation( - const smtk::model::Loop& loop, - const smtk::mesh::ResourcePtr& c, - PreAllocatedTessellation& tess) -{ - smtk::mesh::HandleRange cellRange; - smtk::mesh::CellSet cells(c, cellRange); - - // Grab the edge uses from the loop. - smtk::model::EdgeUses edgeUses = loop.edgeUses(); - - // Loop over the edge uses - for (auto eu = edgeUses.crbegin(); eu != edgeUses.crend(); ++eu) - { - // Collect the cells associated with the edge connected to the edge use - cells = set_union(cells, c->findAssociatedCells(eu->edge())); - } - - extractOrderedTessellation(loop, c, cells.points(), tess); -} - -void extractOrderedTessellation( - const smtk::model::EdgeUse& edgeUse, - const smtk::mesh::ResourcePtr& c, - const smtk::mesh::PointSet& ps, - PreAllocatedTessellation& tess) -{ - smtk::model::EdgeUses edgeUses; - edgeUses.push_back(edgeUse); - extractOrderedTessellation(edgeUses, c, ps, tess); -} - -void extractOrderedTessellation( - const smtk::model::Loop& loop, - const smtk::mesh::ResourcePtr& c, - const smtk::mesh::PointSet& ps, - PreAllocatedTessellation& tess) -{ - smtk::model::EdgeUses euses = loop.edgeUses(); - extractOrderedTessellation(euses, c, ps, tess); -} -} // namespace utility -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/utility/ExtractTessellation.h b/smtk/mesh/utility/ExtractTessellation.h deleted file mode 100644 index 851a532709e8dc156e1ac18685da5dfd7e416a73..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/ExtractTessellation.h +++ /dev/null @@ -1,221 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_utility_ExtractTessellation_h -#define smtk_mesh_utility_ExtractTessellation_h - -#include - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/MeshSet.h" - -namespace smtk -{ -namespace model -{ -class EntityRef; -class Loop; -} // namespace model -namespace mesh -{ -namespace utility -{ - -class SMTKCORE_EXPORT PreAllocatedTessellation -{ -public: - // Todo: Document that connectivityLength is just pure length of connectivity - // if you are enabling vtk length you need to allocate for connectivityLength - // + numberOfCells - static void determineAllocationLengths( - const smtk::mesh::MeshSet& ms, - std::int64_t& connectivityLength, - std::int64_t& numberOfCells, - std::int64_t& numberOfPoints); - - static void determineAllocationLengths( - const smtk::mesh::CellSet& cs, - std::int64_t& connectivityLength, - std::int64_t& numberOfCells, - std::int64_t& numberOfPoints); - - static void determineAllocationLengths( - const smtk::model::EntityRef& eRef, - const smtk::mesh::ResourcePtr& c, - std::int64_t& connectivityLength, - std::int64_t& numberOfCells, - std::int64_t& numberOfPoints); - - static void determineAllocationLengths( - const smtk::model::Loop& loop, - const smtk::mesh::ResourcePtr& c, - std::int64_t& connectivityLength, - std::int64_t& numberOfCells, - std::int64_t& numberOfPoints); - - //Only converts connectivity. The following properties will not be - //converted: cellLocations, cellTypes, and Points - PreAllocatedTessellation(std::int64_t* connectivity); - - //Converts connectivity and store the points as floats. The following properties will not be - //converted: cellLocations, and cellTypes. - PreAllocatedTessellation(std::int64_t* connectivity, float* points); - - //Converts connectivityand store the points as doubles. The following properties will not be - //converted: cellLocations, and cellTypes. - PreAllocatedTessellation(std::int64_t* connectivity, double* points); - - //Converts everything but Points. - PreAllocatedTessellation( - std::int64_t* connectivity, - std::int64_t* cellLocations, - unsigned char* cellTypes); - - //Converts everything and stores the points as floats - PreAllocatedTessellation( - std::int64_t* connectivity, - std::int64_t* cellLocations, - unsigned char* cellTypes, - float* points); - - //Converts everything and stores the points as doubles - PreAllocatedTessellation( - std::int64_t* connectivity, - std::int64_t* cellLocations, - unsigned char* cellTypes, - double* points); - - //determine if you want VTK 6.0 style connectivity array where each cell - //is preceded with an entry that states the length of the cell. Passing - //in True will disable this behavior. The default behavior of the - //class is to use VTK style connectivity. - void disableVTKStyleConnectivity(bool disable) { m_useVTKConnectivity = !disable; } - - //determine if you want VTK cell enum values for the cell types array. - //If this is disabled we use the smtk/mesh cell enum values. - void disableVTKCellTypes(bool disable) { m_useVTKCellTypes = !disable; } - - bool hasConnectivity() const { return m_connectivity != nullptr; } - bool hasCellLocations() const { return m_cellLocations != nullptr; } - bool hasCellTypes() const { return m_cellTypes != nullptr; } - - bool hasDoublePoints() const { return m_dpoints != nullptr; } - bool hasFloatPoints() const { return m_fpoints != nullptr; } - - bool useVTKConnectivity() const { return m_useVTKConnectivity; } - bool useVTKCellTypes() const { return m_useVTKCellTypes; } - -private: - template - friend SMTKCORE_EXPORT void extractTessellationInternal( - PointConnectivity&, - const smtk::mesh::PointSet&, - PreAllocatedTessellation&); - std::int64_t* m_connectivity; - std::int64_t* m_cellLocations; - unsigned char* m_cellTypes; - - double* m_dpoints; - float* m_fpoints; - - bool m_useVTKConnectivity; - bool m_useVTKCellTypes; -}; - -class SMTKCORE_EXPORT Tessellation -{ -public: - //Default construction of Tessellation, enables vtk connectivity and cell types - Tessellation(); - - Tessellation(bool useVTKConnectivity, bool useVTKCellTypes); - - bool useVTKConnectivity() const { return m_useVTKConnectivity; } - bool useVTKCellTypes() const { return m_useVTKCellTypes; } - - //This class self allocates all the memory needed to extract tessellation - //and auto extract the tessellation based on the MeshSet or CellSet you - //pass in - void extract(const smtk::mesh::MeshSet& ms); - void extract(const smtk::mesh::CellSet& cs); - - void extract(const smtk::mesh::MeshSet& cs, const smtk::mesh::PointSet& ps); - void extract(const smtk::mesh::CellSet& cs, const smtk::mesh::PointSet& ps); - - //use these methods to gain access to the tessellation after - const std::vector& connectivity() const { return m_connectivity; } - const std::vector& cellLocations() const { return m_cellLocations; } - const std::vector& cellTypes() const { return m_cellTypes; } - const std::vector& points() const { return m_points; } - -private: - std::vector m_connectivity; - std::vector m_cellLocations; - std::vector m_cellTypes; - - std::vector m_points; - - bool m_useVTKConnectivity{ true }; - bool m_useVTKCellTypes{ true }; -}; - -//Don't wrap these for python, instead python should use the Tessellation class -//and the extract method - -SMTKCORE_EXPORT void extractTessellation(const smtk::mesh::MeshSet&, PreAllocatedTessellation&); -SMTKCORE_EXPORT void extractTessellation(const smtk::mesh::CellSet&, PreAllocatedTessellation&); -SMTKCORE_EXPORT void extractTessellation( - const smtk::model::EntityRef&, - const smtk::mesh::ResourcePtr&, - PreAllocatedTessellation&); -SMTKCORE_EXPORT void extractOrderedTessellation( - const smtk::model::EdgeUse&, - const smtk::mesh::ResourcePtr&, - PreAllocatedTessellation&); -SMTKCORE_EXPORT void extractOrderedTessellation( - const smtk::model::Loop&, - const smtk::mesh::ResourcePtr&, - PreAllocatedTessellation&); - -//Extract Tessellation in respect to another PointSet instead of the PointSet -//contained by the meshset. This is useful if you are sharing a single -//PointSet among multiple Tessellations. -SMTKCORE_EXPORT void extractTessellation( - const smtk::mesh::MeshSet&, - const smtk::mesh::PointSet&, - PreAllocatedTessellation&); -SMTKCORE_EXPORT void extractTessellation( - const smtk::mesh::CellSet&, - const smtk::mesh::PointSet&, - PreAllocatedTessellation&); -SMTKCORE_EXPORT void extractTessellation( - smtk::mesh::PointConnectivity&, - const smtk::mesh::PointSet&, - PreAllocatedTessellation&); -SMTKCORE_EXPORT void extractTessellation( - const smtk::model::EntityRef&, - const smtk::mesh::ResourcePtr&, - const smtk::mesh::PointSet&, - PreAllocatedTessellation&); -SMTKCORE_EXPORT void extractOrderedTessellation( - const smtk::model::EdgeUse&, - const smtk::mesh::ResourcePtr&, - const smtk::mesh::PointSet&, - PreAllocatedTessellation&); -SMTKCORE_EXPORT void extractOrderedTessellation( - const smtk::model::Loop&, - const smtk::mesh::ResourcePtr&, - const smtk::mesh::PointSet&, - PreAllocatedTessellation&); -} // namespace utility -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/utility/Metrics.cxx b/smtk/mesh/utility/Metrics.cxx deleted file mode 100644 index 578ba747c3117b65afc161a1b4f2c316fffda595..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/Metrics.cxx +++ /dev/null @@ -1,108 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/mesh/core/ForEachTypes.h" - -#include - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -std::array extent(const smtk::mesh::MeshSet& ms) -{ - class Extent : public smtk::mesh::PointForEach - { - public: - Extent() - - { - m_values[0] = m_values[2] = m_values[4] = std::numeric_limits::max(); - m_values[1] = m_values[3] = m_values[5] = std::numeric_limits::lowest(); - } - - void forPoints( - const smtk::mesh::HandleRange& /*pointIds*/, - std::vector& xyz, - bool& /*coordinatesModified*/) override - { - for (std::size_t i = 0; i < xyz.size(); i += 3) - { - for (std::size_t j = 0; j < 3; j++) - { - if (xyz[i + j] < m_values[2 * j]) - { - m_values[2 * j] = xyz[i + j]; - } - if (xyz[i + j] > m_values[2 * j + 1]) - { - m_values[2 * j + 1] = xyz[i + j]; - } - } - } - } - - std::array m_values; - }; - - Extent extent; - smtk::mesh::for_each(ms.points(), extent); - return extent.m_values; -} - -smtk::mesh::DimensionType highestDimension(const smtk::mesh::MeshSet& ms) -{ - int highestDimension = smtk::mesh::Dims3; - while (ms.cells(static_cast(highestDimension)).is_empty() && - highestDimension >= 0) - { - --highestDimension; - } - - return highestDimension >= 0 ? static_cast(highestDimension) - : smtk::mesh::DimensionType_MAX; -} - -int eulerCharacteristic(const smtk::mesh::MeshSet& ms) -{ - // We store xi as a long long rather than an int because the algorithm adds - // and subtracts large integral values during its computation. - long long xi = 0; - smtk::mesh::MeshSet meshSet = ms; - - smtk::mesh::DimensionType highestDim = highestDimension(ms); - - if (highestDim == smtk::mesh::DimensionType_MAX) - { - return 0; - } - - // We compute xi by counting the number of adjacency cells at each dimension. - // Because of the way MOAB deals with higher-order cells, we must treat the - // vertex count by specifically requesting the number of "corners-only" points - // rather than the zero-dimensional adjacencies. - for (int i = highestDim; i >= smtk::mesh::Dims1; i--) - { - meshSet = meshSet.extractAdjacenciesOfDimension(i); - int prefactor = (i % 2 == 0 ? +1 : -1); - xi += static_cast(prefactor * meshSet.cells().size()); - } - xi += static_cast(meshSet.points(true).size()); - - return static_cast(xi); -} -} // namespace utility -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/utility/Metrics.h b/smtk/mesh/utility/Metrics.h deleted file mode 100644 index 4394ad4408bab961b47480bbc1b6f7d61d21175c..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/Metrics.h +++ /dev/null @@ -1,45 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_utility_Metrics_h -#define smtk_mesh_utility_Metrics_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/DimensionTypes.h" -#include "smtk/mesh/core/MeshSet.h" - -#include -#include - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -// Compute the bounding box of a mesh set -SMTKCORE_EXPORT -std::array extent(const smtk::mesh::MeshSet& ms); - -// Compute the highest cell dimension present a mesh set -SMTKCORE_EXPORT -smtk::mesh::DimensionType highestDimension(const smtk::mesh::MeshSet& ms); - -// Compute the Euler-Poincare characteristic of a mesh set -SMTKCORE_EXPORT -int eulerCharacteristic(const smtk::mesh::MeshSet& ms); -} // namespace utility -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/utility/Reclassify.cxx b/smtk/mesh/utility/Reclassify.cxx deleted file mode 100644 index 17298860bc79d3511def12cd035327f1b29c2efe..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/Reclassify.cxx +++ /dev/null @@ -1,326 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/mesh/utility/Reclassify.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/Interface.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/PointSet.h" -#include "smtk/mesh/core/Resource.h" - -namespace -{ -class ContainedInNewEdge : public smtk::mesh::CellForEach -{ -public: - ContainedInNewEdge(smtk::model::Edge edge) - : CellForEach(true) - - { - //Find the tessellation of the edge and store the points - //in a search-able structure. - //when we are iterating the cells we need to quickly determine - //if the points are contained inside. - //for now we are going to use a linear search :( - const smtk::model::Tessellation* tess = edge.hasTessellation(); - if (tess) - { - const std::vector& c = tess->coords(); - const std::size_t size = c.size(); - const std::size_t perSize = size / 3; - - m_Xpoints.reserve(perSize); - m_Ypoints.reserve(perSize); - m_Zpoints.reserve(perSize); - - for (std::size_t i = 0; i < size; i += 3) - { - m_Xpoints.push_back(c[i]); - m_Ypoints.push_back(c[i + 1]); - m_Zpoints.push_back(c[i + 2]); - } - } - } - - bool contains(double x, double y, double z) - { - //determine if the given point is contained in this - //edges tessellation - bool found = false; - std::size_t size = m_Xpoints.size(); - for (std::size_t i = 0; i < size && !found; ++i) - { - //Check on the X before doing an assignment to found - if (m_Xpoints[i] == x) - { - found = (m_Ypoints[i] == y && m_Zpoints[i] == z); - } - } - return found; - } - - void forCell( - const smtk::mesh::Handle& cellId, - smtk::mesh::CellType /*cellType*/, - int /*numPointIds*/) override - { - bool contained = true; - //see if the coordinates for this cell are all contained - //in the set of points. We need to build some form search - //otherwise we are looking at a linear search - const std::vector& coords = this->coordinates(); - const std::size_t size = coords.size(); - for (std::size_t i = 0; i < size && contained; i += 3) - { - contained = this->contains(coords[i], coords[i + 1], coords[i + 2]); - } - - if (contained) - { - m_cells.insert(cellId); - } - } - - [[nodiscard]] smtk::mesh::HandleRange cells() const { return m_cells; } - -private: - smtk::mesh::HandleRange m_cells; - std::vector m_Xpoints; - std::vector m_Ypoints; - std::vector m_Zpoints; -}; - -smtk::mesh::MeshSet make_MeshPoint(smtk::mesh::ResourcePtr resource, smtk::model::Vertex vertex) -{ - //What are the steps that are required here: - //1. Allocate a single point - //2. Make a HandleRange of the single point Id - //3. Make a Mesh of that HandleRange - //4. assign an association to that new mesh set - smtk::mesh::InterfacePtr interface = resource->interface(); - smtk::mesh::AllocatorPtr allocator = interface->allocator(); - const smtk::model::Tessellation* tess = vertex.hasTessellation(); - - smtk::mesh::MeshSet result; - if (tess && allocator) - { - const std::vector& c = tess->coords(); - - smtk::mesh::Handle vertexHandle; - std::vector coords; - allocator->allocatePoints(1, vertexHandle, coords); - - coords[0][0] = c[0]; - coords[1][0] = c[1]; - coords[2][0] = c[2]; - - smtk::mesh::HandleRange meshCells; - meshCells.insert(vertexHandle); - - smtk::mesh::CellSet cellsForMesh(resource, meshCells); - result = resource->createMesh(cellsForMesh); - if (!result.is_empty()) - { - resource->setAssociation(vertex, result); - } - } - - return result; -} -} // namespace - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -bool split( - smtk::mesh::ResourcePtr resource, - smtk::model::Edge orignalEdge, - smtk::model::Edge newEdge, - smtk::model::Vertex promotedVertex) -{ - if (!resource) - { - return false; - } - - if (!orignalEdge.hasTessellation() || !newEdge.hasTessellation()) - { - return false; - } //both edges need tessellation for this operator to work - - //1. find all meshes associated to original edge - smtk::mesh::MeshSet origMesh = resource->findAssociatedMeshes(orignalEdge); - if (origMesh.is_empty()) - { - return false; - } - - //1: - //Iterate the cells of the original meshset, for each cell - //check if it contained in the new-edge. If so that cell needs - //to be reclassified. - ContainedInNewEdge functor(newEdge); - smtk::mesh::for_each(origMesh.cells(), functor); - - //2: - //get the cells from the original set that should be reclassified - smtk::mesh::CellSet newEdgeCells(resource, functor.cells()); - if (newEdgeCells.is_empty()) - { //the split new edge is invalid since it had nothing in common with - //the original edge - return false; - } - - //3 create a new mesh set for the vertex - smtk::mesh::MeshSet pointMesh = make_MeshPoint(resource, promotedVertex); - if (pointMesh.is_empty()) - { //for some reason we could not allocate a new mesh - return false; - } - - //4 Make sure the new meshes are properly disjoint - smtk::mesh::MeshSet newMesh = resource->createMesh(newEdgeCells); - resource->setAssociation(newEdge, newMesh); - - bool ret = make_disjoint(resource, newMesh, origMesh, orignalEdge); - if (!ret) - { //if the split failed rollback the creation of the new mesh - resource->removeMeshes(newMesh); - } - - //5 Lastly make sure we don't have any duplicate points in the underlying - //database - smtk::mesh::MeshSet all = newMesh; - all.append(origMesh); - all.append(pointMesh); - all.mergeCoincidentContactPoints(); - - return ret; -} - -bool make_disjoint( - smtk::mesh::ResourcePtr resource, - const smtk::mesh::MeshSet& toBeRemoved, - smtk::mesh::MeshSet& removeFrom, - const smtk::model::EntityRef& modelAssoc) -{ - - //Add a new MeshSet which contains all the original cells, expect the ones - //that are in the new edge mesh set. - smtk::mesh::CellSet diff = smtk::mesh::set_difference(removeFrom.cells(), toBeRemoved.cells()); - - if (!diff.is_empty()) - { - smtk::mesh::MeshSet updatedOriginalMesh = resource->createMesh(diff); - //Remove the original meshset so we don't have the original, and new - //representation existing - const bool success = resource->removeMeshes(removeFrom); - if (!success) - { - //rollback if the the mesh removal fails - resource->removeMeshes(updatedOriginalMesh); - return false; - } - removeFrom = updatedOriginalMesh; - } - - resource->setAssociation(modelAssoc, removeFrom); - return true; -} - -bool merge( - smtk::mesh::ResourcePtr resource, - smtk::model::Vertex toRemoveVert, - smtk::model::Edge toRemoveEdge, - smtk::model::Edge toAddTo) -{ - smtk::mesh::MeshSet vertexToRemoveMS = resource->findAssociatedMeshes(toRemoveVert); - smtk::mesh::MeshSet edgeToRemoveMS = resource->findAssociatedMeshes(toRemoveEdge); - smtk::mesh::MeshSet toAddToMS = resource->findAssociatedMeshes(toAddTo); - const smtk::model::EntityRef& eref = toAddTo; - - //first we need to delete the vertex, that way if the delete fails, we - //can rollback properly. If we merge the edge and vertex and delete them - //in the fuse call, the vertex mesh items will get the edge model association - //if we have to rollback the delete - bool merged = resource->removeMeshes(vertexToRemoveMS); - if (merged) - { - return fuse(resource, edgeToRemoveMS, toAddToMS, eref); - } - else - { - //make sure the association is restored, since the delete failed - //it is better to be safe than sorry - resource->setAssociation(toRemoveVert, vertexToRemoveMS); - } - return false; -} - -bool fuse( - smtk::mesh::ResourcePtr resource, - smtk::mesh::MeshSet& toRemove, - smtk::mesh::MeshSet& toAddTo, - const smtk::model::EntityRef& toAddToAssoc) -{ - //Merge two mesh sets together and create a single meshset from that - // - //The logic of the fuse is slightly more complicated than expected because - //you want to handle the ability to rollback a failed removal properly. - // - //Secondly you want to add the new mesh before removing the old mesh, - //that signals to the underlying interface that the cells of the - //deleted mesh are used by another meshset and shouldn't be deleted, - //but just delete the meshset - - smtk::mesh::CellSet newSetCells = toAddTo.cells(); - newSetCells.append(toRemove.cells()); - if (newSetCells.is_empty()) - { - return false; - } - - smtk::mesh::MeshSet newSet = resource->createMesh(newSetCells); - if (newSet.is_empty()) - { - return false; - } - - bool removed = resource->removeMeshes(toAddTo); - if (!removed) - { - resource->removeMeshes(newSet); - return false; - } - - removed = removed && resource->removeMeshes(toRemove); - if (!removed) - { - //rollback the deletion of the first meshset - toAddTo = resource->createMesh(toAddTo.cells()); - resource->setAssociation(toAddToAssoc, toAddTo); - - resource->removeMeshes(newSet); - return false; - } - - //update what toAddTo is point too - toAddTo = newSet; - resource->setAssociation(toAddToAssoc, toAddTo); - return true; -} -} // namespace utility -} // namespace mesh -} // namespace smtk diff --git a/smtk/mesh/utility/Reclassify.h b/smtk/mesh/utility/Reclassify.h deleted file mode 100644 index c1612682fd75f67862848fbe2bf92d008fde8bd0..0000000000000000000000000000000000000000 --- a/smtk/mesh/utility/Reclassify.h +++ /dev/null @@ -1,75 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_mesh_utility_Reclassify_h -#define smtk_mesh_utility_Reclassify_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/mesh/core/MeshSet.h" - -#include "smtk/model/Edge.h" -#include "smtk/model/Vertex.h" - -namespace smtk -{ -namespace mesh -{ -namespace utility -{ - -//This operation is the mesh mirror for the split operator of a model -//It needs to occur after the model operation has been run. -//The first parameter is the original Edge that has been split, -//the second parameter being the new edge which was -SMTKCORE_EXPORT -bool split( - smtk::mesh::ResourcePtr, - smtk::model::Edge orignalEdge, - smtk::model::Edge newEdge, - smtk::model::Vertex promotedVertex); - -//Merge together two edges and a model vertex into a single new edge mesh -//representation. The model vertex mesh will be removed from the system -SMTKCORE_EXPORT -bool merge( - smtk::mesh::ResourcePtr, - smtk::model::Vertex toRemoveVert, - smtk::model::Edge toRemoveEdge, - smtk::model::Edge toAddTo); - -//Lower level routines that merge/split/etc are based on but could be -//useful for other people to use - -//Given two meshsets we will make sure that all cells that exists both in A -//and B will be removed from B. -SMTKCORE_EXPORT -bool make_disjoint( - smtk::mesh::ResourcePtr, - const smtk::mesh::MeshSet& a, - smtk::mesh::MeshSet& b, - const smtk::model::EntityRef& modelAssoc); - -//Fuse two meshset together to create a new single meshset with a -//model association to the given modelRef. -//When successful it will update 'toAddTo' to point to the new merged -//meshset -SMTKCORE_EXPORT -bool fuse( - smtk::mesh::ResourcePtr, - smtk::mesh::MeshSet& toRemove, - smtk::mesh::MeshSet& toAddTo, - const smtk::model::EntityRef& assoc); -} // namespace utility -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/model/CMakeLists.txt b/smtk/model/CMakeLists.txt index 405a1b7896c647da393fdf872b96f8d64d5c50c9..aa05a1e8693a0451dcd836e6740006a5411c619b 100644 --- a/smtk/model/CMakeLists.txt +++ b/smtk/model/CMakeLists.txt @@ -34,7 +34,6 @@ set(modelSrcs Face.cxx FaceUse.cxx Group.cxx - GridInfo.cxx Instance.cxx Loop.cxx Model.cxx @@ -88,7 +87,6 @@ set(modelHeaders FaceUse.h FilterGrammar.h FloatData.h - GridInfo.h Group.h Instance.h IntegerData.h diff --git a/smtk/model/EntityRef.cxx b/smtk/model/EntityRef.cxx index 5a6cd3b70fb1090398351fd50d74ab821c7f6d1e..c330890acb240ec8d0d035a5d99cb9dac9298e77 100644 --- a/smtk/model/EntityRef.cxx +++ b/smtk/model/EntityRef.cxx @@ -26,9 +26,6 @@ #include "smtk/model/Tessellation.h" #include "smtk/model/Volume.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - #include "smtk/geometry/Geometry.h" #include @@ -824,26 +821,6 @@ Tessellation* EntityRef::resetTessellation() return &tessit->second; } -/**\brief Return the entity's mesh tessellation. - * - * Each entity has a single meshset describing its tessellation. The meshset - * could, but does not have to, contain sub-meshsets within it. - */ -smtk::mesh::MeshSet EntityRef::meshTessellation() const -{ - ResourcePtr rsrc = m_resource.lock(); - if (rsrc && !m_entity.isNull()) - { - smtk::mesh::ResourcePtr resource = rsrc->meshTessellations(); - - if (resource && resource->isValid()) - { - return resource->findAssociatedMeshes(*this); - } - } - return smtk::mesh::MeshSet(); -} - /**\brief Return the entity's tessellation if one exists or nullptr otherwise. * */ diff --git a/smtk/model/EntityRef.h b/smtk/model/EntityRef.h index 0a27cfebf653f847b7032bbfb3512aec6d7b23a7..c6b95bd0b9b8800c63cab332f0edd0160b0f11e8 100644 --- a/smtk/model/EntityRef.h +++ b/smtk/model/EntityRef.h @@ -31,14 +31,6 @@ #include #include -namespace smtk -{ -namespace mesh -{ -class MeshSet; -} -} // namespace smtk - /// A macro to implement mandatory EntityRef-subclass constructors. #define SMTK_ENTITYREF_CLASS(thisclass, superclass, typecheck) \ SMTK_DERIVED_TYPE(thisclass, superclass); \ @@ -231,8 +223,6 @@ public: EntityRef& findOrAddRawRelation(const EntityRef& ent); EntityRef& elideRawRelation(const EntityRef& ent); - smtk::mesh::MeshSet meshTessellation() const; - Tessellation* resetTessellation(); const Tessellation* hasTessellation() const; const Tessellation* hasAnalysisMesh() const; diff --git a/smtk/model/GridInfo.cxx b/smtk/model/GridInfo.cxx deleted file mode 100644 index 9d4f79665076b5041637f11f7f6668538ee1268e..0000000000000000000000000000000000000000 --- a/smtk/model/GridInfo.cxx +++ /dev/null @@ -1,20 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/model/GridInfo.h" - -namespace smtk -{ -namespace model -{ -GridInfo::GridInfo() = default; - -GridInfo::~GridInfo() = default; -} // namespace model -} // namespace smtk diff --git a/smtk/model/GridInfo.h b/smtk/model/GridInfo.h deleted file mode 100644 index ddd76a902662a893d67dab4b3bda2074b1c2dd61..0000000000000000000000000000000000000000 --- a/smtk/model/GridInfo.h +++ /dev/null @@ -1,140 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -// .NAME GridInfo.h - abstract class to get grid information. -// .SECTION Description -// Abstract class to get grid information. Note that we don't assume that -// the whole analysis grid is stored. CMB will implement a version -// of this to get the grid information into SMTK from CMB without -// introducing a dependency on CMB. -// .SECTION See Also - -#ifndef smtk_model_GridInfo_h -#define smtk_model_GridInfo_h - -#include "smtk/CoreExports.h" -#include "smtk/SystemConfig.h" - -#include -#include -#include - -namespace smtk -{ -namespace io -{ -class Logger; -} - -namespace model -{ -class SMTKCORE_EXPORT GridInfo -{ -public: - /// Return type for all public methods - enum ApiReturnType - { - OK = 0, - ENTITY_NOT_FOUND, // model or grid entity not found for specified id - IDENTIFIER_NOT_FOUND, // for methods specific to MOAB grids - NOT_AVAILABLE // requested data not available/found - }; - - /// Structure passed in as the last argument to each API method, for reporting - // back status information. - struct ApiStatus - { - ApiReturnType returnType; - std::string errorMessage; - smtk::io::Logger* logger{ nullptr }; - - ApiStatus() = default; - }; - - /// Enum for specifying point set closure. - enum PointClosure - { - ALL_POINTS = 0, - INTERIOR_POINTS, - BOUNDARY_POINTS - }; - - /// Returns the dimension of the grid, more specifically, the - // highest-dimension elements in the grid. - // If status returnType is not OK, method returns -1. - virtual int dimension(ApiStatus& status) const = 0; - - /// Returns analysis grid cells for specified model entity. - // Only returns native/canonical ids specified in the analysis grid - // i.e., does *not* return internal CMB grid entities. - virtual std::vector analysisGridCells(int modelEntityId, ApiStatus& status) = 0; - - /// Returns "grid items" for the geometry on the boundary of a model entity. - // Each grid item is a pair of integer values; the first integer is the id - // of a cell in the analysis grid, and the second integer is the index - // of a particular side of the cell, using the VTK numbering convention. - virtual std::vector> boundaryItemsOf( - int modelEntityId, - ApiStatus& status) = 0; - - /// Returns "grid items" for the geometry of a model entity that is on - // the boundary of a next-higher-dimension model entity. - // Each grid item is a pair of integer values; the first integer is the id - // of a cell in the analysis grid, and the second integer is the index - // of a particular side of the cell, using the VTK numbering convention. - // If the specified model entity is on the boundary of multiple model - // entities (for example, a model face can be on the boundary of two model - // regions), the grid items are returned for only one bounded model - // entity. The boundedModel argument is used to disambiguate - // these cases. A value of -1 can be passed in for that entity, in which - // case the bounded model entity will be selected internally. - virtual std::vector> - asBoundaryItems(int modelEntityId, int boundedModelId, ApiStatus& status) = 0; - - /// Returns the type of cell for the specified analysis grid cell id. - // The integer value is defined by the VTKCellType enum in vtkCellType.h - virtual int cellType(int gridCellId, ApiStatus& status) = 0; - - /// Returns the grid point ids for a specified model entity id. - // The list can be filtered by the point closure enumeration. - virtual std::vector pointIds(int modelEntityId, PointClosure closure, ApiStatus& status) = 0; - - /// Returns the grid point ids for a specified grid cell id. - // The points are ordered using the VTK convention. - virtual std::vector cellPointIds(int gridCellId, ApiStatus& status) = 0; - - /// Returns the dimensional coordinates of a specified grid point id. - virtual std::vector pointLocation(int gridPointId, ApiStatus& status) = 0; - - /// Returns the classification id for the node or element set for a - // specified model entity. The function applies to MOAB-style grids. - // Note that, although MOAB uses integer ids, this method returns a - // std::string for generality. - virtual std::string nodeElemSetClassification(int modelEntityId, ApiStatus& status) = 0; - - /// Returns the classification id for the mesh side set for a specified - // model entity. The function applies to MOAB-style grids. - // Note that, although MOAB uses integer ids, this method returns a - // std::string for generality. - virtual std::string sideSetClassification(int modelEntityId, ApiStatus& status) = 0; - - /// Returns set of grid point id pairs representing the grid edges - // for an input bounddary group id. - // For interim use exporting 2D grids for AdH output. - virtual std::vector> edgeGridItems( - int boundaryGroupId, - ApiStatus& status) = 0; - - GridInfo(); - virtual ~GridInfo(); -}; -} // namespace model -} // namespace smtk - -#endif /* smtk_model_GridInfo_h */ diff --git a/smtk/model/Resource.cxx b/smtk/model/Resource.cxx index 85cb8fdbce1958b4983ea6a52bae969a0d086a0a..69d1094045433e54aeea2e98557f7562f993d65c 100644 --- a/smtk/model/Resource.cxx +++ b/smtk/model/Resource.cxx @@ -35,8 +35,6 @@ #include "smtk/model/VolumeUse.h" #include "smtk/model/queries/SelectionFootprint.h" -#include "smtk/mesh/core/Resource.h" - #include "smtk/common/UUIDGenerator.h" #include "smtk/resource/Manager.h" @@ -175,49 +173,11 @@ const UUIDsToTessellations& Resource::analysisMesh() const return *m_analysisMesh; } -bool Resource::setMeshTessellations(const smtk::mesh::ResourcePtr& meshResource) -{ - // We reset the mesh tessellation by first unsetting the existing mesh - // tessellation (if it exists) and then adding a new link to the input - // mesh resource. If this becomes a bottleneck, we could add API to - // smtk::resource::Links to modify the RHS id of the current link, - // facilitating link modification in place. - smtk::mesh::ResourcePtr currentMeshTessellations = this->meshTessellations(); - if (currentMeshTessellations != nullptr) - { - this->links().removeLinksTo( - std::static_pointer_cast(currentMeshTessellations), - TessellationRole); - } - return this->links() - .addLinkTo( - std::static_pointer_cast(meshResource), TessellationRole) - .first != smtk::common::UUID::null(); -} - -smtk::mesh::ResourcePtr Resource::meshTessellations() const -{ - auto tessellationObjects = this->links().linkedTo(TessellationRole); - return ( - !tessellationObjects.empty() - ? std::dynamic_pointer_cast(*tessellationObjects.begin()) - : smtk::mesh::ResourcePtr()); -} - void Resource::clear() { m_topology->clear(); m_tessellations->clear(); m_analysisMesh->clear(); - { - smtk::mesh::ResourcePtr currentMeshTessellations = this->meshTessellations(); - if (currentMeshTessellations != nullptr) - { - this->links().removeLinksTo( - std::static_pointer_cast(currentMeshTessellations), - TessellationRole); - } - } m_attributeAssignments->clear(); m_sessions->clear(); m_attributeResources.clear(); diff --git a/smtk/model/Resource.h b/smtk/model/Resource.h index b0dfc3c129bbae0e970837915790f5e793047d27..0fa3d9c1846f925d39c0dfefff43984993ae9250 100644 --- a/smtk/model/Resource.h +++ b/smtk/model/Resource.h @@ -134,9 +134,6 @@ public: UUIDsToTessellations& analysisMesh(); const UUIDsToTessellations& analysisMesh() const; - bool setMeshTessellations(const smtk::mesh::ResourcePtr&); - smtk::mesh::ResourcePtr meshTessellations() const; - /// Remove all entities and properties from this object. Does not change id or emit signals. void clear(); diff --git a/smtk/model/operators/CloseModel.cxx b/smtk/model/operators/CloseModel.cxx index 22d635d02031cb6d31fc40542c3a4498c7fac9e8..4df9132ebc67329b1cc9b2b6b29744a1158ba53e 100644 --- a/smtk/model/operators/CloseModel.cxx +++ b/smtk/model/operators/CloseModel.cxx @@ -14,8 +14,6 @@ #include "smtk/model/Resource.h" #include "smtk/model/Session.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" #include "smtk/resource/Component.h" #include "smtk/attribute/Attribute.h" @@ -66,17 +64,6 @@ CloseModel::Result CloseModel::operateInternal() expunged.insert(ait->component()); } - // Similarly, meshes must be added to the "mesh_expunged" attribute. - auto associatedMeshes = resource->links().linkedFrom(smtk::mesh::Resource::ClassificationRole); - for (const auto& cit : associatedMeshes) - { - auto meshResource = std::dynamic_pointer_cast(cit); - smtk::resource::Component::Visitor temp = [&](const smtk::resource::ComponentPtr& c) { - expunged.insert(c); - }; - meshResource->visit(temp); - } - if (!resource->eraseModel(model)) { success = false; diff --git a/smtk/model/pybind11/PybindResource.h b/smtk/model/pybind11/PybindResource.h index fa44b5f78807da79904ebed00596eba0c804cccb..e834e13ad8e72d76fabdc30f25bfa21b92722818 100644 --- a/smtk/model/pybind11/PybindResource.h +++ b/smtk/model/pybind11/PybindResource.h @@ -18,7 +18,6 @@ #include "smtk/common/UUID.h" #include "smtk/common/pybind11/PybindUUIDTypeCaster.h" #include "smtk/io/Logger.h" -#include "smtk/mesh/core/Resource.h" #include "smtk/model/Arrangement.h" #include "smtk/model/ArrangementKind.h" #include "smtk/model/AuxiliaryGeometry.h" @@ -172,7 +171,6 @@ inline PySharedPtrClass< smtk::model::Resource> pybind11_init_smtk_model_Resourc .def("integerProperty", (smtk::model::IntegerList & (smtk::model::Resource::*)(::smtk::common::UUID const &, ::std::string const &)) &smtk::model::Resource::integerProperty, py::arg("entity"), py::arg("propName")) .def("log", &smtk::model::Resource::log) .def("lowerDimensionalBoundaries", &smtk::model::Resource::lowerDimensionalBoundaries, py::arg("ofEntity"), py::arg("lowerDimension")) - .def("meshTessellations", &smtk::model::Resource::meshTessellations) .def("modelOwningEntity", &smtk::model::Resource::modelOwningEntity, py::arg("uid")) .def("name", (std::string (smtk::model::Resource::*)() const) &smtk::resource::Resource::name) .def("name", (std::string (smtk::model::Resource::*)(const smtk::common::UUID& ) const) &smtk::model::Resource::name, py::arg("ofEntity")) @@ -202,7 +200,6 @@ inline PySharedPtrClass< smtk::model::Resource> pybind11_init_smtk_model_Resourc .def("setIntegerProperty", (void (smtk::model::Resource::*)(::smtk::common::UUID const &, ::std::string const &, ::smtk::model::IntegerList const &)) &smtk::model::Resource::setIntegerProperty, py::arg("entity"), py::arg("propName"), py::arg("propValue")) .def("setLoop", (smtk::model::Loop (smtk::model::Resource::*)(::smtk::common::UUID const &, ::smtk::model::FaceUse const &)) &smtk::model::Resource::setLoop, py::arg("uid"), py::arg("use")) .def("setLoop", (smtk::model::Loop (smtk::model::Resource::*)(::smtk::common::UUID const &, ::smtk::model::Loop const &)) &smtk::model::Resource::setLoop, py::arg("uid"), py::arg("parent")) - .def("setMeshTessellations", &smtk::model::Resource::setMeshTessellations) .def("setShell", (smtk::model::Shell (smtk::model::Resource::*)(::smtk::common::UUID const &, ::smtk::model::VolumeUse const &)) &smtk::model::Resource::setShell, py::arg("uid"), py::arg("use")) .def("setShell", (smtk::model::Shell (smtk::model::Resource::*)(::smtk::common::UUID const &, ::smtk::model::Shell const &)) &smtk::model::Resource::setShell, py::arg("uid"), py::arg("parent")) .def("setStringProperty", (void (smtk::model::Resource::*)(::smtk::common::UUID const &, ::std::string const &, ::smtk::model::String const &)) &smtk::model::Resource::setStringProperty, py::arg("entity"), py::arg("propName"), py::arg("propValue")) diff --git a/smtk/model/testing/cxx/CMakeLists.txt b/smtk/model/testing/cxx/CMakeLists.txt index 9341652b0f0c47a021cd500894b2680fb6e4daea..88ab1d92650bbbcd1abdbc1ae4a5441e30bcc447 100644 --- a/smtk/model/testing/cxx/CMakeLists.txt +++ b/smtk/model/testing/cxx/CMakeLists.txt @@ -36,11 +36,6 @@ add_executable(unitArrangement unitArrangement.cxx) target_link_libraries(unitArrangement smtkCore) add_test(NAME unitArrangement COMMAND unitArrangement) -add_executable(unitExportMeshOperation unitExportMeshOperation.cxx) -target_compile_definitions(unitExportMeshOperation PRIVATE "SMTK_SCRATCH_DIR=\"${CMAKE_BINARY_DIR}/Testing/Temporary\"") -target_link_libraries(unitExportMeshOperation smtkCore smtkCoreModelTesting - ${Boost_LIBRARIES}) - add_executable(benchmarkModel benchmarkModel.cxx) target_link_libraries(benchmarkModel smtkCore smtkCoreModelTesting) #add_test(NAME benchmarkModel COMMAND benchmarkModel) @@ -52,21 +47,9 @@ set(unit_tests ################################################################################ # Tests that require SMTK_DATA_DIR ################################################################################ -if (SMTK_DATA_DIR) - add_test(NAME unitExportMeshOperation - COMMAND $ - "${SMTK_DATA_DIR}/model/2d/smtk/test2D.json") -endif() set(additional_libs) -if (SMTK_ENABLE_MESH_SESSION AND SMTK_ENABLE_VTK_SESSION) - list(APPEND unit_tests_which_require_data - TestInterpolateAnnotatedValues.cxx - TestGroupPropertyQuery.cxx) - list(APPEND additional_libs smtkMeshSession smtkVTKSession) -endif () - if (SMTK_ENABLE_POLYGON_SESSION) list(APPEND unit_tests_which_require_data unitEntity.cxx diff --git a/smtk/model/testing/cxx/TestGroupPropertyQuery.cxx b/smtk/model/testing/cxx/TestGroupPropertyQuery.cxx index a379fe69c0887e968485b3d8da95267b3ae38d02..7756176ee55a273489134aba2a8f14700c379ecf 100644 --- a/smtk/model/testing/cxx/TestGroupPropertyQuery.cxx +++ b/smtk/model/testing/cxx/TestGroupPropertyQuery.cxx @@ -18,9 +18,6 @@ #include "smtk/attribute/StringItem.h" #include "smtk/attribute/VoidItem.h" -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - #include "smtk/model/EntityRef.h" #include "smtk/model/Face.h" #include "smtk/model/Group.h" diff --git a/smtk/model/testing/cxx/TestInterpolateAnnotatedValues.cxx b/smtk/model/testing/cxx/TestInterpolateAnnotatedValues.cxx deleted file mode 100644 index 7574d9842ea011bad0685a1be2f07c988c782add..0000000000000000000000000000000000000000 --- a/smtk/model/testing/cxx/TestInterpolateAnnotatedValues.cxx +++ /dev/null @@ -1,439 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/Definition.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/Resource.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/io/AttributeReader.h" -#include "smtk/io/ExportMesh.h" -#include "smtk/io/ImportMesh.h" -#include "smtk/io/Logger.h" -#include "smtk/io/WriteMesh.h" - -#include "smtk/mesh/core/PointField.h" -#include "smtk/mesh/utility/Create.h" -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Model.h" -#include "smtk/model/utility/InterpolateField.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/session/vtk/RegisterVTKBackend.h" -#include "smtk/session/vtk/Resource.h" -#include "smtk/session/vtk/operators/Import.h" - -#include "smtk/resource/Component.h" - -#include "smtk/common/testing/cxx/helpers.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -#include - -namespace -{ -// SMTK_DATA_DIR is a define setup by cmake -std::string data_root = SMTK_DATA_DIR; -std::string write_root = SMTK_SCRATCH_DIR; - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -// A test attribute description that allows association and has a double item. -// clang-format off -const char* testInput = R"( - - - - - - - - - - - - - - - - - - -)"; -// clang-format on - -// A testing structure to perform regression testing against the results of -// interpolation. -class HistogramFieldData -{ -public: - HistogramFieldData(std::size_t nBins, double min, double max) - : m_min(min) - , m_max(max) - { - m_hist.resize(nBins, 0); - } - - [[nodiscard]] const std::vector& histogram() const { return m_hist; } - -protected: - std::vector m_hist; - double m_min; - double m_max; -}; - -class HistogramPointFieldData - : public smtk::mesh::PointForEach - , public HistogramFieldData -{ -public: - HistogramPointFieldData(std::size_t nBins, double min, double max, smtk::mesh::PointField& pf) - : HistogramFieldData(nBins, min, max) - , m_pointField(pf) - { - } - - void forPoints( - const smtk::mesh::HandleRange& pointIds, - std::vector& /*xyz*/, - bool& /*coordinatesModified*/) override - { - std::vector values(pointIds.size()); - m_pointField.get(pointIds, values.data()); - for (auto& value : values) - { - std::size_t bin = static_cast((value - m_min) / (m_max - m_min) * m_hist.size()); - - ++m_hist[bin]; - } - } - -protected: - smtk::mesh::PointField& m_pointField; -}; - -smtk::session::mesh::Resource::Ptr readMeshResource(const std::string& importFilePath) -{ - smtk::session::mesh::Resource::Ptr resource; - { - auto importOp = smtk::session::mesh::Import::create(); - - if (!importOp) - { - std::cerr << "No import operator\n"; - return nullptr; - } - - importOp->parameters()->findFile("filename")->setValue(importFilePath); - importOp->parameters()->findVoid("construct hierarchy")->setIsEnabled(false); - - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return nullptr; - } - - // Retrieve the resulting resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - // Access the generated resource - resource = std::dynamic_pointer_cast(resourceItem->value()); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - smtk::model::Entity::Ptr modelEntity = - std::dynamic_pointer_cast(componentItem->value()); - - smtk::model::Model model = modelEntity->referenceAs(); - - if (!model.isValid()) - { - std::cerr << "Import operator returned an invalid model\n"; - return nullptr; - } - } - return resource; -} - -smtk::session::vtk::Resource::Ptr readVTKResource(const std::string& importFilePath) -{ - smtk::session::vtk::RegisterVTKBackend::registerClass(); - - smtk::session::vtk::Resource::Ptr resource; - { - auto importOp = smtk::session::vtk::Import::create(); - - if (!importOp) - { - std::cerr << "No import operator\n"; - return nullptr; - } - - importOp->parameters()->findFile("filename")->setValue(importFilePath); - - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return nullptr; - } - - // Retrieve the resulting resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - // Access the generated resource - resource = std::dynamic_pointer_cast(resourceItem->value()); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - smtk::model::Entity::Ptr modelEntity = - std::dynamic_pointer_cast(componentItem->value()); - - smtk::model::Model model = modelEntity->referenceAs(); - - if (!model.isValid()) - { - std::cerr << "Import operator returned an invalid model\n"; - return nullptr; - } - } - return resource; -} -} // namespace - -int TestInterpolateAnnotatedValues(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - for (int testNumber = 0; testNumber < 2; ++testNumber) - { - std::string importFilePath(data_root); - importFilePath += "/mesh/2d/test2D.2dm"; - - // Import a model resource. - smtk::model::Resource::Ptr resource; - std::array extent; - if (testNumber == 0) - { - resource = readMeshResource(importFilePath); - extent = smtk::mesh::utility::extent( - std::dynamic_pointer_cast(resource)->resource()->meshes()); - } - else - { - smtk::mesh::Resource::Ptr meshResource = smtk::mesh::Resource::create(); - smtk::io::importMesh(importFilePath, meshResource); - extent = smtk::mesh::utility::extent(meshResource->meshes()); - - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".exo"; - smtk::io::exportMesh(write_path, meshResource); - - resource = readVTKResource(write_path); - cleanup(write_path); - } - - if (resource == nullptr) - { - return 1; - } - - // Access all of the model's faces - smtk::model::EntityRefs currentEnts = - resource->entitiesMatchingFlagsAs(smtk::model::FACE); - if (currentEnts.empty()) - { - std::cerr << "No faces!" << std::endl; - return 1; - } - - // Arrange the model faces with a consistent ordering - std::vector eRefs(currentEnts.begin(), currentEnts.end()); - std::sort( - eRefs.begin(), - eRefs.end(), - [](const smtk::model::EntityRef& lhs, const smtk::model::EntityRef& rhs) { - return lhs.name() < rhs.name(); - }); - - // Construct the test attribute resource - smtk::attribute::ResourcePtr resptr = smtk::attribute::Resource::create(); - smtk::attribute::Resource& attResource(*resptr.get()); - smtk::io::Logger logger; - smtk::io::AttributeReader reader; - - if (reader.readContents(resptr, testInput, logger)) - { - std::cerr << "Encountered Errors while reading input data\n"; - std::cerr << logger.convertToString(); - return 2; - } - - // Access the attribute resource's definitions - std::vector defs; - attResource.definitions(defs); - if (defs.size() != 1) - { - std::cerr << "Unexpected number of definitions: " << defs.size() << "\n"; - std::cerr << logger.convertToString(); - return 2; - } - - // Access the attribute resource's attributes - std::vector atts; - attResource.attributes(atts); - if (atts.size() != 4) - { - std::cerr << "Unexpected number of attributes: " << atts.size() << "\n"; - std::cerr << logger.convertToString(); - return 2; - } - - // For each attribute, associate the attribute to a model face and assign it - // a value - for (std::size_t i = 0; i < 4; i++) - { - atts[i]->associate(eRefs[i].component()); - atts[i]->findDouble("interpolation value")->setValue(i + 1.); - } - - // Construct a grid of sample points - std::array origin = { extent[0], extent[2], extent[4] }; - std::array size = { (extent[1] - extent[0]), - (extent[3] - extent[2]), - (extent[5] - extent[4]) }; - - // Offset the grid from the model surface - origin[2] += .25; - - smtk::mesh::ResourcePtr gridResource = smtk::mesh::Resource::create(); - - // Construct a mapping from a unit box to the input box - std::function(std::array)> fn = [&](std::array x) { - return std::array( - { { origin[0] + size[0] * x[0], origin[1] + size[1] * x[1], origin[2] + size[2] * x[2] } }); - }; - - std::array disc = { { 50, 20 } }; - - std::array sampleGrid = - smtk::mesh::utility::createUniformGrid(gridResource, disc, fn); - - // Remove superfluous meshes (we are only interested in the surface mesh, not - // its edges) - for (std::size_t i = 1; i < 5; i++) - { - gridResource->removeMeshes(sampleGrid[i]); - } - - // Access the points of the sample grid - std::vector pts; - sampleGrid[0].points().get(pts); - - // Compute the interpolation weights for the sample grid points - std::vector weights = smtk::model::computeWeights(pts, defs[0]); - - // Compute the interpolated values for the sample grid points - std::vector values = - smtk::model::inverseDistanceWeighting(weights, "interpolation value", 2); - - // For testing, assign the interpolated values to the sample grid as a point - // field - sampleGrid[0].createPointField( - "interpolation", 1, smtk::mesh::FieldType::Double, values.data()); - - bool debug = false; - if (debug) - { - //write out the mesh. - std::string write_path(write_root); - write_path += "/" + smtk::common::UUID::random().toString() + ".h5m"; - - smtk::io::WriteMesh write; - bool result = write(write_path, gridResource); - if (!result) - { - test(result, "failed to properly write out a valid hdf5 resource"); - } - } - - // Histogram the resulting points and compare against expected values. - std::vector histogram; - smtk::mesh::PointField pointField = gridResource->meshes().pointField("interpolation"); - HistogramPointFieldData histogramPointFieldData(10, .5, 4.5, pointField); - smtk::mesh::for_each(gridResource->meshes().points(), histogramPointFieldData); - histogram = histogramPointFieldData.histogram(); - - std::array expectedForMeshSession = { - { 0, 301, 84, 112, 69, 55, 109, 100, 241, 0 } - }; - std::array expectedForVTKSession = { - { 0, 303, 81, 112, 70, 55, 109, 101, 240, 0 } - }; - - std::size_t counter = 0; - for (auto& bin : histogram) - { - if ( - bin != - (testNumber == 0 ? expectedForMeshSession[counter++] : expectedForVTKSession[counter++])) - { - std::cerr << "\"interpolate annotations\" produced unexpected results\n"; - return 1; - } - } - } - - return 0; -} diff --git a/smtk/model/testing/cxx/unitExportMeshOperation.cxx b/smtk/model/testing/cxx/unitExportMeshOperation.cxx deleted file mode 100644 index f40488720597e3dfe175537fc159c7fd3cfc3648..0000000000000000000000000000000000000000 --- a/smtk/model/testing/cxx/unitExportMeshOperation.cxx +++ /dev/null @@ -1,145 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" - -#include "smtk/io/ExportMesh.h" -#include "smtk/io/ImportMesh.h" -#include "smtk/io/ModelToMesh.h" - -#include "smtk/model/DefaultSession.h" -#include "smtk/model/json/jsonResource.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/mesh/operators/Export.h" -#include "smtk/model/Resource.h" - -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ -//SMTK_DATA_DIR is a define setup by cmake -std::string write_root = SMTK_SCRATCH_DIR; - -void create_simple_mesh_model(smtk::model::ResourcePtr resource, std::string file_path) -{ - std::ifstream file(file_path.c_str()); - - std::string json_str((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); - nlohmann::json json = nlohmann::json::parse(json_str); - - smtk::model::from_json(json, resource); - for (auto& tessPair : json["tessellations"]) - { - smtk::common::UUID id = tessPair[0]; - smtk::model::Tessellation tess = tessPair[1]; - resource->setTessellation(id, tess); - } - - resource->assignDefaultNames(); - - file.close(); -} - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} -} // namespace - -int main(int argc, char* argv[]) -{ - if (argc == 1) - { - std::cout << "Must provide input file as argument" << std::endl; - return 1; - } - - std::ifstream file; - file.open(argv[1]); - if (!file.good()) - { - std::cout << "Could not open file \"" << argv[1] << "\".\n\n"; - return 1; - } - - // Create a model resource - smtk::model::ResourcePtr resource = smtk::model::Resource::create(); - - // Load in the model - create_simple_mesh_model(resource, std::string(argv[1])); - - // Convert it to a mesh - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr meshResource = convert(resource); - - // Create a new "export mesh" operator - smtk::operation::Operation::Ptr exportMeshOp = smtk::mesh::Export::create(); - if (!exportMeshOp) - { - std::cerr << "No \"export mesh\" operator\n"; - return 1; - } - - // Set "export mesh" operator's file - std::string export_path = std::string(write_root + "/testmesh.2dm"); - exportMeshOp->parameters()->findFile("filename")->setValue(export_path); - - bool valueSet = exportMeshOp->parameters()->associate(meshResource); - - if (!valueSet) - { - std::cerr << "Failed to set mesh value on export mesh operator\n"; - return 1; - } - - if (!exportMeshOp->parameters()->isValid()) - { - std::cerr << "Invalid parameters\n"; - return 1; - } - - // Execute "export mesh" operator... - smtk::operation::Operation::Result exportMeshOpResult = exportMeshOp->operate(); - // ...and test the results for success. - if ( - exportMeshOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Export mesh operator failed\n"; - return 1; - } - - // Test the original mesh resource - if (!meshResource->isModified()) - { - std::cerr << "mesh resource should be marked as modified" << std::endl; - return 1; - } - - cleanup(export_path); - - return 0; -} diff --git a/smtk/model/testing/cxx/unitWriteMeshOperation.cxx b/smtk/model/testing/cxx/unitWriteMeshOperation.cxx deleted file mode 100644 index ac09059695f574f943d89b984a22f92a832c896e..0000000000000000000000000000000000000000 --- a/smtk/model/testing/cxx/unitWriteMeshOperation.cxx +++ /dev/null @@ -1,201 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" - -#include "smtk/io/ModelToMesh.h" -#include "smtk/io/ReadMesh.h" -#include "smtk/io/WriteMesh.h" - -#include "smtk/model/DefaultSession.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/Resource.h" - -#include - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ -//SMTK_DATA_DIR is a define setup by cmake -std::string write_root = SMTK_SCRATCH_DIR; - -void create_simple_mesh_model(smtk::model::ResourcePtr mgr, std::string file_path) -{ - std::ifstream file(file_path.c_str()); - - std::string json((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); - - //we should load in the test2D.json file as an smtk to model - smtk::io::LoadJSON::intoModelResource(json.c_str(), mgr); - mgr->assignDefaultNames(); - - file.close(); -} - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} -} // namespace - -int main(int argc, char* argv[]) -{ - if (argc > 1) - { - std::ifstream file; - file.open(argv[1]); - if (!file.good()) - { - std::cout << "Could not open file \"" << argv[1] << "\".\n\n"; - return 1; - } - - std::vector files_to_delete; - - // Create a model resource - smtk::model::ResourcePtr resource = smtk::model::Resource::create(); - - // Identify available sessions - std::cout << "Available sessions\n"; - typedef smtk::model::StringList StringList; - StringList sessions = resource->sessionTypeNames(); - smtk::mesh::ManagerPtr meshManager = resource->meshes(); - for (StringList::iterator it = sessions.begin(); it != sessions.end(); ++it) - std::cout << " " << *it << "\n"; - std::cout << "\n"; - - // Create a new default session - smtk::model::SessionRef sessRef = resource->createSession("native"); - - // Identify available operators - std::cout << "Available cmb operators\n"; - StringList opnames = sessRef.session()->operatorNames(); - for (StringList::iterator it = opnames.begin(); it != opnames.end(); ++it) - { - std::cout << " " << *it << "\n"; - } - std::cout << "\n"; - - create_simple_mesh_model(resource, std::string(argv[1])); - smtk::io::ModelToMesh convert; - smtk::mesh::ResourcePtr c = convert(meshManager, resource); - - // Test all three mesh file types - std::string extension[2] = { ".exo", ".h5m" }; - - for (int fileType = 0; fileType < 2; ++fileType) - { - std::cout << "Testing file type " << extension[fileType] << std::endl; - - // Create a new "write mesh" operator - smtk::operation::OperationPtr writeMeshOp = sessRef.session()->op("write mesh"); - if (!writeMeshOp) - { - std::cerr << "No \"write mesh\" operator\n"; - return 1; - } - - // Set "write mesh" operator's file - std::string write_path = std::string(write_root + "/testmesh" + extension[fileType]); - writeMeshOp->specification()->findFile("filename")->setValue(write_path); - - bool valueSet = writeMeshOp->specification()->findMesh("mesh")->setValue( - meshManager->collectionBegin()->second->meshes()); - - if (!valueSet) - { - std::cerr << "Failed to set mesh value on write mesh operator\n"; - return 1; - } - - // Execute "write mesh" operator... - smtk::operation::OperationResult writeMeshOpResult = writeMeshOp->operate(); - // ...and test the results for success. - if ( - writeMeshOpResult->findInt("outcome")->value() != - smtk::operation::Operation::OPERATION_SUCCEEDED) - { - std::cerr << "Write mesh operator failed\n"; - return 1; - } - - // Grab the original mesh collection - smtk::mesh::ResourcePtr c = sessRef.session()->meshManager()->collectionBegin()->second; - if (c->isModified()) - { - std::cerr << "collection shouldn't be marked as modified" << std::endl; - return 1; - } - - // Reload the written file and verify the number of meshes are the same as - // the input mesh - // - // NB: a new mesh manager must be used here. If the original mesh manager - // is used instead, a corrupt collection is added to our resource and - // our little trick of grabbing the first collection above will result - // in test failures. - smtk::mesh::ManagerPtr m2 = smtk::mesh::Manager::create(); - smtk::io::ReadMesh read; - smtk::mesh::ResourcePtr c2 = read(write_path, m2); - if (c2->isModified()) - { - std::cerr << "collection shouldn't be marked as modified" << std::endl; - return 1; - } - - // Remove the file from disk - cleanup(write_path); - - // Verify the meshes - if (!c2->isValid()) - { - std::cerr << "collection should be valid" << std::endl; - return 1; - } - if (c2->name() != c->name()) - { - std::cerr << "collection names do not match" << std::endl; - return 1; - } - - // We only guarantee that Moab's native .h5m format is bidirectional. The - // other mesh formats will write, but information is lost when they are - // subsequently imported. - if (extension[fileType] == ".h5m") - { - if (c2->numberOfMeshes() != c->numberOfMeshes()) - { - std::cerr << "number of meshes do not match" << std::endl; - return 1; - } - if (c2->types() != c->types()) - { - std::cerr << "collection types do not match" << std::endl; - return 1; - } - } - } - } - - return 0; -} diff --git a/smtk/project/testing/cxx/CMakeLists.txt b/smtk/project/testing/cxx/CMakeLists.txt index bf29fd713ba8bc2f26330134a97a4e95395df204..aa05b99df64ee928d746d64bc4c83abd24901d85 100644 --- a/smtk/project/testing/cxx/CMakeLists.txt +++ b/smtk/project/testing/cxx/CMakeLists.txt @@ -9,7 +9,6 @@ set(unit_tests ) set(unit_tests_which_require_data TestProjectPortability.cxx - TestProjectReadWrite.cxx TestProjectReadWrite2.cxx TestProjectReadWriteEmpty.cxx ) @@ -23,6 +22,9 @@ set(extra_libs) if (SMTK_ENABLE_VTK_SUPPORT) add_compile_definitions(VTK_SUPPORT) list(APPEND extra_libs smtkVTKSession) + list(APPEND unit_tests_which_require_data + TestProjectReadWrite.cxx + ) endif() smtk_unit_tests( diff --git a/smtk/project/testing/cxx/TestProjectReadWrite.cxx b/smtk/project/testing/cxx/TestProjectReadWrite.cxx index e95e008793600225f0686d22851975c1a32a242c..8ef0c597e1ec982bd100a1f0cb8ca8278398763f 100644 --- a/smtk/project/testing/cxx/TestProjectReadWrite.cxx +++ b/smtk/project/testing/cxx/TestProjectReadWrite.cxx @@ -13,14 +13,15 @@ #include "smtk/attribute/IntItem.h" #include "smtk/attribute/ResourceItem.h" +#include "smtk/model/Entity.h" +#include "smtk/model/Model.h" +#include "smtk/model/Resource.h" + #include "smtk/common/UUIDGenerator.h" #include "smtk/resource/Component.h" #include "smtk/resource/DerivedFrom.h" #include "smtk/resource/Manager.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/resource/Registrar.h" - #include "smtk/operation/Manager.h" #include "smtk/operation/Registrar.h" #include "smtk/operation/operators/ImportResource.h" @@ -29,6 +30,10 @@ #include "smtk/plugin/Registry.h" +#include "smtk/model/Registrar.h" + +#include "smtk/session/vtk/Registrar.h" + #include "smtk/project/Manager.h" #include "smtk/project/Project.h" #include "smtk/project/Registrar.h" @@ -42,7 +47,7 @@ using namespace boost::filesystem; // This test verifies that projects can be serialized to the file system -// and unserialized back. The test project contains an SMTK mesh resource. +// and unserialized back. The test project contains an SMTK model resource. namespace { @@ -80,11 +85,14 @@ int TestProjectReadWrite(int /*unused*/, char** const /*unused*/) auto attributeRegistry = smtk::plugin::addToManagers(resourceManager, operationManager); - auto meshRegistry = - smtk::plugin::addToManagers(resourceManager, operationManager); + auto modelRegistry = + smtk::plugin::addToManagers(resourceManager, operationManager); auto operationRegistry = smtk::plugin::addToManagers(operationManager); + auto vtkSessionRegistry = + smtk::plugin::addToManagers(resourceManager, operationManager); + // Register the resource manager to the operation manager (newly created // resources will be automatically registered to the resource manager). operationManager->registerResourceManager(resourceManager); @@ -103,7 +111,7 @@ int TestProjectReadWrite(int /*unused*/, char** const /*unused*/) // Create a project and write it to disk. std::string projectDirectory = write_root + "/TestProjectReadWrite/"; std::string projectLocation; - std::size_t numberOfMeshes; + std::size_t numberOfModels; { smtk::project::Project::Ptr project = projectManager->create("foo"); if (!project) @@ -141,13 +149,13 @@ int TestProjectReadWrite(int /*unused*/, char** const /*unused*/) return 1; } - // Add the mesh resource to the project + // Add the model resource to the project smtk::attribute::ResourceItemPtr resourceItem = std::dynamic_pointer_cast( importOpResult->findResource("resourcesCreated")); project->resources().add( - std::dynamic_pointer_cast(resourceItem->value()), "my mesh"); + std::dynamic_pointer_cast(resourceItem->value()), "my model"); // Create resource with non-unique role for (int i = 0; i < 2; i++) @@ -170,9 +178,12 @@ int TestProjectReadWrite(int /*unused*/, char** const /*unused*/) } { - std::set myMesh = - project->resources().findByRole("my mesh"); - numberOfMeshes = (*(myMesh.begin()))->meshes().size(); + std::set myModel = + project->resources().findByRole("my model"); + numberOfModels = (*(myModel.begin())) + ->entitiesMatchingFlagsAs( + smtk::model::EntityTypeBits::MODEL_ENTITY, false) + .size(); } { @@ -288,25 +299,27 @@ int TestProjectReadWrite(int /*unused*/, char** const /*unused*/) } } - std::set myMeshSet = - project->resources().findByRole("my mesh"); - - if (myMeshSet.empty()) + auto myModelRsrc = project->resources().findByRole("my model"); + if (myModelRsrc.empty()) { - std::cerr << "Resulting project does not contain mesh resource\n"; + std::cerr << "Resulting project does not contain model resource\n"; return 1; } - if (myMeshSet.size() > 1) + if (myModelRsrc.size() > 1) { std::cerr - << "Resulting project contains more than one(1) mesh resource with role \"my mesh\"\n"; + << "Resulting project contains more than one(1) model resource with role \"my model\"\n"; return 1; } - smtk::mesh::Resource::Ptr myMesh = *(myMeshSet.begin()); - if (myMesh->meshes().size() != numberOfMeshes) + smtk::model::Resource::Ptr myModel = *(myModelRsrc.begin()); + if ( + myModel + ->entitiesMatchingFlagsAs( + smtk::model::EntityTypeBits::MODEL_ENTITY, false) + .size() != numberOfModels) { - std::cerr << "Resulting project's mesh resource was incorrectly transcribed\n"; + std::cerr << "Resulting project's model resource was incorrectly transcribed\n"; return 1; } diff --git a/smtk/pybind11/__init__.py.in b/smtk/pybind11/__init__.py.in index 30b3e385bacb2dca26cd0546d6ba6bdd001c2488..8edcb3f2ecf30510c367c5917513eadc5c39795b 100644 --- a/smtk/pybind11/__init__.py.in +++ b/smtk/pybind11/__init__.py.in @@ -18,7 +18,7 @@ import site import sys __all__ = ('common', 'attribute', 'extension', 'model', - 'mesh', 'io', 'project', 'session', 'simulation', 'task') + 'io', 'project', 'session', 'simulation', 'task') appContext = None @@ -68,7 +68,6 @@ def shufflePlugins(pluginList): 'smtkAttributePlugin': 3, 'smtkOperationPlugin': 4, - 'smtkMeshPlugin': 5, 'smtkModelPlugin': 6, 'smtkTaskPlugin': 7, 'smtkProjectPlugin': 8, @@ -78,9 +77,7 @@ def shufflePlugins(pluginList): 'smtkReadWriteResourceManagerStatePlugin': 11, 'smtkOpencascadeSessionPlugin': 12, - 'smtkDelaunayPlugin': 13, 'smtkPolygonSessionPlugin': 14, - 'smtkMeshSessionPlugin': 15, 'smtkVTKOperationsPlugin': 16, 'smtkVTKSessionPlugin': 17, @@ -89,7 +86,6 @@ def shufflePlugins(pluginList): 'smtkQtPlugin': 20, 'smtkPVServerExtPlugin': 21, - 'smtkPVMeshExtPlugin': 22, 'smtkPVModelExtPlugin': 23, 'smtkPQComponentsPlugin': 24, 'smtkPQReadersPlugin': 25, diff --git a/smtk/resource/query/DerivedFrom.h b/smtk/resource/query/DerivedFrom.h index 39ae3bdae9eb75e4ebcde7e2e53e56d02acd9fc7..2c07a6e12b636861bb4d14b3e2398d59a70b9c56 100644 --- a/smtk/resource/query/DerivedFrom.h +++ b/smtk/resource/query/DerivedFrom.h @@ -48,7 +48,7 @@ protected: /// Return the number of generations from this instance to the type index of /// a parent, or return a large negative number if the two types are /// unrelated. - static int numberOfGenerationsFromType(const std::size_t index) + static int numberOfGenerationsFromType(std::size_t index) { return ( DerivedFrom::typeIndex() == index diff --git a/smtk/resource/query/Query.cxx b/smtk/resource/query/Query.cxx index e5580584929f8926231d851410b35cab8154d6fe..2e8996b93a696ba350276d454560d9e0afa679c3 100644 --- a/smtk/resource/query/Query.cxx +++ b/smtk/resource/query/Query.cxx @@ -18,10 +18,17 @@ namespace resource { namespace query { + std::size_t Query::typeIndex() { return std::type_index(typeid(Query)).hash_code(); } + +int Query::numberOfGenerationsFromType(std::size_t index) +{ + return (Query::typeIndex() == index ? 0 : std::numeric_limits::lowest()); +} + } // namespace query } // namespace resource } // namespace smtk diff --git a/smtk/resource/query/Query.h b/smtk/resource/query/Query.h index cc82053b5ed2ef0e6ce12ccc408029725ff40247..7acd6ac3d23b6109895a4364f97f649a430777c8 100644 --- a/smtk/resource/query/Query.h +++ b/smtk/resource/query/Query.h @@ -35,11 +35,9 @@ public: virtual ~Query() = default; protected: - static int numberOfGenerationsFromType(const std::size_t index) - { - return (Query::typeIndex() == index ? 0 : std::numeric_limits::lowest()); - } + static int numberOfGenerationsFromType(std::size_t index); }; + } // namespace query } // namespace resource } // namespace smtk diff --git a/smtk/session/CMakeLists.txt b/smtk/session/CMakeLists.txt index cba276b14ddb16c95204e8f2fc0e7313c30db81e..415b91cc3ae7b0677f8d6b29cd3adda0cd159e98 100644 --- a/smtk/session/CMakeLists.txt +++ b/smtk/session/CMakeLists.txt @@ -2,8 +2,6 @@ # Initialize flags for configuring Pybind11 session module ################################################################################ set(SMTK_POLYGON_SESSION_ENABLED "False") -set(SMTK_MESH_SESSION_ENABLED "False") -set(SMTK_MULTISCALE_SESSION_ENABLED "False") set(SMTK_VTK_SESSION_ENABLED "False") set(SMTK_OSCILLATOR_SESSION_ENABLED "False") @@ -15,14 +13,6 @@ if (SMTK_ENABLE_POLYGON_SESSION) add_subdirectory(polygon) endif() -################################################################################ -# Build smtk::mesh session -################################################################################ -if (SMTK_ENABLE_MESH_SESSION) - set(SMTK_MESH_SESSION_ENABLED "True") - add_subdirectory(mesh) -endif() - ################################################################################ # Build VTK session ################################################################################ diff --git a/smtk/session/mesh/CMakeLists.txt b/smtk/session/mesh/CMakeLists.txt deleted file mode 100644 index e16b5d168648605dd51a1d8045a2608c905ad6ab..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/CMakeLists.txt +++ /dev/null @@ -1,95 +0,0 @@ -set(meshSrcs - Facade.cxx - Registrar.cxx - Resource.cxx - Session.cxx - Topology.cxx -) - -set(meshHeaders - Facade.h - Registrar.h - Resource.h - Session.h - Topology.h - queries/BoundingBox.h - queries/ClosestPoint.h - queries/DistanceTo.h - queries/RandomPoint.h -) - -if (SMTK_ENABLE_VTK_SUPPORT) - list(APPEND meshSrcs - vtk/Geometry.cxx) - list(APPEND meshHeaders - vtk/Geometry.h) -endif () - -set(meshOperators - CreateUniformGrid - EulerCharacteristicRatio - Export - Import - Merge - Print - Read - Transform - Write - ) - -# Operations which have XML descriptions in separate files -# need to have it encoded as a string in a header. -foreach (operator ${meshOperators}) - smtk_encode_file("${CMAKE_CURRENT_SOURCE_DIR}/operators/${operator}.sbt" - HEADER_OUTPUT headerName) - list(APPEND meshSrcs operators/${operator}.cxx) - list(APPEND meshHeaders operators/${operator}.h) - list(APPEND meshSessionDependencies ${headerName}) -endforeach() -add_custom_target("meshSessionGenHeaders" DEPENDS ${meshSessionDependencies}) - -add_library(smtkMeshSession ${meshSrcs}) -add_dependencies(smtkMeshSession "meshSessionGenHeaders") - -# Install the headers -smtk_public_headers(smtkMeshSession ${meshHeaders}) - -set(vtk_dependencies) - -if (SMTK_ENABLE_VTK_SUPPORT) - target_compile_definitions(smtkMeshSession PUBLIC VTK_SUPPORT) - - list(APPEND vtk_dependencies - VTK::CommonCore - VTK::CommonDataModel - vtkSMTKSourceExt - vtkSMTKModelExt - ) -endif () - -target_link_libraries(smtkMeshSession - LINK_PUBLIC - smtkCore - LINK_PRIVATE - ${vtk_dependencies} - ${__dependencies} - Boost::filesystem -) - -smtk_export_header(smtkMeshSession Exports.h) - -#install the library and exports the library when used from a build tree -smtk_install_library(smtkMeshSession) - -if (SMTK_ENABLE_PARAVIEW_SUPPORT) - set_property(GLOBAL APPEND - PROPERTY _smtk_plugin_files "${CMAKE_CURRENT_SOURCE_DIR}/plugin/paraview.plugin") -endif() - -if (SMTK_ENABLE_PYTHON_WRAPPING) - add_subdirectory(pybind11) -endif() - -if (SMTK_ENABLE_TESTING) -add_subdirectory(testing) -endif() diff --git a/smtk/session/mesh/Facade.cxx b/smtk/session/mesh/Facade.cxx deleted file mode 100644 index 85ac4ff585b5054c232a7babda9d3a6e11dbd7e9..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/Facade.cxx +++ /dev/null @@ -1,51 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/session/mesh/Facade.h" - -#include - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -struct Facade::Internals -{ - std::map m_data; -}; - -Facade::Facade() - : m_internal(new Internals) -{ - - m_internal->m_data["domain"] = "Domain"; - m_internal->m_data["dirichlet"] = "Dirichlet"; - m_internal->m_data["neumann"] = "Neumann"; -} - -Facade::~Facade() -{ - delete m_internal; -} - -std::string& Facade::operator[](const std::string& key) -{ - static std::string dummy; - dummy = ""; - auto loc = m_internal->m_data.find(key); - return loc == m_internal->m_data.end() ? dummy : loc->second; -} -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/Facade.h b/smtk/session/mesh/Facade.h deleted file mode 100644 index 153b993220a244f21576c07360f7df8b27710668..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/Facade.h +++ /dev/null @@ -1,48 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_Facade_h -#define smtk_session_mesh_Facade_h - -#include "smtk/session/mesh/Exports.h" - -#include - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief A facade for naming model entities from mesh properties. - - Models generated from a mesh set have the same properties as mesh sets. Mesh - set properties are "domain" for material properties, "dirichlet" for point- - centric properties, and "neumann" for cell-centric properties. These labels - are often ill-fitting for many use cases, so we provide an interface to - change them. This class is simply a map connecting the native property names - to user-definable names. - */ -struct SMTKMESHSESSION_EXPORT Facade -{ - Facade(); - virtual ~Facade(); - - std::string& operator[](const std::string& key); - -private: - struct Internals; - Internals* m_internal; -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/Registrar.cxx b/smtk/session/mesh/Registrar.cxx deleted file mode 100644 index 4e347825b00f63c8de4dd7c79d442b51f340e6b8..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/Registrar.cxx +++ /dev/null @@ -1,112 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/session/mesh/Registrar.h" - -#include "smtk/session/mesh/operators/CreateUniformGrid.h" -#include "smtk/session/mesh/operators/EulerCharacteristicRatio.h" -#include "smtk/session/mesh/operators/Export.h" -#include "smtk/session/mesh/operators/Import.h" -#include "smtk/session/mesh/operators/Merge.h" -#include "smtk/session/mesh/operators/Print.h" -#include "smtk/session/mesh/operators/Read.h" -#include "smtk/session/mesh/operators/Transform.h" -#include "smtk/session/mesh/operators/Write.h" - -#include "smtk/session/mesh/Resource.h" - -#include "smtk/operation/groups/CreatorGroup.h" -#include "smtk/operation/groups/ImporterGroup.h" -#include "smtk/operation/groups/ReaderGroup.h" -#include "smtk/operation/groups/WriterGroup.h" - -#ifdef VTK_SUPPORT -#include "smtk/session/mesh/vtk/Geometry.h" -#endif - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -namespace -{ -typedef std::tuple< - CreateUniformGrid, - EulerCharacteristicRatio, - Export, - Import, - Merge, - Print, - Read, - Transform, - Write> - OperationList; -} - -void Registrar::registerTo(const smtk::resource::Manager::Ptr& resourceManager) -{ - resourceManager->registerResource(read, write); -} - -void Registrar::registerTo(const smtk::operation::Manager::Ptr& operationManager) -{ - // Register operations - operationManager->registerOperations(); - - smtk::operation::CreatorGroup(operationManager) - .registerOperation(); - - smtk::operation::ImporterGroup(operationManager) - .registerOperation(); - - smtk::operation::ReaderGroup(operationManager) - .registerOperation(); - - smtk::operation::WriterGroup(operationManager) - .registerOperation(); -} - -void Registrar::registerTo(const smtk::geometry::Manager::Ptr& geometryManager) -{ - (void)geometryManager; - -#ifdef VTK_SUPPORT - RegisterVTKBackend::registerClass(); -#endif -} - -void Registrar::unregisterFrom(const smtk::resource::Manager::Ptr& resourceManager) -{ - resourceManager->unregisterResource(); -} - -void Registrar::unregisterFrom(const smtk::operation::Manager::Ptr& operationManager) -{ - smtk::operation::CreatorGroup(operationManager) - .unregisterOperation(); - - smtk::operation::ImporterGroup(operationManager) - .unregisterOperation(); - - smtk::operation::ReaderGroup(operationManager).unregisterOperation(); - - smtk::operation::WriterGroup(operationManager).unregisterOperation(); - - operationManager->unregisterOperations(); -} - -void Registrar::unregisterFrom(const smtk::geometry::Manager::Ptr&) {} -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/Registrar.h b/smtk/session/mesh/Registrar.h deleted file mode 100644 index 92f138d79418938281db8a0ae77681f37a0bca2a..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/Registrar.h +++ /dev/null @@ -1,49 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_Registrar_h -#define smtk_session_mesh_Registrar_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/attribute/Registrar.h" -#include "smtk/geometry/Manager.h" -#include "smtk/mesh/resource/Registrar.h" -#include "smtk/model/Registrar.h" -#include "smtk/operation/Manager.h" -#include "smtk/operation/Registrar.h" -#include "smtk/resource/Manager.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -class SMTKMESHSESSION_EXPORT Registrar -{ -public: - using Dependencies = - std::tuple; - - static void registerTo(const smtk::operation::Manager::Ptr&); - static void unregisterFrom(const smtk::operation::Manager::Ptr&); - - static void registerTo(const smtk::resource::Manager::Ptr&); - static void unregisterFrom(const smtk::resource::Manager::Ptr&); - - static void registerTo(const smtk::geometry::Manager::Ptr&); - static void unregisterFrom(const smtk::geometry::Manager::Ptr&); -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/Resource.cxx b/smtk/session/mesh/Resource.cxx deleted file mode 100644 index c9dc6874353cd29312150fc566ec0b6cd3d5fc1c..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/Resource.cxx +++ /dev/null @@ -1,56 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/session/mesh/Resource.h" - -#include "smtk/session/mesh/queries/BoundingBox.h" -#include "smtk/session/mesh/queries/ClosestPoint.h" -#include "smtk/session/mesh/queries/DistanceTo.h" -#include "smtk/session/mesh/queries/RandomPoint.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -namespace -{ -typedef std::tuple QueryList; -} - -Resource::Resource(const smtk::common::UUID& id, smtk::resource::Manager::Ptr manager) - : smtk::resource::DerivedFrom(id, manager) -{ - queries().registerQueries(); -} - -Resource::Resource(smtk::resource::Manager::Ptr manager) - : smtk::resource::DerivedFrom(manager) -{ - queries().registerQueries(); -} - -void Resource::setSession(const Session::Ptr& session) -{ - m_session = session->shared_from_this(); - this->registerSession(m_session); -} - -smtk::mesh::ResourcePtr Resource::resource() const -{ - Topology* topology = m_session->topology(shared_from_this()); - return (topology != nullptr ? topology->m_resource : smtk::mesh::ResourcePtr()); -} -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/Resource.h b/smtk/session/mesh/Resource.h deleted file mode 100644 index dbf9f25e64a0c664253c3dbb42c92bb5be2232ce..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/Resource.h +++ /dev/null @@ -1,54 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_Resource_h -#define smtk_session_mesh_Resource_h - -#include "smtk/session/mesh/Exports.h" -#include "smtk/session/mesh/Session.h" - -#include "smtk/resource/DerivedFrom.h" - -#include "smtk/model/Resource.h" - -#include "smtk/resource/Manager.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -class SMTKMESHSESSION_EXPORT Resource - : public smtk::resource::DerivedFrom -{ -public: - smtkTypeMacro(smtk::session::mesh::Resource); - smtkSharedPtrCreateMacro(smtk::resource::PersistentObject); - - ~Resource() override = default; - - const Session::Ptr& session() const { return m_session; } - void setSession(const Session::Ptr&); - - smtk::mesh::ResourcePtr resource() const; - -protected: - Resource(const smtk::common::UUID&, smtk::resource::Manager::Ptr manager = nullptr); - Resource(smtk::resource::Manager::Ptr manager = nullptr); - - Session::Ptr m_session; -}; - -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif // smtk_session_mesh_Resource_h diff --git a/smtk/session/mesh/Session.cxx b/smtk/session/mesh/Session.cxx deleted file mode 100644 index dcab2b4f76ccde46cda649e262476a4105b93a38..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/Session.cxx +++ /dev/null @@ -1,231 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/session/mesh/Session.h" -#include "smtk/session/mesh/Resource.h" - -#include "smtk/model/Edge.h" -#include "smtk/model/Face.h" -#include "smtk/model/Model.h" -#include "smtk/model/Vertex.h" -#include "smtk/model/Volume.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -Session::Session() = default; - -void Session::addTopology( - const std::shared_ptr& modelResource, - Topology t) -{ - std::vector::iterator it = - find_if(m_topologies.begin(), m_topologies.end(), [&](const Topology& t) { - return modelResource->links().isLinkedTo( - t.m_resource, smtk::model::Resource::TessellationRole); - }); - - if (it == m_topologies.end()) - { - m_topologies.push_back(t); - } - else - { - *it = t; - } -} - -Topology* Session::topology(const std::shared_ptr& modelResource) -{ - std::vector::iterator it = - find_if(m_topologies.begin(), m_topologies.end(), [&](const Topology& t) { - return modelResource->links().isLinkedTo( - t.m_resource, smtk::model::Resource::TessellationRole); - }); - return (it == m_topologies.end() ? nullptr : &(*it)); -} - -Topology* Session::topology( - const std::shared_ptr& modelResource) -{ - return this->topology(std::const_pointer_cast(modelResource)); -} - -smtk::model::SessionInfoBits Session::transcribeInternal( - const smtk::model::EntityRef& entityRef, - SessionInfoBits requestedInfo, - int depth) -{ - // Start with a null return value - SessionInfoBits actual = smtk::model::SESSION_NOTHING; - - // Find the topology associated with the entity - const smtk::session::mesh::Topology* topology = nullptr; - for (const Topology& top : m_topologies) - { - if (entityRef.entity() == top.m_modelId) - { - // The entity is the model associated with this topology - topology = ⊤ - break; - } - else if (top.m_elements.find(entityRef.entity()) != top.m_elements.end()) - { - // The entity is an element associated with this topology - topology = ⊤ - break; - } - } - - // If we don't find the associated topology, return the null value - if (topology == nullptr) - { - return actual; - } - - const Topology::Element& topologyElement = topology->m_elements.at(entityRef.entity()); - - // create a mutable copy of our entity ref, since the original one is const - smtk::model::EntityRef mutableEntityRef(entityRef); - int dimension = topologyElement.m_dimension; - - // if the entity ref is not already valid, we populate it - if (!mutableEntityRef.isValid()) - { - // Check if the entityRef is for the model. If it is, then its UUID will be - // identical to that of the collection that represents the model. - if (mutableEntityRef.entity() == topology->m_modelId) - { - // We have a model. We insert the model using the resource API. It takes - // the UUID of the model, its parametric dimension and its embedded - // dimension. Additionally, we denote that this model is discrete. - this->resource()->insertModel(mutableEntityRef.entity(), dimension, dimension); - mutableEntityRef.setIntegerProperty(SMTK_GEOM_STYLE_PROP, smtk::model::DISCRETE); - } - else - { - // We have a component of the model. We insert the component using the - // resource API. - switch (dimension) - { - case 0: - this->resource()->insertVertex(mutableEntityRef.entity()); - break; - case 1: - this->resource()->insertEdge(mutableEntityRef.entity()); - break; - case 2: - this->resource()->insertFace(mutableEntityRef.entity()); - break; - case 3: - this->resource()->insertVolume(mutableEntityRef.entity()); - break; - default: - return actual; - } - } - // We have assigned the model entity type, so we record that we have done so - actual |= smtk::model::SESSION_ENTITY_TYPE; - } - else - { - // If the entity is valid, is there any reason to refresh it? - // Perhaps we want additional information transcribed? - if (this->danglingEntities().find(mutableEntityRef) == this->danglingEntities().end()) - { - return smtk::model::SESSION_EVERYTHING; - } - } - - // We now have a valid entity in our model system. - // Next, we assign relations between entities. - if (requestedInfo & (smtk::model::SESSION_ENTITY_RELATIONS | smtk::model::SESSION_ARRANGEMENTS)) - { - for (auto&& childId : topologyElement.m_children) - { - smtk::model::EntityRef childEntityRef(this->resource(), childId); - if (!childEntityRef.isValid()) - { - // Remove this child from the list of dangling entities - this->declareDanglingEntity(childEntityRef, 0); - // Recursively run on this child. - this->transcribeInternal(childEntityRef, requestedInfo, depth < 0 ? depth : depth - 1); - } - mutableEntityRef.findOrAddRawRelation(childEntityRef); - childEntityRef.findOrAddRawRelation(mutableEntityRef); - } - // We have assigned the model relations, so we record that we have done so - actual |= (smtk::model::SESSION_ENTITY_RELATIONS | smtk::model::SESSION_ARRANGEMENTS); - } - - if (requestedInfo & smtk::model::SESSION_ATTRIBUTE_ASSOCIATIONS) - { - // TODO - actual |= smtk::model::SESSION_ATTRIBUTE_ASSOCIATIONS; - } - - // Meshes are visible without an associated tessellation, so there is nothing - // to do here - if (requestedInfo & smtk::model::SESSION_TESSELLATION) - { - actual |= smtk::model::SESSION_TESSELLATION; - } - - if (requestedInfo & smtk::model::SESSION_PROPERTIES) - { - // Models generated from a mesh set naturally have the same properties as - // mesh sets. We query the model entity's associated mesh set for domain, - // Dirichlet and Neumann properties. - - if (topologyElement.m_mesh.size() == 1) - { - // To avoid elements that only partially contain the properties in question, - // we check that the associated meshset contains exactly one property and - // that the property completely spans the meshset. - std::vector domains = topologyElement.m_mesh.domains(); - std::vector dirichlets = topologyElement.m_mesh.dirichlets(); - std::vector neumanns = topologyElement.m_mesh.neumanns(); - - if (domains.size() == 1 && topologyElement.m_mesh.size() == 1) - { - mutableEntityRef.setIntegerProperty("pedigree id", domains[0].value()); - std::stringstream s; - s << m_facade["domain"] << " " << domains[0].value(); - mutableEntityRef.setName(s.str()); - } - else if (dirichlets.size() == 1 && topologyElement.m_mesh.size() == 1) - { - mutableEntityRef.setIntegerProperty("pedigree id", dirichlets[0].value()); - std::stringstream s; - s << m_facade["dirichlet"] << " " << dirichlets[0].value(); - mutableEntityRef.setName(s.str()); - } - else if (neumanns.size() == 1 && topologyElement.m_mesh.size() == 1) - { - mutableEntityRef.setIntegerProperty("pedigree id", neumanns[0].value()); - std::stringstream s; - s << m_facade["neumann"] << " " << neumanns[0].value(); - mutableEntityRef.setName(s.str()); - } - } - - actual |= smtk::model::SESSION_PROPERTIES; - } - - return actual; -} -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/Session.h b/smtk/session/mesh/Session.h deleted file mode 100644 index cd693fb78ac1110cac4a891f40596afcddf56c3e..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/Session.h +++ /dev/null @@ -1,67 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_Session_h -#define smtk_session_mesh_Session_h - -#include "smtk/session/mesh/Exports.h" -#include "smtk/session/mesh/Facade.h" -#include "smtk/session/mesh/Topology.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Session.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -class Resource; - -class SMTKMESHSESSION_EXPORT Session : public smtk::model::Session -{ -public: - smtkTypeMacro(Session); - smtkSuperclassMacro(smtk::model::Session); - smtkSharedFromThisMacro(smtk::model::Session); - smtkCreateMacro(smtk::model::Session); - typedef smtk::model::SessionInfoBits SessionInfoBits; - - ~Session() override = default; - - void addTopology(Topology t) { m_topologies.push_back(t); } - void addTopology(const std::shared_ptr& modelResource, Topology t); - Topology* topology(const std::shared_ptr& modelResource); - Topology* topology(const std::shared_ptr& modelResource); - - std::string defaultFileExtension(const smtk::model::Model&) const override { return ""; } - - Facade& facade() { return m_facade; } - -protected: - Session(); - - SessionInfoBits transcribeInternal( - const smtk::model::EntityRef& entity, - SessionInfoBits requestedInfo, - int depth = -1) override; - - std::vector m_topologies; - Facade m_facade; -}; - -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif // smtk_session_mesh_Session_h diff --git a/smtk/session/mesh/Topology.cxx b/smtk/session/mesh/Topology.cxx deleted file mode 100644 index a350a2890797dff11165f811e9bb44978237cf52..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/Topology.cxx +++ /dev/null @@ -1,310 +0,0 @@ -//============================================================================= -// -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -//============================================================================= -#include "smtk/session/mesh/Topology.h" - -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/ForEachTypes.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -namespace -{ -typedef std::vector> ElementShells; - -class AddFreeElements : public smtk::mesh::MeshForEach -{ -public: - AddFreeElements(Topology* topology, Topology::Element* root) - : m_topology(topology) - , m_root(root) - { - } - - void setElementShells(ElementShells* shells) { m_shells = shells; } - void setDimension(int dimension) { m_dimension = dimension; } - - void forMesh(smtk::mesh::MeshSet& singleMesh) override - { - // Each free mesh is an element. It gets a unique id and has the model as - // its parent. - - // First, check if the mesh has an associated element already. If it does, - // use this value (facilitating persistency across multiple calls to the - // construction of Topologies). - smtk::common::UUIDArray ids = singleMesh.modelEntityIds(); - smtk::common::UUID id; - if (ids.empty()) - { - id = (m_topology->m_resource->modelResource()->unusedUUID()); - // Assign the unique id to the mesh - singleMesh.setModelEntityId(id); - } - else - { - id = ids[0]; - } - - // add the unique id as a child of the model - m_root->m_children.insert(id); - // construct an element for the mesh, insert it into the topology's map - // with its id as the key and, if requested, store its shell as a pair along - // with a pointer to its associated Element (for use in extracting bound - // elements). - Topology::Element* element = - &m_topology->m_elements - .insert(std::make_pair(id, Topology::Element(singleMesh, id, m_dimension))) - .first->second; - element->m_parents.insert(m_root->m_id); - - if (m_shells) - { - smtk::mesh::MeshSet shell = singleMesh.extractShell(); - if (!shell.is_empty()) - { - // The shell is a new meshset containing all of the cells that comprise - // the shell. It does not account for the existing meshsets that may - // comprise the shell (which is what we need). So, we partition the - // shell using the existing meshests of the appropriate dimension. - smtk::mesh::CellSet shellCells = shell.cells(); - smtk::mesh::MeshSet cellsOfDimension = smtk::mesh::set_difference( - m_topology->m_resource->meshes(smtk::mesh::DimensionType(m_dimension - 1)), shell); - for (std::size_t i = 0; i < cellsOfDimension.size(); i++) - { - smtk::mesh::CellSet intersect = - smtk::mesh::set_intersect(cellsOfDimension.subset(i).cells(), shell.cells()); - - // If the intersection is nonzero and the mesh subset is entirely - // contained by the shell, we add the subset as a child entity and we - // remove its contents from the list of shell cells. - if ( - !intersect.is_empty() && intersect.size() == cellsOfDimension.subset(i).cells().size()) - { - m_shells->emplace_back(cellsOfDimension.subset(i), element); - shellCells = smtk::mesh::set_difference(shellCells, intersect); - } - } - // After all predescribed entities have been removed from the shell, - // whatever remains is also an entity. - if (!shellCells.is_empty()) - { - m_shells->emplace_back(m_topology->m_resource->createMesh(shellCells), element); - } - m_topology->m_resource->removeMeshes(shell); - } - } - } - -protected: - Topology* m_topology; - Topology::Element* m_root; - ElementShells* m_shells{ nullptr }; - int m_dimension{ -1 }; -}; - -struct AddBoundElements -{ - AddBoundElements(Topology* topology) - : m_topology(topology) - { - } - - void setElementShells(ElementShells* shells) { m_shells = shells; } - void setDimension(int dimension) { m_dimension = dimension; } - - void operator()(ElementShells::iterator start, ElementShells::iterator end) - { - std::vector activeShells; - - ElementShells::iterator seed = start; - - while (seed != end) - { - activeShells.push_back(seed++); - - while (!activeShells.empty()) - { - smtk::mesh::MeshSet m = activeShells.back()->first; - for (ElementShells::iterator j = seed; j != end; ++j) - { - smtk::mesh::CellSet cs = smtk::mesh::set_intersect(m.cells(), j->first.cells()); - if (!cs.is_empty()) - { - m = m_topology->m_resource->createMesh(cs); - activeShells.push_back(j); - } - if (m_dimension == 2 && activeShells.size() == 2) - { - break; - } - } - - if (!m.is_empty()) - { - // We have an intersection, so we must now process it. We start by - // creating a new id for it. - smtk::common::UUIDArray ids = m.modelEntityIds(); - smtk::common::UUID id; - if (ids.empty()) - { - id = (m_topology->m_resource->modelResource()->unusedUUID()); - // Assign the unique id to the mesh - m.setModelEntityId(id); - } - else - { - id = ids[0]; - } - - // Next, we remove the intersection from the contributing mesh sets - // and add the new id as a child of these sets. We also record the - // sets' ids as parents of the new set. - smtk::common::UUIDArray parents; - for (auto&& shell : activeShells) - { - if (activeShells.size() > 1) - { - smtk::mesh::MeshSet tmp = m_topology->m_resource->createMesh( - smtk::mesh::set_difference(shell->first.cells(), m.cells())); - m_topology->m_resource->removeMeshes(shell->first); - shell->first = tmp; - } - shell->second->m_children.insert(id); - parents.push_back(shell->second->m_id); - } - - // finally, we insert it as an element into the topology. If - // necessary, we store its shell for the bound element calculation of - // lower dimension - Topology::Element* element = - &m_topology->m_elements - .insert(std::make_pair(id, Topology::Element(m, id, m_dimension))) - .first->second; - element->m_parents.insert(parents.begin(), parents.end()); - if (m_shells) - { - m_shells->emplace_back(m.extractShell(), element); - } - } - if (activeShells.size() == 1) - { - activeShells.pop_back(); - } - else - { - activeShells.erase(std::next(activeShells.begin()), activeShells.end()); - } - } - } - } - - Topology* m_topology; - ElementShells* m_shells; - int m_dimension; -}; -} // namespace - -Topology::Topology( - const smtk::common::UUID& modelId, - const smtk::mesh::MeshSet& meshset, - bool constructHierarchy) - : m_resource(meshset.resource()) - , m_modelId(modelId) -{ - // Insert the mesh resource as the top-level element representing the model - Element* model = - &(m_elements.insert(std::make_pair(modelId, Element(meshset, modelId))).first->second); - - if (constructHierarchy) - { - // Extract single meshes as volumes and grab their shells - ElementShells volumeShells; - ElementShells faceShells; - ElementShells edgeShells; - - ElementShells* elementShells[4] = { nullptr, &edgeShells, &faceShells, &volumeShells }; - - AddFreeElements addFreeElements(this, model); - - // all meshes of the highest dimension are considered to be free elements with - // the model as their parent - int dimension = smtk::mesh::DimensionType_MAX - 1; - smtk::mesh::TypeSet types = meshset.types(); - while (dimension >= 0 && !types.hasDimension(static_cast(dimension))) - { - --dimension; - } - - if (dimension < 0) - { - // We have been passed an empty meshset - return; - } - - { - addFreeElements.setElementShells(elementShells[dimension]); - addFreeElements.setDimension(dimension); - smtk::mesh::for_each( - meshset.subset(static_cast(dimension)), addFreeElements); - } - - AddBoundElements addBoundElements(this); - --dimension; - for (; dimension >= 0; dimension--) - { - addFreeElements.setElementShells(elementShells[dimension]); - addFreeElements.setDimension(dimension); - - smtk::mesh::MeshSet allMeshes = - meshset.subset(static_cast(dimension)); - smtk::mesh::MeshSet boundMeshes; - - for (auto&& shell : *elementShells[dimension + 1]) - { - boundMeshes.append(shell.first); - } - if (!boundMeshes.is_empty() && !boundMeshes.cells().is_empty()) - { - smtk::mesh::MeshSet freeMeshes = m_resource->createMesh( - smtk::mesh::set_difference(allMeshes.cells(), boundMeshes.cells())); - smtk::mesh::for_each(freeMeshes, addFreeElements); - } - - addBoundElements.setElementShells(elementShells[dimension]); - addBoundElements.setDimension(dimension); - addBoundElements(elementShells[dimension + 1]->begin(), elementShells[dimension + 1]->end()); - } - } - else - { - AddFreeElements addFreeElements(this, model); - - // all meshes are considered to be free elements with the model as their parent - for (int dimension = smtk::mesh::DimensionType_MAX - 1; dimension >= 0; dimension--) - { - addFreeElements.setDimension(dimension); - smtk::mesh::for_each( - meshset.subset(static_cast(dimension)), addFreeElements); - } - } -} -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/Topology.h b/smtk/session/mesh/Topology.h deleted file mode 100644 index 56c3ace94e6ec1da17bf7459b2b01816cbc84f86..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/Topology.h +++ /dev/null @@ -1,68 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_Topology_h -#define smtk_session_mesh_Topology_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/core/Resource.h" - -#include "smtk/common/UUID.h" -#include "smtk/common/UUIDGenerator.h" - -#include - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief A tree for representing hierarchical relationships between mesh sets. - - When mapping a mesh resource of mesh sets to a model, it is necessary to - construct hierarchical relationships between mesh sets. This struct provides - the description of these relationships, as well as a means of automatically - constructing the hierarchy by extracting mesh shells. - */ -struct SMTKMESHSESSION_EXPORT Topology -{ - Topology( - const smtk::common::UUID& modelId, - const smtk::mesh::MeshSet& meshset, - bool constructHierarchy = true); - - struct Element - { - Element(const smtk::mesh::MeshSet& mesh, const smtk::common::UUID& id, int dimension = -1) - : m_mesh(mesh) - , m_dimension(dimension) - , m_id(id) - { - } - - smtk::mesh::MeshSet m_mesh; - int m_dimension; - smtk::common::UUID m_id; - std::set m_parents; - std::set m_children; - }; - - smtk::mesh::ResourcePtr m_resource; - smtk::common::UUID m_modelId; - std::map m_elements; -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/operators/CreateUniformGrid.cxx b/smtk/session/mesh/operators/CreateUniformGrid.cxx deleted file mode 100644 index 6f7cfb3b7f93188f1e2cf4fc42e0f1d13fae72da..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/CreateUniformGrid.cxx +++ /dev/null @@ -1,217 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/session/mesh/operators/CreateUniformGrid.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/Session.h" -#include "smtk/session/mesh/operators/CreateUniformGrid_xml.h" - -#include "smtk/common/UUID.h" - -#include "smtk/mesh/core/CellTraits.h" -#include "smtk/mesh/core/CellTypes.h" - -#include "smtk/mesh/utility/Create.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -CreateUniformGrid::Result CreateUniformGrid::operateInternal() -{ - // Access the string describing the dimension. The dimension is a string so we - // can use optional children to assign the lengths of the other parameters. - smtk::attribute::StringItem::Ptr dimensionItem = this->parameters()->findString("dimension"); - - int dimension; - std::string suffix; - if (dimensionItem->value() == "2") - { - dimension = 2; - suffix = "2d"; - } - else - { - dimension = 3; - suffix = "3d"; - } - - // Access the origin, size and discretization parameters - smtk::attribute::DoubleItemPtr originItem = this->parameters()->findDouble("origin" + suffix); - smtk::attribute::DoubleItemPtr sizeItem = this->parameters()->findDouble("size" + suffix); - smtk::attribute::IntItemPtr discretizationItem = - this->parameters()->findInt("discretization" + suffix); - - // Copy their values to local fields - std::array origin{ { 0., 0., 0. } }; - std::array size{ { 0., 0., 0. } }; - std::array discretization{ { 1, 1, 1 } }; - - for (int i = 0; i < dimension; i++) - { - origin[i] = originItem->value(i); - size[i] = sizeItem->value(i); - discretization[i] = discretizationItem->value(i); - } - - // Construct a mapping from a unit box to the input box - std::function(std::array)> fn = [&](std::array x) { - return std::array( - { { origin[0] + size[0] * x[0], origin[1] + size[1] * x[1], origin[2] + size[2] * x[2] } }); - }; - - // There are three possible import modes - // - // 1. Import a mesh into an existing resource - // 2. Import a mesh as a new model, but using the session of an existing resource - // 3. Import a mesh into a new resource - - smtk::session::mesh::Resource::Ptr resource = nullptr; - smtk::session::mesh::Session::Ptr session = nullptr; - - // Modes 2 and 3 requre an existing resource for input - smtk::attribute::ResourceItem::Ptr existingResourceItem = - this->parameters()->findResource("resource"); - - if (existingResourceItem && existingResourceItem->isEnabled()) - { - smtk::session::mesh::Resource::Ptr existingResource = - std::static_pointer_cast(existingResourceItem->value()); - - session = existingResource->session(); - - smtk::attribute::StringItem::Ptr sessionOnlyItem = - this->parameters()->findString("session only"); - if (sessionOnlyItem->value() == "this file") - { - // If the "session only" value is set to "this file", then we use the - // existing resource - resource = existingResource; - } - else - { - // If the "session only" value is set to "this session", then we create a - // new resource with the session from the exisiting resource - resource = smtk::session::mesh::Resource::create(); - resource->setSession(session); - } - } - else - { - // If no existing resource is provided, then we create a new session and - // resource. - resource = smtk::session::mesh::Resource::create(); - session = smtk::session::mesh::Session::create(); - - // Create a new resource for the import - resource->setSession(session); - } - - // Create a new mesh mesh resource - smtk::mesh::ResourcePtr meshResource = smtk::mesh::Resource::create(); - - // Construct a uniform grid - std::vector meshes; - if (dimension == 2) - { - std::array disc = { { discretization[0], discretization[1] } }; - auto ms = smtk::mesh::utility::createUniformGrid(meshResource, disc, fn); - for (auto& m : ms) - { - meshes.push_back(m); - } - } - else - { - auto ms = smtk::mesh::utility::createUniformGrid(meshResource, discretization, fn); - for (auto& m : ms) - { - meshes.push_back(m); - } - } - - // Assign the mesh resource's model resource to the one associated with this - // session. - meshResource->setModelResource(resource); - - // Also assign the mesh resource to be the model's tessellation - resource->setMeshTessellations(meshResource); - - // Create a model with the appropriate dimension - smtk::model::Model model = resource->addModel(3, 3); - - // Construct the topology. - session->addTopology( - smtk::session::mesh::Topology(model.entity(), meshResource->meshes(), false)); - - // Declare the model as "dangling" so it will be transcribed. - session->declareDanglingEntity(model); - - meshResource->associateToModel(model.entity()); - - // Set the model's session to point to the current session. - model.setSession(smtk::model::SessionRef(resource, resource->session()->sessionId())); - - // If we don't call "transcribe" ourselves, it never gets called. - resource->session()->transcribe(model, smtk::model::SESSION_EVERYTHING, false); - - // Now that there are model components associated with our mesh sets, give the - // model adjacencies human-readable names. - if (dimension == 2) - { - smtk::model::EntityRef(resource, meshes[0].modelEntityIds().at(0)).setName("Domain"); - smtk::model::EntityRef(resource, meshes[1].modelEntityIds().at(0)).setName("Lower X"); - smtk::model::EntityRef(resource, meshes[2].modelEntityIds().at(0)).setName("Lower Y"); - smtk::model::EntityRef(resource, meshes[3].modelEntityIds().at(0)).setName("Upper X"); - smtk::model::EntityRef(resource, meshes[4].modelEntityIds().at(0)).setName("Upper Y"); - } - else - { - smtk::model::EntityRef(resource, meshes[0].modelEntityIds().at(0)).setName("Domain"); - smtk::model::EntityRef(resource, meshes[1].modelEntityIds().at(0)).setName("Lower X"); - smtk::model::EntityRef(resource, meshes[2].modelEntityIds().at(0)).setName("Lower Y"); - smtk::model::EntityRef(resource, meshes[3].modelEntityIds().at(0)).setName("Lower Z"); - smtk::model::EntityRef(resource, meshes[4].modelEntityIds().at(0)).setName("Upper X"); - smtk::model::EntityRef(resource, meshes[5].modelEntityIds().at(0)).setName("Upper Y"); - smtk::model::EntityRef(resource, meshes[6].modelEntityIds().at(0)).setName("Upper Z"); - } - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - { - smtk::attribute::ResourceItem::Ptr created = result->findResource("resourcesCreated"); - created->appendValue(resource); - } - - { - smtk::attribute::ComponentItem::Ptr created = result->findComponent("created"); - created->appendValue(model.component()); - } - - return result; -} - -const char* CreateUniformGrid::xmlDescription() const -{ - return CreateUniformGrid_xml; -} -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/operators/CreateUniformGrid.h b/smtk/session/mesh/operators/CreateUniformGrid.h deleted file mode 100644 index c3c9bd00db55f0bc7cc03e5ee05eec3069fbb9ec..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/CreateUniformGrid.h +++ /dev/null @@ -1,41 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_CreateUniformGrid_h -#define smtk_session_mesh_CreateUniformGrid_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief Construct a 2- or 3-dimensional uniform grid and its sides. - */ -class SMTKMESHSESSION_EXPORT CreateUniformGrid : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::session::mesh::CreateUniformGrid); - smtkCreateMacro(CreateUniformGrid); - smtkSharedFromThisMacro(smtk::operation::Operation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/operators/CreateUniformGrid.sbt b/smtk/session/mesh/operators/CreateUniformGrid.sbt deleted file mode 100644 index 64ab9fc5b5624138aafb6f9fa6d8556b2244e151..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/CreateUniformGrid.sbt +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - Construct a simple uniform grid - - - - - - - - - - - - - 0,0 - - - - - - - - 0 - 1,1 - - - - - - - - 0 - 5,5 - - - - - - - - - 0,0,0 - - - - - - - - - 0 - 1,1,1 - - - - - - - - - 0 - 5,5,5 - - - - - - - 2 - - origin2d - size2d - discretization2d - - - - 3 - - origin3d - size3d - discretization3d - - - - - - - - - - - - - - - import into this file - - - import into a new file using this file's session - - - - - - - - - - - - - - - - - - - - diff --git a/smtk/session/mesh/operators/EulerCharacteristicRatio.cxx b/smtk/session/mesh/operators/EulerCharacteristicRatio.cxx deleted file mode 100644 index 0683c6e9b8c8ab07fcaa0adb1ab419f44898bb22..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/EulerCharacteristicRatio.cxx +++ /dev/null @@ -1,90 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/session/mesh/operators/EulerCharacteristicRatio.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/Session.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/DoubleItem.h" - -#include "smtk/common/CompilerInformation.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/model/Model.h" - -#include "smtk/session/mesh/operators/EulerCharacteristicRatio_xml.h" - -using namespace smtk::model; -using namespace smtk::common; - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -EulerCharacteristicRatio::Result EulerCharacteristicRatio::operateInternal() -{ - // Access the associated model. - smtk::model::Model model = this->parameters()->associatedModelEntities()[0]; - if (!model.isValid()) - { - smtkErrorMacro(this->log(), "Invalid model."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - smtk::session::mesh::Resource::Ptr resource = - std::static_pointer_cast(model.component()->resource()); - smtk::session::mesh::Session::Ptr session = resource->session(); - - // Access the underlying mesh resource for the model. - smtk::mesh::ResourcePtr meshResource = resource->resource(); - if (meshResource == nullptr || !meshResource->isValid()) - { - smtkErrorMacro(this->log(), "No mesh resource associated with this model."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Access the meshes from the mesh resource. - smtk::mesh::MeshSet mesh = meshResource->meshes(); - - // Compute the Euler characteristics for the model's boundary and volume. - int eulerBoundary = smtk::mesh::utility::eulerCharacteristic(mesh.extractShell()); - int eulerVolume = smtk::mesh::utility::eulerCharacteristic(mesh); - - // Compute the ratio of these two values. - double eulerRatio = ((double)(eulerBoundary)) / ((double)(eulerVolume)); - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Set the double item that will hold the euler ratio. - smtk::attribute::DoubleItemPtr eulerItem = result->findDouble("value"); - eulerItem->setValue(eulerRatio); - - std::stringstream s; - s << "Input mesh has ratio of boundary/volume Euler characteristics = " << eulerBoundary << " / " - << eulerVolume << " = " << eulerRatio << "."; - smtkInfoMacro(this->log(), s.str()); - - return result; -} - -const char* EulerCharacteristicRatio::xmlDescription() const -{ - return EulerCharacteristicRatio_xml; -} - -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/operators/EulerCharacteristicRatio.h b/smtk/session/mesh/operators/EulerCharacteristicRatio.h deleted file mode 100644 index ba2885e5d2ec39fcf04cc43fb461ea6f87003525..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/EulerCharacteristicRatio.h +++ /dev/null @@ -1,43 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_EulerCharacteristicRatio_h -#define smtk_session_mesh_EulerCharacteristicRatio_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief Compute and return the ratio of Euler characteristic surface to volume - for a model's mesh tessellation. - */ -class SMTKMESHSESSION_EXPORT EulerCharacteristicRatio : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::session::mesh::EulerCharacteristicRatio); - smtkCreateMacro(EulerCharacteristicRatio); - smtkSharedFromThisMacro(smtk::operation::Operation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; - -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif // smtk_session_mesh_EulerCharacteristicRatio_h diff --git a/smtk/session/mesh/operators/EulerCharacteristicRatio.sbt b/smtk/session/mesh/operators/EulerCharacteristicRatio.sbt deleted file mode 100644 index 74b4e2350fbd4490be0596742d95fdf30125f179..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/EulerCharacteristicRatio.sbt +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - Compute the ratio of the Euler characteristics for a model's - boundary to its volume. - - - - - - - - - - - - - - diff --git a/smtk/session/mesh/operators/Export.cxx b/smtk/session/mesh/operators/Export.cxx deleted file mode 100644 index 5ee15ec3af62b749ebe2019ba8f2a9b4703e1863..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Export.cxx +++ /dev/null @@ -1,90 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/session/mesh/operators/Export.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/Session.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/WriteMesh.h" - -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" - -#include "smtk/session/mesh/operators/Export_xml.h" - -using namespace smtk::model; -using namespace smtk::common; - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -void breakMaterialsByAssociation(const smtk::mesh::ResourcePtr& c) -{ - //for each association we iterate the meshsets - smtk::model::EntityRefArray refs; - c->meshes().modelEntities(refs); - - int domain = 0; - for (auto&& ref : refs) - { - smtk::mesh::MeshSet m = c->findAssociatedMeshes(ref); - c->setDomainOnMeshes(m, smtk::mesh::Domain(domain++)); - } -} - -smtk::session::mesh::Export::Result Export::operateInternal() -{ - smtk::attribute::FileItem::Ptr filePathItem = this->parameters()->findFile("filename"); - - std::string filePath = filePathItem->value(); - - auto resourceItem = this->parameters()->associations(); - - smtk::session::mesh::Resource::Ptr resource = - std::dynamic_pointer_cast(resourceItem->value()); - - smtk::mesh::ResourcePtr meshResource = resource->resource(); - - if (meshResource == nullptr || !meshResource->isValid()) - { - smtkErrorMacro(this->log(), "No mesh resource associated with this model."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - breakMaterialsByAssociation(meshResource); - - bool writeSuccess = smtk::io::writeMesh(filePath, meshResource); - - if (!writeSuccess) - { - smtkErrorMacro(this->log(), "Mesh resource failed to write."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - return result; -} - -const char* Export::xmlDescription() const -{ - return Export_xml; -} - -} // namespace mesh -} //namespace session -} // namespace smtk diff --git a/smtk/session/mesh/operators/Export.h b/smtk/session/mesh/operators/Export.h deleted file mode 100644 index 43b92a0bf280599198c4ae0e5f4c49d1cf1db793..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Export.h +++ /dev/null @@ -1,40 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_Export_h -#define smtk_session_mesh_Export_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -class SMTKMESHSESSION_EXPORT Export : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::session::mesh::Export); - smtkCreateMacro(Export); - smtkSharedFromThisMacro(smtk::operation::Operation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; - -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif // smtk_session_mesh_Export_h diff --git a/smtk/session/mesh/operators/Export.sbt b/smtk/session/mesh/operators/Export.sbt deleted file mode 100644 index fddd2369d81b90e36bebcaf0b2e2e4efdac902a1..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Export.sbt +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/smtk/session/mesh/operators/Import.cxx b/smtk/session/mesh/operators/Import.cxx deleted file mode 100644 index 9088e160798f27b5fdfbfe4df20f2821485de747..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Import.cxx +++ /dev/null @@ -1,321 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/Session.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/Definition.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/FileItemDefinition.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/Resource.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/common/Paths.h" - -#include "smtk/io/ImportMesh.h" - -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" -#include "smtk/model/Resource.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/resource/Manager.h" - -#include "smtk/session/mesh/operators/Import_xml.h" - -using namespace smtk::model; -using namespace smtk::common; - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -Import::Result Import::operateInternal() -{ - // Get the read file name - smtk::attribute::FileItem::Ptr filePathItem = this->parameters()->findFile("filename"); - std::string filePath = filePathItem->value(); - - // Get the label item - smtk::attribute::StringItem::Ptr labelItem = this->parameters()->findString("label"); - std::string label = labelItem->value(); - - // Check whether or not a model hierarchy should be constructed - smtk::attribute::VoidItem::Ptr hierarchyItem = - this->parameters()->findVoid("construct hierarchy"); - bool constructHierarchy = hierarchyItem->isEnabled(); - - // There are three possible import modes - // - // 1. Import a mesh into an existing resource - // 2. Import a mesh as a new model, but using the session of an existing resource - // 3. Import a mesh into a new resource - - smtk::session::mesh::Resource::Ptr resource = nullptr; - smtk::session::mesh::Session::Ptr session = nullptr; - smtk::mesh::Resource::Ptr meshResource = nullptr; - - // Modes 2 and 3 requre an existing resource for input - smtk::attribute::ReferenceItem::Ptr existingResourceItem = this->parameters()->associations(); - - bool newResource = true; - if (existingResourceItem->numberOfValues() > 0) - { - smtk::session::mesh::Resource::Ptr existingResource = - std::static_pointer_cast(existingResourceItem->value()); - - session = existingResource->session(); - - smtk::attribute::StringItem::Ptr sessionOnlyItem = - this->parameters()->findString("session only"); - if (sessionOnlyItem->value() == "import into this file") - { - // If the "session only" value is set to "this file", then we use the - // existing resource - newResource = false; - resource = existingResource; - meshResource = existingResource->resource(); - - // It is possible that a mesh session resource does not have a valid - // mesh resource (for example, when it is newly created). In this case, we - // need a new mesh resource instead. - if (meshResource == nullptr) - { - newResource = true; - meshResource = smtk::mesh::Resource::create(); - } - } - else - { - // If the "session only" value is set to "this session", then we create a - // new resource with the session from the exisiting resource - resource = smtk::session::mesh::Resource::create(); - meshResource = smtk::mesh::Resource::create(); - resource->setSession(session); - } - } - else - { - // If no existing resource is provided, then we create a new session and - // resource. - resource = smtk::session::mesh::Resource::create(); - session = smtk::session::mesh::Session::create(); - meshResource = smtk::mesh::Resource::create(); - - // Create a new resource for the import - resource->setSession(session); - } - - if (!meshResource || !meshResource->isValid()) - { - // The file was not correctly read. - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Get the mesh resource from the file - smtk::mesh::MeshSet preexistingMeshes = meshResource->meshes(); - smtk::io::importMesh(filePath, meshResource, label); - smtk::mesh::MeshSet allMeshes = meshResource->meshes(); - smtk::mesh::MeshSet newMeshes = smtk::mesh::set_difference(allMeshes, preexistingMeshes); - - // Name the mesh according to the stem of the file - std::string name = smtk::common::Paths::stem(filePath); - if (!name.empty() && newResource) - { - meshResource->setName(name); - resource->setName(name); - } - - auto format = smtk::io::meshFileFormat(filePath); - if (format.Name.find("Exodus") != std::string::npos) - { - session->facade()["domain"] = "Element Block"; - session->facade()["dirichlet"] = "Node Set"; - session->facade()["neumann"] = "Side Set"; - } - - // Assign the mesh resource's model resource to the one associated with this - // session - meshResource->setModelResource(resource); - - // Also assign the mesh resource to be the model's tessellation - resource->setMeshTessellations(meshResource); - - // If we are reading a mesh session resource (as opposed to a new import), we - // should access the existing model instead of creating a new one here. If - // this is the case, then the mesh resource's associated model id will be related - // to a model entity that is already in the resource (as it was put there by - // the Read operation calling this one). - smtk::common::UUID associatedModelId = meshResource->associatedModel(); - - // By default, a model is invalid - smtk::model::Model model; - if (associatedModelId != smtk::common::UUID::null() && newResource) - { - // Assign the model to one described already in the resource with the id of - // mesh resource's associated model. If there is no such model, then this - // instance will also be invalid. - model = smtk::model::Model(resource, associatedModelId); - } - - if (!model.isValid()) - { - // Determine the model's dimension - int dimension = int(smtk::mesh::utility::highestDimension(meshResource->meshes())); - - // Create a model with the appropriate dimension - model = resource->addModel(dimension, dimension); - - // Name the model according to the stem of the file - if (!name.empty()) - { - model.setName(name); - } - } - - // Construct the topology - session->addTopology(resource, Topology(model.entity(), newMeshes, constructHierarchy)); - - // Set the url and type of the model - model.setStringProperty("url", filePath); - model.setStringProperty("type", format.Name); - - // Declare the model as "dangling" so it will be transcribed - session->declareDanglingEntity(model); - - meshResource->associateToModel(model.entity()); - - // Set the model's session to point to the current session - model.setSession(smtk::model::SessionRef(resource, resource->session()->sessionId())); - - // If we don't call "transcribe" ourselves, it never gets called. - resource->session()->transcribe( - model, - (this->callFromRead ? smtk::model::SESSION_EVERYTHING & ~smtk::model::SESSION_PROPERTIES - : smtk::model::SESSION_EVERYTHING), - false); - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - smtk::attribute::ComponentItem::Ptr resultModels = result->findComponent("model"); - resultModels->setValue(model.component()); - - { - smtk::attribute::ResourceItem::Ptr created = result->findResource("resourcesCreated"); - created->appendValue(resource); - } - - { - smtk::attribute::ComponentItem::Ptr created = result->findComponent("created"); - created->appendValue(model.component()); - } - - // Access the model resource's associated topology. - smtk::session::mesh::Topology* topology = resource->session()->topology(resource); - - // Mark the modified model components to update their representative geometry - smtk::operation::MarkGeometry markGeometry(resource); - - std::function mark; - - mark = [&](const smtk::common::UUID& id) { - markGeometry.markModified(resource->find(id)); - auto elementIt = topology->m_elements.find(id); - if (elementIt == topology->m_elements.end()) - { - return; - } - Topology::Element& element = elementIt->second; - - for (const smtk::common::UUID& childId : element.m_children) - { - mark(childId); - } - }; - - mark(model.entity()); - - result->findComponent("mesh_created")->setValue(model.component()); - - return result; -} - -Import::Specification Import::createSpecification() -{ - Specification spec = this->smtk::operation::XMLOperation::createSpecification(); - auto importDef = spec->findDefinition("import"); - - std::vector fileItemDefinitions; - auto fileItemDefinitionFilter = [](smtk::attribute::FileItemDefinition::Ptr ptr) { - return ptr->name() == "filename"; - }; - importDef->filterItemDefinitions(fileItemDefinitions, fileItemDefinitionFilter); - - assert(fileItemDefinitions.size() == 1); - - std::stringstream fileFilters; - bool firstFormat = true; - for (auto& ioType : smtk::io::ImportMesh::SupportedIOTypes()) - { - for (const auto& format : ioType->FileFormats()) - { - if (format.CanImport()) - { - if (firstFormat) - { - firstFormat = false; - } - else - { - fileFilters << ";;"; - } - - fileFilters << format.Name << "("; - bool first = true; - for (const auto& ext : format.Extensions) - { - if (first) - { - first = false; - } - else - { - fileFilters << " "; - } - fileFilters << "*" << ext; - } - fileFilters << ")"; - } - } - } - fileItemDefinitions[0]->setFileFilters(fileFilters.str()); - return spec; -} - -const char* Import::xmlDescription() const -{ - return Import_xml; -} - -} // namespace mesh -} //namespace session -} // namespace smtk diff --git a/smtk/session/mesh/operators/Import.h b/smtk/session/mesh/operators/Import.h deleted file mode 100644 index e3fc261a0d2ea65dd5d792f4f89461525cd86e71..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Import.h +++ /dev/null @@ -1,45 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_Import_h -#define smtk_session_mesh_Import_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ -class Read; - -class SMTKMESHSESSION_EXPORT Import : public smtk::operation::XMLOperation -{ - friend class Read; - -public: - smtkTypeMacro(smtk::session::mesh::Import); - smtkCreateMacro(Import); - smtkSharedFromThisMacro(smtk::operation::Operation); - -protected: - Result operateInternal() override; - Specification createSpecification() override; - const char* xmlDescription() const override; - - bool callFromRead = false; -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/operators/Import.sbt b/smtk/session/mesh/operators/Import.sbt deleted file mode 100644 index f91a415f360351907a7a74957feda676a71adf9d..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Import.sbt +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - Import a model from a mesh file. - - - <p>Import a model from a mesh file. - <p>This operator imports a mesh into smtk, and then - parses its components by dimension and connectivity to form a model. - - - - - - - - - - - - - - - - - import into this file - - - import into a new file using this file's session - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/smtk/session/mesh/operators/Merge.cxx b/smtk/session/mesh/operators/Merge.cxx deleted file mode 100644 index f22e89639dd6b2e7b2961f683a915213b8492608..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Merge.cxx +++ /dev/null @@ -1,272 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/session/mesh/operators/Merge.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/Session.h" -#include "smtk/session/mesh/Topology.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" - -#include "smtk/common/CompilerInformation.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/model/Face.h" -#include "smtk/model/Model.h" - -#include "smtk/resource/Component.h" -#include "smtk/resource/Resource.h" - -#include "smtk/session/mesh/operators/Merge_xml.h" - -using namespace smtk::model; -using namespace smtk::common; - -namespace -{ -// When entities are merged, a name for the resulting merged entity is created -// by concatenating the merging entities with " & ". This quickly becomes -// unwieldy when merging large numbers of entities. This value defines the -// maximum number of entities to merge before switching to the naming convention -// of "# entities". -constexpr const std::size_t DescriptionAppendLimit = 5; -} // namespace - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -bool Merge::ableToOperate() -{ - if (!this->smtk::operation::XMLOperation::ableToOperate()) - { - return false; - } - - // Access the associated model entities - auto associations = this->parameters()->associations(); - - // Access the first input model entity - auto component = associations->valueAs(); - - // Access the model resource associated with the first input model entity - smtk::session::mesh::Resource::Ptr resource = - std::static_pointer_cast(component->resource()); - - // Access the model resource's associated topology - smtk::session::mesh::Topology* topology = resource->session()->topology(resource); - - // Access the dimension of the model entity - int dimension = topology->m_elements.at(component->id()).m_dimension; - - for (auto it = associations->begin(); it != associations->end(); ++it) - { - // All model entities must come from the same resource - if ( - resource->id() != std::static_pointer_cast(*it)->resource()->id()) - { - return false; - } - - // Also, all model entities must have the same dimension - if (dimension != topology->m_elements.at(it->id()).m_dimension) - { - return false; - } - } - - return true; -} - -Merge::Result Merge::operateInternal() -{ - // Access the associated model entities - auto associations = this->parameters()->associations(); - - // Access the model resource associated with all of the input model entities - smtk::session::mesh::Resource::Ptr resource = - std::static_pointer_cast( - associations->valueAs()->resource()); - - // Access the model resource's associated mesh resource - smtk::mesh::Resource::Ptr meshResource = resource->resource(); - - // Access the model resource's associated topology - smtk::session::mesh::Topology* topology = resource->session()->topology(resource); - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - smtk::attribute::ComponentItem::Ptr created = result->findComponent("created"); - smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); - smtk::attribute::ComponentItem::Ptr expunged = result->findComponent("expunged"); - - // Create a new id for the merged entity. - smtk::common::UUID id = resource->unusedUUID(); - - smtk::mesh::HandleRange cells; - std::set parents; - std::set children; - int dimension = -1; - std::string name; - std::set toRemove; - // For each model entity to be merged... - for (auto it = associations->begin(); it != associations->end(); ++it) - { - //...access its associated topology element. - auto elementIt = topology->m_elements.find(it->id()); - Topology::Element& element = elementIt->second; - - // If This is our first model entity... - if (dimension == -1) - { - //...assign the dimension and parent elements. - dimension = element.m_dimension; - parents.insert(element.m_parents.begin(), element.m_parents.end()); - } - else - { - // Otherwise, assign parent elements as the intersection of the current - // parent list and the parents of the current topology element. - std::set intersection; - std::set_intersection( - parents.begin(), - parents.end(), - element.m_parents.begin(), - element.m_parents.end(), - std::inserter(intersection, intersection.begin())); - parents = std::move(intersection); - } - - // Aggregate the cells that comprise the element. - cells += element.m_mesh.cells().range(); - - // Aggregate the element's children. - children.insert(element.m_children.begin(), element.m_children.end()); - - // Access the entity ref associated wit hthe current model entity... - smtk::model::EntityRef eRef(resource, it->id()); - - //...and remove relations to higher- and lower-dimensional entities. - for (auto parentId = element.m_parents.begin(); parentId != element.m_parents.end(); ++parentId) - { - auto parentElementIt = topology->m_elements.find(*parentId); - Topology::Element& parentElement = parentElementIt->second; - parentElement.m_children.erase(it->id()); - parentElement.m_children.insert(id); - - smtk::model::EntityRef parentEntityRef(resource, *parentId); - parentEntityRef.elideRawRelation(eRef); - eRef.elideRawRelation(parentEntityRef); - - modified->appendValue(parentEntityRef.component()); - } - for (auto childId = element.m_children.begin(); childId != element.m_children.end(); ++childId) - { - auto childElementIt = topology->m_elements.find(*childId); - Topology::Element& childElement = childElementIt->second; - childElement.m_parents.erase(it->id()); - childElement.m_parents.insert(id); - - smtk::model::EntityRef childEntityRef(resource, *childId); - childEntityRef.elideRawRelation(eRef); - eRef.elideRawRelation(childEntityRef); - - modified->appendValue(childEntityRef.component()); - } - - // Construct a name for the resulting entity. - if (associations->numberOfValues() <= DescriptionAppendLimit) - { - if (!name.empty()) - { - name += " & "; - } - name += eRef.name(); - } - else - { - if (name.empty()) - { - name = std::to_string(associations->numberOfValues()) + " entities"; - } - } - - // Add the model entity to the list of expunged components. - expunged->appendValue(std::static_pointer_cast(*it)); - - // Remove the model entity from the model resource. - resource->erase(eRef); - - // Remove the underlying meshset. - toRemove.insert(element.m_mesh); - - // Finally, remove the topology element. - topology->m_elements.erase(elementIt); - } - - smtk::model::EntityRef entityRef(resource, id); - entityRef.setName(name); - - smtk::mesh::MeshSet mergedMesh = - meshResource->createMesh(smtk::mesh::CellSet(meshResource, cells)); - - // Associate the merged mesh with the merged model entity. - mergedMesh.setModelEntityId(id); - - // Now that the new mesh is created, we can delete the old meshes without - // losing the cell and point information. - for (const auto& mesh : toRemove) - { - meshResource->removeMeshes(mesh); - } - - Topology::Element* element = - &topology->m_elements.insert(std::make_pair(id, Topology::Element(mergedMesh, id, dimension))) - .first->second; - // If there are no common parents for the merged element, assign the - // encompassing model as its parent. - if (parents.empty()) - { - parents.insert(topology->m_modelId); - } - element->m_parents.insert(parents.begin(), parents.end()); - element->m_children.insert(children.begin(), children.end()); - - // Declare the model as "dangling" so it will be transcribed. - resource->session()->declareDanglingEntity(entityRef); - - for (const auto& parentId : element->m_parents) - { - smtk::model::EntityRef parentEntityRef(resource, parentId); - resource->session()->declareDanglingEntity(parentEntityRef); - resource->session()->transcribe(parentEntityRef, smtk::model::SESSION_ENTITY_RELATIONS, false); - } - - // If we don't call "transcribe" ourselves, it never gets called. - resource->session()->transcribe(entityRef, smtk::model::SESSION_EVERYTHING, false); - - created->appendValue(entityRef.component()); - - return result; -} - -const char* Merge::xmlDescription() const -{ - return Merge_xml; -} - -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/operators/Merge.h b/smtk/session/mesh/operators/Merge.h deleted file mode 100644 index 9db0238eca145ae7c22560b8b414ddf1b8c27130..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Merge.h +++ /dev/null @@ -1,44 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_Merge_h -#define smtk_session_mesh_Merge_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief Merge entities from the same model and of like dimension into a single - entity. - */ -class SMTKMESHSESSION_EXPORT Merge : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::session::mesh::Merge); - smtkCreateMacro(Merge); - smtkSharedFromThisMacro(smtk::operation::Operation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/operators/Merge.sbt b/smtk/session/mesh/operators/Merge.sbt deleted file mode 100644 index 00cc57bd7c41e8240e389be109201feeee718a60..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Merge.sbt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - Merge entities from the same model and of like dimension into a single entity. - - - - - - - - - - diff --git a/smtk/session/mesh/operators/Print.cxx b/smtk/session/mesh/operators/Print.cxx deleted file mode 100644 index 4e844b59cfa050947b5f142a53cf6a45d68c69b4..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Print.cxx +++ /dev/null @@ -1,99 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/session/mesh/operators/Print.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/Session.h" -#include "smtk/session/mesh/Topology.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/utility/Metrics.h" - -#include "smtk/model/Face.h" -#include "smtk/model/Model.h" - -#include "smtk/resource/Component.h" -#include "smtk/resource/Resource.h" - -#include "smtk/session/mesh/operators/Print_xml.h" - -using namespace smtk::model; -using namespace smtk::common; - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -Print::Result Print::operateInternal() -{ - // Access the associated model entities - auto associations = this->parameters()->associations(); - - // Access the model resource associated with all of the input model entities - smtk::session::mesh::Resource::Ptr resource = - std::static_pointer_cast( - associations->valueAs()->resource()); - - // Access the model resource's associated mesh resource - smtk::mesh::Resource::Ptr meshResource = resource->resource(); - - // Access the model resource's associated topology - smtk::session::mesh::Topology* topology = resource->session()->topology(resource); - - // For each model entity to be printed... - for (auto it = associations->begin(); it != associations->end(); ++it) - { - //...access its associated topology element. - auto elementIt = topology->m_elements.find(it->id()); - Topology::Element& element = elementIt->second; - - smtk::mesh::MeshSet meshset = element.m_mesh; - - smtkInfoMacro( - this->log(), - "Model Entity <" << it->id() << ">\n" - << " name: " << it->name() - << "\n" - " # meshes: " - << meshset.size() - << "\n" - " # cells: " - << meshset.cells().size() - << "\n" - " # points: " - << meshset.points().size() - << "\n" - " # domains: " - << meshset.domains().size() - << "\n" - " # dirichlets: " - << meshset.dirichlets().size() - << "\n" - " # neumanns: " - << meshset.neumanns().size()); - } - - return this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - ; -} - -const char* Print::xmlDescription() const -{ - return Print_xml; -} -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/operators/Print.h b/smtk/session/mesh/operators/Print.h deleted file mode 100644 index 327107f63402c60030de906c7b7672c53b8ae858..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Print.h +++ /dev/null @@ -1,41 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_Print_h -#define smtk_session_mesh_Print_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief Print the underlying data of a mesh session entity. - */ -class SMTKMESHSESSION_EXPORT Print : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::session::mesh::Print); - smtkCreateMacro(Print); - smtkSharedFromThisMacro(smtk::operation::Operation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/operators/Print.sbt b/smtk/session/mesh/operators/Print.sbt deleted file mode 100644 index e4f8f272a2343c150c7bafb5ec10c7837c9769c0..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Print.sbt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - Print the underlying data of a mesh session entity. - - - - - - - - - - diff --git a/smtk/session/mesh/operators/Read.cxx b/smtk/session/mesh/operators/Read.cxx deleted file mode 100644 index bd41d7d9eb1be0ca774f478e4f8dcc9a858772dc..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Read.cxx +++ /dev/null @@ -1,165 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/session/mesh/operators/Read.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/common/Archive.h" -#include "smtk/common/CompilerInformation.h" - -#include "smtk/model/json/jsonResource.h" - -#include "smtk/session/mesh/Resource.h" - -#include "smtk/session/mesh/operators/Import.h" -#include "smtk/session/mesh/operators/Read_xml.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "nlohmann/json.hpp" -SMTK_THIRDPARTY_POST_INCLUDE - -#include - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -Read::Result Read::operateInternal() -{ - std::string filename = this->parameters()->findFile("filename")->value(); - - std::ifstream file; - - smtk::common::Archive archive(filename); - if (!archive.contents().empty()) - { - std::string smtkFilename = "index.json"; - - archive.get(smtkFilename, file); - } - else - { - file.open(filename); - } - - if (!file.good()) - { - smtkErrorMacro(log(), "Cannot read file \"" << filename << "\"."); - file.close(); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - nlohmann::json j; - try - { - j = nlohmann::json::parse(file); - } - catch (...) - { - smtkErrorMacro(log(), "Cannot parse file \"" << filename << "\"."); - file.close(); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - file.close(); - - // Access the resource's id - std::string resourceIdStr = j.at("id"); - smtk::common::UUID resourceId(resourceIdStr); - - // Create a new resource for the import - auto resource = smtk::session::mesh::Resource::create(); - resource->setId(resourceId); - auto session = smtk::session::mesh::Session::create(); - resource->setLocation(filename); - resource->setSession(session); - - // Transcribe model data onto the resource - auto modelResource = std::static_pointer_cast(resource); - smtk::model::from_json(j, modelResource); - - std::string meshFilename = j.at("Mesh URL"); - - if (!archive.contents().empty()) - { - meshFilename = archive.location(meshFilename); - } - - // Create an import operator - smtk::session::mesh::Import::Ptr importOp = smtk::session::mesh::Import::create(); - importOp->callFromRead = true; - importOp->parameters()->associate(resource); - importOp->parameters()->findString("session only")->setDiscreteIndex(0); - importOp->parameters()->findFile("filename")->setValue(meshFilename); - importOp->parameters()->findVoid("construct hierarchy")->setIsEnabled(false); - - // Execute the operation - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - // Retrieve the resulting resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - { - smtk::attribute::ResourceItem::Ptr created = result->findResource("resourcesCreated"); - created->appendValue(resourceItem->value()); - } - - return result; -} - -const char* Read::xmlDescription() const -{ - return Read_xml; -} - -void Read::markModifiedResources(Read::Result& res) -{ - auto resourceItem = res->findResource("resourcesCreated"); - for (std::size_t ii = 0; ii < resourceItem->numberOfValues(); ++ii) - { - if (resourceItem->isSet(ii)) - { - auto resource = std::dynamic_pointer_cast(resourceItem->value(ii)); - - // Set the resource as unmodified from its persistent (i.e. on-disk) state - resource->setClean(true); - } - } -} - -smtk::resource::ResourcePtr read( - const std::string& filename, - const std::shared_ptr& managers) -{ - Read::Ptr read = Read::create(); - read->setManagers(managers); - read->parameters()->findFile("filename")->setValue(filename); - Read::Result result = read->operate(); - if (result->findInt("outcome")->value() != static_cast(Read::Outcome::SUCCEEDED)) - { - return smtk::resource::ResourcePtr(); - } - return result->findResource("resourcesCreated")->value(); -} -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/operators/Read.h b/smtk/session/mesh/operators/Read.h deleted file mode 100644 index 13ae63439119c8d910ac37099c3da8d0d04e185e..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Read.h +++ /dev/null @@ -1,55 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_session_mesh_Read_h -#define smtk_session_mesh_Read_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief Read an smtk mesh model file. - * - * Here and throughout SMTK, we use the terms read/write to describe - * serialization of native SMTK files, while the terms import/export describe - * transcription from/to a different format. Currently, the mesh session's - * model file is a .smtk json file that describes model relationships and - * contains the url to the mesh file. The read operation is therefore a veneer - * around the import operation; it simply opens the .smtk file, accesses the url - * of the mesh and imports it. - */ -class SMTKMESHSESSION_EXPORT Read : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::session::mesh::Read); - smtkCreateMacro(Read); - smtkSharedFromThisMacro(smtk::operation::Operation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; - void markModifiedResources(Result&) override; -}; - -SMTKMESHSESSION_EXPORT smtk::resource::ResourcePtr read( - const std::string&, - const std::shared_ptr&); -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/operators/Read.sbt b/smtk/session/mesh/operators/Read.sbt deleted file mode 100644 index 9dc410e6b7349c55d3eb99b15060c33a600bf079..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Read.sbt +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/smtk/session/mesh/operators/Transform.cxx b/smtk/session/mesh/operators/Transform.cxx deleted file mode 100644 index 1efca253a237acb476637e6827cff1cdd4113f6f..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Transform.cxx +++ /dev/null @@ -1,133 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/session/mesh/operators/Transform.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/Session.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/DoubleItem.h" - -#include "smtk/common/CompilerInformation.h" - -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/operators/Transform.h" - -#include "smtk/model/Model.h" - -#include "smtk/operation/MarkGeometry.h" - -#include "smtk/session/mesh/operators/Transform_xml.h" - -using namespace smtk::model; -using namespace smtk::common; - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -Transform::Result Transform::operateInternal() -{ - // Access the associated model. - smtk::model::Model model = this->parameters()->associatedModelEntities()[0]; - if (!model.isValid()) - { - smtkErrorMacro(this->log(), "Invalid model."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - smtk::session::mesh::Resource::Ptr resource = - std::static_pointer_cast(model.component()->resource()); - smtk::session::mesh::Session::Ptr session = resource->session(); - - // Access the underlying mesh resource for the model. - smtk::mesh::ResourcePtr meshResource = resource->resource(); - if (meshResource == nullptr || !meshResource->isValid()) - { - smtkErrorMacro(this->log(), "No mesh resource associated with this model."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Access the transform values - smtk::attribute::DoubleItem::Ptr scaleItem = this->parameters()->findDouble("scale"); - smtk::attribute::DoubleItem::Ptr rotateItem = this->parameters()->findDouble("rotate"); - smtk::attribute::DoubleItem::Ptr translateItem = this->parameters()->findDouble("translate"); - - // Construct a mesh transform operation. - auto transform = smtk::mesh::Transform::create(); - - // Associate it with the model's underlying mesh. - transform->parameters()->associate(smtk::mesh::Component::create(meshResource->meshes())); - - // Access the mesh transform operation's transform values. - smtk::attribute::DoubleItem::Ptr scaleItem_ = transform->parameters()->findDouble("scale"); - smtk::attribute::DoubleItem::Ptr rotateItem_ = transform->parameters()->findDouble("rotate"); - smtk::attribute::DoubleItem::Ptr translateItem_ = - transform->parameters()->findDouble("translate"); - - // Transfer the transform values from this operation to the mesh operation. - for (std::size_t i = 0; i < 3; ++i) - { - scaleItem_->setValue(i, scaleItem->value(i)); - rotateItem_->setValue(i, rotateItem->value(i)); - translateItem_->setValue(i, translateItem->value(i)); - } - - // Execute the transform. - transform->operate(this->childKey()); - - // Access the attribute associated with the modified meshes. - Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - - // Access the attribute associated with the modified model. - smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); - - // Assign the model as modified. - modified->appendValue(model.component()); - - // Construct a MarkGeometry instance. - smtk::operation::MarkGeometry markGeometry(resource); - - // Access the model resource's associated topology. - smtk::session::mesh::Topology* topology = resource->session()->topology(resource); - - std::function mark; - - mark = [&](const smtk::common::UUID& id) { - markGeometry.markModified(resource->find(id)); - auto elementIt = topology->m_elements.find(id); - if (elementIt == topology->m_elements.end()) - { - return; - } - Topology::Element& element = elementIt->second; - - for (const smtk::common::UUID& childId : element.m_children) - { - mark(childId); - } - }; - - mark(model.entity()); - - return result; -} - -const char* Transform::xmlDescription() const -{ - return Transform_xml; -} -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/operators/Transform.h b/smtk/session/mesh/operators/Transform.h deleted file mode 100644 index bfc2684bacc530db8bd09110faa7751deeec8f87..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Transform.h +++ /dev/null @@ -1,41 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_Transform_h -#define smtk_session_mesh_Transform_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief Transform a model. - */ -class SMTKMESHSESSION_EXPORT Transform : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::session::mesh::Transform); - smtkCreateMacro(Transform); - smtkSharedFromThisMacro(smtk::operation::Operation); - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/operators/Transform.sbt b/smtk/session/mesh/operators/Transform.sbt deleted file mode 100644 index 048e70d313c1aa74eceb5af62ece10559c1d49d9..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Transform.sbt +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - Scale model? If so, specify a scale factor for each axis. - - - Enabling this item allows you to specify a scale factor per axis for the - model. - Scaling is performed about the origin before rotation and translation. - - 1, 1, 1 - - - - Rotate model? If so, specify angles about each axis in degrees. - - - Enabling this item allows you to specify angles (in degrees) about which to rotate - the model. Angles are specified about the origin and rotation is applied - before translation. - - 0, 0, 0 - - - Translate model? If so, specify a vector. - - Enabling this item allows you to specify a vector to add to each original point - of the model. - Translation is applied after scaling and rotation; - therefore the vector is not modified by the specifed scaling and rotation (if any). - - 0, 0, 0 - - - - - - - - - - - - - - - - - - - - - - diff --git a/smtk/session/mesh/operators/Write.cxx b/smtk/session/mesh/operators/Write.cxx deleted file mode 100644 index a13d2d30741f1c39c9e29d63042b7f2e666873bb..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Write.cxx +++ /dev/null @@ -1,241 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/session/mesh/operators/Write.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/common/Archive.h" -#include "smtk/common/CompilerInformation.h" -#include "smtk/common/Paths.h" - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Export.h" -#include "smtk/session/mesh/operators/Write_xml.h" - -#include "smtk/model/json/jsonResource.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include "nlohmann/json.hpp" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -SMTK_THIRDPARTY_POST_INCLUDE - -#include - -using namespace smtk::model; - -namespace smtk -{ -namespace session -{ - -namespace mesh -{ - -bool Write::ableToOperate() -{ - if (!this->smtk::operation::XMLOperation::ableToOperate()) - { - return false; - } - - if (this->parameters()->associations()->numberOfValues() < 1) - { - return false; - } - - return true; -} - -Write::Result Write::operateInternal() -{ - auto resourceItem = this->parameters()->associations(); - - smtk::session::mesh::Resource::Ptr resource = - std::dynamic_pointer_cast(resourceItem->value()); - - // Serialize resource into a set of JSON records: - nlohmann::json j = resource; - if (j.is_null()) - { - smtkErrorMacro(log(), "Unable to serialize model to json object."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Check if the mesh files are to be archived into a single file - auto archive = this->parameters()->findVoid("archive"); - if (archive && archive->isEnabled()) - { - boost::filesystem::path smtkFilename("index.json"); - boost::filesystem::path meshFilename("mesh.h5m"); - - boost::filesystem::path temp = - boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); - if (!boost::filesystem::create_directories(temp)) - { - smtkErrorMacro(this->log(), "Failed to create a temporary directory."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - boost::filesystem::path tmpsmtkPath = temp / smtkFilename; - boost::filesystem::path tmpMeshPath = temp / meshFilename; - - j["Mesh URL"] = meshFilename.string(); - - // Write the smtk index - { - std::ofstream file(tmpsmtkPath.string()); - if (!file.good()) - { - smtkErrorMacro(log(), "Unable to open \"" << tmpsmtkPath << "\" for writing."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - file << j.dump(2); - file.close(); - } - - // Write the mesh file - { - // Create a write operator - smtk::session::mesh::Export::Ptr exportOp = smtk::session::mesh::Export::create(); - exportOp->parameters()->findFile("filename")->setValue(tmpMeshPath.string()); - - // Set the entity association - exportOp->parameters()->associate(resource); - - // Execute the operation - smtk::operation::Operation::Result exportOpResult = exportOp->operate(this->childKey()); - - // Test for success - if ( - exportOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - smtkErrorMacro(log(), "Unable to write mesh to \"" << tmpMeshPath << "\"."); - ::boost::filesystem::remove_all(temp); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - - // Populate an archive with the smtk index and mesh file - { - smtk::common::Archive archive(resource->location()); - archive.insert(tmpsmtkPath.string(), smtkFilename.string()); - archive.insert(tmpMeshPath.string(), meshFilename.string()); - if (!archive.archive()) - { - smtkErrorMacro(log(), "Unable to archive files to \"" + resource->location() + "\"."); - ::boost::filesystem::remove_all(temp); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - } - - // Clean up temporary files. - { - ::boost::filesystem::remove_all(temp); - } - - return this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - } - else - { - // Serialize resource into a set of JSON records: - nlohmann::json j = resource; - if (j.is_null()) - { - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - std::string meshFilename = resource->resource()->location(); - - if (meshFilename.empty()) - { - meshFilename = smtk::common::Paths::directory(resource->location()) + "/" + - smtk::common::Paths::stem(resource->location()) + ".h5m"; - } - - j["Mesh URL"] = meshFilename; - - { - std::ofstream file(resource->location()); - if (!file.good()) - { - smtkErrorMacro(log(), "Unable to open \"" << resource->location() << "\" for writing."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - file << j.dump(2); - file.close(); - } - - // Create an export operator - smtk::session::mesh::Export::Ptr exportOp = smtk::session::mesh::Export::create(); - exportOp->parameters()->findFile("filename")->setValue(meshFilename); - - // Set the entity association - exportOp->parameters()->associate(resource); - - // Execute the operation - smtk::operation::Operation::Result exportOpResult = exportOp->operate(this->childKey()); - - // Test for success - if ( - exportOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - smtkErrorMacro(log(), "Unable to write files to \"" + meshFilename + "\"."); - return this->createResult(smtk::operation::Operation::Outcome::FAILED); - } - - // Add the mesh file to the result's list of additional files - auto result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - result->findFile("additional files")->appendValue(meshFilename); - - return result; - } -} - -const char* Write::xmlDescription() const -{ - return Write_xml; -} - -void Write::markModifiedResources(Write::Result& /*unused*/) -{ - auto resourceItem = this->parameters()->associations(); - for (auto rit = resourceItem->begin(); rit != resourceItem->end(); ++rit) - { - auto resource = std::dynamic_pointer_cast(*rit); - - // Set the resource as unmodified from its persistent (i.e. on-disk) state - resource->setClean(true); - } -} - -bool write( - const smtk::resource::ResourcePtr& resource, - const std::shared_ptr& managers) -{ - Write::Ptr write = Write::create(); - write->setManagers(managers); - write->parameters()->associate(resource); - Write::Result result = write->operate(); - return (result->findInt("outcome")->value() == static_cast(Write::Outcome::SUCCEEDED)); -} - -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/operators/Write.h b/smtk/session/mesh/operators/Write.h deleted file mode 100644 index cc255ccb527024bdb83469e221227271742b6de4..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Write.h +++ /dev/null @@ -1,49 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_session_mesh_Write_h -#define smtk_session_mesh_Write_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/operation/XMLOperation.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief Write an smtk mesh model file. - */ -class SMTKMESHSESSION_EXPORT Write : public smtk::operation::XMLOperation -{ -public: - smtkTypeMacro(smtk::session::mesh::Write); - smtkCreateMacro(Write); - smtkSharedFromThisMacro(smtk::operation::Operation); - - bool ableToOperate() override; - -protected: - Result operateInternal() override; - const char* xmlDescription() const override; - void markModifiedResources(Result&) override; -}; - -SMTKMESHSESSION_EXPORT bool write( - const smtk::resource::ResourcePtr&, - const std::shared_ptr&); -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/operators/Write.sbt b/smtk/session/mesh/operators/Write.sbt deleted file mode 100644 index 9cee4a7f351f1bcad41da19d5cbf55b240f8b375..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/operators/Write.sbt +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - Archive all related files into a single archive. - - - - - - - - - - - - - - - diff --git a/smtk/session/mesh/plugin/CMakeLists.txt b/smtk/session/mesh/plugin/CMakeLists.txt deleted file mode 100644 index 67ad0f0d1a12a878e865b7472c3cc0321b57b353..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/plugin/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -smtk_add_plugin(smtkMeshSessionPlugin - REGISTRAR smtk::session::mesh::Registrar - MANAGERS smtk::operation::Manager smtk::resource::Manager smtk::geometry::Manager - PARAVIEW_PLUGIN_ARGS - VERSION 1.0) -target_link_libraries(smtkMeshSessionPlugin - PRIVATE - smtkMeshSession) diff --git a/smtk/session/mesh/plugin/paraview.plugin b/smtk/session/mesh/plugin/paraview.plugin deleted file mode 100644 index f45319fffc16c4c5a8c1ecfbb546bbc879f01fd9..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/plugin/paraview.plugin +++ /dev/null @@ -1,4 +0,0 @@ -NAME - smtkMeshSessionPlugin -DESCRIPTION - SMTK mesh session for ParaView diff --git a/smtk/session/mesh/pybind11/CMakeLists.txt b/smtk/session/mesh/pybind11/CMakeLists.txt deleted file mode 100644 index 57aef8add36df050b0fb2dae4ca745556a698aaa..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set(library_name "_smtkPybindMeshSession") -set(module_path "session/mesh") -set(build_path "${CMAKE_BINARY_DIR}/${SMTK_PYTHON_MODULEDIR}/smtk/${module_path}") -set(install_path "${SMTK_PYTHON_MODULEDIR}/smtk/${module_path}") - -pybind11_add_module(${library_name} PybindMeshSession.cxx) -target_include_directories(${library_name} PUBLIC - $ - ) -target_link_libraries(${library_name} LINK_PUBLIC smtkCore smtkMeshSession) -set_target_properties(${library_name} - PROPERTIES - CXX_VISIBILITY_PRESET hidden - COMPILE_FLAGS ${SMTK_PYBIND11_FLAGS} - LIBRARY_OUTPUT_DIRECTORY "${build_path}" - ) - -# Install library -install(TARGETS ${library_name} DESTINATION "${install_path}") - -# Create and install module __init__.py -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in" - "${build_path}/__init__.py" @ONLY - ) - -install( - FILES "${build_path}/__init__.py" - DESTINATION "${install_path}" - ) diff --git a/smtk/session/mesh/pybind11/PybindCreateUniformGrid.h b/smtk/session/mesh/pybind11/PybindCreateUniformGrid.h deleted file mode 100644 index 22da73495a7d38a44e8341ba3c77a721532c0021..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindCreateUniformGrid.h +++ /dev/null @@ -1,35 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_session_mesh_operators_CreateUniformGrid_h -#define pybind_smtk_session_mesh_operators_CreateUniformGrid_h - -#include - -#include "smtk/session/mesh/operators/CreateUniformGrid.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::session::mesh::CreateUniformGrid, smtk::operation::XMLOperation > pybind11_init_smtk_session_mesh_CreateUniformGrid(py::module &m) -{ - PySharedPtrClass< smtk::session::mesh::CreateUniformGrid, smtk::operation::XMLOperation > instance(m, "CreateUniformGrid"); - instance - .def(py::init<>()) - .def_static("create", (std::shared_ptr (*)()) &smtk::session::mesh::CreateUniformGrid::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::session::mesh::CreateUniformGrid::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::CreateUniformGrid::*)()) &smtk::session::mesh::CreateUniformGrid::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::CreateUniformGrid::*)() const) &smtk::session::mesh::CreateUniformGrid::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/session/mesh/pybind11/PybindEulerCharacteristicRatio.h b/smtk/session/mesh/pybind11/PybindEulerCharacteristicRatio.h deleted file mode 100644 index c50a531de1fba9f407058b85211c580df3922153..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindEulerCharacteristicRatio.h +++ /dev/null @@ -1,35 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_session_mesh_operators_EulerCharacteristicRatio_h -#define pybind_smtk_session_mesh_operators_EulerCharacteristicRatio_h - -#include - -#include "smtk/session/mesh/operators/EulerCharacteristicRatio.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::session::mesh::EulerCharacteristicRatio, smtk::operation::XMLOperation > pybind11_init_smtk_session_mesh_EulerCharacteristicRatio(py::module &m) -{ - PySharedPtrClass< smtk::session::mesh::EulerCharacteristicRatio, smtk::operation::XMLOperation > instance(m, "EulerCharacteristicRatio"); - instance - .def(py::init<>()) - .def_static("create", (std::shared_ptr (*)()) &smtk::session::mesh::EulerCharacteristicRatio::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::session::mesh::EulerCharacteristicRatio::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::EulerCharacteristicRatio::*)()) &smtk::session::mesh::EulerCharacteristicRatio::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::EulerCharacteristicRatio::*)() const) &smtk::session::mesh::EulerCharacteristicRatio::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/session/mesh/pybind11/PybindExport.h b/smtk/session/mesh/pybind11/PybindExport.h deleted file mode 100644 index a842082da32157bd52370221bb5397e9697b23e9..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindExport.h +++ /dev/null @@ -1,35 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_session_mesh_operators_Export_h -#define pybind_smtk_session_mesh_operators_Export_h - -#include - -#include "smtk/session/mesh/operators/Export.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::session::mesh::Export, smtk::operation::XMLOperation > pybind11_init_smtk_session_mesh_Export(py::module &m) -{ - PySharedPtrClass< smtk::session::mesh::Export, smtk::operation::XMLOperation > instance(m, "Export"); - instance - .def(py::init<>()) - .def_static("create", (std::shared_ptr (*)()) &smtk::session::mesh::Export::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::session::mesh::Export::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::Export::*)()) &smtk::session::mesh::Export::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::Export::*)() const) &smtk::session::mesh::Export::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/session/mesh/pybind11/PybindImport.h b/smtk/session/mesh/pybind11/PybindImport.h deleted file mode 100644 index 7c737a9a5491803b028234f6cf0163a0900324c3..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindImport.h +++ /dev/null @@ -1,35 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_session_mesh_operators_Import_h -#define pybind_smtk_session_mesh_operators_Import_h - -#include - -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/operation/XMLOperation.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::session::mesh::Import, smtk::operation::XMLOperation > pybind11_init_smtk_session_mesh_Import(py::module &m) -{ - PySharedPtrClass< smtk::session::mesh::Import, smtk::operation::XMLOperation > instance(m, "Import"); - instance - .def(py::init<>()) - .def_static("create", (std::shared_ptr (*)()) &smtk::session::mesh::Import::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::session::mesh::Import::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::Import::*)()) &smtk::session::mesh::Import::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::Import::*)() const) &smtk::session::mesh::Import::shared_from_this) - ; - return instance; -} - -#endif diff --git a/smtk/session/mesh/pybind11/PybindMeshSession.cxx b/smtk/session/mesh/pybind11/PybindMeshSession.cxx deleted file mode 100644 index 6c9f67de0cb2224ca4ec22f912ae3d56f6a3e4a6..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindMeshSession.cxx +++ /dev/null @@ -1,62 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/common/CompilerInformation.h" - -SMTK_THIRDPARTY_PRE_INCLUDE -#include -SMTK_THIRDPARTY_POST_INCLUDE - -#include - -namespace py = pybind11; - -template -using PySharedPtrClass = py::class_, Args...>; - -#include "PybindResource.h" -#include "PybindSession.h" -#include "PybindTopology.h" - -#include "PybindCreateUniformGrid.h" -#include "PybindImport.h" -#include "PybindExport.h" -#include "PybindRead.h" -#include "PybindEulerCharacteristicRatio.h" -#include "PybindWrite.h" - -#include "PybindRegistrar.h" - -#include "smtk/model/Session.h" - -PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); - -PYBIND11_MODULE(_smtkPybindMeshSession, mesh) -{ - mesh.doc() = ""; - - py::module::import("smtk.operation"); - py::module::import("smtk.model"); - - // The order of these function calls is important! It was determined by - // comparing the dependencies of each of the wrapped objects. - py::class_< smtk::session::mesh::Topology > smtk_session_mesh_Topology = pybind11_init_smtk_session_mesh_Topology(mesh); - PySharedPtrClass< smtk::session::mesh::Session, smtk::model::Session > smtk_session_mesh_Session = pybind11_init_smtk_session_mesh_Session(mesh); - PySharedPtrClass< smtk::session::mesh::Resource> smtk_session_mesh_Resource = pybind11_init_smtk_session_mesh_Resource(mesh); - - PySharedPtrClass< smtk::session::mesh::CreateUniformGrid, smtk::operation::XMLOperation > smtk_session_mesh_CreateUniformGrid = pybind11_init_smtk_session_mesh_CreateUniformGrid(mesh); - PySharedPtrClass< smtk::session::mesh::EulerCharacteristicRatio, smtk::operation::XMLOperation > smtk_session_mesh_EulerCharacteristicRatio = pybind11_init_smtk_session_mesh_EulerCharacteristicRatio(mesh); - PySharedPtrClass< smtk::session::mesh::Import, smtk::operation::XMLOperation > smtk_session_mesh_Import = pybind11_init_smtk_session_mesh_Import(mesh); - PySharedPtrClass< smtk::session::mesh::Export, smtk::operation::XMLOperation > smtk_session_mesh_Export = pybind11_init_smtk_session_mesh_Export(mesh); - PySharedPtrClass< smtk::session::mesh::Read, smtk::operation::XMLOperation > smtk_session_mesh_Read = pybind11_init_smtk_session_mesh_Read(mesh); - PySharedPtrClass< smtk::session::mesh::Write, smtk::operation::XMLOperation > smtk_session_mesh_Write = pybind11_init_smtk_session_mesh_Write(mesh); - - py::class_< smtk::session::mesh::Registrar > smtk_session_mesh_Registrar = pybind11_init_smtk_session_mesh_Registrar(mesh); -} diff --git a/smtk/session/mesh/pybind11/PybindRead.h b/smtk/session/mesh/pybind11/PybindRead.h deleted file mode 100644 index 6746242067299c343f49fa44ab689b36e5e87f25..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindRead.h +++ /dev/null @@ -1,40 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_session_mesh_operators_Read_h -#define pybind_smtk_session_mesh_operators_Read_h - -#include - -#include "smtk/session/mesh/operators/Read.h" - -#include "smtk/operation/XMLOperation.h" - -#include "smtk/common/Managers.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::session::mesh::Read, smtk::operation::XMLOperation > pybind11_init_smtk_session_mesh_Read(py::module &m) -{ - PySharedPtrClass< smtk::session::mesh::Read, smtk::operation::XMLOperation > instance(m, "Read"); - instance - .def(py::init<>()) - .def_static("create", (std::shared_ptr (*)()) &smtk::session::mesh::Read::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::session::mesh::Read::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::Read::*)()) &smtk::session::mesh::Read::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::Read::*)() const) &smtk::session::mesh::Read::shared_from_this) - ; - - m.def("read", (smtk::resource::ResourcePtr (*)(::std::string const &, const std::shared_ptr&)) &smtk::session::mesh::read, "", py::arg("filePath"), py::arg("managers") = nullptr); - - return instance; -} - -#endif diff --git a/smtk/session/mesh/pybind11/PybindRegistrar.h b/smtk/session/mesh/pybind11/PybindRegistrar.h deleted file mode 100644 index 67b7d76ad40cb13d76a9a7c8e7ca3d2e3a8641ce..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindRegistrar.h +++ /dev/null @@ -1,33 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_session_mesh_Registrar_h -#define pybind_smtk_session_mesh_Registrar_h - -#include - -#include "smtk/session/mesh/Registrar.h" - -namespace py = pybind11; - -inline py::class_< smtk::session::mesh::Registrar > pybind11_init_smtk_session_mesh_Registrar(py::module &m) -{ - py::class_< smtk::session::mesh::Registrar > instance(m, "Registrar"); - instance - .def(py::init<>()) - .def_static("registerTo", (void (*)(std::shared_ptr<::smtk::resource::Manager> const &)) &smtk::session::mesh::Registrar::registerTo) - .def_static("unregisterFrom", (void (*)(std::shared_ptr<::smtk::resource::Manager> const &)) &smtk::session::mesh::Registrar::unregisterFrom) - .def_static("registerTo", (void (*)(std::shared_ptr<::smtk::operation::Manager> const &)) &smtk::session::mesh::Registrar::registerTo) - .def_static("unregisterFrom", (void (*)(std::shared_ptr<::smtk::operation::Manager> const &)) &smtk::session::mesh::Registrar::unregisterFrom) - ; - return instance; -} - -#endif diff --git a/smtk/session/mesh/pybind11/PybindResource.h b/smtk/session/mesh/pybind11/PybindResource.h deleted file mode 100644 index d329794efe07703cfecfbef1c4c55cf36d20ebc5..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindResource.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_session_mesh_Resource_h -#define pybind_smtk_session_mesh_Resource_h - -#include - -#include "smtk/session/mesh/Resource.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::session::mesh::Resource> pybind11_init_smtk_session_mesh_Resource(py::module &m) -{ - PySharedPtrClass< smtk::session::mesh::Resource, smtk::model::Resource > instance(m, "Resource"); - instance - .def_static("create", (std::shared_ptr (*)()) &smtk::session::mesh::Resource::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::session::mesh::Resource::create, py::arg("ref")) - .def("session", &smtk::session::mesh::Resource::session) - .def("setSession", &smtk::session::mesh::Resource::setSession) - .def("resource", &smtk::session::mesh::Resource::resource) - .def_static("CastTo", [](const std::shared_ptr i) { - return std::dynamic_pointer_cast(i); - }) - ; - return instance; -} - -#endif diff --git a/smtk/session/mesh/pybind11/PybindSession.h b/smtk/session/mesh/pybind11/PybindSession.h deleted file mode 100644 index be97602615801b89c96fa89dd77794a6d6c2e5c4..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindSession.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_session_mesh_Session_h -#define pybind_smtk_session_mesh_Session_h - -#include - -#include "smtk/session/mesh/Session.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::session::mesh::Session, smtk::model::Session > pybind11_init_smtk_session_mesh_Session(py::module &m) -{ - PySharedPtrClass< smtk::session::mesh::Session, smtk::model::Session > instance(m, "Session"); - instance - .def(py::init<::smtk::session::mesh::Session const &>()) - .def("deepcopy", (smtk::session::mesh::Session & (smtk::session::mesh::Session::*)(::smtk::session::mesh::Session const &)) &smtk::session::mesh::Session::operator=) - .def("addTopology", (void (smtk::session::mesh::Session::*)(smtk::session::mesh::Topology)) &smtk::session::mesh::Session::addTopology, py::arg("t")) - .def("addTopology", (void (smtk::session::mesh::Session::*)(const std::shared_ptr&, smtk::session::mesh::Topology)) &smtk::session::mesh::Session::addTopology, py::arg("modelResource"), py::arg("t")) - .def_static("create", (std::shared_ptr (*)()) &smtk::session::mesh::Session::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::session::mesh::Session::create, py::arg("ref")) - .def("topology", (smtk::session::mesh::Topology* (smtk::session::mesh::Session::*)(const std::shared_ptr<::smtk::session::mesh::Resource>&)) &smtk::session::mesh::Session::topology, py::return_value_policy::reference) - .def("topology", (smtk::session::mesh::Topology* (smtk::session::mesh::Session::*)(const std::shared_ptr&)) &smtk::session::mesh::Session::topology, py::return_value_policy::reference) - ; - return instance; -} - -#endif diff --git a/smtk/session/mesh/pybind11/PybindTopology.h b/smtk/session/mesh/pybind11/PybindTopology.h deleted file mode 100644 index 21c6f32aa30cb5d56cf5e4256bc519335c20a389..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindTopology.h +++ /dev/null @@ -1,42 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_session_mesh_Topology_h -#define pybind_smtk_session_mesh_Topology_h - -#include - -#include "smtk/common/pybind11/PybindUUIDTypeCaster.h" -#include "smtk/session/mesh/Topology.h" - -namespace py = pybind11; - -inline py::class_< smtk::session::mesh::Topology > pybind11_init_smtk_session_mesh_Topology(py::module &m) -{ - py::class_< smtk::session::mesh::Topology > instance(m, "Topology"); - instance - .def(py::init<::smtk::session::mesh::Topology const &>()) - .def(py::init<::smtk::common::UUID const, ::smtk::mesh::MeshSet const &, bool>()) - .def("deepcopy", (smtk::session::mesh::Topology & (smtk::session::mesh::Topology::*)(::smtk::session::mesh::Topology const &)) &smtk::session::mesh::Topology::operator=) - .def("resource", [](const smtk::session::mesh::Topology& topology){ return topology.m_resource; }) - ; - py::class_< smtk::session::mesh::Topology::Element >(instance, "Element") - .def(py::init<::smtk::mesh::MeshSet, smtk::common::UUID const &, int>()) - .def(py::init<::smtk::session::mesh::Topology::Element const &>()) - .def("deepcopy", (smtk::session::mesh::Topology::Element & (smtk::session::mesh::Topology::Element::*)(::smtk::session::mesh::Topology::Element const &)) &smtk::session::mesh::Topology::Element::operator=) - .def_readwrite("m_mesh", &smtk::session::mesh::Topology::Element::m_mesh) - .def_readwrite("m_dimension", &smtk::session::mesh::Topology::Element::m_dimension) - .def_readwrite("m_parents", &smtk::session::mesh::Topology::Element::m_parents) - .def_readwrite("m_children", &smtk::session::mesh::Topology::Element::m_children) - ; - return instance; -} - -#endif diff --git a/smtk/session/mesh/pybind11/PybindWrite.h b/smtk/session/mesh/pybind11/PybindWrite.h deleted file mode 100644 index 98ffebe4a3b66197001bddb89d9fe9d3de5dd71d..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/PybindWrite.h +++ /dev/null @@ -1,40 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef pybind_smtk_session_mesh_operators_Write_h -#define pybind_smtk_session_mesh_operators_Write_h - -#include - -#include "smtk/session/mesh/operators/Write.h" - -#include "smtk/operation/XMLOperation.h" - -#include "smtk/common/Managers.h" - -namespace py = pybind11; - -inline PySharedPtrClass< smtk::session::mesh::Write, smtk::operation::XMLOperation > pybind11_init_smtk_session_mesh_Write(py::module &m) -{ - PySharedPtrClass< smtk::session::mesh::Write, smtk::operation::XMLOperation > instance(m, "Write"); - instance - .def(py::init<>()) - .def_static("create", (std::shared_ptr (*)()) &smtk::session::mesh::Write::create) - .def_static("create", (std::shared_ptr (*)(::std::shared_ptr &)) &smtk::session::mesh::Write::create, py::arg("ref")) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::Write::*)()) &smtk::session::mesh::Write::shared_from_this) - .def("shared_from_this", (std::shared_ptr (smtk::session::mesh::Write::*)() const) &smtk::session::mesh::Write::shared_from_this) - ; - - m.def("write", (bool (*)(const smtk::resource::ResourcePtr&, const std::shared_ptr&)) &smtk::session::mesh::write, "", py::arg("resource"), py::arg("managers") = nullptr); - - return instance; -} - -#endif diff --git a/smtk/session/mesh/pybind11/__init__.py.in b/smtk/session/mesh/pybind11/__init__.py.in deleted file mode 100644 index 4155daad703bb006bf0dcaae1a35183214de1bce..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/pybind11/__init__.py.in +++ /dev/null @@ -1,14 +0,0 @@ -#============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -#============================================================================= - -if @SMTK_MESH_SESSION_ENABLED@: - from ._smtkPybindMeshSession import * diff --git a/smtk/session/mesh/queries/BoundingBox.h b/smtk/session/mesh/queries/BoundingBox.h deleted file mode 100644 index 6404fb4fb9acfa0da81cd03a910d3e05f2ecb675..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/queries/BoundingBox.h +++ /dev/null @@ -1,68 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_session_mesh_BoundingBox_h -#define smtk_session_mesh_BoundingBox_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/geometry/queries/BoundingBox.h" - -#include "smtk/mesh/core/Component.h" - -#include "smtk/session/mesh/Resource.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief An API for computing the bounding box for a geometric resource - * or component. - */ -struct SMTKMESHSESSION_EXPORT BoundingBox - : public smtk::resource::query::DerivedFrom -{ - std::array operator()(const smtk::resource::PersistentObjectPtr& object) const override - { - smtk::session::mesh::Resource::Ptr resource = - std::dynamic_pointer_cast(object); - - if (resource) - { - smtk::mesh::Resource::Ptr meshResource = resource->resource(); - return meshResource->queries().get().operator()(meshResource); - } - else if (auto entity = std::dynamic_pointer_cast(object)) - { - resource = std::dynamic_pointer_cast(entity->resource()); - if (resource) - { - smtk::session::mesh::Topology* topology = resource->session()->topology(resource); - auto elementIt = topology->m_elements.find(object->id()); - - if (elementIt != topology->m_elements.end()) - { - smtk::mesh::Resource::Ptr meshResource = resource->resource(); - return meshResource->queries().get().operator()( - smtk::mesh::Component::create(elementIt->second.m_mesh)); - } - } - } - return smtk::geometry::BoundingBox::operator()(object); - } -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/queries/ClosestPoint.h b/smtk/session/mesh/queries/ClosestPoint.h deleted file mode 100644 index 25e0836828a71d68ba699b75023eeebe85a96fcc..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/queries/ClosestPoint.h +++ /dev/null @@ -1,62 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_session_mesh_ClosestPoint_h -#define smtk_session_mesh_ClosestPoint_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/geometry/queries/ClosestPoint.h" - -#include "smtk/mesh/core/Component.h" - -#include "smtk/session/mesh/Resource.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief An API for computing a the closest point on a geometric resource - * component to an input point. The returned value represents a tessellation or - * model vertex; no interpolation is performed. - */ -struct SMTKMESHSESSION_EXPORT ClosestPoint - : public smtk::resource::query::DerivedFrom -{ - std::array operator()( - const smtk::resource::Component::Ptr& component, - const std::array& sourcePoint) const override - { - if ( - auto resource = - std::dynamic_pointer_cast(component->resource())) - { - smtk::session::mesh::Topology* topology = resource->session()->topology(resource); - auto elementIt = topology->m_elements.find(component->id()); - - if (elementIt != topology->m_elements.end()) - { - smtk::mesh::Resource::Ptr meshResource = resource->resource(); - return meshResource->queries().get().operator()( - smtk::mesh::Component::create(elementIt->second.m_mesh), sourcePoint); - } - } - - return smtk::geometry::ClosestPoint::operator()(component, sourcePoint); - } -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/queries/DistanceTo.h b/smtk/session/mesh/queries/DistanceTo.h deleted file mode 100644 index 3fc1006de2d60d6526f814bbf14edc6eb71f5a50..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/queries/DistanceTo.h +++ /dev/null @@ -1,63 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_session_mesh_DistanceTo_h -#define smtk_session_mesh_DistanceTo_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/geometry/queries/DistanceTo.h" - -#include "smtk/mesh/core/Component.h" - -#include "smtk/session/mesh/Resource.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ -/**\brief An API for computing the shortest distance between an input point and - * a geometric resource component. The location of the point on the component - * is also returned. This query differs from ClosestPoint in that the returned - * point does not need to be explicitly contained within the geometric - * representation. - */ -struct SMTKMESHSESSION_EXPORT DistanceTo - : public smtk::resource::query::DerivedFrom -{ - std::pair> operator()( - const smtk::resource::Component::Ptr& component, - const std::array& sourcePoint) const override - { - if ( - auto resource = - std::dynamic_pointer_cast(component->resource())) - { - smtk::session::mesh::Topology* topology = resource->session()->topology(resource); - auto elementIt = topology->m_elements.find(component->id()); - - if (elementIt != topology->m_elements.end()) - { - smtk::mesh::Resource::Ptr meshResource = resource->resource(); - return meshResource->queries().get().operator()( - smtk::mesh::Component::create(elementIt->second.m_mesh), sourcePoint); - } - } - - return smtk::geometry::DistanceTo::operator()(component, sourcePoint); - } -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/queries/RandomPoint.h b/smtk/session/mesh/queries/RandomPoint.h deleted file mode 100644 index 477cecd174dce710d115c694b82730f8226179e2..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/queries/RandomPoint.h +++ /dev/null @@ -1,65 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef smtk_session_mesh_RandomPoint_h -#define smtk_session_mesh_RandomPoint_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/geometry/queries/RandomPoint.h" - -#include "smtk/mesh/core/Component.h" - -#include "smtk/session/mesh/Resource.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -/**\brief An API for computing a random point on a geometric resource component. - */ -struct SMTKMESHSESSION_EXPORT RandomPoint - : public smtk::resource::query::DerivedFrom -{ - RandomPoint() = default; - - std::array operator()(const smtk::resource::Component::Ptr& component) const override - { - if ( - auto resource = - std::dynamic_pointer_cast(component->resource())) - { - smtk::session::mesh::Topology* topology = resource->session()->topology(resource); - auto elementIt = topology->m_elements.find(component->id()); - - if (elementIt != topology->m_elements.end()) - { - smtk::mesh::Resource::Ptr meshResource = resource->resource(); - return meshResource->queries().get().operator()( - smtk::mesh::Component::create(elementIt->second.m_mesh)); - } - } - - return smtk::geometry::RandomPoint::operator()(component); - } - - void seed(std::size_t i) override { m_seed = i; } - -private: - std::size_t m_seed{ 0 }; -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/mesh/testing/CMakeLists.txt b/smtk/session/mesh/testing/CMakeLists.txt deleted file mode 100644 index 40b119e490118a6d6df1c6ac5c21ffd0a7b65fa3..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -add_subdirectory(cxx) - -if(SMTK_ENABLE_PYTHON_WRAPPING) - add_subdirectory(python) -endif() - -if(SMTK_ENABLE_PARAVIEW_SUPPORT) - add_subdirectory(xml) -endif() diff --git a/smtk/session/mesh/testing/cxx/CMakeLists.txt b/smtk/session/mesh/testing/cxx/CMakeLists.txt deleted file mode 100644 index dfedf795b8b8a637e5bb803d4b1dd5723ed9f6f2..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -#============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -#============================================================================= - -set (unit_tests - TestCreateUniformGridOp.cxx - TestMergeOp.cxx - TestTransformOp.cxx -) - -set (unit_tests_which_require_data - UnitTestEulerRatio.cxx - UnitTestImportFrom3dm.cxx - UnitTestImportFromExodus.cxx - UnitTestImportIntoResource.cxx - UnitTestTopology.cxx - UnitTestImportExport.cxx -) - -set (unit_tests_serial_which_require_data - TestMeshSessionReadWrite.cxx -) - -set(external_libs ${Boost_LIBRARIES}) - -if (SMTK_ENABLE_VTK_SUPPORT) - list (APPEND unit_tests_which_require_data UnitTestImportFromVTK.cxx) - list (APPEND external_libs ${VTK_LIBRARIES} vtkSMTKSourceExt smtkIOVTK) -endif() - -smtk_unit_tests( - LABEL "MeshSession" - SOURCES ${unit_tests} - SOURCES_REQUIRE_DATA ${unit_tests_which_require_data} - SOURCES_SERIAL_REQUIRE_DATA ${unit_tests_serial_which_require_data} - LIBRARIES smtkCore smtkMeshSession smtkCoreModelTesting ${external_libs} -) diff --git a/smtk/session/mesh/testing/cxx/TestCreateUniformGridOp.cxx b/smtk/session/mesh/testing/cxx/TestCreateUniformGridOp.cxx deleted file mode 100644 index 0da7e22511669fc8df9d387471dbff14c9574fc2..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/TestCreateUniformGridOp.cxx +++ /dev/null @@ -1,292 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/session/mesh/Registrar.h" -#include "smtk/session/mesh/Session.h" -#include "smtk/session/mesh/operators/CreateUniformGrid.h" - -#include "smtk/common/testing/cxx/helpers.h" - -#include "smtk/model/CellEntity.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Group.h" -#include "smtk/model/Resource.h" - -#include "smtk/resource/Manager.h" - -#include "smtk/operation/Manager.h" - -#include "smtk/plugin/Registry.h" - -#ifdef SMTK_ENABLE_VTK_SUPPORT -#include "smtk/extension/vtk/source/vtkModelMultiBlockSource.h" - -#include "vtkActor.h" -#include "vtkCamera.h" -#include "vtkCommand.h" -#include "vtkCompositePolyDataMapper.h" -#include "vtkDataSetAttributes.h" -#include "vtkInteractorStyleSwitch.h" -#include "vtkNew.h" -#include "vtkPlane.h" -#include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkRenderWindow.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderer.h" -#include "vtkSmartPointer.h" -#include "vtkStringArray.h" -#include "vtkXMLMultiBlockDataWriter.h" - -// This macro ensures the vtk io library is loaded into the executable -smtkComponentInitMacro(smtk_extension_vtk_io_mesh_MeshIOVTK) -#endif - - namespace -{ - void UniqueEntities(const smtk::model::EntityRef& root, std::set& unique) - { - smtk::model::EntityRefArray children = - (root.isModel() - ? root.as().cellsAs() - : (root.isCellEntity() - ? root.as().boundingCellsAs() - : (root.isGroup() - ? root.as().members() - : smtk::model::EntityRefArray()))); - - for (smtk::model::EntityRefArray::const_iterator it = children.begin(); it != children.end(); - ++it) - { - if (unique.find(*it) == unique.end()) - { - unique.insert(*it); - UniqueEntities(*it, unique); - } - } - } - - void ParseModelTopology(smtk::model::Model model, std::size_t * count) - { - std::set unique; - UniqueEntities(model, unique); - - for (auto&& entity : unique) - { - if (entity.dimension() >= 0 && entity.dimension() <= 3) - { - count[entity.dimension()]++; - float r = static_cast(entity.dimension()) / 3; - float b = static_cast(1. - r); - const_cast(entity).setColor( - (r < 1. ? r : 1.), 0., (b < 1. ? b : 1.), 1.); - } - } - } - - void VisualizeModel(smtk::model::Model model) - { -#ifdef SMTK_ENABLE_VTK_SUPPORT - vtkNew act; - vtkNew src; - vtkNew map; - vtkNew ren; - vtkNew win; - src->SetModelResource(model.resource()); - src->SetDefaultColor(1., 1., 0., 1.); - map->SetInputConnection(src->GetOutputPort()); - act->SetMapper(map.GetPointer()); - act->GetProperty()->SetPointSize(5); - act->GetProperty()->SetLineWidth(2); - - vtkNew camera; - camera->SetPosition(-1., -1., -2.); - camera->SetFocalPoint(0, 0, 0); - - ren->SetActiveCamera(camera.GetPointer()); - - win->AddRenderer(ren.GetPointer()); - ren->AddActor(act.GetPointer()); - - vtkRenderWindowInteractor* iac = win->MakeRenderWindowInteractor(); - vtkInteractorStyleSwitch::SafeDownCast(iac->GetInteractorStyle()) - ->SetCurrentStyleToTrackballCamera(); - win->SetInteractor(iac); - - win->Render(); - ren->ResetCamera(); - - iac->Start(); -#else - (void)model; -#endif - } - - int Test2DGrid() - { - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register mesh operators to the resource and operation managers - auto meshRegistry = smtk::plugin::addToManagers( - resourceManager, operationManager); - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - // Create a "create background domain" operator - smtk::operation::Operation::Ptr createBackgroundDomainOp = - operationManager->create(); - - if (!createBackgroundDomainOp) - { - std::cerr << "Couldn't create \"create uniform grid\" operator" << std::endl; - return 1; - } - - createBackgroundDomainOp->parameters()->findString("dimension")->setValue("2"); - createBackgroundDomainOp->parameters()->findDouble("size2d")->setValue(0, 2); - - createBackgroundDomainOp->parameters()->findInt("discretization2d")->setValue(0, 5); - createBackgroundDomainOp->parameters()->findInt("discretization2d")->setValue(1, 5); - - smtk::operation::Operation::Result createBackgroundDomainOpResult = - createBackgroundDomainOp->operate(); - - if ( - createBackgroundDomainOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"create uniform grid\" operator failed\n"; - return 1; - } - - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - createBackgroundDomainOpResult->findComponent("created")); - - smtk::model::Entity::Ptr model = - std::dynamic_pointer_cast(componentItem->value()); - - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model->referenceAs(), count); - - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 0, "There should zero volumes"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 1, "There should be one face"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 4, "There should be four edges"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 0, "There should be zero vertex groups"); - - bool debug = false; - if (debug) - { - VisualizeModel(model->referenceAs()); - } - - return 0; - } - - int Test3DGrid() - { - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register mesh operators to the resource and operation managers - auto meshRegistry = smtk::plugin::addToManagers( - resourceManager, operationManager); - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - // Create a "create background domain" operator - smtk::operation::Operation::Ptr createBackgroundDomainOp = - operationManager->create(); - - if (!createBackgroundDomainOp) - { - std::cerr << "Couldn't create \"create uniform grid\" operator" << std::endl; - return 1; - } - - createBackgroundDomainOp->parameters()->findString("dimension")->setValue("3"); - createBackgroundDomainOp->parameters()->findDouble("size3d")->setValue(0, 2); - - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(0, 5); - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(1, 5); - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(2, 5); - - smtk::operation::Operation::Result createBackgroundDomainOpResult = - createBackgroundDomainOp->operate(); - - if ( - createBackgroundDomainOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"create uniform grid\" operator failed\n"; - return 1; - } - - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - createBackgroundDomainOpResult->findComponent("created")); - - smtk::model::Entity::Ptr model = - std::dynamic_pointer_cast(componentItem->value()); - - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model->referenceAs(), count); - - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 1, "There should one volume"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 6, "There should be six faces"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 0, "There should be zero edges"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 0, "There should be zero vertex groups"); - - bool debug = false; - if (debug) - { - VisualizeModel(model->referenceAs()); - } - - return 0; - } -} // namespace - -int TestCreateUniformGridOp(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - return Test2DGrid() + Test3DGrid(); -} diff --git a/smtk/session/mesh/testing/cxx/TestMergeOp.cxx b/smtk/session/mesh/testing/cxx/TestMergeOp.cxx deleted file mode 100644 index 790e48acc1f842d909659e875d5aef6c0a470268..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/TestMergeOp.cxx +++ /dev/null @@ -1,280 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/session/mesh/Registrar.h" -#include "smtk/session/mesh/Session.h" -#include "smtk/session/mesh/operators/CreateUniformGrid.h" -#include "smtk/session/mesh/operators/Merge.h" -#include "smtk/session/mesh/operators/Print.h" - -#include "smtk/common/testing/cxx/helpers.h" - -#include "smtk/model/CellEntity.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Resource.h" - -#include "smtk/plugin/Registry.h" - -#include "smtk/resource/Manager.h" - -#include "smtk/operation/Manager.h" - -#ifdef SMTK_ENABLE_VTK_SUPPORT -#include "smtk/extension/vtk/source/vtkModelMultiBlockSource.h" - -#include "vtkActor.h" -#include "vtkCamera.h" -#include "vtkCommand.h" -#include "vtkCompositePolyDataMapper.h" -#include "vtkDataSetAttributes.h" -#include "vtkInteractorStyleSwitch.h" -#include "vtkNew.h" -#include "vtkPlane.h" -#include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkRenderWindow.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderer.h" -#include "vtkSmartPointer.h" -#include "vtkStringArray.h" -#include "vtkXMLMultiBlockDataWriter.h" - -// This macro ensures the vtk io library is loaded into the executable -smtkComponentInitMacro(smtk_extension_vtk_io_mesh_MeshIOVTK) -#endif - -#include "nlohmann/json.hpp" - - namespace -{ - void UniqueEntities(const smtk::model::EntityRef& root, std::set& unique) - { - smtk::model::EntityRefArray children = - (root.isModel() - ? root.as().cellsAs() - : (root.isCellEntity() - ? root.as().boundingCellsAs() - : (root.isGroup() - ? root.as().members() - : smtk::model::EntityRefArray()))); - - for (smtk::model::EntityRefArray::const_iterator it = children.begin(); it != children.end(); - ++it) - { - if (unique.find(*it) == unique.end()) - { - unique.insert(*it); - UniqueEntities(*it, unique); - } - } - } - - void ParseModelTopology(smtk::model::Model model, std::size_t * count) - { - std::set unique; - UniqueEntities(model, unique); - - for (auto&& entity : unique) - { - if (entity.dimension() >= 0 && entity.dimension() <= 3) - { - count[entity.dimension()]++; - float r = static_cast(entity.dimension()) / 3; - float b = static_cast(1. - r); - const_cast(entity).setColor( - (r < 1. ? r : 1.), 0., (b < 1. ? b : 1.), 1.); - } - } - } - - void VisualizeModel(smtk::model::Model model) - { -#ifdef SMTK_ENABLE_VTK_SUPPORT - vtkNew act; - vtkNew src; - vtkNew map; - vtkNew ren; - vtkNew win; - src->SetModelResource(model.resource()); - src->SetDefaultColor(1., 1., 0., 1.); - map->SetInputConnection(src->GetOutputPort()); - act->SetMapper(map.GetPointer()); - act->GetProperty()->SetPointSize(5); - act->GetProperty()->SetLineWidth(2); - - vtkNew camera; - camera->SetPosition(-1., -1., -2.); - camera->SetFocalPoint(0, 0, 0); - - ren->SetActiveCamera(camera.GetPointer()); - - win->AddRenderer(ren.GetPointer()); - ren->AddActor(act.GetPointer()); - - vtkRenderWindowInteractor* iac = win->MakeRenderWindowInteractor(); - vtkInteractorStyleSwitch::SafeDownCast(iac->GetInteractorStyle()) - ->SetCurrentStyleToTrackballCamera(); - win->SetInteractor(iac); - - win->Render(); - ren->ResetCamera(); - - iac->Start(); -#else - (void)model; -#endif - } -} // namespace - -int TestMergeOp(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register mesh operators to the resource and operation managers - auto meshRegistry = - smtk::plugin::addToManagers(resourceManager, operationManager); - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - // Create a "create background domain" operator - smtk::operation::Operation::Ptr createBackgroundDomainOp = - operationManager->create(); - - if (!createBackgroundDomainOp) - { - std::cerr << "Couldn't create \"create uniform grid\" operator" << std::endl; - return 1; - } - - createBackgroundDomainOp->parameters()->findString("dimension")->setValue("3"); - createBackgroundDomainOp->parameters()->findDouble("size3d")->setValue(0, 2); - - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(0, 5); - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(1, 5); - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(2, 5); - - smtk::operation::Operation::Result createBackgroundDomainOpResult = - createBackgroundDomainOp->operate(); - - if ( - createBackgroundDomainOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"create uniform grid\" operation failed\n"; - return 1; - } - - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - createBackgroundDomainOpResult->findComponent("created")); - - smtk::model::Entity::Ptr model = - std::dynamic_pointer_cast(componentItem->value()); - - smtk::operation::Operation::Ptr mergeOp = operationManager->create(); - - auto faces = model->referenceAs().cellsAs>(); - - std::cout << "there are " << faces.size() << " faces before merge" << std::endl; - for (auto& face : faces) - std::cout << " " << face.name() << std::endl; - std::cout << std::endl; - - std::cout << "merging " << faces[0].name() << ", " << faces[1].name() << " and " - << faces[2].name() << std::endl; - std::cout << std::endl; - mergeOp->parameters()->associate(faces[0].component()); - mergeOp->parameters()->associate(faces[1].component()); - mergeOp->parameters()->associate(faces[2].component()); - - smtk::operation::Operation::Result mergeOpResult = mergeOp->operate(); - - if ( - mergeOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"merge\" operation failed\n"; - return 1; - } - - test( - mergeOpResult->findComponent("created")->numberOfValues() == 1, - "Merge operation should have created a component."); - - { - smtk::operation::Operation::Ptr printOp = - operationManager->create(); - - printOp->parameters()->associate(mergeOpResult->findComponent("created")->value()); - - smtk::operation::Operation::Result printOpResult = printOp->operate(); - - if ( - printOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"print\" operation failed\n"; - return 1; - } - - std::cout << "Merged face:" << std::endl; - nlohmann::json j = nlohmann::json::parse(printOpResult->findString("log")->value()); - std::cout << j[0]["message"].get() << std::endl; - std::cout << std::endl; - } - - faces = model->referenceAs().cellsAs>(); - std::cout << "There are " << faces.size() << " faces after merge" << std::endl; - for (auto& face : faces) - std::cout << " " << face.name() << std::endl; - std::cout << std::endl; - - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model->referenceAs(), count); - - std::cout << "Summary: " << std::endl; - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 1, "There should one volume"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 4, "There should be four faces"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 0, "There should be zero edges"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 0, "There should be zero vertex groups"); - - bool debug = false; - if (debug) - { - VisualizeModel(model->referenceAs()); - } - - return 0; -} diff --git a/smtk/session/mesh/testing/cxx/TestMeshSessionReadWrite.cxx b/smtk/session/mesh/testing/cxx/TestMeshSessionReadWrite.cxx deleted file mode 100644 index fce1ce53a0c48a38b21b0e981da4d4d450620493..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/TestMeshSessionReadWrite.cxx +++ /dev/null @@ -1,230 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/common/testing/cxx/helpers.h" -#include "smtk/model/Edge.h" -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" -#include "smtk/model/Session.h" -#include "smtk/model/Vertex.h" - -#include "smtk/operation/Registrar.h" -#include "smtk/operation/operators/ImportResource.h" -#include "smtk/operation/operators/ReadResource.h" -#include "smtk/operation/operators/WriteResource.h" - -#include "smtk/plugin/Registry.h" - -#include "smtk/session/mesh/Registrar.h" -#include "smtk/session/mesh/Resource.h" - -#include "smtk/operation/Manager.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -namespace -{ -std::string dataRoot = SMTK_DATA_DIR; -std::string writeRoot = SMTK_SCRATCH_DIR; -std::string filename("/model/2d/map/simple.map"); - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} - -void UniqueEntities(const smtk::model::EntityRef& root, std::set& unique) -{ - smtk::model::EntityRefArray children = - (root.isModel() - ? root.as().cellsAs() - : (root.isCellEntity() - ? root.as().boundingCellsAs() - : (root.isGroup() ? root.as().members() - : smtk::model::EntityRefArray()))); - - for (smtk::model::EntityRefArray::const_iterator it = children.begin(); it != children.end(); - ++it) - { - if (unique.find(*it) == unique.end()) - { - unique.insert(*it); - UniqueEntities(*it, unique); - } - } -} - -void ParseModelTopology(smtk::model::Model model, std::size_t* count) -{ - std::set unique; - UniqueEntities(model, unique); - - for (auto&& entity : unique) - { - if (entity.dimension() >= 0 && entity.dimension() <= 3) - { - count[entity.dimension()]++; - float r = static_cast(entity.dimension()) / 3; - float b = static_cast(1.) - r; - const_cast(entity).setColor( - (r < 1. ? r : 1.), 0., (b < 1. ? b : 1.), 1.); - } - } -} - -void ValidateModelTopology(smtk::model::Model model) -{ - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model, count); - - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 3, "There should be three volumes"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 9, "There should be nine faces"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 0, "There should be no lines"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 0, "There should be no vertex groups"); -} -} // namespace - -int TestMeshSessionReadWrite(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - auto meshRegistry = - smtk::plugin::addToManagers(resourceManager, operationManager); - auto modelRegistry = smtk::plugin::addToManagers(operationManager); - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - smtk::session::mesh::Resource::Ptr resource; - smtk::model::Entity::Ptr model; - - { - // Create an import operator - smtk::operation::ImportResource::Ptr importOp = - operationManager->create(); - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - // Set the file path - std::string importFilePath(dataRoot); - importFilePath += "/model/3d/exodus/SimpleReactorCore/SimpleReactorCore.exo"; - importOp->parameters()->findFile("filename")->setValue(importFilePath); - - // Execute the operation - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - // Retrieve the resulting polygon resource - smtk::attribute::ResourceItemPtr resourceItem = - std::dynamic_pointer_cast( - importOpResult->findResource("resourcesCreated")); - resource = std::dynamic_pointer_cast(resourceItem->value()); - - // Retrieve the resulting model - smtk::model::Models models = - resource->entitiesMatchingFlagsAs(smtk::model::MODEL_ENTITY, false); - - std::cout << "found " << models.size() << " models" << std::endl; - if (models.empty()) - return 1; - - model = models[0].entityRecord(); - - // Test for success - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - } - - ValidateModelTopology(model); - - std::string writeFilePath(writeRoot); - writeFilePath += "/" + smtk::common::UUID::random().toString() + ".smtk"; - resource->setLocation(writeFilePath); - - { - smtk::operation::WriteResource::Ptr writeOp = - operationManager->create(); - - test(writeOp != nullptr, "No write operator"); - - writeOp->parameters()->associate(resource); - - smtk::operation::Operation::Result writeOpResult = writeOp->operate(); - test( - writeOpResult->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "Write operator failed"); - - smtk::operation::ReadResource::Ptr readOp = - operationManager->create(); - - test(readOp != nullptr, "No read operator"); - - readOp->parameters()->findFile("filename")->setValue(writeFilePath); - - smtk::operation::Operation::Result readOpResult = readOp->operate(); - test( - readOpResult->findInt("outcome")->value() == - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), - "Read operator failed"); - - smtk::session::mesh::Resource::Ptr resource2 = - smtk::dynamic_pointer_cast( - readOpResult->findResource("resourcesCreated")->value(0)); - - cleanup(writeFilePath); - - smtk::model::Models models = - resource2->entitiesMatchingFlagsAs(smtk::model::MODEL_ENTITY, false); - - std::cout << "found " << models.size() << " models" << std::endl; - if (models.empty()) - return 1; - - smtk::model::Model model2 = models[0]; - - ValidateModelTopology(model2); - } - - return 0; -} diff --git a/smtk/session/mesh/testing/cxx/TestTransformOp.cxx b/smtk/session/mesh/testing/cxx/TestTransformOp.cxx deleted file mode 100644 index 1a9f69d282ecb5c58c2cb04c65842af7356ef55f..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/TestTransformOp.cxx +++ /dev/null @@ -1,132 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/GroupItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/session/mesh/Registrar.h" -#include "smtk/session/mesh/Session.h" -#include "smtk/session/mesh/operators/CreateUniformGrid.h" -#include "smtk/session/mesh/operators/Print.h" -#include "smtk/session/mesh/operators/Transform.h" - -#include "smtk/common/testing/cxx/helpers.h" - -#include "smtk/geometry/queries/BoundingBox.h" - -#include "smtk/model/CellEntity.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Resource.h" - -#include "smtk/plugin/Registry.h" - -#include "smtk/resource/Manager.h" - -#include "smtk/operation/Manager.h" - -namespace -{ -const double EPSILON = 1.e-10; -} - -int TestTransformOp(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register mesh operators to the resource and operation managers - auto meshRegistry = - smtk::plugin::addToManagers(resourceManager, operationManager); - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - // Create a "create background domain" operator - smtk::operation::Operation::Ptr createBackgroundDomainOp = - operationManager->create(); - - if (!createBackgroundDomainOp) - { - std::cerr << "Couldn't create \"create uniform grid\" operator" << std::endl; - return 1; - } - - createBackgroundDomainOp->parameters()->findString("dimension")->setValue("3"); - createBackgroundDomainOp->parameters()->findDouble("size3d")->setValue(0, 2); - - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(0, 5); - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(1, 5); - createBackgroundDomainOp->parameters()->findInt("discretization3d")->setValue(2, 5); - - smtk::operation::Operation::Result createBackgroundDomainOpResult = - createBackgroundDomainOp->operate(); - - if ( - createBackgroundDomainOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"create uniform grid\" operation failed\n"; - return 1; - } - - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - createBackgroundDomainOpResult->findComponent("created")); - - smtk::model::Entity::Ptr model = - std::dynamic_pointer_cast(componentItem->value()); - - smtk::geometry::BoundingBox& boundingBox = - model->resource()->queries().get(); - - std::array size = boundingBox(model); - - smtk::operation::Operation::Ptr transformOp = - operationManager->create(); - - transformOp->parameters()->associate(model); - - double scale = 0.5; - transformOp->parameters()->findDouble("scale")->setValue(0, scale); - smtk::operation::Operation::Result transformOpResult = transformOp->operate(); - - if ( - transformOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"transform\" operation failed\n"; - return 1; - } - - std::array transformedSize = boundingBox(model); - - if (fabs(size[1] * scale - transformedSize[1]) >= EPSILON) - { - std::cerr << "Transform operation did something unexpected\n"; - return 1; - } - - return 0; -} diff --git a/smtk/session/mesh/testing/cxx/UnitTestEulerRatio.cxx b/smtk/session/mesh/testing/cxx/UnitTestEulerRatio.cxx deleted file mode 100644 index c6572bd33dc9f1c339a6c98cd3fe797e7364a9cf..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/UnitTestEulerRatio.cxx +++ /dev/null @@ -1,128 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/EulerCharacteristicRatio.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/common/UUID.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" - -#include - -#include "smtk/operation/Manager.h" - -using namespace smtk::model; - -namespace -{ -std::string dataRoot = SMTK_DATA_DIR; -} - -int UnitTestEulerRatio(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Register the mesh resource to the resource manager - { - resourceManager->registerResource(); - } - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register import and euler characteristic ratio operators to the operation manager - { - operationManager->registerOperation("smtk::session::mesh::Import"); - operationManager->registerOperation( - "smtk::session::mesh::EulerCharacteristicRatio"); - } - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - smtk::model::Entity::Ptr model; - - { - // Create an import operator - smtk::session::mesh::Import::Ptr importOp = - operationManager->create(); - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - // Set the file path - std::string importFilePath(dataRoot); - importFilePath += "/mesh/3d/cube.exo"; - importOp->parameters()->findFile("filename")->setValue(importFilePath); - - // Execute the operation - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - model = std::dynamic_pointer_cast(componentItem->value()); - - // Test for success - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - } - - { - smtk::operation::Operation::Ptr eulerOp = - operationManager->create(); - - if (!eulerOp) - { - std::cerr << "No \"euler characteristic ratio\" operator\n"; - return 1; - } - - eulerOp->parameters()->associateEntity(model->referenceAs()); - - smtk::operation::Operation::Result eulerOpResult = eulerOp->operate(); - if ( - eulerOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "\"Euler characteristic ratio\" operator failed\n"; - return 1; - } - - if (std::abs(eulerOpResult->findDouble("value")->value() - 2.) > 1.e-10) - { - std::cerr << "Unexpected Euler ratio\n"; - return 1; - } - } - - return 0; -} diff --git a/smtk/session/mesh/testing/cxx/UnitTestImportExport.cxx b/smtk/session/mesh/testing/cxx/UnitTestImportExport.cxx deleted file mode 100644 index 8b4d839d98ccb5e443e4ff4f737bb8e7f78d909c..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/UnitTestImportExport.cxx +++ /dev/null @@ -1,148 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Export.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/common/UUID.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" - -#include "smtk/operation/Manager.h" - -//force to use filesystem version 3 -#define BOOST_FILESYSTEM_VERSION 3 -#include -using namespace boost::filesystem; - -#include - -using namespace smtk::model; - -namespace -{ -std::string dataRoot = SMTK_DATA_DIR; -std::string writeRoot = SMTK_SCRATCH_DIR; - -void cleanup(const std::string& file_path) -{ - //first verify the file exists - ::boost::filesystem::path path(file_path); - if (::boost::filesystem::is_regular_file(path)) - { - //remove the file_path if it exists. - ::boost::filesystem::remove(path); - } -} -} // namespace - -int UnitTestImportExport(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Register the mesh resource to the resource manager - { - resourceManager->registerResource(); - } - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register import and write operators to the operation manager - { - operationManager->registerOperation("smtk::session::mesh::Export"); - operationManager->registerOperation("smtk::session::mesh::Import"); - } - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - smtk::model::Entity::Ptr model; - - { - // Create an import operator - smtk::session::mesh::Import::Ptr importOp = - operationManager->create(); - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - // Set the file path - std::string importFilePath(dataRoot); - importFilePath += "/model/3d/exodus/SimpleReactorCore/SimpleReactorCore.exo"; - importOp->parameters()->findFile("filename")->setValue(importFilePath); - - // Execute the operation - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - model = std::dynamic_pointer_cast(componentItem->value()); - - // Test for success - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - } - - { - // Create an export operator - smtk::operation::Operation::Ptr exportOp = - operationManager->create(); - if (!exportOp) - { - std::cerr << "No export operator\n"; - return 1; - } - - // Set the file path - std::string exportFilePath(writeRoot); - exportFilePath += "/" + smtk::common::UUID::random().toString() + ".exo"; - exportOp->parameters()->findFile("filename")->setValue(exportFilePath); - - // Set the entity association - exportOp->parameters()->associate(model->resource()); - - // Execute the operation - smtk::operation::Operation::Result exportOpResult = exportOp->operate(); - - // Test for success - if ( - exportOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Export operator failed\n"; - return 1; - } - - cleanup(exportFilePath); - } - - return 0; -} diff --git a/smtk/session/mesh/testing/cxx/UnitTestImportFrom3dm.cxx b/smtk/session/mesh/testing/cxx/UnitTestImportFrom3dm.cxx deleted file mode 100644 index 3a8b88a7adf29aeaa329e22156fd74b8a17d5e52..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/UnitTestImportFrom3dm.cxx +++ /dev/null @@ -1,156 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/io/ExportMesh.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" -#include "smtk/model/Tessellation.h" - -#include "smtk/operation/Manager.h" - -namespace -{ -std::string dataRoot = SMTK_DATA_DIR; - -void UniqueEntities(const smtk::model::EntityRef& root, std::set& unique) -{ - smtk::model::EntityRefArray children = - (root.isModel() - ? root.as().cellsAs() - : (root.isCellEntity() - ? root.as().boundingCellsAs() - : (root.isGroup() ? root.as().members() - : smtk::model::EntityRefArray()))); - - for (smtk::model::EntityRefArray::const_iterator it = children.begin(); it != children.end(); - ++it) - { - if (unique.find(*it) == unique.end()) - { - unique.insert(*it); - UniqueEntities(*it, unique); - } - } -} - -void ParseModelTopology(smtk::model::Model model, std::size_t* count) -{ - std::set unique; - UniqueEntities(model, unique); - - for (auto&& entity : unique) - { - if (entity.dimension() >= 0 && entity.dimension() <= 3) - { - count[entity.dimension()]++; - float r = static_cast(entity.dimension()) / 3; - float b = static_cast(1.) - r; - const_cast(entity).setColor( - (r < 1. ? r : 1.), 0., (b < 1. ? b : 1.), 1.); - } - } -} -} // namespace - -int UnitTestImportFrom3dm(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Register the mesh resource to the resource manager - { - resourceManager->registerResource(); - } - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register import operator to the operation manager - { - operationManager->registerOperation("smtk::session::mesh::Import"); - } - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - smtk::model::Entity::Ptr model; - - { - // Create an import operator - smtk::session::mesh::Import::Ptr importOp = - operationManager->create(); - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - // Set the file path - std::string importFilePath(dataRoot); - importFilePath += "/mesh/3d/Scenario1_Mesh.3dm"; - importOp->parameters()->findFile("filename")->setValue(importFilePath); - importOp->parameters()->findVoid("construct hierarchy")->setIsEnabled(false); - - // Execute the operation - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - model = std::dynamic_pointer_cast(componentItem->value()); - - // Test for success - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - } - - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model->referenceAs(), count); - - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 2, "There should be two volumes"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 0, "There should be no faces"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 0, "There should be no lines"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 0, "There should be no vertex groups"); - - return 0; -} diff --git a/smtk/session/mesh/testing/cxx/UnitTestImportFromExodus.cxx b/smtk/session/mesh/testing/cxx/UnitTestImportFromExodus.cxx deleted file mode 100644 index 3aaa293d3bead93510c5decb293fe1652290b790..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/UnitTestImportFromExodus.cxx +++ /dev/null @@ -1,157 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/io/ExportMesh.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" -#include "smtk/model/Resource.h" -#include "smtk/model/Tessellation.h" - -#include "smtk/operation/Manager.h" - -namespace -{ -std::string dataRoot = SMTK_DATA_DIR; - -void UniqueEntities(const smtk::model::EntityRef& root, std::set& unique) -{ - smtk::model::EntityRefArray children = - (root.isModel() - ? root.as().cellsAs() - : (root.isCellEntity() - ? root.as().boundingCellsAs() - : (root.isGroup() ? root.as().members() - : smtk::model::EntityRefArray()))); - - for (smtk::model::EntityRefArray::const_iterator it = children.begin(); it != children.end(); - ++it) - { - if (unique.find(*it) == unique.end()) - { - unique.insert(*it); - UniqueEntities(*it, unique); - } - } -} - -void ParseModelTopology(smtk::model::Model model, std::size_t* count) -{ - std::set unique; - UniqueEntities(model, unique); - - for (auto&& entity : unique) - { - if (entity.dimension() >= 0 && entity.dimension() <= 3) - { - count[entity.dimension()]++; - float r = static_cast(entity.dimension()) / 3; - float b = static_cast(1.) - r; - const_cast(entity).setColor( - (r < 1. ? r : 1.), 0., (b < 1. ? b : 1.), 1.); - } - } -} -} // namespace - -int UnitTestImportFromExodus(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Register the mesh resource to the resource manager - { - resourceManager->registerResource(); - } - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register import operator to the operation manager - { - operationManager->registerOperation("smtk::session::mesh::Import"); - } - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - smtk::model::Entity::Ptr model; - - { - // Create an import operator - smtk::session::mesh::Import::Ptr importOp = - operationManager->create(); - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - // Set the file path - std::string importFilePath(dataRoot); - importFilePath += "/model/3d/genesis/gun-1fourth.gen"; - importOp->parameters()->findFile("filename")->setValue(importFilePath); - importOp->parameters()->findVoid("construct hierarchy")->setIsEnabled(false); - - // Execute the operation - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - model = std::dynamic_pointer_cast(componentItem->value()); - - // Test for success - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - } - - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model->referenceAs(), count); - - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 1, "There should be one volume"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 5, "There should be five faces"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 0, "There should be no lines"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 0, "There should be no vertex groups"); - - return 0; -} diff --git a/smtk/session/mesh/testing/cxx/UnitTestImportFromVTK.cxx b/smtk/session/mesh/testing/cxx/UnitTestImportFromVTK.cxx deleted file mode 100644 index 695aa47caa33032e9da0a77f4bb05c1d63fe98d9..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/UnitTestImportFromVTK.cxx +++ /dev/null @@ -1,118 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/StringItem.h" - -#include "smtk/io/ExportMesh.h" - -#include "smtk/mesh/core/Resource.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" -#include "smtk/model/Tessellation.h" - -#include "smtk/operation/Manager.h" - -namespace -{ -std::string dataRoot = SMTK_DATA_DIR; -} - -int UnitTestImportFromVTK(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - std::vector files( - { "/mesh/2d/ImportFromDEFORM.vtu", "/../thirdparty/delaunay/data/chesapeake-0.001-100.vtp" }); - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Register the mesh resource to the resource manager - { - resourceManager->registerResource(); - } - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register import operator to the operation manager - { - operationManager->registerOperation("smtk::session::mesh::Import"); - } - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - for (const auto& file : files) - { - smtk::model::Entity::Ptr model; - - { - // Create an import operator - smtk::session::mesh::Import::Ptr importOp = - operationManager->create(); - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - // Set the file path - std::string importFilePath(dataRoot); - importFilePath += file; - importOp->parameters()->findFile("filename")->setValue(importFilePath); - - // Test for success - if (!importOp->ableToOperate()) - { - std::cerr << "Import operator unable to operate\n"; - return 1; - } - - // Execute the operation - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - model = std::dynamic_pointer_cast(componentItem->value()); - - // Test for success - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - } - } - - return 0; -} - -// This macro ensures the vtk io library is loaded into the executable -smtkComponentInitMacro(smtk_extension_vtk_io_mesh_MeshIOVTK) diff --git a/smtk/session/mesh/testing/cxx/UnitTestImportIntoResource.cxx b/smtk/session/mesh/testing/cxx/UnitTestImportIntoResource.cxx deleted file mode 100644 index ad453b9a21e95c095573c32dd6a77a248e4e5b0b..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/UnitTestImportIntoResource.cxx +++ /dev/null @@ -1,205 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/DoubleItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/io/ExportMesh.h" - -#include "smtk/mesh/core/Resource.h" -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "smtk/model/EntityRef.h" -#include "smtk/model/Face.h" -#include "smtk/model/Group.h" -#include "smtk/model/Model.h" -#include "smtk/model/Resource.h" -#include "smtk/model/Tessellation.h" - -#include "smtk/operation/Manager.h" - -namespace -{ -std::string dataRoot = SMTK_DATA_DIR; - -void UniqueEntities(const smtk::model::EntityRef& root, std::set& unique) -{ - smtk::model::EntityRefArray children = - (root.isModel() - ? root.as().cellsAs() - : (root.isCellEntity() - ? root.as().boundingCellsAs() - : (root.isGroup() ? root.as().members() - : smtk::model::EntityRefArray()))); - - for (smtk::model::EntityRefArray::const_iterator it = children.begin(); it != children.end(); - ++it) - { - if (unique.find(*it) == unique.end()) - { - unique.insert(*it); - UniqueEntities(*it, unique); - } - } -} - -void ParseModelTopology(smtk::model::Model model, std::size_t* count) -{ - std::set unique; - UniqueEntities(model, unique); - - for (auto&& entity : unique) - { - if (entity.dimension() >= 0 && entity.dimension() <= 3) - { - count[entity.dimension()]++; - float r = static_cast(entity.dimension()) / 3; - float b = static_cast(1.) - r; - const_cast(entity).setColor( - (r < 1. ? r : 1.), 0., (b < 1. ? b : 1.), 1.); - } - } -} -} // namespace - -int UnitTestImportIntoResource(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Register the mesh resource to the resource manager - { - resourceManager->registerResource(); - } - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register import operator to the operation manager - { - operationManager->registerOperation("smtk::session::mesh::Import"); - } - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - smtk::model::Entity::Ptr model; - - { - // Create an import operator - smtk::session::mesh::Import::Ptr importOp = - operationManager->create(); - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - // Set the file path - std::string importFilePath(dataRoot); - importFilePath += "/model/3d/genesis/gun-1fourth.gen"; - importOp->parameters()->findFile("filename")->setValue(importFilePath); - importOp->parameters()->findVoid("construct hierarchy")->setIsEnabled(false); - - // Execute the operation - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - model = std::dynamic_pointer_cast(componentItem->value()); - - // Test for success - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - } - - { - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model->referenceAs(), count); - - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 1, "There should be one volume"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 5, "There should be five faces"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 0, "There should be no lines"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 0, "There should be no vertex groups"); - } - - smtk::model::Entity::Ptr secondModel; - - { - smtk::session::mesh::Import::Ptr importOp = - operationManager->create(); - importOp->parameters()->associate(model->resource()); - std::string importFilePath(dataRoot); - importFilePath += "/model/3d/exodus/disk_out_ref.ex2"; - importOp->parameters()->findFile("filename")->setValue(importFilePath); - - smtk::operation::Operation::Result importOpResult = importOp->operate(); - - // Test for success - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - - // Retrieve the resulting model - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - // Access the generated model - secondModel = std::dynamic_pointer_cast(componentItem->value()); - } - - { - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model->referenceAs(), count); - ParseModelTopology(secondModel->referenceAs(), count); - - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 2, "There should be two volumes"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 12, "There should be twelve faces"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 0, "There should be no lines"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 3, "There should be three vertex groups"); - } - - return 0; -} diff --git a/smtk/session/mesh/testing/cxx/UnitTestTopology.cxx b/smtk/session/mesh/testing/cxx/UnitTestTopology.cxx deleted file mode 100644 index 456efd2fdfc266212a60469d4231e0ff13c42f04..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/cxx/UnitTestTopology.cxx +++ /dev/null @@ -1,294 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/session/mesh/Resource.h" -#include "smtk/session/mesh/operators/Import.h" - -#include "smtk/attribute/Attribute.h" -#include "smtk/attribute/ComponentItem.h" -#include "smtk/attribute/FileItem.h" -#include "smtk/attribute/IntItem.h" -#include "smtk/attribute/ResourceItem.h" -#include "smtk/attribute/StringItem.h" -#include "smtk/attribute/VoidItem.h" - -#include "smtk/mesh/testing/cxx/helpers.h" - -#include "smtk/model/CellEntity.h" -#include "smtk/model/EntityRef.h" -#include "smtk/model/Group.h" -#include "smtk/model/Resource.h" - -#include "smtk/operation/Manager.h" -#include "smtk/resource/Manager.h" - -#ifdef SMTK_ENABLE_VTK_SUPPORT -#include "smtk/extension/vtk/source/vtkModelMultiBlockSource.h" - -#include "vtkActor.h" -#include "vtkCamera.h" -#include "vtkCommand.h" -#include "vtkCompositePolyDataMapper.h" -#include "vtkDataSetAttributes.h" -#include "vtkInteractorStyleSwitch.h" -#include "vtkNew.h" -#include "vtkPlane.h" -#include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkRenderWindow.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderer.h" -#include "vtkSmartPointer.h" -#include "vtkStringArray.h" -#include "vtkXMLMultiBlockDataWriter.h" - -// This macro ensures the vtk io library is loaded into the executable -smtkComponentInitMacro(smtk_extension_vtk_io_mesh_MeshIOVTK) -#endif - - namespace -{ - std::string dataRoot = SMTK_DATA_DIR; - std::string writeRoot = SMTK_SCRATCH_DIR; - - int ImportModel( - smtk::model::Entity::Ptr & model, - smtk::operation::Manager::Ptr & operationManager, - const std::string& filename, - std::string label = std::string()) - { - { - smtk::session::mesh::Import::Ptr importOp = - operationManager->create(); - if (!importOp) - { - std::cerr << "No import operator\n"; - return 1; - } - - importOp->parameters()->findFile("filename")->setValue(filename); - importOp->parameters()->findString("label")->setValue(label); - importOp->parameters()->findVoid("construct hierarchy")->setIsEnabled(true); - - smtk::session::mesh::Import::Result importOpResult = importOp->operate(); - - smtk::attribute::ComponentItemPtr componentItem = - std::dynamic_pointer_cast( - importOpResult->findComponent("model")); - - model = std::dynamic_pointer_cast(componentItem->value()); - - if ( - importOpResult->findInt("outcome")->value() != - static_cast(smtk::operation::Operation::Outcome::SUCCEEDED)) - { - std::cerr << "Import operator failed\n"; - return 1; - } - } - return 0; - } - - void UniqueEntities(const smtk::model::EntityRef& root, std::set& unique) - { - smtk::model::EntityRefArray children = - (root.isModel() - ? root.as().cellsAs() - : (root.isCellEntity() - ? root.as().boundingCellsAs() - : (root.isGroup() - ? root.as().members() - : smtk::model::EntityRefArray()))); - - for (smtk::model::EntityRefArray::const_iterator it = children.begin(); it != children.end(); - ++it) - { - if (unique.find(*it) == unique.end()) - { - unique.insert(*it); - UniqueEntities(*it, unique); - } - } - } - - void ParseModelTopology(smtk::model::Model model, std::size_t * count) - { - std::set unique; - UniqueEntities(model, unique); - - for (auto&& entity : unique) - { - if (entity.dimension() >= 0 && entity.dimension() <= 3) - { - count[entity.dimension()]++; - float r = static_cast(entity.dimension()) / 3; - float b = static_cast(1. - r); - const_cast(entity).setColor( - (r < 1. ? r : 1.), 0., (b < 1. ? b : 1.), 1.); - } - } - } - - void VisualizeModel(smtk::model::Model model) - { -#ifdef SMTK_ENABLE_VTK_SUPPORT - vtkNew act; - vtkNew src; - vtkNew map; - vtkNew ren; - vtkNew win; - src->SetModelResource(model.resource()); - src->SetDefaultColor(1., 1., 0., 1.); - map->SetInputConnection(src->GetOutputPort()); - act->SetMapper(map.GetPointer()); - act->GetProperty()->SetPointSize(5); - act->GetProperty()->SetLineWidth(2); - - vtkNew camera; - camera->SetPosition(-1., -1., -2.); - camera->SetFocalPoint(0, 0, 0); - - ren->SetActiveCamera(camera.GetPointer()); - - win->AddRenderer(ren.GetPointer()); - ren->AddActor(act.GetPointer()); - - vtkRenderWindowInteractor* iac = win->MakeRenderWindowInteractor(); - vtkInteractorStyleSwitch::SafeDownCast(iac->GetInteractorStyle()) - ->SetCurrentStyleToTrackballCamera(); - win->SetInteractor(iac); - - win->Render(); - ren->ResetCamera(); - - iac->Start(); -#else - (void)model; -#endif - } -} // namespace - -int UnitTestTopology(int argc, char* argv[]) -{ - (void)argc; - (void)argv; - - // Create a resource manager - smtk::resource::Manager::Ptr resourceManager = smtk::resource::Manager::create(); - - // Register the mesh resource to the resource manager - { - resourceManager->registerResource(); - } - - // Create an operation manager - smtk::operation::Manager::Ptr operationManager = smtk::operation::Manager::create(); - - // Register import operator to the operation manager - { - operationManager->registerOperation("smtk::session::mesh::Import"); - } - - // Register the resource manager to the operation manager (newly created - // resources will be automatically registered to the resource manager). - operationManager->registerResourceManager(resourceManager); - - { - smtk::model::Entity::Ptr model; - - std::string readFilePath(dataRoot); - readFilePath += "/model/3d/exodus/SimpleReactorCore/SimpleReactorCore.exo"; - - test( - ImportModel(model, operationManager, readFilePath) == 0, - "Could not import model " + readFilePath); - - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model->referenceAs(), count); - - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 3, "There should be three volumes"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 9, "There should be nine faces"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 6, "There should be six lines"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 0, "There should be no vertex groups"); - - bool debug = false; - if (debug) - { - VisualizeModel(model->referenceAs()); - } - } - - { - smtk::model::Entity::Ptr model; - - std::string readFilePath(dataRoot); - readFilePath += "/model/3d/genesis/gun-1fourth.gen"; - - test( - ImportModel(model, operationManager, readFilePath) == 0, - "Could not import model " + readFilePath); - - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model->referenceAs(), count); - - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 1, "There should be one volume"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 5, "There should be five faces"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 9, "There should be nine lines"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 6, "There should be six vertex groups"); - - bool debug = false; - if (debug) - { - VisualizeModel(model->referenceAs()); - } - } - -#ifdef SMTK_ENABLE_VTK_SUPPORT - { - smtk::model::Entity::Ptr model; - - std::string readFilePath(dataRoot); - readFilePath += "/mesh/3d/nickel_superalloy.vtu"; - - test( - ImportModel(model, operationManager, readFilePath, "ZoneIds") == 0, - "Could not import model " + readFilePath); - - std::size_t count[4] = { 0, 0, 0, 0 }; - ParseModelTopology(model->referenceAs(), count); - - std::cout << count[3] << " volumes" << std::endl; - test(count[3] == 5, "There should be five volumes"); - std::cout << count[2] << " faces" << std::endl; - test(count[2] == 12, "There should be twelve faces"); - std::cout << count[1] << " edges" << std::endl; - test(count[1] == 10, "There should be ten lines"); - std::cout << count[0] << " vertex groups" << std::endl; - test(count[0] == 3, "There should be three vertex groups"); - - bool debug = false; - if (debug) - { - VisualizeModel(model->referenceAs()); - } - } -#endif - - return 0; -} diff --git a/smtk/session/mesh/testing/python/CMakeLists.txt b/smtk/session/mesh/testing/python/CMakeLists.txt deleted file mode 100644 index d5f7d0f38f6317d363238eb76f1ac5de1a3c78ff..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/python/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ - - -# tests that require SMTK_DATA_DIR -set(smtkMeshPythonDataTests - importAndWriteGenesisFile - loadExodusFile -) - -if (SMTK_ENABLE_VTK_SUPPORT) - list (APPEND smtkMeshPythonDataTests eulerRatio) -endif() - -#only run these tests if we have a valid data directory and we have a moab -#built with hdf5 -if (SMTK_DATA_DIR) - foreach (test ${smtkMeshPythonDataTests}) - smtk_add_test_python(${test}Py ${test}.py - --data-dir=${SMTK_DATA_DIR} - --temp-dir=${CMAKE_BINARY_DIR}/Testing/Temporary) - set_tests_properties( ${test}Py PROPERTIES LABELS "MeshSession" ) - endforeach() -endif() diff --git a/smtk/session/mesh/testing/python/eulerRatio.py b/smtk/session/mesh/testing/python/eulerRatio.py deleted file mode 100644 index ea722b674fbd2558091343b4247c2fc783d55458..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/python/eulerRatio.py +++ /dev/null @@ -1,63 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= -import os -import sys -import unittest -import smtk -import smtk.mesh -import smtk.model -import smtk.session.mesh -import smtk.testing -import smtk.io.vtk - - -class EulerRatio(smtk.testing.TestCase): - - def setUp(self): - self.modelFiles = [ - os.path.join( - smtk.testing.DATA_DIR, 'mesh', '3d', 'nickel_superalloy.vtu'), - os.path.join(smtk.testing.DATA_DIR, 'mesh', '3d', 'cube.exo'), - os.path.join( - smtk.testing.DATA_DIR, 'model', '3d', 'genesis', 'gun-1fourth.gen'), - os.path.join( - smtk.testing.DATA_DIR, 'mesh', '3d', 'genesis', 'cube-hex.gen'), - os.path.join( - smtk.testing.DATA_DIR, 'mesh', '3d', 'genesis', 'cube-tet.gen'), - os.path.join( - smtk.testing.DATA_DIR, 'mesh', '3d', 'genesis', 'cube-tet10.gen') - ] - - def testMeshing2D(self): - for modelFile in self.modelFiles: - op = smtk.session.mesh.Import.create() - fname = op.parameters().findFile('filename') - fname.setValue(modelFile) - res = op.operate() - if res.findInt('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - raise RuntimeError - modelEntity = res.find('created').value(0) - self.model = smtk.model.Model( - modelEntity.modelResource(), modelEntity.id()) - - op = smtk.session.mesh.EulerCharacteristicRatio.create() - op.parameters().associateEntity(self.model) - res = op.operate() - if res.findInt('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - raise RuntimeError - value = res.findDouble('value').value(0) - self.assertAlmostEqual(value, 2.) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - unittest.main() diff --git a/smtk/session/mesh/testing/python/importAndWriteGenesisFile.py b/smtk/session/mesh/testing/python/importAndWriteGenesisFile.py deleted file mode 100644 index e0b06e10d6675baf39eb0197f791aa6f9d4882ab..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/python/importAndWriteGenesisFile.py +++ /dev/null @@ -1,100 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= -import os -import sys -import unittest -import smtk -import smtk.common -import smtk.io -import smtk.mesh -import smtk.model -import smtk.operation -import smtk.session.mesh -import smtk.testing - - -class ImportAndWriteGenesisFile(smtk.testing.TestCase): - - def setUp(self): - - # Construct a resource manager - self.resourceManager = smtk.resource.Manager.create() - - # Construct an operation manager - self.operationManager = smtk.operation.Manager.create() - - # Register mesh resource to the resource manager (this allows the - # resource manager to track mesh resources) - smtk.session.mesh.Registrar.registerTo(self.resourceManager) - - # Register mesh operations to the operation manager (this lets the - # operation manager call the mesh session's load methods) - smtk.session.mesh.Registrar.registerTo(self.operationManager) - - # Register operation operations to the operation manager (this lets the - # operation manager create a generic "ImportResource" operation that can - # load any resource it knows about). - smtk.operation.Registrar.registerTo(self.operationManager) - - # Register resource manager to the operation manager - self.operationManager.registerResourceManager(self.resourceManager) - - def testLoadExodusFile(self): - # Set up the path to the test's input file - modelFile = os.path.join( - smtk.testing.DATA_DIR, 'model', '3d', 'genesis', 'gun-1fourth.gen') - - # Create an ImportResource operation (alternatively, we could have just - # created a smtk.session.mesh.Import operation directly, avoiding the - # need for all of the setup registration. This is a test, though, so - loadOp = self.operationManager.createOperation( - 'smtk::operation::ImportResource') - loadOp.parameters().find('filename').setValue(modelFile) - loadRes = loadOp.operate() - - if loadRes.findInt('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - raise RuntimeError - - # Access the resource - resource = smtk.model.Resource.CastTo( - loadRes.find('resourcesCreated').value()) - - # Write the resulting smtk mesh session file - writeOp = self.operationManager.createOperation( - 'smtk::operation::WriteResource') - writeOp.parameters().associate(resource) - filename = os.path.join( - smtk.testing.TEMP_DIR, str(resource.id()) + '.smtk') - writeOp.parameters().find('filename').setIsEnabled(True) - writeOp.parameters().find('filename').setValue(filename) - - writeRes = writeOp.operate() - - if writeRes.findInt('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - print(writeOp.log().convertToString(True)) - raise RuntimeError - - if not os.path.isfile(filename): - raise RuntimeError - - os.remove(filename) - - additionalFilename = os.path.join( - smtk.testing.TEMP_DIR, str(resource.id()) + '.h5m') - - if os.path.isfile(additionalFilename): - os.remove(additionalFilename) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - unittest.main() diff --git a/smtk/session/mesh/testing/python/loadExodusFile.py b/smtk/session/mesh/testing/python/loadExodusFile.py deleted file mode 100644 index cec17b73cec9fec520fe515b35977d084c20020d..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/python/loadExodusFile.py +++ /dev/null @@ -1,72 +0,0 @@ -# ============================================================================= -# -# Copyright (c) Kitware, Inc. -# All rights reserved. -# See LICENSE.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even -# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the above copyright notice for more information. -# -# ============================================================================= -import os -import sys -import unittest -import smtk -import smtk.mesh -import smtk.model -import smtk.operation -import smtk.session.mesh -import smtk.testing - - -class LoadExodusFile(smtk.testing.TestCase): - - def setUp(self): - - # Construct a resource manager - self.resourceManager = smtk.resource.Manager.create() - - # Construct an operation manager - self.operationManager = smtk.operation.Manager.create() - - # Register mesh resource to the resource manager (this allows the - # resource manager to track mesh resources) - smtk.session.mesh.Registrar.registerTo(self.resourceManager) - - # Register mesh operations to the operation manager (this lets the - # operation manager call the mesh session's load methods) - smtk.session.mesh.Registrar.registerTo(self.operationManager) - - # Register operation operations to the operation manager (this lets the - # operation manager create a generic "ImportResource" operation that can - # load any resource it knows about). - smtk.operation.Registrar.registerTo(self.operationManager) - - # Register resource manager to the operation manager - self.operationManager.registerResourceManager(self.resourceManager) - - def testLoadExodusFile(self): - # Set up the path to the test's input file - modelFile = os.path.join( - smtk.testing.DATA_DIR, 'model', '3d', 'exodus', 'disk_out_ref.ex2') - - # Create an ImportResource operation (alternatively, we could have just - # created a smtk.session.mesh.Import operation directly, avoiding the - # need for all of the setup registration. This is a test, though, so - loadOp = self.operationManager.createOperation( - 'smtk::operation::ImportResource') - loadOp.parameters().find('filename').setValue(modelFile) - loadRes = loadOp.operate() - - if loadRes.findInt('outcome').value(0) != int(smtk.operation.Operation.SUCCEEDED): - raise RuntimeError - - # Access the resource - resource = smtk.model.Resource.CastTo( - loadRes.find('resourcesCreated').value()) - - -if __name__ == '__main__': - smtk.testing.process_arguments() - unittest.main() diff --git a/smtk/session/mesh/testing/xml/CMakeLists.txt b/smtk/session/mesh/testing/xml/CMakeLists.txt deleted file mode 100644 index 16a5f419181d3a5c3bb0483701e24d628a6863c1..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/xml/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -set(TESTS_WITH_BASELINES - ${CMAKE_CURRENT_SOURCE_DIR}/OpenExodusFile.xml) - -include(SMTKPVTestingMacros) - -#TODO: this should be set for the entire project's xml tests -set(OpenExodusFile_USES_DIRECT_DATA ON) - -if (SMTK_DATA_DIR) -smtk_add_client_tests( - #LABEL "MeshSession" - TEST_SCRIPTS ${TESTS_WITH_BASELINES} - LOAD_PLUGINS - smtkResourcePlugin - smtkOperationPlugin - smtkGeometryPlugin - smtkViewPlugin - smtkQtPlugin - smtkMeshSessionPlugin - smtkPVServerExtPlugin - smtkPQComponentsPlugin - smtkPQGuiComponentsPlugin - smtkPQReadersPlugin - smtkPQOperationsPanelPlugin - PLUGIN_PATHS - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - $/.. - DATA_DIRECTORY ${PROJECT_SOURCE_DIR}/data - BASELINE_DIR ${PROJECT_SOURCE_DIR}/data/baseline/smtk/mesh - ) - - smtk_test_apply_sanitizer(pv.OpenExodusFile) -endif () diff --git a/smtk/session/mesh/testing/xml/OpenExodusFile.xml b/smtk/session/mesh/testing/xml/OpenExodusFile.xml deleted file mode 100644 index 1fc096db567c634eea74eb623b38dd40d1587ae2..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/testing/xml/OpenExodusFile.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/smtk/session/mesh/vtk/Geometry.cxx b/smtk/session/mesh/vtk/Geometry.cxx deleted file mode 100644 index e7ed32560412a17c5e07b36359ba3afb4b945bdf..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/vtk/Geometry.cxx +++ /dev/null @@ -1,176 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/session/mesh/vtk/Geometry.h" - -#include "smtk/session/mesh/Resource.h" - -#include "smtk/extension/vtk/io/mesh/ExportVTKData.h" -#include "smtk/extension/vtk/model/vtkAuxiliaryGeometryExtension.h" - -#include "smtk/geometry/Generator.h" - -#include -#include - -namespace smtk -{ -namespace session -{ -namespace mesh -{ -namespace vtk -{ - -Geometry::Geometry(const std::shared_ptr& parent) - : m_parent(parent) -{ -} - -smtk::geometry::Resource::Ptr Geometry::resource() const -{ - return std::dynamic_pointer_cast(m_parent.lock()); -} - -void Geometry::queryGeometry(const smtk::resource::PersistentObject::Ptr& obj, CacheEntry& entry) - const -{ - // Do not draw the model (its tessellation contains all meshes in the resource) - auto ent = std::dynamic_pointer_cast(obj); - if (!ent || ent->isModel()) - { - entry.m_generation = Invalid; - return; - } - - // Access the component's resource - auto resource = m_parent.lock(); - if (resource == nullptr) - { - entry.m_generation = Invalid; - return; - } - - // Access the model resource's associated mesh resource - smtk::mesh::Resource::Ptr meshResource = resource->resource(); - - // Access the model resource's associated topology - smtk::session::mesh::Topology* topology = resource->session()->topology(resource); - if (topology == nullptr) - { - entry.m_generation = Invalid; - return; - } - - // Access the component's associated topology element. - auto elementIt = topology->m_elements.find(obj->id()); - if (elementIt == topology->m_elements.end()) - { - // Auxiliary geometry is handled outside of the map used for other - // entity types. For instance, it may be procedural or parametric. - if (ent->isAuxiliaryGeometry()) - { - vtkSmartPointer cgeom; - smtk::model::AuxiliaryGeometry aux(ent); - smtk::common::Extension::visit( - [&cgeom, &aux](const std::string& /*unused*/, vtkAuxiliaryGeometryExtension::Ptr ext) - -> std::pair { - std::vector bbox; - if (ext->canHandleAuxiliaryGeometry(aux, bbox)) - { - cgeom = vtkAuxiliaryGeometryExtension::fetchCachedGeometry(aux); - return std::make_pair(true, true); - } - return std::make_pair(false, false); - }); - if (cgeom) - { - entry.m_geometry = cgeom; - ++entry.m_generation; - // If the object has color properties, apply them - if (obj->properties().contains>("color")) - { - Geometry::addColorArray( - entry.m_geometry, obj->properties().at>("color")); - } - return; - } - } - entry.m_generation = Invalid; - return; - } - Topology::Element& element = elementIt->second; - - // Access the element's associated meshset - smtk::mesh::MeshSet meshset = element.m_mesh; - - // Convert the meshest into a vtkPolyData - smtk::extension::vtk::io::mesh::ExportVTKData exportVTKData; - entry.m_geometry = vtkSmartPointer::New(); - exportVTKData(meshset, vtkPolyData::SafeDownCast(entry.m_geometry)); - ++entry.m_generation; - - // If the object has color properties, apply them - if (obj->properties().contains>("color")) - { - Geometry::addColorArray(entry.m_geometry, obj->properties().at>("color")); - } -} - -int Geometry::dimension(const smtk::resource::PersistentObject::Ptr& obj) const -{ - auto ent = std::dynamic_pointer_cast(obj); - if (ent) - { - // While the geometry may represent a 3-dimensional volume, the geometric - // representation is always a vtkPolyData, which has highest dimension 2. - // Unknown (-1) (like auxiliary geometry) also gets dimension 2. - return (ent->dimension() >= 0 && ent->dimension() <= 2 ? ent->dimension() : 2); - } - return 0; -} - -Geometry::Purpose Geometry::purpose(const smtk::resource::PersistentObject::Ptr& obj) const -{ - auto ent = std::dynamic_pointer_cast(obj); - if (ent) - { - return ent->isInstance() ? Geometry::Glyph : Geometry::Surface; - } - return Geometry::Surface; -} - -void Geometry::update() const -{ - // Do nothing. Mesh session operations set content as needed. -} - -void Geometry::geometricBounds(const DataType& geom, BoundingBox& bbox) const -{ - auto* pset = vtkPointSet::SafeDownCast(geom); - if (pset) - { - pset->GetBounds(bbox.data()); - return; - } - auto* comp = vtkCompositeDataSet::SafeDownCast(geom); - if (comp) - { - comp->GetBounds(bbox.data()); - return; - } - - // Invalid bounding box: - bbox[0] = bbox[2] = bbox[4] = 0.0; - bbox[1] = bbox[3] = bbox[5] = -1.0; -} -} // namespace vtk -} // namespace mesh -} // namespace session -} // namespace smtk diff --git a/smtk/session/mesh/vtk/Geometry.h b/smtk/session/mesh/vtk/Geometry.h deleted file mode 100644 index 6d3b6879dbd1ee7d6c0c1dea5e3731d544fda3e9..0000000000000000000000000000000000000000 --- a/smtk/session/mesh/vtk/Geometry.h +++ /dev/null @@ -1,87 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef smtk_session_mesh_vtk_Geometry_h -#define smtk_session_mesh_vtk_Geometry_h - -#include "smtk/session/mesh/Exports.h" - -#include "smtk/extension/vtk/geometry/Geometry.h" - -#include "smtk/geometry/Cache.h" -#include "smtk/geometry/Generator.h" - -#include "smtk/PublicPointerDefs.h" - -namespace smtk -{ -namespace session -{ -namespace mesh -{ - -class Resource; - -namespace vtk -{ - -/**\brief A VTK geometry provider for the mesh session. - * - */ -class SMTKMESHSESSION_EXPORT Geometry - : public smtk::geometry::Cache -{ -public: - using CacheBaseType = smtk::extension::vtk::geometry::Geometry; - smtkTypeMacro(smtk::session::mesh::vtk::Geometry); - smtkSuperclassMacro(smtk::geometry::Cache); - - Geometry(const std::shared_ptr& parent); - ~Geometry() override = default; - - smtk::geometry::Resource::Ptr resource() const override; - void queryGeometry(const smtk::resource::PersistentObject::Ptr& obj, CacheEntry& entry) - const override; - int dimension(const smtk::resource::PersistentObject::Ptr& obj) const override; - Purpose purpose(const smtk::resource::PersistentObject::Ptr& obj) const override; - void update() const override; - - void geometricBounds(const DataType&, BoundingBox& bbox) const override; - - std::weak_ptr m_parent; -}; -} // namespace vtk - -class SMTKMESHSESSION_EXPORT RegisterVTKBackend - : public smtk::geometry::Supplier -{ -public: - bool valid(const Specification& in) const override - { - smtk::extension::vtk::geometry::Backend backend; - return std::get<1>(in).index() == backend.index(); - } - - GeometryPtr operator()(const Specification& in) override - { - auto rsrc = std::dynamic_pointer_cast(std::get<0>(in)); - if (rsrc) - { - auto* provider = new vtk::Geometry(rsrc); - return GeometryPtr(provider); - } - throw std::invalid_argument("Not a mesh session resource."); - return nullptr; - } -}; -} // namespace mesh -} // namespace session -} // namespace smtk - -#endif diff --git a/smtk/session/oscillator/Registrar.h b/smtk/session/oscillator/Registrar.h index e1f96ed2ba2912ee6eb0b30f4e6d22faabb127ab..bc7e7c415d56ad67427f3b859b607d57abf3e6fc 100644 --- a/smtk/session/oscillator/Registrar.h +++ b/smtk/session/oscillator/Registrar.h @@ -13,7 +13,6 @@ #include "smtk/session/oscillator/Exports.h" #include "smtk/attribute/Registrar.h" -#include "smtk/mesh/resource/Registrar.h" #include "smtk/model/Registrar.h" #include "smtk/operation/Manager.h" #include "smtk/operation/Registrar.h" @@ -29,8 +28,7 @@ namespace oscillator class SMTKOSCILLATORSESSION_EXPORT Registrar { public: - using Dependencies = - std::tuple; + using Dependencies = std::tuple; static void registerTo(const smtk::operation::Manager::Ptr&); static void unregisterFrom(const smtk::operation::Manager::Ptr&); diff --git a/smtk/session/oscillator/operators/EditDomain.cxx b/smtk/session/oscillator/operators/EditDomain.cxx index ec01fa6994a7eb8910c96a1953b114542474fbdd..8e6ba82108e0c9918cce73229332d5a8135513ec 100644 --- a/smtk/session/oscillator/operators/EditDomain.cxx +++ b/smtk/session/oscillator/operators/EditDomain.cxx @@ -12,8 +12,6 @@ #include "smtk/session/oscillator/Resource.h" #include "smtk/session/oscillator/SimulationAttribute.h" -#include "smtk/session/mesh/operators/CreateUniformGrid.h" - #include "smtk/attribute/Attribute.h" #include "smtk/attribute/ComponentItem.h" #include "smtk/attribute/DoubleItem.h" @@ -27,11 +25,6 @@ #include "smtk/model/Tessellation.h" #include "smtk/model/Volume.h" -#include "smtk/mesh/core/CellTraits.h" -#include "smtk/mesh/core/CellTypes.h" - -#include "smtk/mesh/utility/Create.h" - #include "smtk/session/oscillator/operators/EditDomain_xml.h" namespace smtk diff --git a/smtk/session/oscillator/operators/EditSource.cxx b/smtk/session/oscillator/operators/EditSource.cxx index 5b4f69e29c66e9183ecc34069992618bd7c76d65..6ab3ebedda04b583d7f61651b65d454d596f5479 100644 --- a/smtk/session/oscillator/operators/EditSource.cxx +++ b/smtk/session/oscillator/operators/EditSource.cxx @@ -12,8 +12,6 @@ #include "smtk/session/oscillator/Resource.h" #include "smtk/session/oscillator/operators/EditSource_xml.h" -#include "smtk/session/mesh/operators/CreateUniformGrid.h" - #include "smtk/attribute/Attribute.h" #include "smtk/attribute/ComponentItem.h" #include "smtk/attribute/DoubleItem.h" diff --git a/smtk/session/polygon/Registrar.h b/smtk/session/polygon/Registrar.h index c619ae9abf4e66ed8307ce087ee17e4b4e0bc7f7..66f269c54ab7cfa2ed28d66b6544dfa6b98de2ba 100644 --- a/smtk/session/polygon/Registrar.h +++ b/smtk/session/polygon/Registrar.h @@ -13,7 +13,6 @@ #include "smtk/session/polygon/Exports.h" #include "smtk/attribute/Registrar.h" -#include "smtk/mesh/resource/Registrar.h" #include "smtk/model/Registrar.h" #include "smtk/operation/Manager.h" #include "smtk/operation/Registrar.h" @@ -29,8 +28,7 @@ namespace polygon class SMTKPOLYGONSESSION_EXPORT Registrar { public: - using Dependencies = - std::tuple; + using Dependencies = std::tuple; static void registerTo(const smtk::operation::Manager::Ptr&); static void unregisterFrom(const smtk::operation::Manager::Ptr&); diff --git a/smtk/session/polygon/operators/Import.cxx b/smtk/session/polygon/operators/Import.cxx index 029c2ee936b01035377753d8d7c7ed71ec372fe8..6ab38bfa81a67da49eefb9e114bfe24670701568 100644 --- a/smtk/session/polygon/operators/Import.cxx +++ b/smtk/session/polygon/operators/Import.cxx @@ -10,7 +10,7 @@ #include "Import.h" -#include "smtk/Options.h" // for SMTK_ENABLE_REMUS_SUPPORT +#include "smtk/Options.h" #include "smtk/session/polygon/Session.h" #include "smtk/session/polygon/internal/Model.h" diff --git a/smtk/session/polygon/operators/Import.h b/smtk/session/polygon/operators/Import.h index 5eaf9fc178473a6d92b8a3c99b204b64eda30968..1b867b9bc7c24a13ff6b337804a52cf49e3d6167 100644 --- a/smtk/session/polygon/operators/Import.h +++ b/smtk/session/polygon/operators/Import.h @@ -25,9 +25,6 @@ namespace polygon { /**\brief Import a CMB polygon model file. - * - * The supported file extensions currently: - * "Moab files (*.h5m *.sat *.brep *.stp *.cub *.exo) * * NOT YET: * "VTK data files (*.vtk *.vtu *.vtp) diff --git a/smtk/session/pybind11/__init__.py.in b/smtk/session/pybind11/__init__.py.in index 0e41496a1956535398c6796181e43fe1bd043d61..80f2728b2a55075fe6b4bc8b21d4e31b33ca1ee7 100644 --- a/smtk/session/pybind11/__init__.py.in +++ b/smtk/session/pybind11/__init__.py.in @@ -12,8 +12,6 @@ _sessions = [] -if @SMTK_MESH_SESSION_ENABLED@: - _sessions.append("mesh") if @SMTK_POLYGON_SESSION_ENABLED@: _sessions.append("polygon") if @SMTK_VTK_SESSION_ENABLED@: diff --git a/smtk/simulation/pybind11/PybindExportSpec.h b/smtk/simulation/pybind11/PybindExportSpec.h index 4a4523fa31ba444c01f43d3d6b9ff6e9106f6494..da1a5b09612c011249a925ed77783bd25beb1c4b 100644 --- a/smtk/simulation/pybind11/PybindExportSpec.h +++ b/smtk/simulation/pybind11/PybindExportSpec.h @@ -15,7 +15,6 @@ #include "smtk/attribute/Resource.h" #include "smtk/io/Logger.h" -#include "smtk/model/GridInfo.h" #include "smtk/simulation/ExportSpec.h" #include diff --git a/smtk/task/testing/python/CMakeLists.txt b/smtk/task/testing/python/CMakeLists.txt index 8d3b6fda305a5dc64c0fd68da9feb6ddb8a4db12..3f480c6c0bff6356b968182037316743dafaf683 100644 --- a/smtk/task/testing/python/CMakeLists.txt +++ b/smtk/task/testing/python/CMakeLists.txt @@ -14,7 +14,7 @@ foreach (test ${smtkTaskPythonTests}) smtk_add_test_python(${test}Py ${test}.py --temp-dir=${CMAKE_BINARY_DIR}/Testing/Temporary) endforeach() -#only run these tests if we have a valid data directory and we have a moab +#only run these tests if we have a valid data directory #built with hdf5 if (SMTK_DATA_DIR) foreach (test ${smtkTaskPythonDataTests}) diff --git a/smtk/view/ComponentPhraseContent.cxx b/smtk/view/ComponentPhraseContent.cxx index 8dd352cf2165a9d0dff408be99cef540fd17abc8..1b48e03f578bcfdf202da77026c0d8d4393b5961 100644 --- a/smtk/view/ComponentPhraseContent.cxx +++ b/smtk/view/ComponentPhraseContent.cxx @@ -20,11 +20,6 @@ #include "smtk/graph/Component.h" -#include "smtk/mesh/core/CellSet.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/MeshSet.h" -#include "smtk/mesh/operators/SetMeshName.h" - #include "smtk/model/Entity.h" #include "smtk/model/EntityRef.h" @@ -89,10 +84,9 @@ bool ComponentPhraseContent::editable(ContentType contentType) const if (auto component = m_component.lock()) { auto modelComponent = dynamic_pointer_cast(component); - auto meshComponent = dynamic_pointer_cast(component); auto graphComponent = dynamic_pointer_cast(component); - // Models, meshes and graphs may be assigned a name. - return !!modelComponent || !!meshComponent || !!graphComponent; + // Models and graphs may be assigned a name. + return !!modelComponent || !!graphComponent; } } } @@ -126,17 +120,6 @@ std::string ComponentPhraseContent::stringValue(ContentType contentType) const return attributeComponent->type(); } - auto meshComponent = component->as(); - if (meshComponent) - { - std::ostringstream meshSummary; - auto mesh = meshComponent->mesh(); - if (mesh.isValid()) - { - meshSummary << mesh.cells().size() << " cells"; - } - return meshSummary.str(); - } return std::string(); } break; diff --git a/smtk/view/Registrar.cxx b/smtk/view/Registrar.cxx index 51d87899e236d61c9c10667d64fc5c8d3f7073a2..4da261ecefeaf564caebb348ea79c4c922c21cb5 100644 --- a/smtk/view/Registrar.cxx +++ b/smtk/view/Registrar.cxx @@ -12,7 +12,6 @@ #include "smtk/view/Registrar.h" #include "smtk/attribute/Resource.h" -#include "smtk/mesh/core/Resource.h" #include "smtk/model/Resource.h" #include "smtk/plugin/Manager.h" @@ -78,7 +77,6 @@ void Registrar::registerTo(const smtk::view::Manager::Ptr& viewManager) ResourceIconConstructor()); viewManager->objectIcons().registerIconConstructor( AttributeIconConstructor()); - viewManager->objectIcons().registerIconConstructor(MeshIconConstructor()); viewManager->objectIcons().registerIconConstructor(ModelIconConstructor()); // Per-operation icons diff --git a/smtk/view/SVGIconConstructor.cxx b/smtk/view/SVGIconConstructor.cxx index f9a5d06f7d2cdb3f4b2b0d928882e416ddeafbee..40c515327805c52f05fd78e4bf1283fce246d83e 100644 --- a/smtk/view/SVGIconConstructor.cxx +++ b/smtk/view/SVGIconConstructor.cxx @@ -14,10 +14,9 @@ #include "smtk/common/Color.h" -#include "smtk/mesh/core/Resource.h" - #include "smtk/model/Entity.h" #include "smtk/model/EntityTypeBits.h" +#include "smtk/model/Resource.h" #include "smtk/resource/PersistentObject.h" @@ -26,8 +25,6 @@ #include "smtk/view/icons/edge_cpp.h" #include "smtk/view/icons/face_cpp.h" #include "smtk/view/icons/loop_cpp.h" -#include "smtk/view/icons/meshResource_cpp.h" -#include "smtk/view/icons/mesh_cpp.h" #include "smtk/view/icons/modelResource_cpp.h" #include "smtk/view/icons/model_cpp.h" #include "smtk/view/icons/resource_cpp.h" @@ -100,19 +97,6 @@ std::string AttributeIconConstructor::svg(const smtk::resource::PersistentObject } } -std::string MeshIconConstructor::svg(const smtk::resource::PersistentObject& object) const -{ - if (const auto* resource = dynamic_cast(&object)) - { - (void)resource; - return meshResource_svg(); - } - else - { - return mesh_svg(); - } -} - std::string ModelIconConstructor::svg(const smtk::resource::PersistentObject& object) const { if (const auto* resource = dynamic_cast(&object)) diff --git a/smtk/view/SVGIconConstructor.h b/smtk/view/SVGIconConstructor.h index 43815c3430d79bb0cf7926dc23b7952f999081ed..eb51dc5a2b126a94d75973bf6fc0f5bd9e66db10 100644 --- a/smtk/view/SVGIconConstructor.h +++ b/smtk/view/SVGIconConstructor.h @@ -64,11 +64,6 @@ class SMTKCORE_EXPORT AttributeIconConstructor : public SVGIconConstructor std::string svg(const smtk::resource::PersistentObject&) const override; }; -class SMTKCORE_EXPORT MeshIconConstructor : public SVGIconConstructor -{ - std::string svg(const smtk::resource::PersistentObject&) const override; -}; - class SMTKCORE_EXPORT ModelIconConstructor : public SVGIconConstructor { std::string svg(const smtk::resource::PersistentObject&) const override; diff --git a/smtk/view/SubphraseGenerator.cxx b/smtk/view/SubphraseGenerator.cxx index d9da6d9c73f9f080b202fa2dc7e67c58ba2d56d9..808be1dbd67439c27aec9d64a1a6fbcc85fbc30e 100644 --- a/smtk/view/SubphraseGenerator.cxx +++ b/smtk/view/SubphraseGenerator.cxx @@ -25,9 +25,6 @@ #include "smtk/model/Resource.h" #include "smtk/model/UseEntity.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - #include "smtk/attribute/Attribute.h" #include "smtk/attribute/Resource.h" @@ -198,7 +195,6 @@ DescriptivePhrases SubphraseGenerator::subphrases(DescriptivePhrase::Ptr src) { auto attr = dynamic_pointer_cast(comp); auto modelEnt = dynamic_pointer_cast(comp); - // auto meshSet = dynamic_pointer_cast(comp); if (attr) { SubphraseGenerator::itemsOfAttribute(src, attr, result); @@ -207,10 +203,6 @@ DescriptivePhrases SubphraseGenerator::subphrases(DescriptivePhrase::Ptr src) { SubphraseGenerator::childrenOfModelEntity(src, modelEnt, result); } - // else if (meshSet) - // { - // SubphraseGenerator::subsetsOfMeshSet(src, meshSet, result); - // } } } return result; @@ -248,11 +240,6 @@ bool SubphraseGenerator::hasChildren(const DescriptivePhrase& src) const { return SubphraseGenerator::modelEntityHasChildren(modelEnt); } - // auto meshSet = dynamic_pointer_cast(comp); - // if (meshSet) - // { - // ??? - // } return false; } @@ -273,17 +260,12 @@ int MutabilityOfComponent(const T& comp) { constexpr int modelMutability = static_cast(smtk::view::PhraseContent::ContentType::TITLE) | static_cast(smtk::view::PhraseContent::ContentType::COLOR); - constexpr int meshMutability = static_cast(smtk::view::PhraseContent::ContentType::TITLE); constexpr int attrMutability = static_cast(smtk::view::PhraseContent::ContentType::TITLE); if (std::dynamic_pointer_cast(comp)) { return modelMutability; } - else if (std::dynamic_pointer_cast(comp)) - { - return meshMutability; - } else if (std::dynamic_pointer_cast(comp)) { return attrMutability; @@ -469,20 +451,18 @@ SubphraseGenerator::Path SubphraseGenerator::indexOfObjectInParent( smtk::resource::ResourcePtr rsrc; smtk::attribute::AttributePtr attr; - smtk::mesh::ComponentPtr mcmp; smtk::model::EntityPtr ment; bool added = false; // Determine if the component is a direct-ish child of parent if (!actualParent->relatedComponent() && actualParent->relatedResource()) { rsrc = comp->resource(); - // Attribute and mesh resources own all their components directly. + // Attribute resources own all their components directly. // Model resources have only _free_ models as direct children. if (rsrc == actualParent->relatedResource()) { if ( std::dynamic_pointer_cast(comp) || - std::dynamic_pointer_cast(comp) || ((ment = std::dynamic_pointer_cast(comp)) && ment->isModel() && !smtk::model::Model(ment).owningModel().isValid())) { @@ -491,8 +471,7 @@ SubphraseGenerator::Path SubphraseGenerator::indexOfObjectInParent( } else if ( !std::dynamic_pointer_cast(rsrc) && - !std::dynamic_pointer_cast(rsrc) && - !std::dynamic_pointer_cast(rsrc)) + !std::dynamic_pointer_cast(rsrc)) { // Resources of unknown type... plop all the components in the top-level PreparePath(result, parentPath, IndexFromTitle(comp->name(), actualParent->subphrases())); @@ -710,24 +689,6 @@ bool SubphraseGenerator::findSortedLocation( return false; } -bool SubphraseGenerator::findSortedLocation( - Path& pathOut, - smtk::mesh::ComponentPtr comp, - DescriptivePhrase::Ptr& phr, - const DescriptivePhrase::Ptr& parent) const -{ - (void)phr; - if (!comp || !parent || !parent->areSubphrasesBuilt()) - { - // If the user has not opened the parent phrase, do not - // add to it; when subphrases are generated later (on demand) - // they should include \a attr. - return false; - } - (void)pathOut; - return false; -} - void SubphraseGenerator::componentsOfResource( DescriptivePhrase::Ptr src, smtk::resource::ResourcePtr rsrc, @@ -735,7 +696,6 @@ void SubphraseGenerator::componentsOfResource( { auto modelRsrc = dynamic_pointer_cast(rsrc); auto attrRsrc = dynamic_pointer_cast(rsrc); - auto meshRsrc = dynamic_pointer_cast(rsrc); if (modelRsrc) { // By default, make model component names and colors editable but not visibility @@ -759,15 +719,6 @@ void SubphraseGenerator::componentsOfResource( result.push_back(ComponentPhraseContent::createPhrase(attr, mutability, src)); } } - else if (meshRsrc) - { - constexpr int mutability = static_cast(smtk::view::PhraseContent::ContentType::TITLE) | - static_cast(smtk::view::PhraseContent::ContentType::COLOR); - smtk::resource::Component::Visitor visitor = [&](const smtk::resource::Component::Ptr& entry) { - result.push_back(ComponentPhraseContent::createPhrase(entry, mutability, src)); - }; - meshRsrc->visit(visitor); - } else { // Some random resource... // By default, make names and colors editable but not visibility @@ -809,19 +760,13 @@ bool SubphraseGenerator::resourceHasChildren(const smtk::resource::ResourcePtr& return attrRsrc->hasAttributes(); } - auto meshRsrc = dynamic_pointer_cast(rsrc); - if (meshRsrc) - { - return (meshRsrc->numberOfMeshes() > 0); - } - else - { // Some random resource... - bool hasChild = false; - smtk::resource::Component::Visitor visitor = - [&hasChild](const smtk::resource::Component::Ptr&) { hasChild = true; }; - rsrc->visit(visitor); - return hasChild; - } + // Some random resource... + bool hasChild = false; + smtk::resource::Component::Visitor visitor = [&hasChild](const smtk::resource::Component::Ptr&) { + hasChild = true; + }; + rsrc->visit(visitor); + return hasChild; } void SubphraseGenerator::itemsOfAttribute( @@ -1196,69 +1141,6 @@ void SubphraseGenerator::modelsOfModelSession( this->addModelEntityPhrases(modelsOf, src, this->directLimit(), result); } -void SubphraseGenerator::meshesOfModelModel( - DescriptivePhrase::Ptr src, const Model& mod, DescriptivePhrases& result) -{ - std::vector meshResources = - mod.resource()->meshes()->associatedResources(mod); - // We need to sort the meshes before we add them to the result since if - // we sort the result itself we could be intermixing the mesh and model - // information - DescriptivePhrases meshPhrases; - addMeshPhrases(meshResources, src, this->directLimit(), meshPhrases); - std::sort(meshPhrases.begin(), meshPhrases.end(), DescriptivePhrase::compareByTitle); - result.insert(result.end(), meshPhrases.begin(), meshPhrases.end()); -} - -void SubphraseGenerator::meshsetsOfMesh(MeshPhrase::Ptr meshphr, DescriptivePhrases& result) -{ - smtk::mesh::MeshSet meshes = meshphr->relatedMesh(); - // if this is a mesh resource - if (meshphr->isResource()) - { - this->meshsetsOfResourceByDim(meshphr, smtk::mesh::Dims3, result); - this->meshsetsOfResourceByDim(meshphr, smtk::mesh::Dims2, result); - this->meshsetsOfResourceByDim(meshphr, smtk::mesh::Dims1, result); - this->meshsetsOfResourceByDim(meshphr, smtk::mesh::Dims0, result); - } - // if this is a MeshSet - else if (meshes.size() > 1) - { - // if the MeshSet contains more than one mesh, we need to create subphrases for - // each subset, otherwise the meshphr will represent the relatedMesh. - for (std::size_t i = 0; i < meshes.size(); ++i) - { - result.push_back(MeshPhraseContent::createPhrase(meshes.subset(i), meshphr)); - } - } -} - -void SubphraseGenerator::meshsetsOfResourceByDim( - MeshPhrase::Ptr meshphr, smtk::mesh::DimensionType dim, DescriptivePhrases& result) -{ - if (meshphr->isResource()) - { - smtk::mesh::ResourcePtr meshresource = meshphr->relatedMeshResource(); - smtk::mesh::MeshSet dimMeshes = meshresource->meshes(dim); - if (!dimMeshes.is_empty()) - { - result.push_back(MeshPhraseContent::createPhrase(dimMeshes, meshphr)); - } - } -} - -void SubphraseGenerator::meshesOfMeshList(MeshListPhrase::Ptr src, DescriptivePhrases& result) -{ - if (src->relatedResources().size() > 0) - { - addMeshPhrases(src->relatedResources(), src, this->directLimit(), result); - } - else if (src->relatedMeshes().size() > 0) - { - addMeshPhrases(src->relatedMeshes(), src, this->directLimit(), result); - } -} - /// Add subphrases (or a list of them) to \a result for the specified properties. void SubphraseGenerator::addEntityProperties( smtk::resource::PropertyType ptype, std::set& props, diff --git a/smtk/view/SubphraseGenerator.h b/smtk/view/SubphraseGenerator.h index bbdef31c2ceb7fa342f27671f82c8c7741aac131..4947492f5e50dbe6bea25bdabadc78cb9bd60d61 100644 --- a/smtk/view/SubphraseGenerator.h +++ b/smtk/view/SubphraseGenerator.h @@ -179,11 +179,6 @@ protected: smtk::model::EntityPtr entity, DescriptivePhrase::Ptr& phr, const DescriptivePhrase::Ptr& parent) const; - virtual bool findSortedLocation( - Path& pathOut, - smtk::mesh::ComponentPtr comp, - DescriptivePhrase::Ptr& phr, - const DescriptivePhrase::Ptr& parent) const; /// Return true if the resource would cause subphrases to be generated bool resourceHasChildren(const smtk::resource::ResourcePtr& rsrc) const; @@ -364,12 +359,6 @@ protected: void modelsOfModelSession( DescriptivePhrase::Ptr src, const SessionRef& sess, DescriptivePhrases& result); - void meshesOfModelModel(DescriptivePhrase::Ptr src, const Model& mod, DescriptivePhrases& result); - void meshsetsOfMesh(MeshPhrase::Ptr meshphr, DescriptivePhrases& result); - void meshesOfMeshList(MeshListPhrase::Ptr src, DescriptivePhrases& result); - void meshsetsOfCollectionByDim( - MeshPhrase::Ptr meshphr, smtk::mesh::DimensionType dim, DescriptivePhrases& result); - void addEntityProperties(smtk::resource::PropertyType ptype, std::set& props, DescriptivePhrase::Ptr parent, DescriptivePhrases& result); diff --git a/smtk/view/TwoLevelSubphraseGenerator.cxx b/smtk/view/TwoLevelSubphraseGenerator.cxx index ed6a67295957f2585ebe430a41dc72b2620eecbc..a7f07060fefcb87280efce26df7925ff488cbc92 100644 --- a/smtk/view/TwoLevelSubphraseGenerator.cxx +++ b/smtk/view/TwoLevelSubphraseGenerator.cxx @@ -32,9 +32,6 @@ #include "smtk/model/Vertex.h" #include "smtk/model/Volume.h" -#include "smtk/mesh/core/Component.h" -#include "smtk/mesh/core/Resource.h" - namespace smtk { namespace view @@ -139,7 +136,6 @@ void TwoLevelSubphraseGenerator::childrenOfResource( { auto modelRsrc = dynamic_pointer_cast(rsrc); auto attrRsrc = dynamic_pointer_cast(rsrc); - auto meshRsrc = dynamic_pointer_cast(rsrc); if (modelRsrc) { constexpr int mutability = static_cast(smtk::view::PhraseContent::ContentType::TITLE) | @@ -224,18 +220,6 @@ void TwoLevelSubphraseGenerator::childrenOfResource( } std::sort(result.begin(), result.end(), DescriptivePhrase::compareByTypeThenTitle); } - else if (meshRsrc) - { - constexpr int mutability = static_cast(smtk::view::PhraseContent::ContentType::TITLE); - smtk::resource::Component::Visitor visitor = [&](const smtk::resource::Component::Ptr& entry) { - if (entry) - { - result.push_back(ComponentPhraseContent::createPhrase(entry, mutability, src)); - } - }; - meshRsrc->visit(visitor); - std::sort(result.begin(), result.end(), DescriptivePhrase::compareByTypeThenTitle); - } } } // namespace view } // namespace smtk diff --git a/smtk/view/testing/cxx/unitOperationDecorator.cxx b/smtk/view/testing/cxx/unitOperationDecorator.cxx index 508392f29b30bcd38e3cb468df7d33019f4dfb2a..19473fd2ed3fbc3aeead6cc740366fe2f7db326d 100644 --- a/smtk/view/testing/cxx/unitOperationDecorator.cxx +++ b/smtk/view/testing/cxx/unitOperationDecorator.cxx @@ -18,21 +18,6 @@ #include "smtk/attribute/operators/Dissociate.h" #include "smtk/attribute/operators/Export.h" #include "smtk/attribute/operators/Import.h" -#include "smtk/mesh/operators/DeleteMesh.h" -#include "smtk/mesh/operators/ElevateMesh.h" -#include "smtk/mesh/operators/Export.h" -#include "smtk/mesh/operators/ExtractAdjacency.h" -#include "smtk/mesh/operators/ExtractByDihedralAngle.h" -#include "smtk/mesh/operators/ExtractSkin.h" -#include "smtk/mesh/operators/Import.h" -#include "smtk/mesh/operators/InterpolateOntoMesh.h" -#include "smtk/mesh/operators/MergeCoincidentPoints.h" -#include "smtk/mesh/operators/PrintMeshInformation.h" -#include "smtk/mesh/operators/SelectCells.h" -#include "smtk/mesh/operators/SetMeshName.h" -#include "smtk/mesh/operators/Subtract.h" -#include "smtk/mesh/operators/Transform.h" -#include "smtk/mesh/operators/UndoElevateMesh.h" #include "smtk/model/operators/AddAuxiliaryGeometry.h" #include "smtk/model/operators/AddImage.h" #include "smtk/model/operators/CompositeAuxiliaryGeometry.h" @@ -73,21 +58,6 @@ void testInitializerListCtor() wrap(), wrap(), wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), - wrap(), wrap(), wrap(), wrap(), @@ -101,7 +71,7 @@ void testInitializerListCtor() std::cout << " " << bar.m_toolTip.c_str() << "\n " << bar.m_buttonLabel.c_str() << "\n"; test(foo.first, "Expected to find operation."); test(bar.m_label == "edit group", "Failed to override name."); - test(decorator.size() == 31, "Expected to register 31 operations."); + test(decorator.size() == 16, "Expected to register 16 operations."); decorator.dump(); std::cout << std::type_index(typeid(smtk::operation::Operation)).hash_code() @@ -115,19 +85,6 @@ void testConfigurationCtor() // Operations we'll register with an operation manager: using OperationList = std::tuple< smtk::operation::AssignColors, - smtk::mesh::Export, - smtk::mesh::ExtractAdjacency, - smtk::mesh::ExtractByDihedralAngle, - smtk::mesh::ExtractSkin, - smtk::mesh::Import, - smtk::mesh::InterpolateOntoMesh, - smtk::mesh::MergeCoincidentPoints, - smtk::mesh::PrintMeshInformation, - smtk::mesh::SelectCells, - smtk::mesh::SetMeshName, - smtk::mesh::Subtract, - smtk::mesh::Transform, - smtk::mesh::UndoElevateMesh, smtk::operation::SetProperty, smtk::attribute::Associate, smtk::attribute::Dissociate, @@ -141,7 +98,7 @@ void testConfigurationCtor() std::string content(R"xml( - + choose color @@ -161,7 +118,7 @@ void testConfigurationCtor() // Test that the decorator was properly constructed. std::cout << "Configured " << decorator.size() << " operations.\n"; decorator.dump(); - test(decorator.size() == 14, "Expected 14 whitelisted operations."); + test(decorator.size() == 5, "Expected 5 whitelisted operations."); // Test that our override took effect. { @@ -173,16 +130,9 @@ void testConfigurationCtor() // Test that operations present but undecorated are filtered out: { - const auto& entry = decorator.at(); + const auto& entry = decorator.at(); test(!entry.first, "Found an operation that should be omitted."); } - - // Test that the regex included operations we expect. - { - const auto& entry = decorator.at(); - test(entry.first, "Expected to find mesh-transform operation."); - test(entry.second.get().m_label.empty(), "Expected empty overridde label."); - } } } // anonymous namespace diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index a908e6ed3dcefbf31f5e5449dd17ac394bf17a22..8e7b34b3458050e1347ace7c08412c9150b8fa12 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -1,32 +1,3 @@ # Don't perform clang-tidy on third party code. set(CMAKE_C_CLANG_TIDY "") set(CMAKE_CXX_CLANG_TIDY "") - -set(CMAKE_INSTALL_CMAKEDIR - "${SMTK_INSTALL_CONFIG_DIR}/Delaunay") -set(CMAKE_INSTALL_INCLUDEDIR - "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${SMTK_VERSION}") -add_subdirectory(delaunay) -unset(CMAKE_INSTALL_CMAKEDIR) - -# disable warning flags for delaunay. -option(SMTK_IGNORE_DELAUNAY_WARNINGS "disable warning flags for delaunay" ON) -mark_as_advanced(SMTK_IGNORE_DELAUNAY_WARNINGS) - -if (SMTK_IGNORE_DELAUNAY_WARNINGS) - set(ignore_rules_for_delaunay "") - - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - # disables: warning C4251: dll-interface warnings involving stl - set(ignore_rules_for_delaunay "${ignore_rules_for_delaunay} /wd4251") - elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") - # disables warnings for comparing integers of different types - set(ignore_rules_for_delaunay "${ignore_rules_for_delaunay} -Wno-sign-compare") - endif() - - foreach(delaunay_target DelaunayDiscretization DelaunayMesh DelaunayMisc - DelaunayShape DelaunayValidation DelaunayVisualization) - set_property(TARGET ${delaunay_target} APPEND_STRING - PROPERTY COMPILE_FLAGS ${ignore_rules_for_delaunay}) - endforeach() -endif() diff --git a/thirdparty/clpp/detail/argument_caster.hpp b/thirdparty/clpp/detail/argument_caster.hpp deleted file mode 100644 index ce7361dde83a4c4fc04490bd5033438782545ab0..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/argument_caster.hpp +++ /dev/null @@ -1,525 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_ARGUMENT_CASTER_HPP -#define CLPP_DETAIL_ARGUMENT_CASTER_HPP - -#include "misc.hpp" - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -/// \struct argument_caster -/// \brief Cast type of user's function argument (corresponding to parameter with value). -struct argument_caster { -public: - void call_func_with_inputed_arg( const any& arg - , const std::string& name - , const std::string& value ) const { - if ( argument_must_be_bool( arg ) ) { call_with_bool_arg( arg, name, value ); } - else if ( argument_must_be_char( arg ) ) { call_with_char_arg( arg, name, value ); } - else if ( argument_must_be_signed_char( arg ) ) { call_with_signed_char_arg( arg, name, value ); } - else if ( argument_must_be_unsigned_char( arg ) ) { call_with_unsigned_char_arg( arg, name, value ); } - else if ( argument_must_be_int( arg ) ) { call_with_int_arg( arg, name, value ); } - else if ( argument_must_be_signed_int( arg ) ) { call_with_signed_int_arg( arg, name, value ); } - else if ( argument_must_be_unsigned_int( arg ) ) { call_with_unsigned_int_arg( arg, name, value ); } - else if ( argument_must_be_short_int( arg ) ) { call_with_short_int_arg( arg, name, value ); } - else if ( argument_must_be_long_int( arg ) ) { call_with_long_int_arg( arg, name, value ); } - else if ( argument_must_be_unsigned_long_int( arg ) ) { call_with_unsigned_long_int_arg( arg, name, value ); } - else if ( argument_must_be_unsigned_short_int( arg ) ) { call_with_unsigned_short_int_arg( arg, name, value ); } - else if ( argument_must_be_signed_long_int( arg ) ) { call_with_signed_long_int_arg( arg, name, value ); } - else if ( argument_must_be_signed_short_int( arg ) ) { call_with_signed_short_int_arg( arg, name, value ); } - else if ( argument_must_be_float( arg ) ) { call_with_float_arg( arg, name, value ); } - else if ( argument_must_be_double( arg ) ) { call_with_double_arg( arg, name, value ); } - else if ( argument_must_be_long_double( arg ) ) { call_with_long_double_arg( arg, name, value ); } - else if ( argument_must_be_string( arg ) ) { call_with_string_arg( arg, name, value ); } - else { - notify_about_unsupported_type( name ); - } - } - - void call_func_with_default_arg( const any& arg ) const { - if ( argument_must_be_bool( arg ) ) { call_with_bool_arg( arg ); } - else if ( argument_must_be_char( arg ) ) { call_with_char_arg( arg ); } - else if ( argument_must_be_signed_char( arg ) ) { call_with_signed_char_arg( arg ); } - else if ( argument_must_be_unsigned_char( arg ) ) { call_with_unsigned_char_arg( arg ); } - else if ( argument_must_be_int( arg ) ) { call_with_int_arg( arg ); } - else if ( argument_must_be_signed_int( arg ) ) { call_with_signed_int_arg( arg ); } - else if ( argument_must_be_unsigned_int( arg ) ) { call_with_unsigned_int_arg( arg ); } - else if ( argument_must_be_short_int( arg ) ) { call_with_short_int_arg( arg ); } - else if ( argument_must_be_long_int( arg ) ) { call_with_long_int_arg( arg ); } - else if ( argument_must_be_unsigned_long_int( arg ) ) { call_with_unsigned_long_int_arg( arg ); } - else if ( argument_must_be_unsigned_short_int( arg ) ) { call_with_unsigned_short_int_arg( arg ); } - else if ( argument_must_be_signed_long_int( arg ) ) { call_with_signed_long_int_arg( arg ); } - else if ( argument_must_be_signed_short_int( arg ) ) { call_with_signed_short_int_arg( arg ); } - else if ( argument_must_be_float( arg ) ) { call_with_float_arg( arg ); } - else if ( argument_must_be_double( arg ) ) { call_with_double_arg( arg ); } - else if ( argument_must_be_long_double( arg ) ) { call_with_long_double_arg( arg ); } - else if ( argument_must_be_string( arg ) ) { call_with_string_arg( arg ); } - } - - void store_default_value( const any& arg - , const any& value - , const std::string& name ) const { - if ( argument_must_be_bool( arg ) ) { store_bool_value( arg, value, name ); } - else if ( argument_must_be_char( arg ) ) { store_char_value( arg, value, name ); } - else if ( argument_must_be_signed_char( arg ) ) { store_signed_char_value( arg, value, name ); } - else if ( argument_must_be_unsigned_char( arg ) ) { store_unsigned_char_value( arg, value, name ); } - else if ( argument_must_be_int( arg ) ) { store_int_value( arg, value, name ); } - else if ( argument_must_be_signed_int( arg ) ) { store_signed_int_value( arg, value, name ); } - else if ( argument_must_be_unsigned_int( arg ) ) { store_unsigned_int_value( arg, value, name ); } - else if ( argument_must_be_short_int( arg ) ) { store_short_int_value( arg, value, name ); } - else if ( argument_must_be_long_int( arg ) ) { store_long_int_value( arg, value, name ); } - else if ( argument_must_be_unsigned_long_int( arg ) ) { store_unsigned_long_int_value( arg, value, name ); } - else if ( argument_must_be_unsigned_short_int( arg ) ) { store_unsigned_short_int_value( arg, value, name ); } - else if ( argument_must_be_signed_long_int( arg ) ) { store_signed_long_int_value( arg, value, name ); } - else if ( argument_must_be_signed_short_int( arg ) ) { store_signed_short_int_value( arg, value, name ); } - else if ( argument_must_be_float( arg ) ) { store_float_value( arg, value, name ); } - else if ( argument_must_be_double( arg ) ) { store_double_value( arg, value, name ); } - else if ( argument_must_be_long_double( arg ) ) { store_long_double_value( arg, value, name ); } - else if ( argument_must_be_string( arg ) ) { store_string_value( arg, value, name ); } - else { - notify_about_unsupported_type( name ); - } - } -private: - bool argument_must_be_bool( const any& arg ) const { return typeid( b_arg_p ) == arg.type(); } - bool argument_must_be_char( const any& arg ) const { return typeid( c_arg_p ) == arg.type(); } - bool argument_must_be_signed_char( const any& arg ) const { return typeid( sc_arg_p ) == arg.type(); } - bool argument_must_be_unsigned_char( const any& arg ) const { return typeid( uc_arg_p ) == arg.type(); } - bool argument_must_be_int( const any& arg ) const { return typeid( i_arg_p ) == arg.type(); } - bool argument_must_be_signed_int( const any& arg ) const { return typeid( si_arg_p ) == arg.type(); } - bool argument_must_be_unsigned_int( const any& arg ) const { return typeid( ui_arg_p ) == arg.type(); } - bool argument_must_be_short_int( const any& arg ) const { return typeid( shi_arg_p ) == arg.type(); } - bool argument_must_be_long_int( const any& arg ) const { return typeid( li_arg_p ) == arg.type(); } - bool argument_must_be_unsigned_long_int( const any& arg ) const { return typeid( uli_arg_p ) == arg.type(); } - bool argument_must_be_unsigned_short_int( const any& arg ) const { return typeid( ushi_arg_p ) == arg.type(); } - bool argument_must_be_signed_long_int( const any& arg ) const { return typeid( sli_arg_p ) == arg.type(); } - bool argument_must_be_signed_short_int( const any& arg ) const { return typeid( sshi_arg_p ) == arg.type(); } - bool argument_must_be_float( const any& arg ) const { return typeid( f_arg_p ) == arg.type(); } - bool argument_must_be_double( const any& arg ) const { return typeid( d_arg_p ) == arg.type(); } - bool argument_must_be_long_double( const any& arg ) const { return typeid( ld_arg_p ) == arg.type(); } -public: - bool argument_must_be_string( const any& arg ) const { return typeid( s_arg_p ) == arg.type(); } -private: - void call_with_bool_arg( - const any& arg, const std::string& name, const std::string& value ) const { - b_arg_p p = boost::any_cast< b_arg_p >( arg ); - call< bool >( value, name, p ); - } - - void call_with_char_arg( - const any& arg, const std::string& name, const std::string& value ) const { - c_arg_p p = boost::any_cast< c_arg_p >( arg ); - call< char >( value, name, p ); - } - - void call_with_signed_char_arg( - const any& arg, const std::string& name, const std::string& value ) const { - sc_arg_p p = boost::any_cast< sc_arg_p >( arg ); - call< signed char >( value, name, p ); - } - - void call_with_unsigned_char_arg( - const any& arg, const std::string& name, const std::string& value ) const { - uc_arg_p p = boost::any_cast< uc_arg_p >( arg ); - call< unsigned char >( value, name, p ); - } - - void call_with_int_arg( - const any& arg, const std::string& name, const std::string& value ) const { - i_arg_p p = boost::any_cast< i_arg_p >( arg ); - call< int >( value, name, p ); - } - - void call_with_signed_int_arg( - const any& arg, const std::string& name, const std::string& value ) const { - si_arg_p p = boost::any_cast< si_arg_p >( arg ); - call< signed int >( value, name, p ); - } - - void call_with_unsigned_int_arg( - const any& arg, const std::string& name, const std::string& value ) const { - ui_arg_p p = boost::any_cast< ui_arg_p >( arg ); - call< unsigned int >( value, name, p ); - } - - void call_with_short_int_arg( - const any& arg, const std::string& name, const std::string& value ) const { - shi_arg_p p = boost::any_cast< shi_arg_p >( arg ); - call< short int >( value, name, p ); - } - - void call_with_long_int_arg( - const any& arg, const std::string& name, const std::string& value ) const { - li_arg_p p = boost::any_cast< li_arg_p >( arg ); - call< long int >( value, name, p ); - } - - void call_with_unsigned_long_int_arg( - const any& arg, const std::string& name, const std::string& value ) const { - uli_arg_p p = boost::any_cast< uli_arg_p >( arg ); - call< unsigned long int >( value, name, p ); - } - - void call_with_unsigned_short_int_arg( - const any& arg, const std::string& name, const std::string& value ) const { - ushi_arg_p p = boost::any_cast< ushi_arg_p >( arg ); - call< unsigned short int >( value, name, p ); - } - - void call_with_signed_long_int_arg( - const any& arg, const std::string& name, const std::string& value ) const { - sli_arg_p p = boost::any_cast< sli_arg_p >( arg ); - call< signed long int >( value, name, p ); - } - - void call_with_signed_short_int_arg( - const any& arg, const std::string& name, const std::string& value ) const { - sshi_arg_p p = boost::any_cast< sshi_arg_p >( arg ); - call< signed short int >( value, name, p ); - } - - void call_with_float_arg( - const any& arg, const std::string& name, const std::string& value ) const { - f_arg_p p = boost::any_cast< f_arg_p >( arg ); - call< float >( value, name, p ); - } - - void call_with_double_arg( - const any& arg, const std::string& name, const std::string& value ) const { - d_arg_p p = boost::any_cast< d_arg_p >( arg ); - call< double >( value, name, p ); - } - - void call_with_long_double_arg( - const any& arg, const std::string& name, const std::string& value ) const { - ld_arg_p p = boost::any_cast< ld_arg_p >( arg ); - call< long double >( value, name, p ); - } - - void call_with_string_arg( - const any& arg, const std::string& name, const std::string& value ) const { - s_arg_p p = boost::any_cast< s_arg_p >( arg ); - call< std::string >( value, name, p ); - } -private: - template - < - typename ArgType - , typename ArgHolderType - > - void call( const std::string& inputed_value - , const std::string& parameter_name - , ArgHolderType& holder ) const { - ArgType argument; - try { - argument = boost::lexical_cast< ArgType >( inputed_value ); - } catch ( const std::exception& /* exc */ ) { - notify_about_error_type< ArgType >( parameter_name ); - } - holder->func_with_arg( argument ); - } -private: - void call_with_bool_arg( const any& arg ) const { - b_arg_p p = boost::any_cast< b_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_char_arg( const any& arg ) const { - c_arg_p p = boost::any_cast< c_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_signed_char_arg( const any& arg ) const { - sc_arg_p p = boost::any_cast< sc_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_unsigned_char_arg( const any& arg ) const { - uc_arg_p p = boost::any_cast< uc_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_int_arg( const any& arg ) const { - i_arg_p p = boost::any_cast< i_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_signed_int_arg( const any& arg ) const { - si_arg_p p = boost::any_cast< si_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_unsigned_int_arg( const any& arg ) const { - ui_arg_p p = boost::any_cast< ui_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_short_int_arg( const any& arg ) const { - shi_arg_p p = boost::any_cast< shi_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_long_int_arg( const any& arg ) const { - li_arg_p p = boost::any_cast< li_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_unsigned_long_int_arg( const any& arg ) const { - uli_arg_p p = boost::any_cast< uli_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_unsigned_short_int_arg( const any& arg ) const { - ushi_arg_p p = boost::any_cast< ushi_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_signed_long_int_arg( const any& arg ) const { - sli_arg_p p = boost::any_cast< sli_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_signed_short_int_arg( const any& arg ) const { - sshi_arg_p p = boost::any_cast< sshi_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_float_arg( const any& arg ) const { - f_arg_p p = boost::any_cast< f_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_double_arg( const any& arg ) const { - d_arg_p p = boost::any_cast< d_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_long_double_arg( const any& arg ) const { - ld_arg_p p = boost::any_cast< ld_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } - - void call_with_string_arg( const any& arg ) const { - s_arg_p p = boost::any_cast< s_arg_p >( arg ); - p->func_with_arg( p->default_value ); - } -private: - void store_bool_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - b_arg_p p = boost::any_cast< b_arg_p >( arg ); - store< bool >( inputed_value, p, parameter_name ); - } - - void store_char_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - c_arg_p p = boost::any_cast< c_arg_p >( arg ); - store< char >( inputed_value, p, parameter_name ); - } - - void store_signed_char_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - sc_arg_p p = boost::any_cast< sc_arg_p >( arg ); - store< signed char >( inputed_value, p, parameter_name ); - } - - void store_unsigned_char_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - uc_arg_p p = boost::any_cast< uc_arg_p >( arg ); - store< unsigned char >( inputed_value, p, parameter_name ); - } - - void store_int_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - i_arg_p p = boost::any_cast< i_arg_p >( arg ); - store< int >( inputed_value, p, parameter_name ); - } - - void store_signed_int_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - si_arg_p p = boost::any_cast< si_arg_p >( arg ); - store< signed int >( inputed_value, p, parameter_name ); - } - - void store_unsigned_int_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - ui_arg_p p = boost::any_cast< ui_arg_p >( arg ); - store< unsigned int >( inputed_value, p, parameter_name ); - } - - void store_short_int_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - shi_arg_p p = boost::any_cast< shi_arg_p >( arg ); - store< short int >( inputed_value, p, parameter_name ); - } - - void store_long_int_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - li_arg_p p = boost::any_cast< li_arg_p >( arg ); - store< long int >( inputed_value, p, parameter_name ); - } - - void store_unsigned_short_int_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - ushi_arg_p p = boost::any_cast< ushi_arg_p >( arg ); - store< unsigned short int >( inputed_value, p, parameter_name ); - } - - void store_unsigned_long_int_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - uli_arg_p p = boost::any_cast< uli_arg_p >( arg ); - store< unsigned long int >( inputed_value, p, parameter_name ); - } - - void store_signed_short_int_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - sshi_arg_p p = boost::any_cast< sshi_arg_p >( arg ); - store< signed short int >( inputed_value, p, parameter_name ); - } - - void store_signed_long_int_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - sli_arg_p p = boost::any_cast< sli_arg_p >( arg ); - store< signed long int >( inputed_value, p, parameter_name ); - } - - void store_float_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - f_arg_p p = boost::any_cast< f_arg_p >( arg ); - store< float >( inputed_value, p, parameter_name ); - } - - void store_double_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - d_arg_p p = boost::any_cast< d_arg_p >( arg ); - store< double >( inputed_value, p, parameter_name ); - } - - void store_long_double_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - ld_arg_p p = boost::any_cast< ld_arg_p >( arg ); - store< long double >( inputed_value, p, parameter_name ); - } - - void store_string_value( const any& arg - , const any& inputed_value - , const std::string& parameter_name ) const { - s_arg_p p = boost::any_cast< s_arg_p >( arg ); - store< std::string >( inputed_value, p, parameter_name ); - } -private: - template - < - typename ArgType - , typename ArgHolderType - > - void store( const any& inputed_value, ArgHolderType& holder, const std::string& parameter_name ) const { - if ( typeid( ArgType ) == inputed_value.type() ) { - holder->default_value = boost::any_cast< ArgType >( inputed_value ); - } else { - notify_about_error_type_of_default_value< ArgType >( parameter_name ); - } - } -private: - template< typename ArgType > - void notify_about_error_type( const std::string& parameter_name ) const { - const std::string what_happened = lib_prefix() - + "Value's type for parameter '" + parameter_name - + "' must be <" + get_type_identifier< ArgType >() + ">!" - ; - throw std::invalid_argument( what_happened ); - } - - template< typename ArgType > - void notify_about_error_type_of_default_value( const std::string& parameter_name ) const { - const std::string what_happened = lib_prefix() - + "Default value's type for parameter '" + parameter_name - + "' must be <" + get_type_identifier< ArgType >() + ">!" - ; - throw std::invalid_argument( what_happened ); - } - - template< typename ArgType > - std::string get_type_identifier() const { - std::string identifier; - - if ( typeid( ArgType ) == typeid( bool ) ) { identifier = "bool"; } - else if ( typeid( ArgType ) == typeid( char ) ) { identifier = "char"; } - else if ( typeid( ArgType ) == typeid( signed char ) ) { identifier = "signed char"; } - else if ( typeid( ArgType ) == typeid( unsigned char ) ) { identifier = "unsigned char"; } - else if ( typeid( ArgType ) == typeid( int ) ) { identifier = "int"; } - else if ( typeid( ArgType ) == typeid( signed int ) ) { identifier = "signed int"; } - else if ( typeid( ArgType ) == typeid( unsigned int ) ) { identifier = "unsigned int"; } - else if ( typeid( ArgType ) == typeid( short int ) ) { identifier = "short int"; } - else if ( typeid( ArgType ) == typeid( long int ) ) { identifier = "long int"; } - else if ( typeid( ArgType ) == typeid( unsigned long int ) ) { identifier = "unsigned long int"; } - else if ( typeid( ArgType ) == typeid( unsigned short int ) ) { identifier = "unsigned short int"; } - else if ( typeid( ArgType ) == typeid( signed long int ) ) { identifier = "signed long int"; } - else if ( typeid( ArgType ) == typeid( signed short int ) ) { identifier = "signed short int"; } - else if ( typeid( ArgType ) == typeid( float ) ) { identifier = "float"; } - else if ( typeid( ArgType ) == typeid( double ) ) { identifier = "double"; } - else if ( typeid( ArgType ) == typeid( long double ) ) { identifier = "long double"; } - else if ( typeid( ArgType ) == typeid( std::string ) ) { identifier = "std::string"; } - - return identifier; - } - - void notify_about_unsupported_type( const std::string& parameter_name ) const { - const std::string what_happened = "Parameter '" - + parameter_name - + "' registered with function having argument's unsupported type!"; - throw std::invalid_argument( what_happened ); - } -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_ARGUMENT_CASTER_HPP diff --git a/thirdparty/clpp/detail/argument_holder.hpp b/thirdparty/clpp/detail/argument_holder.hpp deleted file mode 100644 index 6d5f0ee96fd44be7bbb6473de988fbc9e5f078b1..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/argument_holder.hpp +++ /dev/null @@ -1,96 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_ARGUMENT_HOLDER_HPP -#define CLPP_DETAIL_ARGUMENT_HOLDER_HPP - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#include -#include -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -#include - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -/// \struct argument_holder -/// \brief Argument's info holder. -/// -/// Hold ptr to function with arguments (corresponding to parameter with value), -/// and default value for it (if defined). -template< typename ArgType > -struct argument_holder { - typedef boost::function< void ( const ArgType& /* value */ ) > - user_function_with_arg; -public: - explicit argument_holder( void (*fn)( ArgType ) ) : - func_with_arg( fn ) {} - - template< typename Object > - explicit argument_holder( Object* obj, void ( Object::*fn )( ArgType ) ) : - func_with_arg( boost::bind( fn, obj, _1 ) ) {} - - template< typename Object > - explicit argument_holder( Object* obj, void ( Object::*fn )( ArgType ) const ) : - func_with_arg( boost::bind( fn, obj, _1 ) ) {} -public: - user_function_with_arg func_with_arg; - typename boost::remove_reference::type default_value; -}; - -typedef boost::shared_ptr< argument_holder< bool > > b_arg_p; - -typedef boost::shared_ptr< argument_holder< char > > c_arg_p; -typedef boost::shared_ptr< argument_holder< signed char > > sc_arg_p; -typedef boost::shared_ptr< argument_holder< unsigned char > > uc_arg_p; -typedef boost::shared_ptr< argument_holder< const char* > > cca_arg_p; - -typedef boost::shared_ptr< argument_holder< int > > i_arg_p; -typedef boost::shared_ptr< argument_holder< signed int > > si_arg_p; -typedef boost::shared_ptr< argument_holder< unsigned int > > ui_arg_p; -typedef boost::shared_ptr< argument_holder< short int > > shi_arg_p; -typedef boost::shared_ptr< argument_holder< long int > > li_arg_p; -typedef boost::shared_ptr< argument_holder< unsigned long int > > uli_arg_p; -typedef boost::shared_ptr< argument_holder< unsigned short int > > ushi_arg_p; -typedef boost::shared_ptr< argument_holder< signed long int > > sli_arg_p; -typedef boost::shared_ptr< argument_holder< signed short int > > sshi_arg_p; - -typedef boost::shared_ptr< argument_holder< float > > f_arg_p; -typedef boost::shared_ptr< argument_holder< double > > d_arg_p; -typedef boost::shared_ptr< argument_holder< long double > > ld_arg_p; - -typedef boost::shared_ptr< argument_holder< std::string > > s_arg_p; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_ARGUMENT_HOLDER_HPP diff --git a/thirdparty/clpp/detail/checkers/all.hpp b/thirdparty/clpp/detail/checkers/all.hpp deleted file mode 100644 index 183ff1557e48cc51072d4e4b1500c9095b294fb0..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/checkers/all.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_ALL_CHECKERS_HPP -#define CLPP_DETAIL_ALL_CHECKERS_HPP - -#include "common_checker.hpp" -#include "incorrect_parameters.hpp" -#include "necessary_parameters.hpp" -#include "parameters_existence.hpp" -#include "parameters_repetition.hpp" -#include "parameters_redundancy.hpp" -#include "values_correction.hpp" -#include "values_semantic.hpp" - -#endif // CLPP_DETAIL_ALL_CHECKERS_HPP diff --git a/thirdparty/clpp/detail/checkers/common_checker.hpp b/thirdparty/clpp/detail/checkers/common_checker.hpp deleted file mode 100644 index dfd14ba62dd73bd545ac6bafe537208eec0879c3..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/checkers/common_checker.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_COMMON_CHECKER_HPP -#define CLPP_DETAIL_COMMON_CHECKER_HPP - -#include "../types.hpp" - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -/// \struct common_checker -/// \brief Superclass for all checkers. -/// -/// Need for polymorphic use of checkers. Parameterized for "file independence". -template -< - typename Parameters - , typename Extractor - , typename Separator -> -struct common_checker { - common_checker( const Parameters& _registered_parameters - , const Extractor& _extractor - , const Separator& _name_value_separator ) : - registered_parameters( _registered_parameters ) - , extractor( _extractor ) - , name_value_separator( _name_value_separator ) {} -public: - const Parameters& registered_parameters; - const Extractor& extractor; - const Separator& name_value_separator; -public: - virtual void check( const str_storage& inputed_parameters ) const = 0; -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_COMMON_CHECKER_HPP diff --git a/thirdparty/clpp/detail/checkers/incorrect_parameters.hpp b/thirdparty/clpp/detail/checkers/incorrect_parameters.hpp deleted file mode 100644 index 60feb45c9057478ae1968bee393b2964d02fe56e..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/checkers/incorrect_parameters.hpp +++ /dev/null @@ -1,103 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_INCORRECT_PARAMETERS_HPP -#define CLPP_DETAIL_INCORRECT_PARAMETERS_HPP - -#include "common_checker.hpp" -#include "../parameter.hpp" -#include "../parameter_parts_extractor.hpp" - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -typedef common_checker< parameters, parameter_parts_extractor, std::string > checker; - -using namespace boost::assign; - -/// \class incorrect_parameters_checker -/// \brief Incorrect parameters checker. -/// -/// Checks existence of incorrect parameters. -/// Assumed that only registered parameters can be inputed. -class incorrect_parameters_checker : public checker { -public: - incorrect_parameters_checker( const parameters& registered_parameters - , const parameter_parts_extractor& extractor - , const std::string& name_value_separator ) : - checker( registered_parameters, extractor, name_value_separator ) {} -public: - void check( const str_storage& inputed_parameters ) const { - str_storage names_of_incorrect_parameters; - collect_names_of_incorrect_parameters_if_such_exists( inputed_parameters, names_of_incorrect_parameters ); - if ( !names_of_incorrect_parameters.empty() ) { - notify_about_incorrect_parameters( names_of_incorrect_parameters ); - } else {} - } -private: - void collect_names_of_incorrect_parameters_if_such_exists( const str_storage& inputed_parameters - , str_storage& names_of_incorrect_parameters ) const { - BOOST_FOREACH ( const std::string& inputed_parameter, inputed_parameters ) { - const std::string name = extractor.extract_name_from( inputed_parameter ); - parameter_const_it it = std::find( registered_parameters.begin() - , registered_parameters.end() - , name ); - if ( registered_parameters.end() == it ) { - names_of_incorrect_parameters += name; - } else {} - } - } - - void notify_about_incorrect_parameters( const str_storage& names_of_incorrect_parameters ) const { - std::string what_happened = lib_prefix() + "Parameter "; - - BOOST_FOREACH ( const std::string& name, names_of_incorrect_parameters ) { - what_happened += "'" + name + "', "; - } - boost::erase_last( what_happened, ", " ); - - if ( 1 == names_of_incorrect_parameters.size() ) { - what_happened += " is incorrect (no such parameter)!"; - } else { - boost::replace_first( what_happened, "Parameter", "Parameters" ); - what_happened += " are incorrect (no such parameters)!"; - } - - throw std::runtime_error( what_happened ); - } -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_INCORRECT_PARAMETERS_HPP diff --git a/thirdparty/clpp/detail/checkers/necessary_parameters.hpp b/thirdparty/clpp/detail/checkers/necessary_parameters.hpp deleted file mode 100644 index 9e42116a7dbcb16da15e6a84de66319588f11d12..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/checkers/necessary_parameters.hpp +++ /dev/null @@ -1,107 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_NECESSARY_PARAMETERS_HPP -#define CLPP_DETAIL_NECESSARY_PARAMETERS_HPP - -#include "common_checker.hpp" -#include "../parameter.hpp" -#include "../parameter_parts_extractor.hpp" - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -typedef common_checker< parameters, parameter_parts_extractor, std::string > checker; - -using namespace boost::assign; - -/// \class necessary_parameters_checker -/// \brief Necessary parameters existence checker. -/// -/// Checks existence of parameters that registered as necessary. -class necessary_parameters_checker : public checker { -public: - necessary_parameters_checker( const parameters& registered_parameters - , const parameter_parts_extractor& extractor - , const std::string& name_value_separator ) : - checker( registered_parameters, extractor, name_value_separator ) {} -public: - void check( const str_storage& inputed_parameters ) const { - str_storage names_that_should_be = collect_names_of_necessary_parameters(); - remove_names_of_inputed_necessary_parameters( inputed_parameters, names_that_should_be ); - if ( !names_that_should_be.empty() ) { - notify_about_missing_of_necessary_parameters( names_that_should_be ); - } else {} - } -private: - str_storage collect_names_of_necessary_parameters() const { - str_storage names; - BOOST_FOREACH ( const parameter& registered_parameter, registered_parameters ) { - if ( registered_parameter.is_necessary ) { - names += registered_parameter.short_name; - } else {} - } - return names; - } - - void remove_names_of_inputed_necessary_parameters( const str_storage& inputed_parameters - , str_storage& names_that_should_be ) const { - BOOST_FOREACH ( const std::string& inputed_parameter, inputed_parameters ) { - const std::string name = extractor.extract_name_from( inputed_parameter ); - detail::delete_element( names_that_should_be, name ); - } - } - - void notify_about_missing_of_necessary_parameters( const str_storage& names_that_should_be ) const { - std::string what_happened = lib_prefix() + "Parameter "; - - BOOST_FOREACH ( const std::string& name, names_that_should_be ) { - what_happened += "'" + name + "', "; - } - boost::erase_last( what_happened, ", " ); - - if ( 1 == names_that_should_be.size() ) { - what_happened += " is defined as necessary, but it missed!"; - } else { - boost::replace_first( what_happened, "Parameter", "Parameters" ); - what_happened += " are defined as necessary, but they missed!"; - } - - throw std::runtime_error( what_happened ); - } -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_NECESSARY_PARAMETERS_HPP diff --git a/thirdparty/clpp/detail/checkers/parameters_existence.hpp b/thirdparty/clpp/detail/checkers/parameters_existence.hpp deleted file mode 100644 index c50ff4f7ad82fffef75057b855b0074ec7305645..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/checkers/parameters_existence.hpp +++ /dev/null @@ -1,63 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_PARAMETERS_EXISTENCE_HPP -#define CLPP_DETAIL_PARAMETERS_EXISTENCE_HPP - -#include "common_checker.hpp" -#include "../parameter.hpp" -#include "../parameter_parts_extractor.hpp" - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -typedef common_checker< parameters, parameter_parts_extractor, std::string > checker; - -/// \class parameters_existence_checker -/// \brief Parameter's existence checker. -/// -/// Checks existence of registered parameters. -class parameters_existence_checker : public checker { -public: - parameters_existence_checker( const parameters& registered_parameters - , const parameter_parts_extractor& extractor - , const std::string& name_value_separator ) : - checker( registered_parameters, extractor, name_value_separator ) {} -public: - void check( const str_storage& inputed_parameters ) const { - if ( registered_parameters.empty() && !inputed_parameters.empty() ) { - notify_about_parameters_absence(); - } else {} - } -private: - void notify_about_parameters_absence() const { - const std::string what_happened = lib_prefix() + "You inputs some parameter(s), but no one registered!"; - throw std::runtime_error( what_happened ); - } -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_PARAMETERS_EXISTENCE_HPP diff --git a/thirdparty/clpp/detail/checkers/parameters_redundancy.hpp b/thirdparty/clpp/detail/checkers/parameters_redundancy.hpp deleted file mode 100644 index 56136d40393d61b951d9874e8ab33c527369e7bf..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/checkers/parameters_redundancy.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_PARAMETERS_REDUNDANCY_HPP -#define CLPP_DETAIL_PARAMETERS_REDUNDANCY_HPP - -#include "common_checker.hpp" -#include "../parameter.hpp" -#include "../parameter_parts_extractor.hpp" - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -typedef common_checker< parameters, parameter_parts_extractor, std::string > checker; - -/// \class parameters_redundancy_checker -/// \brief Parameter's redundancy checker. -/// -/// Check redundancy of inputed parameters. -/// Assumed that each of the parameters can be inputed only once, -/// so quantity of inputed parameters cannot be greater than -/// quantity of registered parameters. -class parameters_redundancy_checker : public checker { -public: - parameters_redundancy_checker( const parameters& registered_parameters - , const parameter_parts_extractor& extractor - , const std::string& name_value_separator ) : - checker( registered_parameters, extractor, name_value_separator ) {} -public: - void check( const str_storage& inputed_parameters ) const { - const size_t inputed_parameters_quantity = inputed_parameters.size(); - const size_t registered_parameters_quantity = registered_parameters.size(); - if ( inputed_parameters_quantity > registered_parameters_quantity ) { - notify_about_parameters_redundancy( inputed_parameters_quantity, registered_parameters_quantity ); - } else {} - } -private: - void notify_about_parameters_redundancy( size_t inputed_parameters_quantity - , size_t registered_parameters_quantity ) const { - o_stream what_happened; - what_happened << lib_prefix() - << "You inputs " << inputed_parameters_quantity << " parameters, " - << "but only " << registered_parameters_quantity << " registered!"; - throw std::runtime_error( what_happened.str() ); - } -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_PARAMETERS_REDUNDANCY_HPP diff --git a/thirdparty/clpp/detail/checkers/parameters_repetition.hpp b/thirdparty/clpp/detail/checkers/parameters_repetition.hpp deleted file mode 100644 index 0d3802123ed23e5ac730c5921c775bc6810b2d79..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/checkers/parameters_repetition.hpp +++ /dev/null @@ -1,96 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_PARAMETERS_REPETITION_HPP -#define CLPP_DETAIL_PARAMETERS_REPETITION_HPP - -#include "common_checker.hpp" -#include "../parameter.hpp" -#include "../parameter_parts_extractor.hpp" - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -typedef common_checker< parameters, parameter_parts_extractor, std::string > checker; - -using namespace boost::assign; - -/// \class parameters_repetition_checker -/// \brief Parameters repetition checker. -/// -/// Checks repetition of parameter(s). -/// Assumed that each of the parameters can be inputed only once. -class parameters_repetition_checker : public checker { -public: - parameters_repetition_checker( const parameters& registered_parameters - , const parameter_parts_extractor& extractor - , const std::string& name_value_separator ) : - checker( registered_parameters, extractor, name_value_separator ) {} -public: - void check( const str_storage& inputed_parameters ) const { - if ( inputed_parameters.size() < 2 ) { - return; - } else {} - - str_storage sorted_parameters = get_sorted_inputed_parameters( inputed_parameters ); - str_storage unique_parameters = get_unique_parameters( sorted_parameters, inputed_parameters ); - - if ( sorted_parameters != unique_parameters ) { - notify_about_parameters_repetition(); - } else {} - } -private: - str_storage get_sorted_inputed_parameters( const str_storage& inputed_parameters ) const { - str_storage parameters_for_sorting( inputed_parameters.begin(), inputed_parameters.end() ); - std::sort( parameters_for_sorting.begin(), parameters_for_sorting.end() ); - return parameters_for_sorting; - } - - str_storage get_unique_parameters( const str_storage& sorted - , const str_storage& inputed_parameters ) const { - str_storage unique_parameters( inputed_parameters.size() ); - str_const_it it = std::unique_copy( sorted.begin(), sorted.end(), unique_parameters.begin() ); - unique_parameters.resize( it - unique_parameters.begin() ); - return unique_parameters; - } - - void notify_about_parameters_repetition() const { - const std::string what_happened = lib_prefix() + "Parameter(s) repetition detected!"; - throw std::runtime_error( what_happened ); - } -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_PARAMETERS_REPETITION_HPP diff --git a/thirdparty/clpp/detail/checkers/values_correction.hpp b/thirdparty/clpp/detail/checkers/values_correction.hpp deleted file mode 100644 index e3261a54c33fba91b92b6dc78e465ff62e9317b6..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/checkers/values_correction.hpp +++ /dev/null @@ -1,108 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_VALUES_CORRECTION_HPP -#define CLPP_DETAIL_VALUES_CORRECTION_HPP - -#include "common_checker.hpp" -#include "../parameter.hpp" -#include "../parameter_parts_extractor.hpp" - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -typedef common_checker< parameters, parameter_parts_extractor, std::string > checker; - -/// \class parameters_values_checker -/// \brief Parameters values checker. -/// -/// Checks parameter's values common correction: -/// - if parameter registered as parameter without value, it cannot have value, -/// - if parameter registered as parameter with value, it must have value. -class parameters_values_checker : public checker { -public: - parameters_values_checker( const parameters& registered_parameters - , const parameter_parts_extractor& extractor - , const std::string& name_value_separator ) : - checker( registered_parameters, extractor, name_value_separator ) {} -public: - void check( const str_storage& inputed_parameters ) const { - BOOST_FOREACH ( const std::string& inputed_parameter, inputed_parameters ) { - const std::string name = extractor.extract_name_from( inputed_parameter ); - if ( this_is_parameter_with_value( inputed_parameter ) ) { - check_parameter_with_value( name, inputed_parameter ); - } else { - check_parameter_without_value( name ); - } - } - } -private: - bool this_is_parameter_with_value( const std::string& inputed_parameter ) const { - return boost::contains( inputed_parameter, name_value_separator ); - } -private: - void check_parameter_with_value( const std::string& name, const std::string& inputed_parameter ) const { - parameter_const_it it = std::find( registered_parameters.begin() - , registered_parameters.end() - , name ); - if ( registered_parameters.end() != it ) { - const std::string value = extractor.extract_value_from( inputed_parameter ); - if ( !it->func_without_arg.empty() ) { - notify_about_parameter_with_unexpected_value( name, value ); - } else if ( value.empty() ) { - notify_about_parameter_with_missing_value( name ); - } - } else {} - } - - void notify_about_parameter_with_unexpected_value( const std::string& name - , const std::string& value ) const { - const std::string what_happened = lib_prefix() - + "Parameter '" + name + "' inputed with value '" + value + "', " - + "but registered without value!"; - throw std::logic_error( what_happened ); - } - - void notify_about_parameter_with_missing_value( const std::string& name ) const { - const std::string what_happened = lib_prefix() + "Parameter '" + name - + "' registered with value, but value is missing!"; - throw std::logic_error( what_happened ); - } -private: - void check_parameter_without_value( const std::string& name ) const { - parameter_const_it it = std::find( registered_parameters.begin() - , registered_parameters.end() - , name ); - if ( registered_parameters.end() != it ) { - if ( it->func_without_arg.empty() ) { - notify_about_parameter_with_missing_value( name ); - } else {} - } else{} - } -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_VALUES_CORRECTION_HPP diff --git a/thirdparty/clpp/detail/checkers/values_semantic.hpp b/thirdparty/clpp/detail/checkers/values_semantic.hpp deleted file mode 100644 index 95aa62c67c277319c939f41e0afe220fec2f95d9..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/checkers/values_semantic.hpp +++ /dev/null @@ -1,228 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_VALUES_SEMANTIC_HPP -#define CLPP_DETAIL_VALUES_SEMANTIC_HPP - -#include "common_checker.hpp" -#include "../parameter.hpp" -#include "../parameter_parts_extractor.hpp" -#include "../argument_caster.hpp" - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#include -#include -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -using namespace boost::assign; - -void check_ipv4_validity( const std::string& address, const std::string& parameter_name ) { - try { - boost::asio::ip::address_v4 a( boost::asio::ip::address_v4::from_string( address ) ); - } catch ( const std::exception& /* exc */ ) { - const std::string what_happened = lib_prefix() - + "Semantic error: parameter '" + parameter_name + "'" - + " has invalid IPv4 value '" + address + "'!"; - throw std::invalid_argument( what_happened ); - } -} - -void check_ipv6_validity( const std::string& address, const std::string& parameter_name ) { - try { - boost::asio::ip::address_v6 a( boost::asio::ip::address_v6::from_string( address ) ); - } catch ( const std::exception& /* exc */ ) { - const std::string what_happened = lib_prefix() - + "Semantic error: parameter '" + parameter_name + "'" - + " has invalid IPv6 value '" + address + "'!"; - throw std::invalid_argument( what_happened ); - } -} - -void check_ip_validity( const std::string& address, const std::string& parameter_name ) { - try { - check_ipv4_validity( address, parameter_name ); - } catch ( const std::exception& /* exc */ ) { - try { - check_ipv6_validity( address, parameter_name ); - } catch ( const std::exception& /* exc */ ) { - const std::string what_happened = lib_prefix() - + "Semantic error: parameter '" + parameter_name + "'" - + " has invalid value '" + address + "' (not IPv4, not IPv6)!"; - throw std::invalid_argument( what_happened ); - } - } -} - -void check_path_existence( const std::string& path, const std::string& parameter_name ) { - if ( !boost::filesystem::exists( path ) ) { - const std::string what_happened = lib_prefix() - + "Semantic error: parameter '" + parameter_name + "'" - + " has invalid path value '" + path + "' (no such path)!"; - throw std::invalid_argument( what_happened ); - } else {} -} - -void check_email_validity( const std::string& email, const std::string& parameter_name ) { - const std::string what_happened = lib_prefix() - + "Semantic error: parameter '" + parameter_name + "'" - + " has invalid e-mail value '" + email + "'!"; - if ( !boost::contains( email, "@" ) || !boost::contains( email, "." ) ) { - throw std::invalid_argument( what_happened ); - } else {} - - const size_t at_quantity = size_t( std::count( email.begin(), email.end(), '@' ) ); - if ( at_quantity > 1 ) { - throw std::invalid_argument( what_happened ); - } else {} - - const size_t at_position = email.find_first_of( '@' ); - const size_t last_dot_position = email.find_last_of( '.' ); - const size_t last_char_position = email.size() - 1; - if ( 0 == at_position - || last_char_position == last_dot_position - || ( last_dot_position - at_position ) == 1 - || at_position > last_dot_position ) { - throw std::invalid_argument( what_happened ); - } else {} -} - -typedef common_checker< parameters, parameter_parts_extractor, std::string > checker; - -/// \class values_semantic_checker -/// \brief Parameter's values semantic checker. -/// -/// Checks semantic of parameters that registered with function 'check_semantic()'. -class values_semantic_checker : public checker { - typedef boost::function< void ( const std::string& /* arg */ - , const std::string& /* parameter name */ ) > - check_func; - - typedef std::map - < - const value_semantic - , const check_func - > - checkers; -public: - values_semantic_checker( const parameters& registered_parameters - , const parameter_parts_extractor& extractor - , const std::string& name_value_separator ) : - checker( registered_parameters, extractor, name_value_separator ) { - insert( semantic_checkers )( path, check_path_existence ) - ( ipv4, check_ipv4_validity ) - ( ipv6, check_ipv6_validity ) - ( ip, check_ip_validity ) - ( email, check_email_validity ) - ; - } -private: - checkers semantic_checkers; - argument_caster caster; -public: - void check( const str_storage& inputed_parameters ) const { - str_storage all_names = collect_names_of_all_registered_parameters(); - check_semantic_of_inputed_values( inputed_parameters, all_names ); - check_semantic_of_default_values( all_names ); - } -private: - str_storage collect_names_of_all_registered_parameters() const { - str_storage all_names; - BOOST_FOREACH ( const parameter& registered_parameter, registered_parameters ) { - all_names += registered_parameter.short_name; - } - return all_names; - } - - void check_semantic_of_inputed_values( const str_storage& inputed_parameters - , str_storage& all_names ) const { - BOOST_FOREACH ( const std::string& inputed_parameter, inputed_parameters ) { - if ( this_is_parameter_with_value( inputed_parameter ) ) { - const std::string name = extractor.extract_name_from( inputed_parameter ); - const std::string value = extractor.extract_value_from( inputed_parameter ); - parameter_const_it it = std::find( registered_parameters.begin() - , registered_parameters.end() - , name ); - if ( registered_parameters.end() != it ) { - check_semantic_of_inputed_value( *it, value ); - delete_element( all_names, name ); - } else {} - } else {} - } - } - - bool this_is_parameter_with_value( const std::string& inputed_parameter ) const { - return boost::contains( inputed_parameter, name_value_separator ); - } - - void check_semantic_of_inputed_value( const parameter& registered_parameter - , const std::string& value ) const { - const value_semantic semantic = registered_parameter.semantic; - if ( no_semantic != semantic ) { - const std::string name = registered_parameter.short_name; - semantic_checkers.at( semantic )( value, name ); - } else {} - } -private: - void check_semantic_of_default_values( const str_storage& all_names ) const { - BOOST_FOREACH ( const parameter& registered_parameter, registered_parameters ) { - str_const_it it = std::find( all_names.begin() - , all_names.end() - , registered_parameter.short_name ); - if ( all_names.end() != it ) { - check_semantic_of_default_value( registered_parameter ); - } else {} - } - } - - void check_semantic_of_default_value( const parameter& registered_parameter ) const { - const value_semantic semantic = registered_parameter.semantic; - if ( need_to_check_semantic( registered_parameter, semantic ) ) { - s_arg_p p = boost::any_cast< s_arg_p >( registered_parameter.for_arg ); - semantic_checkers.at( registered_parameter.semantic )( p->default_value, registered_parameter.short_name ); - } else {} - } - - bool need_to_check_semantic( const parameter& registered_parameter - , const value_semantic& semantic ) const { - return registered_parameter.has_default_value() - && ( no_semantic != semantic ) - && caster.argument_must_be_string( registered_parameter ) - ; - } -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_VALUES_SEMANTIC_HPP diff --git a/thirdparty/clpp/detail/misc.hpp b/thirdparty/clpp/detail/misc.hpp deleted file mode 100644 index e8e175053d417e1eeb8ec9a1861e6fe59d298c61..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/misc.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_MISC_HPP -#define CLPP_DETAIL_MISC_HPP - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#include -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -inline std::string lib_prefix() { return "[CLPP] "; } - -/// \enum value_semantic -/// \brief Value semantic types (for check). -enum value_semantic { - no_semantic /*!< Default value. */ - , path /*!< Path semantic check. */ - , ipv4 /*!< IPv4 semantic check. */ - , ipv6 /*!< IPv6 semantic check. */ - , ip /*!< IP semantic check. */ - , email /*!< E-mail semantic check. */ -}; - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -template< typename T > -inline std::string to_str( const T& t ) { - std::string as_string; - try { - as_string = boost::lexical_cast< std::string >( t ); - } catch ( const std::exception& /* exc */ ) { - std::string what_happened = lib_prefix() + "Value cannot be present as std::string!"; - throw std::invalid_argument( what_happened ); - } - return as_string; -} - -template -< - typename STLContainer - , typename Element -> -inline void delete_element( STLContainer& cont, const Element& element ) { - cont.erase( std::remove( cont.begin(), cont.end(), element ) - , cont.end() ); -} - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_MISC_HPP diff --git a/thirdparty/clpp/detail/parameter.hpp b/thirdparty/clpp/detail/parameter.hpp deleted file mode 100644 index fd85bd95bff0e6920536f161d3dc4a36dba5d73c..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/parameter.hpp +++ /dev/null @@ -1,274 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_PARAMETER_HPP -#define CLPP_DETAIL_PARAMETER_HPP - -#include "argument_holder.hpp" -#include "argument_caster.hpp" -#include "checkers/all.hpp" -#include "misc.hpp" - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -#include - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -/// \class parameter -/// \brief Command line parameter. -/// -/// Presents one command line parameter with all options. -class parameter { - typedef boost::function< void () > user_func_without_arg; - typedef std::set< size_t > orders_storage; -public: - explicit parameter( const std::string& short_name - , const std::string& full_name - , void ( *fn )() ) : - func_without_arg( fn ) { - init( short_name, full_name ); - } - - template< typename ArgType > - explicit parameter( const std::string& short_name - , const std::string& full_name - , void ( *fn )( const ArgType& ) ) : - for_arg( boost::make_shared< argument_holder >( fn ) ) { - init( short_name, full_name ); - } - - template< typename ArgType > - explicit parameter( const std::string& short_name - , const std::string& full_name - , void ( *fn )( ArgType ) ) : - for_arg( boost::make_shared< argument_holder >( fn ) ) { - init( short_name, full_name ); - } - - template< typename ObjectType > - explicit parameter( const std::string& short_name - , const std::string& full_name - , ObjectType* obj - , void ( ObjectType::*fn )() ) : - func_without_arg( boost::bind( fn, obj ) ) { - init( short_name, full_name ); - } - - template< typename ObjectType > - explicit parameter( const std::string& short_name - , const std::string& full_name - , ObjectType* obj - , void ( ObjectType::*fn )() const ) : - func_without_arg( boost::bind( fn, obj ) ) { - init( short_name, full_name ); - } - - template - < - typename ObjectType - , typename ArgType - > - explicit parameter( const std::string& short_name - , const std::string& full_name - , ObjectType* obj - , void ( ObjectType::*fn )( ArgType ) ) : - for_arg( boost::make_shared< argument_holder >( obj, fn ) ) { - init( short_name, full_name ); - } - - template - < - typename ObjectType - , typename ArgType - > - explicit parameter( const std::string& short_name - , const std::string& full_name - , ObjectType* obj - , void ( ObjectType::*fn )( ArgType ) const ) : - for_arg( boost::make_shared< argument_holder >( obj, fn ) ) { - init( short_name, full_name ); - } -private: - void init( const std::string& _short_name, const std::string& _full_name ) { - short_name = _short_name; - full_name = _full_name; - is_necessary = false; - is_has_default_value = false; - semantic = no_semantic; - order_number = 0; - } -public: - std::string short_name; - std::string full_name; - bool is_necessary; - bool is_has_default_value; - any for_arg; - user_func_without_arg func_without_arg; - value_semantic semantic; - int order_number; - static orders_storage orders; -public: - bool has_default_value() const { return is_has_default_value; } - bool it_is_necessary() const { return is_necessary; } -public: - parameter& check_semantic( const value_semantic& _semantic ) { - check_semantic_validity( _semantic ); - semantic = _semantic; - return *this; - } -private: - void check_semantic_validity( const value_semantic& _semantic ) const { - if ( _semantic < no_semantic || _semantic > email ) { - const std::string what_happened = lib_prefix() - + "Incorrect value of semantic, supports only 'path', 'ipv4', 'ipv6', 'ip' and 'email'!"; - throw std::invalid_argument( what_happened ); - } else {} - } -public: - parameter& necessary() { - check_parameter_default_value_existence(); - is_necessary = true; - return *this; - } -private: - void check_validity_of_string_default_value( const any& value ) const { - if ( typeid( std::string ) == value.type() ) { - const std::string value_as_string = boost::any_cast< std::string >( value ); - if ( boost::contains( value_as_string, " " ) ) { - const std::string what_happened = lib_prefix() - + "Invalid default parameter's value '" + short_name - + "': it shouldn't contains space(s)!"; - throw std::invalid_argument( what_happened ); - } else {} - } else {} - } - - void check_parameter_necessity() const { - if ( is_necessary ) { - const std::string what_happened = lib_prefix() - + "Parameter '" + short_name - + "' defined as necessary, it cannot have default value!"; - throw std::logic_error( what_happened ); - } else {} - } - - void check_parameter_default_value_existence() const { - if ( is_has_default_value ) { - const std::string what_happened = lib_prefix() - + "Parameter '" + short_name - + "' already have default value, it cannot be necessary!"; - throw std::logic_error( what_happened ); - } else {} - } -private: - argument_caster caster; -public: - parameter& default_value( const any& value ) { - check_parameter_necessity(); - check_validity_of_string_default_value( value ); - is_has_default_value = true; - caster.store_default_value( for_arg, value, short_name ); - return *this; - } -private: -template< typename ExpectedType > - ExpectedType check_type_of_default_value( const any& value ) const { - ExpectedType default_value; - if ( typeid( default_value ) == value.type() ) { - default_value = boost::any_cast< ExpectedType >( value ); - } else { - const std::string what_happened = lib_prefix() - + "Incorrect default value's type of parameter '" - + short_name + "'!"; - throw std::invalid_argument( what_happened ); - } - return default_value; - } -public: - /// \brief Define parameter's default value. - /// Overloaded for const char* arguments, - /// because boost::any cannot be initialized by array. - parameter& default_value( const char* value ) { - return default_value( std::string( value ) ); - } -public: - parameter& order( int _order_number ) { - order_number = _order_number; - check_order_validity(); - check_order_uniqueness(); - return *this; - } -private: - void check_order_validity() const { - if ( order_number < 1 ) { - o_stream what_happened; - what_happened << lib_prefix() - << "Invalid order number '" << order_number << "' " - << "(parameter '" << short_name << "'), " - << "it cannot be less than 1!"; - throw std::invalid_argument( what_happened.str() ); - } else {} - } - - void check_order_uniqueness() { - const size_t current_orders_quantity = orders.size(); - orders.insert( order_number ); - const size_t new_orders_quantity = orders.size(); - if ( current_orders_quantity == new_orders_quantity ) { - const std::string what_happened = lib_prefix() + "Parameter's order number must be unique!"; - throw std::logic_error( what_happened ); - } else {} - } -public: - bool operator==( const std::string& parameter_name ) const { - return parameter_name == short_name || parameter_name == full_name; - } - - bool operator==( int _order_number ) const { - return _order_number == order_number; - } -}; - -parameter::orders_storage parameter::orders; - -} // namespace detail - -typedef detail::parameter parameter; -typedef std::vector< parameter > parameters; -typedef parameters::iterator parameter_it; -typedef parameters::const_iterator parameter_const_it; - -} // namespace clpp - -#endif // CLPP_DETAIL_PARAMETER_HPP diff --git a/thirdparty/clpp/detail/parameter_parts_extractor.hpp b/thirdparty/clpp/detail/parameter_parts_extractor.hpp deleted file mode 100644 index 353dea07497510f83470b621b89b19cc57fcc1ef..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/parameter_parts_extractor.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_PARAMETER_PARTS_EXTRACTOR_HPP -#define CLPP_DETAIL_PARAMETER_PARTS_EXTRACTOR_HPP - -#include "types.hpp" - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -/// \class parameter_parts_extractor -/// \brief Extracts name or value from inputed parameter. -class parameter_parts_extractor { -public: - explicit parameter_parts_extractor( const std::string& _name_value_separator ) : - name_value_separator( _name_value_separator ) {} -private: - const std::string name_value_separator; -public: - std::string extract_name_from( const std::string& inputed_parameter ) const { - str_storage inputed_parameter_parts = obtain_parts_of( inputed_parameter ); - const size_t parts_quantity = inputed_parameter_parts.size(); - std::string name = inputed_parameter; - if ( 2 == parts_quantity ) { - name = inputed_parameter_parts.front(); - } else if ( parts_quantity > 2 ) { - notify_about_name_value_separator_repetition_in( inputed_parameter ); - } - return name; - } - - std::string extract_value_from( const std::string& inputed_parameter ) const { - str_storage inputed_parameter_parts = obtain_parts_of( inputed_parameter ); - const size_t parts_quantity = inputed_parameter_parts.size(); - std::string value = inputed_parameter; - if ( 2 == parts_quantity ) { - value = inputed_parameter_parts.back(); - } else if ( parts_quantity > 2 ) { - notify_about_name_value_separator_repetition_in( inputed_parameter ); - } - return value; - } -private: - str_storage obtain_parts_of( const std::string& inputed_parameter ) const { - str_storage parts; - boost::split( parts, inputed_parameter, boost::is_any_of( name_value_separator ) ); - return parts; - } - - void notify_about_name_value_separator_repetition_in( const std::string& inputed_parameter ) const { - const std::string what_happened = lib_prefix() - + "Name-value separator repetition detected in parameter '" - + inputed_parameter + "'!"; - throw std::runtime_error( what_happened ); - } -}; - -typedef boost::scoped_ptr< parameter_parts_extractor > parameter_parts_extractor_p; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_PARAMETER_PARTS_EXTRACTOR_HPP diff --git a/thirdparty/clpp/detail/types.hpp b/thirdparty/clpp/detail/types.hpp deleted file mode 100644 index 9d1ec4260b1639f36d680880a05c987489118d7a..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/types.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_TYPES_HPP -#define CLPP_DETAIL_TYPES_HPP - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -#include -#include - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -typedef std::vector< std::string > str_storage; -typedef str_storage::iterator str_it; -typedef str_storage::const_iterator str_const_it; - -typedef std::ostringstream o_stream; - -typedef boost::any any; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_TYPES_HPP diff --git a/thirdparty/clpp/detail/unnamed_parameters_handler.hpp b/thirdparty/clpp/detail/unnamed_parameters_handler.hpp deleted file mode 100644 index 93557e30dfbf892d3bd03b676ad9e53bba0aedb0..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/unnamed_parameters_handler.hpp +++ /dev/null @@ -1,109 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_UNNAMED_PARAMETERS_HANDLER_HPP -#define CLPP_DETAIL_UNNAMED_PARAMETERS_HANDLER_HPP - -#include "parameter.hpp" -#include "parameter_parts_extractor.hpp" - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -/// \class unnamed_parameters_handler -/// \brief Unnamed parameters handler. -/// -/// Handle unnamed inputed parameters. -/// Assumed that unnamed parameter registered with 'order()' function. -class unnamed_parameters_handler { -public: - unnamed_parameters_handler( const parameters& _registered_parameters - , const parameter_parts_extractor& _extractor - , const std::string& _name_value_separator ) : - registered_parameters( _registered_parameters ) - , extractor( _extractor ) - , name_value_separator( _name_value_separator ) {} -private: - const parameters& registered_parameters; - const parameter_parts_extractor& extractor; - const std::string& name_value_separator; -public: - void operator()( str_storage& inputed_parameters ) const { - if ( no_registered_unnamed_parameters() ) { - return; - } else {} - - for ( size_t i = 0; i < inputed_parameters.size(); ++i ) { - std::string& inputed_parameter = inputed_parameters[i]; - if ( this_is_unnamed_parameter( inputed_parameter ) ) { - handle_unnamed_parameter( i, inputed_parameter ); - } else {} - } - } -private: - bool no_registered_unnamed_parameters() const { - return parameter::orders.empty(); - } - - bool this_is_unnamed_parameter( const std::string& inputed_parameter ) const { - return !boost::contains( inputed_parameter, name_value_separator ) - && this_is_not_name( inputed_parameter ); - } - - bool this_is_not_name( const std::string& inputed_parameter ) const { - parameter_const_it it = std::find( registered_parameters.begin() - , registered_parameters.end() - , inputed_parameter ); - return registered_parameters.end() == it; - } - - void handle_unnamed_parameter( size_t inputed_parameter_index, std::string& inputed_parameter ) const { - const size_t inputed_parameter_serial_number = inputed_parameter_index + 1; - parameter_const_it it = std::find( registered_parameters.begin() - , registered_parameters.end() - , inputed_parameter_serial_number ); - if ( registered_parameters.end() != it ) { - const std::string value_of_unnamed_parameter = inputed_parameter; - inputed_parameter = it->short_name + name_value_separator + value_of_unnamed_parameter; - } else { - notify_about_missing_of_parameter_with_serial_number( inputed_parameter - , inputed_parameter_serial_number ); - } - } - - void notify_about_missing_of_parameter_with_serial_number( const std::string& inputed_parameter - , size_t serial_number ) const { - o_stream what_happened; - what_happened << lib_prefix() - << "You passed an unknown parameter '" << inputed_parameter << "' " - << "with order number " << serial_number << ", " - << "but there is no parameter expected at that position!"; - throw std::runtime_error( what_happened.str() ); - } -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_UNNAMED_PARAMETERS_HANDLER_HPP diff --git a/thirdparty/clpp/detail/user_functions_caller.hpp b/thirdparty/clpp/detail/user_functions_caller.hpp deleted file mode 100644 index a52c0ef915da23573d1497faf0604639ba0ac55d..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/detail/user_functions_caller.hpp +++ /dev/null @@ -1,159 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -#ifndef CLPP_DETAIL_USER_FUNCTIONS_CALLER_HPP -#define CLPP_DETAIL_USER_FUNCTIONS_CALLER_HPP - -#include "parameter.hpp" -#include "parameter_parts_extractor.hpp" -#include "argument_caster.hpp" - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -#include - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -/// \namespace clpp::detail -/// \brief Details of realization. -namespace detail { - -using namespace boost::assign; - -/// \class user_functions_caller -/// \brief User's function caller. -/// -/// Calls user's functions corresponding to registered parameters. -/// -/// Exception occurs in the user's functions are NOT handled (take care of this yourself). -class user_functions_caller { -public: - user_functions_caller( const parameters& _registered_parameters - , const parameter_parts_extractor& _extractor - , const std::string& _name_value_separator ) : - registered_parameters( _registered_parameters ) - , extractor( _extractor ) - , name_value_separator( _name_value_separator ) {} -private: - const parameters& registered_parameters; - const parameter_parts_extractor& extractor; - const std::string& name_value_separator; - argument_caster caster; -public: - void call( const str_storage& inputed_parameters ) const { - str_storage all_names = collect_names_of_all_registered_parameters(); - call_functions_for_parameters_without_values( inputed_parameters, all_names ); - call_functions_for_parameters_with_inputed_values( inputed_parameters, all_names ); - call_functions_for_parameters_with_default_values( all_names ); - } -private: - str_storage collect_names_of_all_registered_parameters() const { - str_storage all_names; - BOOST_FOREACH ( const parameter& registered_parameter, registered_parameters ) { - all_names += registered_parameter.short_name; - } - return all_names; - } -private: - void call_functions_for_parameters_without_values( const str_storage& inputed_parameters - , str_storage& all_names ) const { - BOOST_FOREACH ( const std::string& inputed_parameter, inputed_parameters ) { - if ( this_is_parameter_without_value( inputed_parameter ) ) { - const std::string name = inputed_parameter; - parameter_const_it it = std::find( registered_parameters.begin() - , registered_parameters.end() - , name ); - if ( registered_parameters.end() != it ) { - if ( !it->func_without_arg.empty() ) { - it->func_without_arg(); - } else {} - delete_element( all_names, it->short_name ); - } else {} - } - } - } - - void call_functions_for_parameters_with_inputed_values( const str_storage& inputed_parameters - , str_storage& all_names ) const { - BOOST_FOREACH ( const std::string& inputed_parameter, inputed_parameters ) { - if ( this_is_parameter_with_value( inputed_parameter ) ) { - const std::string name = extractor.extract_name_from( inputed_parameter ); - parameter_const_it it = std::find( registered_parameters.begin() - , registered_parameters.end() - , name ); - if ( registered_parameters.end() != it ) { - if ( !it->func_without_arg.empty() ) { - it->func_without_arg(); - } else { - const std::string value = extractor.extract_value_from( inputed_parameter ); - call_func_with_arg( *it, value ); - } - delete_element( all_names, it->short_name ); - } else {} - } - } - } - - bool this_is_parameter_with_value( const std::string& inputed_parameter ) const { - return boost::contains( inputed_parameter, name_value_separator ); - } - - bool this_is_parameter_without_value( const std::string& inputed_parameter ) const { - return !boost::contains( inputed_parameter, name_value_separator ); - } - - void call_func_with_arg( const parameter& registered_parameter - , const std::string& inputed_value ) const { - const any& for_arg = registered_parameter.for_arg; - const std::string name = registered_parameter.short_name; - caster.call_func_with_inputed_arg( for_arg, name, inputed_value ); - } -private: - void call_functions_for_parameters_with_default_values( const str_storage& all_names ) const { - BOOST_FOREACH ( const parameter& registered_parameter, registered_parameters ) { - str_const_it it = std::find( all_names.begin() - , all_names.end() - , registered_parameter.short_name ); - if ( all_names.end() != it ) { - call_func_with_default_arg( registered_parameter ); - } else {} - } - } - - void call_func_with_default_arg( const parameter& registered_parameter ) const { - if ( registered_parameter.has_default_value() && registered_parameter.func_without_arg.empty() ) { - const any& for_arg = registered_parameter.for_arg; - caster.call_func_with_default_arg( for_arg ); - } else {} - } -}; - -} // namespace detail -} // namespace clpp - -#endif // CLPP_DETAIL_USER_FUNCTIONS_CALLER_HPP diff --git a/thirdparty/clpp/parser.hpp b/thirdparty/clpp/parser.hpp deleted file mode 100644 index d49e45f657b24ed04b31e0108e6b41554ad140bd..0000000000000000000000000000000000000000 --- a/thirdparty/clpp/parser.hpp +++ /dev/null @@ -1,995 +0,0 @@ -// C++ Command line parameters parser. -// -// Copyright (C) Denis Shevchenko, 2010. -// shev.denis @ gmail.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// See http://www.opensource.org/licenses/mit-license.php -// -// http://clp-parser.sourceforge.net/ - -///////////////////////////////////////////////////////////////////////////////////////// -/// -/// \mainpage CLPP -/// -/// \section about About -/// -/// This document describes 'Command line parameters parser' library. Library provides parsing -/// of command line parameters, with callback corresponding functions and, if necessary, checking -/// of parameter's values semantic. -/// -/// \htmlonly
\endhtmlonly -/// -/// -/// -/// \section download Download -/// -/// You can download CLPP source code from \htmlonlySourceForge\endhtmlonly. -/// -/// \htmlonly
\endhtmlonly -/// -/// -/// -/// \section license License -/// -/// This library is licensed under \htmlonlyMIT License\endhtmlonly. -/// -/// \htmlonly
\endhtmlonly -/// -/// -/// -/// \section motivation Motivation -/// \htmlonly

"Don't reinvent the wheel"

\endhtmlonly -/// -/// Almost every "console-start" program requires input of some command line parameters, so it handling -/// is very common task. Actually, this handling add up to two tasks: -/// \li check correctness (in all senses of this word) of inputed parameters, -/// \li some reaction(s) on it. -/// -/// CLPP library provides general solution for this tasks. It very easy to use. -/// -/// \htmlonly
\endhtmlonly -/// -/// -/// -/// \section hello-world-example "Hello world" example -/// -/// Simplest example of CLPP using: -/// -/// \code -/// #include -/// -/// #include -/// -/// void help() { -/// std::cout << "My program, version 1.0. Common usage is..." << std::endl; -/// // -/// } -/// -/// int main( int argc, char* argv[] ) { -/// clpp::command_line_parameters_parser parser; -/// // Register parameter, without value and without any checking... -/// parser.add_parameter( "-h", "--help", help ); -/// try { -/// parser.parse( argc, argv ); -/// // If user inputs '-h' or '--help' in command line, function 'help()' will be called. -/// } catch ( const std::exception& exc ) { -/// std::cerr << exc.what() << std::endl; -/// } -/// -/// return 0; -/// } -/// \endcode -/// -/// \htmlonly
\endhtmlonly -/// -/// -/// -/// \section features Features -/// -/// \li Header-only (does not require build). -/// \li Register parameters with two (in Unix-style) or single names. -/// \li Calls correspond functions, with or without argument. -/// \li Register unnamed parameters that can be inputed without names. -/// \li Provides common checks of inputed parameters, like duplication, incorrect, etc. -/// \li Checking of value's type, like integer or real (defines by type of registered function's argument). -/// \li Checking of value's semantic, like correct path, etc. -/// \li Define parameter's necessity. -/// \li Define parameter's default value. -/// \li Define another "name-value" separator. -/// -/// \htmlonly
\endhtmlonly -/// -/// -/// -/// \section changes Backward incompatible changes -/// -/// Since 1.0rc version function check_type() has been removed (it no need anymore). -/// See User's guide for more info. -/// -/// \htmlonly
\endhtmlonly -/// -/// -/// -/// \section acknowledgements Acknowledgements -/// -/// I'm very grateful to \htmlonlyBjarne Stroustrup\endhtmlonly, who invented so beautiful, so powerful and so dangerous language! -/// -/// Also I grateful to all authors of \htmlonlyBoost C++ libraries\endhtmlonly. Thank you for your work! -/// -/// \htmlonly
\endhtmlonly -/// -/// -/// -/// \htmlonly Copyright © Denis Shevchenko, 2010 \endhtmlonly -/// -///////////////////////////////////////////////////////////////////////////////////////// -/// -/// \page dependencies External dependencies -/// -/// There is only "one" dependency - \htmlonlyBoost C++ libraries\endhtmlonly. -/// -/// Strictly speacking, CLPP use following libraries: -/// \li Boost.Any -/// \li Boost.Assign -/// \li Boost.Utility -/// \li Boost.Ptr_container -/// \li Boost.Lexical_cast -/// \li Boost.Algorithm -/// \li Boost.Bind -/// \li Boost.Foreach -/// \li Boost.Asio -/// \li Boost.Smart_ptr -/// \li Boost.Function -/// \li Boost.Filesystem -/// \li Boost.System -/// -/// Full list of Boost C++ libraries see \htmlonlythere\endhtmlonly. -/// -/// All used libraries are header-only, except Boost.Filesystem and Boost.System, -/// so you must build these libraries and link it with your program. -/// -/// However, if you using C++ professionally, you (in my humble opinion) must have -/// Boost C++ libraries. So just download full package from \htmlonlythere\endhtmlonly, install it and enjoy! -/// -/// Note: If you use Windows - see http://www.boostpro.com/download. -/// -///////////////////////////////////////////////////////////////////////////////////////// -/// -/// \page user_guide User's guide -/// -/// Contents: -/// - \ref introduction -/// - \ref value_or_not_value -/// - \ref necessity -/// - \ref default_val -/// - \ref error_reports -/// - \ref common_usage -/// - \ref preparing -/// - \ref defining_parameter -/// - \ref member_functions -/// - \ref parsing -/// - \ref function_arg_types -/// - \ref advanced_usage -/// - \ref how_to_define_necessity -/// - \ref how_to_define_default_value -/// - \ref how_to_define_type_check -/// - \ref how_to_define_semantic_check -/// - \ref combine_of_settings -/// - \ref another_value_separator -/// - \ref unnamed_params -/// -/// \htmlonly
\endhtmlonly -/// -/// \section introduction Introduction -/// -/// Factually, using CLPP library add up to only two tasks: -/// \li registration set of parameters, with definition all required checkings and characteristics, -/// \li parsing inputed parameter(s), with defined check(s) and calls of corresponding functions. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection value_or_not_value Value or not value? -/// -/// Command line parameter can be with or without value. -/// -/// Example of parameter without value: -/// \code -/// # ./program --help -/// \endcode -/// Parameter '--help' is useful of its own accord, it not need any value. -/// -/// Example of parameter with value: -/// \code -/// # ./program --log-dir=/some/path -/// \endcode -/// Parameter '--log-dir', in contrast, useless without value. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection necessity Necessity -/// -/// Command line parameter can be necessary or optionally. -/// -/// In examples above parameter '--help' is optionally, because it may missing -/// (only in cases where user want to see help info, he input '--help'). -/// -/// But parameter '--log-dir' may be necessary, in this case user must input it. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection default_val Default value -/// -/// Command line parameter can have default value, in this case not required input it. -/// This option can be useful for parameters with predefined default values. -/// -/// In example above parameter '--log-dir' may have default value of path, so user can skip it. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection error_reports Error reports -/// -/// All reports about errors begins with [CLPP] prefix, for example: -/// -/// \code -/// [CLPP] You inputs 3 parameters, but only 2 registered! -/// \endcode -/// -/// \htmlonly
\endhtmlonly -/// -/// \section common_usage Common usage -/// -/// This section describes common usage of CLPP. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection preparing Preparing -/// -/// Copy 'clpp' folder in some place where your compiler is looking for header files and add: -/// -/// \code #include \endcode -/// -/// in your program. -/// -/// For simplicity, you can also add: -/// -/// \code using namespace clpp; \endcode -/// -/// Note: In old versions of library used namespace clp_parser, but backward compatibility is maintained. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection defining_parameter Defining command line parameter -/// -/// Registration of new parameter included three tasks: -/// \li define parameter's name (short and full names, or single name), -/// \li define function that will be called if corresponding parameter will be inputed, -/// \li define checks and default value for parameter (optionally). -/// -/// Use clpp::command_line_parameters_parser::add_parameter() function for it. -/// -/// \code -/// -/// void help() { /* some info */ } -/// void config() { /* some config info */ } -/// -/// int main( int argc, char* argv[] ) { -/// clpp::command_line_parameters_parser parser; -/// // Register parameter with two names (in Unix-style) and 'help()' function. -/// parser.add_parameter( "-h", "--help", help ); -/// // Register parameter with single name and 'config()' function. -/// parser.add_parameter( "--config", config ); -/// // ... -/// } -/// \endcode -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection member_functions Register of functions-members -/// -/// You can register not only global functions, but also functions-members. -/// -/// \code -/// struct some_parameters_storage { -/// void some_path( const std::string& path ) { /* Some work with path... */ } -/// void some_num( double number ) { /* Some work with number... */ } -/// } -/// -/// int main( int argc, char* argv[] ) { -/// some_parameters_storage storage; -/// -/// clpp::command_line_parameters_parser parser; -/// parser.add_parameter( "-f", "--file", &storage, &some_parameters_storage::some_path ); -/// parser.add_parameter( "-n", "--number", &storage, &some_parameters_storage::some_num ); -/// // ... -/// } -/// \endcode -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection parsing Parsing -/// -/// For parsing use clpp::command_line_parameters_parser::parse() function. -/// -/// \code -/// int main( int argc, char* argv[] ) { -/// clpp::command_line_parameters_parser parser; -/// // ... -/// try { -/// parser.parse( argc, argv ); -/// } catch ( const std::exception& exc ) { -/// std::cerr << exc.what() << std::endl; -/// } -/// // ... -/// } -/// \endcode -/// -/// This function parse all inputed command line parameters, -/// checks correctness and calls corresponding functions. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection function_arg_types Supported types of user's function argument -/// -/// When you register parameter with value, you can use follow types of function's argument: -/// \li almost all standard C++-types (see below), -/// \li std::string. -/// -/// You CANNOT use const char* and wchar_t argument. -/// But this limitation, in my humble opinion, is not the real problem. -/// -/// You can pass argument by value, like this: -/// \code -/// void f( int i ) { /* some work... */ } -/// \endcode -/// or by const reference: -/// \code -/// void f( const std::string& path ) { /* some work... */ } -/// \endcode -/// -/// Passing by non-const reference is NOT supported (I think this is completely unnecessary). -/// -/// \htmlonly
\endhtmlonly -/// -/// \section advanced_usage Advanced usage -/// -/// This section describes advanced usage of CLPP. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection how_to_define_necessity Define parameter's necessity -/// -/// For define parameter's necessity use clpp::parameter::necessary() function: -/// \code -/// -/// void config( const std::string& path ) { /* some config info */ } -/// -/// int main( int argc, char* argv[] ) { -/// clpp::command_line_parameters_parser parser; -/// parser.add_parameter( "-c", "--config", config ) -/// .necessary(); -/// // ... -/// } -/// \endcode -/// After that user must inputs this parameter in command line. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection how_to_define_default_value Define parameter's default value -/// -/// For set parameter's default value use clpp::parameter::default_value() function: -/// \code -/// -/// void config( const std::string& path ) { /* some config info */ } -/// -/// int main( int argc, char* argv[] ) { -/// clpp::command_line_parameters_parser parser; -/// parser.add_parameter( "-c", "--config", config ) -/// .default_value( "/some/default/path" ); -/// // ... -/// } -/// \endcode -/// After that user can skip this parameter in command line. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection how_to_define_type_check Parameter's value type check -/// -/// Since 1.0rc version value's type checks automatically. If you register callback function -/// \code -/// void some_num( double num ) { /* some work... */ } -/// -/// int main( int argc, char* argv[] ) { -/// clpp::command_line_parameters_parser parser; -/// parser.add_parameter( "-n", "--number", some_num ); -/// // ... -/// } -/// \endcode -/// so number's value must be 'double' type. -/// -/// Note: if you want use function with 'float' argument, like this: -/// -/// \code -/// void some_num( float num ) { /* some work... */ } -/// \endcode -/// AND use 'default_value()' function, you must indicate exactly 'float' type, like this: -/// -/// \code -/// // ... -/// parser.add_parameter( "-n", "--number", some_num ) -/// .default_value( 12.56f ) -/// ; -/// // ... -/// \endcode -/// or like this: -/// -/// \code -/// // ... -/// parser.add_parameter( "-n", "--number", some_num ) -/// .default_value( float( 12.56 ) ) -/// ; -/// // ... -/// \endcode -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection how_to_define_semantic_check Parameter's value semantic check -/// -/// Use clpp::parameter::check_semantic() function. -/// -/// \code -/// void log_dir( const std::string& path_to_log ) { /* some work... */ } -/// -/// int main( int argc, char* argv[] ) { -/// clpp::command_line_parameters_parser parser; -/// parser.add_parameter( "-l", "--log-dir", log_dir ) -/// .check_semantic( clpp::path ); -/// // ... -/// } -/// \endcode -/// -/// In this case, value of '--log-dir' must be valid path in current filesystem. -/// -/// Supported value's semantic: -/// \li path (check of path correctness, in current filesystem), -/// \li ipv4 (check of IP-address validity, exactly IPv4), -/// \li ipv6 (check of IP-address validity, exactly IPv6), -/// \li ip (check of IP-address validity, IPv4 or IPv6). -/// \li email (check of E-mail validity). -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection combine_of_settings Combine of settings -/// -/// Of course, you can combine settings for one parameter, like this: -/// -/// \code -/// void log_dir( const std::string& path_to_log ) { /* some work... */ } -/// -/// int main( int argc, char* argv[] ) { -/// clpp::command_line_parameters_parser parser; -/// parser.add_parameter( "-l", "--log-dir", log_dir ) -/// .default_value( "/some/default/path" ) -/// .check_semantic( clpp::path ) -/// ; -/// // ... -/// } -/// \endcode -/// -/// Note: You cannot combine contradictory settings. For example, if you -/// write like this: -/// -/// \code -/// void log_dir( const std::string& path_to_log ) { /* some work... */ } -/// -/// int main( int argc, char* argv[] ) { -/// clpp::command_line_parameters_parser parser; -/// parser.add_parameter( "-l", "--log-dir", log_dir ) -/// .default_value( "/some/default/path" ) -/// .check_semantic( clpp::path ) -/// .necessary() // Necessary parameter with defined default value?? Hmm... -/// ; -/// // ... -/// } -/// \endcode -/// -/// exception will throw. -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection another_value_separator Another 'name-value' separator -/// -/// You can define another 'name-value' separator, instead default '='. -/// -/// Use clpp::command_line_parameters_parser::set_value_separator() function. -/// -/// \code -/// int main( int argc, char* argv[] ) { -/// clpp::command_line_parameters_parser parser; -/// parser.set_value_separator( ':' ); -/// // ... -/// } -/// \endcode -/// -/// In this case, parameters with value must be input in command line like this: -/// -/// \code -/// # ./program --log-dir:/some/path -/// \endcode -/// -/// Note: You CANNOT use characters with ASCII-code less than 0x21. -/// They are unsuitable candidates for the separator role. :-) -/// -/// \htmlonly
\endhtmlonly -/// -/// \subsection unnamed_params Unnamed parameters -/// -/// Sometimes you may want to use some parameters without explicitly inputed names. -/// -/// For example, if you develop network program with console-defined host and port, -/// you can use it like this: -/// -/// \code -/// # ./program --host=127.0.0.1 --port=80 -/// \endcode -/// -/// but you probably want to use it easier: -/// -/// \code -/// # ./program 127.0.0.1 80 -/// \endcode -/// -/// Use clpp::parameter::order() function. -/// -/// This function sets order number for parameter, so in our example 'host' has -/// order number 1, and 'port' has order number 2. Note that order number begins -/// with 1, because it is not index, but exactly number. -/// -/// Of course, order number cannot be negative. -/// -/// So you must register these parameters like this: -/// -/// \code -/// struct my_server { -/// void host( const std::string& address ) { /* some work... */ } -/// void port( unsigned int some_port ) { /* some work... */ } -/// }; -/// -/// int main( int argc, char* argv[] ) { -/// my_server server; -/// -/// clpp::command_line_parameters_parser parser; -/// parser.add_parameter( "-h", "--host", &server, &my_server::host ) -/// .order( 1 ) -/// ; -/// parser.add_parameter( "-p", "--port", &server, &my_server::port ) -/// .order( 2 ) -/// ; -/// // ... -/// } -/// \endcode -/// -/// Now you can use it like this: -/// -/// \code -/// # ./program 127.0.0.1 80 -/// \endcode -/// -/// but not vice versa: -/// -/// \code -/// # ./program 80 127.0.0.1 -/// \endcode -/// -/// because in this case my_server::port() function get string-argument, and exception will throw. -/// -/// Remember that order numbers must be unique: -/// -/// \code -/// // ... -/// parser.add_parameter( "-h", "--host", &server, &my_server::host ) -/// .order( 1 ) -/// ; -/// parser.add_parameter( "-p", "--port", &server, &my_server::port ) -/// .order( 1 ) // You inputed already used order?? Hmm... -/// ; -/// // ... -/// \endcode -/// -/// Of course, you can use "ordered" parameters with names, in any combination: -/// -/// \code -/// # ./program -h=127.0.0.1 --port=80 -/// \endcode -/// \code -/// # ./program 127.0.0.1 -p=80 -/// \endcode -/// -///////////////////////////////////////////////////////////////////////////////////////// - -#ifndef CLPP_PARSER_HPP -#define CLPP_PARSER_HPP - -#ifndef _MSC_VER - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" - #pragma GCC diagnostic ignored "-Wunused-variable" - #pragma GCC diagnostic ignored "-Wunused-private-field" - #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" - #pragma GCC diagnostic ignored "-Wshadow" -#endif -#include "detail/checkers/all.hpp" -#include "detail/user_functions_caller.hpp" -#include "detail/unnamed_parameters_handler.hpp" -#include "detail/parameter.hpp" -#include "detail/misc.hpp" - -#include -#include -#include - -/// \namespace clpp -/// \brief Main namespace of library. -namespace clpp { - -using namespace boost::assign; - -/// \class command_line_parameters_parser -/// \brief Parser. -/// -/// Presents parsing functionality. -class command_line_parameters_parser : boost::noncopyable { - typedef detail::common_checker< parameters, detail::parameter_parts_extractor, std::string > checker; - typedef boost::ptr_vector< checker > common_checkers; - typedef common_checkers::iterator checker_it; - typedef common_checkers::const_iterator checker_const_it; -public: - command_line_parameters_parser() : - name_value_separator( "=" ) {} -public: - parameter& add_parameter( const std::string& short_name - , const std::string& full_name - , void ( *fn )() ) { - return create_parameter( short_name, full_name, fn ); - } - - template< typename ArgType > - parameter& add_parameter( const std::string& short_name - , const std::string& full_name - , void ( *fn )( const ArgType& ) ) { - return create_parameter( short_name, full_name, fn ); - } - - template< typename ArgType > - parameter& add_parameter( const std::string& short_name - , const std::string& full_name - , void ( *fn )( ArgType ) ) { - return create_parameter( short_name, full_name, fn ); - } - - parameter& add_parameter( const std::string& single_name - , void ( *fn )() ) { - return create_parameter( single_name, "", fn ); - } - - template< typename ArgType > - parameter& add_parameter( const std::string& single_name - , void ( *fn )( const ArgType& ) ) { - return create_parameter( single_name, "", fn ); - } - - template< typename ArgType > - parameter& add_parameter( const std::string& single_name - , void ( *fn )( ArgType ) ) { - return create_parameter( single_name, "", fn ); - } - - template< typename ObjectType > - parameter& add_parameter( const std::string& short_name - , const std::string& full_name - , ObjectType* obj - , void ( ObjectType::*fn )() ) { - return create_parameter( short_name, full_name, obj, fn ); - } - - template< typename ObjectType > - parameter& add_parameter( const std::string& short_name - , const std::string& full_name - , ObjectType* obj - , void ( ObjectType::*fn )() const ) { - return create_parameter( short_name, full_name, obj, fn ); - } - - template - < - typename ObjectType - , typename ArgType - > - parameter& add_parameter( const std::string& short_name - , const std::string& full_name - , ObjectType* obj - , void ( ObjectType::*fn )( const ArgType& ) ) { - return create_parameter( short_name, full_name, obj, fn ); - } - - template - < - typename ObjectType - , typename ArgType - > - parameter& add_parameter( const std::string& short_name - , const std::string& full_name - , ObjectType* obj - , void ( ObjectType::*fn )( const ArgType& ) const ) { - return create_parameter( short_name, full_name, obj, fn ); - } - - template - < - typename ObjectType - , typename ArgType - > - parameter& add_parameter( const std::string& short_name - , const std::string& full_name - , ObjectType* obj - , void ( ObjectType::*fn )( ArgType ) ) { - return create_parameter( short_name, full_name, obj, fn ); - } - - template - < - typename ObjectType - , typename ArgType - > - parameter& add_parameter( const std::string& short_name - , const std::string& full_name - , ObjectType* obj - , void ( ObjectType::*fn )( ArgType ) const ) { - return create_parameter( short_name, full_name, obj, fn ); - } - - template< typename ObjectType > - parameter& add_parameter( const std::string& single_name - , ObjectType* obj - , void ( ObjectType::*fn )() ) { - return create_parameter( single_name, "", obj, fn ); - } - - template< typename ObjectType > - parameter& add_parameter( const std::string& single_name - , ObjectType* obj - , void ( ObjectType::*fn )() const ) { - return create_parameter( single_name, "", obj, fn ); - } - - template - < - typename ObjectType - , typename ArgType - > - parameter& add_parameter( const std::string& single_name - , ObjectType* obj - , void ( ObjectType::*fn )( ArgType ) ) { - return create_parameter( single_name, "", obj, fn ); - } - - template - < - typename ObjectType - , typename ArgType - > - parameter& add_parameter( const std::string& single_name - , ObjectType* obj - , void ( ObjectType::*fn )( ArgType ) const ) { - return create_parameter( single_name, "", obj, fn ); - } -private: - parameters registered_parameters; -private: - template< typename PtrToFun > - parameter& create_parameter( const std::string& short_name - , const std::string& full_name - , const PtrToFun& ptr_to_fun ) { - check_null_ptr( ptr_to_fun, short_name ); - check_names_validity( short_name, full_name ); - - registered_parameters += parameter( short_name, full_name, ptr_to_fun ); - return registered_parameters.back(); - } - - template - < - typename PtrToObj - , typename PtrToObjFun - > - parameter& create_parameter( const std::string& short_name - , const std::string& full_name - , const PtrToObj& ptr_to_obj - , const PtrToObjFun& ptr_to_fun ) { - check_null_ptr( ptr_to_obj, short_name ); - check_null_ptr( ptr_to_fun, short_name ); - check_names_validity( short_name, full_name ); - - registered_parameters += parameter( short_name, full_name, ptr_to_obj, ptr_to_fun ); - return registered_parameters.back(); - } -private: - template< typename Ptr > - void check_null_ptr( const Ptr& ptr, const std::string& parameter_name ) const { - if ( 0 == ptr ) { - const std::string what_happened = - "Zero pointer (function/object/method) detected for parameter '" + parameter_name + "'!"; - throw std::invalid_argument( what_happened ); - } else {} - } - - void check_names_validity( const std::string& short_name, const std::string& full_name ) const { - check_spaces_existence_in( short_name ); - check_spaces_existence_in( full_name ); - check_equality_of( short_name, full_name ); - check_uniqueness_of( short_name ); - if (!full_name.empty()) - check_uniqueness_of( full_name ); - } - - void check_spaces_existence_in( const std::string& name ) const { - if ( boost::contains( name, " " ) ) { - const std::string what_happened = - "Invalid parameter's name '" + name + "', it shouldn't contains space(s)!"; - throw std::runtime_error( what_happened ); - } else {} - } - - void check_equality_of( const std::string& short_name, const std::string& full_name ) const { - if ( short_name == full_name ) { - const std::string what_happened = "Equal names of parameter: '" - + short_name + "', '" + full_name + "'!"; - throw std::invalid_argument( what_happened ); - } else {} - } - - void check_uniqueness_of( const std::string& name ) const { - parameter_const_it it = std::find( registered_parameters.begin() - , registered_parameters.end() - , name ); - if ( registered_parameters.end() != it ) { - const std::string what_happened = "Parameter with name '" + name + "' already exists!"; - throw std::invalid_argument( what_happened ); - } else {} - } -private: - std::string name_value_separator; - common_checkers checkers; - detail::parameter_parts_extractor_p extractor; -public: - void set_value_separator( char separator ) { - check_printable_of( separator ); - name_value_separator = separator; - } -private: - void check_printable_of( char separator ) const { - const int ascii_code = separator; - if ( ascii_code <= 0x20 ) { - const std::string what_happened = "Symbol (ASCII-code is " - + detail::to_str( separator ) - + ") is not suitable for name-value separator!"; - throw std::invalid_argument( what_happened ); - } else {} - } -public: - void parse( int argc, char** argv ) { - detail::str_storage inputed_parameters = obtain_parameters_from( argc, argv ); - if ( there_is_nothing_to_parse( inputed_parameters ) ) { - return; - } else {} - - create_parameter_parts_extractor(); - create_parameters_checkers(); - base_checks( inputed_parameters ); - handle_unnamed_parameters( inputed_parameters ); - remaining_checks( inputed_parameters ); - call_corresponding_user_functions( inputed_parameters ); - } -private: - detail::str_storage obtain_parameters_from( int argc, char** argv ) const { - detail::str_storage inputed_parameters; - for ( int i = 1; i < argc; ++i ) { - inputed_parameters += argv[i]; - } - return inputed_parameters; - } - - bool there_is_nothing_to_parse( const detail::str_storage& inputed_parameters ) const { - return inputed_parameters.empty() - && no_parameters_with_default_value() - && no_necessary_parameters(); - } - - bool no_parameters_with_default_value() const { - parameter_const_it it = std::find_if( registered_parameters.begin() - , registered_parameters.end() - , boost::mem_fn( ¶meter::has_default_value ) ); - return registered_parameters.end() == it; - } - - bool no_necessary_parameters() const { - parameter_const_it it = std::find_if( registered_parameters.begin() - , registered_parameters.end() - , boost::mem_fn( ¶meter::it_is_necessary ) ); - return registered_parameters.end() == it; - } - - void handle_unnamed_parameters( detail::str_storage& inputed_parameters ) { - detail::unnamed_parameters_handler handle( registered_parameters - , *extractor - , name_value_separator ); - handle( inputed_parameters ); - } - - void create_parameter_parts_extractor() { - extractor.reset( new detail::parameter_parts_extractor( name_value_separator ) ); - } - - void create_parameters_checkers() { - using namespace detail; - - checkers.push_back( - new parameters_existence_checker( registered_parameters, *extractor, name_value_separator ) ); - checkers.push_back( - new parameters_redundancy_checker( registered_parameters, *extractor, name_value_separator ) ); - checkers.push_back( - new parameters_repetition_checker( registered_parameters, *extractor, name_value_separator ) ); - checkers.push_back( - new incorrect_parameters_checker( registered_parameters, *extractor, name_value_separator ) ); - checkers.push_back( - new necessary_parameters_checker( registered_parameters, *extractor, name_value_separator ) ); - checkers.push_back( - new parameters_values_checker( registered_parameters, *extractor, name_value_separator ) ); - checkers.push_back( - new values_semantic_checker( registered_parameters, *extractor, name_value_separator ) ); - } - - void base_checks( const detail::str_storage& inputed_parameters ) { - const size_t base_checkers_quantity = 3; - for ( checker_const_it it = checkers.begin(); - checkers.begin() + base_checkers_quantity != it; - ++it ) { - it->check( inputed_parameters ); - } - checkers.erase( checkers.begin(), checkers.begin() + base_checkers_quantity ); - } - - void remaining_checks( const detail::str_storage& inputed_parameters ) { - for ( checker_const_it it = checkers.begin(); checkers.end() != it; ++it ) { - it->check( inputed_parameters ); - } - } - - void call_corresponding_user_functions( const detail::str_storage& inputed_parameters ) { - detail::user_functions_caller caller( registered_parameters, *extractor, name_value_separator ); - caller.call( inputed_parameters ); - } -}; - -/// For backward compatibility with old versions. -typedef command_line_parameters_parser command_line_parameter_parser; - -} // namespace clpp - -/// For backward compatibility with old versions. -namespace clp_parser = clpp; - -#ifndef _MSC_VER - #pragma GCC diagnostic pop -#endif - -#endif // CLPP_PARSER_HPP diff --git a/thirdparty/delaunay b/thirdparty/delaunay deleted file mode 160000 index c3413c96c6a44c2f6d67a6cb71c93bd6e6eb57d6..0000000000000000000000000000000000000000 --- a/thirdparty/delaunay +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c3413c96c6a44c2f6d67a6cb71c93bd6e6eb57d6 diff --git a/utilities/thirdpartyupdate/moab-update.sh b/utilities/thirdpartyupdate/moab-update.sh deleted file mode 100755 index 3a6dddeebc3454055e4d40c445cfd2c066e37cee..0000000000000000000000000000000000000000 --- a/utilities/thirdpartyupdate/moab-update.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -x -shopt -s dotglob - -readonly name="moab" -readonly ownership="MOAB Upstream " -readonly subtree="thirdparty/$name" -readonly repo="https://gitlab.kitware.com/third-party/moab.git" -readonly tag="for/smtk" -readonly paths=" -ANNOUNCE -AUTHORS -CMakeLists.txt -KNOWN_ISSUES -LICENSE -MOABConfig.new.cmake.in -README.md -RELEASE_NOTES -config/ -configure.ac -itaps/ -src/ -" - -extract_source () { - git_archive -} - -. "${BASH_SOURCE%/*}/update-common.sh"