-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from LimHyungTae/support_sudo_make_install
Support sudo make install
- Loading branch information
Showing
9 changed files
with
221 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
cmake_minimum_required(VERSION 3.11) | ||
project(example_of_find_package VERSION 1.0.0) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(PYTHON_EXECUTABLE python3) | ||
set(CMAKE_BUILD_TYPE Release) | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${Open3D_C_FLAGS}") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Open3D_CXX_FLAGS}") | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Open3D_EXE_LINKER_FLAGS}") | ||
|
||
find_package(Eigen3 REQUIRED) | ||
find_package(patchworkpp REQUIRED) | ||
|
||
if(CMAKE_VERSION VERSION_LESS "3.15") | ||
# Just automatically update cmake version | ||
execute_process(COMMAND bash ../scripts/install_latest.cmake.bash | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | ||
endif() | ||
|
||
include_directories(${patchworkpp_INCLUDE_DIRS}) | ||
|
||
list(APPEND Open3D_LIBRARIES dl) | ||
|
||
message(STATUS "Building examples for c++") | ||
find_package(Open3D QUIET) | ||
if (NOT Open3D_FOUND) | ||
message(STATUS "Open3D not found, installing Open3D...") | ||
execute_process(COMMAND bash ../scripts/install_open3d.bash | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | ||
find_package(Open3D REQUIRED HINTS ${CMAKE_INSTALL_PREFIX}/lib/CMake) | ||
else() | ||
message(STATUS "Found Open3D ${Open3D_VERSION}") | ||
endif() | ||
|
||
list(APPEND Open3D_LIBRARIES dl) | ||
link_directories(${Open3D_LIBRARY_DIRS}) | ||
|
||
add_executable(demo_visualize ${CMAKE_CURRENT_SOURCE_DIR}/demo_visualize_copied.cpp) | ||
# Note that `patchworkpp::ground_seg_cores` is aliased as `ground_seg_cores` when installing `patchworkpp` package | ||
target_link_libraries(demo_visualize patchworkpp::ground_seg_cores ${Open3D_LIBRARIES} "stdc++fs") | ||
target_include_directories(demo_visualize PUBLIC ${Open3D_INCLUDE_DIRS}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Patchwork++ as an Independent Package in C++ | ||
|
||
In this directory, we demonstrate how to use `patchworkpp` package using the `find_pakcage` command in `CMakeLists.txt`. | ||
|
||
## How to build | ||
|
||
In this directory, | ||
|
||
```commandline | ||
# mkdir build && cd build | ||
$ cmake -DCMAKE_BUILD_TYPE=Release .. | ||
$ make -j 16 | ||
``` | ||
|
||
If you want to **run demo**, just run the following command: | ||
|
||
```commandline | ||
./demo_visualize | ||
``` | ||
|
||
Then, you can see the exact same result as Example 1 in the `cpp` directory! | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#include <patchwork/patchworkpp.h> | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <open3d/Open3D.h> | ||
|
||
// for list folder | ||
#include <experimental/filesystem> | ||
namespace fs = std::experimental::filesystem; | ||
|
||
using namespace open3d; | ||
|
||
int filename_length = std::string("demo_visaulize_copied.cpp").length(); | ||
std::string file_dir = std::string(__FILE__); | ||
std::string data_dir = file_dir.substr(0, file_dir.size()-filename_length) + "../../data/"; | ||
|
||
|
||
void read_bin(std::string bin_path, Eigen::MatrixXf &cloud) | ||
{ | ||
FILE *file = fopen(bin_path.c_str(), "rb"); | ||
if (!file) { | ||
std::cerr << "error: failed to load " << bin_path << std::endl; | ||
return; | ||
} | ||
|
||
std::vector<float> buffer(1000000); | ||
size_t num_points = fread(reinterpret_cast<char *>(buffer.data()), sizeof(float), buffer.size(), file) / 4; | ||
|
||
cloud.resize(num_points, 4); | ||
for (int i=0; i<num_points; i++) | ||
{ | ||
cloud.row(i) << buffer[i*4], buffer[i*4+1], buffer[i*4+2], buffer[i*4+3]; | ||
} | ||
} | ||
|
||
void eigen2geo(Eigen::MatrixXf add, std::shared_ptr<geometry::PointCloud> geo) | ||
{ | ||
for ( int i=0; i<add.rows(); i++ ) { | ||
geo->points_.push_back(Eigen::Vector3d(add.row(i)(0), add.row(i)(1), add.row(i)(2))); | ||
} | ||
} | ||
|
||
void addNormals(Eigen::MatrixXf normals, std::shared_ptr<geometry::PointCloud> geo) | ||
{ | ||
for (int i=0; i<normals.rows(); i++) { | ||
geo->normals_.push_back(Eigen::Vector3d(normals.row(i)(0), normals.row(i)(1), normals.row(i)(2))); | ||
} | ||
} | ||
|
||
|
||
int main(int argc, char* argv[]) { | ||
|
||
cout << "Execute" << __FILE__ << endl; | ||
// Get the dataset | ||
std::string input_cloud_filepath; | ||
if (argc < 2) { | ||
// Try out running on the test datasets. | ||
input_cloud_filepath = data_dir + "000000.bin"; | ||
std::cout << "\033[1;33mNo point cloud file path specified; defaulting to the test directory. \033[0m" << std::endl; | ||
} else { | ||
input_cloud_filepath = argv[1]; | ||
std::cout << "\033[1;32mLoading point cloud files from " << input_cloud_filepath << "\033[0m" << std::endl; | ||
} | ||
if(!fs::exists(input_cloud_filepath)){ | ||
std::cout << "\033[1;31mERROR HERE: maybe wrong data file path, please check the path or remove argv to run default one. \033[0m" | ||
<< "\nThe file path you provide is: " << input_cloud_filepath << std::endl; | ||
return 0; | ||
} | ||
|
||
// Patchwork++ initialization | ||
patchwork::Params patchwork_parameters; | ||
patchwork_parameters.verbose = true; | ||
|
||
patchwork::PatchWorkpp Patchworkpp(patchwork_parameters); | ||
|
||
// Load point cloud | ||
Eigen::MatrixXf cloud; | ||
read_bin(input_cloud_filepath, cloud); | ||
|
||
// Estimate Ground | ||
Patchworkpp.estimateGround(cloud); | ||
|
||
// Get Ground and Nonground | ||
Eigen::MatrixX3f ground = Patchworkpp.getGround(); | ||
Eigen::MatrixX3f nonground = Patchworkpp.getNonground(); | ||
double time_taken = Patchworkpp.getTimeTaken(); | ||
|
||
Eigen::VectorXi ground_idx = Patchworkpp.getGroundIndices(); | ||
Eigen::VectorXi nonground_idx = Patchworkpp.getNongroundIndices(); | ||
|
||
// Get centers and normals for patches | ||
Eigen::MatrixX3f centers = Patchworkpp.getCenters(); | ||
Eigen::MatrixX3f normals = Patchworkpp.getNormals(); | ||
|
||
cout << "Origianl Points #: " << cloud.rows() << endl; | ||
cout << "Ground Points #: " << ground.rows() << endl; | ||
cout << "Nonground Points #: " << nonground.rows() << endl; | ||
cout << "Time Taken : "<< time_taken / 1000000 << "(sec)" << endl; | ||
cout << "Press ... \n" << endl; | ||
cout << "\t H : help" << endl; | ||
cout << "\t N : visualize the surface normals" << endl; | ||
cout << "\tESC : close the Open3D window" << endl; | ||
|
||
// Visualize | ||
std::shared_ptr<geometry::PointCloud> geo_ground(new geometry::PointCloud); | ||
std::shared_ptr<geometry::PointCloud> geo_nonground(new geometry::PointCloud); | ||
std::shared_ptr<geometry::PointCloud> geo_centers(new geometry::PointCloud); | ||
|
||
eigen2geo(ground, geo_ground); | ||
eigen2geo(nonground, geo_nonground); | ||
eigen2geo(centers, geo_centers); | ||
addNormals(normals, geo_centers); | ||
|
||
geo_ground->PaintUniformColor(Eigen::Vector3d(0.0, 1.0, 0.0)); | ||
geo_nonground->PaintUniformColor(Eigen::Vector3d(1.0, 0.0, 0.0)); | ||
geo_centers->PaintUniformColor(Eigen::Vector3d(1.0, 1.0, 0.0)); | ||
|
||
visualization::Visualizer visualizer; | ||
visualizer.CreateVisualizerWindow("Open3D", 1600, 900); | ||
visualizer.AddGeometry(geo_ground); | ||
visualizer.AddGeometry(geo_nonground); | ||
visualizer.AddGeometry(geo_centers); | ||
visualizer.Run(); | ||
visualizer.DestroyVisualizerWindow(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "patchworkpp.h" | ||
#include "patchwork/patchworkpp.h" | ||
|
||
using namespace std; | ||
using namespace patchwork; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters