Skip to content

Commit

Permalink
generate minumum number of points from an edge
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed May 19, 2019
1 parent 51c317d commit b17a784
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/Mod/MeshPart/App/CurveProjector.cpp
Expand Up @@ -30,6 +30,7 @@
# include <BndLib_Add3dCurve.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <GCPnts_UniformDeflection.hxx>
# include <GCPnts_UniformAbscissa.hxx>
# include <gp_Pln.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
Expand Down Expand Up @@ -688,7 +689,7 @@ MeshProjection::~MeshProjection()
{
}

void MeshProjection::discretize(const TopoDS_Edge& aEdge, std::vector<Base::Vector3f>& polyline) const
void MeshProjection::discretize(const TopoDS_Edge& aEdge, std::vector<Base::Vector3f>& polyline, std::size_t minPoints) const
{
BRepAdaptor_Curve clCurve(aEdge);

Expand All @@ -703,6 +704,18 @@ void MeshProjection::discretize(const TopoDS_Edge& aEdge, std::vector<Base::Vect
polyline.push_back( Base::Vector3f( (float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z() ) );
}
}

if (polyline.size() < minPoints) {
GCPnts_UniformAbscissa clAbsc(clCurve, static_cast<Standard_Integer>(minPoints), fFirst, fLast);
if (clAbsc.IsDone() == Standard_True) {
polyline.clear();
Standard_Integer nNbPoints = clAbsc.NbPoints();
for (Standard_Integer i = 1; i <= nNbPoints; i++) {
gp_Pnt gpPt = clCurve.Value(clAbsc.Parameter(i));
polyline.push_back( Base::Vector3f( (float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z() ) );
}
}
}
}

void MeshProjection::splitMeshByShape ( const TopoDS_Shape &aShape, float fMaxDist ) const
Expand Down Expand Up @@ -765,7 +778,7 @@ void MeshProjection::projectParallelToMesh (const TopoDS_Shape &aShape, const Ba
for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
std::vector<Base::Vector3f> points;
discretize(aEdge, points);
discretize(aEdge, points, 5);

typedef std::pair<Base::Vector3f, unsigned long> HitPoint;
std::vector<HitPoint> hitPoints;
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/MeshPart/App/CurveProjector.h
Expand Up @@ -180,7 +180,7 @@ class MeshPartExport MeshProjection
/// Destruction
~MeshProjection();

void discretize(const TopoDS_Edge& aEdge, std::vector<Base::Vector3f>& polyline) const;
void discretize(const TopoDS_Edge& aEdge, std::vector<Base::Vector3f>& polyline, std::size_t minPoints=2) const;
/**
* Searches all edges that intersect with the projected curve \a aShape. Therefore \a aShape must
* contain shapes of type TopoDS_Edge, other shape types are ignored. A possible solution is
Expand Down
1 change: 1 addition & 0 deletions src/Mod/MeshPart/App/PreCompiled.h
Expand Up @@ -147,6 +147,7 @@
#include <GCE2d_MakeSegment.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <GCPnts_UniformDeflection.hxx>
#include <GCPnts_UniformAbscissa.hxx>
#include <Geom_Axis2Placement.hxx>
#include <Geom_CartesianPoint.hxx>
#include <Geom_Line.hxx>
Expand Down

0 comments on commit b17a784

Please sign in to comment.