Skip to content

Commit

Permalink
Merge pull request #1 from matiasvc/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
matiasvc authored Feb 21, 2021
2 parents e46f4f3 + aecab15 commit 3ca3cd9
Show file tree
Hide file tree
Showing 35 changed files with 1,219 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[submodule "Catch2"]
path = test/Catch2
path = test/unit-tests/Catch2
url = [email protected]:catchorg/Catch2.git
branch = v2.x
[submodule "imgui"]
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_subdirectory(Image2D-Example)
add_subdirectory(Inputs-Example)
add_subdirectory(Primitives3D-Example)
add_subdirectory(RGBD-Example)
add_subdirectory(SimpleLinePlot-Example)
21 changes: 0 additions & 21 deletions examples/Image2D-Example/CMakeLists.txt

This file was deleted.

24 changes: 24 additions & 0 deletions examples/Inputs-Example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.10)
project(inputs-example)

add_executable(
inputs-example
main.cpp
)

set_target_properties(
inputs-example PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)

# This if check is used to work better with a local copy of Toucan.
# In a regular project the 'if' can be omitted, as the 'find_package' command should always be called.
if (NOT Toucan_FOUND)
find_package(Toucan REQUIRED)
endif (NOT Toucan_FOUND)

target_link_libraries(
inputs-example
PRIVATE Toucan::Toucan
)
81 changes: 81 additions & 0 deletions examples/Inputs-Example/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <Toucan/Toucan.h>

#include <chrono>
#include <thread>

int main() {

Toucan::Initialize();

bool checkbox_value = true;

float slider_float_value = 0.0;
Toucan::Vector2f slider_float2_value = Toucan::Vector2f::Zero();
Toucan::Vector3f slider_float3_value = Toucan::Vector3f::Zero();
Toucan::Vector4f slider_float4_value = Toucan::Vector4f::Zero();

int slider_int_value = 0;
Toucan::Vector2i slider_int2_value = Toucan::Vector2i::Zero();
Toucan::Vector3i slider_int3_value = Toucan::Vector3i::Zero();
Toucan::Vector4i slider_int4_value = Toucan::Vector4i::Zero();

Toucan::Color color_value = Toucan::Color::White();

while (Toucan::IsWindowOpen()) {
Toucan::BeginInputWindow("Inputs");
{
if (Toucan::ShowButton("Button")) {
std::cout << "Button clicked\n";
}

if (Toucan::ShowCheckbox("Checkbox", checkbox_value)) {
std::cout << "Checkbox value changed to:\n" << checkbox_value << '\n';
}

if (Toucan::ShowSliderFloat("Slider float", slider_float_value)) {
std::cout << "Slider float value changed to:\n" << slider_float_value << '\n';
}

if (Toucan::ShowSliderFloat2("Slider float 2", slider_float2_value)) {
std::cout << "Slider float 2 value changed to:\n" << slider_float2_value << '\n';
}

if (Toucan::ShowSliderFloat3("Slider float 3", slider_float3_value)) {
std::cout << "Slider float 3 value changed to:\n" << slider_float3_value << '\n';
}

if (Toucan::ShowSliderFloat4("Slider float 4", slider_float4_value)) {
std::cout << "Slider float 4 value changed to:\n" << slider_float4_value << '\n';
}

if (Toucan::ShowSliderInt("Slider int", slider_int_value)) {
std::cout << "Slider int value changed to:\n" << slider_int_value << '\n';
}

if (Toucan::ShowSliderInt2("Slider int 2", slider_int2_value)) {
std::cout << "Slider int 2 value changed to:\n" << slider_int2_value << '\n';
}

if (Toucan::ShowSliderInt3("Slider int 3", slider_int3_value)) {
std::cout << "Slider int 3 value changed to:\n" << slider_int3_value << '\n';
}

if (Toucan::ShowSliderInt4("Slider int 4", slider_int4_value)) {
std::cout << "Slider int 4 value changed to:\n" << slider_int4_value << '\n';
}

if (Toucan::ShowColorPicker("Color picker", color_value)) {
std::cout << "Color picker value changed to:\n (" <<
color_value.r << ", " << color_value.g << ", " << color_value.b << ")\n";
}
}
Toucan::EndInputWindow();

using namespace std::chrono_literals;
std::this_thread::sleep_for(250ms);
}

Toucan::Destroy();

return 0;
}
12 changes: 10 additions & 2 deletions examples/Primitives3D-Example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(primitives3d-example)

add_executable(
primitives3d-example
main.cpp
Expand All @@ -6,10 +9,15 @@ add_executable(
set_target_properties(
primitives3d-example PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS ON
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
)

# This if check is used to work better with a local copy of Toucan.
# In a regular project the 'if' can be omitted, as the 'find_package' command should always be called.
if (NOT Toucan_FOUND)
find_package(Toucan REQUIRED)
endif (NOT Toucan_FOUND)

target_link_libraries(
primitives3d-example
PRIVATE Toucan::Toucan
Expand Down
22 changes: 11 additions & 11 deletions examples/RGBD-Example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
cmake_minimum_required(VERSION 3.10)
project(rgbd-example)

add_executable(
rgbd-example
main.cpp
DataLoader.cpp
DataLoader.cpp DataLoader.h
stb_image.h
)

set_target_properties(
rgbd-example PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS ON
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
)

add_library(stb STATIC stb/stb_image.c)
target_include_directories(rgbd-example PRIVATE stb)

find_package(Eigen3 REQUIRED NO_MODULE)

find_package(Sophus REQUIRED)
target_include_directories(rgbd-example PRIVATE ${Sophus_INCLUDE_DIRS})
# This if check is used to work better with a local copy of Toucan.
# In a regular project the 'if' can be omitted, as the 'find_package' command should always be called.
if (NOT Toucan_FOUND)
find_package(Toucan REQUIRED)
endif (NOT Toucan_FOUND)

target_link_libraries(
rgbd-example
PRIVATE Toucan::Toucan stb stdc++fs Eigen3::Eigen
PRIVATE Toucan::Toucan stdc++fs
)

file(COPY dataset DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
36 changes: 19 additions & 17 deletions examples/RGBD-Example/DataLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
#include <cstdint>
#include <fstream>

#include <stb_image.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

#include <unistd.h>

DataLoader::DataLoader(const std::experimental::filesystem::path& dataset_path, const Sophus::SE3f& transformation) :
m_dataset_path{dataset_path}, m_transformation{transformation}, m_rgb_index{0}, m_depth_index{0}, m_groundtruth_index{0} {
DataLoader::DataLoader(const std::filesystem::path& dataset_path) :
m_dataset_path{dataset_path}, m_rgb_index{0}, m_depth_index{0}, m_groundtruth_index{0} {

const std::experimental::filesystem::path rgb_file_path = dataset_path / "rgb.txt";
const std::filesystem::path rgb_file_path = dataset_path / "rgb.txt";

std::ifstream rgb_file(rgb_file_path.string());
if (!rgb_file.is_open()) { throw std::invalid_argument("Unable to open rgb.txt file"); }
if (!rgb_file.is_open()) { throw std::invalid_argument("Unable to open rgb.txt file. Did you run download-dataset.sh?"); }

std::string line;
const std::string decimal = ".";
Expand All @@ -32,10 +33,10 @@ m_dataset_path{dataset_path}, m_transformation{transformation}, m_rgb_index{0},
m_rgb_files.emplace_back(timestamp, file_name);
}

const std::experimental::filesystem::path depth_file_path = dataset_path / "depth.txt";
const std::filesystem::path depth_file_path = dataset_path / "depth.txt";

std::ifstream depth_file(depth_file_path.string());
if (!depth_file.is_open()) { throw std::invalid_argument("Unable to open depth.txt file"); }
if (!depth_file.is_open()) { throw std::invalid_argument("Unable to open depth.txt file. Did you run download-dataset.sh?"); }

while (getline(depth_file, line))
{
Expand All @@ -50,10 +51,10 @@ m_dataset_path{dataset_path}, m_transformation{transformation}, m_rgb_index{0},
m_depth_files.emplace_back(timestamp, file_name);
}

const std::experimental::filesystem::path groundtruth_file_path = dataset_path / "groundtruth.txt";
const std::filesystem::path groundtruth_file_path = dataset_path / "groundtruth.txt";

std::ifstream groudtruth_file(groundtruth_file_path.string());
if (!groudtruth_file.is_open()) { throw std::invalid_argument("Unable to open groundtruth.txt file"); }
if (!groudtruth_file.is_open()) { throw std::invalid_argument("Unable to open groundtruth.txt file. Did you run download-dataset.sh?"); }

while (getline(groudtruth_file, line))
{
Expand Down Expand Up @@ -89,11 +90,12 @@ m_dataset_path{dataset_path}, m_transformation{transformation}, m_rgb_index{0},
std::getline(ss, item, ' ');
float qw = std::stof(item);

const Eigen::Quaternionf orientation(qw, qx, qy, qz);
const Eigen::Vector3f position(tx, ty, tz);
const Sophus::SE3f transform(orientation, position);
const Toucan::RigidTransform3Df pose(
Toucan::Quaternionf(qw, qx, qy, qz),
Toucan::Vector3f(tx, ty, tz)
);

m_ground_truths.emplace_back(timestamp, transform);
m_ground_truths.emplace_back(timestamp, pose);
}

this->next();
Expand Down Expand Up @@ -127,7 +129,7 @@ int DataLoader::get_current_index() const {
}

Image DataLoader::get_depth() const {
const std::experimental::filesystem::path& depth_image_path = m_dataset_path / m_depth_files[m_depth_index].second;
const std::filesystem::path& depth_image_path = m_dataset_path / m_depth_files[m_depth_index].second;

Image image;

Expand All @@ -141,7 +143,7 @@ Image DataLoader::get_depth() const {
}

Image DataLoader::get_rgb() const {
const std::experimental::filesystem::path& rgb_image_path = m_dataset_path / m_rgb_files[m_rgb_index].second;
const std::filesystem::path& rgb_image_path = m_dataset_path / m_rgb_files[m_rgb_index].second;

Image image;

Expand All @@ -154,8 +156,8 @@ Image DataLoader::get_rgb() const {
return image;
}

Sophus::SE3f DataLoader::get_groundtruth() const {
return m_transformation * m_ground_truths[m_groundtruth_index].second;
Toucan::RigidTransform3Df DataLoader::get_groundtruth() const {
return m_ground_truths[m_groundtruth_index].second;
}

uint64_t DataLoader::get_timestamp() const
Expand Down
13 changes: 6 additions & 7 deletions examples/RGBD-Example/DataLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <utility>
#include <string>
#include <cstdlib>
#include <experimental/filesystem>
#include <filesystem>

#include <sophus/se3.hpp>
#include <Toucan/DataTypes.h>

struct Image {
~Image() {
Expand All @@ -23,27 +23,26 @@ struct Image {

class DataLoader {
public:
explicit DataLoader(const std::experimental::filesystem::path& dataset_path, const Sophus::SE3f& transformation = Sophus::SE3f());
explicit DataLoader(const std::filesystem::path& dataset_path);

void next();
[[nodiscard]] bool has_next() const;
[[nodiscard]] Image get_rgb() const;
[[nodiscard]] Image get_depth() const;
[[nodiscard]] Sophus::SE3f get_groundtruth() const;
[[nodiscard]] Toucan::RigidTransform3Df get_groundtruth() const;
[[nodiscard]] uint64_t get_timestamp() const;

[[nodiscard]] int get_size() const;
[[nodiscard]] int get_current_index() const;

private:
const std::experimental::filesystem::path m_dataset_path;
const Sophus::SE3f m_transformation;
const std::filesystem::path m_dataset_path;

int m_rgb_index;
int m_depth_index;
int m_groundtruth_index;

std::vector<std::pair<uint64_t, const std::string>> m_rgb_files;
std::vector<std::pair<uint64_t, const std::string>> m_depth_files;
std::vector<std::pair<uint64_t, const Sophus::SE3f>> m_ground_truths;
std::vector<std::pair<uint64_t, const Toucan::RigidTransform3Df>> m_ground_truths;
};
2 changes: 2 additions & 0 deletions examples/RGBD-Example/dataset/download-dataset.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

cd "$( dirname "${BASH_SOURCE[0]}" )" || exit

wget https://vision.in.tum.de/rgbd/dataset/freiburg3/rgbd_dataset_freiburg3_long_office_household.tgz -O - | tar xvzf -
26 changes: 10 additions & 16 deletions examples/RGBD-Example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,32 +95,26 @@ int main() {
project_image(depth_points, image, image_depth);

auto gt_pose = data_loader.get_groundtruth();
auto gt_t = gt_pose.translation();
auto gt_q = gt_pose.unit_quaternion();

pose_path.emplace_back(Toucan::LineVertex3D{Toucan::Vector3f(gt_t.x(), gt_t.y(), gt_t.z()), Toucan::Color::Magenta()});
pose_path.emplace_back(Toucan::LineVertex3D{gt_pose.translation, Toucan::Color::Magenta()});
Toucan::BeginFigure3D("Point Projection");
{
Toucan::PushPose3D(Toucan::RigidTransform3Df(Toucan::Quaternionf(Toucan::Vector3f::UnitX(), M_PI_2), Toucan::Vector3f::Zero()));
{ // Static transform to align with our coordinate system
Toucan::ShowLines3D("Pose path", pose_path);

Toucan::PushPose3D(Toucan::RigidTransform3Df(Toucan::Quaternionf(gt_q.w(), gt_q.x(), gt_q.y(), gt_q.z()), Toucan::Vector3f(gt_t.x(), gt_t.y(), gt_t.z())));
{ // The coordinate system of the camera
Toucan::ShowAxis3D("Axis");
Toucan::ShowPoints3D("Depth points", depth_points);
}
Toucan::PopPose3D();
Toucan::ShowLines3D("Pose path", pose_path);

Toucan::PushPose3D(gt_pose);
{ // The coordinate system of the camera
Toucan::ShowAxis3D("Axis");
Toucan::ShowPoints3D("Depth points", depth_points);
}
Toucan::PopPose3D();
}
Toucan::EndFigure3D();

depth_points.clear();

pos_x_plot.emplace_back(gt_t.x());
pos_y_plot.emplace_back(gt_t.y());
pos_z_plot.emplace_back(gt_t.z());
pos_x_plot.emplace_back(gt_pose.translation.x());
pos_y_plot.emplace_back(gt_pose.translation.y());
pos_z_plot.emplace_back(gt_pose.translation.z());

Toucan::BeginFigure2D("Position");
{
Expand Down
3 changes: 0 additions & 3 deletions examples/RGBD-Example/stb/stb_image.c

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 3ca3cd9

Please sign in to comment.