Skip to content

Commit d81c7ed

Browse files
authored
Merge pull request #50 from LimHyungTae/support_sudo_make_install
Support sudo make install
2 parents abf09c5 + 1adebe6 commit d81c7ed

File tree

9 files changed

+221
-7
lines changed

9 files changed

+221
-7
lines changed

cpp/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ $ cmake -DCMAKE_BUILD_TYPE=Release ..
3939
$ make -j 16
4040
```
4141

42-
If you want to run demo, just run
42+
If you want to **run demo**, just run the following command in the top-level directory as follows:
4343

4444
```commandline
4545
make cppinstall_with_demo
4646
```
4747

48-
in the top-level directory, or
48+
, or
4949

5050
```commandline
5151
# in patchwork-plusplus directory
@@ -58,6 +58,19 @@ $ make -j 16
5858
> Please check your cmake version via `cmake --version`.
5959
> If it is lower than 3.20, it is automatically updated by `scripts/install_latest_cmake.bash` (see [here](https://github.com/url-kaist/patchwork-plusplus/blob/master/cpp/CMakeLists.txt#L31)).
6060
61+
### sudo make install
62+
63+
Interestingly, our repository also supports `sudo make install`.
64+
After the build, go to `cpp/build` directory and then just run
65+
66+
```commandline
67+
sudo make install
68+
```
69+
70+
Consequently, our Patchwork++ is installed in your local environment.
71+
An example of finding the `patchworkpp` package in another package is also provided in [example_of_find_package](https://github.com/url-kaist/patchwork-plusplus/tree/master/cpp/example_of_find_package)
72+
73+
6174
## :runner: To run the demo codes
6275
> There are some example codes for your convenience!
6376
> Please try using Patchwork++ to segment ground points in a 3D point cloud :smiley:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
cmake_minimum_required(VERSION 3.11)
2+
project(example_of_find_package VERSION 1.0.0)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
set(PYTHON_EXECUTABLE python3)
6+
set(CMAKE_BUILD_TYPE Release)
7+
8+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${Open3D_C_FLAGS}")
9+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Open3D_CXX_FLAGS}")
10+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Open3D_EXE_LINKER_FLAGS}")
11+
12+
find_package(Eigen3 REQUIRED)
13+
find_package(patchworkpp REQUIRED)
14+
15+
if(CMAKE_VERSION VERSION_LESS "3.15")
16+
# Just automatically update cmake version
17+
execute_process(COMMAND bash ../scripts/install_latest.cmake.bash
18+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
19+
endif()
20+
21+
include_directories(${patchworkpp_INCLUDE_DIRS})
22+
23+
list(APPEND Open3D_LIBRARIES dl)
24+
25+
message(STATUS "Building examples for c++")
26+
find_package(Open3D QUIET)
27+
if (NOT Open3D_FOUND)
28+
message(STATUS "Open3D not found, installing Open3D...")
29+
execute_process(COMMAND bash ../scripts/install_open3d.bash
30+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
31+
find_package(Open3D REQUIRED HINTS ${CMAKE_INSTALL_PREFIX}/lib/CMake)
32+
else()
33+
message(STATUS "Found Open3D ${Open3D_VERSION}")
34+
endif()
35+
36+
list(APPEND Open3D_LIBRARIES dl)
37+
link_directories(${Open3D_LIBRARY_DIRS})
38+
39+
add_executable(demo_visualize ${CMAKE_CURRENT_SOURCE_DIR}/demo_visualize_copied.cpp)
40+
# Note that `patchworkpp::ground_seg_cores` is aliased as `ground_seg_cores` when installing `patchworkpp` package
41+
target_link_libraries(demo_visualize patchworkpp::ground_seg_cores ${Open3D_LIBRARIES} "stdc++fs")
42+
target_include_directories(demo_visualize PUBLIC ${Open3D_INCLUDE_DIRS})
43+

cpp/example_of_find_package/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patchwork++ as an Independent Package in C++
2+
3+
In this directory, we demonstrate how to use `patchworkpp` package using the `find_pakcage` command in `CMakeLists.txt`.
4+
5+
## How to build
6+
7+
In this directory,
8+
9+
```commandline
10+
# mkdir build && cd build
11+
$ cmake -DCMAKE_BUILD_TYPE=Release ..
12+
$ make -j 16
13+
```
14+
15+
If you want to **run demo**, just run the following command:
16+
17+
```commandline
18+
./demo_visualize
19+
```
20+
21+
Then, you can see the exact same result as Example 1 in the `cpp` directory!
22+
23+
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include <patchwork/patchworkpp.h>
2+
3+
#include <iostream>
4+
#include <fstream>
5+
#include <open3d/Open3D.h>
6+
7+
// for list folder
8+
#include <experimental/filesystem>
9+
namespace fs = std::experimental::filesystem;
10+
11+
using namespace open3d;
12+
13+
int filename_length = std::string("demo_visaulize_copied.cpp").length();
14+
std::string file_dir = std::string(__FILE__);
15+
std::string data_dir = file_dir.substr(0, file_dir.size()-filename_length) + "../../data/";
16+
17+
18+
void read_bin(std::string bin_path, Eigen::MatrixXf &cloud)
19+
{
20+
FILE *file = fopen(bin_path.c_str(), "rb");
21+
if (!file) {
22+
std::cerr << "error: failed to load " << bin_path << std::endl;
23+
return;
24+
}
25+
26+
std::vector<float> buffer(1000000);
27+
size_t num_points = fread(reinterpret_cast<char *>(buffer.data()), sizeof(float), buffer.size(), file) / 4;
28+
29+
cloud.resize(num_points, 4);
30+
for (int i=0; i<num_points; i++)
31+
{
32+
cloud.row(i) << buffer[i*4], buffer[i*4+1], buffer[i*4+2], buffer[i*4+3];
33+
}
34+
}
35+
36+
void eigen2geo(Eigen::MatrixXf add, std::shared_ptr<geometry::PointCloud> geo)
37+
{
38+
for ( int i=0; i<add.rows(); i++ ) {
39+
geo->points_.push_back(Eigen::Vector3d(add.row(i)(0), add.row(i)(1), add.row(i)(2)));
40+
}
41+
}
42+
43+
void addNormals(Eigen::MatrixXf normals, std::shared_ptr<geometry::PointCloud> geo)
44+
{
45+
for (int i=0; i<normals.rows(); i++) {
46+
geo->normals_.push_back(Eigen::Vector3d(normals.row(i)(0), normals.row(i)(1), normals.row(i)(2)));
47+
}
48+
}
49+
50+
51+
int main(int argc, char* argv[]) {
52+
53+
cout << "Execute" << __FILE__ << endl;
54+
// Get the dataset
55+
std::string input_cloud_filepath;
56+
if (argc < 2) {
57+
// Try out running on the test datasets.
58+
input_cloud_filepath = data_dir + "000000.bin";
59+
std::cout << "\033[1;33mNo point cloud file path specified; defaulting to the test directory. \033[0m" << std::endl;
60+
} else {
61+
input_cloud_filepath = argv[1];
62+
std::cout << "\033[1;32mLoading point cloud files from " << input_cloud_filepath << "\033[0m" << std::endl;
63+
}
64+
if(!fs::exists(input_cloud_filepath)){
65+
std::cout << "\033[1;31mERROR HERE: maybe wrong data file path, please check the path or remove argv to run default one. \033[0m"
66+
<< "\nThe file path you provide is: " << input_cloud_filepath << std::endl;
67+
return 0;
68+
}
69+
70+
// Patchwork++ initialization
71+
patchwork::Params patchwork_parameters;
72+
patchwork_parameters.verbose = true;
73+
74+
patchwork::PatchWorkpp Patchworkpp(patchwork_parameters);
75+
76+
// Load point cloud
77+
Eigen::MatrixXf cloud;
78+
read_bin(input_cloud_filepath, cloud);
79+
80+
// Estimate Ground
81+
Patchworkpp.estimateGround(cloud);
82+
83+
// Get Ground and Nonground
84+
Eigen::MatrixX3f ground = Patchworkpp.getGround();
85+
Eigen::MatrixX3f nonground = Patchworkpp.getNonground();
86+
double time_taken = Patchworkpp.getTimeTaken();
87+
88+
Eigen::VectorXi ground_idx = Patchworkpp.getGroundIndices();
89+
Eigen::VectorXi nonground_idx = Patchworkpp.getNongroundIndices();
90+
91+
// Get centers and normals for patches
92+
Eigen::MatrixX3f centers = Patchworkpp.getCenters();
93+
Eigen::MatrixX3f normals = Patchworkpp.getNormals();
94+
95+
cout << "Origianl Points #: " << cloud.rows() << endl;
96+
cout << "Ground Points #: " << ground.rows() << endl;
97+
cout << "Nonground Points #: " << nonground.rows() << endl;
98+
cout << "Time Taken : "<< time_taken / 1000000 << "(sec)" << endl;
99+
cout << "Press ... \n" << endl;
100+
cout << "\t H : help" << endl;
101+
cout << "\t N : visualize the surface normals" << endl;
102+
cout << "\tESC : close the Open3D window" << endl;
103+
104+
// Visualize
105+
std::shared_ptr<geometry::PointCloud> geo_ground(new geometry::PointCloud);
106+
std::shared_ptr<geometry::PointCloud> geo_nonground(new geometry::PointCloud);
107+
std::shared_ptr<geometry::PointCloud> geo_centers(new geometry::PointCloud);
108+
109+
eigen2geo(ground, geo_ground);
110+
eigen2geo(nonground, geo_nonground);
111+
eigen2geo(centers, geo_centers);
112+
addNormals(normals, geo_centers);
113+
114+
geo_ground->PaintUniformColor(Eigen::Vector3d(0.0, 1.0, 0.0));
115+
geo_nonground->PaintUniformColor(Eigen::Vector3d(1.0, 0.0, 0.0));
116+
geo_centers->PaintUniformColor(Eigen::Vector3d(1.0, 1.0, 0.0));
117+
118+
visualization::Visualizer visualizer;
119+
visualizer.CreateVisualizerWindow("Open3D", 1600, 900);
120+
visualizer.AddGeometry(geo_ground);
121+
visualizer.AddGeometry(geo_nonground);
122+
visualizer.AddGeometry(geo_centers);
123+
visualizer.Run();
124+
visualizer.DestroyVisualizerWindow();
125+
}

cpp/patchworkpp/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,24 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
2222
)
2323
install(TARGETS ${TARGET_NAME}
2424
EXPORT ${PARENT_PROJECT_NAME}Config
25-
LIBRARY DESTINATION lib
25+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
26+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
2627
)
2728

2829
export(TARGETS ${TARGET_NAME}
2930
NAMESPACE ${PARENT_PROJECT_NAME}::
3031
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PARENT_PROJECT_NAME}Config.cmake"
3132
)
33+
34+
# To install patchworkppConfig.cmake
3235
install(EXPORT ${PARENT_PROJECT_NAME}Config
33-
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PARENT_PROJECT_NAME}/cmake"
36+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PARENT_PROJECT_NAME}"
3437
NAMESPACE ${PARENT_PROJECT_NAME}::
38+
)
39+
40+
# To install patchworkppTargets.cmake
41+
install(EXPORT ${PARENT_PROJECT_NAME}Config
42+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PARENT_PROJECT_NAME}
43+
NAMESPACE ${PARENT_PROJECT_NAME}::
44+
FILE ${PARENT_PROJECT_NAME}Targets.cmake
3545
)

cpp/patchworkpp/src/patchworkpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "patchworkpp.h"
1+
#include "patchwork/patchworkpp.h"
22

33
using namespace std;
44
using namespace patchwork;

python/patchworkpp/pybinding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <pybind11/pybind11.h>
33
#include <pybind11/stl.h>
44

5-
#include "patchworkpp.h"
5+
#include "patchwork/patchworkpp.h"
66

77
namespace py = pybind11;
88

ros/src/GroundSegmentationServer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Patchwork++
2-
#include "patchworkpp.h"
2+
#include "patchwork/patchworkpp.h"
33

44
// ROS 2
55
#include <rclcpp/rclcpp.hpp>

0 commit comments

Comments
 (0)