Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit 4ffd34e

Browse files
author
Daniel
committed
Updated centroid calculation method
0 parents  commit 4ffd34e

File tree

12 files changed

+2085
-0
lines changed

12 files changed

+2085
-0
lines changed

CMakeLists.txt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
##############################################################################
2+
# CMAKE CONFIGURATION
3+
##############################################################################
4+
cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR)
5+
6+
# set project name
7+
project(dbscan VERSION 1.0.2)
8+
9+
# set build type = Debug mode
10+
set(CMAKE_BUILD_TYPE Debug)
11+
12+
message("\n" "=========================================")
13+
message("Project: ${PROJECT_NAME} ")
14+
message("=========================================")
15+
16+
# set the include directive in the same project folder
17+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
18+
19+
# set corresponding package directories
20+
set(PCL_DIR /opt/pcl-1.9.0/build)
21+
22+
# Include dependencies from pcl 1.8.0 in project directory
23+
set(CMAKE_MODULE_PATH ${PCL_DIR}/../cmake/Modules)
24+
25+
# set cmake for use std c++11 and output executable folder to bin
26+
#set(CMAKE_CXX_STANDARD 11)
27+
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
28+
29+
# set turn off the output rule messages of cmake
30+
##set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
31+
32+
##############################################################################
33+
# PACKAGES
34+
##############################################################################
35+
message("***********************")
36+
message("PCL PACKAGE")
37+
message("***********************")
38+
39+
##find_package(PCL 1.8 PATHS ${PCL_DIR} QUIET COMPONENTS common io visualization CONFIG) ##REQUIRED COMPONENTS common io visualization)
40+
find_package(PCL 1.9 PATHS ${PCL_DIR} QUIET)
41+
if(PCL_FOUND)
42+
message(STATUS "PCL status:")
43+
message(STATUS " version: ${PCL_VERSION}")
44+
message(STATUS " directory: ${PCL_DIR}")
45+
else()
46+
message(WARNING " PCL 1.9 not found, attempting 1.8...")
47+
find_package(PCL 1.8 REQUIRED)
48+
if(PCL_FOUND)
49+
message(STATUS "PCL status:")
50+
message(STATUS " version: ${PCL_VERSION}")
51+
message(STATUS " directory: ${PCL_DIR}")
52+
else()
53+
message(WARNING " PCL 1.8 not found, attempting 1.7...")
54+
find_package(PCL 1.7 REQUIRED)
55+
if(PCL_FOUND)
56+
message(STATUS "PCL status:")
57+
message(STATUS " version: ${PCL_VERSION}")
58+
message(STATUS " directory: ${PCL_DIR}")
59+
else()
60+
message(FATAL_ERROR " ERROR: PCL minimum required version 1.7. Not found")
61+
endif()
62+
endif()
63+
endif()
64+
65+
##############################################################################
66+
# HEADERS
67+
##############################################################################
68+
include_directories(${PCL_INCLUDE_DIRS})
69+
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
70+
include(CheckFunctionExists)
71+
72+
# Use the compile definitions defined in PCL
73+
add_definitions(${PCL_DEFINITIONS})
74+
75+
##############################################################################
76+
# LIBRARIES PATH
77+
##############################################################################
78+
link_directories(${PCL_LIBRARY_DIRS})
79+
80+
##############################################################################
81+
# SOURCE CODE
82+
##############################################################################
83+
list(APPEND SOURCE_FILES "main.cpp"
84+
"src/dbScan.cpp"
85+
"src/OctreeGenerator.cpp"
86+
"src/cluster.cpp"
87+
)
88+
89+
##############################################################################
90+
# EXECUTABLES
91+
##############################################################################
92+
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
93+
94+
##############################################################################
95+
# TARGET LIBRARIES
96+
##############################################################################
97+
target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES})
98+
99+
message("=========================================")
100+
message("Project: ${PROJECT_NAME} COMPILED WITH CMAKE " ${CMAKE_VERSION})
101+
message("=========================================")

README.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# DBScan-PCL-Optimized
2+
3+
This project is taken from: **Navarro-Hinojosa, Octavio, y Moisés Alencastre-Miranda. "DBSCAN modificado con Octrees para agrupar nubes de puntos en tiempo real." Research in Computing Science, Vol. 114: Advances in Image Processing and Computer Vision, pp. 173–186, 2016.** Github: https://github.com/Hagen23/DBScan_Octrees
4+
5+
It was modified with:
6+
7+
* It was added a CMakeList.txt for cmake compilation with PCL 1.8.1 (support 1.9.1)
8+
* It was added an argument param options
9+
* It was added a pcl visualizer
10+
* It was deleted the Glut visualizer
11+
* It was added a cluster saving method
12+
* It was added a cluster coloring method
13+
* It was replaced the input file from CSV to PCD
14+
* It was added a cluster coloring method for original color of the point cloud
15+
16+
## Input file structure support
17+
18+
* .pcd
19+
* .ply
20+
* .txt
21+
* .xyz
22+
23+
## Output file structure (default = .pcd)
24+
* cloud_cluster_#.txt:
25+
26+
x y z r g b
27+
28+
## Example
29+
<img src="./example/scan1.png" align="center" height="400" width="720"><br>
30+
<img src="./example/example2.png" align="center" height="400" width="720"><br>
31+
32+
-------------------
33+
## Compilation
34+
* Set "YOUR OWN" PCL Build DIR in CMakeList.txt e.g: **/opt/pcl-1.8.1/build** and save it.
35+
* Create a "build" folder
36+
37+
in the main folder:
38+
39+
- cd build/
40+
- cmake ../
41+
- make
42+
43+
44+
### Test
45+
46+
cd build/bin
47+
./dbscan <input file> <-- This will run a fast testing with default parameters
48+
./dbscan <input file> <octree resolution> <eps> <min Aux Pts> <min Pts> <output dir> <output extension (optional)>
49+
50+
input file = path to input point_cloud (.pcd .txt .ply .xyz)
51+
octree resolution = 124
52+
eps = 40
53+
min Pts = 4
54+
max Pts = 5
55+
output dir = path to output clusters
56+
output extension (optional) = pcd, ply, txt or xyz
57+
58+
Example:
59+
./dbscan /home/xXx/Downloads/point_cloud.pcd 124 40 5 5 /home/xXx/Downloads/clusters ply
60+
61+
¡You can modify the parameters to obtain better results!
62+
I recommend modifying only the eps value, with 40 - 60 you can get better clusters.
63+
64+
## Note
65+
66+
If you do not want to see the output clusters on PCL Viewer, set:
67+
68+
bool showClusters = False; //Main function
69+
70+
## Troubleshoot PCL-1.9.1
71+
if compiling the project with PCL-1.9.1 this occurs:
72+
73+
-- Build files have been written to: /home/t00215031/Downloads/DBScan-PCL-Optimized-master/build
74+
[ 20%] Building CXX object CMakeFiles/dbscan.dir/main.cpp.o
75+
In file included from /opt/pcl-1.9.1/common/include/pcl/pcl_macros.h:75:0,
76+
from /opt/pcl-1.9.1/octree/include/pcl/octree/octree_nodes.h:47,
77+
.
78+
.
79+
.
80+
81+
/opt/pcl-1.9.1/build/include/pcl/pcl_config.h:7:4: error: #error PCL requires C++14 or above
82+
#error PCL requires C++14 or above
83+
^
84+
CMakeFiles/dbscan.dir/build.make:62: recipe for target 'CMakeFiles/dbscan.dir/main.cpp.o' failed
85+
make[2]: *** [CMakeFiles/dbscan.dir/main.cpp.o] Error 1
86+
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/dbscan.dir/all' failed
87+
make[1]: *** [CMakeFiles/dbscan.dir/all] Error 2
88+
Makefile:83: recipe for target 'all' failed
89+
make: *** [all] Error 2
90+
91+
## Solution
92+
1. Update gcc and g++ to version 6:
93+
$ sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
94+
$ sudo apt-get update -y
95+
$ sudo apt-get install -y gcc-6 g++-6 clang-3.8
96+
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 70 --slave /usr/bin/g++ g++ /usr/bin/g++-6
97+
98+
--> check gcc and g++ version:
99+
$ gcc --version
100+
$ g++ --version
101+
102+
g++ (Ubuntu 6.5.0-2ubuntu1~16.04) 6.5.0 20181026
103+
Copyright (C) 2017 Free Software Foundation, Inc.
104+
This is free software; see the source for copying conditions. There is NO
105+
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
106+
107+
2. Compile again
108+
$ cmake../ && make
109+
110+
if:
111+
112+
../../../bin/librtabmap_core.so.0.11.11: undefined reference to `pcl::search::Search<pcl::PointXYZRGBNormal>::getName[abi:cxx11]() const'
113+
../../../bin/librtabmap_core.so.0.11.11: undefined reference to `pcl::search::Search<pcl::PointXYZRGB>::getName[abi:cxx11]() const'
114+
../../../bin/librtabmap_core.so.0.11.11: undefined reference to `pcl::search::Search<pcl::PointXYZ>::getName[abi:cxx11]() const'
115+
collect2: error: ld returned 1 exit status
116+
117+
Solution:
118+
119+
#include <pcl/search/impl/search.hpp>
120+
121+
#ifndef PCL_NO_PRECOMPILE
122+
#include <pcl/impl/instantiate.hpp>
123+
#include <pcl/point_types.h>
124+
PCL_INSTANTIATE(Search, PCL_POINT_TYPES)
125+
#endif // PCL_NO_PRECOMPILE
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+

example/example2.png

341 KB
Loading

example/scan1.png

27.7 KB
Loading

include/HTRBasicDataStructures.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
*@file HTRBasicDataStructures.h
3+
*Data structures that do not depend on external classes.
4+
*
5+
*/
6+
#include <pcl/pcl_macros.h>
7+
#include <pcl/point_types.h>
8+
#define PCL_NO_PRECOMPILE
9+
#pragma once
10+
#ifndef HTR_BASIC_DATA_STRUCTURES_H
11+
#define HTR_BASIC_DATA_STRUCTURES_H
12+
13+
/// Modified pcl point to include an id.
14+
namespace pcl {
15+
16+
class mod_pointXYZ : public PointXYZRGB {
17+
18+
public:
19+
mod_pointXYZ() {
20+
x = y = z = 0;
21+
id = 0;
22+
}
23+
24+
mod_pointXYZ(float x, float y, float z) : PointXYZRGB(x, y, z) { id = 0; }
25+
/*
26+
mod_pointXYZ(unsigned int r, unsigned int g, unsigned int b) : PointXYZRGB(r,g,b){
27+
id = 0;
28+
}
29+
*/
30+
int id;
31+
};
32+
}
33+
34+
namespace htr {
35+
struct Index2D {
36+
int x;
37+
int y;
38+
// Index2D():x(0),y(0){}
39+
};
40+
41+
struct Point3D {
42+
float x;
43+
float y;
44+
float z;
45+
46+
unsigned int r;
47+
unsigned int g;
48+
unsigned int b;
49+
50+
void initRandom() {
51+
x = (rand() % 40);
52+
y = (rand() % 40);
53+
z = (rand() % 40);
54+
}
55+
};
56+
57+
struct FlaggedPoint3D {
58+
Point3D point;
59+
int flag;
60+
};
61+
62+
struct DepthPixel {
63+
int x;
64+
int y;
65+
float z;
66+
};
67+
68+
struct LabeledPoint {
69+
Point3D point;
70+
int label;
71+
};
72+
73+
struct CubeBoundary {
74+
Point3D start;
75+
Point3D end;
76+
};
77+
78+
struct LinearBoundary {
79+
float start;
80+
float end;
81+
};
82+
}
83+
84+
#endif

0 commit comments

Comments
 (0)