Revision: 51295
          http://brlcad.svn.sourceforge.net/brlcad/?rev=51295&view=rev
Author:   starseeker
Date:     2012-06-22 21:37:52 +0000 (Fri, 22 Jun 2012)
Log Message:
-----------
make bots instead of plot files.

Modified Paths:
--------------
    brlcad/trunk/include/raytrace.h
    brlcad/trunk/src/librt/primitives/bot/bot.c
    brlcad/trunk/src/librt/test_botpatches.c

Modified: brlcad/trunk/include/raytrace.h
===================================================================
--- brlcad/trunk/include/raytrace.h     2012-06-22 21:37:24 UTC (rev 51294)
+++ brlcad/trunk/include/raytrace.h     2012-06-22 21:37:52 UTC (rev 51295)
@@ -4381,6 +4381,7 @@
 RT_EXPORT extern int rt_bot_flip(struct rt_bot_internal *bot);
 RT_EXPORT extern int rt_bot_sync(struct rt_bot_internal *bot);
 RT_EXPORT extern struct rt_bot_list * rt_bot_split(struct rt_bot_internal 
*bot);
+RT_EXPORT extern struct rt_bot_list * rt_bot_patches(struct rt_bot_internal 
*bot);
 RT_EXPORT extern void rt_bot_list_free(struct rt_bot_list *headRblp,
                                       int fbflag);
 

Modified: brlcad/trunk/src/librt/primitives/bot/bot.c
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/bot.c 2012-06-22 21:37:24 UTC (rev 
51294)
+++ brlcad/trunk/src/librt/primitives/bot/bot.c 2012-06-22 21:37:52 UTC (rev 
51295)
@@ -4858,6 +4858,168 @@
     return headRblp;
 }
 
+struct rt_bot_list *
+rt_bot_patches(struct rt_bot_internal *bot)
+{
+    size_t i, j;
+    struct tri_pts headTp;
+    struct tri_pts xplus;
+    struct tri_pts xminus;
+    struct tri_pts yplus;
+    struct tri_pts yminus;
+    struct tri_pts zplus;
+    struct tri_pts zminus;
+    struct tri_pts *tpp;
+    struct tri_pts *alltpp;
+    struct rt_bot_list *headRblp = (struct rt_bot_list *)0;
+    struct rt_bot_list *rblp;
+
+    vect_t from_xplus = {-1, 0, 0};
+    vect_t from_xminus = {1, 0, 0};
+    vect_t from_yplus = {0, -1, 0};
+    vect_t from_yminus = {0, 1, 0};
+    vect_t from_zplus = {0, 0, -1};
+    vect_t from_zminus = {0, 0, 1};
+
+    RT_BOT_CK_MAGIC(bot);
+
+    BU_GET(headRblp, struct rt_bot_list);
+    BU_LIST_INIT(&headRblp->l);
+
+    /* Nothing to do */
+    if (bot->num_faces < 2)
+       return NULL;
+
+    BU_LIST_INIT(&headTp.l);
+    BU_LIST_INIT(&xplus.l);
+    BU_LIST_INIT(&xminus.l);
+    BU_LIST_INIT(&yplus.l);
+    BU_LIST_INIT(&yminus.l);
+    BU_LIST_INIT(&zplus.l);
+    BU_LIST_INIT(&zminus.l);
+
+    alltpp = (struct tri_pts *)bu_calloc(bot->num_faces, sizeof(struct 
tri_pts), "patches alltpp");
+
+    for (i=0; i < bot->num_faces; ++i) {
+       vect_t a, b, norm_dir;
+       fastf_t results[6];
+       int result_max = 0;
+       fastf_t tmp = 0.0;
+       VSETALLN(results, 0, 6);
+
+        tpp = &alltpp[i];
+       tpp->tri = i;
+        tpp->a = bot->faces[i*3+0];
+        tpp->b = bot->faces[i*3+1];
+        tpp->c = bot->faces[i*3+2];
+
+       VSUB2(a, &bot->vertices[bot->faces[i*3+1]*3], 
&bot->vertices[bot->faces[i*3]*3]);
+       VSUB2(b, &bot->vertices[bot->faces[i*3+2]*3], 
&bot->vertices[bot->faces[i*3]*3]);
+       VCROSS(norm_dir, a, b);
+       VUNITIZE(norm_dir);
+       results[0] = VDOT(from_xplus, norm_dir);
+       results[1] = VDOT(from_xminus, norm_dir);
+       results[2] = VDOT(from_yplus, norm_dir);
+       results[3] = VDOT(from_yminus, norm_dir);
+       results[4] = VDOT(from_zplus, norm_dir);
+       results[5] = VDOT(from_zminus, norm_dir);
+
+       for(j = 0; j < 6; j++) {
+           if (results[j] > tmp) {
+               result_max = j;
+               tmp = results[j];
+           }
+       }
+
+
+       if (result_max == 0) {
+          BU_LIST_APPEND(&xplus.l, &tpp->l);
+       }
+       if (result_max == 1) {
+          BU_LIST_APPEND(&xminus.l, &tpp->l);
+       }
+       if (result_max == 2) {
+          BU_LIST_APPEND(&yplus.l, &tpp->l);
+       }
+       if (result_max == 3) {
+          BU_LIST_APPEND(&yminus.l, &tpp->l);
+       }
+       if (result_max == 4) {
+          BU_LIST_APPEND(&zplus.l, &tpp->l);
+       }
+       if (result_max == 5) {
+          BU_LIST_APPEND(&zminus.l, &tpp->l);
+       }
+
+    }
+    if (BU_LIST_NON_EMPTY(&xplus.l)) {
+       /* Create a new bot */
+       BU_GET(rblp, struct rt_bot_list);
+       rblp->bot = rt_bot_create(bot, &xplus);
+       BU_LIST_APPEND(&headRblp->l, &rblp->l);
+    }
+    if (BU_LIST_NON_EMPTY(&xminus.l)) {
+       /* Create a new bot */
+       BU_GET(rblp, struct rt_bot_list);
+       rblp->bot = rt_bot_create(bot, &xminus);
+       BU_LIST_APPEND(&headRblp->l, &rblp->l);
+    }
+    if (BU_LIST_NON_EMPTY(&yplus.l)) {
+       /* Create a new bot */
+       BU_GET(rblp, struct rt_bot_list);
+       rblp->bot = rt_bot_create(bot, &yplus);
+       BU_LIST_APPEND(&headRblp->l, &rblp->l);
+    }
+    if (BU_LIST_NON_EMPTY(&yminus.l)) {
+       /* Create a new bot */
+       BU_GET(rblp, struct rt_bot_list);
+       rblp->bot = rt_bot_create(bot, &yminus);
+       BU_LIST_APPEND(&headRblp->l, &rblp->l);
+    }
+    if (BU_LIST_NON_EMPTY(&zplus.l)) {
+       /* Create a new bot */
+       BU_GET(rblp, struct rt_bot_list);
+       rblp->bot = rt_bot_create(bot, &zplus);
+       BU_LIST_APPEND(&headRblp->l, &rblp->l);
+    }
+    if (BU_LIST_NON_EMPTY(&zminus.l)) {
+       /* Create a new bot */
+       BU_GET(rblp, struct rt_bot_list);
+       rblp->bot = rt_bot_create(bot, &zminus);
+       BU_LIST_APPEND(&headRblp->l, &rblp->l);
+    }
+
+    while (BU_LIST_WHILE(tpp, tri_pts, &xplus.l)) {
+       BU_LIST_DEQUEUE(&tpp->l);
+    }
+
+    while (BU_LIST_WHILE(tpp, tri_pts, &xminus.l)) {
+       BU_LIST_DEQUEUE(&tpp->l);
+    }
+
+    while (BU_LIST_WHILE(tpp, tri_pts, &yplus.l)) {
+       BU_LIST_DEQUEUE(&tpp->l);
+    }
+
+    while (BU_LIST_WHILE(tpp, tri_pts, &yminus.l)) {
+       BU_LIST_DEQUEUE(&tpp->l);
+    }
+
+
+    while (BU_LIST_WHILE(tpp, tri_pts, &zplus.l)) {
+       BU_LIST_DEQUEUE(&tpp->l);
+    }
+
+
+    while (BU_LIST_WHILE(tpp, tri_pts, &zminus.l)) {
+       BU_LIST_DEQUEUE(&tpp->l);
+    }
+
+    bu_free((genptr_t)alltpp, "rt_bot_patches: alltpp");
+
+    return headRblp;
+}
+
 void
 rt_bot_list_free(struct rt_bot_list *headRblp, int fbflag)
 {

Modified: brlcad/trunk/src/librt/test_botpatches.c
===================================================================
--- brlcad/trunk/src/librt/test_botpatches.c    2012-06-22 21:37:24 UTC (rev 
51294)
+++ brlcad/trunk/src/librt/test_botpatches.c    2012-06-22 21:37:52 UTC (rev 
51295)
@@ -15,25 +15,20 @@
    struct directory *dp;
    struct rt_db_internal intern;
    struct rt_bot_internal *bot_ip = NULL;
+   struct rt_bot_list *headRblp = NULL;
+   struct rt_db_internal bot_intern;
+   struct rt_bot_list *rblp;
+   struct bu_vls name;
 
-   static FILE* plot = NULL;
-
-   vect_t from_xplus = {-1, 0, 0};
-   vect_t from_xminus = {1, 0, 0};
-   vect_t from_yplus = {0, -1, 0};
-   vect_t from_yminus = {0, 1, 0};
-   vect_t from_zplus = {0, 0, -1};
-   vect_t from_zminus = {0, 0, 1};
-
    int i = 0;
-   int j = 0;
-   point_t min, max;
 
+   bu_vls_init(&name);
+
    if (argc != 3) {
       bu_exit(1, "Usage: %s file.g object", argv[0]);
    }
 
-   dbip = db_open(argv[1], "r");
+   dbip = db_open(argv[1], "r+w");
    if (dbip == DBI_NULL) { 
       bu_exit(1, "ERROR: Unable to read from %s\n", argv[1]);
    }
@@ -60,79 +55,34 @@
    }
    RT_BOT_CK_MAGIC(bot_ip);
 
-  plot = fopen("out.pl", "w");
-  VSET(min, -2048, -2048, -2048);
-  VSET(max, 2048, 2048, 2048);
-  pdv_3space(plot, min, max);
+   headRblp = rt_bot_patches(bot_ip);
 
-  /*printf("num_vertices: %d\n", bot_ip->num_vertices);
-  printf("num_normals: %d\n", bot_ip->num_normals);
-  printf("num_faces: %d\n", bot_ip->num_faces);
-  printf("num_face_normals: %d\n", bot_ip->num_face_normals);*/
+   i = 0;
+   for (BU_LIST_FOR(rblp, rt_bot_list, &headRblp->l)) {
+          bu_vls_sprintf(&name, "%d.bot", i);
+          RT_DB_INTERNAL_INIT(&bot_intern);
+          bot_intern.idb_major_type = DB5_MAJORTYPE_BRLCAD;
+          bot_intern.idb_type = ID_BOT;
+          bot_intern.idb_meth = &rt_functab[ID_BOT];
+          bot_intern.idb_ptr = (genptr_t)rblp->bot;
+          dp = db_diradd(dbip, bu_vls_addr(&name), RT_DIR_PHONY_ADDR, 0, 
RT_DIR_SOLID, (genptr_t)&bot_intern.idb_type);
+          if (dp == RT_DIR_NULL) {
+                   printf("auuugh - dp says diradd failed!\n");
+                  rt_bot_list_free(headRblp, 0);
+                  rt_db_free_internal(&intern);
+          } else {
+                  if (rt_db_put_internal(dp, dbip, &bot_intern, 
&rt_uniresource) < 0) {
+                          printf("auuugh - put_internal failed!\n");
+                          rt_bot_list_free(headRblp, 0);
+                          rt_db_free_internal(&intern);
+                  }
+          }
+          i++;
+   }
 
-  for (i = 0; i < (int)bot_ip->num_faces; i++) {
-      vect_t a, b, norm_dir;
-      fastf_t results[6];
-      int result_max = 0;
-      fastf_t tmp = 0.0;
-      VSETALLN(results, 0, 6);
-      VSUB2(a, &bot_ip->vertices[bot_ip->faces[i*3+1]*3], 
&bot_ip->vertices[bot_ip->faces[i*3]*3]);
-      VSUB2(b, &bot_ip->vertices[bot_ip->faces[i*3+2]*3], 
&bot_ip->vertices[bot_ip->faces[i*3]*3]);
-      VCROSS(norm_dir, a, b);
-      VUNITIZE(norm_dir);
-      results[0] = VDOT(from_xplus, norm_dir);
-      results[1] = VDOT(from_xminus, norm_dir);
-      results[2] = VDOT(from_yplus, norm_dir);
-      results[3] = VDOT(from_yminus, norm_dir);
-      results[4] = VDOT(from_zplus, norm_dir);
-      results[5] = VDOT(from_zminus, norm_dir);
-      VSCALE(norm_dir, norm_dir, 100);
-      VADD2(norm_dir, &bot_ip->vertices[bot_ip->faces[i*3+1]*3], norm_dir);
-      /*printf("vert %d (%f,%f,%f,%f,%f,%f): ", i, results[0], results[1], 
results[2], results[3], results[4], results[5]);*/
-      for(j = 0; j < 6; j++) {
-         if (results[j] > tmp) {
-            result_max = j;
-            tmp = results[j];
-         }
-      }
+   rt_bot_list_free(headRblp, 0);
+   rt_db_free_internal(&intern);
+   bu_vls_free(&name); 
 
-      if (result_max == 0) {
-        COLOR_PLOT(255, 0, 0);
-       pdv_3move(plot, &bot_ip->vertices[bot_ip->faces[i*3+1]*3]);
-        LINE_PLOT(&bot_ip->vertices[bot_ip->faces[i*3+1]*3], norm_dir);
-        /*printf(" xplus ");*/
-      }
-      if (result_max == 1) {
-        COLOR_PLOT(50, 0, 0);
-       pdv_3move(plot, &bot_ip->vertices[bot_ip->faces[i*3+1]*3]);
-        LINE_PLOT(&bot_ip->vertices[bot_ip->faces[i*3+1]*3], norm_dir);
-        /*printf(" xminus ");*/
-      }
-      if (result_max == 2) {
-        COLOR_PLOT(0, 255, 0);
-       pdv_3move(plot, &bot_ip->vertices[bot_ip->faces[i*3+1]*3]);
-        LINE_PLOT(&bot_ip->vertices[bot_ip->faces[i*3+1]*3], norm_dir);
-        /* printf(" yplus "); */
-      }
-      if (result_max == 3) {
-        COLOR_PLOT(0, 50, 0);
-       pdv_3move(plot, &bot_ip->vertices[bot_ip->faces[i*3+1]*3]);
-        LINE_PLOT(&bot_ip->vertices[bot_ip->faces[i*3+1]*3], norm_dir);
-        /* printf(" yminus "); */
-      }
-      if (result_max == 4) {
-        COLOR_PLOT(0, 0, 255);
-       pdv_3move(plot, &bot_ip->vertices[bot_ip->faces[i*3+1]*3]);
-        LINE_PLOT(&bot_ip->vertices[bot_ip->faces[i*3+1]*3], norm_dir);
-        /* printf(" zplus "); */
-      }
-      if (result_max == 5) {
-        COLOR_PLOT(0, 0, 50);
-       pdv_3move(plot, &bot_ip->vertices[bot_ip->faces[i*3+1]*3]);
-        LINE_PLOT(&bot_ip->vertices[bot_ip->faces[i*3+1]*3], norm_dir);
-        /* printf(" zminus "); */
-      }
-      /*printf("\n");*/
-  }
-  return 0;
+   return 0;
 }

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


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to