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

多段线和二维多段线的区别及顶点遍历

近日项目处理中,在遍历多义线的时候,发现客户的图纸有【二维多段线】这个类型,需要做兼容处理,因此总结记录一下。

在 AutoCAD 里,LWPOLYLINE(轻量级多段线,命令是PL,下图左)和POLYLINE(多段线,本次主要讲述二维多段线,下图右)都是用来表示由多个线段或圆弧连接而成的图形对象,通过属性可以简单查看两者的内容:

1. 数据结构与存储

  • LWPOLYLINE
    • 它属于轻量级对象,存储数据时更为紧凑。相较于POLYLINELWPOLYLINE占用的内存和磁盘空间更少,这使得在处理大量多段线对象时,能有效提升性能。
    • 其顶点信息以连续的坐标对形式存储,数据结构较为简单,这也进一步减少了存储空间。
  • POLYLINE
    • 这是一种传统的多段线对象,数据结构相对复杂。它不仅包含顶点信息,还包含更多的属性和扩展数据,因此占用的存储空间更多。

2. 图形特性

  • LWPOLYLINE
    • 只能是二维对象,仅存在于当前 UCS(用户坐标系)的 XY 平面上。
    • 各顶点间的连接方式只能是直线段或圆弧,不能包含其他复杂的曲线。
  • POLYLINE
    • 既可以是二维对象,也可以是三维对象,能在三维空间中表示多段线。
    • 除了直线段和圆弧,还可以包含其他类型的曲线,如样条曲线等,具有更强的图形表达能力。

通过插件,查看两者的组码,内容如下:

从上面的两个图可见,两者组码"0",即它们的类型是不一样的。组码"0"也是从图纸筛选过滤的类型条件。

笔者通过策略模式,封装了两种模式的顶点遍历方案,核心代码如下:

// 顶点处理策略接口public interface IVertexProcessingStrategy{void ProcessVertices(Entity entity, List<CPointInfo> list);}// 顶点处理策略基类public abstract class VertexProcessingStrategyBase : IVertexProcessingStrategy{public abstract void ProcessVertices(Entity entity, List<CPointInfo> list);public CPointInfo ProcessVertex(Point3d vertex3d){System.Globalization.CultureInfo cultures = new System.Globalization.CultureInfo("en-US");Point3d ptLocation = CommonDeal.TransToLayout_3d(m_vp, vertex3d);return (new CPointInfo(){Num = (listRailCar_RedPointInfo.Count + 1).ToString(),XPos = vertex3d.X.ToString("f1", cultures),YPos = vertex3d.Y.ToString("f1", cultures),location = MathKit.Trans2XYZPoint(vertex3d)});}}// LWPOLYLINE 顶点处理策略public class LwPolylineVertexProcessingStrategy : VertexProcessingStrategyBase{public override void ProcessVertices(Entity entity, List<CPointInfo> list){var lwPoly = entity as Autodesk.AutoCAD.DatabaseServices.Polyline;if (lwPoly != null){int iNumberOfVertices = lwPoly.NumberOfVertices;for (int j = 0; j < iNumberOfVertices; j++){Point2d pt2d = lwPoly.GetPoint2dAt(j);CPointInfo processedPoint = ProcessVertex(new Point3d(pt2d.X, pt2d.Y, 0.0));list.Add(processedPoint);}}}}// POLYLINE 顶点处理策略public class PolylineVertexProcessingStrategy : VertexProcessingStrategyBase{public override void ProcessVertices(Entity entity, List<CPointInfo> list){var poly = entity as Autodesk.AutoCAD.DatabaseServices.Polyline2d;if (poly != null){Point3dCollection aaa = new Point3dCollection();poly.GetStretchPoints(aaa);int nn = aaa.Count;for (int i = 0; i < nn; i++){CPointInfo processedPoint = ProcessVertex(aaa[i]);list.Add(processedPoint);}}}}// 顶点处理上下文public class VertexProcessingContext{private IVertexProcessingStrategy _strategy;public VertexProcessingContext(IVertexProcessingStrategy strategy){_strategy = strategy;}public void SetStrategy(IVertexProcessingStrategy strategy){_strategy = strategy;}public void Process(Entity entity, List<CPointInfo> list){_strategy.ProcessVertices(entity, list);}}public void DealTwoTypePolyline(string sPLineLayer, string sLayoutName = ""){Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;// 定义筛选条件TypedValue[] values = new TypedValue[]{// 图元类型为LWPOLYLINE或POLYLINEnew TypedValue((int)DxfCode.Start, "LWPOLYLINE,POLYLINE"),// 图层为sPLineLayernew TypedValue((int)DxfCode.LayerName, sPLineLayer),// 布局名称为sLayoutNamenew TypedValue((int)DxfCode.LayoutName, sLayoutName)};SelectionFilter filter = new SelectionFilter(values);PromptSelectionResult psr;{psr = ed.SelectAll(filter);}if (psr.Status != PromptStatus.OK){return ;}Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;Database db = document.Database;List<CPointInfo> listCPointInfo = new List<CPointInfo>();using (Transaction tr = db.TransactionManager.StartTransaction()){BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);var lwPolyStrategy = new LwPolylineVertexProcessingStrategy();var polyStrategy = new PolylineVertexProcessingStrategy();var context = new VertexProcessingContext(lwPolyStrategy);ObjectId[] ids = psr.Value.GetObjectIds();for (int i = 0; i < ids.Length; i++){Entity ent = (Entity)tr.GetObject(ids[i], OpenMode.ForRead);if (ent is Autodesk.AutoCAD.DatabaseServices.Polyline){context.SetStrategy(lwPolyStrategy);}else if (ent is Autodesk.AutoCAD.DatabaseServices.Polyline2d){context.SetStrategy(polyStrategy);}else{continue;}context.Process(ent, listCPointInfo);}tr.Commit();}}
http://www.xdnf.cn/news/3767.html

相关文章:

  • Linux54 源码包的安装、修改环境变量解决 axel命令找不到;getfacl;测试
  • OpenHarmony平台驱动开发(一),ADC
  • 大模型实践:图文解锁Ollama在个人笔记本上部署llm
  • 一格一格“翻地毯”找单词——用深度优先搜索搞定单词搜索
  • [硬件电路-12]:LD激光器与DFB激光器功能概述、管脚定义、功能比较
  • 基于STM32的温湿度光照强度仿真设计(Proteus仿真+程序设计+设计报告+讲解视频)
  • 使用Scrapy构建高效网络爬虫:从入门到数据导出全流程
  • 互联网与无线广播:数字时代与模拟时代的通讯双轨制-优雅草卓伊凡
  • 【iOS】 分类 拓展 关联对象
  • Dify框架面试内容整理-Dify部署后常见问题有哪些?如何排查?
  • 【SQL触发器、事务、锁的概念和应用】
  • 基于SpringBoot + HTML 的宠物医院预约管理
  • LeetCode 1128 等价多米诺骨牌对的数量 题解
  • pip安装包时网络不畅,替换国内PyPI镜像源
  • Java 集合线程安全
  • Linux | 了解Linux中的任务调度---at与crontab 命令
  • LLM论文笔记 28: Universal length generalization with Turing Programs
  • RabbitMQ入门基础
  • 250504_VsCode使用
  • 14.Excel:排序和筛选
  • 【PINN】DeepXDE学习训练营(13)——operator-antiderivative_aligned.py
  • 汇编常用语法
  • node核心学习
  • IBM DB2 两地三中心方案与配置
  • shell编程补充内容(Linux课程实验3)
  • 【SpringAI+阿里云百炼】AI对话4个Demo
  • 【PostgreSQL数据分析实战:从数据清洗到可视化全流程】3.3 异常值识别(Z-score法/IQR法/业务规则法)
  • 力扣每日一题1007、行相等的最少多米诺旋转
  • 爬虫管理平台-最新版本发布
  • 李沐《动手学深度学习》 | Softmax回归 - 分类问题