add method to project points on mesh
This commit is contained in:
@@ -79,6 +79,11 @@ public:
|
||||
"projectShapeOnMesh(Shape, Mesh, Vector) -> list of polygons\n"
|
||||
"projectShapeOnMesh(list of polygons, Mesh, Vector) -> list of polygons\n"
|
||||
);
|
||||
add_varargs_method("projectPointsOnMesh",&Module::projectPointsOnMesh,
|
||||
"Projects points onto a mesh with a given direction\n"
|
||||
"and tolerance."
|
||||
"projectPointsOnMesh(list of points, Mesh, Vector, [float]) -> list of points\n"
|
||||
);
|
||||
add_varargs_method("wireFromSegment",&Module::wireFromSegment,
|
||||
"Create wire(s) from boundary of segment\n"
|
||||
);
|
||||
@@ -361,6 +366,47 @@ private:
|
||||
"Shape, Mesh, Vector or\n"
|
||||
"Polygons, Mesh, Vector\n");
|
||||
}
|
||||
Py::Object projectPointsOnMesh(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *seq, *m, *v;
|
||||
double precision = -1;
|
||||
if (PyArg_ParseTuple(args.ptr(), "OO!O!|d",
|
||||
&seq,
|
||||
&Mesh::MeshPy::Type, &m,
|
||||
&Base::VectorPy::Type, &v,
|
||||
&precision)) {
|
||||
std::vector<Base::Vector3f> pointsIn;
|
||||
Py::Sequence points(seq);
|
||||
pointsIn.reserve(points.size());
|
||||
|
||||
// collect list of input points
|
||||
for (Py::Sequence::iterator it = points.begin(); it != points.end(); ++it) {
|
||||
Py::Vector pnt(*it);
|
||||
pointsIn.push_back(Base::convertTo<Base::Vector3f>(pnt.toVector()));
|
||||
}
|
||||
|
||||
const Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
|
||||
Base::Vector3d* vec = static_cast<Base::VectorPy*>(v)->getVectorPtr();
|
||||
Base::Vector3f dir = Base::convertTo<Base::Vector3f>(*vec);
|
||||
|
||||
MeshCore::MeshKernel kernel(mesh->getKernel());
|
||||
kernel.Transform(mesh->getTransform());
|
||||
|
||||
MeshProjection proj(kernel);
|
||||
std::vector<Base::Vector3f> pointsOut;
|
||||
proj.projectOnMesh(pointsIn, dir, static_cast<float>(precision), pointsOut);
|
||||
|
||||
Py::List list;
|
||||
for (auto it : pointsOut) {
|
||||
Py::Vector v(it);
|
||||
list.append(v);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
throw Py::Exception();
|
||||
}
|
||||
Py::Object wireFromSegment(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *o, *m;
|
||||
|
||||
@@ -844,6 +844,36 @@ void MeshProjection::projectToMesh (const TopoDS_Shape &aShape, float fMaxDist,
|
||||
}
|
||||
}
|
||||
|
||||
void MeshProjection::projectOnMesh(const std::vector<Base::Vector3f>& pointsIn,
|
||||
const Base::Vector3f& dir,
|
||||
float tolerance,
|
||||
std::vector<Base::Vector3f>& pointsOut) const
|
||||
{
|
||||
// calculate the average edge length and create a grid
|
||||
MeshAlgorithm clAlg(_rcMesh);
|
||||
float fAvgLen = clAlg.GetAverageEdgeLength();
|
||||
MeshFacetGrid cGrid(_rcMesh, 5.0f*fAvgLen);
|
||||
|
||||
Base::SequencerLauncher seq( "Project points on mesh", pointsIn.size() );
|
||||
|
||||
for (auto it : pointsIn) {
|
||||
Base::Vector3f result;
|
||||
unsigned long index;
|
||||
if (clAlg.NearestFacetOnRay(it, dir, cGrid, result, index)) {
|
||||
MeshCore::MeshGeomFacet geomFacet = _rcMesh.GetFacet(index);
|
||||
if (tolerance > 0 && geomFacet.IntersectPlaneWithLine(it, dir, result)) {
|
||||
if (geomFacet.IsPointOfFace(result, tolerance))
|
||||
pointsOut.push_back(result);
|
||||
}
|
||||
else {
|
||||
pointsOut.push_back(result);
|
||||
}
|
||||
}
|
||||
|
||||
seq.next();
|
||||
}
|
||||
}
|
||||
|
||||
void MeshProjection::projectParallelToMesh (const TopoDS_Shape &aShape, const Base::Vector3f& dir, std::vector<PolyLine>& rPolyLines) const
|
||||
{
|
||||
// calculate the average edge length and create a grid
|
||||
|
||||
@@ -196,6 +196,18 @@ public:
|
||||
* taken if the distance between the curve point and the projected point is <= \a fMaxDist.
|
||||
*/
|
||||
void projectToMesh (const TopoDS_Shape &aShape, float fMaxDist, std::vector<PolyLine>& rPolyLines) const;
|
||||
/**
|
||||
* @brief projectOnMesh
|
||||
* Projects the given points onto the mesh along a given direction. The points can can be projected
|
||||
* will be saved to \a pointsOut
|
||||
* @brief projectOnMesh
|
||||
* @param pointsIn
|
||||
* @param dir
|
||||
* @param tolerance
|
||||
* @param pointsOut
|
||||
*/
|
||||
void projectOnMesh(const std::vector<Base::Vector3f>& pointsIn, const Base::Vector3f& dir,
|
||||
float tolerance, std::vector<Base::Vector3f>& pointsOut) const;
|
||||
/**
|
||||
* Project all edges of the shape onto the mesh using parallel projection.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user