11// Portions of this file are Copyright 2023 Google LLC, and licensed under GPL2+. See COPYING.
22#include " ManifoldGeometry.h"
33#include " Polygon2d.h"
4- #include " manifold.h"
4+ #include " manifold/cross_section.h"
5+ #include " manifold/manifold.h"
56#include " PolySet.h"
6- #include " Feature.h"
77#include " PolySetBuilder.h"
88#include " PolySetUtils.h"
99#include " manifoldutils.h"
@@ -23,20 +23,18 @@ Result vector_convert(V const& v) {
2323
2424}
2525
26- ManifoldGeometry::ManifoldGeometry () : manifold_(std::make_shared< const manifold::Manifold> ()) {}
26+ ManifoldGeometry::ManifoldGeometry () : manifold_(manifold::Manifold()) {}
2727
2828ManifoldGeometry::ManifoldGeometry (
29- const std::shared_ptr< const manifold::Manifold>& mani,
29+ manifold::Manifold mani,
3030 const std::set<uint32_t > & originalIDs,
3131 const std::map<uint32_t , Color4f> & originalIDToColor,
3232 const std::set<uint32_t > & subtractedIDs)
33- : manifold_(mani),
33+ : manifold_(std::move( mani) ),
3434 originalIDs_(originalIDs),
3535 originalIDToColor_(originalIDToColor),
3636 subtractedIDs_(subtractedIDs)
3737{
38- assert (manifold_);
39- if (!manifold_) clear ();
4038}
4139
4240std::unique_ptr<Geometry> ManifoldGeometry::copy () const
@@ -45,8 +43,7 @@ std::unique_ptr<Geometry> ManifoldGeometry::copy() const
4543}
4644
4745const manifold::Manifold& ManifoldGeometry::getManifold () const {
48- assert (manifold_);
49- return *manifold_;
46+ return manifold_;
5047}
5148
5249bool ManifoldGeometry::isEmpty () const {
@@ -66,11 +63,11 @@ bool ManifoldGeometry::isManifold() const {
6663}
6764
6865bool ManifoldGeometry::isValid () const {
69- return manifold_-> Status () == manifold::Manifold::Error::NoError;
66+ return manifold_. Status () == manifold::Manifold::Error::NoError;
7067}
7168
7269void ManifoldGeometry::clear () {
73- manifold_ = std::make_shared< manifold::Manifold> ();
70+ manifold_ = manifold::Manifold ();
7471}
7572
7673size_t ManifoldGeometry::memsize () const {
@@ -81,18 +78,18 @@ size_t ManifoldGeometry::memsize() const {
8178std::string ManifoldGeometry::dump () const {
8279 std::ostringstream out;
8380 auto &manifold = getManifold ();
84- auto mesh = manifold.GetMesh ();
81+ auto meshgl = manifold.GetMeshGL64 ();
8582 out << " Manifold:"
8683 << " \n status: " << ManifoldUtils::statusToString (manifold.Status ())
8784 << " \n genus: " << manifold.Genus ()
88- << " \n num vertices: " << mesh. vertPos . size ()
89- << " \n num polygons: " << mesh. triVerts . size ()
85+ << " \n num vertices: " << meshgl. NumVert ()
86+ << " \n num polygons: " << meshgl. NumTri ()
9087 << " \n polygons data:" ;
9188
92- for (const auto &tv : mesh. triVerts ) {
89+ for (size_t faceid = 0 ; faceid < meshgl. NumTri (); faceid++ ) {
9390 out << " \n polygon begin:" ;
9491 for (const int j : {0 , 1 , 2 }) {
95- Vector3d v = vector_convert<Vector3d>(mesh. vertPos [tv[j]] );
92+ auto v = vector_convert<Vector3d>(meshgl. GetVertPos (meshgl. GetTriVerts (faceid)[j]) );
9693 out << " \n vertex:" << v;
9794 }
9895 }
@@ -101,7 +98,7 @@ std::string ManifoldGeometry::dump() const {
10198}
10299
103100std::shared_ptr<PolySet> ManifoldGeometry::toPolySet () const {
104- manifold::MeshGL mesh = getManifold ().GetMeshGL ();
101+ manifold::MeshGL64 mesh = getManifold ().GetMeshGL64 ();
105102 auto ps = std::make_shared<PolySet>(3 );
106103 ps->setTriangular (true );
107104 ps->vertices .reserve (mesh.NumVert ());
@@ -194,18 +191,18 @@ class CGALPolyhedronBuilderFromManifold : public CGAL::Modifier_base<typename Po
194191public:
195192 using CGALPoint = typename CGAL_Polybuilder::Point_3;
196193
197- const manifold::Mesh& mesh ;
198- CGALPolyhedronBuilderFromManifold (const manifold::Mesh & mesh) : mesh (mesh) { }
194+ const manifold::MeshGL64& meshgl ;
195+ CGALPolyhedronBuilderFromManifold (const manifold::MeshGL64 & mesh) : meshgl (mesh) { }
199196
200197 void operator ()(HDS& hds) override {
201198 CGAL_Polybuilder B (hds, true );
202199
203- B.begin_surface (mesh.vertPos .size (), mesh.triVerts .size ());
204- for (const auto &v : mesh.vertPos ) {
205- B.add_vertex (CGALUtils::vector_convert<CGALPoint>(v));
206- }
200+ B.begin_surface (meshgl.NumVert (), meshgl.NumTri ());
201+ for (size_t vertid = 0 ; vertid < meshgl.NumVert (); vertid++)
202+ B.add_vertex (CGALUtils::vector_convert<CGALPoint>(meshgl.GetVertPos (vertid)));
207203
208- for (const auto &tv : mesh.triVerts ) {
204+ for (size_t faceid = 0 ; faceid < meshgl.NumTri (); faceid++) {
205+ const auto tv = meshgl.GetTriVerts (faceid);
209206 B.begin_facet ();
210207 for (const int j : {0 , 1 , 2 }) {
211208 B.add_vertex_to_facet (tv[j]);
@@ -221,8 +218,8 @@ std::shared_ptr<Polyhedron> ManifoldGeometry::toPolyhedron() const
221218{
222219 auto p = std::make_shared<Polyhedron>();
223220 try {
224- manifold::Mesh mesh = getManifold ().GetMesh ();
225- CGALPolyhedronBuilderFromManifold<Polyhedron> builder (mesh );
221+ auto meshgl = getManifold ().GetMeshGL64 ();
222+ CGALPolyhedronBuilderFromManifold<Polyhedron> builder (meshgl );
226223 p->delegate (builder);
227224 } catch (const CGAL::Assertion_exception& e) {
228225 LOG (message_group::Error, " CGAL error in CGALUtils::createPolyhedronFromPolySet: %1$s" , e.what ());
@@ -234,7 +231,7 @@ template std::shared_ptr<CGAL::Polyhedron_3<CGAL_Kernel3>> ManifoldGeometry::toP
234231#endif
235232
236233ManifoldGeometry ManifoldGeometry::binOp (const ManifoldGeometry& lhs, const ManifoldGeometry& rhs, manifold::OpType opType) const {
237- auto mani = std::make_shared<manifold::Manifold>( lhs.manifold_ -> Boolean (* rhs.manifold_ , opType) );
234+ auto mani = lhs.manifold_ . Boolean (rhs.manifold_ , opType);
238235 auto originalIDToColor = lhs.originalIDToColor_ ;
239236 auto subtractedIDs = lhs.subtractedIDs_ ;
240237
@@ -304,34 +301,44 @@ ManifoldGeometry ManifoldGeometry::minkowski(const ManifoldGeometry& other) cons
304301}
305302
306303Polygon2d ManifoldGeometry::slice () const {
307- auto cross_section = manifold_-> Slice ();
304+ auto cross_section = manifold::CrossSection ( manifold_. Slice () );
308305 return ManifoldUtils::polygonsToPolygon2d (cross_section.ToPolygons ());
309306}
310307
311308Polygon2d ManifoldGeometry::project () const {
312- auto cross_section = manifold_-> Project ();
309+ auto cross_section = manifold::CrossSection ( manifold_. Project () );
313310 return ManifoldUtils::polygonsToPolygon2d (cross_section.ToPolygons ());
314311}
315312
316313void ManifoldGeometry::transform (const Transform3d& mat) {
317- glm ::mat4x3 glMat (
314+ manifold ::mat4x3 glMat (
318315 // Column-major ordering
319316 mat (0 , 0 ), mat (1 , 0 ), mat (2 , 0 ),
320317 mat (0 , 1 ), mat (1 , 1 ), mat (2 , 1 ),
321318 mat (0 , 2 ), mat (1 , 2 ), mat (2 , 2 ),
322319 mat (0 , 3 ), mat (1 , 3 ), mat (2 , 3 )
323320 );
324- manifold_ = std::make_shared<manifold::Manifold>( getManifold ().Transform (glMat) );
321+ manifold_ = getManifold ().Transform (glMat);
325322}
326323
327324void ManifoldGeometry::setColor (const Color4f& c) {
328- if (manifold_->OriginalID () == -1 ) {
329- manifold_ = std::make_shared<manifold::Manifold>(manifold_->AsOriginal ());
325+ if (manifold_.OriginalID () == -1 ) {
326+ manifold_ = manifold_.AsOriginal ();
327+ }
328+ originalIDs_.clear ();
329+ originalIDs_.insert (manifold_.OriginalID ());
330+ originalIDToColor_.clear ();
331+ originalIDToColor_[manifold_.OriginalID ()] = c;
332+ subtractedIDs_.clear ();
333+ }
334+
335+ void ManifoldGeometry::toOriginal () {
336+ if (manifold_.OriginalID () == -1 ) {
337+ manifold_ = manifold_.AsOriginal ();
330338 }
331339 originalIDs_.clear ();
332- originalIDs_.insert (manifold_-> OriginalID ());
340+ originalIDs_.insert (manifold_. OriginalID ());
333341 originalIDToColor_.clear ();
334- originalIDToColor_[manifold_->OriginalID ()] = c;
335342 subtractedIDs_.clear ();
336343}
337344
@@ -349,7 +356,7 @@ void ManifoldGeometry::resize(const Vector3d& newsize, const Eigen::Matrix<bool,
349356}
350357
351358/* ! Iterate over all vertices' points until the function returns true (for done). */
352- void ManifoldGeometry::foreachVertexUntilTrue (const std::function<bool (const glm ::vec3& pt)>& f) const {
359+ void ManifoldGeometry::foreachVertexUntilTrue (const std::function<bool (const manifold ::vec3& pt)>& f) const {
353360 auto mesh = getManifold ().GetMesh ();
354361 for (const auto &pt : mesh.vertPos ) {
355362 if (f (pt)) {
0 commit comments