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. HBase的体系结构

  2. 机器学习(七) PCA与梯度上升法 (上)

    一.什么是PCA 主成分分析 Principal Component Analysis 一个非监督学的学习算法 主要用于数据的降维 通过降维,可以发现更便于人类理解的特征 其他应用:可视化:去噪 第一 ...

  3. Slimming Paint (a.k.a. Redesigning Painting and Compositing)

    Slimming Paint is a Paint team project to re-implement the Blink<->cc picture recording API to ...

  4. UI Framework-1: Ash Color Chooser

    Ash Color Chooser Overview This document describes how to achieve <input type=”color”> UI in C ...

  5. [POI2012]HUR-Warehouse Store(贪心,堆)

    题意 n天.第i天上午会进货Ai件商品,中午的时候会有顾客需要购买Bi件商品,可以选择满足顾客的要求,或是无视掉他. 如果要满足顾客的需求,就必须要有足够的库存.问最多能够满足多少个顾客的需求. (n ...

  6. opencv——均值/中值滤波器去噪

    实验内容及实验原理: 1.用均值滤波器(即邻域平均法)去除图像中的噪声: 2.用中值滤波器去除图像中的噪声 3.比较两种方法的处理结果 实验步骤: 用原始图像lena.bmp或cameraman.bm ...

  7. ECNUOJ 2142 放书

    放书 Time Limit:1000MS Memory Limit:65536KBTotal Submit:409 Accepted:173 Description  你要把一叠书放进一些箱子里面,为 ...

  8. HBase 1.1.2 优化插入 Region预分配

    预分Region 与 不预分Region 的测试: 1 不预分Region:       23~29秒插入100W数据   并且蛋疼的是每次都写入一个 RegionServer 且  只在一个 Reg ...

  9. vmware启动虚拟机报错VMware Workstation has paused this virtual machine because the disk on which the virtual machine is stored is almost full. To continue, free an additional 1.4 GB of disk space.

    报错VMware Workstation has paused this virtual machine because the disk on which the virtual machine i ...

  10. 进程:linux用户态-内核态

    用户态:Ring3运行于用户态的代码则要受到处理器的诸多检查,它们只能访问映射其地址空间的页表项中规定的在用户态下可访问页面的虚拟地址,且只能对任务状态段(TSS)中I/O许可位图(I/O Permi ...