Revision: 55807
http://sourceforge.net/p/brlcad/code/55807
Author: starseeker
Date: 2013-06-20 19:56:55 +0000 (Thu, 20 Jun 2013)
Log Message:
-----------
This is less pretty than using edges (doesn't cull all the lines we would want
to cull) but should be faster - if this can't be made 'fast enough' adding more
processing on isn't workable either.
Modified Paths:
--------------
brlcad/trunk/src/librt/primitives/bot/bot_wireframe.cpp
Modified: brlcad/trunk/src/librt/primitives/bot/bot_wireframe.cpp
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/bot_wireframe.cpp 2013-06-20
12:57:54 UTC (rev 55806)
+++ brlcad/trunk/src/librt/primitives/bot/bot_wireframe.cpp 2013-06-20
19:56:55 UTC (rev 55807)
@@ -6,7 +6,6 @@
#include "raytrace.h"
#include "wdb.h"
-
// Calculate area of a face
static double
face_area(struct rt_bot_internal *bot, size_t face_num)
@@ -49,7 +48,6 @@
return 0;
/* Declare key containers */
- double *face_areas= (double *)bu_calloc(bot->num_faces, sizeof(double),
"areas");
double *face_normals= (double *)bu_calloc(bot->num_faces * 3,
sizeof(double), "normals");
/* Stash all the initial categorization test results - can be re-used
later */
// unsigned int *categorization_results = (unsigned int
*)bu_calloc(sizeof(unsigned int) * bot->num_faces * 6, "categorization
results");
@@ -57,19 +55,16 @@
unsigned int *groups = (unsigned int *)bu_calloc(bot->num_faces,
sizeof(unsigned int), "groups");
/* Initially, patch breakdown is made in a faces -> patch_id map */
unsigned int *patches= (unsigned int *)bu_calloc(bot->num_faces,
sizeof(unsigned int), "patch_id_numbers");
- /* Don't know yet how big this needs to be */
+ /* Don't know yet how big these needs to be */
unsigned int *vert_to_face = NULL;
/* Sanity check vertex indicies in face definitions */
for (unsigned int i = 0; i < bot->num_faces; ++i) {
- if ((unsigned int)bot->faces[i*3+0] > (unsigned
int)(bot->num_vertices)) bu_log("bot->faces[%d*3+0]: %d, bot->num_vertices:
%d", i, bot->faces[i*3+0], bot->num_vertices);
- if ((unsigned int)bot->faces[i*3+1] > (unsigned
int)(bot->num_vertices)) bu_log("bot->faces[%d*3+1]: %d, bot->num_vertices:
%d", i, bot->faces[i*3+1], bot->num_vertices);
- if ((unsigned int)bot->faces[i*3+2] > (unsigned
int)(bot->num_vertices)) bu_log("bot->faces[%d*3+2]: %d, bot->num_vertices:
%d", i, bot->faces[i*3+2], bot->num_vertices);
+ if ((unsigned int)bot->faces[i*3+0] > (unsigned
int)(bot->num_vertices)) return 0;
+ if ((unsigned int)bot->faces[i*3+1] > (unsigned
int)(bot->num_vertices)) return 0;
+ if ((unsigned int)bot->faces[i*3+2] > (unsigned
int)(bot->num_vertices)) return 0;
}
- /* Pre-compute face areas once */
- for (unsigned int i = 0; i < bot->num_faces; i++) {
- face_areas[i] = face_area(bot, i);
- }
+
/* Pre-compute face normals once */
for (unsigned int i = 0; i < bot->num_faces; i++) {
vect_t a, b, norm_dir;
@@ -81,6 +76,7 @@
face_normals[i*3+1]=norm_dir[1];
face_normals[i*3+2]=norm_dir[2];
}
+
/* Calculate categorization results and assign groups */
for (unsigned int i = 0; i < bot->num_faces; i++) {
int result_max = 0;
@@ -98,6 +94,8 @@
}
groups[i] = result_max;
}
+ bu_free(face_normals, "face_normals");
+
/* Determine the maximun number of faces associated with any one vertex */
unsigned int *vert_face_cnt = (unsigned int *)bu_calloc(bot->num_vertices,
sizeof(unsigned int), "vert face cnt");
for (unsigned int i = 0; i < bot->num_faces; i++) {
@@ -113,57 +111,58 @@
/* Now, allocate a 2D array that can hold the full vert->face map
* and populate it */
vert_to_face = (unsigned int *)bu_calloc(bot->num_vertices * max_face_cnt,
sizeof(unsigned int), "map");
+ unsigned int *vert_sizes = (unsigned int *)bu_calloc(bot->num_vertices,
sizeof(unsigned int), "map");
for (unsigned int i = 0; i < bot->num_faces; i++) {
for (unsigned int j = 0; j < 3; j++) {
- unsigned int k = 0;
unsigned int vert = bot->faces[i*3+j];
+ unsigned int k = vert_sizes[vert];
/* rows are vertex indexes, columns hold the faces */
- while (vert_to_face[max_face_cnt * vert + k] && k < max_face_cnt)
k++;
/* Need to increment face index by one so we can reference
* the first face and still use the true/false test that 0 allows */
vert_to_face[max_face_cnt * vert + k] = i + 1;
+ vert_sizes[vert]++;
//bu_log("vert_to_face(%d,%d)[%d] = %d\n", vert, k, max_face_cnt *
vert + k, i + 1);
}
}
-
+
+
/* Order the groups by number of bots */
- unsigned int group_cnt[6] = {0};
- unsigned int ordered_groups[6] = {0};
- for (unsigned int i = 0; i < bot->num_faces; i++) {
+ /* Note - needed only when group boarders are not enforced in patch
building */
+// unsigned int group_cnt[6] = {0};
+ unsigned int ordered_groups[6] = {0,1,2,3,4,5};
+/* for (unsigned int i = 0; i < bot->num_faces; i++) {
group_cnt[groups[i]]++;
}
for (unsigned int i = 0; i < 6; i++) {
- unsigned int more = 5;
+ unsigned int more = 0;
for (unsigned int j = 0; j < 6; j++) {
- if (group_cnt[j] > group_cnt[i]) more--;
+ if (group_cnt[j] > group_cnt[i]) more++;
}
ordered_groups[more] = i;
}
+*/
-
// All faces must belong to some patch - continue until all faces are
processed
unsigned int patch_cnt = 0;
for (unsigned int i = 0; i < 6; i++) {
- int largest_face = 0;
- while (largest_face != -1) {
+ int unused = 0;
+ while (unused != -1) {
+ unsigned int face_stp = 0;
// Start a new patch
- vect_t largest_face_normal;
- largest_face = -1;
+ unused = -1;
patch_cnt++;
- // Find largest remaining face in group
- double face_size_criteria = 0.0;
- for (unsigned int j = 0; j < bot->num_faces; j++) {
- if (ordered_groups[i] == groups[j] && !patches[j] &&
(face_areas[j] > face_size_criteria)) {
- largest_face = j;
- face_size_criteria = face_areas[j];
+ // Find remaining face in group
+ while (unused == -1 && face_stp < bot->num_faces) {
+ if (ordered_groups[i] == groups[face_stp] &&
!patches[face_stp]) {
+ unused = face_stp;
}
- }
- if (largest_face != -1) {
+ face_stp++;
+ }
+ if (unused != -1) {
std::queue<unsigned int> face_queue;
- face_queue.push(largest_face);
- patches[largest_face] = patch_cnt;
- VSET(largest_face_normal, face_normals[largest_face*3],
face_normals[largest_face*3+1], face_normals[largest_face*3+2]);
+ face_queue.push(unused);
+ patches[unused] = patch_cnt;
while (!face_queue.empty()) {
unsigned int face_num = face_queue.front();
face_queue.pop();
@@ -172,14 +171,8 @@
for (unsigned int l = 0; l < vert_face_cnt[vert_id];
l++) {
unsigned int new_face = vert_to_face[max_face_cnt *
vert_id + l] - 1;
if (groups[new_face] == ordered_groups[i] &&
!patches[new_face]) {
- if (face_areas[new_face] >
face_areas[largest_face] * 0.1) {
- vect_t new_face_normal;
- VSET(new_face_normal,
face_normals[new_face*3], face_normals[new_face*3+1],
face_normals[new_face*3+2]);
- if (VDOT(largest_face_normal,
new_face_normal) > 0.65) {
- face_queue.push(new_face);
- patches[new_face] = patch_cnt;
- }
- }
+ face_queue.push(new_face);
+ patches[new_face] = patch_cnt;
}
}
}
@@ -187,13 +180,11 @@
}
}
}
- bu_log("patch_cnt: %d\n", patch_cnt);
- bu_free(face_areas, "face_areas");
- bu_free(face_normals, "face_normals");
bu_free(groups, "groups");
bu_free(vert_to_face, "vert_to_face");
- unsigned int *patch_vert_cnt = (unsigned int *)bu_malloc(sizeof(unsigned
int) * bot->num_vertices, "patch_vert_cnt");
+ unsigned int *patch_vert_cnt = vert_sizes;
+ memset(patch_vert_cnt, 0, bot->num_vertices * sizeof(unsigned int));
unsigned int *vert_edge_status = (unsigned int
*)bu_calloc(bot->num_vertices, sizeof(unsigned int), "vert status");
for (unsigned int i = 0; i < patch_cnt; i++) {
memset(patch_vert_cnt, 0, bot->num_vertices * sizeof(unsigned int));
@@ -205,7 +196,9 @@
}
}
for (unsigned int j = 0; j < bot->num_vertices; j++) {
- if (patch_vert_cnt[j] && patch_vert_cnt[j] != vert_face_cnt[j])
vert_edge_status[j]++;
+ if (patch_vert_cnt[j] && patch_vert_cnt[j] != vert_face_cnt[j]) {
+ vert_edge_status[j]++;
+ }
}
}
bu_free(patches, "patches");
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits