Revision: 76075
          http://sourceforge.net/p/brlcad/code/76075
Author:   starseeker
Date:     2020-06-08 19:45:04 +0000 (Mon, 08 Jun 2020)
Log Message:
-----------
Shift logic around so that libgcv plugins don't depend on libgcv.

Modified Paths:
--------------
    brlcad/trunk/include/gcv/util.h
    brlcad/trunk/include/rt/tree.h
    brlcad/trunk/src/adrt/load_g.c
    brlcad/trunk/src/conv/dxf/g-dxf.c
    brlcad/trunk/src/conv/g-egg.c
    brlcad/trunk/src/conv/raw/g-raw.c
    brlcad/trunk/src/conv/stl/g-stl.c
    brlcad/trunk/src/libgcv/CMakeLists.txt
    brlcad/trunk/src/libgcv/plugins/fastgen4/fastgen4_write.cpp
    brlcad/trunk/src/libgcv/plugins/stl/stl_write.c
    brlcad/trunk/src/libgcv/region_end_mc.c
    brlcad/trunk/src/librt/CMakeLists.txt

Added Paths:
-----------
    brlcad/trunk/src/librt/region_end.c

Removed Paths:
-------------
    brlcad/trunk/src/libgcv/region_end.c

Modified: brlcad/trunk/include/gcv/util.h
===================================================================
--- brlcad/trunk/include/gcv/util.h     2020-06-08 19:23:55 UTC (rev 76074)
+++ brlcad/trunk/include/gcv/util.h     2020-06-08 19:45:04 UTC (rev 76075)
@@ -58,28 +58,6 @@
 
 
 /**
- * write_region is a function pointer to a routine that will
- * write out the region in a given file format.
- *
- * This routine must be prepared to run in parallel.
- */
-struct gcv_region_end_data
-{
-    void (*write_region)(struct nmgregion *r, const struct db_full_path 
*pathp, int region_id, int material_id, float color[3], void *client_data);
-    void *client_data;
-};
-
-/**
- * Perform Boolean evaluation on a tree of tessellated leaf nodes.
- *
- * Usually specified as the db_walk_tree() region_end callback,
- * calling this routine for each positive region encountered.
- *
- * The client_data parameter is expected to point to a struct 
gcv_region_end_data.
- */
-GCV_EXPORT extern union tree *gcv_region_end(struct db_tree_state *tsp, const 
struct db_full_path *pathp, union tree *curtree, void *client_data);
-
-/**
  * Exact same as gcv_region_end, except using the marching cubes algorithm.
  */
 GCV_EXPORT extern union tree *gcv_region_end_mc(struct db_tree_state *tsp, 
const struct db_full_path *pathp, union tree *curtree, void *client_data);

Modified: brlcad/trunk/include/rt/tree.h
===================================================================
--- brlcad/trunk/include/rt/tree.h      2020-06-08 19:23:55 UTC (rev 76074)
+++ brlcad/trunk/include/rt/tree.h      2020-06-08 19:45:04 UTC (rev 76075)
@@ -774,7 +774,28 @@
                                    struct resource *resp);
 
 
+/**
+ * write_region is a function pointer to a routine that will
+ * write out the region in a given file format.
+ *
+ * This routine must be prepared to run in parallel.
+ */
+struct rt_region_end_data
+{
+    void (*write_region)(struct nmgregion *r, const struct db_full_path 
*pathp, int region_id, int material_id, float color[3], void *client_data);
+    void *client_data;
+};
 
+/**
+ * Perform Boolean evaluation on a tree of tessellated leaf nodes.
+ *
+ * Usually specified as the db_walk_tree() region_end callback,
+ * calling this routine for each positive region encountered.
+ *
+ * The client_data parameter is expected to point to a struct 
rt_region_end_data.
+ */
+RT_EXPORT extern union tree *rt_region_end(struct db_tree_state *tsp, const 
struct db_full_path *pathp, union tree *curtree, void *client_data);
+
 __END_DECLS
 
 #endif /* RT_TREE_H */

Modified: brlcad/trunk/src/adrt/load_g.c
===================================================================
--- brlcad/trunk/src/adrt/load_g.c      2020-06-08 19:23:55 UTC (rev 76074)
+++ brlcad/trunk/src/adrt/load_g.c      2020-06-08 19:45:04 UTC (rev 76075)
@@ -54,7 +54,7 @@
 static void nmg_to_adrt_gcvwrite(struct nmgregion *r, const struct 
db_full_path *pathp, int region_id, int material_id, float color[3], void 
*client_data);
 
 struct gcv_data {
-    struct gcv_region_end_data region_end_data;
+    struct rt_region_end_data region_end_data;
     struct adrt_mesh_s **meshes;
 };
 static struct gcv_data gcvwriter = {{nmg_to_adrt_gcvwrite, NULL}, NULL};
@@ -309,7 +309,7 @@
                        1,                      /* ncpu */
                        &tree_state,            /* initial tree state */
                        nmg_to_adrt_regstart,   /* region start function */
-                       gcv_region_end,         /* region end function */
+                       rt_region_end,          /* region end function */
                        nmg_booltree_leaf_tess, /* leaf func */
                        (void *)&gcvwriter);    /* client data */
 

Modified: brlcad/trunk/src/conv/dxf/g-dxf.c
===================================================================
--- brlcad/trunk/src/conv/dxf/g-dxf.c   2020-06-08 19:23:55 UTC (rev 76074)
+++ brlcad/trunk/src/conv/dxf/g-dxf.c   2020-06-08 19:45:04 UTC (rev 76075)
@@ -366,7 +366,7 @@
 }
 
 
-static struct gcv_region_end_data gcvwriter = {nmg_to_dxf, NULL};
+static struct rt_region_end_data gcvwriter = {nmg_to_dxf, NULL};
 
 
 /**
@@ -378,7 +378,7 @@
  * 4. db_walk_tree (get_layer) for layer names only
  * 5. Initialize tree_state
  * 6. Initialize model (nmg)\
- * 7. db_walk_tree (gcv_region_end)
+ * 7. db_walk_tree (rt_region_end)
  * 8. Cleanup
  */
 int
@@ -532,9 +532,9 @@
                        1,                      /* ncpu */
                        &tree_state,
                        0,                      /* take all regions */
-                       gcv_region_end,
+                       rt_region_end,
                        nmg_booltree_leaf_tess,
-                       (void *)&gcvwriter);    /* callback for gcv_region_end 
*/
+                       (void *)&gcvwriter);    /* callback for rt_region_end */
 
     percent = 0;
     if (regions_tried>0) {

Modified: brlcad/trunk/src/conv/g-egg.c
===================================================================
--- brlcad/trunk/src/conv/g-egg.c       2020-06-08 19:23:55 UTC (rev 76074)
+++ brlcad/trunk/src/conv/g-egg.c       2020-06-08 19:45:04 UTC (rev 76075)
@@ -192,7 +192,7 @@
 
     int i, use_mc = 0, use_bottess = 0;
     struct egg_conv_data conv_data;
-    struct gcv_region_end_data gcvwriter = {nmg_to_egg, NULL};
+    struct rt_region_end_data gcvwriter = {nmg_to_egg, NULL};
 
     gcvwriter.client_data = (void *)&conv_data;
 
@@ -327,7 +327,7 @@
                            ncpu,               /* ncpu */
                            &tree_state,        /* state */
                            NULL,               /* start func */
-                           
use_mc?gcv_region_end_mc:use_bottess?gcv_bottess_region_end:gcv_region_end, /* 
end func */
+                           
use_mc?gcv_region_end_mc:use_bottess?gcv_bottess_region_end:rt_region_end,  /* 
end func */
                            use_mc?NULL:nmg_booltree_leaf_tess, /* leaf func */
                            (void *)&gcvwriter);  /* client_data */
        fprintf(conv_data.fp, "}\n");

Modified: brlcad/trunk/src/conv/raw/g-raw.c
===================================================================
--- brlcad/trunk/src/conv/raw/g-raw.c   2020-06-08 19:23:55 UTC (rev 76074)
+++ brlcad/trunk/src/conv/raw/g-raw.c   2020-06-08 19:45:04 UTC (rev 76075)
@@ -210,7 +210,7 @@
 }
 
 
-static struct gcv_region_end_data gcvwriter = {nmg_to_raw, NULL};
+static struct rt_region_end_data gcvwriter = {nmg_to_raw, NULL};
 
 
 int
@@ -349,7 +349,7 @@
            1,
            &tree_state,
            0,                  /* take all regions */
-           use_mc?gcv_region_end_mc:gcv_region_end,
+           use_mc?gcv_region_end_mc:rt_region_end,
            use_mc?NULL:nmg_booltree_leaf_tess,
            (void *)&gcvwriter);
 

Modified: brlcad/trunk/src/conv/stl/g-stl.c
===================================================================
--- brlcad/trunk/src/conv/stl/g-stl.c   2020-06-08 19:23:55 UTC (rev 76074)
+++ brlcad/trunk/src/conv/stl/g-stl.c   2020-06-08 19:45:04 UTC (rev 76075)
@@ -301,7 +301,7 @@
 }
 
 
-static struct gcv_region_end_data gcvwriter = {nmg_to_stl, NULL};
+static struct rt_region_end_data gcvwriter = {nmg_to_stl, NULL};
 
 
 int
@@ -474,7 +474,7 @@
                        1,
                        &tree_state,
                        0,                      /* take all regions */
-                       use_mc?gcv_region_end_mc:gcv_region_end,
+                       use_mc?gcv_region_end_mc:rt_region_end,
                        use_mc?NULL:nmg_booltree_leaf_tess,
                        (void *)&gcvwriter);
 

Modified: brlcad/trunk/src/libgcv/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libgcv/CMakeLists.txt      2020-06-08 19:23:55 UTC (rev 
76074)
+++ brlcad/trunk/src/libgcv/CMakeLists.txt      2020-06-08 19:45:04 UTC (rev 
76075)
@@ -21,7 +21,6 @@
   bottess.c
   facetize.c
   gcv.c
-  region_end.c
   region_end_mc.c
   tri_intersect.c
   )

Modified: brlcad/trunk/src/libgcv/plugins/fastgen4/fastgen4_write.cpp
===================================================================
--- brlcad/trunk/src/libgcv/plugins/fastgen4/fastgen4_write.cpp 2020-06-08 
19:23:55 UTC (rev 76074)
+++ brlcad/trunk/src/libgcv/plugins/fastgen4/fastgen4_write.cpp 2020-06-08 
19:45:04 UTC (rev 76075)
@@ -2522,8 +2522,8 @@
     if (tree_state->ts_mater.ma_color_valid)
        section.set_color(color_from_floats(tree_state->ts_mater.ma_color));
 
-    gcv_region_end_data gcv_data = {write_nmg_region, &data};
-    return gcv_region_end(tree_state, path, current_tree, &gcv_data);
+    rt_region_end_data gcv_data = {write_nmg_region, &data};
+    return rt_region_end(tree_state, path, current_tree, &gcv_data);
 }
 
 

Modified: brlcad/trunk/src/libgcv/plugins/stl/stl_write.c
===================================================================
--- brlcad/trunk/src/libgcv/plugins/stl/stl_write.c     2020-06-08 19:23:55 UTC 
(rev 76074)
+++ brlcad/trunk/src/libgcv/plugins/stl/stl_write.c     2020-06-08 19:45:04 UTC 
(rev 76075)
@@ -350,7 +350,7 @@
     double percent;
     struct db_tree_state tree_state;
     struct conversion_state state;
-    struct gcv_region_end_data gcvwriter;
+    struct rt_region_end_data gcvwriter;
 
     gcvwriter.write_region = nmg_to_stl;
     gcvwriter.client_data = &state;
@@ -414,7 +414,7 @@
                        1,
                        &tree_state,
                        0,                      /* take all regions */
-                       (gcv_options->tessellation_algorithm == 
GCV_TESS_MARCHING_CUBES)?gcv_region_end_mc:gcv_region_end,
+                       (gcv_options->tessellation_algorithm == 
GCV_TESS_MARCHING_CUBES)?gcv_region_end_mc:rt_region_end,
                        (gcv_options->tessellation_algorithm == 
GCV_TESS_MARCHING_CUBES)?NULL:nmg_booltree_leaf_tess,
                        (void *)&gcvwriter);
 

Deleted: brlcad/trunk/src/libgcv/region_end.c
===================================================================
--- brlcad/trunk/src/libgcv/region_end.c        2020-06-08 19:23:55 UTC (rev 
76074)
+++ brlcad/trunk/src/libgcv/region_end.c        2020-06-08 19:45:04 UTC (rev 
76075)
@@ -1,216 +0,0 @@
-/*                    R E G I O N _ E N D . C
- * BRL-CAD
- *
- * Copyright (c) 2008-2020 United States Government as represented by
- * the U.S. Army Research Laboratory.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this file; see the file named COPYING for more
- * information.
- */
-/** @file libgcv/region_end.c
- *
- * Routines to process regions during a db_walk_tree.
- *
- */
-
-#include "common.h"
-
-#include "bu/parallel.h"
-#include "rt/wdb.h"
-#include "rt/global.h"
-#include "gcv.h"
-
-
-union tree *
-_gcv_cleanup(int state, union tree *tp)
-{
-    /* restore previous debug state */
-    nmg_debug = state;
-
-    /* Dispose of original tree, so that all associated dynamic memory
-     * is released now, not at the end of all regions.  A return of
-     * TREE_NULL from this routine signals an error, and there is no
-     * point to adding _another_ message to our output, so we need to
-     * cons up an OP_NOP node to return.
-     */
-    db_free_tree(tp, &rt_uniresource); /* Does an nmg_kr() */
-
-    BU_ALLOC(tp, union tree);
-    RT_TREE_INIT(tp);
-    tp->tr_op = OP_NOP;
-    return tp;
-}
-
-
-union tree *
-gcv_region_end(struct db_tree_state *tsp, const struct db_full_path *pathp, 
union tree *curtree, void *client_data)
-{
-    union tree *tp = NULL;
-    union tree *ret_tree = NULL;
-    struct nmgregion *r = NULL;
-    struct shell *s = NULL;
-    struct bu_list vhead;
-
-    int empty_region = 0;
-    int empty_model = 0;
-    int NMG_debug_state = 0;
-
-    struct gcv_region_end_data *data = (struct gcv_region_end_data 
*)client_data;
-
-    if (!tsp || !curtree || !pathp || !client_data) {
-       bu_log("INTERNAL ERROR: gcv_region_end missing parameters\n");
-       return TREE_NULL;
-    }
-
-    if (!data->write_region) {
-       bu_log("INTERNAL ERROR: gcv_region_end missing conversion callback 
function\n");
-       return TREE_NULL;
-    }
-
-    RT_CK_FULL_PATH(pathp);
-    RT_CK_TREE(curtree);
-    BG_CK_TESS_TOL(tsp->ts_ttol);
-    BN_CK_TOL(tsp->ts_tol);
-    NMG_CK_MODEL(*tsp->ts_m);
-
-    BU_LIST_INIT(&vhead);
-
-    if (curtree->tr_op == OP_NOP)
-       return curtree;
-
-    /* get a copy to play with as the parameters might get clobbered
-     * by a longjmp.  FIXME: db_dup_subtree() doesn't create real copies
-     */
-    tp = db_dup_subtree(curtree, &rt_uniresource);
-
-    /* FIXME: we can't free curtree until we get a "real" copy form
-     * db_dup_subtree().  right now we get a fake copy just so we can
-     * keep the compiler quiet about clobbering curtree during longjmp
-     */
-    /* db_free_tree(curtree, &rt_uniresource); */
-
-    /* Sometimes the NMG library adds debugging bits when it detects
-     * an internal error, before bombing.  Stash.
-     */
-    NMG_debug_state = nmg_debug;
-
-    if (!BU_SETJUMP) {
-       /* try */
-       /* perform boolean evaluation on the NMG, presently modifies
-        * curtree to an evaluated result and returns it if the evaluation
-        * is successful.
-        */
-       ret_tree = nmg_booltree_evaluate(tp, &RTG.rtg_vlfree, tsp->ts_tol, 
&rt_uniresource);
-    } else {
-       /* catch */
-       /* Error, bail out */
-       char *sofar;
-
-       /* Relinquish bomb protection */
-       BU_UNSETJUMP;
-
-       sofar = db_path_to_string(pathp);
-       bu_log("FAILED in boolean evaluation: %s\n", sofar);
-       bu_free((char *)sofar, "sofar");
-
-       /* Release any intersector 2d tables */
-       nmg_isect2d_final_cleanup();
-
-       /* Get rid of (m)any other intermediate structures */
-       if ((*tsp->ts_m)->magic == NMG_MODEL_MAGIC)
-           nmg_km(*tsp->ts_m);
-       else
-           bu_log("WARNING: tsp->ts_m pointer corrupted, ignoring it.\n");
-
-       /* Now, make a new, clean model structure for next pass. */
-       *tsp->ts_m = nmg_mm();
-
-       return _gcv_cleanup(NMG_debug_state, tp);
-    } BU_UNSETJUMP; /* Relinquish bomb protection */
-
-    r = (struct nmgregion *)NULL;
-    if (ret_tree)
-       r = ret_tree->tr_d.td_r;
-
-    if (r == (struct nmgregion *)NULL)
-       return _gcv_cleanup(NMG_debug_state, tp);
-
-    /* Kill cracks */
-    s = BU_LIST_FIRST(shell, &r->s_hd);
-    while (BU_LIST_NOT_HEAD(&s->l, &r->s_hd)) {
-       struct shell *next_s;
-
-       next_s = BU_LIST_PNEXT(shell, &s->l);
-       if (nmg_kill_cracks(s)) {
-           if (nmg_ks(s)) {
-               empty_region = 1;
-               break;
-           }
-       }
-       s = next_s;
-    }
-    if (empty_region)
-       return _gcv_cleanup(NMG_debug_state, tp);
-
-    /* kill zero length edgeuses */
-    empty_model = nmg_kill_zero_length_edgeuses(*tsp->ts_m);
-    if (empty_model)
-       return _gcv_cleanup(NMG_debug_state, tp);
-
-    if (BU_SETJUMP) {
-       /* Error, bail out */
-       char *sofar;
-
-       /* Relinquish bomb protection */
-       BU_UNSETJUMP;
-
-       sofar = db_path_to_string(pathp);
-       bu_log("FAILED in triangulator: %s\n", sofar);
-       bu_free((char *)sofar, "sofar");
-
-       /* Release any intersector 2d tables */
-       nmg_isect2d_final_cleanup();
-
-       /* Get rid of (m)any other intermediate structures */
-       if ((*tsp->ts_m)->magic == NMG_MODEL_MAGIC)
-           nmg_km(*tsp->ts_m);
-       else
-           bu_log("WARNING: tsp->ts_m pointer corrupted, ignoring it.\n");
-
-       /* Now, make a new, clean model structure for next pass. */
-       *tsp->ts_m = nmg_mm();
-       nmg_kr(r);
-
-       return _gcv_cleanup(NMG_debug_state, tp);
-    } else {
-
-       /* Write the region out */
-       data->write_region(r, pathp, tsp->ts_regionid, tsp->ts_gmater, 
tsp->ts_mater.ma_color, data->client_data);
-
-    } BU_UNSETJUMP; /* Relinquish bomb protection */
-
-    nmg_kr(r);
-
-    return _gcv_cleanup(NMG_debug_state, tp);
-}
-
-
-/*
- * Local Variables:
- * tab-width: 8
- * mode: C
- * indent-tabs-mode: t
- * c-file-style: "stroustrup"
- * End:
- * ex: shiftwidth=4 tabstop=8
- */

Modified: brlcad/trunk/src/libgcv/region_end_mc.c
===================================================================
--- brlcad/trunk/src/libgcv/region_end_mc.c     2020-06-08 19:23:55 UTC (rev 
76074)
+++ brlcad/trunk/src/libgcv/region_end_mc.c     2020-06-08 19:45:04 UTC (rev 
76075)
@@ -29,12 +29,29 @@
 
 #include "bu/parallel.h"
 #include "rt/rt_instance.h"
+#include "rt/tree.h"
 #include "gcv.h"
 
+union tree *
+_gcv_cleanup(int state, union tree *tp)
+{
+    /* restore previous debug state */
+    nmg_debug = state;
 
-/* in region_end.c */
-union tree * _gcv_cleanup(int state, union tree *tp);
+    /* Dispose of original tree, so that all associated dynamic memory
+     * is released now, not at the end of all regions.  A return of
+     * TREE_NULL from this routine signals an error, and there is no
+     * point to adding _another_ message to our output, so we need to
+     * cons up an OP_NOP node to return.
+     */
+    db_free_tree(tp, &rt_uniresource); /* Does an nmg_kr() */
 
+    BU_ALLOC(tp, union tree);
+    RT_TREE_INIT(tp);
+    tp->tr_op = OP_NOP;
+    return tp;
+}
+
 union tree *
 gcv_region_end_mc(struct db_tree_state *tsp, const struct db_full_path *pathp, 
union tree *curtree, void *client_data)
 {
@@ -49,7 +66,7 @@
     int NMG_debug_state = 0;
     int count = 0;
 
-    struct gcv_region_end_data *data = (struct gcv_region_end_data 
*)client_data;
+    struct rt_region_end_data *data = (struct rt_region_end_data *)client_data;
 
     if (!tsp || !pathp || !client_data) {
        bu_log("INTERNAL ERROR: gcv_region_end_mc missing parameters\n");

Modified: brlcad/trunk/src/librt/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/librt/CMakeLists.txt       2020-06-08 19:23:55 UTC (rev 
76074)
+++ brlcad/trunk/src/librt/CMakeLists.txt       2020-06-08 19:45:04 UTC (rev 
76075)
@@ -211,6 +211,7 @@
   primitives/xxx/xxx.c
   reduce.c
   reduce_db.cpp
+  region_end.c
   regionfix.c
   roots.c
   search.c

Added: brlcad/trunk/src/librt/region_end.c
===================================================================
--- brlcad/trunk/src/librt/region_end.c                         (rev 0)
+++ brlcad/trunk/src/librt/region_end.c 2020-06-08 19:45:04 UTC (rev 76075)
@@ -0,0 +1,216 @@
+/*                    R E G I O N _ E N D . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2008-2020 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file libgcv/region_end.c
+ *
+ * Routines to process regions during a db_walk_tree.
+ *
+ */
+
+#include "common.h"
+
+#include "bu/parallel.h"
+#include "rt/wdb.h"
+#include "rt/global.h"
+#include "gcv.h"
+
+
+static union tree *
+_rt_region_end_cleanup(int state, union tree *tp)
+{
+    /* restore previous debug state */
+    nmg_debug = state;
+
+    /* Dispose of original tree, so that all associated dynamic memory
+     * is released now, not at the end of all regions.  A return of
+     * TREE_NULL from this routine signals an error, and there is no
+     * point to adding _another_ message to our output, so we need to
+     * cons up an OP_NOP node to return.
+     */
+    db_free_tree(tp, &rt_uniresource); /* Does an nmg_kr() */
+
+    BU_ALLOC(tp, union tree);
+    RT_TREE_INIT(tp);
+    tp->tr_op = OP_NOP;
+    return tp;
+}
+
+
+union tree *
+rt_region_end(struct db_tree_state *tsp, const struct db_full_path *pathp, 
union tree *curtree, void *client_data)
+{
+    union tree *tp = NULL;
+    union tree *ret_tree = NULL;
+    struct nmgregion *r = NULL;
+    struct shell *s = NULL;
+    struct bu_list vhead;
+
+    int empty_region = 0;
+    int empty_model = 0;
+    int NMG_debug_state = 0;
+
+    struct rt_region_end_data *data = (struct rt_region_end_data *)client_data;
+
+    if (!tsp || !curtree || !pathp || !client_data) {
+       bu_log("INTERNAL ERROR: rt_region_end_region_end missing parameters\n");
+       return TREE_NULL;
+    }
+
+    if (!data->write_region) {
+       bu_log("INTERNAL ERROR: rt_region_end_region_end missing conversion 
callback function\n");
+       return TREE_NULL;
+    }
+
+    RT_CK_FULL_PATH(pathp);
+    RT_CK_TREE(curtree);
+    BG_CK_TESS_TOL(tsp->ts_ttol);
+    BN_CK_TOL(tsp->ts_tol);
+    NMG_CK_MODEL(*tsp->ts_m);
+
+    BU_LIST_INIT(&vhead);
+
+    if (curtree->tr_op == OP_NOP)
+       return curtree;
+
+    /* get a copy to play with as the parameters might get clobbered
+     * by a longjmp.  FIXME: db_dup_subtree() doesn't create real copies
+     */
+    tp = db_dup_subtree(curtree, &rt_uniresource);
+
+    /* FIXME: we can't free curtree until we get a "real" copy form
+     * db_dup_subtree().  right now we get a fake copy just so we can
+     * keep the compiler quiet about clobbering curtree during longjmp
+     */
+    /* db_free_tree(curtree, &rt_uniresource); */
+
+    /* Sometimes the NMG library adds debugging bits when it detects
+     * an internal error, before bombing.  Stash.
+     */
+    NMG_debug_state = nmg_debug;
+
+    if (!BU_SETJUMP) {
+       /* try */
+       /* perform boolean evaluation on the NMG, presently modifies
+        * curtree to an evaluated result and returns it if the evaluation
+        * is successful.
+        */
+       ret_tree = nmg_booltree_evaluate(tp, &RTG.rtg_vlfree, tsp->ts_tol, 
&rt_uniresource);
+    } else {
+       /* catch */
+       /* Error, bail out */
+       char *sofar;
+
+       /* Relinquish bomb protection */
+       BU_UNSETJUMP;
+
+       sofar = db_path_to_string(pathp);
+       bu_log("FAILED in boolean evaluation: %s\n", sofar);
+       bu_free((char *)sofar, "sofar");
+
+       /* Release any intersector 2d tables */
+       nmg_isect2d_final_cleanup();
+
+       /* Get rid of (m)any other intermediate structures */
+       if ((*tsp->ts_m)->magic == NMG_MODEL_MAGIC)
+           nmg_km(*tsp->ts_m);
+       else
+           bu_log("WARNING: tsp->ts_m pointer corrupted, ignoring it.\n");
+
+       /* Now, make a new, clean model structure for next pass. */
+       *tsp->ts_m = nmg_mm();
+
+       return _rt_region_end_cleanup(NMG_debug_state, tp);
+    } BU_UNSETJUMP; /* Relinquish bomb protection */
+
+    r = (struct nmgregion *)NULL;
+    if (ret_tree)
+       r = ret_tree->tr_d.td_r;
+
+    if (r == (struct nmgregion *)NULL)
+       return _rt_region_end_cleanup(NMG_debug_state, tp);
+
+    /* Kill cracks */
+    s = BU_LIST_FIRST(shell, &r->s_hd);
+    while (BU_LIST_NOT_HEAD(&s->l, &r->s_hd)) {
+       struct shell *next_s;
+
+       next_s = BU_LIST_PNEXT(shell, &s->l);
+       if (nmg_kill_cracks(s)) {
+           if (nmg_ks(s)) {
+               empty_region = 1;
+               break;
+           }
+       }
+       s = next_s;
+    }
+    if (empty_region)
+       return _rt_region_end_cleanup(NMG_debug_state, tp);
+
+    /* kill zero length edgeuses */
+    empty_model = nmg_kill_zero_length_edgeuses(*tsp->ts_m);
+    if (empty_model)
+       return _rt_region_end_cleanup(NMG_debug_state, tp);
+
+    if (BU_SETJUMP) {
+       /* Error, bail out */
+       char *sofar;
+
+       /* Relinquish bomb protection */
+       BU_UNSETJUMP;
+
+       sofar = db_path_to_string(pathp);
+       bu_log("FAILED in triangulator: %s\n", sofar);
+       bu_free((char *)sofar, "sofar");
+
+       /* Release any intersector 2d tables */
+       nmg_isect2d_final_cleanup();
+
+       /* Get rid of (m)any other intermediate structures */
+       if ((*tsp->ts_m)->magic == NMG_MODEL_MAGIC)
+           nmg_km(*tsp->ts_m);
+       else
+           bu_log("WARNING: tsp->ts_m pointer corrupted, ignoring it.\n");
+
+       /* Now, make a new, clean model structure for next pass. */
+       *tsp->ts_m = nmg_mm();
+       nmg_kr(r);
+
+       return _rt_region_end_cleanup(NMG_debug_state, tp);
+    } else {
+
+       /* Write the region out */
+       data->write_region(r, pathp, tsp->ts_regionid, tsp->ts_gmater, 
tsp->ts_mater.ma_color, data->client_data);
+
+    } BU_UNSETJUMP; /* Relinquish bomb protection */
+
+    nmg_kr(r);
+
+    return _rt_region_end_cleanup(NMG_debug_state, tp);
+}
+
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * mode: C
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */


Property changes on: brlcad/trunk/src/librt/region_end.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
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