From db6c6404bc2f6c35a1de24c64aae2c9a91c549a7 Mon Sep 17 00:00:00 2001 From: oan Date: Thu, 30 Jul 2015 12:52:44 +0300 Subject: [PATCH] 0026485: Problem with the normals of a triangulated shape Use gp::Resolution() instead of Precision::SquareConfustion() in order to normalize normal vectors according to implementation of gp_Vec::Normalize(). Test case Test-case for issue #26485 --- src/Poly/Poly.cxx | 2 +- src/QABugs/QABugs_19.cxx | 72 ++++++++++++++++++++++++++++++++++++ tests/bugs/fclasses/bug26485 | 12 ++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/bugs/fclasses/bug26485 diff --git a/src/Poly/Poly.cxx b/src/Poly/Poly.cxx index f8af36d1d9..63db7243c9 100644 --- a/src/Poly/Poly.cxx +++ b/src/Poly/Poly.cxx @@ -460,7 +460,7 @@ void Poly::ComputeNormals(const Handle(Poly_Triangulation)& Tri) Standard_Real aCoord[3]; Standard_Integer iNode[3] = {0, 0, 0}; Standard_Integer iN, iTri; - const Standard_Real eps2 = Precision::SquareConfusion(); + const Standard_Real eps2 = gp::Resolution(); for (iTri = 1; iTri <= arrTri.Length(); iTri++) { // Get the nodes of the current triangle diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index c59479e14f..5002e196b2 100644 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -3805,6 +3805,77 @@ static Standard_Integer OCC26407 (Draw_Interpretor& theDI, Standard_Integer theA return 0; } +//======================================================================= +//function : OCC26485 +//purpose : +//======================================================================= +#include +static Standard_Integer OCC26485 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) +{ + if (theArgNb != 2) + { + std::cerr << "Error: wrong number of arguments! See usage:\n"; + theDI.PrintHelp (theArgVec[0]); + return 1; + } + + TopoDS_Shape aShape = DBRep::Get(theArgVec[1]); + if (aShape.IsNull()) + { + theDI << "Failed. Null shape\n"; + return 1; + } + + Standard_Boolean isFailed = Standard_False; + TopExp_Explorer aExplorer(aShape, TopAbs_FACE); + for (; aExplorer.More(); aExplorer.Next()) + { + const TopoDS_Face& aFace = TopoDS::Face( aExplorer.Current() ); + TopLoc_Location L = TopLoc_Location(); + const Handle(Poly_Triangulation)& aT = BRep_Tool::Triangulation( aFace , L ); + + if(aT.IsNull()) + continue; + + Poly::ComputeNormals(aT); + const TColgp_Array1OfPnt& aVertices = aT->Nodes(); + const TShort_Array1OfShortReal& aNormals = aT->Normals(); + + // Number of nodes in the triangulation + int aVertexNb = aT->Nodes().Length(); + if (aVertexNb*3 != aNormals.Length()) + { + theDI << "Failed. Different number of normals vs. vertices\n"; + return 1; + } + + // Get each vertex index, checking common vertexes between shapes + for( int i=0; i < aVertexNb; i++ ) + { + gp_Pnt aPoint = aVertices.Value( i+1 ); + gp_Vec aNormal = gp_Vec( + aNormals.Value( i*3 + 1 ), + aNormals.Value( i*3 + 2 ), + aNormals.Value( i*3 + 3 ) ); + + if (aNormal.X() == 0 && aNormal.Y() == 0 && aNormal.Z() == 1) + { + char buf[256]; + sprintf(buf, "fail_%d", i+1); + theDI << "Failed. Point " << buf << ": " + << aPoint.X() << " " + << aPoint.Y() << " " + << aPoint.Z() << "\n"; + + DrawTrSurf::Set (buf, aPoint); + } + } + } + + theDI << (isFailed ? "Test failed" : "Test completed") << "\n"; + return 0; +} + void QABugs::Commands_19(Draw_Interpretor& theCommands) { const char *group = "QABugs"; @@ -3879,5 +3950,6 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) { theCommands.Add ("OCC26446", "OCC26446 r c1 c2", __FILE__, OCC26446, group); theCommands.Add ("OCC26448", "OCC26448: check method Prepend() of sequence", __FILE__, OCC26448, group); theCommands.Add ("OCC26407", "OCC26407 result_name", __FILE__, OCC26407, group); + theCommands.Add ("OCC26485", "OCC26485 shape", __FILE__, OCC26485, group); return; } diff --git a/tests/bugs/fclasses/bug26485 b/tests/bugs/fclasses/bug26485 new file mode 100644 index 0000000000..b4421a5e3b --- /dev/null +++ b/tests/bugs/fclasses/bug26485 @@ -0,0 +1,12 @@ +puts "========" +puts "OCC26485" +puts "========" +puts "" +#################################################### +# Problem with the normals of a triangulated shape +#################################################### + +pload QAcommands + +restore [locate_data_file OCC26485-meshed_shape.brep] a +OCC26485 a