Skip to content

Commit

Permalink
Merge pull request #16 from fbxiang/main
Browse files Browse the repository at this point in the history
update python packaging
  • Loading branch information
SarahWeiii committed Jun 15, 2023
2 parents 87ffa46 + eee7a62 commit 6f18727
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 33 deletions.
14 changes: 2 additions & 12 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

PACKAGE_VERSION="0.0.3"
PACKAGE_VERSION="0.0.5"
PY_VERSION=311
BIN=/opt/python/cp${PY_VERSION}-cp${PY_VERSION}/bin/python
COMMAND="${BIN} setup.py bdist_wheel"
Expand All @@ -12,15 +12,5 @@ eval ${COMMAND}
WHEEL_NAME="./dist/coacd-${PACKAGE_VERSION}-cp${PY_VERSION}-cp${PY_VERSION}-linux_x86_64.whl"
auditwheel repair ${WHEEL_NAME}

FIXED_WHEEL_NAME="coacd-${PACKAGE_VERSION}-cp${PY_VERSION}-cp${PY_VERSION}-manylinux2014_x86_64.whl"
NEW_WHEEL_NAME="coacd-${PACKAGE_VERSION}-py3-none-manylinux2014_x86_64.whl"

cd wheelhouse
unzip ${FIXED_WHEEL_NAME}
WHEEL_INFO_FILE="coacd-${PACKAGE_VERSION}.dist-info/WHEEL"
echo "Wheel-Version: 1.0" > ${WHEEL_INFO_FILE}
echo "Generator: bdist_wheel (0.38.4)" >> ${WHEEL_INFO_FILE}
echo "Root-Is-Purelib: false" >> ${WHEEL_INFO_FILE}
echo "Tag: py3-none-manylinux2014_x86_64" >> ${WHEEL_INFO_FILE}
zip -r ${NEW_WHEEL_NAME} coacd coacd-${PACKAGE_VERSION}.data coacd-${PACKAGE_VERSION}.dist-info coacd.libs && \
rm -rf coacd coacd-${PACKAGE_VERSION}.data coacd-${PACKAGE_VERSION}.dist-info coacd.libs ${FIXED_WHEEL_NAME}
${BIN} -m wheel tags --python-tag=py3 --abi-tag=none coacd-0.0.5-cp311-cp311-manylinux2014_x86_64.whl
2 changes: 2 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ RUN echo "#!/opt/python/cp38-cp38/bin/python" > /usr/local/bin/auditwheel && \
echo "if __name__ == '__main__':" >> /usr/local/bin/auditwheel && \
echo " sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])" >> /usr/local/bin/auditwheel && \
echo " sys.exit(main())" >> /usr/local/bin/auditwheel

RUN /opt/python/cp311-cp311/bin/python -m pip install wheel --upgrade
29 changes: 23 additions & 6 deletions public/coacd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ void RecoverParts(vector<Model> &meshes, vector<double> bbox,
}

std::vector<Mesh> CoACD(Mesh const &input, double threshold,
int max_convex_hull, bool preprocess,
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) {

logger::info("threshold {}", threshold);
logger::info("max # convex hull {}", max_convex_hull);
logger::info("preprocess {}", preprocess);
logger::info("preprocess mode {}", preprocess_mode);
logger::info("preprocess resolution {}", prep_resolution);
logger::info("pca {}", pca);
logger::info("mcts max depth {}", mcts_max_depth);
Expand Down Expand Up @@ -48,7 +48,7 @@ std::vector<Mesh> CoACD(Mesh const &input, double threshold,
params.output_name = "";
params.threshold = threshold;
params.max_convex_hull = max_convex_hull;
params.preprocess = preprocess;
params.preprocess_mode = preprocess_mode;
params.prep_resolution = prep_resolution;
params.resolution = sample_resolution;
params.mcts_nodes = mcts_nodes;
Expand All @@ -63,9 +63,16 @@ std::vector<Mesh> CoACD(Mesh const &input, double threshold,
vector<double> bbox = m.Normalize();
array<array<double, 3>, 3> rot{
{{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}};
if (preprocess) {

if (params.preprocess_mode == std::string("auto")) {
bool is_manifold = IsManifold(m);
logger::info("Mesh Manifoldness: {}", is_manifold);
if (!is_manifold)
ManifoldPreprocess(params, m);
} else if (params.preprocess_mode == std::string("on")) {
ManifoldPreprocess(params, m);
}

if (pca) {
rot = m.PCA();
}
Expand Down Expand Up @@ -114,7 +121,7 @@ void CoACD_freeMeshArray(CoACD_MeshArray arr) {
}

CoACD_MeshArray CoACD_run(CoACD_Mesh const &input, double threshold,
int max_convex_hull, bool preprocess,
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,
Expand All @@ -130,7 +137,17 @@ CoACD_MeshArray CoACD_run(CoACD_Mesh const &input, double threshold,
input.triangles_ptr[3 * i + 1],
input.triangles_ptr[3 * i + 2]});
}
auto meshes = coacd::CoACD(mesh, threshold, max_convex_hull, preprocess,

std::string pm;
if (preprocess_mode == preprocess_on) {
pm = "on";
} else if (preprocess_mode == preprocess_off) {
pm = "off";
} else {
pm = "auto";
}

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

Expand Down
20 changes: 12 additions & 8 deletions public/coacd.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace coacd {

#if _WIN32
#define COACD_API __declspec(dllexport)
#define COACD_API __declspec(dllexport)
#else
#define COACD_API
#define COACD_API
#endif

struct Mesh {
Expand All @@ -21,7 +21,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 = 1234);
bool merge = true, unsigned int seed = 0);

void set_log_level(std::string_view level);

Expand All @@ -43,12 +43,16 @@ struct CoACD_MeshArray {

void COACD_API CoACD_freeMeshArray(CoACD_MeshArray arr);

constexpr int preprocess_auto = 0;
constexpr int preprocess_on = 1;
constexpr int preprocess_off = 2;

CoACD_MeshArray COACD_API CoACD_run(CoACD_Mesh const &input, double threshold,
int max_convex_hull, bool preprocess,
int prep_resolution, int sample_resolution,
int mcts_nodes, int mcts_iteration,
int mcts_max_depth, bool pca, bool merge,
unsigned int seed);
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);

void COACD_API CoACD_setLogLevel(char const *level);
}
15 changes: 11 additions & 4 deletions python/package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CoACD_MeshArray(ctypes.Structure):
POINTER(CoACD_Mesh),
c_double,
c_int,
c_bool,
c_int,
c_int,
c_int,
c_int,
Expand Down Expand Up @@ -76,15 +76,15 @@ def run_coacd(
mesh: Mesh,
threshold: float = 0.05,
max_convex_hull: int = -1,
preprocess: bool = True,
preprocess_mode: str = "auto",
preprocess_resolution: int = 30,
resolution: int = 2000,
mcts_nodes: int = 20,
mcts_iterations: int = 150,
mcts_max_depth: int = 3,
pca: int = False,
merge: bool = True,
seed: int = 1234,
seed: int = 0,
):
vertices = np.ascontiguousarray(mesh.vertices, dtype=np.double)
indices = np.ascontiguousarray(mesh.indices, dtype=np.int32)
Expand All @@ -103,11 +103,18 @@ def run_coacd(
)
mesh.triangles_count = indices.shape[0]

if preprocess_mode == "on":
pm = 1
elif preprocess_mode == "off":
pm = 2
else:
pm = 0

mesh_array = _lib.CoACD_run(
mesh,
threshold,
max_convex_hull,
preprocess,
pm,
preprocess_resolution,
resolution,
mcts_nodes,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def build_extension(self, ext):

setup(
name="coacd",
version="0.0.3",
version="0.0.5",
author_email="[email protected]",
keywords="collision convex decomposition",
description="Approximate Convex Decomposition for 3D Meshes with Collision-Aware Concavity and Tree Search",
Expand Down
4 changes: 2 additions & 2 deletions src/bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace coacd
return false;
if (node.isLeaf())
{
for (uint i = 0; i < (uint) node.numTri; i++)
for (int i = 0; i < node.numTri; i++)
{
IntersectVector3 v0, v1, v2, u0, u1, u2;
const vec3i t0 = triangleIdx;
Expand Down Expand Up @@ -227,4 +227,4 @@ namespace coacd
}
}
}
}
}

0 comments on commit 6f18727

Please sign in to comment.