OpenCASCADE中散乱Edge生成Wire

eryar@163.com

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。

实现上述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 = ; e <= aWireOrder.NbEdges(); ++e)
{
// const TopoDS_Edge& anEdge = anEdges.at(e - );
     const TopoDS_Edge& anEdge = anEdges.at(aWireOrder.Ordered(e));
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 ;
}

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

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

3. Conclusion

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

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

OpenCASCADE中散乱Edge生成Wire的更多相关文章

  1. 示例 - 如何在NodeJS中调用SS生成的DLL

    要想在NodeJS中调用SS生成的DLL, 需要借助EdgeJS. EdgeJS: http://tjanczuk.github.io/edge/ 如果你还不知道如何在SS中生成DLL, 请查看: S ...

  2. Git中如何利用生成SSH个人公钥访问git仓库

    Git中如何利用生成SSH个人公钥访问git仓库方法(这里以coding平台为例): 1. 获取 SSH 协议地址 在项目的代码页面点击 SSH 切换到 SSH 协议, 获得访问地址, 请使用这个地址 ...

  3. visual 2008中error PRJ0003 : 生成 cmd.exe 时出错

    visual 2008中error PRJ0003 : 生成 cmd.exe 时出错”,   和vs2008 sp1没关系 解决方案:工具—>选项—>项目和解决方案—>VC++目录, ...

  4. MVC中验证码的生成

    在项目中验证码的生成通常是需要页面无刷新的,所以验证码图片实际是跟在某个input后面的img,通过控制该img来控制验证码显示的位置,例如: <div> <input id=&qu ...

  5. (DT系列五)Linux kernel 是怎么将 devicetree中的内容生成plateform_device

    Linux kernel 是怎么将 devicetree中的内容生成plateform_device 1,实现场景(以Versatile Express V2M为例说明其过程)以arch/arm/ma ...

  6. VS中的预先生成事件和后期生成事件

    原文:VS中的预先生成事件和后期生成事件 在C#开发中,有时候需要在程序编译之前或之后做一些操作. 要达到这个目的,可以使用Visual Studio中的预先生成事件和后期生成事件. 下图是一个简单例 ...

  7. 【转】(DT系列五)Linux kernel 是怎么将 devicetree中的内容生成plateform_device

    原文网址:http://www.cnblogs.com/biglucky/p/4057495.html Linux kernel 是怎么将 devicetree中的内容生成plateform_devi ...

  8. (原)caffe中通过图像生成lmdb格式的数据

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5909121.html 参考网址: http://www.cnblogs.com/wangxiaocvp ...

  9. sql 中获取最后生成的标识值 IDENT_CURRENT ,@@IDENTITY ,SCOPE_IDENTITY 的用法和区别

    原文:sql 中获取最后生成的标识值 IDENT_CURRENT ,@@IDENTITY ,SCOPE_IDENTITY 的用法和区别 IDENT_CURRENT 返回为任何会话和任何作用域中的指定表 ...

随机推荐

  1. windows tensorflow 版本与升级

    tensorflow 的版本在 1.1.0/1.2.0 之后 api 迎来重大变化,有必要将版本升级到最新的 1.1.0 以上. 1. 使用 upgrade CPU:pip3 install –upg ...

  2. BZOJ 1069 求凸包+旋转卡壳

    思路: 求凸包: 先按照x轴排个序 从左往右扫一遍 找到上凸壳 (用叉积) 再从右往左扫一遍 求下凸壳 搞个旋转卡壳就好啦~ 嗯 我手懒 用的C++ Complex库 巨好用! //By Sirius ...

  3. vue 中使用querySelect 封装的万能选择器

    function query (el) { if (typeof el === 'string') { var selector = el; el = document.querySelector(e ...

  4. caffe命令及其参数解析

    caffe的c++主程序(caffe.cpp)放在根目录下的tools文件夹内, 当然还有一些其它的功能文件,如:convert_imageset.cpp, train_net.cpp, test_n ...

  5. vcenter server appliance 5.5 管理中心 linux 版本的部署

    本文选自通过ovf模板部署: 需要下面两个文件即可: 打开vsphere client 登录到你安装了exsi5.5的物理机上面: 点击文件---> 部署ovf模板  ---->选择你的模 ...

  6. input的选中与否以及将input的value追加到一个数组里

    html布局 <div class="mask"> //每一个弹层都有一个隐藏的input <label> <input hidden="& ...

  7. php异常处理的深入

    引出 如果你调一个类,调用时数据验证时报了个错,你会以什么方式返回 数组,布尔值? 数组这个可以带错误原因回来,那布尔值呢? 返回了个 false, 报错时把错误放在类变量里?还是专门用一个获取错误的 ...

  8. HDU 4398 Template Library Management (最优页面调度算法)

    中等偏易题.操作系统理论中的最优页面调度算法,贪心.当需要淘汰某个模版时,淘汰掉当前手中在最远的将来才会被用到(或者以后永远不再用到)的那个. 代码: #include <iostream> ...

  9. 【Round #36 (Div. 2 only) C】Socks Pairs

    [题目链接]:https://csacademy.com/contest/round-36/task/socks-pairs/ [题意] 给你n种颜色的袜子,每种颜色颜色的袜子有ai只; 假设你在取袜 ...

  10. 【转】[译]理解HTTP/304响应

    [转][译]理解HTTP/304响应 原文:http://www.telerik.com/automated-testing-tools/blog/eric-lawrence/12-11-06/und ...