1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0028630: Visualization, StdPrs_ShadedShape - do not create Poly_Connect without need

This commit is contained in:
kgv
2017-04-05 15:59:49 +03:00
committed by bugmaster
parent 4fecc3651c
commit 450c83adcf
7 changed files with 140 additions and 166 deletions

View File

@@ -186,11 +186,10 @@ namespace
// Determinant of transform matrix less then 0 means that mirror transform applied.
Standard_Boolean isMirrored = aTrsf.VectorialPart().Determinant() < 0;
Poly_Connect aPolyConnect (aT);
// Extracts vertices & normals from nodes
const TColgp_Array1OfPnt& aNodes = aT->Nodes();
const TColgp_Array1OfPnt2d& aUVNodes = aT->UVNodes();
StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect);
StdPrs_ToolTriangulatedShape::ComputeNormals (aFace, aT);
const TShort_Array1OfShortReal& aNormals = aT->Normals();
const Standard_ShortReal* aNormArr = &aNormals.First();

View File

@@ -131,15 +131,15 @@ Standard_Boolean StdPrs_ToolTriangulatedShape::IsClosed (const TopoDS_Shape& the
}
//=======================================================================
//function : Normal
//function : ComputeNormals
//purpose :
//=======================================================================
void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace,
Poly_Connect& thePolyConnect)
void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace,
const Handle(Poly_Triangulation)& theTris,
Poly_Connect& thePolyConnect)
{
const Handle(Poly_Triangulation)& aPolyTri = thePolyConnect.Triangulation();
if (aPolyTri.IsNull()
|| aPolyTri->HasNormals())
if (theTris.IsNull()
|| theTris->HasNormals())
{
return;
}
@@ -148,13 +148,13 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace,
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()
Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, theTris->NbNodes() * 3);
const Poly_Array1OfTriangle& aTriangles = theTris->Triangles();
const TColgp_Array1OfPnt2d* aNodesUV = theTris->HasUVNodes() && !aSurf.IsNull()
? &theTris->UVNodes()
: NULL;
Standard_Integer aTri[3];
const TColgp_Array1OfPnt& aNodes = aPolyTri->Nodes();
const TColgp_Array1OfPnt& aNodes = theTris->Nodes();
gp_Dir aNorm;
for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
{
@@ -162,6 +162,11 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace,
if (aNodesUV == NULL
|| GeomLib::NormEstim (aSurf, aNodesUV->Value (aNodeIter), aTol, aNorm) > 1)
{
if (thePolyConnect.Triangulation() != theTris)
{
thePolyConnect.Load (theTris);
}
// compute flat normals
gp_XYZ eqPlan (0.0, 0.0, 0.0);
for (thePolyConnect.Initialize (aNodeIter); thePolyConnect.More(); thePolyConnect.Next())
@@ -185,7 +190,7 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace,
aNormals->SetValue (anId + 2, (Standard_ShortReal )aNorm.Y());
aNormals->SetValue (anId + 3, (Standard_ShortReal )aNorm.Z());
}
aPolyTri->SetNormals (aNormals);
theTris->SetNormals (aNormals);
}
//=======================================================================
@@ -199,7 +204,7 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace,
const Handle(Poly_Triangulation)& aPolyTri = thePolyConnect.Triangulation();
if (!aPolyTri->HasNormals())
{
Normal (theFace, thePolyConnect);
ComputeNormals (theFace, aPolyTri, thePolyConnect);
}
const TColgp_Array1OfPnt& aNodes = aPolyTri->Nodes();

View File

@@ -14,6 +14,7 @@
#ifndef _StdPrs_ToolTriangulatedShape_HeaderFile
#define _StdPrs_ToolTriangulatedShape_HeaderFile
#include <Poly_Connect.hxx>
#include <Poly_Triangulation.hxx>
#include <Prs3d_Drawer.hxx>
#include <Standard.hxx>
@@ -42,9 +43,22 @@ public:
//! Computes nodal normals for Poly_Triangulation structure using UV coordinates and surface.
//! Does nothing if triangulation already defines normals.
//! @param theFace [in] the face
//! @param thePolyConnect [in] the definition of a face triangulation
Standard_EXPORT static void Normal (const TopoDS_Face& theFace,
Poly_Connect& thePolyConnect);
//! @param theTris [in] the definition of a face triangulation
static void ComputeNormals (const TopoDS_Face& theFace,
const Handle(Poly_Triangulation)& theTris)
{
Poly_Connect aPolyConnect;
ComputeNormals (theFace, theTris, aPolyConnect);
}
//! Computes nodal normals for Poly_Triangulation structure using UV coordinates and surface.
//! Does nothing if triangulation already defines normals.
//! @param theFace [in] the face
//! @param theTris [in] the definition of a face triangulation
//! @param thePolyConnect [in,out] optional, initialized tool for exploring triangulation
Standard_EXPORT static void ComputeNormals (const TopoDS_Face& theFace,
const Handle(Poly_Triangulation)& theTris,
Poly_Connect& thePolyConnect);
//! Evaluate normals for a triangle of a face.
//! @param theFace [in] the face.