Revision: 47379
          http://brlcad.svn.sourceforge.net/brlcad/?rev=47379&view=rev
Author:   abhi2011
Date:     2011-11-01 16:42:01 +0000 (Tue, 01 Nov 2011)
Log Message:
-----------
Added a function to check if a solid is present in a comb, required for 
checking which rigid body(a comb), a particular solid belongs to , while 
raytracing.

Modified Paths:
--------------
    brlcad/trunk/src/libged/simulate/simutils.c
    brlcad/trunk/src/libged/simulate/simutils.h

Modified: brlcad/trunk/src/libged/simulate/simutils.c
===================================================================
--- brlcad/trunk/src/libged/simulate/simutils.c 2011-11-01 15:19:59 UTC (rev 
47378)
+++ brlcad/trunk/src/libged/simulate/simutils.c 2011-11-01 16:42:01 UTC (rev 
47379)
@@ -32,7 +32,10 @@
 #define ARROW_BASE_RADIUS 0.02
 #define ARROW_TIP_RADIUS  0.001
 
+#define SOLID_NOT_FOUND 0
+#define SOLID_FOUND     1
 
+
 void
 print_usage(struct bu_vls *str)
 {
@@ -114,7 +117,67 @@
 }
 
 
+HIDDEN int
+find_solid(struct db_i *dbip,
+        struct rt_comb_internal *comb,
+        union tree *comb_leaf,
+        genptr_t object)
+{
+    char *obj_name;
+
+    if (dbip) RT_CK_DBI(dbip);
+    if (comb) RT_CK_COMB(comb);
+    RT_CK_TREE(comb_leaf);
+
+    obj_name = (char *)object;
+    if (!BU_STR_EQUAL(comb_leaf->tr_l.tl_name, obj_name))
+       return SOLID_FOUND;
+    else
+       return SOLID_NOT_FOUND;
+}
+
+
 int
+check_tree_funcleaf(
+    struct db_i *dbip,
+    struct rt_comb_internal *comb,
+    union tree *comb_tree,
+    int (*leaf_func)(),
+    genptr_t user_ptr1)
+{
+       int rv = SOLID_NOT_FOUND;
+
+       RT_CK_DBI(dbip);
+
+    if (!comb_tree)
+       return SOLID_NOT_FOUND;
+
+    RT_CK_TREE(comb_tree);
+
+    switch (comb_tree->tr_op) {
+       case OP_DB_LEAF:
+           rv = (*leaf_func)(dbip, comb, comb_tree, user_ptr1);
+           break;
+       case OP_UNION:
+       case OP_INTERSECT:
+       case OP_SUBTRACT:
+       case OP_XOR:
+           rv = check_tree_funcleaf(dbip, comb, comb_tree->tr_b.tb_left, 
leaf_func, user_ptr1);
+           if(rv == SOLID_NOT_FOUND)
+               rv = check_tree_funcleaf(dbip, comb, comb_tree->tr_b.tb_right, 
leaf_func, user_ptr1);
+           break;
+       default:
+           bu_log("check_tree_funcleaf: bad op %d\n", comb_tree->tr_op);
+           bu_bomb("check_tree_funcleaf: bad op\n");
+           break;
+    }
+
+    return rv;
+}
+
+
+
+int
 kill(struct ged *gedp, char *name)
 {
     char *cmd_args[5];

Modified: brlcad/trunk/src/libged/simulate/simutils.h
===================================================================
--- brlcad/trunk/src/libged/simulate/simutils.h 2011-11-01 15:19:59 UTC (rev 
47378)
+++ brlcad/trunk/src/libged/simulate/simutils.h 2011-11-01 16:42:01 UTC (rev 
47379)
@@ -85,6 +85,36 @@
 
 
 /**
+ * This routine is called at the leaf nodes of the comb tree and checks
+ * if the leaf contains a prim of the same name as that passed in 'object'
+ * Returns SOLID_FOUND if the current(the passed) leaf contains a solid with
+ * the same name as that of 'object', otherwise SOLID_NOT_FOUND
+ *
+ */
+HIDDEN int
+find_solid(struct db_i *dbip,
+                  struct rt_comb_internal *comb,
+                  union tree *comb_leaf,
+                  genptr_t object);
+
+
+/**
+ * This routine traverses a combination (union tree) in LNR order and
+ * calls the provided function for each OP_DB_LEAF node.  Note that
+ * this routine does not go outside this one combination!!!!
+ *
+ * similar to db_tree_funcleaf() with just an extra return statement
+ */
+int
+check_tree_funcleaf(
+    struct db_i *dbip,
+    struct rt_comb_internal *comb,
+    union tree *comb_tree,
+    int (*leaf_func)(),
+    genptr_t user_ptr1);
+
+
+/**
  * Deletes a prim/comb if it exists.
  *
  * TODO: lower to librt

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
RSA® Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to