Skip to content

Commit

Permalink
Merge pull request #50 from LimHyungTae/support_sudo_make_install
Browse files Browse the repository at this point in the history
Support sudo make install
  • Loading branch information
LimHyungTae committed May 31, 2024
2 parents abf09c5 + 1adebe6 commit d81c7ed
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 7 deletions.
17 changes: 15 additions & 2 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ $ cmake -DCMAKE_BUILD_TYPE=Release ..
$ make -j 16
```

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

```commandline
make cppinstall_with_demo
```

in the top-level directory, or
, or

```commandline
# in patchwork-plusplus directory
Expand All @@ -58,6 +58,19 @@ $ make -j 16
> Please check your cmake version via `cmake --version`.
> 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)).
### sudo make install

Interestingly, our repository also supports `sudo make install`.
After the build, go to `cpp/build` directory and then just run

```commandline
sudo make install
```

Consequently, our Patchwork++ is installed in your local environment.
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)


## :runner: To run the demo codes
> There are some example codes for your convenience!
> Please try using Patchwork++ to segment ground points in a 3D point cloud :smiley:
Expand Down
43 changes: 43 additions & 0 deletions cpp/example_of_find_package/CMakeLists.txt
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})

23 changes: 23 additions & 0 deletions cpp/example_of_find_package/README.md
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!


125 changes: 125 additions & 0 deletions cpp/example_of_find_package/demo_visualize_copied.cpp
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();
}
14 changes: 12 additions & 2 deletions cpp/patchworkpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
)
install(TARGETS ${TARGET_NAME}
EXPORT ${PARENT_PROJECT_NAME}Config
LIBRARY DESTINATION lib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

export(TARGETS ${TARGET_NAME}
NAMESPACE ${PARENT_PROJECT_NAME}::
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PARENT_PROJECT_NAME}Config.cmake"
)

# To install patchworkppConfig.cmake
install(EXPORT ${PARENT_PROJECT_NAME}Config
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PARENT_PROJECT_NAME}/cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PARENT_PROJECT_NAME}"
NAMESPACE ${PARENT_PROJECT_NAME}::
)

# To install patchworkppTargets.cmake
install(EXPORT ${PARENT_PROJECT_NAME}Config
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PARENT_PROJECT_NAME}
NAMESPACE ${PARENT_PROJECT_NAME}::
FILE ${PARENT_PROJECT_NAME}Targets.cmake
)
File renamed without changes.
2 changes: 1 addition & 1 deletion cpp/patchworkpp/src/patchworkpp.cpp
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;
Expand Down
2 changes: 1 addition & 1 deletion python/patchworkpp/pybinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "patchworkpp.h"
#include "patchwork/patchworkpp.h"

namespace py = pybind11;

Expand Down
2 changes: 1 addition & 1 deletion ros/src/GroundSegmentationServer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Patchwork++
#include "patchworkpp.h"
#include "patchwork/patchworkpp.h"

// ROS 2
#include <rclcpp/rclcpp.hpp>
Expand Down

0 comments on commit d81c7ed

Please sign in to comment.