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

0 Members and 2 Guests are viewing this topic.

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #600 on: April 23, 2016, 04:57:32 AM »
Rick,

The triangulation is 2.5d , so it means that it cannot handle point with same x and y.

In order to be capable to separate on Z, you would need a 3d triangulation and
this is bound to be way too slow for Autolisp.

ymg

rw2691

  • Newt
  • Posts: 133
Re: Triangulation (re-visited)
« Reply #601 on: April 23, 2016, 10:01:00 AM »
YMG,

So how will we deal with design models? The probability of field work having the same xy is slight, but designing a wall or building would usually have the same xy's. Likewise, topography volumes might be based on the same.

Rick
Hippocrates (400BC), "Life is short, craft long, opportunity fleeting, experiment treacherous, judgment difficult."

lamarn

  • Swamp Rat
  • Posts: 636
Re: Triangulation (re-visited)
« Reply #602 on: April 23, 2016, 12:23:23 PM »
Hi Rick i tried parts of the coding. Marko Ribar (i believe it was him) made the triangulation work in <current ucs>. To triangulate a wall you 'just' need to use this codimg after you set ucs the right way. (so that top view would be the view TO the wall). Check the treat ealier..

It is a great deal of handwork to make a real 3d triangulation for e.g. A bridge construction from multiple scans. I don't have the right workaround amd tools to do this in a fast matter. Most of the times some triangulation fo a detail is just what i need..
Design is something you should do with both hands. My 2d hand , my 3d hand ..

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #603 on: April 23, 2016, 12:35:44 PM »
Rick,

In order to handle a wall, what could work would be to have a closed breakline
follow the top and bottom of the wall.

This way the invalid triangle would be purged.

Just an idea, never really tried it.

Just the same no triangulation that I know of can
handle an overhanged section.

ymg

squirreldip

  • Newt
  • Posts: 114
Re: Triangulation (re-visited)
« Reply #604 on: April 23, 2016, 12:54:22 PM »
Vertical faces are generally handled by adding breaklines at very minor offsets (I usually use 0.5 to 1.0mm).

Another advantage of what I'm proposing above is that you would be able to deal with multiple surfaces - say you had a rock layer or water table under the ground, you would be able to cut cross sections and show multiple layers.

I'm hoping that the master Triangulation can be reworked to include a separate TIN: module.

I've added a screen capture : (had to revise FUZZ in triangulate to be smaller than 0.001 so it didn't remove the wall points)
« Last Edit: April 23, 2016, 01:26:40 PM by squirreldip »

rw2691

  • Newt
  • Posts: 133
Re: Triangulation (re-visited)
« Reply #605 on: April 23, 2016, 02:11:20 PM »
squirreldip,

I have tested your revision. All but one of the functions worked well. The TIN:READ has a few problems. I am a VL challenged person, so I rewrote the code with plain LISP. As such it also works well. In doing so I also had to add a function to replace the VL routines. It is TIN:GETSTRPOS.

I am glad you have done this because I have been wanting to have a READ/WRITE to files for the TIN's. Having that inclusion will allow the system to be more flexible and repeatable. I have also wanted a PICK ELEVATION function for design purposes.

Whether your entire concept should be adopted, however, I can't speak to... except that it looks like a lot of code changes and debugging to pull it off. Nevertheless, I can say that reviewing your code has caused me to have a better grasp of the TRIANGULATION program.

Code: [Select]
; find a string in a string - returns position of first letter - zero if none
(defun TIN:GETSTRPOS (ssub sall / lsub lall i n ret)
       (setq lall (strlen sall)
             lsub (strlen ssub)
             )
       (setq ssub (strcase ssub))
       (setq sall (strcase sall))
       (setq ret nil)
       (cond ((> lsub lall) 0)
             ((<= lsub lall) (setq i 1 n (1+ (- lall lsub)))
                             (while (and (not ret) (<= i n))
                                    (if (= ssub (substr sall i lsub))
                                        (setq ret i)
                                        (setq i (1+ i))
                                        )
                                    )
                             (if (= ret nil) (setq ret 0))
                             ret
                             )
             (T (if (= ssub sall) 1))
             )
       )
       

; TIN:READ reads the input file and returns a triangle list (lists of 3 3dpoint lists)
(defun TIN:READ (DiskFileName / DataFile DataLine P1 P2 P3 TL TLF X Y Z pos1 dat)
 (setq TLF nil dat 0)
 (if (setq DataFile (open DiskFileName "r"))
  (progn
   (while (setq DataLine (read-line DataFile))
          (setq dat (+ dat 1))
         
          (setq pos1 (TIN:GETSTRPOS "," DataLine))
          (setq X (atof (substr DataLine 1 (- pos1 1)))) ;; get X element of point
          (setq DataLine (substr DataLine (+ pos1 1))) ;; reduce DataLine to remainder
         
          (setq pos1 (TIN:GETSTRPOS "," DataLine))
          (setq Y (atof (substr DataLine 1 (- pos1 1)))) ;; get Y element of point
          (setq DataLine (substr DataLine (+ pos1 1))) ;; reduce DataLine to remainder
         
          (setq pos1 (TIN:GETSTRPOS "," DataLine))
          (setq Z (atof (substr DataLine 1 (- pos1 1)))) ;; get Z element of point
          (setq DataLine (substr DataLine (+ pos1 1))) ;; reduce DataLine to remainder
                     
          (setq P1 (list X Y Z))
         
          (setq pos1 (TIN:GETSTRPOS "," DataLine))
          (setq X (atof (substr DataLine 1 (- pos1 1)))) ;; get X element of point
          (setq DataLine (substr DataLine (+ pos1 1))) ;; reduce DataLine to remainder
         
          (setq pos1 (TIN:GETSTRPOS "," DataLine))
          (setq Y (atof (substr DataLine 1 (- pos1 1)))) ;; get Y element of point
          (setq DataLine (substr DataLine (+ pos1 1))) ;; reduce DataLine to remainder
         
          (setq pos1 (TIN:GETSTRPOS "," DataLine))
          (setq Z (atof (substr DataLine 1 (- pos1 1)))) ;; get Z element of point
          (setq DataLine (substr DataLine (+ pos1 1))) ;; reduce DataLine to remainder
                     
          (setq P2 (list X Y Z))
         
          (setq pos1 (TIN:GETSTRPOS "," DataLine))
          (setq X (atof (substr DataLine 1 (- pos1 1)))) ;; get X element of point
          (setq DataLine (substr DataLine (+ pos1 1))) ;; reduce DataLine to remainder
         
          (setq pos1 (TIN:GETSTRPOS "," DataLine))
          (setq Y (atof (substr DataLine 1 (- pos1 1)))) ;; get Y element of point
          (setq DataLine (substr DataLine (+ pos1 1))) ;; reduce DataLine to remainder
         
          (setq Z (atof DataLine)) ;; DataLine no longer has a delimiter
                     
          (setq P3 (list X Y Z))
         
          (setq TL (list P1 P2 P3))
          (setq TLF (append TLF (list TL)))
          ) ;; end while   
    (close DataFile)
  ) ; end progn
 ) ; end if
 (alert (strcat (itoa dat) " TIN's are imported."))
 TLF
) ; end TIN:READ

Thanks again for the new functions. They are important to me.

Rick.
« Last Edit: April 23, 2016, 02:20:37 PM by rw2691 »
Hippocrates (400BC), "Life is short, craft long, opportunity fleeting, experiment treacherous, judgment difficult."

rw2691

  • Newt
  • Posts: 133
Re: Triangulation (re-visited)
« Reply #606 on: April 23, 2016, 02:32:21 PM »
To all,

I have tested my routine for retaining same xy with different z's. I see that it does hang. Previously I had only tested it where there are no same xy's. Since it didn't break the system I assumed it would just keep a wall TIN and work.

Thanks for you patience.

Rick
Hippocrates (400BC), "Life is short, craft long, opportunity fleeting, experiment treacherous, judgment difficult."

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #607 on: April 23, 2016, 02:35:58 PM »
Robert,

So I tested with offset of 0.005 and yes it works.
A fuzz smaller than 0.001 will creates problem
in contours.

However it will not work for an overhang section.

The below image was done with program triang.

« Last Edit: April 23, 2016, 03:03:23 PM by ymg »

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #608 on: April 24, 2016, 04:56:31 AM »
Hi ymg. Any new update ?  :-)

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #609 on: April 25, 2016, 04:49:17 AM »
Topographer,

No, not at the moment, I am still traveling in Europe

ymg

squirreldip

  • Newt
  • Posts: 114
Re: Triangulation (re-visited)
« Reply #610 on: April 26, 2016, 12:50:58 PM »
@Rick:  Here's an update using your code.  VL isn't an issue for myself but if it is for others it's likely best to remove dependence on it.  I believe your subroutine would only be needed within the TIN:READ routine so I added it as a local function.

Also, I also probably have a similar grasp to the program as yourself - I really want to weed out any unnecessary code within each TIN:* routine.

@ymg:  I understand about the FUZZ.  Maybe FUZZ should be a local variable to the contouring - having something smaller is necessary for trying to emulate vertical walls (it's nice to have dimensions accurate to mm).

Edit:  Update to Triang2016...  Added TIN:PROG making it 'global' and added an (entmake) in TIN:DRAW to clear buffer.

Note - revised here:
https://www.theswamp.org/index.php?topic=9042.msg564324#msg564324
« Last Edit: April 26, 2016, 07:15:55 PM by squirreldip »

squirreldip

  • Newt
  • Posts: 114
Re: Triangulation (re-visited)
« Reply #611 on: April 26, 2016, 07:15:05 PM »
Revised Triang2016.lsp...

New routine (TIN:SECTIONPOINTTOPOINT P1 P2 TLIST), returns list of 2D distances (to P1) and elevations

Had to make a couple of local routines global:  TIN:REMDUPPOINT and TIN:BUTLAST

Edit - Link to latest:
https://www.theswamp.org/index.php?topic=9042.msg564537#msg564537
« Last Edit: April 28, 2016, 01:50:37 PM by squirreldip »

rw2691

  • Newt
  • Posts: 133
Re: Triangulation (re-visited)
« Reply #612 on: April 27, 2016, 04:35:20 PM »
squirreldip,

Here are some possible addon's ... NET, IMP, and ELV

They include some server functions to retain the User's active preferences for drafting

Code: [Select]
(defun c:net () ;; select an existing TIN network from drawing
       (princ "\nSelect TIN/3D-FACES")
       (alert "Choose existing 3DFACES")
       (setq ss (ssget '((0 . "3DFACE"))))
       (if ss
           (get_tin ss)
           (alert "No 3DFACES found.")
           )
       (princ)
       )

(defun c:imp () ;; import TIN network from disk file
       (setq TIN-NAME (getvar 'dwgname))
       (setq pos1 (TIN:GETSTRPOS ".dwg" TIN-NAME))
       (setq TIN-NAME (substr TIN-NAME 1 (- pos1 1)))
       (setq TIN-LIST (TIN:READ (strcat (getvar 'dwgprefix) TIN-NAME ".tin")))
       (if TIN-LIST
           (TIN:DRAW TIN-LIST)
           (alert "No TIN file found.")
           )
       (princ)
       )
       
(defun rw-disablesnap ()
       (setq actvsnap (getvar "osmode"))
       (setvar "osmode" 0)
       )

(defun rw-enablesnap ()
       (setvar "osmode" actvsnap)
       )

(defun rw-StoColor ()
       (setq olddrwcolor (getvar "cecolor"))
       (if (= setdrwcolor 0)
           (command "-color" "BYLAYER")
           (command "-color" setdrwcolor)
           )
       )

(defun rw-RclColor ()
       (setvar "cecolor" olddrwcolor)
       )
       
; save text size and style
(defun rw-AlterFont ()
       (setq saved_txtstyle (getvar "textstyle"))
       (setq saved_txtsize (getvar "textsize"))
       (setvar "textstyle" fntdsptyp)
       (princ)
       )

; restore text size and style
(defun rw-ResetFont ()
      (setvar "textstyle" saved_txtstyle)
      (setvar "textsize" saved_txtsize)
      (princ)
      )       
       
(defun c:elv ( / z pnt azm brg lstdir str1 hgtstr) ;; elevation... post the TIN elevation at cursor position
      (if (not TIN-LIST) (c:net))
      (if (not TIN-LIST) (c:imp))
      (if TIN-LIST
          (progn (alert "Select an elevation point")
                 
                 (rw-StoColor)
                 (rw-disablesnap)
                 (rw-AlterFont)
                 
                 (setq hgtstr (* 0.06 (getvar "ltscale")))
                 (setvar "cecolor" "1")
                 
                 (setq lstdir 0 z nil azm nil)
                 (mk_layer (list ".SRF-LBL" 1))
                       
                 (while (setq pnt (getpoint "\nPick elevation-point... "))
                        (setq Z (TIN:ELEVATIONATPOINT pnt TIN-LIST))     
                        (if z
                           (progn (setq str1 (rtos z))
                                  (if (setq azm (getangle pnt "\nDrag-direction for Label <def=last>... "))
                                      (setq brg (angtos azm 4 4))
                                      (setq brg lstdir)
                                      )
                                  (if (= brg "E") (setq brg 0.0))
                                  (command "-style" fntdsptyp fntdspshp hgtstr "1.00" fntobldeg "n" "n" "n")
                                  (command "-TEXT" "J" "MC" pnt brg str1)
                                  (setq lstdir brg)
                                  ) ; end progn                     
                           (alert "No TIN found at location. ") ; no z
                           ) ; end if
                        ) ; end while
             
                 (rw-ResetFont)
                 (rw-enablesnap)
                 (rw-RclColor)
                 
                 (princ)
                 ) ; end progn
          (alert "No TIN found nor any file to import. ")
          ) ; end if         
      ) ; end elv

These are codes that I have depended on for my work. It's a pain when software wrecks how you work. I try to program for the least impact on a user's sensibilities. One caution however... I program for US Feet and Degrees. No Metric in my area of the woods.

**********************************

An after thought and edit... the codes above are what I did to make Triang2016 compatible with TriangV0.6.7.0. They are prior to your recent improvements. To make my codes for NET and IMP I had added the following code to the very bottom of the GET_TIN function...

Code: [Select]
   ;; added for TIN:WRITE
   ;;==========================================   
   (acet-ui-progress "Finding triangles :" (/ (length tl) (setq count 10))) ;; starts acet-ui-progress bar
   (setq TIN-LIST nil) ; Initiate list of faces
   (foreach tr tl
     (setq TIN-LIST (append TIN-LIST (list (list (nth (car tr) pl)
                                                 (nth (cadr tr) pl)
                                                 (nth (caddr tr) pl)
                                                 )
                                           )
                            )
         )
     (prog count) ;; updates acet-ui-progress
     ) ; end foreach
   (acet-ui-progress) ;; ends acet-ui-progress bar
   (setq TIN-NAME (getvar 'dwgname))
   (setq pos1 (TIN:GETSTRPOS ".dwg" TIN-NAME))
   (setq TIN-NAME (substr TIN-NAME 1 (- pos1 1))) ;; get X element of point
   (TIN:WRITE (strcat (getvar 'dwgprefix) TIN-NAME ".tin") TIN-LIST) ;; save to disk
   ;;==========================================   
) ; end get_tin

It and the IMP codes are simply creating default name for the TIN-LIST, which is name of the active drawing with a ".tin" extension.

Rick
« Last Edit: April 28, 2016, 07:00:13 AM by rw2691 »
Hippocrates (400BC), "Life is short, craft long, opportunity fleeting, experiment treacherous, judgment difficult."

rw2691

  • Newt
  • Posts: 133
Re: Triangulation (re-visited)
« Reply #613 on: April 28, 2016, 09:31:29 AM »

I have tested TIN:SECTIONPOINTTOPOINT. Below is the station and elevation output that it gave. Am I right to think that it should remove duplicates?

(
(9.09495e-013 655.968)
(4.82322 655.825) (4.82322 655.825)
(7.16779 656.057) (7.16779 656.057)
(8.54808 656.179) (8.54808 656.179)
(9.70276 655.841)
(10.0535 655.94) (10.0535 655.94)
(10.2378 656.041) (10.2378 656.041)
(13.0985 655.765) (13.0985 655.765)
(14.3455 655.156) (14.3455 655.156)
(20.8435 655.219)
(22.7677 655.213) (22.7677 655.213)
(23.3764 655.234) (23.3764 655.234)
(24.4665 655.195)
(34.6615 654.343) (34.6615 654.343)
(42.6784 653.661) (42.6784 653.661)
(46.4816 653.536)
(50.5878 653.314) (50.5878 653.314)
(54.2639 652.772) (54.2639 652.772)
(57.991 651.973) (57.991 651.973)
(72.7575 650.857)
(94.1628 649.526) (94.1628 649.526)
(106.853 649.14) (106.853 649.14)
(115.254 648.518) (115.254 648.518)
(116.036 648.46) (116.036 648.46)
(123.034 646.986) (123.034 646.986)
(138.04 645.694) (138.04 645.694)
(157.051 644.23) (157.051 644.23)
(168.358 643.21) (168.358 643.21)
(194.807 640.797)
)

Rick
Hippocrates (400BC), "Life is short, craft long, opportunity fleeting, experiment treacherous, judgment difficult."

squirreldip

  • Newt
  • Posts: 114
Re: Triangulation (re-visited)
« Reply #614 on: April 28, 2016, 12:52:40 PM »
Rick,

Little busy at work today (and a while) but I thought I removed the duplicates.  I'll recheck and if you can post your tin and section line I'll confirm what I'm getting.