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 | + | <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) |
− | |||
− | |||
− | |||
− | |||
{ | { | ||
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)); | |
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 | + | <pre> |
− | + | $ gcc db_walk_tree_example.c -L/usr/brlcad/lib -lrt -lbu -I/usr/brlcad/include -I/usr/brlcad/include/brlcad | |
− | + | $ ./a.out 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 | + | counter is 80 |
</pre> | </pre> |