Skip to content

Commit

Permalink
update thin obj pre-process
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahWeiii committed Nov 10, 2022
1 parent 9055223 commit 8943a20
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 59 deletions.
62 changes: 8 additions & 54 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ project(CoACD)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pthread")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3") # enable assert
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG}")

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-int-in-bool-context -Wsign-compare")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-int-in-bool-context -Wsign-compare")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address")
endif()

Expand All @@ -26,56 +25,11 @@ include_directories(3rd/eigen/)
include_directories(3rd/libigl/include)
include_directories(3rd/cdt/CDT)

set(
main_SRC
src/hausdorff.h
src/shape.cpp
src/shape.h
src/sobol.cpp
src/sobol.h
src/clip.cpp
src/clip.h
src/cost.cpp
src/cost.h
src/io.cpp
src/io.h
src/quickhull/QuickHull.cpp
src/quickhull/QuickHull.hpp
src/btConvexHull/btScalar.h
src/btConvexHull/btVector3.h
src/btConvexHull/btMinMax.h
src/btConvexHull/btAlignedObjectArray.h
src/btConvexHull/btAlignedAllocator.cpp
src/btConvexHull/btAlignedAllocator.h
src/btConvexHull/btConvexHullComputer.cpp
src/btConvexHull/btConvexHullComputer.h
src/manifold/BVH.cpp
src/manifold/BVH.h
src/manifold/Intersection.cpp
src/manifold/Intersection.h
src/manifold/Octree.h
src/manifold/model.cpp
src/manifold/model.h
src/manifold/Manifold.h
src/manifold/GridIndex_p.h
src/manifold/IO_p.cc
src/manifold/IO_p.h
src/manifold/Manifold_p.cc
src/manifold/Manifold_p.h
src/manifold/Octree_p.cc
src/manifold/Octree_p.h
src/manifold/types_p.h
file(GLOB_RECURSE MAIN_SRC "src/*.h" "src/*.cc" "src/*.hpp" "src/*.cpp")
add_library(coacd SHARED
${MAIN_SRC}
src/manifold/ManifoldPlus.h
src/model_obj.cpp
src/model_obj.h
src/config.h
src/mcts.h
src/process.cpp
src/process.h
src/main.cpp
)

add_executable(
main
${main_SRC}
)
add_executable(main src/main.cpp)
target_link_libraries(main coacd)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bash run_example.sh

Copyright (c) 2022 Xinyue Wei, Minghua Liu

Please note our code utilizes [Triangle](https://www.cs.cmu.edu/~quake/triangle.html) and [ManifoldPlus](https://github.com/hjwdzh/ManifoldPlus). Although Triangle is freely available, it is copyrighted by the author and may not be sold or included in commercial products without a license. ManifoldPlus is distributed for free for non-commercial use only.
Please note our code utilizes [ManifoldPlus](https://github.com/hjwdzh/ManifoldPlus), which is distributed for free for non-commercial use only. But ManifoldPlus is only used for pre-processing thin objects which cannot be well solved by Manifold. If you don't have non-manifold thin objects, you can **diable** this library by `--no-manifold-plus` or `-nmp`.

## Citation

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 @@ class Params
int prep_depth;
bool pca;
bool merge;
bool mani_plus;

/////////////// MCTS Config ///////////////
int mcts_iteration;
Expand All @@ -56,6 +57,7 @@ class Params
prep_depth = 8;
pca = false;
merge = true;
mani_plus = true;

mcts_iteration = 150;
mcts_max_depth = 3;
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ int main(int argc, char *argv[])
{
params.merge = false;
}
if (strcmp(argv[i], "-nmp") == 0 || strcmp(argv[i], "--no-manifold-plus") == 0)
{
params.mani_plus = false;
}
if (strcmp(argv[i], "--pca") == 0)
{
params.pca = true;
Expand Down
66 changes: 63 additions & 3 deletions src/model_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,70 @@ Model::Model()
bool Model::CheckThin()
{
Normalize();
if (fabs(bbox[0] - bbox[1]) < 0.01 || fabs(bbox[2] - bbox[3]) < 0.01 || fabs(bbox[4] - bbox[5]) < 0.01)
int idx0 = 0;
int idx1;
int idx2;
bool flag = 0;

for (int i = 1; i < (int)points.size(); i++)
{
double dist = sqrt(pow(points[idx0][0] - points[i][0], 2) + pow(points[idx0][1] - points[i][1], 2) + pow(points[idx0][2] - points[i][2], 2));
if (dist > 0.01)
{
flag = 1;
idx1 = i;
break;
}
}
if (!flag)
return true;
else
return false;
flag = 0;

for (int i = 2; i < (int)points.size(); i++)
{
if (i == idx1)
continue;
vec3d p0 = points[idx0];
vec3d p1 = points[idx1];
vec3d p2 = points[i];
vec3d AB, BC;
AB[0] = p1[0] - p0[0];
AB[1] = p1[1] - p0[1];
AB[2] = p1[2] - p0[2];
BC[0] = p2[0] - p1[0];
BC[1] = p2[1] - p1[1];
BC[2] = p2[2] - p1[2];

double dot_product = AB[0] * BC[0] + AB[1] * BC[1] + AB[2] * BC[2];
double res = dot_product / (sqrt(pow(AB[0], 2) + pow(AB[1], 2) + pow(AB[2], 2)) * sqrt(pow(BC[0], 2) + pow(BC[1], 2) + pow(BC[2], 2)));
if (fabs(fabs(res) - 1) > 1e-6 && fabs(res) < INF) // AB not \\ BC, dot product != 1
{
flag = 1;
idx2 = i;
break;
}
}
if (!flag)
return true;

vec3d p0 = points[idx0], p1 = points[idx1], p2 = points[idx2];

Plane p;
double a = (p1[1] - p0[1]) * (p2[2] - p0[2]) - (p1[2] - p0[2]) * (p2[1] - p0[1]);
double b = (p1[2] - p0[2]) * (p2[0] - p0[0]) - (p1[0] - p0[0]) * (p2[2] - p0[2]);
double c = (p1[0] - p0[0]) * (p2[1] - p0[1]) - (p1[1] - p0[1]) * (p2[0] - p0[0]);
p.a = a / sqrt(pow(a, 2) + pow(b, 2) + pow(c, 2));
p.b = b / sqrt(pow(a, 2) + pow(b, 2) + pow(c, 2));
p.c = c / sqrt(pow(a, 2) + pow(b, 2) + pow(c, 2));
p.d = 0 - (p.a * p1[0] + p.b * p1[1] + p.c * p1[2]);

for (int i = 0; i < (int)points.size(); i++)
{
if (p.Side(points[i]) != 0)
return false;
}
return true;

}

vector<vec3d> Model::GetPoints(size_t resolution)
Expand Down
2 changes: 1 addition & 1 deletion src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void ManifoldPreprocess(Params &params, Model &m, ofstream &of)
tmp.LoadOBJ(params.input_model);
bool is_thin = tmp.CheckThin();

if (is_thin)
if (params.mani_plus && is_thin)
ManifoldPlus(of, params.input_model, m, params.prep_depth);
else
Manifold(of, params.input_model, m, params.prep_resolution);
Expand Down

0 comments on commit 8943a20

Please sign in to comment.