Mesh: expose trimByPlane to Python

This commit is contained in:
wmayer
2021-10-15 23:07:59 +02:00
parent 346ff3815d
commit 837de28e9e
5 changed files with 32 additions and 7 deletions

View File

@@ -1121,7 +1121,7 @@ void MeshObject::trim(const Base::Polygon2d& polygon2d,
this->_kernel.AddFacets(triangle);
}
void MeshObject::trim(const Base::Vector3f& base, const Base::Vector3f& normal)
void MeshObject::trimByPlane(const Base::Vector3f& base, const Base::Vector3f& normal)
{
MeshCore::MeshTrimByPlane trim(this->_kernel);
std::vector<FacetIndex> trimFacets, removeFacets;

View File

@@ -240,7 +240,7 @@ public:
float fMinEps = 1.0e-2f, bool bConnectPolygons = false) const;
void cut(const Base::Polygon2d& polygon, const Base::ViewProjMethod& proj, CutType);
void trim(const Base::Polygon2d& polygon, const Base::ViewProjMethod& proj, CutType);
void trim(const Base::Vector3f& base, const Base::Vector3f& normal);
void trimByPlane(const Base::Vector3f& base, const Base::Vector3f& normal);
//@}
/** @name Selection */

View File

@@ -447,7 +447,16 @@ The argument int is the mode: 0=inner, 1=outer
</UserDocu>
</Documentation>
</Methode>
<!-- The Const here is just a hack -->
<Methode Name="trimByPlane">
<Documentation>
<UserDocu>Trims the mesh with a given plane
trimByPlane(Vector, Vector) -> None
The plane is defined by a base and normal vector. Depending on the
direction of the normal the part above or below will be kept.
</UserDocu>
</Documentation>
</Methode>
<!-- The Const here is just a hack -->
<Methode Name="harmonizeNormals" Const="true">
<Documentation>
<UserDocu>Adjust wrong oriented facets</UserDocu>

View File

@@ -1744,6 +1744,22 @@ PyObject* MeshPy::trim(PyObject *args)
Py_Return;
}
PyObject* MeshPy::trimByPlane(PyObject *args)
{
PyObject *base, *norm;
if (!PyArg_ParseTuple(args, "O!O!", &Base::VectorPy::Type, &base,
&Base::VectorPy::Type, &norm))
return nullptr;
Base::Vector3d pnt = Py::Vector(base, false).toVector();
Base::Vector3d dir = Py::Vector(norm, false).toVector();
getMeshObjectPtr()->trimByPlane(Base::convertTo<Base::Vector3f>(pnt),
Base::convertTo<Base::Vector3f>(dir));
Py_Return;
}
PyObject* MeshPy::smooth(PyObject *args, PyObject *kwds)
{
char* method = "Laplace";

View File

@@ -146,19 +146,19 @@ void CmdMeshPartTrimByPlane::activated(int)
Base::Vector3f plnNormal = Base::convertTo<Base::Vector3f>(normal);
if (role == Gui::SelectionRole::Inner) {
mesh->trim(plnBase, plnNormal);
mesh->trimByPlane(plnBase, plnNormal);
static_cast<Mesh::Feature*>(*it)->Mesh.finishEditing();
}
else if (role == Gui::SelectionRole::Outer) {
mesh->trim(plnBase, -plnNormal);
mesh->trimByPlane(plnBase, -plnNormal);
static_cast<Mesh::Feature*>(*it)->Mesh.finishEditing();
}
else if (role == Gui::SelectionRole::Split) {
Mesh::MeshObject copy(*mesh);
mesh->trim(plnBase, plnNormal);
mesh->trimByPlane(plnBase, plnNormal);
static_cast<Mesh::Feature*>(*it)->Mesh.finishEditing();
copy.trim(plnBase, -plnNormal);
copy.trimByPlane(plnBase, -plnNormal);
App::Document* doc = (*it)->getDocument();
Mesh::Feature* fea = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature"));
fea->Label.setValue((*it)->Label.getValue());