mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-19 13:40:49 +03:00
0032133: Modeling Data - Restriction of access to internal arrays for Poly_Triangulation, revision of API
Removed methods from Poly_Triangulation/Poly_PolygonOnTriangulation giving access to internal arrays of 2d and 3d nodes, triangles and normals.
This commit is contained in:
@@ -43,42 +43,48 @@ Handle(Poly_Triangulation) Poly::Catenate (const Poly_ListOfTriangulation& lstTr
|
||||
|
||||
// Sum up the total number of nodes.
|
||||
Poly_ListOfTriangulation::Iterator anIter(lstTri);
|
||||
for (; anIter.More(); anIter.Next()) {
|
||||
for (; anIter.More(); anIter.Next())
|
||||
{
|
||||
const Handle(Poly_Triangulation)& aTri = anIter.Value();
|
||||
if (aTri.IsNull() == Standard_False) {
|
||||
if (!aTri.IsNull())
|
||||
{
|
||||
nNodes += aTri->NbNodes();
|
||||
nTrian += aTri->NbTriangles();
|
||||
}
|
||||
}
|
||||
|
||||
Handle(Poly_Triangulation) aResult;
|
||||
if (nNodes > 0) {
|
||||
aResult = new Poly_Triangulation(nNodes, nTrian, Standard_False);
|
||||
Standard_Integer i, iNode[3];
|
||||
nNodes = 0;
|
||||
nTrian = 0;
|
||||
TColgp_Array1OfPnt& arrNode = aResult->ChangeNodes();
|
||||
Poly_Array1OfTriangle& arrTrian = aResult->ChangeTriangles();
|
||||
for (anIter.Init(lstTri); anIter.More(); anIter.Next()) {
|
||||
const Handle(Poly_Triangulation)& aTri = anIter.Value();
|
||||
if (aTri.IsNull() == Standard_False) {
|
||||
const TColgp_Array1OfPnt& srcNode = aTri->Nodes();
|
||||
const Poly_Array1OfTriangle& srcTrian = aTri->Triangles();
|
||||
const Standard_Integer nbNodes = aTri->NbNodes();
|
||||
const Standard_Integer nbTrian = aTri->NbTriangles();
|
||||
for (i = 1; i <= nbNodes; i++) {
|
||||
arrNode.SetValue(i + nNodes, srcNode(i));
|
||||
}
|
||||
for (i = 1; i <= nbTrian; i++) {
|
||||
srcTrian(i).Get(iNode[0], iNode[1], iNode[2]);
|
||||
arrTrian.SetValue(i + nTrian, Poly_Triangle(iNode[0] + nNodes,
|
||||
iNode[1] + nNodes,
|
||||
iNode[2] + nNodes));
|
||||
}
|
||||
nNodes += nbNodes;
|
||||
nTrian += nbTrian;
|
||||
}
|
||||
if (nNodes == 0)
|
||||
{
|
||||
return Handle(Poly_Triangulation)();
|
||||
}
|
||||
|
||||
Handle(Poly_Triangulation) aResult = new Poly_Triangulation(nNodes, nTrian, Standard_False);
|
||||
Standard_Integer iNode[3] = {};
|
||||
nNodes = 0;
|
||||
nTrian = 0;
|
||||
for (anIter.Init(lstTri); anIter.More(); anIter.Next())
|
||||
{
|
||||
const Handle(Poly_Triangulation)& aTri = anIter.Value();
|
||||
if (aTri.IsNull())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const Standard_Integer nbNodes = aTri->NbNodes();
|
||||
const Standard_Integer nbTrian = aTri->NbTriangles();
|
||||
for (Standard_Integer i = 1; i <= nbNodes; i++)
|
||||
{
|
||||
aResult->SetNode (i + nNodes, aTri->Node (i));
|
||||
}
|
||||
for (Standard_Integer i = 1; i <= nbTrian; i++)
|
||||
{
|
||||
aTri->Triangle (i).Get (iNode[0], iNode[1], iNode[2]);
|
||||
aResult->SetTriangle (i + nTrian, Poly_Triangle (iNode[0] + nNodes,
|
||||
iNode[1] + nNodes,
|
||||
iNode[2] + nNodes));
|
||||
}
|
||||
nNodes += nbNodes;
|
||||
nTrian += nbTrian;
|
||||
}
|
||||
return aResult;
|
||||
}
|
||||
@@ -113,36 +119,39 @@ void Poly::Write(const Handle(Poly_Triangulation)& T,
|
||||
if (!Compact) OS << "\n3D Nodes :\n";
|
||||
|
||||
Standard_Integer i, nbNodes = T->NbNodes();
|
||||
const TColgp_Array1OfPnt& Nodes = T->Nodes();
|
||||
for (i = 1; i <= nbNodes; i++) {
|
||||
for (i = 1; i <= nbNodes; i++)
|
||||
{
|
||||
const gp_Pnt aNode = T->Node (i);
|
||||
if (!Compact) OS << std::setw(10) << i << " : ";
|
||||
if (!Compact) OS << std::setw(17);
|
||||
OS << Nodes(i).X() << " ";
|
||||
OS << aNode.X() << " ";
|
||||
if (!Compact) OS << std::setw(17);
|
||||
OS << Nodes(i).Y() << " ";
|
||||
OS << aNode.Y() << " ";
|
||||
if (!Compact) OS << std::setw(17);
|
||||
OS << Nodes(i).Z() << "\n";
|
||||
OS << aNode.Z() << "\n";
|
||||
}
|
||||
|
||||
if (T->HasUVNodes()) {
|
||||
if (T->HasUVNodes())
|
||||
{
|
||||
if (!Compact) OS << "\nUV Nodes :\n";
|
||||
const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
|
||||
for (i = 1; i <= nbNodes; i++) {
|
||||
for (i = 1; i <= nbNodes; i++)
|
||||
{
|
||||
const gp_Pnt2d aNode2d = T->UVNode (i);
|
||||
if (!Compact) OS << std::setw(10) << i << " : ";
|
||||
if (!Compact) OS << std::setw(17);
|
||||
OS << UVNodes(i).X() << " ";
|
||||
if (!Compact) OS << std::setw(17);
|
||||
OS << UVNodes(i).Y() << "\n";
|
||||
if (!Compact) OS << std::setw(17);
|
||||
OS << aNode2d.X() << " ";
|
||||
if (!Compact) OS << std::setw(17);
|
||||
OS << aNode2d.Y() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (!Compact) OS << "\nTriangles :\n";
|
||||
Standard_Integer nbTriangles = T->NbTriangles();
|
||||
Standard_Integer n1, n2, n3;
|
||||
const Poly_Array1OfTriangle& Triangles = T->Triangles();
|
||||
for (i = 1; i <= nbTriangles; i++) {
|
||||
for (i = 1; i <= nbTriangles; i++)
|
||||
{
|
||||
if (!Compact) OS << std::setw(10) << i << " : ";
|
||||
Triangles(i).Get(n1, n2, n3);
|
||||
T->Triangle (i).Get (n1, n2, n3);
|
||||
if (!Compact) OS << std::setw(10);
|
||||
OS << n1 << " ";
|
||||
if (!Compact) OS << std::setw(10);
|
||||
@@ -447,70 +456,7 @@ Handle(Poly_Polygon2D) Poly::ReadPolygon2D(Standard_IStream& IS)
|
||||
//=======================================================================
|
||||
void Poly::ComputeNormals (const Handle(Poly_Triangulation)& theTri)
|
||||
{
|
||||
const TColgp_Array1OfPnt& aNodes = theTri->Nodes();
|
||||
const Standard_Integer aNbNodes = aNodes.Size();
|
||||
|
||||
const Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, aNbNodes * 3);
|
||||
aNormals->Init (0.0f);
|
||||
Standard_ShortReal* aNormArr = &aNormals->ChangeFirst();
|
||||
|
||||
Standard_Integer anElem[3] = {0, 0, 0};
|
||||
const Standard_Real anEps2 = gp::Resolution();
|
||||
for (Poly_Array1OfTriangle::Iterator aTriIter (theTri->Triangles()); aTriIter.More(); aTriIter.Next())
|
||||
{
|
||||
aTriIter.Value().Get (anElem[0], anElem[1], anElem[2]);
|
||||
const gp_Pnt& aNode0 = aNodes.Value (anElem[0]);
|
||||
const gp_Pnt& aNode1 = aNodes.Value (anElem[1]);
|
||||
const gp_Pnt& aNode2 = aNodes.Value (anElem[2]);
|
||||
|
||||
const gp_XYZ aVec01 = aNode1.XYZ() - aNode0.XYZ();
|
||||
const gp_XYZ aVec02 = aNode2.XYZ() - aNode0.XYZ();
|
||||
gp_XYZ aTriNorm = aVec01 ^ aVec02;
|
||||
/*if (theToIgnoreTriangleSize)
|
||||
{
|
||||
const Standard_Real aMod = aTriNorm.SquareModulus();
|
||||
if (aMod > anEps2)
|
||||
{
|
||||
aTriNorm /= Sqrt (aMod);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
|
||||
for (Standard_Integer aNodeIter = 0; aNodeIter < 3; ++aNodeIter)
|
||||
{
|
||||
const Standard_Size anIndex = (anElem[aNodeIter] - 1) * 3;
|
||||
aNormArr[anIndex + 0] += Standard_ShortReal(aTriNorm.X());
|
||||
aNormArr[anIndex + 1] += Standard_ShortReal(aTriNorm.Y());
|
||||
aNormArr[anIndex + 2] += Standard_ShortReal(aTriNorm.Z());
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize all vectors
|
||||
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;
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
theTri->SetNormals (aNormals);
|
||||
theTri->ComputeNormals();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
|
@@ -51,45 +51,41 @@ Poly_CoherentTriangulation::Poly_CoherentTriangulation
|
||||
: theAlloc)
|
||||
{
|
||||
if (theTriangulation.IsNull() == Standard_False) {
|
||||
const TColgp_Array1OfPnt& arrNodes = theTriangulation->Nodes();
|
||||
const Poly_Array1OfTriangle& arrTriangle = theTriangulation->Triangles();
|
||||
const Standard_Integer nNodes = theTriangulation->NbNodes();
|
||||
const Standard_Integer nTri = theTriangulation->NbTriangles();
|
||||
Standard_Integer i;
|
||||
|
||||
// Copy the nodes
|
||||
for (i = 0; i < nNodes; i++) {
|
||||
const Standard_Integer anOldInd = i + arrNodes.Lower();
|
||||
const Standard_Integer aNewInd = SetNode(arrNodes(anOldInd).XYZ(), i);
|
||||
const Standard_Integer anOldInd = i + 1;
|
||||
const Standard_Integer aNewInd = SetNode (theTriangulation->Node (anOldInd).XYZ(), i);
|
||||
Poly_CoherentNode& aCopiedNode = myNodes(aNewInd);
|
||||
aCopiedNode.SetIndex(anOldInd);
|
||||
}
|
||||
|
||||
// Copy the triangles
|
||||
for (i = 0; i < nTri; i++) {
|
||||
for (i = 1; i <= theTriangulation->NbTriangles(); i++) {
|
||||
Standard_Integer iNode[3];
|
||||
arrTriangle(i + arrTriangle.Lower()).Get(iNode[0], iNode[1], iNode[2]);
|
||||
theTriangulation->Triangle (i).Get (iNode[0], iNode[1], iNode[2]);
|
||||
if (iNode[0] != iNode[1] && iNode[1] != iNode[2] && iNode[2] != iNode[0])
|
||||
AddTriangle (iNode[0]-1, iNode[1]-1, iNode[2]-1);
|
||||
}
|
||||
|
||||
// Copy UV coordinates of nodes
|
||||
if (theTriangulation->HasUVNodes()) {
|
||||
const TColgp_Array1OfPnt2d& arrNodes2d = theTriangulation->UVNodes();
|
||||
for (i = 0; i < nNodes; i++) {
|
||||
const gp_Pnt2d& anUV = arrNodes2d(i + arrNodes2d.Lower());
|
||||
const gp_Pnt2d anUV = theTriangulation->UVNode (i + 1);
|
||||
myNodes(i).SetUV(anUV.X(), anUV.Y());
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the normals at nodes
|
||||
if (theTriangulation->HasNormals()) {
|
||||
const TShort_Array1OfShortReal& arrNorm = theTriangulation->Normals();
|
||||
for (i = 0; i < nNodes; i++) {
|
||||
const gp_XYZ aNormal (arrNorm(3 * i + 0 + arrNorm.Lower()),
|
||||
arrNorm(3 * i + 1 + arrNorm.Lower()),
|
||||
arrNorm(3 * i + 2 + arrNorm.Lower()));
|
||||
myNodes(i).SetNormal(aNormal);
|
||||
if (theTriangulation->HasNormals())
|
||||
{
|
||||
gp_Vec3f aNormal;
|
||||
for (i = 0; i < nNodes; i++)
|
||||
{
|
||||
theTriangulation->Normal (i + 1, aNormal);
|
||||
myNodes (i).SetNormal (gp_XYZ (aNormal.x(), aNormal.y(), aNormal.z()));
|
||||
}
|
||||
}
|
||||
myDeflection = theTriangulation->Deflection();
|
||||
@@ -116,66 +112,59 @@ Poly_CoherentTriangulation::~Poly_CoherentTriangulation ()
|
||||
|
||||
Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const
|
||||
{
|
||||
Handle(Poly_Triangulation) aResult;
|
||||
const Standard_Integer nNodes = NNodes();
|
||||
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);
|
||||
|
||||
TColgp_Array1OfPnt& arrNodes = aResult->ChangeNodes();
|
||||
TColgp_Array1OfPnt2d& arrNodesUV = aResult->ChangeUVNodes();
|
||||
Poly_Array1OfTriangle& arrTriangle = aResult->ChangeTriangles();
|
||||
NCollection_Vector<Standard_Integer> 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++) {
|
||||
const Poly_CoherentNode& aNode = myNodes(i);
|
||||
if (aNode.IsFreeNode())
|
||||
vecNodeId.SetValue(i, 0);
|
||||
else {
|
||||
const gp_XYZ aNormal = aNode.GetNormal();
|
||||
arrNormal[3 * aCount + 0] = static_cast<Standard_ShortReal>(aNormal.X());
|
||||
arrNormal[3 * aCount + 1] = static_cast<Standard_ShortReal>(aNormal.Y());
|
||||
arrNormal[3 * aCount + 2] = static_cast<Standard_ShortReal>(aNormal.Z());
|
||||
|
||||
vecNodeId.SetValue(i, ++aCount);
|
||||
arrNodes.SetValue(aCount, aNode);
|
||||
|
||||
arrNodesUV.SetValue(aCount, gp_Pnt2d(aNode.GetU(), aNode.GetV()));
|
||||
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)
|
||||
aResult->RemoveUVNodes();
|
||||
|
||||
// Copy the triangles
|
||||
aCount = 0;
|
||||
NCollection_Vector<Poly_CoherentTriangle>::Iterator anIterT (myTriangles);
|
||||
for (; anIterT.More(); anIterT.Next()) {
|
||||
const Poly_CoherentTriangle& aTri = anIterT.Value();
|
||||
if (aTri.IsEmpty() == Standard_False) {
|
||||
const Poly_Triangle aPolyTriangle (vecNodeId(aTri.Node(0)),
|
||||
vecNodeId(aTri.Node(1)),
|
||||
vecNodeId(aTri.Node(2)));
|
||||
arrTriangle.SetValue(++aCount, aPolyTriangle);
|
||||
}
|
||||
}
|
||||
if (hasNormals)
|
||||
aResult->SetNormals (harrNormal);
|
||||
|
||||
aResult->Deflection(myDeflection);
|
||||
if (nNodes == 0 || nTriangles == 0)
|
||||
{
|
||||
return Handle(Poly_Triangulation)();
|
||||
}
|
||||
|
||||
Handle(Poly_Triangulation) aResult = new Poly_Triangulation(nNodes, nTriangles, false);
|
||||
|
||||
NCollection_Vector<Standard_Integer> vecNodeId;
|
||||
Standard_Integer aCount = 0;
|
||||
|
||||
// Copy the nodes (3D and 2D coordinates)
|
||||
for (Standard_Integer i = 0; i < myNodes.Length(); i++)
|
||||
{
|
||||
const Poly_CoherentNode& aNode = myNodes(i);
|
||||
if (aNode.IsFreeNode())
|
||||
{
|
||||
vecNodeId.SetValue (i, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
vecNodeId.SetValue (i, ++aCount);
|
||||
const gp_XYZ aNormal = aNode.GetNormal();
|
||||
if (aNormal.SquareModulus() > Precision::Confusion())
|
||||
{
|
||||
aResult->AddNormals();
|
||||
aResult->SetNormal (aCount, gp_Dir (aNormal));
|
||||
}
|
||||
|
||||
aResult->SetNode (aCount, aNode);
|
||||
if (aNode.GetU() * aNode.GetU() + aNode.GetV() * aNode.GetV() > Precision::Confusion())
|
||||
{
|
||||
aResult->AddUVNodes();
|
||||
aResult->SetUVNode (aCount, gp_Pnt2d (aNode.GetU(), aNode.GetV()));
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the triangles
|
||||
aCount = 0;
|
||||
for (NCollection_Vector<Poly_CoherentTriangle>::Iterator anIterT (myTriangles);
|
||||
anIterT.More(); anIterT.Next())
|
||||
{
|
||||
const Poly_CoherentTriangle& aTri = anIterT.Value();
|
||||
if (!aTri.IsEmpty())
|
||||
{
|
||||
aResult->SetTriangle (++aCount, Poly_Triangle (vecNodeId (aTri.Node (0)),
|
||||
vecNodeId (aTri.Node (1)),
|
||||
vecNodeId (aTri.Node (2))));
|
||||
}
|
||||
}
|
||||
|
||||
aResult->Deflection (myDeflection);
|
||||
return aResult;
|
||||
}
|
||||
|
||||
|
@@ -226,8 +226,7 @@ void Poly_Connect::Initialize(const Standard_Integer N)
|
||||
if (mymore)
|
||||
{
|
||||
Standard_Integer i, no[3];
|
||||
const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
|
||||
triangles(myfirst).Get(no[0], no[1], no[2]);
|
||||
myTriangulation->Triangle (myfirst).Get (no[0], no[1], no[2]);
|
||||
for (i = 0; i < 3; i++)
|
||||
if (no[i] == mynode) break;
|
||||
myothernode = no[(i+2)%3];
|
||||
@@ -244,12 +243,11 @@ void Poly_Connect::Next()
|
||||
Standard_Integer i, j;
|
||||
Standard_Integer n[3];
|
||||
Standard_Integer t[3];
|
||||
const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
|
||||
Triangles(mytr, t[0], t[1], t[2]);
|
||||
if (mysense) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (t[i] != 0) {
|
||||
triangles(t[i]).Get(n[0], n[1], n[2]);
|
||||
myTriangulation->Triangle (t[i]).Get (n[0], n[1], n[2]);
|
||||
for (j = 0; j < 3; j++) {
|
||||
if ((n[j] == mynode) && (n[(j+1)%3] == myothernode)) {
|
||||
mytr = t[i];
|
||||
@@ -261,7 +259,7 @@ void Poly_Connect::Next()
|
||||
}
|
||||
}
|
||||
// sinon, depart vers la gauche.
|
||||
triangles(myfirst).Get(n[0], n[1], n[2]);
|
||||
myTriangulation->Triangle (myfirst).Get (n[0], n[1], n[2]);
|
||||
for (i = 0; i < 3; i++)
|
||||
if (n[i] == mynode) break;
|
||||
myothernode = n[(i+1)%3];
|
||||
@@ -272,7 +270,7 @@ void Poly_Connect::Next()
|
||||
if (!mysense) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (t[i] != 0) {
|
||||
triangles(t[i]).Get(n[0], n[1], n[2]);
|
||||
myTriangulation->Triangle (t[i]).Get (n[0], n[1], n[2]);
|
||||
for (j = 0; j < 3; j++) {
|
||||
if ((n[j] == mynode) && (n[(j+2)%3] == myothernode)) {
|
||||
mytr = t[i];
|
||||
|
@@ -17,7 +17,7 @@
|
||||
#ifndef _Poly_PolygonOnTriangulation_HeaderFile
|
||||
#define _Poly_PolygonOnTriangulation_HeaderFile
|
||||
|
||||
|
||||
#include <Standard_NullObject.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <TColStd_Array1OfInteger.hxx>
|
||||
@@ -40,6 +40,7 @@ DEFINE_STANDARD_HANDLE(Poly_PolygonOnTriangulation, Standard_Transient)
|
||||
//! curve.represents a 3d Polygon
|
||||
class Poly_PolygonOnTriangulation : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Poly_PolygonOnTriangulation, Standard_Transient)
|
||||
public:
|
||||
|
||||
//! Constructs a 3D polygon on the triangulation of a shape with specified size of nodes.
|
||||
@@ -79,26 +80,33 @@ public:
|
||||
//! triangle, the function NbNodes returns 4.
|
||||
Standard_Integer NbNodes() const { return myNodes.Length(); }
|
||||
|
||||
//! Returns the table of nodes for this polygon. A node value
|
||||
//! is an index in the table of nodes specific to an existing
|
||||
//! triangulation of a shape.
|
||||
const TColStd_Array1OfInteger& Nodes() const { return myNodes; }
|
||||
//! Returns node at the given index.
|
||||
Standard_Integer Node (Standard_Integer theIndex) const { return myNodes.Value (theIndex); }
|
||||
|
||||
//! Returns the table of nodes for this polygon for modification.
|
||||
TColStd_Array1OfInteger& ChangeNodes() { return myNodes; }
|
||||
//! Sets node at the given index.
|
||||
void SetNode (Standard_Integer theIndex,
|
||||
Standard_Integer theNode)
|
||||
{
|
||||
myNodes.SetValue (theIndex, theNode);
|
||||
}
|
||||
|
||||
//! Returns true if parameters are associated with the nodes in this polygon.
|
||||
Standard_Boolean HasParameters() const { return !myParameters.IsNull(); }
|
||||
|
||||
//! Returns the table of the parameters associated with each node in this polygon.
|
||||
//! Warning
|
||||
//! Use the function HasParameters to check if parameters
|
||||
//! are associated with the nodes in this polygon.
|
||||
const Handle(TColStd_HArray1OfReal)& Parameters() const { return myParameters; }
|
||||
//! Returns parameter at the given index.
|
||||
Standard_Real Parameter (Standard_Integer theIndex) const
|
||||
{
|
||||
Standard_NullObject_Raise_if (myParameters.IsNull(), "Poly_PolygonOnTriangulation::Parameter : parameters is NULL");
|
||||
return myParameters->Value (theIndex);
|
||||
}
|
||||
|
||||
//! Returns the table of the parameters associated with each node in this polygon.
|
||||
//! Warning! HasParameters() should be called beforehand to check if parameters array is allocated.
|
||||
TColStd_Array1OfReal& ChangeParameters() { return myParameters->ChangeArray1(); }
|
||||
//! Sets parameter at the given index.
|
||||
void SetParameter (Standard_Integer theIndex,
|
||||
Standard_Real theValue)
|
||||
{
|
||||
Standard_NullObject_Raise_if (myParameters.IsNull(), "Poly_PolygonOnTriangulation::Parameter : parameters is NULL");
|
||||
myParameters->SetValue (theIndex, theValue);
|
||||
}
|
||||
|
||||
//! Sets the table of the parameters associated with each node in this polygon.
|
||||
//! Raises exception if array size doesn't much number of polygon nodes.
|
||||
@@ -107,7 +115,21 @@ public:
|
||||
//! Dumps the content of me into the stream
|
||||
Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Poly_PolygonOnTriangulation,Standard_Transient)
|
||||
public:
|
||||
|
||||
//! Returns the table of nodes for this polygon.
|
||||
//! A node value is an index in the table of nodes specific to an existing triangulation of a shape.
|
||||
const TColStd_Array1OfInteger& Nodes() const { return myNodes; }
|
||||
|
||||
//! Returns the table of the parameters associated with each node in this polygon.
|
||||
//! Warning! Use the function HasParameters to check if parameters are associated with the nodes in this polygon.
|
||||
const Handle(TColStd_HArray1OfReal)& Parameters() const { return myParameters; }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, SetNode() should be used instead")
|
||||
TColStd_Array1OfInteger& ChangeNodes() { return myNodes; }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, SetParameter() should be used instead")
|
||||
TColStd_Array1OfReal& ChangeParameters() { return myParameters->ChangeArray1(); }
|
||||
|
||||
private:
|
||||
|
||||
|
@@ -89,7 +89,7 @@ public:
|
||||
|
||||
Standard_Integer& operator() (const Standard_Integer Index) { return ChangeValue(Index); }
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
Standard_Integer myNodes[3];
|
||||
|
||||
|
@@ -18,9 +18,7 @@
|
||||
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <Poly_Triangle.hxx>
|
||||
#include <Standard_DomainError.hxx>
|
||||
#include <Standard_Dump.hxx>
|
||||
#include <Standard_NullObject.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT (Poly_Triangulation, Standard_Transient)
|
||||
@@ -35,40 +33,26 @@ Poly_Triangulation::Poly_Triangulation()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Poly_Triangulation
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Poly_Triangulation::Poly_Triangulation(const Standard_Integer theNbNodes,
|
||||
const Standard_Integer theNbTriangles,
|
||||
const Standard_Boolean theHasUVNodes)
|
||||
: myCachedMinMax (NULL),
|
||||
myDeflection (0),
|
||||
myNodes (1, theNbNodes),
|
||||
myTriangles (1, theNbTriangles)
|
||||
{
|
||||
if (theHasUVNodes) myUVNodes = new TColgp_HArray1OfPnt2d(1, 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)
|
||||
: myDeflection(0),
|
||||
Poly_Triangulation::Poly_Triangulation (const Standard_Integer theNbNodes,
|
||||
const Standard_Integer theNbTriangles,
|
||||
const Standard_Boolean theHasUVNodes,
|
||||
const Standard_Boolean theHasNormals)
|
||||
: myCachedMinMax (NULL),
|
||||
myDeflection(0),
|
||||
myNodes (1, theNbNodes),
|
||||
myTriangles (1, theNbTriangles)
|
||||
{
|
||||
if (theHasUVNodes)
|
||||
{
|
||||
myUVNodes = new TColgp_HArray1OfPnt2d(1, theNbNodes);
|
||||
myUVNodes.Resize (1, theNbNodes, false);
|
||||
}
|
||||
if (theHasNormals)
|
||||
{
|
||||
myNormals = new TShort_HArray1OfShortReal(1, theNbNodes * 3);
|
||||
myNormals.Resize (1, theNbNodes, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +60,8 @@ 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),
|
||||
myNodes (1, theNodes.Length()),
|
||||
@@ -92,18 +76,18 @@ 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),
|
||||
myNodes (1, theNodes.Length()),
|
||||
myTriangles (1, theTriangles.Length())
|
||||
myTriangles (1, theTriangles.Length()),
|
||||
myUVNodes (1, theNodes.Length())
|
||||
{
|
||||
myNodes = theNodes;
|
||||
myTriangles = theTriangles;
|
||||
myUVNodes = new TColgp_HArray1OfPnt2d (1, theNodes.Length());
|
||||
myUVNodes->ChangeArray1() = theUVNodes;
|
||||
myUVNodes = theUVNodes;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
@@ -131,226 +115,190 @@ Handle(Poly_Triangulation) Poly_Triangulation::Copy() const
|
||||
//=======================================================================
|
||||
|
||||
Poly_Triangulation::Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation)
|
||||
: myCachedMinMax(NULL),
|
||||
: myCachedMinMax (NULL),
|
||||
myDeflection(theTriangulation->myDeflection),
|
||||
myNodes(theTriangulation->Nodes()),
|
||||
myTriangles(theTriangulation->Triangles())
|
||||
myNodes (theTriangulation->myNodes),
|
||||
myTriangles (theTriangulation->myTriangles),
|
||||
myUVNodes (theTriangulation->myUVNodes),
|
||||
myNormals (theTriangulation->myNormals)
|
||||
{
|
||||
SetCachedMinMax (theTriangulation->CachedMinMax());
|
||||
if (theTriangulation->HasUVNodes())
|
||||
{
|
||||
myUVNodes = new TColgp_HArray1OfPnt2d(theTriangulation->myUVNodes->Array1());
|
||||
}
|
||||
if (theTriangulation->HasNormals())
|
||||
{
|
||||
myNormals = new TShort_HArray1OfShortReal(theTriangulation->myNormals->Array1());
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Deflection
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Triangulation::Deflection(const Standard_Real theDeflection)
|
||||
{
|
||||
myDeflection = theDeflection;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemoveUVNodes
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Triangulation::RemoveUVNodes()
|
||||
{
|
||||
myUVNodes.Nullify();
|
||||
if (!myUVNodes.IsEmpty())
|
||||
{
|
||||
TColgp_Array1OfPnt2d anEmpty;
|
||||
myUVNodes.Move (anEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Node
|
||||
//purpose :
|
||||
//function : RemoveNormals
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const gp_Pnt& Poly_Triangulation::Node (const Standard_Integer theIndex) const
|
||||
void Poly_Triangulation::RemoveNormals()
|
||||
{
|
||||
if (theIndex < 1 || theIndex > myNodes.Size())
|
||||
if (!myNormals.IsEmpty())
|
||||
{
|
||||
throw Standard_OutOfRange ("Poly_Triangulation::Node : index out of range");
|
||||
NCollection_Array1<gp_Vec3f> anEmpty;
|
||||
myNormals.Move (anEmpty);
|
||||
}
|
||||
return myNodes.Value (theIndex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ChangeNode
|
||||
//purpose :
|
||||
//function : MapNodeArray
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
gp_Pnt& Poly_Triangulation::ChangeNode (const Standard_Integer theIndex)
|
||||
Handle(TColgp_HArray1OfPnt) Poly_Triangulation::MapNodeArray() const
|
||||
{
|
||||
if (theIndex < 1 || theIndex > myNodes.Size())
|
||||
if (myNodes.IsEmpty())
|
||||
{
|
||||
throw Standard_OutOfRange ("Poly_Triangulation::ChangeNode : index out of range");
|
||||
return Handle(TColgp_HArray1OfPnt)();
|
||||
}
|
||||
return myNodes.ChangeValue (theIndex);
|
||||
|
||||
Handle(TColgp_HArray1OfPnt) anHArray = new TColgp_HArray1OfPnt();
|
||||
TColgp_Array1OfPnt anArray (myNodes.First(), 1, NbNodes());
|
||||
anHArray->Move (anArray);
|
||||
return anHArray;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UVNode
|
||||
//purpose :
|
||||
//function : MapTriangleArray
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const gp_Pnt2d& Poly_Triangulation::UVNode (const Standard_Integer theIndex) const
|
||||
Handle(Poly_HArray1OfTriangle) Poly_Triangulation::MapTriangleArray() const
|
||||
{
|
||||
if (myUVNodes.IsNull() || theIndex < 1 || theIndex > myUVNodes->Size())
|
||||
if (myTriangles.IsEmpty())
|
||||
{
|
||||
throw Standard_OutOfRange ("Poly_Triangulation::UVNode : index out of range");
|
||||
return Handle(Poly_HArray1OfTriangle)();
|
||||
}
|
||||
return myUVNodes->Value (theIndex);
|
||||
|
||||
Handle(Poly_HArray1OfTriangle) anHArray = new Poly_HArray1OfTriangle();
|
||||
Poly_Array1OfTriangle anArray (myTriangles.First(), 1, NbTriangles());
|
||||
anHArray->Move (anArray);
|
||||
return anHArray;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ChangeUVNode
|
||||
//purpose :
|
||||
//function : MapUVNodeArray
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
gp_Pnt2d& Poly_Triangulation::ChangeUVNode (const Standard_Integer theIndex)
|
||||
Handle(TColgp_HArray1OfPnt2d) Poly_Triangulation::MapUVNodeArray() const
|
||||
{
|
||||
if (myUVNodes.IsNull() || theIndex < 1 || theIndex > myUVNodes->Size())
|
||||
if (myUVNodes.IsEmpty())
|
||||
{
|
||||
throw Standard_OutOfRange ("Poly_Triangulation::ChangeUVNode : index out of range");
|
||||
return Handle(TColgp_HArray1OfPnt2d)();
|
||||
}
|
||||
return myUVNodes->ChangeValue (theIndex);
|
||||
|
||||
Handle(TColgp_HArray1OfPnt2d) anHArray = new TColgp_HArray1OfPnt2d();
|
||||
TColgp_Array1OfPnt2d anArray (myUVNodes.First(), 1, NbNodes());
|
||||
anHArray->Move (anArray);
|
||||
return anHArray;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Triangle
|
||||
//purpose :
|
||||
//function : MapNormalArray
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Poly_Triangle& Poly_Triangulation::Triangle (const Standard_Integer theIndex) const
|
||||
Handle(TShort_HArray1OfShortReal) Poly_Triangulation::MapNormalArray() const
|
||||
{
|
||||
if (theIndex < 1 || theIndex > myTriangles.Size())
|
||||
if (myNormals.IsEmpty())
|
||||
{
|
||||
throw Standard_OutOfRange ("Poly_Triangulation::Triangle : index out of range");
|
||||
return Handle(TShort_HArray1OfShortReal)();
|
||||
}
|
||||
return myTriangles.Value (theIndex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//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);
|
||||
Handle(TShort_HArray1OfShortReal) anHArray = new TShort_HArray1OfShortReal();
|
||||
TShort_Array1OfShortReal anArray (*myNormals.First().GetData(), 1, 3 * NbNodes());
|
||||
anHArray->Move (anArray);
|
||||
return anHArray;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetNormals
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals)
|
||||
{
|
||||
|
||||
if(theNormals.IsNull() || theNormals->Length() != 3 * NbNodes()) {
|
||||
if (theNormals.IsNull() || theNormals->Length() != 3 * NbNodes())
|
||||
{
|
||||
throw Standard_DomainError("Poly_Triangulation::SetNormals : wrong length");
|
||||
}
|
||||
|
||||
myNormals = theNormals;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Normals
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const TShort_Array1OfShortReal& Poly_Triangulation::Normals() const
|
||||
{
|
||||
|
||||
if(myNormals.IsNull() || myNormals->Length() != 3 * NbNodes()) {
|
||||
throw Standard_NullObject("Poly_Triangulation::Normals : "
|
||||
"wrong length or null array");
|
||||
}
|
||||
|
||||
return myNormals->Array1();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ChangeNormals
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals()
|
||||
{
|
||||
|
||||
if(myNormals.IsNull() || myNormals->Length() != 3 * NbNodes()) {
|
||||
throw Standard_NullObject("Poly_Triangulation::ChangeNormals : "
|
||||
"wrong length or null array");
|
||||
}
|
||||
|
||||
return myNormals->ChangeArray1();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : HasNormals
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Poly_Triangulation::HasNormals() const
|
||||
{
|
||||
if(myNormals.IsNull() || myNormals->Length() != 3 * NbNodes()) {
|
||||
return Standard_False;
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetNormal
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Triangulation::SetNormal (const Standard_Integer theIndex, const gp_Dir& theNormal)
|
||||
{
|
||||
if (myNormals.IsNull() || theIndex < 1 || theIndex > myNodes.Size())
|
||||
AddNormals();
|
||||
const Standard_Integer anArrayLower = theNormals->Lower();
|
||||
for (Standard_Integer aNodeIter = 1; aNodeIter <= NbNodes(); ++aNodeIter)
|
||||
{
|
||||
throw Standard_NullObject ("Poly_Triangulation::SetNormal : empty array or index out of range");
|
||||
Standard_Integer anArrayInd = anArrayLower + (aNodeIter - 1) * 3;
|
||||
gp_Vec3f aNorm (theNormals->Value (anArrayInd + 0),
|
||||
theNormals->Value (anArrayInd + 1),
|
||||
theNormals->Value (anArrayInd + 2));
|
||||
SetNormal (aNodeIter, aNorm);
|
||||
}
|
||||
|
||||
myNormals->ChangeValue (theIndex * 3 - 2) = (Standard_ShortReal) theNormal.X();
|
||||
myNormals->ChangeValue (theIndex * 3 - 1) = (Standard_ShortReal) theNormal.Y();
|
||||
myNormals->ChangeValue (theIndex * 3) = (Standard_ShortReal) theNormal.Z();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Normal
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
gp_Dir Poly_Triangulation::Normal (const Standard_Integer theIndex) const
|
||||
// =======================================================================
|
||||
// function : ResizeNodes
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Poly_Triangulation::ResizeNodes (Standard_Integer theNbNodes,
|
||||
Standard_Boolean theToCopyOld)
|
||||
{
|
||||
if (myNormals.IsNull() || theIndex < 1 || theIndex > myNodes.Size())
|
||||
myNodes.Resize (1, theNbNodes, theToCopyOld);
|
||||
if (!myUVNodes.IsEmpty())
|
||||
{
|
||||
throw Standard_NullObject ("Poly_Triangulation::Normal : empty array or index out of range");
|
||||
myUVNodes.Resize (1, theNbNodes, theToCopyOld);
|
||||
}
|
||||
if (!myNormals.IsEmpty())
|
||||
{
|
||||
myNormals.Resize (1, theNbNodes, theToCopyOld);
|
||||
}
|
||||
}
|
||||
|
||||
gp_Dir N(myNormals->Value(theIndex * 3 - 2),
|
||||
myNormals->Value(theIndex * 3 - 1),
|
||||
myNormals->Value(theIndex * 3));
|
||||
// =======================================================================
|
||||
// function : ResizeTriangles
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Poly_Triangulation::ResizeTriangles (Standard_Integer theNbTriangles,
|
||||
Standard_Boolean theToCopyOld)
|
||||
{
|
||||
myTriangles.Resize (1, theNbTriangles, theToCopyOld);
|
||||
}
|
||||
|
||||
return N;
|
||||
// =======================================================================
|
||||
// function : AddUVNodes
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Poly_Triangulation::AddUVNodes()
|
||||
{
|
||||
if (myUVNodes.IsEmpty() || myUVNodes.Size() != myNodes.Size())
|
||||
{
|
||||
myUVNodes.Resize (1, myNodes.Size(), false);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : AddNormals
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Poly_Triangulation::AddNormals()
|
||||
{
|
||||
if (myNormals.IsEmpty() || myNormals.Size() != myNodes.Size())
|
||||
{
|
||||
myNormals.Resize (1, myNodes.Size(), false);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : DumpJson
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
|
||||
void Poly_Triangulation::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
|
||||
{
|
||||
OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
|
||||
@@ -358,10 +306,10 @@ void Poly_Triangulation::DumpJson (Standard_OStream& theOStream, Standard_Intege
|
||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDeflection)
|
||||
|
||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myNodes.Size())
|
||||
if (!myUVNodes.IsNull())
|
||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUVNodes->Size())
|
||||
if (!myNormals.IsNull())
|
||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myNormals->Size())
|
||||
if (!myUVNodes.IsEmpty())
|
||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUVNodes.Size())
|
||||
if (!myNormals.IsEmpty())
|
||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myNormals.Size())
|
||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myTriangles.Size())
|
||||
}
|
||||
|
||||
@@ -455,3 +403,40 @@ Bnd_Box Poly_Triangulation::computeBoundingBox (const gp_Trsf& theTrsf) const
|
||||
}
|
||||
return aBox;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ComputeNormals
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Poly_Triangulation::ComputeNormals()
|
||||
{
|
||||
// zero values
|
||||
AddNormals();
|
||||
myNormals.Init (gp_Vec3f (0.0f));
|
||||
|
||||
Standard_Integer anElem[3] = {0, 0, 0};
|
||||
for (Poly_Array1OfTriangle::Iterator aTriIter (myTriangles); aTriIter.More(); aTriIter.Next())
|
||||
{
|
||||
aTriIter.Value().Get (anElem[0], anElem[1], anElem[2]);
|
||||
const gp_Pnt aNode0 = myNodes.Value (anElem[0]);
|
||||
const gp_Pnt aNode1 = myNodes.Value (anElem[1]);
|
||||
const gp_Pnt aNode2 = myNodes.Value (anElem[2]);
|
||||
|
||||
const gp_XYZ aVec01 = aNode1.XYZ() - aNode0.XYZ();
|
||||
const gp_XYZ aVec02 = aNode2.XYZ() - aNode0.XYZ();
|
||||
const gp_XYZ aTriNorm = aVec01 ^ aVec02;
|
||||
const gp_Vec3f aNorm3f = gp_Vec3f (float(aTriNorm.X()), float(aTriNorm.Y()), float(aTriNorm.Z()));
|
||||
for (Standard_Integer aNodeIter = 0; aNodeIter < 3; ++aNodeIter)
|
||||
{
|
||||
myNormals.ChangeValue (anElem[aNodeIter]) += aNorm3f;
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize all vectors
|
||||
for (NCollection_Array1<gp_Vec3f>::Iterator aNodeIter (myNormals); aNodeIter.More(); aNodeIter.Next())
|
||||
{
|
||||
gp_Vec3f& aNorm3f = aNodeIter.ChangeValue();
|
||||
const float aMod = aNorm3f.Modulus();
|
||||
aNorm3f = aMod == 0.0f ? gp_Vec3f (0.0f, 0.0f, 1.0f) : (aNorm3f / aMod);
|
||||
}
|
||||
}
|
||||
|
@@ -18,21 +18,11 @@
|
||||
#define _Poly_Triangulation_HeaderFile
|
||||
|
||||
#include <Bnd_Box.hxx>
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_DefineHandle.hxx>
|
||||
#include <Standard_Real.hxx>
|
||||
#include <Standard_Integer.hxx>
|
||||
#include <TColgp_Array1OfPnt.hxx>
|
||||
#include <gp_Vec3f.hxx>
|
||||
#include <Poly_HArray1OfTriangle.hxx>
|
||||
#include <TColgp_HArray1OfPnt.hxx>
|
||||
#include <TColgp_HArray1OfPnt2d.hxx>
|
||||
#include <Poly_Array1OfTriangle.hxx>
|
||||
#include <TShort_HArray1OfShortReal.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <TColgp_Array1OfPnt2d.hxx>
|
||||
#include <TShort_Array1OfShortReal.hxx>
|
||||
class Standard_DomainError;
|
||||
class Standard_NullObject;
|
||||
|
||||
|
||||
class Poly_Triangulation;
|
||||
DEFINE_STANDARD_HANDLE(Poly_Triangulation, Standard_Transient)
|
||||
@@ -64,32 +54,24 @@ DEFINE_STANDARD_HANDLE(Poly_Triangulation, Standard_Transient)
|
||||
//! This is a Transient class.
|
||||
class Poly_Triangulation : public Standard_Transient
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Poly_Triangulation, Standard_Transient)
|
||||
public:
|
||||
|
||||
//! Constructs an empty triangulation.
|
||||
Standard_EXPORT Poly_Triangulation();
|
||||
|
||||
//! Constructs a triangulation from a set of triangles. The
|
||||
//! triangulation is initialized without a triangle or a node, but capable of
|
||||
//! containing nbNodes nodes, and nbTriangles
|
||||
//! 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);
|
||||
|
||||
//! Constructs a triangulation from a set of triangles.
|
||||
//! The triangulation is initialized without a triangle or a node,
|
||||
//! but capable of containing nbNodes nodes, and nbTriangles triangles.
|
||||
//! Here the UVNodes flag indicates whether 2D nodes will be associated with 3D ones,
|
||||
//! (i.e. to enable a 2D representation).
|
||||
//! 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 hasNormals);
|
||||
//! but capable of containing specified number of nodes and triangles.
|
||||
//! @param theNbNodes [in] number of nodes to allocate
|
||||
//! @param theNbTriangles [in] number of triangles to allocate
|
||||
//! @param theHasUVNodes [in] indicates whether 2D nodes will be associated with 3D ones,
|
||||
//! (i.e. to enable a 2D representation)
|
||||
//! @param theHasNormals [in] indicates whether normals will be given and associated with nodes
|
||||
Standard_EXPORT Poly_Triangulation (const Standard_Integer theNbNodes,
|
||||
const Standard_Integer theNbTriangles,
|
||||
const Standard_Boolean theHasUVNodes,
|
||||
const Standard_Boolean theHasNormals = false);
|
||||
|
||||
//! Constructs a triangulation from a set of triangles. The
|
||||
//! triangulation is initialized with 3D points from Nodes and triangles
|
||||
@@ -119,10 +101,7 @@ public:
|
||||
|
||||
//! Sets the deflection of this triangulation to theDeflection.
|
||||
//! See more on deflection in Polygon2D
|
||||
Standard_EXPORT void Deflection (const Standard_Real theDeflection);
|
||||
|
||||
//! Deallocates the UV nodes.
|
||||
Standard_EXPORT void RemoveUVNodes();
|
||||
void Deflection (const Standard_Real theDeflection) { myDeflection = theDeflection; }
|
||||
|
||||
//! Returns TRUE if triangulation has some geometry.
|
||||
virtual Standard_Boolean HasGeometry() const { return !myNodes.IsEmpty() && !myTriangles.IsEmpty(); }
|
||||
@@ -134,88 +113,70 @@ public:
|
||||
Standard_Integer NbTriangles() const { return myTriangles.Length(); }
|
||||
|
||||
//! Returns Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
|
||||
Standard_Boolean HasUVNodes() const { return !myUVNodes.IsNull(); }
|
||||
|
||||
//! Returns the table of 3D nodes (3D points) for this triangulation.
|
||||
const TColgp_Array1OfPnt& Nodes() const { return myNodes; }
|
||||
|
||||
//! Returns the table of 3D nodes (3D points) for this triangulation.
|
||||
//! The returned array is
|
||||
//! shared. Therefore if the table is selected by reference, you
|
||||
//! can, by simply modifying it, directly modify the data
|
||||
//! structure of this triangulation.
|
||||
TColgp_Array1OfPnt& ChangeNodes() { return myNodes; }
|
||||
|
||||
//! Returns 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;
|
||||
|
||||
//! 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);
|
||||
|
||||
//! Returns the table of 2D nodes (2D points) associated with
|
||||
//! each 3D node of this triangulation.
|
||||
//! The function HasUVNodes checks if 2D nodes
|
||||
//! are associated with the 3D nodes of this triangulation.
|
||||
//! Const reference on the 2d nodes values.
|
||||
const TColgp_Array1OfPnt2d& UVNodes() const { return myUVNodes->Array1(); }
|
||||
|
||||
//! Returns the table of 2D nodes (2D points) associated with
|
||||
//! each 3D node of this triangulation.
|
||||
//! Function ChangeUVNodes shares the returned array.
|
||||
//! Therefore if the table is selected by reference,
|
||||
//! you can, by simply modifying it, directly modify the data
|
||||
//! structure of this triangulation.
|
||||
TColgp_Array1OfPnt2d& ChangeUVNodes() { return myUVNodes->ChangeArray1(); }
|
||||
|
||||
//! Returns 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;
|
||||
|
||||
//! 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);
|
||||
|
||||
//! Returns the table of triangles for this triangulation.
|
||||
const Poly_Array1OfTriangle& Triangles() const { return myTriangles; }
|
||||
|
||||
//! Returns the table of triangles for this triangulation.
|
||||
//! Function ChangeUVNodes shares the returned array.
|
||||
//! Therefore if the table is selected by reference,
|
||||
//! you can, by simply modifying it, directly modify the data
|
||||
//! structure of this triangulation.
|
||||
Poly_Array1OfTriangle& ChangeTriangles() { return myTriangles; }
|
||||
|
||||
//! Returns 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;
|
||||
|
||||
//! 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);
|
||||
|
||||
//! Sets the table of node normals.
|
||||
//! raises exception if length of theNormals != 3*NbNodes
|
||||
Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals);
|
||||
|
||||
//! Returns the table of node normals.
|
||||
Standard_EXPORT const TShort_Array1OfShortReal& Normals() const;
|
||||
|
||||
//! Gives access to the table of node normals.
|
||||
Standard_EXPORT TShort_Array1OfShortReal& ChangeNormals();
|
||||
Standard_Boolean HasUVNodes() const { return !myUVNodes.IsEmpty(); }
|
||||
|
||||
//! Returns Standard_True if nodal normals are defined.
|
||||
Standard_EXPORT Standard_Boolean HasNormals() const;
|
||||
Standard_Boolean HasNormals() const { return !myNormals.IsEmpty(); }
|
||||
|
||||
//! @return normal at the given index.
|
||||
//! Raises Standard_OutOfRange exception.
|
||||
Standard_EXPORT gp_Dir Normal (const Standard_Integer theIndex) const;
|
||||
//! Returns a node at the given index.
|
||||
const gp_Pnt& Node (Standard_Integer theIndex) const { return myNodes.Value (theIndex); }
|
||||
|
||||
//! Sets a node coordinates.
|
||||
void SetNode (Standard_Integer theIndex,
|
||||
const gp_Pnt& thePnt)
|
||||
{
|
||||
myNodes.SetValue (theIndex, thePnt);
|
||||
}
|
||||
|
||||
//! Returns UV-node at the given index.
|
||||
const gp_Pnt2d& UVNode (Standard_Integer theIndex) const { return myUVNodes.Value (theIndex); }
|
||||
|
||||
//! Sets an UV-node coordinates.
|
||||
void SetUVNode (Standard_Integer theIndex,
|
||||
const gp_Pnt2d& thePnt)
|
||||
{
|
||||
myUVNodes.SetValue (theIndex, thePnt);
|
||||
}
|
||||
|
||||
//! Returns triangle at the given index.
|
||||
const Poly_Triangle& Triangle (Standard_Integer theIndex) const { return myTriangles.Value (theIndex); }
|
||||
|
||||
//! Sets a triangle.
|
||||
void SetTriangle (Standard_Integer theIndex,
|
||||
const Poly_Triangle& theTriangle)
|
||||
{
|
||||
myTriangles.SetValue (theIndex, theTriangle);
|
||||
}
|
||||
|
||||
//! Returns normal at the given index.
|
||||
gp_Dir Normal (Standard_Integer theIndex) const
|
||||
{
|
||||
const gp_Vec3f& aNorm = myNormals.Value (theIndex);
|
||||
return gp_Dir (aNorm.x(), aNorm.y(), aNorm.z());
|
||||
}
|
||||
|
||||
//! Returns normal at the given index.
|
||||
void Normal (Standard_Integer theIndex,
|
||||
gp_Vec3f& theVec3) const
|
||||
{
|
||||
theVec3 = myNormals.Value (theIndex);
|
||||
}
|
||||
|
||||
//! Changes normal at the given index.
|
||||
//! Raises Standard_OutOfRange exception.
|
||||
Standard_EXPORT void SetNormal (const Standard_Integer theIndex,
|
||||
const gp_Dir& theNormal);
|
||||
void SetNormal (const Standard_Integer theIndex,
|
||||
const gp_Vec3f& theNormal)
|
||||
{
|
||||
myNormals.SetValue (theIndex, theNormal);
|
||||
}
|
||||
|
||||
//! Changes normal at the given index.
|
||||
void SetNormal (const Standard_Integer theIndex,
|
||||
const gp_Dir& theNormal)
|
||||
{
|
||||
SetNormal (theIndex, gp_Vec3f (float(theNormal.X()),
|
||||
float(theNormal.Y()),
|
||||
float(theNormal.Z())));
|
||||
}
|
||||
|
||||
//! Returns cached min - max range of triangulation data,
|
||||
//! which is VOID by default (e.g, no cached information).
|
||||
@@ -253,6 +214,105 @@ public:
|
||||
//! Dumps the content of me into the stream
|
||||
Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
|
||||
|
||||
public:
|
||||
|
||||
//! Method resizing internal arrays of nodes (synchronously for all attributes).
|
||||
//! @param theNbNodes [in] new number of nodes
|
||||
//! @param theToCopyOld [in] copy old nodes into the new array
|
||||
Standard_EXPORT void ResizeNodes (Standard_Integer theNbNodes,
|
||||
Standard_Boolean theToCopyOld);
|
||||
|
||||
//! Method resizing an internal array of triangles.
|
||||
//! @param theNbTriangles [in] new number of triangles
|
||||
//! @param theToCopyOld [in] copy old triangles into the new array
|
||||
Standard_EXPORT void ResizeTriangles (Standard_Integer theNbTriangles,
|
||||
Standard_Boolean theToCopyOld);
|
||||
|
||||
//! If an array for UV coordinates is not allocated yet, do it now.
|
||||
Standard_EXPORT void AddUVNodes();
|
||||
|
||||
//! Deallocates the UV nodes array.
|
||||
Standard_EXPORT void RemoveUVNodes();
|
||||
|
||||
//! If an array for normals is not allocated yet, do it now.
|
||||
Standard_EXPORT void AddNormals();
|
||||
|
||||
//! Deallocates the Normals array.
|
||||
Standard_EXPORT void RemoveNormals();
|
||||
|
||||
//! Compute smooth normals by averaging triangle normals.
|
||||
Standard_EXPORT void ComputeNormals();
|
||||
|
||||
public:
|
||||
|
||||
//! Returns the table of 3D points for read-only access or NULL if nodes array is undefined.
|
||||
//! Poly_Triangulation::Node() should be used instead when possible.
|
||||
//! Returned object should not be used after Poly_Triangulation destruction.
|
||||
Standard_EXPORT Handle(TColgp_HArray1OfPnt) MapNodeArray() const;
|
||||
|
||||
//! Returns the triangle array for read-only access or NULL if triangle array is undefined.
|
||||
//! Poly_Triangulation::Triangle() should be used instead when possible.
|
||||
//! Returned object should not be used after Poly_Triangulation destruction.
|
||||
Standard_EXPORT Handle(Poly_HArray1OfTriangle) MapTriangleArray() const;
|
||||
|
||||
//! Returns the table of 2D nodes for read-only access or NULL if UV nodes array is undefined.
|
||||
//! Poly_Triangulation::UVNode() should be used instead when possible.
|
||||
//! Returned object should not be used after Poly_Triangulation destruction.
|
||||
Standard_EXPORT Handle(TColgp_HArray1OfPnt2d) MapUVNodeArray() const;
|
||||
|
||||
//! Returns the table of per-vertex normals for read-only access or NULL if normals array is undefined.
|
||||
//! Poly_Triangulation::Normal() should be used instead when possible.
|
||||
//! Returned object should not be used after Poly_Triangulation destruction.
|
||||
Standard_EXPORT Handle(TShort_HArray1OfShortReal) MapNormalArray() const;
|
||||
|
||||
public:
|
||||
|
||||
//! Returns an internal array of triangles.
|
||||
//! Triangle()/SetTriangle() should be used instead in portable code.
|
||||
Poly_Array1OfTriangle& InternalTriangles() { return myTriangles; }
|
||||
|
||||
//! Returns an internal array of nodes.
|
||||
//! Node()/SetNode() should be used instead in portable code.
|
||||
TColgp_Array1OfPnt& InternalNodes() { return myNodes; }
|
||||
|
||||
//! Returns an internal array of UV nodes.
|
||||
//! UBNode()/SetUVNode() should be used instead in portable code.
|
||||
TColgp_Array1OfPnt2d& InternalUVNodes() { return myUVNodes; }
|
||||
|
||||
//! Return an internal array of normals.
|
||||
//! Normal()/SetNormal() should be used instead in portable code.
|
||||
NCollection_Array1<gp_Vec3f>& InternalNormals() { return myNormals; }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, SetNormal() should be used instead")
|
||||
Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals);
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, Node() should be used instead")
|
||||
const TColgp_Array1OfPnt& Nodes() const { return myNodes; }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, SetNode() should be used instead")
|
||||
TColgp_Array1OfPnt& ChangeNodes() { return myNodes; }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, SetNode() should be used instead")
|
||||
gp_Pnt& ChangeNode (const Standard_Integer theIndex) { return myNodes.ChangeValue (theIndex); }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, UVNode() should be used instead")
|
||||
const TColgp_Array1OfPnt2d& UVNodes() const { return myUVNodes; }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, SetUVNode() should be used instead")
|
||||
TColgp_Array1OfPnt2d& ChangeUVNodes() { return myUVNodes; }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, SetUVNode() should be used instead")
|
||||
gp_Pnt2d& ChangeUVNode (const Standard_Integer theIndex) { return myUVNodes.ChangeValue (theIndex); }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, Triangle() should be used instead")
|
||||
const Poly_Array1OfTriangle& Triangles() const { return myTriangles; }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, SetTriangle() should be used instead")
|
||||
Poly_Array1OfTriangle& ChangeTriangles() { return myTriangles; }
|
||||
|
||||
Standard_DEPRECATED("Deprecated method, SetTriangle() should be used instead")
|
||||
Poly_Triangle& ChangeTriangle (const Standard_Integer theIndex) { return myTriangles.ChangeValue (theIndex); }
|
||||
|
||||
protected:
|
||||
|
||||
//! Clears cached min - max range saved previously.
|
||||
@@ -264,12 +324,12 @@ protected:
|
||||
|
||||
protected:
|
||||
|
||||
Bnd_Box* myCachedMinMax;
|
||||
Standard_Real myDeflection;
|
||||
TColgp_Array1OfPnt myNodes;
|
||||
Handle(TColgp_HArray1OfPnt2d) myUVNodes;
|
||||
Poly_Array1OfTriangle myTriangles;
|
||||
Handle(TShort_HArray1OfShortReal) myNormals;
|
||||
Bnd_Box* myCachedMinMax;
|
||||
Standard_Real myDeflection;
|
||||
TColgp_Array1OfPnt myNodes;
|
||||
Poly_Array1OfTriangle myTriangles;
|
||||
TColgp_Array1OfPnt2d myUVNodes;
|
||||
NCollection_Array1<gp_Vec3f> myNormals;
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user