Skip to content

Commit

Permalink
Box Approximate (#50)
Browse files Browse the repository at this point in the history
* ch -> box

* fix win ci

* only compile linux

* add box to option

* Fix CI compilation on Windows and Mac. (#48)

* Revert "only compile linux"

This reverts commit e263eef.

* Bump OSX version and add windows compile option.

* fix macos build

---------

Co-authored-by: Ruoxi <[email protected]>
  • Loading branch information
SarahWeiii and eliphatfs authored Jul 12, 2024
1 parent fce9d0f commit eef37b5
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
config:
- { os: "ubuntu-20.04", build-dir: "build-linux" }
- { os: "windows-2019", build-dir: "build-windows" }
- { os: "macos-11", build-dir: "build-macos" }
- { os: "macos-12", build-dir: "build-macos" }
steps:
- uses: actions/checkout@v2
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
config:
- { os: "ubuntu-20.04", arch: "auto64" }
- { os: "windows-2019", arch: "auto64" }
- { os: "macos-11", arch: "auto64" }
- { os: "macos-11", arch: "universal2" }
- { os: "macos-12", arch: "auto64" }
- { os: "macos-12", arch: "universal2" }
steps:
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macos-11]
os: [ubuntu-20.04, windows-2019, macos-12]
python-version: ['3.6', '3.11']

steps:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ build/*
dist/*
wheelhouse/*
coacd.egg-info/*
*obj
*wrl
*ply
*DS_Store
91 changes: 91 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"files.associations": {
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"__verbose_abort": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"format": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"span": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"variant": "cpp",
"vector": "cpp",
"*.tcc": "cpp",
"chrono": "cpp",
"compare": "cpp",
"concepts": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"source_location": "cpp",
"utility": "cpp",
"stop_token": "cpp"
}
}
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ else()
endif()

if (MSVC)
add_compile_options("/bigobj")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W0 -fpermissive -D_USE_MATH_DEFINES")
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
else()
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Here is the description of the parameters (sorted by importance).
* `-r/--resolution`: sampling resolution for Hausdorff distance calculation (1e3~1e4), default = 2000.
* `--pca`: flag to enable PCA pre-processing, default = false.
* `-k`: value of $k$ for R_v calculation, default = 0.3.
* `-am/--approximate-mode`: approximation shape type ("ch" for convex hulls, "box" for cubes), default = "ch".
* `--seed`: random seed used for sampling, default = random().

An example of changing the parameters:
Expand Down
4 changes: 4 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ int main(int argc, char *argv[])
{
params.preprocess_mode = argv[i + 1];
}
if (strcmp(argv[i], "-am") == 0 || strcmp(argv[i], "--approximate-mode") == 0)
{
params.apx_mode = argv[i + 1];
}
if (strcmp(argv[i], "-pr") == 0 || strcmp(argv[i], "--prep-resolution") == 0)
{
sscanf(argv[i + 1], "%d", &params.prep_resolution);
Expand Down
18 changes: 14 additions & 4 deletions public/coacd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::vector<Mesh> CoACD(Mesh const &input, double threshold,
int max_convex_hull, std::string preprocess_mode,
int prep_resolution, int sample_resolution,
int mcts_nodes, int mcts_iteration, int mcts_max_depth,
bool pca, bool merge, unsigned int seed) {
bool pca, bool merge, std::string apx_mode, unsigned int seed) {

logger::info("threshold {}", threshold);
logger::info("max # convex hull {}", max_convex_hull);
Expand All @@ -27,6 +27,7 @@ std::vector<Mesh> CoACD(Mesh const &input, double threshold,
logger::info("mcts nodes {}", mcts_nodes);
logger::info("mcts iterations {}", mcts_iteration);
logger::info("merge {}", merge);
logger::info("approximate mode {}", apx_mode);
logger::info("seed {}", seed);

if (threshold < 0.01) {
Expand Down Expand Up @@ -56,6 +57,7 @@ std::vector<Mesh> CoACD(Mesh const &input, double threshold,
params.mcts_max_depth = mcts_max_depth;
params.pca = pca;
params.merge = merge;
params.apx_mode = apx_mode;
params.seed = seed;

Model m;
Expand Down Expand Up @@ -127,7 +129,7 @@ CoACD_MeshArray CoACD_run(CoACD_Mesh const &input, double threshold,
int prep_resolution, int sample_resolution,
int mcts_nodes, int mcts_iteration,
int mcts_max_depth, bool pca, bool merge,
unsigned int seed) {
int apx_mode, unsigned int seed) {
coacd::Mesh mesh;
for (uint64_t i = 0; i < input.vertices_count; ++i) {
mesh.vertices.push_back({input.vertices_ptr[3 * i],
Expand All @@ -140,7 +142,7 @@ CoACD_MeshArray CoACD_run(CoACD_Mesh const &input, double threshold,
input.triangles_ptr[3 * i + 2]});
}

std::string pm;
std::string pm, apx;
if (preprocess_mode == preprocess_on) {
pm = "on";
} else if (preprocess_mode == preprocess_off) {
Expand All @@ -149,9 +151,17 @@ CoACD_MeshArray CoACD_run(CoACD_Mesh const &input, double threshold,
pm = "auto";
}

if (apx_mode == apx_ch) {
apx = "ch";
} else if (apx_mode == apx_box) {
apx = "box";
} else {
throw std::runtime_error("invalid approximation mode " + std::to_string(apx_mode));
}

auto meshes = coacd::CoACD(mesh, threshold, max_convex_hull, pm,
prep_resolution, sample_resolution, mcts_nodes,
mcts_iteration, mcts_max_depth, pca, merge, seed);
mcts_iteration, mcts_max_depth, pca, merge, apx, seed);

CoACD_MeshArray arr;
arr.meshes_ptr = new CoACD_Mesh[meshes.size()];
Expand Down
7 changes: 5 additions & 2 deletions public/coacd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ std::vector<Mesh> CoACD(Mesh const &input, double threshold = 0.05,
int prep_resolution = 50, int sample_resolution = 2000,
int mcts_nodes = 20, int mcts_iteration = 150,
int mcts_max_depth = 3, bool pca = false,
bool merge = true, unsigned int seed = 0);
bool merge = true, std::string apx_mode = "ch", unsigned int seed = 0);
void set_log_level(std::string_view level);

} // namespace coacd
Expand All @@ -47,12 +47,15 @@ constexpr int preprocess_auto = 0;
constexpr int preprocess_on = 1;
constexpr int preprocess_off = 2;

constexpr int apx_ch = 0;
constexpr int apx_box = 1;

CoACD_MeshArray COACD_API CoACD_run(CoACD_Mesh const &input, double threshold,
int max_convex_hull, int preprocess_mode,
int prep_resolution, int sample_resolution,
int mcts_nodes, int mcts_iteration,
int mcts_max_depth, bool pca, bool merge,
unsigned int seed);
int apx_mode, unsigned int seed);

void COACD_API CoACD_setLogLevel(char const *level);
}
8 changes: 8 additions & 0 deletions python/package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CoACD_MeshArray(ctypes.Structure):
c_int,
c_bool,
c_bool,
c_int,
c_uint,
]
_lib.CoACD_run.restype = CoACD_MeshArray
Expand Down Expand Up @@ -84,6 +85,7 @@ def run_coacd(
mcts_max_depth: int = 3,
pca: int = False,
merge: bool = True,
apx_mode: str = "ch",
seed: int = 0,
):
vertices = np.ascontiguousarray(mesh.vertices, dtype=np.double)
Expand All @@ -110,6 +112,11 @@ def run_coacd(
else:
pm = 0

if apx_mode == "ch":
apx = 0
elif apx_mode == "box":
apx = 1

mesh_array = _lib.CoACD_run(
mesh,
threshold,
Expand All @@ -122,6 +129,7 @@ def run_coacd(
mcts_max_depth,
pca,
merge,
apx,
seed,
)

Expand Down
8 changes: 8 additions & 0 deletions python/package/bin/coacd
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ if __name__ == "__main__":
action="store_true",
help="Use PCA to align input mesh. Suitable for non-axis-aligned mesh.",
)
parser.add_argument(
"-am",
"--apx-mode",
type=str,
default="ch",
help="Approximation shape mode (ch/box).",
)
parser.add_argument("--seed", type=int, default=0, help="Random seed.")

args = parser.parse_args()
Expand Down Expand Up @@ -125,6 +132,7 @@ if __name__ == "__main__":
mcts_max_depth=args.mcts_max_depth,
pca=args.pca,
merge=not args.no_merge,
apx_mode=args.apx_mode,
seed=args.seed,
)
mesh_parts = []
Expand Down
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace coacd
bool merge;
int max_convex_hull;
double dmc_thres;
string apx_mode;

/////////////// MCTS Config ///////////////
int mcts_iteration;
Expand All @@ -55,6 +56,7 @@ namespace coacd
pca = false;
merge = true;
dmc_thres = 0.55;
apx_mode = "ch";

mcts_iteration = 150;
mcts_max_depth = 3;
Expand Down
1 change: 1 addition & 0 deletions src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace coacd
logger::info("\tPCA (ON/OFF): {}", params.pca);
logger::info("\tk for Rv: {}", params.rv_k);
logger::info("\tHausdorff Sampling Resolution: {}", params.resolution);
logger::info("\tApproximation Mode (ch/box): {}", params.apx_mode);
logger::info("\tRandom Seed: {}", params.seed);
}

Expand Down
Loading

0 comments on commit eef37b5

Please sign in to comment.