Poly_CoherentTriPtr.hxx
Poly_Connect.cxx
Poly_Connect.hxx
-Poly_Connect.lxx
Poly_HArray1OfTriangle.hxx
Poly_ListOfTriangulation.hxx
Poly_MakeLoops.cxx
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-
#include <Poly_Connect.hxx>
+
#include <Poly_Triangle.hxx>
#include <Poly_Triangulation.hxx>
-#include <Standard.hxx>
+
+// 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()
+: 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);
+}
-Poly_Connect::Poly_Connect(const Handle(Poly_Triangulation)& T) :
- myTriangulation(T),
- myTriangles(1,T->NbNodes()),
- myAdjacents(1,6*T->NbTriangles())
+//=======================================================================
+//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];
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 :
}
mymore = Standard_False;
}
-
-
-//=======================================================================
-//function : Value
-//purpose :
-//=======================================================================
-
-Standard_Integer Poly_Connect::Value() const
-{
- return mytr;
-}
#include <Standard_Boolean.hxx>
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
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.
//! 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
//! 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;
Standard_Boolean mysense;
Standard_Boolean mymore;
-
};
-
-#include <Poly_Connect.lxx>
-
-
-
-
-
#endif // _Poly_Connect_HeaderFile
+++ /dev/null
-// 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);
-}
// 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();
}
//=======================================================================
-//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;
}
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)
{
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())
aNormals->SetValue (anId + 2, (Standard_ShortReal )aNorm.Y());
aNormals->SetValue (anId + 3, (Standard_ShortReal )aNorm.Z());
}
- aPolyTri->SetNormals (aNormals);
+ theTris->SetNormals (aNormals);
}
//=======================================================================
const Handle(Poly_Triangulation)& aPolyTri = thePolyConnect.Triangulation();
if (!aPolyTri->HasNormals())
{
- Normal (theFace, thePolyConnect);
+ ComputeNormals (theFace, aPolyTri, thePolyConnect);
}
const TColgp_Array1OfPnt& aNodes = aPolyTri->Nodes();
#ifndef _StdPrs_ToolTriangulatedShape_HeaderFile
#define _StdPrs_ToolTriangulatedShape_HeaderFile
+#include <Poly_Connect.hxx>
#include <Poly_Triangulation.hxx>
#include <Prs3d_Drawer.hxx>
#include <Standard.hxx>
//! 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.