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

0 Members and 3 Guests are viewing this topic.

rw2691

  • Newt
  • Posts: 133
Re: Triangulation (re-visited)
« Reply #675 on: July 09, 2016, 12:41:23 PM »
irot,

I expect that YMG is still busy with managing flood repairs... I can only ask whether you are selecting a polyline, is it 2d or 3d, and what operation are doing when it happens?

Rick
« Last Edit: July 09, 2016, 01:01:49 PM by rw2691 »
Hippocrates (400BC), "Life is short, craft long, opportunity fleeting, experiment treacherous, judgment difficult."

irot

  • Guest
Re: Triangulation (re-visited)
« Reply #676 on: July 11, 2016, 01:39:23 AM »
my file contains points and 3d polys as breaklines. when running TIN command, after setting up and selecting entities i get that error. another file works just fine so the problem has to do with my file, i just can't seem to find what's wrong with it. i've attached it if you care to have a look.

irot

  • Guest
Re: Triangulation (re-visited)
« Reply #677 on: July 11, 2016, 04:51:12 AM »
I may have found the reason. A friend notified me that I made an error importing the breaklines from Excel to BricsCAD, which caused me to try and create some 3d polys with only one vertex in them. I don't think they were created at all, but it may still throw the lisp off. When I imported correctly TIN command ran OK and created the 3d faces. XSHAPE and CONT seem to get the program to hang though, but it could be because the file is quite huge.

rw2691

  • Newt
  • Posts: 133
Re: Triangulation (re-visited)
« Reply #678 on: July 11, 2016, 11:23:10 AM »
irot,

I loaded your file and started a TIN. It contained 23,684 objects. After 25 minutes it was still processing and had not produced a TIN at that point. It may have muddled through, but I decided to not wait to see. So I closed down Autocad.

I then loaded the file again, and selected a small portion of the drawing. The top 658'. It built the TIN, and it respected all of the breaklines.

In both cases I did not get any errors.

Rick



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

rw2691

  • Newt
  • Posts: 133
Re: Triangulation (re-visited)
« Reply #679 on: July 11, 2016, 11:44:54 AM »
irot,

I forgot to check out contouring. When I built contours it only partially developed them and hung. There had only been 7511 TINs, and it did not report any error.

Keep in mind that I am using the file where you had not made any corrections. Nevertheless, since it built the TINs and CONT only works with TINs, I was surprised to see it fail.

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

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Triangulation (re-visited)
« Reply #680 on: July 11, 2016, 02:52:46 PM »
irot,

OVERKILL-PTS :
Total : 1474 duplicate point entities deleted...

And you still have duplicate points, but with different Z coordinates - see *.png...

This is why TRIANGULATE can't do it...

Attached also DWG with OVERKILLED-PTS...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

irot

  • Guest
Re: Triangulation (re-visited)
« Reply #681 on: July 12, 2016, 04:22:50 AM »
Thank you both for taking the time to check my file. I figure that BricsCAD's express tools engine is a little different than AutoCAD's. As i mentions, when "correctly" importing but with NO overkill I managed to get TINs however there was some error at the end and I get triangles crossing breaklines. CONT command runs only partialy. I can run it on a small number of triangles at a time to get all contours, but that takes forever on a file like this. Still haven't tried running the "overkilled" file.
As a side note, When trying my file on Civil 3D (that basicaly overkills by default) I get good looking triangles that works with CONT with no problem (just takes a while).

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Triangulation (re-visited)
« Reply #682 on: July 12, 2016, 04:48:11 AM »
Like I said, you have bad DWG... You still haven't answered on my question : What will you do with duplicate points that have different Z coordinates and same X and Y? Will you leave top one or bottom one... I hope that you understand that you must solve this problem if you want everything to go smoothly without bugs when triangulate and tincontours...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Triangulation (re-visited)
« Reply #683 on: July 12, 2016, 06:31:13 AM »
Hi, irot, now I used different OVERKILL-PTS algorithm :
Total : 1480 duplicate point entities deleted...

Now there is no problems with duplicate points, but now appeared one different issue : when triangulate-UCS.lsp it bugged when calculating circumcircle from 3 collinear points X values the same, but 3 different Y coordinates and 3 different Z coordinates... So I had to mod triangulate-UCS.lsp, but then again it did finish quite quick, but there were errors in TIN... I'll attach my archive for YMG to investigate if he had chance cos' I did quick mod... in (getcircumcircle) at the end I've put (if (and cp rr) ... ), meaning that sub may return nil, and that nil I've removed from al - active list here :
...
      (while el
        (if (or (member (reverse (car el)) el)
               (member (car el) (cdr el))
            )
            (setq el (vl-remove (reverse (car el)) el)
                  el (vl-remove (car el) el)
            )
            (setq al (cons (getcircumcircle p (car el)) al)
                  al (vl-remove nil al)
                  el (cdr el)
            )
        )
      )
...

OVERKILL-PTS-average-z.lsp now looks like this :

Code: [Select]
(defun c:overkill-pts-average-z ( / ss i ent entptlst k zcoords zaverage subentptlst ti )
  (prompt "\nSelect points...")
  (setq ss (ssget "_:L" '((0 . "POINT"))))
  (setq ti (car (_vl-times)))
  (repeat (setq i (sslength ss))
    (setq ent (ssname ss (setq i (1- i))))
    (setq entptlst (cons (list ent (cdr (assoc 10 (entget ent)))) entptlst))
  )
  (setq k 0)
  (foreach entpt entptlst
    (setq subentptlst (vl-remove-if-not '(lambda ( x ) (and (equal (car (cadr entpt)) (car (cadr x)) 1e-2) (equal (cadr (cadr entpt)) (cadr (cadr x)) 1e-2))) entptlst))
    (if subentptlst
      (progn
        (setq zcoords (mapcar 'caddr (mapcar 'cadr subentptlst)))
        (setq zaverage (/ (apply '+ zcoords) (float (length zcoords))))
        (setq subentptlst (vl-remove entpt subentptlst))
        (foreach subentpt subentptlst
          (if (not (vlax-erased-p (car subentpt)))
            (progn
              (setq k (1+ k))
              (entdel (car subentpt))
            )
          )
        )
        (if (vlax-erased-p (car entpt))
          (progn
            (entdel (car entpt))
            (setq k (1- k))
            (entupd (cdr (assoc -1 (entmod (subst (cons 10 (list (car (cadr entpt)) (cadr (cadr entpt)) zaverage)) (assoc 10 (entget (car entpt))) (entget (car entpt)))))))
          )
        )
      )
    )
  )
  (prompt "\nTotal : ") (princ k) (prompt " duplicate point entities deleted...")
  (prompt "\nElapsed time : ") (princ (rtos (/ (- (car (_vl-times)) ti) 1000.0) 2 50)) (prompt " seconds.")
  (princ)
)

I'll attach new DWG with points OK and my archive for YMG... You may test further with YMG's Triang and see if it's good... I am afraid I can't figure out why my TIN isn't good...

Regards, M.R.
« Last Edit: July 14, 2016, 02:27:19 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

irot

  • Guest
Re: Triangulation (re-visited)
« Reply #684 on: July 12, 2016, 06:37:09 AM »
ribarm:
I really don't have an answer for you. The points were imported directly from a survey fie that was sent to me and is compatible with an external program. I can't test that program to know if it works fine with it as I don't own a copy. But as I mentioned it DOES work well on Civil 3D so I guess that at least most of the surface will be correct.
I must ask: are the duplicates all raw points or some are vertices of the polys?
« Last Edit: July 12, 2016, 07:37:28 AM by irot »

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Triangulation (re-visited)
« Reply #685 on: July 12, 2016, 12:30:06 PM »
irot, I did triangulation at last... The problem was in both X and Y collinearity and duplicate points... I still leaved my version unchanged of triangulate-UCS.lsp so that I could track bugs... It did convex-hull triangulation without mistake - see DWG... Here is the code for preparation of points :

Code: [Select]
(defun c:overkill-pts-average-z-rem-X&Y-collinearity ( / LM:rand ss i ent entptlst k kk zcoords zaverage subentptlst entpt n d ti )

  ;; Rand  -  Lee Mac
  ;; PRNG implementing a linear congruential generator with
  ;; parameters derived from the book 'Numerical Recipes'

  (defun LM:rand ( / a c m )
      (setq m   4294967296.0
            a   1664525.0
            c   1013904223.0
            $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m)
      )
      (/ $xn m)
  )

  (prompt "\nSelect points...")
  (setq ss (ssget "_:L" '((0 . "POINT"))))
  (initget 6)
  (setq d (getdist "\nPick or specify fuzz distance for X&Y collinearity modifications <0.05> : "))
  (if (null d)
    (setq d 0.05)
  )
  (setq ti (car (_vl-times)))
  (repeat (setq i (sslength ss))
    (setq ent (ssname ss (setq i (1- i))))
    (setq entptlst (cons (list ent (cdr (assoc 10 (entget ent)))) entptlst))
  )
  (setq k 0)
  (foreach entpt entptlst
    (setq subentptlst (vl-remove-if-not '(lambda ( x ) (and (equal (car (cadr entpt)) (car (cadr x)) 1e-2) (equal (cadr (cadr entpt)) (cadr (cadr x)) 1e-2))) entptlst))
    (if subentptlst
      (progn
        (setq zcoords (mapcar 'caddr (mapcar 'cadr subentptlst)))
        (setq zaverage (/ (apply '+ zcoords) (float (length zcoords))))
        (setq subentptlst (vl-remove entpt subentptlst))
        (foreach subentpt subentptlst
          (if (not (vlax-erased-p (car subentpt)))
            (progn
              (setq k (1+ k))
              (entdel (car subentpt))
              (setq entptlst (vl-remove subentpt entptlst))
            )
          )
        )
        (if (vlax-erased-p (car entpt))
          (progn
            (entdel (car entpt))
            (setq k (1- k))
            (if (not (vl-position entpt entptlst))
              (setq entptlst (cons entpt entptlst))
            )
            (entupd (cdr (assoc -1 (entmod (subst (cons 10 (list (car (cadr entpt)) (cadr (cadr entpt)) zaverage)) (assoc 10 (entget (car entpt))) (entget (car entpt)))))))
            (setq entptlst (subst (list (car entpt) (list (car (cadr entpt)) (cadr (cadr entpt)) zaverage)) (assoc (car entpt) entptlst) entptlst))
          )
        )
      )
    )
  )
  (setq kk 0)
  (while (setq entpt (car entptlst))
    (setq entptlst (cdr entptlst))
    (setq subentptlst (vl-remove-if-not '(lambda ( x ) (equal (car (cadr entpt)) (car (cadr x)) 1e-2)) entptlst))
    (setq n 0.0)
    (setq subentptlst (vl-remove entpt subentptlst))
    (foreach subentpt subentptlst
      (setq kk (1+ kk))
      (entupd (cdr (assoc -1 (entmod (subst (cons 10 (list ((if (zerop (rem (setq n (1+ n)) 2)) + -) (car (cadr subentpt)) (* (LM:rand) (* 0.5 d))) (cadr (cadr subentpt)) (caddr (cadr subentpt)))) (assoc 10 (entget (car subentpt))) (entget (car subentpt)))))))
      (setq entptlst (subst (list (car subentpt) (cdr (assoc 10 (entget (car subentpt))))) (assoc (car subentpt) entptlst) entptlst))
    )
    (setq subentptlst (vl-remove-if-not '(lambda ( x ) (equal (cadr (cadr entpt)) (cadr (cadr x)) 1e-2)) entptlst))
    (setq n 0.0)
    (setq subentptlst (vl-remove entpt subentptlst))
    (foreach subentpt subentptlst
      (setq kk (1+ kk))
      (entupd (cdr (assoc -1 (entmod (subst (cons 10 (list (car (cadr subentpt)) ((if (zerop (rem (setq n (1+ n)) 2)) + -) (cadr (cadr subentpt)) (* (LM:rand) (* 0.5 d))) (caddr (cadr subentpt)))) (assoc 10 (entget (car subentpt))) (entget (car subentpt)))))))
      (setq entptlst (subst (list (car subentpt) (cdr (assoc 10 (entget (car subentpt))))) (assoc (car subentpt) entptlst) entptlst))
    )
  )
  (prompt "\nTotal : ") (princ k) (prompt " duplicate point entities deleted...")
  (prompt "\nTotal : ") (princ kk) (prompt " X&Y collinear point entities modifications made to apply slight X&Y collinearity...")
  (prompt "\nElapsed time : ") (princ (rtos (/ (- (car (_vl-times)) ti) 1000.0) 2 50)) (prompt " seconds.")
  (princ)
)

As you can see - preparation is now more complex and it lasts longer... I'll attach my archive and both prepared DWG and triangulated one... So it has no effect on break lines, just points are the issue, as you can see from the code... Please ignore my previous attachment... And if it's good for you in Civil3D, I must say that I don't have Civil, but just Vanilla ACAD, so I did this modifications to try to help both me and you...

[EDIT : Code changed and updated archive... Also now TIN was created without mistakes...]

Regards, M.R.
« Last Edit: July 17, 2016, 02:38:05 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Triangulation (re-visited)
« Reply #686 on: July 13, 2016, 12:04:18 PM »
I've updated my previous post... So read it carefully... Still I have no better option for checking collinearity then to change fuzz factor and retry process... triangulate-UCS.lsp should stay unchanged...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Triangulation (re-visited)
« Reply #687 on: July 14, 2016, 04:51:44 AM »
I've added this function into archive, but it's strongly recommended that be used with small number of points and only if you fail to get result with (*-rem-X&Y-collinearity.lsp + triangulate-UCS.lsp)... So if it finish it should prepare points for sure good for triangulate-UCS.lsp, but it's so slooow...

Code: [Select]
(defun c:overkill-pts-average-z-rem-collinearity-slow ( / LM:rand ss i ent entptlst k kk zcoords zaverage subentptlst entpt d z ang angl anglnth anglsrt angdltl angdnth angn p tst ti )

  ;; Rand  -  Lee Mac
  ;; PRNG implementing a linear congruential generator with
  ;; parameters derived from the book 'Numerical Recipes'

  (defun LM:rand ( / a c m )
      (setq m   4294967296.0
            a   1664525.0
            c   1013904223.0
            $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m)
      )
      (/ $xn m)
  )

  (prompt "\nSelect points...")
  (setq ss (ssget "_:L" '((0 . "POINT"))))
  (initget 6)
  (setq d (getdist "\nPick or specify fuzz distance for collinearity modifications <0.05> : "))
  (if (null d)
    (setq d 0.05)
  )
  (setq ti (car (_vl-times)))
  (repeat (setq i (sslength ss))
    (setq ent (ssname ss (setq i (1- i))))
    (setq entptlst (cons (list ent (cdr (assoc 10 (entget ent)))) entptlst))
  )
  (setq k 0)
  (foreach entpt entptlst
    (setq subentptlst (vl-remove-if-not '(lambda ( x ) (and (equal (car (cadr entpt)) (car (cadr x)) 1e-2) (equal (cadr (cadr entpt)) (cadr (cadr x)) 1e-2))) entptlst))
    (if subentptlst
      (progn
        (setq zcoords (mapcar 'caddr (mapcar 'cadr subentptlst)))
        (setq zaverage (/ (apply '+ zcoords) (float (length zcoords))))
        (setq subentptlst (vl-remove entpt subentptlst))
        (foreach subentpt subentptlst
          (if (not (vlax-erased-p (car subentpt)))
            (progn
              (setq k (1+ k))
              (entdel (car subentpt))
              (setq entptlst (vl-remove subentpt entptlst))
            )
          )
        )
        (if (vlax-erased-p (car entpt))
          (progn
            (entdel (car entpt))
            (setq k (1- k))
            (if (not (vl-position entpt entptlst))
              (setq entptlst (cons entpt entptlst))
            )
            (entupd (cdr (assoc -1 (entmod (subst (cons 10 (list (car (cadr entpt)) (cadr (cadr entpt)) zaverage)) (assoc 10 (entget (car entpt))) (entget (car entpt)))))))
            (setq entptlst (subst (list (car entpt) (list (car (cadr entpt)) (cadr (cadr entpt)) zaverage)) (assoc (car entpt) entptlst) entptlst))
          )
        )
      )
    )
  )
  (setq kk 0)
  (setq tst (cons nil tst))
  (while (not (eval (cons 'and tst)))
    (setq z -1 tst nil)
    (while (setq entpt (nth (setq z (1+ z)) entptlst))
      (foreach subentpt (vl-remove entpt entptlst)
        (setq ang (angle (cadr entpt) (cadr subentpt)))
        (setq angl (cons ang angl))
      )
      (setq anglnth (vl-sort-i angl '<))
      (setq anglsrt (mapcar '(lambda ( x ) (nth x angl)) anglnth))
      (setq angdltl (mapcar '(lambda ( a b ) (- b a)) anglsrt (cdr anglsrt)))
      (setq angdnth (vl-sort-i angdltl '<))
      (if (zerop (nth (car angdnth) angdltl))
        (progn
          (setq kk (1+ kk))
          (setq angn (nth (car angdnth) anglsrt))
          (setq p (polar (cadr entpt) (+ angn (* 0.5 pi)) (* (LM:rand) d)))
          (entupd (cdr (assoc -1 (entmod (subst (cons 10 p) (cons 10 (cadr entpt)) (entget (car entpt)))))))
          (setq entptlst (subst (list (car entpt) p) (assoc (car entpt) entptlst) entptlst))
          (setq tst (cons nil tst))
        )
        (setq tst (cons t tst))
      )
      (setq angl nil)
    )
  )
  (prompt "\nTotal : ") (princ k) (prompt " duplicate point entities deleted...")
  (prompt "\nTotal : ") (princ kk) (prompt " collinear point entities modifications made to apply slight collinearity...")
  (prompt "\nElapsed time : ") (princ (rtos (/ (- (car (_vl-times)) ti) 1000.0) 2 50)) (prompt " seconds.")
  (princ)
)

M.R.
« Last Edit: July 17, 2016, 02:38:45 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Triangulation (re-visited)
« Reply #688 on: July 16, 2016, 05:01:58 PM »
When I think more over, this is the fastest solution...

Code: [Select]
(defun c:overkill-pts-average-z-rem-collinearity-new ( / LM:rand ss i ent entptlst k zcoords zaverage subentptlst d pl plrand ti )

  ;; Rand  -  Lee Mac
  ;; PRNG implementing a linear congruential generator with
  ;; parameters derived from the book 'Numerical Recipes'

  (defun LM:rand ( / a c m )
      (setq m   4294967296.0
            a   1664525.0
            c   1013904223.0
            $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m)
      )
      (/ $xn m)
  )

  (prompt "\nSelect points...")
  (setq ss (ssget "_:L" '((0 . "POINT"))))
  (initget 6)
  (setq d (getdist "\nPick or specify fuzz distance for collinearity modifications <0.05> : "))
  (if (null d)
    (setq d 0.05)
  )
  (setq ti (car (_vl-times)))
  (repeat (setq i (sslength ss))
    (setq ent (ssname ss (setq i (1- i))))
    (setq entptlst (cons (list ent (cdr (assoc 10 (entget ent)))) entptlst))
  )
  (setq k 0)
  (foreach entpt entptlst
    (setq subentptlst (vl-remove-if-not '(lambda ( x ) (and (equal (car (cadr entpt)) (car (cadr x)) 1e-2) (equal (cadr (cadr entpt)) (cadr (cadr x)) 1e-2))) entptlst))
    (if subentptlst
      (progn
        (setq zcoords (mapcar 'caddr (mapcar 'cadr subentptlst)))
        (setq zaverage (/ (apply '+ zcoords) (float (length zcoords))))
        (setq subentptlst (vl-remove entpt subentptlst))
        (foreach subentpt subentptlst
          (if (not (vlax-erased-p (car subentpt)))
            (progn
              (setq k (1+ k))
              (entdel (car subentpt))
              (setq entptlst (vl-remove subentpt entptlst))
            )
          )
        )
        (if (vlax-erased-p (car entpt))
          (progn
            (entdel (car entpt))
            (setq k (1- k))
            (if (not (vl-position entpt entptlst))
              (setq entptlst (cons entpt entptlst))
            )
            (entupd (cdr (assoc -1 (entmod (subst (cons 10 (list (car (cadr entpt)) (cadr (cadr entpt)) zaverage)) (assoc 10 (entget (car entpt))) (entget (car entpt)))))))
            (setq entptlst (subst (list (car entpt) (list (car (cadr entpt)) (cadr (cadr entpt)) zaverage)) (assoc (car entpt) entptlst) entptlst))
          )
        )
      )
    )
  )
  (setq pl (mapcar 'cadr entptlst))
  (setq plrand (mapcar '(lambda ( x ) (polar x (* (LM:rand) (* 2.0 pi)) (* (LM:rand) d))) pl))
  (mapcar '(lambda ( a b / e ) (entupd (cdr (assoc -1 (entmod (subst (cons 10 b) (assoc 10 (entget (setq e (caar (vl-member-if '(lambda ( x ) (equal (cadr x) a 1e-50)) entptlst))))) (entget e))))))) pl plrand)
  (prompt "\nTotal : ") (princ k) (prompt " duplicate point entities deleted...")
  (prompt "\nTotal : ") (princ (length pl)) (prompt " collinear point entities modifications made to apply slight collinearity...")
  (prompt "\nElapsed time : ") (princ (rtos (/ (- (car (_vl-times)) ti) 1000.0) 2 50)) (prompt " seconds.")
  (princ)
)

HTH, M.R.
« Last Edit: July 17, 2016, 02:39:27 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Triangulation (re-visited)
« Reply #689 on: July 17, 2016, 07:05:15 AM »
I had mistake in my 3 rem-collinearity functions...

Forgot to add this lines :
            (if (not (vl-position entpt entptlst))
              (setq entptlst (cons entpt entptlst))
            )

Now fixed in attached archive... Sorry for mistake, it happens...
M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube