]> OCCT Git - occt-copy.git/commitdiff
0026458: BRepBuilderAPI_Copy does not copy mesh structure
authorazv <azv@opencascade.com>
Tue, 21 Jul 2015 06:51:19 +0000 (09:51 +0300)
committerssv <ssv@opencascade.com>
Fri, 14 Aug 2015 13:53:42 +0000 (16:53 +0300)
* The possibility to copy mesh is implemented. It may be enabled by copyMesh key, by default it is disabled.
* Poly_Triangulation::Copy() method is added
* Poly_Mesh::Copy() method is added

Conflicts:
src/Poly/Poly_Triangulation.cxx
src/Poly/Poly_Triangulation.hxx

src/BRepBuilderAPI/BRepBuilderAPI_Copy.cdl
src/BRepBuilderAPI/BRepBuilderAPI_Copy.cxx
src/BRepTest/BRepTest_BasicCommands.cxx
src/BRepTools/BRepTools.cdl
src/BRepTools/BRepTools_Modification.cdl
src/BRepTools/BRepTools_Modification.cxx
src/BRepTools/BRepTools_Modifier.cxx
src/Poly/Poly_Mesh.cxx
src/Poly/Poly_Mesh.hxx
src/Poly/Poly_Triangulation.cxx
src/Poly/Poly_Triangulation.hxx

index 2482709efe40be28034d936fa14d4a33501ccd3c..840e4439cad68b3c319c8714cec3a8c9aa9a3e6f 100644 (file)
@@ -37,7 +37,7 @@ is
                returns Copy from BRepBuilderAPI;
 
 
-    Create(S: Shape from TopoDS; copyGeom: Boolean = Standard_True)
+    Create(S: Shape from TopoDS; copyGeom: Boolean = Standard_True; copyMesh: Boolean = Standard_False)
        ---Purpose: Constructs a copy framework and copies the shape S.
        -- Use the function Shape to access the result.
        -- If copyGeom is False, only topological objects will be copied, while 
@@ -47,7 +47,7 @@ is
        returns Copy from BRepBuilderAPI;
 
 
-    Perform(me: in out; S: Shape from TopoDS; copyGeom: Boolean = Standard_True)
+    Perform(me: in out; S: Shape from TopoDS; copyGeom: Boolean = Standard_True; copyMesh: Boolean = Standard_False)
        ---Purpose: Copies the shape S.
        -- Use the function Shape to access the result.
        -- If copyGeom is False, only topological objects will be copied, while 
index ea8862c406abf7a8c49b1efc1f0e6f728dce75f0..99f8d3b998a8ef98a970ffdf28c070230a400aac 100644 (file)
 #include <BRep_Tool.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <gp_Pnt.hxx>
+#include <Poly_Triangulation.hxx>
 
 //! Tool class implementing necessary functionality for copying geometry
 class BRepBuilderAPI_Copy_Modification : public BRepTools_Modification 
 {
 public:
-  BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom)
-    : myCopyGeom(copyGeom)
+  BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom,
+                                    const Standard_Boolean copyMesh = Standard_False)
+    : myCopyGeom(copyGeom),
+      myCopyMesh(copyMesh)
   {
   }
 
@@ -49,6 +52,22 @@ public:
     return Standard_True;
   }
 
+  //! Returns true to indicate the need to copy triangulation;
+  //! copies it if required
+  Standard_Boolean NewTriangulation(const TopoDS_Face& F, Handle(Poly_Triangulation)& T)
+  {
+    TopLoc_Location L;
+    T = BRep_Tool::Triangulation(F, L);
+
+    if (!T.IsNull() && myCopyMesh)
+    {
+      T = T->Copy();
+      return Standard_True;
+    }
+
+    return Standard_False;
+  }
+
   //! Returns true to indicate the need to copy edge;
   //! copies curves if requested
   Standard_Boolean NewCurve (const TopoDS_Edge& E, Handle(Geom_Curve)& C,
@@ -117,6 +136,7 @@ public:
 
 private: 
   Standard_Boolean myCopyGeom;
+  Standard_Boolean myCopyMesh;
 };
 
 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
@@ -140,9 +160,9 @@ BRepBuilderAPI_Copy::BRepBuilderAPI_Copy ()
 //purpose  : 
 //=======================================================================
 
-BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom)
+BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh)
 {
-  myModification = new BRepBuilderAPI_Copy_Modification(copyGeom);
+  myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh);
   DoModif(S);
 }
 
@@ -152,9 +172,9 @@ BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_B
 //purpose  : 
 //=======================================================================
 
-void BRepBuilderAPI_Copy::Perform(const TopoDS_Shape& S, const Standard_Boolean copyGeom)
+void BRepBuilderAPI_Copy::Perform(const TopoDS_Shape& S, const Standard_Boolean copyGeom, const Standard_Boolean copyMesh)
 {
-  myModification = new BRepBuilderAPI_Copy_Modification(copyGeom);
+  myModification = new BRepBuilderAPI_Copy_Modification(copyGeom, copyMesh);
   NotDone(); // on force la copie si on vient deja d`en faire une
   DoModif(S);
 }
index 6b45689c47a6836bbd20c29221fc4763ae452401..ee4d815c13b254b037db22f66a0586aa5d792f4b 100644 (file)
@@ -211,24 +211,39 @@ static Standard_Integer deform(Draw_Interpretor& di,Standard_Integer n,const cha
 static Standard_Integer tcopy(Draw_Interpretor& di,Standard_Integer n,const char** a)
 {
   Standard_Boolean copyGeom = Standard_True;
+  Standard_Boolean copyMesh = Standard_False;
   Standard_Integer iFirst = 1; // index of first shape argument
 
-  if (n > 1 && a[1][0] == '-' && a[1][1] == 'n' )
+  if (n > 1)
   {
-    copyGeom = Standard_False;
-    iFirst = 2;
+    for (Standard_Integer i = 1; i <= 2; i++)
+    {
+      if (a[i][0] != '-')
+        break;
+      if (a[i][1] == 'n')
+      {
+        copyGeom = Standard_False;
+        iFirst++;
+      }
+      else if (a[i][1] == 'm')
+      {
+        copyMesh = Standard_True;
+        iFirst++;
+      }
+    }
   }
 
   if (n < 3 || (n - iFirst) % 2) {
-    cout << "Use: " << a[0] << " [-n(ogeom)] shape1 copy1 [shape2 copy2 [...]]" << endl;
-    cout << "Option -n forbids copying of geometry (it will be shared)" << endl; 
+    cout << "Use: " << a[0] << " [-n(ogeom)] [-m(esh)] shape1 copy1 [shape2 copy2 [...]]" << endl;
+    cout << "Option -n forbids copying of geometry (it will be shared)" << endl;
+    cout << "Option -m forces copying of mesh (disabled by default)" << endl;
     return 1;
   }
 
   BRepBuilderAPI_Copy cop;
   Standard_Integer nbPairs = (n - iFirst) / 2;
   for (Standard_Integer i=0; i < nbPairs; i++) {
-    cop.Perform(DBRep::Get(a[i+iFirst]), copyGeom);
+    cop.Perform(DBRep::Get(a[i+iFirst]), copyGeom, copyMesh);
     DBRep::Set(a[i+iFirst+1],cop.Shape());
     di << a[i+iFirst+1] << " ";
   }
@@ -869,7 +884,7 @@ void  BRepTest::BasicCommands(Draw_Interpretor& theCommands)
                  transform,g);
 
   theCommands.Add("tcopy",
-                 "tcopy [-n(ogeom)] name1 result1 [name2 result2 ...]",
+                 "tcopy [-n(ogeom)] [-m(esh)] name1 result1 [name2 result2 ...]",
                  __FILE__,
                  tcopy,g);
 
index d35496aef9d3eaafaccd3e555f578ac9a91198ff..ea4282a4e17227632aef36f65b75ac0712f8df4c 100644 (file)
@@ -70,7 +70,8 @@ uses
     TColStd,
     TCollection,
     MMgt,
-    Message
+    Message,
+    Poly
 
 is
 
index cbc2a4f5d8d34a96186fd48305904da6b5b998a4..e123c242a0567e75ced4390950c44aaa520fa4fc 100644 (file)
@@ -31,7 +31,9 @@ uses Face     from TopoDS,
      Surface  from Geom,
      Curve    from Geom,
      Curve    from Geom2d,
-     Pnt      from gp
+     Pnt      from gp,
+
+     Triangulation from Poly
 
 
 is
@@ -60,6 +62,16 @@ is
        returns Boolean from Standard
        is deferred;
 
+
+    NewTriangulation(me: mutable; F :     Face          from TopoDS; 
+                                  T : out Triangulation from Poly)
+    ---Purpose: Returns true if the face has been modified according to changed triangulation.
+    -- If the face has been modified:
+    -- - T is a new triangulation on the face
+        returns Boolean from Standard
+        is virtual;
+
+
        
     NewCurve(me: mutable; E  :     Edge     from TopoDS;
                           C  : out Curve    from Geom;
index 641a93e6fb293144da96b31a413535f2b8c62fda..06b916e8678a59fd4cf408c7c1d30b5f09004948 100644 (file)
@@ -16,4 +16,7 @@
 
 #include <BRepTools_Modification.ixx>
 
-
+Standard_Boolean BRepTools_Modification::NewTriangulation(const TopoDS_Face&, Handle(Poly_Triangulation)&)
+{
+  return Standard_False;
+}
index 0b47f43dfb0fc63d96e3f2b5686f5c0e43ee883b..b32bf87d9a304bc0b56675eda850b4c0d1f7f8a2 100644 (file)
@@ -283,6 +283,20 @@ Standard_Boolean BRepTools_Modifier::Rebuild
        B.NaturalRestriction(TopoDS::Face(result),
                             BRep_Tool::NaturalRestriction(TopoDS::Face(S)));
       }
+
+      // update triangulation on the copied face
+      Handle(Poly_Triangulation) aTriangulation;
+      if (M->NewTriangulation(TopoDS::Face(S), aTriangulation))
+      {
+        if (rebuild) // the copied face already exists => update it
+          B.UpdateFace(TopoDS::Face(result), aTriangulation);
+        else
+        { // create new face with bare triangulation
+          B.MakeFace(TopoDS::Face(result), aTriangulation);
+          result.Location(S.Location());
+        }
+        rebuild = Standard_True;
+      }
     }
     break;
 
index d75f81408e5ec54272dd743db71fafceb8190e3f..7aace317d8d39db9477c5dc11075194f9a77f4f9 100644 (file)
@@ -47,6 +47,39 @@ Poly_Mesh::Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation)
   }
 }
 
+//=======================================================================
+//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  :
index c533a3ec39809c84bf8a085c93aa4fddc33457de..98a1db00a5cf77f849cec8e7e6e2c4ba62503613 100644 (file)
@@ -36,6 +36,9 @@ public:
   //! @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.
index 2c05c181572307fd7ac7eb8662ee674c278ed47a..70083bbf2278a0d8a19e0b902f2011f0a0fa85be 100644 (file)
@@ -99,6 +99,23 @@ Poly_Triangulation::Poly_Triangulation (const TColgp_Array1OfPnt&    theNodes,
   }
 }
 
+//=======================================================================
+//function : Copy
+//purpose  : 
+//=======================================================================
+
+Handle(Poly_Triangulation) Poly_Triangulation::Copy() const
+{
+  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  : 
index 62792be253d4b3d939972ed91e40f192ca74702c..688b00ebf3feb1ad2bc8a4950b10de235a946373 100644 (file)
@@ -35,6 +35,7 @@ class TColgp_Array1OfPnt;
 class Poly_Array1OfTriangle;
 class TColgp_Array1OfPnt2d;
 class TShort_Array1OfShortReal;
+class Handle_Poly_Triangulation;
 
 //! 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.
@@ -75,6 +76,9 @@ public:
                                       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);