Skip to content

Commit

Permalink
Remove obsolete trustedPolySetToManifold()
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel committed Mar 13, 2024
1 parent 29ab782 commit f9a1938
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 78 deletions.
42 changes: 13 additions & 29 deletions src/geometry/manifold/ManifoldGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,7 @@ std::shared_ptr<manifold::Manifold> binOp(const manifold::Manifold& lhs, const m
return std::make_shared<manifold::Manifold>(lhs.Boolean(rhs, opType));
}

ManifoldGeometry ManifoldGeometry::operator+(const ManifoldGeometry& other) const {
return {binOp(*this->manifold_, *other.manifold_, manifold::OpType::Add)};
}

void ManifoldGeometry::operator+=(ManifoldGeometry& other) {
manifold_ = binOp(*this->manifold_, *other.manifold_, manifold::OpType::Add);
}

ManifoldGeometry ManifoldGeometry::operator*(const ManifoldGeometry& other) const {
return {binOp(*this->manifold_, *other.manifold_, manifold::OpType::Intersect)};
}

void ManifoldGeometry::operator*=(ManifoldGeometry& other) {
manifold_ = binOp(*this->manifold_, *other.manifold_, manifold::OpType::Intersect);
}

ManifoldGeometry ManifoldGeometry::operator-(const ManifoldGeometry& other) const {
return {binOp(*this->manifold_, *other.manifold_, manifold::OpType::Subtract)};
}

void ManifoldGeometry::operator-=(ManifoldGeometry& other) {
manifold_ = binOp(*this->manifold_, *other.manifold_, manifold::OpType::Subtract);
}

std::shared_ptr<manifold::Manifold> minkowskiOp(const ManifoldGeometry& lhs, const ManifoldGeometry& rhs) {
std::shared_ptr<ManifoldGeometry> minkowskiOp(const ManifoldGeometry& lhs, const ManifoldGeometry& rhs) {
// FIXME: How to deal with operation not supported?
#ifdef ENABLE_CGAL
auto lhs_nef = std::shared_ptr<CGAL_Nef_polyhedron>(CGALUtils::createNefPolyhedronFromPolySet(*lhs.toPolySet()));
Expand All @@ -202,17 +178,25 @@ std::shared_ptr<manifold::Manifold> minkowskiOp(const ManifoldGeometry& lhs, con
auto ps = PolySetUtils::getGeometryAsPolySet(lhs_nef);
if (!ps) return {};
else {
return ManifoldUtils::trustedPolySetToManifold(*ps);
return ManifoldUtils::createManifoldFromPolySet(*ps);
}
#endif
}

void ManifoldGeometry::minkowski(ManifoldGeometry& other) {
manifold_ = minkowskiOp(*this, other);
ManifoldGeometry ManifoldGeometry::operator+(const ManifoldGeometry& other) const {
return {binOp(*this->manifold_, *other.manifold_, manifold::OpType::Add)};
}

ManifoldGeometry ManifoldGeometry::operator*(const ManifoldGeometry& other) const {
return {binOp(*this->manifold_, *other.manifold_, manifold::OpType::Intersect)};
}

ManifoldGeometry ManifoldGeometry::operator-(const ManifoldGeometry& other) const {
return {binOp(*this->manifold_, *other.manifold_, manifold::OpType::Subtract)};
}

ManifoldGeometry ManifoldGeometry::minkowski(const ManifoldGeometry& other) const {
return {minkowskiOp(*this, other)};
return {*minkowskiOp(*this, other)};
}

void ManifoldGeometry::transform(const Transform3d& mat) {
Expand Down
9 changes: 0 additions & 9 deletions src/geometry/manifold/ManifoldGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ class ManifoldGeometry : public Geometry
template <class Polyhedron>
[[nodiscard]] std::shared_ptr<Polyhedron> toPolyhedron() const;

/*! In-place union. */
void operator+=(ManifoldGeometry& other);
/*! In-place intersection. */
void operator*=(ManifoldGeometry& other);
/*! In-place difference. */
void operator-=(ManifoldGeometry& other);
/*! In-place minkowksi operation. */
void minkowski(ManifoldGeometry& other);

/*! union. */
ManifoldGeometry operator+(const ManifoldGeometry& other) const;
/*! intersection. */
Expand Down
42 changes: 5 additions & 37 deletions src/geometry/manifold/manifoldutils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,6 @@ const char* statusToString(Error status) {
}
}

std::shared_ptr<manifold::Manifold> trustedPolySetToManifold(const PolySet& ps) {
manifold::Mesh mesh;
std::unique_ptr<PolySet> buffer;
if (!ps.isTriangular())
buffer = PolySetUtils::tessellate_faces(ps);
const PolySet& triangulated = ps.isTriangular() ? ps : *buffer;

auto numfaces = triangulated.indices.size();
const auto &vertices = triangulated.vertices;
const auto &indices = triangulated.indices;

mesh.vertPos.resize(vertices.size());
mesh.triVerts.resize(numfaces);
for (size_t i = 0, n = vertices.size(); i < n; i++) {
const auto &v = vertices[i];
mesh.vertPos[i] = glm::vec3((float) v.x(), (float) v.y(), (float) v.z());
}
const auto vertexCount = mesh.vertPos.size();
// assert(indices.size() == numfaces * 4);
for (size_t i = 0; i < numfaces; i++) {
unsigned int i0 = indices[i][0];
unsigned int i1 = indices[i][1];
unsigned int i2 = indices[i][2];
assert(i0 >= 0 && i0 < vertexCount &&
i1 >= 0 && i1 < vertexCount &&
i2 >= 0 && i2 < vertexCount);
assert(i0 != i1 && i0 != i2 && i1 != i2);
mesh.triVerts[i] = {i0, i1, i2};
}
return std::make_shared<manifold::Manifold>(std::move(mesh));
}

template <class TriangleMesh>
std::shared_ptr<ManifoldGeometry> createManifoldFromSurfaceMesh(const TriangleMesh& tm)
{
Expand Down Expand Up @@ -106,7 +74,7 @@ template std::shared_ptr<ManifoldGeometry> createManifoldFromSurfaceMesh(const C
template std::shared_ptr<ManifoldGeometry> createManifoldFromSurfaceMesh(const CGAL_DoubleMesh &tm);
#endif

std::unique_ptr<const manifold::Manifold> createManifoldFromTriangularPolySet(const PolySet& ps)
std::shared_ptr<ManifoldGeometry> createManifoldFromTriangularPolySet(const PolySet& ps)
{
assert(ps.isTriangular());

Expand All @@ -123,7 +91,7 @@ std::unique_ptr<const manifold::Manifold> createManifoldFromTriangularPolySet(co
mesh.triVerts.emplace_back(face[0], face[1], face[2]);
}

return std::make_unique<manifold::Manifold>(std::move(mesh));
return std::make_shared<ManifoldGeometry>(std::make_shared<const manifold::Manifold>(std::move(mesh)));
}

std::shared_ptr<ManifoldGeometry> createManifoldFromPolySet(const PolySet& ps)
Expand All @@ -140,14 +108,14 @@ std::shared_ptr<ManifoldGeometry> createManifoldFromPolySet(const PolySet& ps)
const PolySet triangle_set = ps.isTriangular() ? ps : *triangulated;

auto mani = createManifoldFromTriangularPolySet(triangle_set);
if (mani->Status() == Error::NoError) {
return std::make_shared<ManifoldGeometry>(std::shared_ptr<const manifold::Manifold>(std::move(mani)));
if (mani->getManifold().Status() == Error::NoError) {
return mani;
}

// FIXME: Should we suppress this warning, as it may not be very actionable?
LOG(message_group::Warning,"PolySet -> Manifold conversion failed: %1$s\n"
"Trying to repair and reconstruct mesh..",
ManifoldUtils::statusToString(mani->Status()));
ManifoldUtils::statusToString(mani->getManifold().Status()));

// 2. If the PolySet couldn't be converted into a Manifold object, let's try to repair it.
// We currently have to utilize some CGAL functions to do this.
Expand Down
3 changes: 0 additions & 3 deletions src/geometry/manifold/manifoldutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ namespace ManifoldUtils {

const char* statusToString(manifold::Manifold::Error status);

/*! If the PolySet isn't trusted, use createManifoldFromPolySet which will triangulate and reorient it. */
std::shared_ptr<manifold::Manifold> trustedPolySetToManifold(const PolySet& ps);

std::shared_ptr<ManifoldGeometry> createManifoldFromPolySet(const PolySet& ps);
std::shared_ptr<const ManifoldGeometry> createManifoldFromGeometry(const std::shared_ptr<const Geometry>& geom);

Expand Down

0 comments on commit f9a1938

Please sign in to comment.