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

相关文章

基于Java和FFmpeg实现视频压缩和剪辑功能

《基于Java和FFmpeg实现视频压缩和剪辑功能》在视频处理开发中,压缩和剪辑是常见的需求,本文将介绍如何使用Java结合FFmpeg实现视频压缩和剪辑功能,同时去除数据库操作,仅专注于视频处理,需... 目录引言1. 环境准备1.1 项目依赖1.2 安装 FFmpeg2. 视频压缩功能实现2.1 主要功

使用Python实现无损放大图片功能

《使用Python实现无损放大图片功能》本文介绍了如何使用Python的Pillow库进行无损图片放大,区分了JPEG和PNG格式在放大过程中的特点,并给出了示例代码,JPEG格式可能受压缩影响,需先... 目录一、什么是无损放大?二、实现方法步骤1:读取图片步骤2:无损放大图片步骤3:保存图片三、示php

Spring Boot 整合 SSE(Server-Sent Events)实战案例(全网最全)

《SpringBoot整合SSE(Server-SentEvents)实战案例(全网最全)》本文通过实战案例讲解SpringBoot整合SSE技术,涵盖实现原理、代码配置、异常处理及前端交互,... 目录Spring Boot 整合 SSE(Server-Sent Events)1、简述SSE与其他技术的对

深度解析Python yfinance的核心功能和高级用法

《深度解析Pythonyfinance的核心功能和高级用法》yfinance是一个功能强大且易于使用的Python库,用于从YahooFinance获取金融数据,本教程将深入探讨yfinance的核... 目录yfinance 深度解析教程 (python)1. 简介与安装1.1 什么是 yfinance?

Python脚本轻松实现检测麦克风功能

《Python脚本轻松实现检测麦克风功能》在进行音频处理或开发需要使用麦克风的应用程序时,确保麦克风功能正常是非常重要的,本文将介绍一个简单的Python脚本,能够帮助我们检测本地麦克风的功能,需要的... 目录轻松检测麦克风功能脚本介绍一、python环境准备二、代码解析三、使用方法四、知识扩展轻松检测麦

MySQL 临时表与复制表操作全流程案例

《MySQL临时表与复制表操作全流程案例》本文介绍MySQL临时表与复制表的区别与使用,涵盖生命周期、存储机制、操作限制、创建方法及常见问题,本文结合实例代码给大家介绍的非常详细,感兴趣的朋友跟随小... 目录一、mysql 临时表(一)核心特性拓展(二)操作全流程案例1. 复杂查询中的临时表应用2. 临时

MySQL 数据库表与查询操作实战案例

《MySQL数据库表与查询操作实战案例》本文将通过实际案例,详细介绍MySQL中数据库表的设计、数据插入以及常用的查询操作,帮助初学者快速上手,感兴趣的朋友跟随小编一起看看吧... 目录mysql 数据库表操作与查询实战案例项目一:产品相关数据库设计与创建一、数据库及表结构设计二、数据库与表的创建项目二:员

Java实现TXT文件导入功能的详细步骤

《Java实现TXT文件导入功能的详细步骤》在实际开发中,很多应用场景需要将用户上传的TXT文件进行解析,并将文件中的数据导入到数据库或其他存储系统中,本文将演示如何用Java实现一个基本的TXT文件... 目录前言1. 项目需求分析2. 示例文件格式3. 实现步骤3.1. 准备数据库(假设使用 mysql

Springboot项目登录校验功能实现

《Springboot项目登录校验功能实现》本文介绍了Web登录校验的重要性,对比了Cookie、Session和JWT三种会话技术,分析其优缺点,并讲解了过滤器与拦截器的统一拦截方案,推荐使用JWT... 目录引言一、登录校验的基本概念二、HTTP协议的无状态性三、会话跟android踪技术1. Cook

C#中的Drawing 类案例详解

《C#中的Drawing类案例详解》文章解析WPF与WinForms的Drawing类差异,涵盖命名空间、继承链、常用类及应用场景,通过案例展示如何创建带阴影圆角矩形按钮,强调WPF的轻量、可动画特... 目录一、Drawing 是什么?二、典型用法三、案例:画一个“带阴影的圆角矩形按钮”四、WinForm