Revision: 74239
          http://sourceforge.net/p/brlcad/code/74239
Author:   starseeker
Date:     2019-10-25 14:23:41 +0000 (Fri, 25 Oct 2019)
Log Message:
-----------
Have the closest-pt-on-tri calculation optionally return the point as well.

Modified Paths:
--------------
    brlcad/trunk/include/bg/tri_pt.h
    brlcad/trunk/src/libbg/tri_pt.c
    brlcad/trunk/src/libbrep/cdt_mesh.cpp
    brlcad/trunk/src/libbrep/cdt_ovlps.cpp

Modified: brlcad/trunk/include/bg/tri_pt.h
===================================================================
--- brlcad/trunk/include/bg/tri_pt.h    2019-10-25 13:57:47 UTC (rev 74238)
+++ brlcad/trunk/include/bg/tri_pt.h    2019-10-25 14:23:41 UTC (rev 74239)
@@ -39,11 +39,14 @@
 
 __BEGIN_DECLS
 
-BG_EXPORT extern double bg_tri_pt_dist(
-       point_t TP,
-       point_t V0,
-       point_t V1,
-       point_t V2
+/* The parameter closest_pt is optional = if supplied, it will hold the 
closest point found.
+ * The return value is the stance between TP and closest_pt */
+BG_EXPORT extern double bg_tri_closest_pt(
+       point_t *closest_pt,
+       const point_t TP,
+       const point_t V0,
+       const point_t V1,
+       const point_t V2
        );
 
 __END_DECLS

Modified: brlcad/trunk/src/libbg/tri_pt.c
===================================================================
--- brlcad/trunk/src/libbg/tri_pt.c     2019-10-25 13:57:47 UTC (rev 74238)
+++ brlcad/trunk/src/libbg/tri_pt.c     2019-10-25 14:23:41 UTC (rev 74239)
@@ -52,7 +52,7 @@
     V2ADD2(*p, t0, t1);
 }
 
-double bg_tri_pt_dist(point_t tp, point_t V0, point_t V1, point_t V2)
+double bg_tri_closest_pt(point_t *closest_pt, const point_t tp, const point_t 
V0, const point_t V1, const point_t V2)
 {
     vect_t diff, edge0, edge1;
     vect_t e0scaled, e1scaled;
@@ -169,6 +169,9 @@
     VSCALE(e0scaled, edge0, p[0]);
     VSCALE(e1scaled, edge1, p[1]);
     VADD3(closest, V0, e0scaled, e1scaled);
+    if (closest_pt) {
+       VMOVE(*closest_pt, closest);
+    }
     return DIST_PNT_PNT(tp, closest);
 }
 

Modified: brlcad/trunk/src/libbrep/cdt_mesh.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt_mesh.cpp       2019-10-25 13:57:47 UTC (rev 
74238)
+++ brlcad/trunk/src/libbrep/cdt_mesh.cpp       2019-10-25 14:23:41 UTC (rev 
74239)
@@ -40,6 +40,7 @@
 #include "bn/plot3.h"
 #include "bn/plane.h" /* bn_fit_plane */
 #include "bg/polygon.h"
+#include "bg/tri_pt.h"
 #include "brep.h"
 #include "./cdt_mesh.h"
 #include "./cdt.h"
@@ -1787,11 +1788,19 @@
     std::set<uedge_t> ue_s = uedges(t);
     std::set<uedge_t>::iterator u_it;
     double mdist = DBL_MAX;
+
+    point_t tp, v0, v1, v2;
+    VSET(tp, p.x, p.y, p.z);
+    VSET(v0, pnts[t.v[0]]->x, pnts[t.v[0]]->y, pnts[t.v[0]]->z);
+    VSET(v1, pnts[t.v[1]]->x, pnts[t.v[1]]->y, pnts[t.v[1]]->z);
+    VSET(v2, pnts[t.v[2]]->x, pnts[t.v[2]]->y, pnts[t.v[2]]->z);
+    double tdist = bg_tri_closest_pt(NULL, tp, v0, v1, v2);
+
     for (u_it = ue_s.begin(); u_it != ue_s.end(); u_it++) { 
        uedge_t ue = *u_it;
        ON_Line l(*pnts[ue.v[0]], *pnts[ue.v[1]]);
        double dline = p.DistanceTo(l.ClosestPointTo(p));
-       if (dline < mdist) {
+       if (dline < mdist && dline >= tdist) {
            mdist = dline;
            result = ue;
        }

Modified: brlcad/trunk/src/libbrep/cdt_ovlps.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt_ovlps.cpp      2019-10-25 13:57:47 UTC (rev 
74238)
+++ brlcad/trunk/src/libbrep/cdt_ovlps.cpp      2019-10-25 14:23:41 UTC (rev 
74239)
@@ -476,7 +476,7 @@
                VSET(v0, fmesh->pnts[t.v[0]]->x, fmesh->pnts[t.v[0]]->y, 
fmesh->pnts[t.v[0]]->z);
                VSET(v1, fmesh->pnts[t.v[1]]->x, fmesh->pnts[t.v[1]]->y, 
fmesh->pnts[t.v[1]]->z);
                VSET(v2, fmesh->pnts[t.v[2]]->x, fmesh->pnts[t.v[2]]->y, 
fmesh->pnts[t.v[2]]->z);
-               double tdist = bg_tri_pt_dist(tp, v0, v1, v2);
+               double tdist = bg_tri_closest_pt(NULL, tp, v0, v1, v2);
                if (cdist > tdist) {
                    cdist = tdist;
                    closest_tri = *tr_it;
@@ -1930,6 +1930,13 @@
        if (!v) {
            std::cout << "WARNING: - no overt for vertex??\n";
        }
+
+       ON_3dPoint p = v->vpnt();
+       ON_3dPoint prob_pnt(3.04789,7.50032,22.93);
+       if (p.DistanceTo(prob_pnt) < 0.01) {
+           std::cout << "problem\n";
+       }
+
        // If we've got more than one triangle from the other mesh breaking 
through
        // this triangle and sharing this vertex, list it as a point worth 
splitting
        // at the nearest surface point
@@ -1944,9 +1951,13 @@
                tri_isect_cnt++;
            }
            if (tri_isect_cnt > 1) {
-               omesh1->refine_pnt_add(v);
                have_refinement_pnt = true;
 
+               // TODO - if this point doesn't project into any triangle pair, 
it's
+               // an edge-point-split-only point.  Need to either filter it 
here or
+               // in the eventual mesh processing...
+               omesh1->refine_pnt_add(v);
+
                // If this point is also close to a brep face edge, list that 
edge/vert
                // combination for splitting
                ON_3dPoint vp = v->vpnt();
@@ -1959,7 +1970,6 @@
                        edge_verts[bseg].insert(v);
                    }
                }
-
                break;
            }
        }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to