1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0026458: BRepBuilderAPI_Copy does not copy mesh structure

* The possibility to copy mesh is implemented. It may be enabled by copyMesh flag, by default it is disabled.
* Poly_Triangulation::Copy() method is added.
* The mesh is copied if and only if copyMesh flag is true.
This commit is contained in:
azv 2015-07-20 14:23:56 +03:00 committed by bugmaster
parent 031d5ab77c
commit 55e738d2f3
8 changed files with 100 additions and 16 deletions

View File

@ -24,13 +24,16 @@
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx> #include <TopoDS_Vertex.hxx>
#include <Poly_Triangulation.hxx>
//! Tool class implementing necessary functionality for copying geometry //! Tool class implementing necessary functionality for copying geometry
class BRepBuilderAPI_Copy_Modification : public BRepTools_Modification class BRepBuilderAPI_Copy_Modification : public BRepTools_Modification
{ {
public: public:
BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom) BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom,
: myCopyGeom(copyGeom) const Standard_Boolean copyMesh = Standard_False)
: myCopyGeom(copyGeom),
myCopyMesh(copyMesh)
{ {
} }
@ -50,6 +53,23 @@ public:
return Standard_True; 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)
{
if (!myCopyMesh)
return Standard_False;
TopLoc_Location L;
T = BRep_Tool::Triangulation(F, L);
if (T.IsNull())
return Standard_False;
T = T->Copy();
return Standard_True;
}
//! Returns true to indicate the need to copy edge; //! Returns true to indicate the need to copy edge;
//! copies curves if requested //! copies curves if requested
Standard_Boolean NewCurve (const TopoDS_Edge& E, Handle(Geom_Curve)& C, Standard_Boolean NewCurve (const TopoDS_Edge& E, Handle(Geom_Curve)& C,
@ -118,6 +138,7 @@ public:
private: private:
Standard_Boolean myCopyGeom; Standard_Boolean myCopyGeom;
Standard_Boolean myCopyMesh;
}; };
DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification) DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification)
@ -139,9 +160,9 @@ BRepBuilderAPI_Copy::BRepBuilderAPI_Copy ()
//purpose : //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); DoModif(S);
} }
@ -151,9 +172,9 @@ BRepBuilderAPI_Copy::BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_B
//purpose : //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 NotDone(); // on force la copie si on vient deja d`en faire une
DoModif(S); DoModif(S);
} }

View File

@ -48,13 +48,13 @@ public:
//! geometry will be shared with original shape. //! geometry will be shared with original shape.
//! Note: the constructed framework can be reused to copy //! Note: the constructed framework can be reused to copy
//! other shapes: just specify them with the function Perform. //! other shapes: just specify them with the function Perform.
Standard_EXPORT BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom = Standard_True); Standard_EXPORT BRepBuilderAPI_Copy(const TopoDS_Shape& S, const Standard_Boolean copyGeom = Standard_True, const Standard_Boolean copyMesh = Standard_False);
//! Copies the shape S. //! Copies the shape S.
//! Use the function Shape to access the result. //! Use the function Shape to access the result.
//! If copyGeom is False, only topological objects will be copied, while //! If copyGeom is False, only topological objects will be copied, while
//! geometry will be shared with original shape. //! geometry will be shared with original shape.
Standard_EXPORT void Perform (const TopoDS_Shape& S, const Standard_Boolean copyGeom = Standard_True); Standard_EXPORT void Perform (const TopoDS_Shape& S, const Standard_Boolean copyGeom = Standard_True, const Standard_Boolean copyMesh = Standard_False);

View 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) static Standard_Integer tcopy(Draw_Interpretor& di,Standard_Integer n,const char** a)
{ {
Standard_Boolean copyGeom = Standard_True; Standard_Boolean copyGeom = Standard_True;
Standard_Boolean copyMesh = Standard_False;
Standard_Integer iFirst = 1; // index of first shape argument 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; for (Standard_Integer i = 1; i <= 2; i++)
iFirst = 2; {
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) { if (n < 3 || (n - iFirst) % 2) {
cout << "Use: " << a[0] << " [-n(ogeom)] shape1 copy1 [shape2 copy2 [...]]" << 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 -n forbids copying of geometry (it will be shared)" << endl;
cout << "Option -m forces copying of mesh (disabled by default)" << endl;
return 1; return 1;
} }
BRepBuilderAPI_Copy cop; BRepBuilderAPI_Copy cop;
Standard_Integer nbPairs = (n - iFirst) / 2; Standard_Integer nbPairs = (n - iFirst) / 2;
for (Standard_Integer i=0; i < nbPairs; i++) { 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()); DBRep::Set(a[i+iFirst+1],cop.Shape());
di << a[i+iFirst+1] << " "; di << a[i+iFirst+1] << " ";
} }
@ -870,7 +885,7 @@ void BRepTest::BasicCommands(Draw_Interpretor& theCommands)
transform,g); transform,g);
theCommands.Add("tcopy", theCommands.Add("tcopy",
"tcopy [-n(ogeom)] name1 result1 [name2 result2 ...]", "tcopy [-n(ogeom)] [-m(esh)] name1 result1 [name2 result2 ...]",
__FILE__, __FILE__,
tcopy,g); tcopy,g);

View File

@ -25,3 +25,9 @@
#include <TopoDS_Edge.hxx> #include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx> #include <TopoDS_Face.hxx>
#include <TopoDS_Vertex.hxx> #include <TopoDS_Vertex.hxx>
#include <Poly_Triangulation.hxx>
Standard_Boolean BRepTools_Modification::NewTriangulation(const TopoDS_Face&, Handle(Poly_Triangulation)&)
{
return Standard_False;
}

View File

@ -32,6 +32,7 @@ class Geom_Curve;
class TopoDS_Vertex; class TopoDS_Vertex;
class gp_Pnt; class gp_Pnt;
class Geom2d_Curve; class Geom2d_Curve;
class Poly_Triangulation;
class BRepTools_Modification; class BRepTools_Modification;
@ -59,7 +60,12 @@ public:
//! false, and the values of S, L, Tol, RevWires and //! false, and the values of S, L, Tol, RevWires and
//! RevFace are not significant. //! RevFace are not significant.
Standard_EXPORT virtual Standard_Boolean NewSurface (const TopoDS_Face& F, Handle(Geom_Surface)& S, TopLoc_Location& L, Standard_Real& Tol, Standard_Boolean& RevWires, Standard_Boolean& RevFace) = 0; Standard_EXPORT virtual Standard_Boolean NewSurface (const TopoDS_Face& F, Handle(Geom_Surface)& S, TopLoc_Location& L, Standard_Real& Tol, Standard_Boolean& RevWires, Standard_Boolean& RevFace) = 0;
//! 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
Standard_EXPORT virtual Standard_Boolean NewTriangulation(const TopoDS_Face& F, Handle(Poly_Triangulation)& T);
//! Returns true if the edge, E, has been modified. //! Returns true if the edge, E, has been modified.
//! If the edge has been modified: //! If the edge has been modified:
//! - C is the new geometry associated with the edge, //! - C is the new geometry associated with the edge,

View File

@ -286,6 +286,20 @@ Standard_Boolean BRepTools_Modifier::Rebuild
B.NaturalRestriction(TopoDS::Face(result), B.NaturalRestriction(TopoDS::Face(result),
BRep_Tool::NaturalRestriction(TopoDS::Face(S))); 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; break;

View File

@ -77,6 +77,25 @@ Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes,
myUVNodes->ChangeArray1() = UVNodes; myUVNodes->ChangeArray1() = UVNodes;
} }
//=======================================================================
//function : Copy
//purpose :
//=======================================================================
Handle(Poly_Triangulation) Poly_Triangulation::Copy()
{
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());
return aCopy;
}
//======================================================================= //=======================================================================
//function : Deflection //function : Deflection
//purpose : //purpose :

View File

@ -90,6 +90,9 @@ public:
//! constructed triangulation. //! constructed triangulation.
Standard_EXPORT Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, const TColgp_Array1OfPnt2d& UVNodes, const Poly_Array1OfTriangle& Triangles); Standard_EXPORT Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, const TColgp_Array1OfPnt2d& UVNodes, const Poly_Array1OfTriangle& Triangles);
//! Creates full copy of current triangulation
Standard_EXPORT virtual Handle(Poly_Triangulation) Copy();
//! Returns the deflection of this triangulation. //! Returns the deflection of this triangulation.
Standard_EXPORT Standard_Real Deflection() const; Standard_EXPORT Standard_Real Deflection() const;