Skip to content

Commit

Permalink
nmg_booltree_evaluate -> rt_booltree_evaluate
Browse files Browse the repository at this point in the history
Make a version of nmg_booltree_evaluate that abstract out the actual nmg
boolean evaluation into a callback function, in order to allow the
substitution of other evaluation methods in lieu of nmg_bool.

Hopefully, this will make for easier apples-to-apples comparisons with
more complex CSG tree hierarchies when evaluating alternative boolean
methods.
  • Loading branch information
starseeker committed Oct 27, 2023
1 parent 00f5403 commit 6e3a685
Show file tree
Hide file tree
Showing 34 changed files with 454 additions and 322 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -1695,4 +1695,5 @@ s/bg_polygon_triangulate/bg_poly_triangulate/g
s/bg_nested_polygon_triangulate/bg_nested_poly_triangulate/g
s/OP_NMG_TESS/OP_TESS/g
s/tree_nmgregion/tree_tessellation/g
s/nmg_booltree_leaf_tess/rt_booltree_leaf_tess/g

2 changes: 2 additions & 0 deletions include/raytrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ __BEGIN_DECLS

#include "./rt/binunif.h"

#include "./rt/conv.h"

#include "./rt/version.h"


Expand Down
1 change: 1 addition & 0 deletions include/rt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(rt_headers
calc.h
cmd.h
comb.h
conv.h
db4.h
db5.h
db_attr.h
Expand Down
60 changes: 60 additions & 0 deletions include/rt/conv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* C O N V . H
* BRL-CAD
*
* Copyright (c) 1993-2023 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 rt/conv.h */

#ifndef RT_CONV_H
#define RT_CONV_H

#include "common.h"
#include "bu/list.h"
#include "bn/tol.h"
#include "rt/defines.h"
#include "rt/db_internal.h"
#include "rt/resource.h"
#include "nmg.h"

__BEGIN_DECLS

RT_EXPORT extern union tree *rt_booltree_leaf_tess(struct db_tree_state *tsp,
const struct db_full_path *pathp,
struct rt_db_internal *ip,
void *client_data);

RT_EXPORT extern union tree *rt_booltree_evaluate(union tree *tp,
struct bu_list *vlfree,
const struct bn_tol *tol,
struct resource *resp,
int (*do_bool)(union tree *, union tree *, union tree *, int op, struct bu_list *, const struct bn_tol *),
int verbose
);

__END_DECLS

#endif /* RT__CONV_H */

/*
* Local Variables:
* tab-width: 8
* mode: C
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
* ex: shiftwidth=4 tabstop=8
*/
4 changes: 0 additions & 4 deletions include/rt/nmg_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ RT_EXPORT extern struct rt_bot_internal *nmg_mdl_to_bot(struct model *m,
struct bu_list *vlfree,
const struct bn_tol *tol);
struct db_tree_state; /* forward declaration */
RT_EXPORT extern union tree *nmg_booltree_leaf_tess(struct db_tree_state *tsp,
const struct db_full_path *pathp,
struct rt_db_internal *ip,
void *client_data);
RT_EXPORT extern union tree *nmg_booltree_leaf_tnurb(struct db_tree_state *tsp,
const struct db_full_path *pathp,
struct rt_db_internal *ip,
Expand Down
2 changes: 1 addition & 1 deletion src/adrt/load_g.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ load_g(struct tie_s *tie, const char *db, int argc, const char **argv, struct ad
&tree_state, /* initial tree state */
nmg_to_adrt_regstart, /* region start function */
gcv_region_end, /* region end function */
nmg_booltree_leaf_tess, /* leaf func */
rt_booltree_leaf_tess, /* leaf func */
(void *)&gcvwriter); /* client data */

/* Release dynamic storage */
Expand Down
2 changes: 1 addition & 1 deletion src/conv/dxf/g-dxf.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ main(int argc, char *argv[])
&tree_state,
0, /* take all regions */
gcv_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)&gcvwriter); /* callback for gcv_region_end */

if (regions_tried>0) {
Expand Down
2 changes: 1 addition & 1 deletion src/conv/g-acad.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ main(int argc, char **argv)
&tree_state,
0, /* take all regions */
do_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)NULL); /* in librt/nmg_bool.c */

if (regions_tried>0) {
Expand Down
2 changes: 1 addition & 1 deletion src/conv/g-egg.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ main(int argc, char *argv[])
&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?NULL:nmg_booltree_leaf_tess, /* leaf func */
use_mc?NULL:rt_booltree_leaf_tess, /* leaf func */
(void *)&gcvwriter); /* client_data */
fprintf(conv_data.fp, "}\n");
}
Expand Down
2 changes: 1 addition & 1 deletion src/conv/g-nff.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ main(int argc, char *argv[])
&tree_state,
0, /* take all regions */
do_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)NULL); /* in librt/nmg_bool.c */

if (regions_tried > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/conv/g-obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ main(int argc, const char **argv)
&tree_state,
0, /* take all regions */
do_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)NULL); /* in librt/nmg_bool.c */

if (regions_tried>0) {
Expand Down
4 changes: 2 additions & 2 deletions src/conv/g-vrml.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ leaf_tess1(struct db_tree_state *tsp, const struct db_full_path *pathp, struct r

if (ip->idb_type != ID_BOT) {
pmp->num_nonbots++;
return nmg_booltree_leaf_tess(tsp, pathp, ip, client_data);
return rt_booltree_leaf_tess(tsp, pathp, ip, client_data);
}

bot = (struct rt_bot_internal *)ip->idb_ptr;
Expand Down Expand Up @@ -750,7 +750,7 @@ main(int argc, char **argv)
&tree_state,
0,
nmg_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)&pm); /* in librt/nmg_bool.c */
goto out;
}
Expand Down
4 changes: 2 additions & 2 deletions src/conv/g-x3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ leaf_tess(struct db_tree_state *tsp, const struct db_full_path *pathp, struct rt

if (ip->idb_type != ID_BOT) {
pmp->num_nonbots++;
return nmg_booltree_leaf_tess(tsp, pathp, ip, client_data);
return rt_booltree_leaf_tess(tsp, pathp, ip, client_data);
}

bot = (struct rt_bot_internal *)ip->idb_ptr;
Expand All @@ -288,7 +288,7 @@ leaf_tess(struct db_tree_state *tsp, const struct db_full_path *pathp, struct rt

pmp->num_nonbots++;

return nmg_booltree_leaf_tess(tsp, pathp, ip, client_data);
return rt_booltree_leaf_tess(tsp, pathp, ip, client_data);
}


Expand Down
2 changes: 1 addition & 1 deletion src/conv/g-xxx_facets.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ main(int argc, char **argv)
&tree_state,
0, /* take all regions */
do_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)NULL); /* in librt/nmg_bool.c */

if (regions_tried>0) {
Expand Down
4 changes: 2 additions & 2 deletions src/conv/iges/g-iges.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ main(int argc, char *argv[])
&tree_state,
0, /* take all regions */
do_nmg_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)NULL); /* in librt/nmg_bool.c */

if (ret)
Expand Down Expand Up @@ -392,7 +392,7 @@ main(int argc, char *argv[])
&tree_state,
0, /* take all regions */
do_nmg_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)NULL); /* in librt/nmg_bool.c */

if (ret)
Expand Down
2 changes: 1 addition & 1 deletion src/conv/jack/g-jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ main(int argc, char **argv)
&jack_tree_state,
0, /* take all regions */
do_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)NULL); /* in librt/nmg_bool.c */

fprintf(fp_fig, "\troot=%s_seg.base;\n", bu_vls_addr(&base_seg));
Expand Down
2 changes: 1 addition & 1 deletion src/conv/off/g-off.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ main(int argc, char **argv)
&jack_tree_state,
0, /* take all regions */
do_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)NULL); /* in librt/nmg_bool.c */

fprintf(fp_fig, "\troot=%s_seg.base;\n", bu_vls_addr(&base_seg));
Expand Down
2 changes: 1 addition & 1 deletion src/conv/raw/g-raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ main(int argc, char *argv[])
&tree_state,
0, /* take all regions */
use_mc?gcv_region_end_mc:gcv_region_end,
use_mc?NULL:nmg_booltree_leaf_tess,
use_mc?NULL:rt_booltree_leaf_tess,
(void *)&gcvwriter);

if (regions_tried>0) {
Expand Down
2 changes: 1 addition & 1 deletion src/conv/stl/g-stl.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ main(int argc, char *argv[])
&tree_state,
0, /* take all regions */
use_mc?gcv_region_end_mc:gcv_region_end,
use_mc?NULL:nmg_booltree_leaf_tess,
use_mc?NULL:rt_booltree_leaf_tess,
(void *)&gcvwriter);

if (regions_tried>0) {
Expand Down
2 changes: 1 addition & 1 deletion src/isst/gfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ GFile::load_g(const char *filename, int argc, const char *argv[])
&tree_state, /* initial tree state */
nmg_to_adrt_regstart, /* region start function */
gcv_region_end, /* region end function */
nmg_booltree_leaf_tess, /* leaf func */
rt_booltree_leaf_tess, /* leaf func */
(void *)&gcvwriter); /* client data */

/* Release dynamic storage */
Expand Down
2 changes: 1 addition & 1 deletion src/libgcv/bottess.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ gcv_bottess(int argc, const char **argv, struct db_i *dbip, struct bg_tess_tol *
struct db_tree_state tree_state = rt_initial_tree_state;
tree_state.ts_ttol = ttol;

if (db_walk_tree(dbip, argc, argv, 1, &tree_state, NULL, gcv_bottess_region_end, nmg_booltree_leaf_tess, NULL) < 0)
if (db_walk_tree(dbip, argc, argv, 1, &tree_state, NULL, gcv_bottess_region_end, rt_booltree_leaf_tess, NULL) < 0)
bu_log("gcv_bottess: db_walk_tree failure\n");

return NULL;
Expand Down
3 changes: 2 additions & 1 deletion src/libgcv/facetize.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "bu/parallel.h"
#include "gcv/util.h"
#include "rt/conv.h"
#include "rt/db5.h"
#include "rt/db_internal.h"
#include "rt/wdb.h"
Expand Down Expand Up @@ -165,7 +166,7 @@ gcv_facetize(struct db_i *db, const struct db_full_path *path,
nmg_model = nmg_mm();

if (db_walk_tree(db, 1, (const char **)&str_path, 1, &initial_tree_state, NULL,
_gcv_facetize_region_end, nmg_booltree_leaf_tess, &facetize_tree)) {
_gcv_facetize_region_end, rt_booltree_leaf_tess, &facetize_tree)) {
bu_log("gcv_facetize(): error in db_walk_tree()\n");
bu_free(str_path, "str_path");
return _gcv_facetize_cleanup(nmg_model, facetize_tree);
Expand Down
4 changes: 2 additions & 2 deletions src/libgcv/plugins/assetimport/assetimport_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,15 @@ assetimport_write(struct gcv_context *context, const struct gcv_opts *gcv_option
&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)?NULL:nmg_booltree_leaf_tess,
(gcv_options->tessellation_algorithm == GCV_TESS_MARCHING_CUBES)?NULL:rt_booltree_leaf_tess,
(void *)&gcvwriter);
} else {
(void) db_walk_tree(context->dbip, gcv_options->num_objects, (const char **)gcv_options->object_names,
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)?NULL:nmg_booltree_leaf_tess,
(gcv_options->tessellation_algorithm == GCV_TESS_MARCHING_CUBES)?NULL:rt_booltree_leaf_tess,
(void *)&gcvwriter);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libgcv/plugins/fastgen4/fastgen4_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,7 @@ convert_leaf(db_tree_state *tree_state, const db_full_path *path,
if (!facetize && subtracted)
data.m_failed_regions.insert(region_dir);
else
return nmg_booltree_leaf_tess(tree_state, path, internal, client_data);
return rt_booltree_leaf_tess(tree_state, path, internal, client_data);
}

tree *result;
Expand Down
2 changes: 1 addition & 1 deletion src/libgcv/plugins/obj/obj_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ obj_write(struct gcv_context *context, const struct gcv_opts *gcv_options, const

/* Walk indicated tree(s). Each region will be output separately */
(void) db_walk_tree(context->dbip, state.gcv_options->num_objects, (const char **)state.gcv_options->object_names,
1, &tree_state, NULL, do_region_end, nmg_booltree_leaf_tess, (void *)&state);
1, &tree_state, NULL, do_region_end, rt_booltree_leaf_tess, (void *)&state);

if (state.regions_tried) {
double percent = ((double)state.regions_converted * 100.0) / state.regions_tried;
Expand Down
2 changes: 1 addition & 1 deletion src/libgcv/plugins/ply/ply_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ ply_write_gcv(struct gcv_context* context, const struct gcv_opts* gcv_options, c
&tree_state,
0, /* take all regions */
do_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void*)&state);

if (state.ply_write_options->verbose || state.gcv_options->verbosity_level)
Expand Down
2 changes: 1 addition & 1 deletion src/libgcv/plugins/stl/stl_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ stl_write(struct gcv_context *context, const struct gcv_opts *gcv_options, const
&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)?NULL:nmg_booltree_leaf_tess,
(gcv_options->tessellation_algorithm == GCV_TESS_MARCHING_CUBES)?NULL:rt_booltree_leaf_tess,
(void *)&gcvwriter);

if (state.regions_tried>0) {
Expand Down
4 changes: 2 additions & 2 deletions src/libgcv/plugins/vrml/vrml_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ leaf_tess1(struct db_tree_state *tsp, const struct db_full_path *pathp, struct r

if (ip->idb_type != ID_BOT) {
data->pmp->num_nonbots++;
return nmg_booltree_leaf_tess(tsp, pathp, ip, client_data);
return rt_booltree_leaf_tess(tsp, pathp, ip, client_data);
}

bot = (struct rt_bot_internal *)ip->idb_ptr;
Expand Down Expand Up @@ -1300,7 +1300,7 @@ vrml_write(struct gcv_context *context, const struct gcv_opts *gcv_options, cons
&tree_state,
0,
nmg_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)&region_end_data); /* in librt/nmg_bool.c */
goto out;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libged/bev/bev.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ ged_bev_core(struct ged *gedp, int argc, const char *argv[])
&wdbp->wdb_initial_tree_state,
0, /* take all regions */
bev_facetize_region_end,
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)gedp);

if (i < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/libged/draw/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ _ged_drawtrees(struct ged *gedp, int argc, const char *argv[], int kind, struct
&wdbp->wdb_initial_tree_state,
enable_fastpath ? draw_nmg_region_start : 0,
draw_nmg_region_end,
nmg_use_tnurbs ? nmg_booltree_leaf_tnurb : nmg_booltree_leaf_tess,
nmg_use_tnurbs ? nmg_booltree_leaf_tnurb : rt_booltree_leaf_tess,
(void *)&dgcdp);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libged/facetize/facetize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ _try_nmg_facetize(struct ged *gedp, int argc, const char **argv, int nmg_use_tnu
facetize_region_end,
nmg_use_tnurbs ?
nmg_booltree_leaf_tnurb :
nmg_booltree_leaf_tess,
rt_booltree_leaf_tess,
(void *)&facetize_tree
);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/librt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ set(LIBRT_SOURCES
binunif/binunif.c
binunif/db5_bin.c
bool.c
bool_tess.c
bundle.c
cache.c
cache_lz4.c
Expand Down
Loading

0 comments on commit 6e3a685

Please sign in to comment.