Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and add CI #14

Merged
merged 13 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI

on:
pull_request:
push:
branches:
- main

jobs:
build_lib:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Eigen
run: sudo apt-get install libeigen3-dev
- name: Build library
run: make libcevicp.a OPT=RELEASE
- name: Upload library
uses: actions/upload-artifact@v4
with:
name: libcevicp.a
path: libcevicp.a
retention-days: 1
test:
runs-on: ubuntu-22.04
needs: build_lib
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download library
uses: actions/download-artifact@v4
with:
name: libcevicp.a
- name: Install Eigen
run: sudo apt-get install libeigen3-dev
- name: Install simple-test
run: |
git clone https://github.com/cornellev/simple-test
cd simple-test
sudo make install
- name: Run tests
run: make test OPT=RELEASE
bench:
runs-on: ubuntu-22.04
needs: build_lib
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download library
uses: actions/download-artifact@v4
with:
name: libcevicp.a
- name: Install Eigen
run: sudo apt-get install libeigen3-dev
- name: Install SDL2
run: sudo apt-get install libsdl2-dev
- name: Install sdl-wrapper
run: |
git clone https://github.com/cornellev/sdl-wrapper.git
cd sdl-wrapper
sudo make install
- name: Install libcmdapp2
run: |
git clone https://github.com/cornellev/libcmdapp2.git
cd libcmdapp2
sudo make install
- name: Install libconfig
run: |
git clone https://github.com/cornellev/config
cd config
sudo make install
- name: Run benchmarks
run: make bench OPT=RELEASE
6 changes: 3 additions & 3 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"includePath": [
"${default}",
"/usr/local/include/sdlwrapper",
"/usr/local/include/eigen3",
"/usr/include/eigen3",
"/usr/local/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/"
],
Expand All @@ -17,9 +17,9 @@
"name": "Linux",
"includePath": [
"${default}",
"${workspaceFolder}/**",
"${workspaceFolder}/include",
"/usr/include/SDL2",
"/usr/local/include/eigen3",
"/usr/include/eigen3",
"/usr/local/include/sdlwrapper",
"/usr/local/include/cmdapp",
"/usr/local/include/config",
Expand Down
34 changes: 34 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug with gdb on linux",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main",
"args": [
"-S",
"ex_data/scan1/first.conf",
"-D",
"ex_data/scan1/second.conf",
"--method",
"vanilla",
"--gui"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build main with make"
}
]
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
"stop_token": "cpp",
"svd": "cpp",
"core": "cpp",
"text_encoding": "cpp"
"text_encoding": "cpp",
"strstream": "cpp",
"source_location": "cpp",
"stdfloat": "cpp"
}
}
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build main with make",
"type": "shell",
"command": "make main",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}
116 changes: 64 additions & 52 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,72 +1,95 @@
# Copyright (C) 2023 Ethan Uppal. All rights reserved.

INCLUDEDIR := include
LIBDIR := lib
SRCDIR := src
INCLUDEDIR := src
TESTDIR := tests

CC := $(shell which g++ || which clang++)
PY := $(shell which python3 || which python)
CFLAGS := -std=c++17 -pedantic -Wall -Wextra -I $(INCLUDEDIR)
CDEBUG := -g
CRELEASE := -O3 -DRELEASE_BUILD
TARGET := main
LIBNAME := libcevicp.a
MAINNAME := main
TESTNAME := test

# follow instructions in README to install in /usr/local
LDFLAGS := $(shell sdl2-config --libs) \
/usr/local/lib/libcmdapp.a \
/usr/local/lib/libsdlwrapper.a \
/usr/local/lib/libconfig.a
CFLAGS += $(shell sdl2-config --cflags) \
-I/usr/local/include/cmdapp \
-I/usr/local/include/config \
-I/usr/local/include/sdlwrapper \
-I/usr/local/include/simple_test \
-I/usr/local/include/eigen3

# CFLAGS += $(CRELEASE)
ifeq ($(OPT), RELEASE)
CFLAGS += $(CRELEASE)
else
CFLAGS += $(CDEBUG)
endif

SRC := $(shell find $(SRCDIR) -name "*.cpp")
OBJ := $(SRC:.cpp=.o)
DEPS := $(OBJS:.o=.d)


LIBSRC := $(shell find $(SRCDIR)/icp -name "*.cpp" -type f) \
$(shell find $(SRCDIR)/algo -name "*.cpp" -type f)
LIBSRC := $(shell find $(LIBDIR) -name "*.cpp" -type f)
LIBINCLUDE := -I/usr/include/eigen3
LIBOBJ := $(LIBSRC:.cpp=.o)
LIBDEPS := $(LIBOBJ:.o=.d)
$(LIBNAME): CFLAGS += $(LIBINCLUDE)

MAINSRC := $(shell find $(SRCDIR) -name "*.cpp" -type f)
MAININCLUDE := $(shell sdl2-config --cflags) \
-I/usr/include/eigen3 \
-I/usr/local/include/cmdapp \
-I/usr/local/include/config \
-I/usr/local/include/sdlwrapper
MAINLD := $(shell sdl2-config --libs) \
/usr/local/lib/libcmdapp.a \
/usr/local/lib/libsdlwrapper.a \
/usr/local/lib/libconfig.a
MAINOBJ := $(MAINSRC:.cpp=.o)
MAINDEPS := $(MAINOBJ:.o=.d)
$(MAINNAME): CFLAGS += $(MAININCLUDE)
$(MAINNAME): LDFLAGS += $(MAINLD)

TESTSRC := $(shell find $(TESTDIR) -name "*.cpp" -type f)
TESTINCLUDE := -I/usr/include/eigen3 \
-I/usr/local/include/simple_test
TESTOBJ := $(TESTSRC:.cpp=.o)
TESTDEPS := $(TESTOBJ:.o=.d)
$(TESTNAME): CFLAGS += $(TESTINCLUDE)
$(TESTNAME): CFLAGS += -DTEST

-include $(LIBDEPS)
-include $(MAINDEPS)
-include $(TESTDEPS)

-include $(DEPS)

# Config parameters
N := 1
METHOD := trimmed

$(TARGET): main.cpp $(OBJ)
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
@make readme
ifeq ($(shell uname), Darwin)
AR := /usr/bin/libtool
AR_OPT := -static
else
AR := ar
AR_OPT := rcs $@ $^
endif

.PHONY: test
test: test.cpp $(OBJ)
@$(CC) $(CFLAGS) -DTEST -o _temp $^ $(LDFLAGS)
@echo 'Running tests...'
@./_temp
@rm -f ./_temp
$(LIBNAME): $(LIBOBJ)
$(AR) $(AR_OPT) -o $@ $^

.PHONY: view
view: $(TARGET)
./$(TARGET) -S ex_data/scan$(N)/first.conf -D ex_data/scan$(N)/second.conf --method $(METHOD) --gui
$(MAINNAME): $(MAINOBJ) $(LIBNAME)
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@

.PHONY: bench
bench: $(TARGET)
./$(TARGET) -S ex_data/scan$(N)/first.conf -D ex_data/scan$(N)/second.conf --method $(METHOD) --bench
$(TESTNAME): $(TESTOBJ) $(LIBNAME)
@$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
@./$(TESTNAME)
@rm $(TESTNAME)

%.o: %.cpp
@echo 'Compiling $@'
$(CC) $(CFLAGS) -MMD -MP $< -c -o $@

.PHONY: clean
clean:
rm -rf $(OBJ) $(TARGET) $(TARGET) $(DEPS) $(shell find . -name "*.dSYM") $(shell find . -name "*.d") docs
@rm -f $(LIBOBJ) $(LIBDEPS) $(LIBNAME) $(MAINOBJ) $(MAINDEPS) $(MAINNAME)

.PHONY: view
view: $(MAINNAME)
./$(MAINNAME) -S ex_data/scan$(N)/first.conf -D ex_data/scan$(N)/second.conf --method $(METHOD) --gui

.PHONY: bench
bench: $(MAINNAME)
./$(MAINNAME) -S ex_data/scan$(N)/first.conf -D ex_data/scan$(N)/second.conf --method $(METHOD) --bench

# Not building book rn, add these commands to build
# cd book; \
Expand All @@ -91,14 +114,3 @@ readme:
.PHONY: math
math:
@cd math; $(PY) ./icp_math.py

ifeq ($(shell uname), Darwin)
AR := /usr/bin/libtool
AR_OPT := -static
else
AR := ar
AR_OPT := rcs $@ $^
endif

$(LIBNAME): $(LIBOBJ)
$(AR) $(AR_OPT) $^ -o $@
14 changes: 7 additions & 7 deletions book/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ Please read [this document](icp.pdf) to learn more about the math.
First, download and install the dependencies.
**Only eigen3 is necessary for the library. If you only wish to build the library, install eigen3 only. The remaining dependencies are only for the visualization tool.**

| Dependency | Library Location (at which) | Header Location (under which) |
| --- | --- | --- |
| [eigen3](http://eigen.tuxfamily.org/index.php?title=Main_Page) | N/A | `/usr/local/include/eigen3/` |
| [SDL2](https://www.libsdl.org) | `$(sdl2-config --cflags)` | `$(sdl2-config --libs)` |
| My [SDL2 wrapper](https://github.com/cornellev/sdl-wrapper) | `/usr/local/lib/libsdlwrapper.a` | `/usr/local/include/sdlwrapper/` |
| [libcmdapp2](https://ethanuppal.com/libcmdapp2/) | `/usr/local/lib/libcmdapp.a` | `/usr/local/include/` |
| [libconfig](https://github.com/ethanuppal/config) | `/usr/local/lib/libconfig.a` | `/usr/local/include/` |
| Dependency | Library Location (at which) | Header Location (under which) |
| -------------------------------------------------------------- | -------------------------------- | -------------------------------- |
| [eigen3](http://eigen.tuxfamily.org/index.php?title=Main_Page) | N/A | `/usr/include/eigen3/` |
| [SDL2](https://www.libsdl.org) | `$(sdl2-config --cflags)` | `$(sdl2-config --libs)` |
| My [SDL2 wrapper](https://github.com/cornellev/sdl-wrapper) | `/usr/local/lib/libsdlwrapper.a` | `/usr/local/include/sdlwrapper/` |
| [libcmdapp2](https://ethanuppal.com/libcmdapp2/) | `/usr/local/lib/libcmdapp.a` | `/usr/local/include/cmdapp` |
| [libconfig](https://github.com/ethanuppal/config) | `/usr/local/lib/libconfig.a` | `/usr/local/include/config` |

There is also a dependency on [simple-test](https://github.com/ethanuppal/simple-test) if you want to run the tests (`make test`).
Please follow the installation instructions there.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 11 additions & 13 deletions src/icp/icp.h → include/icp/icp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <functional>
#include <unordered_map>
#include <variant>
#include <optional>

#include "geo.h"

namespace icp {
Expand Down Expand Up @@ -57,10 +59,10 @@ namespace icp {
*/
RBTransform transform;

/** The source point cloud relative to its centroid. */
/** The source point cloud. */
std::vector<Vector> a;

/** The destination point cloud relative to its centroid. */
/** The destination point cloud. */
std::vector<Vector> b;

/** Keeps track of the previous cost to ensure that progress is being
Expand Down Expand Up @@ -150,6 +152,10 @@ namespace icp {
/** The current transform. */
const RBTransform& current_transform() const;

/** Registers methods built into libcevicp. Must be called before constructing ICP instances
* for built-in methods. */
static void register_builtin_methods();

/** Registers a new ICP method that can be created with `constructor`,
* returning `false` if `name` has already been registered. */
static bool register_method(std::string name,
Expand All @@ -166,15 +172,7 @@ namespace icp {
* @pre `name` is a valid registered method. See
* ICP::is_registered_method.
*/
static std::unique_ptr<ICP> from_method(std::string name, const Config& params = Config());

/** Whether `name` is a registered ICP method. */
static bool is_registered_method(std::string name);
};

struct Methods {
std::vector<std::string> registered_method_names;
std::vector<std::function<std::unique_ptr<ICP>(const ICP::Config&)>>
registered_method_constructors;
static std::optional<std::unique_ptr<ICP>> from_method(std::string name,
const Config& params = Config());
};
}
}
Loading