- UID
- 676430
- 积分
- 379
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2013-5-20
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
为了验证LISP与.NET的运算速度比较
以删除重复点为例,点数据量9840 个(同样算法的基础上)
结果如下:
c#的处理速度如下:采集点集耗时...耗时: 0.48秒
查找X值相近的点...耗时: 2.64秒
查找Y值相近的点...耗时: 0.14秒
LISP的处理速度如下:
采集点集耗时...耗时: 0.188秒
查找X值相近的点...耗时: 3.031秒
查找Y值相近的点...耗时: 0.328秒
C#的代码:
- #region RRPT-删除整个图形中XY平面投影的重合点(XY值相近的点)
- [CommandMethod("RRPT")]
- public void m_RemoveRepeatPoints()
- {
- m_ed.WriteMessage("\n功能:删除本图中重合的点(XY值相近的点)!");
- double dJD = 0.001;
- PromptDoubleOptions pdo = new PromptDoubleOptions("\n近似精度");
- pdo.AllowNegative = false;
- pdo.AllowNone = true;
- pdo.AllowZero = true;
- pdo.DefaultValue = dJD;
- PromptDoubleResult pdr = m_ed.GetDouble(pdo);
- if (pdr.Status != PromptStatus.OK)
- {
- return;
- }
- dJD = pdr.Value;
- PromptSelectionResult m_Psr = m_ed.SelectAll(new SelectionFilter(new TypedValue[] { new TypedValue(0, "POINT") }));
- int nNumPts = m_Psr.Value.GetObjectIds().Length;
- m_ed.WriteMessage("\n共找到【{0}】个点!\n", nNumPts);
- m_ed.WriteMessage("\n正在准备点集...");
- mFun.m_TimeStart(); //开始记录时间
- List<RRPTStruct> Pts = new List<RRPTStruct>();
- RRPTStruct rs = new RRPTStruct();
- foreach (ObjectId id in m_Psr.Value.GetObjectIds())
- {
- rs.pt = ((DBPoint)mFun.m_OpenEntity(id)).Position;
- rs.id = id;
- Pts.Add(rs);
- }
- m_ed.WriteMessage("耗时:{0}秒", mFun.m_TimeEnd().ToString("0.00"));
- m_ed.WriteMessage("\n查找X值相近的点...");
- var rp = from rps in Pts orderby rps.pt.X select rps;//点集排序(按X从小到大)
- Pts = rp.ToList<RRPTStruct>();
- Utils.SetApplicationStatusBarProgressMeter("正在查找X值相近的点...", 0, nNumPts - 1);
- mFun.m_TimeStart();
- RRPTStruct rs1 = new RRPTStruct();
- rs = Pts[0];
- int n = 0;
- List<RRPTStruct> PtsX = new List<RRPTStruct>();
- for (int i = 1; i < nNumPts; i++)
- {
- rs1 = Pts[i];
- if (Math.Abs(rs.pt.X - rs1.pt.X) <= dJD)
- {
- if (!PtsX.Contains(rs))
- {
- PtsX.Add(rs);
- }
- PtsX.Add(rs1);
- n++;
- }
- else
- {
- rs = rs1;
- }
- Utils.SetApplicationStatusBarProgressMeter(i);
- }
- Utils.RestoreApplicationStatusBar();
- m_ed.WriteMessage("耗时:{0}秒,共有【{1}】个X值相近的点", mFun.m_TimeEnd().ToString("0.00"), n + 1);
- m_ed.WriteMessage("\n查找Y值相近的点...");
- rp = from rps in PtsX orderby rps.pt.Y select rps;//点集排序(按Y从小到大)
- PtsX = rp.ToList<RRPTStruct>();
- if (PtsX.Count > 2)
- {
- Utils.SetApplicationStatusBarProgressMeter("正在查找Y值相近的点...", 0, nNumPts - 1);
- mFun.m_TimeStart();
- rs = PtsX[0];
- n = 0;
- for (int i = 1; i < PtsX.Count; i++)
- {
- rs1 = PtsX[i];[/i]
- if (Math.Abs(rs.pt.Y - rs1.pt.Y) <= dJD)
- {
- mDraw.m_EraseEntity(rs1.id);
- n++;
- }
- else
- {
- rs = rs1;
- }
- Utils.SetApplicationStatusBarProgressMeter(i);
- }
- }
- Utils.RestoreApplicationStatusBar();
- m_ed.WriteMessage("耗时:{0}秒,共有【{1}】个Y值相近的点\n已删除【{2}】个重合点", mFun.m_TimeEnd().ToString("0.00"), n, n);
- }
- private struct RRPTStruct
- {
- public Point3d pt;
- public ObjectId id;
- }
- #endregion
LISP的代码:
[pcode=lisp,true]
(defun c:cc ( / a b e e1 e2 elst i L lst mod nmax num ptx ptxy ss strmsg t0 t1 t2 x1 x2)
(vl-load-com)
(setq mod (getvar "modemacro"))
(if (setq ss (ssget "X" '((0 . "POINT"))))
(progn
;开始记录时间
(setq t0 (car (_VL-TIMES)))
(vla-startundomark (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq L (sslength ss)
i 0
)
(repeat L
(setq e (ssname ss i)
elst (entget e)
PtXY (cdr (assoc 10 elst))
lst (cons (list e PtXY) lst)
)
(setq i (1+ i))
)
;结束记录时间
(princ (strcat "\n采集点集耗时" (rtos (* 0.001 (- (car (_VL-TIMES)) t0)) 2 4) "秒"))
(princ)
;点集排序(按X从小到大)
(setq lst (vl-sort lst (function (lambda (e1 e2) (< (car (cadr e1)) (car (cadr e2)))))))
(setq i 0 num 0 L (length lst) nMax L)
(setq strMsg "◎查找X值相近的点,请稍等...")
(ayProcess1 nMax 0 strMsg) ;初始化状态栏
;开始记录时间
(setq t1 (car (_VL-TIMES)))
(repeat L
(setq a (nth i lst))
(setq x1 (car (cadr a)))
(setq b (nth (1+ i) lst))
(setq x2 (car (cadr b)))
(if (and x2 (equal x1 x2 0.001))
(progn
(setq num (1+ num))
(entdel (car a))
(setq ptX (cons b ptX))
)
)
(setq i (1+ i))
(ayProcess1 nMax i strMsg)
)
;结束记录时间
(princ (strcat "\n查找X值相近的点耗时" (rtos (* 0.001 (- (car (_VL-TIMES)) t1)) 2 4) "秒"))
;点集排序(按Y从小到大)
(setq ptX (vl-sort ptX (function (lambda (e1 e2) (< (cadr (cadr e1)) (cadr (cadr e2)))))))
(setq i 0 L (length ptX) nMax L)
(setq strMsg "◎查找Y值相近的点,请稍等...")
(ayProcess1 nMax 0 strMsg) ;初始化状态栏
;开始记录时间
(setq t2 (car (_VL-TIMES)))
(repeat L
(setq a (nth i ptX))
(setq x1 (cadr (cadr a)))
(setq b (nth (1+ i) ptX))
(setq x2 (cadr (cadr b)))
(if (and x2 (equal x1 x2 0.001))
(progn
(setq num (1+ num))
(entdel (car a))
)
)
(setq i (1+ i))
(ayProcess1 nMax i strMsg)
)
;结束记录时间
(princ (strcat "\n查找Y值相近的点耗时" (rtos (* 0.001 (- (car (_VL-TIMES)) t2)) 2 4) "秒"))
(princ (strcat "\n共删除" (itoa num) "个重复实体"))
(vla-endundomark (vla-get-ActiveDocument (vlax-get-acad-object)))
)
(alert "图面上无高程点!")
)
(setvar "modemacro" mod)
(princ)
)
(defun ayProcess1 (MaxValue Value xMessage / xMax xVal xMsg i)
(vl-load-com)
(setq xMax (fix (abs MaxValue)))
(setq xVal (fix Value))
(setq xMsg xMessage)
(if (<= xMax 0) (setq xMax 100))
(if (> xVal xMax) (setq xVal xMax))
(if (= xMsg nil) (setq xMsg "进度信息"))
;;;捕捉由于ACET-UI_PROGRESS引起的错误而不至于终止程序的运行.
(vl-catch-all-apply
'(lambda (iMax iVal iMsg / xtmp)
(progn
(if (= iMsg nil) (setq iMsg "进度信息"))
(cond
((= iVal 0) (acet-ui-progress iMsg iMax))
((and (> iVal 0) (<= iMax)) (acet-ui-progress -1))
((or (< iVal 0) (> iVal iMax)) (acet-ui-progress))
);end_cond
(setq xtmp "GOOD")
);end_progn
);end_defun Lambda function.
(list xMax xVal xMsg)
);end_vl-catch-all-apply
(setq xxx "A.Yunger Studio Welcome to you have tea together for happy time!")
);end_defun
[/pcode]
总结:程序的算法相当的重要!!!不对之处请指导 |
评分
-
查看全部评分
|