From b62c9889c634bcbb4eb8517f1a404b0aeac93d77 Mon Sep 17 00:00:00 2001 From: vro Date: Wed, 10 Feb 2021 18:13:17 +0300 Subject: [PATCH] 0025936: Modeling Data - reusable data structure for 2D tesselation (3- and 4-nodal mesh) // NCollection_Array1 replaced NCollection_Vector in Poly_Triangulation for nodes, triangles, ... --- src/AIS/AIS_Triangulation.cxx | 8 +- src/BRepLib/BRepLib.cxx | 15 +- src/BRepTools/BRepTools_ShapeSet.cxx | 120 +++---- .../BinMDataXtd_SurfacicMeshDriver.cxx | 83 ++--- src/BinTools/BinTools_ShapeSet.cxx | 11 +- src/DBRep/DBRep_DrawableShape.cxx | 4 +- src/Poly/FILES | 3 +- src/Poly/Poly.cxx | 21 +- src/Poly/Poly_CoherentTriangulation.cxx | 21 +- src/Poly/Poly_Element.cxx | 60 ---- src/Poly/Poly_Element.hxx | 84 ----- src/Poly/Poly_Mesh.cxx | 173 ++--------- src/Poly/Poly_Mesh.hxx | 92 +++--- src/Poly/Poly_Triangle.hxx | 2 +- src/Poly/Poly_Triangulation.cxx | 294 +++++------------- src/Poly/Poly_Triangulation.hxx | 190 +++++++---- src/QABugs/QABugs_19.cxx | 3 +- src/RWGltf/RWGltf_TriangulationReader.cxx | 8 +- src/RWGltf/RWGltf_TriangulationReader.hxx | 42 +-- src/RWMesh/RWMesh_FaceIterator.cxx | 3 +- src/RWObj/RWObj_TriangulationReader.cxx | 17 +- src/StdPrs/StdPrs_ToolTriangulatedShape.cxx | 13 +- src/TDataXtd/TDataXtd_SurfacicMesh.cxx | 147 +++------ src/TDataXtd/TDataXtd_SurfacicMesh.hxx | 128 +++----- src/TDataXtd/TDataXtd_Triangulation.cxx | 19 +- src/TDataXtd/TDataXtd_Triangulation.hxx | 4 - src/ViewerTest/ViewerTest_ObjectCommands.cxx | 9 +- src/VrmlData/VrmlData_ShapeConvert.cxx | 13 +- .../XmlMDataXtd_SurfacicMeshDriver.cxx | 11 +- 29 files changed, 540 insertions(+), 1058 deletions(-) delete mode 100644 src/Poly/Poly_Element.cxx delete mode 100644 src/Poly/Poly_Element.hxx diff --git a/src/AIS/AIS_Triangulation.cxx b/src/AIS/AIS_Triangulation.cxx index dc2906ba14..1b72f9d70a 100644 --- a/src/AIS/AIS_Triangulation.cxx +++ b/src/AIS/AIS_Triangulation.cxx @@ -141,8 +141,9 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP const TColStd_Array1OfInteger& colors = myColor->Array1(); for ( i = 1; i <= myTriangulation->NbNodes(); i++ ) { - anArray->AddVertex(myTriangulation->Node (i), attenuateColor(colors(i), ambient)); - anArray->SetVertexNormal(i, myTriangulation->Normal (i)); + anArray->AddVertex (myTriangulation->Node (i), attenuateColor (colors (i), ambient)); + const Vec3f& aNormal = myTriangulation->Normal (i); + anArray->SetVertexNormal (i, aNormal.x(), aNormal.y(), aNormal.z()); } } else // !hasVColors @@ -150,7 +151,8 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP for ( i = 1; i <= myTriangulation->NbNodes(); i++ ) { anArray->AddVertex(myTriangulation->Node (i)); - anArray->SetVertexNormal(i, myTriangulation->Normal (i)); + const Vec3f& aNormal = myTriangulation->Normal(i); + anArray->SetVertexNormal(i, aNormal.x(), aNormal.y(), aNormal.z()); } } } diff --git a/src/BRepLib/BRepLib.cxx b/src/BRepLib/BRepLib.cxx index 6284fcabd8..7a268f09f7 100644 --- a/src/BRepLib/BRepLib.cxx +++ b/src/BRepLib/BRepLib.cxx @@ -2343,9 +2343,6 @@ Standard_Boolean BRepLib:: } GeomLProp_SLProps aSLP(aSurf, 2, Precision::Confusion()); - const Standard_Integer anArrDim = 3*aPT->NbNodes(); - Handle(TShort_HArray1OfShortReal) aNormArr = new TShort_HArray1OfShortReal(1, anArrDim); - Standard_Integer anNormInd = aNormArr->Lower(); for(Standard_Integer i = 1; i <= aPT->NbNodes(); i++) { const gp_Pnt2d &aP2d = aPT->UVNode (i); @@ -2364,14 +2361,13 @@ Standard_Boolean BRepLib:: if (aFace.Orientation() == TopAbs_REVERSED) aNorm.Reverse(); } - aNormArr->ChangeValue(anNormInd++) = static_cast(aNorm.X()); - aNormArr->ChangeValue(anNormInd++) = static_cast(aNorm.Y()); - aNormArr->ChangeValue(anNormInd++) = static_cast(aNorm.Z()); + aPT->SetNormal (i, static_cast(aNorm.X()), + static_cast(aNorm.Y()), + static_cast(aNorm.Z())); } aRetVal = Standard_True; isNormalsFound = Standard_True; - aPT->SetNormals(aNormArr); } if(!isNormalsFound) @@ -2418,8 +2414,9 @@ Standard_Boolean BRepLib:: const Standard_Integer aFNodF1 = aPTEF1->Nodes().Value(anEdgNode); const Standard_Integer aFNodF2 = aPTEF2->Nodes().Value(anEdgNode); - gp_XYZ aNorm1 (aPT1->Normal (aFNodF1).XYZ()); - gp_XYZ aNorm2 (aPT2->Normal (aFNodF2).XYZ()); + gp_XYZ aNorm1, aNorm2; + aPT1->Normal (aFNodF1, aNorm1); + aPT1->Normal (aFNodF2, aNorm2); const Standard_Real aDot = aNorm1 * aNorm2; if(aDot > aThresDot) diff --git a/src/BRepTools/BRepTools_ShapeSet.cxx b/src/BRepTools/BRepTools_ShapeSet.cxx index c18049c0e7..a263833480 100644 --- a/src/BRepTools/BRepTools_ShapeSet.cxx +++ b/src/BRepTools/BRepTools_ShapeSet.cxx @@ -1522,7 +1522,7 @@ void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS, } for (k = 1; k <= 3; k++) { - OS << T->Normal (j).Coord (k) << " "; + OS << T->Normal (j).GetData() [k - 1] << " "; if (!Compact) { OS << "\n"; @@ -1558,10 +1558,9 @@ void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS, const Message_ProgressRange& theProgress) { char buffer[255]; - // Standard_Integer i, j, val, nbtri; Standard_Integer i, j, nbtri =0; Standard_Real d, x, y, z; - Standard_Real normal; + Standard_Real normalX, normalY, normalZ; Standard_Integer nbNodes =0, nbTriangles=0; Standard_Boolean hasUV= Standard_False; Standard_Boolean hasNormals= Standard_False; @@ -1583,53 +1582,44 @@ void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS, const Message_P } GeomTools::GetReal(IS, d); - TColgp_Array1OfPnt Nodes(1, nbNodes); - TColgp_Array1OfPnt2d UVNodes(1, nbNodes); - Handle(TShort_HArray1OfShortReal) Normals; - if (hasNormals) - { - Normals = new TShort_HArray1OfShortReal(1, nbNodes * 3); - } + T = new Poly_Triangulation (nbNodes, nbTriangles, hasUV, hasNormals); + for (j = 1; j <= nbNodes; j++) { GeomTools::GetReal(IS, x); GeomTools::GetReal(IS, y); GeomTools::GetReal(IS, z); - Nodes(j).SetCoord(x,y,z); + T->ChangeNode (j).SetCoord (x,y,z); } if (hasUV) { for (j = 1; j <= nbNodes; j++) { GeomTools::GetReal(IS, x); GeomTools::GetReal(IS, y); - UVNodes(j).SetCoord(x,y); + T->ChangeUVNode (j).SetCoord (x,y); } } // read the triangles Standard_Integer n1,n2,n3; - Poly_Array1OfTriangle Triangles(1, nbTriangles); for (j = 1; j <= nbTriangles; j++) { IS >> n1 >> n2 >> n3; - Triangles(j).Set(n1,n2,n3); + T->ChangeTriangle (j).Set (n1,n2,n3); } if (hasNormals) { - for (j = 1; j <= nbNodes * 3; j++) + for (j = 1; j <= nbNodes; j++) { - GeomTools::GetReal(IS, normal); - Normals->SetValue(j, static_cast(normal)); + GeomTools::GetReal (IS, normalX); + GeomTools::GetReal (IS, normalY); + GeomTools::GetReal (IS, normalZ); + T->SetNormal (j, static_cast(normalX), + static_cast(normalY), + static_cast(normalZ)); } } - - if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles); - else T = new Poly_Triangulation(Nodes,Triangles); T->Deflection(d); - if (hasNormals) - { - T->SetNormals(Normals); - } myTriangulations.Add(T, hasNormals); } } @@ -1654,17 +1644,18 @@ void BRepTools_ShapeSet::WriteMeshes (Standard_OStream& theOS, { const Handle(Poly_Mesh) aMesh = Handle(Poly_Mesh)::DownCast (theMeshes (i)); const Standard_Integer nbNodes = aMesh->NbNodes(); - const Standard_Integer nbElements = aMesh->NbElements(); + const Standard_Integer nbTriangles = aMesh->NbTriangles(); + const Standard_Integer nbQuads = aMesh->NbQuads(); const Standard_Boolean hasUVNodes = aMesh->HasUVNodes(); if (theCompact) { - theOS << nbNodes << " " << nbElements << " "; + theOS << nbNodes << " " << nbTriangles << " " << nbQuads << " "; theOS << (hasUVNodes ? "1" : "0") << " "; } else { - theOS << " "<< i << " : Mesh with " << nbNodes << " Nodes, " << nbElements <<" Triangles and Quadrangles\n"; + theOS << " "<< i << " : Mesh with " << nbNodes << " Nodes, " << nbTriangles << " Triangles, " << nbQuads << " Quadrangles\n"; theOS << " "<<(hasUVNodes ? "with" : "without") << " UV nodes\n"; } @@ -1707,31 +1698,41 @@ void BRepTools_ShapeSet::WriteMeshes (Standard_OStream& theOS, } } - // write triangles and quadrangles - if (!theCompact) theOS << "\nElements :\n"; - Standard_Integer n, n1, n2, n3, n4; - for (j = 1; j <= nbElements; j++) + // write triangles + if (!theCompact) theOS << "\nTriangles :\n"; + Standard_Integer n1, n2, n3; + for (j = 1; j <= nbTriangles; j++) { if (!theCompact) theOS << std::setw (10) << j << " : "; - aMesh->Element (j, n1, n2, n3, n4); - n = (n4 > 0) ? 4 : 3; - if (!theCompact) theOS << std::setw (10); - theOS << n << " "; + aMesh->Triangle (j).Get (n1, n2, n3); if (!theCompact) theOS << std::setw (10); theOS << n1 << " "; if (!theCompact) theOS << std::setw (10); theOS << n2 << " "; if (!theCompact) theOS << std::setw (10); theOS << n3; - if (n4 > 0) - { - theOS << " "; - if (!theCompact) theOS << std::setw (10); - theOS << n4; - } if (!theCompact) theOS << "\n"; else theOS << " "; } + + // write quadrangles + if (!theCompact) theOS << "\nQuadrangles :\n"; + Standard_Integer n4; + for (j = 1; j <= nbQuads; j++) + { + if (!theCompact) theOS << std::setw(10) << j << " : "; + aMesh->Quad (j).Get (n1, n2, n3, n4); + if (!theCompact) theOS << std::setw(10); + theOS << n1 << " "; + if (!theCompact) theOS << std::setw(10); + theOS << n2 << " "; + if (!theCompact) theOS << std::setw(10); + theOS << n3 << " "; + if (!theCompact) theOS << std::setw(10); + theOS << n4; + if (!theCompact) theOS << "\n"; + else theOS << " "; + } theOS << "\n"; } } @@ -1742,10 +1743,10 @@ void BRepTools_ShapeSet::ReadMeshes (Standard_IStream& theIS, { char buffer[255]; Standard_Integer i, j; - Standard_Integer n, n1(0), n2(0), n3(0), n4(0); + Standard_Integer n1 (0), n2 (0), n3 (0), n4 (0); Standard_Real deflection, x, y, z; - Standard_Integer nbMeshes(0), nbNodes(0), nbElements(0); - Standard_Boolean hasUV(Standard_False); + Standard_Integer nbMeshes (0), nbNodes (0), nbTriangles (0), nbQuads (0); + Standard_Boolean hasUV (Standard_False); gp_Pnt p; // Read the "Meshes" head-line. @@ -1758,11 +1759,11 @@ void BRepTools_ShapeSet::ReadMeshes (Standard_IStream& theIS, for (i = 1; i <= nbMeshes; i++) { - theIS >> nbNodes >> nbElements >> hasUV; + theIS >> nbNodes >> nbTriangles >> nbQuads >> hasUV; GeomTools::GetReal (theIS, deflection); // Allocate the mesh. - Handle(Poly_Mesh) aMesh = new Poly_Mesh (hasUV); + Handle(Poly_Mesh) aMesh = new Poly_Mesh (nbNodes, nbTriangles, nbQuads, hasUV); aMesh->Deflection (deflection); // Read nodes. @@ -1772,7 +1773,7 @@ void BRepTools_ShapeSet::ReadMeshes (Standard_IStream& theIS, GeomTools::GetReal (theIS, y); GeomTools::GetReal (theIS, z); p.SetCoord (x, y, z); - aMesh->AddNode (p); + aMesh->ChangeNode (j) = p; } // Reads 2d-nodes. @@ -1786,21 +1787,24 @@ void BRepTools_ShapeSet::ReadMeshes (Standard_IStream& theIS, } } - // Reads the triangles and quadrangles. - for (j = 1; j <= nbElements; j++) + // Reads the triangles. + for (j = 1; j <= nbTriangles; j++) { - // Read the element. - theIS >> n; - if (n == 3) + // Read the indices. theIS >> n1 >> n2 >> n3; - else if (n == 4) + + // Set the triangle to the mesh. + aMesh->ChangeTriangle (j) = Poly_Triangle (n1, n2, n3); + } + + // Reads the quadrangles. + for (j = 1; j <= nbQuads; j++) + { + // Read the indices. theIS >> n1 >> n2 >> n3 >> n4; - // Set the element to the mesh. - if (n == 3) - aMesh->AddElement (n1, n2, n3); - else if (n == 4) - aMesh->AddElement (n1, n2, n3, n4); + // Set the quadrangle to the mesh. + aMesh->ChangeQuad (j) = Poly_Quad (n1, n2, n3, n4); } theMeshes.Add (aMesh); diff --git a/src/BinMDataXtd/BinMDataXtd_SurfacicMeshDriver.cxx b/src/BinMDataXtd/BinMDataXtd_SurfacicMeshDriver.cxx index 7de8b2395e..b9880369fd 100644 --- a/src/BinMDataXtd/BinMDataXtd_SurfacicMeshDriver.cxx +++ b/src/BinMDataXtd/BinMDataXtd_SurfacicMeshDriver.cxx @@ -45,25 +45,26 @@ Handle(TDF_Attribute) BinMDataXtd_SurfacicMeshDriver::NewEmpty() const //purpose : persistent -> transient (retrieve) //======================================================================= Standard_Boolean BinMDataXtd_SurfacicMeshDriver::Paste (const BinObjMgt_Persistent& theSource, - const Handle(TDF_Attribute)& theTarget, - BinObjMgt_RRelocationTable& ) const + const Handle(TDF_Attribute)& theTarget, + BinObjMgt_RRelocationTable& ) const { Handle(TDataXtd_SurfacicMesh) attrMesh = Handle(TDataXtd_SurfacicMesh)::DownCast (theTarget); Standard_Integer i; Standard_Real deflection, x, y, z; - Standard_Integer n, n1, n2, n3, n4; - Standard_Integer nbNodes(0), nbElements(0); - Standard_Boolean hasUV(Standard_False); + Standard_Integer n1, n2, n3, n4; + Standard_Integer nbNodes (0), nbTriangles (0), nbQuads (0); + Standard_Boolean hasUV (Standard_False); gp_Pnt p; theSource >> nbNodes; - theSource >> nbElements; + theSource >> nbTriangles; + theSource >> nbQuads; theSource >> hasUV; theSource >> deflection; // allocate the mesh - Handle(Poly_Mesh) aMesh = new Poly_Mesh (hasUV); + Handle(Poly_Mesh) aMesh = new Poly_Mesh (nbNodes, nbTriangles, nbQuads, hasUV); // deflection aMesh->Deflection (deflection); @@ -75,7 +76,7 @@ Standard_Boolean BinMDataXtd_SurfacicMeshDriver::Paste (const BinObjMgt_Persiste theSource >> y; theSource >> z; p.SetCoord (x, y, z); - aMesh->AddNode (p); + aMesh->ChangeNode (i) = p; } // read 2d nodes @@ -88,21 +89,24 @@ Standard_Boolean BinMDataXtd_SurfacicMeshDriver::Paste (const BinObjMgt_Persiste aMesh->ChangeUVNode (i).SetCoord (x,y); } } - - // read triangles and quadrangles - for (i = 1; i <= nbElements; i++) + + // read triangles + for (i = 1; i <= nbTriangles; i++) { - theSource >> n; - theSource >> n1; - theSource >> n2; - theSource >> n3; - if (n == 3) - aMesh->AddElement (n1, n2, n3); - else if (n == 4) - { + theSource >> n1; + theSource >> n2; + theSource >> n3; + aMesh->ChangeTriangle (i).Set (n1, n2, n3); + } + + // read quadrangles + for (i = 1; i <= nbQuads; i++) + { + theSource >> n1; + theSource >> n2; + theSource >> n3; theSource >> n4; - aMesh->AddElement (n1, n2, n3, n4); - } + aMesh->ChangeQuad (i).Set (n1, n2, n3, n4); } // Set mesh to Ocaf attribute @@ -115,19 +119,21 @@ Standard_Boolean BinMDataXtd_SurfacicMeshDriver::Paste (const BinObjMgt_Persiste //purpose : transient -> persistent (store) //======================================================================= void BinMDataXtd_SurfacicMeshDriver::Paste (const Handle(TDF_Attribute)& theSource, - BinObjMgt_Persistent& theTarget, - BinObjMgt_SRelocationTable& ) const + BinObjMgt_Persistent& theTarget, + BinObjMgt_SRelocationTable& ) const { const Handle(TDataXtd_SurfacicMesh) attrMesh = Handle(TDataXtd_SurfacicMesh)::DownCast (theSource); const Handle(Poly_Mesh)& aMesh = attrMesh->Get(); if (!aMesh.IsNull()) { Standard_Integer nbNodes = aMesh->NbNodes(); - Standard_Integer nbElements = aMesh->NbElements(); + Standard_Integer nbTriangles = aMesh->NbTriangles(); + Standard_Integer nbQuads = aMesh->NbQuads(); // write number of elements theTarget << nbNodes; - theTarget << nbElements; + theTarget << nbTriangles; + theTarget << nbQuads; theTarget << (aMesh->HasUVNodes() ? 1 : 0); // write the deflection theTarget << aMesh->Deflection(); @@ -136,7 +142,7 @@ void BinMDataXtd_SurfacicMeshDriver::Paste (const Handle(TDF_Attribute)& theSour Standard_Integer i; for (i = 1; i <= nbNodes; i++) { - const gp_Pnt& aNode = aMesh->Node(i); + const gp_Pnt& aNode = aMesh->Node (i); theTarget << aNode.X(); theTarget << aNode.Y(); theTarget << aNode.Z(); @@ -147,24 +153,31 @@ void BinMDataXtd_SurfacicMeshDriver::Paste (const Handle(TDF_Attribute)& theSour { for (i = 1; i <= nbNodes; i++) { - const gp_Pnt2d& aUVNode = aMesh->UVNode(i); + const gp_Pnt2d& aUVNode = aMesh->UVNode (i); theTarget << aUVNode.X(); theTarget << aUVNode.Y(); } } - // write triangles and quadrangles - Standard_Integer n, n1, n2, n3, n4; - for (i = 1; i <= nbElements; i++) + // write triangles + Standard_Integer n1, n2, n3; + for (i = 1; i <= nbTriangles; i++) + { + aMesh->Triangle (i).Get (n1, n2, n3); + theTarget << n1; + theTarget << n2; + theTarget << n3; + } + + // write quadrangles + Standard_Integer n4; + for (i = 1; i <= nbQuads; i++) { - aMesh->Element (i, n1, n2, n3, n4); - n = (n4 > 0) ? 4 : 3; - theTarget << n; + aMesh->Quad (i).Get (n1, n2, n3, n4); theTarget << n1; theTarget << n2; theTarget << n3; - if (n4 > 0) - theTarget << n4; + theTarget << n4; } } } diff --git a/src/BinTools/BinTools_ShapeSet.cxx b/src/BinTools/BinTools_ShapeSet.cxx index 3e53e0191b..3b455eb89e 100644 --- a/src/BinTools/BinTools_ShapeSet.cxx +++ b/src/BinTools/BinTools_ShapeSet.cxx @@ -1532,10 +1532,10 @@ void BinTools_ShapeSet::WriteTriangulation (Standard_OStream& OS, { for (Standard_Integer aNormalIter = 1; aNormalIter <= aNbNodes; ++aNormalIter) { - const gp_Dir aNormal = aTriangulation->Normal (aNormalIter); - BinTools::PutShortReal (OS, (Standard_ShortReal) aNormal.X()); - BinTools::PutShortReal (OS, (Standard_ShortReal) aNormal.Y()); - BinTools::PutShortReal (OS, (Standard_ShortReal) aNormal.Z()); + const Vec3f& aNormal = aTriangulation->Normal (aNormalIter); + BinTools::PutShortReal (OS, aNormal.x()); + BinTools::PutShortReal (OS, aNormal.y()); + BinTools::PutShortReal (OS, aNormal.z()); } } } @@ -1620,8 +1620,7 @@ void BinTools_ShapeSet::ReadTriangulation (Standard_IStream& IS, BinTools::GetShortReal(IS, aNormalX); BinTools::GetShortReal(IS, aNormalY); BinTools::GetShortReal(IS, aNormalZ); - gp_Dir aNormal(aNormalX, aNormalY, aNormalZ); - aTriangulation->SetNormal (aNormalIter, aNormal); + aTriangulation->SetNormal (aNormalIter, aNormalX, aNormalY, aNormalZ); } } diff --git a/src/DBRep/DBRep_DrawableShape.cxx b/src/DBRep/DBRep_DrawableShape.cxx index b9fd5016e5..6a69553bc4 100644 --- a/src/DBRep/DBRep_DrawableShape.cxx +++ b/src/DBRep/DBRep_DrawableShape.cxx @@ -1148,7 +1148,9 @@ Standard_Boolean DBRep_DrawableShape::addMeshNormals (NCollection_VectorNormal (aNodeIter); + gp_XYZ anXYZ; + aTriangulation->Normal (aNodeIter, anXYZ); + aNormal.SetXYZ (anXYZ); } else { diff --git a/src/Poly/FILES b/src/Poly/FILES index 917eca557b..60a7f22e59 100755 --- a/src/Poly/FILES +++ b/src/Poly/FILES @@ -13,8 +13,7 @@ Poly_CoherentTriPtr.cxx Poly_CoherentTriPtr.hxx Poly_Connect.cxx Poly_Connect.hxx -Poly_Element.cxx -Poly_Element.hxx +Poly_Quad.hxx Poly_HArray1OfTriangle.hxx Poly_ListOfTriangulation.hxx Poly_MakeLoops.cxx diff --git a/src/Poly/Poly.cxx b/src/Poly/Poly.cxx index eeeb74c05a..c163683aee 100644 --- a/src/Poly/Poly.cxx +++ b/src/Poly/Poly.cxx @@ -480,28 +480,21 @@ 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) { const Standard_Size anIndex = aNodeIter * 3; aNormXYZ.SetCoord (aNormArr[anIndex + 0], aNormArr[anIndex + 1], aNormArr[anIndex + 2]); const Standard_Real aMod2 = aNormXYZ.SquareModulus(); - if (aMod2 < anEps2) - { - aNormArr[anIndex + 0] = 0.0f; - aNormArr[anIndex + 1] = 0.0f; - aNormArr[anIndex + 2] = 1.0f; - } + if (aMod2 > anEps2) + aNormal = aNormXYZ; else - { - aNormXYZ /= Sqrt (aMod2); - aNormArr[anIndex + 0] = Standard_ShortReal(aNormXYZ.X()); - aNormArr[anIndex + 1] = Standard_ShortReal(aNormXYZ.Y()); - aNormArr[anIndex + 2] = Standard_ShortReal(aNormXYZ.Z()); - } - } + aNormal = gp::DZ(); - theTri->SetNormals (aNormals); + // Set normal. + theTri->SetNormal (aNodeIter + 1, aNormXYZ); + } } //======================================================================= diff --git a/src/Poly/Poly_CoherentTriangulation.cxx b/src/Poly/Poly_CoherentTriangulation.cxx index 0288ee3784..82cf42f4b4 100644 --- a/src/Poly/Poly_CoherentTriangulation.cxx +++ b/src/Poly/Poly_CoherentTriangulation.cxx @@ -81,8 +81,9 @@ Poly_CoherentTriangulation::Poly_CoherentTriangulation // Copy the normals at nodes if (theTriangulation->HasNormals()) { for (i = 0; i < nNodes; i++) { - const gp_XYZ aNormal = theTriangulation->Normal (i + 1).XYZ(); - myNodes(i).SetNormal(aNormal); + const Vec3f& anXYZ = theTriangulation->Normal (i + 1); + gp_XYZ aNormal (anXYZ.x(), anXYZ.y(), anXYZ.z()); + myNodes (i).SetNormal (aNormal); } } myDeflection = theTriangulation->Deflection(); @@ -114,14 +115,10 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const const Standard_Integer nTriangles = NTriangles(); if (nNodes > 0 && nTriangles > 0) { aResult = new Poly_Triangulation(nNodes, nTriangles, Standard_True); - const Handle(TShort_HArray1OfShortReal) harrNormal = - new TShort_HArray1OfShortReal(1, 3 * nNodes); - Standard_ShortReal * arrNormal = &harrNormal->ChangeValue(1); NCollection_Vector vecNodeId; Standard_Integer i, aCount(0); Standard_Boolean hasUV (Standard_False); - Standard_Boolean hasNormals (Standard_False); // Copy the nodes (3D and 2D coordinates) for (i = 0; i < myNodes.Length(); i++) { @@ -130,9 +127,11 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const vecNodeId.SetValue(i, 0); else { const gp_XYZ aNormal = aNode.GetNormal(); - arrNormal[3 * aCount + 0] = static_cast(aNormal.X()); - arrNormal[3 * aCount + 1] = static_cast(aNormal.Y()); - arrNormal[3 * aCount + 2] = static_cast(aNormal.Z()); + if (aNormal.SquareModulus() > Precision::Confusion()) { + aResult->SetNormal (aCount, static_cast(aNormal.X()), + static_cast(aNormal.Y()), + static_cast(aNormal.Z())); + } vecNodeId.SetValue(i, ++aCount); aResult->ChangeNode (aCount) = aNode; @@ -141,8 +140,6 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const if (aNode.GetU()*aNode.GetU() + aNode.GetV()*aNode.GetV() > Precision::Confusion()) hasUV = Standard_True; - if (aNormal.SquareModulus() > Precision::Confusion()) - hasNormals = Standard_True; } } if (hasUV == Standard_False) @@ -159,8 +156,6 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const vecNodeId (aTri.Node (2)));; } } - if (hasNormals) - aResult->SetNormals (harrNormal); aResult->Deflection(myDeflection); } diff --git a/src/Poly/Poly_Element.cxx b/src/Poly/Poly_Element.cxx deleted file mode 100644 index 28011efce3..0000000000 --- a/src/Poly/Poly_Element.cxx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2015 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -//======================================================================= -//function : Poly_Element -//purpose : -//======================================================================= - -Poly_Element::Poly_Element() -{ - myTriangles[0] = myTriangles[1] = 0; -} - -//======================================================================= -//function : Poly_Element -//purpose : -//======================================================================= - -Poly_Element::Poly_Element (const Standard_Integer theTriangle1, - const Standard_Integer theTriangle2) -{ - myTriangles[0] = theTriangle1; - myTriangles[1] = theTriangle2; -} - -//======================================================================= -//function : Set -//purpose : -//======================================================================= - -void Poly_Element::Set (const Standard_Integer theTriangle1, - const Standard_Integer theTriangle2) -{ - myTriangles[0] = theTriangle1; - myTriangles[1] = theTriangle2; -} - -//======================================================================= -//function : Get -//purpose : -//======================================================================= - -void Poly_Element::Get (Standard_Integer& theTriangle1, - Standard_Integer& theTriangle2) const -{ - theTriangle1 = myTriangles[0]; - theTriangle2 = myTriangles[1]; -} diff --git a/src/Poly/Poly_Element.hxx b/src/Poly/Poly_Element.hxx deleted file mode 100644 index 2374826dc5..0000000000 --- a/src/Poly/Poly_Element.hxx +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2015 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Poly_Element_HeaderFile -#define _Poly_Element_HeaderFile - -#include -#include -#include - -//! Describes an element on mesh. -//! It can be defined as triangle index (in this case second index will be 0) -//! or as a pair of triangles indices that make up the quad. -class Poly_Element -{ - -public: - - DEFINE_STANDARD_ALLOC - - //! Constructs an element and sets all indices to zero. - Standard_EXPORT Poly_Element(); - - //! Constructs an element and sets it indices. - Standard_EXPORT Poly_Element (const Standard_Integer theTriangle1, - const Standard_Integer theTriangle2); - - //! Sets the value of triangles indices. - Standard_EXPORT void Set (const Standard_Integer theTriangle1, - const Standard_Integer theTriangle2); - - //! Returns the triangles indices of this element in theTriangle1, theTriangle2. - Standard_EXPORT void Get (Standard_Integer& theTriangle1, - Standard_Integer& theTriangle2) const; - - //! @return the triangle index of given element theIndex. - //! Raises OutOfRange from Standard if theIndex is not in 1,2. - Standard_Integer Value (const Standard_Integer theIndex) const - { - Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL); - return myTriangles[theIndex - 1]; - } - - Standard_Integer operator() (const Standard_Integer theIndex) const { return Value (theIndex); } - - //! @return the triangle index of given element theIndex. - //! Raises OutOfRange from Standard if theIndex is not in 1,2. - Standard_Integer& ChangeValue (const Standard_Integer theIndex) - { - Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL); - return myTriangles[theIndex - 1]; - } - - Standard_Integer& operator() (const Standard_Integer theIndex) { return ChangeValue (theIndex); } - - //! @return Standard_True if the first element index > 0 and the second index == 0. - Standard_Boolean IsTriangle() const - { - return (myTriangles[0] > 0 && myTriangles[1] == 0); - } - - //! @return Standard_True if the first and the second element indices > 0. - Standard_Boolean IsQuad() const - { - return (myTriangles[0] > 0 && myTriangles[1] > 0); - } - -private: - - Standard_Integer myTriangles[2]; - -}; - -#endif // _Poly_Element_HeaderFile diff --git a/src/Poly/Poly_Mesh.cxx b/src/Poly/Poly_Mesh.cxx index e4e9fcb149..3a23808c1f 100644 --- a/src/Poly/Poly_Mesh.cxx +++ b/src/Poly/Poly_Mesh.cxx @@ -12,7 +12,6 @@ // commercial license or contractual agreement. #include - #include IMPLEMENT_STANDARD_RTTIEXT (Poly_Mesh, Poly_Triangulation) @@ -22,178 +21,46 @@ IMPLEMENT_STANDARD_RTTIEXT (Poly_Mesh, Poly_Triangulation) //purpose : //======================================================================= -Poly_Mesh::Poly_Mesh (const Standard_Boolean theHasUVNodes) -: Poly_Triangulation (0, 0, theHasUVNodes), - myNbQuads (0) -{} - -//======================================================================= -//function : Poly_Mesh -//purpose : -//======================================================================= - -Poly_Mesh::Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation) -: Poly_Triangulation ( theTriangulation ), - myNbQuads (0) -{ - const Standard_Integer aNbTris = theTriangulation->NbTriangles(); - - // Fill collection of elements - if ( aNbTris ) - myElements.SetValue( aNbTris - 1, Poly_Element() ); - - // Populate elements with triangles - for ( Standard_Integer i = 1; i <= aNbTris; ++i ) - { - myElements(i - 1).Set(i, 0); - } -} - -//======================================================================= -//function : Copy -//purpose : -//======================================================================= - -Handle(Poly_Triangulation) Poly_Mesh::Copy() const -{ - const Standard_Boolean hasUV = HasUVNodes(); - Handle(Poly_Mesh) aCopy = new Poly_Mesh(hasUV); - // Copy nodes - Standard_Integer aNbNodes = NbNodes(); - for ( Standard_Integer i = 1; i <= aNbNodes; ++i ) - { - aCopy->AddNode(Node(i)); - if ( hasUV ) - aCopy->ChangeUVNode(i) = UVNode(i); - } - // Copy triangles - Standard_Integer aNbTriangles = NbTriangles(); - const Standard_Boolean hasNormals = HasNormals(); - for ( Standard_Integer i = 1; i <= aNbTriangles; ++i ) - { - aCopy->AddTriangle(Triangle(i)); - // Pass normal vector (if any) - if ( hasNormals ) - aCopy->SetNormal(i, Normal(i)); - } - // Copy quads - aCopy->myNbQuads = myNbQuads; - aCopy->myElements = myElements; - return aCopy; -} - -//======================================================================= -//function : AddElement -//purpose : -//======================================================================= - -Standard_Integer Poly_Mesh::AddElement (const Standard_Integer theN1, - const Standard_Integer theN2, - const Standard_Integer theN3) +Poly_Mesh::Poly_Mesh () : Poly_Triangulation (0, 0, Standard_False) { - Standard_Integer anIndex = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN2, theN3) ); - return addElement( Poly_Element(anIndex, 0) ); } //======================================================================= -//function : AddElement -//purpose : -//======================================================================= - -Standard_Integer Poly_Mesh::AddElement (const Standard_Integer theN1, - const Standard_Integer theN2, - const Standard_Integer theN3, - const Standard_Integer theN4) -{ - Standard_Integer anIndex1 = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN2, theN3) ); - Standard_Integer anIndex2 = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN3, theN4) ); - return addElement( Poly_Element(anIndex1, anIndex2) ); -} - -//======================================================================= -//function : Element -//purpose : -//======================================================================= - -const Poly_Element& Poly_Mesh::Element (const Standard_Integer theIndex) const -{ - if ( theIndex < 1 || theIndex > myElements.Size() ) - { - Standard_OutOfRange::Raise("Poly_Mesh::Element : index out of range"); - } - - return myElements.Value(theIndex - 1); -} - -//======================================================================= -//function : Element +//function : Poly_Mesh //purpose : //======================================================================= -void Poly_Mesh::Element (const Standard_Integer theIndex, - Standard_Integer& theN1, - Standard_Integer& theN2, - Standard_Integer& theN3, - Standard_Integer& theN4) const +Poly_Mesh::Poly_Mesh (const Standard_Integer theNbNodes, + const Standard_Integer theNbTriangles, + const Standard_Integer theNbQuads, + const Standard_Boolean theHasUVNodes, + const Standard_Boolean theHasNormals) +: Poly_Triangulation (theNbNodes, theNbTriangles, theHasUVNodes, theHasNormals) { - if ( theIndex < 1 || theIndex > myElements.Size() ) - { - Standard_OutOfRange::Raise("Poly_Mesh::Element : index out of range"); - } - - const Poly_Element& anElem = Element(theIndex); - Standard_Integer aTriIdx1, aTriIdx2; - anElem.Get(aTriIdx1, aTriIdx2); - - // Get node indices for the first triangle - const Poly_Triangle& aTri1 = Poly_Triangulation::Triangle(aTriIdx1); - aTri1.Get(theN1, theN2, theN3); - - // If the second triangle exists, take its node indices for quad - if ( aTriIdx2 ) - { - const Poly_Triangle& aTri2 = Poly_Triangulation::Triangle(aTriIdx2); - aTri2.Get(theN1, theN3, theN4); - } - else - theN4 = 0; + if (theNbQuads > 0) + myQuads.Resize (1, theNbQuads, Standard_False); } //======================================================================= -//function : SetElement +//function : Poly_Mesh //purpose : //======================================================================= -void Poly_Mesh::SetElement (const Standard_Integer theIndex, const Poly_Element& theElement) +Poly_Mesh::Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation) +: Poly_Triangulation ( theTriangulation ) { - if ( theIndex < 1 || theIndex > myElements.Size() ) - { - Standard_OutOfRange::Raise("Poly_Mesh::SetElement : index out of range"); - } - - if ( myElements.Value(theIndex - 1).Value(2) == 0 && theElement.Value(2) != 0 ) - { - myNbQuads++; - } - else if ( myElements.Value(theIndex - 1).Value(2) != 0 && theElement.Value(2) == 0 ) - { - myNbQuads--; - } - - myElements.SetValue(theIndex - 1, theElement); + // No quadrangles. } //======================================================================= -//function : addElement +//function : Copy //purpose : //======================================================================= -Standard_Integer Poly_Mesh::addElement(const Poly_Element& theElement) +Handle(Poly_Triangulation) Poly_Mesh::Copy() const { - myElements.Append(theElement); - if ( theElement.Value(2) != 0 ) - { - myNbQuads++; - } - return myElements.Size(); + Handle(Poly_Triangulation) aCopiedTriangulation = Poly_Triangulation::Copy(); + Handle(Poly_Mesh) aCopiedMesh = new Poly_Mesh (aCopiedTriangulation); + aCopiedMesh->myQuads = myQuads; + return aCopiedMesh; } diff --git a/src/Poly/Poly_Mesh.hxx b/src/Poly/Poly_Mesh.hxx index 061967995d..5a99b29e85 100644 --- a/src/Poly/Poly_Mesh.hxx +++ b/src/Poly/Poly_Mesh.hxx @@ -14,23 +14,31 @@ #ifndef _Poly_Mesh_HeaderFile #define _Poly_Mesh_HeaderFile -#include +#include #include //! This class is extension for Poly_Triangulation. -//! It allows to store mesh with quad polygons as table of Poly_Element. -//! Keep in mind that when you add a triangle, it is also added to the table of elements -//! as Poly_Element. And it will have first index set to triangle index from Poly_Triangulation -//! and second index will be set to 0. +//! It allows to store mesh with quad polygons. class Poly_Mesh : public Poly_Triangulation { public: //! Constructs an empty mesh. + Standard_EXPORT Poly_Mesh(); + + //! Constructs a mesh. + //! @param theNbNodes defines the number of nodes. + //! @param theNbTriangles defines the number of triangles. + //! @param theNbQuads defines the number of quadrangles. //! @param theHasUVNodes indicates whether 2D nodes will be associated with //! 3D ones, (i.e. to enable a 2D representation). - Standard_EXPORT Poly_Mesh (const Standard_Boolean theHasUVNodes = Standard_False); + //! @param theHasNormals defines allocation of normals for the nodes. + Standard_EXPORT Poly_Mesh(const Standard_Integer theNbNodes, + const Standard_Integer theNbTriangles, + const Standard_Integer theNbQuads, + const Standard_Boolean theHasUVNodes = Standard_False, + const Standard_Boolean theHasNormals = Standard_False); //! Constructs a mesh from existing triangulation. //! @param theTriangulation source triangulation. @@ -39,59 +47,39 @@ public: //! Creates full copy of current mesh Standard_EXPORT virtual Handle(Poly_Triangulation) Copy() const; - //! Adds element to the mesh. - //! @param theN1 index of the first node. - //! @param theN2 index of the second node. - //! @param theN3 index of the third node. - //! @return index of the added element. - Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1, - const Standard_Integer theN2, - const Standard_Integer theN3); - - //! Adds element to the mesh. + //! Sets a quadrangle to the mesh. + //! @param theIndex is an index of the quadrangle. //! @param theN1 index of the first node. //! @param theN2 index of the second node. //! @param theN3 index of the third node. //! @param theN4 index of the fourth node. - //! @return index of the added element. - Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1, - const Standard_Integer theN2, - const Standard_Integer theN3, - const Standard_Integer theN4); - - //! @return the number of elements for this mesh. - Standard_Integer NbElements() const { return myElements.Size(); } - - //! @return the number of quads for this mesh. - Standard_Integer NbQuads() const { return myNbQuads; } - - //! @return element at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. - Standard_EXPORT const Poly_Element& Element (const Standard_Integer theIndex) const; - - //! @return nodes of the element at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. - Standard_EXPORT void Element (const Standard_Integer theIndex, - Standard_Integer& theN1, - Standard_Integer& theN2, - Standard_Integer& theN3, - Standard_Integer& theN4) const; - - //! Sets the element at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. - Standard_EXPORT void SetElement (const Standard_Integer theIndex, const Poly_Element& theElement); + void SetQuad (const Standard_Integer theIndex, + const Standard_Integer theN1, + const Standard_Integer theN2, + const Standard_Integer theN3, + const Standard_Integer theN4) + { + myQuads.SetValue (theIndex, Poly_Quad (theN1, theN2, theN3, theN4)); + } + + //! @return the number of quadrangles in the mesh. + Standard_Integer NbQuads() const { + return myQuads.Size(); + } + + //! @return a quadrangle at the given index. + const Poly_Quad& Quad (const Standard_Integer theIndex) const { + return myQuads.Value (theIndex); + } + + //! @return a reference to a quadrangle at the given index. + Poly_Quad& ChangeQuad (const Standard_Integer theIndex) { + return myQuads.ChangeValue (theIndex); + } protected: - //! Adds element to the mesh. - //! @param theElement element to add. - //! @return index of the added element. - Standard_EXPORT Standard_Integer addElement (const Poly_Element& theElement); - -private: - - NCollection_Vector myElements; - Standard_Integer myNbQuads; + NCollection_Array1 myQuads; public: diff --git a/src/Poly/Poly_Triangle.hxx b/src/Poly/Poly_Triangle.hxx index b00ff5f0a5..76e6592eca 100644 --- a/src/Poly/Poly_Triangle.hxx +++ b/src/Poly/Poly_Triangle.hxx @@ -89,7 +89,7 @@ public: Standard_Integer& operator() (const Standard_Integer Index) { return ChangeValue(Index); } -private: +protected: Standard_Integer myNodes[3]; diff --git a/src/Poly/Poly_Triangulation.cxx b/src/Poly/Poly_Triangulation.cxx index 2d70801066..1083227339 100644 --- a/src/Poly/Poly_Triangulation.cxx +++ b/src/Poly/Poly_Triangulation.cxx @@ -18,9 +18,7 @@ #include #include -#include #include -#include #include IMPLEMENT_STANDARD_RTTIEXT (Poly_Triangulation, Standard_Transient) @@ -40,24 +38,24 @@ Poly_Triangulation::Poly_Triangulation() //function : Poly_Triangulation //purpose : //======================================================================= -Poly_Triangulation::Poly_Triangulation(const Standard_Integer theNbNodes, - const Standard_Integer theNbTriangles, - const Standard_Boolean theHasUVNodes) +Poly_Triangulation::Poly_Triangulation (const Standard_Integer theNbNodes, + const Standard_Integer theNbTriangles, + const Standard_Boolean theHasUVNodes) : myCachedMinMax (NULL), myDeflection (0), myHasUVNodes (theHasUVNodes) { if (theNbNodes > 0) { - myNodes.SetValue (theNbNodes - 1, gp_Pnt()); + myNodes.Resize (1, theNbNodes, Standard_False); if (myHasUVNodes) { - myUVNodes.SetValue (theNbNodes - 1, gp_Pnt2d()); + myUVNodes.Resize (1, theNbNodes, Standard_False); } } if (theNbTriangles > 0) { - myTriangles.SetValue (theNbTriangles - 1, Poly_Triangle()); + myTriangles.Resize (1, theNbTriangles, Standard_False); } } @@ -65,15 +63,15 @@ Poly_Triangulation::Poly_Triangulation(const Standard_Integer theNbNodes, //function : Poly_Triangulation //purpose : //======================================================================= -Poly_Triangulation::Poly_Triangulation(const Standard_Integer theNbNodes, - const Standard_Integer theNbTriangles, - const Standard_Boolean theHasUVNodes, - const Standard_Boolean theHasNormals) +Poly_Triangulation::Poly_Triangulation (const Standard_Integer theNbNodes, + const Standard_Integer theNbTriangles, + const Standard_Boolean theHasUVNodes, + const Standard_Boolean theHasNormals) : Poly_Triangulation(theNbNodes, theNbTriangles, theHasUVNodes) { if (theHasNormals) { - myNormals.SetValue (theNbNodes - 1, gp_Dir()); + myNormals.Resize (1, theNbNodes, Standard_False); } } @@ -81,20 +79,17 @@ Poly_Triangulation::Poly_Triangulation(const Standard_Integer theNbNodes, //function : Poly_Triangulation //purpose : //======================================================================= -Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& theNodes, - const Poly_Array1OfTriangle& theTriangles) +Poly_Triangulation::Poly_Triangulation (const TColgp_Array1OfPnt& theNodes, + const Poly_Array1OfTriangle& theTriangles) : myCachedMinMax (NULL), myDeflection (0), myHasUVNodes (Standard_False) { - for (Standard_Integer anIndex = theNodes.Upper(); anIndex >= theNodes.Lower(); anIndex--) - { - myNodes.SetValue (anIndex - 1, theNodes (anIndex)); - } - for (Standard_Integer anIndex = theTriangles.Upper(); anIndex >= theTriangles.Lower(); anIndex--) - { - myTriangles.SetValue (anIndex - 1, theTriangles (anIndex)); - } + myNodes.Resize (1, theNodes.Length(), Standard_False); + myNodes = theNodes; + + myTriangles.Resize (1, theTriangles.Length(), Standard_False); + myTriangles = theTriangles; } //======================================================================= @@ -102,27 +97,22 @@ Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& theNodes, //purpose : //======================================================================= -Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& theNodes, - const TColgp_Array1OfPnt2d& theUVNodes, - const Poly_Array1OfTriangle& theTriangles) +Poly_Triangulation::Poly_Triangulation (const TColgp_Array1OfPnt& theNodes, + const TColgp_Array1OfPnt2d& theUVNodes, + const Poly_Array1OfTriangle& theTriangles) : myCachedMinMax (NULL), myDeflection (0), myHasUVNodes (theNodes.Length() == theUVNodes.Length()) { - for (Standard_Integer anIndex = theNodes.Upper(); anIndex >= theNodes.Lower(); anIndex--) - { - myNodes.SetValue (anIndex - 1, theNodes (anIndex)); - } - if (myHasUVNodes) - { - for (Standard_Integer anIndex = theUVNodes.Upper(); anIndex >= theUVNodes.Lower(); anIndex--) - { - myUVNodes.SetValue (anIndex - 1, theUVNodes (anIndex)); - } - } - for (Standard_Integer anIndex = theTriangles.Upper(); anIndex >= theTriangles.Lower(); anIndex--) - { - myTriangles.SetValue (anIndex - 1, theTriangles (anIndex)); + myNodes.Resize (1, theNodes.Length(), Standard_False); + myNodes = theNodes; + + myTriangles.Resize (1, theTriangles.Length(), Standard_False); + myTriangles = theTriangles; + + if (myHasUVNodes) { + myUVNodes.Resize (1, theNodes.Length(), Standard_False); + myUVNodes = theUVNodes; } } @@ -145,9 +135,16 @@ Handle(Poly_Triangulation) Poly_Triangulation::Copy() const Handle(Poly_Triangulation) aCopy = new Poly_Triangulation (NbNodes(), NbTriangles(), HasUVNodes()); aCopy->myNodes = myNodes; aCopy->myTriangles = myTriangles; - aCopy->myUVNodes = myUVNodes; aCopy->myDeflection = myDeflection; - aCopy->myNormals = myNormals; + + if (HasUVNodes()) + aCopy->myUVNodes = myUVNodes; + + if (HasNormals()) { + aCopy->myNormals.Resize (1, myNodes.Size(), Standard_False); + aCopy->myNormals = myNormals; + } + return aCopy; } @@ -162,23 +159,22 @@ Poly_Triangulation::Poly_Triangulation (const Handle(Poly_Triangulation)& theTri myHasUVNodes (theTriangulation->myHasUVNodes) { SetCachedMinMax (theTriangulation->CachedMinMax()); - myNodes.Assign(theTriangulation->myNodes); - if (myHasUVNodes) - { - myUVNodes.Assign(theTriangulation->myUVNodes); - } - myTriangles.Assign(theTriangulation->myTriangles); - myNormals.Assign(theTriangulation->myNormals); -} -//======================================================================= -//function : Deflection -//purpose : -//======================================================================= + // Re-allocate the arrays. + myNodes.Resize (1, theTriangulation->NbNodes(), Standard_False); + if (myHasUVNodes) + myUVNodes.Resize (1, theTriangulation->NbNodes(), Standard_False); + myTriangles.Resize (1, theTriangulation->NbTriangles(), Standard_False); + if (theTriangulation->HasNormals()) + myNormals.Resize (1, theTriangulation->NbNodes(), Standard_False); -void Poly_Triangulation::Deflection (const Standard_Real theDeflection) -{ - myDeflection = theDeflection; + // Copy data. + myNodes = theTriangulation->myNodes; + if (myHasUVNodes) + myUVNodes = theTriangulation->myUVNodes; + myTriangles = theTriangulation->myTriangles; + if (theTriangulation->HasNormals()) + myNormals = theTriangulation->myNormals; } //======================================================================= @@ -188,127 +184,10 @@ void Poly_Triangulation::Deflection (const Standard_Real theDeflection) void Poly_Triangulation::RemoveUVNodes() { - myUVNodes.Clear(); + myUVNodes = TColgp_Array1OfPnt2d(); myHasUVNodes = Standard_False; } -//======================================================================= -//function : AddNode -//purpose : -//======================================================================= -Standard_Integer Poly_Triangulation::AddNode (const gp_Pnt& theNode) -{ - myNodes.Append (theNode); - - if (myHasUVNodes) - { - myUVNodes.Append (gp_Pnt2d()); - } - - if (!myNormals.IsEmpty()) - { - Standard_Integer aNbNormals = myNodes.Size(); - myNormals.SetValue (aNbNormals, gp_Dir()); - } - - return myNodes.Size(); -} - -//======================================================================= -//function : Node -//purpose : -//======================================================================= - -const gp_Pnt& Poly_Triangulation::Node (const Standard_Integer theIndex) const -{ - if (theIndex < 1 || theIndex > myNodes.Size()) - { - throw Standard_OutOfRange ("Poly_Triangulation::Node : index out of range"); - } - return myNodes.Value (theIndex - 1); -} - -//======================================================================= -//function : ChangeNode -//purpose : -//======================================================================= - -gp_Pnt& Poly_Triangulation::ChangeNode (const Standard_Integer theIndex) -{ - if (theIndex < 1 || theIndex > myNodes.Size()) - { - throw Standard_OutOfRange ("Poly_Triangulation::ChangeNode : index out of range"); - } - return myNodes.ChangeValue (theIndex - 1); -} - -//======================================================================= -//function : UVNode -//purpose : -//======================================================================= - -const gp_Pnt2d& Poly_Triangulation::UVNode (const Standard_Integer theIndex) const -{ - if (myUVNodes.IsEmpty() || theIndex < 1 || theIndex > myUVNodes.Size()) - { - throw Standard_OutOfRange ("Poly_Triangulation::UVNode : index out of range"); - } - return myUVNodes.Value (theIndex - 1); -} - -//======================================================================= -//function : ChangeUVNode -//purpose : -//======================================================================= - -gp_Pnt2d& Poly_Triangulation::ChangeUVNode (const Standard_Integer theIndex) -{ - if (myUVNodes.IsEmpty() || theIndex < 1 || theIndex > myUVNodes.Size()) - { - throw Standard_OutOfRange ("Poly_Triangulation::ChangeUVNode : index out of range"); - } - return myUVNodes.ChangeValue (theIndex - 1); -} - -//======================================================================= -//function : Triangle -//purpose : -//======================================================================= - -Standard_Integer Poly_Triangulation::AddTriangle (const Poly_Triangle& theTriangle) -{ - myTriangles.Append (theTriangle); - return myTriangles.Size(); -} - -//======================================================================= -//function : Triangle -//purpose : -//======================================================================= - -const Poly_Triangle& Poly_Triangulation::Triangle (const Standard_Integer theIndex) const -{ - if (theIndex < 1 || theIndex > myTriangles.Size()) - { - throw Standard_OutOfRange ("Poly_Triangulation::Triangle : index out of range"); - } - return myTriangles.Value (theIndex - 1); -} - -//======================================================================= -//function : ChangeTriangle -//purpose : -//======================================================================= - -Poly_Triangle& Poly_Triangulation::ChangeTriangle (const Standard_Integer theIndex) -{ - if (theIndex < 1 || theIndex > myTriangles.Size()) - { - throw Standard_OutOfRange ("Poly_Triangulation::ChangeTriangle : index out of range"); - } - return myTriangles.ChangeValue (theIndex - 1); -} - //======================================================================= //function : SetNormals //purpose : @@ -322,64 +201,47 @@ void Poly_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& th } Standard_Integer anArrayLower = theNormals->Lower(); - Standard_Integer anArrayInd; - for (Standard_Integer anIndex = NbNodes() - 1; anIndex >= 0; anIndex--) + for (Standard_Integer anIndex = 1; anIndex >= NbNodes(); anIndex--) { - anArrayInd = anArrayLower + anIndex * 3; - gp_Dir aNormal(theNormals->Value(anArrayInd), - theNormals->Value(anArrayInd), - theNormals->Value(anArrayInd)); - myNormals.SetValue (anIndex, aNormal); + Standard_Integer anArrayInd = anArrayLower + (anIndex - 1) * 3; + SetNormal (anIndex, theNormals->Value(anArrayInd), + theNormals->Value(anArrayInd + 1), + theNormals->Value(anArrayInd + 2)); } } -//======================================================================= -//function : SetNormal -//purpose : -//======================================================================= - -void Poly_Triangulation::SetNormal (const Standard_Integer theIndex, const gp_Dir& theNormal) -{ - - if (myNormals.IsEmpty() || theIndex < 1 || theIndex > myNodes.Size()) { - throw Standard_NullObject("Poly_Triangulation::ChangeNormals : " - "wrong length or null array"); - } - - myNormals.ChangeValue (theIndex - 1) = theNormal; -} - -//======================================================================= -//function : HasNormals -//purpose : -//======================================================================= +// ======================================================================= +// function : ResizeNodes +// purpose : +// ======================================================================= -Standard_Boolean Poly_Triangulation::HasNormals() const +void Poly_Triangulation::ResizeNodes (const Standard_Integer theNbNodes) { - if (myNormals.IsEmpty() || myNormals.Length() != NbNodes()) { - return Standard_False; + if (theNbNodes > 0) { + myNodes.Resize (1, theNbNodes, Standard_True); + if (myHasUVNodes) + myUVNodes.Resize (1, theNbNodes, Standard_True); + if (HasNormals()) + myNormals.Resize (1, theNbNodes, Standard_True); } - return Standard_True; } -//======================================================================= -//function : Normal -//purpose : -//======================================================================= +// ======================================================================= +// function : ResizeTriangles +// purpose : +// ======================================================================= -const gp_Dir Poly_Triangulation::Normal (const Standard_Integer theIndex) const +void Poly_Triangulation::ResizeTriangles (const Standard_Integer theNbTriangles) { - if (myNormals.IsEmpty() || theIndex < 1 || theIndex > myNodes.Size()) - { - throw Standard_NullObject ("Poly_Triangulation::Normal : empty array or index out of range"); - } - return myNormals (theIndex - 1); + if (theNbTriangles > 0) + myTriangles.Resize (1, theNbTriangles, Standard_True); } // ======================================================================= // function : DumpJson // purpose : // ======================================================================= + void Poly_Triangulation::DumpJson (Standard_OStream& theOStream, Standard_Integer) const { OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) diff --git a/src/Poly/Poly_Triangulation.hxx b/src/Poly/Poly_Triangulation.hxx index 78474c0465..7b0c8eb2d2 100644 --- a/src/Poly/Poly_Triangulation.hxx +++ b/src/Poly/Poly_Triangulation.hxx @@ -20,19 +20,12 @@ #include #include #include -#include -#include #include #include #include #include -#include -#include -#include -#include -#include -class Standard_DomainError; -class Standard_NullObject; + +typedef NCollection_Vec3 Vec3f; //! Provides a triangulation for a surface, a set of surfaces, or more generally a shape. //! A triangulation consists of an approximate representation of the actual shape, using a collection of points and triangles. @@ -63,7 +56,7 @@ public: //! triangles. Here the UVNodes flag indicates whether //! 2D nodes will be associated with 3D ones, (i.e. to //! enable a 2D representation). - Standard_EXPORT Poly_Triangulation(const Standard_Integer nbNodes, const Standard_Integer nbTriangles, const Standard_Boolean UVNodes); + Standard_EXPORT Poly_Triangulation(const Standard_Integer nbNodes, const Standard_Integer nbTriangles, const Standard_Boolean hasUVNodes); //! Constructs a triangulation from a set of triangles. //! The triangulation is initialized without a triangle or a node, @@ -73,7 +66,7 @@ public: //! Here the hasNormals flag indicates whether normals will be given and associated with nodes. Standard_EXPORT Poly_Triangulation(const Standard_Integer nbNodes, const Standard_Integer nbTriangles, - const Standard_Boolean UVNodes, + const Standard_Boolean hasUVNodes, const Standard_Boolean hasNormals); //! Constructs a triangulation from a set of triangles. The @@ -100,59 +93,138 @@ public: Standard_EXPORT Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation); //! Returns the deflection of this triangulation. - Standard_Real Deflection() const { return myDeflection; } + Standard_Real Deflection() const { + return myDeflection; + } //! Sets the deflection of this triangulation to theDeflection. //! See more on deflection in Polygon2D - Standard_EXPORT void Deflection (const Standard_Real theDeflection); + void Deflection (const Standard_Real theDeflection) { + myDeflection = theDeflection; + } //! Deallocates the UV nodes. Standard_EXPORT void RemoveUVNodes(); //! Returns TRUE if triangulation has some geometry. - virtual Standard_Boolean HasGeometry() const { return !myNodes.IsEmpty() && !myTriangles.IsEmpty(); } - - //! @return the number of nodes for this triangulation. - Standard_Integer NbNodes() const { return myNodes.Size(); } + virtual Standard_Boolean HasGeometry() const { + return !myNodes.IsEmpty() && !myTriangles.IsEmpty(); + } - //! @return the number of triangles for this triangulation. - Standard_Integer NbTriangles() const { return myTriangles.Size(); } + //! Returns the number of nodes for this triangulation. + Standard_Integer NbNodes() const { + return myNodes.Size(); + } - //! @return Standard_True if 2D nodes are associated with 3D nodes for this triangulation. - Standard_Boolean HasUVNodes() const { return myHasUVNodes; } + //! Returns the number of triangles for this triangulation. + Standard_Integer NbTriangles() const { + return myTriangles.Size(); + } - //! Adds Node to the triangulation. If triangulation has UVNodes or Normals - //! they will be expanded and set to zero values to match the new number of nodes. - //! @return index of the added Node. - Standard_EXPORT Standard_Integer AddNode (const gp_Pnt& theNode); + //! Sets a node coordinates. + void SetNode (const Standard_Integer theIndex, + const gp_Pnt& thePnt) + { + myNodes.SetValue (theIndex, thePnt); + } - //! @return node at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. - Standard_EXPORT const gp_Pnt& Node (const Standard_Integer theIndex) const; + //! Returns a node at the given index. + const gp_Pnt& Node (const Standard_Integer theIndex) const { + return myNodes.Value (theIndex); + } //! Give access to the node at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. - Standard_EXPORT gp_Pnt& ChangeNode (const Standard_Integer theIndex); + gp_Pnt& ChangeNode (const Standard_Integer theIndex) { + return myNodes.ChangeValue (theIndex); + } + + //! Returns Standard_True if 2D nodes are associated with 3D nodes for this triangulation. + Standard_Boolean HasUVNodes() const { + return myHasUVNodes; + } + + //! Sets an UV-node coordinates. + void SetUVNode (const Standard_Integer theIndex, + const gp_Pnt2d& thePnt) + { + myUVNodes.SetValue (theIndex, thePnt); + } - //! @return UVNode at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. - Standard_EXPORT const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const; + //! Returns UV-node at the given index. + const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const { + return myUVNodes.Value (theIndex); + } //! Give access to the UVNode at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. - Standard_EXPORT gp_Pnt2d& ChangeUVNode (const Standard_Integer theIndex); + gp_Pnt2d& ChangeUVNode (const Standard_Integer theIndex) { + return myUVNodes.ChangeValue (theIndex); + } - //! Adds triangle to the triangulation. - //! @return index of the added triangle. - Standard_EXPORT virtual Standard_Integer AddTriangle (const Poly_Triangle& theTriangle); + //! Sets a triangle. + void SetTriangle (const Standard_Integer theIndex, + const Poly_Triangle& theTriangle) + { + myTriangles.SetValue (theIndex, theTriangle); + } - //! @return triangle at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. - Standard_EXPORT const Poly_Triangle& Triangle (const Standard_Integer theIndex) const; + //! Returns triangle at the given index. + const Poly_Triangle& Triangle (const Standard_Integer theIndex) const { + return myTriangles.Value (theIndex); + } //! Give access to the triangle at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. - Standard_EXPORT Poly_Triangle& ChangeTriangle (const Standard_Integer theIndex); + //! Raises an exception if theIndex is less than 1 or greater than number of triangles. + Poly_Triangle& ChangeTriangle (const Standard_Integer theIndex) { + return myTriangles.ChangeValue (theIndex); + } + + //! Returns Standard_True if nodal normals are defined. + Standard_Boolean HasNormals() const { + return !myNormals.IsEmpty() && myNormals.Length() == NbNodes(); + } + + //! Changes normal at the given index. + void SetNormal (const Standard_Integer theIndex, + const Vec3f& theNormal) + { + // If an array for normals is not allocated yet, do it now. + if (myNormals.IsEmpty()) + myNormals.Resize (1, myNodes.Size(), Standard_False); + + // Set a normal. + myNormals.ChangeValue (theIndex) = theNormal; + } + + //! Changes normal at the given index. + void SetNormal (const Standard_Integer theIndex, + const gp_XYZ& theNormal) + { + SetNormal (theIndex, static_cast(theNormal.X()), + static_cast(theNormal.Y()), + static_cast(theNormal.Z())); + } + + //! Changes normal at the given index. + void SetNormal (const Standard_Integer theIndex, + const Standard_ShortReal theNormalX, + const Standard_ShortReal theNormalY, + const Standard_ShortReal theNormalZ) + { + SetNormal (theIndex, Vec3f (theNormalX, theNormalY, theNormalZ)); + } + + //! Returns normal at the given index. + const Vec3f& Normal (const Standard_Integer theIndex) const { + return myNormals (theIndex); + } + + //! Returns normal at the given index. + void Normal (const Standard_Integer theIndex, + gp_XYZ& theNormal) const + { + const Vec3f& aCoords = Normal (theIndex); + theNormal.SetCoord (aCoords.x(), aCoords.y(), aCoords.z()); + } //! Sets the table of node normals. //! Raises exception if length of theNormals != 3 * NbNodes @@ -161,17 +233,14 @@ public: Array of floats should be replaced by vector of normals") Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals); - //! Changes normal at the given index. - //! Raises Standard_OutOfRange exception. - Standard_EXPORT void SetNormal (const Standard_Integer theIndex, - const gp_Dir& theNormal); + //! An advanced method resizing an internal array of nodes. + //! The old nodes are copied into the new array. + //! UV-nodes as well as normals, if exist are extended and copied too. + Standard_EXPORT void ResizeNodes (const Standard_Integer theNbNodes); - //! Returns Standard_True if nodal normals are defined. - Standard_EXPORT Standard_Boolean HasNormals() const; - - //! @return normal at the given index. - //! Raises Standard_OutOfRange exception. - Standard_EXPORT const gp_Dir Normal (const Standard_Integer theIndex) const; + //! An advanced method resizing an internal array of triangles. + //! The old triangles are copied into the new array. + Standard_EXPORT void ResizeTriangles (const Standard_Integer theNbTriangles); //! Returns cached min - max range of triangulation data, //! which is VOID by default (e.g, no cached information). @@ -220,14 +289,13 @@ protected: protected: - Bnd_Box* myCachedMinMax; - Standard_Real myDeflection; - Standard_Boolean myHasUVNodes; - NCollection_Vector myNodes; - NCollection_Vector myUVNodes; - NCollection_Vector myTriangles; - NCollection_Vector myNormals; - + Bnd_Box* myCachedMinMax; + Standard_Real myDeflection; + Standard_Boolean myHasUVNodes; + TColgp_Array1OfPnt myNodes; + TColgp_Array1OfPnt2d myUVNodes; + Poly_Array1OfTriangle myTriangles; + NCollection_Array1 myNormals; }; #endif // _Poly_Triangulation_HeaderFile diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index 686d13b208..c84f78af76 100644 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -4038,7 +4038,8 @@ static Standard_Integer OCC26485 (Draw_Interpretor& theDI, Standard_Integer theA for( int i=0; i < aVertexNb; i++ ) { gp_Pnt aPoint = aT->Node ( i+1 ); - gp_Dir aNormal = aT->Normal ( i+1 ); + const Vec3f& aVec = aT->Normal ( i+1 ); + gp_Dir aNormal (aVec.x(), aVec.y(), aVec.z()); if (aNormal.X() == 0 && aNormal.Y() == 0 && aNormal.Z() == 1) { diff --git a/src/RWGltf/RWGltf_TriangulationReader.cxx b/src/RWGltf/RWGltf_TriangulationReader.cxx index 041c162da3..92cec103f6 100644 --- a/src/RWGltf/RWGltf_TriangulationReader.cxx +++ b/src/RWGltf/RWGltf_TriangulationReader.cxx @@ -333,11 +333,11 @@ bool RWGltf_TriangulationReader::readBuffer (std::istream& theStream, if (aVec3->SquareModulus() >= THE_NORMAL_PREC2) { myCoordSysConverter.TransformNormal (*aVec3); - setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_Dir (aVec3->x(), aVec3->y(), aVec3->z())); + setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_XYZ (aVec3->x(), aVec3->y(), aVec3->z())); } else { - setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_Dir (0.0, 0.0, 1.0)); + setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp::DZ().XYZ()); } } } @@ -353,11 +353,11 @@ bool RWGltf_TriangulationReader::readBuffer (std::istream& theStream, } if (aVec3->SquareModulus() >= THE_NORMAL_PREC2) { - setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_Dir (aVec3->x(), aVec3->y(), aVec3->z())); + setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_XYZ (aVec3->x(), aVec3->y(), aVec3->z())); } else { - setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_Dir (0.0, 0.0, 1.0)); + setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp::DZ().XYZ()); } } } diff --git a/src/RWGltf/RWGltf_TriangulationReader.hxx b/src/RWGltf/RWGltf_TriangulationReader.hxx index c6d859c8d3..b36b06a2c8 100644 --- a/src/RWGltf/RWGltf_TriangulationReader.hxx +++ b/src/RWGltf/RWGltf_TriangulationReader.hxx @@ -52,14 +52,8 @@ protected: //! @name interface for filling triangulation data //! Resize array of position nodes to specified size. virtual bool setNbPositionNodes (Standard_Integer theNbNodes) { - if (theNbNodes <= 0) - { - return false; - } - Standard_Integer i = myTriangulation->NbNodes(); - while (++i <= theNbNodes) - myTriangulation->AddNode (gp::Origin()); - return true; + myTriangulation->ResizeNodes (theNbNodes); + return theNbNodes > 0; } //! Set node position. @@ -72,15 +66,9 @@ protected: //! @name interface for filling triangulation data } //! Resize array of UV nodes to specified size. - virtual bool setNbUVNodes (Standard_Integer theNbNodes) + virtual bool setNbUVNodes (Standard_Integer /*theNbNodes*/) { - if (theNbNodes <= 0 - || myTriangulation->NbNodes() != theNbNodes) - { - return false; - } - - // Resizing of the array of nodes extends the array of UV-nodes too. + // Resizing of the array of nodes extends an array of UV-nodes too. return true; } @@ -94,14 +82,9 @@ protected: //! @name interface for filling triangulation data } //! Resize array of nodes normals to specified size. - virtual bool setNbNormalNodes (Standard_Integer theNbNodes) + virtual bool setNbNormalNodes (Standard_Integer /*theNbNodes*/) { - if (theNbNodes <= 0 - || myTriangulation->NbNodes() != theNbNodes) - { - return false; - } - myTriangulation->SetNormals (new TShort_HArray1OfShortReal (1, theNbNodes * 3)); + // Resizing of the array of nodes extends an array of normals too. return true; } @@ -109,7 +92,7 @@ protected: //! @name interface for filling triangulation data //! @param theIndex node index starting from 1 //! @param theNormal node normal virtual void setNodeNormal (Standard_Integer theIndex, - const gp_Dir& theNormal) + const gp_XYZ& theNormal) { myTriangulation->SetNormal (theIndex, theNormal); } @@ -117,15 +100,8 @@ protected: //! @name interface for filling triangulation data //! Resize array of triangles to specified size. virtual bool setNbTriangles (Standard_Integer theNbTris) { - if (theNbTris >= 1) - { - Poly_Triangle emptyTri (0, 0, 0); - Standard_Integer i = myTriangulation->NbTriangles(); - while (++i <= theNbTris) - myTriangulation->AddTriangle (emptyTri); - return true; - } - return false; + myTriangulation->ResizeTriangles (theNbTris); + return theNbTris > 0; } //! Add triangle element. diff --git a/src/RWMesh/RWMesh_FaceIterator.cxx b/src/RWMesh/RWMesh_FaceIterator.cxx index 45bea53a8f..65a86becf9 100644 --- a/src/RWMesh/RWMesh_FaceIterator.cxx +++ b/src/RWMesh/RWMesh_FaceIterator.cxx @@ -132,7 +132,8 @@ gp_Dir RWMesh_FaceIterator::normal (Standard_Integer theNode) gp_Dir aNormal (gp::DZ()); if (myPolyTriang->HasNormals()) { - aNormal = myPolyTriang->Normal (theNode); + const Vec3f& aVec = myPolyTriang->Normal (theNode); + aNormal.SetCoord (aVec.x(), aVec.y(), aVec.z()); if (aNormal.XYZ().Modulus() < Precision::Confusion()) aNormal = gp::DZ(); } diff --git a/src/RWObj/RWObj_TriangulationReader.cxx b/src/RWObj/RWObj_TriangulationReader.cxx index 1299643b26..912dce87fe 100644 --- a/src/RWObj/RWObj_TriangulationReader.cxx +++ b/src/RWObj/RWObj_TriangulationReader.cxx @@ -167,30 +167,19 @@ Handle(Poly_Triangulation) RWObj_TriangulationReader::GetTriangulation() } if (hasNormals) { - const Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, myNodes.Length() * 3); - Standard_ShortReal* aNormArr = &aNormals->ChangeFirst(); - Standard_Integer aNbInvalid = 0; for (Standard_Integer aNodeIter = 0; aNodeIter < myNodes.Size(); ++aNodeIter) { const Graphic3d_Vec3& aNorm = myNormals.Value (aNodeIter); const float aMod2 = aNorm.SquareModulus(); if (aMod2 > 0.001f) { - aNormArr[aNodeIter * 3 + 0] = aNorm.x(); - aNormArr[aNodeIter * 3 + 1] = aNorm.y(); - aNormArr[aNodeIter * 3 + 2] = aNorm.z(); + aPoly->SetNormal (aNodeIter + 1, aNorm.x(), aNorm.y(), aNorm.z()); } else { - ++aNbInvalid; - aNormArr[aNodeIter * 3 + 0] = 0.0f; - aNormArr[aNodeIter * 3 + 1] = 0.0f; - aNormArr[aNodeIter * 3 + 2] = 1.0f; + aPoly->SetNormal (aNodeIter + 1, 0.0f, 0.0f, 1.0f); } - } - if (aNbInvalid != myNodes.Length()) - { - aPoly->SetNormals (aNormals); + aPoly->SetNormal (aNodeIter + 1, aNorm.x(), aNorm.y(), aNorm.z()); } } diff --git a/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx b/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx index e037077ccf..6ae87b152e 100644 --- a/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx +++ b/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx @@ -157,7 +157,6 @@ void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace, } const Standard_Real aTol = Precision::Confusion(); - Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, theTris->NbNodes() * 3); Standard_Integer aTri[3]; gp_Dir aNorm; for (Standard_Integer aNodeIter = 1; aNodeIter <= theTris->NbNodes(); ++aNodeIter) @@ -187,13 +186,10 @@ void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace, const Standard_Real aModMax = eqPlan.Modulus(); aNorm = (aModMax > aTol) ? gp_Dir (eqPlan) : gp::DZ(); } - - const Standard_Integer anId = (aNodeIter - 1) * 3; - aNormals->SetValue (anId + 1, (Standard_ShortReal )aNorm.X()); - aNormals->SetValue (anId + 2, (Standard_ShortReal )aNorm.Y()); - aNormals->SetValue (anId + 3, (Standard_ShortReal )aNorm.Z()); + theTris->SetNormal (aNodeIter, static_cast(aNorm.X()), + static_cast(aNorm.Y()), + static_cast(aNorm.Z())); } - theTris->SetNormals (aNormals); } //======================================================================= @@ -212,7 +208,8 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace, for (Standard_Integer aNodeIter = 1; aNodeIter <= aPolyTri->NbNodes(); ++aNodeIter) { - theNormals.ChangeValue (aNodeIter) = aPolyTri->Normal (aNodeIter); + const Vec3f& aNormal = aPolyTri->Normal (aNodeIter); + theNormals.ChangeValue (aNodeIter).SetCoord (aNormal.x(), aNormal.y(), aNormal.z()); } if (theFace.Orientation() == TopAbs_REVERSED) diff --git a/src/TDataXtd/TDataXtd_SurfacicMesh.cxx b/src/TDataXtd/TDataXtd_SurfacicMesh.cxx index 280f9e9578..6c3bb758ff 100644 --- a/src/TDataXtd/TDataXtd_SurfacicMesh.cxx +++ b/src/TDataXtd/TDataXtd_SurfacicMesh.cxx @@ -35,7 +35,7 @@ const Standard_GUID& TDataXtd_SurfacicMesh::GetID() //purpose : //======================================================================= static Handle(TDataXtd_SurfacicMesh) SetAttr (const TDF_Label& theLabel, - const Standard_GUID& theID) + const Standard_GUID& theID) { Handle(TDataXtd_SurfacicMesh) hMesh; if (!theLabel.FindAttribute (theID, hMesh)) { @@ -60,7 +60,7 @@ Handle(TDataXtd_SurfacicMesh) TDataXtd_SurfacicMesh::Set (const TDF_Label& theLa //purpose : //======================================================================= Handle(TDataXtd_SurfacicMesh) TDataXtd_SurfacicMesh::Set (const TDF_Label& theLabel, - const Standard_GUID& theID) + const Standard_GUID& theID) { return SetAttr (theLabel, theID); } @@ -70,7 +70,7 @@ Handle(TDataXtd_SurfacicMesh) TDataXtd_SurfacicMesh::Set (const TDF_Label& theLa //purpose : //======================================================================= Handle(TDataXtd_SurfacicMesh) TDataXtd_SurfacicMesh::Set (const TDF_Label& theLabel, - const Handle(Poly_Mesh)& theMesh) + const Handle(Poly_Mesh)& theMesh) { Handle(TDataXtd_SurfacicMesh) hMesh = Set (theLabel); hMesh->Set (theMesh); @@ -82,8 +82,8 @@ Handle(TDataXtd_SurfacicMesh) TDataXtd_SurfacicMesh::Set (const TDF_Label& theLa //purpose : //======================================================================= Handle(TDataXtd_SurfacicMesh) TDataXtd_SurfacicMesh::Set (const TDF_Label& theLabel, - const Standard_GUID& theID, - const Handle(Poly_Mesh)& theMesh) + const Standard_GUID& theID, + const Handle(Poly_Mesh)& theMesh) { Handle(TDataXtd_SurfacicMesh) hMesh = Set (theLabel, theID); hMesh->Set (theMesh); @@ -167,6 +167,15 @@ Standard_Integer TDataXtd_SurfacicMesh::NbTriangles() const return myMesh->NbTriangles(); } +//======================================================================= +//function : NbQuads +//purpose : +//======================================================================= +Standard_Integer TDataXtd_SurfacicMesh::NbQuads() const +{ + return myMesh->NbQuads(); +} + //======================================================================= //function : HasUVNodes //purpose : @@ -177,13 +186,13 @@ Standard_Boolean TDataXtd_SurfacicMesh::HasUVNodes() const } //======================================================================= -//function : AddNode +//function : SetNode //purpose : //======================================================================= -Standard_Integer TDataXtd_SurfacicMesh::AddNode (const gp_Pnt& theNode) +void TDataXtd_SurfacicMesh::SetNode (const Standard_Integer& theIndex, const gp_Pnt& theNode) { Backup(); - return myMesh->AddNode (theNode); + myMesh->ChangeNode (theIndex) = theNode; } //======================================================================= @@ -196,13 +205,13 @@ const gp_Pnt& TDataXtd_SurfacicMesh::Node (const Standard_Integer theIndex) cons } //======================================================================= -//function : SetNode +//function : SetUVNode //purpose : //======================================================================= -void TDataXtd_SurfacicMesh::SetNode (const Standard_Integer theIndex, const gp_Pnt& theNode) +void TDataXtd_SurfacicMesh::SetUVNode(const Standard_Integer theIndex, const gp_Pnt2d& theUVNode) { - Backup(); - myMesh->ChangeNode (theIndex) = theNode; + Backup(); + myMesh->ChangeUVNode (theIndex) = theUVNode; } //======================================================================= @@ -215,53 +224,41 @@ const gp_Pnt2d& TDataXtd_SurfacicMesh::UVNode (const Standard_Integer theIndex) } //======================================================================= -//function : SetUVNode -//purpose : -//======================================================================= -void TDataXtd_SurfacicMesh::SetUVNode (const Standard_Integer theIndex, const gp_Pnt2d& theUVNode) -{ - Backup(); - myMesh->ChangeUVNode (theIndex) = theUVNode; -} - -//======================================================================= -//function : AddTriangle +//function : SetTriangle //purpose : //======================================================================= -Standard_Integer TDataXtd_SurfacicMesh::AddTriangle (const Poly_Triangle& theTriangle) +void TDataXtd_SurfacicMesh::SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle) { Backup(); - return myMesh->AddTriangle (theTriangle); + myMesh->ChangeTriangle (theIndex) = theTriangle; } //======================================================================= //function : Triangle //purpose : //======================================================================= -const Poly_Triangle& TDataXtd_SurfacicMesh::Triangle (const Standard_Integer theIndex) const +const Poly_Triangle& TDataXtd_SurfacicMesh::Triangle(const Standard_Integer theIndex) const { return myMesh->Triangle (theIndex); } //======================================================================= -//function : SetTriangle +//function : SetQuad //purpose : //======================================================================= -void TDataXtd_SurfacicMesh::SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle) +void TDataXtd_SurfacicMesh::SetQuad (const Standard_Integer theIndex, const Poly_Quad& theQuad) { Backup(); - myMesh->ChangeTriangle (theIndex) = theTriangle; + myMesh->ChangeQuad (theIndex) = theQuad; } //======================================================================= -//function : SetNormal +//function : Quad //purpose : //======================================================================= -void TDataXtd_SurfacicMesh::SetNormal (const Standard_Integer theIndex, - const gp_Dir& theNormal) +const Poly_Quad& TDataXtd_SurfacicMesh::Quad (const Standard_Integer theIndex) const { - Backup(); - myMesh->SetNormal (theIndex, theNormal); + return myMesh->Quad (theIndex); } //======================================================================= @@ -274,87 +271,36 @@ Standard_Boolean TDataXtd_SurfacicMesh::HasNormals() const } //======================================================================= -//function : Normal +//function : SetNormal //purpose : //======================================================================= -const gp_Dir TDataXtd_SurfacicMesh::Normal (const Standard_Integer theIndex) const -{ - return myMesh->Normal (theIndex); -} - -//======================================================================= -//function : AddElement -//purpose : -//======================================================================= -Standard_Integer TDataXtd_SurfacicMesh::AddElement (const Standard_Integer theN1, - const Standard_Integer theN2, - const Standard_Integer theN3) -{ - Backup(); - return myMesh->AddElement (theN1, theN2, theN3); -} - -//======================================================================= -//function : AddElement -//purpose : -//======================================================================= -Standard_Integer TDataXtd_SurfacicMesh::AddElement (const Standard_Integer theN1, - const Standard_Integer theN2, - const Standard_Integer theN3, - const Standard_Integer theN4) +void TDataXtd_SurfacicMesh::SetNormal (const Standard_Integer theIndex, + const gp_XYZ& theNormal) { Backup(); - return myMesh->AddElement (theN1, theN2, theN3, theN4); -} - -//======================================================================= -//function : NbElements -//purpose : -//======================================================================= -Standard_Integer TDataXtd_SurfacicMesh::NbElements() const -{ - return myMesh->NbElements(); -} - -//======================================================================= -//function : NbQuads -//purpose : -//======================================================================= -Standard_Integer TDataXtd_SurfacicMesh::NbQuads() const -{ - return myMesh->NbQuads(); -} - -//======================================================================= -//function : Element -//purpose : -//======================================================================= -const Poly_Element& TDataXtd_SurfacicMesh::Element (const Standard_Integer theIndex) const -{ - return myMesh->Element (theIndex); + myMesh->SetNormal (theIndex, theNormal); } //======================================================================= -//function : Element +//function : SetNormal //purpose : //======================================================================= -void TDataXtd_SurfacicMesh::Element (const Standard_Integer theIndex, - Standard_Integer& theN1, - Standard_Integer& theN2, - Standard_Integer& theN3, - Standard_Integer& theN4) const +void TDataXtd_SurfacicMesh::SetNormal (const Standard_Integer theIndex, + const Standard_ShortReal theNormalX, + const Standard_ShortReal theNormalY, + const Standard_ShortReal theNormalZ) { - myMesh->Element (theIndex, theN1, theN2, theN3, theN4); + Backup(); + myMesh->SetNormal (theIndex, theNormalX, theNormalY, theNormalZ); } //======================================================================= -//function : SetElement +//function : Normal //purpose : //======================================================================= -void TDataXtd_SurfacicMesh::SetElement (const Standard_Integer theIndex, const Poly_Element& theElement) +const Vec3f& TDataXtd_SurfacicMesh::Normal (const Standard_Integer theIndex) const { - Backup(); - myMesh->SetElement (theIndex, theElement); + return myMesh->Normal (theIndex); } //======================================================================= @@ -417,7 +363,7 @@ void TDataXtd_SurfacicMesh::Restore (const Handle(TDF_Attribute)& theWithMesh) //purpose : //======================================================================= void TDataXtd_SurfacicMesh::Paste (const Handle(TDF_Attribute)& theIntoMesh, - const Handle(TDF_RelocationTable)& ) const + const Handle(TDF_RelocationTable)& ) const { Handle(TDataXtd_SurfacicMesh) intoMesh = Handle(TDataXtd_SurfacicMesh)::DownCast (theIntoMesh); intoMesh->myMesh.Nullify(); @@ -444,6 +390,7 @@ Standard_OStream& TDataXtd_SurfacicMesh::Dump (Standard_OStream& theOS) const theOS << "\n\tDeflection: " << myMesh->Deflection(); theOS << "\n\tNodes: " << myMesh->NbNodes(); theOS << "\n\tTriangles: " << myMesh->NbTriangles(); + theOS << "\n\tQuadrangles: " << myMesh->NbQuads(); if (myMesh->HasUVNodes()) theOS << "\n\tHas UV-Nodes"; else diff --git a/src/TDataXtd/TDataXtd_SurfacicMesh.hxx b/src/TDataXtd/TDataXtd_SurfacicMesh.hxx index 055b033d5f..f8a1d7c220 100644 --- a/src/TDataXtd/TDataXtd_SurfacicMesh.hxx +++ b/src/TDataXtd/TDataXtd_SurfacicMesh.hxx @@ -33,10 +33,7 @@ class TDataXtd_SurfacicMesh; DEFINE_STANDARD_HANDLE(TDataXtd_SurfacicMesh, TDF_Attribute) //! An Ocaf attribute containing a mesh (Poly_Mesh). -//! It duplicates all methods from Poly_Mesh (and Poly_Triangulation). -//! It is highly recommended to modify the mesh through the methods of this attribute, -//! but not directly via the underlying Poly_Mesh object. -//! In this case Undo/Redo will work fine and robust. +//! It includes all methods of Poly_Mesh (and Poly_Triangulation). class TDataXtd_SurfacicMesh : public TDF_Attribute { public: @@ -53,20 +50,20 @@ public: //! Finds or creates a mesh attribute with specified ID. //! It allows setting several mesh-attributes at the same label. Standard_EXPORT static Handle(TDataXtd_SurfacicMesh) Set (const TDF_Label& theLabel, - const Standard_GUID& theID); + const Standard_GUID& theID); //! Finds or creates a mesh attribute. //! Initializes the attribute by a mesh (Poly_Mesh) object. //! If the mesh consists of only triangles, //! you may put Poly_Triangulation object as a 2nd parameter of this method. Standard_EXPORT static Handle(TDataXtd_SurfacicMesh) Set (const TDF_Label& theLabel, - const Handle(Poly_Mesh)& theMesh); + const Handle(Poly_Mesh)& theMesh); //! Finds or creates a mesh attribute (the same method as above). //! Additionally, it allows setting several mesh-attributes at the same label. Standard_EXPORT static Handle(TDataXtd_SurfacicMesh) Set (const TDF_Label& theLabel, - const Standard_GUID& theID, - const Handle(Poly_Mesh)& theMesh); + const Standard_GUID& theID, + const Handle(Poly_Mesh)& theMesh); //! Object methods // ============== @@ -96,117 +93,70 @@ public: // ================= //! The methods are "covered" by this attribute to prevent direct modification of the mesh. - //! There is no performance problem to call Poly_Mesh method through this attribute. - //! The most of the methods are considered as "inline" by the compiler in release mode. //! Returns the deflection of this triangulation. Standard_EXPORT Standard_Real Deflection() const; - //! Sets the deflection of this triangulation to theDeflection. - //! See more on deflection in Polygon2D + //! Sets the deflection of this mesh to theDeflection. Standard_EXPORT void Deflection (const Standard_Real theDeflection); //! Deallocates the UV nodes. Standard_EXPORT void RemoveUVNodes(); - //! @return the number of nodes for this triangulation. + //! @return the number of nodes for this mesh. Standard_EXPORT Standard_Integer NbNodes() const; - //! @return the number of triangles for this triangulation. + //! @return the number of triangles for this mesh. Standard_EXPORT Standard_Integer NbTriangles() const; - //! @return Standard_True if 2D nodes are associated with 3D nodes for this triangulation. + //! @return the number of quadrangles for this mesh. + Standard_EXPORT Standard_Integer NbQuads() const; + + //! @return Standard_True if 2D nodes are associated with 3D nodes for this mesh. Standard_EXPORT Standard_Boolean HasUVNodes() const; - //! Adds Node to the triangulation. If triangulation has UVNodes or Normals - //! they will be expanded and set to zero values to match the new number of nodes. - //! @return index of the added Node. - Standard_EXPORT Standard_Integer AddNode (const gp_Pnt& theNode); + //! Sets a node by index. + Standard_EXPORT void SetNode (const Standard_Integer& theIndex, const gp_Pnt& theNode); - //! @return node at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. + //! Returns a node by index. Standard_EXPORT const gp_Pnt& Node (const Standard_Integer theIndex) const; - //! The method differs from Poly_Mesh! - //! Sets a node at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. - Standard_EXPORT void SetNode (const Standard_Integer theIndex, const gp_Pnt& theNode); + //! Sets a UV-node by index. + Standard_EXPORT void SetUVNode (const Standard_Integer theIndex, const gp_Pnt2d& theUVNode); - //! @return UVNode at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. + //! Returns an UV-node by index. Standard_EXPORT const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const; - //! The method differs from Poly_Mesh! - //! Sets a UVNode at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. - Standard_EXPORT void SetUVNode (const Standard_Integer theIndex, const gp_Pnt2d& theUVNode); - - //! Adds triangle to the triangulation. - //! @return index of the added triangle. - Standard_EXPORT Standard_Integer AddTriangle (const Poly_Triangle& theTriangle); + //! Sets a triangle by index. + Standard_EXPORT void SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle); - //! @return triangle at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. + //! Returns a triangle by index. Standard_EXPORT const Poly_Triangle& Triangle (const Standard_Integer theIndex) const; - //! The method differs from Poly_Mesh! - //! Sets a triangle at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. - Standard_EXPORT void SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle); + //! Sets a quadrangle by index. + Standard_EXPORT void SetQuad (const Standard_Integer theIndex, const Poly_Quad& theQuad); - //! Changes normal at the given index. - //! Raises Standard_OutOfRange exception. - Standard_EXPORT void SetNormal (const Standard_Integer theIndex, - const gp_Dir& theNormal); + //! Returns a quadrangle by index. + Standard_EXPORT const Poly_Quad& Quad (const Standard_Integer theIndex) const; //! Returns Standard_True if nodal normals are defined. Standard_EXPORT Standard_Boolean HasNormals() const; - //! @return normal at the given index. - //! Raises Standard_OutOfRange exception. - Standard_EXPORT const gp_Dir Normal (const Standard_Integer theIndex) const; - - //! Adds element to the mesh. - //! @param theN1 index of the first node. - //! @param theN2 index of the second node. - //! @param theN3 index of the third node. - //! @return index of the added element. - Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1, - const Standard_Integer theN2, - const Standard_Integer theN3); - - //! Adds element to the mesh. - //! @param theN1 index of the first node. - //! @param theN2 index of the second node. - //! @param theN3 index of the third node. - //! @param theN4 index of the fourth node. - //! @return index of the added element. - Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1, - const Standard_Integer theN2, - const Standard_Integer theN3, - const Standard_Integer theN4); - - //! @return the number of elements for this mesh. - Standard_EXPORT Standard_Integer NbElements() const; - - //! @return the number of quads for this mesh. - Standard_EXPORT Standard_Integer NbQuads() const; + //! Sets normal by index. + Standard_EXPORT void SetNormal (const Standard_Integer theIndex, + const gp_XYZ& theNormal); + + //! Sets normal by index. + Standard_EXPORT void SetNormal (const Standard_Integer theIndex, + const Standard_ShortReal theNormalX, + const Standard_ShortReal theNormalY, + const Standard_ShortReal theNormalZ); + + //! Returns normal by index. + Standard_EXPORT const Vec3f& Normal(const Standard_Integer theIndex) const; - //! @return element at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. - Standard_EXPORT const Poly_Element& Element (const Standard_Integer theIndex) const; - - //! @return nodes of the element at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. - Standard_EXPORT void Element (const Standard_Integer theIndex, - Standard_Integer& theN1, - Standard_Integer& theN2, - Standard_Integer& theN3, - Standard_Integer& theN4) const; - - //! Sets an element at the given index. - //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. - Standard_EXPORT void SetElement (const Standard_Integer theIndex, const Poly_Element& theElement); + //! Returns normal by index. + Standard_EXPORT void Normal(const Standard_Integer theIndex, gp_XYZ& theNormal) const; //! Dumps the content of me into the stream Standard_EXPORT virtual void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; diff --git a/src/TDataXtd/TDataXtd_Triangulation.cxx b/src/TDataXtd/TDataXtd_Triangulation.cxx index 60d0249626..aad1cb9c85 100644 --- a/src/TDataXtd/TDataXtd_Triangulation.cxx +++ b/src/TDataXtd/TDataXtd_Triangulation.cxx @@ -217,27 +217,16 @@ void TDataXtd_Triangulation::SetTriangle (const Standard_Integer theIndex, const myTriangulation->ChangeTriangle(theIndex) = theTriangle; } -//======================================================================= -//function : SetNormals -//purpose : Sets the table of node normals. -// Raises exception if length of theNormals = 3 * NbNodes -//======================================================================= -void TDataXtd_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals) -{ - Backup(); - myTriangulation->SetNormals(theNormals); -} - //======================================================================= //function : SetNormal //purpose : Changes normal at the given index. // Raises Standard_OutOfRange exception. //======================================================================= void TDataXtd_Triangulation::SetNormal (const Standard_Integer theIndex, - const gp_Dir& theNormal) + const gp_Dir& theNormal) { Backup(); - myTriangulation->SetNormal(theIndex, theNormal); + myTriangulation->SetNormal (theIndex, theNormal.XYZ()); } //======================================================================= @@ -256,7 +245,9 @@ Standard_Boolean TDataXtd_Triangulation::HasNormals() const //======================================================================= const gp_Dir TDataXtd_Triangulation::Normal (const Standard_Integer theIndex) const { - return myTriangulation->Normal(theIndex); + const Vec3f& aVec = myTriangulation->Normal (theIndex); + gp_Dir aDir (aVec.x(), aVec.y(), aVec.z()); + return aDir; } //======================================================================= diff --git a/src/TDataXtd/TDataXtd_Triangulation.hxx b/src/TDataXtd/TDataXtd_Triangulation.hxx index b127dd8c4a..1c52fa4652 100644 --- a/src/TDataXtd/TDataXtd_Triangulation.hxx +++ b/src/TDataXtd/TDataXtd_Triangulation.hxx @@ -123,10 +123,6 @@ public: //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. Standard_EXPORT void SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle); - //! Sets the table of node normals. - //! Raises exception if length of theNormals != 3 * NbNodes - Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals); - //! Changes normal at the given index. //! Raises Standard_OutOfRange exception. Standard_EXPORT void SetNormal (const Standard_Integer theIndex, diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index d65c6702e5..67ca7cf77c 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -2900,8 +2900,6 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z Poly_Connect* pc = new Poly_Connect(polyTriangulation); - Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3); - Standard_Integer index[3]; Standard_Real Tol = Precision::Confusion(); @@ -2925,15 +2923,10 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z else Nor = gp_Dir(0., 0., 1.); - Standard_Integer j = (i - 1) * 3; - Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X()); - Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y()); - Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z()); + polyTriangulation->SetNormal (i, Nor.XYZ()); } delete pc; - polyTriangulation->SetNormals(Normals); - return polyTriangulation; } diff --git a/src/VrmlData/VrmlData_ShapeConvert.cxx b/src/VrmlData/VrmlData_ShapeConvert.cxx index df33020499..63091ccdce 100644 --- a/src/VrmlData/VrmlData_ShapeConvert.cxx +++ b/src/VrmlData/VrmlData_ShapeConvert.cxx @@ -400,7 +400,8 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet Standard_Integer j; for (i = 0, j = 1; i < nNodes; i++, j += 3) { - gp_XYZ aNormal = theTri->Normal (i + 1).XYZ(); + const Vec3f& aVec = theTri->Normal (i + 1); + gp_XYZ aNormal (aVec.x(), aVec.y(), aVec.z()); if (isReverse) { aNormal.Reverse(); @@ -466,16 +467,10 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet aNormal.SetY(0.); if (aNormal.Z()*aNormal.Z() < aConf2) aNormal.SetZ(0.); - arrVec[i] = aNormal.XYZ(); - - Standard_Integer j = i * 3; - Normals->SetValue(j + 1, (Standard_ShortReal)aNormal.X()); - Normals->SetValue(j + 2, (Standard_ShortReal)aNormal.Y()); - Normals->SetValue(j + 3, (Standard_ShortReal)aNormal.Z()); + arrVec[i] = aNormal.XYZ(); + theTri->SetNormal (i + 1, aNormal.XYZ()); } - - theTri->SetNormals(Normals); const Handle(VrmlData_Normal) aNormalNode = new VrmlData_Normal (myScene, 0L, nNodes, arrVec); diff --git a/src/XmlMDataXtd/XmlMDataXtd_SurfacicMeshDriver.cxx b/src/XmlMDataXtd/XmlMDataXtd_SurfacicMeshDriver.cxx index 069242b753..b88fb04593 100644 --- a/src/XmlMDataXtd/XmlMDataXtd_SurfacicMeshDriver.cxx +++ b/src/XmlMDataXtd/XmlMDataXtd_SurfacicMeshDriver.cxx @@ -53,8 +53,8 @@ Handle(TDF_Attribute) XmlMDataXtd_SurfacicMeshDriver::NewEmpty() const //purpose : persistent -> transient (retrieve) //======================================================================= Standard_Boolean XmlMDataXtd_SurfacicMeshDriver::Paste (const XmlObjMgt_Persistent& theSource, - const Handle(TDF_Attribute)& theTarget, - XmlObjMgt_RRelocationTable& ) const + const Handle(TDF_Attribute)& theTarget, + XmlObjMgt_RRelocationTable& ) const { const XmlObjMgt_Element& anElement = theSource; Handle(TDataXtd_SurfacicMesh) attrMesh = Handle(TDataXtd_SurfacicMesh)::DownCast (theTarget); @@ -94,8 +94,8 @@ Standard_Boolean XmlMDataXtd_SurfacicMeshDriver::Paste (const XmlObjMgt_Persiste //purpose : transient -> persistent (store) //======================================================================= void XmlMDataXtd_SurfacicMeshDriver::Paste (const Handle(TDF_Attribute)& theSource, - XmlObjMgt_Persistent& theTarget, - XmlObjMgt_SRelocationTable& ) const + XmlObjMgt_Persistent& theTarget, + XmlObjMgt_SRelocationTable& ) const { const Handle(TDataXtd_SurfacicMesh) meshAttr = Handle(TDataXtd_SurfacicMesh)::DownCast (theSource); if (meshAttr->Get().IsNull()) @@ -110,7 +110,8 @@ void XmlMDataXtd_SurfacicMeshDriver::Paste (const Handle(TDF_Attribute)& theSour Standard_Integer aSize = aMesh->NbNodes(); aSize *= 3; // 3 coordinates for a node aSize *= 8; // 8 characters are used to represent a coordinate (double) in XML - aSize += 4 * 5 * aMesh->NbElements(); // space for elements (triangles and quadrangles) + aSize += 3 * 5 * aMesh->NbTriangles(); // space for triangles (3 integers of 5 symbols) + aSize += 4 * 5 * aMesh->NbQuads(); // space for quadrangles (4 integers of 5 symbols) aSize *= 2; // just in case :-) if (!aSize) aSize = 1; -- 2.39.5