]> OCCT Git - occt-copy.git/commitdiff
0025936: Reusable data structure for 2D tesselation (3- and 4-nodal mesh)
authorakz <akz@opencascade.com>
Thu, 8 Sep 2016 11:34:59 +0000 (14:34 +0300)
committerakz <akz@opencascade.com>
Thu, 15 Sep 2016 13:19:36 +0000 (16:19 +0300)
* Replaced all arrays in Poly_Triangulation to NCollection_Vector.
* Poly_Triangulation now does not provide access to whole arrays stored inside it. Only by one element.
* New classes Poly_Element, Poly_Mesh.
* New classes BinMDataStd_MeshDriver, XmlMDataStd_MeshDriver, TDataStd_Mesh - Mesh attribute for OCAF
* Test cases on CAD mesh attribute

78 files changed:
dox/dev_guides/upgrade/upgrade.md
src/AIS/AIS_Manipulator.cxx
src/AIS/AIS_Triangulation.cxx
src/BRepBndLib/BRepBndLib.cxx
src/BRepBuilderAPI/BRepBuilderAPI_Copy.cxx
src/BRepCheck/BRepCheck_Edge.cxx
src/BRepExtrema/BRepExtrema_Poly.cxx
src/BRepExtrema/BRepExtrema_TriangleSet.cxx
src/BRepLib/BRepLib.cxx
src/BRepMesh/BRepMesh.hxx
src/BRepMesh/BRepMesh_EdgeTessellationExtractor.cxx
src/BRepMesh/BRepMesh_EdgeTessellationExtractor.hxx
src/BRepMesh/BRepMesh_FastDiscret.cxx
src/BRepMesh/BRepMesh_FastDiscret.hxx
src/BRepMesh/BRepMesh_FastDiscretFace.cxx
src/BRepMesh/BRepMesh_FastDiscretFace.hxx
src/BRepMesh/BRepMesh_IncrementalMesh.cxx
src/BRepMesh/BRepMesh_IncrementalMesh.hxx
src/BRepMesh/BRepMesh_ShapeTool.cxx
src/BRepMesh/BRepMesh_ShapeTool.hxx
src/BRepTools/BRepTools_Modification.cxx
src/BRepTools/BRepTools_ShapeSet.cxx
src/BRepTools/BRepTools_ShapeSet.hxx
src/BinMDataStd/BinMDataStd.cxx
src/BinMDataStd/BinMDataStd_MeshDriver.cxx [new file with mode: 0644]
src/BinMDataStd/BinMDataStd_MeshDriver.hxx [new file with mode: 0644]
src/BinMDataStd/FILES
src/BinTools/BinTools_ShapeSet.cxx
src/DBRep/DBRep_DrawableShape.cxx
src/DDataStd/DDataStd_BasicCommands.cxx
src/DrawTrSurf/DrawTrSurf_Triangulation.cxx
src/DrawTrSurf/DrawTrSurf_Triangulation2D.cxx
src/HLRBRep/HLRBRep_PolyAlgo.cxx
src/IVtkOCC/IVtkOCC_ShapeMesher.cxx
src/MeshTest/MeshTest.cxx
src/MeshTest/MeshTest_CheckTopology.cxx
src/MeshTest/MeshTest_DrawableMesh.cxx
src/MeshTest/MeshTest_PluginCommands.cxx
src/Poly/FILES
src/Poly/Poly.cxx
src/Poly/Poly_CoherentTriangulation.cxx
src/Poly/Poly_Connect.cxx
src/Poly/Poly_Element.cxx [new file with mode: 0644]
src/Poly/Poly_Element.hxx [new file with mode: 0644]
src/Poly/Poly_Mesh.cxx [new file with mode: 0644]
src/Poly/Poly_Mesh.hxx [new file with mode: 0644]
src/Poly/Poly_PolygonOnTriangulation.cxx
src/Poly/Poly_PolygonOnTriangulation.hxx
src/Poly/Poly_Triangulation.cxx
src/Poly/Poly_Triangulation.hxx
src/Poly/Poly_Triangulation.lxx [deleted file]
src/QABugs/QABugs_19.cxx
src/Select3D/Select3D_SensitiveTriangulation.cxx
src/Select3D/Select3D_SensitiveTriangulation.hxx
src/StdPrs/StdPrs_Isolines.cxx
src/StdPrs/StdPrs_ShadedShape.cxx
src/StdPrs/StdPrs_ToolTriangulatedShape.cxx
src/StdPrs/StdPrs_WFShape.cxx
src/StdSelect/StdSelect_BRepSelectionTool.cxx
src/StdSelect/StdSelect_ViewerSelector3d.cxx
src/StlAPI/StlAPI_Writer.cxx
src/StlTransfer/StlTransfer.cxx
src/TDataStd/FILES
src/TDataStd/TDataStd_Mesh.cxx [new file with mode: 0644]
src/TDataStd/TDataStd_Mesh.hxx [new file with mode: 0644]
src/TKLCAF/EXTERNLIB
src/TKXmlL/EXTERNLIB
src/ViewerTest/ViewerTest_ObjectCommands.cxx
src/VrmlConverter/VrmlConverter_ShadedShape.cxx
src/VrmlData/VrmlData_IndexedFaceSet.cxx
src/VrmlData/VrmlData_ShapeConvert.cxx
src/XDEDRAW/XDEDRAW_Props.cxx
src/XmlMDataStd/FILES
src/XmlMDataStd/XmlMDataStd.cxx
src/XmlMDataStd/XmlMDataStd_MeshDriver.cxx [new file with mode: 0644]
src/XmlMDataStd/XmlMDataStd_MeshDriver.hxx [new file with mode: 0644]
tests/caf/basic/N1 [new file with mode: 0644]
tests/caf/basic/N2 [new file with mode: 0644]

index 58db74b63ee179ed316e759bbc93fdff7dbcdd0a..d3979d965feaf0877311eff92dd50339c5a4b862 100644 (file)
@@ -1054,3 +1054,12 @@ The following obsolete features have been removed:
 @subsection upgrade_occt710_correction_of_TObj_Model Correction in TObj_Model class
 
 Methods *TObj_Model::SaveAs* and *TObj_Model::Load* receive *TCollection_ExtendedString* filename arguments instead of char*. This shows that the filename may be not-ASCII explicitly. Also it makes OCAF API related to this functionality more conform.
+
+@subsection upgrade_occt710_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 TDataStd_Mesh that allows to store Poly_Mesh in OCAF documents.
\ No newline at end of file
index 370ec76a448554da994e0855ad81d48ccc25dbd4..3f31dacff45d9bbd072d011a9132cd0b7001afa1 100644 (file)
@@ -1112,11 +1112,11 @@ void AIS_Manipulator::Cube::addTriangle (const Standard_Integer theIndex,
                                          const gp_Pnt& theP1, const gp_Pnt& theP2, const gp_Pnt& theP3,
                                          const gp_Dir& theNormal)
 {
-  myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 1, theP1);
-  myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 2, theP2);
-  myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 3, theP3);
+  myTriangulation->ChangeNode (theIndex * 3 + 1) = theP1;
+  myTriangulation->ChangeNode (theIndex * 3 + 2) = theP2;
+  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 (theP2, theNormal);
   myArray->AddVertex (theP3, theNormal);
index 189518fcc06cb606802260e05ec36f8cda91bf01..30bb62ed15ba0c52ef912372c9893a0ef0b4bda2 100644 (file)
@@ -141,9 +141,6 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP
   switch (aMode) 
   {
     case 0:
-      const TColgp_Array1OfPnt& nodes = myTriangulation->Nodes();             //Nodes
-      const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();  //Triangle
-
       Standard_Boolean hasVNormals = myTriangulation->HasNormals();
       Standard_Boolean hasVColors  = HasVertexColors();
 
@@ -153,29 +150,25 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP
       Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
 
       Standard_Integer i;
-      Standard_Integer j;
 
       Standard_Real ambient = aspect->FrontMaterial().Ambient();
       if (hasVNormals)
       {
-        const TShort_Array1OfShortReal& normals = myTriangulation->Normals();
         if (hasVColors)
         {
           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(nodes(i), attenuateColor(colors(i), ambient));
-            anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3));
+            anArray->AddVertex(myTriangulation->Node (i), attenuateColor(colors(i), ambient));
+            anArray->SetVertexNormal(i, myTriangulation->Normal (i));
           }
         }
         else // !hasVColors
         {
-          for ( i = nodes.Lower(); i <= nodes.Upper(); i++ )
+          for ( i = 1; i <= myTriangulation->NbNodes(); i++ )
           {
-            j = (i - nodes.Lower()) * 3;
-            anArray->AddVertex(nodes(i));
-            anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3));
+            anArray->AddVertex(myTriangulation->Node (i));
+            anArray->SetVertexNormal(i, myTriangulation->Normal (i));
           }
         }
       }
@@ -184,23 +177,23 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP
         if (hasVColors)
         {
           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
         {
-          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};
-      for ( i = triangles.Lower(); i<= triangles.Upper(); i++ ) {
-        triangles(i).Get(indexTriangle[0], indexTriangle[1], indexTriangle[2]);
+      for ( i = 1; i<= myTriangulation->NbTriangles(); i++ ) {
+        myTriangulation->Triangle (i).Get(indexTriangle[0], indexTriangle[1], indexTriangle[2]);
         anArray->AddEdge(indexTriangle[0]);
         anArray->AddEdge(indexTriangle[1]);
         anArray->AddEdge(indexTriangle[2]);
index 6e3f6e28a8b023d7be22e8b6caa3544418c1b47e..9fc485cb9518115c9a07c07c9a2b3a74984c2626 100644 (file)
@@ -92,10 +92,9 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
     if (useTriangulation && !T.IsNull())
     {
       nbNodes = T->NbNodes();
-      const TColgp_Array1OfPnt& Nodes = T->Nodes();
       for (i = 1; i <= nbNodes; i++) {
-        if (l.IsIdentity()) B.Add(Nodes(i));
-        else B.Add(Nodes(i).Transformed(l));
+        if (l.IsIdentity()) B.Add(T->Node (i));
+        else B.Add(T->Node (i).Transformed(l));
       }
       //       B.Enlarge(T->Deflection());
       B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
@@ -153,12 +152,11 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
       if (useTriangulation && !Poly.IsNull())
       {
         const TColStd_Array1OfInteger& Indices = Poly->Nodes();
-        const TColgp_Array1OfPnt& Nodes = T->Nodes();
         nbNodes = Indices.Length();
         for (i = 1; i <= nbNodes; i++)
         {
-          if (l.IsIdentity()) B.Add(Nodes(Indices(i)));
-          else B.Add(Nodes(Indices(i)).Transformed(l));
+          if (l.IsIdentity()) B.Add(T->Node (Indices(i)));
+          else B.Add(T->Node (Indices(i)).Transformed(l));
         }
         //     B.Enlarge(T->Deflection());
         B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E));
@@ -233,11 +231,9 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B,
     Bnd_Box aLocBox;
     if (useTriangulation && !T.IsNull())
     {
-      nbNodes = T->NbNodes();
-      const TColgp_Array1OfPnt& Nodes = T->Nodes();
-      for (i = 1; i <= nbNodes; i++) {
-        if (l.IsIdentity()) aLocBox.Add(Nodes(i));
-        else aLocBox.Add(Nodes(i).Transformed(l));
+      for (i = 1; i <= T->NbNodes(); i++) {
+        if (l.IsIdentity()) aLocBox.Add(T->Node(i));
+        else aLocBox.Add(T->Node(i).Transformed(l));
       }
       //       B.Enlarge(T->Deflection());
       aLocBox.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
@@ -338,12 +334,11 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B,
       if (useTriangulation && !Poly.IsNull())
       {
         const TColStd_Array1OfInteger& Indices = Poly->Nodes();
-        const TColgp_Array1OfPnt& Nodes = T->Nodes();
         nbNodes = Indices.Length();
         for (i = 1; i <= nbNodes; i++)
         {
-          if (l.IsIdentity()) aLocBox.Add(Nodes(Indices(i)));
-          else aLocBox.Add(Nodes(Indices(i)).Transformed(l));
+          if (l.IsIdentity()) aLocBox.Add(T->Node(Indices(i)));
+          else aLocBox.Add(T->Node(Indices(i)).Transformed(l));
         }
         Standard_Real Tol = useShapeTolerance?  BRep_Tool::Tolerance(E) : 0.;
         aLocBox.Enlarge(Poly->Deflection() + Tol);
index 6d370387b67dda13e2d423364085d2123b6276e9..1b6c55cd3352b74db71d22e05ed981e3c1200eb9 100644 (file)
 #include <Geom_Curve.hxx>
 #include <Geom_Surface.hxx>
 #include <gp_Pnt.hxx>
-#include <TopoDS_Shape.hxx>
-#include <TopoDS_Vertex.hxx>
 #include <Poly_Triangulation.hxx>
 
-namespace {
-
 //! Tool class implementing necessary functionality for copying geometry
 class BRepBuilderAPI_Copy_Modification : public BRepTools_Modification 
 {
 public:
   BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom,
-                                    const Standard_Boolean copyMesh)
+                                    const Standard_Boolean copyMesh = Standard_False)
     : myCopyGeom(copyGeom),
       myCopyMesh(copyMesh)
   {
@@ -59,19 +55,16 @@ public:
   //! copies it if required
   Standard_Boolean NewTriangulation(const TopoDS_Face& F, Handle(Poly_Triangulation)& T) Standard_OVERRIDE
   {
-    if (!myCopyMesh)
-      return Standard_False;
-
     TopLoc_Location L;
     T = BRep_Tool::Triangulation(F, L);
 
-    if (T.IsNull())
-      return Standard_False;
-
-    // mesh is copied if and only if the geometry need to be copied too
-    if (myCopyGeom)
+    if (!T.IsNull() && myCopyMesh)
+    {
       T = T->Copy();
-    return Standard_True;
+      return Standard_True;
+    }
+
+    return Standard_False;
   }
 
   //! Returns true to indicate the need to copy edge;
@@ -187,8 +180,6 @@ private:
 
 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
 
-} // anonymous namespace
-
 //=======================================================================
 //function : BRepBuilderAPI_Copy
 //purpose  : 
index 0c192748a75af267e488d5636fdc3dbb89eb34fe..b905353c168ab2b1fb6070a526575c75a4be6b2c 100644 (file)
@@ -605,7 +605,6 @@ BRepCheck_Status BRepCheck_Edge::
       aCR->PolygonOnTriangulation2() : 
     aCR->PolygonOnTriangulation();
     const TColStd_Array1OfInteger& anIndices = aPOnTriag->Nodes();
-    const TColgp_Array1OfPnt& Nodes = aTriang->Nodes();
     const Standard_Integer aNbNodes = anIndices.Length();
 
     const Standard_Real aTol = aPOnTriag->Deflection() +
@@ -618,9 +617,9 @@ BRepCheck_Status BRepCheck_Edge::
       {
         const Standard_Real aParam = aPOnTriag->Parameters()->Value(i);
         const gp_Pnt  aPE(aBC.Value(aParam)), 
-          aPnt(Nodes(anIndices(i)).Transformed(aLL));
+                      aPT(aTriang->Node (anIndices(i)).Transformed(aLL));
 
-        const Standard_Real aSQDist = aPE.SquareDistance(aPnt);
+        const Standard_Real aSQDist = aPE.SquareDistance(aPT);
         if(aSQDist > aTol*aTol)
         {
           return BRepCheck_InvalidPolygonOnTriangulation;
@@ -637,9 +636,9 @@ BRepCheck_Status BRepCheck_Edge::
       for (Standard_Integer i = 1; i <= aNbNodes; i++)
       {
         if (aLL.IsIdentity())
-          aB.Add(Nodes(anIndices(i)));
+          aB.Add(aTriang->Node (anIndices(i)));
         else
-          aB.Add(Nodes(anIndices(i)).Transformed(aLL));
+          aB.Add(aTriang->Node (anIndices(i)).Transformed(aLL));
       }
 
       aB.Enlarge(aTol);
index ff9a0a04aec025330e739f762ba889fe4d7ee14c..ec17a2653cc024da48379b907840bd4b64cd8d89 100644 (file)
@@ -75,12 +75,11 @@ Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, const TopoD
     Tr = BRep_Tool::Triangulation(F,L);
     if (!Tr.IsNull())
     {
-      const TColgp_Array1OfPnt& Nod = Tr->Nodes();
       n = Tr->NbNodes();
       for (i = 1; i <= n; i++)
       {
         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);
     if (!Tr.IsNull())
     {
-      const TColgp_Array1OfPnt& Nod = Tr->Nodes();
       n = Tr->NbNodes();
       for (i = 1; i <= n; i++)
       {
         nbn2++; 
-        TP2.SetValue(nbn2,Nod(i).Transformed(L));
+        TP2.SetValue(nbn2,Tr->Node (i).Transformed(L));
       }
     }
   }
index ff4b5382a12535a9cdf64316a7af0efce4c353da..83dc472e803b345a2a99decbfd5743c2ef7f58ed 100644 (file)
@@ -189,7 +189,7 @@ Standard_Boolean BRepExtrema_TriangleSet::Init (const BRepExtrema_ShapeList& the
 
     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());
 
@@ -197,8 +197,8 @@ Standard_Boolean BRepExtrema_TriangleSet::Init (const BRepExtrema_ShapeList& the
                                           aVertex.Y(),
                                           aVertex.Z()));
 
-      const Standard_Real aU = aTriangulation->UVNodes().Value (aVertIdx).X();
-      const Standard_Real aV = aTriangulation->UVNodes().Value (aVertIdx).Y();
+      const Standard_Real aU = aTriangulation->UVNode (aVertIdx).X();
+      const Standard_Real aV = aTriangulation->UVNode (aVertIdx).Y();
 
       myVertUVArray.push_back (BVH_Vec2d (aU, aV));
     }
@@ -209,9 +209,9 @@ Standard_Boolean BRepExtrema_TriangleSet::Init (const BRepExtrema_ShapeList& the
       Standard_Integer aVertex2;
       Standard_Integer aVertex3;
 
-      aTriangulation->Triangles().Value (aTriIdx).Get (aVertex1,
-                                                       aVertex2,
-                                                       aVertex3);
+      aTriangulation->Triangle (aTriIdx).Get (aVertex1,
+                                              aVertex2,
+                                              aVertex3);
 
       myTriangles.push_back (BVH_Vec4i (aVertex1 + aVertOffset,
                                         aVertex2 + aVertOffset,
index aced41ccb7c539837248e8bc0dd603abfb5971d0..b9d835d357d25fe817f9c9a1e6ed0e4a8fba9329 100644 (file)
@@ -1857,9 +1857,9 @@ Standard_Boolean BRepLib::
     const Standard_Integer anArrDim = 3*aPT->NbNodes();
     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++)
+    for(Standard_Integer i = 1; i <= aPT->NbNodes(); i++)
     {
-      const gp_Pnt2d &aP2d = aPT->UVNodes().Value(i);
+      const gp_Pnt2d &aP2d = aPT->UVNode(i);
       aSLP.SetParameters(aP2d.X(), aP2d.Y());
 
       gp_XYZ aNorm(0.,0.,0.);
@@ -1918,9 +1918,6 @@ Standard_Boolean BRepLib::
     const Handle(Poly_PolygonOnTriangulation)& aPTEF2 = 
                                 BRep_Tool::PolygonOnTriangulation(anEdg, aPT2, aLoc2);
 
-    TShort_Array1OfShortReal& aNormArr1 = aPT1->ChangeNormals();
-    TShort_Array1OfShortReal& aNormArr2 = aPT2->ChangeNormals();
-
     if (aPTEF1->Nodes().Lower() != aPTEF2->Nodes().Lower() || 
         aPTEF1->Nodes().Upper() != aPTEF2->Nodes().Upper()) 
       continue; 
@@ -1932,31 +1929,15 @@ Standard_Boolean BRepLib::
       const Standard_Integer aFNodF1 = aPTEF1->Nodes().Value(anEdgNode);
       const Standard_Integer aFNodF2 = aPTEF2->Nodes().Value(anEdgNode);
 
-      const Standard_Integer aFNorm1FirstIndex = aNormArr1.Lower() + 3*
-                                                    (aFNodF1 - aPT1->Nodes().Lower());
-      const Standard_Integer aFNorm2FirstIndex = aNormArr2.Lower() + 3*
-                                                    (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));
+      gp_XYZ aNorm1(aPT1->Normal(aFNodF1).XYZ());
+      gp_XYZ aNorm2(aPT2->Normal(aFNodF2).XYZ());
       const Standard_Real aDot = aNorm1 * aNorm2;
 
       if(aDot > aThresDot)
       {
         gp_XYZ aNewNorm = (aNorm1 + aNorm2).Normalized();
-        aNormArr1.ChangeValue(aFNorm1FirstIndex) =
-          aNormArr2.ChangeValue(aFNorm2FirstIndex) =
-          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());
+        aPT1->SetNormal(aFNodF1, aNewNorm);
+        aPT2->SetNormal(aFNodF2, aNewNorm);
         aRetVal = Standard_True;
       }
     }
index 8d503f677021509dcaff1bca1363f7b414db1f81..d601334651bb0b2cc7569c1d99c32897887148bf 100644 (file)
@@ -39,6 +39,7 @@
 #include <BRepMesh_PairOfIndex.hxx>
 #include <BRepMesh_Circle.hxx>
 #include <TopTools_ShapeMapHasher.hxx>
+#include <Poly_Triangulation.hxx>
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Shape.hxx>
 
@@ -51,7 +52,6 @@ class BRepMesh_FaceAttribute;
 class BRepMesh_VertexInspector;
 class BRepMesh_CircleInspector;
 class BRepMesh_Classifier;
-class Poly_Triangulation;
 class BRepMesh_VertexTool;
 
 namespace BRepMesh
index 5fbb1bba33a83577436f94bb9aa0e47916411cdf..99252f217ce5d1aeb115cf3f0f239f54034c8386 100644 (file)
@@ -35,7 +35,7 @@ BRepMesh_EdgeTessellationExtractor::BRepMesh_EdgeTessellationExtractor(
   const TopLoc_Location&                      theLocation)
   : myProvider(theEdge, theFace, thePolygon->Parameters()),
     myPCurve(thePCurve),
-    myNodes(theTriangulation->Nodes()),
+    myTriangulation(theTriangulation),
     myIndices(thePolygon->Nodes()),
     myLoc(theLocation)
 {
@@ -51,7 +51,7 @@ Standard_Boolean BRepMesh_EdgeTessellationExtractor::Value(
   gp_Pnt&                thePoint,
   gp_Pnt2d&              theUV)
 {
-  const gp_Pnt& theRefPnt = myNodes(myIndices(theIndex));
+  const gp_Pnt& theRefPnt = myTriangulation->Node (myIndices(theIndex));
   thePoint = BRepMesh_ShapeTool::UseLocation(theRefPnt, myLoc);
 
   theParameter = myProvider.Parameter(theIndex, thePoint);
index d7f20a6146f2f7ef6cd4a2bce1e3997ec13d76af..31f9165be723dd37e3bcb41c9c9523da16635d3a 100644 (file)
 #include <Standard_DefineAlloc.hxx>
 #include <BRepMesh_IEdgeTool.hxx>
 #include <BRepMesh_EdgeParameterProvider.hxx>
+#include <Geom2d_Curve.hxx>
+#include <Poly_PolygonOnTriangulation.hxx>
+#include <Poly_Triangulation.hxx>
 #include <TopLoc_Location.hxx>
 #include <TColgp_Array1OfPnt.hxx>
 #include <TColStd_Array1OfInteger.hxx>
 
-class Poly_Triangulation;
 class Poly_PolygonOnTriangulation;
 class TopoDS_Edge;
 class TopoDS_Face;
@@ -77,7 +79,7 @@ private:
 
   BRepMesh_EdgeParameterProvider myProvider;
   Handle(Geom2dAdaptor_HCurve)   myPCurve;
-  const TColgp_Array1OfPnt&      myNodes;
+  Handle(Poly_Triangulation)     myTriangulation;
   const TColStd_Array1OfInteger& myIndices;
   const TopLoc_Location          myLoc;
 };
index 1d453897ff34488535ab856926a24707482749f5..9abf588f307c1c44bfb415168f1b389b00a4b49d 100644 (file)
@@ -803,15 +803,14 @@ void BRepMesh_FastDiscret::update(
     if (aPolygon->Deflection() > 1.1 * theDefEdge)
       continue;
 
-    const TColgp_Array1OfPnt&      aNodes   = aTriangulation->Nodes();
     const TColStd_Array1OfInteger& aIndices = aPolygon->Nodes();
     Handle(TColStd_HArray1OfReal)  aParams  = aPolygon->Parameters();
 
     aEAttr.FirstVExtractor = new PolyVExplorer(aEAttr.FirstVertex, 
-      aEAttr.IsSameUV, aEAttr.LastVertex, aIndices(1), aNodes, aLoc);
+      aEAttr.IsSameUV, aEAttr.LastVertex, aIndices(1), aTriangulation, aLoc);
 
     aEAttr.LastVExtractor = new PolyVExplorer(aEAttr.LastVertex, 
-      aEAttr.IsSameUV, aEAttr.FirstVertex, aIndices(aIndices.Length()), aNodes, aLoc);
+      aEAttr.IsSameUV, aEAttr.FirstVertex, aIndices(aIndices.Length()), aTriangulation, aLoc);
 
     aEdgeTool = new BRepMesh_EdgeTessellationExtractor(theEdge, theC2d, 
       aFace, aTriangulation, aPolygon, aLoc);
index 3db6feeae21d616f11b26435674a6ab62dfd82cb..443fcc270b7f8879d81db9f8d321ae72c362f09c 100644 (file)
@@ -234,18 +234,18 @@ private:
       const Standard_Boolean    isSameUV,
       const TopoDS_Vertex&      theSameVertex,
       const Standard_Integer    theVertexIndex,
-      const TColgp_Array1OfPnt& thePolygon,
+      const Handle(Poly_Triangulation)& theTriangulation,
       const TopLoc_Location&    theLoc)
       : TopoDSVExplorer(theVertex, isSameUV, theSameVertex),
         myVertexIndex(theVertexIndex),
-        myPolygon(thePolygon),
+        myTriangulation(theTriangulation),
         myLoc(theLoc)
     {
     }
 
     virtual gp_Pnt Point() const
     {
-      return BRepMesh_ShapeTool::UseLocation(myPolygon(myVertexIndex), myLoc);
+      return BRepMesh_ShapeTool::UseLocation(myTriangulation->Node (myVertexIndex), myLoc);
     }
 
   private:
@@ -255,9 +255,9 @@ private:
     }
 
   private:
-    Standard_Integer          myVertexIndex;
-    const TColgp_Array1OfPnt& myPolygon;
-    const TopLoc_Location     myLoc;
+    Standard_Integer           myVertexIndex;
+    Handle(Poly_Triangulation) myTriangulation;
+    const TopLoc_Location      myLoc;
   };
 
   //! Structure keeps common parameters of edge
index 80df07b20f356ba2e013c8524af2ace34ab25d1d..7535dac834579b65012b0356042d7efbb499cdb4 100644 (file)
@@ -1482,8 +1482,6 @@ void BRepMesh_FastDiscretFace::commitSurfaceTriangulation()
   Handle(Poly_Triangulation) aNewTriangulation =
     new Poly_Triangulation(aVerticesNb, aTrianglesNb, Standard_True);
 
-  Poly_Array1OfTriangle& aPolyTrianges = aNewTriangulation->ChangeTriangles();
-
   Standard_Integer aTriangeId = 1;
   BRepMesh::MapOfInteger::Iterator aTriIt(aTriangles);
   for (; aTriIt.More(); aTriIt.Next())
@@ -1497,12 +1495,10 @@ void BRepMesh_FastDiscretFace::commitSurfaceTriangulation()
     for (Standard_Integer i = 0; i < 3; ++i)
       aNodeId[i] = aVetrexEdgeMap->FindIndex(aNode[i]);
 
-    aPolyTrianges(aTriangeId++).Set(aNodeId[0], aNodeId[1], aNodeId[2]);
+    aNewTriangulation->ChangeTriangle (aTriangeId++).Set(aNodeId[0], aNodeId[1], aNodeId[2]);
   }
 
   // Store mesh nodes
-  TColgp_Array1OfPnt&   aNodes   = aNewTriangulation->ChangeNodes();
-  TColgp_Array1OfPnt2d& aNodes2d = aNewTriangulation->ChangeUVNodes();
 
   for (Standard_Integer i = 1; i <= aVerticesNb; ++i)
   {
@@ -1510,8 +1506,8 @@ void BRepMesh_FastDiscretFace::commitSurfaceTriangulation()
     const BRepMesh_Vertex& aVertex   = aStructure->GetNode(aVertexId);
     const gp_Pnt&          aPoint    = myAttribute->GetPoint(aVertex);
 
-    aNodes(i)   = aPoint;
-    aNodes2d(i) = aVertex.Coord();
+    aNewTriangulation->ChangeNode (i)   = aPoint;
+    aNewTriangulation->ChangeUVNode (i) = aVertex.Coord();
   }
 
   aNewTriangulation->Deflection(myAttribute->GetDefFace());
index 76b00e1914d75028e6e350247d1824b666370735..db0459f6f17a3d793b0958cb1822aa6892bb3e1b 100644 (file)
@@ -22,7 +22,8 @@
 #include <BRepMesh_FaceAttribute.hxx>
 #include <Standard_Transient.hxx>
 #include <TopTools_MutexForShapeProvider.hxx>
-#include <TopTools_DataMapOfShapeReal.hxx>
+#include <BRepAdaptor_HSurface.hxx>
+#include <Poly_Triangulation.hxx>
 #include <BRepMesh_Delaun.hxx>
 #include <BRepMesh_Triangle.hxx>
 #include <BRepMesh_Classifier.hxx>
@@ -32,9 +33,7 @@ class BRepMesh_DataStructureOfDelaun;
 class BRepMesh_FaceAttribute;
 class TopoDS_Face;
 class TopoDS_Vertex;
-class BRepAdaptor_HSurface;
 class TopoDS_Edge;
-class Poly_Triangulation;
 class TopLoc_Location;
 class gp_XY;
 class gp_Pnt2d;
index 70278be25991cf217e1b4228a58e00ca659e00c2..3a91e7b70abc7ebbba48333e1b72b143b6cf5d3a 100644 (file)
@@ -415,11 +415,10 @@ Standard_Boolean BRepMesh_IncrementalMesh::toBeMeshed(
         // #25080: check that indices of links forming triangles are in range.
         Standard_Boolean isTriangulationConsistent = Standard_True;
         const Standard_Integer aNodesNb = aTriangulation->NbNodes();
-        const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
-        Standard_Integer i = aTriangles.Lower();
-        for (; i <= aTriangles.Upper() && isTriangulationConsistent; ++i)
+        Standard_Integer i = 1;
+        for (; i <= aTriangulation->NbTriangles() && isTriangulationConsistent; ++i)
         {
-          const Poly_Triangle& aTriangle = aTriangles(i);
+          const Poly_Triangle& aTriangle = aTriangulation->Triangle (i);
           Standard_Integer n[3];
           aTriangle.Get(n[0], n[1], n[2]);
           for (Standard_Integer j = 0; j < 3 && isTriangulationConsistent; ++j)
index 5e7d4f3bdc97a877adf804449e8161d31c0a506c..f3d647810b0b9b61b13fd0c1be6517bfa1c0d1ba 100644 (file)
 #include <TopTools_MapOfShape.hxx>
 #include <TopTools_DataMapOfShapeReal.hxx>
 #include <BRepMesh_DiscretRoot.hxx>
+#include <Poly_Triangulation.hxx>
 #include <BRepMesh.hxx>
 
 #include <vector>
 
-class Poly_Triangulation;
 class TopoDS_Shape;
 class TopoDS_Edge;
 class TopoDS_Face;
index ebd837bd7aa6e8838f725aa28507747c67a37407..d9e4e6c165517f5f352312415e3581bad01cb060 100644 (file)
@@ -203,9 +203,8 @@ void BRepMesh_ShapeTool::AddInFace(
     gp_Trsf aTrsf = aLoc.Transformation();
     aTrsf.Invert();
 
-    TColgp_Array1OfPnt& aNodes = theTriangulation->ChangeNodes();
-    for (Standard_Integer i = aNodes.Lower(); i <= aNodes.Upper(); ++i) 
-      aNodes(i).Transform(aTrsf);
+    for (Standard_Integer i = 1; i <= theTriangulation->NbNodes(); ++i) 
+      theTriangulation->ChangeNode (i).Transform(aTrsf);
   }
 
   BRep_Builder aBuilder;
index e1883d774691ba60e9d6b6cf271c9a646b637b42..7ced7514d78a8cfdf8269696fbd641ece923b47c 100644 (file)
@@ -21,6 +21,7 @@
 #include <BRepAdaptor_HSurface.hxx>
 #include <BRepMesh_FaceAttribute.hxx>
 #include <BRepMesh.hxx>
+#include <Poly_Triangulation.hxx>
 
 class Poly_Triangulation;
 class TopoDS_Face;
index 012035a8b2d2e28ff2f623aca2f8d8ee58182e2c..282d7da365157bd84be33fccb38a806fe74e6b4d 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-
 #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 <TopoDS_Face.hxx>
 
-IMPLEMENT_STANDARD_RTTIEXT(BRepTools_Modification,MMgt_TShared)
+IMPLEMENT_STANDARD_RTTIEXT (BRepTools_Modification, MMgt_TShared)
 
 Standard_Boolean BRepTools_Modification::NewTriangulation(const TopoDS_Face&, Handle(Poly_Triangulation)&)
 {
index a89ebf538a25c844155897abc146712befa7c0cf..ccd0e62efd8f3cf2e377852d19af6fa544b8cb73 100644 (file)
@@ -55,6 +55,7 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Vertex.hxx>
+#include <Poly_Mesh.hxx>
 
 #ifdef MacOS
 #define strcasecmp(p,q) strcmp(p,q)
@@ -1475,7 +1476,7 @@ void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS)
 //=======================================================================
 
 void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream&      OS,
-                                        const Standard_Boolean Compact)const
+                                            const Standard_Boolean Compact) const
 {
   Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
   Standard_Integer nbTriangles = 0, n1, n2, n3;
@@ -1516,28 +1517,26 @@ void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream&      OS,
     if (!Compact) OS << "\n3D Nodes :\n";
     
     nbNodes = T->NbNodes();
-    const TColgp_Array1OfPnt& Nodes = T->Nodes();
     for (j = 1; j <= nbNodes; j++) {
       if (!Compact) OS << setw(10) << j << " : ";
       if (!Compact) OS << setw(17);
-      OS << Nodes(j).X() << " ";
+      OS << T->Node (j).X() << " ";
       if (!Compact) OS << setw(17);
-      OS << Nodes(j).Y() << " ";
+      OS << T->Node (j).Y() << " ";
       if (!Compact) OS << setw(17);
-      OS << Nodes(j).Z();
+      OS << T->Node (j).Z();
       if (!Compact) OS << "\n";
       else OS << " ";
     }
     
     if (T->HasUVNodes()) {
       if (!Compact) OS << "\nUV Nodes :\n";
-      const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
       for (j = 1; j <= nbNodes; j++) {
         if (!Compact) OS << setw(10) << j << " : ";
         if (!Compact) OS << setw(17);
-        OS << UVNodes(j).X() << " ";
+        OS << T->UVNode (j).X() << " ";
         if (!Compact) OS << setw(17);
-        OS << UVNodes(j).Y();
+        OS << T->UVNode (j).Y();
         if (!Compact) OS << "\n";
         else OS << " ";
       }
@@ -1545,10 +1544,9 @@ void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream&      OS,
     
     if (!Compact) OS << "\nTriangles :\n";
     nbTriangles = T->NbTriangles();
-    const Poly_Array1OfTriangle& Triangles = T->Triangles();
     for (j = 1; j <= nbTriangles; j++) {
       if (!Compact) OS << setw(10) << j << " : ";
-      Triangles(j).Get(n1, n2, n3);
+      T->Triangle (j).Get(n1, n2, n3);
       if (!Compact) OS << setw(10);
       OS << n1 << " ";
       if (!Compact) OS << setw(10);
@@ -1618,7 +1616,7 @@ void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS)
         UVNodes(j).SetCoord(x,y);
       }
     }
-      
+
     // read the triangles
     Standard_Integer n1,n2,n3;
     Poly_Array1OfTriangle Triangles(1, nbTriangles);
@@ -1626,12 +1624,185 @@ void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS)
       IS >> n1 >> n2 >> n3;
       Triangles(j).Set(n1,n2,n3);
     }
-      
+
     if (hasUV) T =  new Poly_Triangulation(Nodes,UVNodes,Triangles);
     else T = new Poly_Triangulation(Nodes,Triangles);
-      
+
     T->Deflection(d);
-      
+
     myTriangulations.Add(T);
   }
 }
+
+// Writes meshes (Poly_Mesh).
+void BRepTools_ShapeSet::WriteMeshes(Standard_OStream& OS,
+                                     const TColStd_IndexedMapOfTransient& Meshes,
+                                     const Standard_Boolean Compact)
+{
+  const Standard_Integer nbMeshes = Meshes.Extent();
+
+  if (Compact)
+    OS << "Meshes " << nbMeshes << "\n";
+  else {
+    OS << " -------\n";
+    OS <<"Dump of " << nbMeshes << " meshes\n";
+    OS << " -------\n";
+  }
+
+  Standard_Integer i = 1;
+  for (; i <= nbMeshes; i++)
+  {
+    const Handle(Poly_Mesh) M = Handle(Poly_Mesh)::DownCast(Meshes(i));
+    const Standard_Integer nbNodes = M->NbNodes();
+    const Standard_Integer nbElements = M->NbElements();
+    const Standard_Boolean hasUVNodes = M->HasUVNodes();
+
+    if (Compact)
+    {
+      OS << nbNodes << " " << nbElements << " ";
+      OS << (hasUVNodes ? "1" : "0") << " ";
+    }
+    else
+    {
+      OS << "  "<< i << " : Mesh with " << nbNodes << " Nodes, " << nbElements <<" Triangles and Quadrangles\n";
+      OS << "      "<<(hasUVNodes ? "with" : "without") << " UV nodes\n";
+    }
+    
+    // write the deflection
+    if (!Compact) 
+      OS << "  Deflection : ";
+    OS <<M->Deflection() << "\n";
+    
+    // write the 3d nodes
+    if (!Compact)
+      OS << "\n3D Nodes :\n";
+    
+    Standard_Integer j;
+    for (j = 1; j <= nbNodes; j++)
+    {
+      if (!Compact) OS << setw(10) << j << " : ";
+      if (!Compact) OS << setw(17);
+      OS << M->Node(j).X() << " ";
+      if (!Compact) OS << setw(17);
+      OS << M->Node(j).Y() << " ";
+      if (!Compact) OS << setw(17);
+      OS << M->Node(j).Z();
+      if (!Compact) OS << "\n";
+      else OS << " ";
+    }
+    
+    // write 2d nodes
+    if (hasUVNodes)
+    {
+      if (!Compact) OS << "\nUV Nodes :\n";
+      for (j = 1; j <= nbNodes; j++)
+      {
+        if (!Compact) OS << setw(10) << j << " : ";
+        if (!Compact) OS << setw(17);
+        OS << M->UVNode(j).X() << " ";
+        if (!Compact) OS << setw(17);
+        OS << M->UVNode(j).Y();
+        if (!Compact) OS << "\n";
+        else OS << " ";
+      }
+    }
+    
+    // write triangles and quadrangles
+    if (!Compact) OS << "\nElements :\n";
+    Standard_Integer n, n1, n2, n3, n4;
+    for (j = 1; j <= nbElements; j++)
+    {
+      if (!Compact) OS << setw(10) << j << " : ";
+      M->Element(j, n1, n2, n3, n4);
+      n = (n4 > 0) ? 4 : 3;
+      if (!Compact) OS << setw(10);
+      OS << n << " ";
+      if (!Compact) OS << setw(10);
+      OS << n1 << " ";
+      if (!Compact) OS << setw(10);
+      OS << n2 << " ";
+      if (!Compact) OS << setw(10);
+      OS << n3;
+      if (n4 > 0)
+      {
+        OS << " ";
+        if (!Compact) OS << setw(10);
+        OS << n4;
+      }
+      if (!Compact) OS << "\n";
+      else OS << " ";
+    }
+    OS << "\n";
+  }
+}
+
+// Reads meshes (Poly_Mesh).
+void BRepTools_ShapeSet::ReadMeshes(Standard_IStream& IS,
+                                    TColStd_IndexedMapOfTransient& Meshes)
+{
+  char buffer[255];
+  Standard_Integer i, j;
+  Standard_Integer n, n1, n2, n3, n4;
+  Standard_Real deflection, x, y, z;
+  Standard_Integer nbMeshes(0), nbNodes(0), nbElements(0);
+  Standard_Boolean hasUV(Standard_False);
+  gp_Pnt p;
+
+  // Read the "Meshes" head-line.
+  IS >> buffer;
+  if (strstr(buffer,"Meshes") == NULL)
+    return;
+
+  // Read number of meshes.
+  IS >> nbMeshes;
+
+  for (i = 1; i <= nbMeshes; i++)
+  {
+    IS >> nbNodes >> nbElements >> hasUV;
+    GeomTools::GetReal(IS, deflection);
+
+    // Allocate the mesh.
+    Handle(Poly_Mesh) M = new Poly_Mesh(hasUV);
+    M->Deflection(deflection);
+
+    // Read nodes.
+    for (j = 1; j <= nbNodes; j++)
+    {
+      GeomTools::GetReal(IS, x);
+      GeomTools::GetReal(IS, y);
+      GeomTools::GetReal(IS, z);
+      p.SetCoord(x, y, z);
+      M->AddNode(p);
+    }
+
+    // Reads 2d-nodes.
+    if (hasUV)
+    {
+      for (j = 1; j <= nbNodes; j++)
+      {
+        GeomTools::GetReal(IS, x);
+        GeomTools::GetReal(IS, y);
+        M->ChangeUVNode(j).SetCoord(x,y);
+      }
+    }
+
+    // Reads the triangles and quadrangles.
+    for (j = 1; j <= nbElements; j++)
+    {
+      // Read the element.
+      IS >> n;
+      if (n == 3)
+        IS >> n1 >> n2 >> n3;
+      else if (n == 4)
+        IS >> n1 >> n2 >> n3 >> n4;
+
+      // Set the element to the mesh.
+      if (n == 3)
+        M->AddElement(n1, n2, n3);
+      else if (n == 4)
+        M->AddElement(n1, n2, n3, n4);
+    }
+
+    Meshes.Add(M);
+  }
+}
index caf96de38355d2197f98be4a6e878bfa7b9819bc..a35d99def60f408d772f719a697b99763733e4cf 100644 (file)
@@ -127,7 +127,16 @@ public:
   //! on the stream <OS>.
   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& OS,
+                                          const TColStd_IndexedMapOfTransient& Meshes,
+                                          const Standard_Boolean Compact = 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& IS,
+                                         TColStd_IndexedMapOfTransient& Meshes);
 
 
 protected:
index 9885934ebefa0884c54ce387b5e6cb8b750b3b33..147253c71e99538806e9fce5db34cc517121e888 100644 (file)
@@ -41,6 +41,7 @@
 #include <BinMDataStd_TreeNodeDriver.hxx>
 #include <BinMDataStd_UAttributeDriver.hxx>
 #include <BinMDataStd_VariableDriver.hxx>
+#include <BinMDataStd_MeshDriver.hxx>
 #include <BinMDF_ADriverTable.hxx>
 #include <CDM_MessageDriver.hxx>
 
@@ -80,6 +81,7 @@ void BinMDataStd::AddDrivers (const Handle(BinMDF_ADriverTable)& theDriverTable,
   theDriverTable->AddDriver (new BinMDataStd_NamedDataDriver     (theMsgDriver) );
   theDriverTable->AddDriver (new BinMDataStd_AsciiStringDriver   (theMsgDriver) );
   theDriverTable->AddDriver (new BinMDataStd_IntPackedMapDriver  (theMsgDriver) );
+  theDriverTable->AddDriver (new BinMDataStd_MeshDriver          (theMsgDriver) );
 }
 
 //=======================================================================
diff --git a/src/BinMDataStd/BinMDataStd_MeshDriver.cxx b/src/BinMDataStd/BinMDataStd_MeshDriver.cxx
new file mode 100644 (file)
index 0000000..f0757f1
--- /dev/null
@@ -0,0 +1,169 @@
+// 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 <BinMDataStd_MeshDriver.hxx>
+#include <BinObjMgt_Persistent.hxx>
+#include <CDM_MessageDriver.hxx>
+#include <Standard_Type.hxx>
+#include <TDataStd_Mesh.hxx>
+#include <TDF_Attribute.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_MeshDriver,BinMDF_ADriver)
+
+//=======================================================================
+//function : BinMDataStd_MeshDriver
+//purpose  : Constructor
+//=======================================================================
+BinMDataStd_MeshDriver::BinMDataStd_MeshDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
+     : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_Mesh)->Name())
+{
+
+}
+
+//=======================================================================
+//function : NewEmpty
+//purpose  : 
+//=======================================================================
+Handle(TDF_Attribute) BinMDataStd_MeshDriver::NewEmpty() const
+{
+  return new TDataStd_Mesh();
+}
+
+//=======================================================================
+//function : Paste
+//purpose  : persistent -> transient (retrieve)
+//=======================================================================
+Standard_Boolean BinMDataStd_MeshDriver::Paste(const BinObjMgt_Persistent&  theSource,
+                                               const Handle(TDF_Attribute)& theTarget,
+                                               BinObjMgt_RRelocationTable&  ) const
+{
+  Handle(TDataStd_Mesh) mesh = Handle(TDataStd_Mesh)::DownCast(theTarget);
+
+  Standard_Integer i;
+  Standard_Real deflection, x, y, z;
+  Standard_Integer n, n1, n2, n3, n4;
+  Standard_Integer nbNodes(0), nbElements(0);
+  Standard_Boolean hasUV(Standard_False);
+  gp_Pnt p;
+
+  theSource >> nbNodes;
+  theSource >> nbElements;
+  theSource >> hasUV;
+  theSource >> deflection;
+
+  // allocate the mesh
+  Handle(Poly_Mesh) M = new Poly_Mesh(hasUV);
+
+  // deflection
+  M->Deflection(deflection);
+
+  // read nodes
+  for (i = 1; i <= nbNodes; i++)
+  {
+    theSource >> x;
+    theSource >> y;
+    theSource >> z;
+    p.SetCoord(x, y, z);
+    M->AddNode(p);
+  }
+      
+  // read 2d nodes
+  if (hasUV)
+  {
+    for (i = 1; i <= nbNodes; i++)
+    {
+      theSource >> x;
+      theSource >> y;
+      M->ChangeUVNode(i).SetCoord(x,y);
+    }
+  }
+      
+  // read triangles and quadrangles
+  for (i = 1; i <= nbElements; i++)
+  {
+    theSource >> n;
+    theSource >> n1;
+    theSource >> n2;
+    theSource >> n3;
+    if (n == 3)
+        M->AddElement(n1, n2, n3);
+    else if (n == 4)
+    {
+        theSource >> n4;
+        M->AddElement(n1, n2, n3, n4);
+    }
+  }
+
+  // set mesh to Ocaf attribute
+  mesh->Set(M);
+  return !M.IsNull();
+}
+
+//=======================================================================
+//function : Paste
+//purpose  : transient -> persistent (store)
+//=======================================================================
+void BinMDataStd_MeshDriver::Paste(const Handle(TDF_Attribute)& theSource,
+                                   BinObjMgt_Persistent&        theTarget,
+                                   BinObjMgt_SRelocationTable&  ) const
+{
+  const Handle(TDataStd_Mesh) meshAttr = Handle(TDataStd_Mesh)::DownCast(theSource);
+  const Handle(Poly_Mesh)& M = meshAttr->Get();
+  if (!M.IsNull())
+  {
+    Standard_Integer nbNodes = M->NbNodes();
+    Standard_Integer nbElements = M->NbElements();
+
+    // write number of elements
+    theTarget << nbNodes;
+    theTarget << nbElements;
+    theTarget << (M->HasUVNodes() ? 1 : 0);
+    // write the deflection
+    theTarget << M->Deflection();
+
+    // write 3d nodes
+    Standard_Integer i;
+    for (i = 1; i <= nbNodes; i++)
+    {
+      theTarget << M->Node(i).X();
+      theTarget << M->Node(i).Y();
+      theTarget << M->Node(i).Z();
+    }
+
+    // write 2d nodes
+    if (M->HasUVNodes())
+    {
+      for (i = 1; i <= nbNodes; i++)
+      {
+        theTarget << M->UVNode(i).X();
+        theTarget << M->UVNode(i).Y();
+      }
+    }
+
+    // write triangles and quadrangles
+    Standard_Integer n, n1, n2, n3, n4;
+    for (i = 1; i <= nbElements; i++)
+    {
+      M->Element(i, n1, n2, n3, n4);
+      n = (n4 > 0) ? 4 : 3;
+      theTarget << n;
+      theTarget << n1;
+      theTarget << n2;
+      theTarget << n3;
+      if (n4 > 0)
+        theTarget << n4;
+    }
+  }
+}
diff --git a/src/BinMDataStd/BinMDataStd_MeshDriver.hxx b/src/BinMDataStd/BinMDataStd_MeshDriver.hxx
new file mode 100644 (file)
index 0000000..67d1f08
--- /dev/null
@@ -0,0 +1,49 @@
+// 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 _BinMDataStd_MeshDriver_HeaderFile
+#define _BinMDataStd_MeshDriver_HeaderFile
+
+#include <Standard.hxx>
+#include <Standard_Type.hxx>
+
+#include <BinMDF_ADriver.hxx>
+#include <Standard_Boolean.hxx>
+#include <BinObjMgt_RRelocationTable.hxx>
+#include <BinObjMgt_SRelocationTable.hxx>
+class CDM_MessageDriver;
+class TDF_Attribute;
+class BinObjMgt_Persistent;
+
+DEFINE_STANDARD_HANDLE(BinMDataStd_MeshDriver, BinMDF_ADriver)
+
+//! TDataStd_Mesh attribute bin Driver.
+class BinMDataStd_MeshDriver : public BinMDF_ADriver
+{
+
+public:
+  
+  Standard_EXPORT BinMDataStd_MeshDriver(const Handle(CDM_MessageDriver)& theMessageDriver);
+  
+  Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
+  
+  Standard_EXPORT virtual Standard_Boolean Paste (const BinObjMgt_Persistent& Source, const Handle(TDF_Attribute)& Target, BinObjMgt_RRelocationTable& RelocTable) const Standard_OVERRIDE;
+  
+  Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& Source, BinObjMgt_Persistent& Target, BinObjMgt_SRelocationTable& RelocTable) const Standard_OVERRIDE;
+
+  DEFINE_STANDARD_RTTIEXT(BinMDataStd_MeshDriver,BinMDF_ADriver)
+};
+
+#endif // _BinMDataStd_MeshDriver_HeaderFile
index 49f0d5daafc373b8f7021e60ffe187d8f447643b..da2cca00592b20d533751bab54c4f3adb3abccd7 100644 (file)
@@ -26,6 +26,8 @@ BinMDataStd_IntegerListDriver.cxx
 BinMDataStd_IntegerListDriver.hxx
 BinMDataStd_IntPackedMapDriver.cxx
 BinMDataStd_IntPackedMapDriver.hxx
+BinMDataStd_MeshDriver.cxx
+BinMDataStd_MeshDriver.hxx
 BinMDataStd_NamedDataDriver.cxx
 BinMDataStd_NamedDataDriver.hxx
 BinMDataStd_NameDriver.cxx
index 3f0d45bf1b5588b4818d70c38dc97b8cb3579e0f..48a113b348792140bf78a8682d8d5bd3090dd729 100644 (file)
@@ -1407,24 +1407,23 @@ void BinTools_ShapeSet::WriteTriangulation(Standard_OStream& OS) const
 
     // write the 3d nodes
       nbNodes = T->NbNodes();
-      const TColgp_Array1OfPnt& Nodes = T->Nodes();
       for (j = 1; j <= nbNodes; j++) {
-       BinTools::PutReal(OS, Nodes(j).X());
-       BinTools::PutReal(OS, Nodes(j).Y());
-       BinTools::PutReal(OS, Nodes(j).Z());
+       const gp_Pnt& aNode = T->Node(j);
+       BinTools::PutReal(OS, aNode.X());
+       BinTools::PutReal(OS, aNode.Y());
+       BinTools::PutReal(OS, aNode.Z());
       }
     
       if (T->HasUVNodes()) {
-       const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
        for (j = 1; j <= nbNodes; j++) {
-         BinTools::PutReal(OS, UVNodes(j).X());
-         BinTools::PutReal(OS, UVNodes(j).Y());
+         const gp_Pnt2d& anUVNode = T->UVNode(j);
+         BinTools::PutReal(OS, anUVNode.X());
+         BinTools::PutReal(OS, anUVNode.Y());
        }
       }
       nbTriangles = T->NbTriangles();
-      const Poly_Array1OfTriangle& Triangles = T->Triangles();
       for (j = 1; j <= nbTriangles; j++) {
-       Triangles(j).Get(n1, n2, n3);
+       T->Triangle (j).Get(n1, n2, n3);
        BinTools::PutInteger(OS, n1);
        BinTools::PutInteger(OS, n2);
        BinTools::PutInteger(OS, n3);
index 3da810e7216ef91ab6ccbba2d811e7cbcb8e91d3..45c2129243dd94f805b4cd6a000b9c942ef298bf 100644 (file)
@@ -778,10 +778,9 @@ void  DBRep_DrawableShape::DrawOn(Draw_Display& dis) const
        BRep_Tool::PolygonOnTriangulation(E->Edge(), Poly, PolyTr, loc);
        if (!Poly.IsNull()) {
          const TColStd_Array1OfInteger& Indices = Poly->Nodes();
-         const TColgp_Array1OfPnt& Nodes = PolyTr->Nodes();
          for (i=Indices.Lower()+1; i<=Indices.Upper(); i++) {
-           dis.Draw(Nodes(Indices(i-1)).Transformed(loc),
-                    Nodes(Indices(i)).Transformed(loc));
+           dis.Draw(Tr->Node (Indices(i-1)).Transformed(loc),
+                    Tr->Node (Indices(i)).Transformed(loc));
            if (dis.HasPicked()) {
              pickshape = E->Edge();
              upick = 0;
@@ -1124,11 +1123,10 @@ void  DBRep_DrawableShape::Display(const Handle(Poly_Triangulation)& T,
   TColStd_DataMapOfIntegerInteger Internal;
   
   Standard_Integer fr = 1, in = 1;
-  const Poly_Array1OfTriangle& triangles = T->Triangles();
   Standard_Integer n[3];
   for (i = 1; i <= nbTriangles; i++) {
     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++) {
       Standard_Integer k = (j+1) % 3;
       if (t[j] == 0) {
@@ -1146,16 +1144,13 @@ void  DBRep_DrawableShape::Display(const Handle(Poly_Triangulation)& T,
   }
 
   // Display the edges
-  const TColgp_Array1OfPnt& Nodes = T->Nodes();
-//  cout<<"nb nodes = "<<Nodes.Length()<<endl;
-  
   // free edges
   Standard_Integer nn;
   dis.SetColor(Draw_rouge);
   nn = Free.Length() / 2;
   for (i = 1; i <= nn; i++) {
-    dis.Draw(Nodes(Free(2*i-1)).Transformed(tr),
-            Nodes(Free(2*i)).Transformed(tr));
+    dis.Draw(T->Node (Free(2*i-1)).Transformed(tr),
+            T->Node (Free(2*i)).Transformed(tr));
   }
   
   // internal edges
@@ -1167,8 +1162,8 @@ void  DBRep_DrawableShape::Display(const Handle(Poly_Triangulation)& T,
     //alvays pair is put
     aIt.Next();
     Standard_Integer n2 = aIt.Value();
-    dis.Draw(Nodes(n1).Transformed(tr),
-            Nodes(n2).Transformed(tr));
+    dis.Draw(T->Node (n1).Transformed(tr),
+            T->Node (n2).Transformed(tr));
 
   }
 }
index 88226d176d8a53dc1afc70991a57654fc3f42e95..dcbb8d948154ae32c7b62cb34d7bf0514a3e4a6f 100644 (file)
@@ -32,6 +32,7 @@
 #include <TDF_AttributeList.hxx>
 #include <TDF_ListIteratorOfAttributeList.hxx>
 
+#include <BRep_Tool.hxx>
 #include <DBRep.hxx>
 #include <TopAbs.hxx>
 #include <TopoDS.hxx>
@@ -52,6 +53,7 @@
 
 // LES ATTRIBUTES
 #include <TDataStd.hxx>
+#include <TDataStd_Mesh.hxx>
 #include <TDataStd_Comment.hxx>
 #include <TDataStd_Name.hxx>
 #include <TDataStd_Integer.hxx>
@@ -3733,6 +3735,98 @@ static Standard_Integer DDataStd_GetRefArrayValue (Draw_Interpretor& di,
   return 0; 
 } 
 
+//=======================================================================
+//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) DF;
+    if (!DDF::GetDF(arg[1],DF))
+      return 1;
+
+    TDF_Label L;
+    if (!DDF::AddLabel(DF, arg[2], L))
+      return 1;
+
+    // Get face.
+    TopoDS_Shape face = DBRep::Get(arg[3]);
+    if (face.IsNull() ||
+        face.ShapeType() != TopAbs_FACE)
+    {
+      di << "The face is null or not a face.\n";
+      return 1;
+    }
+
+    // Get triangulation of the face.
+    TopLoc_Location loc;
+    Handle(Poly_Triangulation) tris = BRep_Tool::Triangulation(TopoDS::Face(face), loc);
+    if (tris.IsNull())
+    {
+      di << "No triangulation in the face.\n";
+      return 1;
+    }
+
+    // Make a mesh.
+    Handle(Poly_Mesh) mesh = new Poly_Mesh(tris);
+
+    // Set the attribute.
+    TDataStd_Mesh::Set(L, mesh);
+    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) DF;
+    if (!DDF::GetDF(arg[1],DF))
+      return 1;
+
+    Handle(TDataStd_Mesh) M;
+    if (!DDF::Find(DF,arg[2],TDataStd_Mesh::GetID(),M))
+    {
+      di << "The attribute mesh doesn't exist at the label.\n";
+      return 1;
+    }
+
+    // Dump of the mesh.
+    if (M->Get().IsNull())
+    {
+      di << "No mesh in the attribute.\n";
+      return 1;
+    }
+
+    di << "Deflection            " << M->Deflection() <<"\n";
+    di << "Number of nodes       " << M->NbNodes() << "\n";
+    di << "Number of triangles   " << M->NbTriangles() << "\n";
+    di << "Number of quadrangles " << M->NbQuads() << "\n";
+    if (M->HasUVNodes())
+        di << "It has 2d-nodes\n";
+    if (M->HasNormals())
+        di << "It has normals\n";
+
+    return 0;
+  }
+  di << "DDataStd_DumpMesh : Error\n";
+  return 1;
+}
+
 //=======================================================================
 //function : BasicCommands
 //purpose  : 
@@ -3850,6 +3944,13 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands)
                    "SetReferenceList (DF, entry, elmt1, elmt2, ...  )",
                    __FILE__, DDataStd_SetReferenceList, 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);
+
+   // Insert before and after (for lists)
+
    theCommands.Add ("InsertBeforeExtStringList", 
                    "InsertBeforeExtStringList (DF, entry, index, value )",
                    __FILE__, DDataStd_InsertBeforeExtStringList, g);
@@ -4156,6 +4257,10 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands)
 
 //=========================================================
 
+   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);
 
 //======================================================================
 //======= for internal use
index ddc1ad269699a1024739a621b39428825087a5ff..49b0dc0b7ee2f923982b5bf13db32de9cf0b17a0 100644 (file)
@@ -64,11 +64,10 @@ DrawTrSurf_Triangulation::DrawTrSurf_Triangulation
   TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
 
   Standard_Integer fr = 1, in = 1;
-  const Poly_Array1OfTriangle& triangles = T->Triangles();
   Standard_Integer n[3];
   for (i = 1; i <= nbTriangles; i++) {
     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++) {
       Standard_Integer k = (j+1) % 3;
       if (t[j] == 0) {
@@ -146,15 +145,13 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
   // Display the edges
   Standard_Integer i,n;
 
-  const TColgp_Array1OfPnt& Nodes = myTriangulation->Nodes();
-  
   // free edges
 
   dis.SetColor(Draw_rouge);
   const TColStd_Array1OfInteger& Free = myFree->Array1();
   n = Free.Length() / 2;
   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
@@ -163,7 +160,7 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
   const TColStd_Array1OfInteger& Internal = myInternals->Array1();
   n = Internal.Length() / 2;
   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
@@ -173,7 +170,7 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
     n = myTriangulation->NbNodes();
     for (i = 1; i <= n; i++) {
       Sprintf(text,"%d",i);
-      dis.DrawString(Nodes(i),text);
+      dis.DrawString(myTriangulation->Node (i),text);
     }
   }
 
@@ -181,13 +178,12 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const
     dis.SetColor(Draw_vert);
     n = myTriangulation->NbTriangles();
     Standard_Integer t[3],j;
-    const Poly_Array1OfTriangle& triangle = myTriangulation->Triangles();
     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_XYZ& bary = P.ChangeCoord();
       for (j = 0; j < 3; j++)
-       bary.Add(Nodes(t[j]).Coord());
+       bary.Add(myTriangulation->Node (t[j]).Coord());
       bary.Multiply(1./3.);
 
       Sprintf(text,"%d",i);
index 88ba30c3f8b4c24589fead44d73a5a1fca3e27c8..c039024dfcdec06733cb33221cf0ac6a626f8732 100644 (file)
@@ -67,11 +67,10 @@ DrawTrSurf_Triangulation2D::DrawTrSurf_Triangulation2D
   TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1();
 
   Standard_Integer fr = 1, in = 1;
-  const Poly_Array1OfTriangle& triangles = T->Triangles();
   Standard_Integer n[3];
   for (i = 1; i <= nbTriangles; i++) {
     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++) {
       Standard_Integer k = (j+1) % 3;
       if (t[j] == 0) {
@@ -109,16 +108,14 @@ void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const
   // Display the edges
   Standard_Integer i,n;
   if (myTriangulation->HasUVNodes()) {
-    
-    const TColgp_Array1OfPnt2d& Nodes = myTriangulation->UVNodes();
-    
+
     // free edges
     
     dis.SetColor(Draw_rouge);
     const TColStd_Array1OfInteger& Free = myFree->Array1();
     n = Free.Length() / 2;
     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
@@ -127,7 +124,7 @@ void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const
     const TColStd_Array1OfInteger& Internal = myInternals->Array1();
     n = Internal.Length() / 2;
     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)));
     }
     
   }
index 134b6c7451a58bb479ef3c15b6c9ff103d1fe8bc..d1a213262cc0cfd80cab50d4e30309e341b56173 100644 (file)
@@ -812,10 +812,8 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape,
          TTMa[2][0] = ttma.Value(3,1);
          TTMa[2][1] = ttma.Value(3,2);
          TTMa[2][2] = ttma.Value(3,3);
-         Poly_Array1OfTriangle & Tri = Tr->ChangeTriangles();
-         TColgp_Array1OfPnt    & Nod = Tr->ChangeNodes();
-         Standard_Integer nbN = Nod.Upper();
-         Standard_Integer nbT = Tri.Upper();
+         Standard_Integer nbN = Tr->NbNodes();
+         Standard_Integer nbT = Tr->NbTriangles();
          PD (f) = new HLRAlgo_PolyData();
          psd->PolyData().ChangeValue(iFace) = PD(f);
          PID(f) = new HLRAlgo_PolyInternalData(nbN,nbT);
@@ -829,24 +827,21 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape,
          Standard_Address TData = &pid->TData();
          Standard_Address PISeg = &pid->PISeg();
          Standard_Address PINod = &pid->PINod();
-         Poly_Triangle       * OT = &(Tri.ChangeValue(1));
          HLRAlgo_TriangleData* NT =
            &(((HLRAlgo_Array1OfTData*)TData)->ChangeValue(1));
 
          for (i = 1; i <= nbT; i++) {
            Standard_Address Tri2Indices = NT->Indices();
-           OT->Get(Tri2Node1,Tri2Node2,Tri2Node3);
+           Tr->Triangle (i).Get(Tri2Node1, Tri2Node2, Tri2Node3);
            Tri2Flags = 0;
            if (reversed) {
              j         = Tri2Node1;
              Tri2Node1 = Tri2Node3;
              Tri2Node3 = j;
            }
-           OT++;
            NT++;
          }
 
-         gp_Pnt                          * ON = &(Nod.ChangeValue(1));
          Handle(HLRAlgo_PolyInternalNode)* NN = 
            &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(1));
 
@@ -855,26 +850,23 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape,
            const Standard_Address Nod1Indices = (*NN)->Indices();
            Nod1NdSg = 0;
            Nod1Flag = 0;
-           Nod1PntX = ON->X();
-           Nod1PntY = ON->Y();
-           Nod1PntZ = ON->Z();
+           Nod1PntX = Tr->Node (i).X();
+           Nod1PntY = Tr->Node(i).Y();
+           Nod1PntZ = Tr->Node(i).Z();
            TTMultiply(Nod1PntX,Nod1PntY,Nod1PntZ);
-           ON++;
            NN++;
          }
          pid->UpdateLinks(TData,PISeg,PINod);
          if (Tr->HasUVNodes()) {
            myBSurf.Initialize(F,Standard_False);
-           TColgp_Array1OfPnt2d & UVN = Tr->ChangeUVNodes();
-           gp_Pnt2d* OUVN = &(UVN.ChangeValue(1));
            NN             = &(((HLRAlgo_Array1OfPINod*)PINod)->
                               ChangeValue(1));
            
            for (i = 1; i <= nbN; i++) {
              const Standard_Address Nod1Indices = (*NN)->Indices();
              const Standard_Address Nod1RValues = (*NN)->RValues();
-             Nod1PntU = OUVN->X();
-             Nod1PntV = OUVN->Y();
+             Nod1PntU = Tr->UVNode (i).X();
+             Nod1PntV = Tr->UVNode (i).Y();
              if (Normal(i,Nod1Indices,Nod1RValues,
                         TData,PISeg,PINod,Standard_False))
                Nod1Flag |=  NMskNorm;
@@ -882,7 +874,6 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape,
                Nod1Flag &= ~NMskNorm;
                Nod1Scal = 0;
              }
-             OUVN++;
              NN++;
            }
          }
index 2adc977964e7ec365ae17ba763f69aadfc648897..606006e425d2574891000643532391026a90b0e6 100644 (file)
@@ -379,7 +379,12 @@ void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge&  theEdge,
   {
     Standard_Integer aNbNodes = aPolyOnTriangulation->NbNodes();
     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,
                      aPoints,
@@ -943,7 +948,6 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
   }
 
   // Get triangulation points.
-  const TColgp_Array1OfPnt& aPoints = anOcctTriangulation->Nodes();
   Standard_Integer aNbPoints = anOcctTriangulation->NbNodes();
 
   // Keep inserted points id's of triangulation in an array.
@@ -953,7 +957,7 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
   Standard_Integer anI;
   for (anI = 1; anI <= aNbPoints; anI++)
   {
-    gp_Pnt aPoint = aPoints (anI);
+    gp_Pnt aPoint = anOcctTriangulation->Node(anI);
 
     if (!noTransform)
     {
@@ -966,12 +970,11 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
   }
 
   // Create triangles on the created triangulation points.
-  const Poly_Array1OfTriangle& aTriangles = anOcctTriangulation->Triangles();
   Standard_Integer aNbTriangles = anOcctTriangulation->NbTriangles();
   Standard_Integer aN1, aN2, aN3;
   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.
     myShapeData->InsertTriangle (
       theShapeId, aPointIds(aN1), aPointIds(aN2), aPointIds(aN3), MT_ShadedFace);
index fc6165f8f814f0ef438121d04d9c98c75b270e91..9ebe2b504959bda49fada3fd7aa02a2286c46164 100644 (file)
@@ -304,7 +304,6 @@ static Standard_Integer tessellate (Draw_Interpretor& /*di*/, Standard_Integer n
     new Poly_Triangulation (aNbNodes, aNbTriangles, Standard_False);
 
   // fill nodes
-  TColgp_Array1OfPnt &aNodes = aTriangulation->ChangeNodes();
   GeomAdaptor_Surface anAdSurf (aSurf);
   double aDU = (aUMax - aUMin) / aNbU;
   double aDV = (aVMax - aVMin) / aNbV;
@@ -315,12 +314,11 @@ static Standard_Integer tessellate (Draw_Interpretor& /*di*/, Standard_Integer n
     {
       double aV = aVMin + iV * aDV;
       gp_Pnt aP = anAdSurf.Value (aU, aV);
-      aNodes.SetValue (iShift + iV, aP);
+      aTriangulation->ChangeNode(iShift + iV) = aP;
     }
   }
 
   // fill triangles
-  Poly_Array1OfTriangle &aTriangles = aTriangulation->ChangeTriangles();
   for (int iU = 0, iShift = 1, iTri = 0; iU < aNbU; iU++, iShift += aNbV + 1)
   {
     for (int iV = 0; iV < aNbV; iV++)
@@ -328,8 +326,8 @@ static Standard_Integer tessellate (Draw_Interpretor& /*di*/, Standard_Integer n
       int iBase = iShift + iV;
       Poly_Triangle aTri1 (iBase, iBase + aNbV + 2, iBase + 1);
       Poly_Triangle aTri2 (iBase, iBase + aNbV + 1, iBase + aNbV + 2);
-      aTriangles.SetValue (++iTri, aTri1);
-      aTriangles.SetValue (++iTri, aTri2);
+      aTriangulation->ChangeTriangle(++iTri) = aTri1;
+      aTriangulation->ChangeTriangle(++iTri) = aTri2;
     }
   }
 
@@ -578,10 +576,9 @@ static void MeshStats(const TopoDS_Shape& theSape,
 
       BRepMesh_MapOfCouple aMap;
       //count number of links
-      Poly_Array1OfTriangle& Trian = T->ChangeTriangles();
-      for(Standard_Integer i = 1; i<=Trian.Length();i++) {
+      for(Standard_Integer i = 1; i<=T->NbTriangles();i++) {
         Standard_Integer v1, v2, v3;
-        Trian(i).Get(v1,v2,v3);
+        T->Triangle (i).Get(v1,v2,v3);
 
         AddLink(aMap, v1, v2);
         AddLink(aMap, v2, v3);
@@ -647,9 +644,8 @@ static Standard_Integer triangule(Draw_Interpretor& di, Standard_Integer nbarg,
     if (!aTriangulation.IsNull())
     {
       const Standard_Integer    aLength = aTriangulation->NbNodes();
-      const TColgp_Array1OfPnt& aNodes  = aTriangulation->Nodes();
       for (Standard_Integer i = 1; i <= aLength; ++i)
-        aBox.Add(aNodes(i));
+        aBox.Add(aTriangulation->Node (i));
     }
   }
 
@@ -1181,21 +1177,18 @@ static Standard_Integer veriftriangles(Draw_Interpretor& di, Standard_Integer n,
     Standard_Real deflemax = 0, deflemin = 1.e100;
     if (!T.IsNull()) {
       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);
 
-      for(i = 1; i <= triangles.Length(); i++) {
+      for(i = 1; i <= T->NbTriangles(); i++) {
         if (F.Orientation() == TopAbs_REVERSED) 
-          triangles(i).Get(n1,n3,n2);
+          T->Triangle (i).Get(n1,n3,n2);
         else 
-          triangles(i).Get(n1,n2,n3);
+          T->Triangle (i).Get(n1,n2,n3);
 
-        const gp_XY& xy1 = Nodes2d(n1).XY();
-        const gp_XY& xy2 = Nodes2d(n2).XY();
-        const gp_XY& xy3 = Nodes2d(n3).XY();
+        const gp_XY& xy1 = T->UVNode (n1).XY();
+        const gp_XY& xy2 = T->UVNode (n2).XY();
+        const gp_XY& xy3 = T->UVNode (n3).XY();
 
         mi2d1.SetCoord((xy2.X()+xy3.X())*0.5, 
           (xy2.Y()+xy3.Y())*0.5);
@@ -1204,9 +1197,9 @@ static Standard_Integer veriftriangles(Draw_Interpretor& di, Standard_Integer n,
         mi2d3.SetCoord((xy1.X()+xy2.X())*0.5, 
           (xy1.Y()+xy2.Y())*0.5);
 
-        gp_XYZ p1 = Nodes(n1).Transformed(L.Transformation()).XYZ();
-        gp_XYZ p2 = Nodes(n2).Transformed(L.Transformation()).XYZ();
-        gp_XYZ p3 = Nodes(n3).Transformed(L.Transformation()).XYZ();
+        gp_XYZ p1 = T->Node (n1).Transformed (L.Transformation()).XYZ();
+        gp_XYZ p2 = T->Node (n2).Transformed (L.Transformation()).XYZ();
+        gp_XYZ p3 = T->Node (n3).Transformed (L.Transformation()).XYZ();
 
         vecEd1=p2-p1;
         vecEd2=p3-p2;
@@ -1332,11 +1325,10 @@ Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char** a)
     TColStd_Array1OfInteger Internal(0,2*nInternal);
 
     Standard_Integer fr = 1, in = 1;
-    const Poly_Array1OfTriangle& triangles = T->Triangles();
     Standard_Integer nodes[3];
     for (i = 1; i <= nbTriangles; i++) {
       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++) {
         Standard_Integer k = (j+1) % 3;
         if (t[j] == 0) {
@@ -1355,16 +1347,14 @@ Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char** a)
 
     // Display the edges
     if (T->HasUVNodes()) {
-      const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes();
-
       Handle(Draw_Segment2D) Seg;
 
       // free edges
       Standard_Integer nn;
       nn = Free.Length() / 2;
       for (i = 1; i <= nn; i++) {
-        Seg = new Draw_Segment2D(Nodes2d(Free(2*i-1)),
-          Nodes2d(Free(2*i)),
+        Seg = new Draw_Segment2D(T->UVNode (Free(2*i-1)),
+          T->UVNode (Free(2*i)),
           Draw_rouge);
         dout << Seg;
       }
@@ -1373,8 +1363,8 @@ Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char** a)
 
       nn = nInternal;
       for (i = 1; i <= nn; i++) {
-        Seg = new Draw_Segment2D(Nodes2d(Internal(2*i-1)),
-          Nodes2d(Internal(2*i)),
+        Seg = new Draw_Segment2D(T->UVNode (Internal(2*i-1)),
+          T->UVNode (Internal(2*i)),
           Draw_bleu);
         dout << Seg;
       }
@@ -1448,11 +1438,10 @@ static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, con
 
     if (!Tr.IsNull()) {
       nbNodes = Tr->NbNodes();
-      const TColgp_Array1OfPnt& Nodes = Tr->Nodes();
 
       // les noeuds.
       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();
         y = Pnt.Y();
         z = Pnt.Z();
@@ -1465,12 +1454,11 @@ static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, con
       // les normales.
 
       if (Tr->HasUVNodes()) {
-        const TColgp_Array1OfPnt2d& UVNodes = Tr->UVNodes();
         BRepAdaptor_Surface BS(F, Standard_False);
 
         for (i = 1; i <= nbNodes; i++) {
-          U = UVNodes(i).X();
-          V = UVNodes(i).Y();
+          U = Tr->UVNode (i).X();
+          V = Tr->UVNode (i).Y();
 
           BS.D1(U,V,P,D1U,D1V);
           CSLib::Normal(D1U,D1V,Precision::Angular(),Status,Nor);
@@ -1490,14 +1478,12 @@ static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, con
 
       // les triangles.
       Standard_Integer nbTriangles = Tr->NbTriangles();
-      const Poly_Array1OfTriangle& triangles = Tr->Triangles();
-
 
       for (i = 1; i <= nbTriangles; i++) {
         if (F.Orientation()  == TopAbs_REVERSED)
-          triangles(i).Get(n1, n3, n2);
+          Tr->Triangle (i).Get(n1, n3, n2);
         else 
-          triangles(i).Get(n1, n2, n3);
+          Tr->Triangle (i).Get(n1, n2, n3);
         k1 = n1+totalnodes;
         k2 = n2+totalnodes;
         k3 = n3+totalnodes;
@@ -1707,14 +1693,13 @@ Standard_Integer triedgepoints(Draw_Interpretor& di, Standard_Integer nbarg, con
       BRep_Tool::PolygonOnTriangulation(TopoDS::Edge(it.Key()), aPoly, aT, aLoc);
       if ( aT.IsNull() || aPoly.IsNull() )
         continue;
-      
-      const TColgp_Array1OfPnt&      Nodes   = aT->Nodes();
+
       const TColStd_Array1OfInteger& Indices = aPoly->Nodes();
       const Standard_Integer         nbnodes = Indices.Length();
 
       for( Standard_Integer j = 1; j <= nbnodes; j++ )
       {
-        gp_Pnt P3d = Nodes(Indices(j));
+        gp_Pnt P3d = aT->Node (Indices(j));
         if( !aLoc.IsIdentity() )
           P3d.Transform(aLoc.Transformation());
 
index c0887c65f17766f293b0a12b4d2733a5ebe4a659..eb785ca4d10b12c8c43685acd7f6b621bcb04617 100644 (file)
@@ -88,8 +88,6 @@ void MeshTest_CheckTopology::Perform (Draw_Interpretor& di)
 
       // check distances between corresponding points
       Standard_Real aDefle = Max(aT1->Deflection(), aT2->Deflection());
-      const TColgp_Array1OfPnt& aPoints1 = aT1->Nodes();
-      const TColgp_Array1OfPnt& aPoints2 = aT2->Nodes();
       Standard_Integer iF1 = aMapF.FindIndex(aFace1);
       Standard_Integer iF2 = aMapF.FindIndex(aFace2);
       Standard_Integer i1 = aNodes1.Lower();
@@ -97,8 +95,8 @@ void MeshTest_CheckTopology::Perform (Draw_Interpretor& di)
       gp_Trsf aTrsf1 = aFace1.Location().Transformation();
       gp_Trsf aTrsf2 = aFace2.Location().Transformation();
       for (; i1 <= aNodes1.Upper(); i1++, i2++) {
-       gp_Pnt aP1 = aPoints1(aNodes1(i1)).Transformed(aTrsf1);
-       gp_Pnt aP2 = aPoints2(aNodes2(i2)).Transformed(aTrsf2);
+       gp_Pnt aP1 = aT1->Node (aNodes1(i1)).Transformed(aTrsf1);
+       gp_Pnt aP2 = aT2->Node (aNodes2(i2)).Transformed(aTrsf2);
        Standard_Real aDist = aP1.Distance(aP2);
        if (aDist > aDefle) {
          myErrors.Append(iF1);
@@ -140,10 +138,9 @@ void MeshTest_CheckTopology::Perform (Draw_Interpretor& di)
 
     // check of free links and nodes
     Poly_Connect aConn(aT);
-    const Poly_Array1OfTriangle& aTriangles = aT->Triangles();
     Standard_Integer nbTri = aT->NbTriangles(), i, j, n[3], t[3];
     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[1]);
index 5385c51e55016226e40b0565defecd1f5b1ce35a..d6f4bdda5863a4586651714bf8f65b7868299e79 100644 (file)
@@ -253,10 +253,9 @@ void MeshTest_DrawableMesh::Whatis(Draw_Interpretor& theStream) const
 
     // Count number of links
     BRepMesh_MapOfLinks aMap;
-    const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
-    for (Standard_Integer i = 1, v[3]; i <= aTriangles.Length(); ++i)
+    for (Standard_Integer i = 1, v[3]; i <= aTriangulation->NbTriangles(); ++i)
     {
-      aTriangles(i).Get(v[0], v[1], v[2]);
+      aTriangulation->Triangle (i).Get(v[0], v[1], v[2]);
 
       addLink(v[0], v[1], aMap);
       addLink(v[1], v[2], aMap);
index 0e8e5092381a9ebe8dd341ae798bd05cf7d3b5b1..fad5a76b06604c0fa7d08445d4b4722774118ff3 100644 (file)
@@ -300,15 +300,13 @@ static Standard_Integer triarea (Draw_Interpretor& di, int n, const char ** a)
         cout << "face "<<i<<" has no triangulation"<<endl;
         continue;
       }
-      const Poly_Array1OfTriangle& triangles = aPoly->Triangles();
-      const TColgp_Array1OfPnt& nodes = aPoly->Nodes();
-      for (int j=triangles.Lower(); j <= triangles.Upper(); j++) {
-        const Poly_Triangle& tri = triangles(j);
+      for (int j = 1; j <= aPoly->NbTriangles(); j++) {
+        const Poly_Triangle& tri = aPoly->Triangle (j);
         int n1, n2, n3;
         tri.Get (n1, n2, n3);
-        const gp_Pnt& p1 = nodes(n1);
-        const gp_Pnt& p2 = nodes(n2);
-        const gp_Pnt& p3 = nodes(n3);
+        const gp_Pnt& p1 = aPoly->Node (n1);
+        const gp_Pnt& p2 = aPoly->Node (n2);
+        const gp_Pnt& p3 = aPoly->Node (n3);
         gp_Vec v1(p1, p2);
         gp_Vec v2(p1, p3);
         double ar = v1.CrossMagnitude(v2);
@@ -365,7 +363,6 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
       const TopoDS_Face& aFace = TopoDS::Face(aShape);
       TopLoc_Location aLoc;
       Handle(Poly_Triangulation) aT = BRep_Tool::Triangulation(aFace, aLoc);
-      const TColgp_Array1OfPnt& aPoints = aT->Nodes();
       const gp_Trsf& trsf = aLoc.Transformation();
 
       TColgp_Array1OfPnt pnts(1,2);
@@ -374,17 +371,16 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
         Standard_Integer n1, n2;
         aCheck.GetFreeLink(k, i, n1, n2);
         di << "{" << n1 << " " << n2 << "} ";
-        pnts(1) = aPoints(n1).Transformed(trsf);
-        pnts(2) = aPoints(n2).Transformed(trsf);
+        pnts(1) = aT->Node (n1).Transformed(trsf);
+        pnts(2) = aT->Node (n2).Transformed(trsf);
         Handle(Poly_Polygon3D) poly = new Poly_Polygon3D (pnts);
         DrawTrSurf::Set (name, poly);
         DrawTrSurf::Set (name, pnts(1));
         DrawTrSurf::Set (name, pnts(2));
         if (aT->HasUVNodes())
         {
-          const TColgp_Array1OfPnt2d& aPoints2d = aT->UVNodes();
-          pnts2d(1) = aPoints2d(n1);
-          pnts2d(2) = aPoints2d(n2);
+          pnts2d(1) = aT->UVNode (n1);
+          pnts2d(2) = aT->UVNode (n2);
           Handle(Poly_Polygon2D) poly2d = new Poly_Polygon2D (pnts2d);
           DrawTrSurf::Set (name, poly2d);
           DrawTrSurf::Set (name, pnts2d(1));
@@ -430,12 +426,11 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
       const TopoDS_Face& aFace = TopoDS::Face(aMapF.FindKey(iface));
       TopLoc_Location aLoc;
       Handle(Poly_Triangulation) aT = BRep_Tool::Triangulation(aFace, aLoc);
-      const TColgp_Array1OfPnt& aPoints = aT->Nodes();
       const gp_Trsf& trsf = aLoc.Transformation();
-      DrawTrSurf::Set (name, aPoints(inode).Transformed(trsf));
+      DrawTrSurf::Set (name, aT->Node(inode).Transformed(trsf));
       if (aT->HasUVNodes())
       {
-        DrawTrSurf::Set (name, aT->UVNodes()(inode));
+        DrawTrSurf::Set (name, aT->UVNode(inode));
       }
 
       di << "{" << iface << " " << inode << "} ";
@@ -496,12 +491,11 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
       break;
     }
 
-    const Poly_Array1OfTriangle& aTris = aT->Triangles();
     NCollection_Map<BRepMesh_Edge> aFreeEdgeMap;
-    Standard_Integer aTriNum = aTris.Length();
+    Standard_Integer aTriNum = aT->NbTriangles();
     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)};
 
       for (Standard_Integer j = 1; j <= 3; ++j)
@@ -524,7 +518,6 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
     {
       di << "Not connected mesh inside face " << aFaceId << "\n";
 
-      const TColgp_Array1OfPnt& aPoints = aT->Nodes();
       const gp_Trsf& trsf = aLoc.Transformation();
 
       TColgp_Array1OfPnt pnts(1,2);
@@ -534,17 +527,16 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a)
       {
         const BRepMesh_Edge& aLink = aMapIt.Key();
         di << "{" << aLink.FirstNode() << " " << aLink.LastNode() << "} ";
-        pnts(1) = aPoints(aLink.FirstNode()).Transformed(trsf);
-        pnts(2) = aPoints(aLink.LastNode()).Transformed(trsf);
+        pnts(1) = aT->Node(aLink.FirstNode()).Transformed(trsf);
+        pnts(2) = aT->Node(aLink.LastNode()).Transformed(trsf);
         Handle(Poly_Polygon3D) poly = new Poly_Polygon3D (pnts);
         DrawTrSurf::Set (name, poly);
         DrawTrSurf::Set (name, pnts(1));
         DrawTrSurf::Set (name, pnts(2));
         if (aT->HasUVNodes())
         {
-          const TColgp_Array1OfPnt2d& aPoints2d = aT->UVNodes();
-          pnts2d(1) = aPoints2d(aLink.FirstNode());
-          pnts2d(2) = aPoints2d(aLink.LastNode());
+          pnts2d(1) = aT->UVNode(aLink.FirstNode());
+          pnts2d(2) = aT->UVNode(aLink.LastNode());
           Handle(Poly_Polygon2D) poly2d = new Poly_Polygon2D (pnts2d);
           DrawTrSurf::Set (name, poly2d);
           DrawTrSurf::Set (name, pnts2d(1));
index 641d172ec00244871c0272125a8d1d82fc308ec1..170352103cc808a458f5392f3a4da238cecf5667 100755 (executable)
@@ -14,22 +14,25 @@ Poly_CoherentTriPtr.hxx
 Poly_Connect.cxx
 Poly_Connect.hxx
 Poly_Connect.lxx
+Poly_Element.cxx
+Poly_Element.hxx
 Poly_HArray1OfTriangle.hxx
 Poly_ListOfTriangulation.hxx
 Poly_MakeLoops.cxx
 Poly_MakeLoops.hxx
-Poly_Polygon2D.cxx
+Poly_Mesh.cxx
+Poly_Mesh.hxx
 Poly_Polygon2D.hxx
+Poly_Polygon2D.cxx
 Poly_Polygon2D.lxx
-Poly_Polygon3D.cxx
 Poly_Polygon3D.hxx
+Poly_Polygon3D.cxx
 Poly_Polygon3D.lxx
-Poly_PolygonOnTriangulation.cxx
 Poly_PolygonOnTriangulation.hxx
+Poly_PolygonOnTriangulation.cxx
 Poly_PolygonOnTriangulation.lxx
-Poly_Triangle.cxx
 Poly_Triangle.hxx
+Poly_Triangle.cxx
 Poly_Triangle.lxx
-Poly_Triangulation.cxx
 Poly_Triangulation.hxx
-Poly_Triangulation.lxx
+Poly_Triangulation.cxx
\ No newline at end of file
index 63db7243c9ff9c38fd1b9979ea119e5846f42bd4..ff375f6d318a46996694a495a124c5957d266328 100644 (file)
@@ -57,23 +57,19 @@ Handle(Poly_Triangulation) Poly::Catenate (const Poly_ListOfTriangulation& lstTr
     Standard_Integer i, iNode[3];
     nNodes = 0;
     nTrian = 0;
-    TColgp_Array1OfPnt&    arrNode  = aResult->ChangeNodes();
-    Poly_Array1OfTriangle& arrTrian = aResult->ChangeTriangles();
     for (anIter.Init(lstTri); anIter.More(); anIter.Next()) {
       const Handle(Poly_Triangulation)& aTri = anIter.Value();
       if (aTri.IsNull() == Standard_False) {
-        const TColgp_Array1OfPnt&    srcNode  = aTri->Nodes();
-        const Poly_Array1OfTriangle& srcTrian = aTri->Triangles();
         const Standard_Integer nbNodes = aTri->NbNodes(); 
         const Standard_Integer nbTrian = aTri->NbTriangles(); 
         for (i = 1; i <= nbNodes; i++) {
-          arrNode.SetValue(i + nNodes, srcNode(i));
+          aResult->ChangeNode (i + nNodes) = aTri->Node (i);
         }
         for (i = 1; i <= nbTrian; i++) {
-          srcTrian(i).Get(iNode[0], iNode[1], iNode[2]);
-          arrTrian.SetValue(i + nTrian, Poly_Triangle(iNode[0] + nNodes,
+          aTri->Triangle (i).Get(iNode[0], iNode[1], iNode[2]);
+          aResult->ChangeTriangle (i + nTrian) = Poly_Triangle(iNode[0] + nNodes,
                                                       iNode[1] + nNodes,
-                                                      iNode[2] + nNodes));
+                                                      iNode[2] + nNodes);
         }
         nNodes += nbNodes;
         nTrian += nbTrian;
@@ -113,36 +109,33 @@ void Poly::Write(const Handle(Poly_Triangulation)& T,
   if (!Compact) OS << "\n3D Nodes :\n";
 
   Standard_Integer i, nbNodes = T->NbNodes();
-  const TColgp_Array1OfPnt& Nodes = T->Nodes();
   for (i = 1; i <= nbNodes; i++) {
     if (!Compact) OS << setw(10) << i << " : ";
     if (!Compact) OS << setw(17);
-    OS << Nodes(i).X() << " ";
+    OS << T->Node (i).X() << " ";
     if (!Compact) OS << setw(17);
-    OS << Nodes(i).Y() << " ";
+    OS << T->Node (i).Y() << " ";
     if (!Compact) OS << setw(17);
-    OS << Nodes(i).Z() << "\n";
+    OS << T->Node (i).Z() << "\n";
   }
 
   if (T->HasUVNodes()) {
     if (!Compact) OS << "\nUV Nodes :\n";
-    const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
     for (i = 1; i <= nbNodes; i++) {
       if (!Compact) OS << setw(10) << i << " : ";
     if (!Compact) OS << setw(17);
-      OS << UVNodes(i).X() << " ";
+      OS << T->UVNode (i).X() << " ";
     if (!Compact) OS << setw(17);
-      OS << UVNodes(i).Y() << "\n";
+      OS << T->UVNode (i).Y() << "\n";
     }
   }
 
   if (!Compact) OS << "\nTriangles :\n";
   Standard_Integer nbTriangles = T->NbTriangles();
   Standard_Integer n1, n2, n3;
-  const Poly_Array1OfTriangle& Triangles = T->Triangles();
   for (i = 1; i <= nbTriangles; i++) {
     if (!Compact) OS << setw(10) << i << " : ";
-    Triangles(i).Get(n1, n2, n3);
+    T->Triangle(i).Get(n1, n2, n3);
     if (!Compact) OS << setw(10);
     OS << n1 << " ";
     if (!Compact) OS << setw(10);
@@ -448,8 +441,6 @@ Handle(Poly_Polygon2D) Poly::ReadPolygon2D(Standard_IStream& IS)
 
 void  Poly::ComputeNormals(const Handle(Poly_Triangulation)& Tri)
 {
-  const TColgp_Array1OfPnt&     arrNodes = Tri->Nodes();
-  const Poly_Array1OfTriangle & arrTri   = Tri->Triangles();
   Standard_Integer              nbNormVal  = Tri->NbNodes() * 3;
   const Handle(TShort_HArray1OfShortReal) Normals =
     new TShort_HArray1OfShortReal(1, nbNormVal);
@@ -462,12 +453,12 @@ void  Poly::ComputeNormals(const Handle(Poly_Triangulation)& Tri)
   Standard_Integer              iN, iTri;
   const Standard_Real eps2 = gp::Resolution();
 
-  for (iTri = 1; iTri <= arrTri.Length(); iTri++) {
+  for (iTri = 1; iTri <= Tri->NbTriangles(); iTri++) {
     // Get the nodes of the current triangle
-    arrTri(iTri).Get (iNode[0], iNode[1], iNode[2]);
+    Tri->Triangle (iTri).Get (iNode[0], iNode[1], iNode[2]);
       const gp_XYZ aVec[2] = {
-        arrNodes(iNode[1]).XYZ() - arrNodes(iNode[0]).XYZ(),
-        arrNodes(iNode[2]).XYZ() - arrNodes(iNode[0]).XYZ()
+        Tri->Node (iNode[1]).XYZ() - Tri->Node (iNode[0]).XYZ(),
+        Tri->Node (iNode[2]).XYZ() - Tri->Node (iNode[0]).XYZ()
       };
 
     // Find the normal vector of the current triangle
index 0c2f7617ae2fc1f705f6c70937e75441a1f01f84..f15a72aafa5eb1e6b35433456445c192cd43f335 100644 (file)
@@ -51,44 +51,37 @@ Poly_CoherentTriangulation::Poly_CoherentTriangulation
              : theAlloc)
 {
   if (theTriangulation.IsNull() == Standard_False) {
-    const TColgp_Array1OfPnt&    arrNodes    = theTriangulation->Nodes();
-    const Poly_Array1OfTriangle& arrTriangle = theTriangulation->Triangles();
     const Standard_Integer nNodes = theTriangulation->NbNodes();
-    const Standard_Integer nTri   = theTriangulation->NbTriangles();
     Standard_Integer i;
 
     // Copy the nodes
     for (i = 0; i < nNodes; i++) {
-      const Standard_Integer anOldInd = i + arrNodes.Lower();
-      const Standard_Integer aNewInd = SetNode(arrNodes(anOldInd).XYZ(), i);
+      const Standard_Integer anOldInd = i + 1;
+      const Standard_Integer aNewInd = SetNode(theTriangulation->Node (anOldInd).XYZ(), i);
       Poly_CoherentNode& aCopiedNode = myNodes(aNewInd);
       aCopiedNode.SetIndex(anOldInd);
     }
 
     // Copy the triangles
-    for (i = 0; i < nTri; i++) {
+    for (i = 1; i <= theTriangulation->NbTriangles(); i++) {
       Standard_Integer iNode[3];
-      arrTriangle(i + arrTriangle.Lower()).Get(iNode[0], iNode[1], iNode[2]);
+      theTriangulation->Triangle (i).Get(iNode[0], iNode[1], iNode[2]);
       if (iNode[0] != iNode[1] && iNode[1] != iNode[2] && iNode[2] != iNode[0])
         AddTriangle (iNode[0]-1, iNode[1]-1, iNode[2]-1);
     }
 
     // Copy UV coordinates of nodes
     if (theTriangulation->HasUVNodes()) {
-      const TColgp_Array1OfPnt2d& arrNodes2d = theTriangulation->UVNodes();
       for (i = 0; i < nNodes; i++) {
-        const gp_Pnt2d& anUV = arrNodes2d(i + arrNodes2d.Lower());
+        const gp_Pnt2d& anUV = theTriangulation->UVNode (i + 1);
         myNodes(i).SetUV(anUV.X(), anUV.Y());
       }
     }
 
     // Copy the normals at nodes
     if (theTriangulation->HasNormals()) {
-      const TShort_Array1OfShortReal& arrNorm = theTriangulation->Normals();
       for (i = 0; i < nNodes; i++) {
-        const gp_XYZ aNormal (arrNorm(3 * i + 0 + arrNorm.Lower()),
-                              arrNorm(3 * i + 1 + arrNorm.Lower()),
-                              arrNorm(3 * i + 2 + arrNorm.Lower()));
+        const gp_XYZ aNormal = theTriangulation->Normal (i + 1).XYZ();
         myNodes(i).SetNormal(aNormal);
       }
     }
@@ -125,9 +118,6 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const
       new TShort_HArray1OfShortReal(1, 3 * nNodes);
     Standard_ShortReal * arrNormal = &harrNormal->ChangeValue(1);
 
-    TColgp_Array1OfPnt&    arrNodes    = aResult->ChangeNodes();
-    TColgp_Array1OfPnt2d&  arrNodesUV  = aResult->ChangeUVNodes();
-    Poly_Array1OfTriangle& arrTriangle = aResult->ChangeTriangles();
     NCollection_Vector<Standard_Integer> vecNodeId;
     Standard_Integer i, aCount(0);
     Standard_Boolean hasUV (Standard_False);
@@ -145,9 +135,9 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const
         arrNormal[3 * aCount + 2] = static_cast<Standard_ShortReal>(aNormal.Z());
 
         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() >
             Precision::Confusion())
           hasUV = Standard_True;
@@ -164,10 +154,9 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const
     for (; anIterT.More(); anIterT.Next()) {
       const Poly_CoherentTriangle& aTri = anIterT.Value();
       if (aTri.IsEmpty() == Standard_False) {
-        const Poly_Triangle aPolyTriangle (vecNodeId(aTri.Node(0)),
-                                           vecNodeId(aTri.Node(1)),
-                                           vecNodeId(aTri.Node(2)));
-        arrTriangle.SetValue(++aCount, aPolyTriangle);
+        aResult->ChangeTriangle (++aCount) = Poly_Triangle (vecNodeId(aTri.Node(0)),
+                                                            vecNodeId(aTri.Node(1)),
+                                                            vecNodeId(aTri.Node(2)));;
       }
     }
     if (hasNormals)
index 992053902ab5511d90a85e91971b875596f369d9..b2571c698ddda77ebc1faca1951163b5db9eb3ac 100644 (file)
@@ -58,12 +58,11 @@ Poly_Connect::Poly_Connect(const Handle(Poly_Triangulation)& T) :
 
   // loop on the triangles
   Standard_Integer j,k,n[3],n1,n2;
-  const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
 
   for (i = 1; i <= nbTriangles; i++) {
 
     // get the nodes
-    triangles(i).Get(n[0],n[1],n[2]);
+    myTriangulation->Triangle (i).Get(n[0],n[1],n[2]);
 
     // Update the myTriangles array
     myTriangles(n[0]) = i;
@@ -120,7 +119,7 @@ Poly_Connect::Poly_Connect(const Handle(Poly_Triangulation)& T) :
   for (i = 1; i <= nbTriangles; i++) {
     
     // get the nodes
-    triangles(i).Get(n[0],n[1],n[2]);
+    myTriangulation->Triangle (i).Get(n[0],n[1],n[2]);
 
     // fore each edge
     for (j = 0; j < 3; j++) {
@@ -212,8 +211,7 @@ void Poly_Connect::Initialize(const Standard_Integer N)
   if (mymore)
   {
     Standard_Integer i, no[3];
-    const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
-    triangles(myfirst).Get(no[0], no[1], no[2]);
+    myTriangulation->Triangle (myfirst).Get(no[0], no[1], no[2]);
     for (i = 0; i < 3; i++)
       if (no[i] == mynode) break;
     myothernode = no[(i+2)%3];
@@ -230,12 +228,11 @@ void Poly_Connect::Next()
   Standard_Integer i, j;
   Standard_Integer n[3];
   Standard_Integer t[3];
-  const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
   Triangles(mytr, t[0], t[1], t[2]);
   if (mysense) {
     for (i = 0; i < 3; i++) {
       if (t[i] != 0) {
-       triangles(t[i]).Get(n[0], n[1], n[2]);
+       myTriangulation->Triangle (t[i]).Get(n[0], n[1], n[2]);
        for (j = 0; j < 3; j++) {
          if ((n[j] == mynode) && (n[(j+1)%3] == myothernode)) {
            mytr = t[i];
@@ -247,7 +244,7 @@ void Poly_Connect::Next()
       }
     }
     // sinon, depart vers la gauche.
-    triangles(myfirst).Get(n[0], n[1], n[2]);
+    myTriangulation->Triangle (myfirst).Get(n[0], n[1], n[2]);
     for (i = 0; i < 3; i++)
       if (n[i] == mynode) break;
     myothernode = n[(i+1)%3];
@@ -258,7 +255,7 @@ void Poly_Connect::Next()
   if (!mysense) {
     for (i = 0; i < 3; i++) {
       if (t[i] != 0) {
-       triangles(t[i]).Get(n[0], n[1], n[2]);
+       myTriangulation->Triangle (t[i]).Get(n[0], n[1], n[2]);
        for (j = 0; j < 3; j++) {
          if ((n[j] == mynode) && (n[(j+2)%3] == myothernode)) {
            mytr = t[i];
diff --git a/src/Poly/Poly_Element.cxx b/src/Poly/Poly_Element.cxx
new file mode 100644 (file)
index 0000000..28011ef
--- /dev/null
@@ -0,0 +1,60 @@
+// 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_Element.hxx>
+
+//=======================================================================
+//function : Poly_Element
+//purpose  :
+//=======================================================================
+
+Poly_Element::Poly_Element()
+{
+  myTriangles[0] = myTriangles[1] = 0;
+}
+
+//=======================================================================
+//function : Poly_Element
+//purpose  :
+//=======================================================================
+
+Poly_Element::Poly_Element (const Standard_Integer theTriangle1,
+                            const Standard_Integer theTriangle2)
+{
+  myTriangles[0] = theTriangle1;
+  myTriangles[1] = theTriangle2;
+}
+
+//=======================================================================
+//function : Set
+//purpose  :
+//=======================================================================
+
+void Poly_Element::Set (const Standard_Integer theTriangle1,
+                        const Standard_Integer theTriangle2)
+{
+  myTriangles[0] = theTriangle1;
+  myTriangles[1] = theTriangle2;
+}
+
+//=======================================================================
+//function : Get
+//purpose  :
+//=======================================================================
+
+void Poly_Element::Get (Standard_Integer& theTriangle1,
+                        Standard_Integer& theTriangle2) const
+{
+  theTriangle1 = myTriangles[0];
+  theTriangle2 = myTriangles[1];
+}
diff --git a/src/Poly/Poly_Element.hxx b/src/Poly/Poly_Element.hxx
new file mode 100644 (file)
index 0000000..2374826
--- /dev/null
@@ -0,0 +1,84 @@
+// 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_Element_HeaderFile
+#define _Poly_Element_HeaderFile
+
+#include <Standard_DefineAlloc.hxx>
+#include <Standard_Integer.hxx>
+#include <Standard_OutOfRange.hxx>
+
+//! Describes an element on mesh.
+//! It can be defined as triangle index (in this case second index will be 0)
+//! or as a pair of triangles indices that make up the quad.
+class Poly_Element
+{
+
+public:
+
+  DEFINE_STANDARD_ALLOC
+
+  //! Constructs an element and sets all indices to zero.
+  Standard_EXPORT Poly_Element();
+
+  //! Constructs an element and sets it indices.
+  Standard_EXPORT Poly_Element (const Standard_Integer theTriangle1,
+                                const Standard_Integer theTriangle2);
+
+  //! Sets the value of triangles indices.
+  Standard_EXPORT void Set (const Standard_Integer theTriangle1,
+                            const Standard_Integer theTriangle2);
+
+  //! Returns the triangles indices of this element in theTriangle1, theTriangle2.
+  Standard_EXPORT void Get (Standard_Integer& theTriangle1,
+                            Standard_Integer& theTriangle2) const;
+
+  //! @return the triangle index of given element theIndex.
+  //! Raises OutOfRange from Standard if theIndex is not in 1,2.
+  Standard_Integer Value (const Standard_Integer theIndex) const
+  {
+    Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL);
+    return myTriangles[theIndex - 1];
+  }
+
+  Standard_Integer operator() (const Standard_Integer theIndex) const { return Value (theIndex); }
+
+  //! @return the triangle index of given element theIndex.
+  //! Raises OutOfRange from Standard if theIndex is not in 1,2.
+  Standard_Integer& ChangeValue (const Standard_Integer theIndex)
+  {
+    Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL);
+    return myTriangles[theIndex - 1];
+  }
+
+  Standard_Integer& operator() (const Standard_Integer theIndex) { return ChangeValue (theIndex); }
+
+  //! @return Standard_True if the first element index > 0 and the second index == 0.
+  Standard_Boolean IsTriangle() const
+  {
+    return (myTriangles[0] > 0 && myTriangles[1] == 0);
+  }
+
+  //! @return Standard_True if the first and the second element indices > 0.
+  Standard_Boolean IsQuad() const
+  {
+    return (myTriangles[0] > 0 && myTriangles[1] > 0);
+  }
+
+private:
+
+  Standard_Integer myTriangles[2];
+
+};
+
+#endif // _Poly_Element_HeaderFile
diff --git a/src/Poly/Poly_Mesh.cxx b/src/Poly/Poly_Mesh.cxx
new file mode 100644 (file)
index 0000000..e4e9fcb
--- /dev/null
@@ -0,0 +1,199 @@
+// 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 (const Standard_Boolean theHasUVNodes)
+: Poly_Triangulation (0, 0, theHasUVNodes),
+  myNbQuads (0)
+{}
+
+//=======================================================================
+//function : Poly_Mesh
+//purpose  :
+//=======================================================================
+
+Poly_Mesh::Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation)
+: Poly_Triangulation ( theTriangulation ),
+  myNbQuads (0)
+{
+  const Standard_Integer aNbTris = theTriangulation->NbTriangles();
+  
+  // Fill collection of elements
+  if ( aNbTris )
+    myElements.SetValue( aNbTris - 1, Poly_Element() );
+
+  // Populate elements with triangles
+  for ( Standard_Integer i = 1; i <= aNbTris; ++i )
+  {
+    myElements(i - 1).Set(i, 0);
+  }
+}
+
+//=======================================================================
+//function : Copy
+//purpose  :
+//=======================================================================
+
+Handle(Poly_Triangulation) Poly_Mesh::Copy() const
+{
+  const Standard_Boolean hasUV = HasUVNodes();
+  Handle(Poly_Mesh) aCopy = new Poly_Mesh(hasUV);
+  // Copy nodes
+  Standard_Integer aNbNodes = NbNodes();
+  for ( Standard_Integer i = 1; i <= aNbNodes; ++i )
+  {
+    aCopy->AddNode(Node(i));
+    if ( hasUV )
+      aCopy->ChangeUVNode(i) = UVNode(i);
+  }
+  // Copy triangles
+  Standard_Integer aNbTriangles = NbTriangles();
+  const Standard_Boolean hasNormals = HasNormals();
+  for ( Standard_Integer i = 1; i <= aNbTriangles; ++i )
+  {
+    aCopy->AddTriangle(Triangle(i));
+    // Pass normal vector (if any)
+    if ( hasNormals )
+      aCopy->SetNormal(i, Normal(i));
+  }
+  // Copy quads
+  aCopy->myNbQuads = myNbQuads;
+  aCopy->myElements = myElements;
+  return aCopy;
+}
+
+//=======================================================================
+//function : AddElement
+//purpose  :
+//=======================================================================
+
+Standard_Integer Poly_Mesh::AddElement (const Standard_Integer theN1,
+                                        const Standard_Integer theN2,
+                                        const Standard_Integer theN3)
+{
+  Standard_Integer anIndex = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN2, theN3) );
+  return addElement( Poly_Element(anIndex, 0) );
+}
+
+//=======================================================================
+//function : AddElement
+//purpose  :
+//=======================================================================
+
+Standard_Integer Poly_Mesh::AddElement (const Standard_Integer theN1,
+                                        const Standard_Integer theN2,
+                                        const Standard_Integer theN3,
+                                        const Standard_Integer theN4)
+{
+  Standard_Integer anIndex1 = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN2, theN3) );
+  Standard_Integer anIndex2 = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN3, theN4) );
+  return addElement( Poly_Element(anIndex1, anIndex2) );
+}
+
+//=======================================================================
+//function : Element
+//purpose  :
+//=======================================================================
+
+const Poly_Element& Poly_Mesh::Element (const Standard_Integer theIndex) const
+{
+  if ( theIndex < 1 || theIndex > myElements.Size() )
+  {
+    Standard_OutOfRange::Raise("Poly_Mesh::Element : index out of range");
+  }
+
+  return myElements.Value(theIndex - 1);
+}
+
+//=======================================================================
+//function : Element
+//purpose  :
+//=======================================================================
+
+void Poly_Mesh::Element (const Standard_Integer theIndex,
+                         Standard_Integer& theN1,
+                         Standard_Integer& theN2,
+                         Standard_Integer& theN3,
+                         Standard_Integer& theN4) const
+{
+  if ( theIndex < 1 || theIndex > myElements.Size() )
+  {
+    Standard_OutOfRange::Raise("Poly_Mesh::Element : index out of range");
+  }
+
+  const Poly_Element& anElem = Element(theIndex);
+  Standard_Integer aTriIdx1, aTriIdx2;
+  anElem.Get(aTriIdx1, aTriIdx2);
+
+  // Get node indices for the first triangle
+  const Poly_Triangle& aTri1 = Poly_Triangulation::Triangle(aTriIdx1);
+  aTri1.Get(theN1, theN2, theN3);
+
+  // If the second triangle exists, take its node indices for quad
+  if ( aTriIdx2 )
+  {
+    const Poly_Triangle& aTri2 = Poly_Triangulation::Triangle(aTriIdx2);
+    aTri2.Get(theN1, theN3, theN4);
+  }
+  else
+    theN4 = 0;
+}
+
+//=======================================================================
+//function : SetElement
+//purpose  :
+//=======================================================================
+
+void Poly_Mesh::SetElement (const Standard_Integer theIndex, const Poly_Element& theElement)
+{
+  if ( theIndex < 1 || theIndex > myElements.Size() )
+  {
+    Standard_OutOfRange::Raise("Poly_Mesh::SetElement : index out of range");
+  }
+
+  if ( myElements.Value(theIndex - 1).Value(2) == 0 && theElement.Value(2) != 0 )
+  {
+    myNbQuads++;
+  }
+  else if ( myElements.Value(theIndex - 1).Value(2) != 0 && theElement.Value(2) == 0 )
+  {
+    myNbQuads--;
+  }
+
+  myElements.SetValue(theIndex - 1, theElement);
+}
+
+//=======================================================================
+//function : addElement
+//purpose  :
+//=======================================================================
+
+Standard_Integer Poly_Mesh::addElement(const Poly_Element& theElement)
+{
+  myElements.Append(theElement);
+  if ( theElement.Value(2) != 0 )
+  {
+    myNbQuads++;
+  }
+  return myElements.Size();
+}
diff --git a/src/Poly/Poly_Mesh.hxx b/src/Poly/Poly_Mesh.hxx
new file mode 100644 (file)
index 0000000..0619679
--- /dev/null
@@ -0,0 +1,104 @@
+// 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_Element.hxx>
+#include <Poly_Triangulation.hxx>
+
+//! This class is extension for Poly_Triangulation.
+//! It allows to store mesh with quad polygons as table of Poly_Element.
+//! Keep in mind that when you add a triangle, it is also added to the table of elements
+//! as Poly_Element. And it will have first index set to triangle index from Poly_Triangulation
+//! and second index will be set to 0.
+class Poly_Mesh : public Poly_Triangulation
+{
+
+public:
+
+  //! Constructs an empty mesh.
+  //! @param theHasUVNodes indicates whether 2D nodes will be associated with
+  //!        3D ones, (i.e. to enable a 2D representation).
+  Standard_EXPORT Poly_Mesh (const Standard_Boolean theHasUVNodes = 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;
+
+  //! Adds element to the mesh.
+  //! @param theN1 index of the first node.
+  //! @param theN2 index of the second node.
+  //! @param theN3 index of the third node.
+  //! @return index of the added element.
+  Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1,
+                                               const Standard_Integer theN2,
+                                               const Standard_Integer theN3);
+
+  //! Adds element to the mesh.
+  //! @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.
+  //! @return index of the added element.
+  Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1,
+                                               const Standard_Integer theN2,
+                                               const Standard_Integer theN3,
+                                               const Standard_Integer theN4);
+
+  //! @return the number of elements for this mesh.
+  Standard_Integer NbElements() const { return myElements.Size(); }
+
+  //! @return the number of quads for this mesh.
+  Standard_Integer NbQuads() const { return myNbQuads; }
+
+  //! @return element at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
+  Standard_EXPORT const Poly_Element& Element (const Standard_Integer theIndex) const;
+
+  //! @return nodes of the element at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
+  Standard_EXPORT void Element (const Standard_Integer theIndex,
+                                Standard_Integer& theN1,
+                                Standard_Integer& theN2,
+                                Standard_Integer& theN3,
+                                Standard_Integer& theN4) const;
+
+  //! Sets the element at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
+  Standard_EXPORT void SetElement (const Standard_Integer theIndex, const Poly_Element& theElement);
+
+protected:
+
+  //! Adds element to the mesh.
+  //! @param theElement element to add.
+  //! @return index of the added element.
+  Standard_EXPORT Standard_Integer addElement (const Poly_Element& theElement);
+
+private:
+
+  NCollection_Vector<Poly_Element> myElements;
+  Standard_Integer                 myNbQuads;
+
+public:
+
+  DEFINE_STANDARD_RTTIEXT(Poly_Mesh, Poly_Triangulation)
+
+};
+
+DEFINE_STANDARD_HANDLE(Poly_Mesh, Poly_Triangulation)
+
+#endif // _Poly_Mesh_HeaderFile
index fa26b4365cbfc24eeeb272efbc73736a85a464f9..acaedbda80fd0e9383855d4bd58e7e07ec8ad14a 100644 (file)
@@ -95,6 +95,29 @@ const TColStd_Array1OfInteger& Poly_PolygonOnTriangulation::Nodes() const
   return myNodes;
 }
 
+//=======================================================================
+//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 : HasParameters
@@ -116,3 +139,30 @@ Handle(TColStd_HArray1OfReal) Poly_PolygonOnTriangulation::Parameters() const
   return myParameters;
 }
 
+//=======================================================================
+//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);
+}
index 87f99227fd9338017f18c9470d6046879edfcaf1..edd6cac2e0ac3ddfa696e42e7edc17db2a8e267e 100644 (file)
@@ -90,7 +90,14 @@ public:
   //! is an index in the table of nodes specific to an existing
   //! triangulation of a shape.
   Standard_EXPORT const TColStd_Array1OfInteger& Nodes() const;
-  
+
+  //! Return node at the given index.
+  //! 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.
   Standard_EXPORT Standard_Boolean HasParameters() const;
@@ -101,7 +108,15 @@ public:
   //! are associated with the nodes in this polygon.
   Standard_EXPORT Handle(TColStd_HArray1OfReal) Parameters() const;
 
+  //! Return 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 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);
 
 
   DEFINE_STANDARD_RTTIEXT(Poly_PolygonOnTriangulation,MMgt_TShared)
index 5bd7944cdfa3d68e17020ddaf2e71dec6f3701e8..2475ac2bd65936854ce5037d1f999b14c48dc112 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
+#include <Poly_Triangulation.hxx>
 
 #include <gp_Pnt.hxx>
-#include <Poly_Triangle.hxx>
-#include <Poly_Triangulation.hxx>
-#include <Standard_DomainError.hxx>
 #include <Standard_NullObject.hxx>
-#include <Standard_Type.hxx>
+#include <TShort_HArray1OfShortReal.hxx>
 
-IMPLEMENT_STANDARD_RTTIEXT(Poly_Triangulation,MMgt_TShared)
+IMPLEMENT_STANDARD_RTTIEXT (Poly_Triangulation, MMgt_TShared)
 
 //=======================================================================
 //function : Poly_Triangulation
 //purpose  : 
 //=======================================================================
-Poly_Triangulation::Poly_Triangulation(const Standard_Integer NbNodes, 
-                                       const Standard_Integer NbTriangles,
-                                       const Standard_Boolean UVNodes) :
-   myDeflection(0),
-   myNbNodes(NbNodes),
-   myNbTriangles(NbTriangles),
-   myNodes(1, NbNodes),
-   myTriangles(1, NbTriangles)
+
+Poly_Triangulation::Poly_Triangulation (const Standard_Integer theNbNodes,
+                                        const Standard_Integer theNbTriangles,
+                                        const Standard_Boolean theHasUVNodes)
+: myHasUVNodes (theHasUVNodes),
+  myDeflection (0)
 {
-  if (UVNodes) myUVNodes = new TColgp_HArray1OfPnt2d(1, myNbNodes);
+  if (theNbNodes > 0)
+  {
+    myNodes.SetValue (theNbNodes - 1, gp_Pnt());
+    if (myHasUVNodes)
+    {
+      myUVNodes.SetValue (theNbNodes - 1, gp_Pnt2d());
+    }
+  }
+  if (theNbTriangles > 0)
+  {
+    myTriangles.SetValue (theNbTriangles - 1, Poly_Triangle());
+  }
 }
 
 //=======================================================================
@@ -45,16 +52,19 @@ Poly_Triangulation::Poly_Triangulation(const Standard_Integer NbNodes,
 //purpose  : 
 //=======================================================================
 
-Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt&    Nodes, 
-                                       const Poly_Array1OfTriangle& Triangles) :
-   myDeflection(0),
-   myNbNodes(Nodes.Length()),
-   myNbTriangles(Triangles.Length()),
-   myNodes(1, Nodes.Length()),
-   myTriangles(1, Triangles.Length())
+Poly_Triangulation::Poly_Triangulation (const TColgp_Array1OfPnt&    theNodes,
+                                        const Poly_Array1OfTriangle& theTriangles)
+: myHasUVNodes (Standard_False),
+  myDeflection (0)
 {
-  myNodes = Nodes;
-  myTriangles = Triangles;
+  for (Standard_Integer anIndex = theNodes.Upper(); anIndex >= theNodes.Lower(); anIndex--)
+  {
+    myNodes.SetValue (anIndex - 1, theNodes (anIndex));
+  }
+  for (Standard_Integer anIndex = theTriangles.Upper(); anIndex >= theTriangles.Lower(); anIndex--)
+  {
+    myTriangles.SetValue (anIndex - 1, theTriangles (anIndex));
+  }
 }
 
 
@@ -64,19 +74,27 @@ Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt&    Nodes,
 //purpose  : 
 //=======================================================================
 
-Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt&    Nodes,
-                                       const TColgp_Array1OfPnt2d&  UVNodes,
-                                       const Poly_Array1OfTriangle& Triangles) :
-   myDeflection(0),
-   myNbNodes(Nodes.Length()),
-   myNbTriangles(Triangles.Length()),
-   myNodes(1, Nodes.Length()),
-   myTriangles(1, Triangles.Length())
+Poly_Triangulation::Poly_Triangulation (const TColgp_Array1OfPnt&    theNodes,
+                                        const TColgp_Array1OfPnt2d&  theUVNodes,
+                                        const Poly_Array1OfTriangle& theTriangles)
+: myHasUVNodes (theNodes.Length() == theUVNodes.Length()),
+  myDeflection (0)
 {
-  myNodes = Nodes;
-  myTriangles = Triangles;
-  myUVNodes = new TColgp_HArray1OfPnt2d(1, myNbNodes);
-  myUVNodes->ChangeArray1() = UVNodes;
+  for (Standard_Integer anIndex = theNodes.Upper(); anIndex >= theNodes.Lower(); anIndex--)
+  {
+    myNodes.SetValue (anIndex - 1, theNodes (anIndex));
+  }
+  if (myHasUVNodes)
+  {
+    for (Standard_Integer anIndex = theUVNodes.Upper(); anIndex >= theUVNodes.Lower(); anIndex--)
+    {
+      myUVNodes.SetValue (anIndex - 1, theUVNodes (anIndex));
+    }
+  }
+  for (Standard_Integer anIndex = theTriangles.Upper(); anIndex >= theTriangles.Lower(); anIndex--)
+  {
+    myTriangles.SetValue (anIndex - 1, theTriangles (anIndex));
+  }
 }
 
 //=======================================================================
@@ -86,24 +104,39 @@ Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt&    Nodes,
 
 Handle(Poly_Triangulation) Poly_Triangulation::Copy() const
 {
-  Handle(Poly_Triangulation) aCopy;
-  if (HasUVNodes())
-    aCopy = new Poly_Triangulation(Nodes(), UVNodes(), Triangles());
-  else
-    aCopy = new Poly_Triangulation(Nodes(), Triangles());
-  aCopy->Deflection(myDeflection);
-  if (HasNormals())
-    aCopy->myNormals = new TShort_HArray1OfShortReal(myNormals->Array1());
-
+  Handle(Poly_Triangulation) aCopy = new Poly_Triangulation(NbNodes(), NbTriangles(), HasUVNodes());
+  aCopy->myNodes = myNodes;
+  aCopy->myTriangles = myTriangles;
+  aCopy->myUVNodes = myUVNodes;
+  aCopy->myDeflection = myDeflection;
+  aCopy->myNormals = myNormals;
   return aCopy;
 }
 
+//=======================================================================
+//function : Poly_Triangulation
+//purpose  : 
+//=======================================================================
+
+Poly_Triangulation::Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation)
+: myHasUVNodes ( theTriangulation->myHasUVNodes ),
+  myDeflection ( theTriangulation->myDeflection )
+{
+  myNodes.Assign(theTriangulation->myNodes);
+  if (myHasUVNodes)
+  {
+    myUVNodes.Assign(theTriangulation->myUVNodes);
+  }
+  myTriangles.Assign(theTriangulation->myTriangles);
+  myNormals.Assign(theTriangulation->myNormals);
+}
+
 //=======================================================================
 //function : Deflection
 //purpose  : 
 //=======================================================================
 
-Standard_Real Poly_Triangulation::Deflection() const 
+Standard_Real Poly_Triangulation::Deflection() const
 {
   return myDeflection;
 }
@@ -113,9 +146,9 @@ Standard_Real Poly_Triangulation::Deflection() const
 //purpose  : 
 //=======================================================================
 
-void Poly_Triangulation::Deflection(const Standard_Real D)
+void Poly_Triangulation::Deflection (const Standard_Real theDeflection)
 {
-  myDeflection = D;
+  myDeflection = theDeflection;
 }
 
 
@@ -127,119 +160,164 @@ void Poly_Triangulation::Deflection(const Standard_Real D)
 
 void Poly_Triangulation::RemoveUVNodes()
 {
-  myUVNodes.Nullify();
+  myUVNodes.Clear();
+  myHasUVNodes = Standard_False;
 }
 
 //=======================================================================
-//function : Nodes
+//function : AddNode
 //purpose  : 
 //=======================================================================
-
-const TColgp_Array1OfPnt& Poly_Triangulation::Nodes() const 
+Standard_Integer Poly_Triangulation::AddNode (const gp_Pnt& theNode)
 {
-  return myNodes;
+  myNodes.Append (theNode);
+
+  if (myHasUVNodes)
+  {
+    myUVNodes.Append (gp_Pnt2d());
+  }
+
+  if (!myNormals.IsEmpty())
+  {
+    Standard_Integer aNbNormals = myNodes.Size();
+    myNormals.SetValue (aNbNormals, gp_Dir());
+  }
+
+  return myNodes.Size();
 }
 
 //=======================================================================
-//function : ChangeNodes
+//function : Node
 //purpose  : 
 //=======================================================================
 
-TColgp_Array1OfPnt& Poly_Triangulation::ChangeNodes()
+const gp_Pnt& Poly_Triangulation::Node (const Standard_Integer theIndex) const
 {
-  return myNodes;
+  if (theIndex < 1 || theIndex > myNodes.Size())
+  {
+    Standard_OutOfRange::Raise ("Poly_Triangulation::Node : index out of range");
+  }
+  return myNodes.Value (theIndex - 1);
 }
 
 //=======================================================================
-//function : UVNodes
+//function : ChangeNode
 //purpose  : 
 //=======================================================================
 
-const TColgp_Array1OfPnt2d& Poly_Triangulation::UVNodes() const 
+gp_Pnt& Poly_Triangulation::ChangeNode (const Standard_Integer theIndex)
 {
-  return myUVNodes->Array1();
+  if (theIndex < 1 || theIndex > myNodes.Size())
+  {
+    Standard_OutOfRange::Raise ("Poly_Triangulation::ChangeNode : index out of range");
+  }
+  return myNodes.ChangeValue (theIndex - 1);
 }
 
 //=======================================================================
-//function : ChangeUVNodes
+//function : UVNode
 //purpose  : 
 //=======================================================================
 
-TColgp_Array1OfPnt2d& Poly_Triangulation::ChangeUVNodes()
+const gp_Pnt2d& Poly_Triangulation::UVNode (const Standard_Integer theIndex) const
 {
-  return myUVNodes->ChangeArray1();
+  if (myUVNodes.IsEmpty() || theIndex < 1 || theIndex > myUVNodes.Size())
+  {
+    Standard_OutOfRange::Raise ("Poly_Triangulation::UVNode : index out of range");
+  }
+  return myUVNodes.Value (theIndex - 1);
 }
 
 //=======================================================================
-//function : Triangles
+//function : ChangeUVNode
 //purpose  : 
 //=======================================================================
 
-const Poly_Array1OfTriangle& Poly_Triangulation::Triangles() const 
+gp_Pnt2d& Poly_Triangulation::ChangeUVNode (const Standard_Integer theIndex)
 {
-  return myTriangles;
+  if (myUVNodes.IsEmpty() || theIndex < 1 || theIndex > myUVNodes.Size())
+  {
+    Standard_OutOfRange::Raise ("Poly_Triangulation::ChangeUVNode : index out of range");
+  }
+  return myUVNodes.ChangeValue (theIndex - 1);
 }
 
 //=======================================================================
-//function : ChangeTriangles
+//function : Triangle
 //purpose  : 
 //=======================================================================
 
-Poly_Array1OfTriangle& Poly_Triangulation::ChangeTriangles()
+Standard_Integer Poly_Triangulation::AddTriangle (const Poly_Triangle& theTriangle)
 {
-  return myTriangles;
+  myTriangles.Append (theTriangle);
+  return myTriangles.Size();
 }
 
-
 //=======================================================================
-//function : SetNormals
+//function : Triangle
 //purpose  : 
 //=======================================================================
 
-void Poly_Triangulation::SetNormals
-                        (const Handle(TShort_HArray1OfShortReal)& theNormals)
+const Poly_Triangle& Poly_Triangulation::Triangle (const Standard_Integer theIndex) const
 {
-
-  if(theNormals.IsNull() || theNormals->Length() != 3*myNbNodes) {
-    Standard_DomainError::Raise("Poly_Triangulation::SetNormals : wrong length");
+  if (theIndex < 1 || theIndex > myTriangles.Size())
+  {
+    Standard_OutOfRange::Raise ("Poly_Triangulation::Triangle : index out of range");
   }
+  return myTriangles.Value (theIndex - 1);
+}
 
-  myNormals = theNormals;
+//=======================================================================
+//function : ChangeTriangle
+//purpose  : 
+//=======================================================================
 
+Poly_Triangle& Poly_Triangulation::ChangeTriangle (const Standard_Integer theIndex)
+{
+  if (theIndex < 1 || theIndex > myTriangles.Size())
+  {
+    Standard_OutOfRange::Raise ("Poly_Triangulation::ChangeTriangle : index out of range");
+  }
+  return myTriangles.ChangeValue (theIndex - 1);
 }
 
 //=======================================================================
-//function : Normals
+//function : SetNormals
 //purpose  : 
 //=======================================================================
 
-const TShort_Array1OfShortReal& Poly_Triangulation::Normals() const
+void Poly_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals)
 {
-
-  if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
-    Standard_NullObject::Raise("Poly_Triangulation::Normals : "
-                               "wrong length or null array");
+  if (theNormals.IsNull() || theNormals->Length() != 3 * NbNodes())
+  {
+    Standard_DomainError::Raise("Poly_Triangulation::SetNormals : wrong length");
   }
 
-  return myNormals->Array1();
-
+  Standard_Integer anArrayLower = theNormals->Lower();
+  Standard_Integer anArrayInd;
+  for (Standard_Integer anIndex = NbNodes() - 1; anIndex >= 0; anIndex--)
+  {
+    anArrayInd = anArrayLower + anIndex * 3;
+    gp_Dir aNormal(theNormals->Value(anArrayInd),
+                   theNormals->Value(anArrayInd),
+                   theNormals->Value(anArrayInd));
+    myNormals.SetValue (anIndex, aNormal);
+  }
 }
 
 //=======================================================================
-//function : ChangeNormals
+//function : SetNormal
 //purpose  : 
 //=======================================================================
 
-TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals() 
+void Poly_Triangulation::SetNormal (const Standard_Integer theIndex, const gp_Dir& theNormal)
 {
-
-  if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
-    Standard_NullObject::Raise("Poly_Triangulation::ChangeNormals : "
-                               "wrong length or null array");
+  if (myNormals.IsEmpty() || theIndex < 1 || theIndex > myNodes.Size())
+  {
+    Standard_NullObject::Raise("Poly_Triangulation::SetNormal : empty array or index out of range");
   }
 
-  return myNormals->ChangeArray1();
-
+  myNormals.ChangeValue (theIndex - 1) = theNormal;
 }
 
 //=======================================================================
@@ -249,12 +327,24 @@ TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals()
 
 Standard_Boolean Poly_Triangulation::HasNormals() const
 {
-
-  if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
+  if (myNormals.IsEmpty() || myNormals.Length() != NbNodes())
+  {
     return Standard_False;
   }
   return Standard_True;
 }
 
+//=======================================================================
+//function : Normal
+//purpose  : 
+//=======================================================================
 
+const gp_Dir Poly_Triangulation::Normal (const Standard_Integer theIndex) const
+{
+  if (myNormals.IsEmpty() || theIndex < 1 || theIndex > myNodes.Size())
+  {
+    Standard_NullObject::Raise("Poly_Triangulation::Normal : empty array or index out of range");
+  }
 
+  return myNormals (theIndex - 1);
+}
index b4857d28ecdcf6db293773bbbf695599a945b623..febb46ec02b10b7db3e43fe269096f66aa602ac1 100644 (file)
@@ -1,7 +1,4 @@
-// Created on: 1995-03-06
-// Created by: Laurent PAINNOT
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2014 OPEN CASCADE SAS
+// Copyright (c) 2015 OPEN CASCADE SAS
 //
 // This file is part of Open CASCADE Technology software library.
 //
 #ifndef _Poly_Triangulation_HeaderFile
 #define _Poly_Triangulation_HeaderFile
 
+#include <Poly_Array1OfTriangle.hxx>
 #include <Standard.hxx>
-#include <Standard_Type.hxx>
-
+#include <Standard_DefineHandle.hxx>
 #include <Standard_Real.hxx>
 #include <Standard_Integer.hxx>
 #include <TColgp_Array1OfPnt.hxx>
-#include <TColgp_HArray1OfPnt2d.hxx>
-#include <Poly_Array1OfTriangle.hxx>
-#include <TShort_HArray1OfShortReal.hxx>
+#include <TColgp_Array1OfPnt2d.hxx>
 #include <MMgt_TShared.hxx>
 #include <Standard_Boolean.hxx>
-#include <TColgp_Array1OfPnt2d.hxx>
-#include <TShort_Array1OfShortReal.hxx>
+#include <NCollection_Vector.hxx>
+#include <Poly_Triangle.hxx>
+
+class TShort_HArray1OfShortReal;
 class Standard_DomainError;
 class Standard_NullObject;
 
-
-class Poly_Triangulation;
-DEFINE_STANDARD_HANDLE(Poly_Triangulation, MMgt_TShared)
-
-//! 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
+//! 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.
 //! A triangulation comprises:
 //! -   A table of 3D nodes (3D points on the surface).
-//! -   A table of triangles. Each triangle (Poly_Triangle
-//! object) comprises a triplet of indices in the table of 3D
-//! nodes specific to the triangulation.
-//! -   A table of 2D nodes (2D points), parallel to the table of
-//! 3D nodes. This table is optional. 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.
-//! -   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.
+//! -   A table of triangles. Each triangle (Poly_Triangle object) comprises a triplet of indices in the table of 3D
+//!     nodes specific to the triangulation.
+//! -   A table of 2D nodes (2D points), parallel to the table of 3D nodes. This table is optional.
+//!     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.
+//! -   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.
 class Poly_Triangulation : public MMgt_TShared
 {
 
 public:
 
-  
-  //! Constructs a triangulation from a set of triangles. The
-  //! triangulation is initialized without a triangle or a node, but capable of
-  //! containing nbNodes nodes, and nbTriangles
-  //! triangles. Here the UVNodes flag indicates whether
-  //! 2D nodes will be associated with 3D ones, (i.e. to
-  //! enable a 2D representation).
-  Standard_EXPORT Poly_Triangulation(const Standard_Integer nbNodes, const Standard_Integer nbTriangles, const Standard_Boolean UVNodes);
-  
-  //! Constructs a triangulation from a set of triangles. The
-  //! triangulation is initialized with 3D points from Nodes and triangles
-  //! from Triangles.
-  Standard_EXPORT Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, const Poly_Array1OfTriangle& Triangles);
-  
-  //! Constructs a triangulation from a set of triangles. The
-  //! triangulation is initialized with 3D points from Nodes, 2D points from
-  //! UVNodes and triangles from Triangles, where
-  //! coordinates of a 2D point from UVNodes are the
-  //! (u, v) parameters of the corresponding 3D point
-  //! from Nodes on the surface approximated by the
-  //! constructed triangulation.
-  Standard_EXPORT Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, const TColgp_Array1OfPnt2d& UVNodes, const Poly_Array1OfTriangle& Triangles);
-  
+  //! Constructs a triangulation from a set of triangles.
+  //! The triangulation is initialized without a triangle or a node, but capable of containing theNbNodes nodes, and theNbTriangles triangles.
+  //! Here theHasUVNodes flag indicates whether 2D nodes will be associated with 3D ones, (i.e. to enable a 2D representation).
+  Standard_EXPORT Poly_Triangulation (const Standard_Integer theNbNodes,
+                                      const Standard_Integer theNbTriangles,
+                                      const Standard_Boolean theHasUVNodes);
+
+  //! Constructs a triangulation from a set of triangles.
+  //! The triangulation is initialized with 3D points from Nodes and triangles from Triangles.
+  Standard_EXPORT Poly_Triangulation (const TColgp_Array1OfPnt&    theNodes,
+                                      const Poly_Array1OfTriangle& theTriangles);
+
+  //! Constructs a triangulation from a set of triangles.
+  //! The triangulation is initialized with 3D points from Nodes, 2D points from theUVNodes and triangles from theTriangles,
+  //! where coordinates of a 2D point from theUVNodes are the (u, v) parameters of the corresponding 3D point
+  //! from theNodes on the surface approximated by the constructed triangulation. If size of theUVNodes != size of theNodes
+  //! then triangulation will be created without theUVNodes.
+  Standard_EXPORT Poly_Triangulation (const TColgp_Array1OfPnt&    theNodes,
+                                      const TColgp_Array1OfPnt2d&  theUVNodes,
+                                      const Poly_Array1OfTriangle& theTriangles);
+
   //! Creates full copy of current triangulation
   Standard_EXPORT virtual Handle(Poly_Triangulation) Copy() const;
-  
+
+  //! Copy constructor for triangulation.
+  Standard_EXPORT Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation);
+
   //! Returns the deflection of this triangulation.
   Standard_EXPORT Standard_Real Deflection() const;
-  
-  //! Sets the deflection of this triangulation to D.
+
+  //! Sets the deflection of this triangulation to theDeflection.
   //! See more on deflection in Polygon2D
-  Standard_EXPORT void Deflection (const Standard_Real D);
-  
+  Standard_EXPORT void Deflection (const Standard_Real theDeflection);
+
   //! Deallocates the UV nodes.
   Standard_EXPORT void RemoveUVNodes();
-  
-  //! Returns the number of nodes for this triangulation.
-  //! Null if the nodes are not yet defined.
-    Standard_Integer NbNodes() const;
-  
-  //! Returns the number of triangles for this triangulation.
-  //! Null if the Triangles are not yet defined.
-    Standard_Integer NbTriangles() const;
-  
-  //! Returns true if 2D nodes are associated with 3D nodes for
-  //! this triangulation.
-    Standard_Boolean HasUVNodes() const;
-  
-  //! Returns the table of 3D nodes (3D points) for this triangulation.
-  Standard_EXPORT const TColgp_Array1OfPnt& Nodes() const;
-  
-  //! 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.
-  Standard_EXPORT TColgp_Array1OfPnt& ChangeNodes();
-  
-  //! Returns the table of 2D nodes (2D points) associated with
-  //! each 3D node of this triangulation.
-  //! The function HasUVNodes  checks if 2D nodes
-  //! are associated with the 3D nodes of this triangulation.
-  //! Const reference on the 2d nodes values.
-  Standard_EXPORT const TColgp_Array1OfPnt2d& UVNodes() const;
-  
-  //! Returns the table of 2D nodes (2D points) associated with
-  //! each 3D node of this triangulation.
-  //! Function ChangeUVNodes shares  the returned array.
-  //! Therefore if the table is selected by reference,
-  //! you can, by simply modifying it, directly modify the data
-  //! structure of this triangulation.
-  Standard_EXPORT TColgp_Array1OfPnt2d& ChangeUVNodes();
-  
-  //! Returns the table of triangles for this triangulation.
-  Standard_EXPORT const Poly_Array1OfTriangle& Triangles() const;
-  
-  //! Returns the table of triangles for this triangulation.
-  //! Function ChangeUVNodes shares  the returned array.
-  //! Therefore if the table is selected by reference,
-  //! you can, by simply modifying it, directly modify the data
-  //! structure of this triangulation.
-  Standard_EXPORT Poly_Array1OfTriangle& ChangeTriangles();
-  
-  //! Sets the table of node normals.
-  //! raises exception if length of theNormals != 3*NbNodes
-  Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals);
-  
-  Standard_EXPORT const TShort_Array1OfShortReal& Normals() const;
-  
-  Standard_EXPORT TShort_Array1OfShortReal& ChangeNormals();
-  
-  Standard_EXPORT Standard_Boolean HasNormals() const;
 
+  //! @return the number of nodes for this triangulation.
+  Standard_Integer NbNodes() const { return myNodes.Size(); }
 
+  //! @return the number of triangles for this triangulation.
+  Standard_Integer NbTriangles() const { return myTriangles.Size(); }
 
+  //! @return Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
+  Standard_Boolean HasUVNodes() const { return myHasUVNodes; }
 
-  DEFINE_STANDARD_RTTIEXT(Poly_Triangulation,MMgt_TShared)
+  //! Adds Node to the triangulation. If triangulation has UVNodes or Normals
+  //! they will be expanded and set to zero values to match the new number of nodes.
+  //! @return index of the added Node.
+  Standard_EXPORT Standard_Integer AddNode (const gp_Pnt& theNode);
 
-protected:
+  //! @return node at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+  Standard_EXPORT const gp_Pnt& Node (const Standard_Integer theIndex) const;
 
+  //! Give access to the node at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+  Standard_EXPORT gp_Pnt& ChangeNode (const Standard_Integer theIndex);
 
+  //! @return UVNode at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+  Standard_EXPORT const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const;
 
+  //! Give access to the UVNode at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+  Standard_EXPORT gp_Pnt2d& ChangeUVNode (const Standard_Integer theIndex);
 
-private:
+  //! Adds triangle to the triangulation.
+  //! @return index of the added triangle.
+  Standard_EXPORT virtual Standard_Integer AddTriangle (const Poly_Triangle& theTriangle);
 
+  //! @return triangle at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
+  Standard_EXPORT const Poly_Triangle& Triangle (const Standard_Integer theIndex) const;
 
-  Standard_Real myDeflection;
-  Standard_Integer myNbNodes;
-  Standard_Integer myNbTriangles;
-  TColgp_Array1OfPnt myNodes;
-  Handle(TColgp_HArray1OfPnt2d) myUVNodes;
-  Poly_Array1OfTriangle myTriangles;
-  Handle(TShort_HArray1OfShortReal) myNormals;
+  //! Give access to the triangle at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
+  Standard_EXPORT Poly_Triangle& ChangeTriangle (const Standard_Integer theIndex);
 
+  //! Sets the table of node normals.
+  //! Raises exception if length of theNormals != 3 * NbNodes
+  Standard_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);
 
-};
+  //! Changes normal at the given index.
+  //! Raises Standard_OutOfRange exception.
+  Standard_EXPORT void SetNormal (const Standard_Integer theIndex,
+                                  const gp_Dir&          theNormal);
 
+  //! Returns Standard_True if nodal normals are defined.
+  Standard_EXPORT Standard_Boolean HasNormals() const;
+
+  //! @return normal at the given index.
+  //! Raises Standard_OutOfRange exception.
+  Standard_EXPORT const gp_Dir Normal (const Standard_Integer theIndex) const;
 
-#include <Poly_Triangulation.lxx>
+protected:
 
+  Standard_Boolean                       myHasUVNodes;
+  Standard_Real                          myDeflection;
+  NCollection_Vector<gp_Pnt>             myNodes;
+  NCollection_Vector<gp_Pnt2d>           myUVNodes;
+  NCollection_Vector<Poly_Triangle>      myTriangles;
+  NCollection_Vector<gp_Dir>             myNormals;
 
+public:
 
+  DEFINE_STANDARD_RTTIEXT(Poly_Triangulation, MMgt_TShared)
 
+};
+
+DEFINE_STANDARD_HANDLE(Poly_Triangulation, MMgt_TShared)
 
 #endif // _Poly_Triangulation_HeaderFile
diff --git a/src/Poly/Poly_Triangulation.lxx b/src/Poly/Poly_Triangulation.lxx
deleted file mode 100644 (file)
index 63809e9..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// Created on: 1995-03-06
-// Created by: Laurent PAINNOT
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-//=======================================================================
-//function : NbNodes
-//purpose  : 
-//=======================================================================
-
-inline Standard_Integer Poly_Triangulation::NbNodes() const 
-{
-  return myNbNodes;
-}
-
-//=======================================================================
-//function : NbTriangles
-//purpose  : 
-//=======================================================================
-
-inline Standard_Integer Poly_Triangulation::NbTriangles() const 
-{
-  return myNbTriangles;
-}
-
-//=======================================================================
-//function : HasUVNodes
-//purpose  : 
-//=======================================================================
-
-inline Standard_Boolean Poly_Triangulation::HasUVNodes() const 
-{
-  return !myUVNodes.IsNull();
-}
-
index 13bbade0789402335e340ceee88fbe4935f7622a..9a0f33df4e9d2498f05b04e74c13cebf2dbe56dc 100644 (file)
@@ -3948,25 +3948,15 @@ static Standard_Integer OCC26485 (Draw_Interpretor& theDI, Standard_Integer theA
       continue;
 
     Poly::ComputeNormals(aT);
-    const TColgp_Array1OfPnt&       aVertices = aT->Nodes();
-    const TShort_Array1OfShortReal& aNormals  = aT->Normals();
 
     // Number of nodes in the triangulation
-    int aVertexNb = aT->Nodes().Length();
-    if (aVertexNb*3 != aNormals.Length())
-    {
-      theDI << "Failed. Different number of normals vs. vertices\n";
-      return 1;
-    }
+    int aVertexNb = aT->NbNodes();
 
     // Get each vertex index, checking common vertexes between shapes
     for( int i=0; i < aVertexNb; i++ )
     {
-      gp_Pnt aPoint = aVertices.Value( i+1 );
-      gp_Vec aNormal = gp_Vec(
-        aNormals.Value( i*3 + 1 ),
-        aNormals.Value( i*3 + 2 ),
-        aNormals.Value( i*3 + 3 ) );
+      gp_Pnt aPoint = aT->Node( i+1 );
+      gp_Dir aNormal = aT->Normal( i+1 );
 
       if (aNormal.X() == 0 && aNormal.Y() == 0 && aNormal.Z() == 1)
       {
index 88543d5ecd3b86dbbda8a608c1ffbf254ff858e6..f0511d95c5d5640f924d3d70ff9f4d6df71f9064 100644 (file)
@@ -57,8 +57,6 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S
 {
   myInvInitLocation = myInitLocation.Transformation().Inverted();
   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());
   gp_XYZ aCenter (0.0, 0.0, 0.0);
 
@@ -77,8 +75,8 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S
     for (Standard_Integer aTriangleIdx = 1; aTriangleIdx <= aNbTriangles; aTriangleIdx++)
     {
       aPoly.Triangles (aTriangleIdx, aTriangle[0], aTriangle[1], aTriangle[2]);
-      aTriangles (aTriangleIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]);
-      aCenter += (aNodes (aTrNodeIdx[0]).XYZ() + aNodes (aTrNodeIdx[1]).XYZ()+ aNodes (aTrNodeIdx[2]).XYZ()) / 3.0;
+      myTriangul->Triangle (aTriangleIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]);
+      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++)
       {
         Standard_Integer aNextVert = (aVertIdx + 1) % 3;
@@ -96,8 +94,8 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S
     Standard_Integer aTrNodeIdx[3];
     for (Standard_Integer aTrIdx = 1; aTrIdx <= aNbTriangles; aTrIdx++)
     {
-      aTriangles (aTrIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]);
-      aCenter += (aNodes (aTrNodeIdx[0]).XYZ() + aNodes (aTrNodeIdx[1]).XYZ()+ aNodes (aTrNodeIdx[2]).XYZ()) / 3.0;
+      myTriangul->Triangle (aTrIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]);
+      aCenter += (myTriangul->Node (aTrNodeIdx[0]).XYZ() + myTriangul->Node (aTrNodeIdx[1]).XYZ()+ myTriangul->Node (aTrNodeIdx[2]).XYZ()) / 3.0;
     }
   }
   if (aNbTriangles != 0)
@@ -107,9 +105,9 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S
   myBndBox.Clear();
   for (Standard_Integer aNodeIdx = 1; aNodeIdx <= myTriangul->NbNodes(); ++aNodeIdx)
   {
-    myBndBox.Add (SelectMgr_Vec3 (aNodes (aNodeIdx).X(),
-                                  aNodes (aNodeIdx).Y(),
-                                  aNodes (aNodeIdx).Z()));
+    myBndBox.Add (SelectMgr_Vec3 (myTriangul->Node (aNodeIdx).X(),
+                                  myTriangul->Node (aNodeIdx).Y(),
+                                  myTriangul->Node (aNodeIdx).Z()));
   }
 
   if (theIsInterior)
@@ -149,7 +147,7 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S
 {
   myInvInitLocation = myInitLocation.Transformation().Inverted();
   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);
   if (theIsInterior)
   {
@@ -191,11 +189,11 @@ Select3D_BndBox3d Select3D_SensitiveTriangulation::Box (const Standard_Integer t
   if (mySensType == Select3D_TOS_INTERIOR)
   {
     Standard_Integer aNode1, aNode2, aNode3;
-    myTriangul->Triangles() (aPrimIdx + 1).Get (aNode1, aNode2, aNode3);
+    myTriangul->Triangle (aPrimIdx + 1).Get (aNode1, aNode2, aNode3);
 
-    gp_Pnt aPnt1 = myTriangul->Nodes().Value (aNode1);
-    gp_Pnt aPnt2 = myTriangul->Nodes().Value (aNode2);
-    gp_Pnt aPnt3 = myTriangul->Nodes().Value (aNode3);
+    gp_Pnt aPnt1 = myTriangul->Node(aNode1);
+    gp_Pnt aPnt2 = myTriangul->Node(aNode2);
+    gp_Pnt aPnt3 = myTriangul->Node(aNode3);
 
     aMinPnt = SelectMgr_Vec3 (Min (aPnt1.X(), Min (aPnt2.X(), aPnt3.X())),
                               Min (aPnt1.Y(), Min (aPnt2.Y(), aPnt3.Y())),
@@ -208,8 +206,8 @@ Select3D_BndBox3d Select3D_SensitiveTriangulation::Box (const Standard_Integer t
   {
     Standard_Integer aNodeIdx1 = myFreeEdges->Value (myFreeEdges->Lower() + aPrimIdx);
     Standard_Integer aNodeIdx2 = myFreeEdges->Value (myFreeEdges->Lower() + aPrimIdx + 1);
-    gp_Pnt aNode1 = myTriangul->Nodes().Value (aNodeIdx1);
-    gp_Pnt aNode2 = myTriangul->Nodes().Value (aNodeIdx2);
+    gp_Pnt aNode1 = myTriangul->Node(aNodeIdx1);
+    gp_Pnt aNode2 = myTriangul->Node(aNodeIdx2);
 
     aMinPnt = SelectMgr_Vec3 (Min (aNode1.X(), aNode2.X()),
                               Min (aNode1.Y(), aNode2.Y()),
@@ -266,8 +264,8 @@ Standard_Boolean Select3D_SensitiveTriangulation::overlapsElement (SelectBasics_
     Standard_Integer aSegmStartIdx = myFreeEdges->Value (aPrimitiveIdx * 2 + 1);
     Standard_Integer aSegmEndIdx = myFreeEdges->Value (aPrimitiveIdx * 2 + 2);
     Handle(TColgp_HArray1OfPnt) anEdgePnts = new TColgp_HArray1OfPnt (1, 2);
-    gp_Pnt aSegmStart = myTriangul->Nodes().Value (aSegmStartIdx);
-    gp_Pnt aSegmEnd   = myTriangul->Nodes().Value (aSegmEndIdx);
+    gp_Pnt aSegmStart = myTriangul->Node(aSegmStartIdx);
+    gp_Pnt aSegmEnd   = myTriangul->Node(aSegmEndIdx);
     anEdgePnts->SetValue (1, aSegmStart);
     anEdgePnts->SetValue (2, aSegmEnd);
     Standard_Boolean isMatched = theMgr.Overlaps (anEdgePnts, Select3D_TOS_BOUNDARY, theMatchDepth);
@@ -276,12 +274,11 @@ Standard_Boolean Select3D_SensitiveTriangulation::overlapsElement (SelectBasics_
   }
   else
   {
-    const Poly_Array1OfTriangle& aTriangles = myTriangul->Triangles();
     Standard_Integer aNode1, aNode2, aNode3;
-    aTriangles (aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3);
-    gp_Pnt aPnt1 = myTriangul->Nodes().Value (aNode1);
-    gp_Pnt aPnt2 = myTriangul->Nodes().Value (aNode2);
-    gp_Pnt aPnt3 = myTriangul->Nodes().Value (aNode3);
+    myTriangul->Triangle(aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3);
+    gp_Pnt aPnt1 = myTriangul->Node(aNode1);
+    gp_Pnt aPnt2 = myTriangul->Node(aNode2);
+    gp_Pnt aPnt3 = myTriangul->Node(aNode3);
     return theMgr.Overlaps (aPnt1, aPnt2, aPnt3, Select3D_TOS_INTERIOR, theMatchDepth);
   }
 }
@@ -297,8 +294,8 @@ Standard_Boolean Select3D_SensitiveTriangulation::elementIsInside (SelectBasics_
 
   if (mySensType == Select3D_TOS_BOUNDARY)
   {
-    gp_Pnt aSegmPnt1 = myTriangul->Nodes().Value (myFreeEdges->Value (aPrimitiveIdx * 2 + 1));
-    gp_Pnt aSegmPnt2 = myTriangul->Nodes().Value (myFreeEdges->Value (aPrimitiveIdx * 2 + 2));
+    gp_Pnt aSegmPnt1 = myTriangul->Node(myFreeEdges->Value (aPrimitiveIdx * 2 + 1));
+    gp_Pnt aSegmPnt2 = myTriangul->Node(myFreeEdges->Value (aPrimitiveIdx * 2 + 2));
 
     return theMgr.Overlaps (aSegmPnt1) && theMgr.Overlaps (aSegmPnt2);
   }
@@ -308,11 +305,11 @@ Standard_Boolean Select3D_SensitiveTriangulation::elementIsInside (SelectBasics_
     Standard_Integer aNode2;
     Standard_Integer aNode3;
 
-    myTriangul->Triangles() (aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3);
+    myTriangul->Triangle(aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3);
 
-    gp_Pnt aPnt1 = myTriangul->Nodes().Value (aNode1);
-    gp_Pnt aPnt2 = myTriangul->Nodes().Value (aNode2);
-    gp_Pnt aPnt3 = myTriangul->Nodes().Value (aNode3);
+    gp_Pnt aPnt1 = myTriangul->Node(aNode1);
+    gp_Pnt aPnt2 = myTriangul->Node(aNode2);
+    gp_Pnt aPnt3 = myTriangul->Node(aNode3);
 
     return theMgr.Overlaps (aPnt1)
         && theMgr.Overlaps (aPnt2)
@@ -382,12 +379,10 @@ Select3D_BndBox3d Select3D_SensitiveTriangulation::BoundingBox()
   if (myBndBox.IsValid())
     return applyTransformation();
 
-  const Standard_Integer aLower = myTriangul->Nodes().Lower();
-  const Standard_Integer anUpper = myTriangul->Nodes().Upper();
   Select3D_BndBox3d aBndBox;
-  for (Standard_Integer aNodeIdx = aLower; aNodeIdx <= anUpper; ++aNodeIdx)
+  for (Standard_Integer aNodeIdx = 1; aNodeIdx <= myTriangul->NbNodes(); ++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());
     aBndBox.Add (aNodeTransf);
   }
@@ -413,7 +408,7 @@ gp_Pnt Select3D_SensitiveTriangulation::CenterOfGeometry() const
 //=======================================================================
 Standard_Integer Select3D_SensitiveTriangulation::NbSubElements()
 {
-  return myTriangul->Nodes().Length();
+  return myTriangul->NbNodes();
 }
 
 //=======================================================================
index 5f212cdd541355b62a222f95008c2e9672941181..fb9e9cb0628eb79041105f371c07243d8ed812c7 100644 (file)
@@ -25,6 +25,7 @@
 #include <Standard_Type.hxx>
 #include <Standard_Type.hxx>
 
+#include <Poly_Triangulation.hxx>
 #include <TopLoc_Location.hxx>
 #include <gp_Trsf.hxx>
 #include <gp_Pnt.hxx>
index 15e7a4b6e564658e1ad237d86ba6c4ae82d47f48..1f3abfef50785fcdb948ba18f3cf88efbbf1589d 100644 (file)
@@ -236,25 +236,21 @@ void StdPrs_Isolines::addOnTriangulation (const Handle(Poly_Triangulation)& theT
 
   SeqOfVecOfSegments aUPolylines, aVPolylines;
 
-  const Poly_Array1OfTriangle& aTriangles = theTriangulation->Triangles();
-  const TColgp_Array1OfPnt&    aNodes     = theTriangulation->Nodes();
-  const TColgp_Array1OfPnt2d&  aUVNodes   = theTriangulation->UVNodes();
-
   TColStd_Array1OfInteger aUIsoIndexes (1, aNbIsoU);
   TColStd_Array1OfInteger aVIsoIndexes (1, aNbIsoV);
   aUIsoIndexes.Init (-1);
   aVIsoIndexes.Init (-1);
 
-  for (Standard_Integer anI = aTriangles.Lower(); anI <= aTriangles.Upper(); ++anI)
+  for (Standard_Integer anI = 1; anI <= theTriangulation->NbTriangles(); ++anI)
   {
     Standard_Integer aNodeIdxs[3];
-    aTriangles.Value (anI).Get (aNodeIdxs[0], aNodeIdxs[1],aNodeIdxs[2]);
-    const gp_Pnt aNodesXYZ[3] = { aNodes.Value (aNodeIdxs[0]),
-                                  aNodes.Value (aNodeIdxs[1]),
-                                  aNodes.Value (aNodeIdxs[2]) };
-    const gp_Pnt2d aNodesUV[3] = { aUVNodes.Value (aNodeIdxs[0]),
-                                   aUVNodes.Value (aNodeIdxs[1]),
-                                   aUVNodes.Value (aNodeIdxs[2]) };
+    theTriangulation->Triangle(anI).Get (aNodeIdxs[0], aNodeIdxs[1],aNodeIdxs[2]);
+    const gp_Pnt aNodesXYZ[3] = { theTriangulation->Node(aNodeIdxs[0]),
+                                  theTriangulation->Node(aNodeIdxs[1]),
+                                  theTriangulation->Node(aNodeIdxs[2]) };
+    const gp_Pnt2d aNodesUV[3] = { theTriangulation->UVNode(aNodeIdxs[0]),
+                                   theTriangulation->UVNode(aNodeIdxs[1]),
+                                   theTriangulation->UVNode(aNodeIdxs[2]) };
 
     // Evaluate polyline points for u isolines.
     for (Standard_Integer anIsoIdx = 1; anIsoIdx <= aNbIsoU; ++anIsoIdx)
index 243ee8e06f9f1af011217951a7b28815320636f5..bd769430413ed811dd0a22552a4c90755782ddb1 100644 (file)
@@ -190,9 +190,7 @@ namespace
 
       Poly_Connect aPolyConnect (aT);
       // Extracts vertices & normals from nodes
-      const TColgp_Array1OfPnt&   aNodes   = aT->Nodes();
-      const TColgp_Array1OfPnt2d& aUVNodes = aT->UVNodes();
-      TColgp_Array1OfDir aNormals (aNodes.Lower(), aNodes.Upper());
+      TColgp_Array1OfDir aNormals (1, aT->NbNodes());
       StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
 
       if (theHasTexels)
@@ -203,9 +201,9 @@ namespace
       }
 
       const Standard_Integer aDecal = anArray->VertexNumber();
-      for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
+      for (Standard_Integer aNodeIter = 1; aNodeIter <= aT->NbNodes(); ++aNodeIter)
       {
-        aPoint = aNodes (aNodeIter);
+        aPoint = aT->Node (aNodeIter);
         if (!aLoc.IsIdentity())
         {
           aPoint.Transform (aTrsf);
@@ -213,10 +211,10 @@ namespace
           aNormals (aNodeIter) = aNormals (aNodeIter).Transformed (aTrsf);
         }
 
-        if (theHasTexels && aUVNodes.Upper() == aNodes.Upper())
+        if (theHasTexels && aT->HasUVNodes())
         {
-          const gp_Pnt2d aTexel = gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aUVNodes (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(),
-                                            (-theUVOrigin.Y() + (theUVRepeat.Y() * (aUVNodes (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y());
+          const gp_Pnt2d aTexel = gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aT->UVNode (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(),
+                                            (-theUVOrigin.Y() + (theUVRepeat.Y() * (aT->UVNode (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y());
           anArray->AddVertex (aPoint, aNormals (aNodeIter), aTexel);
         }
         else
@@ -226,22 +224,21 @@ namespace
       }
 
       // Fill array with vertex and edge visibility info
-      const Poly_Array1OfTriangle& aTriangles = aT->Triangles();
       Standard_Integer anIndex[3];
       for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter)
       {
         if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored)
         {
-          aTriangles (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]);
+          aT->Triangle (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]);
         }
         else
         {
-          aTriangles (aTriIter).Get (anIndex[0], anIndex[1], anIndex[2]);
+          aT->Triangle (aTriIter).Get (anIndex[0], anIndex[1], anIndex[2]);
         }
 
-        gp_Pnt aP1 = aNodes (anIndex[0]);
-        gp_Pnt aP2 = aNodes (anIndex[1]);
-        gp_Pnt aP3 = aNodes (anIndex[2]);
+        gp_Pnt aP1 = aT->Node (anIndex[0]);
+        gp_Pnt aP2 = aT->Node (anIndex[1]);
+        gp_Pnt aP3 = aT->Node (anIndex[2]);
 
         gp_Vec aV1 (aP1, aP2);
         if (aV1.SquareMagnitude() <= aPreci)
@@ -367,8 +364,10 @@ namespace
       }
 
       // 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 ();
+
+      if (anEdgeNodes.Length () < 2)
+        continue;
 
       // collect the edge nodes
       Standard_Integer aSegmentEdge = aSegments->VertexNumber() + 1;
@@ -377,8 +376,8 @@ namespace
         // node index in face triangulation
         // get node and apply location transformation to the node
         const Standard_Integer aTriIndex = anEdgeNodes.Value (aNodeIdx);
-        gp_Pnt aTriNode = aTriNodes.Value (aTriIndex);
-        if (!aTrsf.IsIdentity())
+        gp_Pnt aTriNode = aTriangulation->Node (aTriIndex);
+        if (!aTrsf.IsIdentity ())
         {
           aTriNode.Transform (aTrsf);
         }
index e5ba469c559ce06533d6c55a315262e5e6fafe26..09f23b78a5adc356a888331cb0577ac5adec6899 100644 (file)
@@ -139,24 +139,17 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face&  theFace,
                                            TColgp_Array1OfDir& theNormals)
 {
   const Handle(Poly_Triangulation)& aPolyTri = thePolyConnect.Triangulation();
-  const TColgp_Array1OfPnt&         aNodes   = aPolyTri->Nodes();
   if (aPolyTri->HasNormals())
   {
     // normals pre-computed in triangulation structure
-    const TShort_Array1OfShortReal& aNormals = aPolyTri->Normals();
-    const Standard_ShortReal*       aNormArr = &(aNormals.Value (aNormals.Lower()));
-    for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
+    for (Standard_Integer aNodeIter = 1; aNodeIter <= aPolyTri->NbNodes(); ++aNodeIter)
     {
-      const Standard_Integer anId = 3 * (aNodeIter - aNodes.Lower());
-      const gp_Dir aNorm (aNormArr[anId + 0],
-                          aNormArr[anId + 1],
-                          aNormArr[anId + 2]);
-      theNormals (aNodeIter) = aNorm;
+      theNormals (aNodeIter) = aPolyTri->Normal (aNodeIter);
     }
 
     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();
       }
@@ -169,24 +162,21 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face&  theFace,
   Handle(Geom_Surface)   aSurf     = BRep_Tool::Surface (aZeroFace);
   const Standard_Real    aTol      = Precision::Confusion();
   Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, aPolyTri->NbNodes() * 3);
-  const Poly_Array1OfTriangle& aTriangles = aPolyTri->Triangles();
-  const TColgp_Array1OfPnt2d*  aNodesUV   = aPolyTri->HasUVNodes() && !aSurf.IsNull()
-                                          ? &aPolyTri->UVNodes()
-                                          : NULL;
+  Standard_Boolean hasUVNodes = aPolyTri->HasUVNodes() && !aSurf.IsNull();
   Standard_Integer aTri[3];
-  for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
+  for (Standard_Integer aNodeIter = 1; aNodeIter <= aPolyTri->NbNodes(); ++aNodeIter)
   {
     // try to retrieve normal from real surface first, when UV coordinates are available
-    if (aNodesUV == NULL
-     || GeomLib::NormEstim (aSurf, aNodesUV->Value (aNodeIter), aTol, theNormals (aNodeIter)) > 1)
+    if (hasUVNodes == Standard_False
+     || GeomLib::NormEstim (aSurf, aPolyTri->UVNode (aNodeIter), aTol, theNormals (aNodeIter)) > 1)
     {
       // compute flat normals
       gp_XYZ eqPlan (0.0, 0.0, 0.0);
       for (thePolyConnect.Initialize (aNodeIter); thePolyConnect.More(); thePolyConnect.Next())
       {
-        aTriangles (thePolyConnect.Value()).Get (aTri[0], aTri[1], aTri[2]);
-        const gp_XYZ v1 (aNodes (aTri[1]).Coord() - aNodes (aTri[0]).Coord());
-        const gp_XYZ v2 (aNodes (aTri[2]).Coord() - aNodes (aTri[1]).Coord());
+        aPolyTri->Triangle (thePolyConnect.Value()).Get (aTri[0], aTri[1], aTri[2]);
+        const gp_XYZ v1 (aPolyTri->Node (aTri[1]).Coord() - aPolyTri->Node (aTri[0]).Coord());
+        const gp_XYZ v2 (aPolyTri->Node (aTri[2]).Coord() - aPolyTri->Node (aTri[1]).Coord());
         const gp_XYZ vv = v1 ^ v2;
         const Standard_Real aMod = vv.Modulus();
         if (aMod >= aTol)
@@ -198,7 +188,7 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face&  theFace,
       theNormals (aNodeIter) = (aModMax > aTol) ? gp_Dir (eqPlan) : gp::DZ();
     }
 
-    const Standard_Integer anId = (aNodeIter - aNodes.Lower()) * 3;
+    const Standard_Integer anId = (aNodeIter - 1) * 3;
     aNormals->SetValue (anId + 1, (Standard_ShortReal )theNormals (aNodeIter).X());
     aNormals->SetValue (anId + 2, (Standard_ShortReal )theNormals (aNodeIter).Y());
     aNormals->SetValue (anId + 3, (Standard_ShortReal )theNormals (aNodeIter).Z());
@@ -207,7 +197,7 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face&  theFace,
 
   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();
     }
index 5522ea5fe186279a1d8a77a3fbc2c61f88003b8f..0d740ede12b140e17b3c30464503f008bb52bdc6 100644 (file)
@@ -202,21 +202,20 @@ void StdPrs_WFShape::addEdges (const TopTools_ListOfShape&  theEdges,
     {
       // Presentation based on triangulation of a face.
       const TColStd_Array1OfInteger& anIndices = anEdgeIndicies->Nodes();
-      const TColgp_Array1OfPnt&      aNodes    = aTriangulation->Nodes();
 
       Standard_Integer anIndex = anIndices.Lower();
       if (aLocation.IsIdentity())
       {
         for (; anIndex <= anIndices.Upper(); ++anIndex)
         {
-          aPoints->Append (aNodes (anIndices (anIndex)));
+          aPoints->Append (aTriangulation->Node(anIndices (anIndex)));
         }
       }
       else
       {
         for (; anIndex <= anIndices.Upper(); ++anIndex)
         {
-          aPoints->Append (aNodes (anIndices (anIndex)).Transformed (aLocation));
+          aPoints->Append (aTriangulation->Node(anIndices (anIndex)).Transformed (aLocation));
         }
       }
     }
@@ -281,8 +280,6 @@ void StdPrs_WFShape::addEdgesOnTriangulation (const Handle(Prs3d_Presentation)&
       continue;
     }
 
-    const TColgp_Array1OfPnt& aNodes = T->Nodes();
-
     // Build the connect tool.
     Poly_Connect aPolyConnect (T);
 
@@ -315,11 +312,10 @@ void StdPrs_WFShape::addEdgesOnTriangulation (const Handle(Prs3d_Presentation)&
     TColStd_Array1OfInteger anInternal (0, 2 * aNbInternal);
 
     Standard_Integer aFreeIndex = 1, anIntIndex = 1;
-    const Poly_Array1OfTriangle& aTriangles = T->Triangles();
     for (Standard_Integer anI = 1; anI <= aNbTriangles; ++anI)
     {
       aPolyConnect.Triangles (anI, aT[0], aT[1], aT[2]);
-      aTriangles (anI).Get (aN[0], aN[1], aN[2]);
+      T->Triangle (anI).Get (aN[0], aN[1], aN[2]);
       for (Standard_Integer aJ = 0; aJ < 3; aJ++)
       {
         Standard_Integer k = (aJ + 1) % 3;
@@ -343,8 +339,8 @@ void StdPrs_WFShape::addEdgesOnTriangulation (const Handle(Prs3d_Presentation)&
     Standard_Integer aFreeHalfNb = aFree.Length() / 2;
     for (Standard_Integer anI = 1; anI <= aFreeHalfNb; ++anI)
     {
-      gp_Pnt aPoint1 = aNodes (aFree (2 * anI - 1)).Transformed (aLocation);
-      gp_Pnt aPoint2 = aNodes (aFree (2 * anI    )).Transformed (aLocation);
+      gp_Pnt aPoint1 = T->Node(aFree (2 * anI - 1)).Transformed (aLocation);
+      gp_Pnt aPoint2 = T->Node(aFree (2 * anI    )).Transformed (aLocation);
       aSurfPoints.Append (aPoint1);
       aSurfPoints.Append (aPoint2);
     }
index 9b837219739123ba1f73543e5341f51b0f72bd0e..8a034e9e4178e6d6ca60f405a0f9046a90b88d01 100644 (file)
@@ -356,7 +356,6 @@ static Handle(TColgp_HArray1OfPnt) GetPointsFromPolygon (const TopoDS_Edge& theE
   if (!anHIndices.IsNull())
   {
     const TColStd_Array1OfInteger& anIndices = anHIndices->Nodes();
-    const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
 
     aResultPoints = new TColgp_HArray1OfPnt (1, anIndices.Length());
 
@@ -364,14 +363,14 @@ static Handle(TColgp_HArray1OfPnt) GetPointsFromPolygon (const TopoDS_Edge& theE
     {
       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
     {
       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;
index d79356c955ea7094b23e621878dfbbf886cefcef..8775016369686b291112027a092fe60d7278bc29 100644 (file)
@@ -539,8 +539,6 @@ void StdSelect_ViewerSelector3d::computeSensitivePrs (const Handle(Graphic3d_Str
     {
       Handle(Poly_Triangulation) PT (Handle(Select3D_SensitiveTriangulation)::DownCast (Ent)->Triangulation());
 
-      const Poly_Array1OfTriangle& triangles = PT->Triangles();
-      const TColgp_Array1OfPnt& Nodes = PT->Nodes();
       Standard_Integer n[3];
 
       TopLoc_Location iloc, bidloc;
@@ -555,10 +553,10 @@ void StdSelect_ViewerSelector3d::computeSensitivePrs (const Handle(Graphic3d_Str
       Standard_Integer i;
       for (i = 1; i <= PT->NbTriangles(); i++)
       {
-        triangles (i).Get (n[0], n[1], n[2]);
-        gp_Pnt P1 (Nodes (n[0]).Transformed (iloc));
-        gp_Pnt P2 (Nodes (n[1]).Transformed (iloc));
-        gp_Pnt P3 (Nodes (n[2]).Transformed (iloc));
+        PT->Triangle (i).Get (n[0], n[1], n[2]);
+        gp_Pnt P1 (PT->Node (n[0]).Transformed (iloc));
+        gp_Pnt P2 (PT->Node (n[1]).Transformed (iloc));
+        gp_Pnt P3 (PT->Node (n[2]).Transformed (iloc));
         gp_XYZ V1 (P1.XYZ());
         gp_XYZ V2 (P2.XYZ());
         gp_XYZ V3 (P3.XYZ());
@@ -585,7 +583,7 @@ void StdSelect_ViewerSelector3d::computeSensitivePrs (const Handle(Graphic3d_Str
       for (i = 1; i <= PT->NbTriangles(); i++)
       {
         pc.Triangles (i, t[0], t[1], t[2]);
-        triangles (i).Get (n[0], n[1], n[2]);
+        PT->Triangle (i).Get (n[0], n[1], n[2]);
         for (j = 0; j < 3; j++)
         {
           Standard_Integer k = (j + 1) % 3;
@@ -599,7 +597,7 @@ void StdSelect_ViewerSelector3d::computeSensitivePrs (const Handle(Graphic3d_Str
       }
       for (Standard_Integer ifri = 1; ifri <= FreeE.Length(); ifri += 2)
       {
-        gp_Pnt pe1 (Nodes (FreeE (ifri)).Transformed (iloc)), pe2 (Nodes (FreeE (ifri + 1)).Transformed (iloc));
+        gp_Pnt pe1 (PT->Node (FreeE (ifri)).Transformed (iloc)), pe2 (PT->Node (FreeE (ifri + 1)).Transformed (iloc));
         aSeqFree.Append(pe1);
         aSeqFree.Append(pe2);
       }
index 1b4c6fe5fa305b02683a5484c9a8946fab1eb9c8..efd5cc0bf712983609e9800442e588660fea90c7 100644 (file)
@@ -50,7 +50,7 @@ namespace
       TopLoc_Location aLoc;
       myPoly = BRep_Tool::Triangulation (aFace, aLoc);
       myTrsf = aLoc.Transformation();
-      myNbTriangles = (myPoly.IsNull() ? 0 : myPoly->Triangles().Length());
+      myNbTriangles = (myPoly.IsNull() ? 0 : myPoly->NbTriangles());
       myInvert = (aFace.Orientation() == TopAbs_REVERSED);
       if (myTrsf.IsNegative())
         myInvert = ! myInvert;
@@ -63,10 +63,10 @@ namespace
     {
       // get positions of nodes
       int iNode1, iNode2, iNode3;
-      myPoly->Triangles()(iTri).Get (iNode1, iNode2, iNode3);
-      thePnt1 = myPoly->Nodes()(iNode1);
-      thePnt2 = myPoly->Nodes()(myInvert ? iNode3 : iNode2);
-      thePnt3 = myPoly->Nodes()(myInvert ? iNode2 : iNode3);
+      myPoly->Triangle(iTri).Get (iNode1, iNode2, iNode3);
+      thePnt1 = myPoly->Node(iNode1);
+      thePnt2 = myPoly->Node(myInvert ? iNode3 : iNode2);
+      thePnt3 = myPoly->Node(myInvert ? iNode2 : iNode3);
 
       // apply transormation if not identity
       if (myTrsf.Form() != gp_Identity)
index d8916120baaf296df28dbd4bd7c3be6a102ee61f..717c506279b2fe87cf7e3197e9abea4e066e6054 100644 (file)
@@ -62,11 +62,10 @@ static void Normal(const TopoDS_Face&  aFace,
     CSLib_DerivativeStatus Status;
     CSLib_NormalStatus NStat;
     S.Initialize(aFace, Standard_False);
-    const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
     if (S.GetType() != GeomAbs_Plane) {
-      for (i = UVNodes.Lower(); i <= UVNodes.Upper(); i++) {
-       U = UVNodes(i).X();
-       V = UVNodes(i).Y();
+      for (i = 1; i <= T->NbNodes(); i++) {
+       U = T->UVNode (i).X();
+       V = T->UVNode (i).Y();
        S.D1(U,V,P,D1U,D1V);
        CSLib::Normal(D1U,D1V,Precision::Angular(),Status,Nor(i));
        if (Status != CSLib_Done) {
@@ -78,8 +77,8 @@ static void Normal(const TopoDS_Face&  aFace,
     }
     else {
       gp_Dir NPlane;
-      U = UVNodes(UVNodes.Lower()).X();
-      V = UVNodes(UVNodes.Lower()).Y();
+      U = T->UVNode (1).X();
+      V = T->UVNode (1).Y();
       S.D1(U,V,P,D1U,D1V);
       CSLib::Normal(D1U,D1V,Precision::Angular(),Status,NPlane);
       if (Status != CSLib_Done) {
@@ -92,16 +91,14 @@ static void Normal(const TopoDS_Face&  aFace,
     }
   }
   else {
-    const TColgp_Array1OfPnt& Nodes = T->Nodes();
     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);
       for (pc.Initialize(i);  pc.More(); pc.Next()) {
-       triangles(pc.Value()).Get(n[0], n[1], n[2]);
-       gp_XYZ v1(Nodes(n[1]).Coord()-Nodes(n[0]).Coord());
-       gp_XYZ v2(Nodes(n[2]).Coord()-Nodes(n[1]).Coord());
+       T->Triangle (pc.Value()).Get(n[0], n[1], n[2]);
+       gp_XYZ v1(T->Node (n[1]).Coord() - T->Node (n[0]).Coord());
+       gp_XYZ v2(T->Node (n[2]).Coord() - T->Node (n[1]).Coord());
        eqPlan += (v1^v2).Normalized();
       }
       Nor(i) = gp_Dir(eqPlan);
@@ -118,30 +115,25 @@ void StlTransfer::RetrieveMesh (const TopoDS_Shape&  Shape,
     TopLoc_Location Loc, loc;
     Handle(Poly_Triangulation) theTriangulation = BRep_Tool::Triangulation(face, Loc);
     if (theTriangulation.IsNull()) continue; //Meshing was not done for this face!
-    Poly_Array1OfTriangle theTriangles(1,theTriangulation->NbTriangles());
-    theTriangles.Assign(theTriangulation->Triangles());
     Mesh->AddDomain (theTriangulation->Deflection());
-    
-    TColgp_Array1OfPnt thePoints(1, theTriangulation->NbNodes());
-    thePoints.Assign(theTriangulation->Nodes());
+
     //compute normal of face
-    const TColgp_Array1OfPnt& Nodes = theTriangulation->Nodes();
-    TColgp_Array1OfDir NORMAL(Nodes.Lower(), Nodes.Upper());
+    TColgp_Array1OfDir NORMAL(1, theTriangulation->NbNodes());
     Poly_Connect pc(theTriangulation);
     Normal(face, pc, NORMAL);
     Standard_Integer i;
-    for(i=1;i<=thePoints.Length();i++) {
+    for(i=1;i<=theTriangulation->NbNodes();i++) {
       Standard_Real X1, Y1, Z1;
-      gp_Pnt p = thePoints.Value(i);
+      gp_Pnt p = theTriangulation->Node (i);
       p.Transform(Loc.Transformation());
       p.Coord (X1, Y1, Z1);
       Mesh->AddVertex (X1, Y1, Z1);
     }
     try {
       OCC_CATCH_SIGNALS
-      for (i=1;i<=theTriangles.Length();i++) {
+      for (i=1;i<=theTriangulation->NbTriangles();i++) {
        Standard_Integer V1, V2, V3;
-       Poly_Triangle triangle = theTriangles.Value(i);
+       Poly_Triangle triangle = theTriangulation->Triangle (i);
        triangle.Get(V1, V2, V3);
        gp_Pnt P1, P2, P3;
        P1 = Mesh->Vertices(Mesh->NbDomains()).Value(V1);
index f9b707f64b2c8a05521aa03f3423fa746344c07f..e72ac561eb764e4b2bd6258f0857b97f10e17669 100644 (file)
@@ -79,6 +79,8 @@ TDataStd_ListIteratorOfListOfByte.hxx
 TDataStd_ListIteratorOfListOfExtendedString.hxx
 TDataStd_ListOfByte.hxx
 TDataStd_ListOfExtendedString.hxx
+TDataStd_Mesh.cxx
+TDataStd_Mesh.hxx
 TDataStd_Name.cxx
 TDataStd_Name.hxx
 TDataStd_NamedData.cxx
diff --git a/src/TDataStd/TDataStd_Mesh.cxx b/src/TDataStd/TDataStd_Mesh.cxx
new file mode 100644 (file)
index 0000000..67ae42a
--- /dev/null
@@ -0,0 +1,427 @@
+// Created on: 2015-12-10
+// 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 <TDataStd_Mesh.hxx>
+#include <Standard_GUID.hxx>
+#include <Standard_Type.hxx>
+#include <TDF_Attribute.hxx>
+#include <TDF_Label.hxx>
+#include <TDF_RelocationTable.hxx>
+
+//=======================================================================
+//function : GetID
+//purpose  : Returns the ID of the mesh attribute.
+//=======================================================================
+const Standard_GUID& TDataStd_Mesh::GetID() 
+{ 
+  static Standard_GUID TDataStd_MeshID ("D7E3F1CF-38A4-4DCA-94F4-51C31F3FCBA5");
+  return TDataStd_MeshID; 
+}
+
+//=======================================================================
+//function : Set
+//purpose  : Finds or creates a mesh attribute.
+//=======================================================================
+Handle(TDataStd_Mesh) TDataStd_Mesh::Set(const TDF_Label& label) 
+{
+  Handle(TDataStd_Mesh) A;
+  if (!label.FindAttribute (TDataStd_Mesh::GetID(), A)) 
+  {
+    A = new TDataStd_Mesh;
+    label.AddAttribute(A);
+  }
+  return A;
+}
+
+//=======================================================================
+//function : Set
+//purpose  : Finds or creates a mesh attribute.
+//           Initializes the attribute by a mesh (Poly_Mesh) object.
+//           If the mesh consists of only triangles,
+//           you may put Poly_Triangulation object as a 2nd parameter of this method.
+//=======================================================================
+Handle(TDataStd_Mesh) TDataStd_Mesh::Set(const TDF_Label& label, const Handle(Poly_Mesh)& mesh)
+{
+   Handle(TDataStd_Mesh) M = TDataStd_Mesh::Set(label);
+   M->Set(mesh);
+   return M;
+}
+
+//=======================================================================
+//function : TDataStd_Mesh
+//purpose  : A constructor.
+//           Don't use it directly, 
+//           use please the static method Set(),
+//           which returns the attribute attached to a label.
+//=======================================================================
+TDataStd_Mesh::TDataStd_Mesh() 
+{
+
+}
+  
+//=======================================================================
+//function : TDataStd_Mesh
+//purpose  : Sets the mesh.
+//           If the mesh consists of only triangles,
+//           you may put Poly_Triangulation object.
+//=======================================================================
+void TDataStd_Mesh::Set(const Handle(Poly_Mesh)& mesh)
+{
+  Backup();
+  myMesh = mesh;
+}
+
+//=======================================================================
+//function : TDataStd_Mesh
+//purpose  : Returns the underlying mesh.
+//=======================================================================
+const Handle(Poly_Mesh)& TDataStd_Mesh::Get() const
+{
+  return myMesh;
+}
+
+// Poly_Mesh methods
+
+// The methods are "covered" by this attribute to prevent direct modification of the mesh.
+// There is no performance problem to call Poly_Mesh method through this attribute.
+// The most of the methods are considered as "inline" by the compiler in release mode.
+
+//=======================================================================
+//function : Deflection
+//purpose  : Returns the deflection of this triangulation.
+//=======================================================================
+Standard_Real TDataStd_Mesh::Deflection() const
+{
+  return myMesh->Deflection();
+}
+
+//=======================================================================
+//function : Deflection
+//purpose  : Sets the deflection of this triangulation to theDeflection.
+//           See more on deflection in Polygon2D
+//=======================================================================
+void TDataStd_Mesh::Deflection (const Standard_Real theDeflection)
+{
+  Backup();
+  myMesh->Deflection(theDeflection);
+}
+
+//=======================================================================
+//function : RemoveUVNodes
+//purpose  : Deallocates the UV nodes.
+//=======================================================================
+void TDataStd_Mesh::RemoveUVNodes()
+{
+  Backup();
+  myMesh->RemoveUVNodes();
+}
+
+//=======================================================================
+//function : NbNodes
+//purpose  : return the number of nodes for this triangulation.
+//=======================================================================
+Standard_Integer TDataStd_Mesh::NbNodes() const
+{
+  return myMesh->NbNodes();
+}
+
+//=======================================================================
+//function : NbTriangles
+//purpose  : return the number of triangles for this triangulation.
+//=======================================================================
+Standard_Integer TDataStd_Mesh::NbTriangles() const
+{
+  return myMesh->NbTriangles();
+}
+
+//=======================================================================
+//function : HasUVNodes
+//purpose  : return Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
+//=======================================================================
+Standard_Boolean TDataStd_Mesh::HasUVNodes() const
+{
+  return myMesh->HasUVNodes();
+}
+
+//=======================================================================
+//function : AddNode
+//purpose  : Adds Node to the triangulation. If triangulation has UVNodes or Normals
+//           they will be expanded and set to zero values to match the new number of nodes.
+//           return index of the added Node.
+//=======================================================================
+Standard_Integer TDataStd_Mesh::AddNode (const gp_Pnt& theNode)
+{
+  Backup();
+  return myMesh->AddNode(theNode);
+}
+
+//=======================================================================
+//function : Node
+//purpose  : return node at the given index.
+//           Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+//=======================================================================
+const gp_Pnt& TDataStd_Mesh::Node (const Standard_Integer theIndex) const
+{
+  return myMesh->Node(theIndex);
+}
+
+//=======================================================================
+//function : SetNode
+//purpose  : The method differs from Poly_Mesh
+//           Sets a node at the given index.
+//           Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+//=======================================================================
+void TDataStd_Mesh::SetNode (const Standard_Integer theIndex, const gp_Pnt& theNode)
+{
+  Backup();
+  myMesh->ChangeNode(theIndex) = theNode;
+}
+
+//=======================================================================
+//function : UVNode
+//purpose  : return UVNode at the given index.
+//           Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+//=======================================================================
+const gp_Pnt2d& TDataStd_Mesh::UVNode (const Standard_Integer theIndex) const
+{
+  return myMesh->UVNode(theIndex);
+}
+
+//=======================================================================
+//function : SetUVNode
+//purpose  : The method differs from Poly_Mesh
+//           Sets a UVNode at the given index.
+//           Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+//=======================================================================
+void TDataStd_Mesh::SetUVNode (const Standard_Integer theIndex, const gp_Pnt2d& theUVNode)
+{
+  Backup();
+  myMesh->ChangeUVNode(theIndex) = theUVNode;
+}
+
+//=======================================================================
+//function : AddTriangle
+//purpose  : Adds triangle to the triangulation.
+//           return index of the added triangle.
+//=======================================================================
+Standard_Integer TDataStd_Mesh::AddTriangle (const Poly_Triangle& theTriangle)
+{
+  Backup();
+  return myMesh->AddTriangle(theTriangle);
+}
+
+//=======================================================================
+//function : Triangle
+//purpose  : return triangle at the given index.
+//           Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
+//=======================================================================
+const Poly_Triangle& TDataStd_Mesh::Triangle (const Standard_Integer theIndex) const
+{
+  return myMesh->Triangle(theIndex);
+}
+
+//=======================================================================
+//function : SetTriangle
+//purpose  : The method differs from Poly_Mesh
+//           Sets a triangle at the given index.
+//           Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
+//=======================================================================
+void TDataStd_Mesh::SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle)
+{
+  Backup();
+  myMesh->ChangeTriangle(theIndex) = theTriangle;
+}
+
+//=======================================================================
+//function : SetNormals
+//purpose  : Sets the table of node normals.
+//           Raises exception if length of theNormals = 3 * NbNodes
+//=======================================================================
+void TDataStd_Mesh::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals)
+{
+  Backup();
+  myMesh->SetNormals(theNormals);
+}
+
+//=======================================================================
+//function : SetNormal
+//purpose  : Changes normal at the given index.
+//           Raises Standard_OutOfRange exception.
+//=======================================================================
+void TDataStd_Mesh::SetNormal (const Standard_Integer theIndex,
+                               const gp_Dir&          theNormal)
+{
+  Backup();
+  myMesh->SetNormal(theIndex, theNormal);
+}
+
+//=======================================================================
+//function : HasNormals
+//purpose  : Returns Standard_True if nodal normals are defined.
+//=======================================================================
+Standard_Boolean TDataStd_Mesh::HasNormals() const
+{
+  return myMesh->HasNormals();
+}
+
+//=======================================================================
+//function : Normal
+//purpose  : return normal at the given index.
+//           Raises Standard_OutOfRange exception.
+//=======================================================================
+const gp_Dir TDataStd_Mesh::Normal (const Standard_Integer theIndex) const
+{
+  return myMesh->Normal(theIndex);
+}
+
+//=======================================================================
+//function : AddElement
+//purpose  :
+//=======================================================================
+Standard_Integer TDataStd_Mesh::AddElement (const Standard_Integer theN1,
+                                            const Standard_Integer theN2,
+                                            const Standard_Integer theN3)
+{
+  Backup();
+  return myMesh->AddElement(theN1, theN2, theN3);
+}
+
+//=======================================================================
+//function : AddElement
+//purpose  :
+//=======================================================================
+Standard_Integer TDataStd_Mesh::AddElement (const Standard_Integer theN1,
+                                            const Standard_Integer theN2,
+                                            const Standard_Integer theN3,
+                                            const Standard_Integer theN4)
+{
+  Backup();
+  return myMesh->AddElement(theN1, theN2, theN3, theN4);
+}
+
+//=======================================================================
+//function : NbElements
+//purpose  : return the number of elements for this mesh.
+//=======================================================================
+Standard_Integer TDataStd_Mesh::NbElements() const
+{
+  return myMesh->NbElements();
+}
+
+//=======================================================================
+//function : NbQuads
+//purpose  : return the number of quads for this mesh.
+//=======================================================================
+Standard_Integer TDataStd_Mesh::NbQuads() const
+{
+  return myMesh->NbQuads();
+}
+
+//=======================================================================
+//function : Element
+//purpose  : return element at the given index.
+//           Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
+//=======================================================================
+const Poly_Element& TDataStd_Mesh::Element (const Standard_Integer theIndex) const
+{
+  return myMesh->Element(theIndex);
+}
+
+//=======================================================================
+//function : Element
+//purpose  : return nodes of the element at the given index.
+//           Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
+//=======================================================================
+void TDataStd_Mesh::Element (const Standard_Integer theIndex,
+                            Standard_Integer& theN1,
+                            Standard_Integer& theN2,
+                            Standard_Integer& theN3,
+                            Standard_Integer& theN4) const
+{
+  myMesh->Element(theIndex, theN1, theN2, theN3, theN4);
+}
+
+//=======================================================================
+//function : SetElement
+//purpose  : Sets an element at the given index.
+//           Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
+//=======================================================================
+void TDataStd_Mesh::SetElement (const Standard_Integer theIndex, const Poly_Element& theElement)
+{
+  Backup();
+  myMesh->SetElement(theIndex, theElement);
+}
+
+//=======================================================================
+//function : ID
+//purpose  : 
+//=======================================================================
+const Standard_GUID& TDataStd_Mesh::ID () const 
+{ 
+  return GetID(); 
+}
+
+//=======================================================================
+//function : NewEmpty
+//purpose  : 
+//=======================================================================
+Handle(TDF_Attribute) TDataStd_Mesh::NewEmpty () const
+{  
+  return new TDataStd_Mesh(); 
+}
+
+//=======================================================================
+//function : Restore
+//purpose  : 
+//=======================================================================
+void TDataStd_Mesh::Restore(const Handle(TDF_Attribute)& With) 
+{
+  myMesh.Nullify();
+  Handle(TDataStd_Mesh) M = Handle(TDataStd_Mesh)::DownCast(With);
+  if (!M->myMesh.IsNull())
+  {
+    Handle(Poly_Triangulation) T = M->myMesh->Copy();
+    if (!T.IsNull())
+        myMesh = Handle(Poly_Mesh)::DownCast(T);
+  }
+}
+
+//=======================================================================
+//function : Paste
+//purpose  : 
+//=======================================================================
+void TDataStd_Mesh::Paste (const Handle(TDF_Attribute)& Into,
+                           const Handle(TDF_RelocationTable)& ) const
+{
+  Handle(TDataStd_Mesh) M = Handle(TDataStd_Mesh)::DownCast(Into);
+  M->myMesh.Nullify();
+  if (!myMesh.IsNull())
+  {
+      Handle(Poly_Triangulation) T = myMesh->Copy();
+      if (!T.IsNull())
+        M->myMesh = Handle(Poly_Mesh)::DownCast(T);
+  }
+}
+
+//=======================================================================
+//function : Dump
+//purpose  : 
+//=======================================================================
+Standard_OStream& TDataStd_Mesh::Dump (Standard_OStream& anOS) const
+{  
+  anOS << "Mesh";
+  //TODO: Make a good dump.
+  return anOS;
+}
diff --git a/src/TDataStd/TDataStd_Mesh.hxx b/src/TDataStd/TDataStd_Mesh.hxx
new file mode 100644 (file)
index 0000000..d268106
--- /dev/null
@@ -0,0 +1,218 @@
+// Created on: 2015-12-10
+// 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 _TDataStd_Mesh_HeaderFile
+#define _TDataStd_Mesh_HeaderFile
+
+#include <Standard.hxx>
+#include <Standard_Type.hxx>
+
+#include <Poly_Mesh.hxx>
+#include <TDF_Attribute.hxx>
+#include <Standard_Boolean.hxx>
+#include <Standard_Integer.hxx>
+#include <Standard_OStream.hxx>
+class Standard_GUID;
+class TDF_Label;
+class TDF_Attribute;
+class TDF_RelocationTable;
+
+class TDataStd_Mesh;
+DEFINE_STANDARD_HANDLE(TDataStd_Mesh, TDF_Attribute)
+
+//! An Ocaf attribute containing a mesh (Poly_Mesh).
+//! It duplicates all methods from Poly_Mesh (and Poly_Triangulation).
+//! It is highly recommended to modify the mesh through the methods of this attribute,
+//! but not directly via the underlying Poly_Mesh object.
+//! In this case Undo/Redo will work fine and robust.
+class TDataStd_Mesh : public TDF_Attribute
+{
+public:
+  
+  //! Static methods
+  //  ==============
+
+  //! Returns the ID of the mesh attribute.
+  Standard_EXPORT static const Standard_GUID& GetID();
+  
+  //! Finds or creates a mesh attribute.
+  Standard_EXPORT static Handle(TDataStd_Mesh) Set(const TDF_Label& label);
+
+  //! Finds or creates a mesh attribute.
+  //! Initializes the attribute by a mesh (Poly_Mesh) object.
+  //! If the mesh consists of only triangles,
+  //! you may put Poly_Triangulation object as a 2nd parameter of this method.
+  Standard_EXPORT static Handle(TDataStd_Mesh) Set(const TDF_Label& label, const Handle(Poly_Mesh)& mesh);
+  
+  //! Object methods
+  //  ==============
+
+  //! A constructor.
+  //! Don't use it directly, 
+  //! use please the static method Set(),
+  //! which returns the attribute attached to a label.
+  Standard_EXPORT TDataStd_Mesh();
+  
+  //! Sets the mesh.
+  //! If the mesh consists of only triangles,
+  //! you may put Poly_Triangulation object.
+  Standard_EXPORT void Set(const Handle(Poly_Mesh)& mesh);
+
+  //! Returns the underlying mesh.
+  Standard_EXPORT const Handle(Poly_Mesh)& Get() const;
+
+
+  //! Poly_Mesh methods
+  //  =================
+
+  //! The methods are "covered" by this attribute to prevent direct modification of the mesh.
+  //! There is no performance problem to call Poly_Mesh method through this attribute.
+  //! The most of the methods are considered as "inline" by the compiler in release mode.
+
+  //! Returns the deflection of this triangulation.
+  Standard_EXPORT Standard_Real Deflection() const;
+
+  //! Sets the deflection of this triangulation to theDeflection.
+  //! See more on deflection in Polygon2D
+  Standard_EXPORT void Deflection (const Standard_Real theDeflection);
+
+  //! Deallocates the UV nodes.
+  Standard_EXPORT void RemoveUVNodes();
+
+  //! @return the number of nodes for this triangulation.
+  Standard_EXPORT Standard_Integer NbNodes() const;
+
+  //! @return the number of triangles for this triangulation.
+  Standard_EXPORT Standard_Integer NbTriangles() const;
+
+  //! @return Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
+  Standard_EXPORT Standard_Boolean HasUVNodes() const;
+
+  //! Adds Node to the triangulation. If triangulation has UVNodes or Normals
+  //! they will be expanded and set to zero values to match the new number of nodes.
+  //! @return index of the added Node.
+  Standard_EXPORT Standard_Integer AddNode (const gp_Pnt& theNode);
+
+  //! @return 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;
+
+  //! The method differs from Poly_Mesh!
+  //! Sets a node at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+  Standard_EXPORT void SetNode (const Standard_Integer theIndex, const gp_Pnt& theNode);
+
+  //! @return UVNode at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+  Standard_EXPORT const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const;
+
+  //! The method differs from Poly_Mesh!
+  //! Sets a UVNode at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
+  Standard_EXPORT void SetUVNode (const Standard_Integer theIndex, const gp_Pnt2d& theUVNode);
+
+  //! Adds triangle to the triangulation.
+  //! @return index of the added triangle.
+  Standard_EXPORT Standard_Integer AddTriangle (const Poly_Triangle& theTriangle);
+
+  //! @return triangle at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
+  Standard_EXPORT const Poly_Triangle& Triangle (const Standard_Integer theIndex) const;
+
+  //! The method differs from Poly_Mesh!
+  //! Sets a triangle at the given index.
+  //! 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);
+
+  //! 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.
+  //! Raises Standard_OutOfRange exception.
+  Standard_EXPORT void SetNormal (const Standard_Integer theIndex,
+                                  const gp_Dir&          theNormal);
+
+  //! Returns Standard_True if nodal normals are defined.
+  Standard_EXPORT Standard_Boolean HasNormals() const;
+
+  //! @return normal at the given index.
+  //! Raises Standard_OutOfRange exception.
+  Standard_EXPORT const gp_Dir Normal (const Standard_Integer theIndex) const;
+
+  //! Adds element to the mesh.
+  //! @param theN1 index of the first node.
+  //! @param theN2 index of the second node.
+  //! @param theN3 index of the third node.
+  //! @return index of the added element.
+  Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1,
+                                               const Standard_Integer theN2,
+                                               const Standard_Integer theN3);
+
+  //! Adds element to the mesh.
+  //! @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.
+  //! @return index of the added element.
+  Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1,
+                                               const Standard_Integer theN2,
+                                               const Standard_Integer theN3,
+                                               const Standard_Integer theN4);
+
+  //! @return the number of elements for this mesh.
+  Standard_EXPORT Standard_Integer NbElements() const;
+
+  //! @return the number of quads for this mesh.
+  Standard_EXPORT Standard_Integer NbQuads() const;
+
+  //! @return element at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
+  Standard_EXPORT const Poly_Element& Element (const Standard_Integer theIndex) const;
+
+  //! @return nodes of the element at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
+  Standard_EXPORT void Element (const Standard_Integer theIndex,
+                                Standard_Integer& theN1,
+                                Standard_Integer& theN2,
+                                Standard_Integer& theN3,
+                                Standard_Integer& theN4) const;
+
+  //! Sets an element at the given index.
+  //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements.
+  Standard_EXPORT void SetElement (const Standard_Integer theIndex, const Poly_Element& theElement);
+
+
+  //! Inherited attribute methods
+  //  ===========================
+
+  Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
+  
+  Standard_EXPORT void Restore (const Handle(TDF_Attribute)& With) Standard_OVERRIDE;
+  
+  Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
+  
+  Standard_EXPORT void Paste (const Handle(TDF_Attribute)& Into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
+  
+  Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& anOS) const Standard_OVERRIDE;
+
+  DEFINE_STANDARD_RTTI_INLINE(TDataStd_Mesh,TDF_Attribute)
+
+private:
+
+  Handle(Poly_Mesh) myMesh;
+};
+
+#endif // _TDataStd_Mesh_HeaderFile
index 590b3c0512461b9d1ae58c19bb46e5cfe46a204c..02949339084a906151de96d54e00603c7ffac832 100644 (file)
@@ -1,2 +1,3 @@
 TKCDF
 TKernel
+TKMath
index 1f4bc90e062a4ff4b1c6537deffa1751a052d861..44abe60c02949f0c3247de2b1936f9dff5a1acbb 100755 (executable)
@@ -2,3 +2,4 @@ TKCDF
 TKernel
 TKMath
 TKLCAF
+TKBRep
index 1cad752d8a02d70a7f8acd7ba4648a4cdae94466..ba94e834f16592ad7fd7f6c026ba8134bfff6fd1 100644 (file)
@@ -3009,14 +3009,12 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
   }
 
   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 ){
       x[0] =  mCenter[0];
       x[1] =  mCenter[1];
       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
@@ -3024,7 +3022,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
       x[0] =  mCenter[0];
       x[1] =  mCenter[1];
       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;
@@ -3039,7 +3037,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
         x[0] = n[0] +  mCenter[0];
         x[1] = n[1] +  mCenter[1];
         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++;
       }
     }
@@ -3051,7 +3049,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
         pts[0] = phiResolution*i + numPoles;
         pts[1] = (phiResolution*(i+1) % base) + numPoles;
         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++;
       }
     }
@@ -3062,7 +3060,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
         pts[0] = phiResolution*i + numOffset;
         pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
         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++;
       }
     }
@@ -3074,11 +3072,11 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
         pts[0] = phiResolution*i + j + numPoles;
         pts[1] = pts[0] + 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++;
         pts[1] = pts[2];
         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++;
       }
     }
@@ -3091,12 +3089,12 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
   Standard_Real Tol = Precision::Confusion();
 
   gp_Dir Nor;
-  for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
+  for (i = 1; i <= polyTriangulation->NbNodes(); i++) {
       gp_XYZ eqPlan(0, 0, 0);
       for ( pc->Initialize(i); pc->More(); pc->Next()) {
-        pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
-        gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
-        gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
+        polyTriangulation->Triangle (pc->Value()).Get(index[0], index[1], index[2]);
+        gp_XYZ v1(polyTriangulation->Node (index[1]).Coord() - polyTriangulation->Node (index[0]).Coord());
+        gp_XYZ v2(polyTriangulation->Node (index[2]).Coord() - polyTriangulation->Node (index[1]).Coord());
         gp_XYZ vv = v1^v2;
         Standard_Real mod = vv.Modulus();
         if(mod < Tol) continue;
@@ -3109,11 +3107,11 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
         Nor = gp_Dir(eqPlan);
       else
         Nor = gp_Dir(0., 0., 1.);
-      
-      Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
-      Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
-      Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
-      Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
+
+      Standard_Integer j = (i - 1) * 3;
+      Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
+      Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
+      Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
   }
 
   delete pc;
@@ -3162,8 +3160,8 @@ static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const c
     = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
                                                   aResolution,
                                                   aRadius));
-  Standard_Integer aNumberPoints    = aShape->GetTriangulation()->Nodes().Length();
-  Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
+  Standard_Integer aNumberPoints    = aShape->GetTriangulation()->NbNodes();
+  Standard_Integer aNumberTriangles = aShape->GetTriangulation()->NbTriangles();
 
   // stupid initialization of Green color in RGBA space as integer
   // probably wrong for big-endian CPUs
@@ -6125,20 +6123,19 @@ static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
         continue;
       }
 
-      const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
       const gp_Trsf&            aTrsf  = aLocation.Transformation();
 
       // extract normals from nodes
-      TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
+      TColgp_Array1OfDir aNormals (1, hasNormals ? aTriangulation->NbNodes() : 1);
       if (hasNormals)
       {
         Poly_Connect aPolyConnect (aTriangulation);
         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())
         {
           aPoint.Transform (aTrsf);
index fcfe879fff7026ba9829d4450f579ccc5f46edde..90bb409bb76872c858bd9e4dd2c5d75462505834 100644 (file)
@@ -85,22 +85,18 @@ void VrmlConverter_ShadedShape::Add( Standard_OStream& anOStream,
       // number of triangles:
     if (T.IsNull()) continue; //smh 
       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
     // of the triangle.
     for (nt = 1; nt <= nnn; nt++) {
       if (F.Orientation() == TopAbs_REVERSED) 
-       triangles(nt).Get(n1,n3,n2);
+       T->Triangle (nt).Get(n1,n3,n2);
       else 
-       triangles(nt).Get(n1,n2,n3);
+       T->Triangle (nt).Get(n1,n2,n3);
       
-      const gp_Pnt& P1 = Nodes(n1);
-      const gp_Pnt& P2 = Nodes(n2);
-      const gp_Pnt& P3 = Nodes(n3);
+      const gp_Pnt& P1 = T->Node (n1);
+      const gp_Pnt& P2 = T->Node (n2);
+      const gp_Pnt& P3 = T->Node (n3);
       // controlling whether the triangle correct from a 3d point of 
       // view: (the triangle may exist in the UV space but the
       // in the 3d space a dimension is null for example)
@@ -161,13 +157,12 @@ void VrmlConverter_ShadedShape::Add( Standard_OStream& anOStream,
        // 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
        
-       const TColgp_Array1OfPnt& Nodes = T->Nodes();
-       TColgp_Array1OfDir NORMAL(Nodes.Lower(), Nodes.Upper());
+       TColgp_Array1OfDir NORMAL(1, T->NbNodes());
 
          decal = nnv-1;
        
-       for (j= Nodes.Lower(); j<= Nodes.Upper(); j++) {
-         p = Nodes(j).Transformed(theLocation.Transformation());
+       for (j= 1; j<= T->NbNodes(); j++) {
+         p = T->Node (j).Transformed(theLocation.Transformation());
 
           V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z());
           HAV1->SetValue(nnv,V);
@@ -186,16 +181,15 @@ void VrmlConverter_ShadedShape::Add( Standard_OStream& anOStream,
        // 2 -   Building HAI1 - array of indexes of all triangles and
        //        HAI3 - array of indexes of all normales  for Vrml_IndexedFaceSet
         nbTriangles = T->NbTriangles();
-       const Poly_Array1OfTriangle& triangles = T->Triangles();        
         for (i = 1; i <= nbTriangles; i++) {
           pc.Triangles(i,t[0],t[1],t[2]);
           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 
-            triangles(i).Get(n[0],n[1],n[2]);
-          const gp_Pnt& P1 = Nodes(n[0]);
-          const gp_Pnt& P2 = Nodes(n[1]);
-          const gp_Pnt& P3 = Nodes(n[2]);
+            T->Triangle (i).Get(n[0],n[1],n[2]);
+          const gp_Pnt& P1 = T->Node (n[0]);
+          const gp_Pnt& P2 = T->Node (n[1]);
+          const gp_Pnt& P3 = T->Node (n[2]);
           gp_Vec V1(P1,P2);
           if (V1.SquareMagnitude() > 1.e-10) {
             gp_Vec V2(P2,P3);
@@ -390,10 +384,9 @@ void VrmlConverter_ShadedShape::ComputeNormal(const TopoDS_Face& aFace,
     CSLib_DerivativeStatus Status;
     CSLib_NormalStatus NStat;
     S.Initialize(aFace);
-    const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
-    for (i = UVNodes.Lower(); i <= UVNodes.Upper(); i++) {
-      U = UVNodes(i).X();
-      V = UVNodes(i).Y();
+    for (i = 1; i <= T->NbNodes(); i++) {
+      U = T->UVNode (i).X();
+      V = T->UVNode (i).Y();
       S.D1(U,V,P,D1U,D1V);
       CSLib::Normal(D1U,D1V,Precision::Angular(),Status,Nor(i));
       if (Status != CSLib_Done) {
@@ -404,16 +397,14 @@ void VrmlConverter_ShadedShape::ComputeNormal(const TopoDS_Face& aFace,
     }
   }
   else {
-    const TColgp_Array1OfPnt& Nodes = T->Nodes();
     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);
       for (pc.Initialize(i);  pc.More(); pc.Next()) {
-       triangles(pc.Value()).Get(n[0], n[1], n[2]);
-       gp_XYZ v1(Nodes(n[1]).Coord()-Nodes(n[0]).Coord());
-       gp_XYZ v2(Nodes(n[2]).Coord()-Nodes(n[1]).Coord());
+       T->Triangle (pc.Value()).Get(n[0], n[1], n[2]);
+       gp_XYZ v1(T->Node (n[1]).Coord() - T->Node (n[0]).Coord());
+       gp_XYZ v2(T->Node (n[2]).Coord() - T->Node (n[1]).Coord());
        eqPlan += (v1^v2).Normalized();
       }
       Nor(i) = gp_Dir(eqPlan);
index 0e5f8c4fe8358e58b1cacf2f05814c1d7f734343..5c48b9e9d7504461da1f4b91d5302de39f0aa776 100644 (file)
@@ -133,18 +133,16 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape ()
     myTShape = aFace;
 
     // Copy the triangulation vertices
-    TColgp_Array1OfPnt& aNodes = aTriangulation->ChangeNodes();
     NCollection_DataMap <int, int>::Iterator anIterN(mapNodeId);
     for (i = 1; anIterN.More(); anIterN.Next()) {
       const int aKey = anIterN.Key();
       const gp_XYZ& aNodePnt = arrNodes[aKey];
-      aNodes(i) = gp_Pnt (aNodePnt);
+      aTriangulation->ChangeNode (i) = gp_Pnt (aNodePnt);
       anIterN.ChangeValue() = i++;
     }
 
     // Copy the triangles. Only the triangle-type polygons are supported.
     // In this loop we also get rid of any possible degenerated triangles.
-    Poly_Array1OfTriangle& aTriangles = aTriangulation->ChangeTriangles();
     nTri = 0;
     for (i = 0; i < (int)myNbPolygons; i++) {
       const Standard_Integer * arrIndice;
@@ -153,9 +151,9 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape ()
             arrIndice[0] < nNodes &&
             arrIndice[1] < nNodes &&
             arrIndice[2] < nNodes)  // check to avoid previously skipped faces
-          aTriangles(++nTri).Set (mapNodeId(arrIndice[0]),
-                                  mapNodeId(arrIndice[1]),
-                                  mapNodeId(arrIndice[2]));
+            aTriangulation->ChangeTriangle (++nTri).Set (mapNodeId(arrIndice[0]),
+                                                         mapNodeId(arrIndice[1]),
+                                                         mapNodeId(arrIndice[2]));
     }
 
     // Normals should be defined; if they are not, compute them
index 0f29c5462beae05d9b2cf747492bc1dee971bd70..8472a0f9801b66a95e9f32948ea3b9d14f11abbc 100644 (file)
@@ -309,8 +309,6 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
   Standard_Integer i;
   const Standard_Integer nNodes         (theTri->NbNodes());
   const Standard_Integer nTriangles     (theTri->NbTriangles());
-  const TColgp_Array1OfPnt&    arrPolyNodes = theTri->Nodes();
-  const Poly_Array1OfTriangle& arrTriangles = theTri->Triangles();
 
   const Handle(VrmlData_IndexedFaceSet) aFaceSet =
     new VrmlData_IndexedFaceSet (myScene,
@@ -331,7 +329,7 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
     Standard_Integer * aPolygon = static_cast<Standard_Integer *>
       (anAlloc->Allocate (4*sizeof(Standard_Integer)));
     aPolygon[0] = 3;
-    arrTriangles(i+1).Get (aPolygon[1],aPolygon[2],aPolygon[3]);
+    theTri->Triangle (i+1).Get (aPolygon[1],aPolygon[2],aPolygon[3]);
     aPolygon[1]--;
     if (isReverse) {
       const Standard_Integer aTmp = aPolygon[2]-1;
@@ -351,7 +349,7 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
     gp_XYZ * arrNodes = static_cast <gp_XYZ *>
       (anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
     for  (i = 0; i < nNodes; i++)
-      arrNodes[i] = arrPolyNodes(i+1).XYZ() * myScale;
+      arrNodes[i] = theTri->Node (i+1).XYZ() * myScale;
 
     const Handle(VrmlData_Coordinate) aCoordNode =
       new VrmlData_Coordinate (myScene, 0L, nNodes, arrNodes);
@@ -363,13 +361,9 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
   if(theTri->HasNormals()) {
     gp_XYZ * arrVec = static_cast <gp_XYZ *>
       (anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
-    const TShort_Array1OfShortReal& Norm = theTri->Normals();
-    Standard_Integer j;
-    for  (i = 0, j = 1; i < nNodes; i++, j += 3) {
-      
-      gp_XYZ aNormal(Norm(j), Norm(j+1), Norm(j+2));
-      arrVec[i] = aNormal;
-
+    for (i = 0; i < nNodes; i++)
+    {
+      arrVec[i] = theTri->Normal (i + 1).XYZ();
     }
     const Handle(VrmlData_Normal) aNormalNode =
       new VrmlData_Normal (myScene, 0L, nNodes, arrVec);
@@ -390,14 +384,13 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
       Handle(TShort_HArray1OfShortReal) Normals = 
         new TShort_HArray1OfShortReal(1, nbNormVal);
 
-      const TColgp_Array1OfPnt2d& arrUV = theTri->UVNodes();
       gp_XYZ * arrVec = static_cast <gp_XYZ *>
         (anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
 
       // Compute the normal vectors
       Standard_Real Tol = Sqrt(aConf2);
       for  (i = 0; i < nNodes; i++) {
-        const gp_Pnt2d& aUV = arrUV(i+1);
+        const gp_Pnt2d& aUV = theTri->UVNode (i+1);
         
         gp_Dir aNormal;
         
@@ -407,9 +400,9 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet
 
           gp_XYZ eqPlan(0., 0., 0.);
           for (PC.Initialize(i+1);  PC.More(); PC.Next()) {
-            arrTriangles(PC.Value()).Get(n[0], n[1], n[2]);
-            gp_XYZ v1(arrPolyNodes(n[1]).Coord()-arrPolyNodes(n[0]).Coord());
-            gp_XYZ v2(arrPolyNodes(n[2]).Coord()-arrPolyNodes(n[1]).Coord());
+            theTri->Triangle (PC.Value()).Get(n[0], n[1], n[2]);
+            gp_XYZ v1(theTri->Node (n[1]).Coord() - theTri->Node (n[0]).Coord());
+            gp_XYZ v2(theTri->Node (n[2]).Coord() - theTri->Node (n[1]).Coord());
             gp_XYZ vv = v1^v2;
 
             Standard_Real mod = vv.Modulus();
index 64c818cea69dc6fbb404114f8dc892abbe875dcb..92362437598771d2930aa0c5aa6a94fe3f749a93 100644 (file)
@@ -146,24 +146,20 @@ static Standard_Real CalculVolume(const TopoDS_Shape& So,
          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++)
        {
          
-         Poly_Triangle trian = tri.Value(i);
+         Poly_Triangle trian = facing->Triangle (i);
          Standard_Integer index1,index2,index3;//M,N;
          if( F.Orientation() == TopAbs_REVERSED )
            trian.Get(index1,index3,index2);
          else
            trian.Get(index1,index2,index3);
-         curVolume = TetraVol(aRefPoint, tab.Value(index1),
-                              tab.Value(index2), tab.Value(index3));
+         curVolume = TetraVol(aRefPoint, facing->Node (index1),
+                              facing->Node (index2), facing->Node (index3));
          myVolume += curVolume;
-         curCentroid = TetraCen(aRefPoint, tab.Value(index1),
-                                tab.Value(index2), tab.Value(index3));
+         curCentroid = TetraCen(aRefPoint, facing->Node (index1),
+                                facing->Node (index2), facing->Node (index3));
          
          localCentroid = localCentroid + curCentroid*curVolume;
        }
index 370f797a4da320fbee0f54b0cca35c554b695f7f..b2bf55e06d58f0181d5d555e5debf675b53a732b 100644 (file)
@@ -26,6 +26,8 @@ XmlMDataStd_IntegerListDriver.cxx
 XmlMDataStd_IntegerListDriver.hxx
 XmlMDataStd_IntPackedMapDriver.cxx
 XmlMDataStd_IntPackedMapDriver.hxx
+XmlMDataStd_MeshDriver.cxx
+XmlMDataStd_MeshDriver.hxx
 XmlMDataStd_NamedDataDriver.cxx
 XmlMDataStd_NamedDataDriver.hxx
 XmlMDataStd_NameDriver.cxx
index 8a10e98f0b52b93aebc8fca3968a8c1fc4f663ae..0bfd088e3e298150bd14c7b2dfe6976969a5d0a1 100644 (file)
@@ -43,6 +43,7 @@
 #include <XmlMDataStd_TreeNodeDriver.hxx>
 #include <XmlMDataStd_UAttributeDriver.hxx>
 #include <XmlMDataStd_VariableDriver.hxx>
+#include <XmlMDataStd_MeshDriver.hxx>
 #include <XmlMDF_ADriverTable.hxx>
 
 static Standard_Integer myDocumentVersion = -1;
@@ -80,6 +81,7 @@ void XmlMDataStd::AddDrivers (const Handle(XmlMDF_ADriverTable)& aDriverTable,
   aDriverTable-> AddDriver (new XmlMDataStd_NamedDataDriver     (anMsgDrv));
   aDriverTable-> AddDriver (new XmlMDataStd_AsciiStringDriver   (anMsgDrv));
   aDriverTable-> AddDriver (new XmlMDataStd_IntPackedMapDriver  (anMsgDrv));
+  aDriverTable-> AddDriver (new XmlMDataStd_MeshDriver          (anMsgDrv));
 }
 
 //=======================================================================
diff --git a/src/XmlMDataStd/XmlMDataStd_MeshDriver.cxx b/src/XmlMDataStd/XmlMDataStd_MeshDriver.cxx
new file mode 100644 (file)
index 0000000..eefb03a
--- /dev/null
@@ -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 <XmlMDataStd_MeshDriver.hxx>
+#include <CDM_MessageDriver.hxx>
+#include <NCollection_LocalArray.hxx>
+#include <Standard_Type.hxx>
+#include <TDF_Attribute.hxx>
+#include <XmlObjMgt.hxx>
+#include <XmlObjMgt_Persistent.hxx>
+#include <TDataStd_Mesh.hxx>
+#include <LDOM_OSStream.hxx>
+#include <BRepTools_ShapeSet.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_MeshDriver,XmlMDF_ADriver)
+IMPLEMENT_DOMSTRING (MeshString, "mesh")
+IMPLEMENT_DOMSTRING (NullString, "null")
+IMPLEMENT_DOMSTRING (ExistString, "exists")
+
+//=======================================================================
+//function : XmlMDataStd_MeshDriver
+//purpose  : Constructor
+//=======================================================================
+XmlMDataStd_MeshDriver::XmlMDataStd_MeshDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
+     : XmlMDF_ADriver (theMsgDriver, NULL)
+{
+
+}
+
+//=======================================================================
+//function : NewEmpty
+//purpose  : 
+//=======================================================================
+Handle(TDF_Attribute) XmlMDataStd_MeshDriver::NewEmpty() const
+{
+  return new TDataStd_Mesh();
+}
+
+//=======================================================================
+//function : Paste
+//purpose  : persistent -> transient (retrieve)
+//=======================================================================
+Standard_Boolean XmlMDataStd_MeshDriver::Paste(const XmlObjMgt_Persistent&  theSource,
+                                               const Handle(TDF_Attribute)& theTarget,
+                                               XmlObjMgt_RRelocationTable&  ) const
+{
+  const XmlObjMgt_Element& element = theSource;
+  Handle(TDataStd_Mesh) mesh = Handle(TDataStd_Mesh)::DownCast(theTarget);
+
+  // Read the FirstIndex; if the attribute is absent initialize to 1
+  XmlObjMgt_DOMString meshStatus = element.getAttribute(::MeshString());
+  if (meshStatus == NULL ||
+      meshStatus.Type() != LDOMBasicString::LDOM_AsciiDoc ||
+      strcmp(meshStatus.GetString(), ::ExistString().GetString())) 
+  {
+    // No mesh.
+    return Standard_True;
+  }
+
+  // Get mesh as a string.
+  const XmlObjMgt_DOMString& data = XmlObjMgt::GetStringValue(element);
+  std::stringstream stream(std::string(data.GetString()));
+
+  // Read the mesh.
+  BRepTools_ShapeSet shapeSet;
+  TColStd_IndexedMapOfTransient meshes;
+  shapeSet.ReadMeshes(stream, meshes);
+
+  // Set mesh.
+  if (!meshes.IsEmpty())
+  {
+    // We expect only one mesh.
+    Handle(Poly_Mesh) M = Handle(Poly_Mesh)::DownCast(meshes(1));
+    if (!M.IsNull())
+      mesh->Set(M);
+  }
+
+  return Standard_True;
+}
+
+//=======================================================================
+//function : Paste
+//purpose  : transient -> persistent (store)
+//=======================================================================
+void XmlMDataStd_MeshDriver::Paste(const Handle(TDF_Attribute)& theSource,
+                                   XmlObjMgt_Persistent&        theTarget,
+                                   XmlObjMgt_SRelocationTable&  ) const
+{
+  const Handle(TDataStd_Mesh) meshAttr = Handle(TDataStd_Mesh)::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)& mesh = meshAttr->Get();
+    Standard_Integer size = mesh->NbNodes();
+    size *= 3; // 3 coordinates for a node
+    size *= 8; // 8 characters are used to represent a coordinate (double) in XML
+    size += 4 * 5 * mesh->NbElements(); // space for elements (triangles and quadrangles)
+    size *= 2; // just in case :-)
+    if (!size)
+      size = 1;
+
+    // Allocate a string stream.
+    LDOM_OSStream stream(size);
+
+    // Write the mesh.
+    BRepTools_ShapeSet shapeSet;
+    TColStd_IndexedMapOfTransient meshes;
+    meshes.Add(mesh);
+    shapeSet.WriteMeshes(stream, meshes, Standard_True/*compact*/);
+    stream<<ends;
+
+    Standard_Character* dump = (Standard_Character*)stream.str(); // copying! Don't forget to delete it.
+    XmlObjMgt::SetStringValue(theTarget, dump, Standard_True);
+    delete[] dump;
+  }
+}
diff --git a/src/XmlMDataStd/XmlMDataStd_MeshDriver.hxx b/src/XmlMDataStd/XmlMDataStd_MeshDriver.hxx
new file mode 100644 (file)
index 0000000..4cdc181
--- /dev/null
@@ -0,0 +1,49 @@
+// 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 _XmlMDataStd_MeshDriver_HeaderFile
+#define _XmlMDataStd_MeshDriver_HeaderFile
+
+#include <Standard.hxx>
+#include <Standard_Type.hxx>
+
+#include <XmlMDF_ADriver.hxx>
+#include <Standard_Boolean.hxx>
+#include <XmlObjMgt_RRelocationTable.hxx>
+#include <XmlObjMgt_SRelocationTable.hxx>
+class CDM_MessageDriver;
+class TDF_Attribute;
+class XmlObjMgt_Persistent;
+
+DEFINE_STANDARD_HANDLE(XmlMDataStd_MeshDriver, XmlMDF_ADriver)
+
+//! TDataStd_Mesh attribute XML Driver.
+class XmlMDataStd_MeshDriver : public XmlMDF_ADriver
+{
+
+public:
+  
+  Standard_EXPORT XmlMDataStd_MeshDriver(const Handle(CDM_MessageDriver)& theMessageDriver);
+  
+  Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
+  
+  Standard_EXPORT Standard_Boolean Paste (const XmlObjMgt_Persistent& Source, const Handle(TDF_Attribute)& Target, XmlObjMgt_RRelocationTable& RelocTable) const Standard_OVERRIDE;
+  
+  Standard_EXPORT void Paste (const Handle(TDF_Attribute)& Source, XmlObjMgt_Persistent& Target, XmlObjMgt_SRelocationTable& RelocTable) const Standard_OVERRIDE;
+
+  DEFINE_STANDARD_RTTIEXT(XmlMDataStd_MeshDriver,XmlMDF_ADriver)
+};
+
+#endif // _XmlMDataStd_MeshDriver_HeaderFile
diff --git a/tests/caf/basic/N1 b/tests/caf/basic/N1
new file mode 100644 (file)
index 0000000..03b327b
--- /dev/null
@@ -0,0 +1,41 @@
+#INTERFACE CAF
+# Basic attributes
+#
+# Testing attribute: TDataStd_Mesh
+#
+# Testing command:   SetMesh
+# Testing command:   DumpMesh
+#
+
+puts "caf001-N1"
+
+# Make a sphere and produce triangulation
+psphere s 100
+vdisplay s
+explode s f
+
+# Create a XML document
+NewDocument D XmlXCAF
+
+# Set mesh from the spherical face
+SetMesh D 0:1 s_1
+
+# Print the mesh data
+set dump1 [DumpMesh D 0:1]
+
+# Save document on disk.
+SaveAs D "test.xml"
+
+# Close and open the document again.
+Close D
+Open test.xml DD
+
+# Print mesh data
+set dump2 [DumpMesh DD 0:1]
+
+# Check data
+if { ${dump1}!=${dump2} } {
+       puts "TDataStd_Mesh(XML) attribute: Error"
+       return
+}
+puts "TDataStd_Mesh(XML) attribute: OK"
diff --git a/tests/caf/basic/N2 b/tests/caf/basic/N2
new file mode 100644 (file)
index 0000000..e2e91fa
--- /dev/null
@@ -0,0 +1,42 @@
+#INTERFACE CAF
+# Basic attributes
+#
+# Testing attribute: TDataStd_Mesh
+#
+# Testing command:   SetMesh
+# Testing command:   DumpMesh
+# Test           :   Binary file format
+#
+
+puts "caf001-N2"
+
+# Make a sphere and produce triangulation
+psphere s 100
+vdisplay s
+explode s f
+
+# Create a binary document
+NewDocument D BinXCAF
+
+# Set mesh from the spherical face
+SetMesh D 0:1 s_1
+
+# Print the mesh data
+set dump1 [DumpMesh D 0:1]
+
+# Save document on disk.
+SaveAs D "test.xbf"
+
+# Close and open the document again.
+Close D
+Open test.xbf DD
+
+# Print mesh data
+set dump2 [DumpMesh DD 0:1]
+
+# Check data
+if { ${dump1}!=${dump2} } {
+       puts "TDataStd_Mesh(BIN) attribute: Error"
+       return
+}
+puts "TDataStd_Mesh(BIN) attribute: OK"