-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Qinqing Liu
committed
Oct 26, 2020
1 parent
cd14fbd
commit abbbc42
Showing
211 changed files
with
238,108 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,120 @@ | ||
cmake_minimum_required(VERSION 3.8.2) | ||
|
||
# options | ||
option(USE_MINIBALL "Use the Miniball.hpp" ON) | ||
option(USE_WINDOWS_IO "Use the header io.h provided by Windows" OFF) | ||
option(USE_CUDA "CPU only, without CUDA" ON) | ||
option(USE_PYTHON "Build the python interface with pybind11" ON) | ||
option(USE_GLOG "Use glog" OFF) | ||
option(USE_OPENMP "Use OpenMP for speed up" OFF) | ||
option(USE_RPLY "Use the library rply in the project octree" OFF) | ||
set(VCPKG "<Set VCPKG path>" CACHE PATH "The VCPKG path, containing glog and gtest") | ||
|
||
|
||
# set languanges | ||
if(USE_CUDA) | ||
project(Octree LANGUAGES CUDA CXX C) | ||
add_definitions(-DUSE_CUDA) | ||
set(CMAKE_CUDA_STANDARD 11) | ||
set(CMAKE_CUDA_STANDARD_REQUIRED ON) | ||
else() | ||
project(Octree LANGUAGES C CXX) | ||
endif() | ||
|
||
# use folder to orgnize the project | ||
set_property(GLOBAL PROPERTY USE_FOLDERS ON) | ||
|
||
# # c++11 Support | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
# add target_link_libraries | ||
if(USE_MINIBALL) | ||
add_definitions(-DUSE_MINIBALL) | ||
set(miniball_path "${PROJECT_SOURCE_DIR}/external/octree-ext/miniball") | ||
include_directories(${miniball_path}) | ||
endif() | ||
|
||
if(USE_RPLY) | ||
add_definitions(-DUSE_RPLY) | ||
file(GLOB src_rply | ||
"${PROJECT_SOURCE_DIR}/external/octree-ext/rply-1.1.4/*.h" | ||
"${PROJECT_SOURCE_DIR}/external/octree-ext/rply-1.1.4/*.c") | ||
include_directories("${PROJECT_SOURCE_DIR}/external/octree-ext/rply-1.1.4") | ||
add_library(rply ${src_rply}) | ||
endif() | ||
|
||
if(USE_GLOG) | ||
add_definitions(-DUSE_GLOG) | ||
endif() | ||
|
||
if(USE_WINDOWS_IO) | ||
add_definitions(-DUSE_WINDOWS_IO) | ||
endif() | ||
|
||
if(USE_OPENMP) | ||
find_package(OpenMP) | ||
if (OPENMP_FOUND) | ||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") | ||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") | ||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") | ||
endif() | ||
endif() | ||
|
||
set(happly_path "${PROJECT_SOURCE_DIR}/external/octree-ext/happly") | ||
include_directories(${happly_path}) | ||
|
||
set(nanoflann_path "${PROJECT_SOURCE_DIR}/external/octree-ext/nanoflann/include") | ||
include_directories(${nanoflann_path}) | ||
|
||
|
||
# files | ||
file(GLOB src_octree_lib | ||
"${PROJECT_SOURCE_DIR}/octree/*.h" | ||
"${PROJECT_SOURCE_DIR}/octree/*.cpp") | ||
if(USE_CUDA) | ||
file(GLOB cuda_octree_lib | ||
"${PROJECT_SOURCE_DIR}/octree/*.cu") | ||
set(src_octree_lib ${src_octree_lib} ${cuda_octree_lib}) | ||
endif() | ||
|
||
file(GLOB src_viewer | ||
"${PROJECT_SOURCE_DIR}/viewer/*.h" | ||
"${PROJECT_SOURCE_DIR}/viewer/*.cpp" ) | ||
file(GLOB src_scanner | ||
"${PROJECT_SOURCE_DIR}/scanner/*.h" | ||
"${PROJECT_SOURCE_DIR}/scanner/*.cpp" ) | ||
file(GLOB src_test | ||
"${PROJECT_SOURCE_DIR}/test/*.cpp") | ||
|
||
# includes | ||
include_directories("${PROJECT_BINARY_DIR}") | ||
include_directories("${PROJECT_SOURCE_DIR}/octree") | ||
include_directories("${PROJECT_SOURCE_DIR}/viewer") | ||
include_directories("${PROJECT_SOURCE_DIR}/scanner") | ||
|
||
|
||
# add the octree lib | ||
add_library(octree_lib ${src_octree_lib}) | ||
target_compile_features(octree_lib PUBLIC cxx_std_11) | ||
if(USE_RPLY) | ||
target_link_libraries(octree_lib rply) | ||
endif(USE_RPLY) | ||
|
||
# add tools | ||
file(GLOB_RECURSE srcs "${PROJECT_SOURCE_DIR}/tools/*.cpp") | ||
foreach(source ${srcs}) | ||
get_filename_component(name ${source} NAME_WE) | ||
if(name MATCHES "build_octree") | ||
set(name "octree") | ||
endif() | ||
add_executable(${name} ${source}) | ||
target_link_libraries(${name} octree_lib) | ||
set_target_properties(${name} PROPERTIES FOLDER "tools") | ||
endforeach(source) | ||
|
||
|
||
# add the python interface | ||
if(USE_PYTHON) | ||
add_subdirectory(python) | ||
endif() |
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,8 @@ | ||
# ReadMe | ||
|
||
This folder contains the external libraries used by the octree project. | ||
These libraries can be downloaded via the following commaneds: | ||
|
||
``` | ||
git clone --recursive https://github.com/wang-ps/octree-ext.git | ||
``` |
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,194 @@ | ||
#ifndef CMD_FLAGS_H_ | ||
#define CMD_FLAGS_H_ | ||
|
||
#include <map> | ||
#include <memory> | ||
#include <vector> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <algorithm> | ||
|
||
namespace cflags { | ||
|
||
using std::string; | ||
using std::shared_ptr; | ||
|
||
enum Require { kOptional = 0, kRequired}; | ||
|
||
class CmdFlags { | ||
public: | ||
CmdFlags(const string& name, const string& usage, const Require require) | ||
: name_(name), usage_(usage), require_(require), set_(false) {} | ||
virtual const string help() const = 0; | ||
virtual void set_value(const char* argv) = 0; | ||
const string& name() const { return name_; } | ||
const string& usage() const { return usage_; } | ||
const Require& require() const { return require_; } | ||
const bool& set() { return set_; } | ||
|
||
protected: | ||
string name_; | ||
string usage_; | ||
Require require_; | ||
bool set_; | ||
}; | ||
|
||
template<typename Dtype> | ||
class CmdFlags_Dtype : public CmdFlags { | ||
public: | ||
CmdFlags_Dtype(const string& name, const Dtype& value, const string& usage, | ||
const Require require) : CmdFlags(name, usage, require), value_(value) {} | ||
void set_value(const Dtype& value) { | ||
value_ = value; set_ = true; | ||
} | ||
const Dtype& value() { return value_; } | ||
virtual const string help() const { | ||
std::ostringstream oss; | ||
bool optional = require_ == kOptional; | ||
if (optional) { oss << "\t["; } else { oss << "\t "; } | ||
oss << "--" << name_ << " <" << usage_ << ">"; | ||
if (optional) oss << "=" << value_ << "]"; | ||
oss << "\n"; | ||
return oss.str(); | ||
} | ||
protected: | ||
Dtype value_; | ||
}; | ||
|
||
class CmdFlags_int : public CmdFlags_Dtype<int> { | ||
public: | ||
CmdFlags_int(const string& name, const int& value, const string& usage, | ||
const Require require) : CmdFlags_Dtype<int>(name, value, usage, require) {} | ||
virtual void set_value(const char* argv) { | ||
value_ = atoi(argv); set_ = true; | ||
} | ||
}; | ||
|
||
class CmdFlags_float : public CmdFlags_Dtype<float> { | ||
public: | ||
CmdFlags_float(const string& name, const float& value, const string& usage, | ||
const Require require) : CmdFlags_Dtype<float>(name, value, usage, require) {} | ||
virtual void set_value(const char* argv) { | ||
value_ = static_cast<float>(atof(argv)); set_ = true; | ||
} | ||
}; | ||
|
||
class CmdFlags_bool : public CmdFlags_Dtype<bool> { | ||
public: | ||
CmdFlags_bool(const string& name, const bool& value, const string& usage, | ||
const Require require) : CmdFlags_Dtype<bool>(name, value, usage, require) {} | ||
virtual void set_value(const char* argv) { | ||
value_ = atoi(argv) != 0; set_ = true; | ||
} | ||
}; | ||
|
||
class CmdFlags_string : public CmdFlags_Dtype<string> { | ||
public: | ||
CmdFlags_string(const string& name, const string& value, const string& usage, | ||
const Require require) : CmdFlags_Dtype<string>(name, value, usage, require) {} | ||
virtual void set_value(const char* argv) { | ||
value_.assign(argv); set_ = true; | ||
} | ||
}; | ||
|
||
class FlagRegistry { | ||
public: | ||
typedef std::map<string, shared_ptr<CmdFlags> > FlagMap; | ||
|
||
static FlagMap& Registry() { | ||
static std::unique_ptr<FlagMap> g_registry_(new FlagMap()); | ||
return *g_registry_; | ||
} | ||
|
||
static void AddFlag(const string& name, shared_ptr<CmdFlags> flag) { | ||
FlagMap& flag_map = Registry(); | ||
flag_map[name] = flag; | ||
} | ||
|
||
private: | ||
// FlagRegistry should never be instantiated - | ||
// everything is done with its static variables. | ||
FlagRegistry() {} | ||
}; | ||
|
||
class FlagRegisterer { | ||
public: | ||
FlagRegisterer(const string& name, shared_ptr<CmdFlags> cmd_flag) { | ||
FlagRegistry::AddFlag(name, cmd_flag); | ||
} | ||
}; | ||
|
||
void PrintHelpInfo(const string& info = "") { | ||
std::cout << info << std::endl; | ||
std::vector<string> help_info; | ||
auto& flag_map = FlagRegistry::Registry(); | ||
for (auto& it : flag_map) { | ||
help_info.push_back(it.second->help()); | ||
} | ||
std::sort(help_info.begin(), help_info.end()); | ||
for (auto& it : help_info) { | ||
std::cout << it; | ||
} | ||
std::cout << std::endl; | ||
} | ||
|
||
bool ParseCmd(int argc, char *argv[]) { | ||
// parse | ||
auto& flag_map = FlagRegistry::Registry(); | ||
for (int i = 1; i < argc; i += 2) { | ||
if (argv[i][0] == '-' && argv[i][1] == '-') { | ||
string name(&argv[i][2]); | ||
auto it = flag_map.find(name); | ||
if (it != flag_map.end()) { | ||
if (i + 1 >= argc) { | ||
std::cout << "The parameter " << argv[i] << " is unset!" << std::endl; | ||
return false; | ||
} | ||
it->second->set_value(argv[i + 1]); | ||
//} else if (name == "help") { | ||
// PrintHelpInfo(); | ||
} else { | ||
std::cout << "Unknown cmd parameter: " << argv[i] << std::endl; | ||
return false; | ||
} | ||
} else { | ||
std::cout << "Invalid cmd parameter: " << argv[i] << std::endl; | ||
return false; | ||
} | ||
} | ||
|
||
// check | ||
for (auto& it : flag_map) { | ||
CmdFlags* pflag = it.second.get(); | ||
if (pflag->require() == kRequired && pflag->set() == false) { | ||
std::cout << " The parameter --" << pflag->name() | ||
<< " has to be set!\n"; | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} // namespace cflags | ||
|
||
#define DEFINE_CFLAG_VAR(dtype, name, require, val, usage) \ | ||
namespace cflags{ \ | ||
static FlagRegisterer g_registor_##name(#name, \ | ||
shared_ptr<CmdFlags>(new CmdFlags_##dtype(#name, val, usage, require))); \ | ||
const dtype& FLAGS_##name = std::dynamic_pointer_cast<CmdFlags_##dtype>( \ | ||
FlagRegistry::Registry()[#name])->value(); \ | ||
} \ | ||
using cflags::FLAGS_##name | ||
|
||
#define DEFINE_int(name, require, default_val, usage) \ | ||
DEFINE_CFLAG_VAR(int, name, require, default_val, usage) | ||
|
||
#define DEFINE_float(name, require, default_val, usage) \ | ||
DEFINE_CFLAG_VAR(float, name, require, default_val, usage) | ||
|
||
#define DEFINE_bool(name, require, default_val, usage) \ | ||
DEFINE_CFLAG_VAR(bool, name, require, default_val, usage) | ||
|
||
#define DEFINE_string(name, require, default_val, usage) \ | ||
DEFINE_CFLAG_VAR(string, name, require, default_val, usage) | ||
|
||
#endif // CMD_FLAGS_H_ |
Oops, something went wrong.