From c2bda2f75684ed8bb64813d4a92a5a595181f556 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 2 Sep 2023 01:36:21 +0200 Subject: [PATCH] MeshPart: apply clang format --- src/Mod/MeshPart/App/AppMeshPart.cpp | 7 +- src/Mod/MeshPart/App/AppMeshPartPy.cpp | 12 +- src/Mod/MeshPart/App/CurveProjector.cpp | 1015 +++++++++-------- src/Mod/MeshPart/App/CurveProjector.h | 172 +-- src/Mod/MeshPart/App/MeshAlgos.cpp | 748 ++++++------ src/Mod/MeshPart/App/MeshAlgos.h | 95 +- src/Mod/MeshPart/App/MeshFlattening.h | 4 +- .../App/MeshFlatteningBoostPython.cpp | 28 +- .../MeshPart/App/MeshFlatteningLscmRelax.cpp | 16 +- .../MeshPart/App/MeshFlatteningLscmRelax.h | 2 + src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp | 6 +- src/Mod/MeshPart/App/MeshFlatteningNurbs.h | 2 + src/Mod/MeshPart/App/MeshFlatteningPy.cpp | 2 + src/Mod/MeshPart/App/Mesher.cpp | 381 ++++--- src/Mod/MeshPart/App/Mesher.h | 203 +++- src/Mod/MeshPart/App/PreCompiled.h | 22 +- 16 files changed, 1469 insertions(+), 1246 deletions(-) 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 -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include #endif // boost is purposely not in the precompiled headers, see // https://github.com/FreeCAD/FreeCAD/pull/7979#issuecomment-1358123252 +#include +#include +#include +#include +#include +#include #include #include #include @@ -40,18 +46,13 @@ #include #include #include -#include -#include -#include -#include -#include -#include #include "MeshFlattening.h" #include "MeshFlatteningLscmRelax.h" #include "MeshFlatteningNurbs.h" +// clang-format off namespace py = boost::python; const TopoDS_Face& getTopoDSFace(const py::object& face) @@ -261,3 +262,4 @@ BOOST_PYTHON_MODULE(flatmesh) fm::eigen_matrix>::to_python_converter(); fm::eigen_matrix>::to_python_converter(); } +// clang-format on diff --git a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp index e462d76e9a..025d81416c 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp +++ b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp @@ -22,16 +22,16 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include #endif #ifndef M_PI -# define M_PI 3.14159265358979323846f +#define M_PI 3.14159265358979323846f #endif #include @@ -43,6 +43,7 @@ // area constrained (scale the final unwrapped mesh to the original area) // FEM approach +// clang-format off namespace lscmrelax { @@ -715,3 +716,4 @@ Eigen::MatrixXd LscmRelax::get_nullspace() } +// clang-format on diff --git a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h index 1874a793d3..27d9abbf28 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h +++ b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h @@ -21,6 +21,7 @@ ***************************************************************************/ +// clang-format off // LeastSquareConformalMapping + fem relaxing // ------------------------------------------ // @@ -123,3 +124,4 @@ public: } #endif +// clang-format on diff --git a/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp b/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp index db35df9087..03e28a57fc 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp +++ b/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp @@ -22,13 +22,14 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include "MeshFlatteningNurbs.h" +// clang-format off namespace nurbs{ double divide(double a, double b) @@ -516,3 +517,4 @@ Eigen::VectorXd NurbsBase1D::getUMesh(int num_u_points) } +// clang-format on diff --git a/src/Mod/MeshPart/App/MeshFlatteningNurbs.h b/src/Mod/MeshPart/App/MeshFlatteningNurbs.h index dd4929f434..7a963a87a5 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningNurbs.h +++ b/src/Mod/MeshPart/App/MeshFlatteningNurbs.h @@ -20,6 +20,7 @@ * * ***************************************************************************/ +// clang-format off #ifndef NURBS_H #define NURBS_H @@ -115,3 +116,4 @@ struct NurbsBase1D } #endif +// clang-format on diff --git a/src/Mod/MeshPart/App/MeshFlatteningPy.cpp b/src/Mod/MeshPart/App/MeshFlatteningPy.cpp index 8ba715cb26..700aba7f23 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningPy.cpp +++ b/src/Mod/MeshPart/App/MeshFlatteningPy.cpp @@ -20,6 +20,7 @@ * * ***************************************************************************/ +// clang-format off #ifdef _MSC_VER # define strdup _strdup #endif @@ -162,3 +163,4 @@ PYBIND11_MODULE(flatmesh, m) .def_readonly("A", &FaceUnwrapper::A); }; +// clang-format on diff --git a/src/Mod/MeshPart/App/Mesher.cpp b/src/Mod/MeshPart/App/Mesher.cpp index ed023917d0..20f8b02be0 100644 --- a/src/Mod/MeshPart/App/Mesher.cpp +++ b/src/Mod/MeshPart/App/Mesher.cpp @@ -22,12 +22,12 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include -# include +#include +#include +#include +#include #endif #include @@ -40,47 +40,47 @@ #ifdef HAVE_SMESH #if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Woverloaded-virtual" -# pragma clang diagnostic ignored "-Wextra-semi" -#elif defined (__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wpedantic" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Woverloaded-virtual" +#pragma clang diagnostic ignored "-Wextra-semi" +#elif defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" #endif -#include -#include -#include #include +#include +#include +#include #if SMESH_VERSION_MAJOR < 7 #include #endif -#include -#include -#include -#include -#include #include +#include +#include +#include +#include #include -#include +#include #include #include +#include #include #include #if defined(HAVE_NETGEN) -#include #include +#include #include -#endif // HAVE_NETGEN +#endif// HAVE_NETGEN #if defined(__clang__) -# pragma clang diagnostic pop -#elif defined (__GNUC__) -# pragma GCC diagnostic pop +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop #endif -#endif // HAVE_SMESH +#endif// HAVE_SMESH using namespace MeshPart; @@ -94,8 +94,9 @@ MeshingOutput::MeshingOutput() int MeshingOutput::overflow(int c) { - if (c != EOF) + if (c != EOF) { buffer.push_back((char)c); + } return c; } @@ -108,7 +109,7 @@ int MeshingOutput::sync() std::string sub; if (pos != std::string::npos) { // chop the last newline - sub = buffer.substr(pos+3, buffer.size()-pos-4); + sub = buffer.substr(pos + 3, buffer.size() - pos - 4); } else { sub = buffer; @@ -122,16 +123,20 @@ int MeshingOutput::sync() // ---------------------------------------------------------------------------- -namespace MeshPart { +namespace MeshPart +{ -struct Vertex { +struct Vertex +{ static const double deflection; - Standard_Real x,y,z; + Standard_Real x, y, z; Standard_Integer i = 0; mutable MeshCore::MeshPoint p; Vertex(Standard_Real X, Standard_Real Y, Standard_Real Z) - : x(X),y(Y),z(Z) + : x(X) + , y(Y) + , z(Z) { p.x = static_cast(x); p.y = static_cast(y); @@ -143,15 +148,18 @@ struct Vertex { return p; } - bool operator < (const Vertex &v) const + bool operator<(const Vertex& v) const { - if (fabs ( this->x - v.x) >= deflection) + if (fabs(this->x - v.x) >= deflection) { return this->x < v.x; - if (fabs ( this->y - v.y) >= deflection) + } + if (fabs(this->y - v.y) >= deflection) { return this->y < v.y; - if (fabs ( this->z - v.z) >= deflection) + } + if (fabs(this->z - v.z) >= deflection) { return this->z < v.z; - return false; // points are considered to be equal + } + return false;// points are considered to be equal } }; @@ -159,20 +167,21 @@ const double Vertex::deflection = gp::Resolution(); // ---------------------------------------------------------------------------- -class BrepMesh { +class BrepMesh +{ bool segments; std::vector colors; + public: BrepMesh(bool s, const std::vector& c) : segments(s) , colors(c) - { - } + {} Mesh::MeshObject* create(const std::vector& domains) const { - std::map > colorMap; - for (std::size_t i=0; i> colorMap; + for (std::size_t i = 0; i < colors.size(); i++) { colorMap[colors[i]].push_back(i); } @@ -180,8 +189,9 @@ public: MeshCore::MeshFacetArray faces; std::size_t numTriangles = 0; - for (const auto& it : domains) + for (const auto& it : domains) { numTriangles += it.facets.size(); + } faces.reserve(numTriangles); std::set vertices; @@ -189,7 +199,7 @@ public: Standard_Real x2, y2, z2; Standard_Real x3, y3, z3; - std::vector< std::vector > meshSegments; + std::vector> meshSegments; std::size_t numMeshFaces = 0; for (const auto& domain : domains) { @@ -212,7 +222,7 @@ public: MeshCore::MeshFacet face; // 1st vertex - Vertex v1(x1,y1,z1); + Vertex v1(x1, y1, z1); it = vertices.find(v1); if (it == vertices.end()) { v1.i = vertices.size(); @@ -224,7 +234,7 @@ public: } // 2nd vertex - Vertex v2(x2,y2,z2); + Vertex v2(x2, y2, z2); it = vertices.find(v2); if (it == vertices.end()) { v2.i = vertices.size(); @@ -236,7 +246,7 @@ public: } // 3rd vertex - Vertex v3(x3,y3,z3); + Vertex v3(x3, y3, z3); it = vertices.find(v3); if (it == vertices.end()) { v3.i = vertices.size(); @@ -248,9 +258,9 @@ public: } // make sure that we don't insert invalid facets - if (face._aulPoints[0] != face._aulPoints[1] && - face._aulPoints[1] != face._aulPoints[2] && - face._aulPoints[2] != face._aulPoints[0]) { + if (face._aulPoints[0] != face._aulPoints[1] + && face._aulPoints[1] != face._aulPoints[2] + && face._aulPoints[2] != face._aulPoints[0]) { faces.push_back(face); numDomainFaces++; } @@ -259,7 +269,9 @@ public: // add a segment for the face if (createSegm || this->segments) { std::vector segment(numDomainFaces); - std::generate(segment.begin(), segment.end(), Base::iotaGen(numMeshFaces)); + std::generate(segment.begin(), + segment.end(), + Base::iotaGen(numMeshFaces)); numMeshFaces += numDomainFaces; meshSegments.push_back(segment); } @@ -267,8 +279,9 @@ public: MeshCore::MeshPointArray verts; verts.resize(vertices.size()); - for (const auto& it : vertices) + for (const auto& it : vertices) { verts[it.i] = it.toPoint(); + } MeshCore::MeshKernel kernel; kernel.Adopt(verts, faces, true); @@ -300,14 +313,13 @@ public: return meshdata; } }; -} +}// namespace MeshPart // ---------------------------------------------------------------------------- Mesher::Mesher(const TopoDS_Shape& s) - : shape(s) -{ -} + : shape(s) +{} Mesher::~Mesher() = default; @@ -337,8 +349,9 @@ Mesh::MeshObject* Mesher::createMesh() const #else std::list hypoth; - if (!Mesher::_mesh_gen) + if (!Mesher::_mesh_gen) { Mesher::_mesh_gen = new SMESH_Gen(); + } SMESH_Gen* meshgen = Mesher::_mesh_gen; #if SMESH_VERSION_MAJOR >= 9 @@ -348,137 +361,147 @@ Mesh::MeshObject* Mesher::createMesh() const #endif - int hyp=0; + int hyp = 0; switch (method) { -#if defined (HAVE_NETGEN) - case Netgen: { +#if defined(HAVE_NETGEN) + case Netgen: { #if SMESH_VERSION_MAJOR >= 9 - NETGENPlugin_Hypothesis_2D* hyp2d = new NETGENPlugin_Hypothesis_2D(hyp++,meshgen); + NETGENPlugin_Hypothesis_2D* hyp2d = new NETGENPlugin_Hypothesis_2D(hyp++, meshgen); #else - NETGENPlugin_Hypothesis_2D* hyp2d = new NETGENPlugin_Hypothesis_2D(hyp++,0,meshgen); + NETGENPlugin_Hypothesis_2D* hyp2d = new NETGENPlugin_Hypothesis_2D(hyp++, 0, meshgen); #endif - if (fineness >=0 && fineness < 5) { - hyp2d->SetFineness(NETGENPlugin_Hypothesis_2D::Fineness(fineness)); - } - // user defined values - else { - if (growthRate > 0) - hyp2d->SetGrowthRate(growthRate); - if (nbSegPerEdge > 0) - hyp2d->SetNbSegPerEdge(nbSegPerEdge); - if (nbSegPerRadius > 0) - hyp2d->SetNbSegPerRadius(nbSegPerRadius); - } + if (fineness >= 0 && fineness < 5) { + hyp2d->SetFineness(NETGENPlugin_Hypothesis_2D::Fineness(fineness)); + } + // user defined values + else { + if (growthRate > 0) { + hyp2d->SetGrowthRate(growthRate); + } + if (nbSegPerEdge > 0) { + hyp2d->SetNbSegPerEdge(nbSegPerEdge); + } + if (nbSegPerRadius > 0) { + hyp2d->SetNbSegPerRadius(nbSegPerRadius); + } + } - if (maxLen > 0) - hyp2d->SetMaxSize(maxLen); - if (minLen > 0) - hyp2d->SetMinSize(minLen); + if (maxLen > 0) { + hyp2d->SetMaxSize(maxLen); + } + if (minLen > 0) { + hyp2d->SetMinSize(minLen); + } - hyp2d->SetQuadAllowed(allowquad); - hyp2d->SetOptimize(optimize); - hyp2d->SetSecondOrder(secondOrder); // apply bisecting to create four triangles out of one - hypoth.push_back(hyp2d); - -#if SMESH_VERSION_MAJOR >= 9 - NETGENPlugin_NETGEN_2D* alg2d = new NETGENPlugin_NETGEN_2D(hyp++,meshgen); -#else - NETGENPlugin_NETGEN_2D* alg2d = new NETGENPlugin_NETGEN_2D(hyp++,0,meshgen); -#endif - hypoth.push_back(alg2d); - } break; -#endif -#if defined (HAVE_MEFISTO) - case Mefisto: { - if (maxLength > 0) { -#if SMESH_VERSION_MAJOR >= 9 - StdMeshers_MaxLength* hyp1d = new StdMeshers_MaxLength(hyp++, meshgen); -#else - StdMeshers_MaxLength* hyp1d = new StdMeshers_MaxLength(hyp++, 0, meshgen); -#endif - hyp1d->SetLength(maxLength); - hypoth.push_back(hyp1d); - } - else if (localLength > 0) { -#if SMESH_VERSION_MAJOR >= 9 - StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(hyp++,meshgen); -#else - StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(hyp++,0,meshgen); -#endif - hyp1d->SetLength(localLength); - hypoth.push_back(hyp1d); - } - else if (maxArea > 0) { -#if SMESH_VERSION_MAJOR >= 9 - StdMeshers_MaxElementArea* hyp2d = new StdMeshers_MaxElementArea(hyp++,meshgen); -#else - StdMeshers_MaxElementArea* hyp2d = new StdMeshers_MaxElementArea(hyp++,0,meshgen); -#endif - hyp2d->SetMaxArea(maxArea); + hyp2d->SetQuadAllowed(allowquad); + hyp2d->SetOptimize(optimize); + hyp2d->SetSecondOrder( + secondOrder);// apply bisecting to create four triangles out of one hypoth.push_back(hyp2d); - } - else if (deflection > 0) { -#if SMESH_VERSION_MAJOR >= 9 - StdMeshers_Deflection1D* hyp1d = new StdMeshers_Deflection1D(hyp++,meshgen); -#else - StdMeshers_Deflection1D* hyp1d = new StdMeshers_Deflection1D(hyp++,0,meshgen); -#endif - hyp1d->SetDeflection(deflection); - hypoth.push_back(hyp1d); - } - else if (minLen > 0 && maxLen > 0) { -#if SMESH_VERSION_MAJOR >= 9 - StdMeshers_Arithmetic1D* hyp1d = new StdMeshers_Arithmetic1D(hyp++,meshgen); -#else - StdMeshers_Arithmetic1D* hyp1d = new StdMeshers_Arithmetic1D(hyp++,0,meshgen); -#endif - hyp1d->SetLength(minLen, false); - hyp1d->SetLength(maxLen, true); - hypoth.push_back(hyp1d); - } - else { -#if SMESH_VERSION_MAJOR >= 9 - StdMeshers_AutomaticLength* hyp1d = new StdMeshers_AutomaticLength(hyp++,meshgen); -#else - StdMeshers_AutomaticLength* hyp1d = new StdMeshers_AutomaticLength(hyp++,0,meshgen); -#endif - hypoth.push_back(hyp1d); - } - { #if SMESH_VERSION_MAJOR >= 9 - StdMeshers_NumberOfSegments* hyp1d = new StdMeshers_NumberOfSegments(hyp++,meshgen); + NETGENPlugin_NETGEN_2D* alg2d = new NETGENPlugin_NETGEN_2D(hyp++, meshgen); #else - StdMeshers_NumberOfSegments* hyp1d = new StdMeshers_NumberOfSegments(hyp++,0,meshgen); + NETGENPlugin_NETGEN_2D* alg2d = new NETGENPlugin_NETGEN_2D(hyp++, 0, meshgen); #endif - hyp1d->SetNumberOfSegments(1); - hypoth.push_back(hyp1d); - } + hypoth.push_back(alg2d); + } break; +#endif +#if defined(HAVE_MEFISTO) + case Mefisto: { + if (maxLength > 0) { +#if SMESH_VERSION_MAJOR >= 9 + StdMeshers_MaxLength* hyp1d = new StdMeshers_MaxLength(hyp++, meshgen); +#else + StdMeshers_MaxLength* hyp1d = new StdMeshers_MaxLength(hyp++, 0, meshgen); +#endif + hyp1d->SetLength(maxLength); + hypoth.push_back(hyp1d); + } + else if (localLength > 0) { +#if SMESH_VERSION_MAJOR >= 9 + StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(hyp++, meshgen); +#else + StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(hyp++, 0, meshgen); +#endif + hyp1d->SetLength(localLength); + hypoth.push_back(hyp1d); + } + else if (maxArea > 0) { +#if SMESH_VERSION_MAJOR >= 9 + StdMeshers_MaxElementArea* hyp2d = new StdMeshers_MaxElementArea(hyp++, meshgen); +#else + StdMeshers_MaxElementArea* hyp2d = new StdMeshers_MaxElementArea(hyp++, 0, meshgen); +#endif + hyp2d->SetMaxArea(maxArea); + hypoth.push_back(hyp2d); + } + else if (deflection > 0) { +#if SMESH_VERSION_MAJOR >= 9 + StdMeshers_Deflection1D* hyp1d = new StdMeshers_Deflection1D(hyp++, meshgen); +#else + StdMeshers_Deflection1D* hyp1d = new StdMeshers_Deflection1D(hyp++, 0, meshgen); +#endif + hyp1d->SetDeflection(deflection); + hypoth.push_back(hyp1d); + } + else if (minLen > 0 && maxLen > 0) { +#if SMESH_VERSION_MAJOR >= 9 + StdMeshers_Arithmetic1D* hyp1d = new StdMeshers_Arithmetic1D(hyp++, meshgen); +#else + StdMeshers_Arithmetic1D* hyp1d = new StdMeshers_Arithmetic1D(hyp++, 0, meshgen); +#endif + hyp1d->SetLength(minLen, false); + hyp1d->SetLength(maxLen, true); + hypoth.push_back(hyp1d); + } + else { +#if SMESH_VERSION_MAJOR >= 9 + StdMeshers_AutomaticLength* hyp1d = new StdMeshers_AutomaticLength(hyp++, meshgen); +#else + StdMeshers_AutomaticLength* hyp1d = + new StdMeshers_AutomaticLength(hyp++, 0, meshgen); +#endif + hypoth.push_back(hyp1d); + } - if (regular) { + { #if SMESH_VERSION_MAJOR >= 9 - StdMeshers_Regular_1D* hyp1d = new StdMeshers_Regular_1D(hyp++,meshgen); + StdMeshers_NumberOfSegments* hyp1d = + new StdMeshers_NumberOfSegments(hyp++, meshgen); #else - StdMeshers_Regular_1D* hyp1d = new StdMeshers_Regular_1D(hyp++,0,meshgen); + StdMeshers_NumberOfSegments* hyp1d = + new StdMeshers_NumberOfSegments(hyp++, 0, meshgen); #endif - hypoth.push_back(hyp1d); - } + hyp1d->SetNumberOfSegments(1); + hypoth.push_back(hyp1d); + } + + if (regular) { +#if SMESH_VERSION_MAJOR >= 9 + StdMeshers_Regular_1D* hyp1d = new StdMeshers_Regular_1D(hyp++, meshgen); +#else + StdMeshers_Regular_1D* hyp1d = new StdMeshers_Regular_1D(hyp++, 0, meshgen); +#endif + hypoth.push_back(hyp1d); + } #if SMESH_VERSION_MAJOR < 7 - StdMeshers_TrianglePreference* hyp2d_1 = new StdMeshers_TrianglePreference(hyp++,0,meshgen); - hypoth.push_back(hyp2d_1); + StdMeshers_TrianglePreference* hyp2d_1 = + new StdMeshers_TrianglePreference(hyp++, 0, meshgen); + hypoth.push_back(hyp2d_1); #endif #if SMESH_VERSION_MAJOR >= 9 - StdMeshers_MEFISTO_2D* alg2d = new StdMeshers_MEFISTO_2D(hyp++,meshgen); + StdMeshers_MEFISTO_2D* alg2d = new StdMeshers_MEFISTO_2D(hyp++, meshgen); #else - StdMeshers_MEFISTO_2D* alg2d = new StdMeshers_MEFISTO_2D(hyp++,0,meshgen); + StdMeshers_MEFISTO_2D* alg2d = new StdMeshers_MEFISTO_2D(hyp++, 0, meshgen); #endif - hypoth.push_back(alg2d); - } break; + hypoth.push_back(alg2d); + } break; #endif - default: - break; + default: + break; } // Set new cout @@ -487,8 +510,9 @@ Mesh::MeshObject* Mesher::createMesh() const // Apply the hypothesis and create the mesh mesh->ShapeToMesh(shape); - for (int i=0; iAddHypothesis(shape, i); + } meshgen->Compute(*mesh, mesh->GetShapeToMesh()); // Restore old cout @@ -502,11 +526,12 @@ Mesh::MeshObject* Mesher::createMesh() const mesh->ShapeToMesh(aNull); mesh->Clear(); delete mesh; - for (auto it : hypoth) + for (auto it : hypoth) { delete it; + } return meshdata; -#endif // HAVE_SMESH +#endif// HAVE_SMESH } Mesh::MeshObject* Mesher::createFrom(SMESH_Mesh* mesh) const @@ -520,9 +545,9 @@ Mesh::MeshObject* Mesher::createFrom(SMESH_Mesh* mesh) const verts.reserve(mesh->NbNodes()); faces.reserve(mesh->NbFaces()); - int index=0; + int index = 0; std::map mapNodeIndex; - for (;aNodeIter->more();) { + for (; aNodeIter->more();) { const SMDS_MeshNode* aNode = aNodeIter->next(); MeshCore::MeshPoint p; p.Set((float)aNode->X(), (float)aNode->Y(), (float)aNode->Z()); @@ -530,11 +555,11 @@ Mesh::MeshObject* Mesher::createFrom(SMESH_Mesh* mesh) const mapNodeIndex[aNode] = index++; } - for (;aFaceIter->more();) { + for (; aFaceIter->more();) { const SMDS_MeshFace* aFace = aFaceIter->next(); if (aFace->NbNodes() == 3) { MeshCore::MeshFacet f; - for (int i=0; i<3;i++) { + for (int i = 0; i < 3; i++) { const SMDS_MeshNode* node = aFace->GetNode(i); f._aulPoints[i] = mapNodeIndex[node]; } @@ -617,12 +642,12 @@ Mesh::MeshObject* Mesher::createFrom(SMESH_Mesh* mesh) const // Two solutions are possible: // <4,6,7>, <4,5,6> or <4,5,7>, <5,6,7> - Base::Vector3d v4(node4->X(),node4->Y(),node4->Z()); - Base::Vector3d v5(node5->X(),node5->Y(),node5->Z()); - Base::Vector3d v6(node6->X(),node6->Y(),node6->Z()); - Base::Vector3d v7(node7->X(),node7->Y(),node7->Z()); - double dist46 = Base::DistanceP2(v4,v6); - double dist57 = Base::DistanceP2(v5,v7); + Base::Vector3d v4(node4->X(), node4->Y(), node4->Z()); + Base::Vector3d v5(node5->X(), node5->Y(), node5->Z()); + Base::Vector3d v6(node6->X(), node6->Y(), node6->Z()); + Base::Vector3d v7(node7->X(), node7->Y(), node7->Z()); + double dist46 = Base::DistanceP2(v4, v6); + double dist57 = Base::DistanceP2(v5, v7); if (dist46 > dist57) { f5._aulPoints[0] = mapNodeIndex[node4]; f5._aulPoints[1] = mapNodeIndex[node6]; diff --git a/src/Mod/MeshPart/App/Mesher.h b/src/Mod/MeshPart/App/Mesher.h index 6cb979260a..14f6f95aeb 100644 --- a/src/Mod/MeshPart/App/Mesher.h +++ b/src/Mod/MeshPart/App/Mesher.h @@ -28,23 +28,28 @@ #include #ifdef HAVE_SMESH -# include +#include #endif class TopoDS_Shape; class SMESH_Gen; class SMESH_Mesh; -namespace Mesh { class MeshObject; } -namespace MeshPart { +namespace Mesh +{ +class MeshObject; +} +namespace MeshPart +{ class Mesher { public: - enum Method { + enum Method + { None = 0, Mefisto = 1, -#if defined (HAVE_NETGEN) +#if defined(HAVE_NETGEN) Netgen = 2, #endif Standard = 3 @@ -54,83 +59,155 @@ public: ~Mesher(); void setMethod(Method m) - { method = m; } + { + method = m; + } Method getMethod() const - { return method; } + { + return method; + } /** @name Mefisto settings */ //@{ void setMaxLength(double s) - { maxLength = s; } + { + maxLength = s; + } double getMaxLength() const - { return maxLength; } + { + return maxLength; + } void setMaxArea(double s) - { maxArea = s; } + { + maxArea = s; + } double getMaxArea() const - { return maxArea; } + { + return maxArea; + } void setLocalLength(double s) - { localLength = s; } + { + localLength = s; + } double getLocalLength() const - { return localLength; } + { + return localLength; + } void setDeflection(double s) - { deflection = s; } + { + deflection = s; + } double getDeflection() const - { return deflection; } + { + return deflection; + } void setAngularDeflection(double s) - { angularDeflection = s; } + { + angularDeflection = s; + } double getAngularDeflection() const - { return angularDeflection; } + { + return angularDeflection; + } void setMinMaxLengths(double f, double l) - { minLen = f; maxLen = l; } + { + minLen = f; + maxLen = l; + } void getMinMaxLengths(double& f, double& l) const - { f = minLen; l= maxLen; } + { + f = minLen; + l = maxLen; + } void setRegular(bool s) - { regular = s; } + { + regular = s; + } bool isRegular() const - { return regular; } + { + return regular; + } void setRelative(bool s) - { relative = s; } + { + relative = s; + } bool isRelative() const - { return relative; } + { + return relative; + } void setSegments(bool s) - { segments = s; } + { + segments = s; + } bool isSegments() const - { return segments; } + { + return segments; + } void setColors(const std::vector& c) - { colors = c; } + { + colors = c; + } //@} -#if defined (HAVE_NETGEN) +#if defined(HAVE_NETGEN) /** @name Netgen settings */ //@{ void setFineness(int s) - { fineness = s; } + { + fineness = s; + } int getFineness() const - { return fineness; } + { + return fineness; + } void setGrowthRate(double r) - { growthRate = r; } + { + growthRate = r; + } double getGrowthRate() const - { return growthRate; } + { + return growthRate; + } void setNbSegPerEdge(double v) - { nbSegPerEdge = v;} + { + nbSegPerEdge = v; + } double getNbSegPerEdge() const - { return nbSegPerEdge; } + { + return nbSegPerEdge; + } void setNbSegPerRadius(double v) - { nbSegPerRadius = v; } + { + nbSegPerRadius = v; + } double getNbSegPerRadius() const - { return nbSegPerRadius; } + { + return nbSegPerRadius; + } void setSecondOrder(bool on) - { secondOrder = on; } + { + secondOrder = on; + } bool getSecondOrder() const - { return secondOrder; } + { + return secondOrder; + } void setOptimize(bool on) - { optimize = on;} + { + optimize = on; + } bool getOptimize() const - { return optimize; } + { + return optimize; + } void setQuadAllowed(bool on) - { allowquad = on;} + { + allowquad = on; + } bool isQuadAllowed() const - { return allowquad; } + { + return allowquad; + } //@} #endif @@ -142,31 +219,31 @@ private: private: const TopoDS_Shape& shape; - Method method{None}; - double maxLength{0}; - double maxArea{0}; - double localLength{0}; - double deflection{0}; - double angularDeflection{0.5}; - double minLen{0}, maxLen{0}; - bool relative{false}; - bool regular{false}; - bool segments{false}; -#if defined (HAVE_NETGEN) - int fineness{5}; - double growthRate{0}; - double nbSegPerEdge{0}; - double nbSegPerRadius{0}; - bool secondOrder{false}; - bool optimize{true}; - bool allowquad{false}; + Method method {None}; + double maxLength {0}; + double maxArea {0}; + double localLength {0}; + double deflection {0}; + double angularDeflection {0.5}; + double minLen {0}, maxLen {0}; + bool relative {false}; + bool regular {false}; + bool segments {false}; +#if defined(HAVE_NETGEN) + int fineness {5}; + double growthRate {0}; + double nbSegPerEdge {0}; + double nbSegPerRadius {0}; + bool secondOrder {false}; + bool optimize {true}; + bool allowquad {false}; #endif std::vector colors; - static SMESH_Gen *_mesh_gen; + static SMESH_Gen* _mesh_gen; }; -class MeshingOutput : public std::streambuf +class MeshingOutput: public std::streambuf { public: MeshingOutput(); @@ -179,6 +256,6 @@ private: std::string buffer; }; -} // namespace MeshPart +}// namespace MeshPart -#endif // MESHPART_MESHER_H +#endif// MESHPART_MESHER_H diff --git a/src/Mod/MeshPart/App/PreCompiled.h b/src/Mod/MeshPart/App/PreCompiled.h index 4b4917bf65..eff761a54d 100644 --- a/src/Mod/MeshPart/App/PreCompiled.h +++ b/src/Mod/MeshPart/App/PreCompiled.h @@ -26,10 +26,10 @@ #include #ifdef _MSC_VER -# pragma warning(disable : 4244) -# pragma warning(disable : 4275) -# pragma warning(disable : 4290) -# pragma warning(disable : 4522) +#pragma warning(disable : 4244) +#pragma warning(disable : 4275) +#pragma warning(disable : 4290) +#pragma warning(disable : 4522) #endif #ifdef _PreComp_ @@ -49,24 +49,23 @@ #include // OpenCasCade -#include -#include -#include #include #include #include #include #include #include +#include +#include +#include #include -#include #include +#include +#include #include #include #include #include -#include -#include #include #include #include @@ -77,6 +76,7 @@ #include #include #include +#include -#endif // _PreComp_ +#endif// _PreComp_ #endif