1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-29 14:00: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:
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

@@ -208,17 +208,15 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape ()
Handle(Poly_Triangulation) aTriangulation =
new Poly_Triangulation(aNodes.Length(), aTriangles.Extent(), Standard_False);
// Copy the triangulation vertices
TColgp_Array1OfPnt& aTNodes = aTriangulation->ChangeNodes();
for (i = 0; i < aNodes.Length(); i++)
{
aTNodes.SetValue(i + 1, gp_Pnt(aNodes(i)));
aTriangulation->SetNode (i + 1, gp_Pnt (aNodes (i)));
}
// Copy the triangles.
Poly_Array1OfTriangle& aTTriangles = aTriangulation->ChangeTriangles();
NCollection_List<Poly_Triangle>::Iterator itT(aTriangles);
for (i = 1; itT.More(); itT.Next(), i++)
{
aTTriangles.SetValue(i, itT.Value());
aTriangulation->SetTriangle (i, itT.Value());
}
Handle(BRep_TFace) aFace = new BRep_TFace();
@@ -229,19 +227,18 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape ()
if (myNormals.IsNull()) {
Poly::ComputeNormals(aTriangulation);
}
else {
else
{
// Copy the normals. Currently only normals-per-vertex are supported.
Handle(TShort_HArray1OfShortReal) Normals =
new TShort_HArray1OfShortReal(1, 3 * nbNodes);
if (myNormalPerVertex) {
if (myArrNormalInd == 0L) {
if (myNormalPerVertex)
{
aTriangulation->AddNormals();
if (myArrNormalInd == 0L)
{
for (i = 0; i < nbNodes; i++)
{
Standard_Integer anIdx = i * 3 + 1;
const gp_XYZ& aNormal = myNormals->Normal(i);
Normals->SetValue(anIdx + 0, Standard_ShortReal(aNormal.X()));
Normals->SetValue(anIdx + 1, Standard_ShortReal(aNormal.Y()));
Normals->SetValue(anIdx + 2, Standard_ShortReal(aNormal.Z()));
const gp_XYZ& aNormal = myNormals->Normal (i);
aTriangulation->SetNormal (i + 1, aNormal);
}
}
else
@@ -254,12 +251,10 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape ()
Polygon(i, anArrNodes);
const Standard_Integer * arrIndice;
int nbn = IndiceNormals(i, arrIndice);
for (Standard_Integer j = 0; j < nbn; j++) {
for (Standard_Integer j = 0; j < nbn; j++)
{
const gp_XYZ& aNormal = myNormals->Normal(arrIndice[j]);
Standard_Integer anInd = mapIdId(anArrNodes[j]) * 3 + 1;
Normals->SetValue(anInd + 0, Standard_ShortReal(aNormal.X()));
Normals->SetValue(anInd + 1, Standard_ShortReal(aNormal.Y()));
Normals->SetValue(anInd + 2, Standard_ShortReal(aNormal.Z()));
aTriangulation->SetNormal (mapIdId (anArrNodes[j]) + 1, aNormal);
}
}
}
@@ -268,7 +263,6 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape ()
else {
//TODO ..
}
aTriangulation->SetNormals(Normals);
}
myIsModified = Standard_False;

View File

@@ -330,21 +330,19 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
Standard_Integer i;
const Standard_Integer nNodes (theTri->NbNodes());
const Standard_Integer nTriangles (theTri->NbTriangles());
const TColgp_Array1OfPnt& arrPolyNodes = theTri->Nodes();
const Poly_Array1OfTriangle& arrTriangles = theTri->Triangles();
// protection against creation degenerative triangles
Standard_Integer nbTri = 0;
Poly_Array1OfTriangle aTriangles(1, nTriangles);
for (i = 0; i < nTriangles; i++) {
Standard_Integer idx[3];
arrTriangles(i + 1).Get(idx[0], idx[1], idx[2]);
theTri->Triangle (i + 1).Get (idx[0], idx[1], idx[2]);
if (idx[0] == idx[1] || idx[0] == idx[2] || idx[1] == idx[2])
{
continue;
}
nbTri++;
aTriangles.SetValue(nbTri, arrTriangles(i + 1));
aTriangles.SetValue (nbTri, theTri->Triangle (i + 1));
}
aTriangles.Resize(1, nbTri, Standard_True);
@@ -387,7 +385,9 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
gp_XYZ * arrNodes = static_cast <gp_XYZ *>
(anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
for (i = 0; i < nNodes; i++)
arrNodes[i] = arrPolyNodes(i+1).XYZ() * myScale;
{
arrNodes[i] = theTri->Node (i+1).XYZ() * myScale;
}
const Handle(VrmlData_Coordinate) aCoordNode =
new VrmlData_Coordinate (myScene, 0L, nNodes, arrNodes);
@@ -396,14 +396,14 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
}
// Create the Normals node if theTri has normals
if(theTri->HasNormals()) {
gp_XYZ * arrVec = static_cast <gp_XYZ *>
(anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
const TShort_Array1OfShortReal& Norm = theTri->Normals();
Standard_Integer j;
for (i = 0, j = 1; i < nNodes; i++, j += 3)
if (theTri->HasNormals())
{
gp_XYZ* arrVec = static_cast<gp_XYZ*>(anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
gp_Vec3f aVec3;
for (i = 0; i < nNodes; i++)
{
gp_XYZ aNormal(Norm(j), Norm(j+1), Norm(j+2));
theTri->Normal (i + 1, aVec3);
gp_XYZ aNormal (aVec3.x(), aVec3.y(), aVec3.z());
if (isReverse)
{
aNormal.Reverse();
@@ -422,24 +422,18 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
TopLoc_Location aLoc;
const Standard_Real aConf2 = Precision::SquareConfusion();
const Handle(Geom_Surface) aSurface = BRep_Tool::Surface (theFace, aLoc);
if (theTri->HasUVNodes() && aSurface.IsNull() == Standard_False) {
if (theTri->HasUVNodes() && aSurface.IsNull() == Standard_False)
{
if (aSurface->IsCNu(1) && aSurface->IsCNv(1))
{
Standard_Integer nbNormVal = nNodes * 3;
Handle(TShort_HArray1OfShortReal) Normals =
new TShort_HArray1OfShortReal(1, nbNormVal);
const TColgp_Array1OfPnt2d& arrUV = theTri->UVNodes();
gp_XYZ * arrVec = static_cast <gp_XYZ *>
(anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
gp_XYZ* arrVec = static_cast<gp_XYZ*> (anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
// Compute the normal vectors
Standard_Real Tol = Sqrt(aConf2);
for (i = 0; i < nNodes; i++) {
const gp_Pnt2d& aUV = arrUV(i+1);
for (i = 0; i < nNodes; i++)
{
const gp_Pnt2d aUV = theTri->UVNode (i+1);
gp_Dir aNormal;
if (GeomLib::NormEstim(aSurface, aUV, Tol, aNormal) > 1) {
//Try to estimate as middle normal of adjacent triangles
Standard_Integer n[3];
@@ -447,8 +441,8 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
gp_XYZ eqPlan(0., 0., 0.);
for (PC.Initialize(i+1); PC.More(); PC.Next()) {
aTriangles(PC.Value()).Get(n[0], n[1], n[2]);
gp_XYZ v1(arrPolyNodes(n[1]).Coord()-arrPolyNodes(n[0]).Coord());
gp_XYZ v2(arrPolyNodes(n[2]).Coord()-arrPolyNodes(n[1]).Coord());
gp_XYZ v1 (theTri->Node (n[1]).Coord()-theTri->Node (n[0]).Coord());
gp_XYZ v2 (theTri->Node (n[2]).Coord()-theTri->Node (n[1]).Coord());
gp_XYZ vv = v1^v2;
Standard_Real mod = vv.Modulus();
@@ -470,17 +464,10 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
aNormal.SetY(0.);
if (aNormal.Z()*aNormal.Z() < aConf2)
aNormal.SetZ(0.);
arrVec[i] = aNormal.XYZ();
Standard_Integer j = i * 3;
Normals->SetValue(j + 1, (Standard_ShortReal)aNormal.X());
Normals->SetValue(j + 2, (Standard_ShortReal)aNormal.Y());
Normals->SetValue(j + 3, (Standard_ShortReal)aNormal.Z());
}
theTri->SetNormals(Normals);
const Handle(VrmlData_Normal) aNormalNode =
new VrmlData_Normal (myScene, 0L, nNodes, arrVec);
myScene.AddNode (aNormalNode, Standard_False);