求分堆分组后包围盒的最小点与最大点
以下代码来自:http://bbs.mjtd.com/thread-187448-1-1.html
kucha007大神整理的
我的疑问是,怎么样求出每组包围盒的最小点与最大点?
[*];对图元进行扎堆分组(矩形分堆),并返回每一个组的包围盒
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif;时间复杂度为n(1),测试了17万个图元480组仅10秒
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif;作者:Tryhi-大海 (优化 by Kucha)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif;SS是选择集,Dist是方框之间的间隙容差。
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif(defun K:RtnBox4SSGroup (SS Dist
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif/ K:GetEntBox K:GetSSBoxLst K:2RecIntersect Lst NewLst TmpLst Flag Rdo BasRec FstRec IntRec a b)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif(progn ;基础函数
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif ;获取实体最小外接矩形的WCS坐标(忽略Z值)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (defun K:GetEntBox (en / MaxPt MinPt)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (vla-GetBoundingBox (vlax-ename->vla-object en) 'MinPt 'MaxPt) ;取得包容图元的最大点和最小点
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq MinPt (vlax-safearray->list MinPt)) ;把变体数据转化为表
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq MaxPt (vlax-safearray->list MaxPt)) ;把变体数据转化为表
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (list (car MinPt) (cadr MinPt) (car MaxPt) (cadr MaxPt))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif ;获取选择集每个实体的最小边界框坐标列表
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (defun K:GetSSBoxLst (SS / i en Lst)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (if SS
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (repeat (setq i (sslength SS))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq en (ssname SS (setq i (1- i))))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq Lst (cons (K:GetEntBox en) Lst))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif Lst
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif ;如果矩形相交,则返回两矩形的最大边界框
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (defun K:2RecIntersect (A B)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (if
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (not
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (or;不可能重叠的四种情况
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (> (car A) (caddr B)) ;A的左侧比B的右侧大:X
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (> (cadr A) (Last B)) ;A的下部比B的上部大:Y
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (< (caddr A) (car B)) ;A的右侧比B的左侧小:X
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (< (Last A) (cadr B)) ;A的上部比B的下部小:Y
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (list
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (min (car A) (car B))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (min (cadr A) (cadr B))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (max (caddr A) (caddr B))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (max (Last A) (Last B))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif(if (and SS(setq Dist (/ Dist 2)))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (progn
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq Lst
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (vl-sort
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (K:GetSSBoxLst SS)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif '(lambda (A B) ;左下右上
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (if (equal (car A) (car B) 1e-3)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (if (equal (cadr A) (cadr B) 1e-3)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (if (equal (caddr A) (caddr B) 1e-3)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (< (cadddr A) (cadddr B)) ;上小在前
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (< (caddr A) (caddr B)) ;右小在前
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (< (cadr A) (cadr B)) ;下小在前
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (< (car A) (car B)) ;左小在前
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif );边界框矩形排序
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq Lst
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (mapcar
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif '(lambda (x)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (list
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (- (car x) Dist)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (- (cadr x) Dist)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (+ (caddr x) Dist)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (+ (cadddr x) Dist)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif Lst
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif );矩形扩大
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (progn ;合并矩形
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq Flag T Rdo Nil)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (while Flag
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq BasRec (car Lst)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif NewLst Nil
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (while (setq FstRec (car Lst)) ;主要耗时点
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq Lst (cdr Lst)) ;更新列表
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (if (setq IntRec (K:2RecIntersect BasRec (setq FstRec (car Lst))))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq BasRec IntRec);存在相交矩形
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (if
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq TmpLst (vl-some
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif '(lambda (a / b)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (if (setq b (K:2RecIntersect BasRec a))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (list b a)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif NewLst
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif );NewLst中有和BasRec相交的矩形?
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (progn
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (if (not (eq (car TmpLst) (Last TmpLst)))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq NewLst (subst (car TmpLst) (Last TmpLst) NewLst))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq BasRec FstRec)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq NewLst (cons BasRec NewLst)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif BasRec FstRec
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (if (eq (length NewLst) (length Rdo))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq Flag Nil)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq Rdo NewLst
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif Lst NewLst
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (setq Lst
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (mapcar
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif '(lambda (x)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (list
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (+ (car x) Dist)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (+ (cadr x) Dist)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (- (caddr x) Dist)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (- (cadddr x) Dist)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif NewLst
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif );矩形缩小
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif);矩形分堆得到互不相交的矩形LST
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif(mapcar
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif '(lambda (x)
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (list
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (list (car x) (cadr x))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif (list (caddr x) (cadddr x))
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif )
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif Lst
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif);调整LST表的数据结构
[*]http://bbs.mjtd.com/source/plugin/imc_colorcode/images/jssc_none.gif)
本帖最后由 yaojing38 于 2023-10-23 19:52 编辑
(mapcar
'(lambda (x)
(list
(list (car x) (cadr x))
(list (caddr x) (cadddr x))
(command "line"(list (car x) (cadr x)) (list (caddr x) (cadddr x)) "")
)
)
Lst
)
返回值 本来就是每组的最小点,,最大点了 yaojing38 发表于 2023-10-21 11:12
返回值 本来就是每组的最小点,,最大点了
我就以每组的最小点与最大点画一条直线,没有成功。看来是我获取的最小点,最大点出现错误了。:L qazxswk 发表于 2023-10-22 00:47
我就以每组的最小点与最大点画一条直线,没有成功。看来是我获取的最小点,最大点出现错误了。
你的图形有问题估计 yaojing38 发表于 2023-10-22 22:37
你的图形有问题估计
应该是我设定的最小点与最大点有问题。
最小点也就是左下角点,(setq Pt1 (vlax-3D-point (car Lst)))
最大点,也就是右上角点,我搞不懂了。 qazxswk 发表于 2023-10-22 23:08
应该是我设定的最小点与最大点有问题。
最小点也就是左下角点,(setq Pt1 (vlax-3D-point (car Lst))) ...
(mapcar
'(lambda (x)
(list
(list (car x) (cadr x)) ;最小点
(list (caddr x) (cadddr x));最大点
)
)
Lst
);调整LST表的数据结构 yaojing38 发表于 2023-10-23 11:32
(mapcar
'(lambda (x)
(list
这个是最小点点集,与最大点点集吧。我现在想做的是,分堆后,把每组的最小点与最大点之间,画一条直线。可能是我太笨,望赐教。
页:
[1]