乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 19|回复: 19

[编程交流] points density - dense.lsp - o

[复制链接]

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-5 23:54:30 | 显示全部楼层 |阅读模式
Hi all, recently I tried to make routine for making greater density of points that are to be used in generating terrain model. I know one desirable process that I've already tried (thread ab surveying points here on www.cadtutor.net) with DTM routine for 3DFACEs generation, AC (AutoCurve) routine that had small bug - line : (inters pt1 pt2 pt3 pt4) should be (inters pt1 pt2 pt3 pt4 nil) within one subfunction (I corrected this and that's now OK), LV routine for making mesh from sections over exploded polylines isohypses (equal elevation) from before used AC on 3DFACEs from DTM, and finally M2S (mesh2solid) routine for making 3D solid terrain... Anyway, my question is ab routine I made... Now it gives approximately desired results with less than 1000 points... I want to speed somehow process of calculation - code optimization and to allow more than 1000 points to be considered for routine calculations (this is even now possible but process is so slow - time consumption is greater with every single point added more for calculation consideration)... And one more thing, if process of repeating execution of routine is performed (4-5 times on starting 4 points) at the end when used command OVERKILL it removes duplicated points, and I just don't know how in the first place they have been created (look closely to code - especially line (if (not (member pp pplst)) (setq pplst (cons pp pplst)))...
Any help on these 2 issues will be very appreciated... So here is my code :
 
  1. (defun nearest ( pt lst / d1 d2 p1 p2 ) (setq lst (vl-remove pt lst)) (setq d1 (distance pt (car lst))       p1 (car lst) ) (foreach p2 (cdr lst)   (if (> d1 (setq d2 (distance pt p2)))     (setq d1 d2 p1 p2)   ) ) p1)(defun mid ( p1 p2 ) (mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2))(defun c:dense ( / ss n entpt pt ptlst pttlst pp pplst p2 ptt loop ) (setq ss (ssget '((0 . "POINT")))) [color=red](vl-cmdf "_.osnap" "off")[/color] (repeat (setq n (sslength ss))   (setq entpt (ssname ss (setq n (1- n))))   (setq pt (cdr (assoc 10 (entget entpt))))   (setq ptlst (cons pt ptlst)) ) (setq pttlst ptlst) (foreach pt pttlst   (setq ptlst pttlst)   (setq ptt nil)   (setq loop T)   (while loop     (if ptt (setq ptlst (vl-remove ptt ptlst)))     (if (not (null (vl-remove pt ptlst)))       (progn         (setq p2 (nearest pt ptlst))         (setq pp (mid pt p2))         (if (not (member pp pplst)) (setq pplst (cons pp pplst)))         (setq ptt pt)         (setq pt p2)       )       (setq loop nil)     )   ) ) (foreach pt pplst   (entmakex (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 pt))) ) (princ))
Thanks for any reply, sincerely M.R.
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-5 23:59:52 | 显示全部楼层
I've found out what was problem with overlapping - it was OSNAP...
 
So I added :
  1. (vl-cmdf "_.osnap" "off")
 
So now remains issue ab speed...
 
M.R. (Above code updated - added (vl-cmdf "_.osnap" "off"))
回复

使用道具 举报

35

主题

2471

帖子

2447

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
174
发表于 2022-7-6 00:01:37 | 显示全部楼层
A good programming practice call to restore user’s environment after you changed it:
  
  1. (setq userOsnap (getvar "OSMODE")) (setvar "OSMODE" 0)   ;;; processing   (setvar "OSMODE" userOsnap)
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-6 00:05:06 | 显示全部楼层
I've checked now with 5 points at start and repeated routine 4-5 times... It creates again overlapping points, so it isn't OSNAP the problem... Still there is issue of overlapping...
 
M.R.
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
211
发表于 2022-7-6 00:08:45 | 显示全部楼层
Try
 
  1. (if [color=blue][b](not (ssget "_C" pp pp))[/b][/color][color=blue][b](entmakex (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 pp)))[/b][/color]             )
 
and remove the creation of pplst and entaking the point entity on the fly rather than from a list.
 
or even (not (nentselp pp)) ;
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-6 00:10:45 | 显示全部楼层
pBe, your method seems to work... Thank you very much... Now only issue is is there better alternative then cycling through each point to gain a few new points that are between 2 near points... With one cycle I have almost correct result, I just don't know how to gain remaining points without these repetitions for each point... Now code looks like this :
 
  1. (defun nearest ( pt lst / d1 d2 p1 p2 ) (setq lst (vl-remove pt lst)) (setq d1 (distance pt (car lst))       p1 (car lst) ) (foreach p2 (cdr lst)   (if (> d1 (setq d2 (distance pt p2)))     (setq d1 d2 p1 p2)   ) ) p1)(defun mid ( p1 p2 ) (mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2))(defun c:dense ( / ss n entpt pt ptlst pttlst pp p2 ptt loop ) (setq ss (ssget '((0 . "POINT")))) (vl-cmdf "_.osnap" "off") (repeat (setq n (sslength ss))   (setq entpt (ssname ss (setq n (1- n))))   (setq pt (cdr (assoc 10 (entget entpt))))   (setq ptlst (cons pt ptlst)) ) (setq pttlst ptlst) (foreach pt pttlst   (setq ptlst pttlst)   (setq ptt nil)   (setq loop T)   (while loop     (if ptt (setq ptlst (vl-remove ptt ptlst)))     (if (not (null (vl-remove pt ptlst)))       (progn         (setq p2 (nearest pt ptlst))         (setq pp (mid pt p2))         (if (not (ssget "_C" pp pp))            (entmakex (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 pp)))         )         (setq ptt pt)         (setq pt p2)       )       (setq loop nil)     )   ) ) (princ))
pBe, thanks again for your reply and solving overlapping problem...
Regards, M.R.
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-6 00:15:20 | 显示全部楼层
And here is streight forward solution from first to last point derivation in single loop...
 
  1. (defun mid ( p1 p2 ) (mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2))(defun c:dense ( / ss n entpt ptlst pt pp p2 ) (setq ss (ssget "_X" '((0 . "POINT")))) (vl-cmdf "_.osnap" "off") (repeat (setq n (sslength ss))   (setq entpt (ssname ss (setq n (1- n))))   (setq pt (cdr (assoc 10 (entget entpt))))   (setq ptlst (cons pt ptlst)) ) (setq ptlst (reverse ptlst)) (while ptlst   (setq pt (car ptlst))   (if (cadr ptlst) (setq p2 (cadr ptlst)) (setq p2 nil))   (if p2     (progn       (entdel (ssname (ssget "_C" pt pt) 0))       (entmakex (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 pt)))       (setq pp (mid pt p2))       (entmakex (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 pp)))     )     (progn       (entdel (ssname (ssget "_C" pt pt) 0))       (entmakex (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 pt)))     )            )   (setq ptlst (cdr ptlst)) ) (princ))
 
M.R.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 00:18:13 | 显示全部楼层
I can appreciate what you are doing but really the bottom line is how is the original survey data being captured adding extra points may not improve the model, we work the other way and ask our surveyors to change their technique, a good example is a existing road being surveyed, getting the points roughly square across yields a far better model than randomly walking the individual lines that make a road also when breaklines are added they are in true direction.
 
If you have a perfect grid survey no extra point will make it any better only reducing grid size will improve. The facets will not change.
 
Last word yes we will on occasions add some pts to individual lines to improve the mesh not a global add.
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
211
发表于 2022-7-6 00:22:24 | 显示全部楼层
 
You are welcome M.R.
 
On your latest post, I cant say for sure I understand what its supposed to do. Cant give any advice or suggestions really.
 
Keep on coding
Cheers
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-6 00:25:33 | 显示全部楼层
I struggled for a while until I didn't figured out whats the catch (seen triangulate.lsp - DTM function)... The catch was to check for every 3 points circumcircle against rest of points and find those 3 for witch no other rest points are inside circumcircle... My version of DTM is I guess preciser than DTM, but it's so much slower, I strongly suggest to use DTM.vlx... So here is my version (all before posts refer to this triangulation witch I finally got wright)...
 
  1. (defun averpttriang (triangle) (mapcar '(lambda (a b c) (/ (+ a b c) 3.0)) (car triangle) (cadr triangle) (caddr triangle)))(defun unique (lst) (if lst (cons (car lst) (unique (vl-remove (car lst) (cdr lst))))))(defun uniquetriangles (triangles / lst assoctriangles uniquetriangs) (foreach triangle triangles   (setq lst (cons (averpttriang triangle) lst)) ) (setq lst (unique lst)) (foreach triangle triangles   (setq assoctriangles (cons (cons (averpttriang triangle) triangle) assoctriangles)) ) (foreach averpt lst   (setq uniquetriangs (cons (cdr (assoc averpt assoctriangles)) uniquetriangs)) ) uniquetriangs)(defun mid (p1 p2) (mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2))(defun circumtriang (p1 p2 p3 / pp1 pp2 pp3 mp1p2 mp2p3 npmp1p2 npmp2p3 cen rad) (setq pp1 (list (car p1) (cadr p1))) (setq pp2 (list (car p2) (cadr p2))) (setq pp3 (list (car p3) (cadr p3))) (setq mp1p2 (mid pp1 pp2)) (setq mp2p3 (mid pp2 pp3)) (setq npmp1p2 (polar mp1p2 (+ (angle pp1 pp2) (/ pi 2.0)) 1.0)) (setq npmp2p3 (polar mp2p3 (+ (angle pp2 pp3) (/ pi 2.0)) 1.0)) (setq cen (inters mp1p2 npmp1p2 mp2p3 npmp2p3 nil)) (setq rad (distance cen p1)) (list cen rad))(defun ptinsidecir (pt circle) (setq pt (list (car pt) (cadr pt))) (> (cadr circle) (distance (car circle) pt)))(defun c:triangulate ( / msp ss n pt ptlst pttlst p1 p2 p3 circle tst lst triangles) (vl-load-com) (setq msp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) (setq ss (ssget '((0 . "POINT")))) (repeat (setq n (sslength ss))   (setq pt (cdr (assoc 10 (entget (ssname ss (setq n (1- n)))))))   (setq ptlst (cons pt ptlst)) ) (setq pttlst ptlst) (while (> (length ptlst) 2)   (setq p1 (car ptlst))   (foreach p2 (cdr ptlst)     (foreach p3 (vl-remove p2 (cdr ptlst))       (setq circle (circumtriang p1 p2 p3))       (foreach pp (vl-remove p3 (vl-remove p2 (vl-remove p1 pttlst)))         (if (not (ptinsidecir pp circle)) (setq tst (cons T tst)) (setq tst (cons nil tst)))       )       (if (eval (cons 'and tst)) (setq lst (cons p1 lst) lst (cons p2 lst) lst (cons p3 lst)))       (if lst (setq triangles (cons lst triangles)))       (setq lst nil)       (setq tst nil)       (setq ptlst (vl-remove p1 ptlst))       (setq ptlst (vl-remove p2 ptlst))       (setq ptlst (vl-remove p3 ptlst))       (setq ptlst (cons p3 ptlst))       (setq ptlst (cons p2 ptlst))     )   ) ) (foreach triangle (uniquetriangles triangles)   (vla-add3dface msp (vlax-3d-point (car triangle)) (vlax-3d-point (cadr triangle)) (vlax-3d-point (caddr triangle)) (vlax-3d-point (caddr triangle))) )     (princ))
BIGAL, you're wright ab interpolation of points... It's totally unnecessary as these 3dfaces represent just that...
pBe, thanks for your hidden suggestion not to suggest anything - it made me think and search for solution...
Keep coding
Regards, M.R.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 21:20 , Processed in 0.695570 second(s), 83 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表