Skip to content

Commit

Permalink
[rerun] Add experimental integration with rerun
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Mar 29, 2024
1 parent d9af2d2 commit b3a03ef
Show file tree
Hide file tree
Showing 8 changed files with 5,697 additions and 1,719 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ dart_option(DART_FAST_DEBUG "Add -O1 option for DEBUG mode build" OFF)
dart_option(DART_FORCE_COLORED_OUTPUT
"Always produce ANSI-colored output (GNU/Clang only)." OFF)
dart_option(DART_USE_SYSTEM_IMGUI "Use system ImGui" OFF)
dart_option(DART_BUILD_RERUN "Build with Rerun SDK" OFF)
dart_option(DART_IN_CI "Indicate building DART as part of CI" OFF)

#===============================================================================
Expand Down Expand Up @@ -199,12 +200,12 @@ endif()
set_property(CACHE DART_ACTIVE_LOG_LEVEL PROPERTY STRINGS TRACE DEBUG INFO WARN ERROR FATAL OFF)

if(DART_BUILD_MODE_DEBUG)
option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
dart_option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
else()
option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" ON)
dart_option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" ON)
endif()

option(DART_BUILD_WHEELS "Indicate building dartpy for wheels" OFF)
dart_option(DART_BUILD_WHEELS "Indicate building dartpy for wheels" OFF)

#===============================================================================
# Find dependencies
Expand Down
9 changes: 8 additions & 1 deletion cmake/DARTFindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,18 @@ option(DART_SKIP_spdlog "If ON, do not use spdlog even if it is found." OFF)
mark_as_advanced(DART_SKIP_spdlog)
dart_find_package(spdlog)

if(DART_BUILD_RERUN)
include(FetchContent)
FetchContent_Declare(rerun_sdk
URL https://github.com/rerun-io/rerun/releases/download/0.14.1/rerun_cpp_sdk.zip
)
FetchContent_MakeAvailable(rerun_sdk)
endif()

#--------------------
# Misc. dependencies
#--------------------

# Doxygen
find_package(Doxygen QUIET)
dart_check_optional_package(DOXYGEN "generating API documentation" "doxygen")

2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ add_subdirectory(fetch)

# Deprecated examples
add_subdirectory(deprecated_examples)

add_subdirectory(rerun)
8 changes: 7 additions & 1 deletion examples/rerun/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
cmake_minimum_required(VERSION 3.22.1)

get_filename_component(example_name ${CMAKE_CURRENT_LIST_DIR} NAME)
set(example_name example-${example_name})

project(${example_name})

set(required_components utils-urdf)
set(required_libraries dart dart-utils-urdf)
set(required_libraries dart dart-utils-urdf rerun_sdk)

# TODO: Fix dart_build_example_in_source() to handle this case
if(NOT TARGET rerun_sdk)
return()
endif()

if(DART_IN_SOURCE_BUILD)
dart_build_example_in_source(${example_name} LINK_LIBRARIES ${required_libraries})
Expand Down
20 changes: 20 additions & 0 deletions examples/rerun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This project is dependent on DART. Please make sure a proper version of DART is
installed before building this project.

## Build Instructions

From this directory:

$ mkdir build
$ cd build
$ cmake ..
$ make

## Execute Instructions

Launch the executable from the build directory above:

$ ./{generated_executable}

Follow the instructions detailed in the console.

91 changes: 91 additions & 0 deletions examples/rerun/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2011-2024, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/main/LICENSE
*
* 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/urdf/urdf.hpp>
#include <dart/utils/utils.hpp>

#include <dart/simulation/World.hpp>

#include <dart/dart.hpp>

#include <rerun.hpp>
#include <rerun/demo_utils.hpp>

using namespace dart;
using namespace dart::common;
using namespace dart::dynamics;
using namespace dart::simulation;
using namespace dart::utils;
using namespace dart::math;
using namespace rerun::demo;

int main()
{
auto shape
= std::make_shared<dynamics::BoxShape>(Eigen::Vector3d(0.3, 0.3, 0.3));

// Create a box-shaped rigid body
auto skeleton = dynamics::Skeleton::create();
auto jointAndBody
= skeleton->createJointAndBodyNodePair<dynamics::FreeJoint>();
auto body = jointAndBody.second;
body->createShapeNodeWith<
dynamics::VisualAspect,
dynamics::CollisionAspect,
dynamics::DynamicsAspect>(shape);

// Create a world and add the rigid body
auto world = simulation::World::create();
world->addSkeleton(skeleton);

// Spawn Rerun viewer
const auto rec = rerun::RecordingStream("rerun_example_cpp");
rec.spawn().exit_on_failure();

for (auto i = 0; i < 1000; ++i) {
world->step();

for (auto j = 0u; j < world->getNumSkeletons(); ++j) {
auto skel = world->getSkeleton(j);

for (auto k = 0u; k < skel->getNumBodyNodes(); ++k) {
auto body = skel->getBodyNode(k);
body->eachShapeNodeWith<dynamics::VisualAspect>(
[&](const dynamics::ShapeNode* shapeNode) {
const auto& visualAspect = shapeNode->getVisualAspect();
shapeNode->getTransform();
const auto& shape = shapeNode->getShape();
});
}
}
}
}
Loading

0 comments on commit b3a03ef

Please sign in to comment.