Revision: 47408
          http://brlcad.svn.sourceforge.net/brlcad/?rev=47408&view=rev
Author:   abhi2011
Date:     2011-11-03 05:27:51 +0000 (Thu, 03 Nov 2011)
Log Message:
-----------
Normals already encountered, were not being added to the list of normals, fixed 
that. There are situations where summing the normals in the overlapping surface 
alone will not give the exact direction from which a body is hitting another 
body. But simply using the velocity also does not work for all cases to find 
this direction. Somewhere these 2 ways need to be merged or chosen from , based 
upon criteria.

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

Modified: brlcad/trunk/src/libged/simulate/simrt.c
===================================================================
--- brlcad/trunk/src/libged/simulate/simrt.c    2011-11-03 00:34:08 UTC (rev 
47407)
+++ brlcad/trunk/src/libged/simulate/simrt.c    2011-11-03 05:27:51 UTC (rev 
47408)
@@ -464,18 +464,35 @@
 exists_normal(vect_t n)
 {
     int i;
-    vect_t a;
+
     for(i=0; i<rt_result.num_normals; i++){
-       VMOVE(a, rt_result.normals[i]);
-       if(VEQUAL(a, n))
-           return 1;
+               if(VEQUAL(rt_result.normals[i], n))
+                       return 1;
     }
 
     return 0;
 }
 
 
+
 int
+add_normal(vect_t n)
+{
+    if(rt_result.num_normals < MAX_NORMALS){
+       VMOVE(rt_result.normals[rt_result.num_normals], n);
+       rt_result.num_normals++;
+       return 1;
+    }
+    else{
+       bu_log("add_normal: WARNING Number of normals have been exceeded, only 
%d allowed, (%f,%f,%f) not added",
+                       MAX_NORMALS, V3ARGS(n));
+    }
+
+    return 0;
+}
+
+
+int
 traverse_xray_lists(
                struct sim_manifold *current_manifold,
                struct simulation_params *sim_params,
@@ -531,13 +548,13 @@
                comb = (struct rt_comb_internal *)intern.idb_ptr;
 
 
-               /* Check if the in solid belongs to rbB */
+               /* Check if the in solid belongs to rbB and also if the normal 
has been summed before(do not sum if so) */
                rv = check_tree_funcleaf(sim_params->gedp->ged_wdbp->dbip,
                                                        comb,
                                                        comb->tree,
                                                        find_solid,
                                                        
(genptr_t)(overlap_list[i].insol->st_name));
-               if(rv == SOLID_FOUND){
+               if(rv == FOUND && !exists_normal(overlap_list[i].in_normal) ){
                        /* It does, so sum the in_normal */
                        bu_log("traverse_xray_lists: %s is present in %s", 
overlap_list[i].insol->st_name,
                                                                                
                                           current_manifold->rbB->rb_namep);
@@ -546,20 +563,17 @@
                        VADD2(rt_result.resultant_normal_B, 
rt_result.resultant_normal_B, overlap_list[i].in_normal);
                        bu_log("traverse_xray_lists: resultant_normal_B is now 
(%f,%f,%f) after adding (%f,%f,%f)",
                                        V3ARGS(rt_result.resultant_normal_B), 
V3ARGS(overlap_list[i].in_normal));
+                       add_normal(overlap_list[i].in_normal);
 
-                       VUNITIZE(rt_result.resultant_normal_B);
-                       bu_log("traverse_xray_lists: resultant_normal_B is 
(%f,%f,%f) after unitizing",
-                                                                               
        V3ARGS(rt_result.resultant_normal_B));
-
                }
 
-               /* Check if the out solid belongs to rbB */
+               /* Check if the out solid belongs to rbB and also if the normal 
has been summed before(do not sum if so) */
                rv = check_tree_funcleaf(sim_params->gedp->ged_wdbp->dbip,
                                                                        comb,
                                                                        
comb->tree,
                                                                        
find_solid,
                                                                        
(genptr_t)(overlap_list[i].outsol->st_name));
-               if(rv == SOLID_FOUND){
+               if(rv == FOUND && !exists_normal(overlap_list[i].out_normal) ){
                        /* It does, so sum the in_normal */
                        bu_log("traverse_xray_lists: %s is present in %s", 
overlap_list[i].outsol->st_name,
                                                                                
                                           current_manifold->rbB->rb_namep);
@@ -568,11 +582,8 @@
                        VADD2(rt_result.resultant_normal_B, 
rt_result.resultant_normal_B, overlap_list[i].out_normal);
                        bu_log("traverse_xray_lists: resultant_normal_B is now 
(%f,%f,%f) after adding (%f,%f,%f)",
                                        V3ARGS(rt_result.resultant_normal_B), 
V3ARGS(overlap_list[i].out_normal));
+                       add_normal(overlap_list[i].out_normal);
 
-                       VUNITIZE(rt_result.resultant_normal_B);
-                       bu_log("traverse_xray_lists: resultant_normal_B is 
(%f,%f,%f) after unitizing",
-                                                                               
        V3ARGS(rt_result.resultant_normal_B));
-
                }
 
                rt_db_free_internal(&intern);
@@ -580,26 +591,6 @@
 
        }
 
-    /* Draw all the hit regions : not really needed to be visualized */
-    /* if (hit_list.forw != &hit_list) {
-
-       hrp = hit_list.forw;
-
-       while (hrp != &hit_list) {
-       bu_vls_sprintf(&reg_vls, "ray_hit_%s_%d_%f_%f_%f_%f_%f_%f",
-       hrp->reg_name,
-       hrp->index,
-       V3ARGS(pt), V3ARGS(dir));
-       line(gedp, bu_vls_addr(&reg_vls),
-       hrp->in_point,
-       hrp->out_point,
-       0, 210, 0);
-
-       add_to_comb(gedp, sim_params->sim_comb_name, bu_vls_addr(&reg_vls));
-       hrp = hrp->forw;
-       }
-       }*/
-
     bu_vls_free(&reg_vls);
 
     return GED_OK;
@@ -670,7 +661,7 @@
                                                        comb->tree,
                                                        find_solid,
                                                        
(genptr_t)(overlap_list[i].insol->st_name));
-               if(rv == SOLID_FOUND){
+               if(rv == FOUND && !exists_normal(overlap_list[i].in_normal) ){
                        /* It does, so sum the in_normal */
                        bu_log("traverse_yray_lists: %s is present in %s", 
overlap_list[i].insol->st_name,
                                                                                
                                           current_manifold->rbB->rb_namep);
@@ -679,11 +670,8 @@
                        VADD2(rt_result.resultant_normal_B, 
rt_result.resultant_normal_B, overlap_list[i].in_normal);
                        bu_log("traverse_yray_lists: resultant_normal_B is now 
(%f,%f,%f) after adding (%f,%f,%f)",
                                        V3ARGS(rt_result.resultant_normal_B), 
V3ARGS(overlap_list[i].in_normal));
+                       add_normal(overlap_list[i].in_normal);
 
-                       VUNITIZE(rt_result.resultant_normal_B);
-                       bu_log("traverse_yray_lists: resultant_normal_B is 
(%f,%f,%f) after unitizing",
-                                                                               
        V3ARGS(rt_result.resultant_normal_B));
-
                }
 
                /* Check if the out solid belongs to rbB */
@@ -692,7 +680,7 @@
                                                                        
comb->tree,
                                                                        
find_solid,
                                                                        
(genptr_t)(overlap_list[i].outsol->st_name));
-               if(rv == SOLID_FOUND){
+               if(rv == FOUND && !exists_normal(overlap_list[i].out_normal) ){
                        /* It does, so sum the out_normal */
                        bu_log("traverse_yray_lists: %s is present in %s", 
overlap_list[i].outsol->st_name,
                                                                                
                                           current_manifold->rbB->rb_namep);
@@ -701,10 +689,7 @@
                        VADD2(rt_result.resultant_normal_B, 
rt_result.resultant_normal_B, overlap_list[i].out_normal);
                        bu_log("traverse_yray_lists: resultant_normal_B is now 
(%f,%f,%f) after adding (%f,%f,%f)",
                                        V3ARGS(rt_result.resultant_normal_B), 
V3ARGS(overlap_list[i].out_normal));
-
-                       VUNITIZE(rt_result.resultant_normal_B);
-                       bu_log("traverse_yray_lists: resultant_normal_B is 
(%f,%f,%f) after unitizing",
-                                                                               
        V3ARGS(rt_result.resultant_normal_B));
+                       add_normal(overlap_list[i].out_normal);
                }
 
                rt_db_free_internal(&intern);
@@ -712,26 +697,7 @@
 
        }
 
-    /* Draw all the hit regions : not really needed to be visualized */
-    /* if (hit_list.forw != &hit_list) {
 
-       hrp = hit_list.forw;
-
-       while (hrp != &hit_list) {
-       bu_vls_sprintf(&reg_vls, "ray_hit_%s_%d_%f_%f_%f_%f_%f_%f",
-       hrp->reg_name,
-       hrp->index,
-       V3ARGS(pt), V3ARGS(dir));
-       line(gedp, bu_vls_addr(&reg_vls),
-       hrp->in_point,
-       hrp->out_point,
-       0, 210, 0);
-
-       add_to_comb(gedp, sim_params->sim_comb_name, bu_vls_addr(&reg_vls));
-       hrp = hrp->forw;
-       }
-       }*/
-
     bu_vls_free(&reg_vls);
 
     return GED_OK;
@@ -801,7 +767,7 @@
                                                        comb->tree,
                                                        find_solid,
                                                        
(genptr_t)(overlap_list[i].insol->st_name));
-               if(rv == SOLID_FOUND){
+               if(rv == FOUND && !exists_normal(overlap_list[i].in_normal) ){
                        /* It does, so sum the in_normal */
                        bu_log("traverse_zray_lists: %s is present in %s", 
overlap_list[i].insol->st_name,
                                                                                
                                           current_manifold->rbB->rb_namep);
@@ -810,11 +776,8 @@
                        VADD2(rt_result.resultant_normal_B, 
rt_result.resultant_normal_B, overlap_list[i].in_normal);
                        bu_log("traverse_zray_lists: resultant_normal_B is now 
(%f,%f,%f) after adding (%f,%f,%f)",
                                        V3ARGS(rt_result.resultant_normal_B), 
V3ARGS(overlap_list[i].in_normal));
+                       add_normal(overlap_list[i].in_normal);
 
-                       VUNITIZE(rt_result.resultant_normal_B);
-                       bu_log("traverse_zray_lists: resultant_normal_B is 
(%f,%f,%f) after unitizing",
-                                                                               
        V3ARGS(rt_result.resultant_normal_B));
-
                }
 
                /* Check if the out solid belongs to rbB */
@@ -823,7 +786,7 @@
                                                                        
comb->tree,
                                                                        
find_solid,
                                                                        
(genptr_t)(overlap_list[i].outsol->st_name));
-               if(rv == SOLID_FOUND){
+               if(rv == FOUND && !exists_normal(overlap_list[i].out_normal) ){
                        /* It does, so sum the out_normal */
                        bu_log("traverse_zray_lists: %s is present in %s", 
overlap_list[i].outsol->st_name,
                                                                                
                                           current_manifold->rbB->rb_namep);
@@ -832,37 +795,14 @@
                        VADD2(rt_result.resultant_normal_B, 
rt_result.resultant_normal_B, overlap_list[i].out_normal);
                        bu_log("traverse_zray_lists: resultant_normal_B is now 
(%f,%f,%f) after adding (%f,%f,%f)",
                                        V3ARGS(rt_result.resultant_normal_B), 
V3ARGS(overlap_list[i].out_normal));
+                       add_normal(overlap_list[i].out_normal);
 
-                       VUNITIZE(rt_result.resultant_normal_B);
-                       bu_log("traverse_zray_lists: resultant_normal_B is 
(%f,%f,%f) after unitizing",
-                                                                               
        V3ARGS(rt_result.resultant_normal_B));
                }
 
                rt_db_free_internal(&intern);
-
-
        }
 
-    /* Draw all the hit regions : not really needed to be visualized */
-    /* if (hit_list.forw != &hit_list) {
 
-       hrp = hit_list.forw;
-
-       while (hrp != &hit_list) {
-       bu_vls_sprintf(&reg_vls, "ray_hit_%s_%d_%f_%f_%f_%f_%f_%f",
-       hrp->reg_name,
-       hrp->index,
-       V3ARGS(pt), V3ARGS(dir));
-       line(gedp, bu_vls_addr(&reg_vls),
-       hrp->in_point,
-       hrp->out_point,
-       0, 210, 0);
-
-       add_to_comb(gedp, sim_params->sim_comb_name, bu_vls_addr(&reg_vls));
-       hrp = hrp->forw;
-       }
-       }*/
-
     bu_vls_free(&reg_vls);
 
     return GED_OK;
@@ -1121,6 +1061,7 @@
     /* vect_t diff;*/ 
     /* int i; */
 
+
     mf->num_contacts = 0;
 
 

Modified: brlcad/trunk/src/libged/simulate/simutils.c
===================================================================
--- brlcad/trunk/src/libged/simulate/simutils.c 2011-11-03 00:34:08 UTC (rev 
47407)
+++ brlcad/trunk/src/libged/simulate/simutils.c 2011-11-03 05:27:51 UTC (rev 
47408)
@@ -128,9 +128,9 @@
 
     obj_name = (char *)object;
     if (BU_STR_EQUAL(comb_leaf->tr_l.tl_name, obj_name))
-       return SOLID_FOUND;
+       return FOUND;
     else
-       return SOLID_NOT_FOUND;
+       return NOT_FOUND;
 }
 
 
@@ -142,12 +142,12 @@
     int (*leaf_func)(),
     genptr_t user_ptr1)
 {
-       int rv = SOLID_NOT_FOUND;
+       int rv = NOT_FOUND;
 
        RT_CK_DBI(dbip);
 
     if (!comb_tree)
-       return SOLID_NOT_FOUND;
+       return NOT_FOUND;
 
     RT_CK_TREE(comb_tree);
 
@@ -160,7 +160,7 @@
        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)
+           if(rv == NOT_FOUND)
                rv = check_tree_funcleaf(dbip, comb, comb_tree->tr_b.tb_right, 
leaf_func, user_ptr1);
            break;
        default:

Modified: brlcad/trunk/src/libged/simulate/simutils.h
===================================================================
--- brlcad/trunk/src/libged/simulate/simutils.h 2011-11-03 00:34:08 UTC (rev 
47407)
+++ brlcad/trunk/src/libged/simulate/simutils.h 2011-11-03 05:27:51 UTC (rev 
47408)
@@ -49,8 +49,8 @@
 #include "simulate.h"
 
 
-#define SOLID_NOT_FOUND 0
-#define SOLID_FOUND     1
+#define NOT_FOUND 0
+#define FOUND     1
 
 
 /**

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


------------------------------------------------------------------------------
RSA(R) 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