Part: remove ViewProviderPartExt::getNormals
This commit is contained in:
@@ -125,6 +125,7 @@
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/Part/App/PrimitiveFeature.h>
|
||||
#include <Mod/Part/App/Tools.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
#endif
|
||||
|
||||
#include "ViewProviderAddSub.h"
|
||||
#include "Mod/Part/Gui/SoBrepFaceSet.h"
|
||||
#include <Mod/Part/Gui/SoBrepFaceSet.h>
|
||||
#include <Mod/Part/App/Tools.h>
|
||||
#include <Mod/PartDesign/App/FeatureAddSub.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
#include <Gui/Control.h>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user