# Representation Data in OpenCascade BRep

eryar@163.com

## 一、引言 Introduction

Figure 1.1 Parametric geometry curves

Figure 1.2 Parametric geometry surfaces

## 二、细分曲线 Subdivision of Curves

Figure 2.1 Uniform sampling on a curve

BNF定义：

<3D polygon record>定义了空间多段线（3D polyline）L，用来逼近空间参数曲线C。多段线的数据包含节点数m>=2，参数显示标志位p，逼近偏差（deflection）d>=0，节点Ni（1=<i<=m），参数ui（1=<i<=m）。当参数显示标志位p＝1时，参数u才会显示。多段线L通过这些节点，多段线L逼近曲线C的逼近偏差定义如下所示：

## 三、细分曲面 Subdivision of surfaces

Figure 3.1 Triangulation of Chinese Dragon

BNF定义：

<triangulation record>定义了逼近曲面S的三角剖分T（triangulation）。三角剖分的数据包含节点数m>=3，三角形数k>=1，参数显示标志位p，逼近偏差d>=0，节点Ni（1<=i<=m），参数对ui,vi（1<=i<=m），三角形nj,1，nj,2，nj,3。参数只有当参数显示标志位p＝1时才显示。三角剖分逼近曲面的偏差d定义如下所示：

## 四、程序示例 Code Example

```/*
*
*        File    : Main.cpp
*        Author  : eryar@163.com
*        Date    : 2013-12-12 21:46
*        Version : 1.0v
*
*    Description : There are two kind of data for shape representation
*                  of the BRep file of OpenCascade. One is Polyline to
*                  approximates a 3D curve; the other is triangulations
*                  to approximates a surface.
*
*       KeyWords : OpenCascade, BRep File, Polygon, Triangulation
*
*/

#define WNT
#include <TColStd_Array1OfReal.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColgp_Array1OfPnt2d.hxx>

#include <Poly.hxx>
#include <Poly_Polygon3D.hxx>
#include <Poly_Array1OfTriangle.hxx>
#include <Poly_Triangulation.hxx>

#pragma comment(lib, \"TKernel.lib\")
#pragma comment(lib, \"TKMath.lib\")

int main(void)
{
// 3D Polygons:
// Polygon3D 1
// 2 1
// 0.1
// 1 0 0 2 0 0
// 0 1
TColStd_Array1OfReal parameters(1, 2);
TColgp_Array1OfPnt nodes(1, 2);
Handle_Poly_Polygon3D polyline;

nodes.SetValue(1, gp_Pnt(1, 0, 0));
nodes.SetValue(2, gp_Pnt(2, 0, 0));

parameters.SetValue(1, 0.0);
parameters.SetValue(2, 1.0);

polyline = new Poly_Polygon3D(nodes, parameters);
polyline->Deflection(0.1);

Poly::Write(polyline, std::cout);
Poly::Write(polyline, std::cout, false);

// Triangulations.
// 4 2 1 0
// 0 0 0 0 0 3 0 2 3 0 2 0 0 0 3 0 3 -2 0 -2 2 4 3 2 1 4
Standard_Integer nodeCount = 4;
Standard_Integer triangleCount = 2;
Standard_Real deflection = 0.0;
Standard_Boolean hasUV = Standard_True;

TColgp_Array1OfPnt triNodes(1, nodeCount);
TColgp_Array1OfPnt2d UVNodes(1, nodeCount);
Poly_Array1OfTriangle triangles(1, triangleCount);
Handle_Poly_Triangulation triangulation;

triNodes(1).SetCoord(0, 0, 0);
triNodes(2).SetCoord(0, 0, 3);
triNodes(3).SetCoord(0, 2, 3);
triNodes(4).SetCoord(0, 2, 0);

UVNodes(1).SetCoord(0.0, 0.0);
UVNodes(2).SetCoord(3.0, 0.0);
UVNodes(3).SetCoord(3.0, -2.0);
UVNodes(4).SetCoord(0.0, -2.0);

triangles(1).Set(2, 4, 3);
triangles(2).Set(2, 1, 4);

triangulation = new Poly_Triangulation(triNodes, UVNodes, triangles);
triangulation->Deflection(deflection);

Poly::Write(triangulation, std::cout);
Poly::Write(triangulation, std::cout, false);

return 0;
}```

```Poly_Polygon3D
2 1
0.1
1 0 0
2 0 0
0 1
Poly_Polygon3D
2 Nodes
with parameters
Deflection : 0.1

Nodes :
1 :                 1                 0                 0
2 :                 2                 0                 0

Parameters :
0 1
Poly_Triangulation
4 2 1
0
0 0 0
0 0 3
0 2 3
0 2 0
0 0
3 0
3 -2
0 -2
2 4 3
2 1 4
Poly_Triangulation
4 Nodes
2 Triangles
with UV nodes
Deflection : 0

3D Nodes :
1 :                 0                 0                 0
2 :                 0                 0                 3
3 :                 0                 2                 3
4 :                 0                 2                 0

UV Nodes :
1 :                 0                 0
2 :                 3                 0
3 :                 3                -2
4 :                 0                -2

Triangles :
1 :          2          4          3
2 :          2          1          4
Press any key to continue . . .```

THE END

暂无评论内容