1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-29 14:00:49 +03:00

0025936: Modeling Data - reusable data structure for 2D tesselation (3- and 4-nodal mesh)

Extension of triangular mesh of Open CASCADE to support quadrangular elements.
A Poly_Mesh class inherits Poly_Triangulation and manipulates quadrangles.
A TDataXtd_SurfacicMesh OCAF attribute is added to support a new surface mesh in OCAF operations.

// Porting of old development (for OCCT 7.1.0) to the current version of Open CASCADE.
// All remarks are checked, regressions are fixed.
// A new test-case is added : caf basic Z1
This commit is contained in:
vro
2021-02-14 08:55:02 +03:00
parent 92f8ec2f01
commit d289c94297
88 changed files with 1935 additions and 1270 deletions

View File

@@ -2210,3 +2210,12 @@ BRep and Binary BRep Shape formats (only in case of triangulation-only Faces, wi
Versions of formats have been changed (11 for BinOCAF, 10 for XmlOCAF, 4 for BRep Shape and 3 for Binary BRep Shape). Versions of formats have been changed (11 for BinOCAF, 10 for XmlOCAF, 4 for BRep Shape and 3 for Binary BRep Shape).
Files written with the new version will not be readable by applications of old versions. Files written with the new version will not be readable by applications of old versions.
@subsection upgrade_occt760_poly Changes in *Poly* package and *Poly_Triangulation* class:
* Poly_Triangulation: Replaced all arrays with NCollection_Vector.
* Poly_Triangulation: Old fashion of data access via getting collection reference is not more allowed for safety reasons.
Instead of old API, data access is organized via getters of single element by index.
* New class Poly_Element that allows to store triangles or quads (quad consists of two triangles).
* New class Poly_Mesh is extension of Poly_Triangulation that allows to store mesh with quad polygons as table of Poly_Element.
* New OCAF attribute TDataXtd_SurfacicMesh that allows to store Poly_Mesh in OCAF documents.

View File

@@ -70,14 +70,9 @@ void TriangulationSamples::Triangulation3dSample()
TopLoc_Location aLocation; TopLoc_Location aLocation;
Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(aFace, aLocation); Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(aFace, aLocation);
TColgp_Array1OfPnt aTriangNodes(1, (aTriangulation->NbNodes()));
aTriangNodes = aTriangulation->Nodes();
Poly_Array1OfTriangle aTriangles(1, aTriangulation->NbTriangles());
aTriangles = aTriangulation->Triangles();
for (Standard_Integer i = 1; i <= (aTriangulation->NbTriangles()); i++) for (Standard_Integer i = 1; i <= (aTriangulation->NbTriangles()); i++)
{ {
Poly_Triangle trian = aTriangles.Value(i); const Poly_Triangle& trian = aTriangulation->Triangle (i);
Standard_Integer index1, index2, index3, M = 0, N = 0; Standard_Integer index1, index2, index3, M = 0, N = 0;
trian.Get(index1, index2, index3); trian.Get(index1, index2, index3);
@@ -96,7 +91,7 @@ void TriangulationSamples::Triangulation3dSample()
M = index2; M = index2;
} }
BRepBuilderAPI_MakeEdge anEdgeMaker(aTriangNodes.Value(M), aTriangNodes.Value(N)); BRepBuilderAPI_MakeEdge anEdgeMaker(aTriangulation->Node (M), aTriangulation->Node (N));
if (anEdgeMaker.IsDone()) if (anEdgeMaker.IsDone())
{ {
aBuilder.Add(aCompound, anEdgeMaker.Edge()); aBuilder.Add(aCompound, anEdgeMaker.Edge());

View File

@@ -1217,14 +1217,12 @@ void CGeometryDoc::simplify(const TopoDS_Shape& aShape)
"\n" "\n"
" if(!aTr.IsNull())\n" " if(!aTr.IsNull())\n"
" { \n" " { \n"
" // takes the array of nodes for this triangulation\n" " nbNodes = aTr->NbNodes();\n"
" const TColgp_Array1OfPnt& aNodes = aTr->Nodes(); \n"
" nbNodes = aNodes.Length();\n"
"\n" "\n"
" for( Standard_Integer i = 1; i <= nbNodes; i++)\n" " for( Standard_Integer i = 1; i <= nbNodes; i++)\n"
" {\n" " {\n"
" // create seguence of node points in absolute coordinate system\n" " // create seguence of node points in absolute coordinate system\n"
" gp_Pnt aPnt = aNodes(i).Transformed(aLocation);\n" " gp_Pnt aPnt = aTr->Node (i).Transformed (aLocation);\n"
" aPoints.Append(aPnt);\n" " aPoints.Append(aPnt);\n"
" \n" " \n"
" }\n" " }\n"
@@ -1371,13 +1369,12 @@ void CGeometryDoc::simplify(const TopoDS_Shape& aShape)
if(!aTr.IsNull()) if(!aTr.IsNull())
{ {
// takes the array of nodes for this triangulation // takes the array of nodes for this triangulation
const TColgp_Array1OfPnt& aNodes = aTr->Nodes(); nbNodes = aTr->NbNodes();
nbNodes = aNodes.Length();
for( Standard_Integer i = 1; i <= nbNodes; i++) for( Standard_Integer i = 1; i <= nbNodes; i++)
{ {
// create seguence of node points in absolute coordinate system // create seguence of node points in absolute coordinate system
gp_Pnt aPnt = aNodes(i).Transformed(aLocation); gp_Pnt aPnt = aTr->Node (i).Transformed (aLocation);
aPoints.Append(aPnt); aPoints.Append(aPnt);
} }

View File

@@ -126,15 +126,10 @@ void Tesselate_Presentation::tesselateShape(const TopoDS_Shape& aShape)
" if(!aTr.IsNull()) // if this triangulation is not NULL" EOL " if(!aTr.IsNull()) // if this triangulation is not NULL" EOL
" { " EOL " { " EOL
" // takes the array of nodes for this triangulation:" EOL
" const TColgp_Array1OfPnt& aNodes = aTr->Nodes();" EOL
" // takes the array of triangles for this triangulation:" EOL
" const Poly_Array1OfTriangle& triangles = aTr->Triangles();" EOL EOL
" // create array of node points in absolute coordinate system" EOL " // create array of node points in absolute coordinate system" EOL
" TColgp_Array1OfPnt aPoints(1, aNodes.Length());" EOL " TColgp_Array1OfPnt aPoints(1, aTr->NbNodes());" EOL
" for( Standard_Integer i = 1; i < aNodes.Length()+1; i++)" EOL " for( Standard_Integer i = 1; i < aTr->NbNodes()+1; i++)" EOL
" aPoints(i) = aNodes(i).Transformed(aLocation);" EOL EOL " aPoints(i) = aTr->Node (i).Transformed (aLocation);" EOL EOL
" // Takes the node points of each triangle of this triangulation." EOL " // Takes the node points of each triangle of this triangulation." EOL
" // takes a number of triangles:" EOL " // takes a number of triangles:" EOL
@@ -143,7 +138,7 @@ void Tesselate_Presentation::tesselateShape(const TopoDS_Shape& aShape)
" for( nt = 1 ; nt < nnn+1 ; nt++)" EOL " for( nt = 1 ; nt < nnn+1 ; nt++)" EOL
" {" EOL " {" EOL
" // takes the node indices of each triangle in n1,n2,n3:" EOL " // takes the node indices of each triangle in n1,n2,n3:" EOL
" triangles(nt).Get(n1,n2,n3);" EOL " aTr->Triangle (nt).Get (n1,n2,n3);" EOL
" // takes the node points:" EOL " // takes the node points:" EOL
" gp_Pnt aPnt1 = aPoints(n1);" EOL " gp_Pnt aPnt1 = aPoints(n1);" EOL
" gp_Pnt aPnt2 = aPoints(n2);" EOL " gp_Pnt aPnt2 = aPoints(n2);" EOL
@@ -211,11 +206,9 @@ void Tesselate_Presentation::tesselateShape(const TopoDS_Shape& aShape)
if(!aTr.IsNull()) if(!aTr.IsNull())
{ {
const TColgp_Array1OfPnt& aNodes = aTr->Nodes();
aNumOfNodes += aTr->NbNodes(); aNumOfNodes += aTr->NbNodes();
//Standard_Integer aLower = aNodes.Lower(); //Standard_Integer aLower = aNodes.Lower();
//Standard_Integer anUpper = aNodes.Upper(); //Standard_Integer anUpper = aNodes.Upper();
const Poly_Array1OfTriangle& triangles = aTr->Triangles();
aNumOfTriangles += aTr->NbTriangles(); aNumOfTriangles += aTr->NbTriangles();
if(aCount == aNumOfFace) if(aCount == aNumOfFace)
@@ -251,8 +244,8 @@ void Tesselate_Presentation::tesselateShape(const TopoDS_Shape& aShape)
Standard_Integer aLower = aNodesOfPol.Lower(), anUpper = aNodesOfPol.Upper(); Standard_Integer aLower = aNodesOfPol.Lower(), anUpper = aNodesOfPol.Upper();
for( int i = aLower; i < anUpper ; i++) for( int i = aLower; i < anUpper ; i++)
{ {
gp_Pnt aPnt1 = aNodes(aNodesOfPol(i)).Transformed(aLocation); gp_Pnt aPnt1 = aTr->Node (aNodesOfPol (i)).Transformed (aLocation);
gp_Pnt aPnt2 = aNodes(aNodesOfPol(i+1)).Transformed(aLocation); gp_Pnt aPnt2 = aTr->Node (aNodesOfPol (i+1)).Transformed (aLocation);
TopoDS_Vertex aVertex1 = BRepBuilderAPI_MakeVertex (aPnt1); TopoDS_Vertex aVertex1 = BRepBuilderAPI_MakeVertex (aPnt1);
TopoDS_Vertex aVertex2 = BRepBuilderAPI_MakeVertex (aPnt2); TopoDS_Vertex aVertex2 = BRepBuilderAPI_MakeVertex (aPnt2);
@@ -283,9 +276,9 @@ void Tesselate_Presentation::tesselateShape(const TopoDS_Shape& aShape)
TopTools_DataMapOfIntegerShape aEdges; TopTools_DataMapOfIntegerShape aEdges;
TopTools_SequenceOfShape aVertices; TopTools_SequenceOfShape aVertices;
for( Standard_Integer i = 1; i < aNodes.Length()+1; i++) for( Standard_Integer i = 1; i < aTr->NbNodes()+1; i++)
{ {
gp_Pnt aPnt = aNodes(i).Transformed(aLocation); gp_Pnt aPnt = aTr->Node (i).Transformed (aLocation);
TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(aPnt); TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(aPnt);
if(!aVertex.IsNull()) if(!aVertex.IsNull())
@@ -302,7 +295,7 @@ void Tesselate_Presentation::tesselateShape(const TopoDS_Shape& aShape)
for( nt = 1 ; nt < nnn+1 ; nt++) for( nt = 1 ; nt < nnn+1 ; nt++)
{ {
triangles(nt).Get(n1,n2,n3); aTr->Triangle (nt).Get (n1,n2,n3);
Standard_Integer key[3]; Standard_Integer key[3];

View File

@@ -157,13 +157,9 @@ for (TopExp_Explorer ex(ShapeFused,TopAbs_FACE) ; ex.More(); ex.Next()) {
TopoDS_Face F =TopoDS::Face(ex.Current()); TopoDS_Face F =TopoDS::Face(ex.Current());
TopLoc_Location L; TopLoc_Location L;
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L); Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
TColgp_Array1OfPnt tab(1,(facing->NbNodes()));
tab = facing->Nodes();
Poly_Array1OfTriangle tri(1,facing->NbTriangles());
tri = facing->Triangles();
for (Standard_Integer i=1;i<=(facing->NbTriangles());i++) { for (Standard_Integer i=1;i<=(facing->NbTriangles());i++) {
Poly_Triangle trian = tri.Value(i); const Poly_Triangle& trian = facing->Triangle (i);
Standard_Integer index1,index2,index3,M = 0, N = 0; Standard_Integer index1,index2,index3,M = 0, N = 0;
trian.Get(index1,index2,index3); trian.Get(index1,index2,index3);
@@ -180,7 +176,7 @@ for (TopExp_Explorer ex(ShapeFused,TopAbs_FACE) ; ex.More(); ex.Next()) {
M = index2; M = index2;
} }
BRepBuilderAPI_MakeEdge ME(tab.Value(M),tab.Value(N)); BRepBuilderAPI_MakeEdge ME(facing->Node (M), facing->Node (N));
if (ME.IsDone()) { if (ME.IsDone()) {
builder.Add(Comp,ME.Edge()); builder.Add(Comp,ME.Edge());
} }
@@ -210,13 +206,9 @@ for (TopExp_Explorer ex(ShapeFused,TopAbs_FACE) ; ex.More(); ex.Next()) { \n\
TopoDS_Face F =TopoDS::Face(ex.Current()); \n\ TopoDS_Face F =TopoDS::Face(ex.Current()); \n\
TopLoc_Location L; \n\ TopLoc_Location L; \n\
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L); \n\ Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L); \n\
TColgp_Array1OfPnt tab(1,(facing->NbNodes())); \n\ \n\
tab = facing->Nodes(); \n\
Poly_Array1OfTriangle tri(1,facing->NbTriangles()); \n\
tri = facing->Triangles(); \n\
\n\
for (Standard_Integer i=1;i<=(facing->NbTriangles());i++) { \n\ for (Standard_Integer i=1;i<=(facing->NbTriangles());i++) { \n\
Poly_Triangle trian = tri.Value(i); \n\ Poly_Triangle trian = facing->Triangle (i); \n\
Standard_Integer index1,index2,index3,M,N; \n\ Standard_Integer index1,index2,index3,M,N; \n\
trian.Get(index1,index2,index3); \n\ trian.Get(index1,index2,index3); \n\
\n\ \n\
@@ -233,7 +225,7 @@ for (TopExp_Explorer ex(ShapeFused,TopAbs_FACE) ; ex.More(); ex.Next()) { \n\
M = index2; \n\ M = index2; \n\
} \n\ } \n\
\n\ \n\
BRepBuilderAPI_MakeEdge ME(tab.Value(M),tab.Value(N)); \n\ BRepBuilderAPI_MakeEdge ME(facing->Node (M),facing->Node (N)); \n\
if (ME.IsDone()) { \n\ if (ME.IsDone()) { \n\
builder.Add(Comp,ME.Edge()); \n\ builder.Add(Comp,ME.Edge()); \n\
} \n\ } \n\

View File

@@ -158,10 +158,6 @@ case 6: //color
return; return;
} }
const TColgp_Array1OfPnt& Nodes= myT->Nodes();
const Poly_Array1OfTriangle& triangles = myT->Triangles();
Standard_Integer nnn = myT->NbTriangles(); // nnn : nombre de triangles Standard_Integer nnn = myT->NbTriangles(); // nnn : nombre de triangles
Standard_Integer nt, n1, n2, n3 = 0;// nt : triangle courant Standard_Integer nt, n1, n2, n3 = 0;// nt : triangle courant
// ni : sommet i du triangle courant // ni : sommet i du triangle courant
@@ -171,15 +167,15 @@ case 6: //color
// triangles(nt).Get(n1,n2,n3); // le triangle est n1,n2,n3 // triangles(nt).Get(n1,n2,n3); // le triangle est n1,n2,n3
if (myFace.Orientation() == TopAbs_REVERSED) // si la face est "reversed" if (myFace.Orientation() == TopAbs_REVERSED) // si la face est "reversed"
triangles(nt).Get(n1,n3,n2); // le triangle est n1,n3,n2 myT->Triangle (nt).Get (n1,n3,n2); // le triangle est n1,n3,n2
else else
triangles(nt).Get(n1,n2,n3); // le triangle est n1,n2,n3 myT->Triangle (nt).Get (n1,n2,n3); // le triangle est n1,n2,n3
if (TriangleIsValid (Nodes(n1),Nodes(n2),Nodes(n3)) ) if (TriangleIsValid (myT->Node (n1), myT->Node (n2), myT->Node (n3)) )
{ // Associates a vertexNT to each node { // Associates a vertexNT to each node
gp_Pnt p = Nodes(n1).Transformed(myLocation.Transformation()); gp_Pnt p = myT->Node (n1).Transformed (myLocation.Transformation());
gp_Pnt q = Nodes(n2).Transformed(myLocation.Transformation()); gp_Pnt q = myT->Node (n2).Transformed (myLocation.Transformation());
gp_Pnt r = Nodes(n3).Transformed(myLocation.Transformation()); gp_Pnt r = myT->Node (n3).Transformed (myLocation.Transformation());
if (p.Z() > H.Z()) H=p; if (p.Z() > H.Z()) H=p;
if (q.Z() > H.Z()) H=q; if (q.Z() > H.Z()) H=q;
@@ -213,14 +209,12 @@ case 6: //color
return; return;
} }
Poly_Connect pc(myT); Poly_Connect pc(myT);
const TColgp_Array1OfPnt& Nodes= myT->Nodes(); TColgp_Array1OfPnt Nodes (1, myT->NbNodes());
for (Standard_Integer in = 1; in <= myT->NbNodes(); in++)
Nodes.SetValue(in, myT->Node (in));
BAR = GProp_PGProps::Barycentre(Nodes); BAR = GProp_PGProps::Barycentre(Nodes);
//const TColgp_Array1OfPnt2d& UVNodes = myT->UVNodes();
const Poly_Array1OfTriangle& triangles = myT->Triangles();
TColgp_Array1OfDir myNormal(Nodes.Lower(), Nodes.Upper()); TColgp_Array1OfDir myNormal(Nodes.Lower(), Nodes.Upper());
StdPrs_ToolTriangulatedShape::Normal(myFace, pc, myNormal); StdPrs_ToolTriangulatedShape::Normal(myFace, pc, myNormal);
BRepTools::UVBounds(myFace,Umin, Umax, Vmin, Vmax); BRepTools::UVBounds(myFace,Umin, Umax, Vmin, Vmax);
dUmax = (Umax - Umin); dUmax = (Umax - Umin);
@@ -238,9 +232,9 @@ case 6: //color
{ {
// triangles(nt).Get(n1,n2,n3); // le triangle est n1,n2,n3 // triangles(nt).Get(n1,n2,n3); // le triangle est n1,n2,n3
if (myFace.Orientation() == TopAbs_REVERSED) // si la face est "reversed" if (myFace.Orientation() == TopAbs_REVERSED) // si la face est "reversed"
triangles(nt).Get(n1,n3,n2); // le triangle est n1,n3,n2 myT->Triangle (nt).Get (n1,n3,n2); // le triangle est n1,n3,n2
else else
triangles(nt).Get(n1,n2,n3); // le triangle est n1,n2,n3 myT->Triangle (nt).Get (n1,n2,n3); // le triangle est n1,n2,n3
if (TriangleIsValid (Nodes(n1),Nodes(n2),Nodes(n3)) ) if (TriangleIsValid (Nodes(n1),Nodes(n2),Nodes(n3)) )
{ // Associates a vertexNT to each node { // Associates a vertexNT to each node
@@ -258,9 +252,9 @@ case 6: //color
std::cout << "On traite actuellement le triangle : "<< nt <<"\n"; std::cout << "On traite actuellement le triangle : "<< nt <<"\n";
#endif #endif
if (myFace.Orientation() == TopAbs_REVERSED) // si la face est "reversed" if (myFace.Orientation() == TopAbs_REVERSED) // si la face est "reversed"
triangles(nt).Get(n1,n3,n2); // le triangle est n1,n3,n2 myT->Triangle (nt).Get (n1,n3,n2); // le triangle est n1,n3,n2
else else
triangles(nt).Get(n1,n2,n3); // le triangle est n1,n2,n3 myT->Triangle (nt).Get (n1,n2,n3); // le triangle est n1,n2,n3
if (TriangleIsValid (Nodes(n1),Nodes(n2),Nodes(n3)) ) if (TriangleIsValid (Nodes(n1),Nodes(n2),Nodes(n3)) )
{ // Associates a vertexNT to each node { // Associates a vertexNT to each node

View File

@@ -1336,11 +1336,11 @@ void AIS_Manipulator::Cube::addTriangle (const Standard_Integer theIndex,
const gp_Pnt& theP1, const gp_Pnt& theP2, const gp_Pnt& theP3, const gp_Pnt& theP1, const gp_Pnt& theP2, const gp_Pnt& theP3,
const gp_Dir& theNormal) const gp_Dir& theNormal)
{ {
myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 1, theP1); myTriangulation->ChangeNode (theIndex * 3 + 1) = theP1;
myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 2, theP2); myTriangulation->ChangeNode (theIndex * 3 + 2) = theP2;
myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 3, theP3); myTriangulation->ChangeNode (theIndex * 3 + 3) = theP3;
myTriangulation->ChangeTriangles().SetValue (theIndex + 1, Poly_Triangle (theIndex * 3 + 1, theIndex * 3 + 2, theIndex * 3 + 3)); myTriangulation->ChangeTriangle (theIndex + 1) = Poly_Triangle (theIndex * 3 + 1, theIndex * 3 + 2, theIndex * 3 + 3);
myArray->AddVertex (theP1, theNormal); myArray->AddVertex (theP1, theNormal);
myArray->AddVertex (theP2, theNormal); myArray->AddVertex (theP2, theNormal);
myArray->AddVertex (theP3, theNormal); myArray->AddVertex (theP3, theNormal);

View File

@@ -123,9 +123,6 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP
switch (aMode) switch (aMode)
{ {
case 0: case 0:
const TColgp_Array1OfPnt& nodes = myTriangulation->Nodes(); //Nodes
const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles(); //Triangle
Standard_Boolean hasVNormals = myTriangulation->HasNormals(); Standard_Boolean hasVNormals = myTriangulation->HasNormals();
Standard_Boolean hasVColors = HasVertexColors(); Standard_Boolean hasVColors = HasVertexColors();
@@ -135,29 +132,27 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP
Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect(); Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
Standard_Integer i; Standard_Integer i;
Standard_Integer j;
const Standard_Real ambient = 0.2; const Standard_Real ambient = 0.2;
if (hasVNormals) if (hasVNormals)
{ {
const TShort_Array1OfShortReal& normals = myTriangulation->Normals();
if (hasVColors) if (hasVColors)
{ {
const TColStd_Array1OfInteger& colors = myColor->Array1(); const TColStd_Array1OfInteger& colors = myColor->Array1();
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) for ( i = 1; i <= myTriangulation->NbNodes(); i++ )
{ {
j = (i - nodes.Lower()) * 3; anArray->AddVertex (myTriangulation->Node (i), attenuateColor (colors (i), ambient));
anArray->AddVertex(nodes(i), attenuateColor(colors(i), ambient)); const Vec3f& aNormal = myTriangulation->Normal (i);
anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3)); anArray->SetVertexNormal (i, aNormal.x(), aNormal.y(), aNormal.z());
} }
} }
else // !hasVColors else // !hasVColors
{ {
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) for ( i = 1; i <= myTriangulation->NbNodes(); i++ )
{ {
j = (i - nodes.Lower()) * 3; anArray->AddVertex(myTriangulation->Node (i));
anArray->AddVertex(nodes(i)); const Vec3f& aNormal = myTriangulation->Normal(i);
anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3)); anArray->SetVertexNormal(i, aNormal.x(), aNormal.y(), aNormal.z());
} }
} }
} }
@@ -166,23 +161,23 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP
if (hasVColors) if (hasVColors)
{ {
const TColStd_Array1OfInteger& colors = myColor->Array1(); const TColStd_Array1OfInteger& colors = myColor->Array1();
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) for ( i = 1; i <= myTriangulation->NbNodes(); i++ )
{ {
anArray->AddVertex(nodes(i), attenuateColor(colors(i), ambient)); anArray->AddVertex(myTriangulation->Node (i), attenuateColor(colors(i), ambient));
} }
} }
else // !hasVColors else // !hasVColors
{ {
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) for ( i = 1; i <= myTriangulation->NbNodes(); i++ )
{ {
anArray->AddVertex(nodes(i)); anArray->AddVertex(myTriangulation->Node (i));
} }
} }
} }
Standard_Integer indexTriangle[3] = {0,0,0}; Standard_Integer indexTriangle[3] = {0,0,0};
for ( i = triangles.Lower(); i<= triangles.Upper(); i++ ) { for ( i = 1; i<= myTriangulation->NbTriangles(); i++ ) {
triangles(i).Get(indexTriangle[0], indexTriangle[1], indexTriangle[2]); myTriangulation->Triangle (i).Get(indexTriangle[0], indexTriangle[1], indexTriangle[2]);
anArray->AddEdge(indexTriangle[0]); anArray->AddEdge(indexTriangle[0]);
anArray->AddEdge(indexTriangle[1]); anArray->AddEdge(indexTriangle[1]);
anArray->AddEdge(indexTriangle[2]); anArray->AddEdge(indexTriangle[2]);

View File

@@ -149,20 +149,19 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
if (useTriangulation && !Poly.IsNull() && !T.IsNull() && T->NbNodes() > 0) if (useTriangulation && !Poly.IsNull() && !T.IsNull() && T->NbNodes() > 0)
{ {
const TColStd_Array1OfInteger& Indices = Poly->Nodes(); const TColStd_Array1OfInteger& Indices = Poly->Nodes();
const TColgp_Array1OfPnt& Nodes = T->Nodes();
nbNodes = Indices.Length(); nbNodes = Indices.Length();
if (l.IsIdentity()) if (l.IsIdentity())
{ {
for (i = 1; i <= nbNodes; i++) for (i = 1; i <= nbNodes; i++)
{ {
B.Add(Nodes(Indices[i])); B.Add (T->Node (Indices[i]));
} }
} }
else else
{ {
for (i = 1; i <= nbNodes; i++) for (i = 1; i <= nbNodes; i++)
{ {
B.Add(Nodes(Indices[i]).Transformed(l)); B.Add (T->Node (Indices[i]).Transformed (l));
} }
} }
// B.Enlarge(T->Deflection()); // B.Enlarge(T->Deflection());
@@ -341,12 +340,11 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B,
if (useTriangulation && !Poly.IsNull() && !T.IsNull() && T->NbNodes() > 0) if (useTriangulation && !Poly.IsNull() && !T.IsNull() && T->NbNodes() > 0)
{ {
const TColStd_Array1OfInteger& Indices = Poly->Nodes(); const TColStd_Array1OfInteger& Indices = Poly->Nodes();
const TColgp_Array1OfPnt& Nodes = T->Nodes();
nbNodes = Indices.Length(); nbNodes = Indices.Length();
for (i = 1; i <= nbNodes; i++) for (i = 1; i <= nbNodes; i++)
{ {
if (l.IsIdentity()) aLocBox.Add(Nodes(Indices[i])); if (l.IsIdentity()) aLocBox.Add (T->Node (Indices[i]));
else aLocBox.Add(Nodes(Indices[i]).Transformed(l)); else aLocBox.Add (T->Node (Indices[i]).Transformed (l));
} }
Standard_Real Tol = useShapeTolerance? BRep_Tool::Tolerance(E) : 0.; Standard_Real Tol = useShapeTolerance? BRep_Tool::Tolerance(E) : 0.;
aLocBox.Enlarge(Poly->Deflection() + Tol); aLocBox.Enlarge(Poly->Deflection() + Tol);

View File

@@ -191,13 +191,12 @@ static Standard_Integer PointsForOBB(const TopoDS_Shape& theS,
return 0; return 0;
const Standard_Integer aCNode = aTrng->NbNodes(); const Standard_Integer aCNode = aTrng->NbNodes();
const TColgp_Array1OfPnt& aNodesArr = aTrng->Nodes();
for (Standard_Integer i = 1; i <= aCNode; i++) for (Standard_Integer i = 1; i <= aCNode; i++)
{ {
if (thePts) if (thePts)
{ {
const gp_Pnt aP = aLoc.IsIdentity() ? aNodesArr[i] : const gp_Pnt aP = aLoc.IsIdentity() ? aTrng->Node (i) :
aNodesArr[i].Transformed(aLoc); aTrng->Node (i).Transformed(aLoc);
(*thePts)(aRetVal) = aP; (*thePts)(aRetVal) = aP;
} }

View File

@@ -704,7 +704,6 @@ BRepCheck_Status BRepCheck_Edge::
aCR->PolygonOnTriangulation2() : aCR->PolygonOnTriangulation2() :
aCR->PolygonOnTriangulation(); aCR->PolygonOnTriangulation();
const TColStd_Array1OfInteger& anIndices = aPOnTriag->Nodes(); const TColStd_Array1OfInteger& anIndices = aPOnTriag->Nodes();
const TColgp_Array1OfPnt& Nodes = aTriang->Nodes();
const Standard_Integer aNbNodes = anIndices.Length(); const Standard_Integer aNbNodes = anIndices.Length();
const Standard_Real aTol = aPOnTriag->Deflection() + const Standard_Real aTol = aPOnTriag->Deflection() +
@@ -717,7 +716,7 @@ BRepCheck_Status BRepCheck_Edge::
{ {
const Standard_Real aParam = aPOnTriag->Parameters()->Value(i); const Standard_Real aParam = aPOnTriag->Parameters()->Value(i);
const gp_Pnt aPE(aBC.Value(aParam)), const gp_Pnt aPE(aBC.Value(aParam)),
aPnt(Nodes(anIndices(i)).Transformed(aLL)); aPnt(aTriang->Node (anIndices(i)).Transformed(aLL));
const Standard_Real aSQDist = aPE.SquareDistance(aPnt); const Standard_Real aSQDist = aPE.SquareDistance(aPnt);
if(aSQDist > aTol*aTol) if(aSQDist > aTol*aTol)
@@ -736,9 +735,9 @@ BRepCheck_Status BRepCheck_Edge::
for (Standard_Integer i = 1; i <= aNbNodes; i++) for (Standard_Integer i = 1; i <= aNbNodes; i++)
{ {
if (aLL.IsIdentity()) if (aLL.IsIdentity())
aB.Add(Nodes(anIndices(i))); aB.Add(aTriang->Node (anIndices(i)));
else else
aB.Add(Nodes(anIndices(i)).Transformed(aLL)); aB.Add(aTriang->Node (anIndices(i)).Transformed(aLL));
} }
aB.Enlarge(aTol); aB.Enlarge(aTol);

View File

@@ -75,12 +75,11 @@ Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, const TopoD
Tr = BRep_Tool::Triangulation(F,L); Tr = BRep_Tool::Triangulation(F,L);
if (!Tr.IsNull()) if (!Tr.IsNull())
{ {
const TColgp_Array1OfPnt& Nod = Tr->Nodes();
n = Tr->NbNodes(); n = Tr->NbNodes();
for (i = 1; i <= n; i++) for (i = 1; i <= n; i++)
{ {
nbn1++; nbn1++;
TP1.SetValue(nbn1,Nod(i).Transformed(L)); TP1.SetValue(nbn1,Tr->Node (i).Transformed(L));
} }
} }
} }
@@ -96,12 +95,11 @@ Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, const TopoD
Tr = BRep_Tool::Triangulation(F,L); Tr = BRep_Tool::Triangulation(F,L);
if (!Tr.IsNull()) if (!Tr.IsNull())
{ {
const TColgp_Array1OfPnt& Nod = Tr->Nodes();
n = Tr->NbNodes(); n = Tr->NbNodes();
for (i = 1; i <= n; i++) for (i = 1; i <= n; i++)
{ {
nbn2++; nbn2++;
TP2.SetValue(nbn2,Nod(i).Transformed(L)); TP2.SetValue(nbn2,Tr->Node (i).Transformed(L));
} }
} }
} }

View File

@@ -179,7 +179,7 @@ Standard_Boolean BRepExtrema_TriangleSet::Init (const BRepExtrema_ShapeList& the
for (Standard_Integer aVertIdx = 1; aVertIdx <= aTriangulation->NbNodes(); ++aVertIdx) for (Standard_Integer aVertIdx = 1; aVertIdx <= aTriangulation->NbNodes(); ++aVertIdx)
{ {
gp_Pnt aVertex = aTriangulation->Nodes().Value (aVertIdx); gp_Pnt aVertex = aTriangulation->Node (aVertIdx);
aVertex.Transform (aLocation.Transformation()); aVertex.Transform (aLocation.Transformation());
@@ -194,9 +194,9 @@ Standard_Boolean BRepExtrema_TriangleSet::Init (const BRepExtrema_ShapeList& the
Standard_Integer aVertex2; Standard_Integer aVertex2;
Standard_Integer aVertex3; Standard_Integer aVertex3;
aTriangulation->Triangles().Value (aTriIdx).Get (aVertex1, aTriangulation->Triangle (aTriIdx).Get (aVertex1,
aVertex2, aVertex2,
aVertex3); aVertex3);
myTriangles.push_back (BVH_Vec4i (aVertex1 + aVertOffset, myTriangles.push_back (BVH_Vec4i (aVertex1 + aVertOffset,
aVertex2 + aVertOffset, aVertex2 + aVertOffset,

View File

@@ -180,13 +180,12 @@ void BRepGProp_MeshCinert::PreparePolygon(const TopoDS_Edge& theE,
Standard_Integer aNbNodes = aPOnTri->NbNodes(); Standard_Integer aNbNodes = aPOnTri->NbNodes();
thePolyg = new TColgp_HArray1OfPnt(1, aNbNodes); thePolyg = new TColgp_HArray1OfPnt(1, aNbNodes);
const TColStd_Array1OfInteger& aNodeInds = aPOnTri->Nodes(); const TColStd_Array1OfInteger& aNodeInds = aPOnTri->Nodes();
const TColgp_Array1OfPnt& aNodes = aTri->Nodes();
Standard_Integer i; Standard_Integer i;
if (aLoc.IsIdentity()) if (aLoc.IsIdentity())
{ {
for (i = 1; i <= aNbNodes; ++i) for (i = 1; i <= aNbNodes; ++i)
{ {
thePolyg->SetValue(i, aNodes(aNodeInds(i))); thePolyg->SetValue (i, aTri->Node (aNodeInds (i)));
} }
} }
else else
@@ -194,7 +193,7 @@ void BRepGProp_MeshCinert::PreparePolygon(const TopoDS_Edge& theE,
const gp_Trsf& aTr = aLoc.Transformation(); const gp_Trsf& aTr = aLoc.Transformation();
for (i = 1; i <= aNbNodes; ++i) for (i = 1; i <= aNbNodes; ++i)
{ {
thePolyg->SetValue(i, aNodes.Value(aNodeInds(i)).Transformed(aTr)); thePolyg->SetValue (i, aTri->Node (aNodeInds (i)).Transformed (aTr));
} }
} }
return; return;

View File

@@ -171,7 +171,7 @@ void BRepGProp_MeshProps::Perform(const Handle(Poly_Triangulation)& theMesh,
} }
if (theLoc.IsIdentity()) if (theLoc.IsIdentity())
{ {
Perform(theMesh->Nodes(), theMesh->Triangles(), theOri); Perform (theMesh, theOri);
} }
else else
{ {
@@ -181,21 +181,25 @@ void BRepGProp_MeshProps::Perform(const Handle(Poly_Triangulation)& theMesh,
Abs(Abs(aTr.ScaleFactor()) - 1.) > gp::Resolution(); Abs(Abs(aTr.ScaleFactor()) - 1.) > gp::Resolution();
if (isToCopy) if (isToCopy)
{ {
TColgp_Array1OfPnt aNodes(1, theMesh->NbNodes()); // Copy and transform nodes.
const TColgp_Array1OfPnt& aMeshNodes = theMesh->Nodes();
Standard_Integer i; Standard_Integer i;
for (i = 1; i <= aMeshNodes.Length(); ++i) TColgp_Array1OfPnt aNodes (1, theMesh->NbNodes());
{ for (i = 1; i <= theMesh->NbNodes(); ++i)
aNodes(i) = aMeshNodes.Value(i).Transformed(aTr); aNodes (i) = theMesh->Node (i).Transformed (aTr);
}
Perform(aNodes, theMesh->Triangles(), theOri); // Copy triangles.
Poly_Array1OfTriangle aTriangles (1, theMesh->NbTriangles());
for (i = 1; i <= theMesh->NbTriangles();++i)
aTriangles (i) = theMesh->Triangle (i);
Perform(new Poly_Triangulation(aNodes, aTriangles), theOri);
return; return;
} }
// //
gp_Trsf aTrInv = aTr.Inverted(); gp_Trsf aTrInv = aTr.Inverted();
gp_Pnt loc_save = loc; gp_Pnt loc_save = loc;
loc.Transform(aTrInv); loc.Transform(aTrInv);
Perform(theMesh->Nodes(), theMesh->Triangles(), theOri); Perform(theMesh, theOri);
//Computes the inertia tensor at mesh gravity center //Computes the inertia tensor at mesh gravity center
gp_Mat HMat, inertia0; gp_Mat HMat, inertia0;
gp_Pnt g0 = g; gp_Pnt g0 = g;
@@ -229,11 +233,10 @@ void BRepGProp_MeshProps::Perform(const Handle(Poly_Triangulation)& theMesh,
//function : Perform //function : Perform
//purpose : //purpose :
//======================================================================= //=======================================================================
void BRepGProp_MeshProps::Perform(const TColgp_Array1OfPnt& theNodes, void BRepGProp_MeshProps::Perform (const Handle(Poly_Triangulation)& theMesh,
const Poly_Array1OfTriangle& theTriangles,
const TopAbs_Orientation theOri) const TopAbs_Orientation theOri)
{ {
if (theNodes.IsEmpty() || theTriangles.IsEmpty()) if (theMesh.IsNull() || !theMesh->NbNodes() || !theMesh->NbTriangles())
{ {
return; return;
} }
@@ -257,11 +260,11 @@ void BRepGProp_MeshProps::Perform(const TColgp_Array1OfPnt& theNodes,
Standard_Boolean isVolume = myType == Vinert; Standard_Boolean isVolume = myType == Vinert;
Standard_Integer i; Standard_Integer i;
Standard_Integer n1, n2, n3; //node indices Standard_Integer n1, n2, n3; //node indeces
for (i = theTriangles.Lower(); i <= theTriangles.Upper(); ++i) for (i = 1; i <= theMesh->NbTriangles(); ++i)
{ {
const Poly_Triangle& aTri = theTriangles(i); const Poly_Triangle& aTri = theMesh->Triangle (i);
aTri.Get(n1, n2, n3); aTri.Get (n1, n2, n3);
if (theOri == TopAbs_REVERSED) if (theOri == TopAbs_REVERSED)
{ {
Standard_Integer nn = n2; Standard_Integer nn = n2;
@@ -269,10 +272,10 @@ void BRepGProp_MeshProps::Perform(const TColgp_Array1OfPnt& theNodes,
n3 = nn; n3 = nn;
} }
// Calculate properties of a pyramid built on face and apex // Calculate properties of a pyramid built on face and apex
const gp_Pnt& p1 = theNodes(n1); const gp_Pnt& p1 = theMesh->Node (n1);
const gp_Pnt& p2 = theNodes(n2); const gp_Pnt& p2 = theMesh->Node (n2);
const gp_Pnt& p3 = theNodes(n3); const gp_Pnt& p3 = theMesh->Node (n3);
CalculateProps(p1, p2, p3, loc, isVolume, aGProps, aNbGaussPoints, GPtsWg); CalculateProps (p1, p2, p3, loc, isVolume, aGProps, aNbGaussPoints, GPtsWg);
} }
dim = aGProps[0]; dim = aGProps[0];

View File

@@ -55,8 +55,7 @@ public:
const TopLoc_Location& theLoc, const TopLoc_Location& theLoc,
const TopAbs_Orientation theOri); const TopAbs_Orientation theOri);
Standard_EXPORT void Perform(const TColgp_Array1OfPnt& theNodes, Standard_EXPORT void Perform(const Handle(Poly_Triangulation)& theMesh,
const Poly_Array1OfTriangle& theTriangles,
const TopAbs_Orientation theOri); const TopAbs_Orientation theOri);
//! Computes the global properties of triangle {p1, p2, p3} relatively //! Computes the global properties of triangle {p1, p2, p3} relatively

View File

@@ -2343,12 +2343,9 @@ Standard_Boolean BRepLib::
} }
GeomLProp_SLProps aSLP(aSurf, 2, Precision::Confusion()); GeomLProp_SLProps aSLP(aSurf, 2, Precision::Confusion());
const Standard_Integer anArrDim = 3*aPT->NbNodes(); for(Standard_Integer i = 1; i <= aPT->NbNodes(); i++)
Handle(TShort_HArray1OfShortReal) aNormArr = new TShort_HArray1OfShortReal(1, anArrDim);
Standard_Integer anNormInd = aNormArr->Lower();
for(Standard_Integer i = aPT->UVNodes().Lower(); i <= aPT->UVNodes().Upper(); i++)
{ {
const gp_Pnt2d &aP2d = aPT->UVNodes().Value(i); const gp_Pnt2d &aP2d = aPT->UVNode (i);
aSLP.SetParameters(aP2d.X(), aP2d.Y()); aSLP.SetParameters(aP2d.X(), aP2d.Y());
gp_XYZ aNorm(0.,0.,0.); gp_XYZ aNorm(0.,0.,0.);
@@ -2364,14 +2361,13 @@ Standard_Boolean BRepLib::
if (aFace.Orientation() == TopAbs_REVERSED) if (aFace.Orientation() == TopAbs_REVERSED)
aNorm.Reverse(); aNorm.Reverse();
} }
aNormArr->ChangeValue(anNormInd++) = static_cast<Standard_ShortReal>(aNorm.X()); aPT->SetNormal (i, static_cast<Standard_ShortReal>(aNorm.X()),
aNormArr->ChangeValue(anNormInd++) = static_cast<Standard_ShortReal>(aNorm.Y()); static_cast<Standard_ShortReal>(aNorm.Y()),
aNormArr->ChangeValue(anNormInd++) = static_cast<Standard_ShortReal>(aNorm.Z()); static_cast<Standard_ShortReal>(aNorm.Z()));
} }
aRetVal = Standard_True; aRetVal = Standard_True;
isNormalsFound = Standard_True; isNormalsFound = Standard_True;
aPT->SetNormals(aNormArr);
} }
if(!isNormalsFound) if(!isNormalsFound)
@@ -2407,9 +2403,6 @@ Standard_Boolean BRepLib::
const Handle(Poly_PolygonOnTriangulation)& aPTEF2 = const Handle(Poly_PolygonOnTriangulation)& aPTEF2 =
BRep_Tool::PolygonOnTriangulation(anEdg, aPT2, aLoc2); BRep_Tool::PolygonOnTriangulation(anEdg, aPT2, aLoc2);
TShort_Array1OfShortReal& aNormArr1 = aPT1->ChangeNormals();
TShort_Array1OfShortReal& aNormArr2 = aPT2->ChangeNormals();
if (aPTEF1->Nodes().Lower() != aPTEF2->Nodes().Lower() || if (aPTEF1->Nodes().Lower() != aPTEF2->Nodes().Lower() ||
aPTEF1->Nodes().Upper() != aPTEF2->Nodes().Upper()) aPTEF1->Nodes().Upper() != aPTEF2->Nodes().Upper())
continue; continue;
@@ -2421,31 +2414,16 @@ Standard_Boolean BRepLib::
const Standard_Integer aFNodF1 = aPTEF1->Nodes().Value(anEdgNode); const Standard_Integer aFNodF1 = aPTEF1->Nodes().Value(anEdgNode);
const Standard_Integer aFNodF2 = aPTEF2->Nodes().Value(anEdgNode); const Standard_Integer aFNodF2 = aPTEF2->Nodes().Value(anEdgNode);
const Standard_Integer aFNorm1FirstIndex = aNormArr1.Lower() + 3* gp_XYZ aNorm1, aNorm2;
(aFNodF1 - aPT1->Nodes().Lower()); aPT1->Normal (aFNodF1, aNorm1);
const Standard_Integer aFNorm2FirstIndex = aNormArr2.Lower() + 3* aPT1->Normal (aFNodF2, aNorm2);
(aFNodF2 - aPT2->Nodes().Lower());
gp_XYZ aNorm1(aNormArr1.Value(aFNorm1FirstIndex),
aNormArr1.Value(aFNorm1FirstIndex+1),
aNormArr1.Value(aFNorm1FirstIndex+2));
gp_XYZ aNorm2(aNormArr2.Value(aFNorm2FirstIndex),
aNormArr2.Value(aFNorm2FirstIndex+1),
aNormArr2.Value(aFNorm2FirstIndex+2));
const Standard_Real aDot = aNorm1 * aNorm2; const Standard_Real aDot = aNorm1 * aNorm2;
if(aDot > aThresDot) if(aDot > aThresDot)
{ {
gp_XYZ aNewNorm = (aNorm1 + aNorm2).Normalized(); gp_XYZ aNewNorm = (aNorm1 + aNorm2).Normalized();
aNormArr1.ChangeValue(aFNorm1FirstIndex) = aPT1->SetNormal (aFNodF1, aNewNorm);
aNormArr2.ChangeValue(aFNorm2FirstIndex) = aPT2->SetNormal (aFNodF2, aNewNorm);
static_cast<Standard_ShortReal>(aNewNorm.X());
aNormArr1.ChangeValue(aFNorm1FirstIndex+1) =
aNormArr2.ChangeValue(aFNorm2FirstIndex+1) =
static_cast<Standard_ShortReal>(aNewNorm.Y());
aNormArr1.ChangeValue(aFNorm1FirstIndex+2) =
aNormArr2.ChangeValue(aFNorm2FirstIndex+2) =
static_cast<Standard_ShortReal>(aNewNorm.Z());
aRetVal = Standard_True; aRetVal = Standard_True;
} }
} }

View File

@@ -284,7 +284,9 @@ Handle(Poly_Triangulation) BRepMesh_BaseMeshAlgo::collectTriangles()
Handle(Poly_Triangulation) aTriangulation = new Poly_Triangulation( Handle(Poly_Triangulation) aTriangulation = new Poly_Triangulation(
myUsedNodes->Extent(), aTriangles.Extent(), Standard_True); myUsedNodes->Extent(), aTriangles.Extent(), Standard_True);
aTriangulation->ChangeTriangles() = aPolyTrianges; for (Standard_Integer iTri = 1; iTri <= aPolyTrianges.Upper(); iTri++)
aTriangulation->ChangeTriangle (iTri) = aPolyTrianges (iTri);
return aTriangulation; return aTriangulation;
} }
@@ -295,10 +297,6 @@ Handle(Poly_Triangulation) BRepMesh_BaseMeshAlgo::collectTriangles()
void BRepMesh_BaseMeshAlgo::collectNodes( void BRepMesh_BaseMeshAlgo::collectNodes(
const Handle(Poly_Triangulation)& theTriangulation) const Handle(Poly_Triangulation)& theTriangulation)
{ {
// Store mesh nodes
TColgp_Array1OfPnt& aNodes = theTriangulation->ChangeNodes();
TColgp_Array1OfPnt2d& aNodes2d = theTriangulation->ChangeUVNodes();
for (Standard_Integer i = 1; i <= myNodesMap->Size(); ++i) for (Standard_Integer i = 1; i <= myNodesMap->Size(); ++i)
{ {
if (myUsedNodes->IsBound(i)) if (myUsedNodes->IsBound(i))
@@ -306,8 +304,8 @@ void BRepMesh_BaseMeshAlgo::collectNodes(
const BRepMesh_Vertex& aVertex = myStructure->GetNode(i); const BRepMesh_Vertex& aVertex = myStructure->GetNode(i);
const Standard_Integer aNodeIndex = myUsedNodes->Find(i); const Standard_Integer aNodeIndex = myUsedNodes->Find(i);
aNodes(aNodeIndex) = myNodesMap->Value(aVertex.Location3d()); theTriangulation->ChangeNode (aNodeIndex) = myNodesMap->Value(aVertex.Location3d());
aNodes2d(aNodeIndex) = getNodePoint2d(aVertex); theTriangulation->ChangeUVNode (aNodeIndex) = getNodePoint2d(aVertex);
} }
} }
} }

View File

@@ -14,6 +14,7 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <BRepMesh_EdgeTessellationExtractor.hxx> #include <BRepMesh_EdgeTessellationExtractor.hxx>
#include <Poly_Triangulation.hxx>
#include <BRepMesh_ShapeTool.hxx> #include <BRepMesh_ShapeTool.hxx>
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
@@ -36,7 +37,7 @@ BRepMesh_EdgeTessellationExtractor::BRepMesh_EdgeTessellationExtractor (
Handle (Poly_PolygonOnTriangulation) aPolygon = Handle (Poly_PolygonOnTriangulation) aPolygon =
BRep_Tool::PolygonOnTriangulation (theEdge->GetEdge(), aTriangulation, myLoc); BRep_Tool::PolygonOnTriangulation (theEdge->GetEdge(), aTriangulation, myLoc);
myNodes = &aTriangulation->Nodes (); myTriangulation = aTriangulation;
myIndices = &aPolygon->Nodes (); myIndices = &aPolygon->Nodes ();
myProvider.Init (theEdge, TopAbs_FORWARD, theFace, aPolygon->Parameters ()); myProvider.Init (theEdge, TopAbs_FORWARD, theFace, aPolygon->Parameters ());
} }
@@ -67,7 +68,7 @@ Standard_Boolean BRepMesh_EdgeTessellationExtractor::Value (
gp_Pnt& thePoint, gp_Pnt& thePoint,
Standard_Real& theParameter) const Standard_Real& theParameter) const
{ {
const gp_Pnt& theRefPnt = (*myNodes) ((*myIndices) (theIndex)); const gp_Pnt& theRefPnt = myTriangulation->Node ((*myIndices)(theIndex));
thePoint = BRepMesh_ShapeTool::UseLocation (theRefPnt, myLoc); thePoint = BRepMesh_ShapeTool::UseLocation (theRefPnt, myLoc);
theParameter = myProvider.Parameter (theIndex, thePoint); theParameter = myProvider.Parameter (theIndex, thePoint);

View File

@@ -55,7 +55,7 @@ public:
private: private:
BRepMesh_EdgeParameterProvider<Handle(TColStd_HArray1OfReal)> myProvider; BRepMesh_EdgeParameterProvider<Handle(TColStd_HArray1OfReal)> myProvider;
const TColgp_Array1OfPnt* myNodes; Handle(Poly_Triangulation) myTriangulation;
const TColStd_Array1OfInteger* myIndices; const TColStd_Array1OfInteger* myIndices;
TopLoc_Location myLoc; TopLoc_Location myLoc;
}; };

View File

@@ -63,19 +63,16 @@ namespace
if (isTriangulationConsistent) if (isTriangulationConsistent)
{ {
// #25080: check that indices of links forming triangles are in range. // #25080: check that indices of links forming triangles are in range.
const Standard_Integer aNodesNb = aTriangulation->NbNodes(); Standard_Integer i = 1;
const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles(); for (; i <= aTriangulation->NbTriangles() && isTriangulationConsistent; ++i)
Standard_Integer i = aTriangles.Lower();
for (; i <= aTriangles.Upper() && isTriangulationConsistent; ++i)
{ {
const Poly_Triangle& aTriangle = aTriangles(i); const Poly_Triangle& aTriangle = aTriangulation->Triangle (i);
Standard_Integer aNode[3]; Standard_Integer aNode[3];
aTriangle.Get(aNode[0], aNode[1], aNode[2]); aTriangle.Get(aNode[0], aNode[1], aNode[2]);
for (Standard_Integer j = 0; j < 3 && isTriangulationConsistent; ++j) for (Standard_Integer j = 0; j < 3 && isTriangulationConsistent; ++j)
{ {
isTriangulationConsistent = (aNode[j] >= 1 && aNode[j] <= aNodesNb); isTriangulationConsistent = (aNode[j] >= 1 && aNode[j] <= aTriangulation->NbNodes());
} }
} }
} }

View File

@@ -208,10 +208,8 @@ void BRepMesh_ShapeTool::AddInFace(
{ {
gp_Trsf aTrsf = aLoc.Transformation(); gp_Trsf aTrsf = aLoc.Transformation();
aTrsf.Invert(); aTrsf.Invert();
for (Standard_Integer i = 1; i <= theTriangulation->NbNodes(); ++i)
TColgp_Array1OfPnt& aNodes = theTriangulation->ChangeNodes(); theTriangulation->ChangeNode (i).Transform (aTrsf);
for (Standard_Integer i = aNodes.Lower(); i <= aNodes.Upper(); ++i)
aNodes(i).Transform(aTrsf);
} }
BRep_Builder aBuilder; BRep_Builder aBuilder;

View File

@@ -16,17 +16,8 @@
#include <BRepTools_Modification.hxx> #include <BRepTools_Modification.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Surface.hxx>
#include <gp_Pnt.hxx>
#include <Standard_Type.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Vertex.hxx>
#include <Poly_PolygonOnTriangulation.hxx>
#include <Poly_Triangulation.hxx> #include <Poly_Triangulation.hxx>
#include <TopoDS_Face.hxx>
IMPLEMENT_STANDARD_RTTIEXT(BRepTools_Modification,Standard_Transient) IMPLEMENT_STANDARD_RTTIEXT(BRepTools_Modification,Standard_Transient)

View File

@@ -54,6 +54,7 @@
#include <TopoDS.hxx> #include <TopoDS.hxx>
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx> #include <TopoDS_Vertex.hxx>
#include <Poly_Mesh.hxx>
#ifdef MacOS #ifdef MacOS
#define strcasecmp(p,q) strcmp(p,q) #define strcasecmp(p,q) strcmp(p,q)
@@ -1421,7 +1422,7 @@ void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
const Standard_Boolean Compact, const Standard_Boolean Compact,
const Message_ProgressRange& theProgress)const const Message_ProgressRange& theProgress)const
{ {
Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent(); Standard_Integer i, j, k, nbNodes, nbtri = myTriangulations.Extent();
Standard_Integer nbTriangles = 0, n1, n2, n3; Standard_Integer nbTriangles = 0, n1, n2, n3;
Message_ProgressScope aPS(theProgress, "Triangulations", nbtri); Message_ProgressScope aPS(theProgress, "Triangulations", nbtri);
@@ -1467,28 +1468,26 @@ void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
if (!Compact) OS << "\n3D Nodes :\n"; if (!Compact) OS << "\n3D Nodes :\n";
nbNodes = T->NbNodes(); nbNodes = T->NbNodes();
const TColgp_Array1OfPnt& Nodes = T->Nodes();
for (j = 1; j <= nbNodes; j++) { for (j = 1; j <= nbNodes; j++) {
if (!Compact) OS << std::setw(10) << j << " : "; if (!Compact) OS << std::setw(10) << j << " : ";
if (!Compact) OS << std::setw(17); if (!Compact) OS << std::setw(17);
OS << Nodes(j).X() << " "; OS << T->Node (j).X() << " ";
if (!Compact) OS << std::setw(17); if (!Compact) OS << std::setw(17);
OS << Nodes(j).Y() << " "; OS << T->Node (j).Y() << " ";
if (!Compact) OS << std::setw(17); if (!Compact) OS << std::setw(17);
OS << Nodes(j).Z(); OS << T->Node (j).Z();
if (!Compact) OS << "\n"; if (!Compact) OS << "\n";
else OS << " "; else OS << " ";
} }
if (T->HasUVNodes()) { if (T->HasUVNodes()) {
if (!Compact) OS << "\nUV Nodes :\n"; if (!Compact) OS << "\nUV Nodes :\n";
const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
for (j = 1; j <= nbNodes; j++) { for (j = 1; j <= nbNodes; j++) {
if (!Compact) OS << std::setw(10) << j << " : "; if (!Compact) OS << std::setw(10) << j << " : ";
if (!Compact) OS << std::setw(17); if (!Compact) OS << std::setw(17);
OS << UVNodes(j).X() << " "; OS << T->UVNode (j).X() << " ";
if (!Compact) OS << std::setw(17); if (!Compact) OS << std::setw(17);
OS << UVNodes(j).Y(); OS << T->UVNode (j).Y();
if (!Compact) OS << "\n"; if (!Compact) OS << "\n";
else OS << " "; else OS << " ";
} }
@@ -1496,10 +1495,9 @@ void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
if (!Compact) OS << "\nTriangles :\n"; if (!Compact) OS << "\nTriangles :\n";
nbTriangles = T->NbTriangles(); nbTriangles = T->NbTriangles();
const Poly_Array1OfTriangle& Triangles = T->Triangles();
for (j = 1; j <= nbTriangles; j++) { for (j = 1; j <= nbTriangles; j++) {
if (!Compact) OS << std::setw(10) << j << " : "; if (!Compact) OS << std::setw(10) << j << " : ";
Triangles(j).Get(n1, n2, n3); T->Triangle (j).Get (n1, n2, n3);
if (!Compact) OS << std::setw(10); if (!Compact) OS << std::setw(10);
OS << n1 << " "; OS << n1 << " ";
if (!Compact) OS << std::setw(10); if (!Compact) OS << std::setw(10);
@@ -1515,22 +1513,24 @@ void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
if (T->HasNormals() && toWriteNormals) if (T->HasNormals() && toWriteNormals)
{ {
if (!Compact) OS << "\nNormals :\n"; if (!Compact) OS << "\nNormals :\n";
const TShort_Array1OfShortReal& Normals = T->Normals(); for (j = 1; j <= nbNodes; j++)
for (j = 1; j <= nbNodes * 3; j++)
{ {
if (!Compact) if (!Compact)
{ {
OS << std::setw(10) << j << " : "; OS << std::setw(10) << j << " : ";
OS << std::setw(17); OS << std::setw(17);
} }
OS << Normals(j) << " "; for (k = 1; k <= 3; k++)
if (!Compact)
{ {
OS << "\n"; OS << T->Normal (j).GetData() [k - 1] << " ";
} if (!Compact)
else {
{ OS << "\n";
OS << " "; }
else
{
OS << " ";
}
} }
} }
} }
@@ -1558,10 +1558,9 @@ void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const
void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS, const Message_ProgressRange& theProgress) void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS, const Message_ProgressRange& theProgress)
{ {
char buffer[255]; char buffer[255];
// Standard_Integer i, j, val, nbtri;
Standard_Integer i, j, nbtri =0; Standard_Integer i, j, nbtri =0;
Standard_Real d, x, y, z; Standard_Real d, x, y, z;
Standard_Real normal; Standard_Real normalX, normalY, normalZ;
Standard_Integer nbNodes =0, nbTriangles=0; Standard_Integer nbNodes =0, nbTriangles=0;
Standard_Boolean hasUV= Standard_False; Standard_Boolean hasUV= Standard_False;
Standard_Boolean hasNormals= Standard_False; Standard_Boolean hasNormals= Standard_False;
@@ -1583,53 +1582,231 @@ void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS, const Message_P
} }
GeomTools::GetReal(IS, d); GeomTools::GetReal(IS, d);
TColgp_Array1OfPnt Nodes(1, nbNodes); T = new Poly_Triangulation (nbNodes, nbTriangles, hasUV, hasNormals);
TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
Handle(TShort_HArray1OfShortReal) Normals;
if (hasNormals)
{
Normals = new TShort_HArray1OfShortReal(1, nbNodes * 3);
}
for (j = 1; j <= nbNodes; j++) { for (j = 1; j <= nbNodes; j++) {
GeomTools::GetReal(IS, x); GeomTools::GetReal(IS, x);
GeomTools::GetReal(IS, y); GeomTools::GetReal(IS, y);
GeomTools::GetReal(IS, z); GeomTools::GetReal(IS, z);
Nodes(j).SetCoord(x,y,z); T->ChangeNode (j).SetCoord (x,y,z);
} }
if (hasUV) { if (hasUV) {
for (j = 1; j <= nbNodes; j++) { for (j = 1; j <= nbNodes; j++) {
GeomTools::GetReal(IS, x); GeomTools::GetReal(IS, x);
GeomTools::GetReal(IS, y); GeomTools::GetReal(IS, y);
UVNodes(j).SetCoord(x,y); T->ChangeUVNode (j).SetCoord (x,y);
} }
} }
// read the triangles // read the triangles
Standard_Integer n1,n2,n3; Standard_Integer n1,n2,n3;
Poly_Array1OfTriangle Triangles(1, nbTriangles);
for (j = 1; j <= nbTriangles; j++) { for (j = 1; j <= nbTriangles; j++) {
IS >> n1 >> n2 >> n3; IS >> n1 >> n2 >> n3;
Triangles(j).Set(n1,n2,n3); T->ChangeTriangle (j).Set (n1,n2,n3);
} }
if (hasNormals) if (hasNormals)
{ {
for (j = 1; j <= nbNodes * 3; j++) for (j = 1; j <= nbNodes; j++)
{ {
GeomTools::GetReal(IS, normal); GeomTools::GetReal (IS, normalX);
Normals->SetValue(j, static_cast<Standard_ShortReal>(normal)); GeomTools::GetReal (IS, normalY);
GeomTools::GetReal (IS, normalZ);
T->SetNormal (j, static_cast<Standard_ShortReal>(normalX),
static_cast<Standard_ShortReal>(normalY),
static_cast<Standard_ShortReal>(normalZ));
} }
} }
if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
else T = new Poly_Triangulation(Nodes,Triangles);
T->Deflection(d); T->Deflection(d);
if (hasNormals)
{
T->SetNormals(Normals);
}
myTriangulations.Add(T, hasNormals); myTriangulations.Add(T, hasNormals);
} }
} }
// Writes meshes (Poly_Mesh).
void BRepTools_ShapeSet::WriteMeshes (Standard_OStream& theOS,
const TColStd_IndexedMapOfTransient& theMeshes,
const Standard_Boolean theCompact)
{
const Standard_Integer nbMeshes = theMeshes.Extent();
if (theCompact)
theOS << "Meshes " << nbMeshes << "\n";
else {
theOS << " -------\n";
theOS <<"Dump of " << nbMeshes << " meshes\n";
theOS << " -------\n";
}
Standard_Integer i = 1;
for (; i <= nbMeshes; i++)
{
const Handle(Poly_Mesh) aMesh = Handle(Poly_Mesh)::DownCast (theMeshes (i));
const Standard_Integer nbNodes = aMesh->NbNodes();
const Standard_Integer nbTriangles = aMesh->NbTriangles();
const Standard_Integer nbQuads = aMesh->NbQuads();
const Standard_Boolean hasUVNodes = aMesh->HasUVNodes();
if (theCompact)
{
theOS << nbNodes << " " << nbTriangles << " " << nbQuads << " ";
theOS << (hasUVNodes ? "1" : "0") << " ";
}
else
{
theOS << " "<< i << " : Mesh with " << nbNodes << " Nodes, " << nbTriangles << " Triangles, " << nbQuads << " Quadrangles\n";
theOS << " "<<(hasUVNodes ? "with" : "without") << " UV nodes\n";
}
// write the deflection
if (!theCompact)
theOS << " Deflection : ";
theOS << aMesh->Deflection() << "\n";
// write the 3d nodes
if (!theCompact)
theOS << "\n3D Nodes :\n";
Standard_Integer j;
for (j = 1; j <= nbNodes; j++)
{
if (!theCompact) theOS << std::setw (10) << j << " : ";
if (!theCompact) theOS << std::setw (17);
theOS << aMesh->Node (j).X() << " ";
if (!theCompact) theOS << std::setw (17);
theOS << aMesh->Node (j).Y() << " ";
if (!theCompact) theOS << std::setw (17);
theOS << aMesh->Node (j).Z();
if (!theCompact) theOS << "\n";
else theOS << " ";
}
// write 2d nodes
if (hasUVNodes)
{
if (!theCompact) theOS << "\nUV Nodes :\n";
for (j = 1; j <= nbNodes; j++)
{
if (!theCompact) theOS << std::setw (10) << j << " : ";
if (!theCompact) theOS << std::setw (17);
theOS << aMesh->UVNode (j).X() << " ";
if (!theCompact) theOS << std::setw (17);
theOS << aMesh->UVNode (j).Y();
if (!theCompact) theOS << "\n";
else theOS << " ";
}
}
// write triangles
if (!theCompact) theOS << "\nTriangles :\n";
Standard_Integer n1, n2, n3;
for (j = 1; j <= nbTriangles; j++)
{
if (!theCompact) theOS << std::setw (10) << j << " : ";
aMesh->Triangle (j).Get (n1, n2, n3);
if (!theCompact) theOS << std::setw (10);
theOS << n1 << " ";
if (!theCompact) theOS << std::setw (10);
theOS << n2 << " ";
if (!theCompact) theOS << std::setw (10);
theOS << n3;
if (!theCompact) theOS << "\n";
else theOS << " ";
}
// write quadrangles
if (!theCompact) theOS << "\nQuadrangles :\n";
Standard_Integer n4;
for (j = 1; j <= nbQuads; j++)
{
if (!theCompact) theOS << std::setw(10) << j << " : ";
aMesh->Quad (j).Get (n1, n2, n3, n4);
if (!theCompact) theOS << std::setw(10);
theOS << n1 << " ";
if (!theCompact) theOS << std::setw(10);
theOS << n2 << " ";
if (!theCompact) theOS << std::setw(10);
theOS << n3 << " ";
if (!theCompact) theOS << std::setw(10);
theOS << n4;
if (!theCompact) theOS << "\n";
else theOS << " ";
}
theOS << "\n";
}
}
// Reads meshes (Poly_Mesh).
void BRepTools_ShapeSet::ReadMeshes (Standard_IStream& theIS,
TColStd_IndexedMapOfTransient& theMeshes)
{
char buffer[255];
Standard_Integer i, j;
Standard_Integer n1 (0), n2 (0), n3 (0), n4 (0);
Standard_Real deflection, x, y, z;
Standard_Integer nbMeshes (0), nbNodes (0), nbTriangles (0), nbQuads (0);
Standard_Boolean hasUV (Standard_False);
gp_Pnt p;
// Read the "Meshes" head-line.
theIS >> buffer;
if (strstr (buffer, "Meshes") == NULL)
return;
// Read number of meshes.
theIS >> nbMeshes;
for (i = 1; i <= nbMeshes; i++)
{
theIS >> nbNodes >> nbTriangles >> nbQuads >> hasUV;
GeomTools::GetReal (theIS, deflection);
// Allocate the mesh.
Handle(Poly_Mesh) aMesh = new Poly_Mesh (nbNodes, nbTriangles, nbQuads, hasUV);
aMesh->Deflection (deflection);
// Read nodes.
for (j = 1; j <= nbNodes; j++)
{
GeomTools::GetReal (theIS, x);
GeomTools::GetReal (theIS, y);
GeomTools::GetReal (theIS, z);
p.SetCoord (x, y, z);
aMesh->ChangeNode (j) = p;
}
// Reads 2d-nodes.
if (hasUV)
{
for (j = 1; j <= nbNodes; j++)
{
GeomTools::GetReal (theIS, x);
GeomTools::GetReal (theIS, y);
aMesh->ChangeUVNode (j).SetCoord (x, y);
}
}
// Reads the triangles.
for (j = 1; j <= nbTriangles; j++)
{
// Read the indices.
theIS >> n1 >> n2 >> n3;
// Set the triangle to the mesh.
aMesh->ChangeTriangle (j) = Poly_Triangle (n1, n2, n3);
}
// Reads the quadrangles.
for (j = 1; j <= nbQuads; j++)
{
// Read the indices.
theIS >> n1 >> n2 >> n3 >> n4;
// Set the quadrangle to the mesh.
aMesh->ChangeQuad (j) = Poly_Quad (n1, n2, n3, n4);
}
theMeshes.Add (aMesh);
}
}

View File

@@ -155,7 +155,16 @@ public:
//! on the stream <OS>. //! on the stream <OS>.
Standard_EXPORT void DumpPolygonOnTriangulation (Standard_OStream& OS) const; Standard_EXPORT void DumpPolygonOnTriangulation (Standard_OStream& OS) const;
//! Writes meshes (Poly_Mesh).
//! TODO: Call this method when BRep_TFace refers to a list of meshes of type Poly_Mesh.
Standard_EXPORT static void WriteMeshes (Standard_OStream& theOS,
const TColStd_IndexedMapOfTransient& theMeshes,
const Standard_Boolean theCompact = Standard_True);
//! Reads meshes (Poly_Mesh).
//! TODO: Call this method when BRep_TFace refers to a list of meshes of type Poly_Mesh.
Standard_EXPORT static void ReadMeshes (Standard_IStream& theIS,
TColStd_IndexedMapOfTransient& theMeshes);
protected: protected:

View File

@@ -24,7 +24,8 @@
#include <BinMDataXtd_PresentationDriver.hxx> #include <BinMDataXtd_PresentationDriver.hxx>
#include <BinMDataXtd_PositionDriver.hxx> #include <BinMDataXtd_PositionDriver.hxx>
#include <BinMDataXtd_TriangulationDriver.hxx> #include <BinMDataXtd_TriangulationDriver.hxx>
#include <BinMDataXtd_SurfacicMeshDriver.hxx>
static Standard_Integer myDocumentVersion = -1; static Standard_Integer myDocumentVersion = -1;
//======================================================================= //=======================================================================
//function : AddDrivers //function : AddDrivers
@@ -38,6 +39,7 @@ void BinMDataXtd::AddDrivers (const Handle(BinMDF_ADriverTable)& theDriverTable,
theDriverTable->AddDriver (new BinMDataXtd_GeometryDriver (theMsgDriver) ); theDriverTable->AddDriver (new BinMDataXtd_GeometryDriver (theMsgDriver) );
theDriverTable->AddDriver (new BinMDataXtd_PatternStdDriver (theMsgDriver) ); theDriverTable->AddDriver (new BinMDataXtd_PatternStdDriver (theMsgDriver) );
theDriverTable->AddDriver (new BinMDataXtd_TriangulationDriver(theMsgDriver) ); theDriverTable->AddDriver (new BinMDataXtd_TriangulationDriver(theMsgDriver) );
theDriverTable->AddDriver (new BinMDataXtd_SurfacicMeshDriver (theMsgDriver) );
theDriverTable->AddDriver (new BinMDataXtd_PresentationDriver (theMsgDriver) ); theDriverTable->AddDriver (new BinMDataXtd_PresentationDriver (theMsgDriver) );
theDriverTable->AddDriver (new BinMDataXtd_PositionDriver (theMsgDriver) ); theDriverTable->AddDriver (new BinMDataXtd_PositionDriver (theMsgDriver) );

View File

@@ -0,0 +1,183 @@
// Created on: 2015-12-17
// Created by: Vlad Romashko
// Copyright (c) 2015 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.
#include <BinMDataXtd_SurfacicMeshDriver.hxx>
#include <BinObjMgt_Persistent.hxx>
#include <Standard_Type.hxx>
#include <TDataXtd_SurfacicMesh.hxx>
#include <TDF_Attribute.hxx>
IMPLEMENT_STANDARD_RTTIEXT(BinMDataXtd_SurfacicMeshDriver,BinMDF_ADriver)
//=======================================================================
//function : BinMDataXtd_SurfacicMeshDriver
//purpose : Constructor
//=======================================================================
BinMDataXtd_SurfacicMeshDriver::BinMDataXtd_SurfacicMeshDriver (const Handle(Message_Messenger)& theMsgDriver)
: BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataXtd_SurfacicMesh)->Name())
{
}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) BinMDataXtd_SurfacicMeshDriver::NewEmpty() const
{
return new TDataXtd_SurfacicMesh();
}
//=======================================================================
//function : Paste
//purpose : persistent -> transient (retrieve)
//=======================================================================
Standard_Boolean BinMDataXtd_SurfacicMeshDriver::Paste (const BinObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
BinObjMgt_RRelocationTable& ) const
{
Handle(TDataXtd_SurfacicMesh) attrMesh = Handle(TDataXtd_SurfacicMesh)::DownCast (theTarget);
Standard_Integer i;
Standard_Real deflection, x, y, z;
Standard_Integer n1, n2, n3, n4;
Standard_Integer nbNodes (0), nbTriangles (0), nbQuads (0);
Standard_Boolean hasUV (Standard_False);
gp_Pnt p;
theSource >> nbNodes;
theSource >> nbTriangles;
theSource >> nbQuads;
theSource >> hasUV;
theSource >> deflection;
// allocate the mesh
Handle(Poly_Mesh) aMesh = new Poly_Mesh (nbNodes, nbTriangles, nbQuads, hasUV);
// deflection
aMesh->Deflection (deflection);
// read nodes
for (i = 1; i <= nbNodes; i++)
{
theSource >> x;
theSource >> y;
theSource >> z;
p.SetCoord (x, y, z);
aMesh->ChangeNode (i) = p;
}
// read 2d nodes
if (hasUV)
{
for (i = 1; i <= nbNodes; i++)
{
theSource >> x;
theSource >> y;
aMesh->ChangeUVNode (i).SetCoord (x,y);
}
}
// read triangles
for (i = 1; i <= nbTriangles; i++)
{
theSource >> n1;
theSource >> n2;
theSource >> n3;
aMesh->ChangeTriangle (i).Set (n1, n2, n3);
}
// read quadrangles
for (i = 1; i <= nbQuads; i++)
{
theSource >> n1;
theSource >> n2;
theSource >> n3;
theSource >> n4;
aMesh->ChangeQuad (i).Set (n1, n2, n3, n4);
}
// Set mesh to Ocaf attribute
attrMesh->Set (aMesh);
return !aMesh.IsNull();
}
//=======================================================================
//function : Paste
//purpose : transient -> persistent (store)
//=======================================================================
void BinMDataXtd_SurfacicMeshDriver::Paste (const Handle(TDF_Attribute)& theSource,
BinObjMgt_Persistent& theTarget,
BinObjMgt_SRelocationTable& ) const
{
const Handle(TDataXtd_SurfacicMesh) attrMesh = Handle(TDataXtd_SurfacicMesh)::DownCast (theSource);
const Handle(Poly_Mesh)& aMesh = attrMesh->Get();
if (!aMesh.IsNull())
{
Standard_Integer nbNodes = aMesh->NbNodes();
Standard_Integer nbTriangles = aMesh->NbTriangles();
Standard_Integer nbQuads = aMesh->NbQuads();
// write number of elements
theTarget << nbNodes;
theTarget << nbTriangles;
theTarget << nbQuads;
theTarget << (aMesh->HasUVNodes() ? 1 : 0);
// write the deflection
theTarget << aMesh->Deflection();
// write 3d nodes
Standard_Integer i;
for (i = 1; i <= nbNodes; i++)
{
const gp_Pnt& aNode = aMesh->Node (i);
theTarget << aNode.X();
theTarget << aNode.Y();
theTarget << aNode.Z();
}
// write 2d nodes
if (aMesh->HasUVNodes())
{
for (i = 1; i <= nbNodes; i++)
{
const gp_Pnt2d& aUVNode = aMesh->UVNode (i);
theTarget << aUVNode.X();
theTarget << aUVNode.Y();
}
}
// write triangles
Standard_Integer n1, n2, n3;
for (i = 1; i <= nbTriangles; i++)
{
aMesh->Triangle (i).Get (n1, n2, n3);
theTarget << n1;
theTarget << n2;
theTarget << n3;
}
// write quadrangles
Standard_Integer n4;
for (i = 1; i <= nbQuads; i++)
{
aMesh->Quad (i).Get (n1, n2, n3, n4);
theTarget << n1;
theTarget << n2;
theTarget << n3;
theTarget << n4;
}
}
}

View File

@@ -0,0 +1,51 @@
// Created on: 2015-12-17
// Created by: Vlad Romashko
// Copyright (c) 2015 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.
#ifndef _BinMDataXtd_SurfacicMeshDriver_HeaderFile
#define _BinMDataXtd_SurfacicMeshDriver_HeaderFile
#include <Standard.hxx>
#include <BinMDF_ADriver.hxx>
#include <BinObjMgt_RRelocationTable.hxx>
#include <BinObjMgt_SRelocationTable.hxx>
class TDF_Attribute;
class Message_Messenger;
class BinObjMgt_Persistent;
DEFINE_STANDARD_HANDLE(BinMDataXtd_SurfacicMeshDriver, BinMDF_ADriver)
//! TDataXtd_SurfacicMesh attribute bin-driver.
class BinMDataXtd_SurfacicMeshDriver : public BinMDF_ADriver
{
public:
Standard_EXPORT BinMDataXtd_SurfacicMeshDriver(const Handle(Message_Messenger)& theMessageDriver);
Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean Paste (const BinObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
BinObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE;
Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& theSource,
BinObjMgt_Persistent& theTarget,
BinObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(BinMDataXtd_SurfacicMeshDriver, BinMDF_ADriver)
};
#endif // _BinMDataXtd_SurfacicMeshDriver_HeaderFile

View File

@@ -135,9 +135,9 @@ void BinMDataXtd_TriangulationDriver::Paste(const Handle(TDF_Attribute)& theSour
Standard_Integer i; Standard_Integer i;
for (i = 1; i <= nbNodes; i++) for (i = 1; i <= nbNodes; i++)
{ {
theTarget << PT->Node(i).X(); theTarget << PT->Node (i).X();
theTarget << PT->Node(i).Y(); theTarget << PT->Node (i).Y();
theTarget << PT->Node(i).Z(); theTarget << PT->Node (i).Z();
} }
// write 2d nodes // write 2d nodes
@@ -145,16 +145,15 @@ void BinMDataXtd_TriangulationDriver::Paste(const Handle(TDF_Attribute)& theSour
{ {
for (i = 1; i <= nbNodes; i++) for (i = 1; i <= nbNodes; i++)
{ {
theTarget << PT->UVNode(i).X(); theTarget << PT->UVNode (i).X();
theTarget << PT->UVNode(i).Y(); theTarget << PT->UVNode (i).Y();
} }
} }
// Write triangles // Write triangles
const Poly_Array1OfTriangle& Triangles = PT->Triangles();
for (i = 1; i <= nbTriangles; i++) for (i = 1; i <= nbTriangles; i++)
{ {
Triangles(i).Get(n1, n2, n3); PT->Triangle (i).Get (n1, n2, n3);
theTarget << n1; theTarget << n1;
theTarget << n2; theTarget << n2;
theTarget << n3; theTarget << n3;

View File

@@ -12,3 +12,5 @@ BinMDataXtd_PositionDriver.hxx
BinMDataXtd_PositionDriver.cxx BinMDataXtd_PositionDriver.cxx
BinMDataXtd_TriangulationDriver.cxx BinMDataXtd_TriangulationDriver.cxx
BinMDataXtd_TriangulationDriver.hxx BinMDataXtd_TriangulationDriver.hxx
BinMDataXtd_SurfacicMeshDriver.cxx
BinMDataXtd_SurfacicMeshDriver.hxx

View File

@@ -1321,10 +1321,11 @@ void BinTools_ShapeSet::ReadPolygonOnTriangulation
Standard_Integer aNbNodes = 0; Standard_Integer aNbNodes = 0;
BinTools::GetInteger(IS, aNbNodes); BinTools::GetInteger(IS, aNbNodes);
Handle(Poly_PolygonOnTriangulation) aPoly = new Poly_PolygonOnTriangulation (aNbNodes, Standard_False); Handle(Poly_PolygonOnTriangulation) aPoly = new Poly_PolygonOnTriangulation (aNbNodes, Standard_False);
TColStd_Array1OfInteger& aNodes = aPoly->ChangeNodes();
for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter) for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
{ {
BinTools::GetInteger(IS, aNodes.ChangeValue (aNodeIter)); Standard_Integer aNode;
BinTools::GetInteger(IS, aNode);
aPoly->SetNode (aNodeIter, aNode);
} }
Standard_Real aDefl = 0.0; Standard_Real aDefl = 0.0;
@@ -1498,10 +1499,9 @@ void BinTools_ShapeSet::WriteTriangulation (Standard_OStream& OS,
BinTools::PutReal(OS, aTriangulation->Deflection()); BinTools::PutReal(OS, aTriangulation->Deflection());
// write the 3d nodes // write the 3d nodes
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter) for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
{ {
const gp_Pnt& aPnt = aNodes.Value (aNodeIter); const gp_Pnt& aPnt = aTriangulation->Node (aNodeIter);
BinTools::PutReal(OS, aPnt.X()); BinTools::PutReal(OS, aPnt.X());
BinTools::PutReal(OS, aPnt.Y()); BinTools::PutReal(OS, aPnt.Y());
BinTools::PutReal(OS, aPnt.Z()); BinTools::PutReal(OS, aPnt.Z());
@@ -1509,19 +1509,17 @@ void BinTools_ShapeSet::WriteTriangulation (Standard_OStream& OS,
if (aTriangulation->HasUVNodes()) if (aTriangulation->HasUVNodes())
{ {
const TColgp_Array1OfPnt2d& aUVNodes = aTriangulation->UVNodes();
for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter) for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
{ {
const gp_Pnt2d aUV = aUVNodes.Value (aNodeIter); const gp_Pnt2d& aUV = aTriangulation->UVNode (aNodeIter);
BinTools::PutReal(OS, aUV.X()); BinTools::PutReal(OS, aUV.X());
BinTools::PutReal(OS, aUV.Y()); BinTools::PutReal(OS, aUV.Y());
} }
} }
const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
for (Standard_Integer aTriIter = 1; aTriIter <= aNbTriangles; ++aTriIter) for (Standard_Integer aTriIter = 1; aTriIter <= aNbTriangles; ++aTriIter)
{ {
const Poly_Triangle& aTri = aTriangles.Value (aTriIter); const Poly_Triangle& aTri = aTriangulation->Triangle (aTriIter);
BinTools::PutInteger(OS, aTri.Value (1)); BinTools::PutInteger(OS, aTri.Value (1));
BinTools::PutInteger(OS, aTri.Value (2)); BinTools::PutInteger(OS, aTri.Value (2));
BinTools::PutInteger(OS, aTri.Value (3)); BinTools::PutInteger(OS, aTri.Value (3));
@@ -1532,11 +1530,12 @@ void BinTools_ShapeSet::WriteTriangulation (Standard_OStream& OS,
{ {
if (aTriangulation->HasNormals() && NeedToWriteNormals) if (aTriangulation->HasNormals() && NeedToWriteNormals)
{ {
const TShort_Array1OfShortReal& aNormals = aTriangulation->Normals(); for (Standard_Integer aNormalIter = 1; aNormalIter <= aNbNodes; ++aNormalIter)
for (Standard_Integer aNormalIter = 1; aNormalIter <= 3 * aNbNodes; ++aNormalIter)
{ {
const Standard_ShortReal& aNormal = aNormals.Value(aNormalIter); const Vec3f& aNormal = aTriangulation->Normal (aNormalIter);
BinTools::PutShortReal(OS, aNormal); BinTools::PutShortReal (OS, aNormal.x());
BinTools::PutShortReal (OS, aNormal.y());
BinTools::PutShortReal (OS, aNormal.z());
} }
} }
} }
@@ -1589,45 +1588,39 @@ void BinTools_ShapeSet::ReadTriangulation (Standard_IStream& IS,
Handle(Poly_Triangulation) aTriangulation = new Poly_Triangulation (aNbNodes, aNbTriangles, hasUV, hasNormals); Handle(Poly_Triangulation) aTriangulation = new Poly_Triangulation (aNbNodes, aNbTriangles, hasUV, hasNormals);
aTriangulation->Deflection (aDefl); aTriangulation->Deflection (aDefl);
TColgp_Array1OfPnt& aNodes = aTriangulation->ChangeNodes();
for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter) for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
{ {
Standard_Real* anXYZ = aNodes.ChangeValue (aNodeIter).ChangeCoord().ChangeData(); BinTools::GetReal(IS, aTriangulation->ChangeNode (aNodeIter).ChangeCoord().ChangeCoord(1));
BinTools::GetReal(IS, anXYZ[0]); BinTools::GetReal(IS, aTriangulation->ChangeNode (aNodeIter).ChangeCoord().ChangeCoord(2));
BinTools::GetReal(IS, anXYZ[1]); BinTools::GetReal(IS, aTriangulation->ChangeNode (aNodeIter).ChangeCoord().ChangeCoord(3));
BinTools::GetReal(IS, anXYZ[2]);
} }
if (hasUV) if (hasUV)
{ {
TColgp_Array1OfPnt2d& aUVNodes = aTriangulation->ChangeUVNodes();
for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter) for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
{ {
gp_XY& anUV = aUVNodes.ChangeValue (aNodeIter).ChangeCoord(); BinTools::GetReal(IS, aTriangulation->ChangeUVNode (aNodeIter).ChangeCoord().ChangeCoord (1));
BinTools::GetReal(IS, anUV.ChangeCoord (1)); BinTools::GetReal(IS, aTriangulation->ChangeUVNode (aNodeIter).ChangeCoord().ChangeCoord (2));
BinTools::GetReal(IS, anUV.ChangeCoord (2));
} }
} }
// read the triangles // read the triangles
Poly_Array1OfTriangle& aTriangles = aTriangulation->ChangeTriangles();
for (Standard_Integer aTriIter = 1; aTriIter <= aNbTriangles; ++aTriIter) for (Standard_Integer aTriIter = 1; aTriIter <= aNbTriangles; ++aTriIter)
{ {
Poly_Triangle& aTri = aTriangles.ChangeValue (aTriIter); BinTools::GetInteger(IS, aTriangulation->ChangeTriangle (aTriIter).ChangeValue (1));
BinTools::GetInteger(IS, aTri.ChangeValue (1)); BinTools::GetInteger(IS, aTriangulation->ChangeTriangle (aTriIter).ChangeValue (2));
BinTools::GetInteger(IS, aTri.ChangeValue (2)); BinTools::GetInteger(IS, aTriangulation->ChangeTriangle (aTriIter).ChangeValue (3));
BinTools::GetInteger(IS, aTri.ChangeValue (3));
} }
if (hasNormals) if (hasNormals)
{ {
TShort_Array1OfShortReal& aNormals = aTriangulation->ChangeNormals(); for (Standard_Integer aNormalIter = 1; aNormalIter <= aNbNodes; ++aNormalIter)
for (Standard_Integer aNormalIter = 1; aNormalIter <= aNbNodes*3; ++aNormalIter)
{ {
Standard_ShortReal aNormalFromFile; Standard_ShortReal aNormalX, aNormalY, aNormalZ;
BinTools::GetShortReal(IS, aNormalFromFile); BinTools::GetShortReal(IS, aNormalX);
Standard_ShortReal& aNormalCoordinate = aNormals.ChangeValue(aNormalIter); BinTools::GetShortReal(IS, aNormalY);
aNormalCoordinate = aNormalFromFile; BinTools::GetShortReal(IS, aNormalZ);
aTriangulation->SetNormal (aNormalIter, aNormalX, aNormalY, aNormalZ);
} }
} }

View File

@@ -779,10 +779,9 @@ void DBRep_DrawableShape::DrawOn(Draw_Display& dis) const
BRep_Tool::PolygonOnTriangulation(E->Edge(), Poly, PolyTr, loc); BRep_Tool::PolygonOnTriangulation(E->Edge(), Poly, PolyTr, loc);
if (!Poly.IsNull()) { if (!Poly.IsNull()) {
const TColStd_Array1OfInteger& Indices = Poly->Nodes(); const TColStd_Array1OfInteger& Indices = Poly->Nodes();
const TColgp_Array1OfPnt& Nodes = PolyTr->Nodes();
for (i=Indices.Lower()+1; i<=Indices.Upper(); i++) { for (i=Indices.Lower()+1; i<=Indices.Upper(); i++) {
dis.Draw(Nodes(Indices(i-1)).Transformed(loc), dis.Draw (PolyTr->Node (Indices (i-1)).Transformed (loc),
Nodes(Indices(i)).Transformed(loc)); PolyTr->Node (Indices (i)).Transformed (loc));
if (dis.HasPicked()) { if (dis.HasPicked()) {
pickshape = E->Edge(); pickshape = E->Edge();
upick = 0; upick = 0;
@@ -1079,11 +1078,11 @@ void DBRep_DrawableShape::display(const Handle(Poly_Triangulation)& T,
NCollection_Vector< NCollection_Vec2<Standard_Integer> > anInternal; NCollection_Vector< NCollection_Vec2<Standard_Integer> > anInternal;
Standard_Integer fr = 1; Standard_Integer fr = 1;
const Poly_Array1OfTriangle& triangles = T->Triangles();
Standard_Integer n[3]; Standard_Integer n[3];
for (i = 1; i <= nbTriangles; i++) { for (i = 1; i <= nbTriangles; i++) {
pc.Triangles(i,t[0],t[1],t[2]); pc.Triangles(i,t[0],t[1],t[2]);
triangles(i).Get(n[0],n[1],n[2]); T->Triangle (i).Get (n[0],n[1],n[2]);
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {
Standard_Integer k = (j+1) % 3; Standard_Integer k = (j+1) % 3;
if (t[j] == 0) { if (t[j] == 0) {
@@ -1099,16 +1098,14 @@ void DBRep_DrawableShape::display(const Handle(Poly_Triangulation)& T,
} }
// Display the edges // Display the edges
const TColgp_Array1OfPnt& Nodes = T->Nodes();
// std::cout<<"nb nodes = "<<Nodes.Length()<<std::endl;
// free edges // free edges
Standard_Integer nn; Standard_Integer nn;
dis.SetColor(Draw_rouge); dis.SetColor(Draw_rouge);
nn = Free.Length() / 2; nn = Free.Length() / 2;
for (i = 1; i <= nn; i++) { for (i = 1; i <= nn; i++) {
dis.Draw(Nodes(Free(2*i-1)).Transformed(tr), dis.Draw (T->Node (Free (2*i-1)).Transformed (tr),
Nodes(Free(2*i)).Transformed(tr)); T->Node (Free (2*i)).Transformed (tr));
} }
// internal edges // internal edges
@@ -1118,7 +1115,7 @@ void DBRep_DrawableShape::display(const Handle(Poly_Triangulation)& T,
{ {
const Standard_Integer n1 = anInterIter.Value()[0]; const Standard_Integer n1 = anInterIter.Value()[0];
const Standard_Integer n2 = anInterIter.Value()[1]; const Standard_Integer n2 = anInterIter.Value()[1];
dis.Draw (Nodes(n1).Transformed(tr), Nodes(n2).Transformed(tr)); dis.Draw (T->Node (n1).Transformed (tr), T->Node (n2).Transformed (tr));
} }
} }
@@ -1139,11 +1136,10 @@ Standard_Boolean DBRep_DrawableShape::addMeshNormals (NCollection_Vector<std::pa
return Standard_False; return Standard_False;
} }
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
BRepAdaptor_Surface aSurface (theFace); BRepAdaptor_Surface aSurface (theFace);
for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) for (Standard_Integer aNodeIter = 1; aNodeIter <= aTriangulation->NbNodes(); ++aNodeIter)
{ {
gp_Pnt aP1 = aNodes (aNodeIter); gp_Pnt aP1 = aTriangulation->Node (aNodeIter);
if (!aLoc.IsIdentity()) if (!aLoc.IsIdentity())
{ {
aP1.Transform (aLoc.Transformation()); aP1.Transform (aLoc.Transformation());
@@ -1152,7 +1148,9 @@ Standard_Boolean DBRep_DrawableShape::addMeshNormals (NCollection_Vector<std::pa
gp_Vec aNormal; gp_Vec aNormal;
if (hasNormals) if (hasNormals)
{ {
aNormal = aTriangulation->Normal (aNodeIter); gp_XYZ anXYZ;
aTriangulation->Normal (aNodeIter, anXYZ);
aNormal.SetXYZ (anXYZ);
} }
else else
{ {

View File

@@ -54,6 +54,7 @@
// LES ATTRIBUTES // LES ATTRIBUTES
#include <TDataStd.hxx> #include <TDataStd.hxx>
#include <TDataXtd_SurfacicMesh.hxx>
#include <TDataXtd_Triangulation.hxx> #include <TDataXtd_Triangulation.hxx>
#include <TDataStd_Comment.hxx> #include <TDataStd_Comment.hxx>
#include <TDataStd_Name.hxx> #include <TDataStd_Name.hxx>
@@ -4357,9 +4358,9 @@ static Standard_Integer DDataStd_SetTriangulation (Draw_Interpretor& di,
//purpose : DumpTriangulation (DF, entry) //purpose : DumpTriangulation (DF, entry)
//======================================================================= //=======================================================================
static Standard_Integer DDataStd_DumpMesh (Draw_Interpretor& di, static Standard_Integer DDataStd_DumpTriangulation (Draw_Interpretor& di,
Standard_Integer nb, Standard_Integer nb,
const char** arg) const char** arg)
{ {
if (nb == 3) if (nb == 3)
{ {
@@ -4395,6 +4396,98 @@ static Standard_Integer DDataStd_DumpMesh (Draw_Interpretor& di,
return 1; return 1;
} }
//=======================================================================
//function : DDataStd_SetMesh
//purpose : SetMesh (DF, entry, face)
//=======================================================================
static Standard_Integer DDataStd_SetMesh (Draw_Interpretor& di,
Standard_Integer nb,
const char** arg)
{
if (nb == 4)
{
Handle(TDF_Data) aDF;
if (!DDF::GetDF (arg[1], aDF))
return 1;
TDF_Label aLabel;
if (!DDF::AddLabel (aDF, arg[2], aLabel))
return 1;
// Get face.
TopoDS_Shape aFace = DBRep::Get (arg[3]);
if (aFace.IsNull() ||
aFace.ShapeType() != TopAbs_FACE)
{
di << "The face is null or not a face.\n";
return 1;
}
// Get triangulation of the face.
TopLoc_Location aLoc;
Handle(Poly_Triangulation) aTris = BRep_Tool::Triangulation (TopoDS::Face (aFace), aLoc);
if (aTris.IsNull())
{
di << "No triangulation in the face.\n";
return 1;
}
// Make a mesh.
Handle(Poly_Mesh) aMesh = new Poly_Mesh (aTris);
// Set the attribute.
TDataXtd_SurfacicMesh::Set (aLabel, aMesh);
return 0;
}
di << "DDataStd_SetMesh : Error\n";
return 1;
}
//=======================================================================
//function : DDataStd_DumpMesh
//purpose : DumpMesh (DF, entry)
//=======================================================================
static Standard_Integer DDataStd_DumpMesh (Draw_Interpretor& di,
Standard_Integer nb,
const char** arg)
{
if (nb == 3)
{
Handle(TDF_Data) aDF;
if (!DDF::GetDF (arg[1], aDF))
return 1;
Handle(TDataXtd_SurfacicMesh) aMesh;
if (!DDF::Find (aDF, arg[2], TDataXtd_SurfacicMesh::GetID(), aMesh))
{
di << "The attribute mesh doesn't exist at the label.\n";
return 1;
}
// Dump of the mesh.
if (aMesh->Get().IsNull())
{
di << "No mesh in the attribute.\n";
return 1;
}
di << "Deflection " << aMesh->Deflection() <<"\n";
di << "Number of nodes " << aMesh->NbNodes() << "\n";
di << "Number of triangles " << aMesh->NbTriangles() << "\n";
di << "Number of quadrangles " << aMesh->NbQuads() << "\n";
if (aMesh->HasUVNodes())
di << "It has 2d-nodes\n";
if (aMesh->HasNormals())
di << "It has normals\n";
return 0;
}
di << "DDataStd_DumpMesh : Error\n";
return 1;
}
//======================================================================= //=======================================================================
//function : BasicCommands //function : BasicCommands
//purpose : //purpose :
@@ -4516,6 +4609,11 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands)
"SetTriangulation (DF, entry, face) - adds label with passed entry to \ "SetTriangulation (DF, entry, face) - adds label with passed entry to \
DF and put an attribute with the triangulation from passed face", DF and put an attribute with the triangulation from passed face",
__FILE__, DDataStd_SetTriangulation, g); __FILE__, DDataStd_SetTriangulation, g);
theCommands.Add ("SetMesh",
"SetMesh (DF, entry, face) - adds label with passed entry to \
DF and put an attribute with the triangulation from passed face",
__FILE__, DDataStd_SetMesh, g);
theCommands.Add ("InsertBeforeExtStringList", theCommands.Add ("InsertBeforeExtStringList",
"InsertBeforeExtStringList (DF, entry, index, value )", "InsertBeforeExtStringList (DF, entry, index, value )",
@@ -4826,6 +4924,11 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands)
theCommands.Add ("DumpTriangulation", theCommands.Add ("DumpTriangulation",
"DumpTriangulations (DF, entry) - dumps info about triangulation that \ "DumpTriangulations (DF, entry) - dumps info about triangulation that \
stored in DF in triangulation attribute of a label with the passed entry", stored in DF in triangulation attribute of a label with the passed entry",
__FILE__, DDataStd_DumpTriangulation, g);
theCommands.Add ("DumpMesh",
"DumpMesh (DF, entry) - dumps info about mesh that stored \
in DF in mesh attribute of a label with the passed entry",
__FILE__, DDataStd_DumpMesh, g); __FILE__, DDataStd_DumpMesh, g);
//====================================================================== //======================================================================

View File

@@ -64,11 +64,10 @@ DrawTrSurf_Triangulation::DrawTrSurf_Triangulation
TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1(); TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
Standard_Integer fr = 1, in = 1; Standard_Integer fr = 1, in = 1;
const Poly_Array1OfTriangle& triangles = T->Triangles();
Standard_Integer n[3]; Standard_Integer n[3];
for (i = 1; i <= nbTriangles; i++) { for (i = 1; i <= nbTriangles; i++) {
pc.Triangles(i,t[0],t[1],t[2]); pc.Triangles(i,t[0],t[1],t[2]);
triangles(i).Get(n[0],n[1],n[2]); T->Triangle (i).Get (n[0],n[1],n[2]);
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {
Standard_Integer k = (j+1) % 3; Standard_Integer k = (j+1) % 3;
if (t[j] == 0) { if (t[j] == 0) {
@@ -146,15 +145,14 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
// Display the edges // Display the edges
Standard_Integer i,n; Standard_Integer i,n;
const TColgp_Array1OfPnt& Nodes = myTriangulation->Nodes();
// free edges // free edges
dis.SetColor(Draw_rouge); dis.SetColor(Draw_rouge);
const TColStd_Array1OfInteger& Free = myFree->Array1(); const TColStd_Array1OfInteger& Free = myFree->Array1();
n = Free.Length() / 2; n = Free.Length() / 2;
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
dis.Draw(Nodes(Free(2*i-1)),Nodes(Free(2*i))); dis.Draw (myTriangulation->Node (Free (2*i-1)),
myTriangulation->Node (Free (2*i)));
} }
// internal edges // internal edges
@@ -163,7 +161,8 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
const TColStd_Array1OfInteger& Internal = myInternals->Array1(); const TColStd_Array1OfInteger& Internal = myInternals->Array1();
n = Internal.Length() / 2; n = Internal.Length() / 2;
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
dis.Draw(Nodes(Internal(2*i-1)),Nodes(Internal(2*i))); dis.Draw (myTriangulation->Node (Internal (2*i-1)),
myTriangulation->Node (Internal (2*i)));
} }
// texts // texts
@@ -173,7 +172,7 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
n = myTriangulation->NbNodes(); n = myTriangulation->NbNodes();
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
Sprintf(text,"%d",i); Sprintf(text,"%d",i);
dis.DrawString(Nodes(i),text); dis.DrawString (myTriangulation->Node (i), text);
} }
} }
@@ -181,13 +180,12 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
dis.SetColor(Draw_vert); dis.SetColor(Draw_vert);
n = myTriangulation->NbTriangles(); n = myTriangulation->NbTriangles();
Standard_Integer t[3],j; Standard_Integer t[3],j;
const Poly_Array1OfTriangle& triangle = myTriangulation->Triangles();
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
triangle(i).Get(t[0],t[1],t[2]); myTriangulation->Triangle (i).Get (t[0],t[1],t[2]);
gp_Pnt P(0,0,0); gp_Pnt P(0,0,0);
gp_XYZ& bary = P.ChangeCoord(); gp_XYZ& bary = P.ChangeCoord();
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
bary.Add(Nodes(t[j]).Coord()); bary.Add (myTriangulation->Node (t[j]).Coord());
bary.Multiply(1./3.); bary.Multiply(1./3.);
Sprintf(text,"%d",i); Sprintf(text,"%d",i);

View File

@@ -67,11 +67,10 @@ DrawTrSurf_Triangulation2D::DrawTrSurf_Triangulation2D
TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1(); TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
Standard_Integer fr = 1, in = 1; Standard_Integer fr = 1, in = 1;
const Poly_Array1OfTriangle& triangles = T->Triangles();
Standard_Integer n[3]; Standard_Integer n[3];
for (i = 1; i <= nbTriangles; i++) { for (i = 1; i <= nbTriangles; i++) {
pc.Triangles(i,t[0],t[1],t[2]); pc.Triangles(i,t[0],t[1],t[2]);
triangles(i).Get(n[0],n[1],n[2]); T->Triangle(i).Get (n[0],n[1],n[2]);
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {
Standard_Integer k = (j+1) % 3; Standard_Integer k = (j+1) % 3;
if (t[j] == 0) { if (t[j] == 0) {
@@ -109,16 +108,15 @@ void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const
// Display the edges // Display the edges
Standard_Integer i,n; Standard_Integer i,n;
if (myTriangulation->HasUVNodes()) { if (myTriangulation->HasUVNodes()) {
const TColgp_Array1OfPnt2d& Nodes = myTriangulation->UVNodes();
// free edges // free edges
dis.SetColor(Draw_rouge); dis.SetColor(Draw_rouge);
const TColStd_Array1OfInteger& Free = myFree->Array1(); const TColStd_Array1OfInteger& Free = myFree->Array1();
n = Free.Length() / 2; n = Free.Length() / 2;
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
dis.Draw(Nodes(Free(2*i-1)),Nodes(Free(2*i))); dis.Draw (myTriangulation->UVNode (Free (2*i-1)),
myTriangulation->UVNode (Free (2*i)));
} }
// internal edges // internal edges
@@ -127,7 +125,8 @@ void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const
const TColStd_Array1OfInteger& Internal = myInternals->Array1(); const TColStd_Array1OfInteger& Internal = myInternals->Array1();
n = Internal.Length() / 2; n = Internal.Length() / 2;
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
dis.Draw(Nodes(Internal(2*i-1)),Nodes(Internal(2*i))); dis.Draw (myTriangulation->UVNode (Internal (2*i-1)),
myTriangulation->UVNode (Internal (2*i)));
} }
} }

View File

@@ -428,10 +428,8 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape,
TTMa[2][0] = ttma.Value(3,1); TTMa[2][0] = ttma.Value(3,1);
TTMa[2][1] = ttma.Value(3,2); TTMa[2][1] = ttma.Value(3,2);
TTMa[2][2] = ttma.Value(3,3); TTMa[2][2] = ttma.Value(3,3);
Poly_Array1OfTriangle & Tri = Tr->ChangeTriangles(); Standard_Integer nbN = Tr->NbNodes();
TColgp_Array1OfPnt & Nod = Tr->ChangeNodes(); Standard_Integer nbT = Tr->NbTriangles();
Standard_Integer nbN = Nod.Upper();
Standard_Integer nbT = Tri.Upper();
PD (f) = new HLRAlgo_PolyData(); PD (f) = new HLRAlgo_PolyData();
psd->PolyData().ChangeValue(iFace) = PD(f); psd->PolyData().ChangeValue(iFace) = PD(f);
PID(f) = new HLRAlgo_PolyInternalData(nbN,nbT); PID(f) = new HLRAlgo_PolyInternalData(nbN,nbT);
@@ -452,22 +450,19 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape,
HLRAlgo_Array1OfTData* TData = &pid->TData(); HLRAlgo_Array1OfTData* TData = &pid->TData();
HLRAlgo_Array1OfPISeg* PISeg = &pid->PISeg(); HLRAlgo_Array1OfPISeg* PISeg = &pid->PISeg();
HLRAlgo_Array1OfPINod* PINod = &pid->PINod(); HLRAlgo_Array1OfPINod* PINod = &pid->PINod();
Poly_Triangle * OT = &(Tri.ChangeValue(1));
HLRAlgo_TriangleData* NT = &TData->ChangeValue(1); HLRAlgo_TriangleData* NT = &TData->ChangeValue(1);
for (i = 1; i <= nbT; i++) { for (i = 1; i <= nbT; i++) {
OT->Get(NT->Node1, NT->Node2, NT->Node3); Tr->Triangle (i).Get (NT->Node1, NT->Node2, NT->Node3);
NT->Flags = 0; NT->Flags = 0;
if (reversed) { if (reversed) {
j = NT->Node1; j = NT->Node1;
NT->Node1 = NT->Node3; NT->Node1 = NT->Node3;
NT->Node3 = j; NT->Node3 = j;
} }
OT++;
NT++; NT++;
} }
gp_Pnt * ON = &(Nod.ChangeValue(1));
Handle(HLRAlgo_PolyInternalNode)* NN = &PINod->ChangeValue(1); Handle(HLRAlgo_PolyInternalNode)* NN = &PINod->ChangeValue(1);
for (i = 1; i <= nbN; i++) { for (i = 1; i <= nbN; i++) {
@@ -475,23 +470,20 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape,
HLRAlgo_PolyInternalNode::NodeIndices& aNodIndices = (*NN)->Indices(); HLRAlgo_PolyInternalNode::NodeIndices& aNodIndices = (*NN)->Indices();
aNodIndices.NdSg = 0; aNodIndices.NdSg = 0;
aNodIndices.Flag = 0; aNodIndices.Flag = 0;
Nod1RValues.Point = ON->Coord(); Nod1RValues.Point = Tr->Node (i).Coord();
TTMultiply(Nod1RValues.Point); TTMultiply(Nod1RValues.Point);
ON++;
NN++; NN++;
} }
pid->UpdateLinks(TData,PISeg,PINod); pid->UpdateLinks(TData,PISeg,PINod);
if (Tr->HasUVNodes()) { if (Tr->HasUVNodes()) {
myBSurf.Initialize(F,Standard_False); myBSurf.Initialize(F,Standard_False);
TColgp_Array1OfPnt2d & UVN = Tr->ChangeUVNodes();
gp_Pnt2d* OUVN = &(UVN.ChangeValue(1));
NN = &(((HLRAlgo_Array1OfPINod*)PINod)-> NN = &(((HLRAlgo_Array1OfPINod*)PINod)->
ChangeValue(1)); ChangeValue(1));
for (i = 1; i <= nbN; i++) { for (i = 1; i <= nbN; i++) {
HLRAlgo_PolyInternalNode::NodeIndices& aNodIndices = (*NN)->Indices(); HLRAlgo_PolyInternalNode::NodeIndices& aNodIndices = (*NN)->Indices();
HLRAlgo_PolyInternalNode::NodeData& Nod1RValues = (*NN)->Data(); HLRAlgo_PolyInternalNode::NodeData& Nod1RValues = (*NN)->Data();
Nod1RValues.UV = OUVN->Coord(); Nod1RValues.UV = Tr->UVNode (i).Coord();
if (Normal(i,aNodIndices,Nod1RValues, if (Normal(i,aNodIndices,Nod1RValues,
TData,PISeg,PINod,Standard_False)) TData,PISeg,PINod,Standard_False))
aNodIndices.Flag |= NMsk_Norm; aNodIndices.Flag |= NMsk_Norm;
@@ -499,7 +491,6 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape,
aNodIndices.Flag &= ~NMsk_Norm; aNodIndices.Flag &= ~NMsk_Norm;
Nod1RValues.Scal = 0; Nod1RValues.Scal = 0;
} }
OUVN++;
NN++; NN++;
} }
} }

View File

@@ -386,7 +386,12 @@ void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge& theEdge,
{ {
Standard_Integer aNbNodes = aPolyOnTriangulation->NbNodes(); Standard_Integer aNbNodes = aPolyOnTriangulation->NbNodes();
const TColStd_Array1OfInteger& aPointIds = aPolyOnTriangulation->Nodes(); const TColStd_Array1OfInteger& aPointIds = aPolyOnTriangulation->Nodes();
const TColgp_Array1OfPnt& aPoints = aTriangulation->Nodes();
TColgp_Array1OfPnt aPoints(1, aTriangulation->NbNodes());
for (Standard_Integer anI = 1; anI <= aTriangulation->NbNodes(); anI++)
{
aPoints.SetValue (anI, aTriangulation->Node (anI));
}
processPolyline (aNbNodes, processPolyline (aNbNodes,
aPoints, aPoints,
@@ -493,7 +498,6 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
} }
// Get triangulation points. // Get triangulation points.
const TColgp_Array1OfPnt& aPoints = anOcctTriangulation->Nodes();
Standard_Integer aNbPoints = anOcctTriangulation->NbNodes(); Standard_Integer aNbPoints = anOcctTriangulation->NbNodes();
// Keep inserted points id's of triangulation in an array. // Keep inserted points id's of triangulation in an array.
@@ -503,7 +507,7 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
Standard_Integer anI; Standard_Integer anI;
for (anI = 1; anI <= aNbPoints; anI++) for (anI = 1; anI <= aNbPoints; anI++)
{ {
gp_Pnt aPoint = aPoints (anI); gp_Pnt aPoint = anOcctTriangulation->Node (anI);
if (!noTransform) if (!noTransform)
{ {
@@ -516,12 +520,11 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
} }
// Create triangles on the created triangulation points. // Create triangles on the created triangulation points.
const Poly_Array1OfTriangle& aTriangles = anOcctTriangulation->Triangles();
Standard_Integer aNbTriangles = anOcctTriangulation->NbTriangles(); Standard_Integer aNbTriangles = anOcctTriangulation->NbTriangles();
Standard_Integer aN1, aN2, aN3; Standard_Integer aN1, aN2, aN3;
for (anI = 1; anI <= aNbTriangles; anI++) for (anI = 1; anI <= aNbTriangles; anI++)
{ {
aTriangles(anI).Get (aN1, aN2, aN3); // get indexes of triangle's points anOcctTriangulation->Triangle (anI).Get (aN1, aN2, aN3); // get indexes of triangle's points
// Insert new triangle on these points into output shape data. // Insert new triangle on these points into output shape data.
myShapeData->InsertTriangle ( myShapeData->InsertTriangle (
theShapeId, aPointIds(aN1), aPointIds(aN2), aPointIds(aN3), MT_ShadedFace); theShapeId, aPointIds(aN1), aPointIds(aN2), aPointIds(aN3), MT_ShadedFace);

View File

@@ -334,7 +334,6 @@ static Standard_Integer tessellate (Draw_Interpretor& /*di*/, Standard_Integer n
new Poly_Triangulation (aNbNodes, aNbTriangles, Standard_False); new Poly_Triangulation (aNbNodes, aNbTriangles, Standard_False);
// fill nodes // fill nodes
TColgp_Array1OfPnt &aNodes = aTriangulation->ChangeNodes();
GeomAdaptor_Surface anAdSurf (aSurf); GeomAdaptor_Surface anAdSurf (aSurf);
double aDU = (aUMax - aUMin) / aNbU; double aDU = (aUMax - aUMin) / aNbU;
double aDV = (aVMax - aVMin) / aNbV; double aDV = (aVMax - aVMin) / aNbV;
@@ -345,12 +344,11 @@ static Standard_Integer tessellate (Draw_Interpretor& /*di*/, Standard_Integer n
{ {
double aV = aVMin + iV * aDV; double aV = aVMin + iV * aDV;
gp_Pnt aP = anAdSurf.Value (aU, aV); gp_Pnt aP = anAdSurf.Value (aU, aV);
aNodes.SetValue (iShift + iV, aP); aTriangulation->ChangeNode (iShift + iV) = aP;
} }
} }
// fill triangles // fill triangles
Poly_Array1OfTriangle &aTriangles = aTriangulation->ChangeTriangles();
for (int iU = 0, iShift = 1, iTri = 0; iU < aNbU; iU++, iShift += aNbV + 1) for (int iU = 0, iShift = 1, iTri = 0; iU < aNbU; iU++, iShift += aNbV + 1)
{ {
for (int iV = 0; iV < aNbV; iV++) for (int iV = 0; iV < aNbV; iV++)
@@ -358,8 +356,8 @@ static Standard_Integer tessellate (Draw_Interpretor& /*di*/, Standard_Integer n
int iBase = iShift + iV; int iBase = iShift + iV;
Poly_Triangle aTri1 (iBase, iBase + aNbV + 2, iBase + 1); Poly_Triangle aTri1 (iBase, iBase + aNbV + 2, iBase + 1);
Poly_Triangle aTri2 (iBase, iBase + aNbV + 1, iBase + aNbV + 2); Poly_Triangle aTri2 (iBase, iBase + aNbV + 1, iBase + aNbV + 2);
aTriangles.SetValue (++iTri, aTri1); aTriangulation->ChangeTriangle (++iTri) = aTri1;
aTriangles.SetValue (++iTri, aTri2); aTriangulation->ChangeTriangle (++iTri) = aTri2;
} }
} }
@@ -574,21 +572,18 @@ static Standard_Integer veriftriangles(Draw_Interpretor& di, Standard_Integer n,
Standard_Real deflemax = 0, deflemin = 1.e100; Standard_Real deflemax = 0, deflemin = 1.e100;
if (!T.IsNull()) { if (!T.IsNull()) {
Standard_Real defstock = T->Deflection(); Standard_Real defstock = T->Deflection();
const Poly_Array1OfTriangle& triangles = T->Triangles();
const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes();
const TColgp_Array1OfPnt& Nodes = T->Nodes();
S = BRep_Tool::Surface(F, L); S = BRep_Tool::Surface(F, L);
for(i = 1; i <= triangles.Length(); i++) { for(i = 1; i <= T->NbTriangles(); i++) {
if (F.Orientation() == TopAbs_REVERSED) if (F.Orientation() == TopAbs_REVERSED)
triangles(i).Get(n1,n3,n2); T->Triangle (i).Get (n1,n3,n2);
else else
triangles(i).Get(n1,n2,n3); T->Triangle (i).Get (n1,n2,n3);
const gp_XY& xy1 = Nodes2d(n1).XY(); const gp_XY& xy1 = T->UVNode (n1).XY();
const gp_XY& xy2 = Nodes2d(n2).XY(); const gp_XY& xy2 = T->UVNode (n2).XY();
const gp_XY& xy3 = Nodes2d(n3).XY(); const gp_XY& xy3 = T->UVNode (n3).XY();
mi2d1.SetCoord((xy2.X()+xy3.X())*0.5, mi2d1.SetCoord((xy2.X()+xy3.X())*0.5,
(xy2.Y()+xy3.Y())*0.5); (xy2.Y()+xy3.Y())*0.5);
@@ -597,9 +592,9 @@ static Standard_Integer veriftriangles(Draw_Interpretor& di, Standard_Integer n,
mi2d3.SetCoord((xy1.X()+xy2.X())*0.5, mi2d3.SetCoord((xy1.X()+xy2.X())*0.5,
(xy1.Y()+xy2.Y())*0.5); (xy1.Y()+xy2.Y())*0.5);
gp_XYZ p1 = Nodes(n1).Transformed(L.Transformation()).XYZ(); gp_XYZ p1 = T->Node (n1).Transformed (L.Transformation()).XYZ();
gp_XYZ p2 = Nodes(n2).Transformed(L.Transformation()).XYZ(); gp_XYZ p2 = T->Node (n2).Transformed (L.Transformation()).XYZ();
gp_XYZ p3 = Nodes(n3).Transformed(L.Transformation()).XYZ(); gp_XYZ p3 = T->Node (n3).Transformed (L.Transformation()).XYZ();
vecEd1=p2-p1; vecEd1=p2-p1;
vecEd2=p3-p2; vecEd2=p3-p2;
@@ -721,11 +716,10 @@ static Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char*
TColStd_Array1OfInteger Internal(0,2*nInternal); TColStd_Array1OfInteger Internal(0,2*nInternal);
Standard_Integer fr = 1, in = 1; Standard_Integer fr = 1, in = 1;
const Poly_Array1OfTriangle& triangles = T->Triangles();
Standard_Integer nodes[3]; Standard_Integer nodes[3];
for (i = 1; i <= nbTriangles; i++) { for (i = 1; i <= nbTriangles; i++) {
pc.Triangles(i,t[0],t[1],t[2]); pc.Triangles(i,t[0],t[1],t[2]);
triangles(i).Get(nodes[0],nodes[1],nodes[2]); T->Triangle (i).Get (nodes[0],nodes[1],nodes[2]);
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {
Standard_Integer k = (j+1) % 3; Standard_Integer k = (j+1) % 3;
if (t[j] == 0) { if (t[j] == 0) {
@@ -744,17 +738,15 @@ static Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char*
// Display the edges // Display the edges
if (T->HasUVNodes()) { if (T->HasUVNodes()) {
const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes();
Handle(Draw_Segment2D) Seg; Handle(Draw_Segment2D) Seg;
// free edges // free edges
Standard_Integer nn; Standard_Integer nn;
nn = Free.Length() / 2; nn = Free.Length() / 2;
for (i = 1; i <= nn; i++) { for (i = 1; i <= nn; i++) {
Seg = new Draw_Segment2D(Nodes2d(Free(2*i-1)), Seg = new Draw_Segment2D (T->UVNode (Free (2*i-1)),
Nodes2d(Free(2*i)), T->UVNode (Free (2*i)),
Draw_rouge); Draw_rouge);
dout << Seg; dout << Seg;
} }
@@ -762,9 +754,9 @@ static Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char*
nn = nInternal; nn = nInternal;
for (i = 1; i <= nn; i++) { for (i = 1; i <= nn; i++) {
Seg = new Draw_Segment2D(Nodes2d(Internal(2*i-1)), Seg = new Draw_Segment2D (T->UVNode (Internal (2*i-1)),
Nodes2d(Internal(2*i)), T->UVNode (Internal (2*i)),
Draw_bleu); Draw_bleu);
dout << Seg; dout << Seg;
} }
} }
@@ -833,11 +825,10 @@ static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, con
if (!Tr.IsNull()) { if (!Tr.IsNull()) {
nbNodes = Tr->NbNodes(); nbNodes = Tr->NbNodes();
const TColgp_Array1OfPnt& Nodes = Tr->Nodes();
// les noeuds. // les noeuds.
for (i = 1; i <= nbNodes; i++) { for (i = 1; i <= nbNodes; i++) {
gp_Pnt Pnt = Nodes(i).Transformed(L.Transformation()); gp_Pnt Pnt = Tr->Node (i).Transformed (L.Transformation());
x = Pnt.X(); x = Pnt.X();
y = Pnt.Y(); y = Pnt.Y();
z = Pnt.Z(); z = Pnt.Z();
@@ -850,12 +841,11 @@ static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, con
// les normales. // les normales.
if (Tr->HasUVNodes()) { if (Tr->HasUVNodes()) {
const TColgp_Array1OfPnt2d& UVNodes = Tr->UVNodes();
BRepAdaptor_Surface BS(F, Standard_False); BRepAdaptor_Surface BS(F, Standard_False);
for (i = 1; i <= nbNodes; i++) { for (i = 1; i <= nbNodes; i++) {
U = UVNodes(i).X(); U = Tr->UVNode (i).X();
V = UVNodes(i).Y(); V = Tr->UVNode (i).Y();
BS.D1(U,V,P,D1U,D1V); BS.D1(U,V,P,D1U,D1V);
CSLib::Normal (D1U, D1V, Precision::Angular(), aStatus, Nor); CSLib::Normal (D1U, D1V, Precision::Angular(), aStatus, Nor);
@@ -875,14 +865,12 @@ static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, con
// les triangles. // les triangles.
Standard_Integer nbTriangles = Tr->NbTriangles(); Standard_Integer nbTriangles = Tr->NbTriangles();
const Poly_Array1OfTriangle& triangles = Tr->Triangles();
for (i = 1; i <= nbTriangles; i++) { for (i = 1; i <= nbTriangles; i++) {
if (F.Orientation() == TopAbs_REVERSED) if (F.Orientation() == TopAbs_REVERSED)
triangles(i).Get(n1, n3, n2); Tr->Triangle (i).Get (n1, n3, n2);
else else
triangles(i).Get(n1, n2, n3); Tr->Triangle (i).Get (n1, n2, n3);
k1 = n1+totalnodes; k1 = n1+totalnodes;
k2 = n2+totalnodes; k2 = n2+totalnodes;
k3 = n3+totalnodes; k3 = n3+totalnodes;
@@ -950,14 +938,13 @@ static Standard_Integer triedgepoints(Draw_Interpretor& di, Standard_Integer nba
BRep_Tool::PolygonOnTriangulation(TopoDS::Edge(it.Key()), aPoly, aT, aLoc); BRep_Tool::PolygonOnTriangulation(TopoDS::Edge(it.Key()), aPoly, aT, aLoc);
if ( aT.IsNull() || aPoly.IsNull() ) if ( aT.IsNull() || aPoly.IsNull() )
continue; continue;
const TColgp_Array1OfPnt& Nodes = aT->Nodes();
const TColStd_Array1OfInteger& Indices = aPoly->Nodes(); const TColStd_Array1OfInteger& Indices = aPoly->Nodes();
const Standard_Integer nbnodes = Indices.Length(); const Standard_Integer nbnodes = Indices.Length();
for( Standard_Integer j = 1; j <= nbnodes; j++ ) for( Standard_Integer j = 1; j <= nbnodes; j++ )
{ {
gp_Pnt P3d = Nodes(Indices(j)); gp_Pnt P3d = aT->Node (Indices (j));
if( !aLoc.IsIdentity() ) if( !aLoc.IsIdentity() )
P3d.Transform(aLoc.Transformation()); P3d.Transform(aLoc.Transformation());

View File

@@ -112,8 +112,6 @@ void MeshTest_CheckTopology::Perform (Draw_Interpretor& di)
// check distances between corresponding points // check distances between corresponding points
Standard_Real aSqDefle = BRep_Tool::Tolerance(aEdge); Standard_Real aSqDefle = BRep_Tool::Tolerance(aEdge);
aSqDefle *= aSqDefle; aSqDefle *= aSqDefle;
const TColgp_Array1OfPnt& aPoints1 = aT1->Nodes();
const TColgp_Array1OfPnt& aPoints2 = aT2->Nodes();
Standard_Integer iF1 = aMapF.FindIndex(aFace1); Standard_Integer iF1 = aMapF.FindIndex(aFace1);
Standard_Integer iF2 = aMapF.FindIndex(aFace2); Standard_Integer iF2 = aMapF.FindIndex(aFace2);
Standard_Integer i1 = aNodes1.Lower(); Standard_Integer i1 = aNodes1.Lower();
@@ -121,17 +119,17 @@ void MeshTest_CheckTopology::Perform (Draw_Interpretor& di)
const gp_Trsf &aTrsf1 = aFace1.Location().Transformation(); const gp_Trsf &aTrsf1 = aFace1.Location().Transformation();
const gp_Trsf &aTrsf2 = aFace2.Location().Transformation(); const gp_Trsf &aTrsf2 = aFace2.Location().Transformation();
for (; i1 <= aNodes1.Upper(); i1++, i2++) { for (; i1 <= aNodes1.Upper(); i1++, i2++) {
const gp_Pnt aP1 = aPoints1(aNodes1(i1)).Transformed(aTrsf1); const gp_Pnt aP1 = aT1->Node (aNodes1 (i1)).Transformed (aTrsf1);
const gp_Pnt aP2 = aPoints2(aNodes2(i2)).Transformed(aTrsf2); const gp_Pnt aP2 = aT2->Node (aNodes2 (i2)).Transformed (aTrsf2);
const Standard_Real aSqDist = aP1.SquareDistance(aP2); const Standard_Real aSqDist = aP1.SquareDistance(aP2);
if (aSqDist > aSqDefle) if (aSqDist > aSqDefle)
{ {
myErrors.Append(iF1); myErrors.Append(iF1);
myErrors.Append(i1); myErrors.Append(i1);
myErrors.Append(iF2); myErrors.Append(iF2);
myErrors.Append(i2); myErrors.Append(i2);
myErrorsVal.Append(Sqrt(aSqDist)); myErrorsVal.Append(Sqrt(aSqDist));
} }
} }
} }
} }
@@ -167,10 +165,9 @@ void MeshTest_CheckTopology::Perform (Draw_Interpretor& di)
// check of free links and nodes // check of free links and nodes
Poly_Connect aConn(aT); Poly_Connect aConn(aT);
const Poly_Array1OfTriangle& aTriangles = aT->Triangles();
Standard_Integer nbTri = aT->NbTriangles(), i, j, n[3], t[3]; Standard_Integer nbTri = aT->NbTriangles(), i, j, n[3], t[3];
for (i = 1; i <= nbTri; i++) { for (i = 1; i <= nbTri; i++) {
aTriangles(i).Get(n[0], n[1], n[2]); aT->Triangle (i).Get (n[0], n[1], n[2]);
aUsedNodes.Add (n[0]); aUsedNodes.Add (n[0]);
aUsedNodes.Add (n[1]); aUsedNodes.Add (n[1]);

View File

@@ -303,15 +303,13 @@ static Standard_Integer triarea (Draw_Interpretor& di, int n, const char ** a)
std::cout << "face "<<i<<" has no triangulation"<<std::endl; std::cout << "face "<<i<<" has no triangulation"<<std::endl;
continue; continue;
} }
const Poly_Array1OfTriangle& triangles = aPoly->Triangles(); for (int j = 1; j <= aPoly->NbTriangles(); j++) {
const TColgp_Array1OfPnt& nodes = aPoly->Nodes(); const Poly_Triangle& tri = aPoly->Triangle (j);
for (int j=triangles.Lower(); j <= triangles.Upper(); j++) {
const Poly_Triangle& tri = triangles(j);
int n1, n2, n3; int n1, n2, n3;
tri.Get (n1, n2, n3); tri.Get (n1, n2, n3);
const gp_Pnt& p1 = nodes(n1); const gp_Pnt& p1 = aPoly->Node (n1);
const gp_Pnt& p2 = nodes(n2); const gp_Pnt& p2 = aPoly->Node (n2);
const gp_Pnt& p3 = nodes(n3); const gp_Pnt& p3 = aPoly->Node (n3);
gp_Vec v1(p1, p2); gp_Vec v1(p1, p2);
gp_Vec v2(p1, p3); gp_Vec v2(p1, p3);
double ar = v1.CrossMagnitude(v2); double ar = v1.CrossMagnitude(v2);
@@ -370,7 +368,6 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
const TopoDS_Face& aFace = TopoDS::Face(aShape); const TopoDS_Face& aFace = TopoDS::Face(aShape);
TopLoc_Location aLoc; TopLoc_Location aLoc;
Handle(Poly_Triangulation) aT = BRep_Tool::Triangulation(aFace, aLoc); Handle(Poly_Triangulation) aT = BRep_Tool::Triangulation(aFace, aLoc);
const TColgp_Array1OfPnt& aPoints = aT->Nodes();
const gp_Trsf& trsf = aLoc.Transformation(); const gp_Trsf& trsf = aLoc.Transformation();
TColgp_Array1OfPnt pnts(1,2); TColgp_Array1OfPnt pnts(1,2);
@@ -379,17 +376,16 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
Standard_Integer n1, n2; Standard_Integer n1, n2;
aCheck.GetFreeLink(k, i, n1, n2); aCheck.GetFreeLink(k, i, n1, n2);
di << "{" << n1 << " " << n2 << "} "; di << "{" << n1 << " " << n2 << "} ";
pnts(1) = aPoints(n1).Transformed(trsf); pnts (1) = aT->Node (n1).Transformed (trsf);
pnts(2) = aPoints(n2).Transformed(trsf); pnts (2) = aT->Node (n2).Transformed (trsf);
Handle(Poly_Polygon3D) poly = new Poly_Polygon3D (pnts); Handle(Poly_Polygon3D) poly = new Poly_Polygon3D (pnts);
DrawTrSurf::Set (name, poly); DrawTrSurf::Set (name, poly);
DrawTrSurf::Set (name, pnts(1)); DrawTrSurf::Set (name, pnts(1));
DrawTrSurf::Set (name, pnts(2)); DrawTrSurf::Set (name, pnts(2));
if (aT->HasUVNodes()) if (aT->HasUVNodes())
{ {
const TColgp_Array1OfPnt2d& aPoints2d = aT->UVNodes(); pnts2d (1) = aT->UVNode (n1);
pnts2d(1) = aPoints2d(n1); pnts2d (2) = aT->UVNode (n2);
pnts2d(2) = aPoints2d(n2);
Handle(Poly_Polygon2D) poly2d = new Poly_Polygon2D (pnts2d); Handle(Poly_Polygon2D) poly2d = new Poly_Polygon2D (pnts2d);
DrawTrSurf::Set (name, poly2d); DrawTrSurf::Set (name, poly2d);
DrawTrSurf::Set (name, pnts2d(1)); DrawTrSurf::Set (name, pnts2d(1));
@@ -435,12 +431,11 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
const TopoDS_Face& aFace = TopoDS::Face(aMapF.FindKey(iface)); const TopoDS_Face& aFace = TopoDS::Face(aMapF.FindKey(iface));
TopLoc_Location aLoc; TopLoc_Location aLoc;
Handle(Poly_Triangulation) aT = BRep_Tool::Triangulation(aFace, aLoc); Handle(Poly_Triangulation) aT = BRep_Tool::Triangulation(aFace, aLoc);
const TColgp_Array1OfPnt& aPoints = aT->Nodes();
const gp_Trsf& trsf = aLoc.Transformation(); const gp_Trsf& trsf = aLoc.Transformation();
DrawTrSurf::Set (name, aPoints(inode).Transformed(trsf)); DrawTrSurf::Set (name, aT->Node (inode).Transformed (trsf));
if (aT->HasUVNodes()) if (aT->HasUVNodes())
{ {
DrawTrSurf::Set (name, aT->UVNodes()(inode)); DrawTrSurf::Set (name, aT->UVNode (inode));
} }
di << "{" << iface << " " << inode << "} "; di << "{" << iface << " " << inode << "} ";
@@ -464,12 +459,11 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
const Poly_Triangle &aTri = aT->Triangle(aTriID); const Poly_Triangle &aTri = aT->Triangle(aTriID);
Standard_Integer aN1, aN2, aN3; Standard_Integer aN1, aN2, aN3;
aTri.Get(aN1, aN2, aN3); aTri.Get(aN1, aN2, aN3);
const TColgp_Array1OfPnt& aPoints = aT->Nodes();
TColgp_Array1OfPnt aPoles(1, 4); TColgp_Array1OfPnt aPoles(1, 4);
aPoles(1) = aPoles(4) = aPoints(aN1).Transformed(aTrsf); aPoles (1) = aPoles (4) = aT->Node (aN1).Transformed (aTrsf);
aPoles(2) = aPoints(aN2).Transformed(aTrsf); aPoles (2) = aT->Node (aN2).Transformed (aTrsf);
aPoles(3) = aPoints(aN3).Transformed(aTrsf); aPoles (3) = aT->Node (aN3).Transformed (aTrsf);
TColStd_Array1OfInteger aMults(1, 4); TColStd_Array1OfInteger aMults(1, 4);
aMults(1) = aMults(4) = 2; aMults(1) = aMults(4) = 2;
@@ -488,9 +482,9 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
if (aT->HasUVNodes()) if (aT->HasUVNodes())
{ {
TColgp_Array1OfPnt2d aPoles2d(1, 4); TColgp_Array1OfPnt2d aPoles2d(1, 4);
aPoles2d(1) = aPoles2d(4) = aT->UVNodes()(aN1); aPoles2d (1) = aPoles2d (4) = aT->UVNode (aN1);
aPoles2d(2) = aT->UVNodes()(aN2); aPoles2d (2) = aT->UVNode (aN2);
aPoles2d(3) = aT->UVNodes()(aN3); aPoles2d (3) = aT->UVNode (aN3);
Handle(Geom2d_BSplineCurve) aBS2d = new Geom2d_BSplineCurve(aPoles2d, aKnots, aMults, 1); Handle(Geom2d_BSplineCurve) aBS2d = new Geom2d_BSplineCurve(aPoles2d, aKnots, aMults, 1);
@@ -562,12 +556,11 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
break; break;
} }
const Poly_Array1OfTriangle& aTris = aT->Triangles();
NCollection_Map<BRepMesh_Edge> aFreeEdgeMap; NCollection_Map<BRepMesh_Edge> aFreeEdgeMap;
Standard_Integer aTriNum = aTris.Length(); Standard_Integer aTriNum = aT->NbTriangles();
for ( Standard_Integer aTriIndx = 1; aTriIndx <= aTriNum; aTriIndx++ ) for ( Standard_Integer aTriIndx = 1; aTriIndx <= aTriNum; aTriIndx++ )
{ {
const Poly_Triangle& aTri = aTris(aTriIndx); const Poly_Triangle& aTri = aT->Triangle (aTriIndx);
Standard_Integer aTriNodes[3] = { aTri.Value(1), aTri.Value(2), aTri.Value(3)}; Standard_Integer aTriNodes[3] = { aTri.Value(1), aTri.Value(2), aTri.Value(3)};
for (Standard_Integer j = 1; j <= 3; ++j) for (Standard_Integer j = 1; j <= 3; ++j)
@@ -590,7 +583,6 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
{ {
di << "Not connected mesh inside face " << aFaceId << "\n"; di << "Not connected mesh inside face " << aFaceId << "\n";
const TColgp_Array1OfPnt& aPoints = aT->Nodes();
const gp_Trsf& trsf = aLoc.Transformation(); const gp_Trsf& trsf = aLoc.Transformation();
TColgp_Array1OfPnt pnts(1,2); TColgp_Array1OfPnt pnts(1,2);
@@ -600,17 +592,16 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
{ {
const BRepMesh_Edge& aLink = aMapIt.Key(); const BRepMesh_Edge& aLink = aMapIt.Key();
di << "{" << aLink.FirstNode() << " " << aLink.LastNode() << "} "; di << "{" << aLink.FirstNode() << " " << aLink.LastNode() << "} ";
pnts(1) = aPoints(aLink.FirstNode()).Transformed(trsf); pnts (1) = aT->Node (aLink.FirstNode()).Transformed (trsf);
pnts(2) = aPoints(aLink.LastNode()).Transformed(trsf); pnts (2) = aT->Node (aLink.LastNode()).Transformed (trsf);
Handle(Poly_Polygon3D) poly = new Poly_Polygon3D (pnts); Handle(Poly_Polygon3D) poly = new Poly_Polygon3D (pnts);
DrawTrSurf::Set (name, poly); DrawTrSurf::Set (name, poly);
DrawTrSurf::Set (name, pnts(1)); DrawTrSurf::Set (name, pnts(1));
DrawTrSurf::Set (name, pnts(2)); DrawTrSurf::Set (name, pnts(2));
if (aT->HasUVNodes()) if (aT->HasUVNodes())
{ {
const TColgp_Array1OfPnt2d& aPoints2d = aT->UVNodes(); pnts2d (1) = aT->UVNode (aLink.FirstNode());
pnts2d(1) = aPoints2d(aLink.FirstNode()); pnts2d (2) = aT->UVNode (aLink.LastNode());
pnts2d(2) = aPoints2d(aLink.LastNode());
Handle(Poly_Polygon2D) poly2d = new Poly_Polygon2D (pnts2d); Handle(Poly_Polygon2D) poly2d = new Poly_Polygon2D (pnts2d);
DrawTrSurf::Set (name, poly2d); DrawTrSurf::Set (name, poly2d);
DrawTrSurf::Set (name, pnts2d(1)); DrawTrSurf::Set (name, pnts2d(1));

View File

@@ -17,12 +17,15 @@ Poly_HArray1OfTriangle.hxx
Poly_ListOfTriangulation.hxx Poly_ListOfTriangulation.hxx
Poly_MakeLoops.cxx Poly_MakeLoops.cxx
Poly_MakeLoops.hxx Poly_MakeLoops.hxx
Poly_Mesh.cxx
Poly_Mesh.hxx
Poly_Polygon2D.cxx Poly_Polygon2D.cxx
Poly_Polygon2D.hxx Poly_Polygon2D.hxx
Poly_Polygon3D.cxx Poly_Polygon3D.cxx
Poly_Polygon3D.hxx Poly_Polygon3D.hxx
Poly_PolygonOnTriangulation.cxx Poly_PolygonOnTriangulation.cxx
Poly_PolygonOnTriangulation.hxx Poly_PolygonOnTriangulation.hxx
Poly_Quad.hxx
Poly_Triangle.hxx Poly_Triangle.hxx
Poly_Triangulation.cxx Poly_Triangulation.cxx
Poly_Triangulation.hxx Poly_Triangulation.hxx

View File

@@ -57,23 +57,19 @@ Handle(Poly_Triangulation) Poly::Catenate (const Poly_ListOfTriangulation& lstTr
Standard_Integer i, iNode[3]; Standard_Integer i, iNode[3];
nNodes = 0; nNodes = 0;
nTrian = 0; nTrian = 0;
TColgp_Array1OfPnt& arrNode = aResult->ChangeNodes();
Poly_Array1OfTriangle& arrTrian = aResult->ChangeTriangles();
for (anIter.Init(lstTri); anIter.More(); anIter.Next()) { for (anIter.Init(lstTri); anIter.More(); anIter.Next()) {
const Handle(Poly_Triangulation)& aTri = anIter.Value(); const Handle(Poly_Triangulation)& aTri = anIter.Value();
if (aTri.IsNull() == Standard_False) { 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 nbNodes = aTri->NbNodes();
const Standard_Integer nbTrian = aTri->NbTriangles(); const Standard_Integer nbTrian = aTri->NbTriangles();
for (i = 1; i <= nbNodes; i++) { for (i = 1; i <= nbNodes; i++) {
arrNode.SetValue(i + nNodes, srcNode(i)); aResult->ChangeNode (i + nNodes) = aTri->Node (i);
} }
for (i = 1; i <= nbTrian; i++) { for (i = 1; i <= nbTrian; i++) {
srcTrian(i).Get(iNode[0], iNode[1], iNode[2]); aTri->Triangle (i).Get (iNode[0], iNode[1], iNode[2]);
arrTrian.SetValue(i + nTrian, Poly_Triangle(iNode[0] + nNodes, aResult->ChangeTriangle (i + nTrian) = Poly_Triangle (iNode[0] + nNodes,
iNode[1] + nNodes, iNode[1] + nNodes,
iNode[2] + nNodes)); iNode[2] + nNodes);
} }
nNodes += nbNodes; nNodes += nbNodes;
nTrian += nbTrian; nTrian += nbTrian;
@@ -113,36 +109,33 @@ void Poly::Write(const Handle(Poly_Triangulation)& T,
if (!Compact) OS << "\n3D Nodes :\n"; if (!Compact) OS << "\n3D Nodes :\n";
Standard_Integer i, nbNodes = T->NbNodes(); Standard_Integer i, nbNodes = T->NbNodes();
const TColgp_Array1OfPnt& Nodes = T->Nodes();
for (i = 1; i <= nbNodes; i++) { for (i = 1; i <= nbNodes; i++) {
if (!Compact) OS << std::setw(10) << i << " : "; if (!Compact) OS << std::setw(10) << i << " : ";
if (!Compact) OS << std::setw(17); if (!Compact) OS << std::setw(17);
OS << Nodes(i).X() << " "; OS << T->Node (i).X() << " ";
if (!Compact) OS << std::setw(17); if (!Compact) OS << std::setw(17);
OS << Nodes(i).Y() << " "; OS << T->Node (i).Y() << " ";
if (!Compact) OS << std::setw(17); if (!Compact) OS << std::setw(17);
OS << Nodes(i).Z() << "\n"; OS << T->Node (i).Z() << "\n";
} }
if (T->HasUVNodes()) { if (T->HasUVNodes()) {
if (!Compact) OS << "\nUV Nodes :\n"; if (!Compact) OS << "\nUV Nodes :\n";
const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
for (i = 1; i <= nbNodes; i++) { for (i = 1; i <= nbNodes; i++) {
if (!Compact) OS << std::setw(10) << i << " : "; if (!Compact) OS << std::setw(10) << i << " : ";
if (!Compact) OS << std::setw(17); if (!Compact) OS << std::setw(17);
OS << UVNodes(i).X() << " "; OS << T->UVNode (i).X() << " ";
if (!Compact) OS << std::setw(17); if (!Compact) OS << std::setw(17);
OS << UVNodes(i).Y() << "\n"; OS << T->UVNode (i).Y() << "\n";
} }
} }
if (!Compact) OS << "\nTriangles :\n"; if (!Compact) OS << "\nTriangles :\n";
Standard_Integer nbTriangles = T->NbTriangles(); Standard_Integer nbTriangles = T->NbTriangles();
Standard_Integer n1, n2, n3; 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 << " : "; 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); if (!Compact) OS << std::setw(10);
OS << n1 << " "; OS << n1 << " ";
if (!Compact) OS << std::setw(10); if (!Compact) OS << std::setw(10);
@@ -447,21 +440,19 @@ Handle(Poly_Polygon2D) Poly::ReadPolygon2D(Standard_IStream& IS)
//======================================================================= //=======================================================================
void Poly::ComputeNormals (const Handle(Poly_Triangulation)& theTri) void Poly::ComputeNormals (const Handle(Poly_Triangulation)& theTri)
{ {
const TColgp_Array1OfPnt& aNodes = theTri->Nodes(); const Standard_Integer aNbNodes = theTri->NbNodes();
const Standard_Integer aNbNodes = aNodes.Size();
const Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, aNbNodes * 3); const Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, aNbNodes * 3);
aNormals->Init (0.0f); aNormals->Init (0.0f);
Standard_ShortReal* aNormArr = &aNormals->ChangeFirst(); Standard_ShortReal* aNormArr = &aNormals->ChangeFirst();
Standard_Integer anElem[3] = {0, 0, 0}; Standard_Integer anElem[3] = {0, 0, 0};
const Standard_Real anEps2 = gp::Resolution(); const Standard_Real anEps2 = gp::Resolution();
for (Poly_Array1OfTriangle::Iterator aTriIter (theTri->Triangles()); aTriIter.More(); aTriIter.Next()) for (Standard_Integer iTri = 1; iTri <= theTri->NbTriangles(); iTri++)
{ {
aTriIter.Value().Get (anElem[0], anElem[1], anElem[2]); theTri->Triangle (iTri).Get (anElem[0], anElem[1], anElem[2]);
const gp_Pnt& aNode0 = aNodes.Value (anElem[0]); const gp_Pnt& aNode0 = theTri->Node (anElem[0]);
const gp_Pnt& aNode1 = aNodes.Value (anElem[1]); const gp_Pnt& aNode1 = theTri->Node (anElem[1]);
const gp_Pnt& aNode2 = aNodes.Value (anElem[2]); const gp_Pnt& aNode2 = theTri->Node (anElem[2]);
const gp_XYZ aVec01 = aNode1.XYZ() - aNode0.XYZ(); const gp_XYZ aVec01 = aNode1.XYZ() - aNode0.XYZ();
const gp_XYZ aVec02 = aNode2.XYZ() - aNode0.XYZ(); const gp_XYZ aVec02 = aNode2.XYZ() - aNode0.XYZ();
@@ -489,28 +480,21 @@ void Poly::ComputeNormals (const Handle(Poly_Triangulation)& theTri)
} }
// Normalize all vectors // Normalize all vectors
gp_Dir aNormal;
gp_XYZ aNormXYZ; gp_XYZ aNormXYZ;
for (Standard_Integer aNodeIter = 0; aNodeIter < aNbNodes; ++aNodeIter) for (Standard_Integer aNodeIter = 0; aNodeIter < aNbNodes; ++aNodeIter)
{ {
const Standard_Size anIndex = aNodeIter * 3; const Standard_Size anIndex = aNodeIter * 3;
aNormXYZ.SetCoord (aNormArr[anIndex + 0], aNormArr[anIndex + 1], aNormArr[anIndex + 2]); aNormXYZ.SetCoord (aNormArr[anIndex + 0], aNormArr[anIndex + 1], aNormArr[anIndex + 2]);
const Standard_Real aMod2 = aNormXYZ.SquareModulus(); const Standard_Real aMod2 = aNormXYZ.SquareModulus();
if (aMod2 < anEps2) if (aMod2 > anEps2)
{ aNormal = aNormXYZ;
aNormArr[anIndex + 0] = 0.0f;
aNormArr[anIndex + 1] = 0.0f;
aNormArr[anIndex + 2] = 1.0f;
}
else else
{ aNormal = gp::DZ();
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); // Set normal.
theTri->SetNormal (aNodeIter + 1, aNormXYZ);
}
} }
//======================================================================= //=======================================================================

View File

@@ -51,45 +51,39 @@ Poly_CoherentTriangulation::Poly_CoherentTriangulation
: theAlloc) : theAlloc)
{ {
if (theTriangulation.IsNull() == Standard_False) { 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 nNodes = theTriangulation->NbNodes();
const Standard_Integer nTri = theTriangulation->NbTriangles();
Standard_Integer i; Standard_Integer i;
// Copy the nodes // Copy the nodes
for (i = 0; i < nNodes; i++) { for (i = 0; i < nNodes; i++) {
const Standard_Integer anOldInd = i + arrNodes.Lower(); const Standard_Integer anOldInd = i + 1;
const Standard_Integer aNewInd = SetNode(arrNodes(anOldInd).XYZ(), i); const Standard_Integer aNewInd = SetNode (theTriangulation->Node (anOldInd).XYZ(), i);
Poly_CoherentNode& aCopiedNode = myNodes(aNewInd); Poly_CoherentNode& aCopiedNode = myNodes(aNewInd);
aCopiedNode.SetIndex(anOldInd); aCopiedNode.SetIndex(anOldInd);
} }
// Copy the triangles // Copy the triangles
for (i = 0; i < nTri; i++) { for (i = 1; i <= theTriangulation->NbTriangles(); i++) {
Standard_Integer iNode[3]; 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]) if (iNode[0] != iNode[1] && iNode[1] != iNode[2] && iNode[2] != iNode[0])
AddTriangle (iNode[0]-1, iNode[1]-1, iNode[2]-1); AddTriangle (iNode[0]-1, iNode[1]-1, iNode[2]-1);
} }
// Copy UV coordinates of nodes // Copy UV coordinates of nodes
if (theTriangulation->HasUVNodes()) { if (theTriangulation->HasUVNodes()) {
const TColgp_Array1OfPnt2d& arrNodes2d = theTriangulation->UVNodes();
for (i = 0; i < nNodes; i++) { 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()); myNodes(i).SetUV(anUV.X(), anUV.Y());
} }
} }
// Copy the normals at nodes // Copy the normals at nodes
if (theTriangulation->HasNormals()) { if (theTriangulation->HasNormals()) {
const TShort_Array1OfShortReal& arrNorm = theTriangulation->Normals();
for (i = 0; i < nNodes; i++) { for (i = 0; i < nNodes; i++) {
const gp_XYZ aNormal (arrNorm(3 * i + 0 + arrNorm.Lower()), const Vec3f& anXYZ = theTriangulation->Normal (i + 1);
arrNorm(3 * i + 1 + arrNorm.Lower()), gp_XYZ aNormal (anXYZ.x(), anXYZ.y(), anXYZ.z());
arrNorm(3 * i + 2 + arrNorm.Lower())); myNodes (i).SetNormal (aNormal);
myNodes(i).SetNormal(aNormal);
} }
} }
myDeflection = theTriangulation->Deflection(); myDeflection = theTriangulation->Deflection();
@@ -121,17 +115,10 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const
const Standard_Integer nTriangles = NTriangles(); const Standard_Integer nTriangles = NTriangles();
if (nNodes > 0 && nTriangles > 0) { if (nNodes > 0 && nTriangles > 0) {
aResult = new Poly_Triangulation(nNodes, nTriangles, Standard_True); 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; NCollection_Vector<Standard_Integer> vecNodeId;
Standard_Integer i, aCount(0); Standard_Integer i, aCount(0);
Standard_Boolean hasUV (Standard_False); Standard_Boolean hasUV (Standard_False);
Standard_Boolean hasNormals (Standard_False);
// Copy the nodes (3D and 2D coordinates) // Copy the nodes (3D and 2D coordinates)
for (i = 0; i < myNodes.Length(); i++) { for (i = 0; i < myNodes.Length(); i++) {
@@ -140,19 +127,19 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const
vecNodeId.SetValue(i, 0); vecNodeId.SetValue(i, 0);
else { else {
const gp_XYZ aNormal = aNode.GetNormal(); const gp_XYZ aNormal = aNode.GetNormal();
arrNormal[3 * aCount + 0] = static_cast<Standard_ShortReal>(aNormal.X()); if (aNormal.SquareModulus() > Precision::Confusion()) {
arrNormal[3 * aCount + 1] = static_cast<Standard_ShortReal>(aNormal.Y()); aResult->SetNormal (aCount, static_cast<Standard_ShortReal>(aNormal.X()),
arrNormal[3 * aCount + 2] = static_cast<Standard_ShortReal>(aNormal.Z()); static_cast<Standard_ShortReal>(aNormal.Y()),
static_cast<Standard_ShortReal>(aNormal.Z()));
}
vecNodeId.SetValue(i, ++aCount); vecNodeId.SetValue(i, ++aCount);
arrNodes.SetValue(aCount, aNode); aResult->ChangeNode (aCount) = aNode;
arrNodesUV.SetValue(aCount, gp_Pnt2d(aNode.GetU(), aNode.GetV())); aResult->ChangeUVNode (aCount) = gp_Pnt2d (aNode.GetU(), aNode.GetV());
if (aNode.GetU()*aNode.GetU() + aNode.GetV()*aNode.GetV() > if (aNode.GetU()*aNode.GetU() + aNode.GetV()*aNode.GetV() >
Precision::Confusion()) Precision::Confusion())
hasUV = Standard_True; hasUV = Standard_True;
if (aNormal.SquareModulus() > Precision::Confusion())
hasNormals = Standard_True;
} }
} }
if (hasUV == Standard_False) if (hasUV == Standard_False)
@@ -164,14 +151,11 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const
for (; anIterT.More(); anIterT.Next()) { for (; anIterT.More(); anIterT.Next()) {
const Poly_CoherentTriangle& aTri = anIterT.Value(); const Poly_CoherentTriangle& aTri = anIterT.Value();
if (aTri.IsEmpty() == Standard_False) { if (aTri.IsEmpty() == Standard_False) {
const Poly_Triangle aPolyTriangle (vecNodeId(aTri.Node(0)), aResult->ChangeTriangle (++aCount) = Poly_Triangle (vecNodeId (aTri.Node (0)),
vecNodeId(aTri.Node(1)), vecNodeId (aTri.Node (1)),
vecNodeId(aTri.Node(2))); vecNodeId (aTri.Node (2)));;
arrTriangle.SetValue(++aCount, aPolyTriangle);
} }
} }
if (hasNormals)
aResult->SetNormals (harrNormal);
aResult->Deflection(myDeflection); aResult->Deflection(myDeflection);
} }

View File

@@ -226,8 +226,7 @@ void Poly_Connect::Initialize(const Standard_Integer N)
if (mymore) if (mymore)
{ {
Standard_Integer i, no[3]; Standard_Integer i, no[3];
const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles(); myTriangulation->Triangle (myfirst).Get (no[0], no[1], no[2]);
triangles(myfirst).Get(no[0], no[1], no[2]);
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
if (no[i] == mynode) break; if (no[i] == mynode) break;
myothernode = no[(i+2)%3]; myothernode = no[(i+2)%3];
@@ -244,12 +243,11 @@ void Poly_Connect::Next()
Standard_Integer i, j; Standard_Integer i, j;
Standard_Integer n[3]; Standard_Integer n[3];
Standard_Integer t[3]; Standard_Integer t[3];
const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
Triangles(mytr, t[0], t[1], t[2]); Triangles(mytr, t[0], t[1], t[2]);
if (mysense) { if (mysense) {
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
if (t[i] != 0) { 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++) { for (j = 0; j < 3; j++) {
if ((n[j] == mynode) && (n[(j+1)%3] == myothernode)) { if ((n[j] == mynode) && (n[(j+1)%3] == myothernode)) {
mytr = t[i]; mytr = t[i];
@@ -261,7 +259,7 @@ void Poly_Connect::Next()
} }
} }
// sinon, depart vers la gauche. // 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++) for (i = 0; i < 3; i++)
if (n[i] == mynode) break; if (n[i] == mynode) break;
myothernode = n[(i+1)%3]; myothernode = n[(i+1)%3];
@@ -272,7 +270,7 @@ void Poly_Connect::Next()
if (!mysense) { if (!mysense) {
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
if (t[i] != 0) { 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++) { for (j = 0; j < 3; j++) {
if ((n[j] == mynode) && (n[(j+2)%3] == myothernode)) { if ((n[j] == mynode) && (n[(j+2)%3] == myothernode)) {
mytr = t[i]; mytr = t[i];

66
src/Poly/Poly_Mesh.cxx Normal file
View File

@@ -0,0 +1,66 @@
// Copyright (c) 2015 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.
#include <Poly_Mesh.hxx>
#include <Standard_DefineHandle.hxx>
IMPLEMENT_STANDARD_RTTIEXT (Poly_Mesh, Poly_Triangulation)
//=======================================================================
//function : Poly_Mesh
//purpose :
//=======================================================================
Poly_Mesh::Poly_Mesh () : Poly_Triangulation (0, 0, Standard_False)
{
}
//=======================================================================
//function : Poly_Mesh
//purpose :
//=======================================================================
Poly_Mesh::Poly_Mesh (const Standard_Integer theNbNodes,
const Standard_Integer theNbTriangles,
const Standard_Integer theNbQuads,
const Standard_Boolean theHasUVNodes,
const Standard_Boolean theHasNormals)
: Poly_Triangulation (theNbNodes, theNbTriangles, theHasUVNodes, theHasNormals)
{
if (theNbQuads > 0)
myQuads.Resize (1, theNbQuads, Standard_False);
}
//=======================================================================
//function : Poly_Mesh
//purpose :
//=======================================================================
Poly_Mesh::Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation)
: Poly_Triangulation ( theTriangulation )
{
// No quadrangles.
}
//=======================================================================
//function : Copy
//purpose :
//=======================================================================
Handle(Poly_Triangulation) Poly_Mesh::Copy() const
{
Handle(Poly_Triangulation) aCopiedTriangulation = Poly_Triangulation::Copy();
Handle(Poly_Mesh) aCopiedMesh = new Poly_Mesh (aCopiedTriangulation);
aCopiedMesh->myQuads = myQuads;
return aCopiedMesh;
}

92
src/Poly/Poly_Mesh.hxx Normal file
View File

@@ -0,0 +1,92 @@
// Copyright (c) 2015 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.
#ifndef _Poly_Mesh_HeaderFile
#define _Poly_Mesh_HeaderFile
#include <Poly_Quad.hxx>
#include <Poly_Triangulation.hxx>
//! This class is extension for Poly_Triangulation.
//! It allows to store mesh with quad polygons.
class Poly_Mesh : public Poly_Triangulation
{
public:
//! Constructs an empty mesh.
Standard_EXPORT Poly_Mesh();
//! Constructs a mesh.
//! @param theNbNodes defines the number of nodes.
//! @param theNbTriangles defines the number of triangles.
//! @param theNbQuads defines the number of quadrangles.
//! @param theHasUVNodes indicates whether 2D nodes will be associated with
//! 3D ones, (i.e. to enable a 2D representation).
//! @param theHasNormals defines allocation of normals for the nodes.
Standard_EXPORT Poly_Mesh(const Standard_Integer theNbNodes,
const Standard_Integer theNbTriangles,
const Standard_Integer theNbQuads,
const Standard_Boolean theHasUVNodes = Standard_False,
const Standard_Boolean theHasNormals = Standard_False);
//! Constructs a mesh from existing triangulation.
//! @param theTriangulation source triangulation.
Standard_EXPORT Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation);
//! Creates full copy of current mesh
Standard_EXPORT virtual Handle(Poly_Triangulation) Copy() const Standard_OVERRIDE;
//! Sets a quadrangle to the mesh.
//! @param theIndex is an index of the quadrangle.
//! @param theN1 index of the first node.
//! @param theN2 index of the second node.
//! @param theN3 index of the third node.
//! @param theN4 index of the fourth node.
void SetQuad (const Standard_Integer theIndex,
const Standard_Integer theN1,
const Standard_Integer theN2,
const Standard_Integer theN3,
const Standard_Integer theN4)
{
myQuads.SetValue (theIndex, Poly_Quad (theN1, theN2, theN3, theN4));
}
//! @return the number of quadrangles in the mesh.
Standard_Integer NbQuads() const {
return myQuads.Size();
}
//! @return a quadrangle at the given index.
const Poly_Quad& Quad (const Standard_Integer theIndex) const {
return myQuads.Value (theIndex);
}
//! @return a reference to a quadrangle at the given index.
Poly_Quad& ChangeQuad (const Standard_Integer theIndex) {
return myQuads.ChangeValue (theIndex);
}
protected:
NCollection_Array1<Poly_Quad> myQuads;
public:
DEFINE_STANDARD_RTTIEXT(Poly_Mesh, Poly_Triangulation)
};
DEFINE_STANDARD_HANDLE(Poly_Mesh, Poly_Triangulation)
#endif // _Poly_Mesh_HeaderFile

View File

@@ -15,6 +15,7 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <Poly_PolygonOnTriangulation.hxx> #include <Poly_PolygonOnTriangulation.hxx>
#include <Standard_NullObject.hxx>
#include <Standard_Dump.hxx> #include <Standard_Dump.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Poly_PolygonOnTriangulation,Standard_Transient) IMPLEMENT_STANDARD_RTTIEXT(Poly_PolygonOnTriangulation,Standard_Transient)
@@ -78,6 +79,58 @@ Handle(Poly_PolygonOnTriangulation) Poly_PolygonOnTriangulation::Copy() const
return aCopy; return aCopy;
} }
//=======================================================================
//function : Node
//purpose :
//=======================================================================
Standard_Integer Poly_PolygonOnTriangulation::Node (const Standard_Integer theIndex) const
{
Standard_OutOfRange_Raise_if ((theIndex < 1 || theIndex > myNodes.Length()),
"Poly_PolygonOnTriangulation::Node : index out of range");
return myNodes.Value (theIndex);
}
//=======================================================================
//function : SetNode
//purpose :
//=======================================================================
void Poly_PolygonOnTriangulation::SetNode (const Standard_Integer theIndex, const Standard_Integer theNode)
{
Standard_OutOfRange_Raise_if ((theIndex < 1 || theIndex > myNodes.Length()),
"Poly_PolygonOnTriangulation::SetNode : index out of range");
myNodes.SetValue (theIndex, theNode);
}
//=======================================================================
//function : Parameter
//purpose :
//=======================================================================
Standard_Real Poly_PolygonOnTriangulation::Parameter (const Standard_Integer theIndex) const
{
Standard_NullObject_Raise_if (myParameters.IsNull(),
"Poly_PolygonOnTriangulation::Parameter : parameters is NULL");
Standard_OutOfRange_Raise_if ((theIndex < 1 || theIndex > myParameters->Length()),
"Poly_PolygonOnTriangulation::Parameter : index out of range");
return myParameters->Value (theIndex);
}
//=======================================================================
//function : SetParameter
//purpose :
//=======================================================================
void Poly_PolygonOnTriangulation::SetParameter (const Standard_Integer theIndex, const Standard_Real theValue)
{
Standard_NullObject_Raise_if (myParameters.IsNull(),
"Poly_PolygonOnTriangulation::Parameter : parameters is NULL");
Standard_OutOfRange_Raise_if ((theIndex < 1 || theIndex > myParameters->Length()),
"Poly_PolygonOnTriangulation::Parameter : index out of range");
myParameters->SetValue (theIndex, theValue);
}
//======================================================================= //=======================================================================
//function : SetParameters //function : SetParameters
//purpose : //purpose :

View File

@@ -84,8 +84,13 @@ public:
//! triangulation of a shape. //! triangulation of a shape.
const TColStd_Array1OfInteger& Nodes() const { return myNodes; } const TColStd_Array1OfInteger& Nodes() const { return myNodes; }
//! Returns the table of nodes for this polygon for modification. //! Return node at the given index.
TColStd_Array1OfInteger& ChangeNodes() { return myNodes; } //! Raises exception if theIndex is less than NodesLowerIndex or bigger than NodesUpperIndex.
Standard_EXPORT Standard_Integer Node (const Standard_Integer theIndex) const;
//! Sets node at the given index.
//! Raises exception if theIndex is less than NodesLowerIndex or bigger than NodesUpperIndex.
Standard_EXPORT void SetNode (const Standard_Integer theIndex, const Standard_Integer theNode);
//! Returns true if parameters are associated with the nodes in this polygon. //! Returns true if parameters are associated with the nodes in this polygon.
Standard_Boolean HasParameters() const { return !myParameters.IsNull(); } Standard_Boolean HasParameters() const { return !myParameters.IsNull(); }
@@ -96,9 +101,16 @@ public:
//! are associated with the nodes in this polygon. //! are associated with the nodes in this polygon.
const Handle(TColStd_HArray1OfReal)& Parameters() const { return myParameters; } const Handle(TColStd_HArray1OfReal)& Parameters() const { return myParameters; }
//! Returns the table of the parameters associated with each node in this polygon. //! Return parameter at the given index.
//! Warning! HasParameters() should be called beforehand to check if parameters array is allocated. //! Raises Standard_NullObject exception if parameters has not been initialized.
TColStd_Array1OfReal& ChangeParameters() { return myParameters->ChangeArray1(); } //! Raises Standard_OutOfRange exception if theIndex is less than ParametersLowerIndex or bigger than ParametersUpperIndex.
Standard_EXPORT Standard_Real Parameter (const Standard_Integer theIndex) const;
//! Sets parameter at the given index.
//! Raises Standard_NullObject exception if parameters has not been initialized.
//! Raises Standard_OutOfRange exception if theIndex is less than ParametersLowerIndex or bigger than ParametersUpperIndex.
Standard_EXPORT void SetParameter (const Standard_Integer theIndex, const Standard_Real theValue);
//! Sets the table of the parameters associated with each node in this polygon. //! 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. //! Raises exception if array size doesn't much number of polygon nodes.

73
src/Poly/Poly_Quad.hxx Normal file
View File

@@ -0,0 +1,73 @@
// Copyright (c) 2015 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.
#ifndef _Poly_Quad_HeaderFile
#define _Poly_Quad_HeaderFile
#include <Standard_DefineAlloc.hxx>
#include <Standard_Integer.hxx>
#include <Poly_Triangle.hxx>
//! Describes a quadric element of a mesh.
class Poly_Quad : public Poly_Triangle
{
public:
DEFINE_STANDARD_ALLOC
//! Constructs an empty Quad object.
Poly_Quad():myNode4 (0) {
myNodes[0] = myNodes[1] = myNodes[2] = 0;
}
//! Constructs a quadric element.
Poly_Quad (const Standard_Integer theNode1,
const Standard_Integer theNode2,
const Standard_Integer theNode3,
const Standard_Integer theNode4)
{
Set (theNode1, theNode2, theNode3, theNode4);
}
//! Sets indices of nodes.
void Set (const Standard_Integer theNode1,
const Standard_Integer theNode2,
const Standard_Integer theNode3,
const Standard_Integer theNode4)
{
myNodes[0] = theNode1;
myNodes[1] = theNode2;
myNodes[2] = theNode3;
myNode4 = theNode4;
}
//! Returns indices of nodes of the quadric element.
void Get (Standard_Integer& theNode1,
Standard_Integer& theNode2,
Standard_Integer& theNode3,
Standard_Integer& theNode4) const
{
theNode1 = myNodes[0];
theNode2 = myNodes[1];
theNode3 = myNodes[2];
theNode4 = myNode4;
}
protected:
Standard_Integer myNode4;
};
#endif // _Poly_Quad_HeaderFile

View File

@@ -89,7 +89,7 @@ public:
Standard_Integer& operator() (const Standard_Integer Index) { return ChangeValue(Index); } Standard_Integer& operator() (const Standard_Integer Index) { return ChangeValue(Index); }
private: protected:
Standard_Integer myNodes[3]; Standard_Integer myNodes[3];

View File

@@ -18,9 +18,7 @@
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
#include <Poly_Triangle.hxx> #include <Poly_Triangle.hxx>
#include <Standard_DomainError.hxx>
#include <Standard_Dump.hxx> #include <Standard_Dump.hxx>
#include <Standard_NullObject.hxx>
#include <Standard_Type.hxx> #include <Standard_Type.hxx>
IMPLEMENT_STANDARD_RTTIEXT (Poly_Triangulation, Standard_Transient) IMPLEMENT_STANDARD_RTTIEXT (Poly_Triangulation, Standard_Transient)
@@ -31,7 +29,8 @@ IMPLEMENT_STANDARD_RTTIEXT (Poly_Triangulation, Standard_Transient)
//======================================================================= //=======================================================================
Poly_Triangulation::Poly_Triangulation() Poly_Triangulation::Poly_Triangulation()
: myCachedMinMax (NULL), : myCachedMinMax (NULL),
myDeflection (0) myDeflection (0),
myHasUVNodes (Standard_False)
{ {
} }
@@ -39,36 +38,40 @@ Poly_Triangulation::Poly_Triangulation()
//function : Poly_Triangulation //function : Poly_Triangulation
//purpose : //purpose :
//======================================================================= //=======================================================================
Poly_Triangulation::Poly_Triangulation(const Standard_Integer theNbNodes, Poly_Triangulation::Poly_Triangulation (const Standard_Integer theNbNodes,
const Standard_Integer theNbTriangles, const Standard_Integer theNbTriangles,
const Standard_Boolean theHasUVNodes) const Standard_Boolean theHasUVNodes)
: myCachedMinMax (NULL), : myCachedMinMax (NULL),
myDeflection (0), myDeflection (0),
myNodes (1, theNbNodes), myHasUVNodes (theHasUVNodes)
myTriangles (1, theNbTriangles)
{ {
if (theHasUVNodes) myUVNodes = new TColgp_HArray1OfPnt2d(1, theNbNodes); if (theNbNodes > 0)
{
myNodes.Resize (1, theNbNodes, Standard_False);
if (myHasUVNodes)
{
myUVNodes.Resize (1, theNbNodes, Standard_False);
}
}
if (theNbTriangles > 0)
{
myTriangles.Resize (1, theNbTriangles, Standard_False);
}
} }
//======================================================================= //=======================================================================
//function : Poly_Triangulation //function : Poly_Triangulation
//purpose : //purpose :
//======================================================================= //=======================================================================
Poly_Triangulation::Poly_Triangulation(const Standard_Integer theNbNodes, Poly_Triangulation::Poly_Triangulation (const Standard_Integer theNbNodes,
const Standard_Integer theNbTriangles, const Standard_Integer theNbTriangles,
const Standard_Boolean theHasUVNodes, const Standard_Boolean theHasUVNodes,
const Standard_Boolean theHasNormals) const Standard_Boolean theHasNormals)
: myDeflection(0), : Poly_Triangulation(theNbNodes, theNbTriangles, theHasUVNodes)
myNodes (1, theNbNodes),
myTriangles (1, theNbTriangles)
{ {
if (theHasUVNodes)
{
myUVNodes = new TColgp_HArray1OfPnt2d(1, theNbNodes);
}
if (theHasNormals) if (theHasNormals)
{ {
myNormals = new TShort_HArray1OfShortReal(1, theNbNodes * 3); myNormals.Resize (1, theNbNodes, Standard_False);
} }
} }
@@ -76,14 +79,16 @@ Poly_Triangulation::Poly_Triangulation(const Standard_Integer theNbNodes,
//function : Poly_Triangulation //function : Poly_Triangulation
//purpose : //purpose :
//======================================================================= //=======================================================================
Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& theNodes, Poly_Triangulation::Poly_Triangulation (const TColgp_Array1OfPnt& theNodes,
const Poly_Array1OfTriangle& theTriangles) const Poly_Array1OfTriangle& theTriangles)
: myCachedMinMax (NULL), : myCachedMinMax (NULL),
myDeflection (0), myDeflection (0),
myNodes (1, theNodes.Length()), myHasUVNodes (Standard_False)
myTriangles (1, theTriangles.Length())
{ {
myNodes.Resize (1, theNodes.Length(), Standard_False);
myNodes = theNodes; myNodes = theNodes;
myTriangles.Resize (1, theTriangles.Length(), Standard_False);
myTriangles = theTriangles; myTriangles = theTriangles;
} }
@@ -92,18 +97,23 @@ Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& theNodes,
//purpose : //purpose :
//======================================================================= //=======================================================================
Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& theNodes, Poly_Triangulation::Poly_Triangulation (const TColgp_Array1OfPnt& theNodes,
const TColgp_Array1OfPnt2d& theUVNodes, const TColgp_Array1OfPnt2d& theUVNodes,
const Poly_Array1OfTriangle& theTriangles) const Poly_Array1OfTriangle& theTriangles)
: myCachedMinMax (NULL), : myCachedMinMax (NULL),
myDeflection (0), myDeflection (0),
myNodes (1, theNodes.Length()), myHasUVNodes (theNodes.Length() == theUVNodes.Length())
myTriangles (1, theTriangles.Length())
{ {
myNodes.Resize (1, theNodes.Length(), Standard_False);
myNodes = theNodes; myNodes = theNodes;
myTriangles.Resize (1, theTriangles.Length(), Standard_False);
myTriangles = theTriangles; myTriangles = theTriangles;
myUVNodes = new TColgp_HArray1OfPnt2d (1, theNodes.Length());
myUVNodes->ChangeArray1() = theUVNodes; if (myHasUVNodes) {
myUVNodes.Resize (1, theNodes.Length(), Standard_False);
myUVNodes = theUVNodes;
}
} }
//======================================================================= //=======================================================================
@@ -122,7 +132,20 @@ Poly_Triangulation::~Poly_Triangulation()
Handle(Poly_Triangulation) Poly_Triangulation::Copy() const Handle(Poly_Triangulation) Poly_Triangulation::Copy() const
{ {
return new Poly_Triangulation (this); Handle(Poly_Triangulation) aCopy = new Poly_Triangulation (NbNodes(), NbTriangles(), HasUVNodes());
aCopy->myNodes = myNodes;
aCopy->myTriangles = myTriangles;
aCopy->myDeflection = myDeflection;
if (HasUVNodes())
aCopy->myUVNodes = myUVNodes;
if (HasNormals()) {
aCopy->myNormals.Resize (1, myNodes.Size(), Standard_False);
aCopy->myNormals = myNormals;
}
return aCopy;
} }
//======================================================================= //=======================================================================
@@ -132,29 +155,26 @@ Handle(Poly_Triangulation) Poly_Triangulation::Copy() const
Poly_Triangulation::Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation) Poly_Triangulation::Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation)
: myCachedMinMax(NULL), : myCachedMinMax(NULL),
myDeflection(theTriangulation->myDeflection), myDeflection (theTriangulation->myDeflection),
myNodes(theTriangulation->Nodes()), myHasUVNodes (theTriangulation->myHasUVNodes)
myTriangles(theTriangulation->Triangles())
{ {
SetCachedMinMax (theTriangulation->CachedMinMax()); SetCachedMinMax (theTriangulation->CachedMinMax());
if (theTriangulation->HasUVNodes())
{ // Re-allocate the arrays.
myUVNodes = new TColgp_HArray1OfPnt2d(theTriangulation->myUVNodes->Array1()); myNodes.Resize (1, theTriangulation->NbNodes(), Standard_False);
} if (myHasUVNodes)
myUVNodes.Resize (1, theTriangulation->NbNodes(), Standard_False);
myTriangles.Resize (1, theTriangulation->NbTriangles(), Standard_False);
if (theTriangulation->HasNormals()) if (theTriangulation->HasNormals())
{ myNormals.Resize (1, theTriangulation->NbNodes(), Standard_False);
myNormals = new TShort_HArray1OfShortReal(theTriangulation->myNormals->Array1());
}
}
//======================================================================= // Copy data.
//function : Deflection myNodes = theTriangulation->myNodes;
//purpose : if (myHasUVNodes)
//======================================================================= myUVNodes = theTriangulation->myUVNodes;
myTriangles = theTriangulation->myTriangles;
void Poly_Triangulation::Deflection(const Standard_Real theDeflection) if (theTriangulation->HasNormals())
{ myNormals = theTriangulation->myNormals;
myDeflection = theDeflection;
} }
//======================================================================= //=======================================================================
@@ -164,91 +184,8 @@ void Poly_Triangulation::Deflection(const Standard_Real theDeflection)
void Poly_Triangulation::RemoveUVNodes() void Poly_Triangulation::RemoveUVNodes()
{ {
myUVNodes.Nullify(); myUVNodes = TColgp_Array1OfPnt2d();
} myHasUVNodes = Standard_False;
//=======================================================================
//function : Node
//purpose :
//=======================================================================
const gp_Pnt& Poly_Triangulation::Node (const Standard_Integer theIndex) const
{
if (theIndex < 1 || theIndex > myNodes.Size())
{
throw Standard_OutOfRange ("Poly_Triangulation::Node : index out of range");
}
return myNodes.Value (theIndex);
}
//=======================================================================
//function : ChangeNode
//purpose :
//=======================================================================
gp_Pnt& Poly_Triangulation::ChangeNode (const Standard_Integer theIndex)
{
if (theIndex < 1 || theIndex > myNodes.Size())
{
throw Standard_OutOfRange ("Poly_Triangulation::ChangeNode : index out of range");
}
return myNodes.ChangeValue (theIndex);
}
//=======================================================================
//function : UVNode
//purpose :
//=======================================================================
const gp_Pnt2d& Poly_Triangulation::UVNode (const Standard_Integer theIndex) const
{
if (myUVNodes.IsNull() || theIndex < 1 || theIndex > myUVNodes->Size())
{
throw Standard_OutOfRange ("Poly_Triangulation::UVNode : index out of range");
}
return myUVNodes->Value (theIndex);
}
//=======================================================================
//function : ChangeUVNode
//purpose :
//=======================================================================
gp_Pnt2d& Poly_Triangulation::ChangeUVNode (const Standard_Integer theIndex)
{
if (myUVNodes.IsNull() || theIndex < 1 || theIndex > myUVNodes->Size())
{
throw Standard_OutOfRange ("Poly_Triangulation::ChangeUVNode : index out of range");
}
return myUVNodes->ChangeValue (theIndex);
}
//=======================================================================
//function : Triangle
//purpose :
//=======================================================================
const Poly_Triangle& Poly_Triangulation::Triangle (const Standard_Integer theIndex) const
{
if (theIndex < 1 || theIndex > myTriangles.Size())
{
throw Standard_OutOfRange ("Poly_Triangulation::Triangle : index out of range");
}
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);
} }
//======================================================================= //=======================================================================
@@ -263,94 +200,48 @@ void Poly_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& th
throw Standard_DomainError("Poly_Triangulation::SetNormals : wrong length"); throw Standard_DomainError("Poly_Triangulation::SetNormals : wrong length");
} }
myNormals = theNormals; Standard_Integer anArrayLower = theNormals->Lower();
} for (Standard_Integer anIndex = 1; anIndex >= NbNodes(); anIndex--)
//=======================================================================
//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())
{ {
throw Standard_NullObject ("Poly_Triangulation::SetNormal : empty array or index out of range"); Standard_Integer anArrayInd = anArrayLower + (anIndex - 1) * 3;
SetNormal (anIndex, theNormals->Value(anArrayInd),
theNormals->Value(anArrayInd + 1),
theNormals->Value(anArrayInd + 2));
} }
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 // function : ResizeNodes
//purpose : // purpose :
//======================================================================= // =======================================================================
gp_Dir Poly_Triangulation::Normal (const Standard_Integer theIndex) const void Poly_Triangulation::ResizeNodes (const Standard_Integer theNbNodes)
{ {
if (myNormals.IsNull() || theIndex < 1 || theIndex > myNodes.Size()) if (theNbNodes > 0) {
{ myNodes.Resize (1, theNbNodes, Standard_True);
throw Standard_NullObject ("Poly_Triangulation::Normal : empty array or index out of range"); if (myHasUVNodes)
myUVNodes.Resize (1, theNbNodes, Standard_True);
if (HasNormals())
myNormals.Resize (1, theNbNodes, Standard_True);
} }
}
gp_Dir N(myNormals->Value(theIndex * 3 - 2), // =======================================================================
myNormals->Value(theIndex * 3 - 1), // function : ResizeTriangles
myNormals->Value(theIndex * 3)); // purpose :
// =======================================================================
return N; void Poly_Triangulation::ResizeTriangles (const Standard_Integer theNbTriangles)
{
if (theNbTriangles > 0)
myTriangles.Resize (1, theNbTriangles, Standard_True);
} }
// ======================================================================= // =======================================================================
// function : DumpJson // function : DumpJson
// purpose : // purpose :
// ======================================================================= // =======================================================================
void Poly_Triangulation::DumpJson (Standard_OStream& theOStream, Standard_Integer) const void Poly_Triangulation::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
{ {
OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
@@ -358,10 +249,10 @@ void Poly_Triangulation::DumpJson (Standard_OStream& theOStream, Standard_Intege
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDeflection) OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDeflection)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myNodes.Size()) OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myNodes.Size())
if (!myUVNodes.IsNull()) if (!myUVNodes.IsEmpty())
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUVNodes->Size()) OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUVNodes.Size())
if (!myNormals.IsNull()) if (!myNormals.IsEmpty())
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myNormals->Size()) OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myNormals.Size())
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myTriangles.Size()) OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myTriangles.Size())
} }

View File

@@ -20,48 +20,26 @@
#include <Bnd_Box.hxx> #include <Bnd_Box.hxx>
#include <Standard.hxx> #include <Standard.hxx>
#include <Standard_DefineHandle.hxx> #include <Standard_DefineHandle.hxx>
#include <Standard_Real.hxx>
#include <Standard_Integer.hxx>
#include <TColgp_Array1OfPnt.hxx> #include <TColgp_Array1OfPnt.hxx>
#include <TColgp_HArray1OfPnt2d.hxx> #include <TColgp_HArray1OfPnt2d.hxx>
#include <Poly_Array1OfTriangle.hxx> #include <Poly_Array1OfTriangle.hxx>
#include <TShort_HArray1OfShortReal.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;
typedef NCollection_Vec3 <Standard_ShortReal> Vec3f;
class Poly_Triangulation; //! Provides a triangulation for a surface, a set of surfaces, or more generally a shape.
DEFINE_STANDARD_HANDLE(Poly_Triangulation, Standard_Transient) //! A triangulation consists of an approximate representation of the actual shape, using a collection of points and triangles.
//! The points are located on the surface. The edges of the triangles connect adjacent points with a
//! Provides a triangulation for a surface, a set of surfaces, or
//! more generally a shape.
//! A triangulation consists of an approximate representation
//! of the actual shape, using a collection of points and
//! triangles. The points are located on the surface. The
//! edges of the triangles connect adjacent points with a
//! straight line that approximates the true curve on the surface. //! straight line that approximates the true curve on the surface.
//! A triangulation comprises: //! A triangulation comprises:
//! - A table of 3D nodes (3D points on the surface). //! - A table of 3D nodes (3D points on the surface).
//! - A table of triangles. Each triangle (Poly_Triangle //! - A table of triangles. Each triangle (Poly_Triangle object) comprises a triplet of indices in the table of 3D
//! object) comprises a triplet of indices in the table of 3D //! nodes specific to the triangulation.
//! nodes specific to the triangulation. //! - A table of 2D nodes (2D points), parallel to the table of 3D nodes. This table is optional.
//! - A table of 2D nodes (2D points), parallel to the table of //! If it exists, the coordinates of a 2D point are the (u, v) parameters of the corresponding 3D point on the surface approximated by the triangulation.
//! 3D nodes. This table is optional. If it exists, the //! - A deflection (optional), which maximizes the distance from a point on the surface to the corresponding point on its approximate triangulation.
//! coordinates of a 2D point are the (u, v) parameters //! In many cases, algorithms do not need to work with the exact representation of a surface.
//! of the corresponding 3D point on the surface //! A triangular representation induces simpler and more robust adjusting, faster performances, and the results are as good.
//! approximated by the triangulation.
//! - A deflection (optional), which maximizes the distance
//! from a point on the surface to the corresponding point
//! on its approximate triangulation.
//! In many cases, algorithms do not need to work with the
//! exact representation of a surface. A triangular
//! representation induces simpler and more robust adjusting,
//! faster performances, and the results are as good.
//! This is a Transient class.
class Poly_Triangulation : public Standard_Transient class Poly_Triangulation : public Standard_Transient
{ {
@@ -78,7 +56,7 @@ public:
//! triangles. Here the UVNodes flag indicates whether //! triangles. Here the UVNodes flag indicates whether
//! 2D nodes will be associated with 3D ones, (i.e. to //! 2D nodes will be associated with 3D ones, (i.e. to
//! enable a 2D representation). //! enable a 2D representation).
Standard_EXPORT Poly_Triangulation(const Standard_Integer nbNodes, const Standard_Integer nbTriangles, const Standard_Boolean UVNodes); Standard_EXPORT Poly_Triangulation(const Standard_Integer nbNodes, const Standard_Integer nbTriangles, const Standard_Boolean hasUVNodes);
//! Constructs a triangulation from a set of triangles. //! Constructs a triangulation from a set of triangles.
//! The triangulation is initialized without a triangle or a node, //! The triangulation is initialized without a triangle or a node,
@@ -88,7 +66,7 @@ public:
//! Here the hasNormals flag indicates whether normals will be given and associated with nodes. //! Here the hasNormals flag indicates whether normals will be given and associated with nodes.
Standard_EXPORT Poly_Triangulation(const Standard_Integer nbNodes, Standard_EXPORT Poly_Triangulation(const Standard_Integer nbNodes,
const Standard_Integer nbTriangles, const Standard_Integer nbTriangles,
const Standard_Boolean UVNodes, const Standard_Boolean hasUVNodes,
const Standard_Boolean hasNormals); const Standard_Boolean hasNormals);
//! Constructs a triangulation from a set of triangles. The //! Constructs a triangulation from a set of triangles. The
@@ -115,107 +93,154 @@ public:
Standard_EXPORT Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation); Standard_EXPORT Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation);
//! Returns the deflection of this triangulation. //! Returns the deflection of this triangulation.
Standard_Real Deflection() const { return myDeflection; } Standard_Real Deflection() const {
return myDeflection;
}
//! Sets the deflection of this triangulation to theDeflection. //! Sets the deflection of this triangulation to theDeflection.
//! See more on deflection in Polygon2D //! See more on deflection in Polygon2D
Standard_EXPORT void Deflection (const Standard_Real theDeflection); void Deflection (const Standard_Real theDeflection) {
myDeflection = theDeflection;
}
//! Deallocates the UV nodes. //! Deallocates the UV nodes.
Standard_EXPORT void RemoveUVNodes(); Standard_EXPORT void RemoveUVNodes();
//! Returns TRUE if triangulation has some geometry. //! Returns TRUE if triangulation has some geometry.
virtual Standard_Boolean HasGeometry() const { return !myNodes.IsEmpty() && !myTriangles.IsEmpty(); } virtual Standard_Boolean HasGeometry() const {
return !myNodes.IsEmpty() && !myTriangles.IsEmpty();
}
//! Returns the number of nodes for this triangulation. //! Returns the number of nodes for this triangulation.
Standard_Integer NbNodes() const { return myNodes.Length(); } Standard_Integer NbNodes() const {
return myNodes.Size();
}
//! Returns the number of triangles for this triangulation. //! Returns the number of triangles for this triangulation.
Standard_Integer NbTriangles() const { return myTriangles.Length(); } Standard_Integer NbTriangles() const {
return myTriangles.Size();
}
//! Returns Standard_True if 2D nodes are associated with 3D nodes for this triangulation. //! Sets a node coordinates.
Standard_Boolean HasUVNodes() const { return !myUVNodes.IsNull(); } void SetNode (const Standard_Integer theIndex,
const gp_Pnt& thePnt)
{
myNodes.SetValue (theIndex, thePnt);
}
//! Returns the table of 3D nodes (3D points) for this triangulation. //! Returns a node at the given index.
const TColgp_Array1OfPnt& Nodes() const { return myNodes; } const gp_Pnt& Node (const Standard_Integer theIndex) const {
return myNodes.Value (theIndex);
//! 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. //! Give access to the node at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. gp_Pnt& ChangeNode (const Standard_Integer theIndex) {
Standard_EXPORT gp_Pnt& ChangeNode (const Standard_Integer theIndex); return myNodes.ChangeValue (theIndex);
}
//! Returns the table of 2D nodes (2D points) associated with //! Returns Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
//! each 3D node of this triangulation. Standard_Boolean HasUVNodes() const {
//! The function HasUVNodes checks if 2D nodes return myHasUVNodes;
//! 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 //! Sets an UV-node coordinates.
//! each 3D node of this triangulation. void SetUVNode (const Standard_Integer theIndex,
//! Function ChangeUVNodes shares the returned array. const gp_Pnt2d& thePnt)
//! Therefore if the table is selected by reference, {
//! you can, by simply modifying it, directly modify the data myUVNodes.SetValue (theIndex, thePnt);
//! structure of this triangulation. }
TColgp_Array1OfPnt2d& ChangeUVNodes() { return myUVNodes->ChangeArray1(); }
//! Returns UVNode at the given index. //! Returns UV-node at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const {
Standard_EXPORT const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const; return myUVNodes.Value (theIndex);
}
//! Give access to the UVNode at the given index. //! Give access to the UVNode at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. gp_Pnt2d& ChangeUVNode (const Standard_Integer theIndex) {
Standard_EXPORT gp_Pnt2d& ChangeUVNode (const Standard_Integer theIndex); return myUVNodes.ChangeValue (theIndex);
}
//! Returns the table of triangles for this triangulation. //! Sets a triangle.
const Poly_Array1OfTriangle& Triangles() const { return myTriangles; } void SetTriangle (const Standard_Integer theIndex,
const Poly_Triangle& theTriangle)
//! Returns the table of triangles for this triangulation. {
//! Function ChangeUVNodes shares the returned array. myTriangles.SetValue (theIndex, theTriangle);
//! 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. //! Returns triangle at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. const Poly_Triangle& Triangle (const Standard_Integer theIndex) const {
Standard_EXPORT const Poly_Triangle& Triangle (const Standard_Integer theIndex) const; return myTriangles.Value (theIndex);
}
//! Give access to the triangle at the given index. //! Give access to the triangle at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. //! Raises an exception if theIndex is less than 1 or greater than number of triangles.
Standard_EXPORT Poly_Triangle& ChangeTriangle (const Standard_Integer theIndex); Poly_Triangle& ChangeTriangle (const Standard_Integer theIndex) {
return myTriangles.ChangeValue (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();
//! Returns Standard_True if nodal normals are defined. //! Returns Standard_True if nodal normals are defined.
Standard_EXPORT Standard_Boolean HasNormals() const; Standard_Boolean HasNormals() const {
return !myNormals.IsEmpty() && myNormals.Length() == NbNodes();
//! @return normal at the given index. }
//! Raises Standard_OutOfRange exception.
Standard_EXPORT gp_Dir Normal (const Standard_Integer theIndex) const;
//! Changes normal at the given index. //! Changes normal at the given index.
//! Raises Standard_OutOfRange exception. void SetNormal (const Standard_Integer theIndex,
Standard_EXPORT void SetNormal (const Standard_Integer theIndex, const Vec3f& theNormal)
const gp_Dir& theNormal); {
// If an array for normals is not allocated yet, do it now.
if (myNormals.IsEmpty())
myNormals.Resize (1, myNodes.Size(), Standard_False);
// Set a normal.
myNormals.ChangeValue (theIndex) = theNormal;
}
//! Changes normal at the given index.
void SetNormal (const Standard_Integer theIndex,
const gp_XYZ& theNormal)
{
SetNormal (theIndex, static_cast<Standard_ShortReal>(theNormal.X()),
static_cast<Standard_ShortReal>(theNormal.Y()),
static_cast<Standard_ShortReal>(theNormal.Z()));
}
//! Changes normal at the given index.
void SetNormal (const Standard_Integer theIndex,
const Standard_ShortReal theNormalX,
const Standard_ShortReal theNormalY,
const Standard_ShortReal theNormalZ)
{
SetNormal (theIndex, Vec3f (theNormalX, theNormalY, theNormalZ));
}
//! Returns normal at the given index.
const Vec3f& Normal (const Standard_Integer theIndex) const {
return myNormals (theIndex);
}
//! Returns normal at the given index.
void Normal (const Standard_Integer theIndex,
gp_XYZ& theNormal) const
{
const Vec3f& aCoords = Normal (theIndex);
theNormal.SetCoord (aCoords.x(), aCoords.y(), aCoords.z());
}
//! Sets the table of node normals.
//! Raises exception if length of theNormals != 3 * NbNodes
Standard_DEPRECATED("Deprecated method SetNormals() should be replaced \
by method with array as object instead of handle. \
Array of floats should be replaced by vector of normals")
Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals);
//! An advanced method resizing an internal array of nodes.
//! The old nodes are copied into the new array.
//! UV-nodes as well as normals, if exist are extended and copied too.
Standard_EXPORT void ResizeNodes (const Standard_Integer theNbNodes);
//! An advanced method resizing an internal array of triangles.
//! The old triangles are copied into the new array.
Standard_EXPORT void ResizeTriangles (const Standard_Integer theNbTriangles);
//! Returns cached min - max range of triangulation data, //! Returns cached min - max range of triangulation data,
//! which is VOID by default (e.g, no cached information). //! which is VOID by default (e.g, no cached information).
@@ -264,13 +289,13 @@ protected:
protected: protected:
Bnd_Box* myCachedMinMax; Bnd_Box* myCachedMinMax;
Standard_Real myDeflection; Standard_Real myDeflection;
TColgp_Array1OfPnt myNodes; Standard_Boolean myHasUVNodes;
Handle(TColgp_HArray1OfPnt2d) myUVNodes; TColgp_Array1OfPnt myNodes;
Poly_Array1OfTriangle myTriangles; TColgp_Array1OfPnt2d myUVNodes;
Handle(TShort_HArray1OfShortReal) myNormals; Poly_Array1OfTriangle myTriangles;
NCollection_Array1<Vec3f> myNormals;
}; };
#endif // _Poly_Triangulation_HeaderFile #endif // _Poly_Triangulation_HeaderFile

View File

@@ -36,11 +36,8 @@ void Prs3d::AddFreeEdges (TColgp_SequenceOfPnt& theSegments,
return; return;
} }
const TColgp_Array1OfPnt& aNodes = thePolyTri->Nodes();
// Build the connect tool. // Build the connect tool.
Poly_Connect aPolyConnect (thePolyTri); Poly_Connect aPolyConnect (thePolyTri);
Standard_Integer aNbTriangles = thePolyTri->NbTriangles(); Standard_Integer aNbTriangles = thePolyTri->NbTriangles();
Standard_Integer aT[3]; Standard_Integer aT[3];
Standard_Integer aN[3]; Standard_Integer aN[3];
@@ -66,11 +63,10 @@ void Prs3d::AddFreeEdges (TColgp_SequenceOfPnt& theSegments,
TColStd_Array1OfInteger aFree (1, 2 * aNbFree); TColStd_Array1OfInteger aFree (1, 2 * aNbFree);
Standard_Integer aFreeIndex = 1; Standard_Integer aFreeIndex = 1;
const Poly_Array1OfTriangle& aTriangles = thePolyTri->Triangles();
for (Standard_Integer anI = 1; anI <= aNbTriangles; ++anI) for (Standard_Integer anI = 1; anI <= aNbTriangles; ++anI)
{ {
aPolyConnect.Triangles (anI, aT[0], aT[1], aT[2]); aPolyConnect.Triangles (anI, aT[0], aT[1], aT[2]);
aTriangles (anI).Get (aN[0], aN[1], aN[2]); thePolyTri->Triangle (anI).Get (aN[0], aN[1], aN[2]);
for (Standard_Integer aJ = 0; aJ < 3; aJ++) for (Standard_Integer aJ = 0; aJ < 3; aJ++)
{ {
Standard_Integer k = (aJ + 1) % 3; Standard_Integer k = (aJ + 1) % 3;
@@ -87,8 +83,8 @@ void Prs3d::AddFreeEdges (TColgp_SequenceOfPnt& theSegments,
Standard_Integer aFreeHalfNb = aFree.Length() / 2; Standard_Integer aFreeHalfNb = aFree.Length() / 2;
for (Standard_Integer anI = 1; anI <= aFreeHalfNb; ++anI) for (Standard_Integer anI = 1; anI <= aFreeHalfNb; ++anI)
{ {
const gp_Pnt aPoint1 = aNodes (aFree (2 * anI - 1)).Transformed (theLocation); const gp_Pnt aPoint1 = thePolyTri->Node (aFree (2 * anI - 1)).Transformed (theLocation);
const gp_Pnt aPoint2 = aNodes (aFree (2 * anI )).Transformed (theLocation); const gp_Pnt aPoint2 = thePolyTri->Node (aFree (2 * anI )).Transformed (theLocation);
theSegments.Append (aPoint1); theSegments.Append (aPoint1);
theSegments.Append (aPoint2); theSegments.Append (aPoint2);
} }

View File

@@ -100,9 +100,6 @@ Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolQuadric::CreateTriangulation (const
Handle(Poly_Triangulation) Prs3d_ToolQuadric::CreatePolyTriangulation (const gp_Trsf& theTrsf) const Handle(Poly_Triangulation) Prs3d_ToolQuadric::CreatePolyTriangulation (const gp_Trsf& theTrsf) const
{ {
Handle(Poly_Triangulation) aTriangulation = new Poly_Triangulation (VerticesNb(), TrianglesNb(), Standard_False); Handle(Poly_Triangulation) aTriangulation = new Poly_Triangulation (VerticesNb(), TrianglesNb(), Standard_False);
TColgp_Array1OfPnt& aNodes = aTriangulation->ChangeNodes();
Poly_Array1OfTriangle& aTriangles = aTriangulation->ChangeTriangles();
Standard_ShortReal aStepU = 1.0f / mySlicesNb; Standard_ShortReal aStepU = 1.0f / mySlicesNb;
Standard_ShortReal aStepV = 1.0f / myStacksNb; Standard_ShortReal aStepV = 1.0f / myStacksNb;
@@ -116,11 +113,11 @@ Handle(Poly_Triangulation) Prs3d_ToolQuadric::CreatePolyTriangulation (const gp_
const Standard_Integer aVertId = aU * (myStacksNb + 1) + (aV + 1); const Standard_Integer aVertId = aU * (myStacksNb + 1) + (aV + 1);
gp_Pnt aVertex = Vertex (aParamU, aParamV).Transformed (theTrsf); gp_Pnt aVertex = Vertex (aParamU, aParamV).Transformed (theTrsf);
aNodes.SetValue (aVertId, aVertex); aTriangulation->ChangeNode (aVertId) = aVertex;
if (aU != 0 && aV != 0) if (aU != 0 && aV != 0)
{ {
aTriangles.SetValue (++anIndex, Poly_Triangle (aVertId, aVertId - myStacksNb - 2, aVertId - 1)); aTriangulation->ChangeTriangle (++anIndex) = Poly_Triangle (aVertId, aVertId - myStacksNb - 2, aVertId - 1);
aTriangles.SetValue (++anIndex, Poly_Triangle (aVertId - myStacksNb - 2, aVertId, aVertId - myStacksNb - 1)); aTriangulation->ChangeTriangle (++anIndex) = Poly_Triangle (aVertId - myStacksNb - 2, aVertId, aVertId - myStacksNb - 1);
} }
} }
} }

View File

@@ -4030,25 +4030,16 @@ static Standard_Integer OCC26485 (Draw_Interpretor& theDI, Standard_Integer theA
continue; continue;
Poly::ComputeNormals(aT); Poly::ComputeNormals(aT);
const TColgp_Array1OfPnt& aVertices = aT->Nodes();
const TShort_Array1OfShortReal& aNormals = aT->Normals();
// Number of nodes in the triangulation // Number of nodes in the triangulation
int aVertexNb = aT->Nodes().Length(); int aVertexNb = aT->NbNodes();
if (aVertexNb*3 != aNormals.Length())
{
theDI << "Failed. Different number of normals vs. vertices\n";
return 1;
}
// Get each vertex index, checking common vertexes between shapes // Get each vertex index, checking common vertexes between shapes
for( int i=0; i < aVertexNb; i++ ) for( int i=0; i < aVertexNb; i++ )
{ {
gp_Pnt aPoint = aVertices.Value( i+1 ); gp_Pnt aPoint = aT->Node ( i+1 );
gp_Vec aNormal = gp_Vec( const Vec3f& aVec = aT->Normal ( i+1 );
aNormals.Value( i*3 + 1 ), gp_Dir aNormal (aVec.x(), aVec.y(), aVec.z());
aNormals.Value( i*3 + 2 ),
aNormals.Value( i*3 + 3 ) );
if (aNormal.X() == 0 && aNormal.Y() == 0 && aNormal.Z() == 1) if (aNormal.X() == 0 && aNormal.Y() == 0 && aNormal.Z() == 1)
{ {

View File

@@ -648,20 +648,17 @@ static Standard_Integer QABVH_PairDistance (Draw_Interpretor& theDI,
TopLoc_Location aLoc; TopLoc_Location aLoc;
const Handle(Poly_Triangulation)& aTriangulation = BRep_Tool::Triangulation(aF, aLoc); const Handle(Poly_Triangulation)& aTriangulation = BRep_Tool::Triangulation(aF, aLoc);
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); const int aNbTriangles = aTriangulation->NbTriangles();
const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
const int aNbTriangles = aTriangles.Length();
for (int iT = 1; iT <= aNbTriangles; ++iT) for (int iT = 1; iT <= aNbTriangles; ++iT)
{ {
const Poly_Triangle& aTriangle = aTriangles (iT); const Poly_Triangle& aTriangle = aTriangulation->Triangle (iT);
// Nodes indices // Nodes indices
Standard_Integer id1, id2, id3; Standard_Integer id1, id2, id3;
aTriangle.Get (id1, id2, id3); aTriangle.Get (id1, id2, id3);
const gp_Pnt& aP1 = aNodes(id1).Transformed(aLoc.Transformation()); const gp_Pnt aP1 = aTriangulation->Node (id1).Transformed (aLoc.Transformation());
const gp_Pnt& aP2 = aNodes(id2).Transformed(aLoc.Transformation()); const gp_Pnt aP2 = aTriangulation->Node (id2).Transformed (aLoc.Transformation());
const gp_Pnt& aP3 = aNodes(id3).Transformed(aLoc.Transformation()); const gp_Pnt aP3 = aTriangulation->Node (id3).Transformed (aLoc.Transformation());
BVH_Vec3d aBVHP1 (aP1.X(), aP1.Y(), aP1.Z()); BVH_Vec3d aBVHP1 (aP1.X(), aP1.Y(), aP1.Z());
BVH_Vec3d aBVHP2 (aP2.X(), aP2.Y(), aP2.Z()); BVH_Vec3d aBVHP2 (aP2.X(), aP2.Y(), aP2.Z());
@@ -711,20 +708,17 @@ public:
TopLoc_Location aLoc; TopLoc_Location aLoc;
const Handle(Poly_Triangulation)& aTriangulation = BRep_Tool::Triangulation(theFace, aLoc); const Handle(Poly_Triangulation)& aTriangulation = BRep_Tool::Triangulation(theFace, aLoc);
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); const int aNbTriangles = aTriangulation->NbTriangles();
const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
const int aNbTriangles = aTriangles.Length();
for (int iT = 1; iT <= aNbTriangles; ++iT) for (int iT = 1; iT <= aNbTriangles; ++iT)
{ {
const Poly_Triangle& aTriangle = aTriangles (iT); const Poly_Triangle& aTriangle = aTriangulation->Triangle (iT);
// Nodes indices // Nodes indices
Standard_Integer id1, id2, id3; Standard_Integer id1, id2, id3;
aTriangle.Get (id1, id2, id3); aTriangle.Get (id1, id2, id3);
const gp_Pnt& aP1 = aNodes(id1).Transformed(aLoc.Transformation()); const gp_Pnt aP1 = aTriangulation->Node (id1).Transformed (aLoc.Transformation());
const gp_Pnt& aP2 = aNodes(id2).Transformed(aLoc.Transformation()); const gp_Pnt aP2 = aTriangulation->Node (id2).Transformed (aLoc.Transformation());
const gp_Pnt& aP3 = aNodes(id3).Transformed(aLoc.Transformation()); const gp_Pnt aP3 = aTriangulation->Node (id3).Transformed (aLoc.Transformation());
BVH_Vec3d aBVHP1 (aP1.X(), aP1.Y(), aP1.Z()); BVH_Vec3d aBVHP1 (aP1.X(), aP1.Y(), aP1.Z());
BVH_Vec3d aBVHP2 (aP2.X(), aP2.Y(), aP2.Z()); BVH_Vec3d aBVHP2 (aP2.X(), aP2.Y(), aP2.Z());

View File

@@ -48,19 +48,7 @@ RWGltf_TriangulationReader::RWGltf_TriangulationReader()
// ======================================================================= // =======================================================================
void RWGltf_TriangulationReader::reset() void RWGltf_TriangulationReader::reset()
{ {
myTriangulation = new Poly_Triangulation (1, 1, true); myTriangulation = new Poly_Triangulation (0, 0, true);
{
TColgp_Array1OfPnt anEmpty;
myTriangulation->ChangeNodes().Move (anEmpty);
}
{
TColgp_Array1OfPnt2d anEmpty;
myTriangulation->ChangeUVNodes().Move (anEmpty);
}
{
Poly_Array1OfTriangle anEmpty;
myTriangulation->ChangeTriangles().Move (anEmpty);
}
} }
// ======================================================================= // =======================================================================
@@ -73,11 +61,6 @@ Handle(Poly_Triangulation) RWGltf_TriangulationReader::result()
{ {
return Handle(Poly_Triangulation)(); return Handle(Poly_Triangulation)();
} }
if (myTriangulation->UVNodes().Size() != myTriangulation->NbNodes())
{
myTriangulation->RemoveUVNodes();
}
if (myTriangulation->NbTriangles() < 1) if (myTriangulation->NbTriangles() < 1)
{ {
// reconstruct indexes // reconstruct indexes
@@ -350,11 +333,11 @@ bool RWGltf_TriangulationReader::readBuffer (std::istream& theStream,
if (aVec3->SquareModulus() >= THE_NORMAL_PREC2) if (aVec3->SquareModulus() >= THE_NORMAL_PREC2)
{ {
myCoordSysConverter.TransformNormal (*aVec3); myCoordSysConverter.TransformNormal (*aVec3);
setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_Dir (aVec3->x(), aVec3->y(), aVec3->z())); setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_XYZ (aVec3->x(), aVec3->y(), aVec3->z()));
} }
else else
{ {
setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_Dir (0.0, 0.0, 1.0)); setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp::DZ().XYZ());
} }
} }
} }
@@ -370,11 +353,11 @@ bool RWGltf_TriangulationReader::readBuffer (std::istream& theStream,
} }
if (aVec3->SquareModulus() >= THE_NORMAL_PREC2) if (aVec3->SquareModulus() >= THE_NORMAL_PREC2)
{ {
setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_Dir (aVec3->x(), aVec3->y(), aVec3->z())); setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_XYZ (aVec3->x(), aVec3->y(), aVec3->z()));
} }
else else
{ {
setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp_Dir (0.0, 0.0, 1.0)); setNodeNormal (THE_LOWER_NODE_INDEX + aVertIter, gp::DZ().XYZ());
} }
} }
} }

View File

@@ -52,12 +52,8 @@ protected: //! @name interface for filling triangulation data
//! Resize array of position nodes to specified size. //! Resize array of position nodes to specified size.
virtual bool setNbPositionNodes (Standard_Integer theNbNodes) virtual bool setNbPositionNodes (Standard_Integer theNbNodes)
{ {
if (theNbNodes <= 0) myTriangulation->ResizeNodes (theNbNodes);
{ return theNbNodes > 0;
return false;
}
myTriangulation->ChangeNodes().Resize (1, theNbNodes, false);
return true;
} }
//! Set node position. //! Set node position.
@@ -70,14 +66,9 @@ protected: //! @name interface for filling triangulation data
} }
//! Resize array of UV nodes to specified size. //! Resize array of UV nodes to specified size.
virtual bool setNbUVNodes (Standard_Integer theNbNodes) virtual bool setNbUVNodes (Standard_Integer /*theNbNodes*/)
{ {
if (theNbNodes <= 0 // Resizing of the array of nodes extends an array of UV-nodes too.
|| myTriangulation->NbNodes() != theNbNodes)
{
return false;
}
myTriangulation->ChangeUVNodes().Resize (1, theNbNodes, false);
return true; return true;
} }
@@ -91,14 +82,9 @@ protected: //! @name interface for filling triangulation data
} }
//! Resize array of nodes normals to specified size. //! Resize array of nodes normals to specified size.
virtual bool setNbNormalNodes (Standard_Integer theNbNodes) virtual bool setNbNormalNodes (Standard_Integer /*theNbNodes*/)
{ {
if (theNbNodes <= 0 // Resizing of the array of nodes extends an array of normals too.
|| myTriangulation->NbNodes() != theNbNodes)
{
return false;
}
myTriangulation->SetNormals (new TShort_HArray1OfShortReal (1, theNbNodes * 3));
return true; return true;
} }
@@ -106,7 +92,7 @@ protected: //! @name interface for filling triangulation data
//! @param theIndex node index starting from 1 //! @param theIndex node index starting from 1
//! @param theNormal node normal //! @param theNormal node normal
virtual void setNodeNormal (Standard_Integer theIndex, virtual void setNodeNormal (Standard_Integer theIndex,
const gp_Dir& theNormal) const gp_XYZ& theNormal)
{ {
myTriangulation->SetNormal (theIndex, theNormal); myTriangulation->SetNormal (theIndex, theNormal);
} }
@@ -114,12 +100,8 @@ protected: //! @name interface for filling triangulation data
//! Resize array of triangles to specified size. //! Resize array of triangles to specified size.
virtual bool setNbTriangles (Standard_Integer theNbTris) virtual bool setNbTriangles (Standard_Integer theNbTris)
{ {
if (theNbTris >= 1) myTriangulation->ResizeTriangles (theNbTris);
{ return theNbTris > 0;
myTriangulation->ChangeTriangles().Resize (1, theNbTris, false);
return true;
}
return false;
} }
//! Add triangle element. //! Add triangle element.
@@ -129,9 +111,9 @@ protected: //! @name interface for filling triangulation data
virtual bool setTriangle (Standard_Integer theIndex, virtual bool setTriangle (Standard_Integer theIndex,
const Poly_Triangle& theTriangle) const Poly_Triangle& theTriangle)
{ {
if (theTriangle.Value (1) < myTriangulation->Nodes().Lower() || theTriangle.Value (1) > myTriangulation->Nodes().Upper() if (theTriangle.Value (1) < 1 || theTriangle.Value (1) > myTriangulation->NbNodes()
|| theTriangle.Value (2) < myTriangulation->Nodes().Lower() || theTriangle.Value (2) > myTriangulation->Nodes().Upper() || theTriangle.Value (2) < 1 || theTriangle.Value (2) > myTriangulation->NbNodes()
|| theTriangle.Value (3) < myTriangulation->Nodes().Lower() || theTriangle.Value (3) > myTriangulation->Nodes().Upper()) || theTriangle.Value (3) < 1 || theTriangle.Value (3) > myTriangulation->NbNodes())
{ {
return false; return false;
} }

View File

@@ -31,9 +31,6 @@ RWMesh_FaceIterator::RWMesh_FaceIterator (const TDF_Label& theLabel,
: myDefStyle (theStyle), : myDefStyle (theStyle),
myToMapColors (theToMapColors), myToMapColors (theToMapColors),
mySLTool (1, 1e-12), mySLTool (1, 1e-12),
myNodes (NULL),
myNormals (NULL),
myNodeUVs (NULL),
myHasNormals (false), myHasNormals (false),
myIsMirrored (false), myIsMirrored (false),
myHasFaceColor (false) myHasFaceColor (false)
@@ -133,21 +130,17 @@ void RWMesh_FaceIterator::dispatchStyles (const TDF_Label& theLabel,
gp_Dir RWMesh_FaceIterator::normal (Standard_Integer theNode) gp_Dir RWMesh_FaceIterator::normal (Standard_Integer theNode)
{ {
gp_Dir aNormal (gp::DZ()); gp_Dir aNormal (gp::DZ());
if (myNormals != NULL) if (myPolyTriang->HasNormals())
{ {
const Standard_Integer aNodeIndex = theNode - myNodes->Lower(); const Vec3f& aVec = myPolyTriang->Normal (theNode);
const Graphic3d_Vec3 aNormVec3 (myNormals->Value (myNormals->Lower() + aNodeIndex * 3), aNormal.SetCoord (aVec.x(), aVec.y(), aVec.z());
myNormals->Value (myNormals->Lower() + aNodeIndex * 3 + 1), if (aNormal.XYZ().Modulus() < Precision::Confusion())
myNormals->Value (myNormals->Lower() + aNodeIndex * 3 + 2)); aNormal = gp::DZ();
if (aNormVec3.Modulus() != 0.0f) }
{
aNormal.SetCoord (aNormVec3.x(), aNormVec3.y(), aNormVec3.z());
}
}
else if (myHasNormals else if (myHasNormals
&& myNodeUVs != NULL) && myPolyTriang->HasUVNodes())
{ {
const gp_XY& anUV = myNodeUVs->Value (theNode).XY(); const gp_XY& anUV = myPolyTriang->UVNode (theNode).XY();
mySLTool.SetParameters (anUV.X(), anUV.Y()); mySLTool.SetParameters (anUV.X(), anUV.Y());
if (mySLTool.IsNormalDefined()) if (mySLTool.IsNormalDefined())
{ {
@@ -169,7 +162,7 @@ void RWMesh_FaceIterator::Next()
myPolyTriang = BRep_Tool::Triangulation (myFace, myFaceLocation); myPolyTriang = BRep_Tool::Triangulation (myFace, myFaceLocation);
myTrsf = myFaceLocation.Transformation(); myTrsf = myFaceLocation.Transformation();
if (myPolyTriang.IsNull() if (myPolyTriang.IsNull()
|| myPolyTriang->Triangles().Length() == 0) || myPolyTriang->NbTriangles() == 0)
{ {
resetFace(); resetFace();
continue; continue;
@@ -192,29 +185,20 @@ void RWMesh_FaceIterator::initFace()
myHasNormals = false; myHasNormals = false;
myHasFaceColor = false; myHasFaceColor = false;
myIsMirrored = myTrsf.VectorialPart().Determinant() < 0.0; myIsMirrored = myTrsf.VectorialPart().Determinant() < 0.0;
myNormals = NULL;
myNodeUVs = NULL;
myNodes = &myPolyTriang->Nodes();
if (myPolyTriang->HasNormals()) if (myPolyTriang->HasNormals())
{ {
myNormals = &myPolyTriang->Normals();
myHasNormals = true; myHasNormals = true;
} }
if (myPolyTriang->HasUVNodes()) if (myPolyTriang->HasUVNodes() && !myHasNormals)
{ {
myNodeUVs = &myPolyTriang->UVNodes(); TopoDS_Face aFaceFwd = TopoDS::Face (myFace.Oriented (TopAbs_FORWARD));
if (!myHasNormals) aFaceFwd.Location (TopLoc_Location());
TopLoc_Location aLoc;
if (!BRep_Tool::Surface (aFaceFwd, aLoc).IsNull())
{ {
TopoDS_Face aFaceFwd = TopoDS::Face (myFace.Oriented (TopAbs_FORWARD)); myFaceAdaptor.Initialize (aFaceFwd, false);
aFaceFwd.Location (TopLoc_Location()); mySLTool.SetSurface (myFaceAdaptor);
TopLoc_Location aLoc; myHasNormals = true;
if (!BRep_Tool::Surface (aFaceFwd, aLoc).IsNull())
{
myFaceAdaptor.Initialize (aFaceFwd, false);
mySLTool.SetSurface (myFaceAdaptor);
myHasNormals = true;
}
} }
} }
if (!myToMapColors) if (!myToMapColors)

View File

@@ -75,10 +75,10 @@ public:
Standard_Integer NbTriangles() const { return myPolyTriang->NbTriangles(); } Standard_Integer NbTriangles() const { return myPolyTriang->NbTriangles(); }
//! Lower element index in current triangulation. //! Lower element index in current triangulation.
Standard_Integer ElemLower() const { return myPolyTriang->Triangles().Lower(); } Standard_Integer ElemLower() const { return 1; }
//! Upper element index in current triangulation. //! Upper element index in current triangulation.
Standard_Integer ElemUpper() const { return myPolyTriang->Triangles().Upper(); } Standard_Integer ElemUpper() const { return myPolyTriang->NbTriangles(); }
//! Return triangle with specified index with applied Face orientation. //! Return triangle with specified index with applied Face orientation.
Poly_Triangle TriangleOriented (Standard_Integer theElemIndex) const Poly_Triangle TriangleOriented (Standard_Integer theElemIndex) const
@@ -97,7 +97,7 @@ public:
bool HasNormals() const { return myHasNormals; } bool HasNormals() const { return myHasNormals; }
//! Return true if triangulation has defined normals. //! Return true if triangulation has defined normals.
bool HasTexCoords() const { return myNodeUVs != NULL; } bool HasTexCoords() const { return myPolyTriang->HasUVNodes(); }
//! Return normal at specified node index with face transformation applied and face orientation applied. //! Return normal at specified node index with face transformation applied and face orientation applied.
gp_Dir NormalTransformed (Standard_Integer theNode) gp_Dir NormalTransformed (Standard_Integer theNode)
@@ -118,15 +118,15 @@ public:
Standard_Integer NbNodes() const Standard_Integer NbNodes() const
{ {
return !myPolyTriang.IsNull() return !myPolyTriang.IsNull()
? myPolyTriang->Nodes().Length() ? myPolyTriang->NbNodes()
: 0; : 0;
} }
//! Lower node index in current triangulation. //! Lower node index in current triangulation.
Standard_Integer NodeLower() const { return myPolyTriang->Nodes().Lower(); } Standard_Integer NodeLower() const { return 1; }
//! Upper node index in current triangulation. //! Upper node index in current triangulation.
Standard_Integer NodeUpper() const { return myPolyTriang->Nodes().Upper(); } Standard_Integer NodeUpper() const { return myPolyTriang->NbNodes(); }
//! Return the node with specified index with applied transformation. //! Return the node with specified index with applied transformation.
gp_Pnt NodeTransformed (const Standard_Integer theNode) const gp_Pnt NodeTransformed (const Standard_Integer theNode) const
@@ -139,19 +139,19 @@ public:
//! Return texture coordinates for the node. //! Return texture coordinates for the node.
gp_Pnt2d NodeTexCoord (const Standard_Integer theNode) const gp_Pnt2d NodeTexCoord (const Standard_Integer theNode) const
{ {
return myNodeUVs != NULL ? myNodeUVs->Value (theNode) : gp_Pnt2d(); return myPolyTriang->HasUVNodes() ? myPolyTriang->UVNode (theNode) : gp_Pnt2d();
} }
public: public:
//! Return the node with specified index with applied transformation. //! Return the node with specified index with applied transformation.
gp_Pnt node (const Standard_Integer theNode) const { return myPolyTriang->Nodes().Value (theNode); } gp_Pnt node (const Standard_Integer theNode) const { return myPolyTriang->Node (theNode); }
//! Return normal at specified node index without face transformation applied. //! Return normal at specified node index without face transformation applied.
Standard_EXPORT gp_Dir normal (Standard_Integer theNode); Standard_EXPORT gp_Dir normal (Standard_Integer theNode);
//! Return triangle with specified index. //! Return triangle with specified index.
Poly_Triangle triangle (Standard_Integer theElemIndex) const { return myPolyTriang->Triangles().Value (theElemIndex); } Poly_Triangle triangle (Standard_Integer theElemIndex) const { return myPolyTriang->Triangle (theElemIndex); }
private: private:
@@ -165,9 +165,6 @@ private:
{ {
myPolyTriang.Nullify(); myPolyTriang.Nullify();
myFace.Nullify(); myFace.Nullify();
myNodes = NULL;
myNormals = NULL;
myNodeUVs = NULL;
myHasNormals = false; myHasNormals = false;
myHasFaceColor = false; myHasFaceColor = false;
myFaceColor = Quantity_ColorRGBA(); myFaceColor = Quantity_ColorRGBA();
@@ -190,9 +187,6 @@ private:
TopLoc_Location myFaceLocation; //!< current face location TopLoc_Location myFaceLocation; //!< current face location
BRepLProp_SLProps mySLTool; //!< auxiliary tool for fetching normals from surface BRepLProp_SLProps mySLTool; //!< auxiliary tool for fetching normals from surface
BRepAdaptor_Surface myFaceAdaptor; //!< surface adaptor for fetching normals from surface BRepAdaptor_Surface myFaceAdaptor; //!< surface adaptor for fetching normals from surface
const TColgp_Array1OfPnt* myNodes; //!< node positions of current face
const TShort_Array1OfShortReal* myNormals; //!< node normals of current face
const TColgp_Array1OfPnt2d* myNodeUVs; //!< node UV coordinates of current face
Standard_Boolean myHasNormals; //!< flag indicating that current face has normals Standard_Boolean myHasNormals; //!< flag indicating that current face has normals
gp_Trsf myTrsf; //!< current face transformation gp_Trsf myTrsf; //!< current face transformation
Standard_Boolean myIsMirrored; //!< flag indicating that face triangles should be mirrored Standard_Boolean myIsMirrored; //!< flag indicating that face triangles should be mirrored

View File

@@ -167,30 +167,19 @@ Handle(Poly_Triangulation) RWObj_TriangulationReader::GetTriangulation()
} }
if (hasNormals) if (hasNormals)
{ {
const Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, myNodes.Length() * 3);
Standard_ShortReal* aNormArr = &aNormals->ChangeFirst();
Standard_Integer aNbInvalid = 0;
for (Standard_Integer aNodeIter = 0; aNodeIter < myNodes.Size(); ++aNodeIter) for (Standard_Integer aNodeIter = 0; aNodeIter < myNodes.Size(); ++aNodeIter)
{ {
const Graphic3d_Vec3& aNorm = myNormals.Value (aNodeIter); const Graphic3d_Vec3& aNorm = myNormals.Value (aNodeIter);
const float aMod2 = aNorm.SquareModulus(); const float aMod2 = aNorm.SquareModulus();
if (aMod2 > 0.001f) if (aMod2 > 0.001f)
{ {
aNormArr[aNodeIter * 3 + 0] = aNorm.x(); aPoly->SetNormal (aNodeIter + 1, aNorm.x(), aNorm.y(), aNorm.z());
aNormArr[aNodeIter * 3 + 1] = aNorm.y();
aNormArr[aNodeIter * 3 + 2] = aNorm.z();
} }
else else
{ {
++aNbInvalid; aPoly->SetNormal (aNodeIter + 1, 0.0f, 0.0f, 1.0f);
aNormArr[aNodeIter * 3 + 0] = 0.0f;
aNormArr[aNodeIter * 3 + 1] = 0.0f;
aNormArr[aNodeIter * 3 + 2] = 1.0f;
} }
} aPoly->SetNormal (aNodeIter + 1, aNorm.x(), aNorm.y(), aNorm.z());
if (aNbInvalid != myNodes.Length())
{
aPoly->SetNormals (aNormals);
} }
} }

View File

@@ -284,17 +284,15 @@ Standard_Boolean RWStl::writeASCII (const Handle(Poly_Triangulation)& theMesh,
const Standard_Integer NBTriangles = theMesh->NbTriangles(); const Standard_Integer NBTriangles = theMesh->NbTriangles();
Message_ProgressScope aPS (theProgress, "Triangles", NBTriangles); Message_ProgressScope aPS (theProgress, "Triangles", NBTriangles);
const TColgp_Array1OfPnt& aNodes = theMesh->Nodes();
const Poly_Array1OfTriangle& aTriangles = theMesh->Triangles();
Standard_Integer anElem[3] = {0, 0, 0}; Standard_Integer anElem[3] = {0, 0, 0};
for (Standard_Integer aTriIter = 1; aTriIter <= NBTriangles; ++aTriIter) for (Standard_Integer aTriIter = 1; aTriIter <= NBTriangles; ++aTriIter)
{ {
const Poly_Triangle& aTriangle = aTriangles (aTriIter); const Poly_Triangle& aTriangle = theMesh->Triangle (aTriIter);
aTriangle.Get (anElem[0], anElem[1], anElem[2]); aTriangle.Get (anElem[0], anElem[1], anElem[2]);
const gp_Pnt aP1 = aNodes (anElem[0]); const gp_Pnt& aP1 = theMesh->Node (anElem[0]);
const gp_Pnt aP2 = aNodes (anElem[1]); const gp_Pnt& aP2 = theMesh->Node (anElem[1]);
const gp_Pnt aP3 = aNodes (anElem[2]); const gp_Pnt& aP3 = theMesh->Node (anElem[2]);
const gp_Vec aVec1 (aP1, aP2); const gp_Vec aVec1 (aP1, aP2);
const gp_Vec aVec2 (aP1, aP3); const gp_Vec aVec2 (aP1, aP3);
@@ -365,9 +363,6 @@ Standard_Boolean RWStl::writeBinary (const Handle(Poly_Triangulation)& theMesh,
NCollection_Array1<Standard_Character> aData (1, aChunkSize); NCollection_Array1<Standard_Character> aData (1, aChunkSize);
Standard_Character* aDataChunk = &aData.ChangeFirst(); Standard_Character* aDataChunk = &aData.ChangeFirst();
const TColgp_Array1OfPnt& aNodes = theMesh->Nodes();
const Poly_Array1OfTriangle& aTriangles = theMesh->Triangles();
Standard_Character aConv[4]; Standard_Character aConv[4];
convertInteger (aNBTriangles, aConv); convertInteger (aNBTriangles, aConv);
if (fwrite (aConv, 1, 4, theFile) != 4) if (fwrite (aConv, 1, 4, theFile) != 4)
@@ -379,12 +374,12 @@ Standard_Boolean RWStl::writeBinary (const Handle(Poly_Triangulation)& theMesh,
for (Standard_Integer aTriIter = 1; aTriIter <= aNBTriangles; ++aTriIter) for (Standard_Integer aTriIter = 1; aTriIter <= aNBTriangles; ++aTriIter)
{ {
Standard_Integer id[3]; Standard_Integer id[3];
const Poly_Triangle& aTriangle = aTriangles (aTriIter); const Poly_Triangle& aTriangle = theMesh->Triangle (aTriIter);
aTriangle.Get (id[0], id[1], id[2]); aTriangle.Get (id[0], id[1], id[2]);
const gp_Pnt aP1 = aNodes (id[0]); const gp_Pnt& aP1 = theMesh->Node (id[0]);
const gp_Pnt aP2 = aNodes (id[1]); const gp_Pnt& aP2 = theMesh->Node (id[1]);
const gp_Pnt aP3 = aNodes (id[2]); const gp_Pnt& aP3 = theMesh->Node (id[2]);
gp_Vec aVec1 (aP1, aP2); gp_Vec aVec1 (aP1, aP2);
gp_Vec aVec2 (aP1, aP3); gp_Vec aVec2 (aP1, aP3);

View File

@@ -63,8 +63,6 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S
{ {
myInvInitLocation = myInitLocation.Transformation().Inverted(); myInvInitLocation = myInitLocation.Transformation().Inverted();
mySensType = theIsInterior ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY; mySensType = theIsInterior ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY;
const Poly_Array1OfTriangle& aTriangles = myTriangul->Triangles();
const TColgp_Array1OfPnt& aNodes = myTriangul->Nodes();
Standard_Integer aNbTriangles (myTriangul->NbTriangles()); Standard_Integer aNbTriangles (myTriangul->NbTriangles());
gp_XYZ aCenter (0.0, 0.0, 0.0); gp_XYZ aCenter (0.0, 0.0, 0.0);
@@ -83,8 +81,8 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S
for (Standard_Integer aTriangleIdx = 1; aTriangleIdx <= aNbTriangles; aTriangleIdx++) for (Standard_Integer aTriangleIdx = 1; aTriangleIdx <= aNbTriangles; aTriangleIdx++)
{ {
aPoly.Triangles (aTriangleIdx, aTriangle[0], aTriangle[1], aTriangle[2]); aPoly.Triangles (aTriangleIdx, aTriangle[0], aTriangle[1], aTriangle[2]);
aTriangles (aTriangleIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]); myTriangul->Triangle (aTriangleIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]);
aCenter += (aNodes (aTrNodeIdx[0]).XYZ() + aNodes (aTrNodeIdx[1]).XYZ()+ aNodes (aTrNodeIdx[2]).XYZ()) / 3.0; aCenter += (myTriangul->Node (aTrNodeIdx[0]).XYZ() + myTriangul->Node (aTrNodeIdx[1]).XYZ()+ myTriangul->Node (aTrNodeIdx[2]).XYZ()) / 3.0;
for (Standard_Integer aVertIdx = 0; aVertIdx < 3; aVertIdx++) for (Standard_Integer aVertIdx = 0; aVertIdx < 3; aVertIdx++)
{ {
Standard_Integer aNextVert = (aVertIdx + 1) % 3; Standard_Integer aNextVert = (aVertIdx + 1) % 3;
@@ -102,8 +100,8 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S
Standard_Integer aTrNodeIdx[3]; Standard_Integer aTrNodeIdx[3];
for (Standard_Integer aTrIdx = 1; aTrIdx <= aNbTriangles; aTrIdx++) for (Standard_Integer aTrIdx = 1; aTrIdx <= aNbTriangles; aTrIdx++)
{ {
aTriangles (aTrIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]); myTriangul->Triangle (aTrIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]);
aCenter += (aNodes (aTrNodeIdx[0]).XYZ() + aNodes (aTrNodeIdx[1]).XYZ()+ aNodes (aTrNodeIdx[2]).XYZ()) / 3.0; aCenter += (myTriangul->Node (aTrNodeIdx[0]).XYZ() + myTriangul->Node (aTrNodeIdx[1]).XYZ()+ myTriangul->Node (aTrNodeIdx[2]).XYZ()) / 3.0;
} }
} }
if (aNbTriangles != 0) if (aNbTriangles != 0)
@@ -113,9 +111,9 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S
myBndBox.Clear(); myBndBox.Clear();
for (Standard_Integer aNodeIdx = 1; aNodeIdx <= myTriangul->NbNodes(); ++aNodeIdx) for (Standard_Integer aNodeIdx = 1; aNodeIdx <= myTriangul->NbNodes(); ++aNodeIdx)
{ {
myBndBox.Add (SelectMgr_Vec3 (aNodes (aNodeIdx).X(), myBndBox.Add (SelectMgr_Vec3 (myTriangul->Node (aNodeIdx).X(),
aNodes (aNodeIdx).Y(), myTriangul->Node (aNodeIdx).Y(),
aNodes (aNodeIdx).Z())); myTriangul->Node (aNodeIdx).Z()));
} }
if (theIsInterior) if (theIsInterior)
@@ -154,7 +152,7 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S
{ {
myInvInitLocation = myInitLocation.Transformation().Inverted(); myInvInitLocation = myInitLocation.Transformation().Inverted();
mySensType = theIsInterior ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY; mySensType = theIsInterior ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY;
myPrimitivesNb = theIsInterior ? theTrg->Triangles().Length() : theFreeEdges->Length() / 2; myPrimitivesNb = theIsInterior ? theTrg->NbTriangles() : theFreeEdges->Length() / 2;
myBVHPrimIndexes = new TColStd_HArray1OfInteger(0, myPrimitivesNb - 1); myBVHPrimIndexes = new TColStd_HArray1OfInteger(0, myPrimitivesNb - 1);
if (theIsInterior) if (theIsInterior)
{ {
@@ -196,11 +194,11 @@ Select3D_BndBox3d Select3D_SensitiveTriangulation::Box (const Standard_Integer t
if (mySensType == Select3D_TOS_INTERIOR) if (mySensType == Select3D_TOS_INTERIOR)
{ {
Standard_Integer aNode1, aNode2, aNode3; Standard_Integer aNode1, aNode2, aNode3;
myTriangul->Triangles() (aPrimIdx + 1).Get (aNode1, aNode2, aNode3); myTriangul->Triangle (aPrimIdx + 1).Get (aNode1, aNode2, aNode3);
const gp_Pnt& aPnt1 = myTriangul->Nodes().Value (aNode1); const gp_Pnt& aPnt1 = myTriangul->Node (aNode1);
const gp_Pnt& aPnt2 = myTriangul->Nodes().Value (aNode2); const gp_Pnt& aPnt2 = myTriangul->Node (aNode2);
const gp_Pnt& aPnt3 = myTriangul->Nodes().Value (aNode3); const gp_Pnt& aPnt3 = myTriangul->Node (aNode3);
aMinPnt = SelectMgr_Vec3 (Min (aPnt1.X(), Min (aPnt2.X(), aPnt3.X())), aMinPnt = SelectMgr_Vec3 (Min (aPnt1.X(), Min (aPnt2.X(), aPnt3.X())),
Min (aPnt1.Y(), Min (aPnt2.Y(), aPnt3.Y())), Min (aPnt1.Y(), Min (aPnt2.Y(), aPnt3.Y())),
@@ -213,8 +211,8 @@ Select3D_BndBox3d Select3D_SensitiveTriangulation::Box (const Standard_Integer t
{ {
Standard_Integer aNodeIdx1 = myFreeEdges->Value (myFreeEdges->Lower() + aPrimIdx); Standard_Integer aNodeIdx1 = myFreeEdges->Value (myFreeEdges->Lower() + aPrimIdx);
Standard_Integer aNodeIdx2 = myFreeEdges->Value (myFreeEdges->Lower() + aPrimIdx + 1); Standard_Integer aNodeIdx2 = myFreeEdges->Value (myFreeEdges->Lower() + aPrimIdx + 1);
const gp_Pnt& aNode1 = myTriangul->Nodes().Value (aNodeIdx1); const gp_Pnt& aNode1 = myTriangul->Node (aNodeIdx1);
const gp_Pnt& aNode2 = myTriangul->Nodes().Value (aNodeIdx2); const gp_Pnt& aNode2 = myTriangul->Node (aNodeIdx2);
aMinPnt = SelectMgr_Vec3 (Min (aNode1.X(), aNode2.X()), aMinPnt = SelectMgr_Vec3 (Min (aNode1.X(), aNode2.X()),
Min (aNode1.Y(), aNode2.Y()), Min (aNode1.Y(), aNode2.Y()),
@@ -281,9 +279,9 @@ bool Select3D_SensitiveTriangulation::LastDetectedTriangle (Poly_Triangle& theTr
return false; return false;
} }
theTriNodes[0] = myTriangul->Nodes().Value (theTriangle.Value (1)).Transformed (myInitLocation.Transformation());; theTriNodes[0] = myTriangul->Node (theTriangle.Value (1)).Transformed (myInitLocation.Transformation());;
theTriNodes[1] = myTriangul->Nodes().Value (theTriangle.Value (2)).Transformed (myInitLocation.Transformation());; theTriNodes[1] = myTriangul->Node (theTriangle.Value (2)).Transformed (myInitLocation.Transformation());;
theTriNodes[2] = myTriangul->Nodes().Value (theTriangle.Value (3)).Transformed (myInitLocation.Transformation());; theTriNodes[2] = myTriangul->Node (theTriangle.Value (3)).Transformed (myInitLocation.Transformation());;
return true; return true;
} }
@@ -310,8 +308,8 @@ Standard_Boolean Select3D_SensitiveTriangulation::overlapsElement (SelectBasics_
const gp_Pnt anEdgePnts[2] = const gp_Pnt anEdgePnts[2] =
{ {
myTriangul->Nodes().Value (aSegmStartIdx), myTriangul->Node (aSegmStartIdx),
myTriangul->Nodes().Value (aSegmEndIdx) myTriangul->Node (aSegmEndIdx)
}; };
TColgp_Array1OfPnt anEdgePntsArr (anEdgePnts[0], 1, 2); TColgp_Array1OfPnt anEdgePntsArr (anEdgePnts[0], 1, 2);
Standard_Boolean isMatched = theMgr.Overlaps (anEdgePntsArr, Select3D_TOS_BOUNDARY, thePickResult); Standard_Boolean isMatched = theMgr.Overlaps (anEdgePntsArr, Select3D_TOS_BOUNDARY, thePickResult);
@@ -319,12 +317,11 @@ Standard_Boolean Select3D_SensitiveTriangulation::overlapsElement (SelectBasics_
} }
else else
{ {
const Poly_Array1OfTriangle& aTriangles = myTriangul->Triangles();
Standard_Integer aNode1, aNode2, aNode3; Standard_Integer aNode1, aNode2, aNode3;
aTriangles (aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3); myTriangul->Triangle (aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3);
const gp_Pnt& aPnt1 = myTriangul->Nodes().Value (aNode1); const gp_Pnt& aPnt1 = myTriangul->Node (aNode1);
const gp_Pnt& aPnt2 = myTriangul->Nodes().Value (aNode2); const gp_Pnt& aPnt2 = myTriangul->Node (aNode2);
const gp_Pnt& aPnt3 = myTriangul->Nodes().Value (aNode3); const gp_Pnt& aPnt3 = myTriangul->Node (aNode3);
return theMgr.Overlaps (aPnt1, aPnt2, aPnt3, Select3D_TOS_INTERIOR, thePickResult); return theMgr.Overlaps (aPnt1, aPnt2, aPnt3, Select3D_TOS_INTERIOR, thePickResult);
} }
} }
@@ -345,8 +342,8 @@ Standard_Boolean Select3D_SensitiveTriangulation::elementIsInside (SelectBasics_
const Standard_Integer aPrimitiveIdx = myBVHPrimIndexes->Value (theElemIdx); const Standard_Integer aPrimitiveIdx = myBVHPrimIndexes->Value (theElemIdx);
if (mySensType == Select3D_TOS_BOUNDARY) if (mySensType == Select3D_TOS_BOUNDARY)
{ {
const gp_Pnt& aSegmPnt1 = myTriangul->Nodes().Value (myFreeEdges->Value (aPrimitiveIdx * 2 + 1)); const gp_Pnt& aSegmPnt1 = myTriangul->Node (myFreeEdges->Value (aPrimitiveIdx * 2 + 1));
const gp_Pnt& aSegmPnt2 = myTriangul->Nodes().Value (myFreeEdges->Value (aPrimitiveIdx * 2 + 2)); const gp_Pnt& aSegmPnt2 = myTriangul->Node (myFreeEdges->Value (aPrimitiveIdx * 2 + 2));
if (theMgr.GetActiveSelectionType() == SelectBasics_SelectingVolumeManager::Polyline) if (theMgr.GetActiveSelectionType() == SelectBasics_SelectingVolumeManager::Polyline)
{ {
SelectBasics_PickResult aDummy; SelectBasics_PickResult aDummy;
@@ -357,11 +354,11 @@ Standard_Boolean Select3D_SensitiveTriangulation::elementIsInside (SelectBasics_
else else
{ {
Standard_Integer aNode1, aNode2, aNode3; Standard_Integer aNode1, aNode2, aNode3;
myTriangul->Triangles() (aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3); myTriangul->Triangle (aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3);
const gp_Pnt& aPnt1 = myTriangul->Nodes().Value (aNode1); const gp_Pnt& aPnt1 = myTriangul->Node (aNode1);
const gp_Pnt& aPnt2 = myTriangul->Nodes().Value (aNode2); const gp_Pnt& aPnt2 = myTriangul->Node (aNode2);
const gp_Pnt& aPnt3 = myTriangul->Nodes().Value (aNode3); const gp_Pnt& aPnt3 = myTriangul->Node (aNode3);
if (theMgr.GetActiveSelectionType() == SelectBasics_SelectingVolumeManager::Polyline) if (theMgr.GetActiveSelectionType() == SelectBasics_SelectingVolumeManager::Polyline)
{ {
SelectBasics_PickResult aDummy; SelectBasics_PickResult aDummy;
@@ -435,12 +432,12 @@ Select3D_BndBox3d Select3D_SensitiveTriangulation::BoundingBox()
if (myBndBox.IsValid()) if (myBndBox.IsValid())
return applyTransformation(); return applyTransformation();
const Standard_Integer aLower = myTriangul->Nodes().Lower(); const Standard_Integer aLower = 1;
const Standard_Integer anUpper = myTriangul->Nodes().Upper(); const Standard_Integer anUpper = myTriangul->NbNodes();
Select3D_BndBox3d aBndBox; Select3D_BndBox3d aBndBox;
for (Standard_Integer aNodeIdx = aLower; aNodeIdx <= anUpper; ++aNodeIdx) for (Standard_Integer aNodeIdx = aLower; aNodeIdx <= anUpper; ++aNodeIdx)
{ {
const gp_Pnt& aNode = myTriangul->Nodes().Value (aNodeIdx); const gp_Pnt& aNode = myTriangul->Node (aNodeIdx);
const SelectMgr_Vec3 aNodeTransf = SelectMgr_Vec3 (aNode.X(), aNode.Y(), aNode.Z()); const SelectMgr_Vec3 aNodeTransf = SelectMgr_Vec3 (aNode.X(), aNode.Y(), aNode.Z());
aBndBox.Add (aNodeTransf); aBndBox.Add (aNodeTransf);
} }
@@ -466,7 +463,7 @@ gp_Pnt Select3D_SensitiveTriangulation::CenterOfGeometry() const
//======================================================================= //=======================================================================
Standard_Integer Select3D_SensitiveTriangulation::NbSubElements() const Standard_Integer Select3D_SensitiveTriangulation::NbSubElements() const
{ {
return myTriangul->Nodes().Length(); return myTriangul->NbNodes();
} }
//======================================================================= //=======================================================================

View File

@@ -198,13 +198,31 @@ ShapePersistent_Poly::Translate(const Handle(Poly_Triangulation)& thePolyTriang,
{ {
aPT = new Triangulation; aPT = new Triangulation;
aPT->myPersistent = new pTriangulation; aPT->myPersistent = new pTriangulation;
// Create an array of nodes.
Standard_Integer i;
TColgp_Array1OfPnt pArrayOfNodes (1, thePolyTriang->NbNodes());
for (i = 1; i <= thePolyTriang->NbNodes(); i++)
pArrayOfNodes.SetValue (i, thePolyTriang->Node (i));
// Create an array of triangles.
Poly_Array1OfTriangle pArrayOfTriangles (1, thePolyTriang->NbTriangles());
for (i = 1; i <= thePolyTriang->NbTriangles(); i++)
pArrayOfTriangles.SetValue (i, thePolyTriang->Triangle (i));
aPT->myPersistent->myNodes = aPT->myPersistent->myNodes =
StdLPersistent_HArray1::Translate<TColgp_HArray1OfPnt>("PColgp_HArray1OfPnt", thePolyTriang->Nodes()); StdLPersistent_HArray1::Translate<TColgp_HArray1OfPnt>("PColgp_HArray1OfPnt", pArrayOfNodes);
aPT->myPersistent->myTriangles = aPT->myPersistent->myTriangles =
StdLPersistent_HArray1::Translate<Poly_HArray1OfTriangle>("PPoly_HArray1OfTriangle", thePolyTriang->Triangles()); StdLPersistent_HArray1::Translate<Poly_HArray1OfTriangle>("PPoly_HArray1OfTriangle", pArrayOfTriangles);
if (thePolyTriang->HasUVNodes()) { if (thePolyTriang->HasUVNodes()) {
// Create an array of UV-nodes.
TColgp_Array1OfPnt2d pArrayOfUVNodes (1, thePolyTriang->NbNodes());
for (i = 1; i <= thePolyTriang->NbNodes(); i++)
pArrayOfUVNodes.SetValue (i, thePolyTriang->UVNode (i));
aPT->myPersistent->myUVNodes = aPT->myPersistent->myUVNodes =
StdLPersistent_HArray1::Translate<TColgp_HArray1OfPnt2d>("PColgp_HArray1OfPnt2d", thePolyTriang->UVNodes()); StdLPersistent_HArray1::Translate<TColgp_HArray1OfPnt2d>("PColgp_HArray1OfPnt2d", pArrayOfUVNodes);
} }
theMap.Bind(thePolyTriang, aPT); theMap.Bind(thePolyTriang, aPT);
} }

View File

@@ -253,9 +253,6 @@ void StdPrs_Isolines::addOnTriangulation (const Handle(Poly_Triangulation)& theT
Prs3d_NListOfSequenceOfPnt& theUPolylines, Prs3d_NListOfSequenceOfPnt& theUPolylines,
Prs3d_NListOfSequenceOfPnt& theVPolylines) 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) for (Standard_Integer anUVIter = 0; anUVIter < 2; ++anUVIter)
{ {
const Standard_Boolean isUIso = anUVIter == 0; 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)); 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]; Standard_Integer aNodeIdxs[3];
aTriangles.Value (aTriIter).Get (aNodeIdxs[0], aNodeIdxs[1],aNodeIdxs[2]); theTriangulation->Triangle (aTriIter).Get (aNodeIdxs[0], aNodeIdxs[1],aNodeIdxs[2]);
const gp_Pnt aNodesXYZ[3] = { aNodes.Value (aNodeIdxs[0]), const gp_Pnt aNodesXYZ[3] = { theTriangulation->Node (aNodeIdxs[0]),
aNodes.Value (aNodeIdxs[1]), theTriangulation->Node (aNodeIdxs[1]),
aNodes.Value (aNodeIdxs[2]) }; theTriangulation->Node (aNodeIdxs[2]) };
const gp_Pnt2d aNodesUV[3] = { aUVNodes.Value (aNodeIdxs[0]), const gp_Pnt2d aNodesUV[3] = { theTriangulation->UVNode (aNodeIdxs[0]),
aUVNodes.Value (aNodeIdxs[1]), theTriangulation->UVNode (aNodeIdxs[1]),
aUVNodes.Value (aNodeIdxs[2]) }; theTriangulation->UVNode (aNodeIdxs[2]) };
// Find intersections with triangle in uv space and its projection on triangulation. // Find intersections with triangle in uv space and its projection on triangulation.
SegOnIso aSegment; SegOnIso aSegment;

View File

@@ -188,14 +188,10 @@ namespace
// Determinant of transform matrix less then 0 means that mirror transform applied. // Determinant of transform matrix less then 0 means that mirror transform applied.
Standard_Boolean isMirrored = aTrsf.VectorialPart().Determinant() < 0; Standard_Boolean isMirrored = aTrsf.VectorialPart().Determinant() < 0;
Poly_Connect aPolyConnect (aT);
// Extracts vertices & normals from nodes // Extracts vertices & normals from nodes
const TColgp_Array1OfPnt& aNodes = aT->Nodes(); TColgp_Array1OfDir aNormals (1, aT->NbNodes());
const TColgp_Array1OfPnt2d* aUVNodes = theHasTexels && aT->HasUVNodes() && aT->UVNodes().Upper() == aNodes.Upper() StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
? &aT->UVNodes()
: NULL;
StdPrs_ToolTriangulatedShape::ComputeNormals (aFace, aT);
const TShort_Array1OfShortReal& aNormals = aT->Normals();
const Standard_ShortReal* aNormArr = &aNormals.First();
if (theHasTexels) if (theHasTexels)
{ {
@@ -205,11 +201,10 @@ namespace
} }
const Standard_Integer aDecal = anArray->VertexNumber(); 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); aPoint = aT->Node (aNodeIter);
const Standard_Integer anId = 3 * (aNodeIter - aNodes.Lower()); gp_Dir aNorm = aNormals (aNodeIter);
gp_Dir aNorm (aNormArr[anId + 0], aNormArr[anId + 1], aNormArr[anId + 2]);
if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored) if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored)
{ {
aNorm.Reverse(); aNorm.Reverse();
@@ -220,12 +215,12 @@ namespace
aNorm.Transform (aTrsf); aNorm.Transform (aTrsf);
} }
if (aUVNodes != NULL) if (theHasTexels && aT->HasUVNodes())
{ {
const gp_Pnt2d aTexel = (dUmax == 0.0 || dVmax == 0.0) const gp_Pnt2d aTexel = (dUmax == 0.0 || dVmax == 0.0)
? aUVNodes->Value (aNodeIter) ? aT->UVNode (aNodeIter)
: gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aUVNodes->Value (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(), : gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aT->UVNode (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(),
(-theUVOrigin.Y() + (theUVRepeat.Y() * (aUVNodes->Value (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y()); (-theUVOrigin.Y() + (theUVRepeat.Y() * (aT->UVNode (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y());
anArray->AddVertex (aPoint, aNorm, aTexel); anArray->AddVertex (aPoint, aNorm, aTexel);
} }
else else
@@ -235,22 +230,21 @@ namespace
} }
// Fill array with vertex and edge visibility info // Fill array with vertex and edge visibility info
const Poly_Array1OfTriangle& aTriangles = aT->Triangles();
Standard_Integer anIndex[3]; Standard_Integer anIndex[3];
for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter) for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter)
{ {
if ((aFace.Orientation() == TopAbs_REVERSED)) 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 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 aP1 = aT->Node (anIndex[0]);
gp_Pnt aP2 = aNodes (anIndex[1]); gp_Pnt aP2 = aT->Node (anIndex[1]);
gp_Pnt aP3 = aNodes (anIndex[2]); gp_Pnt aP3 = aT->Node (anIndex[2]);
gp_Vec aV1 (aP1, aP2); gp_Vec aV1 (aP1, aP2);
if (aV1.SquareMagnitude() <= aPreci) if (aV1.SquareMagnitude() <= aPreci)
@@ -415,7 +409,6 @@ namespace
} }
// get edge nodes indexes from face triangulation // get edge nodes indexes from face triangulation
const TColgp_Array1OfPnt& aTriNodes = aTriangulation->Nodes();
const TColStd_Array1OfInteger& anEdgeNodes = anEdgePoly->Nodes(); const TColStd_Array1OfInteger& anEdgeNodes = anEdgePoly->Nodes();
// collect the edge nodes // collect the edge nodes
@@ -425,7 +418,7 @@ namespace
// node index in face triangulation // node index in face triangulation
// get node and apply location transformation to the node // get node and apply location transformation to the node
const Standard_Integer aTriIndex = anEdgeNodes.Value (aNodeIdx); const Standard_Integer aTriIndex = anEdgeNodes.Value (aNodeIdx);
gp_Pnt aTriNode = aTriNodes.Value (aTriIndex); gp_Pnt aTriNode = aTriangulation->Node (aTriIndex);
if (!aTrsf.IsIdentity()) if (!aTrsf.IsIdentity())
{ {
aTriNode.Transform (aTrsf); aTriNode.Transform (aTrsf);

View File

@@ -149,7 +149,6 @@ void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace,
// take in face the surface location // take in face the surface location
const TopoDS_Face aZeroFace = TopoDS::Face (theFace.Located (TopLoc_Location())); const TopoDS_Face aZeroFace = TopoDS::Face (theFace.Located (TopLoc_Location()));
Handle(Geom_Surface) aSurf = BRep_Tool::Surface (aZeroFace); Handle(Geom_Surface) aSurf = BRep_Tool::Surface (aZeroFace);
const Poly_Array1OfTriangle& aTriangles = theTris->Triangles();
if (!theTris->HasUVNodes() || aSurf.IsNull()) if (!theTris->HasUVNodes() || aSurf.IsNull())
{ {
// compute normals by averaging triangulation normals sharing the same vertex // compute normals by averaging triangulation normals sharing the same vertex
@@ -158,15 +157,12 @@ void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace,
} }
const Standard_Real aTol = Precision::Confusion(); 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]; Standard_Integer aTri[3];
const TColgp_Array1OfPnt& aNodes = theTris->Nodes();
gp_Dir aNorm; gp_Dir aNorm;
for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) for (Standard_Integer aNodeIter = 1; aNodeIter <= theTris->NbNodes(); ++aNodeIter)
{ {
// try to retrieve normal from real surface first, when UV coordinates are available // 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) if (thePolyConnect.Triangulation() != theTris)
{ {
@@ -177,9 +173,9 @@ void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace,
gp_XYZ eqPlan (0.0, 0.0, 0.0); gp_XYZ eqPlan (0.0, 0.0, 0.0);
for (thePolyConnect.Initialize (aNodeIter); thePolyConnect.More(); thePolyConnect.Next()) for (thePolyConnect.Initialize (aNodeIter); thePolyConnect.More(); thePolyConnect.Next())
{ {
aTriangles (thePolyConnect.Value()).Get (aTri[0], aTri[1], aTri[2]); theTris->Triangle (thePolyConnect.Value()).Get (aTri[0], aTri[1], aTri[2]);
const gp_XYZ v1 (aNodes (aTri[1]).Coord() - aNodes (aTri[0]).Coord()); const gp_XYZ v1 (theTris->Node (aTri[1]).Coord() - theTris->Node (aTri[0]).Coord());
const gp_XYZ v2 (aNodes (aTri[2]).Coord() - aNodes (aTri[1]).Coord()); const gp_XYZ v2 (theTris->Node (aTri[2]).Coord() - theTris->Node (aTri[1]).Coord());
const gp_XYZ vv = v1 ^ v2; const gp_XYZ vv = v1 ^ v2;
const Standard_Real aMod = vv.Modulus(); const Standard_Real aMod = vv.Modulus();
if (aMod >= aTol) if (aMod >= aTol)
@@ -190,13 +186,10 @@ void StdPrs_ToolTriangulatedShape::ComputeNormals (const TopoDS_Face& theFace,
const Standard_Real aModMax = eqPlan.Modulus(); const Standard_Real aModMax = eqPlan.Modulus();
aNorm = (aModMax > aTol) ? gp_Dir (eqPlan) : gp::DZ(); aNorm = (aModMax > aTol) ? gp_Dir (eqPlan) : gp::DZ();
} }
theTris->SetNormal (aNodeIter, static_cast<Standard_ShortReal>(aNorm.X()),
const Standard_Integer anId = (aNodeIter - aNodes.Lower()) * 3; static_cast<Standard_ShortReal>(aNorm.Y()),
aNormals->SetValue (anId + 1, (Standard_ShortReal )aNorm.X()); static_cast<Standard_ShortReal>(aNorm.Z()));
aNormals->SetValue (anId + 2, (Standard_ShortReal )aNorm.Y());
aNormals->SetValue (anId + 3, (Standard_ShortReal )aNorm.Z());
} }
theTris->SetNormals (aNormals);
} }
//======================================================================= //=======================================================================
@@ -213,21 +206,15 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace,
ComputeNormals (theFace, aPolyTri, thePolyConnect); ComputeNormals (theFace, aPolyTri, thePolyConnect);
} }
const TColgp_Array1OfPnt& aNodes = aPolyTri->Nodes(); for (Standard_Integer aNodeIter = 1; aNodeIter <= aPolyTri->NbNodes(); ++aNodeIter)
const TShort_Array1OfShortReal& aNormals = aPolyTri->Normals();
const Standard_ShortReal* aNormArr = &aNormals.First();
for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
{ {
const Standard_Integer anId = 3 * (aNodeIter - aNodes.Lower()); const Vec3f& aNormal = aPolyTri->Normal (aNodeIter);
const gp_Dir aNorm (aNormArr[anId + 0], theNormals.ChangeValue (aNodeIter).SetCoord (aNormal.x(), aNormal.y(), aNormal.z());
aNormArr[anId + 1],
aNormArr[anId + 2]);
theNormals (aNodeIter) = aNorm;
} }
if (theFace.Orientation() == TopAbs_REVERSED) 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(); 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. // Presentation based on triangulation of a face.
const TColStd_Array1OfInteger& anIndices = anEdgeIndicies->Nodes(); const TColStd_Array1OfInteger& anIndices = anEdgeIndicies->Nodes();
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
Standard_Integer anIndex = anIndices.Lower(); Standard_Integer anIndex = anIndices.Lower();
if (aLocation.IsIdentity()) if (aLocation.IsIdentity())
{ {
for (; anIndex <= anIndices.Upper(); ++anIndex) for (; anIndex <= anIndices.Upper(); ++anIndex)
{ {
aPoints->Append (aNodes (anIndices (anIndex))); aPoints->Append (aTriangulation->Node (anIndices (anIndex)));
} }
} }
else else
{ {
for (; anIndex <= anIndices.Upper(); ++anIndex) for (; anIndex <= anIndices.Upper(); ++anIndex)
{ {
aPoints->Append (aNodes (anIndices (anIndex)).Transformed (aLocation)); aPoints->Append (aTriangulation->Node (anIndices (anIndex)).Transformed (aLocation));
} }
} }
} }

View File

@@ -350,7 +350,6 @@ static Handle(TColgp_HArray1OfPnt) GetPointsFromPolygon (const TopoDS_Edge& theE
if (!anHIndices.IsNull()) if (!anHIndices.IsNull())
{ {
const TColStd_Array1OfInteger& anIndices = anHIndices->Nodes(); const TColStd_Array1OfInteger& anIndices = anHIndices->Nodes();
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
aResultPoints = new TColgp_HArray1OfPnt (1, anIndices.Length()); aResultPoints = new TColgp_HArray1OfPnt (1, anIndices.Length());
@@ -358,14 +357,14 @@ static Handle(TColgp_HArray1OfPnt) GetPointsFromPolygon (const TopoDS_Edge& theE
{ {
for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId) for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId)
{ {
aResultPoints->SetValue (aPntId, aNodes (anIndices (anIndex))); aResultPoints->SetValue (aPntId, aTriangulation->Node (anIndices (anIndex)));
} }
} }
else else
{ {
for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId) for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId)
{ {
aResultPoints->SetValue (aPntId, aNodes (anIndices (anIndex)).Transformed (aLocation)); aResultPoints->SetValue (aPntId, aTriangulation->Node (anIndices (anIndex)).Transformed (aLocation));
} }
} }
return aResultPoints; return aResultPoints;

View File

@@ -52,20 +52,18 @@ Standard_Boolean StlAPI_Reader::Read (TopoDS_Shape& theShape,
BRep_Builder BuildTool; BRep_Builder BuildTool;
BuildTool.MakeCompound (aComp); BuildTool.MakeCompound (aComp);
const TColgp_Array1OfPnt& aNodes = aMesh->Nodes(); for (Standard_Integer aTriIdx = 1;
const Poly_Array1OfTriangle& aTriangles = aMesh->Triangles(); aTriIdx <= aMesh->NbTriangles();
for (Standard_Integer aTriIdx = aTriangles.Lower();
aTriIdx <= aTriangles.Upper();
++aTriIdx) ++aTriIdx)
{ {
const Poly_Triangle& aTriangle = aTriangles(aTriIdx); const Poly_Triangle& aTriangle = aMesh->Triangle (aTriIdx);
Standard_Integer anId[3]; Standard_Integer anId[3];
aTriangle.Get(anId[0], anId[1], anId[2]); aTriangle.Get(anId[0], anId[1], anId[2]);
const gp_Pnt& aPnt1 = aNodes (anId[0]); const gp_Pnt& aPnt1 = aMesh->Node (anId[0]);
const gp_Pnt& aPnt2 = aNodes (anId[1]); const gp_Pnt& aPnt2 = aMesh->Node (anId[1]);
const gp_Pnt& aPnt3 = aNodes (anId[2]); const gp_Pnt& aPnt3 = aMesh->Node (anId[2]);
if ((!(aPnt1.IsEqual (aPnt2, 0.0))) if ((!(aPnt1.IsEqual (aPnt2, 0.0)))
&& (!(aPnt1.IsEqual (aPnt3, 0.0)))) && (!(aPnt1.IsEqual (aPnt3, 0.0))))
{ {

View File

@@ -83,23 +83,20 @@ Standard_Boolean StlAPI_Writer::Write (const TopoDS_Shape& theShape,
continue; continue;
} }
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
// copy nodes // copy nodes
gp_Trsf aTrsf = aLoc.Transformation(); gp_Trsf aTrsf = aLoc.Transformation();
for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) for (Standard_Integer aNodeIter = 1; aNodeIter <= aTriangulation->NbNodes(); ++aNodeIter)
{ {
gp_Pnt aPnt = aNodes (aNodeIter); gp_Pnt aPnt = aTriangulation->Node (aNodeIter);
aPnt.Transform (aTrsf); aPnt.Transform (aTrsf);
aMesh->ChangeNode (aNodeIter + aNodeOffset) = aPnt; aMesh->ChangeNode (aNodeIter + aNodeOffset) = aPnt;
} }
// copy triangles // copy triangles
const TopAbs_Orientation anOrientation = anExpSF.Current().Orientation(); const TopAbs_Orientation anOrientation = anExpSF.Current().Orientation();
for (Standard_Integer aTriIter = aTriangles.Lower(); aTriIter <= aTriangles.Upper(); ++aTriIter) for (Standard_Integer aTriIter = 1; aTriIter <= aTriangulation->NbTriangles(); ++aTriIter)
{ {
Poly_Triangle aTri = aTriangles (aTriIter); Poly_Triangle aTri = aTriangulation->Triangle (aTriIter);
Standard_Integer anId[3]; Standard_Integer anId[3];
aTri.Get (anId[0], anId[1], anId[2]); aTri.Get (anId[0], anId[1], anId[2]);
@@ -120,8 +117,8 @@ Standard_Boolean StlAPI_Writer::Write (const TopoDS_Shape& theShape,
aMesh->ChangeTriangle (aTriIter + aTriangleOffet) = aTri; aMesh->ChangeTriangle (aTriIter + aTriangleOffet) = aTri;
} }
aNodeOffset += aNodes.Size(); aNodeOffset += aTriangulation->NbNodes();
aTriangleOffet += aTriangles.Size(); aTriangleOffet += aTriangulation->NbTriangles();
} }
OSD_Path aPath (theFileName); OSD_Path aPath (theFileName);

View File

@@ -27,5 +27,7 @@ TDataXtd_Presentation.hxx
TDataXtd_Presentation.cxx TDataXtd_Presentation.cxx
TDataXtd_Shape.cxx TDataXtd_Shape.cxx
TDataXtd_Shape.hxx TDataXtd_Shape.hxx
TDataXtd_SurfacicMesh.cxx
TDataXtd_SurfacicMesh.hxx
TDataXtd_Triangulation.cxx TDataXtd_Triangulation.cxx
TDataXtd_Triangulation.hxx TDataXtd_Triangulation.hxx

View File

@@ -24,6 +24,7 @@
#include <TDataXtd_Point.hxx> #include <TDataXtd_Point.hxx>
#include <TDataXtd_Position.hxx> #include <TDataXtd_Position.hxx>
#include <TDataXtd_Shape.hxx> #include <TDataXtd_Shape.hxx>
#include <TDataXtd_SurfacicMesh.hxx>
#include <TDF_IDList.hxx> #include <TDF_IDList.hxx>
//======================================================================= //=======================================================================
@@ -32,16 +33,16 @@
//======================================================================= //=======================================================================
void TDataXtd::IDList(TDF_IDList& anIDList) void TDataXtd::IDList(TDF_IDList& anIDList)
{ {
anIDList.Append(TDataXtd_Axis::GetID()); anIDList.Append (TDataXtd_Axis::GetID());
anIDList.Append(TDataXtd_Constraint::GetID()); anIDList.Append (TDataXtd_Constraint::GetID());
anIDList.Append(TDataXtd_Geometry::GetID()); anIDList.Append (TDataXtd_Geometry::GetID());
anIDList.Append(TDataXtd_PatternStd::GetID()); anIDList.Append (TDataXtd_PatternStd::GetID());
anIDList.Append(TDataXtd_Placement::GetID()); anIDList.Append (TDataXtd_Placement::GetID());
anIDList.Append(TDataXtd_Point::GetID()); anIDList.Append (TDataXtd_Point::GetID());
anIDList.Append(TDataXtd_Plane::GetID()); anIDList.Append (TDataXtd_Plane::GetID());
anIDList.Append(TDataXtd_Position::GetID()); anIDList.Append (TDataXtd_Position::GetID());
anIDList.Append(TDataXtd_Shape::GetID()); anIDList.Append (TDataXtd_Shape::GetID());
anIDList.Append (TDataXtd_SurfacicMesh::GetID());
} }
//======================================================================= //=======================================================================

View File

@@ -217,27 +217,16 @@ void TDataXtd_Triangulation::SetTriangle (const Standard_Integer theIndex, const
myTriangulation->ChangeTriangle(theIndex) = theTriangle; myTriangulation->ChangeTriangle(theIndex) = theTriangle;
} }
//=======================================================================
//function : SetNormals
//purpose : Sets the table of node normals.
// Raises exception if length of theNormals = 3 * NbNodes
//=======================================================================
void TDataXtd_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals)
{
Backup();
myTriangulation->SetNormals(theNormals);
}
//======================================================================= //=======================================================================
//function : SetNormal //function : SetNormal
//purpose : Changes normal at the given index. //purpose : Changes normal at the given index.
// Raises Standard_OutOfRange exception. // Raises Standard_OutOfRange exception.
//======================================================================= //=======================================================================
void TDataXtd_Triangulation::SetNormal (const Standard_Integer theIndex, void TDataXtd_Triangulation::SetNormal (const Standard_Integer theIndex,
const gp_Dir& theNormal) const gp_Dir& theNormal)
{ {
Backup(); Backup();
myTriangulation->SetNormal(theIndex, theNormal); myTriangulation->SetNormal (theIndex, theNormal.XYZ());
} }
//======================================================================= //=======================================================================
@@ -256,7 +245,9 @@ Standard_Boolean TDataXtd_Triangulation::HasNormals() const
//======================================================================= //=======================================================================
const gp_Dir TDataXtd_Triangulation::Normal (const Standard_Integer theIndex) const const gp_Dir TDataXtd_Triangulation::Normal (const Standard_Integer theIndex) const
{ {
return myTriangulation->Normal(theIndex); const Vec3f& aVec = myTriangulation->Normal (theIndex);
gp_Dir aDir (aVec.x(), aVec.y(), aVec.z());
return aDir;
} }
//======================================================================= //=======================================================================

View File

@@ -123,10 +123,6 @@ public:
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
Standard_EXPORT void SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle); Standard_EXPORT void SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle);
//! Sets the table of node normals.
//! Raises exception if length of theNormals != 3 * NbNodes
Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals);
//! Changes normal at the given index. //! Changes normal at the given index.
//! Raises Standard_OutOfRange exception. //! Raises Standard_OutOfRange exception.
Standard_EXPORT void SetNormal (const Standard_Integer theIndex, Standard_EXPORT void SetNormal (const Standard_Integer theIndex,

View File

@@ -2826,14 +2826,12 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
} }
Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false); Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
if ( mStartPhi <= 0.0 ){ if ( mStartPhi <= 0.0 ){
x[0] = mCenter[0]; x[0] = mCenter[0];
x[1] = mCenter[1]; x[1] = mCenter[1];
x[2] = mCenter[2] + mRadius; x[2] = mCenter[2] + mRadius;
PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2])); polyTriangulation->ChangeNode (1) = gp_Pnt (x[0],x[1],x[2]);
} }
// Create south pole if needed // Create south pole if needed
@@ -2841,7 +2839,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
x[0] = mCenter[0]; x[0] = mCenter[0];
x[1] = mCenter[1]; x[1] = mCenter[1];
x[2] = mCenter[2] - mRadius; x[2] = mCenter[2] - mRadius;
PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2])); polyTriangulation->ChangeNode (2) = gp_Pnt (x[0],x[1],x[2]);
} }
number_point = 3; number_point = 3;
@@ -2856,7 +2854,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
x[0] = n[0] + mCenter[0]; x[0] = n[0] + mCenter[0];
x[1] = n[1] + mCenter[1]; x[1] = n[1] + mCenter[1];
x[2] = n[2] + mCenter[2]; x[2] = n[2] + mCenter[2];
PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2])); polyTriangulation->ChangeNode (number_point) = gp_Pnt (x[0],x[1],x[2]);
number_point++; number_point++;
} }
} }
@@ -2868,7 +2866,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
pts[0] = phiResolution*i + numPoles; pts[0] = phiResolution*i + numPoles;
pts[1] = (phiResolution*(i+1) % base) + numPoles; pts[1] = (phiResolution*(i+1) % base) + numPoles;
pts[2] = 1; pts[2] = 1;
pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); polyTriangulation->ChangeTriangle (number_triangle) = Poly_Triangle (pts[0],pts[1],pts[2]);
number_triangle++; number_triangle++;
} }
} }
@@ -2879,7 +2877,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
pts[0] = phiResolution*i + numOffset; pts[0] = phiResolution*i + numOffset;
pts[2] = ((phiResolution*(i+1)) % base) + numOffset; pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
pts[1] = numPoles - 1; pts[1] = numPoles - 1;
pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); polyTriangulation->ChangeTriangle (number_triangle) = Poly_Triangle (pts[0],pts[1],pts[2]);
number_triangle++; number_triangle++;
} }
} }
@@ -2891,29 +2889,27 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
pts[0] = phiResolution*i + j + numPoles; pts[0] = phiResolution*i + j + numPoles;
pts[1] = pts[0] + 1; pts[1] = pts[0] + 1;
pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1; pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); polyTriangulation->ChangeTriangle (number_triangle) = Poly_Triangle (pts[0],pts[1],pts[2]);
number_triangle++; number_triangle++;
pts[1] = pts[2]; pts[1] = pts[2];
pts[2] = pts[1] - 1; pts[2] = pts[1] - 1;
pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); polyTriangulation->ChangeTriangle (number_triangle) = Poly_Triangle (pts[0],pts[1],pts[2]);
number_triangle++; number_triangle++;
} }
} }
Poly_Connect* pc = new Poly_Connect(polyTriangulation); Poly_Connect* pc = new Poly_Connect(polyTriangulation);
Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
Standard_Integer index[3]; Standard_Integer index[3];
Standard_Real Tol = Precision::Confusion(); Standard_Real Tol = Precision::Confusion();
gp_Dir Nor; gp_Dir Nor;
for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) { for (i = 1; i <= polyTriangulation->NbNodes(); i++) {
gp_XYZ eqPlan(0, 0, 0); gp_XYZ eqPlan(0, 0, 0);
for ( pc->Initialize(i); pc->More(); pc->Next()) { for ( pc->Initialize(i); pc->More(); pc->Next()) {
pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]); polyTriangulation->Triangle (pc->Value()).Get (index[0], index[1], index[2]);
gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord()); gp_XYZ v1 (polyTriangulation->Node (index[1]).Coord() - polyTriangulation->Node (index[0]).Coord());
gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord()); gp_XYZ v2 (polyTriangulation->Node (index[2]).Coord() - polyTriangulation->Node (index[1]).Coord());
gp_XYZ vv = v1^v2; gp_XYZ vv = v1^v2;
Standard_Real mod = vv.Modulus(); Standard_Real mod = vv.Modulus();
if(mod < Tol) continue; if(mod < Tol) continue;
@@ -2926,16 +2922,11 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
Nor = gp_Dir(eqPlan); Nor = gp_Dir(eqPlan);
else else
Nor = gp_Dir(0., 0., 1.); Nor = gp_Dir(0., 0., 1.);
Standard_Integer k = (i - PointsOfArray.Lower()) * 3; polyTriangulation->SetNormal (i, Nor.XYZ());
Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
} }
delete pc; delete pc;
polyTriangulation->SetNormals(Normals);
return polyTriangulation; return polyTriangulation;
} }
@@ -2979,8 +2970,8 @@ static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const c
= new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ, = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
aResolution, aResolution,
aRadius)); aRadius));
Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length(); Standard_Integer aNumberPoints = aShape->GetTriangulation()->NbNodes();
Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length(); Standard_Integer aNumberTriangles = aShape->GetTriangulation()->NbTriangles();
// stupid initialization of Green color in RGBA space as integer // stupid initialization of Green color in RGBA space as integer
// probably wrong for big-endian CPUs // probably wrong for big-endian CPUs
@@ -6410,20 +6401,19 @@ static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
continue; continue;
} }
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
const gp_Trsf& aTrsf = aLocation.Transformation(); const gp_Trsf& aTrsf = aLocation.Transformation();
// extract normals from nodes // extract normals from nodes
TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower()); TColgp_Array1OfDir aNormals (1, hasNormals ? aTriangulation->NbNodes() : 1);
if (hasNormals) if (hasNormals)
{ {
Poly_Connect aPolyConnect (aTriangulation); Poly_Connect aPolyConnect (aTriangulation);
StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals); StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
} }
for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) for (Standard_Integer aNodeIter = 1; aNodeIter <= aTriangulation->NbNodes(); ++aNodeIter)
{ {
gp_Pnt aPoint = aNodes (aNodeIter); gp_Pnt aPoint = aTriangulation->Node (aNodeIter);
if (!aLocation.IsIdentity()) if (!aLocation.IsIdentity())
{ {
aPoint.Transform (aTrsf); aPoint.Transform (aTrsf);

View File

@@ -84,22 +84,18 @@ void VrmlConverter_ShadedShape::Add( Standard_OStream& anOStream,
// number of triangles: // number of triangles:
if (T.IsNull()) continue; //smh if (T.IsNull()) continue; //smh
nnn = T->NbTriangles(); nnn = T->NbTriangles();
const TColgp_Array1OfPnt& Nodes = T->Nodes();
// getting a triangle. It is a triplet of indices in the node table:
const Poly_Array1OfTriangle& triangles = T->Triangles();
// Taking the nodes of the triangle, taking into account the orientation // Taking the nodes of the triangle, taking into account the orientation
// of the triangle. // of the triangle.
for (nt = 1; nt <= nnn; nt++) { for (nt = 1; nt <= nnn; nt++) {
if (F.Orientation() == TopAbs_REVERSED) if (F.Orientation() == TopAbs_REVERSED)
triangles(nt).Get(n1,n3,n2); T->Triangle (nt).Get (n1,n3,n2);
else else
triangles(nt).Get(n1,n2,n3); T->Triangle (nt).Get (n1,n2,n3);
const gp_Pnt& P1 = Nodes(n1); const gp_Pnt& P1 = T->Node (n1);
const gp_Pnt& P2 = Nodes(n2); const gp_Pnt& P2 = T->Node (n2);
const gp_Pnt& P3 = Nodes(n3); const gp_Pnt& P3 = T->Node (n3);
// controlling whether the triangle correct from a 3d point of // controlling whether the triangle correct from a 3d point of
// view: (the triangle may exist in the UV space but the // view: (the triangle may exist in the UV space but the
// in the 3d space a dimension is null for example) // in the 3d space a dimension is null for example)
@@ -160,13 +156,12 @@ void VrmlConverter_ShadedShape::Add( Standard_OStream& anOStream,
// 1 - Building HAV1 - array of all XYZ of nodes for Vrml_Coordinate3 from the triangles // 1 - Building HAV1 - array of all XYZ of nodes for Vrml_Coordinate3 from the triangles
// and HAV2 - array of all normals of nodes for Vrml_Normal // and HAV2 - array of all normals of nodes for Vrml_Normal
const TColgp_Array1OfPnt& Nodes = T->Nodes(); TColgp_Array1OfDir NORMAL(1, T->NbNodes());
TColgp_Array1OfDir NORMAL(Nodes.Lower(), Nodes.Upper());
decal = nnv-1; decal = nnv-1;
for (j= Nodes.Lower(); j<= Nodes.Upper(); j++) { for (j= 1; j<= T->NbNodes(); j++) {
p = Nodes(j).Transformed(theLocation.Transformation()); p = T->Node (j).Transformed (theLocation.Transformation());
V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z()); V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z());
HAV1->SetValue(nnv,V); HAV1->SetValue(nnv,V);
@@ -185,16 +180,15 @@ void VrmlConverter_ShadedShape::Add( Standard_OStream& anOStream,
// 2 - Building HAI1 - array of indexes of all triangles and // 2 - Building HAI1 - array of indexes of all triangles and
// HAI3 - array of indexes of all normales for Vrml_IndexedFaceSet // HAI3 - array of indexes of all normales for Vrml_IndexedFaceSet
nbTriangles = T->NbTriangles(); nbTriangles = T->NbTriangles();
const Poly_Array1OfTriangle& triangles = T->Triangles();
for (i = 1; i <= nbTriangles; i++) { for (i = 1; i <= nbTriangles; i++) {
pc.Triangles(i,t[0],t[1],t[2]); pc.Triangles(i,t[0],t[1],t[2]);
if (F.Orientation() == TopAbs_REVERSED) if (F.Orientation() == TopAbs_REVERSED)
triangles(i).Get(n[0],n[2],n[1]); T->Triangle (i).Get (n[0],n[2],n[1]);
else else
triangles(i).Get(n[0],n[1],n[2]); T->Triangle (i).Get (n[0],n[1],n[2]);
const gp_Pnt& P1 = Nodes(n[0]); const gp_Pnt& P1 = T->Node (n[0]);
const gp_Pnt& P2 = Nodes(n[1]); const gp_Pnt& P2 = T->Node (n[1]);
const gp_Pnt& P3 = Nodes(n[2]); const gp_Pnt& P3 = T->Node (n[2]);
gp_Vec V1(P1,P2); gp_Vec V1(P1,P2);
if (V1.SquareMagnitude() > 1.e-10) { if (V1.SquareMagnitude() > 1.e-10) {
gp_Vec V2(P2,P3); gp_Vec V2(P2,P3);
@@ -389,10 +383,9 @@ void VrmlConverter_ShadedShape::ComputeNormal(const TopoDS_Face& aFace,
CSLib_DerivativeStatus aStatus; CSLib_DerivativeStatus aStatus;
CSLib_NormalStatus NStat; CSLib_NormalStatus NStat;
S.Initialize(aFace); S.Initialize(aFace);
const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes(); for (i = 1; i <= T->NbNodes(); i++) {
for (i = UVNodes.Lower(); i <= UVNodes.Upper(); i++) { U = T->UVNode (i).X();
U = UVNodes(i).X(); V = T->UVNode (i).Y();
V = UVNodes(i).Y();
S.D1(U,V,P,D1U,D1V); S.D1(U,V,P,D1U,D1V);
CSLib::Normal(D1U,D1V,Precision::Angular(),aStatus,Nor(i)); CSLib::Normal(D1U,D1V,Precision::Angular(),aStatus,Nor(i));
if (aStatus != CSLib_Done) { if (aStatus != CSLib_Done) {
@@ -403,16 +396,14 @@ void VrmlConverter_ShadedShape::ComputeNormal(const TopoDS_Face& aFace,
} }
} }
else { else {
const TColgp_Array1OfPnt& Nodes = T->Nodes();
Standard_Integer n[3]; Standard_Integer n[3];
const Poly_Array1OfTriangle& triangles = T->Triangles();
for (i = Nodes.Lower(); i <= Nodes.Upper(); i++) { for (i = 1; i <= T->NbNodes(); i++) {
gp_XYZ eqPlan(0, 0, 0); gp_XYZ eqPlan(0, 0, 0);
for (pc.Initialize(i); pc.More(); pc.Next()) { for (pc.Initialize(i); pc.More(); pc.Next()) {
triangles(pc.Value()).Get(n[0], n[1], n[2]); T->Triangle (pc.Value()).Get (n[0], n[1], n[2]);
gp_XYZ v1(Nodes(n[1]).Coord()-Nodes(n[0]).Coord()); gp_XYZ v1 (T->Node (n[1]).Coord() - T->Node (n[0]).Coord());
gp_XYZ v2(Nodes(n[2]).Coord()-Nodes(n[1]).Coord()); gp_XYZ v2 (T->Node (n[2]).Coord() - T->Node (n[1]).Coord());
eqPlan += (v1^v2).Normalized(); eqPlan += (v1^v2).Normalized();
} }
Nor(i) = gp_Dir(eqPlan); Nor(i) = gp_Dir(eqPlan);

View File

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

View File

@@ -330,21 +330,19 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
Standard_Integer i; Standard_Integer i;
const Standard_Integer nNodes (theTri->NbNodes()); const Standard_Integer nNodes (theTri->NbNodes());
const Standard_Integer nTriangles (theTri->NbTriangles()); const Standard_Integer nTriangles (theTri->NbTriangles());
const TColgp_Array1OfPnt& arrPolyNodes = theTri->Nodes();
const Poly_Array1OfTriangle& arrTriangles = theTri->Triangles();
// protection against creation degenerative triangles // protection against creation degenerative triangles
Standard_Integer nbTri = 0; Standard_Integer nbTri = 0;
Poly_Array1OfTriangle aTriangles(1, nTriangles); Poly_Array1OfTriangle aTriangles(1, nTriangles);
for (i = 0; i < nTriangles; i++) { for (i = 0; i < nTriangles; i++) {
Standard_Integer idx[3]; 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]) if (idx[0] == idx[1] || idx[0] == idx[2] || idx[1] == idx[2])
{ {
continue; continue;
} }
nbTri++; nbTri++;
aTriangles.SetValue(nbTri, arrTriangles(i + 1)); aTriangles.SetValue (nbTri, theTri->Triangle (i + 1));
} }
aTriangles.Resize(1, nbTri, Standard_True); aTriangles.Resize(1, nbTri, Standard_True);
@@ -387,7 +385,7 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
gp_XYZ * arrNodes = static_cast <gp_XYZ *> gp_XYZ * arrNodes = static_cast <gp_XYZ *>
(anAlloc->Allocate (nNodes * sizeof(gp_XYZ))); (anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
for (i = 0; i < nNodes; i++) 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 = const Handle(VrmlData_Coordinate) aCoordNode =
new VrmlData_Coordinate (myScene, 0L, nNodes, arrNodes); new VrmlData_Coordinate (myScene, 0L, nNodes, arrNodes);
@@ -399,11 +397,11 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
if(theTri->HasNormals()) { if(theTri->HasNormals()) {
gp_XYZ * arrVec = static_cast <gp_XYZ *> gp_XYZ * arrVec = static_cast <gp_XYZ *>
(anAlloc->Allocate (nNodes * sizeof(gp_XYZ))); (anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
const TShort_Array1OfShortReal& Norm = theTri->Normals();
Standard_Integer j; Standard_Integer j;
for (i = 0, j = 1; i < nNodes; i++, j += 3) for (i = 0, j = 1; i < nNodes; i++, j += 3)
{ {
gp_XYZ aNormal(Norm(j), Norm(j+1), Norm(j+2)); const Vec3f& aVec = theTri->Normal (i + 1);
gp_XYZ aNormal (aVec.x(), aVec.y(), aVec.z());
if (isReverse) if (isReverse)
{ {
aNormal.Reverse(); aNormal.Reverse();
@@ -429,14 +427,13 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
Handle(TShort_HArray1OfShortReal) Normals = Handle(TShort_HArray1OfShortReal) Normals =
new TShort_HArray1OfShortReal(1, nbNormVal); new TShort_HArray1OfShortReal(1, nbNormVal);
const TColgp_Array1OfPnt2d& arrUV = theTri->UVNodes();
gp_XYZ * arrVec = static_cast <gp_XYZ *> gp_XYZ * arrVec = static_cast <gp_XYZ *>
(anAlloc->Allocate (nNodes * sizeof(gp_XYZ))); (anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
// Compute the normal vectors // Compute the normal vectors
Standard_Real Tol = Sqrt(aConf2); Standard_Real Tol = Sqrt(aConf2);
for (i = 0; i < nNodes; i++) { for (i = 0; i < nNodes; i++) {
const gp_Pnt2d& aUV = arrUV(i+1); const gp_Pnt2d& aUV = theTri->UVNode (i+1);
gp_Dir aNormal; gp_Dir aNormal;
@@ -447,8 +444,8 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
gp_XYZ eqPlan(0., 0., 0.); gp_XYZ eqPlan(0., 0., 0.);
for (PC.Initialize(i+1); PC.More(); PC.Next()) { for (PC.Initialize(i+1); PC.More(); PC.Next()) {
aTriangles(PC.Value()).Get(n[0], n[1], n[2]); aTriangles(PC.Value()).Get(n[0], n[1], n[2]);
gp_XYZ v1(arrPolyNodes(n[1]).Coord()-arrPolyNodes(n[0]).Coord()); gp_XYZ v1 (theTri->Node (n[1]).Coord()-theTri->Node (n[0]).Coord());
gp_XYZ v2(arrPolyNodes(n[2]).Coord()-arrPolyNodes(n[1]).Coord()); gp_XYZ v2 (theTri->Node (n[2]).Coord()-theTri->Node (n[1]).Coord());
gp_XYZ vv = v1^v2; gp_XYZ vv = v1^v2;
Standard_Real mod = vv.Modulus(); Standard_Real mod = vv.Modulus();
@@ -470,16 +467,10 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
aNormal.SetY(0.); aNormal.SetY(0.);
if (aNormal.Z()*aNormal.Z() < aConf2) if (aNormal.Z()*aNormal.Z() < aConf2)
aNormal.SetZ(0.); aNormal.SetZ(0.);
arrVec[i] = aNormal.XYZ(); arrVec[i] = aNormal.XYZ();
theTri->SetNormal (i + 1, 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 = const Handle(VrmlData_Normal) aNormalNode =
new VrmlData_Normal (myScene, 0L, nNodes, arrVec); new VrmlData_Normal (myScene, 0L, nNodes, arrVec);

View File

@@ -146,24 +146,22 @@ static Standard_Real CalculVolume(const TopoDS_Shape& So,
facing = BRep_Tool::Triangulation(F,L); facing = BRep_Tool::Triangulation(F,L);
} }
TColgp_Array1OfPnt tab(1,(facing->NbNodes()));
tab = facing->Nodes();
Poly_Array1OfTriangle tri(1,facing->NbTriangles());
tri = facing->Triangles();
for (Standard_Integer i=1;i<=(facing->NbTriangles());i++) for (Standard_Integer i=1;i<=(facing->NbTriangles());i++)
{ {
Poly_Triangle trian = tri.Value(i); Poly_Triangle trian = facing->Triangle (i);
Standard_Integer index1,index2,index3;//M,N; Standard_Integer index1,index2,index3;//M,N;
if( F.Orientation() == TopAbs_REVERSED ) if( F.Orientation() == TopAbs_REVERSED )
trian.Get(index1,index3,index2); trian.Get(index1,index3,index2);
else else
trian.Get(index1,index2,index3); trian.Get(index1,index2,index3);
curVolume = TetraVol(aRefPoint, tab.Value(index1), curVolume = TetraVol (aRefPoint, facing->Node (index1),
tab.Value(index2), tab.Value(index3)); facing->Node (index2),
facing->Node (index3));
myVolume += curVolume; myVolume += curVolume;
curCentroid = TetraCen(aRefPoint, tab.Value(index1), curCentroid = TetraCen (aRefPoint, facing->Node (index1),
tab.Value(index2), tab.Value(index3)); facing->Node (index2),
facing->Node (index3));
localCentroid = localCentroid + curCentroid*curVolume; localCentroid = localCentroid + curCentroid*curVolume;
} }

View File

@@ -783,7 +783,7 @@ static Standard_Integer createmesh
// Hide all nodes by default // Hide all nodes by default
Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger(); Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
Standard_Integer aLen = aSTLMesh->Nodes().Length(); Standard_Integer aLen = aSTLMesh->NbNodes();
for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ ) for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ )
aNodes->ChangeMap().Add( anIndex ); aNodes->ChangeMap().Add( anIndex );
aMesh->SetHiddenNodes( aNodes ); aMesh->SetHiddenNodes( aNodes );

View File

@@ -33,8 +33,7 @@ XSDRAWSTLVRML_DataSource::XSDRAWSTLVRML_DataSource (const Handle(Poly_Triangulat
if( !myMesh.IsNull() ) if( !myMesh.IsNull() )
{ {
const TColgp_Array1OfPnt& aCoords = myMesh->Nodes(); Standard_Integer len = myMesh->NbNodes(), i, j;
Standard_Integer len = aCoords.Length(), i, j;
myNodeCoords = new TColStd_HArray2OfReal(1, len, 1, 3); myNodeCoords = new TColStd_HArray2OfReal(1, len, 1, 3);
std::cout << "Nodes : " << len << std::endl; std::cout << "Nodes : " << len << std::endl;
@@ -43,15 +42,14 @@ XSDRAWSTLVRML_DataSource::XSDRAWSTLVRML_DataSource (const Handle(Poly_Triangulat
for( i = 1; i <= len; i++ ) for( i = 1; i <= len; i++ )
{ {
myNodes.Add( i ); myNodes.Add( i );
xyz = aCoords(i).XYZ(); xyz = myMesh->Node (i).XYZ();
myNodeCoords->SetValue(i, 1, xyz.X()); myNodeCoords->SetValue(i, 1, xyz.X());
myNodeCoords->SetValue(i, 2, xyz.Y()); myNodeCoords->SetValue(i, 2, xyz.Y());
myNodeCoords->SetValue(i, 3, xyz.Z()); myNodeCoords->SetValue(i, 3, xyz.Z());
} }
const Poly_Array1OfTriangle& aSeq = myMesh->Triangles(); len = myMesh->NbTriangles();
len = aSeq.Length();
myElemNormals = new TColStd_HArray2OfReal(1, len, 1, 3); myElemNormals = new TColStd_HArray2OfReal(1, len, 1, 3);
myElemNodes = new TColStd_HArray2OfInteger(1, len, 1, 3); myElemNodes = new TColStd_HArray2OfInteger(1, len, 1, 3);
@@ -61,14 +59,14 @@ XSDRAWSTLVRML_DataSource::XSDRAWSTLVRML_DataSource (const Handle(Poly_Triangulat
{ {
myElements.Add( i ); myElements.Add( i );
const Poly_Triangle& aTri = aSeq(i); const Poly_Triangle& aTri = myMesh->Triangle (i);
Standard_Integer V[3]; Standard_Integer V[3];
aTri.Get (V[0], V[1], V[2]); aTri.Get (V[0], V[1], V[2]);
const gp_Pnt aP1 = aCoords (V[0]); const gp_Pnt& aP1 = myMesh->Node (V[0]);
const gp_Pnt aP2 = aCoords (V[1]); const gp_Pnt& aP2 = myMesh->Node (V[1]);
const gp_Pnt aP3 = aCoords (V[2]); const gp_Pnt& aP3 = myMesh->Node (V[2]);
gp_Vec aV1(aP1, aP2); gp_Vec aV1(aP1, aP2);
gp_Vec aV2(aP2, aP3); gp_Vec aV2(aP2, aP3);

View File

@@ -10,5 +10,7 @@ XmlMDataXtd_PositionDriver.hxx
XmlMDataXtd_PositionDriver.cxx XmlMDataXtd_PositionDriver.cxx
XmlMDataXtd_PresentationDriver.hxx XmlMDataXtd_PresentationDriver.hxx
XmlMDataXtd_PresentationDriver.cxx XmlMDataXtd_PresentationDriver.cxx
XmlMDataXtd_SurfacicMeshDriver.cxx
XmlMDataXtd_SurfacicMeshDriver.hxx
XmlMDataXtd_TriangulationDriver.cxx XmlMDataXtd_TriangulationDriver.cxx
XmlMDataXtd_TriangulationDriver.hxx XmlMDataXtd_TriangulationDriver.hxx

View File

@@ -21,6 +21,7 @@
#include <XmlMDataXtd_GeometryDriver.hxx> #include <XmlMDataXtd_GeometryDriver.hxx>
#include <XmlMDataXtd_PatternStdDriver.hxx> #include <XmlMDataXtd_PatternStdDriver.hxx>
#include <XmlMDataXtd_TriangulationDriver.hxx> #include <XmlMDataXtd_TriangulationDriver.hxx>
#include <XmlMDataXtd_SurfacicMeshDriver.hxx>
#include <XmlMDF_ADriverTable.hxx> #include <XmlMDF_ADriverTable.hxx>
#include <XmlMDataXtd_PresentationDriver.hxx> #include <XmlMDataXtd_PresentationDriver.hxx>
@@ -34,13 +35,14 @@ static Standard_Integer myDocumentVersion = -1;
void XmlMDataXtd::AddDrivers (const Handle(XmlMDF_ADriverTable)& aDriverTable, void XmlMDataXtd::AddDrivers (const Handle(XmlMDF_ADriverTable)& aDriverTable,
const Handle(Message_Messenger)& anMsgDrv) const Handle(Message_Messenger)& anMsgDrv)
{ {
aDriverTable->AddDriver(new XmlMDataXtd_GeometryDriver (anMsgDrv)); aDriverTable->AddDriver (new XmlMDataXtd_GeometryDriver (anMsgDrv));
aDriverTable->AddDriver(new XmlMDataXtd_ConstraintDriver (anMsgDrv)); aDriverTable->AddDriver (new XmlMDataXtd_ConstraintDriver (anMsgDrv));
aDriverTable->AddDriver(new XmlMDataXtd_PatternStdDriver (anMsgDrv)); aDriverTable->AddDriver (new XmlMDataXtd_PatternStdDriver (anMsgDrv));
aDriverTable->AddDriver(new XmlMDataXtd_TriangulationDriver (anMsgDrv)); aDriverTable->AddDriver (new XmlMDataXtd_TriangulationDriver (anMsgDrv));
aDriverTable->AddDriver (new XmlMDataXtd_SurfacicMeshDriver (anMsgDrv));
aDriverTable->AddDriver(new XmlMDataXtd_PresentationDriver (anMsgDrv)); aDriverTable->AddDriver (new XmlMDataXtd_PresentationDriver (anMsgDrv));
aDriverTable->AddDriver(new XmlMDataXtd_PositionDriver (anMsgDrv)); aDriverTable->AddDriver (new XmlMDataXtd_PositionDriver (anMsgDrv));
} }
//======================================================================= //=======================================================================

View File

@@ -0,0 +1,133 @@
// Created on: 2015-12-15
// Created by: Vlad Romashko
// Copyright (c) 2015 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.
#include <XmlMDataXtd_SurfacicMeshDriver.hxx>
#include <Message_Messenger.hxx>
#include <NCollection_LocalArray.hxx>
#include <Standard_Type.hxx>
#include <TDF_Attribute.hxx>
#include <XmlObjMgt.hxx>
#include <XmlObjMgt_Persistent.hxx>
#include <TDataXtd_SurfacicMesh.hxx>
#include <LDOM_OSStream.hxx>
#include <BRepTools_ShapeSet.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XmlMDataXtd_SurfacicMeshDriver,XmlMDF_ADriver)
IMPLEMENT_DOMSTRING (MeshString, "mesh")
IMPLEMENT_DOMSTRING (NullString, "null")
IMPLEMENT_DOMSTRING (ExistString, "exists")
//=======================================================================
//function : XmlMDataXtd_SurfacicMeshDriver
//purpose : Constructor
//=======================================================================
XmlMDataXtd_SurfacicMeshDriver::XmlMDataXtd_SurfacicMeshDriver (const Handle(Message_Messenger)& theMsgDriver)
: XmlMDF_ADriver (theMsgDriver, NULL)
{
}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) XmlMDataXtd_SurfacicMeshDriver::NewEmpty() const
{
return new TDataXtd_SurfacicMesh();
}
//=======================================================================
//function : Paste
//purpose : persistent -> transient (retrieve)
//=======================================================================
Standard_Boolean XmlMDataXtd_SurfacicMeshDriver::Paste (const XmlObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
XmlObjMgt_RRelocationTable& ) const
{
const XmlObjMgt_Element& anElement = theSource;
Handle(TDataXtd_SurfacicMesh) attrMesh = Handle(TDataXtd_SurfacicMesh)::DownCast (theTarget);
// Read the FirstIndex; if the attribute is absent initialize to 1
XmlObjMgt_DOMString aMeshStatus = anElement.getAttribute (::MeshString());
if (aMeshStatus == NULL ||
aMeshStatus.Type() != LDOMBasicString::LDOM_AsciiDoc ||
strcmp (aMeshStatus.GetString(), ::ExistString().GetString()))
{
// No mesh.
return Standard_True;
}
// Get mesh as a string.
const XmlObjMgt_DOMString& aData = XmlObjMgt::GetStringValue (anElement);
std::stringstream aStream (std::string (aData.GetString()));
// Read the mesh.
BRepTools_ShapeSet aShapeSet;
TColStd_IndexedMapOfTransient aMeshes;
aShapeSet.ReadMeshes (aStream, aMeshes);
// Set mesh.
if (!aMeshes.IsEmpty()) {
// We expect only one mesh.
Handle(Poly_Mesh) aMesh = Handle(Poly_Mesh)::DownCast (aMeshes (1));
if (!aMesh.IsNull())
attrMesh->Set (aMesh);
}
return Standard_True;
}
//=======================================================================
//function : Paste
//purpose : transient -> persistent (store)
//=======================================================================
void XmlMDataXtd_SurfacicMeshDriver::Paste (const Handle(TDF_Attribute)& theSource,
XmlObjMgt_Persistent& theTarget,
XmlObjMgt_SRelocationTable& ) const
{
const Handle(TDataXtd_SurfacicMesh) meshAttr = Handle(TDataXtd_SurfacicMesh)::DownCast (theSource);
if (meshAttr->Get().IsNull())
theTarget.Element().setAttribute (::MeshString(), ::NullString());
else
{
theTarget.Element().setAttribute (::MeshString(), ::ExistString());
// Analyse the size of the mesh
// (to allocate properly the string array).
const Handle(Poly_Mesh)& aMesh = meshAttr->Get();
Standard_Integer aSize = aMesh->NbNodes();
aSize *= 3; // 3 coordinates for a node
aSize *= 8; // 8 characters are used to represent a coordinate (double) in XML
aSize += 3 * 5 * aMesh->NbTriangles(); // space for triangles (3 integers of 5 symbols)
aSize += 4 * 5 * aMesh->NbQuads(); // space for quadrangles (4 integers of 5 symbols)
aSize *= 2; // just in case :-)
if (!aSize)
aSize = 1;
// Allocate a string stream.
LDOM_OSStream aStream (aSize);
// Write the mesh.
BRepTools_ShapeSet aShapeSet;
TColStd_IndexedMapOfTransient aMeshes;
aMeshes.Add (aMesh);
aShapeSet.WriteMeshes (aStream, aMeshes, Standard_True/*compact*/);
aStream << std::ends;
Standard_Character* aDump = (Standard_Character*) aStream.str(); // copying! Don't forget to delete it.
XmlObjMgt::SetStringValue (theTarget, aDump, Standard_True);
delete[] aDump;
}
}

View File

@@ -0,0 +1,50 @@
// Created on: 2015-12-15
// Created by: Vlad Romashko
// Copyright (c) 2015 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.
#ifndef _XmlMDataXtd_SurfacicMeshDriver_HeaderFile
#define _XmlMDataXtd_SurfacicMeshDriver_HeaderFile
#include <Standard.hxx>
#include <XmlMDF_ADriver.hxx>
#include <XmlObjMgt_RRelocationTable.hxx>
#include <XmlObjMgt_SRelocationTable.hxx>
class Message_Messenger;
class TDF_Attribute;
class XmlObjMgt_Persistent;
DEFINE_STANDARD_HANDLE(XmlMDataXtd_SurfacicMeshDriver, XmlMDF_ADriver)
//! TDataXtd_SurfacicMesh attribute XML-driver.
class XmlMDataXtd_SurfacicMeshDriver : public XmlMDF_ADriver
{
public:
Standard_EXPORT XmlMDataXtd_SurfacicMeshDriver (const Handle(Message_Messenger)& theMessageDriver);
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT Standard_Boolean Paste (const XmlObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
XmlObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE;
Standard_EXPORT void Paste (const Handle(TDF_Attribute)& theSource, XmlObjMgt_Persistent& theTarget,
XmlObjMgt_SRelocationTable& RelocTable) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(XmlMDataXtd_SurfacicMeshDriver, XmlMDF_ADriver)
};
#endif // _XmlMDataXtd_SurfacicMeshDriver_HeaderFile

View File

@@ -158,28 +158,25 @@ void XmlMDataXtd_TriangulationDriver::Paste(const Handle(TDF_Attribute)& theSour
stream << PT->Deflection() << "\n"; stream << PT->Deflection() << "\n";
// write the 3d nodes // write the 3d nodes
const TColgp_Array1OfPnt& Nodes = PT->Nodes();
for (i = 1; i <= nbNodes; i++) for (i = 1; i <= nbNodes; i++)
{ {
stream << Nodes(i).X() << " " stream << PT->Node (i).X() << " "
<< Nodes(i).Y() << " " << PT->Node (i).Y() << " "
<< Nodes(i).Z() << " "; << PT->Node (i).Z() << " ";
} }
if (PT->HasUVNodes()) if (PT->HasUVNodes())
{ {
const TColgp_Array1OfPnt2d& UVNodes = PT->UVNodes();
for (i = 1; i <= nbNodes; i++) for (i = 1; i <= nbNodes; i++)
{ {
stream << UVNodes(i).X() << " " stream << PT->UVNode (i).X() << " "
<< UVNodes(i).Y() << " "; << PT->UVNode (i).Y() << " ";
} }
} }
const Poly_Array1OfTriangle& Triangles = PT->Triangles();
for (i = 1; i <= nbTriangles; i++) for (i = 1; i <= nbTriangles; i++)
{ {
Triangles(i).Get(n1, n2, n3); PT->Triangle (i).Get (n1, n2, n3);
stream << n1 << " " stream << n1 << " "
<< n2 << " " << n2 << " "
<< n3 << " "; << n3 << " ";

47
tests/caf/basic/Z1 Normal file
View File

@@ -0,0 +1,47 @@
#INTERFACE CAF
# Basic attributes
#
# Testing attribute: TDataStd_Mesh
#
# Testing command: SetMesh
# Testing command: DumpMesh
#
puts "caf001-Z1"
set QA_DUP 0
# Make a sphere and produce triangulation
box s 100 200 300
explode s f
incmesh s_1 0.1
# Set mesh from the spherical face
NewCommand D
SetMesh D 0:1 s_1
NewCommand D
# Test Undo/Redo.
Undo D
Redo D
# Print the mesh data
set dump1 [DumpMesh D 0:1]
# Save document on disk.
set filename ${imagedir}/${casename}.cbf
SaveAs D ${filename}
# Close and open the document again.
Close D
Open ${filename} DD
# Print mesh data
set dump2 [DumpMesh DD 0:1]
Close DD
# Check data
if { ${dump1}!=${dump2} } {
puts "TDataStd_Mesh(XML) attribute: Error"
return
}
puts "TDataStd_Mesh(XML) attribute: OK"