From fd76595d64eb8b77a4a379622538ba32d6d8e1f8 Mon Sep 17 00:00:00 2001 From: vro Date: Mon, 15 Feb 2021 14:27:53 +0300 Subject: [PATCH] 0025936: Modeling Data - reusable data structure for 2D tesselation (3- and 4-nodal mesh) // Fixed a twice-reverse of normals (revealed in bugs vis... tests). --- src/Poly/Poly.cxx | 9 ++++++--- src/Poly/Poly_CoherentTriangulation.cxx | 4 ++-- src/Poly/Poly_Triangulation.hxx | 2 +- src/RWObj/RWObj_TriangulationReader.cxx | 1 - src/Select3D/Select3D_SensitiveTriangulation.cxx | 5 ++--- src/StdPrs/StdPrs_ShadedShape.cxx | 10 +++------- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Poly/Poly.cxx b/src/Poly/Poly.cxx index c163683aee..3b0b98db01 100644 --- a/src/Poly/Poly.cxx +++ b/src/Poly/Poly.cxx @@ -480,7 +480,6 @@ void Poly::ComputeNormals (const Handle(Poly_Triangulation)& theTri) } // Normalize all vectors - gp_Dir aNormal; gp_XYZ aNormXYZ; for (Standard_Integer aNodeIter = 0; aNodeIter < aNbNodes; ++aNodeIter) { @@ -488,9 +487,13 @@ void Poly::ComputeNormals (const Handle(Poly_Triangulation)& theTri) aNormXYZ.SetCoord (aNormArr[anIndex + 0], aNormArr[anIndex + 1], aNormArr[anIndex + 2]); const Standard_Real aMod2 = aNormXYZ.SquareModulus(); if (aMod2 > anEps2) - aNormal = aNormXYZ; + { + aNormXYZ /= Sqrt (aMod2); + } else - aNormal = gp::DZ(); + { + aNormXYZ = gp::DZ().XYZ(); + } // Set normal. theTri->SetNormal (aNodeIter + 1, aNormXYZ); diff --git a/src/Poly/Poly_CoherentTriangulation.cxx b/src/Poly/Poly_CoherentTriangulation.cxx index 82cf42f4b4..4123041c50 100644 --- a/src/Poly/Poly_CoherentTriangulation.cxx +++ b/src/Poly/Poly_CoherentTriangulation.cxx @@ -126,6 +126,8 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const if (aNode.IsFreeNode()) vecNodeId.SetValue(i, 0); else { + vecNodeId.SetValue(i, ++aCount); + const gp_XYZ aNormal = aNode.GetNormal(); if (aNormal.SquareModulus() > Precision::Confusion()) { aResult->SetNormal (aCount, static_cast(aNormal.X()), @@ -133,9 +135,7 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const static_cast(aNormal.Z())); } - vecNodeId.SetValue(i, ++aCount); aResult->ChangeNode (aCount) = aNode; - aResult->ChangeUVNode (aCount) = gp_Pnt2d (aNode.GetU(), aNode.GetV()); if (aNode.GetU()*aNode.GetU() + aNode.GetV()*aNode.GetV() > Precision::Confusion()) diff --git a/src/Poly/Poly_Triangulation.hxx b/src/Poly/Poly_Triangulation.hxx index 7b0c8eb2d2..a5cc885b17 100644 --- a/src/Poly/Poly_Triangulation.hxx +++ b/src/Poly/Poly_Triangulation.hxx @@ -188,7 +188,7 @@ public: const Vec3f& theNormal) { // If an array for normals is not allocated yet, do it now. - if (myNormals.IsEmpty()) + if (myNormals.IsEmpty() || myNormals.Size() != myNodes.Size()) myNormals.Resize (1, myNodes.Size(), Standard_False); // Set a normal. diff --git a/src/RWObj/RWObj_TriangulationReader.cxx b/src/RWObj/RWObj_TriangulationReader.cxx index 912dce87fe..c4ef86170d 100644 --- a/src/RWObj/RWObj_TriangulationReader.cxx +++ b/src/RWObj/RWObj_TriangulationReader.cxx @@ -179,7 +179,6 @@ Handle(Poly_Triangulation) RWObj_TriangulationReader::GetTriangulation() { aPoly->SetNormal (aNodeIter + 1, 0.0f, 0.0f, 1.0f); } - aPoly->SetNormal (aNodeIter + 1, aNorm.x(), aNorm.y(), aNorm.z()); } } diff --git a/src/Select3D/Select3D_SensitiveTriangulation.cxx b/src/Select3D/Select3D_SensitiveTriangulation.cxx index 3a7631404a..c611974c21 100644 --- a/src/Select3D/Select3D_SensitiveTriangulation.cxx +++ b/src/Select3D/Select3D_SensitiveTriangulation.cxx @@ -111,9 +111,8 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S myBndBox.Clear(); for (Standard_Integer aNodeIdx = 1; aNodeIdx <= myTriangul->NbNodes(); ++aNodeIdx) { - myBndBox.Add (SelectMgr_Vec3 (myTriangul->Node (aNodeIdx).X(), - myTriangul->Node (aNodeIdx).Y(), - myTriangul->Node (aNodeIdx).Z())); + const gp_Pnt& aNode = myTriangul->Node (aNodeIdx); + myBndBox.Add (SelectMgr_Vec3 (aNode.X(), aNode.Y(), aNode.Z())); } if (theIsInterior) diff --git a/src/StdPrs/StdPrs_ShadedShape.cxx b/src/StdPrs/StdPrs_ShadedShape.cxx index 2ba10dcc7c..a434c61daa 100644 --- a/src/StdPrs/StdPrs_ShadedShape.cxx +++ b/src/StdPrs/StdPrs_ShadedShape.cxx @@ -205,10 +205,6 @@ namespace { aPoint = aT->Node (aNodeIter); gp_Dir aNorm = aNormals (aNodeIter); - if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored) - { - aNorm.Reverse(); - } if (!aLoc.IsIdentity()) { aPoint.Transform (aTrsf); @@ -242,9 +238,9 @@ namespace aT->Triangle (aTriIter).Get (anIndex[0], anIndex[1], anIndex[2]); } - gp_Pnt aP1 = aT->Node (anIndex[0]); - gp_Pnt aP2 = aT->Node (anIndex[1]); - gp_Pnt aP3 = aT->Node (anIndex[2]); + const gp_Pnt& aP1 = aT->Node (anIndex[0]); + const gp_Pnt& aP2 = aT->Node (anIndex[1]); + const gp_Pnt& aP3 = aT->Node (anIndex[2]); gp_Vec aV1 (aP1, aP2); if (aV1.SquareMagnitude() <= aPreci) -- 2.39.5