[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48917] trunk/blender/source/blender/ blenkernel/intern/mask_rasterize.c: minor refactor, some comments and var names were misleading.
Campbell Barton
ideasman42 at gmail.com
Sat Jul 14 18:03:04 CEST 2012
Revision: 48917
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48917
Author: campbellbarton
Date: 2012-07-14 16:03:03 +0000 (Sat, 14 Jul 2012)
Log Message:
-----------
minor refactor, some comments and var names were misleading.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
Modified: trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c 2012-07-14 15:46:32 UTC (rev 48916)
+++ trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c 2012-07-14 16:03:03 UTC (rev 48917)
@@ -55,6 +55,10 @@
#define TRI_VERT ((unsigned int) -1)
+/* --------------------------------------------------------------------- */
+/* local structs for mask rasterizeing */
+/* --------------------------------------------------------------------- */
+
/**
* A single #MaskRasterHandle contains multile #MaskRasterLayer's,
* each #MaskRasterLayer does its own lookup which contributes to
@@ -64,19 +68,19 @@
/* internal use only */
typedef struct MaskRasterLayer {
/* geometry */
- unsigned int tri_tot;
- unsigned int (*tri_array)[4]; /* access coords tri/quad */
- float (*tri_coords)[3]; /* xy, z 0-1 (1.0 == filled) */
+ unsigned int face_tot;
+ unsigned int (*face_array)[4]; /* access coords tri/quad */
+ float (*face_coords)[3]; /* xy, z 0-1 (1.0 == filled) */
- /* 2d bounds (to quickly skip raytree lookup) */
+ /* 2d bounds (to quickly skip bucket lookup) */
rctf bounds;
/* buckets */
- unsigned int **buckets_tri;
+ unsigned int **buckets_face;
/* cache divide and subtract */
- float buckets_xy_scalar[2]; /* 1.0 / (buckets_width + FLT_EPSILON) */
+ float buckets_xy_scalar[2]; /* (1.0 / (buckets_width + FLT_EPSILON)) * buckets_x */
unsigned int buckets_x;
unsigned int buckets_y;
@@ -89,13 +93,6 @@
} MaskRasterLayer;
-static void layer_bucket_init(MaskRasterLayer *layer);
-
-
-/* --------------------------------------------------------------------- */
-/* alloc / free functions */
-/* --------------------------------------------------------------------- */
-
/**
* opaque local struct for mask pixel lookup, each MaskLayer needs one of these
*/
@@ -103,10 +100,15 @@
MaskRasterLayer *layers;
unsigned int layers_tot;
- /* 2d bounds (to quickly skip raytree lookup) */
+ /* 2d bounds (to quickly skip bucket lookup) */
rctf bounds;
};
+
+/* --------------------------------------------------------------------- */
+/* alloc / free functions */
+/* --------------------------------------------------------------------- */
+
MaskRasterHandle *BLI_maskrasterize_handle_new(void)
{
MaskRasterHandle *mr_handle;
@@ -125,25 +127,25 @@
/* raycast vars */
for (i = 0; i < layers_tot; i++, raslayers++) {
- if (raslayers->tri_array) {
- MEM_freeN(raslayers->tri_array);
+ if (raslayers->face_array) {
+ MEM_freeN(raslayers->face_array);
}
- if (raslayers->tri_coords) {
- MEM_freeN(raslayers->tri_coords);
+ if (raslayers->face_coords) {
+ MEM_freeN(raslayers->face_coords);
}
- if (raslayers->buckets_tri) {
+ if (raslayers->buckets_face) {
const unsigned int bucket_tot = raslayers->buckets_x * raslayers->buckets_y;
unsigned int bucket_index;
for (bucket_index = 0; bucket_index < bucket_tot; bucket_index++) {
- unsigned int *tri_index = raslayers->buckets_tri[bucket_index];
- if (tri_index) {
- MEM_freeN(tri_index);
+ unsigned int *face_index = raslayers->buckets_face[bucket_index];
+ if (face_index) {
+ MEM_freeN(face_index);
}
}
- MEM_freeN(raslayers->buckets_tri);
+ MEM_freeN(raslayers->buckets_face);
}
}
@@ -226,25 +228,25 @@
layer->buckets_xy_scalar[1] = (1.0f / ((layer->bounds.ymax - layer->bounds.ymin) + FLT_EPSILON)) * layer->buckets_y;
{
- unsigned int *tri = &layer->tri_array[0][0];
- float (*cos)[3] = layer->tri_coords;
+ unsigned int *face = &layer->face_array[0][0];
+ float (*cos)[3] = layer->face_coords;
- const unsigned int bucket_tot = layer->buckets_x * layer->buckets_y;
+ const unsigned int bucket_tot = layer->buckets_x * layer->buckets_y;
LinkNode **bucketstore = MEM_callocN(bucket_tot * sizeof(LinkNode *), __func__);
unsigned int *bucketstore_tot = MEM_callocN(bucket_tot * sizeof(unsigned int), __func__);
- unsigned int tri_index;
+ unsigned int face_index;
- for (tri_index = 0; tri_index < layer->tri_tot; tri_index++, tri += 4) {
+ for (face_index = 0; face_index < layer->face_tot; face_index++, face += 4) {
float xmin;
float xmax;
float ymin;
float ymax;
- if (tri[3] == TRI_VERT) {
- const float *v1 = cos[tri[0]];
- const float *v2 = cos[tri[1]];
- const float *v3 = cos[tri[2]];
+ if (face[3] == TRI_VERT) {
+ const float *v1 = cos[face[0]];
+ const float *v2 = cos[face[1]];
+ const float *v3 = cos[face[2]];
xmin = fminf(v1[0], fminf(v2[0], v3[0]));
xmax = fmaxf(v1[0], fmaxf(v2[0], v3[0]));
@@ -252,10 +254,10 @@
ymax = fmaxf(v1[1], fmaxf(v2[1], v3[1]));
}
else {
- const float *v1 = cos[tri[0]];
- const float *v2 = cos[tri[1]];
- const float *v3 = cos[tri[2]];
- const float *v4 = cos[tri[3]];
+ const float *v1 = cos[face[0]];
+ const float *v2 = cos[face[1]];
+ const float *v3 = cos[face[2]];
+ const float *v4 = cos[face[3]];
xmin = fminf(v1[0], fminf(v2[0], fminf(v3[0], v4[0])));
xmax = fmaxf(v1[0], fmaxf(v2[0], fmaxf(v3[0], v4[0])));
@@ -282,7 +284,7 @@
BLI_assert(bucket_index < bucket_tot);
BLI_linklist_prepend_arena(&bucketstore[bucket_index],
- SET_UINT_IN_POINTER(tri_index),
+ SET_UINT_IN_POINTER(face_index),
arena);
bucketstore_tot[bucket_index]++;
@@ -293,7 +295,7 @@
if (1) {
/* now convert linknodes into arrays for faster per pixel access */
- unsigned int **buckets_tri = MEM_mallocN(bucket_tot * sizeof(unsigned int **), __func__);
+ unsigned int **buckets_face = MEM_mallocN(bucket_tot * sizeof(unsigned int **), __func__);
unsigned int bucket_index;
for (bucket_index = 0; bucket_index < bucket_tot; bucket_index++) {
@@ -302,7 +304,7 @@
__func__);
LinkNode *bucket_node;
- buckets_tri[bucket_index] = bucket;
+ buckets_face[bucket_index] = bucket;
for (bucket_node = bucketstore[bucket_index]; bucket_node; bucket_node = bucket_node->next) {
*bucket = GET_UINT_FROM_POINTER(bucket_node->link);
@@ -311,11 +313,11 @@
*bucket = TRI_TERMINATOR_ID;
}
else {
- buckets_tri[bucket_index] = NULL;
+ buckets_face[bucket_index] = NULL;
}
}
- layer->buckets_tri = buckets_tri;
+ layer->buckets_face = buckets_face;
}
MEM_freeN(bucketstore);
@@ -497,22 +499,22 @@
}
if (sf_ctx.fillvertbase.first) {
- unsigned int (*tri_array)[4], *tri; /* access coords */
- float (*tri_coords)[3], *cos; /* xy, z 0-1 (1.0 == filled) */
+ unsigned int (*face_array)[4], *face; /* access coords */
+ float (*face_coords)[3], *cos; /* xy, z 0-1 (1.0 == filled) */
int sf_tri_tot;
rctf bounds;
- int tri_index;
+ int face_index;
float bvhcos[4][3];
/* now we have all the splines */
- tri_coords = MEM_mallocN((sizeof(float) * 3) * sf_vert_tot, "maskrast_tri_coords");
+ face_coords = MEM_mallocN((sizeof(float) * 3) * sf_vert_tot, "maskrast_face_coords");
/* init bounds */
BLI_rctf_init_minmax(&bounds);
/* coords */
- cos = (float *)tri_coords;
+ cos = (float *)face_coords;
for (sf_vert = sf_ctx.fillvertbase.first; sf_vert; sf_vert = sf_vert_next) {
sf_vert_next = sf_vert->next;
copy_v3_v3(cos, sf_vert->co);
@@ -531,52 +533,52 @@
/* main scanfill */
sf_tri_tot = BLI_scanfill_calc_ex(&sf_ctx, FALSE, zvec);
- tri_array = MEM_mallocN(sizeof(*tri_array) * (sf_tri_tot + tot_feather_quads), "maskrast_tri_index");
+ face_array = MEM_mallocN(sizeof(*face_array) * (sf_tri_tot + tot_feather_quads), "maskrast_face_index");
/* tri's */
- tri = (unsigned int *)tri_array;
- for (sf_tri = sf_ctx.fillfacebase.first, tri_index = 0; sf_tri; sf_tri = sf_tri->next, tri_index++) {
- *(tri++) = sf_tri->v1->tmp.u;
- *(tri++) = sf_tri->v2->tmp.u;
- *(tri++) = sf_tri->v3->tmp.u;
- *(tri++) = TRI_VERT;
+ face = (unsigned int *)face_array;
+ for (sf_tri = sf_ctx.fillfacebase.first, face_index = 0; sf_tri; sf_tri = sf_tri->next, face_index++) {
+ *(face++) = sf_tri->v1->tmp.u;
+ *(face++) = sf_tri->v2->tmp.u;
+ *(face++) = sf_tri->v3->tmp.u;
+ *(face++) = TRI_VERT;
}
/* start of feather faces... if we have this set,
- * 'tri_index' is kept from loop above */
+ * 'face_index' is kept from loop above */
- BLI_assert(tri_index == sf_tri_tot);
+ BLI_assert(face_index == sf_tri_tot);
if (tot_feather_quads) {
ScanFillEdge *sf_edge;
for (sf_edge = sf_ctx.filledgebase.first; sf_edge; sf_edge = sf_edge->next) {
if (sf_edge->tmp.c == SF_EDGE_IS_BOUNDARY) {
- *(tri++) = sf_edge->v1->tmp.u;
- *(tri++) = sf_edge->v2->tmp.u;
- *(tri++) = sf_edge->v2->keyindex;
- *(tri++) = sf_edge->v1->keyindex;
+ *(face++) = sf_edge->v1->tmp.u;
+ *(face++) = sf_edge->v2->tmp.u;
+ *(face++) = sf_edge->v2->keyindex;
+ *(face++) = sf_edge->v1->keyindex;
- copy_v3_v3(bvhcos[0], tri_coords[*(tri - 4)]);
- copy_v3_v3(bvhcos[1], tri_coords[*(tri - 3)]);
- copy_v3_v3(bvhcos[2], tri_coords[*(tri - 2)]);
- copy_v3_v3(bvhcos[3], tri_coords[*(tri - 1)]);
+ copy_v3_v3(bvhcos[0], face_coords[*(face - 4)]);
+ copy_v3_v3(bvhcos[1], face_coords[*(face - 3)]);
+ copy_v3_v3(bvhcos[2], face_coords[*(face - 2)]);
+ copy_v3_v3(bvhcos[3], face_coords[*(face - 1)]);
- tri_index++;
+ face_index++;
}
}
}
- fprintf(stderr, "%d %d\n", tri_index, sf_tri_tot + tot_feather_quads);
+ // fprintf(stderr, "%d %d\n", face_index, sf_face_tot + tot_feather_quads);
- BLI_assert(tri_index == sf_tri_tot + tot_feather_quads);
+ BLI_assert(face_index == sf_tri_tot + tot_feather_quads);
{
MaskRasterLayer *raslayer = &mr_handle->layers[masklay_index];
- raslayer->tri_tot = sf_tri_tot + tot_feather_quads;
- raslayer->tri_coords = tri_coords;
- raslayer->tri_array = tri_array;
+ raslayer->face_tot = sf_tri_tot + tot_feather_quads;
+ raslayer->face_coords = face_coords;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list