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

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #135 on: March 07, 2014, 10:38:39 AM »
Hello ymg nice job but , I find a bug in your code and i dont know why.

I write TIN ---> make TINS
I write CONT ----> open the contour window and gives me this error

Code - Auto/Visual Lisp: [Select]
  1. Select objects: Specify opposite corner: 71 found
  2. Select objects:
  3. Error: bad argument type: fixnump: nil

here is my dwg file ... Any options ?

Thanks

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #136 on: March 07, 2014, 04:40:42 PM »
with the  ContourTest.dwg  the lisp working fine but with my dwg is not working .Can you tell me what i am doing wrong ?
Thanks

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Triangulation (re-visited)
« Reply #137 on: March 07, 2014, 05:21:28 PM »
I think he may be on the other side of the world so you may need to give some time for a response.  8)
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.

chlh_jd

  • Guest
Re: Triangulation (re-visited)
« Reply #138 on: March 08, 2014, 01:43:20 AM »
chlh_jd,

Here is a revision with the bugs in contour generation removed.

Bear in mind, that this is still a work in progress, so the routine does  not clean themselves nicely on completion.

ymg
Thanks Ymg , it did fix the bug in the case "intv=0.25 majcnt=1.0"; but error in the case  "intv=0.1 majcnt=0.5".

And some suggestion in 'contour function:
1. defined lambda function will short codes
Code - Auto/Visual Lisp: [Select]
  1. (defun f1  ()
  2.     (setq  z1  (caddr p1)
  3.            z2  (caddr p2)
  4.            z1 (if (= z1 z) (setq z1 (- z1 1e-08)) z1)
  5.            z2 (if (= z2 z) (setq z2 (- z2 1e-08)) z2)
  6.            p1  (list (car p1) (cadr p1)))
  7.       (polar p1
  8.              (angle p1 p2)
  9.              (* (distance p1 p2) (/ (- z z1) (- z2 z1)))))
  10.  
to
Code - Auto/Visual Lisp: [Select]
  1. (if (equal (car p) (reverse (last p)))
  2.         (setq isclosed 1
  3.               p        (append p (list (cadr p))))
  4.         (setq isclosed 0
  5.               p1       (nth (caar p) pl)
  6.               p2       (nth (cadar p) pl)            
  7.               ent      (list (cons 10
  8.                                    (f1)));_
  9.               )
  10.         )
  11. ...
  12. (while (> (length p) 2)
  13.         (setq p1  (nth (caar p) pl)
  14.               p2  (nth (cadar p) pl)         
  15.               v1  (f1)
  16.               p1  (nth (caadr p) pl)
  17.               p2  (nth (cadadr p) pl)        
  18.               v2  (f1)
  19.               p1  (nth (caaddr p) pl)
  20.               p2  (nth (cadr (caddr p)) pl)          
  21.               v3  (f1)
  22.               prv (car p)
  23.               nxt (caddr p)
  24.               p   (cdr p)
  25.               p1  (nth (caar p) pl)
  26.               p3  (nth (cadar p) pl)
  27.               p2  (nth (car prv) pl)
  28.               p4  (nth (car nxt) pl)
  29.               )
  30.   ...
  31.  
2. in the 'cl while loop , (setq n ...) before (while n ...) will reduce one time vl-position .
Code - Auto/Visual Lisp: [Select]
  1.       (setq n (vl-position nxt cl));_reduce 'vl-position one time , edited by GSLS(SS)
  2.       (while n
  3.         (setq cl  (vl-remove nxt cl)
  4.               n   (- n (rem n 2))
  5.               m   (nth n cl)
  6.               pol (cons m pol)
  7.               cl  (vl-remove m cl));_reduce 'nth one time
  8.         (if (vl-position nxt pol)
  9.           (setq nxt nil)
  10.           (setq nxt (reverse (car pol))))
  11.         (and (not (setq n (vl-position nxt cl)))
  12.              (setq pol (reverse pol)
  13.                    nxt (reverse (car pol))
  14.                    n   (vl-position nxt cl)
  15.                    ))
  16.         )
  17.  
3. define lambda function to replace vl-remove for build cl list loop will improve speed for huge list ; It also can be added position determine for > (/ (length lst) 2) , and use reverse to speed up .
Code - Auto/Visual Lisp: [Select]
  1.   ;; remove-nth for contour
  2.   (defun f2  (i lst / fst)
  3.     (setq fst nil)
  4.     (repeat (rem i 4)
  5.       (setq fst (cons (car lst) fst)
  6.             lst (cdr lst)))
  7.     (repeat (/ i 4)
  8.       (setq fst (vl-list* (cadddr lst)
  9.                           (caddr lst)
  10.                           (cadr lst)
  11.                           (car lst)
  12.                           fst)
  13.             lst (cddddr lst)))
  14.     (append
  15.       (reverse fst)
  16.       (cdddr lst)))
  17. ;;--------------
  18. ...
  19. (while (< j (length el))
  20.       (setq e  (nth j el)
  21.             z1 (nth (car e) zl)
  22.             z2 (nth (cadr e) zl)
  23.             zm (max zm z1 z2)
  24.             j  (1+ j))
  25.  ;_ Reduce size of el on zmax criteria.                                  ;
  26.       (if (and (= (rem j 3) 0) (< zm (+ z intv)))
  27.         (setq j  (- j 3)
  28.               el (f2 j el);_remove-nth for contour
  29.               zm -1e19))
  30.       (if (= z1 z)
  31.         (setq z1 (- z1 1e-8)))          ; If on Interval we disturb         ;
  32.       (if (= z2 z)
  33.         (setq z2 (- z2 1e-8)))          ; the z value a little.             ;
  34.       (if (or (< z1 z z2) (> z1 z z2))
  35.         (setq cl (cons e cl))           ; Edge is added to Crossed List     ;
  36.         )      
  37.       )
  38. ...
  39.  
4. don't shift 'clayer between major with minor ,just use (cons 8 ...)
Code - Auto/Visual Lisp: [Select]
  1. ...
  2. (setq seg       (length ent)
  3.             vcs (+ vcs seg)
  4.             ent (vl-list* (cons 0 "LWPOLYLINE")
  5.                           (cons 100 "AcDbEntity")
  6.                           (cons 100 "AcDbPolyline")
  7.                           (cons 8
  8.                                 (if (zerop (rem z majcnt))
  9.                                   "Contour Major"
  10.                                   "Contour Minor"))                      
  11.                           (cons 90 seg)                  
  12.                           (cons 70 isclosed)
  13.                           (cons 38 z)
  14.                           ent)
  15.             )
  16. ...
  17.  
« Last Edit: March 08, 2014, 02:18:41 AM by chlh_jd »

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #139 on: March 08, 2014, 05:37:28 AM »
I try the prof command but i can't change the scale .

And what ocd command do?

Can you give me some instructions for them ?

Thanks
« Last Edit: March 08, 2014, 05:46:34 AM by Topographer »

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #140 on: March 09, 2014, 08:09:55 AM »
Topographer,

Sorry for late reply.

In your drawing there is an incorrect triangle, so the sorting routine for the triangle list
crash on it.

I will check the get_tin routine to see if there is a bug there, or add something to prevent this.

Meanwhile use tin on the point and you will get the contour.

The prof routine is for making a profile from a set of 3dface, or a triangulation or yet again from
a 3dpolyline.  However it is not finished, so not ready for production.

OCD is a routine i got from AUGI forum, will be use to trim triangulation.  This is also not ready

ymg
« Last Edit: March 09, 2014, 08:24:29 AM by ymg »

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #141 on: March 09, 2014, 08:20:03 AM »
chlh_jd,

The previous version of the program had function like that.

But in an effort to squeeze every bit of speed I`ve put everything inline
thus gaining a tiny bit of speed by not calling a function.  On a 1000 points
triangulation this is about 50000 calls.

Second suggestion make sense to me.

Setting the current layer also saves me as many  calls to cons  as there are vertices in the contours.

Thanks for the helping hands.

ymg
« Last Edit: March 09, 2014, 10:14:42 AM by ymg »

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #142 on: March 09, 2014, 12:29:15 PM »
Thank you ymg

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #143 on: March 10, 2014, 04:26:04 AM »
Topographer,

The problem was in the GET_TIN routine.

Find a revision attached below.

By the way OCD stands for Outside Contour Delete.
So given a boundary polyline, it will trim everything that is outside
polyline.

ymg
« Last Edit: March 14, 2014, 04:28:22 AM by ymg »

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #144 on: March 10, 2014, 05:04:05 AM »
Thank you  ymg

I have two comments

1) OCD delete everething out of the polyline. This is a problem because  delete all my measure points, block,TINS , etc. Can  you fix it to delete only contours ?
It is good to have all the TINS .I forget  delete things in layer off
2) Can you add breaklines is important for correct TINS.

Nice job keep working we need you !!!!!

Thanks

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #145 on: March 10, 2014, 01:47:49 PM »
Topographer,

As stated earlier OCD did not originate with me.

It is in the program because we will need a  functionnality of that type
sooner or later.  Right now I did not even look at it although I know we
will need to modify it some.

Breaklines are certainly a needed additions.  I have done some exploratory
work on it.  Still not ready for prime time though.

Understand that I do this as a hobby, so I sometimes get fed up of looking
at it and move on to something else.  I let it cook then come back to it.

There is also some more work to be done with the contouring.  Namely we
need to highlight the depression contour.  There too I've done a bit of work
but not ready.  Another recurring problem is roundoff error with the fractionnal
contour.  So far still haven't got 100% reliability.

ymg

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #146 on: March 10, 2014, 01:56:44 PM »
I understand , Thank you.

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #147 on: March 11, 2014, 10:59:09 AM »
chlh_jd,

Quote
Thanks Ymg , it did fix the bug in the case "intv=0.25 majcnt=1.0"; but error in the case  "intv=0.1 majcnt=0.5".

I had to add a fuzz factor when we compare current contour z to see if the points z1 and z2 are equal to it.

I have also increased the disruption to 1e-03 from 1e-08.

Seems to have cured it!, so find attached the revision.

ymg
« Last Edit: March 14, 2014, 04:27:12 AM by ymg »

chlh_jd

  • Guest
Re: Triangulation (re-visited)
« Reply #148 on: March 12, 2014, 09:09:17 AM »
Hello Ymg ,
I'm sorry , did not read your every version .
Thank you for your reply and fixing the bug .
I'll take much time to test the new version after some time ,
Very pleased to test it and help some . :-)

chlh_jd

  • Guest
Re: Triangulation (re-visited)
« Reply #149 on: March 12, 2014, 09:31:21 AM »
Hi Ymg,
In my head , Longer code still requires a larger computer memory , so shorting the codes is necessary for reduce computer memory usage , if we have enough computer memory  , we also can build other ways list for contour routine  to replace a large number of 'nth' . So we have to compare the speed after complied the file .
In the contour routine , make a zl will speed up some .
Code: [Select]
...
(setq ti   (car (_VL-TIMES)) ; Re-initialize timer for Contouring
zl   (mapcar (function caddr) pl) ;_only for zlist                               
zmin (apply (function min) zl) ;_improve speed by GSLS(SS) 2014.3.2             
zmax (apply (function max) zl)
zmin (* (fix (/ zmin intv)) intv) ;_zmin, first level for contour.   (* (+ (fix (/ zmin intv)) 1) intv)
zmax (* (fix (/ zmax intv)) intv) ;_ zmax; last level for contour.               
z    zmin ; Initialize Current Contour level.             
...                 
)
  (setq tl (vl-sort tl
    (function
      (lambda (a b)
(< (max (nth (car a) zl)
(nth (cadr a) zl)
(nth (caddr a) zl))
   (max (nth (car b) zl)
(nth (cadr b) zl)
(nth (caddr b) zl)))))))
...
« Last Edit: March 12, 2014, 09:44:26 AM by chlh_jd »