Commit d86b70c8 authored by T.J. Corona's avatar T.J. Corona

Initial commit

parent 4b4b3131
# Declare unit tests Usage:
#
# smtk_unit_tests(
# LABEL <prefix for all unit tests>
# SOURCES <test_source_list>
# SOURCES_REQUIRE_DATA <test_sources_that_require_DATA_DIR>
# EXTRA_SOURCES <helper_source_files>
# LIBRARIES <dependent_library_list>
# )
function(smtk_of_unit_tests)
set(options)
set(oneValueArgs)
set(multiValueArgs LABEL SOURCES SOURCES_REQUIRE_DATA EXTRA_SOURCES LIBRARIES)
cmake_parse_arguments(SMTK_OF_ut
"${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
)
list(APPEND SMTK_OF_ut_SOURCES ${SMTK_OF_ut_SOURCES_REQUIRE_DATA})
list(LENGTH SMTK_OF_ut_SOURCES num_sources)
if(NOT ${num_sources})
#no sources don't make a target
return()
endif()
if (ENABLE_TESTING)
smtk_get_kit_name(kit)
#we use UnitTests_ so that it is an unique key to exclude from coverage
set(test_prog UnitTests_${kit})
create_test_sourcelist(TestSources ${test_prog}.cxx ${SMTK_OF_ut_SOURCES})
add_executable(${test_prog} ${TestSources} ${SMTK_OF_ut_EXTRA_SOURCES})
target_link_libraries(${test_prog} LINK_PRIVATE ${SMTK_OF_ut_LIBRARIES})
target_include_directories(${test_prog}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${MOAB_INCLUDE_DIRS}
${VTK_INCLUDE_DIRS}
)
target_compile_definitions(${test_prog} PRIVATE "SMTK_OF_DATA_DIR=\"${PROJECT_SOURCE_DIR}/data\"")
target_compile_definitions(${test_prog} PRIVATE "SMTK_OF_SCRATCH_DIR=\"${CMAKE_BINARY_DIR}/Testing/Temporary\"")
foreach (test ${SMTK_OF_ut_SOURCES})
get_filename_component(tname ${test} NAME_WE)
add_test(NAME ${tname}
COMMAND ${test_prog} ${tname} ${${tname}_EXTRA_ARGUMENTS}
)
set_tests_properties(${tname} PROPERTIES TIMEOUT 120)
if(SMTK_OF_ut_LABEL)
set_tests_properties(${tname} PROPERTIES LABELS ${SMTK_OF_ut_LABEL})
endif()
endforeach(test)
endif (ENABLE_TESTING)
endfunction(smtk_of_unit_tests)
# A contract file for testing the OpenFOAM session within SMTK.
cmake_minimum_required(VERSION 3.8.2)
project(openfoam-session)
include(ExternalProject)
# If on Windows, force response file usage. The command line gets way too long
# on Windows without this. Once VTK_USE_FILE and PARAVIEW_USE_FILE are gone,
# this can be removed.
set(response_file)
if (WIN32)
set(response_file -DCMAKE_NINJA_FORCE_RESPONSE_FILE:BOOL=ON)
endif ()
ExternalProject_Add(openfoam-session
GIT_REPOSITORY "https://gitlab.kitware.com/cmb/plugins/openfoam-session"
GIT_TAG "origin/master"
PREFIX plugin
STAMP_DIR plugin/stamp
SOURCE_DIR plugin/src
BINARY_DIR plugin/build
CMAKE_ARGS
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DENABLE_PYTHON_WRAPPING=ON
-DENABLE_TESTING=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-Dsmtk_DIR=${smtk_DIR}
${response_file}
INSTALL_COMMAND ""
TEST_BEFORE_INSTALL True
)
project(openfoam_session)
cmake_minimum_required(VERSION 3.8.2)
if (POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
#if (POLICY CMP0054)
# cmake_policy(SET CMP0054 OLD)
#endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS False)
set(CMAKE_MODULE_PATH
"${SMTK_DIR}"
${CMAKE_MODULE_PATH}
)
#Add our CMake directory to the module search path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMake)
# Find SMTK
find_package(smtk REQUIRED)
# this is probably not the right way to do this, but we need the path to SMTK's
# include directory so EncodeStringFunctions.cmake finds things.
get_target_property(SMTK_INCLUDE_DIR smtkCore INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(SMTK_LIB_DIR smtkCore LOCATION)
get_filename_component(SMTK_LIB_DIR ${SMTK_LIB_DIR} DIRECTORY)
# Find ParaView
find_package(ParaView)
# ParaView's included CMake macros
include(${PARAVIEW_USE_FILE})
include(ParaViewPlugins)
# Find boost
find_package(Boost 1.64.0 REQUIRED COMPONENTS filesystem)
if(WIN32 AND MSVC)
#setup windows exception handling so we can compile properly with boost
#enabled
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
#quiet warnings about printf being potentially unsafe
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996")
#quiet warnings about truncating decorated name
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4503")
add_definitions(-DBOOST_ALL_NO_LIB)
endif()
# Setting this ensures that "make install" will leave rpaths to external
# libraries (not part of the build-tree e.g. Qt, ffmpeg, etc.) intact on
# "make install". This ensures that one can install a version of this project on
# the build machine without any issues. If this not desired, simply specify
# CMAKE_INSTALL_RPATH_USE_LINK_PATH when configuring and "make install" will
# strip all rpaths, which is the default behavior.
if (NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_PATH)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif ()
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib/")
# Use SMTK
include(SMTKMacros)
include(SMTKOperationXML)
# Header locations
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
## ----------------------- ##
## Python ##
## ----------------------- ##
# by including the correct python cmake scripts before adding pybind11, we
# work around pybind11's custom python cmake scripts without having to patch
# pybind11.
if (NOT PYTHONINTERP_FOUND)
find_package(PythonInterp 2.7 REQUIRED)
endif ()
if (NOT PYTHONLIBS_FOUND)
find_package(PythonLibs REQUIRED)
endif ()
if(MSVC)
set(PYTHON_MODULE_EXTENSION ".pyd")
else()
set(PYTHON_MODULE_EXTENSION ".so")
endif()
set(PYTHON_MODULE_PREFIX "")
find_package(pybind11 REQUIRED)
set(PYBIND11_FLAGS " ")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(PYBIND11_FLAGS "${PYBIND11_FLAGS} -Wno-shadow")
endif()
# Initialize PYTHON_MODULEDIR.
# This stores the location where we'll install our Python modules.
# Note that PYTHON_MODULEDIR may be provided if the project is being
# built as a submodule or as part of a superbuild.
if (NOT DEFINED PYTHON_MODULEDIR)
if (INSTALL_PYTHON_TO_SITE_PACKAGES)
execute_process(
COMMAND
${PYTHON_EXECUTABLE}
-c "import site; print(site.getsitepackages())[-1]"
RESULT_VARIABLE PYTHON_MODULEDIR
)
elseif(WIN32)
set(PYTHON_MODULEDIR
"bin/Lib/site-packages")
else()
set(PYTHON_MODULEDIR
"lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages")
endif()
endif()
## ----------------------- ##
## Testing ##
## ----------------------- ##
include(OpenFOAMSMTKTestingMacros)
option(ENABLE_TESTING "Build tests of OpenFOAM session?" ON)
if (ENABLE_TESTING)
enable_testing()
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib/")
endif()
add_subdirectory(smtk)
export(
TARGETS smtkOpenFOAMSession
FILE "${CMAKE_BINARY_DIR}/OpenFOAMSMTKSession-targets.cmake")
install(
EXPORT openfoam_smtk
DESTINATION lib/cmake/OpenFOAMSMTKSession
FILE OpenFOAMSMTKSession-targets.cmake)
This diff is collapsed.
add_subdirectory(session)
add_subdirectory(openfoam)
# Only include the VTK use-file in subdirectories
# that require VTK include paths. Otherwise, command
# lines get too long on some platforms.
include("${VTK_USE_FILE}")
list(APPEND CMAKE_MODULE_PATH "${VTK_MODULES_DIR}")
set(openfoamSrcs
ImportSTLFile.cxx
Registrar.cxx
Resource.cxx
Session.cxx
)
set(openfoamHeaders
ImportSTLFile.h
Registrar.h
Resource.h
Session.h
)
install(FILES PointerDefs.h DESTINATION include/smtk/${SMTK_VERSION}/smtk/bridge/openfoam)
add_library(smtkOpenFOAMSession SHARED ${openfoamSrcs})
target_compile_definitions(smtkOpenFOAMSession PRIVATE "SMTK_SCRATCH_DIR=\"${CMAKE_BINARY_DIR}/Testing/Temporary\"")
#set smtkOpenfoamSession to publicly link to smtkCore and VTK
target_link_libraries(smtkOpenFOAMSession
LINK_PUBLIC
smtkCore
smtkMeshSession
smtkIOVTK
vtkCommonDataModel
vtkPythonInterpreter
LINK_PRIVATE
vtkIOXdmf2
vtkImagingCore
vtkFiltersGeneral
vtkFiltersGeometry
vtkFiltersModeling
${Boost_LIBRARIES}
)
smtk_export_header(smtkOpenFOAMSession Exports.h)
install(
TARGETS smtkOpenFOAMSession
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
# Operators which have XML descriptions in separate files
# need to have it encoded as a string in a header.
# We do not need the path to the generated header (appended
# to openfoamOperatorXML) since the operators themselves include
# the header in their implementations.
# Install the headers
smtk_public_headers(smtkOpenFOAMSession ${openfoamHeaders})
if (TARGET smtkPluginSupport)
include(SMTKPluginMacros)
add_smtk_plugin(
smtkOpenFOAMSessionPlugin "1.0"
REGISTRAR smtk::session::openfoam::Registrar
MANAGERS smtk::operation::Manager smtk::resource::Manager
LIBRARIES smtkCore smtkOpenFOAMSession)
install(
TARGETS smtkOpenFOAMSession
EXPORT openfoam_smtk
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
endif()
if (SMTK_ENABLE_PYTHON_WRAPPING)
set(openfoamPySrcs
operators/add_obstacle.py
operators/constant_input_files.py
operators/create_wind_tunnel.py
operators/set_main_controls.py
operators/initialize_working_environment.py
)
set(openfoam_pymodulefiles)
set(openfoam_pyxmlfiles)
smtk_pyoperation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/add_obstacle.sbt" openfoam_pyxmlfiles)
smtk_pyoperation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/create_wind_tunnel.sbt" openfoam_pyxmlfiles)
smtk_pyoperation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/set_main_controls.sbt" openfoam_pyxmlfiles)
smtk_pyoperation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/initialize_working_environment.sbt" openfoam_pyxmlfiles)
foreach(pyfile ${openfoamPySrcs})
get_filename_component(filename ${pyfile} NAME)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/${pyfile}"
"${PROJECT_BINARY_DIR}/openfoamsession/${filename}" @ONLY
)
list(APPEND openfoam_pymodulefiles "${PROJECT_BINARY_DIR}/openfoamsession/${filename}")
endforeach()
foreach(pyfile ${openfoam_pyxmlfiles})
get_filename_component(filename ${pyfile} NAME)
configure_file(
"${pyfile}"
"${CMAKE_BINARY_DIR}/openfoamsession/${filename}" @ONLY
)
list(APPEND openfoam_pymodulefiles "${CMAKE_BINARY_DIR}/openfoamsession/${filename}")
endforeach()
install(
FILES ${openfoam_pymodulefiles}
DESTINATION "${PYTHON_MODULEDIR}/openfoamsession"
)
add_subdirectory(pybind11)
endif()
if (ENABLE_TESTING)
add_subdirectory(testing)
endif()
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed 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/openfoam/ImportSTLFile.h"
#include "smtk/extension/vtk/io/mesh/ImportVTKData.h"
#include "smtk/mesh/core/Interface.h"
#include "smtk/mesh/core/MeshSet.h"
#include "smtk/mesh/core/Resource.h"
#include "vtkCellData.h"
#include "vtkSTLReader.h"
namespace smtk
{
namespace session
{
namespace openfoam
{
ImportSTLFile::ImportSTLFile()
{
}
smtk::mesh::ResourcePtr ImportSTLFile::operator()(
const std::string& filename, const smtk::mesh::InterfacePtr& interface) const
{
smtk::mesh::ResourcePtr resource = smtk::mesh::Resource::create(interface);
return this->operator()(filename, resource) ? resource : smtk::mesh::ResourcePtr();
}
bool ImportSTLFile::operator()(const std::string& filename, smtk::mesh::ResourcePtr resource) const
{
vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
reader->ScalarTagsOn();
reader->SetFileName(filename.c_str());
reader->Update();
reader->GetOutput()->Register(reader);
vtkDataSet* data = vtkDataSet::SafeDownCast(reader->GetOutput());
smtk::extension::vtk::io::mesh::ImportVTKData importVTKData;
if (data->GetCellData()->HasArray("STLSolidLabeling"))
{
return importVTKData(data, resource, "STLSolidLabeling");
}
else
{
return importVTKData(data, resource, "");
}
}
}
}
}
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed 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_smtk_session_openfoam_ImportSTLFile_h
#define __smtk_smtk_session_openfoam_ImportSTLFile_h
#include "smtk/session/openfoam/Exports.h"
#include "smtk/PublicPointerDefs.h"
#include <string>
class vtkDataSet;
namespace smtk
{
namespace mesh
{
class MeshSet;
}
}
namespace smtk
{
namespace session
{
namespace openfoam
{
//Import an STL file to a smtk::mesh::resource.
class SMTKOPENFOAMSESSION_EXPORT ImportSTLFile
{
public:
explicit ImportSTLFile();
//Import an STL file as a collection.
smtk::mesh::ResourcePtr operator()(
const std::string& filename, const smtk::mesh::InterfacePtr& interface) const;
bool operator()(const std::string& filename, smtk::mesh::ResourcePtr resource) const;
};
}
}
}
#endif //__smtk_session_openfoam_ImportSTLFile_h
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed 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 PublicPointerDefs.h -
// .SECTION Description
// .SECTION See Also
#ifndef __smtk_session_openfoam_PointerDefs_h
#define __smtk_session_openfoam_PointerDefs_h
#include "smtk/SharedPtr.h"
#include "smtk/SystemConfig.h"
namespace smtk
{ //session relates pointer classes
namespace session
{
namespace openfoam
{
class Session;
typedef smtk::shared_ptr<smtk::session::openfoam::Session> SessionPtr;
}
}
}
#endif
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed 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/openfoam/Registrar.h"
#include "smtk/session/mesh/operators/Import.h"
#include "smtk/session/mesh/operators/Read.h"
#include "smtk/session/mesh/operators/Write.h"
#include "smtk/session/openfoam/Resource.h"
#include "smtk/operation/RegisterPythonOperations.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"
namespace smtk
{
namespace session
{
namespace openfoam
{
namespace
{
typedef std::tuple<> OperationList;
}
void Registrar::registerTo(const smtk::resource::Manager::Ptr& resourceManager)
{
resourceManager->registerResource<smtk::session::openfoam::Resource>();
}
void Registrar::registerTo(const smtk::operation::Manager::Ptr& operationManager)
{
// Register operations
operationManager->registerOperations<OperationList>();
smtk::operation::registerPythonOperations(
operationManager, "openfoamsession.initialize_working_environment");
smtk::operation::CreatorGroup(operationManager)
.registerOperation<smtk::session::openfoam::Resource>(
"openfoamsession.initialize_working_environment.initialize_working_environment");
smtk::operation::registerPythonOperations(
operationManager, "openfoamsession.add_obstacle");
smtk::operation::registerPythonOperations(
operationManager, "openfoamsession.create_wind_tunnel");
smtk::operation::registerPythonOperations(
operationManager, "openfoamsession.set_main_controls");
}
void Registrar::unregisterFrom(const smtk::resource::Manager::Ptr& resourceManager)
{
resourceManager->unregisterResource<smtk::session::openfoam::Resource>();
}
void Registrar::unregisterFrom(const smtk::operation::Manager::Ptr& operationManager)
{
operationManager->unregisterOperations<OperationList>();
}
}
}
}
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed 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_openfoam_Registrar_h
#define __smtk_session_openfoam_Registrar_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"
#include "smtk/resource/Manager.h"
#include "smtk/session/mesh/Registrar.h"
#include "smtk/session/openfoam/Exports.h"
namespace smtk
{
namespace session
{
namespace openfoam
{
class SMTKOPENFOAMSESSION_EXPORT Registrar
{
public:
using Dependencies =
std::tuple<operation::Registrar, model::Registrar, attribute::Registrar, mesh::Registrar>;
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&);
};
}
}
}
#endif
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed 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/openfoam/Resource.h"
namespace smtk
{
namespace session
{
namespace openfoam
{
Resource::Resource(const smtk::common::UUID& id, resource::Manager::Ptr manager)
: smtk::resource::DerivedFrom<Resource, smtk::model::Resource>(id, manager)
{
}
Resource::~Resource()
{
}
Resource::Resource(resource::Manager::Ptr manager)
: smtk::resource::DerivedFrom<Resource, smtk::model::Resource>(manager)
{
}
void Resource::setSession(const Session::Ptr& session)
{
m_session = session->shared_from_this();
this->registerSession(m_session);
}
}
}
}
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed 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_openfoam_Resource_h
#define __smtk_session_openfoam_Resource_h
#include "smtk/session/openfoam/Exports.h"
#include "smtk/session/openfoam/Session.h"
#include "smtk/model/Resource.h"
#include "smtk/resource/DerivedFrom.h"
#include "smtk/resource/Manager.h"
#include "smtk/resource/Resource.h"
namespace smtk
{
namespace session
{
namespace openfoam
{
class SMTKOPENFOAMSESSION_EXPORT Resource
: public smtk::resource::DerivedFrom<Resource, smtk::model::Resource>
{
public:
smtkTypeMacro(smtk::session::openfoam::Resource);
smtkSharedPtrCreateMacro(smtk::resource::Resource);
virtual ~Resource() override;
Session::Ptr session() const { return m_session; }
void setSession(const Session::Ptr& session);
protected:
Resource(const smtk::common::UUID&, smtk::resource::Manager::Ptr manager = nullptr);
Resource(smtk::resource::Manager::Ptr manager = nullptr);
Session::Ptr m_session;
};
}
}
}
#endif
//=============================================================================