Revision: 74699
          http://sourceforge.net/p/brlcad/code/74699
Author:   starseeker
Date:     2020-01-15 18:37:43 +0000 (Wed, 15 Jan 2020)
Log Message:
-----------
Don't hit the RTrees more than we have to for the application - if a test point 
isn't within the bbox face, don't worry about it.  We may have to get slightly 
more sophisticated down the road, but this makes a surprisingly massive 
performance difference.

Modified Paths:
--------------
    brlcad/trunk/src/libbrep/cdt/mesh.cpp
    brlcad/trunk/src/libbrep/cdt/mesh.h
    brlcad/trunk/src/libbrep/cdt/omesh.cpp
    brlcad/trunk/src/libbrep/cdt/ovlps_grps.cpp
    brlcad/trunk/src/libbrep/cdt/tri_isect.cpp

Modified: brlcad/trunk/src/libbrep/cdt/mesh.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt/mesh.cpp       2020-01-15 18:03:23 UTC (rev 
74698)
+++ brlcad/trunk/src/libbrep/cdt/mesh.cpp       2020-01-15 18:37:43 UTC (rev 
74699)
@@ -1578,6 +1578,9 @@
     // flag.
     boundary_edges_stale = true;
 
+    // Ditto bounding box
+    bounding_box_stale = true;
+
     return true;
 }
 
@@ -1620,6 +1623,7 @@
 
     // flag boundary edge information for updating
     boundary_edges_stale = true;
+    bounding_box_stale = true;
 }
 
 std::vector<triangle_t>
@@ -1931,28 +1935,38 @@
 }
 
 
-ON_BoundingBox
+ON_BoundingBox &
 cdt_mesh_t::bbox()
 {
+    if (!bounding_box_stale) {
+       return mbb;
+    }
+
     RTree<size_t, double, 3>::Iterator tree_it;
     tris_tree.GetFirst(tree_it);
 
-    if (tree_it.IsNull()) return ON_BoundingBox();
+    if (tree_it.IsNull()) {
+       mbb = ON_BoundingBox();
+       return mbb;
+    }
 
     ON_3dPoint *p3d = pnts[tris_vect[*tree_it].v[0]];
-    ON_BoundingBox bb(*p3d, *p3d);
+    ON_BoundingBox cbb(*p3d, *p3d);
 
     while (!tree_it.IsNull()) {
        p3d = pnts[tris_vect[*tree_it].v[0]];
-       bb.Set(*p3d, true);
+       cbb.Set(*p3d, true);
        p3d = pnts[tris_vect[*tree_it].v[1]];
-       bb.Set(*p3d, true);
+       cbb.Set(*p3d, true);
        p3d = pnts[tris_vect[*tree_it].v[2]];
-       bb.Set(*p3d, true);
+       cbb.Set(*p3d, true);
        ++tree_it;
     }
+    mbb = cbb;
 
-    return bb;
+    bounding_box_stale = false;
+
+    return mbb;
 }
 
 
@@ -3937,6 +3951,7 @@
 
     boundary_edges.clear();
     boundary_edges_stale = true;
+    bounding_box_stale = true;
     problem_edges.clear();
 
     while (std::getline(sfile,switch_line)) {
@@ -4081,6 +4096,7 @@
 
            }
            boundary_edges_stale = true;
+           bounding_box_stale = true;
            continue;
        }
 

Modified: brlcad/trunk/src/libbrep/cdt/mesh.h
===================================================================
--- brlcad/trunk/src/libbrep/cdt/mesh.h 2020-01-15 18:03:23 UTC (rev 74698)
+++ brlcad/trunk/src/libbrep/cdt/mesh.h 2020-01-15 18:37:43 UTC (rev 74699)
@@ -641,7 +641,8 @@
 
     bool tri_active(size_t tind);
 
-    ON_BoundingBox bbox();
+    ON_BoundingBox& bbox();
+    ON_BoundingBox mbb;
     ON_BoundingBox tri_bbox(size_t tind);
 
     // Find the edge of the triangle that is closest to the
@@ -755,6 +756,9 @@
     std::set<uedge_t> problem_edges;
     edge_t find_boundary_oriented_edge(uedge_t &ue);
 
+    
+    bool bounding_box_stale;
+
     // Submesh building
     std::vector<triangle_t> singularity_triangles();
     void remove_dangling_tris();
@@ -925,8 +929,21 @@
        // Find closest point on mesh
         ON_3dPoint closest_pt(double *pdist, ON_3dPoint &op);
 
-       // Find closest point on any active mesh face
-       bool closest_brep_mesh_point(ON_3dPoint &s_p, ON_3dPoint *p, struct 
ON_Brep_CDT_State *s_cdt);
+       // Find closest point on any nearby mesh face in the
+       // specified brep.  This isn't guaranteed to return
+       // the closest point on the brep mesh - it will check
+       // to see if the test point p is close to a face per
+       // it's bounding box, and if it is look for the closest
+       // point.  If the point isn't within any bbox, it will
+       // return the closest point for the current mesh.
+       //
+       // This is done to save the work of searching out the
+       // closest point for every face all the time, which
+       // for the current application isn't what we need -
+       // we just need to know if there's a very close point
+       // to a nearby triangle that is closer (i.e. changes
+       // the triangle status) for the local problem.
+       bool closest_nearby_mesh_point(ON_3dPoint &s_p, ON_3dPoint *p, struct 
ON_Brep_CDT_State *s_cdt);
 
         bool validate_vtree();
 

Modified: brlcad/trunk/src/libbrep/cdt/omesh.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt/omesh.cpp      2020-01-15 18:03:23 UTC (rev 
74698)
+++ brlcad/trunk/src/libbrep/cdt/omesh.cpp      2020-01-15 18:37:43 UTC (rev 
74699)
@@ -517,7 +517,7 @@
 }
 
 bool
-omesh_t::closest_brep_mesh_point(ON_3dPoint &s_p, ON_3dPoint *p, struct 
ON_Brep_CDT_State *s_cdt)
+omesh_t::closest_nearby_mesh_point(ON_3dPoint &s_p, ON_3dPoint *p, struct 
ON_Brep_CDT_State *s_cdt)
 {
     std::set<omesh_t *> check_meshes;
     std::set<std::pair<cdt_mesh_t *, cdt_mesh_t *>>::iterator o_it;
@@ -530,18 +530,26 @@
        }
     }
 
+    ON_BoundingBox pbb(*p, *p);
+
+    bool have_dist = false;
     double cdist = DBL_MAX;
     ON_3dPoint cp;
     std::set<omesh_t *>::iterator om_it;
     for (om_it = check_meshes.begin(); om_it != check_meshes.end(); om_it++) {
        omesh_t *om = *om_it;
+       if (om->fmesh->bbox().IsDisjoint(pbb)) continue;
        double ldist;
        ON_3dPoint om_cp = om->closest_pt(&ldist, *p);
        if (ldist < DBL_MAX && cdist > ldist) {
            cdist = ldist;
            cp = om_cp;
+           have_dist = true;
        }
     }
+    if (!have_dist) {
+       cp = closest_pt(&cdist, *p);
+    }
 
     s_p = cp;
 

Modified: brlcad/trunk/src/libbrep/cdt/ovlps_grps.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt/ovlps_grps.cpp 2020-01-15 18:03:23 UTC (rev 
74698)
+++ brlcad/trunk/src/libbrep/cdt/ovlps_grps.cpp 2020-01-15 18:37:43 UTC (rev 
74699)
@@ -601,6 +601,7 @@
            }
 
            if (bins[i].state == 1) {
+               std::cout << "Interior edges: bin " << i << "\n";
                bins[i].split_interior_uedges();
            }
        }

Modified: brlcad/trunk/src/libbrep/cdt/tri_isect.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt/tri_isect.cpp  2020-01-15 18:03:23 UTC (rev 
74698)
+++ brlcad/trunk/src/libbrep/cdt/tri_isect.cpp  2020-01-15 18:37:43 UTC (rev 
74699)
@@ -499,7 +499,7 @@
                // surface may not be fmesh2...  Need a s_cdt level 
closest_surf_pnt function
                if (on_point_inside(s_cdt, &lmid)) {
                    ON_3dPoint bs_p;
-                   bool cpeval = fmesh2->omesh->closest_brep_mesh_point(bs_p, 
&lmid, s_cdt);
+                   bool cpeval = 
fmesh2->omesh->closest_nearby_mesh_point(bs_p, &lmid, s_cdt);
                    if (!cpeval) {
                        std::cout << "Error - couldn't find closest point for 
mesh\n";
                        continue;
@@ -520,7 +520,7 @@
                // TODO - need some distance metric here - ON the mesh is fine, 
to within tolerance...
                if (on_point_inside(s_cdt, &lmid)) {
                    ON_3dPoint bs_p;
-                   bool cpeval = fmesh1->omesh->closest_brep_mesh_point(bs_p, 
&lmid, s_cdt);
+                   bool cpeval = 
fmesh1->omesh->closest_nearby_mesh_point(bs_p, &lmid, s_cdt);
                    if (!cpeval) {
                        std::cout << "Error - couldn't find closest point for 
mesh\n";
                        continue;

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



_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to