更多课程 选择中心

C/C++培训
达内IT学院

400-111-8989

C++开发中OpenCASCADE中散乱Edge生成Wired的教程

  • 发布:C++培训
  • 来源:网络
  • 时间:2018-05-25 17:42

这篇文章讲述的是C++开发中OpenCASCADE中散乱Edge生成Wired的教程。达内C++培训班正在火热招生中,同学你要不要加入我们呐?在这里小编每天也会分享一下干货给大家。那么今天说道的就是C++培训课程中的章节。

Abstract. In OpenCASCADE a wire can be built from any number of edges in sequence. If edges are not in sequence, you must sort them in order.

Key Words. Edge, Wire, Wire order

1. Introduction

在OpenCASCADE中生成WIRE时要求添加到WIRE中的边EDGE是有顺序要求的。当给定的边没有按顺序添加到WIRE之前,需要自己将EDGE按顺序处理。OpenCASCADE中也提供了对EDGE按顺序进行排序的功能,方便WIRE的生成。

本文给出将散乱的EDGE排序后生成WIRE的实现代码,这个功能用处还是很大的。

2. Code

在模型检查模块TKShHealing中,OpenCASCADE提供了类ShapeAnalysis_WireOrder用来将用于生成WIRE的一系列EDGE进行排序。这个类的实现原理是根据EDGE的起点、终点坐标来进行连接,生成顺序。

如下图所示为一个封闭的WIRE,根据这些尺寸标注,生成WIRE的EDGE。

C++开发中OpenCASCADE中散乱Edge生成Wired的教程

实现上述Wire的程序代码如下所示:

/*

The MIT License (MIT)

---------------------

Copyright(C) 2018 Shing Liu(eryar@163.com)

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files(the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and / or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions :

The above copyright notice and this permission notice shall be included in all

copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

SOFTWARE.

*/

#include <vector>

#include <gp_Pnt.hxx>

#include <gp_Circ.hxx>

#include <TopTools_ListOfShape.hxx>

#include <BRep_Tool.hxx>

#include <BRepTools.hxx>

#include <BRepBuilderAPI_MakeEdge.hxx>

#include <BRepBuilderAPI_MakeWire.hxx>

#include <ShapeAnalysis_Edge.hxx>

#include <ShapeAnalysis_WireOrder.hxx>

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

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

#pragma comment(lib, "TKG2d.lib")

#pragma comment(lib, "TKG3d.lib")

#pragma comment(lib, "TKGeomBase.lib")

#pragma comment(lib, "TKGeomAlgo.lib")

#pragma comment(lib, "TKBRep.lib")

#pragma comment(lib, "TKTopAlgo.lib")

#pragma comment(lib, "TKShHealing.lib")

void test(void)

{

std::vector<TopoDS_Edge> anEdges;

// 5 Segment edges.

BRepBuilderAPI_MakeEdge anEdgeMaker1(

gp_Pnt(-1650.0, 2857.88383249, 0.0),

gp_Pnt(-750.0, 1299.03810568, 0.0));

BRepBuilderAPI_MakeEdge anEdgeMaker2(

gp_Pnt(1299.03810568, 750.0, 0.0),

gp_Pnt(2857.88383249, 1650.0, 0.0));

BRepBuilderAPI_MakeEdge anEdgeMaker3(

gp_Pnt(2857.88383249, 1650.0, 0.0),

gp_Pnt(8000.0, 1650.0, 0.0));

BRepBuilderAPI_MakeEdge anEdgeMaker4(

gp_Pnt(8000.0, 1650.0, 0.0),

gp_Pnt(8000.0, -3300.0, 0.0));

BRepBuilderAPI_MakeEdge anEdgeMaker5(

gp_Pnt(8000.0, -3300.0, 0.0),

gp_Pnt(0.0, -3300.0, 0.0));

anEdges.push_back(anEdgeMaker1.Edge());

anEdges.push_back(anEdgeMaker2.Edge());

anEdges.push_back(anEdgeMaker3.Edge());

anEdges.push_back(anEdgeMaker4.Edge());

anEdges.push_back(anEdgeMaker5.Edge());

// 2 Arc edges.

gp_Circ aCircle1(gp::XOY(), 1500.0);

gp_Circ aCircle2(gp::XOY(), 3300.0);

BRepBuilderAPI_MakeEdge anEdgeMaker6(aCircle1,

gp_Pnt(-750.0, 1299.03810568, 0.0),

gp_Pnt(1299.03810568, 750.0, 0.0));

BRepBuilderAPI_MakeEdge anEdgeMaker7(aCircle2,

gp_Pnt(-1650.0, 2857.88383249, 0.0),

gp_Pnt(0.0, -3300.0, 0.0));

anEdges.push_back(anEdgeMaker6.Edge());

anEdges.push_back(anEdgeMaker7.Edge());

// Get edges order for the wire.

ShapeAnalysis_Edge anEdgeAnalyser;

ShapeAnalysis_WireOrder aWireOrder;

for (std::vector<TopoDS_Edge>::const_iterator i = anEdges.begin();

i != anEdges.end(); ++i)

{

TopoDS_Vertex aVf = anEdgeAnalyser.FirstVertex(*i);

TopoDS_Vertex aVl = anEdgeAnalyser.LastVertex(*i);

gp_Pnt aPf = BRep_Tool::Pnt(aVf);

gp_Pnt aPl = BRep_Tool::Pnt(aVl);

aWireOrder.Add(aPf.XYZ(), aPl.XYZ());

}

//

TopTools_ListOfShape aOrderedEdges;

for (Standard_Integer e = 1; e <= aWireOrder.NbEdges(); ++e)

{

const TopoDS_Edge& anEdge = anEdges.at(e - 1);

aOrderedEdges.Append(anEdge);

}

BRepBuilderAPI_MakeWire aWireMaker;

aWireMaker.Add(aOrderedEdges);

if (aWireMaker.IsDone())

{

BRepTools::Write(aWireMaker.Shape(), "d:/wire.brep");

}

}

int main(int argc, char* argv[])

{

test();

return 0;

}

程序先添加5条线段到EDGE数组,再添加两个圆弧到EDGE数组。再使用类ShapeAnalysis_WireOrder来对EDGE数组进行排序,将排序后的EDGE数组去生成WIRE。如果生成WIRE成功,会在D盘得到一个wire.brep文件。在Draw中加载后显示如下图所示:

C++开发中OpenCASCADE中散乱Edge生成Wired的教程

生成WIRE后,继而可以生成FACE,对FACE进行拉伸可以得到拉伸体,如下图所示:

C++开发中OpenCASCADE中散乱Edge生成Wired的教程

3. Conclusion

OpenCASCADE中生成WIRE时对添加的EDGE是有顺序的要求。如何对散乱的EDGE进行排序以达到生成WIRE的要求呢?OpenCASCADE在TKShHealing模块中提供了对EDGE排序的功能。

对EDGE排序的功能原理很简单,就是将所有的EDGE首尾相连,感兴趣的读者可以结合源码学习下。

更多C++培训类相关知识敬请关注C++培训官网c.tedu.cn

免责声明:内容和图片源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容

预约申请免费试听课

填写下面表单即可预约申请免费试听!怕钱不够?可就业挣钱后再付学费! 怕学不会?助教全程陪读,随时解惑!担心就业?一地学习,可全国推荐就业!

上一篇:C++培训-C++ 变量作用域的教程
下一篇:LSH解决问题的教程

C语言创建windows窗口实例

C++回调函数是什么?

C++ shared_ptr和动态数组

C语言有哪些关键词,C语言44个关键词大全

  • 扫码领取资料

    回复关键字:视频资料

    免费领取 达内课程视频学习资料

  • 搜索抖音号

    搜索抖音号:1821685962

    免费领取达内课程视频学习资料

Copyright © 2021 Tedu.cn All Rights Reserved 京ICP备08000853号-56 京公网安备 11010802029508号 达内时代科技集团有限公司 版权所有

选择城市和中心
黑龙江省

吉林省

河北省

湖南省

贵州省

云南省

广西省

海南省