Open CASCADE学习|为什么由Edge生成Wire不成功?

2024-02-21 12:04

本文主要是介绍Open CASCADE学习|为什么由Edge生成Wire不成功?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Wire 是一种复合形状,不是由几何形状构建的,而是由边缘的装配构建的。BRepBuilderAPI_MakeWire类可以从一个或多个Edge构建Wire,或将新Edge连接到现有Wire。

 BRepBuilderAPI_MakeWire 类将Edge连接到Wire。添加新Edge时,如果其顶点之一与Wire共享,则认为它已连接到Wire。如果没有共享顶点,则算法会搜索边的一个顶点和Wire的一个顶点,这两个顶点位于同一位置(使用顶点的公差来测试它们是否具有相同的位置)。如果找到这样的一对顶点,则将Edge与Wire的顶点一起复制,以替换原始顶点。Edge的所有顶点都可以与Wire的顶点交换。如果找不到连接,则认为Wire已断开连接。这是一个错误。

BRepBuilderAPI_MakeWire 类可以返回添加到Wire上的最后一条边(Edge 方法)。如果复制了这条Edge,则它可能与原始Edge不同。

#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax3.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GCE2d_MakeSegment.hxx>
​
#include <GeomAPI_PointsToBSpline.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
​
#include <gp_GTrsf.hxx>
#include <BRepBuilderAPI_Transform.hxx>
​
#include"Viewer.h"
​
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <BRepAlgoAPI_Section.hxx>
#include"GEOMAlgo_Splitter.h"
#include <TopExp_Explorer.hxx>
#include <ShapeAnalysis_Edge.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
​
​
int main(int argc, char* argv[])
{gp_Dir  Z(0.0, 0.0, 1.0);gp_Pnt center(0, 0, 0.0);gp_Pnt xr(0.5, 0, 0.0);gp_Pnt yr(0.0, 1.0, 0.0);gp_Pnt zr(0.0, 0.0, 7.0);gp_Ax2  wb(center, Z);gp_Circ  wbcircle(wb, 0.125 / 2);TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);
​Standard_Real smallR = 0.112;Standard_Real bigR = 0.1975;Standard_Real xb = 0.0;Standard_Real yb = bigR;Standard_Real xs = 0.0105;Standard_Real ys = 0.1023;gp_Pnt p1(-0.0998, 0.0828, 0.0);gp_Pnt p2(-0.0456, 0.0053, 0.0);gp_Pnt p3(0.1637, 0.0871, 0.0);gp_Pnt p4(0.2237, 0.1471, 0.0);gp_Pnt scenter(xs, ys, 0.0);gp_Pnt bcenter(xb, yb, 0.0);gp_Ax2  sr(scenter, Z);gp_Ax2  br(bcenter, Z);gp_Circ  scircle(sr, smallR);gp_Circ  bcircle(br, bigR);TopoDS_Vertex v1 = BRepBuilderAPI_MakeVertex(p1);TopoDS_Vertex v2 = BRepBuilderAPI_MakeVertex(p2);TopoDS_Vertex v3 = BRepBuilderAPI_MakeVertex(p3);TopoDS_Vertex v4 = BRepBuilderAPI_MakeVertex(p4);Handle(Geom_TrimmedCurve) sc = GC_MakeArcOfCircle(scircle, p1, p2, 1);Handle(Geom_TrimmedCurve) bc = GC_MakeArcOfCircle(bcircle, p2, p3, 1);TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(sc);TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(bc);TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(v3, v4);TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge(v4, v1);//TopoDS_Wire out = BRepBuilderAPI_MakeWire(anEdge1,anEdge2);//TopoDS_Shape out1 = BRepAlgoAPI_Fuse(anEdge1, anEdge2);//TopoDS_Shape out = BRepAlgoAPI_Fuse(out1, anEdge3);TopTools_ListOfShape listEdge;listEdge.Append(anEdge4);listEdge.Append(anEdge3);listEdge.Append(anEdge2);//listEdge.Append(anEdge1);BRepBuilderAPI_MakeWire mw;mw.Add(listEdge);mw.Build();if (!mw.IsDone()){if (mw.Error() == BRepBuilderAPI_WireError::BRepBuilderAPI_EmptyWire){std::cout << "Wire failed-EmptyWire!\n";}else if (mw.Error() == BRepBuilderAPI_WireError::BRepBuilderAPI_DisconnectedWire){std::cout << "Wire failed-DisconnectedWire!\n";}else if (mw.Error() == BRepBuilderAPI_WireError::BRepBuilderAPI_NonManifoldWire){std::cout << "Wire failed-NonManifoldWire!\n";}else{std::cout << "Wire failed!\n";}}//mw.Add(anEdge3);//mw.Add(anEdge2);//mw.Add(anEdge1);//TopoDS_Shape bcut = BRepBuilderAPI_MakeFace(aCylinder->Cylinder(), TopoDS::Wire(seccut), Standard_True);//std::cout << "ok" << std::endl;Viewer vout(50, 50, 500, 500);vout << wbe;vout << xline;vout << yline;vout << zline;vout << mw;//vout << anEdge1;//vout << anEdge2;vout.StartMessageLoop();return 0;
}
​

Error 方法返回 BRepBuilderAPI_WireError 枚举中的一个术语:WireDone – 没有发生错误。

EmptyWire – 未初始化算法,使用了空构造函数。

DisconnectedWire – 最后添加的边未连接到Wire。

NonManifoldWire – 具有某种奇异性的Wire。

上述代码返回结果:Wire failed-DisconnectedWire!

表明后面添加的边未连接到Wire,也就是两个圆弧未连接线

通过以下代码输出圆弧的端点坐标,发现圆弧之间的交点距离过大,超出了容差,将距离过大的用直线连接起来,成功生成Wire。
 

#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax3.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GCE2d_MakeSegment.hxx>
​
#include <GeomAPI_PointsToBSpline.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
​
#include <gp_GTrsf.hxx>
#include <BRepBuilderAPI_Transform.hxx>
​
#include"Viewer.h"
​
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <BRepAlgoAPI_Section.hxx>
#include <TopExp_Explorer.hxx>
#include <ShapeAnalysis_Edge.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
​
​
int main(int argc, char* argv[])
{gp_Dir  Z(0.0, 0.0, 1.0);gp_Pnt center(0, 0, 0.0);gp_Pnt xr(0.5, 0, 0.0);gp_Pnt yr(0.0, 1.0, 0.0);gp_Pnt zr(0.0, 0.0, 7.0);gp_Ax2  wb(center, Z);gp_Circ  wbcircle(wb, 0.125 / 2);TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);
​Standard_Real smallR = 0.112;Standard_Real bigR = 0.1975;Standard_Real xb = 0.0;Standard_Real yb = bigR;Standard_Real xs = 0.0105;Standard_Real ys = 0.1023;gp_Pnt p1(-0.0998, 0.0828, 0.0);gp_Pnt p2(-0.0456, 0.0053, 0.0);gp_Pnt p3(0.1637, 0.0871, 0.0);gp_Pnt p4(0.2237, 0.1471, 0.0);gp_Pnt scenter(xs, ys, 0.0);gp_Pnt bcenter(xb, yb, 0.0);gp_Ax2  sr(scenter, Z);gp_Ax2  br(bcenter, Z);gp_Circ  scircle(sr, smallR);gp_Circ  bcircle(br, bigR);TopoDS_Vertex v1 = BRepBuilderAPI_MakeVertex(p1);TopoDS_Vertex v2 = BRepBuilderAPI_MakeVertex(p2);TopoDS_Vertex v3 = BRepBuilderAPI_MakeVertex(p3);TopoDS_Vertex v4 = BRepBuilderAPI_MakeVertex(p4);Handle(Geom_TrimmedCurve) sc = GC_MakeArcOfCircle(scircle, p1, p2, 1);Standard_Real scfirstParam = sc->FirstParameter();Standard_Real sclastParam = sc->LastParameter();gp_Pnt scpf,scpl;sc->D0(scfirstParam, scpf);sc->D0(sclastParam, scpl);Handle(Geom_TrimmedCurve) bc = GC_MakeArcOfCircle(bcircle, p2, p3, 1);Standard_Real bcfirstParam = bc->FirstParameter();Standard_Real bclastParam = bc->LastParameter();gp_Pnt bcpf, bcpl;bc->D0(bcfirstParam, bcpf);bc->D0(bclastParam, bcpl);std::cout << "sc first:(" << scpf.X() << "," << scpf.Y() << "," << scpf.Z() << ")" << std::endl;std::cout << "sc last:(" << scpl.X() << "," << scpl.Y() << "," << scpl.Z() << ")" << std::endl;std::cout << "bc first:(" << bcpf.X() << "," << bcpf.Y() << "," << bcpf.Z() << ")" << std::endl;std::cout << "bc last:(" << bcpl.X() << "," << bcpl.Y() << "," << bcpl.Z() << ")" << std::endl;TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(sc);TopoDS_Edge anEdge12 = BRepBuilderAPI_MakeEdge(scpl, bcpf);TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(bc);TopoDS_Edge anEdge23 = BRepBuilderAPI_MakeEdge(bcpl,p3);TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(v3, v4);TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge(v4, v1);TopoDS_Edge anEdge41 = BRepBuilderAPI_MakeEdge(p1, scpf);//TopoDS_Wire out = BRepBuilderAPI_MakeWire(anEdge1,anEdge2);//TopoDS_Shape out1 = BRepAlgoAPI_Fuse(anEdge1, anEdge2);//TopoDS_Shape out = BRepAlgoAPI_Fuse(out1, anEdge3);TopTools_ListOfShape listEdge;listEdge.Append(anEdge1);listEdge.Append(anEdge12);listEdge.Append(anEdge2);listEdge.Append(anEdge23);listEdge.Append(anEdge3);listEdge.Append(anEdge4);listEdge.Append(anEdge41);//listEdge.Append(anEdge2);//listEdge.Append(anEdge1);BRepBuilderAPI_MakeWire mw;mw.Add(listEdge);mw.Build();if (!mw.IsDone()){if (mw.Error() == BRepBuilderAPI_WireError::BRepBuilderAPI_EmptyWire){std::cout << "Wire failed-EmptyWire!\n";}else if (mw.Error() == BRepBuilderAPI_WireError::BRepBuilderAPI_DisconnectedWire){std::cout << "Wire failed-DisconnectedWire!\n";}else if (mw.Error() == BRepBuilderAPI_WireError::BRepBuilderAPI_NonManifoldWire){std::cout << "Wire failed-NonManifoldWire!\n";}else{std::cout << "Wire failed!\n";}}//mw.Add(anEdge3);//mw.Add(anEdge2);//mw.Add(anEdge1);
​//TopoDS_Shape bcut = BRepBuilderAPI_MakeFace(aCylinder->Cylinder(), TopoDS::Wire(seccut), Standard_True);//std::cout << "ok" << std::endl;Viewer vout(50, 50, 500, 500);vout << wbe;vout << xline;vout << yline;vout << zline;vout << mw;//vout << anEdge1;//vout << anEdge2;vout.StartMessageLoop();return 0;
}
​

sc first:(-0.0997897,0.0828018,0)

sc last:(-0.0455727,0.00534717,0)

bc first:(-0.0455918,0.00533436,0)

bc last:(0.163743,0.0870711,0)

这篇关于Open CASCADE学习|为什么由Edge生成Wire不成功?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/731714

相关文章

详解Java中如何使用JFreeChart生成甘特图

《详解Java中如何使用JFreeChart生成甘特图》甘特图是一种流行的项目管理工具,用于显示项目的进度和任务分配,在Java开发中,JFreeChart是一个强大的开源图表库,能够生成各种类型的图... 目录引言一、JFreeChart简介二、准备工作三、创建甘特图1. 定义数据集2. 创建甘特图3.

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

学习hash总结

2014/1/29/   最近刚开始学hash,名字很陌生,但是hash的思想却很熟悉,以前早就做过此类的题,但是不知道这就是hash思想而已,说白了hash就是一个映射,往往灵活利用数组的下标来实现算法,hash的作用:1、判重;2、统计次数;

AI一键生成 PPT

AI一键生成 PPT 操作步骤 作为一名打工人,是不是经常需要制作各种PPT来分享我的生活和想法。但是,你们知道,有时候灵感来了,时间却不够用了!😩直到我发现了Kimi AI——一个能够自动生成PPT的神奇助手!🌟 什么是Kimi? 一款月之暗面科技有限公司开发的AI办公工具,帮助用户快速生成高质量的演示文稿。 无论你是职场人士、学生还是教师,Kimi都能够为你的办公文

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]

poj 1258 Agri-Net(最小生成树模板代码)

感觉用这题来当模板更适合。 题意就是给你邻接矩阵求最小生成树啦。~ prim代码:效率很高。172k...0ms。 #include<stdio.h>#include<algorithm>using namespace std;const int MaxN = 101;const int INF = 0x3f3f3f3f;int g[MaxN][MaxN];int n

poj 1287 Networking(prim or kruscal最小生成树)

题意给你点与点间距离,求最小生成树。 注意点是,两点之间可能有不同的路,输入的时候选择最小的,和之前有道最短路WA的题目类似。 prim代码: #include<stdio.h>const int MaxN = 51;const int INF = 0x3f3f3f3f;int g[MaxN][MaxN];int P;int prim(){bool vis[MaxN];