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">
+
<pre>
 
#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, genptr_t 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 18: Line 14:
 
}
 
}
  
int main(int argc, char *argv[]){
+
int
 
+
main(int argc, char *argv[])
 +
{
 
   struct db_i *dbip;
 
   struct db_i *dbip;
 
   int counter = 0;
 
   int counter = 0;
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 53: Line 50:
  
 
   bu_log("counter is %d\n", counter);
 
   bu_log("counter is %d\n", counter);
 +
 
   return 0;
 
   return 0;
 
}
 
}
Line 59: Line 57:
 
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">
+
<pre>
# you may need to replace /usr/brlcad with the path to where BRL-CAD is installed on your system
+
$ gcc db_walk_tree_example.c -L/usr/brlcad/lib -lrt -lbu -I/usr/brlcad/include -I/usr/brlcad/include/brlcad
$ 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
+
$ ./a.out db/ktank.g tank
 
 
$ ./db_walk_tree_example db/ktank.g tank
 
 
Database title is:
 
Database title is:
 
Keith's Tank
 
Keith's Tank
 
+
Units: in
 
...incrementing...
 
...incrementing...
 
<... trimmed output ...>
 
<... trimmed output ...>
 
...incrementing...
 
...incrementing...
counter is 83
+
counter is 80
 
</pre>
 
</pre>

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)