From 9aa287ba7bedd1bc7c7b906e3cc5533127da94bc Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 8 Oct 2021 19:34:48 +0200 Subject: [PATCH] Part: remove ViewProviderPartExt::getNormals --- src/Mod/Part/Gui/ViewProviderExt.cpp | 91 +------------------ src/Mod/Part/Gui/ViewProviderExt.h | 2 - src/Mod/PartDesign/Gui/ViewProviderAddSub.cpp | 5 +- 3 files changed, 5 insertions(+), 93 deletions(-) diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index ba197f1811..77cefbe3e0 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -125,6 +125,7 @@ #include #include +#include FC_LOG_LEVEL_INIT("Part", true, true) @@ -133,94 +134,6 @@ using namespace PartGui; PROPERTY_SOURCE(PartGui::ViewProviderPartExt, Gui::ViewProviderGeometryObject) -void ViewProviderPartExt::getNormals(const TopoDS_Face& theFace, - const Handle(Poly_Triangulation)& aPolyTri, - TColgp_Array1OfDir& theNormals) -{ - const TColgp_Array1OfPnt& aNodes = aPolyTri->Nodes(); - - if(aPolyTri->HasNormals()) - { - // normals pre-computed in triangulation structure - const TShort_Array1OfShortReal& aNormals = aPolyTri->Normals(); - const Standard_ShortReal* aNormArr = &(aNormals.Value(aNormals.Lower())); - - for(Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) - { - const Standard_Integer anId = 3 * (aNodeIter - aNodes.Lower()); - const gp_Dir aNorm(aNormArr[anId + 0], - aNormArr[anId + 1], - aNormArr[anId + 2]); - theNormals(aNodeIter) = aNorm; - } - - if(theFace.Orientation() == TopAbs_REVERSED) - { - for(Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) - { - theNormals.ChangeValue(aNodeIter).Reverse(); - } - } - - return; - } - - // take in face the surface location - Poly_Connect thePolyConnect(aPolyTri); - const TopoDS_Face aZeroFace = TopoDS::Face(theFace.Located(TopLoc_Location())); - Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aZeroFace); - const Standard_Real aTol = Precision::Confusion(); - Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal(1, aPolyTri->NbNodes() * 3); - const Poly_Array1OfTriangle& aTriangles = aPolyTri->Triangles(); - const TColgp_Array1OfPnt2d* aNodesUV = aPolyTri->HasUVNodes() && !aSurf.IsNull() - ? &aPolyTri->UVNodes() - : NULL; - Standard_Integer aTri[3]; - - for(Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) - { - // try to retrieve normal from real surface first, when UV coordinates are available - if(aNodesUV == NULL - || GeomLib::NormEstim(aSurf, aNodesUV->Value(aNodeIter), aTol, theNormals(aNodeIter)) > 1) - { - // compute flat normals - gp_XYZ eqPlan(0.0, 0.0, 0.0); - - for(thePolyConnect.Initialize(aNodeIter); thePolyConnect.More(); thePolyConnect.Next()) - { - aTriangles(thePolyConnect.Value()).Get(aTri[0], aTri[1], aTri[2]); - const gp_XYZ v1(aNodes(aTri[1]).Coord() - aNodes(aTri[0]).Coord()); - const gp_XYZ v2(aNodes(aTri[2]).Coord() - aNodes(aTri[1]).Coord()); - const gp_XYZ vv = v1 ^ v2; - const Standard_Real aMod = vv.Modulus(); - - if(aMod >= aTol) - { - eqPlan += vv / aMod; - } - } - - const Standard_Real aModMax = eqPlan.Modulus(); - theNormals(aNodeIter) = (aModMax > aTol) ? gp_Dir(eqPlan) : gp::DZ(); - } - - const Standard_Integer anId = (aNodeIter - aNodes.Lower()) * 3; - aNormals->SetValue(anId + 1, (Standard_ShortReal)theNormals(aNodeIter).X()); - aNormals->SetValue(anId + 2, (Standard_ShortReal)theNormals(aNodeIter).Y()); - aNormals->SetValue(anId + 3, (Standard_ShortReal)theNormals(aNodeIter).Z()); - } - - aPolyTri->SetNormals(aNormals); - - if(theFace.Orientation() == TopAbs_REVERSED) - { - for(Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) - { - theNormals.ChangeValue(aNodeIter).Reverse(); - } - } -} - //************************************************************************** // Construction/Destruction @@ -1174,7 +1087,7 @@ void ViewProviderPartExt::updateVisual() const TColgp_Array1OfPnt& Nodes = mesh->Nodes(); TColgp_Array1OfDir Normals (Nodes.Lower(), Nodes.Upper()); if (NormalsFromUV) - getNormals(actFace, mesh, Normals); + Part::Tools::getPointNormals(actFace, mesh, Normals); for (int g=1;g<=nbTriInFace;g++) { // Get the triangle diff --git a/src/Mod/Part/Gui/ViewProviderExt.h b/src/Mod/Part/Gui/ViewProviderExt.h index d890e9a716..2cb55c1873 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.h +++ b/src/Mod/Part/Gui/ViewProviderExt.h @@ -158,8 +158,6 @@ protected: virtual void onChanged(const App::Property* prop) override; bool loadParameter(); void updateVisual(); - void getNormals(const TopoDS_Face& theFace, const Handle(Poly_Triangulation)& aPolyTri, - TColgp_Array1OfDir& theNormals); // nodes for the data representation SoMaterialBinding * pcFaceBind; diff --git a/src/Mod/PartDesign/Gui/ViewProviderAddSub.cpp b/src/Mod/PartDesign/Gui/ViewProviderAddSub.cpp index 85bcf6e551..642eb9dc76 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderAddSub.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderAddSub.cpp @@ -40,7 +40,8 @@ #endif #include "ViewProviderAddSub.h" -#include "Mod/Part/Gui/SoBrepFaceSet.h" +#include +#include #include #include #include @@ -196,7 +197,7 @@ void ViewProviderAddSub::updateAddSubShapeIndicator() { const Poly_Array1OfTriangle& Triangles = mesh->Triangles(); const TColgp_Array1OfPnt& Nodes = mesh->Nodes(); TColgp_Array1OfDir Normals (Nodes.Lower(), Nodes.Upper()); - getNormals(actFace, mesh, Normals); + Part::Tools::getPointNormals(actFace, mesh, Normals); for (int g=1;g<=nbTriInFace;g++) { // Get the triangle