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

0 Members and 2 Guests are viewing this topic.

XXL66

  • Newt
  • Posts: 99
Re: Triangulation (re-visited)
« Reply #285 on: June 19, 2014, 02:46:09 AM »
I'm have a problem with this example dwg
When using lines you get multiple point definitions and the sorting seems to go wrong.


(((1058.56 1136.88 5.35))
((1058.56 1136.88 5.35) 3)
((1058.95 1137.71 5.35))
((1058.95 1137.71 5.35) 4)
((1060.88 1136.68 5.5))
((1060.88 1136.68 5.5) 0)
((1060.88 1137.85 5.5))
((1060.88 1137.85 5.5) 1)
((1061.13 1137.71 5.35) 2)
((1061.13 1136.88 5.35))
((1061.13 1136.88 5.35) 3)
((1061.13 1136.88 5.35) 2)
((1061.13 1136.88 5.35) 0)
((1061.13 1137.71 5.35))
((1061.13 1137.71 5.35) 4)
((1061.13 1137.71 5.35) 1))

I tried it also with your lastest TIN version and this also has of course the same sorting.
There seem to be 7 pts in pl although there should only be 6.

Command: !pl
((1058.56 1136.88 5.35) (1058.95 1137.71 5.35) (1060.88 1136.68 5.5) (1060.88 1137.85 5.5) (1061.13 1137.71 5.35) (1061.13 1136.88 5.35) (1061.13 1137.71 5.35))
Command: !cdtl
((1 6) (4 0) (4 5) (3 6) (2 5))

I tried different sorting alternatives but none seem to work, removing the duplicates first for me is not an option (because of the constraint indices added in the list).


XXL66

  • Newt
  • Posts: 99
Re: Triangulation (re-visited)
« Reply #286 on: June 19, 2014, 02:56:38 AM »
Code: [Select]
 
(setq pl (vl-sort pl
  '(lambda (x y)
     (cond
       ((equal (car (car x)) (car (car y)) 0.001)
(< (cadr (car x)) (cadr (car y)))
       )
       ((< (car (car x)) (car (car y))))
     )
   )
)
)

adding a fuzz to the sort seems to solve it

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #287 on: June 19, 2014, 10:11:39 AM »
nice job ymg. Can you  modified so that Points Natural Ground remain on their original layer ?

Thanks

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #288 on: June 19, 2014, 10:21:59 AM »
topographer,

Just remove or rem out this line at beginning of program.

Code: [Select]
(entmod (subst (cons 8 ptlay) (assoc 8 ent) ent))

As I said the layer handling is not proper as it is.
Not sure how to go about it, the goal being to be
able to have more than one TIN per drawing and
do volumetry.

ymg

motee-z

  • Newt
  • Posts: 40
Re: Triangulation (re-visited)
« Reply #289 on: August 21, 2014, 03:00:15 PM »
Long time not hear from ymg about developing triangulation

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #290 on: August 25, 2014, 05:12:45 AM »
Any news about Profile Along An Alignment ;

d2010

  • Bull Frog
  • Posts: 326
Re: Triangulation (re-visited)
« Reply #291 on: August 25, 2014, 06:51:45 AM »
Didge;
I have used this library:
http://www.cs.cmu.edu/~quake/triangle.html
But it is to be use with your C++ solutions.   :-(
You can transform C++ script,  or C C++ algorithms ,into autolisp-source-automatically.
Have fun ,you with youtube==
www.youtube.com/watch?v=91mwgtNSIrE
 :roll:
Our  compilator.EXE can transform C++ to autolisp and reverse, lsp2cpp
Downloading  the full version, from:
http://lisp2arx.3xforum.ro/post/22/1/DOWNLOADING_vlacompilator_Here_/
You make user-account, and you  click again...on blue-blue-string...
Full tested in WindowsXP.
Best Regards..
« Last Edit: August 27, 2014, 07:08:04 AM by d2010 »

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #292 on: August 26, 2014, 11:38:32 AM »
Quote
Long time not hear from ymg about developing triangulation

Been on vacation and will remain at it until October.

Till then not much progress to expect.

ymg

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Triangulation (re-visited)
« Reply #293 on: August 26, 2014, 02:57:58 PM »
Enjoy your time off.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Triangulation (re-visited)
« Reply #294 on: August 26, 2014, 03:57:29 PM »

lamarn

  • Swamp Rat
  • Posts: 636
Re: Triangulation (re-visited)
« Reply #295 on: August 27, 2014, 04:55:03 AM »
To make TIN surfaces for walls i need to 3D rotate point temporary. see jpg
Would it be possible to make the function work with the local UCS (wall view) set.
I noticed some trans functions convert it to WCS.
Thanks in regard
Hans
Design is something you should do with both hands. My 2d hand , my 3d hand ..

lamarn

  • Swamp Rat
  • Posts: 636
Re: Triangulation (re-visited)
« Reply #296 on: August 29, 2014, 03:56:05 AM »
I am breaking my head to re-write this code so this works in user UCS.
There is something thats fixes the TIN to be created in WCS. What could it be?
Would like a achieve likewise code so i I do have to rotate3D the point to get right results..


Code: [Select]
;******************************************************************;
; TRIANGULATE - Lisp command to create a TIN from 3D points.       ;
; ===========                                                      ;
;                                                                  ;
; Written by Daniele Piazza, ADN member Mechanical Solution s.r.l. ;
; http://pdcode.com/code.htm                                       ;
;                                                                  ;
; Original C coding "Triangulate"  written by PAUL BOURKE          ;
; http://astronomy.swin.edu.au/~pbourke/modelling/triangulate/     ;
;                                                                  ;
; This program triangulates an irregular set of points.            ;
; You can replace some code (sorting, list manipulation,...) with  ;
; VLisp functions to reduce the execution time.                    ;
;                                                                  ;
; This code is not seriously tested, if you find a bug...sorry!!   ;
; Goodbye, Daniele                                                 ;
;*******************************************************************
;
;;
;;  Changes by CAB 03/13/06
;;  replaced the GETCIRCIRCUMCIRCLE routine
;;
(defun C:TRIANGULATE (/ fuzzy nulllist ss1 ptlst nv supertriangle trianglelst i j k edgelst
                        circle pt flag perc)

(setq OLDCMD (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command ".UNDO" "GROUP")
(setq OLDSNAP (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq fuzzy 1e-8)   ; tolerance in equality test
(setq nulllist nil)
 
(princ "\nSelect points...")
(setq ss1 (ssget '((0 . "POINT"))))
(setq start (getvar "date") THINK-CNT 0)            ; initiate timer & Progress Spinner Counter
(setq ptlst (getptlist ss1))                        ; convert selection set to point list
(setq ptlst (xsort ptlst))                          ; sort point list by X co-ordinate
(setq nv (length ptlst))      ; number of points
(setq supertriangle (findsupertriangle ptlst))      ; find super triangle
(setq ptlst (append ptlst supertriangle))      ; append coordinates to the end of vertex list
(setq trianglelst (list (list supertriangle nil)))  ; add supertriangle to the triangle list

(setq i 0)
(setq cab 0) ; CAB debug
(while (< i nv)
   (THINKING (strcat "Processing TIN - " (itoa (/ (* i 100) nv)) "%    "))  ; update progress spinner
   (setq pt (nth i ptlst))
   (setq edgelst nil)                                ; initialize edge buffer
   (setq j 0)
   (while (and trianglelst (setq triangle (car (nth j trianglelst))))
     (setq flag T)
     (if (not (cadr (nth j trianglelst)))
       (progn
         (setq circle (getcircircumcircle triangle))       ; calculate circumcircle   
(if (< (+ (caar circle) (cadr circle)) (car pt))  ; test point x and (pt) location
   (setq trianglelst (nth_subst j (list (car (nth j trianglelst)) T) trianglelst))
)
(if (isinside pt circle)
   (setq edgelst     (addtriangleedges triangle edgelst)
trianglelst (nth_del j trianglelst)
flag      nil
   )
)
       ) ; end progn
     )   ; end if
     (if flag (setq j (1+ j)) )
   ) ; end while loop
   (setq edgelst (removedoublyedges edgelst fuzzy nulllist))           ; remove all doubly specified edges
   (setq trianglelst (addnewtriangles pt edgelst trianglelst))         ; form new triangles for current point
   (setq i (1+ i))                                                     ; get next vertex
) ; end while loop
(setq trianglelst (purgetrianglelst trianglelst supertriangle fuzzy)) ; remove triangles with supertriangles edges

(foreach triangle (mapcar 'car trianglelst)                           ; draw triangles
   (drawtriangle triangle)
)

(setvar "OSMODE" OLDSNAP)
(setq OLDSNAP nil)
(command ".UNDO" "END")
(setq stop (getvar "date"))
(princ (strcat "\r TIN Complete - Elapsed time: " (rtos (* 86400.0 (- stop start)) 2 2) " secs."))
(setvar "CMDECHO" OLDCMD) 
(princ)
)



; XSORT - Original Shell Sort function replaced with VLISP sort (much quicker :-)  ;
;                                                                                        ;
(defun XSORT ( PTLST /)
  (vl-sort PTLST (function (lambda (e1 e2) (< (car e1) (car e2)) ) ) )
)

; NTH_DEL ;
; ;
; delete the n item in the list (by position, not by value!!) ;
; ;
; Elimina l'oggetto che si trova nella posizione N della lista LST. L'utilizzo di ;
; funzioni ricorsive,oltre a non assicurare maggiore velocità, può creare problemi;
; di overflow dello stack in caso di liste molto lunghe. ;
(defun NTH_DEL (N LST / l)
(repeat n
  (setq l (cons (car lst) l)
lst (cdr lst)
  )
)
(append (reverse l)(cdr lst))
)

; NTH_SUBST ;
; ;
; Replace the index element in the list with new element. This function is ;
; recursive this is not a great solution with a large amount of data. ;
; ;
(defun NTH_SUBST (index new Alist)
(cond
  ((minusp index) Alist)
  ((zerop index)(cons new (cdr Alist)))
  (T (cons (car Alist)(nth_subst (1- index) new (cdr Alist))))
)
)

; GETPTLIST ;
; ;
; sset -> list (p1 p2 p3 ... pn) ;
; ;
(defun GETPTLIST (ss1 / i pt ptlst)
(if (not (zerop (sslength ss1)))
  (progn
   (setq i 0)
   (while
     (setq pt (ssname ss1 i))
     (setq ptlst (cons (cdr (assoc 10 (entget pt))) ptlst))
     (setq i (1+ i))
   )
  )
)
ptlst
)

; FINDSUPERTRIANGLE ;
; ;
; Search the supertriangle that contain all points in the data set ;
; ;
(defun FINDSUPERTRIANGLE (ptlst / xmax xmin ymax ymin dx dy dmax xmid ymid
          trx1 trx2 trx3 try1 try2 try3 trz1 trz2 trz3
)
(setq xmax (apply 'max (mapcar 'car ptlst))
       xmin (apply 'min (mapcar 'car ptlst))
       ymax (apply 'max (mapcar 'cadr ptlst))
       ymin (apply 'min (mapcar 'cadr ptlst))
       dx (- xmax xmin)
       dy (- ymax ymin)
       dmax (max dx dy)
       xmid (* (+ xmax xmin) 0.5)
       ymid (* (+ ymax ymin) 0.5)
       trx1 (- xmid (* dmax 2.0))
       try1 (- ymid dmax)
       trz1 0.0
       trx2 xmid
       try2 (+ ymid dmax)
       trz2 0.0
       trx3 (+ xmid (* dmax 2.0))
       try3 (- ymid dmax)
       trz3 0.0       
)
(list (list trx1 try1 trz1)
       (list trx2 try2 trz2)
       (list trx3 try3 trz3)
)
)




;;=============================================================
;;  Changes by CAB 03/13/06
;;  replaced the GETCIRCIRCUMCIRCLE routine
;;=============================================================

(defun getcircircumcircle (triangle / p1 p2 p3 pr1 pr2 cen rad bisector)
  ;;  return a pt list for a perpendicular bisector 20 units long
  (defun bisector (p1 p2 / perp_ang midpt)
    (setq p1       (list (car p1) (cadr p1)) ; make sure 2d point
          perp_ang (+ (angle p1 p2) (/ pi 2.0))) ; perpendicular angle
    (setq midpt (mapcar '(lambda (pa pb) (+ (/ (- pb pa) 2.0) pa)) p1 p2))
    (list (polar midpt perp_ang 10) (polar midpt (+ pi perp_ang) 10))
  )
  (setq p1  (car triangle)
        p2  (cadr triangle)
        p3  (caddr triangle)
        pr1 (bisector p1 p2)
        pr2 (bisector p1 p3)
        cen (inters (car pr1) (cadr pr1) (car pr2) (cadr pr2) nil)
        rad (distance cen p1)
  )
  (list cen rad)
)
;;=============================================================



; ISINSIDE ;
; ;
; test if pt is inside a circle ;
; ;
(defun ISINSIDE (pt circle)
(setq ctr (car circle)
       rad (cadr circle)
)
(< (distance pt ctr) rad)
)

; ADDTRIANGLEEDGES ;
; ;
; add triangle edges at the edge queue ;
; ;
(defun ADDTRIANGLEEDGES (triangle edgelst)
(append edgelst (list (list (car triangle)  (cadr triangle))
                       (list (cadr triangle) (caddr triangle))
                       (list (caddr triangle)(car triangle))
                 )
)
)

; DRAWTRIANGLE ;
; ;
; the fun side of the algorithm. Draw triangulation. ;
; ;
(defun DRAWTRIANGLE (triangle)
  (entmake (list (cons 0 "3DFACE") (cons 10 (car triangle))  (cons 11 (caddr triangle))
                                   (cons 12 (cadr triangle)) (cons 13 (cadr triangle))))
)

; EQUALMEMBER ;
; ;
; Check if "item" is in "lista" or not by equality test. With real number the ;
; standard fuction "member" not work correctly. ;
; ;
(defun EQUALMEMBER (item lista fuzzy /)
(apply 'or (mapcar '(lambda (x) (equal x item fuzzy)) lista))
)         

; REMOVEDOUBLYEDGES ;
; ;
; Test the edge queue to remove duplicates (warning CW & CCW!) ;
; ;
(defun REMOVEDOUBLYEDGES (edgelst fuzzy nulllist /)
(setq j 0)
(while (< j (length edgelst))
  (setq k (1+ j))
  (while (< k (length edgelst))
   (if
    (or (and (equal (car  (nth j edgelst)) (car  (nth k edgelst)) fuzzy)
             (equal (cadr (nth j edgelst)) (cadr (nth k edgelst)) fuzzy)
        )
        (and (equal (car  (nth j edgelst)) (cadr (nth k edgelst)) fuzzy)
             (equal (cadr (nth j edgelst)) (car  (nth k edgelst)) fuzzy)
        )
    )
    (setq edgelst (nth_subst j nulllist edgelst)
          edgelst (nth_subst k nulllist edgelst)
    )
   )
   (setq k (1+ k))
  )
  (setq j (1+ j))
)
edgelst
)

; ADDNEWTRIANGLES ;
; ;
; Add new triangle generated by pt to triangle list. ;
; ;
(defun ADDNEWTRIANGLES (pt edgelst trianglelst / j triangle )
(setq j 0)
(while (< j (length edgelst))
  (if (nth j edgelst)
   (setq triangle    (cons pt (nth j edgelst))
         trianglelst (cons (list triangle nil) trianglelst)
   )
  )
  (setq j (1+ j))
)
trianglelst
)

; PURGETRIANGLELST ;
; ;
; replace all triangles that share a vertex with supertriangle ;
; ;
(defun PURGETRIANGLELST (trianglelst supertriangle fuzzy /)
(setq j 0)
(while (and trianglelst (setq triangle (car (nth j trianglelst))))
  (if (apply 'or
             (mapcar '(lambda (x) (equalmember x supertriangle fuzzy))
                     triangle
             )
      )
   (setq trianglelst (nth_del j trianglelst))
   (setq j (1+ j))
  )
)
)


;                                       ;
; THINKING - STANDARD PROGRESS SPINNER  ;
;                                       ;
(defun THINKING (prmpt)
  (setq THINK-CNT (1+ THINK-CNT))
  (princ (strcat "\r" (nth (rem THINK-CNT 4) '("\|" "\/" "\-" "\\")) prmpt))
)


; ********************************* END OF CODING *******************************************
(princ "\n'TRIANGULATE' Loaded \n")
(princ)

Design is something you should do with both hands. My 2d hand , my 3d hand ..

RAYAKMAL

  • Guest
Re: Triangulation (re-visited)
« Reply #297 on: September 12, 2014, 09:19:55 AM »
I modified C:Prof to C:Sect.
What I was trying to accomplish is to create a sectioning function using available codes

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Sect ( )
  2.    (prompt "\nSelect a Linear Entity: ")
  3.    (if (setq ent (entsel "\n. Select Line: "))
  4.       (progn        
  5.          (setq enm  (car ent))    
  6.          (setq dtot (vlax-curve-getDistAtPoint enm (vlax-curve-getEndPoint enm)))
  7.          (setq tn nil)
  8.          (setq ss   (ssget "_X" '((0 . "3DFACE"))))
  9.          (get_tin ss) ;; Output from get_tin: PL & TL (Global variables)        
  10.          (setq nl (get_neighbour tl))
  11.  
  12.          (setq  pobj (vlax-ename->vla-object enm)            
  13.                 prof nil          
  14.          )
  15.          (setq i (+ (vlax-curve-getEndParam enm) 1))
  16.  
  17.          (while (setq p (vlax-curve-getPointAtParam enm (setq i (1- i))))
  18.             (setq tn (triloc p pl tl nl)
  19.                   tr (nth tn tl)
  20.                   t1 (nth (car tr) pl)
  21.                   t2 (nth (cadr tr) pl)
  22.                   t3 (nth (caddr tr) pl)
  23.                   prof (cons (list (vlax-curve-getDistAtPoint enm p)
  24.                                    (caddr (getz p t1 t2 t3))
  25.                              )
  26.                              prof
  27.                        )
  28.             )
  29.          )
  30.          (setq p0 (vlax-curve-getStartPoint enm)
  31.                tn (triloc p0 pl tl nl)    tr (nth tn tl)
  32.                t1 (nth (car tr) pl) t2 (nth (cadr tr) pl) t3 (nth (caddr tr) pl)
  33.              dist 0.0
  34.            lastd 0.0
  35.             dtot (vlax-curve-getDistAtPoint enm (vlax-curve-getEndPoint enm))          
  36.           found t
  37.          )
  38.          (while (and (< dist dtot) found)
  39.             (setq tn (triloc p0 pl tl nl)
  40.                   tr (nth tn tl)
  41.                   t1 (nth (car tr) pl)
  42.                   t2 (nth (cadr tr) pl)
  43.                   t3 (nth (caddr tr) pl)
  44.                   el (list (list t1 t2) (list t2 t3) (list t3 t1))
  45.                found nil
  46.              )    
  47.             (foreach lin el        
  48.                (if (setq p1 (car (intersections (setq linobj (mk_lwp lin)) pobj)))
  49.                  (progn
  50.                    (setq dist (vlax-curve-getDistAtPoint enm p1))
  51.                       (if (> dist lastd)
  52.                         (setq  prof (cons (list dist (caddr (getz p1 t1 t2 t3))) prof)
  53.                                p0 (vlax-curve-getPointAtDist enm (+ dist 0.05))
  54.                                lastd dist
  55.                                found t                                
  56.                         )                      
  57.                       )                  
  58.                    )              
  59.                  )  
  60.                  (entdel (entlast))
  61.               )      
  62.            )
  63.            (setq prof (vl-sort prof (function (lambda (a b) (< (car a) (car b))))))
  64.            ;; Var prof now contains the list of the profile sorted.                  ;
  65.       );end progn
  66.    );end if
  67. )
  68.  

It worked. But I think it's too slow for cross sectioning on a very long polyline.
I found it interesting, if I choose a LINE I will get a profile with vertexes every 1 unit on the section; if I choose a POLYLINE, profile will be generated only on vertexes. I don't have any idea why this happens.

I tried to change (setq ss   (ssget "_X" '((0 . "3DFACE")))) with this (setq ss (ssget "F" (list pt1 pt2) '((0 . "3DFACE")))) where pt1 and pt2 were defined as vertexes of a line, but it returned error: error: bad argument type: fixnump: nil

I meant, ssget is ok, but the error is on this code:

Code - Auto/Visual Lisp: [Select]
  1.            (while (setq p (vlax-curve-getPointAtParam enm (setq i (1- i))))
  2.               (setq tn (triloc p pl tl nl)
  3.                     tr (nth tn tl)
  4.                     t1 (nth (car tr) pl)
  5.                     t2 (nth (cadr tr) pl)
  6.                     t3 (nth (caddr tr) pl)
  7.                     prof (cons (list (vlax-curve-getDistAtPoint enm p) (caddr (getz p t1 t2 t3))) prof)
  8.               )
  9.            )
  10.  

(vlax-curve-getPointAtParam enm (setq i (1- i))) <<<< This returned nil

Any idea how to fix this error?
Thanks in advance

« Last Edit: September 12, 2014, 11:20:38 AM by RAYAKMAL »

lamarn

  • Swamp Rat
  • Posts: 636
Re: Triangulation (re-visited)
« Reply #298 on: September 12, 2014, 10:49:02 AM »
Error: no function definition: GET_NEIGHBOUR
Missing function?
Design is something you should do with both hands. My 2d hand , my 3d hand ..

RAYAKMAL

  • Guest
Re: Triangulation (re-visited)
« Reply #299 on: September 12, 2014, 11:08:46 AM »
Error: no function definition: GET_NEIGHBOUR
Missing function?

No. it's in TriangV0.5.9.LSP written by YMG