Skip to content

Commit

Permalink
Merge pull request #842 from dartsim/building_examples_tutorials
Browse files Browse the repository at this point in the history
Allow examples and tutorials to be built out of DART source tree
  • Loading branch information
jslee02 committed Feb 5, 2017
2 parents 37c0fd1 + 3cbbbc7 commit ad75443
Show file tree
Hide file tree
Showing 197 changed files with 2,181 additions and 769 deletions.
78 changes: 59 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ set(INCLUDE_INSTALL_DIR "include")
set(LIBRARY_INSTALL_DIR "lib")
set(CONFIG_INSTALL_DIR "share/${PROJECT_NAME}/cmake")

# Set relative location to install additional documentation (sample data,
# examples, and tutorials)
set(DART_ADDITIONAL_DOCUMENTATION_INSTALL_PATH "share/doc/${PROJECT_NAME}")

set(CMAKE_DEBUG_POSTFIX "d")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

Expand Down Expand Up @@ -246,21 +250,6 @@ if(DART_VERBOSE)
message(STATUS "CMAKE_BINARY_DIR : ${CMAKE_BINARY_DIR}")
endif(DART_VERBOSE)

#===============================================================================
# Helper Functions
#===============================================================================
function(dart_add_example)
dart_property_add(DART_EXAMPLES ${ARGN})
endfunction(dart_add_example)

function(dart_add_tutorial)
dart_property_add(DART_TUTORIALS ${ARGN})
endfunction(dart_add_tutorial)

function(dart_format_add)
dart_property_add(DART_FORMAT_FILES ${ARGN})
endfunction()

#===============================================================================
# Add sub-directories
#===============================================================================
Expand All @@ -275,9 +264,36 @@ if(TINYXML_FOUND AND TINYXML2_FOUND AND BULLET_FOUND)

if (OPENGL_FOUND AND HAVE_GLUT)

# Add an "examples" target to build examples.
add_subdirectory(examples EXCLUDE_FROM_ALL)
# Add example targets
dart_add_example(examples/addDeleteSkels dart dart-utils-urdf dart-gui)
dart_add_example(examples/atlasSimbicon dart dart-utils-urdf dart-gui)
dart_add_example(examples/bipedStand dart dart-utils-urdf dart-gui)
dart_add_example(examples/hardcodedDesign dart dart-utils-urdf dart-gui)
dart_add_example(examples/hybridDynamics dart dart-utils-urdf dart-gui)
dart_add_example(examples/jointConstraints dart dart-utils-urdf dart-gui)
dart_add_example(examples/mixedChain dart dart-utils-urdf dart-gui)
dart_add_example(examples/operationalSpaceControl dart dart-utils-urdf dart-gui)
dart_add_example(examples/rigidChain dart dart-utils-urdf dart-gui)
dart_add_example(examples/rigidLoop dart dart-utils-urdf dart-gui)
dart_add_example(examples/rigidShapes dart dart-utils-urdf dart-gui)
dart_add_example(examples/simpleFrames dart dart-utils-urdf dart-gui)
dart_add_example(examples/softBodies dart dart-utils-urdf dart-gui)
dart_add_example(examples/speedTest dart dart-utils-urdf dart-gui)
dart_add_example(examples/vehicle dart dart-utils-urdf dart-gui)

if(HAVE_OPENSCENEGRAPH)
dart_add_example(examples/osgExamples/osgAtlasPuppet dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgAtlasSimbicon dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgDragAndDrop dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgEmpty dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgHuboPuppet dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgImGui dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgOperationalSpaceControl dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgSoftBodies dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgTinkertoy dart dart-utils-urdf dart-gui-osg)
endif()

# Add an "examples" target to build examples.
get_property(examples GLOBAL PROPERTY DART_EXAMPLES)
add_custom_target(examples DEPENDS ${examples})

Expand All @@ -292,9 +308,17 @@ if(TINYXML_FOUND AND TINYXML2_FOUND AND BULLET_FOUND)
message(STATUS "Adding ${examples_length} examples")
endif(DART_VERBOSE)

# Add a "tutorials" target to build tutorials.
add_subdirectory(tutorials EXCLUDE_FROM_ALL)
# Add tutorial targets
dart_add_tutorial(tutorials/tutorialBiped dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialBiped-Finished dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialCollisions dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialCollisions-Finished dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialDominoes dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialDominoes-Finished dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialMultiPendulum dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialMultiPendulum-Finished dart-utils-urdf dart-gui)

# Add a "tutorials" target to build tutorials.
get_property(tutorials GLOBAL PROPERTY DART_TUTORIALS)
add_custom_target(tutorials DEPENDS ${tutorials})

Expand Down Expand Up @@ -378,6 +402,22 @@ install(FILES ${PC_CONFIG_OUT} DESTINATION lib/pkgconfig)
# Install a Catkin 'package.xml' file. This is required by REP-136.
install(FILES package.xml DESTINATION share/${PROJECT_NAME})

#===============================================================================
# Install sample data, examples, and tutorials
#===============================================================================

# Sample data
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data"
DESTINATION ${DART_ADDITIONAL_DOCUMENTATION_INSTALL_PATH})

# Examples source
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/examples"
DESTINATION ${DART_ADDITIONAL_DOCUMENTATION_INSTALL_PATH})

# Tutorials source
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tutorials"
DESTINATION ${DART_ADDITIONAL_DOCUMENTATION_INSTALL_PATH})

#===============================================================================
# Uninstall
#===============================================================================
Expand Down
51 changes: 51 additions & 0 deletions cmake/DARTMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ macro(dart_get_filename_components _var _cacheDesc)
endforeach()
endmacro()

#===============================================================================
# Generate directory list of ${curdir}
# Usage:
# dart_get_subdir_list(var curdir)
#===============================================================================
macro(dart_get_subdir_list var curdir)
file(GLOB children RELATIVE ${curdir} "${curdir}/*")
set(dirlist "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
LIST(APPEND dirlist ${child})
endif()
endforeach()
set(${var} ${dirlist})
endmacro()

#===============================================================================
# Generate header file list to a cached list.
# Usage:
Expand Down Expand Up @@ -104,3 +120,38 @@ function(dart_check_optional_package variable component dependency)
return()
endif()
endfunction()

#===============================================================================
function(dart_add_custom_target rel_dir property_name)
set(abs_dir "${CMAKE_CURRENT_LIST_DIR}/${rel_dir}")

if(NOT IS_DIRECTORY ${abs_dir})
message(SEND_ERROR "Failed to find directory: ${abs_dir}")
endif()

# Use the directory name as the executable name
get_filename_component(target_name ${rel_dir} NAME)

file(GLOB hdrs "${abs_dir}/*.hpp")
file(GLOB srcs "${abs_dir}/*.cpp")
if(srcs)
add_executable(${target_name} EXCLUDE_FROM_ALL ${hdrs} ${srcs})
target_link_libraries(${target_name} ${ARGN})
dart_property_add(${property_name} ${target_name})
endif()
endfunction()

#===============================================================================
function(dart_add_example rel_dir)
dart_add_custom_target(${rel_dir} DART_EXAMPLES ${ARGN})
endfunction()

#===============================================================================
function(dart_add_tutorial rel_dir)
dart_add_custom_target(${rel_dir} DART_TUTORIALS ${ARGN})
endfunction(dart_add_tutorial)

#===============================================================================
function(dart_format_add)
dart_property_add(DART_FORMAT_FILES ${ARGN})
endfunction()
4 changes: 4 additions & 0 deletions dart/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@
#cmakedefine01 HAVE_BULLET_COLLISION
#cmakedefine01 HAVE_FLANN

// Deprecated in DART 6.2 and will be removed in DART 7.
#define DART_ROOT_PATH "@CMAKE_SOURCE_DIR@/"
#define DART_DATA_PATH "@CMAKE_SOURCE_DIR@/data/"

#define DART_DATA_LOCAL_PATH "@CMAKE_SOURCE_DIR@/data/"
#define DART_DATA_GLOBAL_PATH "@CMAKE_INSTALL_PREFIX@/@DART_ADDITIONAL_DOCUMENTATION_INSTALL_PATH@/data/"

// See #451
#cmakedefine01 ASSIMP_AISCENE_CTOR_DTOR_DEFINED
#cmakedefine01 ASSIMP_AIMATERIAL_CTOR_DTOR_DEFINED
Expand Down
2 changes: 2 additions & 0 deletions dart/gui/SimWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ namespace gui {

SimWindow::SimWindow()
: Win3D() {
mWorld = std::make_shared<simulation::World>();

mBackground[0] = 1.0;
mBackground[1] = 1.0;
mBackground[2] = 1.0;
Expand Down
143 changes: 143 additions & 0 deletions dart/utils/DartResourceRetriever.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright (c) 2017, Graphics Lab, Georgia Tech Research Corporation
* Copyright (c) 2017, Personal Robotics Lab, Carnegie Mellon University
* All rights reserved.
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include "dart/utils/DartResourceRetriever.hpp"

#include <iostream>
#include <fstream>
#include "dart/config.hpp"
#include "dart/common/Console.hpp"
#include "dart/common/LocalResourceRetriever.hpp"

namespace dart {
namespace utils {

//==============================================================================
DartResourceRetriever::DartResourceRetriever()
: mLocalRetriever(std::make_shared<common::LocalResourceRetriever>())
{
addDataDirectory(DART_DATA_LOCAL_PATH);
addDataDirectory(DART_DATA_GLOBAL_PATH);
}

//==============================================================================
bool DartResourceRetriever::exists(const common::Uri& uri)
{
std::string relativePath;
if (!resolveDataUri(uri, relativePath))
return false;

if (uri.mAuthority.get() == "sample")
{
for (const auto& dataPath : mDataDirectories)
{
common::Uri fileUri;
fileUri.fromPath(dataPath + relativePath);

if (mLocalRetriever->exists(fileUri))
return true;
}
}
else
{
if (mLocalRetriever->exists(uri))
return true;
}

return false;
}

//==============================================================================
common::ResourcePtr DartResourceRetriever::retrieve(const common::Uri& uri)
{
std::string relativePath;
if (!resolveDataUri(uri, relativePath))
return nullptr;

if (uri.mAuthority.get() == "sample")
{
for (const auto& dataPath : mDataDirectories)
{
common::Uri fileUri;
fileUri.fromPath(dataPath + relativePath);

if (const auto resource = mLocalRetriever->retrieve(fileUri))
return resource;
}
}
else
{
if (const auto resource = mLocalRetriever->retrieve(uri))
return resource;
}

return nullptr;
}

//==============================================================================
void DartResourceRetriever::addDataDirectory(
const std::string& dataDirectory)
{
// Strip a trailing slash.
std::string normalizedDataDirectory;
if (!dataDirectory.empty() && dataDirectory.back() == '/')
{
normalizedDataDirectory
= dataDirectory.substr(0, dataDirectory.size() - 1);
}
else
{
normalizedDataDirectory = dataDirectory;
}

mDataDirectories.push_back(normalizedDataDirectory);
}

//==============================================================================
bool DartResourceRetriever::resolveDataUri(
const common::Uri& uri,
std::string& relativePath) const
{
if (uri.mScheme.get_value_or("dart") != "dart")
return false;

if (!uri.mPath)
{
dtwarn << "[DartResourceRetriever::resolveDataUri] Failed extracting"
" relative path from URI '" << uri.toString() << "'.\n";
return false;
}
relativePath = uri.mPath.get_value_or("");

return true;
}

} // namespace utils
} // namespace dart
Loading

0 comments on commit ad75443

Please sign in to comment.