Skip to content

Commit 1bb6936

Browse files
authored
Merge pull request #27 from JMUWRobotics/icpFixpoint_dev
Merge ICP fixpoint after resolving any merge conflicts (there was just one conflict with a single space in code)
2 parents 799a4e4 + a5066c1 commit 1bb6936

16 files changed

Lines changed: 1113 additions & 1 deletion
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# FindSystemC.cmake
2+
3+
find_path(SYSTEMC_INCLUDE_DIR
4+
NAMES systemc.h
5+
PATHS /usr/include
6+
)
7+
8+
find_library(SYSTEMC_LIBRARY
9+
NAMES systemc
10+
PATHS /usr/lib /usr/lib/x86_64-linux-gnu
11+
12+
)
13+
14+
include(FindPackageHandleStandardArgs)
15+
find_package_handle_standard_args(SystemC DEFAULT_MSG
16+
SYSTEMC_LIBRARY SYSTEMC_INCLUDE_DIR
17+
)
18+
19+
mark_as_advanced(SYSTEMC_INCLUDE_DIR SYSTEMC_LIBRARY)
20+
21+
if(SystemC_FOUND)
22+
set(SystemC_INCLUDE_DIRS ${SYSTEMC_INCLUDE_DIR})
23+
set(SystemC_LIBRARIES ${SYSTEMC_LIBRARY})
24+
25+
if(NOT TARGET SystemC::systemc)
26+
add_library(SystemC::systemc UNKNOWN IMPORTED)
27+
set_target_properties(SystemC::systemc PROPERTIES
28+
IMPORTED_LOCATION "${SYSTEMC_LIBRARY}"
29+
INTERFACE_INCLUDE_DIRECTORIES "${SYSTEMC_INCLUDE_DIR}"
30+
)
31+
endif()
32+
endif()

CMakeLists.txt

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ option(WITH_3DMOUSE "Support for 3DConnexion Space Mouse" OFF)
147147
option(WITH_TSDF "Complie with TSDF (openVDB)" OFF)
148148
option(WITH_CALIB "Complie with calibration" OFF)
149149
option(WITH_SYSTEM_APRILTAG "Link against system-wide apriltag library" OFF)
150+
option(WITH_SYSTEMC "Compile with SystemC library for fixedPoint arithmetic" ON)
150151

151152
# Adds imgui to show using opengl2 and glut
152153
if(WITH_IMGUI)
@@ -455,6 +456,7 @@ add_subdirectory(src/gps)
455456
add_subdirectory(src/curvefusion)
456457
add_subdirectory(src/mesh)
457458
add_subdirectory(src/detectCylinder)
459+
add_subdirectory(src/sc_fixed)
458460
# 3rdparty must come before src/calibration because it sets
459461
# APRILTAG_INCLUDE_DIRS
460462
add_subdirectory(3rdparty)
@@ -474,9 +476,42 @@ find_package(Boost COMPONENTS system filesystem unit_test_framework REQUIRED)
474476
enable_testing()
475477
add_subdirectory(testing)
476478

479+
480+
# SystemC integration
481+
482+
# Configurable constants for SystemC fixed-point value
483+
set(FIXED_WORD_LENGTH 48 CACHE STRING "Word length for fixed-point type")
484+
set(FIXED_INT_WORD_LENGTH 36 CACHE STRING "Integer word length for fixed-point type")
485+
set(FIXED_HERON_ITERATIONS 3 CACHE STRING "Iterations ins heron algorithm for square root calculations for fixed point numbers")
486+
487+
if(WITH_SYSTEMC)
488+
message(STATUS "SystemC support enabled")
489+
find_package(SystemC REQUIRED)
490+
491+
if(SystemC_FOUND)
492+
message(STATUS "SystemC installation found")
493+
include_directories(${SYSTEMC_INCLUDE_DIR})
494+
add_definitions(-DWITH_SYSTEMC)
495+
# Set configurable constants for SystemC fixed-point value as compiler definition
496+
target_compile_definitions(icpFixpoint PRIVATE
497+
FIXED_WORD_LENGTH=${FIXED_WORD_LENGTH}
498+
FIXED_INT_WORD_LENGTH=${FIXED_INT_WORD_LENGTH}
499+
FIXED_HERON_ITERATIONS=${FIXED_HERON_ITERATIONS}
500+
)
501+
set(SYSTEMC_LINK_LIBS ${SYSTEMC_LIBRARY})
502+
503+
else()
504+
message(FATAL_ERROR "SystemC was enabled, but could not be found")
505+
endif()
506+
507+
set(SYSTEMC_INCLUDE_DIR)
508+
509+
else()
510+
message(STATUS "SystemC support disabled")
511+
endif()
477512
# Dummy target with all header files
478513
# This is a hint for some IDEs, such as Qt Creator, to show all headers in the project tree
479514
file(GLOB_RECURSE 3DTK_HEADER_FILES "include/*.h")
480515
add_custom_target(headers SOURCES ${3DTK_HEADER_FILES})
481516

482-
message (STATUS "Build environment is set up!")
517+
message(STATUS "Build environment is set up!")
199 KB
Binary file not shown.

doc/icpFixpoint_Pflichtenheft.pdf

190 KB
Binary file not shown.

include/sc_fixed/sc_ICP.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/** @file
2+
* @brief Representation of 3D scan matching with ICP
3+
* @author Tom Fleischmann, Jonas Wiesner, Yannik Winzer - University of Wuerzburg, Germany
4+
*/
5+
6+
#ifndef __SC_ICP_H__
7+
#define __SC_ICP_H__
8+
9+
#include <vector>
10+
#include <array>
11+
12+
#include "sc_fixed/sc_fixed_math.h"
13+
#include "sc_fixed/sc_ICPminimizer.h"
14+
15+
/**
16+
* Manages the matching of 3D scans.
17+
* Important values, such as maximal matching distance,
18+
* maximal number of iterations, etc.
19+
* are specified in the constructor.
20+
*/
21+
class sc_ICP {
22+
23+
public:
24+
/**
25+
* Constructor
26+
*/
27+
sc_ICP(sc_ICPminimizer *my_sc_ICPminimizer,
28+
f_float max_dist_match = 25.0,
29+
int max_num_iterations = 50,
30+
bool quiet = false,
31+
int epsilonICPexp = 3);
32+
33+
/**
34+
* Destructor (empty, but needed, because virtual)
35+
*/
36+
virtual ~sc_ICP() {};
37+
38+
virtual int match(std::vector<std::array<f_float, 3>>& source, std::vector<std::array<f_float, 3>>& target, std::array<f_float, 16>& transMat, std::array<f_float, 16>& dalignxf, std::ofstream& frame);
39+
40+
inline f_float get_max_dist_match2();
41+
inline void set_max_dist_match2(f_float max_dist_match2);
42+
inline void set_max_num_iterations(int max_num_iterations);
43+
inline int get_nr_pointPair();
44+
45+
protected:
46+
47+
/**
48+
* suppress output to cout
49+
*/
50+
bool quiet;
51+
52+
/**
53+
* the maximal distance (^2 !!!) for matching
54+
*/
55+
f_float max_dist_match2;
56+
57+
/**
58+
* the maximal number of iterations
59+
*/
60+
int max_num_iterations;
61+
62+
/**
63+
* epsilon for stopping ICP algorithm ( convergence criterium )
64+
*/
65+
int epsilonICPexp;
66+
f_float epsilonICP;
67+
68+
/**
69+
* ptr to ICP error function minimizer functor
70+
*/
71+
sc_ICPminimizer *my_sc_ICPminimizer;
72+
73+
/**
74+
* Maximum number of points in all scans
75+
*/
76+
unsigned int max_scn_size; //FIXME -> update with metascan
77+
78+
/**
79+
* number of matched points in ICP
80+
*/
81+
int nr_pointPair;
82+
};
83+
84+
#include "sc_fixed/sc_ICP.icc"
85+
86+
#endif //__SC_ICP_H__

include/sc_fixed/sc_ICP.icc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* ICP-fixpoint implementation
3+
*
4+
* Copyright (C) Tom Fleischmann, Jonas Wiesner, Yannik Winzer
5+
*
6+
* Released under the GPL version 3.
7+
*
8+
*/
9+
10+
/**
11+
* @file
12+
* @brief Implementation of 3D scan matching with ICP
13+
* @author Tom Fleischmann, Jonas Wiesner, Yannik Winzer. Institute of Computer Science, University of Wuerzburg, Germany.
14+
*/
15+
16+
/**
17+
* Get the maximal distance for matching
18+
*
19+
* @return the maximal distance for matching
20+
*/
21+
inline f_float sc_ICP::get_max_dist_match2() {
22+
return max_dist_match2;
23+
}
24+
25+
/**
26+
* Set the maximal distance for matching
27+
*
28+
* @param max_dist_match2 the maximal distance (^2 !!!) for matching
29+
*/
30+
inline void sc_ICP::set_max_dist_match2(f_float max_dist_match2) {
31+
this->max_dist_match2 = max_dist_match2;
32+
}
33+
34+
/**
35+
* Set the Maximum number of iterations
36+
*
37+
* @param max_num_iterations Maximum number of iterations
38+
*/
39+
inline void sc_ICP::set_max_num_iterations(int max_num_iterations) {
40+
this->max_num_iterations = max_num_iterations;
41+
}
42+
43+
/**
44+
* Get the nr of point pairs
45+
*
46+
* @return the nr of point pairs
47+
*/
48+
inline int sc_ICP::get_nr_pointPair() {
49+
return nr_pointPair;
50+
}

include/sc_fixed/sc_ICPapx.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/** @file
2+
* @brief Definition of the ICP error function minimization
3+
* @author Tom Fleischmann, Jonas Wiesner, Yannik Winzer - University of Wuerzburg, Germany
4+
*/
5+
6+
#ifndef __SC_ICPAPX_H__
7+
#define __SC_ICPAPX_H__
8+
9+
#include "sc_fixed/sc_fixed_math.h"
10+
#include "sc_fixed/sc_ICPminimizer.h"
11+
12+
/**
13+
* @brief Implementation of the ICP error function minimization via
14+
* approximation using the small angle approximation
15+
*/
16+
class sc_ICPapx : public sc_ICPminimizer
17+
{
18+
public:
19+
/**
20+
* Constructor
21+
*/
22+
sc_ICPapx(bool quiet = false) : sc_ICPminimizer(quiet) {};
23+
/**
24+
* Destructor
25+
*/
26+
virtual ~sc_ICPapx() {};
27+
28+
f_float Align(const std::vector<std::array<f_float, 3>>& matchedSource,
29+
const std::vector<std::array<f_float, 3>>& matchedTarget,
30+
f_float *alignxf,
31+
const std::array<f_float, 3> centerSource,
32+
const std::array<f_float, 3> centerTarget) override;
33+
34+
inline int getAlgorithmID() { return 6; };
35+
};
36+
37+
#endif

include/sc_fixed/sc_ICPminimizer.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* sc_ICPminimizer implementation
3+
*
4+
* Copyright (C) Tom Fleischmann, Jonas Wiesner, Yannik Winzer
5+
*
6+
* Released under the GPL version 3.
7+
*
8+
*/
9+
10+
/**
11+
* @file
12+
* @brief Implementation of the virtual functor for ICP error function minimization
13+
* @author Tom Fleischmann, Jonas Wiesner, Yannik Winzer. Institute of Computer Science, University of Wuerzburg, Germany.
14+
*/
15+
16+
#ifndef __SC_ICPMINIMIZER__
17+
#define __SC_ICPMINIMIZER__
18+
19+
#include <vector>
20+
#include "sc_fixed/sc_fixed_math.h"
21+
22+
#include <iostream>
23+
#include <stdlib.h>
24+
#include <array>
25+
26+
class sc_ICPminimizer {
27+
28+
public:
29+
/**
30+
* Constructor
31+
*/
32+
sc_ICPminimizer(bool quiet = false) { this->quiet = quiet; };
33+
/**
34+
* Destructor
35+
*/
36+
virtual ~sc_ICPminimizer() {};
37+
38+
/**
39+
* aligning the point pairs
40+
*/
41+
// a detailed discussion of the minimization techniques used for this
42+
// function is given in:
43+
// Andreas Nuechter, Jan Elseberg, Peter Schneider, and Dietrich Paulus.
44+
// Study of Parameterizations for the Rigid Body Transformations of The
45+
// Scan Registration Problem, Journal Computer Vision and Image
46+
// Understanding (CVIU), Elsevier Science, Volume 114, Issue 8,
47+
// pp. 963-980, August 2010.
48+
49+
virtual f_float Align(const std::vector<std::array<f_float, 3>>& matchedSource,
50+
const std::vector<std::array<f_float, 3>>& matchedTarget,
51+
f_float *alignxf,
52+
const std::array<f_float, 3> centerSource,
53+
const std::array<f_float, 3> centerTarget) = 0;
54+
55+
virtual int getAlgorithmID() = 0;
56+
57+
protected:
58+
bool quiet; ///< determines the verbosity
59+
};
60+
61+
#endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef SC_FIXED_CONVERTER
2+
#define SC_FIXED_CONVERTER
3+
4+
#include "slam6d/data_types.h"
5+
#include <vector>
6+
#include <array>
7+
#include "sc_fixed/sc_fixed_math.h"
8+
9+
std::vector<std::array<f_float, 3>> array2fixedArray(const DataXYZ &input);
10+
std::array<f_float, 16> array2fixedArray16(const double input[16]);
11+
void printPoints(const std::vector<std::array<f_float, 3>>& points);
12+
void writeFrame(std::ofstream& frame, std::array<f_float, 16>& matrix, int viewFactor);
13+
14+
#endif //SC_FIXED_CONVERTER

include/sc_fixed/sc_fixed_math.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef SC_FIXED_MATH_H
2+
#define SC_FIXED_MATH_H
3+
4+
#define SC_INCLUDE_FX
5+
6+
#include <systemc.h>
7+
#include <array>
8+
#include <cstring>
9+
#include <iostream>
10+
11+
#ifndef FIXED_WORD_LENGTH
12+
#define FIXED_WORD_LENGTH 48
13+
#endif
14+
15+
#ifndef FIXED_INT_WORD_LENGTH
16+
#define FIXED_INT_WORD_LENGTH 36
17+
#endif
18+
19+
#ifndef FIXED_HERON_ITERATIONS
20+
#define FIXED_HERON_ITERATIONS 3
21+
#endif
22+
23+
using namespace sc_dt;
24+
using f_float = sc_fixed<FIXED_WORD_LENGTH, FIXED_INT_WORD_LENGTH>;
25+
26+
f_float sc_fixed_heron_sqrt(f_float s);
27+
bool sc_choldc(f_float A[3][3], f_float diag[3]);
28+
void sc_cholsl(f_float A[3][3], f_float diag[3], f_float B[3], f_float x[3]);
29+
30+
void transform(std::vector<std::array<f_float, 3>>& scan, f_float alignxf[16], std::array<f_float, 16>& transMat, std::array<f_float, 16>& dalignxf, std::ofstream& frame, int islum);
31+
void transformPoints(const f_float alignxf[16], std::vector<std::array<f_float, 3>>& scan);
32+
void transformMatrix(const f_float alignxf[16], std::array<f_float, 16>& transMat, std::array<f_float, 16>& dalignxf);
33+
void transform3(const f_float alignxf[16], std::array<f_float, 3>& point);
34+
void MMult(const f_float M1[16], const std::array<f_float, 16>& M2, std::array<f_float, 16>& Mout);
35+
f_float sc_abs(f_float);
36+
37+
#endif // SC_FIXED_MATH_H

0 commit comments

Comments
 (0)