1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-08 14:17:06 +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:
vro
2021-02-16 14:24:15 +03:00
committed by bugmaster
parent 008210c3e2
commit a8b605eb5e
73 changed files with 1235 additions and 1445 deletions

View File

@@ -253,9 +253,6 @@ void StdPrs_Isolines::addOnTriangulation (const Handle(Poly_Triangulation)& theT
Prs3d_NListOfSequenceOfPnt& theUPolylines,
Prs3d_NListOfSequenceOfPnt& theVPolylines)
{
const Poly_Array1OfTriangle& aTriangles = theTriangulation->Triangles();
const TColgp_Array1OfPnt& aNodes = theTriangulation->Nodes();
const TColgp_Array1OfPnt2d& aUVNodes = theTriangulation->UVNodes();
for (Standard_Integer anUVIter = 0; anUVIter < 2; ++anUVIter)
{
const Standard_Boolean isUIso = anUVIter == 0;
@@ -278,16 +275,16 @@ void StdPrs_Isolines::addOnTriangulation (const Handle(Poly_Triangulation)& theT
anIsoPnts = aPolylines.ChangeValue (anIsoIndexes.Value (anIsoIdx));
}
for (Standard_Integer aTriIter = aTriangles.Lower(); aTriIter <= aTriangles.Upper(); ++aTriIter)
for (Standard_Integer aTriIter = 1; aTriIter <= theTriangulation->NbTriangles(); ++aTriIter)
{
Standard_Integer aNodeIdxs[3];
aTriangles.Value (aTriIter).Get (aNodeIdxs[0], aNodeIdxs[1],aNodeIdxs[2]);
const gp_Pnt aNodesXYZ[3] = { aNodes.Value (aNodeIdxs[0]),
aNodes.Value (aNodeIdxs[1]),
aNodes.Value (aNodeIdxs[2]) };
const gp_Pnt2d aNodesUV[3] = { aUVNodes.Value (aNodeIdxs[0]),
aUVNodes.Value (aNodeIdxs[1]),
aUVNodes.Value (aNodeIdxs[2]) };
theTriangulation->Triangle (aTriIter).Get (aNodeIdxs[0], aNodeIdxs[1],aNodeIdxs[2]);
const gp_Pnt aNodesXYZ[3] = { theTriangulation->Node (aNodeIdxs[0]),
theTriangulation->Node (aNodeIdxs[1]),
theTriangulation->Node (aNodeIdxs[2]) };
const gp_Pnt2d aNodesUV[3] = { theTriangulation->UVNode (aNodeIdxs[0]),
theTriangulation->UVNode (aNodeIdxs[1]),
theTriangulation->UVNode (aNodeIdxs[2]) };
// Find intersections with triangle in uv space and its projection on triangulation.
SegOnIso aSegment;

View File

@@ -189,13 +189,7 @@ namespace
Standard_Boolean isMirrored = aTrsf.VectorialPart().Determinant() < 0;
// Extracts vertices & normals from nodes
const TColgp_Array1OfPnt& aNodes = aT->Nodes();
const TColgp_Array1OfPnt2d* aUVNodes = theHasTexels && aT->HasUVNodes() && aT->UVNodes().Upper() == aNodes.Upper()
? &aT->UVNodes()
: NULL;
StdPrs_ToolTriangulatedShape::ComputeNormals (aFace, aT);
const TShort_Array1OfShortReal& aNormals = aT->Normals();
const Standard_ShortReal* aNormArr = &aNormals.First();
if (theHasTexels)
{
@@ -205,11 +199,10 @@ namespace
}
const Standard_Integer aDecal = anArray->VertexNumber();
for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
for (Standard_Integer aNodeIter = 1; aNodeIter <= aT->NbNodes(); ++aNodeIter)
{
aPoint = aNodes (aNodeIter);
const Standard_Integer anId = 3 * (aNodeIter - aNodes.Lower());
gp_Dir aNorm (aNormArr[anId + 0], aNormArr[anId + 1], aNormArr[anId + 2]);
aPoint = aT->Node (aNodeIter);
gp_Dir aNorm = aT->Normal (aNodeIter);
if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored)
{
aNorm.Reverse();
@@ -217,15 +210,16 @@ namespace
if (!aLoc.IsIdentity())
{
aPoint.Transform (aTrsf);
aNorm.Transform (aTrsf);
aNorm .Transform (aTrsf);
}
if (aUVNodes != NULL)
if (theHasTexels && aT->HasUVNodes())
{
const gp_Pnt2d aNode2d = aT->UVNode (aNodeIter);
const gp_Pnt2d aTexel = (dUmax == 0.0 || dVmax == 0.0)
? aUVNodes->Value (aNodeIter)
: gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aUVNodes->Value (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(),
(-theUVOrigin.Y() + (theUVRepeat.Y() * (aUVNodes->Value (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y());
? aNode2d
: gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aNode2d.X() - aUmin)) / dUmax) / theUVScale.X(),
(-theUVOrigin.Y() + (theUVRepeat.Y() * (aNode2d.Y() - aVmin)) / dVmax) / theUVScale.Y());
anArray->AddVertex (aPoint, aNorm, aTexel);
}
else
@@ -235,22 +229,21 @@ namespace
}
// Fill array with vertex and edge visibility info
const Poly_Array1OfTriangle& aTriangles = aT->Triangles();
Standard_Integer anIndex[3];
for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter)
{
if ((aFace.Orientation() == TopAbs_REVERSED))
{
aTriangles (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]);
aT->Triangle (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]);
}
else
{
aTriangles (aTriIter).Get (anIndex[0], anIndex[1], anIndex[2]);
aT->Triangle (aTriIter).Get (anIndex[0], anIndex[1], anIndex[2]);
}
gp_Pnt aP1 = aNodes (anIndex[0]);
gp_Pnt aP2 = aNodes (anIndex[1]);
gp_Pnt aP3 = aNodes (anIndex[2]);
const gp_Pnt aP1 = aT->Node (anIndex[0]);
const gp_Pnt aP2 = aT->Node (anIndex[1]);
const gp_Pnt aP3 = aT->Node (anIndex[2]);
gp_Vec aV1 (aP1, aP2);
if (aV1.SquareMagnitude() <= aPreci)
@@ -415,7 +408,6 @@ namespace
}
// get edge nodes indexes from face triangulation
const TColgp_Array1OfPnt& aTriNodes = aTriangulation->Nodes();
const TColStd_Array1OfInteger& anEdgeNodes = anEdgePoly->Nodes();
// collect the edge nodes
@@ -425,7 +417,7 @@ namespace
// node index in face triangulation
// get node and apply location transformation to the node
const Standard_Integer aTriIndex = anEdgeNodes.Value (aNodeIdx);
gp_Pnt aTriNode = aTriNodes.Value (aTriIndex);
gp_Pnt aTriNode = aTriangulation->Node (aTriIndex);
if (!aTrsf.IsIdentity())
{
aTriNode.Transform (aTrsf);

View File

@@ -149,7 +149,6 @@ void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace,
// take in face the surface location
const TopoDS_Face aZeroFace = TopoDS::Face (theFace.Located (TopLoc_Location()));
Handle(Geom_Surface) aSurf = BRep_Tool::Surface (aZeroFace);
const Poly_Array1OfTriangle& aTriangles = theTris->Triangles();
if (!theTris->HasUVNodes() || aSurf.IsNull())
{
// compute normals by averaging triangulation normals sharing the same vertex
@@ -158,15 +157,13 @@ 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);
const TColgp_Array1OfPnt2d& aNodesUV = theTris->UVNodes();
Standard_Integer aTri[3];
const TColgp_Array1OfPnt& aNodes = theTris->Nodes();
gp_Dir aNorm;
for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
theTris->AddNormals();
for (Standard_Integer aNodeIter = 1; aNodeIter <= theTris->NbNodes(); ++aNodeIter)
{
// try to retrieve normal from real surface first, when UV coordinates are available
if (GeomLib::NormEstim (aSurf, aNodesUV.Value (aNodeIter), aTol, aNorm) > 1)
if (GeomLib::NormEstim (aSurf, theTris->UVNode (aNodeIter), aTol, aNorm) > 1)
{
if (thePolyConnect.Triangulation() != theTris)
{
@@ -177,9 +174,9 @@ void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace,
gp_XYZ eqPlan (0.0, 0.0, 0.0);
for (thePolyConnect.Initialize (aNodeIter); thePolyConnect.More(); thePolyConnect.Next())
{
aTriangles (thePolyConnect.Value()).Get (aTri[0], aTri[1], aTri[2]);
const gp_XYZ v1 (aNodes (aTri[1]).Coord() - aNodes (aTri[0]).Coord());
const gp_XYZ v2 (aNodes (aTri[2]).Coord() - aNodes (aTri[1]).Coord());
theTris->Triangle (thePolyConnect.Value()).Get (aTri[0], aTri[1], aTri[2]);
const gp_XYZ v1 (theTris->Node (aTri[1]).Coord() - theTris->Node (aTri[0]).Coord());
const gp_XYZ v2 (theTris->Node (aTri[2]).Coord() - theTris->Node (aTri[1]).Coord());
const gp_XYZ vv = v1 ^ v2;
const Standard_Real aMod = vv.Modulus();
if (aMod >= aTol)
@@ -191,12 +188,8 @@ void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace,
aNorm = (aModMax > aTol) ? gp_Dir (eqPlan) : gp::DZ();
}
const Standard_Integer anId = (aNodeIter - aNodes.Lower()) * 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, aNorm);
}
theTris->SetNormals (aNormals);
}
//=======================================================================
@@ -213,21 +206,16 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace,
ComputeNormals (theFace, aPolyTri, thePolyConnect);
}
const TColgp_Array1OfPnt& aNodes = aPolyTri->Nodes();
const TShort_Array1OfShortReal& aNormals = aPolyTri->Normals();
const Standard_ShortReal* aNormArr = &aNormals.First();
for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
gp_Vec3f aNormal;
for (Standard_Integer aNodeIter = 1; aNodeIter <= aPolyTri->NbNodes(); ++aNodeIter)
{
const Standard_Integer anId = 3 * (aNodeIter - aNodes.Lower());
const gp_Dir aNorm (aNormArr[anId + 0],
aNormArr[anId + 1],
aNormArr[anId + 2]);
theNormals (aNodeIter) = aNorm;
aPolyTri->Normal (aNodeIter, aNormal);
theNormals.ChangeValue (aNodeIter).SetCoord (aNormal.x(), aNormal.y(), aNormal.z());
}
if (theFace.Orientation() == TopAbs_REVERSED)
{
for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
for (Standard_Integer aNodeIter = 1; aNodeIter <= aPolyTri->NbNodes(); ++aNodeIter)
{
theNormals.ChangeValue (aNodeIter).Reverse();
}

View File

@@ -332,21 +332,20 @@ void StdPrs_WFShape::addEdges (const TopTools_ListOfShape& theEdges,
{
// Presentation based on triangulation of a face.
const TColStd_Array1OfInteger& anIndices = anEdgeIndicies->Nodes();
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
Standard_Integer anIndex = anIndices.Lower();
if (aLocation.IsIdentity())
{
for (; anIndex <= anIndices.Upper(); ++anIndex)
{
aPoints->Append (aNodes (anIndices (anIndex)));
aPoints->Append (aTriangulation->Node (anIndices[anIndex]));
}
}
else
{
for (; anIndex <= anIndices.Upper(); ++anIndex)
{
aPoints->Append (aNodes (anIndices (anIndex)).Transformed (aLocation));
aPoints->Append (aTriangulation->Node (anIndices[anIndex]).Transformed (aLocation));
}
}
}