Skip to content

Commit

Permalink
add command line arguments using CLI11 module
Browse files Browse the repository at this point in the history
  • Loading branch information
henrykrumb committed Jul 6, 2023
1 parent 6e9aa45 commit a297c02
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cmake_minimum_required(VERSION 3.26)
project(spacenavigt)
include(FetchContent)

Expand All @@ -8,6 +9,13 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(OpenIGTLink)

FetchContent_Declare(
cli11
GIT_REPOSITORY https://github.com/CLIUtils/CLI11
GIT_TAG 985a19f3860be0cba87354336f6588494b20111c
)
FetchContent_MakeAvailable(cli11)

ExternalProject_Add(
spnav
GIT_REPOSITORY https://github.com/FreeSpacenav/libspnav
Expand All @@ -23,13 +31,12 @@ ExternalProject_Get_Property(spnav install_dir)
add_library(lspnav STATIC IMPORTED)
set_property(TARGET lspnav PROPERTY IMPORTED_LOCATION ${install_dir}/lib/libspnav.so)
add_dependencies(lspnav spnav)
include_directories(${install_dir}/include)

find_package(OpenIGTLink REQUIRED)
include(${OpenIGTLink_USE_FILE})

find_package(X11 REQUIRED)
include_directories(${X11_INCLUDE_DIR})
include_directories(${install_dir}/include ${X11_INCLUDE_DIR} ${cli11_SOURCE_DIR}/include)
link_directories(${X11_LIBRARIES})

add_executable(spnavigt src/spnavigt.cpp)
Expand Down
13 changes: 0 additions & 13 deletions Makefile

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ transform called "SpaceMouse".

## TODOs ##

* [ ] CMake build with FetchContent (auto-install OpenIGTLink)
* [x] CMake build with FetchContent (auto-install OpenIGTLink)
* [x] Rotations (so far, only translations are supported)
* [ ] Flexible configuration via JSON
* [ ] System-wide installation
* [x] System-wide installation
* [ ] Use button events somehow
* [ ] Command line arguments
* [x] Command line arguments
29 changes: 20 additions & 9 deletions src/spnavigt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include <csignal>
#include <cmath>


#include <CLI/App.hpp>
#include <CLI/Formatter.hpp>
#include <CLI/Config.hpp>

#include <spnav.h>

#include <igtlServerSocket.h>
Expand All @@ -23,19 +28,19 @@ QuadMatrix<4> rotmatX(float angle)
double a = M_PI * angle / 180.0;
float arr[4][4] = {
{1.0f, 0.0f, 0.0f, 0.0f},
{0.0f, cos(a), -sin(a), 0.0f},
{0.0f, sin(a), cos(a), 0.0f},
{0.0f, (float)cos(a), (float)-sin(a), 0.0f},
{0.0f, (float)sin(a), (float)cos(a), 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}};
return QuadMatrix<4>(arr);
}

QuadMatrix<4> rotmatY(float angle)
{
double a = M_PI * angle / 180.0;
float arr[4][4] = {
{cos(a), 0.0f, sin(a), 0.0f},
float arr[4][4] = {
{(float)cos(a), 0.0f, (float)sin(a), 0.0f},
{0.0f, 1.0f, 0.0f, 0.0f},
{-sin(a), 0.0f, cos(a), 0.0f},
{(float)-sin(a), 0.0f, (float)cos(a), 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}};
return QuadMatrix<4>(arr);
}
Expand All @@ -44,14 +49,14 @@ QuadMatrix<4> rotmatZ(float angle)
{
double a = M_PI * angle / 180.0;
float arr[4][4] = {
{cos(a), -sin(a), 0.0f, 0.0f},
{sin(a), cos(a), 0.0f, 0.0f},
{(float)cos(a), (float)-sin(a), 0.0f, 0.0f},
{(float)sin(a), (float)cos(a), 0.0f, 0.0f},
{0.0f, 0.0f, 1.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}};
return QuadMatrix<4>(arr);
}

int main(void)
int main(int argc, char* argv[])
{
spnav_event sev;

Expand All @@ -63,12 +68,18 @@ int main(void)
return 1;
}

int port = 18945;
int port = 18944;
int timeout = 1000;
running = true;
auto server_socket = igtl::ServerSocket::New();
int status = server_socket->CreateServer(port);

// parse command line args
CLI::App app{"3DConnexion IGTLink Server"};
app.add_option("-p,--port", port, "IGTLink server port");
app.add_option("-t,--timeout", timeout, "Connection timeout");
CLI11_PARSE(app, argc, argv);

QuadMatrix<4> T, Rx, Ry, Rz;

if (status < 0)
Expand Down

0 comments on commit a297c02

Please sign in to comment.