Revision: 68850
          http://sourceforge.net/p/brlcad/code/68850
Author:   starseeker
Date:     2016-09-19 19:45:09 +0000 (Mon, 19 Sep 2016)
Log Message:
-----------
Import the individual element shell lines with part groupings, one bot per part 
id.

Modified Paths:
--------------
    brlcad/trunk/src/conv/dyn-g.cpp

Modified: brlcad/trunk/src/conv/dyn-g.cpp
===================================================================
--- brlcad/trunk/src/conv/dyn-g.cpp     2016-09-19 15:33:08 UTC (rev 68849)
+++ brlcad/trunk/src/conv/dyn-g.cpp     2016-09-19 19:45:09 UTC (rev 68850)
@@ -30,6 +30,7 @@
 #include <fstream>
 #include <string>
 #include <map>
+#include <set>
 
 #include "vmath.h"
 #include "bu/malloc.h"
@@ -145,6 +146,7 @@
        int col_cnt = 0;
        struct dyna_element_shell *es;
        BU_GET(es, struct dyna_element_shell);
+       es->nodal_pnts[3] = -1;
        while (i < 80 && i < (int)strlen(line.c_str())) {
            int incr = 8;
            std::string col = line.substr(i,incr);
@@ -239,16 +241,16 @@
     process_nodes(infile, nodepos, world);
     process_element_shell(infile, espos, world);
 
-    /*
+    std::map<long,long> NID_to_world;
     for (size_t i = 0; i < BU_PTBL_LEN(world->nodes); i++) {
        struct dyna_node *n = (struct dyna_node *)BU_PTBL_GET(world->nodes, i);
-       bu_log("Node(%ld): %f, %f, %f\n", n->NID, n->pnt[0], n->pnt[1], 
n->pnt[2]);
+       NID_to_world.insert(std::pair<long,long>(n->NID, (long)i));
     }
+    std::map<long,long> EID_to_world;
     for (size_t i = 0; i < BU_PTBL_LEN(world->element_shells); i++) {
        struct dyna_element_shell *es = (struct dyna_element_shell 
*)BU_PTBL_GET(world->element_shells, i);
-       bu_log("Element Shell(%ld,%ld): %ld, %ld, %ld, %ld\n", es->EID, 
es->PID, es->nodal_pnts[0], es->nodal_pnts[1], es->nodal_pnts[2], 
es->nodal_pnts[3]);
+       EID_to_world.insert(std::pair<long,long>(es->EID, (long)i));
     }
-    */
 
     struct rt_wdb *fd_out;
     if ((fd_out=wdb_fopen(argv[2])) == NULL) {
@@ -256,35 +258,75 @@
        bu_exit(1, NULL);
     }
 
-    std::map<long, long> NID_to_array;
-    /* Initially, punt and shove everything into a single BoT.  This is almost
-     * certainly wrong - at a minimum PID is probably a guide for separation -
-     * but the idea at this point is to see what we've got. */
-    fastf_t *bot_vertices = (fastf_t *)bu_calloc(BU_PTBL_LEN(world->nodes)*3, 
sizeof(fastf_t), "BoT vertices (Dyna nodes)");
-    for (size_t i = 0; i < BU_PTBL_LEN(world->nodes); i++) {
-       struct dyna_node *n = (struct dyna_node *)BU_PTBL_GET(world->nodes, i);
-       NID_to_array.insert(std::pair<long,long>(n->NID, (long)i));
-       for (int j = 0; j < 3; j++) {
-           bot_vertices[(i*3)+j] = n->pnt[j];
-       }
-    }
-    int *bot_faces = (int *)bu_calloc(BU_PTBL_LEN(world->element_shells) * 2 * 
3, sizeof(int), "BoT faces (2 per Dyna element shell line)");
+    /* Construct map of part ids to EIS */
+    std::multimap<long,long> PID_to_EIS;
+    std::set<long> PIDs;
     for (size_t i = 0; i < BU_PTBL_LEN(world->element_shells); i++) {
        struct dyna_element_shell *es = (struct dyna_element_shell 
*)BU_PTBL_GET(world->element_shells, i);
-       int np1 = (int)NID_to_array.find(es->nodal_pnts[0])->second;
-       int np2 = (int)NID_to_array.find(es->nodal_pnts[1])->second;
-       int np3 = (int)NID_to_array.find(es->nodal_pnts[2])->second;
-       int np4 = (int)NID_to_array.find(es->nodal_pnts[3])->second;
-       bot_faces[(i*6)+0] = np1;
-       bot_faces[(i*6)+1] = np2;
-       bot_faces[(i*6)+2] = np4;
-       bot_faces[(i*6)+3] = np2;
-       bot_faces[(i*6)+4] = np3;
-       bot_faces[(i*6)+5] = np4;
+       PID_to_EIS.insert(std::pair<long,long>(es->PID,es->EID));
+       PIDs.insert(es->PID);
     }
 
-    mk_bot(fd_out, "dyna.s", RT_BOT_SURFACE, RT_BOT_UNORIENTED, NULL, 
BU_PTBL_LEN(world->nodes), BU_PTBL_LEN(world->element_shells) * 2, 
bot_vertices, bot_faces, NULL, NULL);
+    /* For each PID, make a bot with the set of EID elements associated with 
it */
+    for (std::set<long>::iterator it = PIDs.begin(); it != PIDs.end(); it++) {
+       std::set<long> EIDs;
+       std::set<long> NIDs;
+       std::pair<std::multimap<long,long>::iterator, 
std::multimap<long,long>::iterator> ret;
+       ret = PID_to_EIS.equal_range(*it);
+       for (std::multimap<long,long>::iterator eit=ret.first; eit != 
ret.second; eit++) {
+           long wid = EID_to_world.find(eit->second)->second;
+           struct dyna_element_shell *es = (struct dyna_element_shell 
*)BU_PTBL_GET(world->element_shells, wid);
+           EIDs.insert(eit->second);
+           for (int ind = 0; ind < 4; ind++) {
+               if (es->nodal_pnts[ind] != -1) NIDs.insert(es->nodal_pnts[ind]);
+           }
+       }
 
+       int array_ind = 0;
+       std::map<long, long> NID_to_array;
+       fastf_t *bot_vertices = (fastf_t *)bu_calloc(NIDs.size()*3, 
sizeof(fastf_t), "BoT vertices (Dyna nodes)");
+       for (std::set<long>::iterator nit = NIDs.begin(); nit != NIDs.end(); 
nit++) {
+           long wid = NID_to_world.find(*nit)->second;
+           struct dyna_node *n = (struct dyna_node *)BU_PTBL_GET(world->nodes, 
wid);
+           NID_to_array.insert(std::pair<long, long>(*nit,(long)array_ind));
+           for (int j = 0; j < 3; j++) {
+               bot_vertices[(array_ind*3)+j] = n->pnt[j];
+           }
+           array_ind++;
+       }
+
+       int *bot_faces = (int *)bu_calloc(EIDs.size() * 2 * 3, sizeof(int), 
"BoT faces (2 per Dyna element shell quad, 1 per triangle)");
+       int eind = 0;
+       for (std::set<long>::iterator eit = EIDs.begin(); eit != EIDs.end(); 
eit++) {
+           long wid = EID_to_world.find(*eit)->second;
+           struct dyna_element_shell *es = (struct dyna_element_shell 
*)BU_PTBL_GET(world->element_shells, wid);
+           int np1 = (int)NID_to_array.find(es->nodal_pnts[0])->second;
+           int np2 = (int)NID_to_array.find(es->nodal_pnts[1])->second;
+           int np3 = (int)NID_to_array.find(es->nodal_pnts[2])->second;
+           int np4 = (int)NID_to_array.find(es->nodal_pnts[3])->second;
+           bot_faces[(eind*6)+0] = np1;
+           bot_faces[(eind*6)+1] = np3;
+           bot_faces[(eind*6)+2] = np2;
+           if (np4 != -1) {
+               bot_faces[(eind*6)+3] = np1;
+               bot_faces[(eind*6)+4] = np4;
+               bot_faces[(eind*6)+5] = np3;
+           } else {
+               bot_faces[(eind*6)+3] = -1;
+               bot_faces[(eind*6)+4] = -1;
+               bot_faces[(eind*6)+5] = -1;
+           }
+           eind++;
+       }
+
+       struct bu_vls ptname = BU_VLS_INIT_ZERO;
+       bu_vls_sprintf(&ptname, "%ld.bot", *it);
+       mk_bot(fd_out, bu_vls_addr(&ptname), RT_BOT_SURFACE, RT_BOT_UNORIENTED, 
NULL, NIDs.size(), EIDs.size() * 2, bot_vertices, bot_faces, NULL, NULL);
+       bu_vls_free(&ptname);
+
+    }
+
+
     wdb_close(fd_out);
     rt_clean_resource_complete(NULL, &rt_uniresource);
 

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


------------------------------------------------------------------------------
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to