Mesh: refactor MeshPy::getSelfIntersections

This commit is contained in:
wmayer
2022-08-04 10:34:49 +02:00
parent 3db79c907c
commit 9b8cf02aaf
3 changed files with 41 additions and 10 deletions

View File

@@ -1436,6 +1436,32 @@ bool MeshObject::hasSelfIntersections() const
return !cMeshEval.Evaluate();
}
MeshObject::TFacePairs MeshObject::getSelfIntersections() const
{
MeshCore::MeshEvalSelfIntersection eval(getKernel());
MeshObject::TFacePairs pairs;
eval.GetIntersections(pairs);
return pairs;
}
std::vector<Base::Line3d> MeshObject::getSelfIntersections(const MeshObject::TFacePairs& facets) const
{
MeshCore::MeshEvalSelfIntersection eval(getKernel());
using Section = std::pair<Base::Vector3f, Base::Vector3f>;
std::vector<Section> selfPoints;
eval.GetIntersections(facets, selfPoints);
std::vector<Base::Line3d> lines;
lines.reserve(selfPoints.size());
Base::Matrix4D mat(getTransform());
std::transform(selfPoints.begin(), selfPoints.end(), std::back_inserter(lines), [&mat](const Section& l){
return Base::Line3d(mat * Base::convertTo<Base::Vector3d>(l.first),
mat * Base::convertTo<Base::Vector3d>(l.second));
});
return lines;
}
void MeshObject::removeSelfIntersections()
{
std::vector<std::pair<FacetIndex, FacetIndex> > selfIntersections;

View File

@@ -31,7 +31,7 @@
#include <map>
#include <Base/Matrix.h>
#include <Base/Vector3D.h>
#include <Base/Tools3D.h>
#include <App/PropertyStandard.h>
#include <App/PropertyGeo.h>
@@ -88,9 +88,12 @@ public:
enum GeometryType {PLANE, CYLINDER, SPHERE};
enum CutType {INNER, OUTER};
using TFacePair = std::pair<FacetIndex, FacetIndex>;
using TFacePairs = std::vector<TFacePair>;
// typedef needed for cross-section
typedef std::pair<Base::Vector3f, Base::Vector3f> TPlane;
typedef std::list<std::vector<Base::Vector3f> > TPolylines;
using TPlane = std::pair<Base::Vector3f, Base::Vector3f>;
using TPolylines = std::list<std::vector<Base::Vector3f>>;
MeshObject();
explicit MeshObject(const MeshCore::MeshKernel& Kernel);
@@ -308,6 +311,8 @@ public:
void removeNonManifolds();
void removeNonManifoldPoints();
bool hasSelfIntersections() const;
TFacePairs getSelfIntersections() const;
std::vector<Base::Line3d> getSelfIntersections(const TFacePairs&) const;
void removeSelfIntersections();
void removeSelfIntersections(const std::vector<FacetIndex>&);
void removeFoldsOnSurface();

View File

@@ -1043,19 +1043,19 @@ PyObject* MeshPy::getSelfIntersections(PyObject *args)
return nullptr;
std::vector<std::pair<FacetIndex, FacetIndex> > selfIndices;
std::vector<std::pair<Base::Vector3f, Base::Vector3f> > selfPoints;
MeshCore::MeshEvalSelfIntersection eval(getMeshObjectPtr()->getKernel());
eval.GetIntersections(selfIndices);
eval.GetIntersections(selfIndices, selfPoints);
std::vector<Base::Line3d> selfLines;
selfIndices = getMeshObjectPtr()->getSelfIntersections();
selfLines = getMeshObjectPtr()->getSelfIntersections(selfIndices);
Py::Tuple tuple(selfIndices.size());
if (selfIndices.size() == selfPoints.size()) {
if (selfIndices.size() == selfLines.size()) {
for (std::size_t i=0; i<selfIndices.size(); i++) {
Py::Tuple item(4);
item.setItem(0, Py::Long(selfIndices[i].first));
item.setItem(1, Py::Long(selfIndices[i].second));
item.setItem(2, Py::Vector(selfPoints[i].first));
item.setItem(3, Py::Vector(selfPoints[i].second));
item.setItem(2, Py::Vector(selfLines[i].p1));
item.setItem(3, Py::Vector(selfLines[i].p2));
tuple.setItem(i, item);
}
}