1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0023987: 2D fillets

Added test cases in group bugs/modalg_5
Test cases were put to corresponding regular grid fillet2d
This commit is contained in:
vro
2013-08-22 13:04:16 +04:00
committed by bugmaster
parent 22774b6295
commit 8b7c5e4715
25 changed files with 3165 additions and 1 deletions

View File

@@ -34,8 +34,16 @@
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS.hxx>
#include <TopExp_Explorer.hxx>
#include <TopExp.hxx>
#include <TopoDS.hxx>
#include <ChFi2d_FilletAPI.hxx>
#include <ChFi2d_ChamferAPI.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_FindPlane.hxx>
#include <BRep_Builder.hxx>
//=======================================================================
//function : chfi2d
@@ -171,6 +179,258 @@ static Standard_Integer chfi2d(Draw_Interpretor& di, Standard_Integer n, const c
return 0;
}
//=======================================================================
//function : fillet2d
//purpose : A method to find a plane for 2 edges.
// : It may return a NULL object of the plane is not found
// : (the edge are located not in a plane).
//=======================================================================
static Handle(Geom_Plane) findPlane(const TopoDS_Shape& S)
{
Handle(Geom_Plane) plane;
BRepBuilderAPI_FindPlane planeFinder(S);
if (planeFinder.Found())
plane = planeFinder.Plane();
return plane;
}
static Handle(Geom_Plane) findPlane(const TopoDS_Shape& E1, const TopoDS_Shape& E2)
{
BRep_Builder B;
TopoDS_Compound C;
B.MakeCompound(C);
B.Add(C, E1);
B.Add(C, E2);
return findPlane(C);
}
//=======================================================================
//function : findCommonPoint
//purpose : Find a common (or the most close) point of two edges.
//=======================================================================
static gp_Pnt findCommonPoint(const TopoDS_Shape& E1, const TopoDS_Shape& E2)
{
TopoDS_Vertex v11, v12, v21, v22;
TopExp::Vertices(TopoDS::Edge(E1), v11, v12);
TopExp::Vertices(TopoDS::Edge(E2), v21, v22);
gp_Pnt p11 = BRep_Tool::Pnt(v11);
gp_Pnt p12 = BRep_Tool::Pnt(v12);
gp_Pnt p21 = BRep_Tool::Pnt(v21);
gp_Pnt p22 = BRep_Tool::Pnt(v22);
gp_Pnt common;
const double d1121 = p11.SquareDistance(p21);
const double d1122 = p11.SquareDistance(p22);
const double d1221 = p12.SquareDistance(p21);
const double d1222 = p12.SquareDistance(p22);
if (d1121 < d1122 && d1121 < d1221 && d1121 < d1222)
common = p11;
else if (d1122 < d1121 && d1122 < d1221 && d1122 < d1222)
common = p11;
else if (d1221 < d1121 && d1221 < d1122 && d1221 < d1222)
common = p12;
else if (d1222 < d1121 && d1222 < d1122 && d1222 < d1221)
common = p12;
return common;
}
static gp_Pnt findCommonPoint(const TopoDS_Shape& W)
{
// The common point for two edges inside a wire
// is a sharing vertex of two edges.
TopTools_MapOfShape vertices;
TopExp_Explorer expl(W, TopAbs_VERTEX);
for (; expl.More(); expl.Next())
{
if (!vertices.Add(expl.Current()))
{
return BRep_Tool::Pnt(TopoDS::Vertex(expl.Current()));
}
}
return gp::Origin(); // not found
}
//=======================================================================
//function : fillet2d
//purpose : Fillet 2d based on Newton method (recursive, iteration)
//usage : fillet2d result wire (or edge1 edge2) radius
//=======================================================================
static Standard_Integer fillet2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n != 4 && n != 5)
{
di << "Usage : fillet2d result wire (or edge1 edge2) radius";
return 1;
}
TopoDS_Shape E1, E2, W;
if (n == 5)
{
// Get the edges.
E1 = DBRep::Get(a[2], TopAbs_EDGE, Standard_True);
E2 = DBRep::Get(a[3], TopAbs_EDGE, Standard_True);
}
else
{
// Get the wire.
W = DBRep::Get(a[2], TopAbs_WIRE, Standard_True);
}
// Get the radius value.
const Standard_Real radius = Atof(n == 5 ? a[4] : a[3]);
// Find plane of the edges.
Handle(Geom_Plane) hPlane = n == 5 ? findPlane(E1, E2) : findPlane(W);
if (hPlane.IsNull())
{
di << "Error: the edges are located not in a plane.";
return 1;
}
// Algo.
ChFi2d_FilletAPI algo;
gp_Pln plane = hPlane->Pln();
if (n == 5)
{
const TopoDS_Edge& e1 = TopoDS::Edge(E1);
const TopoDS_Edge& e2 = TopoDS::Edge(E2);
algo.Init(e1, e2, plane);
}
else
{
const TopoDS_Wire& w = TopoDS::Wire(W);
algo.Init(w, plane);
}
Standard_Boolean status = algo.Perform(radius);
if (!status)
{
di << "Error: the algrithm failed.";
return 1;
}
// Find a common point of the edges.
gp_Pnt common = n == 5 ? findCommonPoint(E1, E2) : findCommonPoint(W);
// Get the number of solutions (usually it is equal to 1).
Standard_Integer nbSolutions = algo.NbResults(common);
if (!nbSolutions)
{
di << "Error: no solutions.";
return 1;
}
// Get the result for the "nearest" solution (near the common point).
TopoDS_Edge M1, M2; // modified E1 and E2
TopoDS_Edge fillet = algo.Result(common, M1, M2);
if (fillet.IsNull())
{
di << "Error: the algrithm produced no result.";
return 1;
}
// Set result for DRAW.
DBRep::Set(a[1], fillet);
// Update neighbour edges in DRAW.
if (n == 5)
{
DBRep::Set(a[2], M1);
DBRep::Set(a[3], M2);
}
else // recreate the wire using the fillet
{
BRepBuilderAPI_MakeWire mkWire(M1, fillet, M2);
if (mkWire.IsDone())
DBRep::Set(a[1], mkWire.Wire());
else
DBRep::Set(a[1], fillet);
}
return 0;
}
//=======================================================================
//function : chamfer2d
//purpose : Chamfer 2d.
//usage : chamfer2d result wire (or edge1 edge2) length1 length2
//=======================================================================
static Standard_Integer chamfer2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n != 5 && n != 6)
{
di << "Usage : chamfer2d result wire (or edge1 edge2) length1 length2";
return 1;
}
TopoDS_Shape W;
TopoDS_Shape E1, E2;
if (n == 6)
{
// Get the edges.
E1 = DBRep::Get(a[2], TopAbs_EDGE, Standard_True);
E2 = DBRep::Get(a[3], TopAbs_EDGE, Standard_True);
}
else
{
W = DBRep::Get(a[2], TopAbs_WIRE, Standard_True);
}
// Get the lengths.
const Standard_Real length1 = (n == 6) ? Atof(a[4]) : Atof(a[3]);
const Standard_Real length2 = (n == 6) ? Atof(a[5]) : Atof(a[4]);
// Algo.
ChFi2d_ChamferAPI algo;
if (n == 6)
{
const TopoDS_Edge& e1 = TopoDS::Edge(E1);
const TopoDS_Edge& e2 = TopoDS::Edge(E2);
algo.Init(e1, e2);
}
else
{
const TopoDS_Wire& w = TopoDS::Wire(W);
algo.Init(w);
}
// Prepare the chamfer.
algo.Perform();
// Get the result.
TopoDS_Edge M1, M2; // modified E1 and E2
TopoDS_Edge chamfer = algo.Result(M1, M2, length1, length2);
if (chamfer.IsNull())
{
di << "Error: the algrithm produced no result.";
return 1;
}
if (n == 6)
{
// Set result for DRAW.
DBRep::Set(a[1], chamfer);
// Update neighbour edges in DRAW.
DBRep::Set(a[2], M1);
DBRep::Set(a[3], M2);
}
else // recreate the wire using the chamfer
{
BRepBuilderAPI_MakeWire mkWire(M1, chamfer, M2);
if (mkWire.IsDone())
DBRep::Set(a[1], mkWire.Wire());
else
DBRep::Set(a[1], chamfer);
}
return 0;
}
//=======================================================================
//function : Fillet2DCommands
//purpose :
@@ -187,4 +447,6 @@ void BRepTest::Fillet2DCommands(Draw_Interpretor& theCommands)
const char* g = "TOPOLOGY Fillet2D construction commands";
theCommands.Add("chfi2d","chfi2d result face [edge1 edge2 (F radius/CDD d1 d2/CDA d ang) ....]",__FILE__,chfi2d,g);
theCommands.Add("fillet2d","fillet2d result wire (or edge1 edge2) radius",__FILE__,fillet2d,g);
theCommands.Add("chamfer2d","chamfer2d result wire (or edge1 edge2) length1 length2",__FILE__,chamfer2d,g);
}