Revision: 65139
http://sourceforge.net/p/brlcad/code/65139
Author: starseeker
Date: 2015-06-01 21:05:14 +0000 (Mon, 01 Jun 2015)
Log Message:
-----------
Start setting up for a reall geometry diff visualization. Something's not
right with the pattern, but getting a meaningful visual.
Modified Paths:
--------------
brlcad/trunk/include/analyze.h
brlcad/trunk/src/libanalyze/raydiff.c
brlcad/trunk/src/libanalyze/tests/raydiff.c
brlcad/trunk/src/libanalyze/tests/raydiff.g
brlcad/trunk/src/libged/gdiff.c
Modified: brlcad/trunk/include/analyze.h
===================================================================
--- brlcad/trunk/include/analyze.h 2015-06-01 20:13:36 UTC (rev 65138)
+++ brlcad/trunk/include/analyze.h 2015-06-01 21:05:14 UTC (rev 65139)
@@ -126,9 +126,24 @@
voxelize(struct rt_i *rtip, fastf_t voxelSize[3], int levelOfDetail, void
(*create_boxes)(void *callBackData, int x, int y, int z, const char
*regionName, fastf_t percentageFill), void *callBackData);
+struct analyze_raydiff_results {
+ struct bu_ptbl *left;
+ struct bu_ptbl *right;
+ struct bu_ptbl *both;
+};
+
+struct diff_seg {
+ point_t in_pt;
+ point_t out_pt;
+};
+
+void
+analyze_raydiff_results_free(struct analyze_raydiff_results *results);
+
ANALYZE_EXPORT int
-analyze_raydiff(struct db_i *dbip, const char *obj1, const char *obj2, struct
bn_tol *tol);
+analyze_raydiff(struct analyze_raydiff_results **results, struct db_i *dbip,
+ const char *left, const char *right, struct bn_tol *tol);
__END_DECLS
Modified: brlcad/trunk/src/libanalyze/raydiff.c
===================================================================
--- brlcad/trunk/src/libanalyze/raydiff.c 2015-06-01 20:13:36 UTC (rev
65138)
+++ brlcad/trunk/src/libanalyze/raydiff.c 2015-06-01 21:05:14 UTC (rev
65139)
@@ -30,12 +30,48 @@
#include "bu/log.h"
#include "bu/ptbl.h"
#include "raytrace.h"
+#include "analyze.h"
-struct diff_seg {
- point_t in_pt;
- point_t out_pt;
-};
+void
+analyze_raydiff_results_init(struct analyze_raydiff_results **results)
+{
+ if (!results) return;
+ BU_GET((*results), struct analyze_raydiff_results);
+ BU_GET((*results)->left, struct bu_ptbl);
+ BU_GET((*results)->right, struct bu_ptbl);
+ BU_GET((*results)->both, struct bu_ptbl);
+ bu_ptbl_init((*results)->left, 64, "init left");
+ bu_ptbl_init((*results)->right, 64, "init right");
+ bu_ptbl_init((*results)->both, 64, "init both");
+}
+void
+analyze_raydiff_results_free(struct analyze_raydiff_results *results)
+{
+ size_t i;
+ if (!results) return;
+ for (i = 0; i < BU_PTBL_LEN(results->left); i++) {
+ struct diff_seg *dseg = (struct diff_seg *)BU_PTBL_GET(results->left,
i);
+ BU_PUT(dseg, struct diff_seg);
+ }
+ bu_ptbl_free(results->left);
+ BU_PUT(results->left, struct diff_seg);
+ for (i = 0; i < BU_PTBL_LEN(results->both); i++) {
+ struct diff_seg *dseg = (struct diff_seg *)BU_PTBL_GET(results->both,
i);
+ BU_PUT(dseg, struct diff_seg);
+ }
+ bu_ptbl_free(results->both);
+ BU_PUT(results->both, struct diff_seg);
+ for (i = 0; i < BU_PTBL_LEN(results->right); i++) {
+ struct diff_seg *dseg = (struct diff_seg *)BU_PTBL_GET(results->right,
i);
+ BU_PUT(dseg, struct diff_seg);
+ }
+ bu_ptbl_free(results->right);
+ BU_PUT(results->right, struct diff_seg);
+
+ BU_PUT(results, struct analyze_raydiff_results);
+}
+
struct raydiff_container {
struct rt_i *rtip;
struct resource *resp;
@@ -171,8 +207,8 @@
/* 0 = no difference within tolerance, 1 = difference >= tolerance */
int
-analyze_raydiff(/* TODO - decide what to return. Probably some sort of left,
common, right segment sets. See what rtcheck does... */
- struct db_i *dbip, const char *obj1, const char *obj2, struct bn_tol
*tol)
+analyze_raydiff(struct analyze_raydiff_results **results, struct db_i *dbip,
+ const char *left, const char *right, struct bn_tol *tol)
{
int ret;
int count = 0;
@@ -183,11 +219,11 @@
fastf_t *rays;
struct raydiff_container *state;
- if (!dbip || !obj1 || !obj2 || !tol) return 0;
+ if (!results || !dbip || !left || !right|| !tol) return 0;
rtip = rt_new_rti(dbip);
- if (rt_gettree(rtip, obj1) < 0) return -1;
- if (rt_gettree(rtip, obj2) < 0) return -1;
+ if (rt_gettree(rtip, left) < 0) return -1;
+ if (rt_gettree(rtip, right) < 0) return -1;
rt_prep_parallel(rtip, 1);
@@ -287,8 +323,8 @@
state[i].rtip = rtip;
state[i].tol = 0.5;
state[i].ncpus = ncpus;
- state[i].left_name = bu_strdup(obj1);
- state[i].right_name = bu_strdup(obj2);
+ state[i].left_name = bu_strdup(left);
+ state[i].right_name = bu_strdup(right);
BU_GET(state[i].resp, struct resource);
rt_init_resource(state[i].resp, i, state->rtip);
BU_GET(state[i].left, struct bu_ptbl);
@@ -302,43 +338,28 @@
}
bu_parallel(raydiff_gen_worker, ncpus, (void *)state);
+
+ /* Now we should have results */
+ analyze_raydiff_results_init(results);
+
/* Collect and print all of the results */
for (i = 0; i < ncpus+1; i++) {
for (j = 0; j < (int)BU_PTBL_LEN(state[i].left); j++) {
- struct diff_seg *dseg = (struct diff_seg
*)BU_PTBL_GET(state[i].left, j);
- bu_log("Result: LEFT diff vol (%s): %g %g %g -> %g %g %g\n",
obj1, V3ARGS(dseg->in_pt), V3ARGS(dseg->out_pt));
+ bu_ptbl_ins((*results)->left, BU_PTBL_GET(state[i].left, j));
}
for (j = 0; j < (int)BU_PTBL_LEN(state[i].both); j++) {
- struct diff_seg *dseg = (struct diff_seg
*)BU_PTBL_GET(state[i].both, j);
- bu_log("Result: BOTH): %g %g %g -> %g %g %g\n",
V3ARGS(dseg->in_pt), V3ARGS(dseg->out_pt));
+ bu_ptbl_ins((*results)->both, BU_PTBL_GET(state[i].both, j));
}
for (j = 0; j < (int)BU_PTBL_LEN(state[i].right); j++) {
- struct diff_seg *dseg = (struct diff_seg
*)BU_PTBL_GET(state[i].right, j);
- bu_log("Result: RIGHT diff vol (%s): %g %g %g -> %g %g %g\n",
obj2, V3ARGS(dseg->in_pt), V3ARGS(dseg->out_pt));
+ bu_ptbl_ins((*results)->right, BU_PTBL_GET(state[i].right, j));
}
}
- /* Free results */
+ /* Free memory not stored in tables */
for (i = 0; i < ncpus+1; i++) {
- for (j = 0; j < (int)BU_PTBL_LEN(state[i].left); j++) {
- struct diff_seg *dseg = (struct diff_seg
*)BU_PTBL_GET(state[i].left, j);
- BU_PUT(dseg, struct diff_seg);
- }
- bu_ptbl_free(state[i].left);
- BU_PUT(state[i].left, struct diff_seg);
- for (j = 0; j < (int)BU_PTBL_LEN(state[i].both); j++) {
- struct diff_seg *dseg = (struct diff_seg
*)BU_PTBL_GET(state[i].both, j);
- BU_PUT(dseg, struct diff_seg);
- }
- bu_ptbl_free(state[i].both);
- BU_PUT(state[i].both, struct diff_seg);
- for (j = 0; j < (int)BU_PTBL_LEN(state[i].right); j++) {
- struct diff_seg *dseg = (struct diff_seg
*)BU_PTBL_GET(state[i].right, j);
- BU_PUT(dseg, struct diff_seg);
- }
- bu_ptbl_free(state[i].right);
- BU_PUT(state[i].right, struct diff_seg);
-
+ BU_PUT(state[i].left, struct bu_ptbl);
+ BU_PUT(state[i].right, struct bu_ptbl);
+ BU_PUT(state[i].both, struct bu_ptbl);
bu_free((void *)state[i].left_name, "left name");
bu_free((void *)state[i].right_name, "right name");
BU_PUT(state[i].resp, struct resource);
Modified: brlcad/trunk/src/libanalyze/tests/raydiff.c
===================================================================
--- brlcad/trunk/src/libanalyze/tests/raydiff.c 2015-06-01 20:13:36 UTC (rev
65138)
+++ brlcad/trunk/src/libanalyze/tests/raydiff.c 2015-06-01 21:05:14 UTC (rev
65139)
@@ -30,10 +30,12 @@
int
main(int argc, char **argv)
{
+ size_t i;
struct db_i *dbip = DBI_NULL;
struct directory *dp1 = RT_DIR_NULL;
struct directory *dp2 = RT_DIR_NULL;
struct bn_tol tol = {BN_TOL_MAGIC, BN_TOL_DIST, BN_TOL_DIST * BN_TOL_DIST,
1.0e-6, 1.0 - 1.0e-6 };
+ struct analyze_raydiff_results *results;
if (argc != 4) {
bu_log("Error - please specify a .g file and two objects\n");
@@ -59,8 +61,24 @@
if (dp1 == RT_DIR_NULL || dp2 == RT_DIR_NULL) return 1;
- analyze_raydiff(dbip, dp1->d_namep, dp2->d_namep, &tol);
+ analyze_raydiff(&results, dbip, dp1->d_namep, dp2->d_namep, &tol);
+ /* Print results */
+ for (i = 0; i < BU_PTBL_LEN(results->left); i++) {
+ struct diff_seg *dseg = (struct diff_seg *)BU_PTBL_GET(results->left,
i);
+ bu_log("Result: LEFT diff vol (%s): %g %g %g -> %g %g %g\n", argv[2],
V3ARGS(dseg->in_pt), V3ARGS(dseg->out_pt));
+ }
+ for (i = 0; i < BU_PTBL_LEN(results->both); i++) {
+ struct diff_seg *dseg = (struct diff_seg *)BU_PTBL_GET(results->both,
i);
+ bu_log("Result: BOTH): %g %g %g -> %g %g %g\n", V3ARGS(dseg->in_pt),
V3ARGS(dseg->out_pt));
+ }
+ for (i = 0; i < BU_PTBL_LEN(results->right); i++) {
+ struct diff_seg *dseg = (struct diff_seg *)BU_PTBL_GET(results->right,
i);
+ bu_log("Result: RIGHT diff vol (%s): %g %g %g -> %g %g %g\n", argv[3],
V3ARGS(dseg->in_pt), V3ARGS(dseg->out_pt));
+ }
+
+ analyze_raydiff_results_free(results);
+
db_close(dbip);
return 0;
}
Modified: brlcad/trunk/src/libanalyze/tests/raydiff.g
===================================================================
(Binary files differ)
Modified: brlcad/trunk/src/libged/gdiff.c
===================================================================
--- brlcad/trunk/src/libged/gdiff.c 2015-06-01 20:13:36 UTC (rev 65138)
+++ brlcad/trunk/src/libged/gdiff.c 2015-06-01 21:05:14 UTC (rev 65139)
@@ -29,6 +29,7 @@
#include "bu/cmd.h"
#include "bu/getopt.h"
+#include "analyze.h"
#include "./ged_private.h"
@@ -41,6 +42,9 @@
int
ged_gdiff(struct ged *gedp, int argc, const char *argv[])
{
+ size_t i;
+ struct analyze_raydiff_results *results;
+ struct bn_tol tol = {BN_TOL_MAGIC, BN_TOL_DIST, BN_TOL_DIST * BN_TOL_DIST,
1.0e-6, 1.0 - 1.0e-6 };
int left_dbip_specified = 0;
int right_dbip_specified = 0;
int c = 0;
@@ -86,40 +90,6 @@
return GED_ERROR;
}
}
-
- {
- /* Construct a minimal example visual display of a ray diff */
- struct bu_list *vhead;
- struct bu_list local_vlist;
- struct bn_vlblock *vbp;
- point_t a, b;
- BU_LIST_INIT(&local_vlist);
- vbp = bn_vlblock_init(&local_vlist, 32);
- VSET(a, -100, 0, 0);
- VSET(b, 0, 0, 0);
- /* Draw left-only lines */
- vhead = bn_vlblock_find(vbp, 255, 0, 0); /* should be red */
- BN_ADD_VLIST(vbp->free_vlist_hd, vhead, a, BN_VLIST_LINE_MOVE);
- BN_ADD_VLIST(vbp->free_vlist_hd, vhead, b, BN_VLIST_LINE_DRAW);
- /* Draw overlap lines */
- VSET(a, 0, 0, 0);
- VSET(b, 100, 0, 0);
- vhead = bn_vlblock_find(vbp, 255, 255, 255); /* should be white */
- BN_ADD_VLIST(vbp->free_vlist_hd, vhead, a, BN_VLIST_LINE_MOVE);
- BN_ADD_VLIST(vbp->free_vlist_hd, vhead, b, BN_VLIST_LINE_DRAW);
- /* Draw right-only lines */
- VSET(a, 100, 0, 0);
- VSET(b, 200, 0, 0);
- vhead = bn_vlblock_find(vbp, 0, 0, 255); /* should be blue */
- BN_ADD_VLIST(vbp->free_vlist_hd, vhead, a, BN_VLIST_LINE_MOVE);
- BN_ADD_VLIST(vbp->free_vlist_hd, vhead, b, BN_VLIST_LINE_DRAW);
-
- _ged_cvt_vlblock_to_solids(gedp, vbp, "diff_visual", 0);
-
- bn_vlist_cleanup(&local_vlist);
- bn_vlblock_free(vbp);
- }
-
/* There are possible convention-based interpretations of 1, 2, 3, 4 and n
args
* beyond those used as options. For the shortest cases, the
interpretation depends
* on whether one or two .g files are known:
@@ -152,7 +122,6 @@
*
* When there is a current .g environment and two additional .g files are
* specified, the argv environments will override use of the "current" .g
environment.
- */
if ((argc - bu_optind) == 2) {
bu_log("left: %s", argv[bu_optind]);
bu_log("right: %s", argv[bu_optind+1]);
@@ -165,7 +134,63 @@
return GED_ERROR;
}
}
+ */
+
+ if ((argc - bu_optind) != 2) {
+ return GED_ERROR;
+ }
+
+ bu_log("left: %s", argv[bu_optind]);
+ bu_log("right: %s", argv[bu_optind+1]);
+
+ analyze_raydiff(&results, gedp->ged_wdbp->dbip, argv[bu_optind],
argv[bu_optind+1], &tol);
+
+ {
+ /* Construct a minimal example visual display of a ray diff */
+ struct bu_list *vhead;
+ struct bu_list local_vlist;
+ struct bn_vlblock *vbp;
+ point_t a, b;
+ BU_LIST_INIT(&local_vlist);
+ vbp = bn_vlblock_init(&local_vlist, 32);
+
+ /* Draw left-only lines */
+ for (i = 0; i < BU_PTBL_LEN(results->left); i++) {
+ struct diff_seg *dseg = (struct diff_seg
*)BU_PTBL_GET(results->left, i);
+ VMOVE(a, dseg->in_pt);
+ VMOVE(b, dseg->out_pt);
+ vhead = bn_vlblock_find(vbp, 255, 0, 0); /* should be red */
+ BN_ADD_VLIST(vbp->free_vlist_hd, vhead, a, BN_VLIST_LINE_MOVE);
+ BN_ADD_VLIST(vbp->free_vlist_hd, vhead, b, BN_VLIST_LINE_DRAW);
+ }
+ /* Draw overlap lines */
+ for (i = 0; i < BU_PTBL_LEN(results->both); i++) {
+ struct diff_seg *dseg = (struct diff_seg
*)BU_PTBL_GET(results->both, i);
+ VMOVE(a, dseg->in_pt);
+ VMOVE(b, dseg->out_pt);
+ vhead = bn_vlblock_find(vbp, 255, 255, 255); /* should be white */
+ BN_ADD_VLIST(vbp->free_vlist_hd, vhead, a, BN_VLIST_LINE_MOVE);
+ BN_ADD_VLIST(vbp->free_vlist_hd, vhead, b, BN_VLIST_LINE_DRAW);
+
+ }
+ for (i = 0; i < BU_PTBL_LEN(results->right); i++) {
+ struct diff_seg *dseg = (struct diff_seg
*)BU_PTBL_GET(results->right, i);
+ VMOVE(a, dseg->in_pt);
+ VMOVE(b, dseg->out_pt);
+ vhead = bn_vlblock_find(vbp, 0, 0, 255); /* should be blue */
+ BN_ADD_VLIST(vbp->free_vlist_hd, vhead, a, BN_VLIST_LINE_MOVE);
+ BN_ADD_VLIST(vbp->free_vlist_hd, vhead, b, BN_VLIST_LINE_DRAW);
+ }
+
+ _ged_cvt_vlblock_to_solids(gedp, vbp, "diff_visual", 0);
+
+ bn_vlist_cleanup(&local_vlist);
+ bn_vlblock_free(vbp);
+ }
+
+ analyze_raydiff_results_free(results);
+
return GED_OK;
}
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