Editing Example db walk tree

From BRL-CAD

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 2: Line 2:
 
This is a simple example program that shows how to walk a geometry database while performing some operation on geometry as it is encountered.  In this particular example, we iterate just over regions and simply count them:
 
This is a simple example program that shows how to walk a geometry database while performing some operation on geometry as it is encountered.  In this particular example, we iterate just over regions and simply count them:
  
<pre lang="C">
+
<source lang="C">
 +
 
 
#include "common.h"
 
#include "common.h"
 
#include "raytrace.h"
 
#include "raytrace.h"
  
int incr_region(
+
int incr_region(struct db_tree_state *tsp, struct db_full_path *pathp, const struct rt_comb_internal *combp, void *data)
    struct db_tree_state *tsp,
 
    struct db_full_path *pathp,
 
    const struct rt_comb_internal *combp,
 
    void *data)
 
 
{
 
{
 
   int *counter = (int*)data;
 
   int *counter = (int*)data;
Line 39: Line 36:
  
 
   bu_log("Database title is:\n%s\n", dbip->dbi_title);
 
   bu_log("Database title is:\n%s\n", dbip->dbi_title);
//bu_log("Units: %s\n", bu_units_string(dbip->dbi_local2base));
+
// bu_log("Units: %s\n", bu_units_string(dbip->dbi_local2base));
  
 
   if (db_lookup(dbip, argv[2], 1) == NULL) {
 
   if (db_lookup(dbip, argv[2], 1) == NULL) {
Line 51: Line 48:
  
 
   db_walk_tree(dbip, 1, (const char **)argv+2, 1, &state, incr_region, NULL, NULL, &counter);
 
   db_walk_tree(dbip, 1, (const char **)argv+2, 1, &state, incr_region, NULL, NULL, &counter);
 +
 +
  
 
   bu_log("counter is %d\n", counter);
 
   bu_log("counter is %d\n", counter);
 
   return 0;
 
   return 0;
 +
 
}
 
}
</pre>
+
</source>
  
 
If we compile this program and run it on a sample geometry database, we get the following:
 
If we compile this program and run it on a sample geometry database, we get the following:
  
<pre lang="bash">
+
<source lang="bash">
 
# you may need to replace /usr/brlcad with the path to where BRL-CAD is installed on your system
 
# you may need to replace /usr/brlcad with the path to where BRL-CAD is installed on your system
 
$ gcc -o db_walk_tree_example -I/usr/brlcad/include -I/usr/brlcad/include/brlcad db_walk_tree_example.c -L/usr/brlcad/lib -lrt -lbu
 
$ gcc -o db_walk_tree_example -I/usr/brlcad/include -I/usr/brlcad/include/brlcad db_walk_tree_example.c -L/usr/brlcad/lib -lrt -lbu
Line 71: Line 71:
 
...incrementing...
 
...incrementing...
 
counter is 83
 
counter is 83
</pre>
+
</source>

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)