OpenCASCADE中散乱Edge生成Wire
OpenCASCADE中散乱Edge生成Wire
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的更多相关文章
- 示例 - 如何在NodeJS中调用SS生成的DLL
要想在NodeJS中调用SS生成的DLL, 需要借助EdgeJS. EdgeJS: http://tjanczuk.github.io/edge/ 如果你还不知道如何在SS中生成DLL, 请查看: S ...
- Git中如何利用生成SSH个人公钥访问git仓库
Git中如何利用生成SSH个人公钥访问git仓库方法(这里以coding平台为例): 1. 获取 SSH 协议地址 在项目的代码页面点击 SSH 切换到 SSH 协议, 获得访问地址, 请使用这个地址 ...
- visual 2008中error PRJ0003 : 生成 cmd.exe 时出错
visual 2008中error PRJ0003 : 生成 cmd.exe 时出错”, 和vs2008 sp1没关系 解决方案:工具—>选项—>项目和解决方案—>VC++目录, ...
- MVC中验证码的生成
在项目中验证码的生成通常是需要页面无刷新的,所以验证码图片实际是跟在某个input后面的img,通过控制该img来控制验证码显示的位置,例如: <div> <input id=&qu ...
- (DT系列五)Linux kernel 是怎么将 devicetree中的内容生成plateform_device
Linux kernel 是怎么将 devicetree中的内容生成plateform_device 1,实现场景(以Versatile Express V2M为例说明其过程)以arch/arm/ma ...
- VS中的预先生成事件和后期生成事件
原文:VS中的预先生成事件和后期生成事件 在C#开发中,有时候需要在程序编译之前或之后做一些操作. 要达到这个目的,可以使用Visual Studio中的预先生成事件和后期生成事件. 下图是一个简单例 ...
- 【转】(DT系列五)Linux kernel 是怎么将 devicetree中的内容生成plateform_device
原文网址:http://www.cnblogs.com/biglucky/p/4057495.html Linux kernel 是怎么将 devicetree中的内容生成plateform_devi ...
- (原)caffe中通过图像生成lmdb格式的数据
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5909121.html 参考网址: http://www.cnblogs.com/wangxiaocvp ...
- sql 中获取最后生成的标识值 IDENT_CURRENT ,@@IDENTITY ,SCOPE_IDENTITY 的用法和区别
原文:sql 中获取最后生成的标识值 IDENT_CURRENT ,@@IDENTITY ,SCOPE_IDENTITY 的用法和区别 IDENT_CURRENT 返回为任何会话和任何作用域中的指定表 ...
随机推荐
- 如何让alertdialog选择完后自动关闭
builder.setIcon(R.drawable.ic_system) .setTitle("串口号") .setSingleChoiceItems(mPorts, mSele ...
- Kali linux 2016.2(Rolling)中metasploit的主机探测
不多说,直接上干货! 1.活跃主机扫描 root@kali:~# ping -c 202.193.58.13 PING () bytes of data. bytes ttl= time=25.4 m ...
- 集合 List和Set
分别向Set集合以及List集合中添加“A”,“a”,“c”,“C”,“a”5个元素,观察重复值“a”能否在List集合以及Set集合中成功添加. List<String> ls=new ...
- GoldenGate 性能优化方法
从根本上讲,OGG复制性能和要复制的表是否存在主键和唯一索引有很大关系,所以从应用系统开发商对表结构的规范更为有效.OGG调优通常采用拆分进行的方式,拆分方法如下所述. Extract拆分方法 1) ...
- Rendering and compositing out of process iframes
For Developers > Design Documents > Out-of-Process iframes (OOPIFs) > Rendering and ...
- JS文字特效:彩色滚动变幻效果,只适合少量的文字。(过多对页面有影响)
JS代码如下: 代码具体是在哪里的我不知道但是我的有道云上有.如有哪位朋友知道,还望联系下,添加出处. <div id="chakhsu"></div> & ...
- 推荐《R数据可视化手册》高清英文版PDF+中文版PDF+源代码
绝大多数的绘图案例都是以强大.灵活制图而著称的R包ggplot2实现的,充分展现了ggplot2生动.翔实的一面.从如何画点图.线图.柱状图,到如何添加注解.修改坐标轴和图例,再到分面的使用和颜色的选 ...
- sed命令的介绍
命令格式 sed [options] 'command' file(s) sed [options] -f scriptfile file(s) 选项 -e<script>或--expre ...
- python note #1
To record my process of studying python and to practice my English meanwhile, I'd like to start writ ...
- 使用SVN+Axure RP 8.0创建团队项目
一.使用到的工具:VisualSVN Server --SVN服务器:https://www.visualsvn.com/server/ Axure RP 8.0 :http://www.downc ...