Trimming & cutting from python
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <Base/ViewProj.h>
|
||||
|
||||
#include "Core/Builder.h"
|
||||
#include "Core/MeshKernel.h"
|
||||
@@ -46,6 +47,8 @@
|
||||
#include "Core/Degeneration.h"
|
||||
#include "Core/Segmentation.h"
|
||||
#include "Core/SetOperations.h"
|
||||
#include "Core/Triangulation.h"
|
||||
#include "Core/Trim.h"
|
||||
#include "Core/Visitor.h"
|
||||
|
||||
#include "Mesh.h"
|
||||
@@ -812,6 +815,80 @@ void MeshObject::crossSections(const std::vector<MeshObject::TPlane>& planes, st
|
||||
}
|
||||
}
|
||||
|
||||
void MeshObject::cut(const std::vector<Base::Vector3f>& polygon, MeshObject::CutType type)
|
||||
{
|
||||
MeshCore::FlatTriangulator tria;
|
||||
tria.SetPolygon(polygon);
|
||||
// this gives us the inverse matrix
|
||||
Base::Matrix4D inv = tria.GetTransformToFitPlane();
|
||||
// compute the matrix for the coordinate transformation
|
||||
Base::Matrix4D mat = inv;
|
||||
mat.inverseOrthogonal();
|
||||
|
||||
std::vector<Base::Vector3f> poly = tria.ProjectToFitPlane();
|
||||
|
||||
Base::ViewProjMatrix proj(mat);
|
||||
Base::Polygon2D polygon2d;
|
||||
for (std::vector<Base::Vector3f>::const_iterator it = poly.begin(); it != poly.end(); ++it)
|
||||
polygon2d.Add(Base::Vector2D(it->x, it->y));
|
||||
|
||||
MeshCore::MeshAlgorithm meshAlg(this->_kernel);
|
||||
std::vector<unsigned long> check;
|
||||
|
||||
bool inner;
|
||||
switch (type) {
|
||||
case INNER:
|
||||
inner = true;
|
||||
break;
|
||||
case OUTER:
|
||||
inner = false;
|
||||
break;
|
||||
}
|
||||
|
||||
MeshCore::MeshFacetGrid meshGrid(this->_kernel);
|
||||
meshAlg.CheckFacets(meshGrid, &proj, polygon2d, inner, check);
|
||||
if (!check.empty())
|
||||
this->deleteFacets(check);
|
||||
}
|
||||
|
||||
void MeshObject::trim(const std::vector<Base::Vector3f>& polygon, MeshObject::CutType type)
|
||||
{
|
||||
MeshCore::FlatTriangulator tria;
|
||||
tria.SetPolygon(polygon);
|
||||
// this gives us the inverse matrix
|
||||
Base::Matrix4D inv = tria.GetTransformToFitPlane();
|
||||
// compute the matrix for the coordinate transformation
|
||||
Base::Matrix4D mat = inv;
|
||||
mat.inverseOrthogonal();
|
||||
|
||||
std::vector<Base::Vector3f> poly = tria.ProjectToFitPlane();
|
||||
|
||||
Base::ViewProjMatrix proj(mat);
|
||||
Base::Polygon2D polygon2d;
|
||||
for (std::vector<Base::Vector3f>::const_iterator it = poly.begin(); it != poly.end(); ++it)
|
||||
polygon2d.Add(Base::Vector2D(it->x, it->y));
|
||||
MeshCore::MeshTrimming trim(this->_kernel, &proj, polygon2d);
|
||||
std::vector<unsigned long> check;
|
||||
std::vector<MeshCore::MeshGeomFacet> triangle;
|
||||
|
||||
switch (type) {
|
||||
case INNER:
|
||||
trim.SetInnerOrOuter(MeshCore::MeshTrimming::INNER);
|
||||
break;
|
||||
case OUTER:
|
||||
trim.SetInnerOrOuter(MeshCore::MeshTrimming::OUTER);
|
||||
break;
|
||||
}
|
||||
|
||||
MeshCore::MeshFacetGrid meshGrid(this->_kernel);
|
||||
trim.CheckFacets(meshGrid, check);
|
||||
trim.TrimFacets(check, triangle);
|
||||
if (!check.empty())
|
||||
this->deleteFacets(check);
|
||||
if (!triangle.empty())
|
||||
this->_kernel.AddFacets(triangle);
|
||||
}
|
||||
|
||||
MeshObject* MeshObject::unite(const MeshObject& mesh) const
|
||||
{
|
||||
MeshCore::MeshKernel result;
|
||||
@@ -1423,7 +1500,7 @@ MeshObject* MeshObject::meshFromSegment(const std::vector<unsigned long>& indice
|
||||
return new MeshObject(kernel, _Mtrx);
|
||||
}
|
||||
|
||||
std::vector<Segment> MeshObject::getSegmentsFromType(MeshObject::Type type, const Segment& aSegment,
|
||||
std::vector<Segment> MeshObject::getSegmentsFromType(MeshObject::GeometryType type, const Segment& aSegment,
|
||||
float dev, unsigned long minFacets) const
|
||||
{
|
||||
std::vector<Segment> segm;
|
||||
|
||||
Reference in New Issue
Block a user