# eryar

posts - 485, comments - 590, trackbacks - 0, articles - 0

## ModelingAlgorithmsFilletsandChamfers

### 一、倒圆FilletConstructor

#### 1． BRepFilletAPI_MakeFillet

l 首先，给定一个需要倒圆的形状；

l 最后，通过询问结果来执行倒圆操作。

Figure 1. Filleting two edges using radius r1 and r2

Figure 2. Filleting a box

a = 100b = 60c = 80r = 10

```#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <TopoDS_Solid.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <TopExp_Explorer.hxx>

TopoDS_Shape FilletedBox(const Standard_Real a,
const Standard_Real b,
const Standard_Real c,
const Standard_Real r)
{
TopoDS_Solid Box = BRepPrimAPI_MakeBox(a,b,c);
BRepFilletAPI_MakeFillet MF(Box);

// add all the edges to fillet
TopExp_Explorer ex(Box,TopAbs_EDGE);
while (ex.More())
{
ex.Next();
}

return MF.Shape();
}
```

Figure 4. Evolutive radius fillet a box

```  1:     TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200, 200, 200);
2:     BRepFilletAPI_MakeFillet Rake(theBox);
3:     ChFi3d_FilletShape FSH = ChFi3d_Rational;
4:     Rake.SetFilletShape(FSH);
5:
13:
14:     TopExp_Explorer ex(theBox, TopAbs_EDGE);
16:     TopoDS_Shape evolvedBox = Rake.Shape();
17: ```

#### 2． BRepFilletAPI_MakeFillet2d

BRepFilletAPI_MakeFillet2d is used to construct fillets and chamfers on planar faces.

```  1: #include “BRepPrimAPI_MakeBox.hxx”
2: #include “TopoDS_Shape.hxx”
3: #include “TopExp_Explorer.hxx”
4: #include “BRepFilletAPI_MakeFillet2d.hxx”
5: #include “TopoDS.hxx”
6: #include “TopoDS_Solid.hxx”
7:
8: TopoDS_Shape FilletFace(const Standard_Real a,
9:     const Standard_Real b,
10:     const Standard_Real c,
11:     const Standard_Real r)
12: {
13:     TopoDS_Solid Box = BRepPrimAPI_MakeBox (a,b,c);
14:     TopExp_Explorer ex1(Box,TopAbs_FACE);
15:
16:     const TopoDS_Face& F = TopoDS::Face(ex1.Current());
17:     BRepFilletAPI_MakeFillet2d MF(F);
18:     TopExp_Explorer ex2(F, TopAbs_VERTEX);
19:
20:     while (ex2.More())
21:     {
23:         ex2.Next();
24:     }
25:
26:     // while...
27:     return MF.Shape();
28: }
29: ```

### 二、倒角ChamferConstructor

#### 1．BRepFilletAPI_MakeChamfer

BREpFilletAPI_MakeChamfer的使用方法与BRepFilletAPI_MakeFillet大致类似，但稍有不同：

a) The surfaces created are ruled and not smooth;

b) The Add syntax for selecting edges requires one or two distances, one edge and one face(contiguous to the edge);

Add(d1, d2, E, F); with d1 on the face F.

Figure 5. Creating a chamfer

Figure 6. The box with chamfers

```  1: TopoDS_Shape theBox = BRepPrimAPI_MakeBox(130,200,170);
2: BRepFilletAPI_MakeChamfer MC(theBox);
3: TopTools_IndexedDataMapOfShapeListOfShape M;
4: TopExp::MapShapesAndAncestors(theBox,TopAbs_EDGE,TopAbs_FACE,M);
5:
6: for (Standar1d_Integer i;i<M.Extent();i++)
7: {
8:     TopoDS_Edge E = TopoDS::Edge(M.FindKey(i));
9:     TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First());
11: }
12:
13: TopoDS_Shape ChanfrenedBox = MC.Shape();
14: ```

### Feedback

http://blog.csdn.net/fcqwin/article/details/17204707