当前位置: 首页 > news >正文

opencascade如何保存选中的面到本地

环境:occ 7.6
需求场景:用户点击了一个TopoDS_Shape,还选中了其中一个面,这时候他点了保存。用户下次打开模型文件时,我们的viewer窗口要恢复上次的选中状态。
核心问题:如何把用户选中的面保存,并下次复原?

首先,保存的时候,把用户选中的面的中心点A,给存到本地文件,或数据库里。
下次打开的时候,读取这个中心点
遍历已保存的TopoDS_Shape的所有拓扑面,计算它们的中心点,跟点A距离最近的,就是用户上次选择的面了。

//获取面的中心点
bool getFaceCenterNormal(const TopoDS_Face &face,  gp_Pnt &aCenterPoint)
{if (face.IsNull()){return Standard_False;}BRepAdaptor_Surface aSurface(face);//获取曲面最大最小UV值Standard_Real aUmin = aSurface.FirstUParameter();Standard_Real aUmax = aSurface.LastUParameter();Standard_Real aVmin = aSurface.FirstVParameter();Standard_Real aVmax = aSurface.LastVParameter();//曲面中心点UV值Standard_Real aMidU = (aUmax + aUmin) / 2;Standard_Real aMidV = (aVmax + aVmin) / 2;aSurface.D0(aMidU, aMidV, aCenterPoint);//面中心点坐标和此点切线向量return Standard_True;
}//myShape :用户最后点击的物体
//centerPointFromDataBase :从数据库读到的中心点,记录用户最后点击的面
TopoDS_Face LoadFace(TopoDS_Shape myShape,gp_Pnt centerPointFromDataBase){TopoDS_Face  targetFace;double minDist = std::numeric_limits<double>::max();for (Ex.Init(myShape, TopAbs_FACE); Ex.More(); Ex.Next()){TopoDS_Face currentFace = TopoDS::Face(Ex.Current());gp_Pnt centerPoint;getFaceCenterNormal(currentFace, centerPoint);double dist = centerPoint.Distance(centerPointFromDataBase);if (dist < minDist){targetFace = currentFace;minDist = dist;}}return targetFace;
}
http://www.xdnf.cn/news/538291.html

相关文章:

  • 使用MCP驱动IDA pro分析样本
  • DV SSL证书管理主要有哪些功能?
  • C语言—字符函数和字符串函数
  • 如何实现从网页一键启动你的 Electron 桌面应用(zxjapp://)
  • pcie phy电气层(PCS)详解gen1、2 (rx)
  • 北斗卫星通讯终端的技术原理是什么
  • 2025-05-19 学习记录--Python-简易用户登录系统 + 计算天数
  • RAG策略
  • 第二章、IMU(Inertial Measurement Unit 惯性测量单元)
  • 包装可靠性测试【二】
  • C++寻位映射的奇幻密码:哈希
  • AtomicReference 和 volatile 的比较
  • C++--综合应用-演讲比赛项目
  • 让数据驱动增长更简单! ClkLog用户行为分析系统正式入驻GitCode
  • 【随手记】 Event Bus vs. Event Loop
  • 01、java方法
  • 【Python训练营打卡】day30 @浙大疏锦行
  • 盲盒APP开发——解锁盲盒经济无限可能
  • mapbox-gl强制请求需要accessToken的问题
  • Chromium 回调设计实战:BindOnce 与 BindRepeating 的最佳实践
  • 【css】【面试提问】css经典问题总结
  • Golang中的runtime.LockOSThread 和 runtime.UnlockOSThread
  • 嵌入式自学第二十四天
  • 整数的个数
  • Ollama 如何在显存资源有限的情况下合理分配给不同的服务?
  • 理解前端工程化
  • 新书速览|鸿蒙HarmonyOS NEXT开发之路 卷2:从入门到应用篇
  • java集成mqtt
  • 停等协议(Stop-and-Wait Protocol)
  • AI人工智能写作平台:AnKo助力内容创作变革!