Revision: 71776
          http://sourceforge.net/p/brlcad/code/71776
Author:   starseeker
Date:     2018-09-21 22:57:04 +0000 (Fri, 21 Sep 2018)
Log Message:
-----------
Seeing a SPSR failure mode where the BoT is 'valid' and matches the bbox within 
tolerance, but is wildly wrong for the original shape.  Check the avg. 
thickness calculation as an additional validation.

Modified Paths:
--------------
    brlcad/trunk/src/libged/facetize.c

Modified: brlcad/trunk/src/libged/facetize.c
===================================================================
--- brlcad/trunk/src/libged/facetize.c  2018-09-20 21:16:04 UTC (rev 71775)
+++ brlcad/trunk/src/libged/facetize.c  2018-09-21 22:57:04 UTC (rev 71776)
@@ -62,6 +62,7 @@
 #define GED_FACETIZE_FAILURE_NMG 7
 #define GED_FACETIZE_FAILURE_CONTINUATION_SURFACE 10
 #define GED_FACETIZE_FAILURE_SPSR_SURFACE 11
+#define GED_FACETIZE_FAILURE_SPSR_NONMATCHING 12
 
 /* size of available memory (in bytes) below which we can't continue */
 #define GED_FACETIZE_MEMORY_THRESHOLD 150000000
@@ -110,6 +111,9 @@
        case GED_FACETIZE_FAILURE_SPSR_SURFACE:
            bu_vls_printf(msg, "%s: Screened Poisson surface reconstruction 
failed.\n", prefix);
            break;
+       case GED_FACETIZE_FAILURE_SPSR_NONMATCHING:
+           bu_vls_printf(msg, "%s: Screened Poisson surface reconstruction did 
not produce a BoT matching the original shape.\n", prefix);
+           break;
        default:
            return;
            break;
@@ -876,6 +880,7 @@
     struct rt_pnts_internal *pnts;
     struct rt_bot_internal *bot = NULL;
     struct pnt_normal *pn, *pl;
+    double avg_thickness = 0.0;
     int flags = 0;
     int i = 0;
     int free_pnts = 0;
@@ -933,7 +938,7 @@
            bu_log("SPSR: generating %d points from %s\n", objname);
        }
 
-       if (analyze_obj_to_pnts(pnts, NULL, gedp->ged_wdbp->dbip, objname, 
&btol, flags, max_pnts, opts->max_time, opts->verbosity)) {
+       if (analyze_obj_to_pnts(pnts, &avg_thickness, gedp->ged_wdbp->dbip, 
objname, &btol, flags, max_pnts, opts->max_time, opts->verbosity)) {
            r->failure_mode = GED_FACETIZE_FAILURE_PNTGEN;
            ret = GED_FACETIZE_FAILURE;
            goto ged_facetize_spsr_memfree;
@@ -1016,6 +1021,71 @@
        }
     }
 
+    /* Because SPSR has some observed failure modes that produce a "valid" BoT 
totally different
+     * from the original shape, if we know the avg. thickness of the original 
object raytrace
+     * the candidate BoT and compare the avg. thicknesses */
+    if (avg_thickness > 0) {
+       const char *av[3];
+       int max_pnts = (opts->max_pnts) ? opts->max_pnts : 200000;
+       double navg_thickness = 0.0;
+       struct bu_vls tmpname = BU_VLS_INIT_ZERO;
+       struct rt_bot_internal *tbot = NULL;
+       BU_ALLOC(tbot, struct rt_bot_internal);
+       tbot->magic = RT_BOT_INTERNAL_MAGIC;
+       tbot->mode = RT_BOT_SOLID;
+       tbot->orientation = RT_BOT_UNORIENTED;
+       tbot->thickness = (fastf_t *)NULL;
+       tbot->face_mode = (struct bu_bitv *)NULL;
+
+       tbot->num_vertices = bot->num_vertices;
+       tbot->num_faces = bot->num_faces;
+       tbot->vertices = (fastf_t *)bu_malloc(sizeof(fastf_t) * 
tbot->num_vertices * 3, "vert array");
+       memcpy(tbot->vertices, bot->vertices, sizeof(fastf_t) * 
tbot->num_vertices * 3);
+       tbot->faces = (int *)bu_malloc(sizeof(int) * tbot->num_faces * 3, 
"faces array");
+       memcpy(tbot->faces, bot->faces, sizeof(int) * tbot->num_faces *3);
+
+       flags = ANALYZE_OBJ_TO_PNTS_RAND;
+       bu_vls_sprintf(&tmpname, "%s.tmp", newname);
+       if (db_lookup(gedp->ged_wdbp->dbip, bu_vls_addr(&tmpname), 
LOOKUP_QUIET) != RT_DIR_NULL) {
+           bu_vls_printf(&tmpname, "-0");
+           bu_vls_incr(&tmpname, NULL, NULL, &_db_uniq_test, (void *)gedp);
+       }
+       if (_write_bot(gedp, tbot, bu_vls_addr(&tmpname), opts) == GED_ERROR) {
+           bu_log("SPSR: could not write BoT to temporary name %s\n", 
bu_vls_addr(&tmpname));
+           bu_vls_free(&tmpname);
+           ret = GED_FACETIZE_FAILURE;
+           goto ged_facetize_spsr_memfree;
+       }
+
+       if (analyze_obj_to_pnts(NULL, &navg_thickness, gedp->ged_wdbp->dbip, 
bu_vls_addr(&tmpname), &btol, flags, max_pnts, opts->max_time, 
opts->verbosity)) {
+           bu_log("SPSR: could not raytrace temporary BoT %s\n", 
bu_vls_addr(&tmpname));
+           ret = GED_FACETIZE_FAILURE;
+       }
+
+       /* Remove the temporary BoT object, succeed or fail. */
+       av[0] = "kill";
+       av[1] = bu_vls_addr(&tmpname);
+       av[2] = NULL;
+       (void)ged_kill(gedp, 2, (const char **)av);
+
+       if (ret == GED_FACETIZE_FAILURE) {
+           bu_vls_free(&tmpname);
+           goto ged_facetize_spsr_memfree;
+       }
+
+
+       if (fabs(avg_thickness - navg_thickness) > avg_thickness * 0.5) {
+           bu_log("SPSR: BoT average sampled thickness %f is widely different 
from original sampled thickness %f\n", navg_thickness, avg_thickness);
+           ret = GED_FACETIZE_FAILURE;
+           r->failure_mode = GED_FACETIZE_FAILURE_SPSR_NONMATCHING;
+           bu_vls_free(&tmpname);
+           goto ged_facetize_spsr_memfree;
+       }
+
+       /* Passed test, continue */
+       bu_vls_free(&tmpname);
+    }
+
     if (decimation_succeeded && !opts->quiet) {
        bu_log("SPSR: decimation succeeded, final BoT has %d faces\n", 
bot->num_faces);
     }
@@ -1926,6 +1996,10 @@
     if (cmethod == GED_FACETIZE_SPSR) {
 
        if (!opts->quiet) {
+           bu_log("SPSR: tessellating %s (%d of %d)\n", oname, ocnt, max_cnt);
+       }
+
+       if (opts->verbosity) {
            bu_log("SPSR: tessellating %s with depth %d, interpolation weight 
%g, and samples-per-node %g\n", oname, opts->s_opts.depth, 
opts->s_opts.point_weight, opts->s_opts.samples_per_node);
        }
 

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