Commit ef92b714 authored by Hina Shah's avatar Hina Shah

COMP Adding configure time option to use pre-installed ODE

parent c0d1505a
set(iMSTK_ODE_DEPENDS)
if( iMSTK_USE_ODE)
# add ode if requested
set(iMSTK_ODE_DEPENDS libodedouble)
endif()
#-----------------------------------------------------------------------------
# Create target
#-----------------------------------------------------------------------------
......@@ -11,6 +18,7 @@ imstk_add_library( SceneElements
TimeIntegrators
DynamicalModels
Solvers
${iMSTK_ODE_DEPENDS}
)
#-----------------------------------------------------------------------------
......
......@@ -18,9 +18,50 @@
limitations under the License.
=========================================================================*/
#ifdef iMSTK_USE_ODE
#include "imstkRigidObject.h"
#include "ode/ode.h"
namespace imstk
{
void RigidObject::setup()
{
// dynamics and collision objects
dWorldID world;
dSpaceID space;
dBodyID body;
dGeomID geom;
dMass m;
dJointGroupID contactgroup;
dInitODE();
// create world
world = dWorldCreate();
space = dHashSpaceCreate(0);
dWorldSetGravity(world, 0, 0, -0.2);
dWorldSetCFM(world, 1e-5);
dCreatePlane(space, 0, 0, 1, 0);
contactgroup = dJointGroupCreate(0);
// create object
body = dBodyCreate(world);
geom = dCreateSphere(space, 0.5);
dMassSetSphere(&m, 1, 0.5);
dBodySetMass(body, &m);
dGeomSetBody(geom, body);
// set initial position
dBodySetPosition(body, 0, 0, 3);
// run simulation
char** filename;
filename = new char*;
// clean up
dJointGroupDestroy(contactgroup);
dSpaceDestroy(space);
dWorldDestroy(world);
dCloseODE();
}
} // imstk
#endif
......@@ -47,6 +47,9 @@ public:
m_type = Type::Rigid;
}
// This is just a simple function to test ODE
void setup();
///
/// \brief Destructor
///
......
......@@ -119,5 +119,7 @@ ExternalProject_Add( ${PROJECT_NAME}
CMAKE_ARGS
-D${PROJECT_NAME}_SUPERBUILD:BOOL=OFF
-D${PROJECT_NAME}_USE_OMNI:BOOL=${${PROJECT_NAME}_USE_OMNI}
-D${PROJECT_NAME}_USE_ODE:BOOL=${${PROJECT_NAME}_USE_ODE}
-DODE_ROOT_DIR:PATH=${ODE_ROOT_DIR}
DEPENDS ${${PROJECT_NAME}_DEPENDENCIES}
)
#----------------------------------------------------------
# ODE does not have a cmake version.
# Use of this file is a workaround to create a mode for setting
# up iMSTK to build with ODE.
# This piece of code also sets other necessary directories.
# It is assumed that ODE was compiled with double precision.
#
# When ODE is configured with cmake (in future),
# this script should be updated.
#----------------------------------------------------------
set(USE_SYSTEM_ODE 1 CACHE BOOL "Use system ODE" FORCE)
#-----------------------------------------------------------------------------
# Add External Project
#-----------------------------------------------------------------------------
include(imstkAddExternalProject)
imstk_add_external_project( ODE
DOWNLOAD_COMMAND ${SKIP_STEP_COMMAND}
CONFIGURE_COMMAND ${SKIP_STEP_COMMAND}
BUILD_COMMAND ${SKIP_STEP_COMMAND}
INSTALL_COMMAND ${SKIP_STEP_COMMAND}
RELATIVE_INCLUDE_PATH ""
DEPENDENCIES ""
#VERBOSE
)
mark_as_superbuild(ODE_INCLUDE_DIR)
mark_as_superbuild(ODE_LIBRARY)
#-----------------------------------------------------------------------------
if(WIN32)
# Since on windows there is no support for Runtime Path, we need to copy
# the ODE shared library.
if(NOT DEFINED ODE_SHARED_LIBRARY)
get_filename_component(_dir ${ODE_LIBRARY} DIRECTORY)
get_filename_component(_name_we ${ODE_LIBRARY} NAME_WE)
set(ODE_SHARED_LIBRARY "${_dir}/${_name_we}.dll")
if(NOT EXISTS "${ODE_SHARED_LIBRARY}")
message(FATAL_ERROR "ODE_SHARED_LIBRARY corresponds to a nonexistent file. ODE_SHARED_LIBRARY is '${ODE_SHARED_LIBRARY}'")
endif()
endif()
set(_dest "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/")
ExternalProject_Add_Step( ODE copy_shared_library
COMMAND ${CMAKE_COMMAND} -E make_directory ${_dest}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ODE_SHARED_LIBRARY} ${_dest}
COMMENT "Copy ODE shared library into ${_dest}"
DEPENDERS download
USES_TERMINAL 1
)
endif()
# Finding ODE from a pre-installed directory
# Find ODE include directories and libraries
find_path(ODE_INCLUDE_DIR
NAMES
ode/ode.h
PATHS
${ODE_ROOT_DIR}
${ODE_ROOT_DIR}/include
NO_DEFAULT_PATH
)
# Create library directory hints
list(APPEND ODE_LIBRARY_HINTS ${ODE_ROOT_DIR}/lib)
# Windows compilation has special directories.
set(_ode_lib_name_win)
if(WIN32)
list(APPEND ODE_LIBRARY_HINTS ${ODE_ROOT_DIR}/lib/ReleaseDoubleDLL)
list(APPEND ODE_LIBRARY_HINTS ${ODE_ROOT_DIR}/lib/DebugDoubleDLL)
set(_ode_lib_name_win ode_double)
list(APPEND _ode_lib_name_win ode_doubled)
endif()
find_library(ODE_LIBRARY
NAMES
${_ode_lib_name_win}
ode
HINTS
${ODE_LIBRARY_HINTS}
)
list(APPEND ODE_LIBRARIES ${ODE_LIBRARY})
if(NOT ODE_FIND_QUIETLY)
message(STATUS "ODE_INCLUDE_DIR is ${ODE_INCLUDE_DIR}")
message(STATUS "ODE_LIBRARIES is ${ODE_LIBRARIES}")
endif()
#-----------------------------------------------------------------------------
# Find package
#-----------------------------------------------------------------------------
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ODE
REQUIRED_VARS
ODE_INCLUDE_DIR
ODE_LIBRARIES
)
#-----------------------------------------------------------------------------
# If missing target, create it
#-----------------------------------------------------------------------------
if(ODE_FOUND AND NOT TARGET libodedouble)
add_library(libodedouble INTERFACE IMPORTED)
set_target_properties(libodedouble PROPERTIES
INTERFACE_LINK_LIBRARIES "${ODE_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${ODE_INCLUDE_DIR}"
)
endif()
\ No newline at end of file
......@@ -103,6 +103,16 @@ if(${PROJECT_NAME}_SUPERBUILD)
imstk_define_dependency(VRPN)
imstk_define_dependency(LibNiFalcon)
option(${PROJECT_NAME}_USE_ODE "Build iMSTK with ODE support." OFF)
if(${PROJECT_NAME}_USE_ODE)
imstk_define_dependency(ODE)
endif()
#----------------------------------------------------
# Setting up ODE from preinstalled directories.
#----------------------------------------------------
#include(CMake/External/External_ODE.cmake)
if(BUILD_TESTING)
imstk_define_dependency(GoogleTest)
......@@ -217,6 +227,17 @@ else()
remove_definitions( -DVRPN_USE_PHANTOM_SERVER )
endif()
# ODE
if(${PROJECT_NAME}_USE_ODE)
find_package(ODE)
# Assuming that ODE was compiled with Double precision.
add_definitions( -DdDOUBLE ) # Needed by ODE library.
add_definitions( -DiMSTK_USE_ODE )
else()
remove_definitions( -DdDouble )
remove_definitions( -DiMSTK_USE_ODE )
endif()
# Google Test
if(BUILD_TESTING)
find_package( GoogleTest REQUIRED )
......
......@@ -33,6 +33,7 @@
#include "imstkSceneObject.h"
#include "imstkLight.h"
#include "imstkCamera.h"
#include "imstkRigidObject.h"
// Time Integrators
#include "imstkBackwardEuler.h"
......@@ -3226,6 +3227,34 @@ void testVirtualCouplingCylinder()
sdk->startSimulation(false);
}
void testRigidBody()
{
// SDK and Scene
auto sdk = std::make_shared<imstk::SimulationManager>();
auto scene = sdk->createNewScene("RigidObjectPhysocs");
// Create a plane in the scene (visual)
auto planeGeom = std::make_shared<imstk::Plane>();
planeGeom->setWidth(10);
planeGeom->setPosition(0.0, -50, 0.0);
auto planeObj = std::make_shared<imstk::VisualObject>("Plane");
planeObj->setVisualGeometry(planeGeom);
scene->addSceneObject(planeObj);
#ifdef iMSTK_USE_ODE
auto rgidibody = imstk::RigidObject("Rigid Object Yo!");
rgidibody.setup();
#endif
// Move Camera
auto cam = scene->getCamera();
cam->setPosition(imstk::Vec3d(200, 200, 200));
cam->setFocalPoint(imstk::Vec3d(0, 0, 0));
//Run
sdk->setCurrentScene(scene);
sdk->startSimulation(false);
}
int main()
{
std::cout << "****************\n"
......@@ -3263,12 +3292,13 @@ int main()
/*------------------
Test physics
------------------*/
testPbdVolume();
//testPbdVolume();
//testPbdCloth();
//testPbdCollision();
testPbdFluidBenchmarking();
testPbdFluid();
testDeformableBody();
//testPbdFluidBenchmarking();
//testPbdFluid();
//testDeformableBody();
//testDeformableBodyCollision();
//liverToolInteraction();
//testPicking();
......@@ -3299,7 +3329,7 @@ int main()
//testVirtualCoupling();
//testBoneDrilling();
//testVirtualCouplingCylinder();
testRigidBody();
return 0;
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment