diff --git a/src/Poly/FILES b/src/Poly/FILES index 5452e22df2..3d22dcd6b9 100755 --- a/src/Poly/FILES +++ b/src/Poly/FILES @@ -13,7 +13,6 @@ Poly_CoherentTriPtr.cxx Poly_CoherentTriPtr.hxx Poly_Connect.cxx Poly_Connect.hxx -Poly_Connect.lxx Poly_HArray1OfTriangle.hxx Poly_ListOfTriangulation.hxx Poly_MakeLoops.cxx diff --git a/src/Poly/Poly_Connect.cxx b/src/Poly/Poly_Connect.cxx index 992053902a..2d2590e704 100644 --- a/src/Poly/Poly_Connect.cxx +++ b/src/Poly/Poly_Connect.cxx @@ -14,42 +14,89 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. - #include + #include #include -#include + +// this structure records one of the edges starting from a node +struct polyedge +{ + polyedge* next; // the next edge in the list + Standard_Integer nd; // the second node of the edge + Standard_Integer nt[2]; // the two adjacent triangles + Standard_Integer nn[2]; // the two adjacent nodes + DEFINE_STANDARD_ALLOC +}; //======================================================================= //function : Poly_Connect -//purpose : +//purpose : //======================================================================= -// this structure records one of the edges starting from a node -//typedef struct polyedge { -struct polyedge { - polyedge* next; // the next edge in the list - Standard_Integer nd; // the second node of the edge - Standard_Integer nt[2]; // the two adjacent triangles - Standard_Integer nn[2]; // the two adjacent nodes - DEFINE_STANDARD_ALLOC - }; - -Poly_Connect::Poly_Connect(const Handle(Poly_Triangulation)& T) : - myTriangulation(T), - myTriangles(1,T->NbNodes()), - myAdjacents(1,6*T->NbTriangles()) +Poly_Connect::Poly_Connect() +: mytr (0), + myfirst (0), + mynode (0), + myothernode (0), + mysense (false), + mymore (false) { + // +} + +//======================================================================= +//function : Poly_Connect +//purpose : +//======================================================================= +Poly_Connect::Poly_Connect(const Handle(Poly_Triangulation)& theTriangulation) +: myTriangulation (theTriangulation), + myTriangles (1, theTriangulation->NbNodes()), + myAdjacents (1, 6 * theTriangulation->NbTriangles()), + mytr (0), + myfirst (0), + mynode (0), + myothernode (0), + mysense (false), + mymore (false) +{ + Load (theTriangulation); +} + +//======================================================================= +//function : Load +//purpose : +//======================================================================= +void Poly_Connect::Load (const Handle(Poly_Triangulation)& theTriangulation) +{ + myTriangulation = theTriangulation; + mytr = 0; + myfirst = 0; + mynode = 0; + myothernode = 0; + mysense = false; + mymore = false; + + const Standard_Integer nbNodes = myTriangulation->NbNodes(); + const Standard_Integer nbTriangles = myTriangulation->NbTriangles(); + { + const Standard_Integer aNbAdjs = 6 * nbTriangles; + if (myTriangles.Size() != nbNodes) + { + TColStd_Array1OfInteger aTriArray (1, nbNodes); + myTriangles.Move (std::move (aTriArray)); + } + if (myAdjacents.Size() != aNbAdjs) + { + TColStd_Array1OfInteger anAdjArray (1, aNbAdjs); + myAdjacents.Move (std::move (anAdjArray)); + } + } + myTriangles.Init(0); myAdjacents.Init(0); - Standard_Integer nbNodes = myTriangulation->NbNodes(); - Standard_Integer nbTriangles = myTriangulation->NbTriangles(); // We first build an array of the list of edges connected to the nodes - - - // create an array to store the edges starting from the vertices - Standard_Integer i; // the last node is not used because edges are stored at the lower node index polyedge** edges = new polyedge*[nbNodes]; @@ -164,39 +211,6 @@ Poly_Connect::Poly_Connect(const Handle(Poly_Triangulation)& T) : delete [] edges; } -//======================================================================= -//function : Triangles -//purpose : -//======================================================================= - -void Poly_Connect::Triangles(const Standard_Integer T, - Standard_Integer& t1, - Standard_Integer& t2, - Standard_Integer& t3) const -{ - Standard_Integer index = 6*(T-1); - t1 = myAdjacents(index+1); - t2 = myAdjacents(index+2); - t3 = myAdjacents(index+3); -} - -//======================================================================= -//function : Nodes -//purpose : -//======================================================================= - -void Poly_Connect::Nodes(const Standard_Integer T, - Standard_Integer& n1, - Standard_Integer& n2, - Standard_Integer& n3) const -{ - Standard_Integer index = 6*(T-1); - n1 = myAdjacents(index+4); - n2 = myAdjacents(index+5); - n3 = myAdjacents(index+6); -} - - //======================================================================= //function : Initialize //purpose : @@ -272,14 +286,3 @@ void Poly_Connect::Next() } mymore = Standard_False; } - - -//======================================================================= -//function : Value -//purpose : -//======================================================================= - -Standard_Integer Poly_Connect::Value() const -{ - return mytr; -} diff --git a/src/Poly/Poly_Connect.hxx b/src/Poly/Poly_Connect.hxx index 5c7ede16c5..29fa2024a3 100644 --- a/src/Poly/Poly_Connect.hxx +++ b/src/Poly/Poly_Connect.hxx @@ -26,8 +26,6 @@ #include class Poly_Triangulation; - - //! Provides an algorithm to explore, inside a triangulation, the //! adjacency data for a node or a triangle. //! Adjacency data for a node consists of triangles which @@ -67,33 +65,53 @@ public: DEFINE_STANDARD_ALLOC - + //! Constructs an uninitialized algorithm. + Standard_EXPORT Poly_Connect(); + //! Constructs an algorithm to explore the adjacency data of //! nodes or triangles for the triangulation T. - Standard_EXPORT Poly_Connect(const Handle(Poly_Triangulation)& T); - + Standard_EXPORT Poly_Connect (const Handle(Poly_Triangulation)& theTriangulation); + + //! Initialize the algorithm to explore the adjacency data of + //! nodes or triangles for the triangulation theTriangulation. + Standard_EXPORT void Load (const Handle(Poly_Triangulation)& theTriangulation); + //! Returns the triangulation analyzed by this tool. - Handle(Poly_Triangulation) Triangulation() const; - + const Handle(Poly_Triangulation)& Triangulation() const { return myTriangulation; } + //! Returns the index of a triangle containing the node at //! index N in the nodes table specific to the triangulation analyzed by this tool - Standard_Integer Triangle (const Standard_Integer N) const; - + Standard_Integer Triangle (const Standard_Integer N) const { return myTriangles (N); } + //! Returns in t1, t2 and t3, the indices of the 3 triangles //! adjacent to the triangle at index T in the triangles table //! specific to the triangulation analyzed by this tool. //! Warning //! Null indices are returned when there are fewer than 3 //! adjacent triangles. - Standard_EXPORT void Triangles (const Standard_Integer T, Standard_Integer& t1, Standard_Integer& t2, Standard_Integer& t3) const; - + void Triangles (const Standard_Integer T, Standard_Integer& t1, Standard_Integer& t2, Standard_Integer& t3) const + { + Standard_Integer index = 6*(T-1); + t1 = myAdjacents(index+1); + t2 = myAdjacents(index+2); + t3 = myAdjacents(index+3); + } + //! Returns, in n1, n2 and n3, the indices of the 3 nodes //! adjacent to the triangle referenced at index T in the //! triangles table specific to the triangulation analyzed by this tool. //! Warning //! Null indices are returned when there are fewer than 3 adjacent nodes. - Standard_EXPORT void Nodes (const Standard_Integer T, Standard_Integer& n1, Standard_Integer& n2, Standard_Integer& n3) const; - + void Nodes (const Standard_Integer T, Standard_Integer& n1, Standard_Integer& n2, Standard_Integer& n3) const + { + Standard_Integer index = 6*(T-1); + n1 = myAdjacents(index+4); + n2 = myAdjacents(index+5); + n3 = myAdjacents(index+6); + } + +public: + //! Initializes an iterator to search for all the triangles //! containing the node referenced at index N in the nodes //! table, for the triangulation analyzed by this tool. @@ -116,8 +134,8 @@ public: //! Returns true if there is another element in the iterator //! defined with the function Initialize (i.e. if there is another //! triangle containing the given node). - Standard_Boolean More() const; - + Standard_Boolean More() const { return mymore; } + //! Advances the iterator defined with the function Initialize to //! access the next triangle. //! Note: There is no action if the iterator is empty (i.e. if the @@ -128,21 +146,10 @@ public: //! iterator, defined with the function Initialize, points. This is //! an index in the triangles table specific to the triangulation //! analyzed by this tool - Standard_EXPORT Standard_Integer Value() const; - - - - -protected: - - - - + Standard_Integer Value() const { return mytr; } private: - - Handle(Poly_Triangulation) myTriangulation; TColStd_Array1OfInteger myTriangles; TColStd_Array1OfInteger myAdjacents; @@ -153,14 +160,6 @@ private: Standard_Boolean mysense; Standard_Boolean mymore; - }; - -#include - - - - - #endif // _Poly_Connect_HeaderFile diff --git a/src/Poly/Poly_Connect.lxx b/src/Poly/Poly_Connect.lxx deleted file mode 100644 index 66081ad8a2..0000000000 --- a/src/Poly/Poly_Connect.lxx +++ /dev/null @@ -1,45 +0,0 @@ -// Created on: 1995-03-06 -// Created by: Laurent PAINNOT -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 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. - -//======================================================================= -//function : Triangulation -//purpose : -//======================================================================= - -inline Handle(Poly_Triangulation) Poly_Connect::Triangulation() const -{ - return myTriangulation; -} - -//======================================================================= -//function : Triangle -//purpose : -//======================================================================= - -inline Standard_Integer Poly_Connect::Triangle(const Standard_Integer N) const -{ - return myTriangles(N); -} - -//======================================================================= -//function : More -//purpose : -//======================================================================= - -inline Standard_Boolean Poly_Connect::More() const -{ - return (mymore); -} diff --git a/src/StdPrs/StdPrs_ShadedShape.cxx b/src/StdPrs/StdPrs_ShadedShape.cxx index 59ea4c2c90..e29b6950c0 100644 --- a/src/StdPrs/StdPrs_ShadedShape.cxx +++ b/src/StdPrs/StdPrs_ShadedShape.cxx @@ -186,11 +186,10 @@ namespace // Determinant of transform matrix less then 0 means that mirror transform applied. Standard_Boolean isMirrored = aTrsf.VectorialPart().Determinant() < 0; - Poly_Connect aPolyConnect (aT); // Extracts vertices & normals from nodes const TColgp_Array1OfPnt& aNodes = aT->Nodes(); const TColgp_Array1OfPnt2d& aUVNodes = aT->UVNodes(); - StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect); + StdPrs_ToolTriangulatedShape::ComputeNormals (aFace, aT); const TShort_Array1OfShortReal& aNormals = aT->Normals(); const Standard_ShortReal* aNormArr = &aNormals.First(); diff --git a/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx b/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx index 6d9eaa02b9..e53be8ef5f 100644 --- a/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx +++ b/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx @@ -131,15 +131,15 @@ Standard_Boolean StdPrs_ToolTriangulatedShape::IsClosed (const TopoDS_Shape& the } //======================================================================= -//function : Normal +//function : ComputeNormals //purpose : //======================================================================= -void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace, - Poly_Connect& thePolyConnect) +void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace, + const Handle(Poly_Triangulation)& theTris, + Poly_Connect& thePolyConnect) { - const Handle(Poly_Triangulation)& aPolyTri = thePolyConnect.Triangulation(); - if (aPolyTri.IsNull() - || aPolyTri->HasNormals()) + if (theTris.IsNull() + || theTris->HasNormals()) { return; } @@ -148,13 +148,13 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace, const TopoDS_Face aZeroFace = TopoDS::Face (theFace.Located (TopLoc_Location())); Handle(Geom_Surface) aSurf = BRep_Tool::Surface (aZeroFace); const Standard_Real aTol = Precision::Confusion(); - Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, aPolyTri->NbNodes() * 3); - const Poly_Array1OfTriangle& aTriangles = aPolyTri->Triangles(); - const TColgp_Array1OfPnt2d* aNodesUV = aPolyTri->HasUVNodes() && !aSurf.IsNull() - ? &aPolyTri->UVNodes() + Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, theTris->NbNodes() * 3); + const Poly_Array1OfTriangle& aTriangles = theTris->Triangles(); + const TColgp_Array1OfPnt2d* aNodesUV = theTris->HasUVNodes() && !aSurf.IsNull() + ? &theTris->UVNodes() : NULL; Standard_Integer aTri[3]; - const TColgp_Array1OfPnt& aNodes = aPolyTri->Nodes(); + const TColgp_Array1OfPnt& aNodes = theTris->Nodes(); gp_Dir aNorm; for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) { @@ -162,6 +162,11 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace, if (aNodesUV == NULL || GeomLib::NormEstim (aSurf, aNodesUV->Value (aNodeIter), aTol, aNorm) > 1) { + if (thePolyConnect.Triangulation() != theTris) + { + thePolyConnect.Load (theTris); + } + // compute flat normals gp_XYZ eqPlan (0.0, 0.0, 0.0); for (thePolyConnect.Initialize (aNodeIter); thePolyConnect.More(); thePolyConnect.Next()) @@ -185,7 +190,7 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace, aNormals->SetValue (anId + 2, (Standard_ShortReal )aNorm.Y()); aNormals->SetValue (anId + 3, (Standard_ShortReal )aNorm.Z()); } - aPolyTri->SetNormals (aNormals); + theTris->SetNormals (aNormals); } //======================================================================= @@ -199,7 +204,7 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace, const Handle(Poly_Triangulation)& aPolyTri = thePolyConnect.Triangulation(); if (!aPolyTri->HasNormals()) { - Normal (theFace, thePolyConnect); + ComputeNormals (theFace, aPolyTri, thePolyConnect); } const TColgp_Array1OfPnt& aNodes = aPolyTri->Nodes(); diff --git a/src/StdPrs/StdPrs_ToolTriangulatedShape.hxx b/src/StdPrs/StdPrs_ToolTriangulatedShape.hxx index 0ea94a2245..db85a042e0 100644 --- a/src/StdPrs/StdPrs_ToolTriangulatedShape.hxx +++ b/src/StdPrs/StdPrs_ToolTriangulatedShape.hxx @@ -14,6 +14,7 @@ #ifndef _StdPrs_ToolTriangulatedShape_HeaderFile #define _StdPrs_ToolTriangulatedShape_HeaderFile +#include #include #include #include @@ -42,9 +43,22 @@ public: //! Computes nodal normals for Poly_Triangulation structure using UV coordinates and surface. //! Does nothing if triangulation already defines normals. //! @param theFace [in] the face - //! @param thePolyConnect [in] the definition of a face triangulation - Standard_EXPORT static void Normal (const TopoDS_Face& theFace, - Poly_Connect& thePolyConnect); + //! @param theTris [in] the definition of a face triangulation + static void ComputeNormals (const TopoDS_Face& theFace, + const Handle(Poly_Triangulation)& theTris) + { + Poly_Connect aPolyConnect; + ComputeNormals (theFace, theTris, aPolyConnect); + } + + //! Computes nodal normals for Poly_Triangulation structure using UV coordinates and surface. + //! Does nothing if triangulation already defines normals. + //! @param theFace [in] the face + //! @param theTris [in] the definition of a face triangulation + //! @param thePolyConnect [in,out] optional, initialized tool for exploring triangulation + Standard_EXPORT static void ComputeNormals (const TopoDS_Face& theFace, + const Handle(Poly_Triangulation)& theTris, + Poly_Connect& thePolyConnect); //! Evaluate normals for a triangle of a face. //! @param theFace [in] the face.