Author Topic: Triangulation (re-visited)  (Read 317166 times)

0 Members and 2 Guests are viewing this topic.

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #180 on: May 07, 2014, 06:54:07 PM »
The error message is quite clear.

Check line 402 in temp.dcl it correspond to this.

Code: [Select]
(write-line "      list = \"0 \\n0.0 \\n0.00
                                             \\n0.000\\n0.0000\";          " f)

Make sure that it is what you have in the lisp file.

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #181 on: May 08, 2014, 01:25:51 AM »
Why create the dcl file wrong in the temp folder.
This path created wrong
Quote
list = \"0 \\n0.0 \\n0.00
                                             \\n0.000\\n0.0000\";     

This is my tin.dcl full of erorss !! Can any tell me why? This happend sundenly. I unistall autocad and then i clear all temp files .I installl autocad again and i have the same problem. I don't now what to do, because this lisp works .....


pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #182 on: May 08, 2014, 06:04:04 AM »
The version 5.5 works fine .The new version has the problem.Can you fix it ?

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #183 on: May 08, 2014, 11:30:29 AM »
topographer,

Delete the tin.dcl that is in your temp folder.

Then make sure you change the line
in the generatedcl routine of the lisp file,
to read like so all in one line :

Code: [Select]
(write-line "      list = \"0 \\n0.0 \\n0.00\\n0.000\\n0.0000\"; " f)

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #184 on: May 08, 2014, 12:49:50 PM »
The attachment in reply #177 triangV0.5.6.lsp has been modified to correct
a bug in generatedcl routine.

ymg

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #185 on: May 08, 2014, 05:26:26 PM »
Thank you ymg

XXL66

  • Newt
  • Posts: 99
Re: Triangulation (re-visited)
« Reply #186 on: May 28, 2014, 09:22:25 AM »
Hi,

Added a TEXT entity selection option, thus texts representing elevations (f.e. "15.256" etc) We use a decimal sign in the EU, don't know about the US.

BTW, i cannot run these functions in ACAD2015, works fine in BricsCAD. TIN computes 25000 points in less then 25 seconds.

XXL66

  • Newt
  • Posts: 99
Re: Triangulation (re-visited)
« Reply #187 on: May 28, 2014, 12:38:13 PM »
i would like to try to add breaklines. I came across this document:
This method seems to be used in arcgis.

http://www.isprs.org/proceedings/xxix/congress/part4/28_XXIX-part4.pdf

If you can find any other interesting documents for implementing breaklines, please share it !

thx


ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #188 on: May 28, 2014, 01:07:59 PM »
xxl66,

I am working on adding breaklines.

However, due to the way Evgeny's triangulation work
I still have not find the proper way.

I do have another triangulation program (not published yet)
which should be easier to modify to accomodate breaklines.

If the breakline are defined before hand, it normally is sufficient
to prevent Triangle Swap when the common side between
to triangle on the stack are part of a breakline.

The bad news is that new triangulation is quite a bit slower
than Evgenyi's way, although probably still acceptable
if we get Breaklines.

ymg

XXL66

  • Newt
  • Posts: 99
Re: Triangulation (re-visited)
« Reply #189 on: May 29, 2014, 05:23:03 AM »
hi,

i would just add a 3D polyline option and add the vertices to the TIN. When TIN completed integrate the polylines, but of course easier said then done.
Maybe it is an idea when building the TIN to add some kind of property to the triangles when it is crossing or touching a poly(break)line. Thus the (after)computation only needs to use a selection of triangles involved with breaklines. Or maybe add entity name of the breakline as property.
Of course there should also be a verification for self-crossing and crossing polylines first.

XXL66

  • Newt
  • Posts: 99
Re: Triangulation (re-visited)
« Reply #190 on: May 30, 2014, 03:35:41 AM »
http://www.cs.berkeley.edu/~jrs/papers/inccdt.pdf

Found this very interesting document. There is pseudo code available for inserting segments into a delaunay triangulation.

XXL66

  • Newt
  • Posts: 99
Re: Triangulation (re-visited)
« Reply #191 on: May 30, 2014, 06:35:29 AM »
hi,

i was comparing speed between acad and bcad, in bcad 2500 take .3 seconds in acad 3+ seconds. for 10000 points in acad 33 seonds and bcad 3.6 seconds. It seems bcad is 10 times faster !
i wasn't able to test larger sets in acad. in bcad i have no trouble, even 60000 points. But when i try fe 25000 points in acad (2015) i get the following error.

Command: TIN
Select objects: all
25000 found
Select objects:
Usage: (acet-ui-progress [<label> [<max>] | <current>])

is this function integer limited?




ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #192 on: May 30, 2014, 10:15:35 AM »
XXL66

I had read the paper by Shewchuk.  It is indeed interesting.

A more interesting one would be An improved incremental algorithm for
constructing restricted Delaunay triangulations
by Marc Vigo Anglada

Although basic content and method is the same.  You need to evacuate
all triangle edges cut by a breakline and then re-triangulate the 2 polygons
created by the insertion of that edge.

The complexity of that operation is bound to slow down processing of a set of points.

A way out would be to begin by the insertion of all the edges, then as said previously
prevent any swapping of edges for these triangles.

But I am not too sure that Evgenyi's algorithm can be modified to do that.

I am not too concerned about huge triangulations.  For that there are all kind of
solutions.  What I am after is something that is very flexible and easy to operate
for triangulation on the order of a few thousands points.

The other suject that need to be addressed are boundaries and holes in the TIN.

ymg

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #193 on: May 30, 2014, 10:31:50 AM »
Here is the new triangulation as per Sloan's paper.

This is a first version, so there are certainly many ways
to optimize it and gain some speed.

To use it just call sloan instead of triangulate in the Tin program.

ymg

Code - Auto/Visual Lisp: [Select]
  1. ;;****************************************************************************;
  2. ;; sloan              by ymg                                                  ;
  3. ;; Delaunay's Triangulation as per S.W. Sloan's papers,                       ;
  4. ;; A Fast Algorithm For Constructing Delaunay Triangulations In The Plane.    ;
  5. ;; A Fast Algorithm For Generating Constrained Delaunay Triangulations.       ;
  6. ;;                                                                            ;
  7. ;;                                                                            ;
  8. ;;****************************************************************************;
  9.  
  10. (defun sloan (pl  / )
  11.    (setq version "V0.0.1")
  12.    (setq tl nil nl nil tn nil)  
  13.    (if pl
  14.       (progn
  15.          (setq   ti (car (_VL-TIMES));Initialize timer for Triangulation      ;
  16.                  bb (list (apply 'mapcar (cons 'min pl))
  17.                           (apply 'mapcar (cons 'max pl))
  18.                     )
  19.                xmin (caar bb)      
  20.                xmax (caadr bb)      
  21.                ymin (cadar bb)      
  22.                ymax (cadadr bb)
  23.                dmax (max (- xmax xmin)(- ymax ymin))
  24.                  ; Points are Scaled to 1 along Max of x and y dimensions     ;
  25.                  pl (mapcar
  26.                        (function
  27.                            (lambda (a) (list (/ (- (car a) xmin) dmax)
  28.                                              (/ (- (cadr a) ymin) dmax)
  29.                                              (caddr a)
  30.                                        )
  31.                            )        
  32.                        )
  33.                        pl
  34.                     )
  35.                  np (length pl)                      ; Number of Pts          ;
  36.                  
  37.                  ;Vertex of Supertriangle are appended to the Point list      ;
  38.                  pl (append pl (list '(-100. -100. 0.)'(100. -100. 0.)'(0. 100. 0.)))
  39.                
  40.                  tl (list (list np (1+ np)(+ np 2))) ; Init.  Triangle list.  ;
  41.                  nl (list (list nil nil nil))        ; Init.  Neighbour list. ;
  42.                 stk nil                              ; Init.  Swapping Stack. ;
  43.                  nt 0                                ; Init.  Triangles Index.;
  44.                  n -1                                ; Init.  Point Index.    ;
  45.                  
  46.          )              
  47.  
  48.          
  49.          ;Begin Insertion of Points                                           ;
  50.          (acet-ui-progress "Points Insertion:" np)
  51.          (repeat np
  52.            
  53.             (setq   n (1+ n)
  54.                     p (nth n pl)
  55.                    tn (triloc p pl tl nl) ; Index of Triangle containing p.   ;
  56.                    tc (nth tn tl)   ntc (nth tn nl)        
  57.                     a (car ntc)       b (cadr ntc)    c (caddr ntc)
  58.                    v1 (car  tc)       v2 (cadr  tc)   v3 (caddr  tc)
  59.                    t1 (list n v1 v2)  nt1 (list (+ nt 2) a (+ nt 1))
  60.                    nt (1+ nt)
  61.                    t2 (list n v2 v3)  nt2 (list tn b  (+ nt 1))
  62.                    nt (1+ nt)
  63.                    t3 (list n v3 v1)  nt3 (list (- nt 1) c tn)
  64.                    
  65.                    tl (subst t1 tc tl)             ; Updates Current Triangles;
  66.                    nl (subst nt1 ntc nl)           ; Updates Its Neighbours   ;
  67.  
  68.                    tl (append tl (list t2 t3))     ; Creates 2 New Triangles  ;
  69.                    nl (append nl (list nt2 nt3))   ; Creates 2 New Neighbours ;
  70.             )      
  71.             (if a (setq stk (cons tn stk)))
  72.             (if b
  73.                (progn
  74.                   (setq bn (nth b nl))
  75.                   (cond
  76.                      ((= (car   bn) tn) (setq nl (subst (list (- nt 1) (cadr bn) (caddr bn)) bn nl)))
  77.                      ((= (cadr  bn) tn) (setq nl (subst (list (car bn) (- nt 1)  (caddr bn)) bn nl)))
  78.                      ((= (caddr bn) tn) (setq nl (subst (list (car bn) (cadr bn) (- nt 1))   bn nl)))                  
  79.                   )
  80.                   (setq stk (cons (- nt 1) stk))
  81.                )
  82.             )  
  83.             (if c
  84.                (progn
  85.                   (setq cn (nth c nl))
  86.                   (cond
  87.                      ((= (car   cn) tn) (setq nl (subst (list nt (cadr cn) (caddr cn)) cn nl)))
  88.                      ((= (cadr  cn) tn) (setq nl (subst (list (car cn) nt  (caddr cn)) cn nl)))
  89.                      ((= (caddr cn) tn) (setq nl (subst (list (car cn) (cadr cn) nt)   cn nl)))                
  90.                   )
  91.                   (setq stk (cons nt stk))
  92.                )
  93.            )
  94.            
  95.            (while stk
  96.                 (setq   l (car stk) ln (nth l nl) lt (nth l tl)
  97.                         r (cadr ln) rn (nth r nl) rt (nth r tl)
  98.                       stk (cdr stk)    
  99.                 )      
  100.                 (cond
  101.                    ((= (car   rn) l) (setq v1 (car    rt) v2 (cadr  rt) v3 (caddr rt)
  102.                                             a (cadr   rn)  b (caddr rn)  c (caddr ln)))
  103.                    ((= (cadr  rn) l) (setq v1 (cadr   rt) v2 (caddr rt) v3 (car   rt)
  104.                                             a (caddr  rn)  b (car   rn)  c (caddr ln)))
  105.                    ((= (caddr rn) l) (setq v1 (caddr  rt) v2 (car  rt) v3 (cadr rt)
  106.                                             a (car    rn)  b (cadr  rn)  c (caddr ln)))
  107.                 )
  108.              
  109.                 (if (swap v1 v2 v3 n pl)
  110.                    (progn
  111.                       (setq tl (subst (list (car lt) (cadr lt) v3) lt tl)
  112.                             nl (subst (list (car ln) a r) ln nl)
  113.                                    
  114.                             tl (subst (list n v3 v1) rt tl)
  115.                             nl (subst (list l  b  c) rn nl)
  116.                       )
  117.                       (if a
  118.                          (progn
  119.                             (setq an (nth a nl))
  120.                             (cond
  121.                                ((= (car   an) r) (setq nl (subst (list l (cadr an) (caddr an)) an nl)))
  122.                                ((= (cadr  an) r) (setq nl (subst (list (car an) l  (caddr an)) an nl)))
  123.                                ((= (caddr an) r) (setq nl (subst (list (car an) (cadr an) l)   an nl)))                
  124.                             )
  125.                             (setq stk (cons l stk))
  126.                          )
  127.                       )
  128.                       (if b (setq stk (cons r stk)))
  129.                       (if c
  130.                          (progn
  131.                             (setq cn (nth c nl))
  132.                             (cond
  133.                                ((= (car   cn) l) (setq nl (subst (list r (cadr cn) (caddr cn)) cn nl)))
  134.                                ((= (cadr  cn) l) (setq nl (subst (list (car cn) r  (caddr cn)) cn nl)))
  135.                                ((= (caddr cn) l) (setq nl (subst (list (car cn) (cadr cn) r)   cn nl)))                
  136.                             )
  137.                          )
  138.                       )
  139.                    )
  140.                 )
  141.            )  
  142.          
  143.            (acet-ui-progress -1)
  144.          
  145.          ) ;We are done with points insertion. ;
  146.          
  147.          (acet-ui-progress)
  148.          
  149.          ;Purge Triangle list of any triangle that has a common vertex with supertriangle.        
  150.          (setq tl (vl-remove-if-not
  151.                      (function
  152.                         (lambda (a) (and (< (car a) np)(< (cadr a) np)(< (caddr a) np)))
  153.                      )
  154.                      tl
  155.                   )
  156.          )
  157.          ;; Here we will replace call to get neighour wit adjustment to nl          
  158.          (setq nl (getneighbour tl))
  159.          
  160.          ; Re-Scale the point list                                            ;
  161.          (setq pl (mapcar
  162.                      (function
  163.                          (lambda (a) (list (+ (* (car  a) dmax) xmin)
  164.                                            (+ (* (cadr a) dmax) ymin)
  165.                                            (caddr a)
  166.                                      )
  167.                          )
  168.                       )  
  169.                       pl
  170.                   )
  171.          )
  172.  
  173.          ;Create a layer and Draw the triangulation                           ;
  174.          
  175.          (mk_layer (list "TIN" 8))
  176.          (acet-ui-progress "Drawing 3DFaces:" (length tl))
  177.          (setq 3df '(0 . "3DFACE"))
  178.          (foreach tr tl
  179.             (entmakex (list 3df                        
  180.                            (cons 10 (nth (car tr)   pl))
  181.                            (cons 11 (nth (car tr)   pl))
  182.                            (cons 12 (nth (cadr tr)  pl))
  183.                            (cons 13 (nth (caddr tr) pl))
  184.                       )
  185.             )
  186.             (acet-ui-progress -1)
  187.          )
  188.          (acet-ui-progress)
  189.       )
  190.    )
  191.    
  192.    (princ (strcat "\n     CDT " version " - Elapsed time: " (rtos (/ (- (car (_VL-TIMES)) ti) 1000.) 2 4) " secs, " (itoa (length tl)) " 3DFACES"))
  193.  
  194. )
  195.  
  196.  
  197.  
  198. ;;****************************************************************************;
  199. ;; (swap l r pl)                                                              ;
  200. ;; Cline & Renka Swap Test                                                    ;
  201. ;;                                                                            ;
  202. ;; Given a triangle defined by three points indices v1, v2, v3                ;
  203. ;; and an index to pointp ,                                                   ;
  204. ;; Returns T is p is inside circle circumscribing triangle v1 v2 v3.          ;
  205. ;;                                                                            ;
  206. ;;****************************************************************************;
  207.  
  208. (defun swap (v1 v2 v3 p pl / cosa cosb sina sinb v1 v2 v3
  209.                              x1 x13 x1p x2 x23 x2p x3 xp
  210.                              y1 y13 y1p y2 y23 y2p y3 yp)
  211.    
  212.     (setq  p (nth p pl)  xp (car  p) yp (cadr  p)
  213.           v1 (nth v1 pl) x1 (car v1) y1 (cadr v1)
  214.           v2 (nth v2 pl) x2 (car v2) y2 (cadr v2)
  215.           v3 (nth v3 pl) x3 (car v3) y3 (cadr v3)
  216.          x13 (- x1 x3)  y13 (- y1 y3)
  217.          x23 (- x2 x3)  y23 (- y2 y3)
  218.          x1p (- x1 xp)  y1p (- y1 yp)
  219.          x2p (- x2 xp)  y2p (- y2 yp)
  220.         cosa (+ (* x13 x23) (* y13 y23))
  221.         cosb (+ (* x1p x2p) (* y1p y2p))  
  222.     )            
  223.     (cond
  224.        ((and (not (minusp cosa))(not (minusp cosb))) nil)
  225.        ((and (minusp cosa)(minusp cosb)))
  226.        (t  (setq sina (- (* x13 y23) (* x23 y13))
  227.                  sinb (- (* x2p y1p) (* x1p y2p))
  228.            )    
  229.            (minusp (+ (* sina cosb)(* sinb cosa)))
  230.        )         
  231.     )
  232. )  
  233.  
  234. ;;****************************************************************************;
  235. ;; (edgrpl l k r e)                                                           ;
  236. ;;                                                                            ;
  237. ;; Find edge in Triangle l which is adjacent to triangle K                    ;
  238. ;;                                                                            ;
  239. ;; Input: l Index of triangle                                                 ;
  240. ;;        r Index of triangle r in neighbour list                             ;
  241. ;;        v Replacement value                                                 ;
  242. ;;        e Neighbour List                                                    ;
  243. ;;                                                                            ;
  244. ;;****************************************************************************;
  245.  
  246. (defun edgrpl (l r v e /  ln tr)
  247.    (setq ln (nth l e) tr (nth r tl))
  248.    (cond
  249.        ((= (car   ln) r) (list v (cadr tr) (caddr tr)))
  250.        ((= (cadr  ln) r) (list (car tr) v (caddr tr)))
  251.        ((= (caddr ln) r) (list (car tr) (cadr tr) v))
  252.    )     
  253. )        
  254.  
  255.  
  256. ;;****************************************************************************;
  257. ;; (triloc p)                                                                 ;
  258. ;;                                                                            ;
  259. ;; Locates triangle which encloses point p using Lawson's Walk.               ;
  260. ;;                                                                            ;
  261. ;; Given p a point, Returns Index in tl of triangle containing the point.     ;
  262. ;; If outside the triangulation Return is nil.                                ;
  263. ;;                                                                            ;
  264. ;; Point List pl and Neigbour List nl are defined outside this routine.       ;
  265. ;; by ymg  August 2013                                                        ;
  266. ;; Optimized Speed and re-organized code January 2014                         ;
  267. ;; Nice but get lost when triangulation is disjointed.                        ;
  268. ;;****************************************************************************;
  269.  
  270. (defun triloc (p pl tl nl / notfound i p1 p2 p3 x x1 x2 x3 y y1 y2 y3)
  271.      
  272.     (if (not tn) (setq tn (/ (length tl) 2)))
  273.     (setq x (car p)  y (cadr p)  notfound t)  
  274.     (while (and notfound tn)        
  275.         (setq   i (nth tn tl)
  276.                p1 (nth (car   i) pl)  p2 (nth (cadr  i) pl) p3 (nth (caddr i) pl)                
  277.               x1x (- (car p1) x)  y1y (- (cadr p1) y)
  278.               x2x (- (car p2) x)  y2y (- (cadr p2) y)
  279.               x3x (- (car p3) x)  y3y (- (cadr p3) y)  
  280.         )      
  281.         (cond
  282.            ((minusp (- (* x1x y2y) (* y1y x2x))) (setq tn (car   (nth tn nl))))
  283.            ((minusp (- (* x2x y3y) (* y2y x3x))) (setq tn (cadr  (nth tn nl))))
  284.            ((minusp (- (* x3x y1y) (* y3y x1x))) (setq tn (caddr (nth tn nl))))          
  285.            ((setq notfound nil))      
  286.         )        
  287.     )  
  288.     tn
  289. )
  290.  
« Last Edit: May 30, 2014, 10:36:26 AM by ymg »

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #194 on: May 31, 2014, 01:42:30 PM »
Quote
Here is the new triangulation as per Sloan's paper.

This is a first version, so there are certainly many ways
to optimize it and gain some speed.

To use it just call sloan instead of triangulate in the Tin program.

Hi  ymg.I can not understand it ,can you explain me plesase. To load the sloan  we must copy sloan.lsp and paste in Triangulation.lsp ?

Thanks