BRepOffsetAPI_MakeOffset功能案例

2023-10-27 21:12

本文主要是介绍BRepOffsetAPI_MakeOffset功能案例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

void ViewWindow::OnGen2dCurve()
{// Clear All_ctrlUi->listView->Clear();try{//构造一个线段GC_MakeSegment  Segment1(gp_Pnt(20, 0, 0), gp_Pnt(30, 0, 0));//根据线段构造一个边BRepBuilderAPI_MakeEdge anEdge(Segment1.Value());BRepBuilderAPI_MakeEdge anEdge2(gp_Pnt(30, 0, 0), gp_Pnt(30, 20, 0));BRepBuilderAPI_MakeEdge anEdge3(gp_Pnt(30, 20, 0), gp_Pnt(20, 0, 0));//aWire.Add(anEdge3.Edge());GC_MakeArcOfCircle arc4(gp_Pnt(30, 20, 0), gp_Pnt(34.651, 31.229, 0), gp_Pnt(45.88, 35.88, 0));BRepBuilderAPI_MakeEdge anEdge4(arc4.Value());构造一个圆double dr5 = 49.4178;double dAngelS5 = 98.82;double dAngelE5 = 94.4815;double dCenterX5 = 41.2769;double dCenterY5 = -12.4703;double dx5 = dr5 * cos(((dAngelE5 - dAngelS5) / 2 + dAngelS5) * M_PI / 180) + dCenterX5;double dy5 = dr5 * sin(((dAngelE5 - dAngelS5) / 2 + dAngelS5) * M_PI / 180) + dCenterY5;double dxs5 = dr5 * cos(dAngelS5 * M_PI / 180) + dCenterX5;double dys5 = dr5 * sin(dAngelS5 * M_PI / 180) + dCenterY5;double dxe5 = dr5 * cos(dAngelE5 * M_PI / 180) + dCenterX5;double dye5 = dr5 * sin(dAngelE5 * M_PI / 180) + dCenterY5;//GC_MakeArcOfCircle arc5(gp_Pnt(33.7, 36.363, 0), gp_Pnt(35.554, 36.615, 0),gp_Pnt(37.416, 36.796, 0));GC_MakeArcOfCircle arc5(gp_Pnt(dxs5, dys5, 0), gp_Pnt(dx5, dy5, 0), gp_Pnt(dxe5, dye5, 0));BRepBuilderAPI_MakeEdge anEdge5(arc5.Value());//      gp_Circ circle55(gp_Ax2(gp_Pnt(41.277, -12.470, 0), gp_Dir(0, 0, 1)), 49.418);//      //构造一个圆弧边//      GC_MakeArcOfCircle arc55(circle55, 94.481*M_PI/180, 98.82 * M_PI / 180,Standard_True);//   const Handle(Geom_TrimmedCurve) TrimmedCurve5 = arc55.Value();//      //求中间点位置//      Standard_Real first5 = TrimmedCurve5->FirstParameter();//      Standard_Real Last5 = TrimmedCurve5->LastParameter();//      Standard_Real mid5 = (Last5 - first5) / 2+ first5;//GC_MakeArcOfCircle arc5(TrimmedCurve5->Value(first5),//          TrimmedCurve5->Value(mid5),//          TrimmedCurve5->Value(Last5));//BRepBuilderAPI_MakeEdge anEdge5(arc5.Value());Standard_Real fBegin5 = 0, fEnd5 = 0;Handle(Geom_Curve) hCurveEdge5 = BRep_Tool::Curve(anEdge5, fBegin5, fEnd5);Handle(Geom_Circle) circle5 = Handle_Geom_Circle::DownCast(hCurveEdge5);// 在这里处理圆对象qDebug() << "Circle5";//读取圆弧起点和终点坐标qDebug() << "start5:[" << circle5->Value(fBegin5).X() << "," << circle5->Value(fBegin5).Y() << ","<< circle5->Value(fBegin5).Z() << "]";qDebug() << "end5:[" << circle5->Value(fEnd5).X() << "," << circle5->Value(fEnd5).Y() << ","<< circle5->Value(fEnd5).Z() << "]";qDebug() << "mid5:[" << circle5->Value((fEnd5- fBegin5)/2+ fBegin5).X() << "," << circle5->Value((fEnd5 - fBegin5) / 2 + fBegin5).Y() << ","<< circle5->Value((fEnd5 - fBegin5) / 2 + fBegin5).Z() << "]";qDebug() << "R5:" << circle5->Radius();const gp_Circ& circ5 = circle5->Circ();const gp_Pnt& center5 = circ5.Location();// 获取圆心坐标qDebug() << "Center5:[" << center5.X() << "," << center5.Y() << ","<< center5.Z() << "]";//gp_Circ circle66(gp_Ax2(gp_Pnt(41.329, -13.129, 0), gp_Dir(0, 0, 1)), 50.078);构造一个圆弧边//GC_MakeArcOfCircle arc66(circle66, 90.199 * M_PI / 180,94.481 * M_PI / 180, Standard_True);//const Handle(Geom_TrimmedCurve) TrimmedCurve6 = arc66.Value();求中间点位置//Standard_Real first6 = TrimmedCurve6->FirstParameter();//Standard_Real Last6 = TrimmedCurve6->LastParameter();//Standard_Real mid6 = (Last6 - first6) / 2 + first6;//GC_MakeArcOfCircle arc6(TrimmedCurve6->Value(first6),//	TrimmedCurve6->Value(mid6),//	TrimmedCurve6->Value(Last6));double dr6 = 50.0781;double dAngelS6 = 94.4815 ;double dAngelE6 = 90.1993;double dCenterX6 = 41.3285;double dCenterY6 = -13.1286;double dx6 = dr6 * cos(((dAngelE6 - dAngelS6) / 2 + dAngelS6) * M_PI / 180) + dCenterX6;double dy6 = dr6 * sin(((dAngelE6 - dAngelS6) / 2 + dAngelS6) * M_PI / 180) + dCenterY6;double dxs6 = dr6 * cos(dAngelS6 * M_PI / 180) + dCenterX6;double dys6 = dr6 * sin(dAngelS6 * M_PI / 180) + dCenterY6;double dxe6 = dr6 * cos(dAngelE6 * M_PI / 180) + dCenterX6;double dye6 = dr6 * sin(dAngelE6 * M_PI / 180) + dCenterY6;//GC_MakeArcOfCircle arc6(gp_Pnt(37.416, 36.796, 0), gp_Pnt(39.283, 36.908, 0), gp_Pnt(41.154, 36.949, 0));GC_MakeArcOfCircle arc6(gp_Pnt(dxe5, dye5, 0), gp_Pnt(dx6, dy6, 0), gp_Pnt(dxe6, dye6, 0));BRepBuilderAPI_MakeEdge anEdge6(arc6.Value());Standard_Real fBegin6 = 0, fEnd6 = 0;Handle(Geom_Curve) hCurveEdge6 = BRep_Tool::Curve(anEdge6, fBegin6, fEnd6);Handle(Geom_Circle) circle6 = Handle_Geom_Circle::DownCast(hCurveEdge6);// 在这里处理圆对象qDebug() << "Circle6";//读取圆弧起点和终点坐标qDebug() << "start6:[" << circle6->Value(fBegin6).X() << "," << circle6->Value(fBegin6).Y() << ","<< circle6->Value(fBegin6).Z() << "]";qDebug() << "end6:[" << circle6->Value(fEnd6).X() << "," << circle6->Value(fEnd6).Y() << ","<< circle6->Value(fEnd6).Z() << "]";qDebug() << "R6:" << circle6->Radius();const gp_Circ& circ6 = circle6->Circ();const gp_Pnt& center6 = circ6.Location();// 获取圆心坐标qDebug() << "Center6:[" << center6.X() << "," << center6.Y() << ","<< center6.Z() << "]";Handle(Geom2d_Circle) circle = new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(center6.X(), center6.Y()) , gp_Dir2d(1, 0)), dr6);Handle(Geom2d_TrimmedCurve) trimmedCurve61 = new Geom2d_TrimmedCurve(circle, dAngelS6*M_PI/180, dAngelE6 * M_PI / 180);Geom2d_OffsetCurve OffsetCurve61(trimmedCurve61, -0.2);// 获取起始点和结束点gp_Pnt2d startPoint66 = OffsetCurve61.Value(OffsetCurve61.FirstParameter());gp_Pnt2d endPoint66 = OffsetCurve61.Value(OffsetCurve61.LastParameter());qDebug() << "startPoint66:(" << startPoint66.X() << "," << startPoint66.Y() << ")";qDebug() << "endPoint66:(" << endPoint66.X() << "," << endPoint66.Y() << ")";GC_MakeSegment  Segment7(gp_Pnt(dxe6, dye6, 0), gp_Pnt(41.901, 37.697, 0));BRepBuilderAPI_MakeEdge anEdge7(Segment7.Value());gp_Pnt2d piont71(dxe6, dye6);gp_Pnt2d piont72(41.901, 37.697);GCE2d_MakeSegment seg71(piont71, piont72);Geom2d_OffsetCurve OffsetCurve71(seg71.Value(), 0.2);// 获取起始点和结束点gp_Pnt2d startPoint77 = OffsetCurve71.Value(OffsetCurve71.FirstParameter());gp_Pnt2d endPoint77 = OffsetCurve71.Value(OffsetCurve71.LastParameter());qDebug() << "startPoint77:(" << startPoint77.X() << "," << startPoint77.Y() << ")";qDebug() << "endPoint77:(" << endPoint77.X() << "," << endPoint77.Y() << ")";//GC_MakeSegment  Segment8(gp_Pnt(41.901, 37.697, 0), gp_Pnt(41.901, 40.162, 0));GC_MakeSegment  Segment8(Segment7.Value()->EndPoint(), gp_Pnt(Segment7.Value()->EndPoint().X(), Segment7.Value()->EndPoint().Y()+10, 0));BRepBuilderAPI_MakeEdge anEdge8(Segment8.Value());GC_MakeSegment  Segment9(Segment8.Value()->EndPoint(), gp_Pnt(dxs5, Segment8.Value()->EndPoint().Y(), 0));BRepBuilderAPI_MakeEdge anEdge9(Segment9.Value());GC_MakeSegment  Segment10(gp_Pnt(dxs5, Segment8.Value()->EndPoint().Y(), 0), gp_Pnt(dxs5, dys5, 0));BRepBuilderAPI_MakeEdge anEdge10(Segment10.Value());// TopTools_ListOfShape listEdge;listEdge.Append(anEdge5.Edge());listEdge.Append(anEdge6.Edge());listEdge.Append(anEdge7.Edge());listEdge.Append(anEdge8.Edge());listEdge.Append(anEdge9.Edge());listEdge.Append(anEdge10.Edge());//根据一个边构造一个线框BRepBuilderAPI_MakeWire aWire;//aWire.Add(anEdge.Edge());//aWire.Add(anEdge2.Edge());//添加到线框中//aWire.Add(anEdge4.Edge());aWire.Add(listEdge);// aWire.Build();if (!aWire.IsDone()){if (aWire.Error()== BRepBuilderAPI_WireError::BRepBuilderAPI_EmptyWire){qDebug() << "Wire failed-EmptyWire!\n";}else if (aWire.Error() == BRepBuilderAPI_WireError::BRepBuilderAPI_DisconnectedWire){qDebug() << "Wire failed-DisconnectedWire!\n";} else if (aWire.Error() == BRepBuilderAPI_WireError::BRepBuilderAPI_NonManifoldWire){qDebug() << "Wire failed-NonManifoldWire!\n";}else{qDebug() << "Wire failed!\n";}//return;}// 创建 ShapeFix_Wireframe 对象并传入线框//      Handle(ShapeFix_Wireframe) aFixWire = new ShapeFix_Wireframe(aWire.Shape());aFixWire->SetPrecision(thePrec);//aFixWire->SetMaxTolerance(0.01);//      aFixWire->FixWireGaps();Handle(AIS_Shape) wire_shape = new AIS_Shape(aWire.Shape());_ctrlUi->listView->RecordModel(wire_shape, QString("wire shape"));wire_shape->SetColor(Quantity_NOC_YELLOW);//offset shape//线框做偏置距离BRepOffsetAPI_MakeOffset mk_offset;mk_offset.AddWire(aWire.Wire());//mk_offset.SetApprox(true);mk_offset.Init(GeomAbs_Arc, Standard_False);Standard_Real offset = _ctrlUi->doubleSpinBox_offsetDist->value();mk_offset.Perform(offset);if (!mk_offset.IsDone()){qDebug() << "Offset failed!\n";}else{const TopoDS_Shape& offsetShape = mk_offset.Shape();if (offsetShape.IsNull()){qDebug() << "offsetShape is null!\n";return;}Handle(AIS_Shape) offset_shape = new AIS_Shape(offsetShape);_ctrlUi->listView->RecordModel(offset_shape, QString("offset shape"));offset_shape->SetColor(Quantity_NOC_RED);//将拓扑数据转为几何数据TopTools_IndexedMapOfShape aEdgeMap;TopExp::MapShapes(offsetShape, TopAbs_EDGE, aEdgeMap);qDebug() << "edge count is " << aEdgeMap.Extent();//遍历结果for (int i = 1; i <= aEdgeMap.Extent(); ++i){const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeMap(i));const TopoDS_Vertex& aFirstVertex = TopExp::FirstVertex(aEdge);const TopoDS_Vertex& aLastVertex = TopExp::LastVertex(aEdge);Standard_Real fBegin = 0, fEnd = 0;Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge, fBegin, fEnd);if (!hCurve.IsNull()){if (hCurve->IsKind(STANDARD_TYPE(Geom_Line))) {// 是直线Handle(Geom_Line) line = Handle_Geom_Line::DownCast(hCurve);// 在这里处理直线对象qDebug() << "Line";//读取直线起点和终点坐标qDebug() << "start:[" << line->Value(fBegin).X() << "," << line->Value(fBegin).Y() << ","<< line->Value(fBegin).Z() << "]";qDebug() << "end:[" << line->Value(fEnd).X() << "," << line->Value(fEnd).Y() << ","<< line->Value(fEnd).Z() << "]";}else if (hCurve->IsKind(STANDARD_TYPE(Geom_Circle))) {// 是圆Handle(Geom_Circle) circle = Handle_Geom_Circle::DownCast(hCurve);// 在这里处理圆对象qDebug() << "Circle";//读取圆弧起点和终点坐标qDebug() << "start:[" << circle->Value(fBegin).X() << "," << circle->Value(fBegin).Y() << ","<< circle->Value(fBegin).Z() << "]";qDebug() << "end:[" << circle->Value(fEnd).X() << "," << circle->Value(fEnd).Y() << ","<< circle->Value(fEnd).Z() << "]";qDebug() << "R:" << circle->Radius();const gp_Circ& circ = circle->Circ();const gp_Pnt& center = circ.Location();// 获取圆心坐标qDebug() << "Center:[" << center.X() << "," << center.Y() << ","<< center.Z() << "]";}else if (hCurve->IsKind(STANDARD_TYPE(Geom_BezierCurve))) {// 是贝塞尔曲线Handle(Geom_BezierCurve) bezierCurve = Handle_Geom_BezierCurve::DownCast(hCurve);// 在这里处理贝塞尔曲线对象qDebug() << "BezierCurve";}else if (hCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) {// 是B样条曲线Handle(Geom_BSplineCurve) bsplineCurve = Handle_Geom_BSplineCurve::DownCast(hCurve);// 在这里处理B样条曲线对象qDebug() << "SplineCurve";}else {// 其他类型的曲线// 在这里处理其他类型的曲线对象qDebug() << "OtherCurve";}}}}_view->fitAll();//_context->Activate(ViewHelper::SM_FACE);//_context->Activate(ViewHelper::SM_WIRE);}catch (Standard_Failure const& theFailure){qDebug() << "info: " << theFailure.GetMessageString() << "\n";}
}

这篇关于BRepOffsetAPI_MakeOffset功能案例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

SpringBoot集成Milvus实现数据增删改查功能

《SpringBoot集成Milvus实现数据增删改查功能》milvus支持的语言比较多,支持python,Java,Go,node等开发语言,本文主要介绍如何使用Java语言,采用springboo... 目录1、Milvus基本概念2、添加maven依赖3、配置yml文件4、创建MilvusClient

使用Python开发一个带EPUB转换功能的Markdown编辑器

《使用Python开发一个带EPUB转换功能的Markdown编辑器》Markdown因其简单易用和强大的格式支持,成为了写作者、开发者及内容创作者的首选格式,本文将通过Python开发一个Markd... 目录应用概览代码结构与核心组件1. 初始化与布局 (__init__)2. 工具栏 (setup_t

Python中使用正则表达式精准匹配IP地址的案例

《Python中使用正则表达式精准匹配IP地址的案例》Python的正则表达式(re模块)是完成这个任务的利器,但你知道怎么写才能准确匹配各种合法的IP地址吗,今天我们就来详细探讨这个问题,感兴趣的朋... 目录为什么需要IP正则表达式?IP地址的基本结构基础正则表达式写法精确匹配0-255的数字验证IP地

MySQL高级查询之JOIN、子查询、窗口函数实际案例

《MySQL高级查询之JOIN、子查询、窗口函数实际案例》:本文主要介绍MySQL高级查询之JOIN、子查询、窗口函数实际案例的相关资料,JOIN用于多表关联查询,子查询用于数据筛选和过滤,窗口函... 目录前言1. JOIN(连接查询)1.1 内连接(INNER JOIN)1.2 左连接(LEFT JOI

SpringBoot实现微信小程序支付功能

《SpringBoot实现微信小程序支付功能》小程序支付功能已成为众多应用的核心需求之一,本文主要介绍了SpringBoot实现微信小程序支付功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作... 目录一、引言二、准备工作(一)微信支付商户平台配置(二)Spring Boot项目搭建(三)配置文件

在Android平台上实现消息推送功能

《在Android平台上实现消息推送功能》随着移动互联网应用的飞速发展,消息推送已成为移动应用中不可或缺的功能,在Android平台上,实现消息推送涉及到服务端的消息发送、客户端的消息接收、通知渠道(... 目录一、项目概述二、相关知识介绍2.1 消息推送的基本原理2.2 Firebase Cloud Me

Spring Boot项目中结合MyBatis实现MySQL的自动主从切换功能

《SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能》:本文主要介绍SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能,本文分步骤给大家介绍的... 目录原理解析1. mysql主从复制(Master-Slave Replication)2. 读写分离3.

Mybatis 传参与排序模糊查询功能实现

《Mybatis传参与排序模糊查询功能实现》:本文主要介绍Mybatis传参与排序模糊查询功能实现,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、#{ }和${ }传参的区别二、排序三、like查询四、数据库连接池五、mysql 开发企业规范一、#{ }和${ }传参的

springboot循环依赖问题案例代码及解决办法

《springboot循环依赖问题案例代码及解决办法》在SpringBoot中,如果两个或多个Bean之间存在循环依赖(即BeanA依赖BeanB,而BeanB又依赖BeanA),会导致Spring的... 目录1. 什么是循环依赖?2. 循环依赖的场景案例3. 解决循环依赖的常见方法方法 1:使用 @La

Java实现文件图片的预览和下载功能

《Java实现文件图片的预览和下载功能》这篇文章主要为大家详细介绍了如何使用Java实现文件图片的预览和下载功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... Java实现文件(图片)的预览和下载 @ApiOperation("访问文件") @GetMapping("