Revision: 73833
          http://sourceforge.net/p/brlcad/code/73833
Author:   starseeker
Date:     2019-09-05 13:03:22 +0000 (Thu, 05 Sep 2019)
Log Message:
-----------
Not sure this is really necessary, but use point-in-polygon test to pre-cull 
points outside the outer loop or inside the inner trimming loops before handing 
off for triangulation.  poly2tri may handle this itself correctly, but a couple 
of planar triangulation oddities make me wonder enough to want to try an extra 
culling step.

Modified Paths:
--------------
    brlcad/trunk/src/libbrep/cdt_mesh.cpp
    brlcad/trunk/src/libbrep/cdt_mesh.h
    brlcad/trunk/src/libbrep/cdt_surf.cpp

Modified: brlcad/trunk/src/libbrep/cdt_mesh.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt_mesh.cpp       2019-09-05 01:49:12 UTC (rev 
73832)
+++ brlcad/trunk/src/libbrep/cdt_mesh.cpp       2019-09-05 13:03:22 UTC (rev 
73833)
@@ -819,7 +819,55 @@
     return result;
 }
 
+void
+cpolygon_t::rm_points_in_polygon(std::set<ON_2dPoint *> *pnts, bool flip)
+{
+    if (!closed() || !pnts || !pnts->size()) return;
 
+    point2d_t *polypnts = (point2d_t *)bu_calloc(poly.size()+1, 
sizeof(point2d_t), "polyline");
+
+    size_t pind = 0;
+
+    cpolyedge_t *pe = (*poly.begin());
+    cpolyedge_t *first = pe;
+    cpolyedge_t *next = pe->next;
+
+    V2SET(polypnts[pind], pnts_2d[pe->v[0]].first, pnts_2d[pe->v[0]].second);
+    pind++;
+    V2SET(polypnts[pind], pnts_2d[pe->v[1]].first, pnts_2d[pe->v[1]].second);
+
+    // Walk the loop
+    while (first != next) {
+       pind++;
+       V2SET(polypnts[pind], pnts_2d[next->v[1]].first, 
pnts_2d[next->v[1]].second);
+       next = next->next;
+    }
+
+    std::set<ON_2dPoint *> rm_pnts;
+    std::set<ON_2dPoint *>::iterator p_it;
+
+    for (p_it = pnts->begin(); p_it != pnts->end(); p_it++) {
+       ON_2dPoint *p2d = *p_it;
+       point2d_t test_pnt;
+       V2SET(test_pnt, p2d->x, p2d->y);
+
+       bool result = (bool)bg_pt_in_polygon(pind, (const point2d_t *)polypnts, 
(const point2d_t *)&test_pnt);
+
+       if (flip) {
+           result = (result) ? false : true;
+       }
+
+       if (result) {
+           rm_pnts.insert(p2d);
+       }
+    }
+    for (p_it = rm_pnts.begin(); p_it != rm_pnts.end(); p_it++) {
+       pnts->erase(*p_it);
+    }
+
+    bu_free(polypnts, "polyline");
+}
+
 bool
 cpolygon_t::cdt()
 {

Modified: brlcad/trunk/src/libbrep/cdt_mesh.h
===================================================================
--- brlcad/trunk/src/libbrep/cdt_mesh.h 2019-09-05 01:49:12 UTC (rev 73832)
+++ brlcad/trunk/src/libbrep/cdt_mesh.h 2019-09-05 13:03:22 UTC (rev 73833)
@@ -363,6 +363,10 @@
         * report if the point is outside the polygon.
         * TODO - document what it does if it's ON the polygon...*/
        bool point_in_polygon(long v, bool flip);
+
+       /* Process a set of points and filter out those in (or out, if flip is 
set) of the polygon */
+       void rm_points_in_polygon(std::set<ON_2dPoint *> *pnts, bool flip);
+
        // Debugging routines
        void polygon_plot_in_plane(const char *filename);
        void polygon_plot(const char *filename);

Modified: brlcad/trunk/src/libbrep/cdt_surf.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt_surf.cpp       2019-09-05 01:49:12 UTC (rev 
73832)
+++ brlcad/trunk/src/libbrep/cdt_surf.cpp       2019-09-05 13:03:22 UTC (rev 
73833)
@@ -404,17 +404,14 @@
 
     // Next check the face loops with the point in polygon test.  If it's
     // outside the outer loop or inside one of the interior trimming loops,
-    // it's out.  For the inner loops, check the bbox of the loop first to see
-    // if we need to care... in theory we probably should be using an RTree of
-    // the loops to filter this, but I'm guessing that might be premature
-    // optimization at this point...  Could combine with the above and have one
-    // rtree per loop rather than one per face, and "zero in" for testing per
-    // loop as needed.  The tree hierarchy might be worth doing anyway, as
-    // those trees may be needed for overlap detection of edge polycurves
-    // between breps...
+    // it's out.
+    cdt_mesh::cdt_mesh_t *fmesh = 
&sinfo->s_cdt->fmeshes[sinfo->f->m_face_index];
+    fmesh->outer_loop.rm_points_in_polygon(&sinfo->on_surf_points, true);
+    std::map<int, cdt_mesh::cpolygon_t*>::iterator i_it;
+    for (i_it = fmesh->inner_loops.begin(); i_it != fmesh->inner_loops.end(); 
i_it++) {
+       i_it->second->rm_points_in_polygon(&sinfo->on_surf_points, false);
+    }
 
-
-
     // TODO - In addition to removing points on the line in 2D, we don't want 
points that
     // would be outside the edge polygon in projection. Find the "close" trims 
(if any)
     // for the candidate 3D point, then use the normals of the Brep edge 
points and
@@ -425,7 +422,6 @@
     // sets for both edge points to localize on that particular segment.
 
     // Populate m_interior_pnts with the final set
-    cdt_mesh::cdt_mesh_t *fmesh = 
&sinfo->s_cdt->fmeshes[sinfo->f->m_face_index];
     for (osp_it = sinfo->on_surf_points.begin(); osp_it != 
sinfo->on_surf_points.end(); osp_it++) {
        ON_2dPoint n2dp(**osp_it);
        long f_ind2d = fmesh->add_point(n2dp);

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