Revision: 70694
          http://sourceforge.net/p/brlcad/code/70694
Author:   starseeker
Date:     2018-02-12 14:06:23 +0000 (Mon, 12 Feb 2018)
Log Message:
-----------
reorder some stuff to do lazier prepping - only differences in nirt-regress 
output now are the missing GAP output in the old nirt.ref and whitespace lines 
after attr -p output.

Modified Paths:
--------------
    brlcad/trunk/src/libanalyze/nirt.cxx
    brlcad/trunk/src/nirt/main.cxx

Modified: brlcad/trunk/src/libanalyze/nirt.cxx
===================================================================
--- brlcad/trunk/src/libanalyze/nirt.cxx        2018-02-11 20:25:55 UTC (rev 
70693)
+++ brlcad/trunk/src/libanalyze/nirt.cxx        2018-02-12 14:06:23 UTC (rev 
70694)
@@ -265,6 +265,7 @@
     struct resource *res;
     struct rt_i *rtip_air;
     struct resource *res_air;
+    int need_reprep;
 
     /* internal format specifier arrays */
     struct bu_attribute_value_set *val_types;
@@ -335,10 +336,8 @@
 
 void grid2targ(struct nirt_state *nss)
 {
-    vect_t grid;
     double ar = nss->vals->a * DEG2RAD;
     double er = nss->vals->e * DEG2RAD;
-    VSET(grid, nss->vals->h, nss->vals->v, nss->vals->d_orig);
     nss->vals->orig[X] = - nss->vals->h * sin(ar) - nss->vals->v * cos(ar) * 
sin(er) + nss->vals->d_orig * cos(ar) * cos(er);
     nss->vals->orig[Y] =   nss->vals->h * cos(ar) - nss->vals->v * sin(ar) * 
sin(er) + nss->vals->d_orig * sin(ar) * cos(er);
     nss->vals->orig[Z] =   nss->vals->v * cos(er) + nss->vals->d_orig * 
sin(er);
@@ -346,13 +345,11 @@
 
 void targ2grid(struct nirt_state *nss)
 {
-    vect_t target;
     double ar = nss->vals->a * DEG2RAD;
     double er = nss->vals->e * DEG2RAD;
-    VMOVE(target, nss->vals->orig);
-    nss->vals->h = - target[X] * sin(ar) + target[Y] * cos(ar);
-    nss->vals->v = - target[X] * cos(ar) * sin(er) - target[Y] * sin(er) * 
sin(ar) + target[Z] * cos(er);
-    nss->vals->d_orig =   target[X] * cos(er) * cos(ar) + target[Y] * cos(er) 
* sin(ar) + target[Z] * sin(er);
+    nss->vals->h = - nss->vals->orig[X] * sin(ar) + nss->vals->orig[Y] * 
cos(ar);
+    nss->vals->v = - nss->vals->orig[X] * cos(ar) * sin(er) - 
nss->vals->orig[Y] * sin(er) * sin(ar) + nss->vals->orig[Z] * cos(er);
+    nss->vals->d_orig =   nss->vals->orig[X] * cos(er) * cos(ar) + 
nss->vals->orig[Y] * cos(er) * sin(ar) + nss->vals->orig[Z] * sin(er);
 }
 
 void dir2ae(struct nirt_state *nss)
@@ -448,7 +445,7 @@
 HIDDEN struct rt_i *
 get_rtip(struct nirt_state *nss)
 {
-    if (!nss || nss->dbip == DBI_NULL) return NULL;
+    if (!nss || nss->dbip == DBI_NULL || nss->active_paths.size() == 0) return 
NULL;
 
     if (nss->use_air) {
        if (nss->rtip_air == RTI_NULL) {
@@ -483,6 +480,7 @@
 HIDDEN struct resource *
 get_resource(struct nirt_state *nss)
 {
+    if (!nss || nss->dbip == DBI_NULL || nss->active_paths.size() == 0) return 
NULL;
     if (nss->use_air) return nss->res_air;
     return nss->res;
 }
@@ -494,6 +492,10 @@
     int acnt = 0;
     std::set<std::string>::iterator s_it;
 
+    /* Based on current settings, pick the particular rtip */
+    nss->ap->a_rt_i = get_rtip(nss);
+    nss->ap->a_resource = get_resource(nss);
+
     /* Don't have enough info to prep yet - can happen if we're in a pre 
"nirt_init" state */
     if (!nss->ap->a_rt_i) return 0;
 
@@ -534,6 +536,7 @@
        }
     }
     lout(nss, " processed\n");
+    nss->need_reprep = 0;
     return 0;
 }
 
@@ -1341,7 +1344,9 @@
        }
     }
 
-    if (nss->attrs.size() != orig_size) return raytrace_prep(nss);
+    if (nss->attrs.size() != orig_size) {
+       nss->need_reprep = 1;
+    }
     return 0;
 }
 
@@ -1522,7 +1527,7 @@
 {
     int i;
     struct nirt_state *nss = (struct nirt_state *)ns;
-    if (!ns || !nss->ap || !nss->ap->a_rt_i) return -1;
+    if (!ns || !nss->ap) return -1;
 
     if (argc != 1) {
        lerr(nss, "Usage:  s\n");
@@ -1529,6 +1534,23 @@
        return -1;
     }
 
+    /* If we have no active rtip, we don't need to prep or shoot */
+    if (!get_rtip(nss)) {
+       return 0;
+    } else {
+       if (nss->need_reprep) {
+           /* If we need to (re)prep, do it now. Failure is an error. */
+           if (raytrace_prep(nss)) {
+               lerr(nss, "Error: raytrace prep failed!\n");
+               return -1;
+           }
+       } else {
+           /* Based on current settings, tell the ap which rtip to use */
+           nss->ap->a_rt_i = get_rtip(nss);
+           nss->ap->a_resource = get_resource(nss);
+       }
+    }
+
     double bov = backout(nss);
     for (i = 0; i < 3; ++i) {
        nss->vals->orig[i] = nss->vals->orig[i] + (bov * 
-1*(nss->vals->dir[i]));
@@ -1599,8 +1621,6 @@
        lerr(nss, "Error: bu_opt value read failure: %s\n\nUsage:  useair 
%s\n", bu_vls_addr(&optparse_msg), get_desc_args("useair"));
        return -1;
     }
-    nss->ap->a_rt_i = get_rtip(nss);
-    nss->ap->a_resource = get_resource(nss);
     return 0;
 }
 
@@ -1950,7 +1970,7 @@
     if (rt_bot_minpieces != (size_t)minpieces) {
        rt_bot_minpieces = minpieces;
        bu_vls_free(&opt_msg);
-       return raytrace_prep(nss);
+       nss->need_reprep = 1;
     }
 
 bot_minpieces_done:
@@ -2078,7 +2098,7 @@
            nss->active_paths.push_back(argv[i]);
        }
     }
-    if (nss->active_paths.size() != orig_size) return raytrace_prep(nss);
+    if (nss->active_paths.size() != orig_size) nss->need_reprep = 1;
     return 0;
 }
 
@@ -2095,7 +2115,7 @@
            nss->active_paths.erase(v_it);
        }
     }
-    if (nss->active_paths.size() > 0 && nss->active_paths.size() != orig_size) 
return raytrace_prep(nss);
+    if (nss->active_paths.size() > 0 && nss->active_paths.size() != orig_size) 
nss->need_reprep = 1;
     return 0;
 }
 
@@ -2104,8 +2124,6 @@
 {
     struct nirt_state *nss = (struct nirt_state *)ns;
     if (!ns) return -1;
-    struct rt_i *rtip = nss->ap->a_rt_i;
-    double base2local = rtip->rti_dbip->dbi_base2local;
     if (argc == 1) {
        // TODO
        return 0;
@@ -2135,13 +2153,24 @@
            lerr(nss, "TODO - state cmd help\n");
            return -1;
        }
-       lout(nss, "model_min = (%g, %g, %g)    model_max = (%g, %g, %g)\n",
-               rtip->mdl_min[X] * base2local,
-               rtip->mdl_min[Y] * base2local,
-               rtip->mdl_min[Z] * base2local,
-               rtip->mdl_max[X] * base2local,
-               rtip->mdl_max[Y] * base2local,
-               rtip->mdl_max[Z] * base2local);
+       if (nss->need_reprep) {
+           if (raytrace_prep(nss)) {
+               lerr(nss, "Error: raytrace prep failed!\n");
+               return -1;
+           }
+       }
+       if (nss->ap->a_rt_i) {
+           double base2local = nss->ap->a_rt_i->rti_dbip->dbi_base2local;
+           lout(nss, "model_min = (%g, %g, %g)    model_max = (%g, %g, %g)\n",
+                   nss->ap->a_rt_i->mdl_min[X] * base2local,
+                   nss->ap->a_rt_i->mdl_min[Y] * base2local,
+                   nss->ap->a_rt_i->mdl_min[Z] * base2local,
+                   nss->ap->a_rt_i->mdl_max[X] * base2local,
+                   nss->ap->a_rt_i->mdl_max[Y] * base2local,
+                   nss->ap->a_rt_i->mdl_max[Z] * base2local);
+       } else {
+           lout(nss, "model_min = (0, 0, 0)    model_max = (0, 0, 0)\n");
+       }
        return 0;
     }
     return 0;
@@ -2409,6 +2438,7 @@
     BU_GET(n->res_air, struct resource);
     n->rtip = RTI_NULL;
     n->rtip_air = RTI_NULL;
+    n->need_reprep = 1;
 
     BU_GET(n->val_types, struct bu_attribute_value_set);
     BU_GET(n->val_docs, struct bu_attribute_value_set);
@@ -2482,7 +2512,7 @@
 
     RT_CK_DBI(dbip);
 
-    ns->dbip = dbip;
+    ns->dbip = db_clone_dbi(dbip, NULL);
 
     /* initialize the application structure */
     RT_APPLICATION_INIT(ns->ap);
@@ -2498,6 +2528,14 @@
     ns->ap->a_zero2 = 0;           /* sanity check, sayth raytrace.h */
     ns->ap->a_uptr = (void *)ns;
 
+    /* If we've already got something, go ahead and prep */
+    if (ns->need_reprep && ns->active_paths.size() > 0) {
+       if (raytrace_prep(ns)) {
+           lerr(ns, "Error - raytrace prep failed during initialization!\n");
+           return -1;
+       }
+    }
+
     /* By default use the .g units */
     ns->base2local = dbip->dbi_base2local;
     ns->local2base = dbip->dbi_local2base;
@@ -2537,6 +2575,8 @@
     if (ns->rtip != RTI_NULL) rt_free_rti(ns->rtip);
     if (ns->rtip_air != RTI_NULL) rt_free_rti(ns->rtip_air);
 
+    db_close(ns->dbip);
+
     bu_vls_free(ns->vals->path_name);
     bu_vls_free(ns->vals->reg_name);
     bu_vls_free(ns->vals->ov_reg1_name);

Modified: brlcad/trunk/src/nirt/main.cxx
===================================================================
--- brlcad/trunk/src/nirt/main.cxx      2018-02-11 20:25:55 UTC (rev 70693)
+++ brlcad/trunk/src/nirt/main.cxx      2018-02-12 14:06:23 UTC (rev 70694)
@@ -425,7 +425,6 @@
 int
 main(int argc, const char **argv)
 {
-
     return old_nirt_main(argc, argv);
 #if 0
     /* Make the old behavior accessible */
@@ -646,13 +645,7 @@
        bu_vls_free(&ncmd);
     }
 
-    /* We know enough now to initialize */
-    if (nirt_init(ns, dbip) == -1) {
-       bu_exit(EXIT_FAILURE, "nirt_init failed: %s\n", argv[0]);
-    }
-    db_close(dbip); /* nirt will now manage its own copies of the dbip */
-
-    /* Ready now - draw the initial set of objects, if supplied */
+    /* Draw the initial set of objects, if supplied */
     if (ac > 1) {
        int i = 0;
        struct bu_vls ncmd = BU_VLS_INIT_ZERO;
@@ -664,6 +657,12 @@
        bu_vls_free(&ncmd);
     }
 
+    /* We know enough now to initialize */
+    if (nirt_init(ns, dbip) == -1) {
+       bu_exit(EXIT_FAILURE, "nirt_init failed: %s\n", argv[0]);
+    }
+    db_close(dbip); /* nirt will now manage its own copies of the dbip */
+
     /* Report Database info */
     if (silent_mode != SILENT_YES) {
        const char *ustr = bu_units_string(dbip->dbi_local2base);

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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to