diff --git a/src/Mod/MeshPart/App/AppMeshPart.cpp b/src/Mod/MeshPart/App/AppMeshPart.cpp
index 6483d22c43..1fb7b4d611 100644
--- a/src/Mod/MeshPart/App/AppMeshPart.cpp
+++ b/src/Mod/MeshPart/App/AppMeshPart.cpp
@@ -27,7 +27,8 @@
#include
-namespace MeshPart {
+namespace MeshPart
+{
extern PyObject* initModule();
}
@@ -37,9 +38,9 @@ PyMOD_INIT_FUNC(MeshPart)
// load dependent module
try {
Base::Interpreter().loadModule("Part");
- //Base::Interpreter().loadModule("Mesh");
+ // Base::Interpreter().loadModule("Mesh");
}
- catch(const Base::Exception& e) {
+ catch (const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
PyMOD_Return(nullptr);
}
diff --git a/src/Mod/MeshPart/App/AppMeshPartPy.cpp b/src/Mod/MeshPart/App/AppMeshPartPy.cpp
index 6d9b707955..4215369f0c 100644
--- a/src/Mod/MeshPart/App/AppMeshPartPy.cpp
+++ b/src/Mod/MeshPart/App/AppMeshPartPy.cpp
@@ -22,8 +22,8 @@
#include "PreCompiled.h"
#ifndef _PreComp_
-# include
-# include
+#include
+#include
#endif
#include
@@ -33,17 +33,18 @@
#include
#include
#include
+#include
+#include
+#include
#include
#include
#include
-#include
-#include
-#include
#include "MeshAlgos.h"
#include "Mesher.h"
+// clang-format off
namespace MeshPart {
class Module : public Py::ExtensionModule
{
@@ -639,3 +640,4 @@ PyObject* initModule()
}
} // namespace MeshPart
+// clang-format on
diff --git a/src/Mod/MeshPart/App/CurveProjector.cpp b/src/Mod/MeshPart/App/CurveProjector.cpp
index 71742a05b5..703813ab68 100644
--- a/src/Mod/MeshPart/App/CurveProjector.cpp
+++ b/src/Mod/MeshPart/App/CurveProjector.cpp
@@ -22,26 +22,26 @@
#include "PreCompiled.h"
#ifndef _PreComp_
-# ifdef FC_OS_LINUX
-# include
-# endif
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
+#ifdef FC_OS_LINUX
+#include
+#endif
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#endif
#include
@@ -59,32 +59,31 @@
using namespace MeshPart;
-using MeshCore::MeshKernel;
-using MeshCore::MeshFacetIterator;
-using MeshCore::MeshPointIterator;
using MeshCore::MeshAlgorithm;
-using MeshCore::MeshFacetGrid;
using MeshCore::MeshFacet;
+using MeshCore::MeshFacetGrid;
+using MeshCore::MeshFacetIterator;
+using MeshCore::MeshKernel;
+using MeshCore::MeshPointIterator;
-CurveProjector::CurveProjector(const TopoDS_Shape &aShape, const MeshKernel &pMesh)
- : _Shape(aShape)
- , _Mesh(pMesh)
-{
-}
+CurveProjector::CurveProjector(const TopoDS_Shape& aShape, const MeshKernel& pMesh)
+ : _Shape(aShape)
+ , _Mesh(pMesh)
+{}
-void CurveProjector::writeIntersectionPointsToFile(const char *name)
+void CurveProjector::writeIntersectionPointsToFile(const char* name)
{
- // export points
- Base::FileInfo fi(name);
- Base::ofstream str(fi, std::ios::out | std::ios::binary);
- str.precision(4);
- str.setf(std::ios::fixed | std::ios::showpoint);
- for (const auto & it1 : mvEdgeSplitPoints) {
- for (const auto & it2 : it1.second) {
- str << it2.p1.x << " " << it2.p1.y << " " << it2.p1.z << std::endl;
- }
- }
- str.close();
+ // export points
+ Base::FileInfo fi(name);
+ Base::ofstream str(fi, std::ios::out | std::ios::binary);
+ str.precision(4);
+ str.setf(std::ios::fixed | std::ios::showpoint);
+ for (const auto& it1 : mvEdgeSplitPoints) {
+ for (const auto& it2 : it1.second) {
+ str << it2.p1.x << " " << it2.p1.y << " " << it2.p1.z << std::endl;
+ }
+ }
+ str.close();
}
@@ -93,159 +92,170 @@ void CurveProjector::writeIntersectionPointsToFile(const char *name)
// Separator for additional classes
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-CurveProjectorShape::CurveProjectorShape(const TopoDS_Shape &aShape, const MeshKernel &pMesh)
- : CurveProjector(aShape, pMesh)
+CurveProjectorShape::CurveProjectorShape(const TopoDS_Shape& aShape, const MeshKernel& pMesh)
+ : CurveProjector(aShape, pMesh)
{
CurveProjectorShape::Do();
}
void CurveProjectorShape::Do()
{
- TopExp_Explorer Ex;
- for (Ex.Init(_Shape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
- const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
+ TopExp_Explorer Ex;
+ for (Ex.Init(_Shape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
+ const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
- //std::vector vSplitEdges;
- projectCurve(aEdge, mvEdgeSplitPoints[aEdge]);
- }
+ // std::vector vSplitEdges;
+ projectCurve(aEdge, mvEdgeSplitPoints[aEdge]);
+ }
}
void CurveProjectorShape::projectCurve(const TopoDS_Edge& aEdge,
- std::vector &vSplitEdges)
+ std::vector& vSplitEdges)
{
- Standard_Real fFirst, fLast;
- Handle(Geom_Curve) hCurve = BRep_Tool::Curve( aEdge,fFirst,fLast );
+ Standard_Real fFirst, fLast;
+ Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge, fFirst, fLast);
- // getting start point
- gp_Pnt gpPt = hCurve->Value(fFirst);
+ // getting start point
+ gp_Pnt gpPt = hCurve->Value(fFirst);
- // projection of the first point
- Base::Vector3f cStartPoint = Base::Vector3f((float)gpPt.X(),
- (float)gpPt.Y(),
- (float)gpPt.Z());
- Base::Vector3f cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal;
- MeshCore::FacetIndex uStartFacetIdx,uCurFacetIdx;
- MeshCore::FacetIndex uLastFacetIdx=MeshCore::FACET_INDEX_MAX-1; // use another value as FACET_INDEX_MAX
- MeshCore::FacetIndex auNeighboursIdx[3];
- bool GoOn;
+ // projection of the first point
+ Base::Vector3f cStartPoint = Base::Vector3f((float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z());
+ Base::Vector3f cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal;
+ MeshCore::FacetIndex uStartFacetIdx, uCurFacetIdx;
+ MeshCore::FacetIndex uLastFacetIdx =
+ MeshCore::FACET_INDEX_MAX - 1;// use another value as FACET_INDEX_MAX
+ MeshCore::FacetIndex auNeighboursIdx[3];
+ bool GoOn;
- if( !findStartPoint(_Mesh,cStartPoint,cResultPoint,uStartFacetIdx) )
- return;
+ if (!findStartPoint(_Mesh, cStartPoint, cResultPoint, uStartFacetIdx)) {
+ return;
+ }
- uCurFacetIdx = uStartFacetIdx;
- do{
- MeshGeomFacet cCurFacet= _Mesh.GetFacet(uCurFacetIdx);
- _Mesh.GetFacetNeighbours ( uCurFacetIdx, auNeighboursIdx[0], auNeighboursIdx[1], auNeighboursIdx[2]);
- Base::Vector3f PointOnEdge[3];
+ uCurFacetIdx = uStartFacetIdx;
+ do {
+ MeshGeomFacet cCurFacet = _Mesh.GetFacet(uCurFacetIdx);
+ _Mesh.GetFacetNeighbours(uCurFacetIdx,
+ auNeighboursIdx[0],
+ auNeighboursIdx[1],
+ auNeighboursIdx[2]);
+ Base::Vector3f PointOnEdge[3];
- GoOn = false;
- int NbrOfHits = 0,HitIdx=0;
+ GoOn = false;
+ int NbrOfHits = 0, HitIdx = 0;
- for(int i=0; i<3; i++)
- {
- // ignore last visited facet
- if ( auNeighboursIdx[i] == uLastFacetIdx )
- continue;
+ for (int i = 0; i < 3; i++) {
+ // ignore last visited facet
+ if (auNeighboursIdx[i] == uLastFacetIdx) {
+ continue;
+ }
- // get points of the edge i
- const Base::Vector3f& cP0 = cCurFacet._aclPoints[i];
- const Base::Vector3f& cP1 = cCurFacet._aclPoints[(i+1)%3];
+ // get points of the edge i
+ const Base::Vector3f& cP0 = cCurFacet._aclPoints[i];
+ const Base::Vector3f& cP1 = cCurFacet._aclPoints[(i + 1) % 3];
- if ( auNeighboursIdx[i] != MeshCore::FACET_INDEX_MAX )
- {
- // calculate the normal by the edge vector and the middle between the two face normals
- MeshGeomFacet N = _Mesh.GetFacet( auNeighboursIdx[i] );
- cPlaneNormal = ( N.GetNormal() + cCurFacet.GetNormal() ) % ( cP1 - cP0 );
- cPlanePnt = cP0;
- }else{
- // with no neighbours the face normal is used
- cPlaneNormal = cCurFacet.GetNormal() % ( cP1 - cP0 );
- cPlanePnt = cP0;
- }
+ if (auNeighboursIdx[i] != MeshCore::FACET_INDEX_MAX) {
+ // calculate the normal by the edge vector and the middle between the two face
+ // normals
+ MeshGeomFacet N = _Mesh.GetFacet(auNeighboursIdx[i]);
+ cPlaneNormal = (N.GetNormal() + cCurFacet.GetNormal()) % (cP1 - cP0);
+ cPlanePnt = cP0;
+ }
+ else {
+ // with no neighbours the face normal is used
+ cPlaneNormal = cCurFacet.GetNormal() % (cP1 - cP0);
+ cPlanePnt = cP0;
+ }
- Handle(Geom_Plane) hPlane = new Geom_Plane(gp_Pln(gp_Pnt(cPlanePnt.x,cPlanePnt.y,cPlanePnt.z),
- gp_Dir(cPlaneNormal.x,cPlaneNormal.y,cPlaneNormal.z)));
+ Handle(Geom_Plane) hPlane =
+ new Geom_Plane(gp_Pln(gp_Pnt(cPlanePnt.x, cPlanePnt.y, cPlanePnt.z),
+ gp_Dir(cPlaneNormal.x, cPlaneNormal.y, cPlaneNormal.z)));
- GeomAPI_IntCS Alg(hCurve,hPlane);
+ GeomAPI_IntCS Alg(hCurve, hPlane);
- if ( Alg.IsDone() )
- {
- // deciding by the number of result points (intersections)
- if( Alg.NbPoints() == 1)
- {
- gp_Pnt P = Alg.Point(1);
- float l = ((Base::Vector3f((float)P.X(),(float)P.Y(),(float)P.Z()) - cP0)
- * (cP1 - cP0) ) / ((cP1 - cP0) * (cP1 - cP0));
- // is the Point on the Edge of the facet?
- if(l<0.0 || l>1.0)
- PointOnEdge[i] = Base::Vector3f(FLOAT_MAX,0,0);
- else{
- cSplitPoint = (1-l) * cP0 + l * cP1;
- PointOnEdge[i] = (1-l)*cP0 + l * cP1;
- NbrOfHits ++;
- HitIdx = i;
- }
- // no intersection
- }else if(Alg.NbPoints() == 0){
- PointOnEdge[i] = Base::Vector3f(FLOAT_MAX,0,0);
- // more the one intersection (@ToDo)
- }else if(Alg.NbPoints() > 1){
- PointOnEdge[i] = Base::Vector3f(FLOAT_MAX,0,0);
- Base::Console().Log("MeshAlgos::projectCurve(): More then one intersection in Facet %lu, Edge %d\n",uCurFacetIdx,i);
+ if (Alg.IsDone()) {
+ // deciding by the number of result points (intersections)
+ if (Alg.NbPoints() == 1) {
+ gp_Pnt P = Alg.Point(1);
+ float l = ((Base::Vector3f((float)P.X(), (float)P.Y(), (float)P.Z()) - cP0)
+ * (cP1 - cP0))
+ / ((cP1 - cP0) * (cP1 - cP0));
+ // is the Point on the Edge of the facet?
+ if (l < 0.0 || l > 1.0) {
+ PointOnEdge[i] = Base::Vector3f(FLOAT_MAX, 0, 0);
+ }
+ else {
+ cSplitPoint = (1 - l) * cP0 + l * cP1;
+ PointOnEdge[i] = (1 - l) * cP0 + l * cP1;
+ NbrOfHits++;
+ HitIdx = i;
+ }
+ // no intersection
+ }
+ else if (Alg.NbPoints() == 0) {
+ PointOnEdge[i] = Base::Vector3f(FLOAT_MAX, 0, 0);
+ // more the one intersection (@ToDo)
+ }
+ else if (Alg.NbPoints() > 1) {
+ PointOnEdge[i] = Base::Vector3f(FLOAT_MAX, 0, 0);
+ Base::Console().Log("MeshAlgos::projectCurve(): More then one intersection in "
+ "Facet %lu, Edge %d\n",
+ uCurFacetIdx,
+ i);
+ }
+ }
}
- }
- }
- uLastFacetIdx = uCurFacetIdx;
+ uLastFacetIdx = uCurFacetIdx;
- if(NbrOfHits == 1)
- {
- uCurFacetIdx = auNeighboursIdx[HitIdx];
- FaceSplitEdge splitEdge;
- splitEdge.ulFaceIndex = uCurFacetIdx;
- splitEdge.p1 = cResultPoint;
- splitEdge.p2 = cSplitPoint;
- vSplitEdges.push_back( splitEdge );
- cResultPoint = cSplitPoint;
- GoOn = true;
- }else{
- Base::Console().Log("MeshAlgos::projectCurve(): Possible reentry in Facet %lu\n", uCurFacetIdx);
- }
+ if (NbrOfHits == 1) {
+ uCurFacetIdx = auNeighboursIdx[HitIdx];
+ FaceSplitEdge splitEdge;
+ splitEdge.ulFaceIndex = uCurFacetIdx;
+ splitEdge.p1 = cResultPoint;
+ splitEdge.p2 = cSplitPoint;
+ vSplitEdges.push_back(splitEdge);
+ cResultPoint = cSplitPoint;
+ GoOn = true;
+ }
+ else {
+ Base::Console().Log("MeshAlgos::projectCurve(): Possible reentry in Facet %lu\n",
+ uCurFacetIdx);
+ }
- if( uCurFacetIdx == uStartFacetIdx )
- GoOn = false;
-
- }while(GoOn);
+ if (uCurFacetIdx == uStartFacetIdx) {
+ GoOn = false;
+ }
+ } while (GoOn);
}
-bool CurveProjectorShape::findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,MeshCore::FacetIndex &FaceIndex)
+bool CurveProjectorShape::findStartPoint(const MeshKernel& MeshK,
+ const Base::Vector3f& Pnt,
+ Base::Vector3f& Rslt,
+ MeshCore::FacetIndex& FaceIndex)
{
- Base::Vector3f TempResultPoint;
- float MinLength = FLOAT_MAX;
- bool bHit = false;
+ Base::Vector3f TempResultPoint;
+ float MinLength = FLOAT_MAX;
+ bool bHit = false;
- // go through the whole Mesh
- MeshFacetIterator It(MeshK);
- for(It.Init();It.More();It.Next())
- {
- // try to project (with angle) to the face
- if(It->Foraminate (Pnt, It->GetNormal(), TempResultPoint) )
- {
- // distance to the projected point
- float Dist = (Pnt-TempResultPoint).Length();
- if(Dist < MinLength)
- {
- // remember the point with the closest distance
- bHit = true;
- MinLength = Dist;
- Rslt = TempResultPoint;
- FaceIndex = It.Position();
- }
+ // go through the whole Mesh
+ MeshFacetIterator It(MeshK);
+ for (It.Init(); It.More(); It.Next()) {
+ // try to project (with angle) to the face
+ if (It->Foraminate(Pnt, It->GetNormal(), TempResultPoint)) {
+ // distance to the projected point
+ float Dist = (Pnt - TempResultPoint).Length();
+ if (Dist < MinLength) {
+ // remember the point with the closest distance
+ bHit = true;
+ MinLength = Dist;
+ Rslt = TempResultPoint;
+ FaceIndex = It.Position();
+ }
+ }
}
- }
- return bHit;
+ return bHit;
}
@@ -255,148 +265,149 @@ bool CurveProjectorShape::findStartPoint(const MeshKernel &MeshK,const Base::Vec
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-CurveProjectorSimple::CurveProjectorSimple(const TopoDS_Shape &aShape, const MeshKernel &pMesh)
-: CurveProjector(aShape,pMesh)
+CurveProjectorSimple::CurveProjectorSimple(const TopoDS_Shape& aShape, const MeshKernel& pMesh)
+ : CurveProjector(aShape, pMesh)
{
- Do();
+ Do();
}
void CurveProjectorSimple::Do()
{
- TopExp_Explorer Ex;
+ TopExp_Explorer Ex;
- std::vector vEdgePolygon;
+ std::vector vEdgePolygon;
- for (Ex.Init(_Shape, TopAbs_EDGE); Ex.More(); Ex.Next())
- {
- const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
-// GetSampledCurves(aEdge,vEdgePolygon,2000);
+ for (Ex.Init(_Shape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
+ const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
+ // GetSampledCurves(aEdge,vEdgePolygon,2000);
- //std::vector vSplitEdges;
- projectCurve(aEdge,vEdgePolygon, mvEdgeSplitPoints[aEdge]);
- }
+ // std::vector vSplitEdges;
+ projectCurve(aEdge, vEdgePolygon, mvEdgeSplitPoints[aEdge]);
+ }
}
-void CurveProjectorSimple::GetSampledCurves( const TopoDS_Edge& aEdge, std::vector& rclPoints, unsigned long ulNbOfPoints)
+void CurveProjectorSimple::GetSampledCurves(const TopoDS_Edge& aEdge,
+ std::vector& rclPoints,
+ unsigned long ulNbOfPoints)
{
- rclPoints.clear();
+ rclPoints.clear();
Standard_Real fBegin, fEnd;
- Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge,fBegin,fEnd);
- float fLen = float(fEnd - fBegin);
+ Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge, fBegin, fEnd);
+ float fLen = float(fEnd - fBegin);
- for (unsigned long i = 0; i < ulNbOfPoints; i++)
- {
- gp_Pnt gpPt = hCurve->Value(fBegin + (fLen * float(i)) / float(ulNbOfPoints-1));
- rclPoints.emplace_back((float)gpPt.X(),
- (float)gpPt.Y(),
- (float)gpPt.Z());
+ for (unsigned long i = 0; i < ulNbOfPoints; i++) {
+ gp_Pnt gpPt = hCurve->Value(fBegin + (fLen * float(i)) / float(ulNbOfPoints - 1));
+ rclPoints.emplace_back((float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z());
}
}
-//projectToNeighbours(Handle(Geom_Curve) hCurve,float pos
+// projectToNeighbours(Handle(Geom_Curve) hCurve,float pos
-void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge,
- const std::vector &/*rclPoints*/,
- std::vector &/*vSplitEdges*/)
+void CurveProjectorSimple::projectCurve(const TopoDS_Edge& aEdge,
+ const std::vector& /*rclPoints*/,
+ std::vector& /*vSplitEdges*/)
{
- Base::Vector3f /*cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal,*/TempResultPoint;
- bool bFirst = true;
- //unsigned long auNeighboursIdx[3];
- //std::map >::iterator N1,N2,N3;
+ Base::Vector3f /*cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal,*/ TempResultPoint;
+ bool bFirst = true;
+ // unsigned long auNeighboursIdx[3];
+ // std::map >::iterator N1,N2,N3;
- Standard_Real fBegin, fEnd;
- Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge,fBegin,fEnd);
- float fLen = float(fEnd - fBegin);
+ Standard_Real fBegin, fEnd;
+ Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge, fBegin, fEnd);
+ float fLen = float(fEnd - fBegin);
- unsigned long ulNbOfPoints = 1000,PointCount=0;
+ unsigned long ulNbOfPoints = 1000, PointCount = 0;
- MeshFacetIterator It(_Mesh);
+ MeshFacetIterator It(_Mesh);
- Base::SequencerLauncher seq("Building up projection map...", ulNbOfPoints+1);
- Base::FileInfo fi("projected.asc");
- Base::ofstream str(fi, std::ios::out | std::ios::binary);
- str.precision(4);
- str.setf(std::ios::fixed | std::ios::showpoint);
+ Base::SequencerLauncher seq("Building up projection map...", ulNbOfPoints + 1);
+ Base::FileInfo fi("projected.asc");
+ Base::ofstream str(fi, std::ios::out | std::ios::binary);
+ str.precision(4);
+ str.setf(std::ios::fixed | std::ios::showpoint);
- std::map > FaceProjctMap;
+ std::map> FaceProjctMap;
- for (unsigned long i = 0; i <= ulNbOfPoints; i++)
- {
- seq.next();
- gp_Pnt gpPt = hCurve->Value(fBegin + (fLen * float(i)) / float(ulNbOfPoints-1));
+ for (unsigned long i = 0; i <= ulNbOfPoints; i++) {
+ seq.next();
+ gp_Pnt gpPt = hCurve->Value(fBegin + (fLen * float(i)) / float(ulNbOfPoints - 1));
+
+ // go through the whole Mesh
+ for (It.Init(); It.More(); It.Next()) {
+ // try to project (with angle) to the face
+ if (It->IntersectWithLine(
+ Base::Vector3f((float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z()),
+ It->GetNormal(),
+ TempResultPoint)) {
+ FaceProjctMap[It.Position()].push_back(TempResultPoint);
+ str << TempResultPoint.x << " " << TempResultPoint.y << " " << TempResultPoint.z
+ << std::endl;
+ Base::Console().Log("IDX %d\n", It.Position());
+
+ if (bFirst) {
+ bFirst = false;
+ }
+
+ PointCount++;
+ }
+ }
+ }
+
+ str.close();
+ Base::Console().Log("Projection map [%d facets with %d points]\n",
+ FaceProjctMap.size(),
+ PointCount);
+
+ // estimate the first face
+ // gp_Pnt gpPt = hCurve->Value(fBegin);
+ // if(
+ // !findStartPoint(MeshK,Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()),cResultPoint,uCurFacetIdx)
+ // )
+ // uCurFacetIdx = FaceProjctMap.begin()->first;
+
+ /*
+ do{
+ Base::Console().Log("Grow on %d %d left\n",uCurFacetIdx,FaceProjctMap.size());
+
+ if(FaceProjctMap[uCurFacetIdx].size() == 1)
+ {
+ Base::Console().Log("Single hit\n");
+ }else{
- // go through the whole Mesh
- for(It.Init();It.More();It.Next())
- {
- // try to project (with angle) to the face
- if (It->IntersectWithLine (Base::Vector3f((float)gpPt.X(),(float)gpPt.Y(),(float)gpPt.Z()),
- It->GetNormal(), TempResultPoint))
- {
- FaceProjctMap[It.Position()].push_back(TempResultPoint);
- str << TempResultPoint.x << " "
- << TempResultPoint.y << " "
- << TempResultPoint.z << std::endl;
- Base::Console().Log("IDX %d\n",It.Position());
- if(bFirst){
- bFirst = false;
}
- PointCount++;
- }
- }
- }
+ FaceProjctMap.erase(uCurFacetIdx);
- str.close();
- Base::Console().Log("Projection map [%d facets with %d points]\n",FaceProjctMap.size(),PointCount);
+ // estimate next facet
+ MeshGeomFacet cCurFacet= MeshK.GetFacet(uCurFacetIdx);
+ MeshK.GetFacetNeighbours ( uCurFacetIdx, auNeighboursIdx[0], auNeighboursIdx[1],
+ auNeighboursIdx[2]);
- // estimate the first face
-// gp_Pnt gpPt = hCurve->Value(fBegin);
-// if( !findStartPoint(MeshK,Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()),cResultPoint,uCurFacetIdx) )
-// uCurFacetIdx = FaceProjctMap.begin()->first;
+ uCurFacetIdx = MeshCore::FACET_INDEX_MAX;
+ PointCount = 0;
-/*
- do{
- Base::Console().Log("Grow on %d %d left\n",uCurFacetIdx,FaceProjctMap.size());
-
- if(FaceProjctMap[uCurFacetIdx].size() == 1)
- {
- Base::Console().Log("Single hit\n");
- }else{
-
-
- }
-
- FaceProjctMap.erase(uCurFacetIdx);
-
- // estimate next facet
- MeshGeomFacet cCurFacet= MeshK.GetFacet(uCurFacetIdx);
- MeshK.GetFacetNeighbours ( uCurFacetIdx, auNeighboursIdx[0], auNeighboursIdx[1], auNeighboursIdx[2]);
-
- uCurFacetIdx = MeshCore::FACET_INDEX_MAX;
- PointCount = 0;
-
- for(int i=0; i<3; i++)
- {
- N1 = FaceProjctMap.find(auNeighboursIdx[i]);
- // if the i'th neighbour is valid
- if ( N1 != FaceProjctMap.end() )
- {
- unsigned long temp = N1->second.size();
- if(temp >= PointCount){
- PointCount = N1->second.size();
- uCurFacetIdx = auNeighboursIdx[i];
+ for(int i=0; i<3; i++)
+ {
+ N1 = FaceProjctMap.find(auNeighboursIdx[i]);
+ // if the i'th neighbour is valid
+ if ( N1 != FaceProjctMap.end() )
+ {
+ unsigned long temp = N1->second.size();
+ if(temp >= PointCount){
+ PointCount = N1->second.size();
+ uCurFacetIdx = auNeighboursIdx[i];
+ }
+ }
}
- }
- }
- }while(uCurFacetIdx != MeshCore::FACET_INDEX_MAX);
-*/
+ }while(uCurFacetIdx != MeshCore::FACET_INDEX_MAX);
+ */
}
/*
@@ -416,9 +427,8 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge,
Base::Vector3f cStartPoint = Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z());
Base::Vector3f cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal,TempResultPoint;
MeshCore::FacetIndex uStartFacetIdx,uCurFacetIdx;
- MeshCore::FacetIndex uLastFacetIdx=MeshCore::FACET_INDEX_MAX-1; // use another value as FACET_INDEX_MAX
- MeshCore::FacetIndex auNeighboursIdx[3];
- bool GoOn;
+ MeshCore::FacetIndex uLastFacetIdx=MeshCore::FACET_INDEX_MAX-1; // use another value as
+FACET_INDEX_MAX MeshCore::FacetIndex auNeighboursIdx[3]; bool GoOn;
// go through the whole Mesh, find the first projection
MeshFacetIterator It(MeshK);
@@ -443,14 +453,16 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge,
float fStep = (fLast-fFirst)/20;
unsigned long HitCount,Sentinel = 0 ;
MeshGeomFacet cCurFacet= MeshK.GetFacet(uCurFacetIdx);
- MeshK.GetFacetNeighbours ( uCurFacetIdx, auNeighboursIdx[0], auNeighboursIdx[1], auNeighboursIdx[2]);
+ MeshK.GetFacetNeighbours ( uCurFacetIdx, auNeighboursIdx[0], auNeighboursIdx[1],
+auNeighboursIdx[2]);
do{
// lower the step until you find a neigbourfacet to project...
fStep /= 2.0;
// still on the same facet?
gpPt = hCurve->Value(fAct+fStep);
- if(MeshFacetFunc::IntersectWithLine (cCurFacet, Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()), cCurFacet.GetNormal(), cResultPoint) )
+ if(MeshFacetFunc::IntersectWithLine (cCurFacet, Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()),
+cCurFacet.GetNormal(), cResultPoint) )
{
fAct += fStep;
fStep *= 2.0;
@@ -466,7 +478,8 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge,
// try to project next interval
MeshGeomFacet N = MeshK.GetFacet( auNeighboursIdx[i] );
gpPt = hCurve->Value(fAct+fStep);
- if(MeshFacetFunc::IntersectWithLine (*It, Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()), It->GetNormal(), cResultPoint) )
+ if(MeshFacetFunc::IntersectWithLine (*It, Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()),
+It->GetNormal(), cResultPoint) )
{
HitCount++;
uStartFacetIdx = auNeighboursIdx[i];
@@ -502,9 +515,8 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge,
Base::Vector3f cStartPoint = Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z());
Base::Vector3f cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal;
MeshCore::FacetIndex uStartFacetIdx,uCurFacetIdx;
- MeshCore::FacetIndex uLastFacetIdx=MeshCore::FACET_INDEX_MAX-1; // use another value as FACET_INDEX_MAX
- MeshCore::FacetIndex auNeighboursIdx[3];
- bool GoOn;
+ MeshCore::FacetIndex uLastFacetIdx=MeshCore::FACET_INDEX_MAX-1; // use another value as
+FACET_INDEX_MAX MeshCore::FacetIndex auNeighboursIdx[3]; bool GoOn;
if( !findStartPoint(MeshK,cStartPoint,cResultPoint,uStartFacetIdx) )
return;
@@ -515,8 +527,9 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge,
MeshFacetIterator It1(MeshK);
for(It1.Init();It1.More();It1.Next())
{
- // cycling through the points and find the first projecteble point ( if the curve starts outside the mesh)
- for( std::vector::const_iterator It = rclPoints.begin()+1;It!=rclPoints.end();++It)
+ // cycling through the points and find the first projecteble point ( if the curve starts outside
+the mesh) for( std::vector::const_iterator It =
+rclPoints.begin()+1;It!=rclPoints.end();++It)
{
// MeshGeomFacet facet = MeshK.GetFacet(uStartFacetIdx);
MeshGeomFacet facet = *It1;
@@ -532,32 +545,32 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge,
}
*/
-bool CurveProjectorSimple::findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,MeshCore::FacetIndex &FaceIndex)
+bool CurveProjectorSimple::findStartPoint(const MeshKernel& MeshK,
+ const Base::Vector3f& Pnt,
+ Base::Vector3f& Rslt,
+ MeshCore::FacetIndex& FaceIndex)
{
- Base::Vector3f TempResultPoint;
- float MinLength = FLOAT_MAX;
- bool bHit = false;
+ Base::Vector3f TempResultPoint;
+ float MinLength = FLOAT_MAX;
+ bool bHit = false;
- // go through the whole Mesh
- MeshFacetIterator It(MeshK);
- for(It.Init();It.More();It.Next())
- {
- // try to project (with angle) to the face
- if(It->Foraminate (Pnt, It->GetNormal(), TempResultPoint) )
- {
- // distance to the projected point
- float Dist = (Pnt-TempResultPoint).Length();
- if(Dist < MinLength)
- {
- // remember the point with the closest distance
- bHit = true;
- MinLength = Dist;
- Rslt = TempResultPoint;
- FaceIndex = It.Position();
- }
+ // go through the whole Mesh
+ MeshFacetIterator It(MeshK);
+ for (It.Init(); It.More(); It.Next()) {
+ // try to project (with angle) to the face
+ if (It->Foraminate(Pnt, It->GetNormal(), TempResultPoint)) {
+ // distance to the projected point
+ float Dist = (Pnt - TempResultPoint).Length();
+ if (Dist < MinLength) {
+ // remember the point with the closest distance
+ bHit = true;
+ MinLength = Dist;
+ Rslt = TempResultPoint;
+ FaceIndex = It.Position();
+ }
+ }
}
- }
- return bHit;
+ return bHit;
}
//**************************************************************************
@@ -566,151 +579,153 @@ bool CurveProjectorSimple::findStartPoint(const MeshKernel &MeshK,const Base::Ve
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-CurveProjectorWithToolMesh::CurveProjectorWithToolMesh(const TopoDS_Shape &aShape, const MeshKernel &pMesh,MeshKernel &rToolMesh)
-: CurveProjector(aShape,pMesh),ToolMesh(rToolMesh)
+CurveProjectorWithToolMesh::CurveProjectorWithToolMesh(const TopoDS_Shape& aShape,
+ const MeshKernel& pMesh,
+ MeshKernel& rToolMesh)
+ : CurveProjector(aShape, pMesh)
+ , ToolMesh(rToolMesh)
{
- Do();
+ Do();
}
void CurveProjectorWithToolMesh::Do()
{
- TopExp_Explorer Ex;
- std::vector cVAry;
+ TopExp_Explorer Ex;
+ std::vector cVAry;
- for (Ex.Init(_Shape, TopAbs_EDGE); Ex.More(); Ex.Next())
- {
- const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
- makeToolMesh(aEdge,cVAry);
- }
+ for (Ex.Init(_Shape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
+ const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
+ makeToolMesh(aEdge, cVAry);
+ }
- ToolMesh.AddFacets(cVAry);
+ ToolMesh.AddFacets(cVAry);
}
-//projectToNeighbours(Handle(Geom_Curve) hCurve,float pos
+// projectToNeighbours(Handle(Geom_Curve) hCurve,float pos
-void CurveProjectorWithToolMesh::makeToolMesh( const TopoDS_Edge& aEdge,std::vector &cVAry )
+void CurveProjectorWithToolMesh::makeToolMesh(const TopoDS_Edge& aEdge,
+ std::vector& cVAry)
{
- Standard_Real fBegin, fEnd;
- Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge,fBegin,fEnd);
- float fLen = float(fEnd - fBegin);
- Base::Vector3f cResultPoint;
+ Standard_Real fBegin, fEnd;
+ Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge, fBegin, fEnd);
+ float fLen = float(fEnd - fBegin);
+ Base::Vector3f cResultPoint;
- unsigned long ulNbOfPoints = 15,PointCount=0/*,uCurFacetIdx*/;
+ unsigned long ulNbOfPoints = 15, PointCount = 0 /*,uCurFacetIdx*/;
- std::vector LineSegs;
+ std::vector LineSegs;
- MeshFacetIterator It(_Mesh);
+ MeshFacetIterator It(_Mesh);
- Base::SequencerLauncher seq("Building up tool mesh...", ulNbOfPoints+1);
+ Base::SequencerLauncher seq("Building up tool mesh...", ulNbOfPoints + 1);
- std::map > FaceProjctMap;
+ std::map> FaceProjctMap;
- for (unsigned long i = 0; i < ulNbOfPoints; i++)
- {
- seq.next();
- gp_Pnt gpPt = hCurve->Value(fBegin + (fLen * float(i)) / float(ulNbOfPoints-1));
- Base::Vector3f LinePoint((float)gpPt.X(),
- (float)gpPt.Y(),
- (float)gpPt.Z());
+ for (unsigned long i = 0; i < ulNbOfPoints; i++) {
+ seq.next();
+ gp_Pnt gpPt = hCurve->Value(fBegin + (fLen * float(i)) / float(ulNbOfPoints - 1));
+ Base::Vector3f LinePoint((float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z());
- Base::Vector3f ResultNormal;
-
- // go through the whole Mesh
- for(It.Init();It.More();It.Next())
- {
- // try to project (with angle) to the face
- if (It->IntersectWithLine (Base::Vector3f((float)gpPt.X(),(float)gpPt.Y(),(float)gpPt.Z()),
- It->GetNormal(), cResultPoint) )
- {
- if(Base::Distance(LinePoint,cResultPoint) < 0.5)
- ResultNormal += It->GetNormal();
- }
- }
- LineSeg s;
- s.p = Base::Vector3f((float)gpPt.X(),
- (float)gpPt.Y(),
- (float)gpPt.Z());
- s.n = ResultNormal.Normalize();
- LineSegs.push_back(s);
- }
-
- Base::Console().Log("Projection map [%d facets with %d points]\n",FaceProjctMap.size(),PointCount);
-
-
- // build up the new mesh
- Base::Vector3f lp(FLOAT_MAX,0,0), ln, p1, p2, p3, p4,p5,p6;
- float ToolSize = 0.2f;
-
- for (const auto & It2 : LineSegs)
- {
- if(lp.x != FLOAT_MAX)
- {
- p1 = lp + (ln * (-ToolSize));
- p2 = lp + (ln * ToolSize);
- p3 = lp;
- p4 = It2.p;
- p5 = It2.p + (It2.n * (-ToolSize));
- p6 = It2.p + (It2.n * ToolSize);
-
- cVAry.emplace_back(p3,p2,p6);
- cVAry.emplace_back(p3,p6,p4);
- cVAry.emplace_back(p1,p3,p4);
- cVAry.emplace_back(p1,p4,p5);
+ Base::Vector3f ResultNormal;
+ // go through the whole Mesh
+ for (It.Init(); It.More(); It.Next()) {
+ // try to project (with angle) to the face
+ if (It->IntersectWithLine(
+ Base::Vector3f((float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z()),
+ It->GetNormal(),
+ cResultPoint)) {
+ if (Base::Distance(LinePoint, cResultPoint) < 0.5) {
+ ResultNormal += It->GetNormal();
+ }
+ }
+ }
+ LineSeg s;
+ s.p = Base::Vector3f((float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z());
+ s.n = ResultNormal.Normalize();
+ LineSegs.push_back(s);
}
- lp = It2.p;
- ln = It2.n;
- }
+ Base::Console().Log("Projection map [%d facets with %d points]\n",
+ FaceProjctMap.size(),
+ PointCount);
+
+
+ // build up the new mesh
+ Base::Vector3f lp(FLOAT_MAX, 0, 0), ln, p1, p2, p3, p4, p5, p6;
+ float ToolSize = 0.2f;
+
+ for (const auto& It2 : LineSegs) {
+ if (lp.x != FLOAT_MAX) {
+ p1 = lp + (ln * (-ToolSize));
+ p2 = lp + (ln * ToolSize);
+ p3 = lp;
+ p4 = It2.p;
+ p5 = It2.p + (It2.n * (-ToolSize));
+ p6 = It2.p + (It2.n * ToolSize);
+
+ cVAry.emplace_back(p3, p2, p6);
+ cVAry.emplace_back(p3, p6, p4);
+ cVAry.emplace_back(p1, p3, p4);
+ cVAry.emplace_back(p1, p4, p5);
+ }
+
+ lp = It2.p;
+ ln = It2.n;
+ }
}
// ----------------------------------------------------------------------------
MeshProjection::MeshProjection(const MeshKernel& rMesh)
- : _rcMesh(rMesh)
-{
-}
+ : _rcMesh(rMesh)
+{}
-void MeshProjection::discretize(const TopoDS_Edge& aEdge, std::vector& polyline, std::size_t minPoints) const
+void MeshProjection::discretize(const TopoDS_Edge& aEdge,
+ std::vector& polyline,
+ std::size_t minPoints) const
{
BRepAdaptor_Curve clCurve(aEdge);
Standard_Real fFirst = clCurve.FirstParameter();
- Standard_Real fLast = clCurve.LastParameter();
+ Standard_Real fLast = clCurve.LastParameter();
GCPnts_UniformDeflection clDefl(clCurve, 0.01f, fFirst, fLast);
if (clDefl.IsDone() == Standard_True) {
Standard_Integer nNbPoints = clDefl.NbPoints();
for (Standard_Integer i = 1; i <= nNbPoints; i++) {
gp_Pnt gpPt = clCurve.Value(clDefl.Parameter(i));
- polyline.emplace_back( (float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z() );
+ polyline.emplace_back((float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z());
}
}
if (polyline.size() < minPoints) {
- GCPnts_UniformAbscissa clAbsc(clCurve, static_cast(minPoints), fFirst, fLast);
+ GCPnts_UniformAbscissa clAbsc(clCurve,
+ static_cast(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.emplace_back( (float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z() );
+ polyline.emplace_back((float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z());
}
}
}
}
-void MeshProjection::splitMeshByShape ( const TopoDS_Shape &aShape, float fMaxDist ) const
+void MeshProjection::splitMeshByShape(const TopoDS_Shape& aShape, float fMaxDist) const
{
std::vector rPolyLines;
- projectToMesh( aShape, fMaxDist, rPolyLines );
+ projectToMesh(aShape, fMaxDist, rPolyLines);
Base::FileInfo fi("output.asc");
Base::ofstream str(fi, std::ios::out | std::ios::binary);
str.precision(4);
str.setf(std::ios::fixed | std::ios::showpoint);
- for (const auto & it : rPolyLines) {
+ for (const auto& it : rPolyLines) {
for (const auto& jt : it.points) {
str << jt.x << " " << jt.y << " " << jt.z << std::endl;
}
@@ -718,8 +733,10 @@ void MeshProjection::splitMeshByShape ( const TopoDS_Shape &aShape, float fMaxDi
str.close();
}
-bool MeshProjection::findIntersection(const Edge& edgeSegm, const Edge& meshEdge,
- const Base::Vector3f& dir, Base::Vector3f& res) const
+bool MeshProjection::findIntersection(const Edge& edgeSegm,
+ const Edge& meshEdge,
+ const Base::Vector3f& dir,
+ Base::Vector3f& res) const
{
Base::Vector3f planeNormal;
planeNormal = dir.Cross(edgeSegm.cPt2 - edgeSegm.cPt1);
@@ -731,30 +748,33 @@ bool MeshProjection::findIntersection(const Edge& edgeSegm, const Edge& meshEdge
dist2 = planeNormal.Dot(edgeSegm.cPt2 - meshEdge.cPt1);
if (dist1 * dist2 < 0) {
// intersection detected
- float t = planeNormal.Dot(meshEdge.cPt1 - edgeSegm.cPt1) /
- planeNormal.Dot(edgeSegm.cPt2 - edgeSegm.cPt1);
- res = edgeSegm.cPt1 * (1-t) + edgeSegm.cPt2 * t;
+ float t = planeNormal.Dot(meshEdge.cPt1 - edgeSegm.cPt1)
+ / planeNormal.Dot(edgeSegm.cPt2 - edgeSegm.cPt1);
+ res = edgeSegm.cPt1 * (1 - t) + edgeSegm.cPt2 * t;
return true;
}
}
return false;
}
-void MeshProjection::findSectionParameters(const TopoDS_Edge& edge, const Base::Vector3f& dir, std::set& parameters) const
+void MeshProjection::findSectionParameters(const TopoDS_Edge& edge,
+ const Base::Vector3f& dir,
+ std::set& parameters) const
{
- MeshAlgorithm clAlg( _rcMesh );
+ MeshAlgorithm clAlg(_rcMesh);
float fAvgLen = clAlg.GetAverageEdgeLength();
BRepAdaptor_Curve adapt(edge);
double edgeLen = GCPnts_AbscissaPoint::Length(adapt, Precision::Confusion());
std::vector polyline;
- discretize(edge, polyline, std::max(10, static_cast(edgeLen/fAvgLen)));
- if (polyline.empty())
+ discretize(edge, polyline, std::max(10, static_cast(edgeLen / fAvgLen)));
+ if (polyline.empty()) {
return;
+ }
std::vector lines;
Base::Vector3f start = polyline.front();
- for (auto it = polyline.begin()+1; it != polyline.end(); ++it) {
+ for (auto it = polyline.begin() + 1; it != polyline.end(); ++it) {
Edge line;
line.cPt1 = start;
line.cPt2 = *it;
@@ -767,9 +787,9 @@ void MeshProjection::findSectionParameters(const TopoDS_Edge& edge, const Base::
Base::Vector3f res;
for (const auto& it : facets) {
- for (int i=0; i<3; i++) {
+ for (int i = 0; i < 3; i++) {
Base::Vector3f pt1 = points[it._aulPoints[i]];
- Base::Vector3f pt2 = points[it._aulPoints[(i+1)%3]];
+ Base::Vector3f pt2 = points[it._aulPoints[(i + 1) % 3]];
Edge line;
line.cPt1 = pt1;
line.cPt2 = pt2;
@@ -777,12 +797,12 @@ void MeshProjection::findSectionParameters(const TopoDS_Edge& edge, const Base::
for (auto jt : lines) {
if (findIntersection(jt, line, dir, res)) {
try {
- BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(res.x,res.y,res.z));
+ BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(res.x, res.y, res.z));
BRepExtrema_DistShapeShape extss(aBuilder.Vertex(), edge);
if (extss.NbSolution() == 1) {
Standard_Real par;
- //gp_pnt pnt = extss.PointOnShape2(1);
- //Standard_Real par = BRep_Tool::Parameter(aBuilder.Vertex(), edge);
+ // gp_pnt pnt = extss.PointOnShape2(1);
+ // Standard_Real par = BRep_Tool::Parameter(aBuilder.Vertex(), edge);
extss.ParOnEdgeS2(1, par);
parameters.insert(par);
break;
@@ -797,20 +817,23 @@ void MeshProjection::findSectionParameters(const TopoDS_Edge& edge, const Base::
}
}
-void MeshProjection::projectToMesh (const TopoDS_Shape &aShape, float fMaxDist, std::vector& rPolyLines) const
+void MeshProjection::projectToMesh(const TopoDS_Shape& aShape,
+ float fMaxDist,
+ std::vector& rPolyLines) const
{
// calculate the average edge length and create a grid
- MeshAlgorithm clAlg( _rcMesh );
+ MeshAlgorithm clAlg(_rcMesh);
float fAvgLen = clAlg.GetAverageEdgeLength();
- MeshFacetGrid cGrid( _rcMesh, 5.0f*fAvgLen );
+ MeshFacetGrid cGrid(_rcMesh, 5.0f * fAvgLen);
TopExp_Explorer Ex;
- int iCnt=0;
- for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next())
+ int iCnt = 0;
+ for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
iCnt++;
+ }
- Base::SequencerLauncher seq( "Project curve on mesh", iCnt );
+ Base::SequencerLauncher seq("Project curve on mesh", iCnt);
for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
@@ -818,8 +841,9 @@ void MeshProjection::projectToMesh (const TopoDS_Shape &aShape, float fMaxDist,
projectEdgeToEdge(aEdge, fMaxDist, cGrid, rSplitEdges);
PolyLine polyline;
polyline.points.reserve(rSplitEdges.size());
- for (auto it : rSplitEdges)
+ for (auto it : rSplitEdges) {
polyline.points.push_back(it.cPt);
+ }
rPolyLines.push_back(polyline);
seq.next();
}
@@ -833,7 +857,7 @@ void MeshProjection::projectOnMesh(const std::vector& pointsIn,
// calculate the average edge length and create a grid
MeshAlgorithm clAlg(_rcMesh);
float fAvgLen = clAlg.GetAverageEdgeLength();
- MeshFacetGrid cGrid(_rcMesh, 5.0f*fAvgLen);
+ MeshFacetGrid cGrid(_rcMesh, 5.0f * fAvgLen);
// get all boundary points and edges of the mesh
std::vector boundaryPoints;
@@ -842,20 +866,20 @@ void MeshProjection::projectOnMesh(const std::vector& pointsIn,
const MeshCore::MeshFacetArray& facets = _rcMesh.GetFacets();
const MeshCore::MeshPointArray& points = _rcMesh.GetPoints();
for (const auto& it : facets) {
- for (int i=0; i<3; i++) {
+ for (int i = 0; i < 3; i++) {
if (!it.HasNeighbour(i)) {
boundaryPoints.push_back(points[it._aulPoints[i]]);
MeshCore::MeshGeomEdge edge;
edge._bBorder = true;
edge._aclPoints[0] = points[it._aulPoints[i]];
- edge._aclPoints[1] = points[it._aulPoints[(i+1)%3]];
+ edge._aclPoints[1] = points[it._aulPoints[(i + 1) % 3]];
boundaryEdges.push_back(edge);
}
}
}
- Base::SequencerLauncher seq( "Project points on mesh", pointsIn.size() );
+ Base::SequencerLauncher seq("Project points on mesh", pointsIn.size());
for (auto it : pointsIn) {
Base::Vector3f result;
@@ -863,8 +887,9 @@ void MeshProjection::projectOnMesh(const std::vector& pointsIn,
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))
+ if (geomFacet.IsPointOfFace(result, tolerance)) {
pointsOut.push_back(result);
+ }
}
else {
pointsOut.push_back(result);
@@ -873,12 +898,13 @@ void MeshProjection::projectOnMesh(const std::vector& pointsIn,
else {
// go through the boundary points and check if the point can be directly projected
// onto one of them
- auto boundaryPnt = std::find_if(boundaryPoints.begin(), boundaryPoints.end(),
- [&it, &dir](const Base::Vector3f& pnt)->bool {
- Base::Vector3f vec = pnt - it;
- float angle = vec.GetAngle(dir);
- return angle < 1e-6f;
- });
+ auto boundaryPnt = std::find_if(boundaryPoints.begin(),
+ boundaryPoints.end(),
+ [&it, &dir](const Base::Vector3f& pnt) -> bool {
+ Base::Vector3f vec = pnt - it;
+ float angle = vec.GetAngle(dir);
+ return angle < 1e-6f;
+ });
if (boundaryPnt != boundaryPoints.end()) {
pointsOut.push_back(*boundaryPnt);
@@ -889,8 +915,8 @@ void MeshProjection::projectOnMesh(const std::vector& pointsIn,
Base::Vector3f result1, result2;
for (auto jt : boundaryEdges) {
jt.ClosestPointsToLine(it, dir, result1, result2);
- float dot = (result1-jt._aclPoints[0]).Dot(result1-jt._aclPoints[1]);
- //float distance = Base::Distance(result1, result2);
+ float dot = (result1 - jt._aclPoints[0]).Dot(result1 - jt._aclPoints[1]);
+ // float distance = Base::Distance(result1, result2);
Base::Vector3f vec = result1 - it;
float angle = vec.GetAngle(dir);
if (dot <= 0 && angle < 1e-6f) {
@@ -905,19 +931,22 @@ void MeshProjection::projectOnMesh(const std::vector& pointsIn,
}
}
-void MeshProjection::projectParallelToMesh (const TopoDS_Shape &aShape, const Base::Vector3f& dir, std::vector& rPolyLines) const
+void MeshProjection::projectParallelToMesh(const TopoDS_Shape& aShape,
+ const Base::Vector3f& dir,
+ std::vector& rPolyLines) const
{
// calculate the average edge length and create a grid
MeshAlgorithm clAlg(_rcMesh);
float fAvgLen = clAlg.GetAverageEdgeLength();
- MeshFacetGrid cGrid(_rcMesh, 5.0f*fAvgLen);
+ MeshFacetGrid cGrid(_rcMesh, 5.0f * fAvgLen);
TopExp_Explorer Ex;
- int iCnt=0;
- for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next())
+ int iCnt = 0;
+ for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
iCnt++;
+ }
- Base::SequencerLauncher seq( "Project curve on mesh", iCnt );
+ Base::SequencerLauncher seq("Project curve on mesh", iCnt);
for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
@@ -935,8 +964,8 @@ void MeshProjection::projectParallelToMesh (const TopoDS_Shape &aShape, const Ba
hitPoints.emplace_back(result, index);
if (hitPoints.size() > 1) {
- HitPoint p1 = hitPoints[hitPoints.size()-2];
- HitPoint p2 = hitPoints[hitPoints.size()-1];
+ HitPoint p1 = hitPoints[hitPoints.size() - 2];
+ HitPoint p2 = hitPoints[hitPoints.size() - 1];
hitPointPairs.emplace_back(p1, p2);
}
}
@@ -946,8 +975,13 @@ void MeshProjection::projectParallelToMesh (const TopoDS_Shape &aShape, const Ba
PolyLine polyline;
for (auto it : hitPointPairs) {
points.clear();
- if (meshProjection.projectLineOnMesh(cGrid, it.first.first, it.first.second,
- it.second.first, it.second.second, dir, points)) {
+ if (meshProjection.projectLineOnMesh(cGrid,
+ it.first.first,
+ it.first.second,
+ it.second.first,
+ it.second.second,
+ dir,
+ points)) {
polyline.points.insert(polyline.points.end(), points.begin(), points.end());
}
}
@@ -957,14 +991,16 @@ void MeshProjection::projectParallelToMesh (const TopoDS_Shape &aShape, const Ba
}
}
-void MeshProjection::projectParallelToMesh (const std::vector &aEdges, const Base::Vector3f& dir, std::vector& rPolyLines) const
+void MeshProjection::projectParallelToMesh(const std::vector& aEdges,
+ const Base::Vector3f& dir,
+ std::vector& rPolyLines) const
{
// calculate the average edge length and create a grid
MeshAlgorithm clAlg(_rcMesh);
float fAvgLen = clAlg.GetAverageEdgeLength();
- MeshFacetGrid cGrid(_rcMesh, 5.0f*fAvgLen);
+ MeshFacetGrid cGrid(_rcMesh, 5.0f * fAvgLen);
- Base::SequencerLauncher seq( "Project curve on mesh", aEdges.size() );
+ Base::SequencerLauncher seq("Project curve on mesh", aEdges.size());
for (const auto& it : aEdges) {
std::vector points = it.points;
@@ -980,8 +1016,8 @@ void MeshProjection::projectParallelToMesh (const std::vector &aEdges,
hitPoints.emplace_back(result, index);
if (hitPoints.size() > 1) {
- HitPoint p1 = hitPoints[hitPoints.size()-2];
- HitPoint p2 = hitPoints[hitPoints.size()-1];
+ HitPoint p1 = hitPoints[hitPoints.size() - 2];
+ HitPoint p2 = hitPoints[hitPoints.size() - 1];
hitPointPairs.emplace_back(p1, p2);
}
}
@@ -991,8 +1027,13 @@ void MeshProjection::projectParallelToMesh (const std::vector &aEdges,
PolyLine polyline;
for (auto it : hitPointPairs) {
points.clear();
- if (meshProjection.projectLineOnMesh(cGrid, it.first.first, it.first.second,
- it.second.first, it.second.second, dir, points)) {
+ if (meshProjection.projectLineOnMesh(cGrid,
+ it.first.first,
+ it.first.second,
+ it.second.first,
+ it.second.second,
+ dir,
+ points)) {
polyline.points.insert(polyline.points.end(), points.begin(), points.end());
}
}
@@ -1002,18 +1043,21 @@ void MeshProjection::projectParallelToMesh (const std::vector &aEdges,
}
}
-void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist, const MeshFacetGrid& rGrid,
- std::vector& rSplitEdges ) const
+void MeshProjection::projectEdgeToEdge(const TopoDS_Edge& aEdge,
+ float fMaxDist,
+ const MeshFacetGrid& rGrid,
+ std::vector& rSplitEdges) const
{
std::vector auFInds;
- std::map, std::list > pEdgeToFace;
+ std::map, std::list>
+ pEdgeToFace;
const std::vector& rclFAry = _rcMesh.GetFacets();
// search the facets in the local area of the curve
std::vector acPolyLine;
discretize(aEdge, acPolyLine);
- MeshAlgorithm(_rcMesh).SearchFacetsFromPolyline( acPolyLine, fMaxDist, rGrid, auFInds);
+ MeshAlgorithm(_rcMesh).SearchFacetsFromPolyline(acPolyLine, fMaxDist, rGrid, auFInds);
// remove duplicated elements
std::sort(auFInds.begin(), auFInds.end());
auFInds.erase(std::unique(auFInds.begin(), auFInds.end()), auFInds.end());
@@ -1022,9 +1066,12 @@ void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist
for (MeshCore::FacetIndex index : auFInds) {
const MeshFacet& rF = rclFAry[index];
for (int i = 0; i < 3; i++) {
- MeshCore::PointIndex ulPt0 = std::min(rF._aulPoints[i], rF._aulPoints[(i+1)%3]);
- MeshCore::PointIndex ulPt1 = std::max(rF._aulPoints[i], rF._aulPoints[(i+1)%3]);
- pEdgeToFace[std::pair(ulPt0, ulPt1)].push_front(index);
+ MeshCore::PointIndex ulPt0 =
+ std::min(rF._aulPoints[i], rF._aulPoints[(i + 1) % 3]);
+ MeshCore::PointIndex ulPt1 =
+ std::max(rF._aulPoints[i], rF._aulPoints[(i + 1) % 3]);
+ pEdgeToFace[std::pair(ulPt0, ulPt1)]
+ .push_front(index);
}
}
@@ -1033,65 +1080,69 @@ void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist
BRepAdaptor_Curve clCurve(aEdge);
Standard_Real fFirst = clCurve.FirstParameter();
- Standard_Real fLast = clCurve.LastParameter();
- Handle(Geom_Curve) hCurve = BRep_Tool::Curve( aEdge,fFirst,fLast );
+ Standard_Real fLast = clCurve.LastParameter();
+ Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge, fFirst, fLast);
// bounds of curve
-// Bnd_Box clBB;
-// BndLib_Add3dCurve::Add( BRepAdaptor_Curve(aEdge), 0.0, clBB );
+ // Bnd_Box clBB;
+ // BndLib_Add3dCurve::Add( BRepAdaptor_Curve(aEdge), 0.0, clBB );
- MeshPointIterator cPI( _rcMesh );
- MeshFacetIterator cFI( _rcMesh );
+ MeshPointIterator cPI(_rcMesh);
+ MeshFacetIterator cFI(_rcMesh);
- Base::SequencerLauncher seq( "Project curve on mesh", pEdgeToFace.size() );
- std::map, std::list >::iterator it;
- for ( it = pEdgeToFace.begin(); it != pEdgeToFace.end(); ++it ) {
+ Base::SequencerLauncher seq("Project curve on mesh", pEdgeToFace.size());
+ std::map,
+ std::list>::iterator it;
+ for (it = pEdgeToFace.begin(); it != pEdgeToFace.end(); ++it) {
seq.next();
// edge points
MeshCore::PointIndex uE0 = it->first.first;
- cPI.Set( uE0 );
+ cPI.Set(uE0);
Base::Vector3f cE0 = *cPI;
MeshCore::PointIndex uE1 = it->first.second;
- cPI.Set( uE1 );
+ cPI.Set(uE1);
Base::Vector3f cE1 = *cPI;
const std::list& auFaces = it->second;
- if ( auFaces.size() > 2 )
- continue; // non-manifold edge -> don't handle this
-// if ( clBB.IsOut( gp_Pnt(cE0.x, cE0.y, cE0.z) ) && clBB.IsOut( gp_Pnt(cE1.x, cE1.y, cE1.z) ) )
-// continue;
+ if (auFaces.size() > 2) {
+ continue;// non-manifold edge -> don't handle this
+ }
+ // if ( clBB.IsOut( gp_Pnt(cE0.x, cE0.y, cE0.z) ) && clBB.IsOut( gp_Pnt(cE1.x, cE1.y,
+ // cE1.z) ) )
+ // continue;
Base::Vector3f cEdgeNormal;
for (MeshCore::FacetIndex itF : auFaces) {
- cFI.Set( itF );
+ cFI.Set(itF);
cEdgeNormal += cFI->GetNormal();
}
// create a plane from the edge normal and point
Base::Vector3f cPlaneNormal = cEdgeNormal % (cE1 - cE0);
- Handle(Geom_Plane) hPlane = new Geom_Plane(gp_Pln(gp_Pnt(cE0.x,cE0.y,cE0.z),
- gp_Dir(cPlaneNormal.x,cPlaneNormal.y,cPlaneNormal.z)));
+ Handle(Geom_Plane) hPlane =
+ new Geom_Plane(gp_Pln(gp_Pnt(cE0.x, cE0.y, cE0.z),
+ gp_Dir(cPlaneNormal.x, cPlaneNormal.y, cPlaneNormal.z)));
// get intersection of curve and plane
- GeomAPI_IntCS Alg(hCurve,hPlane);
- if ( Alg.IsDone() ) {
+ GeomAPI_IntCS Alg(hCurve, hPlane);
+ if (Alg.IsDone()) {
Standard_Integer nNbPoints = Alg.NbPoints();
- if ( nNbPoints == 1 ) {
+ if (nNbPoints == 1) {
Standard_Real fU, fV, fW;
- Alg.Parameters( 1, fU, fV, fW);
+ Alg.Parameters(1, fU, fV, fW);
gp_Pnt P = Alg.Point(1);
Base::Vector3f cP0((float)P.X(), (float)P.Y(), (float)P.Z());
- float l = ( (cP0 - cE0) * (cE1 - cE0) ) / ( (cE1 - cE0) * ( cE1 - cE0) );
+ float l = ((cP0 - cE0) * (cE1 - cE0)) / ((cE1 - cE0) * (cE1 - cE0));
// lies the point inside the edge?
- if ( l>=0.0f && l<=1.0f ) {
- Base::Vector3f cSplitPoint = (1-l) * cE0 + l * cE1;
- float fDist = Base::Distance( cP0, cSplitPoint );
+ if (l >= 0.0f && l <= 1.0f) {
+ Base::Vector3f cSplitPoint = (1 - l) * cE0 + l * cE1;
+ float fDist = Base::Distance(cP0, cSplitPoint);
- if ( fDist <= fMaxDist ) {
+ if (fDist <= fMaxDist) {
SplitEdge splitEdge;
splitEdge.uE0 = uE0;
splitEdge.uE1 = uE1;
@@ -1101,23 +1152,23 @@ void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist
}
}
// search for the right solution
- else if ( nNbPoints > 1 ) {
- int nCntSol=0;
+ else if (nNbPoints > 1) {
+ int nCntSol = 0;
Base::Vector3f cSplitPoint;
Standard_Real fSol;
Base::Vector3f cP0;
- for ( int j=1; j<=nNbPoints; j++ ) {
+ for (int j = 1; j <= nNbPoints; j++) {
Standard_Real fU, fV, fW;
- Alg.Parameters( j, fU, fV, fW);
+ Alg.Parameters(j, fU, fV, fW);
gp_Pnt P = Alg.Point(j);
cP0.Set((float)P.X(), (float)P.Y(), (float)P.Z());
- float l = ( (cP0 - cE0) * (cE1 - cE0) ) / ( (cE1 - cE0) * ( cE1 - cE0) );
+ float l = ((cP0 - cE0) * (cE1 - cE0)) / ((cE1 - cE0) * (cE1 - cE0));
// lies the point inside the edge?
- if ( l>=0.0 && l<=1.0 ) {
- cSplitPoint = (1-l) * cE0 + l * cE1;
- float fDist = Base::Distance( cP0, cSplitPoint );
+ if (l >= 0.0 && l <= 1.0) {
+ cSplitPoint = (1 - l) * cE0 + l * cE1;
+ float fDist = Base::Distance(cP0, cSplitPoint);
if (fDist <= fMaxDist) {
nCntSol++;
@@ -1127,14 +1178,14 @@ void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist
}
// ok, only one sensible solution
- if ( nCntSol == 1 ) {
+ if (nCntSol == 1) {
SplitEdge splitEdge;
splitEdge.uE0 = uE0;
splitEdge.uE1 = uE1;
splitEdge.cPt = cSplitPoint;
rParamSplitEdges[fSol] = splitEdge;
}
- else if ( nCntSol > 1 ) {
+ else if (nCntSol > 1) {
Base::Console().Log("More than one possible intersection points\n");
}
}
@@ -1142,7 +1193,7 @@ void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist
}
// sorted by parameter
- for (const auto & itS : rParamSplitEdges) {
- rSplitEdges.push_back( itS.second );
+ for (const auto& itS : rParamSplitEdges) {
+ rSplitEdges.push_back(itS.second);
}
}
diff --git a/src/Mod/MeshPart/App/CurveProjector.h b/src/Mod/MeshPart/App/CurveProjector.h
index 63fdd1b4b5..c812d98d68 100644
--- a/src/Mod/MeshPart/App/CurveProjector.h
+++ b/src/Mod/MeshPart/App/CurveProjector.h
@@ -24,7 +24,7 @@
#define _CurveProjector_h_
#ifdef FC_USE_GTS
-# include
+#include
#endif
#include
@@ -38,10 +38,10 @@ namespace MeshCore
class MeshKernel;
class MeshGeomFacet;
class MeshFacetGrid;
-}
+}// namespace MeshCore
-using MeshCore::MeshKernel;
using MeshCore::MeshGeomFacet;
+using MeshCore::MeshKernel;
namespace MeshPart
{
@@ -51,35 +51,39 @@ namespace MeshPart
class MeshPartExport CurveProjector
{
public:
- CurveProjector(const TopoDS_Shape &aShape, const MeshKernel &pMesh);
- virtual ~CurveProjector() = default;
+ CurveProjector(const TopoDS_Shape& aShape, const MeshKernel& pMesh);
+ virtual ~CurveProjector() = default;
- struct FaceSplitEdge
- {
- MeshCore::FacetIndex ulFaceIndex;
- Base::Vector3f p1,p2;
- };
+ struct FaceSplitEdge
+ {
+ MeshCore::FacetIndex ulFaceIndex;
+ Base::Vector3f p1, p2;
+ };
- template
- struct TopoDSLess {
- bool operator()(const T& x, const T& y) const {
- return x.HashCode(INT_MAX-1) < y.HashCode(INT_MAX-1);
+ template
+ struct TopoDSLess
+ {
+ bool operator()(const T& x, const T& y) const
+ {
+ return x.HashCode(INT_MAX - 1) < y.HashCode(INT_MAX - 1);
+ }
+ };
+
+ using result_type = std::map, TopoDSLess>;
+
+
+ result_type& result()
+ {
+ return mvEdgeSplitPoints;
}
- };
- using result_type = std::map,TopoDSLess >;
-
-
- result_type &result() {return mvEdgeSplitPoints;}
-
- void writeIntersectionPointsToFile(const char *name="export_pts.asc");
+ void writeIntersectionPointsToFile(const char* name = "export_pts.asc");
protected:
- virtual void Do()=0;
- const TopoDS_Shape &_Shape;
- const MeshKernel &_Mesh;
- result_type mvEdgeSplitPoints;
-
+ virtual void Do() = 0;
+ const TopoDS_Shape& _Shape;
+ const MeshKernel& _Mesh;
+ result_type mvEdgeSplitPoints;
};
@@ -88,44 +92,48 @@ protected:
class MeshPartExport CurveProjectorShape: public CurveProjector
{
public:
- CurveProjectorShape(const TopoDS_Shape &aShape, const MeshKernel &pMesh);
- ~CurveProjectorShape() override = default;
+ CurveProjectorShape(const TopoDS_Shape& aShape, const MeshKernel& pMesh);
+ ~CurveProjectorShape() override = default;
- void projectCurve(const TopoDS_Edge& aEdge,
- std::vector &vSplitEdges);
-
- bool findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,MeshCore::FacetIndex &FaceIndex);
+ void projectCurve(const TopoDS_Edge& aEdge, std::vector& vSplitEdges);
+ bool findStartPoint(const MeshKernel& MeshK,
+ const Base::Vector3f& Pnt,
+ Base::Vector3f& Rslt,
+ MeshCore::FacetIndex& FaceIndex);
protected:
- void Do() override;
+ void Do() override;
};
-
/** Project by projecting a sampled curve to the mesh
*/
class MeshPartExport CurveProjectorSimple: public CurveProjector
{
public:
- CurveProjectorSimple(const TopoDS_Shape &aShape, const MeshKernel &pMesh);
- ~CurveProjectorSimple() override = default;
+ CurveProjectorSimple(const TopoDS_Shape& aShape, const MeshKernel& pMesh);
+ ~CurveProjectorSimple() override = default;
- /// helper to discredicice a Edge...
- void GetSampledCurves( const TopoDS_Edge& aEdge, std::vector& rclPoints, unsigned long ulNbOfPoints = 30);
+ /// helper to discredicice a Edge...
+ void GetSampledCurves(const TopoDS_Edge& aEdge,
+ std::vector& rclPoints,
+ unsigned long ulNbOfPoints = 30);
- void projectCurve(const TopoDS_Edge& aEdge,
- const std::vector &rclPoints,
- std::vector &vSplitEdges);
-
- bool findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,MeshCore::FacetIndex &FaceIndex);
+ void projectCurve(const TopoDS_Edge& aEdge,
+ const std::vector& rclPoints,
+ std::vector& vSplitEdges);
+ bool findStartPoint(const MeshKernel& MeshK,
+ const Base::Vector3f& Pnt,
+ Base::Vector3f& Rslt,
+ MeshCore::FacetIndex& FaceIndex);
protected:
- void Do() override;
+ void Do() override;
};
/** Project by projecting a sampled curve to the mesh
@@ -133,22 +141,25 @@ protected:
class MeshPartExport CurveProjectorWithToolMesh: public CurveProjector
{
public:
- struct LineSeg {
- Base::Vector3f p;
- Base::Vector3f n;
- };
+ struct LineSeg
+ {
+ Base::Vector3f p;
+ Base::Vector3f n;
+ };
- CurveProjectorWithToolMesh(const TopoDS_Shape &aShape, const MeshKernel &pMesh,MeshKernel &rToolMesh);
- ~CurveProjectorWithToolMesh() override = default;
+ CurveProjectorWithToolMesh(const TopoDS_Shape& aShape,
+ const MeshKernel& pMesh,
+ MeshKernel& rToolMesh);
+ ~CurveProjectorWithToolMesh() override = default;
- void makeToolMesh(const TopoDS_Edge& aEdge,std::vector &cVAry );
+ void makeToolMesh(const TopoDS_Edge& aEdge, std::vector& cVAry);
- MeshKernel &ToolMesh;
+ MeshKernel& ToolMesh;
protected:
- void Do() override;
+ void Do() override;
};
/**
@@ -162,7 +173,7 @@ public:
struct SplitEdge
{
MeshCore::PointIndex uE0, uE1; /**< start and endpoint of an edge */
- Base::Vector3f cPt; /**< Point on edge (\a uE0, \a uE1) */
+ Base::Vector3f cPt; /**< Point on edge (\a uE0, \a uE1) */
};
struct Edge
{
@@ -184,49 +195,66 @@ public:
* @param dir
* @param parameters
*/
- void findSectionParameters(const TopoDS_Edge& edge, const Base::Vector3f& dir, std::set& parameters) const;
- void discretize(const TopoDS_Edge& aEdge, std::vector& polyline, std::size_t minPoints=2) const;
+ void findSectionParameters(const TopoDS_Edge& edge,
+ const Base::Vector3f& dir,
+ std::set& parameters) const;
+ void discretize(const TopoDS_Edge& aEdge,
+ std::vector& 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
- * taken if the distance between the curve point and the projected point is <= \a fMaxDist.
+ * 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 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& rPolyLines) const;
+ void projectToMesh(const TopoDS_Shape& aShape,
+ float fMaxDist,
+ std::vector& 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
+ * 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& pointsIn, const Base::Vector3f& dir,
- float tolerance, std::vector& pointsOut) const;
+ void projectOnMesh(const std::vector& pointsIn,
+ const Base::Vector3f& dir,
+ float tolerance,
+ std::vector& pointsOut) const;
/**
* Project all edges of the shape onto the mesh using parallel projection.
*/
- void projectParallelToMesh (const TopoDS_Shape &aShape, const Base::Vector3f& dir, std::vector& rPolyLines) const;
+ void projectParallelToMesh(const TopoDS_Shape& aShape,
+ const Base::Vector3f& dir,
+ std::vector& rPolyLines) const;
/**
* Project all polylines onto the mesh using parallel projection.
*/
- void projectParallelToMesh (const std::vector& aEdges, const Base::Vector3f& dir, std::vector& rPolyLines) const;
+ void projectParallelToMesh(const std::vector& aEdges,
+ const Base::Vector3f& dir,
+ std::vector& rPolyLines) const;
/**
- * Cuts the mesh at the curve defined by \a aShape. This method call @ref projectToMesh() to get the
- * split the facet at the found points. @see projectToMesh() for more details.
+ * Cuts the mesh at the curve defined by \a aShape. This method call @ref projectToMesh() to get
+ * the split the facet at the found points. @see projectToMesh() for more details.
*/
- void splitMeshByShape (const TopoDS_Shape &aShape, float fMaxDist) const;
+ void splitMeshByShape(const TopoDS_Shape& aShape, float fMaxDist) const;
protected:
- void projectEdgeToEdge(const TopoDS_Edge &aCurve, float fMaxDist, const MeshCore::MeshFacetGrid& rGrid,
+ void projectEdgeToEdge(const TopoDS_Edge& aCurve,
+ float fMaxDist,
+ const MeshCore::MeshFacetGrid& rGrid,
std::vector& rSplitEdges) const;
- bool findIntersection(const Edge&, const Edge&, const Base::Vector3f& dir, Base::Vector3f& res) const;
+ bool findIntersection(const Edge&,
+ const Edge&,
+ const Base::Vector3f& dir,
+ Base::Vector3f& res) const;
private:
const MeshKernel& _rcMesh;
};
-} // namespace MeshPart
+}// namespace MeshPart
#endif
diff --git a/src/Mod/MeshPart/App/MeshAlgos.cpp b/src/Mod/MeshPart/App/MeshAlgos.cpp
index f812be8d21..b274c9d7c3 100644
--- a/src/Mod/MeshPart/App/MeshAlgos.cpp
+++ b/src/Mod/MeshPart/App/MeshAlgos.cpp
@@ -22,13 +22,13 @@
#include "PreCompiled.h"
#ifndef _PreComp_
-# ifdef FC_OS_LINUX
-# include
-# endif
+#ifdef FC_OS_LINUX
+#include
+#endif
#endif
-#include
#include
+#include
#include
#include
#include
@@ -43,66 +43,74 @@ using namespace MeshCore;
void MeshAlgos::offset(MeshCore::MeshKernel* Mesh, float fSize)
{
- std::vector normals = Mesh->CalcVertexNormals();
+ std::vector normals = Mesh->CalcVertexNormals();
- unsigned int i = 0;
- // go through all the Vertex normals
- for(std::vector::iterator It= normals.begin();It != normals.end();++It,i++)
- // and move each mesh point in the normal direction
- Mesh->MovePoint(i,It->Normalize() * fSize);
- Mesh->RecalcBoundBox();
+ unsigned int i = 0;
+ // go through all the Vertex normals
+ for (std::vector::iterator It = normals.begin(); It != normals.end();
+ ++It, i++) {
+ // and move each mesh point in the normal direction
+ Mesh->MovePoint(i, It->Normalize() * fSize);
+ }
+ Mesh->RecalcBoundBox();
}
-
void MeshAlgos::offsetSpecial2(MeshCore::MeshKernel* Mesh, float fSize)
{
Base::Builder3D builder;
- std::vector PointNormals= Mesh->CalcVertexNormals();
+ std::vector PointNormals = Mesh->CalcVertexNormals();
std::vector FaceNormals;
std::set fliped;
MeshFacetIterator it(*Mesh);
- for ( it.Init(); it.More(); it.Next() )
+ for (it.Init(); it.More(); it.Next()) {
FaceNormals.push_back(it->GetNormal().Normalize());
+ }
unsigned int i = 0;
// go through all the Vertex normals
- for(std::vector::iterator It= PointNormals.begin();It != PointNormals.end();++It,i++) {
- Base::Line3f line{Mesh->GetPoint(i), Mesh->GetPoint(i) + It->Normalize() * fSize};
+ for (std::vector::iterator It = PointNormals.begin(); It != PointNormals.end();
+ ++It, i++) {
+ Base::Line3f line {Mesh->GetPoint(i), Mesh->GetPoint(i) + It->Normalize() * fSize};
Base::DrawStyle drawStyle;
- builder.addNode(Base::LineItem{line, drawStyle});
+ builder.addNode(Base::LineItem {line, drawStyle});
// and move each mesh point in the normal direction
- Mesh->MovePoint(i,It->Normalize() * fSize);
+ Mesh->MovePoint(i, It->Normalize() * fSize);
}
Mesh->RecalcBoundBox();
MeshTopoAlgorithm alg(*Mesh);
- for(int l= 0; l<1 ;l++){
- for ( it.Init(),i=0; it.More(); it.Next(),i++ )
- {
- if(it->IsFlag(MeshFacet::INVALID))
+ for (int l = 0; l < 1; l++) {
+ for (it.Init(), i = 0; it.More(); it.Next(), i++) {
+ if (it->IsFlag(MeshFacet::INVALID)) {
continue;
+ }
// calculate the angle between them
- float angle = acos((FaceNormals[i] * it->GetNormal()) / (it->GetNormal().Length() * FaceNormals[i].Length()));
- if (angle > 1.6){
+ float angle = acos((FaceNormals[i] * it->GetNormal())
+ / (it->GetNormal().Length() * FaceNormals[i].Length()));
+ if (angle > 1.6) {
Base::DrawStyle drawStyle;
drawStyle.pointSize = 4.0F;
- Base::PointItem item{it->GetGravityPoint(), drawStyle, Base::ColorRGB{1.0F, 0.0F, 0.0F}};
+ Base::PointItem item {it->GetGravityPoint(),
+ drawStyle,
+ Base::ColorRGB {1.0F, 0.0F, 0.0F}};
builder.addNode(item);
fliped.insert(it.Position());
}
}
// if there are no flipped triangles -> stop
- //int f =fliped.size();
- if(fliped.empty())
+ // int f =fliped.size();
+ if (fliped.empty()) {
break;
+ }
- for(MeshCore::FacetIndex It : fliped)
+ for (MeshCore::FacetIndex It : fliped) {
alg.CollapseFacet(It);
+ }
fliped.clear();
}
@@ -110,56 +118,59 @@ void MeshAlgos::offsetSpecial2(MeshCore::MeshKernel* Mesh, float fSize)
// search for intersected facets
MeshCore::MeshEvalSelfIntersection eval(*Mesh);
- std::vector > faces;
+ std::vector> faces;
eval.GetIntersections(faces);
builder.saveToLog();
-
}
void MeshAlgos::offsetSpecial(MeshCore::MeshKernel* Mesh, float fSize, float zmax, float zmin)
{
- std::vector normals = Mesh->CalcVertexNormals();
+ std::vector normals = Mesh->CalcVertexNormals();
- unsigned int i = 0;
- // go through all the Vertex normals
- for(std::vector::iterator It= normals.begin();It != normals.end();++It,i++)
- {
- Base::Vector3f Pnt = Mesh->GetPoint(i);
+ unsigned int i = 0;
+ // go through all the Vertex normals
+ for (std::vector::iterator It = normals.begin(); It != normals.end();
+ ++It, i++) {
+ Base::Vector3f Pnt = Mesh->GetPoint(i);
- if(Pnt.z < zmax && Pnt.z > zmin)
- {
- Pnt.z = 0;
- Mesh->MovePoint(i,Pnt.Normalize() * fSize);
- }else
- // and move each mesh point in the normal direction
- Mesh->MovePoint(i,It->Normalize() * fSize);
- }
+ if (Pnt.z < zmax && Pnt.z > zmin) {
+ Pnt.z = 0;
+ Mesh->MovePoint(i, Pnt.Normalize() * fSize);
+ }
+ else {
+ // and move each mesh point in the normal direction
+ Mesh->MovePoint(i, It->Normalize() * fSize);
+ }
+ }
}
void MeshAlgos::coarsen(MeshCore::MeshKernel* /*Mesh*/, float /*f*/)
{
#ifdef FC_USE_GTS
- GtsSurface * surface;
+ GtsSurface* surface;
- // create a GTS surface
- surface = MeshAlgos::createGTSSurface(Mesh);
+ // create a GTS surface
+ surface = MeshAlgos::createGTSSurface(Mesh);
- Mesh->Clear();
+ Mesh->Clear();
- guint stop_number=100000;
- gdouble fold = 3.1415 / 180.;
+ guint stop_number = 100000;
+ gdouble fold = 3.1415 / 180.;
- gts_surface_coarsen (surface,
- NULL, NULL,
- NULL, NULL,
- (GtsStopFunc)gts_coarsen_stop_number,
- &stop_number, fold);
+ gts_surface_coarsen(surface,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ (GtsStopFunc)gts_coarsen_stop_number,
+ &stop_number,
+ fold);
- // get the standard mesh
- fillMeshFromGTSSurface(Mesh,surface);
+ // get the standard mesh
+ fillMeshFromGTSSurface(Mesh, surface);
#endif
}
@@ -170,143 +181,142 @@ MeshCore::MeshKernel* MeshAlgos::boolean(MeshCore::MeshKernel* pMesh1,
int /*Type*/)
{
#ifdef FC_USE_GTS
- GtsSurface * s1, * s2, * s3;
- GtsSurfaceInter * si;
- GNode * tree1, * tree2;
- gboolean check_self_intersection = false;
- gboolean closed = true, is_open1, is_open2;
+ GtsSurface *s1, *s2, *s3;
+ GtsSurfaceInter* si;
+ GNode *tree1, *tree2;
+ gboolean check_self_intersection = false;
+ gboolean closed = true, is_open1, is_open2;
- // create a GTS surface
- s1 = MeshAlgos::createGTSSurface(pMesh1);
- s2 = MeshAlgos::createGTSSurface(pMesh2);
+ // create a GTS surface
+ s1 = MeshAlgos::createGTSSurface(pMesh1);
+ s2 = MeshAlgos::createGTSSurface(pMesh2);
- // clear the mesh (memory)
- //Mesh1.clear();
- //Mesh2.clear();
+ // clear the mesh (memory)
+ // Mesh1.clear();
+ // Mesh2.clear();
- /* check that the surfaces are orientable manifolds */
- if (!gts_surface_is_orientable (s1)) {
- gts_object_destroy (GTS_OBJECT (s1));
- gts_object_destroy (GTS_OBJECT (s2));
- throw std::runtime_error("surface 1 is not an orientable manifold\n");
- }
- if (!gts_surface_is_orientable (s2)) {
- gts_object_destroy (GTS_OBJECT (s1));
- gts_object_destroy (GTS_OBJECT (s2));
- throw std::runtime_error("surface 2 is not an orientable manifold\n");
- }
-
- /* check that the surfaces are not self-intersecting */
- if (check_self_intersection) {
- GtsSurface * self_intersects;
-
- self_intersects = gts_surface_is_self_intersecting (s1);
- if (self_intersects != NULL) {
-// if (verbose)
-// gts_surface_print_stats (self_intersects, stderr);
-// gts_surface_write (self_intersects, stdout);
- gts_object_destroy (GTS_OBJECT (self_intersects));
- gts_object_destroy (GTS_OBJECT (s1));
- gts_object_destroy (GTS_OBJECT (s2));
- throw std::runtime_error("surface is self-intersecting\n");
+ /* check that the surfaces are orientable manifolds */
+ if (!gts_surface_is_orientable(s1)) {
+ gts_object_destroy(GTS_OBJECT(s1));
+ gts_object_destroy(GTS_OBJECT(s2));
+ throw std::runtime_error("surface 1 is not an orientable manifold\n");
}
- self_intersects = gts_surface_is_self_intersecting (s2);
- if (self_intersects != NULL) {
-// if (verbose)
-// gts_surface_print_stats (self_intersects, stderr);
-// gts_surface_write (self_intersects, stdout);
- gts_object_destroy (GTS_OBJECT (self_intersects));
- gts_object_destroy (GTS_OBJECT (s1));
- gts_object_destroy (GTS_OBJECT (s2));
- throw std::runtime_error("surface is self-intersecting\n");
+ if (!gts_surface_is_orientable(s2)) {
+ gts_object_destroy(GTS_OBJECT(s1));
+ gts_object_destroy(GTS_OBJECT(s2));
+ throw std::runtime_error("surface 2 is not an orientable manifold\n");
}
- }
- /* build bounding box tree for first surface */
- tree1 = gts_bb_tree_surface (s1);
- is_open1 = gts_surface_volume (s1) < 0. ? true : false;
+ /* check that the surfaces are not self-intersecting */
+ if (check_self_intersection) {
+ GtsSurface* self_intersects;
- /* build bounding box tree for second surface */
- tree2 = gts_bb_tree_surface (s2);
- is_open2 = gts_surface_volume (s2) < 0. ? true : false;
-
- si = gts_surface_inter_new (gts_surface_inter_class (),
- s1, s2, tree1, tree2, is_open1, is_open2);
- g_assert (gts_surface_inter_check (si, &closed));
- if (!closed) {
- gts_object_destroy (GTS_OBJECT (s1));
- gts_object_destroy (GTS_OBJECT (s2));
- gts_bb_tree_destroy (tree1, true);
- gts_bb_tree_destroy (tree2, true);
- throw"the intersection of 1 and 2 is not a closed curve\n";
- }
-
- s3 = gts_surface_new (gts_surface_class (),
- gts_face_class (),
- gts_edge_class (),
- gts_vertex_class ());
- if (Type==0) { // union
- gts_surface_inter_boolean (si, s3, GTS_1_OUT_2);
- gts_surface_inter_boolean (si, s3, GTS_2_OUT_1);
- }
- else if (Type==1) { // inter
- gts_surface_inter_boolean (si, s3, GTS_1_IN_2);
- gts_surface_inter_boolean (si, s3, GTS_2_IN_1);
- }
- else if (Type==2) { //diff
- gts_surface_inter_boolean (si, s3, GTS_1_OUT_2);
- gts_surface_inter_boolean (si, s3, GTS_2_IN_1);
- gts_surface_foreach_face (si->s2, (GtsFunc) gts_triangle_revert, NULL);
- gts_surface_foreach_face (s2, (GtsFunc) gts_triangle_revert, NULL);
- }
- else if (Type==3) { // cut inner
- gts_surface_inter_boolean (si, s3, GTS_1_IN_2);
- }
- else if (Type==4) { // cut outer
- gts_surface_inter_boolean (si, s3, GTS_1_OUT_2);
- }
-
- // check that the resulting surface is not self-intersecting
- if (check_self_intersection) {
- GtsSurface * self_intersects;
-
- self_intersects = gts_surface_is_self_intersecting (s3);
- if (self_intersects != NULL) {
-// if (verbose)
-// gts_surface_print_stats (self_intersects, stderr);
-// gts_surface_write (self_intersects, stdout);
- gts_object_destroy (GTS_OBJECT (self_intersects));
- gts_object_destroy (GTS_OBJECT (s1));
- gts_object_destroy (GTS_OBJECT (s2));
- gts_object_destroy (GTS_OBJECT (s3));
- gts_object_destroy (GTS_OBJECT (si));
- gts_bb_tree_destroy (tree1, true);
- gts_bb_tree_destroy (tree2, true);
- throw std::runtime_error("the resulting surface is self-intersecting\n");
+ self_intersects = gts_surface_is_self_intersecting(s1);
+ if (self_intersects != NULL) {
+ // if (verbose)
+ // gts_surface_print_stats (self_intersects, stderr);
+ // gts_surface_write (self_intersects, stdout);
+ gts_object_destroy(GTS_OBJECT(self_intersects));
+ gts_object_destroy(GTS_OBJECT(s1));
+ gts_object_destroy(GTS_OBJECT(s2));
+ throw std::runtime_error("surface is self-intersecting\n");
+ }
+ self_intersects = gts_surface_is_self_intersecting(s2);
+ if (self_intersects != NULL) {
+ // if (verbose)
+ // gts_surface_print_stats (self_intersects, stderr);
+ // gts_surface_write (self_intersects, stdout);
+ gts_object_destroy(GTS_OBJECT(self_intersects));
+ gts_object_destroy(GTS_OBJECT(s1));
+ gts_object_destroy(GTS_OBJECT(s2));
+ throw std::runtime_error("surface is self-intersecting\n");
+ }
}
- }
- // display summary information about the resulting surface
-// if (verbose)
-// gts_surface_print_stats (s3, stderr);
- // write resulting surface to standard output
- // get the standard mesh
- fillMeshFromGTSSurface(pResult,s3);
+ /* build bounding box tree for first surface */
+ tree1 = gts_bb_tree_surface(s1);
+ is_open1 = gts_surface_volume(s1) < 0. ? true : false;
+
+ /* build bounding box tree for second surface */
+ tree2 = gts_bb_tree_surface(s2);
+ is_open2 = gts_surface_volume(s2) < 0. ? true : false;
+
+ si = gts_surface_inter_new(gts_surface_inter_class(), s1, s2, tree1, tree2, is_open1, is_open2);
+ g_assert(gts_surface_inter_check(si, &closed));
+ if (!closed) {
+ gts_object_destroy(GTS_OBJECT(s1));
+ gts_object_destroy(GTS_OBJECT(s2));
+ gts_bb_tree_destroy(tree1, true);
+ gts_bb_tree_destroy(tree2, true);
+ throw "the intersection of 1 and 2 is not a closed curve\n";
+ }
+
+ s3 = gts_surface_new(gts_surface_class(),
+ gts_face_class(),
+ gts_edge_class(),
+ gts_vertex_class());
+ if (Type == 0) {// union
+ gts_surface_inter_boolean(si, s3, GTS_1_OUT_2);
+ gts_surface_inter_boolean(si, s3, GTS_2_OUT_1);
+ }
+ else if (Type == 1) {// inter
+ gts_surface_inter_boolean(si, s3, GTS_1_IN_2);
+ gts_surface_inter_boolean(si, s3, GTS_2_IN_1);
+ }
+ else if (Type == 2) {// diff
+ gts_surface_inter_boolean(si, s3, GTS_1_OUT_2);
+ gts_surface_inter_boolean(si, s3, GTS_2_IN_1);
+ gts_surface_foreach_face(si->s2, (GtsFunc)gts_triangle_revert, NULL);
+ gts_surface_foreach_face(s2, (GtsFunc)gts_triangle_revert, NULL);
+ }
+ else if (Type == 3) {// cut inner
+ gts_surface_inter_boolean(si, s3, GTS_1_IN_2);
+ }
+ else if (Type == 4) {// cut outer
+ gts_surface_inter_boolean(si, s3, GTS_1_OUT_2);
+ }
+
+ // check that the resulting surface is not self-intersecting
+ if (check_self_intersection) {
+ GtsSurface* self_intersects;
+
+ self_intersects = gts_surface_is_self_intersecting(s3);
+ if (self_intersects != NULL) {
+ // if (verbose)
+ // gts_surface_print_stats (self_intersects, stderr);
+ // gts_surface_write (self_intersects, stdout);
+ gts_object_destroy(GTS_OBJECT(self_intersects));
+ gts_object_destroy(GTS_OBJECT(s1));
+ gts_object_destroy(GTS_OBJECT(s2));
+ gts_object_destroy(GTS_OBJECT(s3));
+ gts_object_destroy(GTS_OBJECT(si));
+ gts_bb_tree_destroy(tree1, true);
+ gts_bb_tree_destroy(tree2, true);
+ throw std::runtime_error("the resulting surface is self-intersecting\n");
+ }
+ }
+ // display summary information about the resulting surface
+ // if (verbose)
+ // gts_surface_print_stats (s3, stderr);
+ // write resulting surface to standard output
+
+ // get the standard mesh
+ fillMeshFromGTSSurface(pResult, s3);
- // destroy surfaces
- gts_object_destroy (GTS_OBJECT (s1));
- gts_object_destroy (GTS_OBJECT (s2));
-// gts_object_destroy (GTS_OBJECT (s3));
-// gts_object_destroy (GTS_OBJECT (si));
+ // destroy surfaces
+ gts_object_destroy(GTS_OBJECT(s1));
+ gts_object_destroy(GTS_OBJECT(s2));
+ // gts_object_destroy (GTS_OBJECT (s3));
+ // gts_object_destroy (GTS_OBJECT (si));
- // destroy bounding box trees (including bounding boxes)
-// gts_bb_tree_destroy (tree1, true);
-// gts_bb_tree_destroy (tree2, true);
+ // destroy bounding box trees (including bounding boxes)
+ // gts_bb_tree_destroy (tree1, true);
+ // gts_bb_tree_destroy (tree2, true);
#endif
- return pMesh1;
+ return pMesh1;
}
@@ -314,70 +324,70 @@ MeshCore::MeshKernel* MeshAlgos::boolean(MeshCore::MeshKernel* pMesh1,
/// helper function - construct a Edge out of two Vertexes if not already there
-static GtsEdge * new_edge (GtsVertex * v1, GtsVertex * v2)
+static GtsEdge* new_edge(GtsVertex* v1, GtsVertex* v2)
{
- GtsSegment * s = gts_vertices_are_connected (v1, v2);
- if( s == NULL )
- return gts_edge_new (gts_edge_class (), v1, v2);
- else
- return GTS_EDGE (s);
+ GtsSegment* s = gts_vertices_are_connected(v1, v2);
+ if (s == NULL) {
+ return gts_edge_new(gts_edge_class(), v1, v2);
+ }
+ else {
+ return GTS_EDGE(s);
+ }
}
GtsSurface* MeshAlgos::createGTSSurface(MeshCore::MeshKernel* Mesh)
{
- GtsSurface* Surf = gts_surface_new (gts_surface_class (),
- gts_face_class (),
- gts_edge_class (),
- gts_vertex_class () );
+ GtsSurface* Surf = gts_surface_new(gts_surface_class(),
+ gts_face_class(),
+ gts_edge_class(),
+ gts_vertex_class());
- unsigned long p1,p2,p3;
- Base::Vector3f Vertex;
+ unsigned long p1, p2, p3;
+ Base::Vector3f Vertex;
- // Getting all the points
- GtsVertex ** aVertex = (GtsVertex **) malloc(Mesh->CountPoints() * sizeof (GtsVertex *));
- for (unsigned int PIter = 0;PIter < Mesh->CountPoints(); PIter++)
- {
- Vertex = Mesh->GetPoint(PIter);
- aVertex[PIter] = gts_vertex_new (gts_vertex_class (), Vertex.x, Vertex.y, Vertex.z);
- }
+ // Getting all the points
+ GtsVertex** aVertex = (GtsVertex**)malloc(Mesh->CountPoints() * sizeof(GtsVertex*));
+ for (unsigned int PIter = 0; PIter < Mesh->CountPoints(); PIter++) {
+ Vertex = Mesh->GetPoint(PIter);
+ aVertex[PIter] = gts_vertex_new(gts_vertex_class(), Vertex.x, Vertex.y, Vertex.z);
+ }
// cycling through the facets
- for (unsigned int pFIter = 0;pFIter < Mesh->CountFacets(); pFIter++)
- {
- // getting the three points of the facet
- Mesh->GetFacetPoints(pFIter,p1,p2,p3);
+ for (unsigned int pFIter = 0; pFIter < Mesh->CountFacets(); pFIter++) {
+ // getting the three points of the facet
+ Mesh->GetFacetPoints(pFIter, p1, p2, p3);
- // creating the edges and add the face to the surface
- gts_surface_add_face (Surf,
- gts_face_new (Surf->face_class,
- new_edge (aVertex[p1],aVertex[p2]),
- new_edge (aVertex[p2],aVertex[p3]),
- new_edge (aVertex[p3],aVertex[p1])));
- }
+ // creating the edges and add the face to the surface
+ gts_surface_add_face(Surf,
+ gts_face_new(Surf->face_class,
+ new_edge(aVertex[p1], aVertex[p2]),
+ new_edge(aVertex[p2], aVertex[p3]),
+ new_edge(aVertex[p3], aVertex[p1])));
+ }
- Base::Console().Log("GTS [%d faces, %d Points, %d Edges,%s ,%s]\n",gts_surface_face_number(Surf),
- gts_surface_vertex_number(Surf),
- gts_surface_edge_number(Surf),
- gts_surface_is_orientable (Surf)?"orientable":"not orientable",
- gts_surface_is_self_intersecting(Surf)?"self-intersections":"no self-intersection" );
-
- return Surf;
+ Base::Console().Log("GTS [%d faces, %d Points, %d Edges,%s ,%s]\n",
+ gts_surface_face_number(Surf),
+ gts_surface_vertex_number(Surf),
+ gts_surface_edge_number(Surf),
+ gts_surface_is_orientable(Surf) ? "orientable" : "not orientable",
+ gts_surface_is_self_intersecting(Surf) ? "self-intersections"
+ : "no self-intersection");
+ return Surf;
}
/// helper function for the face (triangle iteration
-static void onFaces (GtsTriangle * t, std::vector *VAry )
+static void onFaces(GtsTriangle* t, std::vector* VAry)
{
- GtsVertex *mv0,*mv1,*mv2;
+ GtsVertex *mv0, *mv1, *mv2;
- gts_triangle_vertices (t,&mv0,&mv1,&mv2);
-
- VAry->push_back(MeshGeomFacet(Base::Vector3f(mv0->p.x,mv0->p.y,mv0->p.z),
- Base::Vector3f(mv1->p.x,mv1->p.y,mv1->p.z),
- Base::Vector3f(mv2->p.x,mv2->p.y,mv2->p.z)));
+ gts_triangle_vertices(t, &mv0, &mv1, &mv2);
+ VAry->push_back(MeshGeomFacet(Base::Vector3f(mv0->p.x, mv0->p.y, mv0->p.z),
+ Base::Vector3f(mv1->p.x, mv1->p.y, mv1->p.z),
+ Base::Vector3f(mv2->p.x, mv2->p.y, mv2->p.z)));
}
/*
@@ -388,55 +398,54 @@ static void onVertices(GtsVertex *v, MeshKernel *pKernel )
void MeshAlgos::fillMeshFromGTSSurface(MeshCore::MeshKernel* pMesh, GtsSurface* pSurface)
{
- std::vector VAry;
+ std::vector VAry;
- // remove old mesh
- pMesh->Clear();
+ // remove old mesh
+ pMesh->Clear();
-// gts_surface_foreach_vertex(pSurface,(GtsFunc) onVertices,&MeshK);
- gts_surface_foreach_face (pSurface, (GtsFunc) onFaces,&VAry);
+ // gts_surface_foreach_vertex(pSurface,(GtsFunc) onVertices,&MeshK);
+ gts_surface_foreach_face(pSurface, (GtsFunc)onFaces, &VAry);
- // destroy surfaces
- gts_object_destroy (GTS_OBJECT (pSurface));
-
- // put the facets the simple way in the mesh, totp is recalculated!
- (*pMesh) = VAry;
+ // destroy surfaces
+ gts_object_destroy(GTS_OBJECT(pSurface));
+ // put the facets the simple way in the mesh, totp is recalculated!
+ (*pMesh) = VAry;
}
#endif
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
#include
#include
#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
-void MeshAlgos::cutByShape(const TopoDS_Shape &aShape,const MeshCore::MeshKernel* pMesh,MeshCore::MeshKernel* pToolMesh)
+void MeshAlgos::cutByShape(const TopoDS_Shape& aShape,
+ const MeshCore::MeshKernel* pMesh,
+ MeshCore::MeshKernel* pToolMesh)
{
- // calculate the projection for each Edge
-// CurveProjectorShape Project(aShape,*pMesh);
- CurveProjectorWithToolMesh Project(aShape,*pMesh,*pToolMesh);
-
- //IntersectionLine Lines;
-// MeshWithProperty *ResultMesh = new MeshWithProperty();
-
-
- // boolean(pMesh,ToolMesh,ResultMesh,1);
+ // calculate the projection for each Edge
+ // CurveProjectorShape Project(aShape,*pMesh);
+ CurveProjectorWithToolMesh Project(aShape, *pMesh, *pToolMesh);
+ // IntersectionLine Lines;
+ // MeshWithProperty *ResultMesh = new MeshWithProperty();
+ // boolean(pMesh,ToolMesh,ResultMesh,1);
}
/*
-void MeshAlgos::doIntersection(const MeshWithProperty &pMesh,const MeshWithProperty ToolMesh,IntersectionLine &Lines)
+void MeshAlgos::doIntersection(const MeshWithProperty &pMesh,const MeshWithProperty
+ToolMesh,IntersectionLine &Lines)
{
@@ -444,140 +453,145 @@ void MeshAlgos::doIntersection(const MeshWithProperty &pMesh,const MeshWithPrope
*/
-void MeshAlgos::cutByCurve(MeshCore::MeshKernel* pMesh,const std::vector &vSplitEdges)
+void MeshAlgos::cutByCurve(MeshCore::MeshKernel* pMesh,
+ const std::vector& vSplitEdges)
{
- MeshTopoAlgorithm cTopAlg(*pMesh);
+ MeshTopoAlgorithm cTopAlg(*pMesh);
- for (const auto & it : vSplitEdges)
- {
- cTopAlg.SplitFacet( it.ulFaceIndex, it.p1, it.p2 );
- }
+ for (const auto& it : vSplitEdges) {
+ cTopAlg.SplitFacet(it.ulFaceIndex, it.p1, it.p2);
+ }
}
class _VertexCompare
{
- public:
- bool operator () (const TopoDS_Vertex &rclV1, const TopoDS_Vertex &rclV2) const
+public:
+ bool operator()(const TopoDS_Vertex& rclV1, const TopoDS_Vertex& rclV2) const
{
- if (rclV1.IsSame(rclV2) == Standard_True)
- return false;
+ if (rclV1.IsSame(rclV2) == Standard_True) {
+ return false;
+ }
- gp_XYZ clP1 = BRep_Tool::Pnt(rclV1).XYZ();
- gp_XYZ clP2 = BRep_Tool::Pnt(rclV2).XYZ();
+ gp_XYZ clP1 = BRep_Tool::Pnt(rclV1).XYZ();
+ gp_XYZ clP2 = BRep_Tool::Pnt(rclV2).XYZ();
- if (fabs(clP1.X() - clP2.X()) < dE)
- {
- if (fabs(clP1.Y() - clP2.Y()) < dE)
- return clP1.Z() < clP2.Z();
- else
- return clP1.Y() < clP2.Y();
- }
- else
- return clP1.X() < clP2.X();
+ if (fabs(clP1.X() - clP2.X()) < dE) {
+ if (fabs(clP1.Y() - clP2.Y()) < dE) {
+ return clP1.Z() < clP2.Z();
+ }
+ else {
+ return clP1.Y() < clP2.Y();
+ }
+ }
+ else {
+ return clP1.X() < clP2.X();
+ }
}
double dE = 1.0e-5;
};
-
-void MeshAlgos::LoftOnCurve(MeshCore::MeshKernel &ResultMesh, const TopoDS_Shape &Shape, const std::vector &poly, const Base::Vector3f & up, float MaxSize)
+void MeshAlgos::LoftOnCurve(MeshCore::MeshKernel& ResultMesh,
+ const TopoDS_Shape& Shape,
+ const std::vector& poly,
+ const Base::Vector3f& up,
+ float MaxSize)
{
- TopExp_Explorer Ex;
- Standard_Real fBegin, fEnd;
- std::vector cVAry;
- std::map,_VertexCompare> ConnectMap;
+ TopExp_Explorer Ex;
+ Standard_Real fBegin, fEnd;
+ std::vector cVAry;
+ std::map, _VertexCompare> ConnectMap;
- for (Ex.Init(Shape, TopAbs_EDGE); Ex.More(); Ex.Next())
- {
- // get the edge and the belonging Vertexes
- TopoDS_Edge Edge = (TopoDS_Edge&)Ex.Current();
- TopoDS_Vertex V1, V2;
- TopExp::Vertices(Edge, V1, V2);
- bool bBegin = false,bEnd = false;
- // getting the geometric curve and the interval
- GeomLProp_CLProps prop(BRep_Tool::Curve(Edge,fBegin,fEnd),1,0.0000000001);
- int res = int((fEnd - fBegin)/MaxSize);
- // do at least 2 segments
- if(res < 2)
- res = 2;
- gp_Dir Tangent;
-
- std::vector prePoint(poly.size());
- std::vector actPoint(poly.size());
-
- // checking if there is already a end to connect
- if(ConnectMap.find(V1) != ConnectMap.end() ){
- bBegin = true;
- prePoint = ConnectMap[V1];
- }
-
- if(ConnectMap.find(V2) != ConnectMap.end() )
- bEnd = true;
-
- for (long i = 0; i < res; i++)
- {
-
- // get point and tangent at the position, up is fix for the moment
- prop.SetParameter(fBegin + ((fEnd - fBegin) * float(i)) / float(res-1));
- prop.Tangent(Tangent);
- Base::Vector3f Tng((float)Tangent.X(),
- (float)Tangent.Y(),
- (float)Tangent.Z());
- Base::Vector3f Ptn((float)prop.Value().X(),
- (float)prop.Value().Y(),
- (float)prop.Value().Z());
- Base::Vector3f Up (up);
- // normalize and calc the third vector of the plane coordinatesystem
- Tng.Normalize();
- Up.Normalize();
- Base::Vector3f Third(Tng%Up);
-
-// Base::Console().Log("Pos: %f %f %f \n",Ptn.x,Ptn.y,Ptn.z);
-
- unsigned int l=0;
- std::vector::const_iterator It;
-
- // got through the profile
- for(It=poly.begin();It!=poly.end();++It,l++)
- actPoint[l] = ((Third*It->x)+(Up*It->y)+(Tng*It->z)+Ptn);
-
- if(i == res-1 && !bEnd)
- // remember the last row to connect to a otger edge with the same vertex
- ConnectMap[V2] = actPoint;
-
- if(i==1 && bBegin)
- // using the end of an other edge as start
- prePoint = ConnectMap[V1];
-
- if(i==0 && !bBegin)
- // remember the first row for connection to a edge with the same vertex
- ConnectMap[V1] = actPoint;
-
- if(i ) // not the first row or something to connect to
- {
- for(l=0;l prePoint(poly.size());
+ std::vector actPoint(poly.size());
+
+ // checking if there is already a end to connect
+ if (ConnectMap.find(V1) != ConnectMap.end()) {
+ bBegin = true;
+ prePoint = ConnectMap[V1];
+ }
+
+ if (ConnectMap.find(V2) != ConnectMap.end()) {
+ bEnd = true;
+ }
+
+ for (long i = 0; i < res; i++) {
+
+ // get point and tangent at the position, up is fix for the moment
+ prop.SetParameter(fBegin + ((fEnd - fBegin) * float(i)) / float(res - 1));
+ prop.Tangent(Tangent);
+ Base::Vector3f Tng((float)Tangent.X(), (float)Tangent.Y(), (float)Tangent.Z());
+ Base::Vector3f Ptn((float)prop.Value().X(),
+ (float)prop.Value().Y(),
+ (float)prop.Value().Z());
+ Base::Vector3f Up(up);
+ // normalize and calc the third vector of the plane coordinatesystem
+ Tng.Normalize();
+ Up.Normalize();
+ Base::Vector3f Third(Tng % Up);
+
+ // Base::Console().Log("Pos: %f %f %f \n",Ptn.x,Ptn.y,Ptn.z);
+
+ unsigned int l = 0;
+ std::vector::const_iterator It;
+
+ // got through the profile
+ for (It = poly.begin(); It != poly.end(); ++It, l++) {
+ actPoint[l] = ((Third * It->x) + (Up * It->y) + (Tng * It->z) + Ptn);
+ }
+
+ if (i == res - 1 && !bEnd) {
+ // remember the last row to connect to a otger edge with the same vertex
+ ConnectMap[V2] = actPoint;
+ }
+
+ if (i == 1 && bBegin) {
+ // using the end of an other edge as start
+ prePoint = ConnectMap[V1];
+ }
+
+ if (i == 0 && !bBegin) {
+ // remember the first row for connection to a edge with the same vertex
+ ConnectMap[V1] = actPoint;
+ }
+
+ if (i)// not the first row or something to connect to
+ {
+ for (l = 0; l < actPoint.size(); l++) {
+ if (l)// not first point in row
+ {
+ if (i == res - 1 && bEnd) {// if last row and a end to connect
+ actPoint = ConnectMap[V2];
+ }
+
+ Base::Vector3f p1 = prePoint[l - 1], p2 = actPoint[l - 1], p3 = prePoint[l],
+ p4 = actPoint[l];
+
+ cVAry.emplace_back(p1, p2, p3);
+ cVAry.emplace_back(p3, p2, p4);
+ }
+ }
+ }
+
+ prePoint = actPoint;
+ }
}
- }
-
- ResultMesh.AddFacets(cVAry);
+ ResultMesh.AddFacets(cVAry);
}
diff --git a/src/Mod/MeshPart/App/MeshAlgos.h b/src/Mod/MeshPart/App/MeshAlgos.h
index 2e8b1827c4..55c278bf68 100644
--- a/src/Mod/MeshPart/App/MeshAlgos.h
+++ b/src/Mod/MeshPart/App/MeshAlgos.h
@@ -24,7 +24,7 @@
#define _MeshAlgos_h_
#ifdef FC_USE_GTS
-# include
+#include
#endif
#include
@@ -50,61 +50,72 @@ namespace MeshPart
class MeshPartExport MeshAlgos
{
public:
- /** Calculate per Vertex normals and adds the Normal property bag
- */
- static void offset(MeshCore::MeshKernel* Mesh, float fSize);
- static void offsetSpecial2(MeshCore::MeshKernel* Mesh, float fSize);
- static void offsetSpecial(MeshCore::MeshKernel* Mesh, float fSize, float zmax, float zmin);
+ /** Calculate per Vertex normals and adds the Normal property bag
+ */
+ static void offset(MeshCore::MeshKernel* Mesh, float fSize);
+ static void offsetSpecial2(MeshCore::MeshKernel* Mesh, float fSize);
+ static void offsetSpecial(MeshCore::MeshKernel* Mesh, float fSize, float zmax, float zmin);
- /** Coarsen the mesh
- */
- static void coarsen(MeshCore::MeshKernel* Mesh, float f);
+ /** Coarsen the mesh
+ */
+ static void coarsen(MeshCore::MeshKernel* Mesh, float f);
- /** makes a boolean add
- * The int Type stears the boolean oberation: 0=add;1=intersection;2=diff
- */
- static MeshCore::MeshKernel* boolean(MeshCore::MeshKernel* Mesh1, MeshCore::MeshKernel* Mesh2, MeshCore::MeshKernel* pResult, int Type=0);
+ /** makes a boolean add
+ * The int Type stears the boolean oberation: 0=add;1=intersection;2=diff
+ */
+ static MeshCore::MeshKernel* boolean(MeshCore::MeshKernel* Mesh1,
+ MeshCore::MeshKernel* Mesh2,
+ MeshCore::MeshKernel* pResult,
+ int Type = 0);
#ifdef FC_USE_GTS
- /** Creates a GTS Surface from a MeshKernel
- */
- static GtsSurface* createGTSSurface(MeshCore::MeshKernel* Mesh);
+ /** Creates a GTS Surface from a MeshKernel
+ */
+ static GtsSurface* createGTSSurface(MeshCore::MeshKernel* Mesh);
- /** Creates a GTS Surface from a MeshKernel
- */
+ /** Creates a GTS Surface from a MeshKernel
+ */
- static void fillMeshFromGTSSurface(MeshCore::MeshKernel* pMesh, GtsSurface* pSurface);
+ static void fillMeshFromGTSSurface(MeshCore::MeshKernel* pMesh, GtsSurface* pSurface);
#endif
- static void cutByShape(const TopoDS_Shape &aShape,const MeshCore::MeshKernel* pMesh,MeshCore::MeshKernel* pToolMesh);
+ static void cutByShape(const TopoDS_Shape& aShape,
+ const MeshCore::MeshKernel* pMesh,
+ MeshCore::MeshKernel* pToolMesh);
- /// helper to discredicice a Edge...
- static void GetSampledCurves( const TopoDS_Edge& aEdge, std::vector& rclPoints, unsigned long ulNbOfPoints = 30);
+ /// helper to discredicice a Edge...
+ static void GetSampledCurves(const TopoDS_Edge& aEdge,
+ std::vector& rclPoints,
+ unsigned long ulNbOfPoints = 30);
- /// creates a mesh loft on base of a curve and an up vector
- static void LoftOnCurve(MeshCore::MeshKernel &ResultMesh,const TopoDS_Shape &Shape, const std::vector &poly,
- const Base::Vector3f & up = Base::Vector3f(0,0,1), float MaxSize = 0.1);
+ /// creates a mesh loft on base of a curve and an up vector
+ static void LoftOnCurve(MeshCore::MeshKernel& ResultMesh,
+ const TopoDS_Shape& Shape,
+ const std::vector& poly,
+ const Base::Vector3f& up = Base::Vector3f(0, 0, 1),
+ float MaxSize = 0.1);
- /*
- struct FaceSplitEdge
- {
- unsigned long ulFaceIndex;
- Base::Vector3f p1,p2;
- };
-
- static void projectCurve( MeshWithProperty* pMesh,
- const TopoDS_Edge& aEdge,
- const std::vector &rclPoints,
- std::vector &vSplitEdges);
-*/
- static void cutByCurve(MeshCore::MeshKernel* pMesh,const std::vector &vSplitEdges);
-/*
- static bool projectPointToMesh(MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,unsigned long &FaceIndex);
-*/
+ /*
+ struct FaceSplitEdge
+ {
+ unsigned long ulFaceIndex;
+ Base::Vector3f p1,p2;
+ };
+ static void projectCurve( MeshWithProperty* pMesh,
+ const TopoDS_Edge& aEdge,
+ const std::vector &rclPoints,
+ std::vector &vSplitEdges);
+ */
+ static void cutByCurve(MeshCore::MeshKernel* pMesh,
+ const std::vector& vSplitEdges);
+ /*
+ static bool projectPointToMesh(MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f
+ &Rslt,unsigned long &FaceIndex);
+ */
};
-} // namespace MeshPart
+}// namespace MeshPart
#endif
diff --git a/src/Mod/MeshPart/App/MeshFlattening.h b/src/Mod/MeshPart/App/MeshFlattening.h
index 0ef9a6a16a..3b1d0c2a95 100644
--- a/src/Mod/MeshPart/App/MeshFlattening.h
+++ b/src/Mod/MeshPart/App/MeshFlattening.h
@@ -36,6 +36,7 @@
#include "MeshFlatteningNurbs.h"
+// clang-format off
using Vector3 = Eigen::Vector3d;
using Vector2 = Eigen::Vector2d;
@@ -75,5 +76,6 @@ public:
spMat A; // mapping between nurbs(poles) and mesh(vertices) computed with nurbs-basis-functions and uv_mesh
};
+// clang-format on
-#endif // MESHFLATTENING
+#endif// MESHFLATTENING
diff --git a/src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp b/src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp
index 7c332318ef..c77a6b9268 100644
--- a/src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp
+++ b/src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp
@@ -22,17 +22,23 @@
#include "PreCompiled.h"
#ifndef _PreComp_
-# include