Revision: 59005
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59005
Author:   walid
Date:     2013-08-07 21:56:34 +0000 (Wed, 07 Aug 2013)
Log Message:
-----------
Vertex Color transfer through projection: separating the transfer into either a 
single layer or many layers to start supporting a speed optimisation for 
multi-layer transfer while preserving the memory optimised single layer transfer

Modified Paths:
--------------
    
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c

Modified: 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
===================================================================
--- 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
        2013-08-07 21:49:11 UTC (rev 59004)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
        2013-08-07 21:56:34 UTC (rev 59005)
@@ -2129,12 +2129,121 @@
        src_lay_end = replace_info.src_lay_end;
        dst_lay_start = replace_info.dst_lay_start;
 
-       for (src_lay_iter = src_lay_start, dst_lay_iter = dst_lay_start; 
src_lay_iter <= src_lay_end;
-               src_lay_iter++, dst_lay_iter++) {
+       if (src_lay_start < src_lay_end) {
+               //we've multiple layers: we shall optimise for multiple layers 
by storing the relationships between the src and
+               //dst before getting into the transfer ... that would consume 
more memory; thus the otherway is left in case
+               //that the transfer is for a single layer
 
+               for (src_lay_iter = src_lay_start, dst_lay_iter = 
dst_lay_start; src_lay_iter < src_lay_end;
+                       src_lay_iter++, dst_lay_iter++) {
+
+                       //fix the layer index of the source & dest
+                       CD_src = CustomData_get_n_offset(&bm_src->ldata, 
CD_MLOOPCOL, src_lay_iter);
+                       CD_dst = CustomData_get_n_offset(&bm_dst->ldata, 
CD_MLOOPCOL, dst_lay_iter);
+
+                       //the way we do it is by looping over each face!!
+                       BM_ITER_MESH (f_dst, &fiter, bm_dst, BM_FACES_OF_MESH) {
+
+                               //get the dst face center
+                               BM_face_calc_center_mean(f_dst, f_mid_dst);
+
+                               //supporting either to copy relative to the 
target or not
+                               if (relative_to_target == true) {
+                                       // Transform into target space.
+                                       mul_v3_m4v3(f_mid_dst_proj, tmp_mat, 
f_mid_dst);        //to start searching for a match
+                                       ///the radius could be used to avoid 
overwriting data at at certain distance
+                                       f_src = 
BKE_bmbvh_find_face_closest(bmtree_src, f_mid_dst_proj, FLT_MAX);
+                               }
+
+                               else {
+                                       f_src = 
BKE_bmbvh_find_face_closest(bmtree_src, f_mid_dst, FLT_MAX);
+                               }
+
+                               ///if we removed the FLT_MAX we shall check for 
the null f_src here
+
+                               //we should be so cautious about reallocating 
extra memory in loops!!
+                               if (f_src->len > exp_vert_per_face) {
+                                       if (f_src->len > v_src_max_count) {
+                                               v_co_list_src = 
MEM_reallocN(v_co_list_src, sizeof(*v_co_list_src) * f_src->len);
+                                               tmp_weight = 
MEM_reallocN(tmp_weight, sizeof(*tmp_weight) * f_src->len);
+                                               v_src_max_count = f_src->len;
+                                       }
+                               }
+
+                               BM_ITER_ELEM_INDEX (v, &iter, f_src, 
BM_VERTS_OF_FACE, b) {
+                                       copy_v3_v3(v_co_list_src[b], v->co);
+                               }
+
+                               //get the face center
+                               BM_face_calc_center_mean(f_src, f_mid_src);
+
+                               BM_ITER_ELEM (l, &liter, f_dst, 
BM_LOOPS_OF_FACE) {
+                                       MLoopCol *lcol = 
BM_ELEM_CD_GET_VOID_P(l, CD_dst);
+                                       MLoopCol *lcol_out = 
MEM_mallocN(sizeof(*lcol_out), "lcol_out bmesh_data_transfer.c");
+
+                                       if (relative_to_target == true) {
+                                               zero_v3(v_dst_co);
+
+                                               // Transform into target space.
+                                               mul_v3_m4v3(v_dst_co, tmp_mat, 
l->v->co);
+                                       }
+
+                                       else {
+                                               copy_v3_v3(v_dst_co, l->v->co);
+                                       }
+
+
+                                       // Project each vertex onto face.
+                                       project_v3_plane(v_dst_co, f_src->no, 
f_mid_src);
+
+                                       // Interpolate weights over face.
+
+                                       //spatially finding the weights from 
the face's vertices (no need to reset the weights/ it already gets
+                                       //rewritten in the 
interp_weights_poly_v3()
+                                       interp_weights_poly_v3(tmp_weight, 
v_co_list_src, f_src->len, v_dst_co);
+
+                                       // Interpolating according to the 
spatially found weights
+                                       lcol_out->a = 0;
+                                       lcol_out->b = 0;
+                                       lcol_out->g = 0;
+                                       lcol_out->r = 0;
+
+                                       BM_ITER_ELEM_INDEX (l2, &liter2, f_src, 
BM_LOOPS_OF_FACE, a) {
+                                               MLoopCol *lcol2 = 
BM_ELEM_CD_GET_VOID_P(l2, CD_src);
+
+                                               //there's no madd_v4_v4fl for 
char!
+                                               lcol_out->a += (lcol2->a * 
tmp_weight[a]);
+                                               lcol_out->b += (lcol2->b * 
tmp_weight[a]);
+                                               lcol_out->g += (lcol2->g * 
tmp_weight[a]);
+                                               lcol_out->r += (lcol2->r * 
tmp_weight[a]);
+
+                                       }
+
+                                       //shall we verify the indices!?
+                                       //there's no copy_v4_v4 for char!
+                                       lcol->a = lcol_out->a;
+                                       lcol->b = lcol_out->b;
+                                       lcol->g = lcol_out->g;
+                                       lcol->r = lcol_out->r;
+
+                                       //end of interpolation
+                               }
+                       }
+
+               }
+
+               BKE_bmbvh_free(bmtree_src);
+
+               MEM_freeN(v_co_list_src);
+               MEM_freeN(tmp_weight);
+               return true;
+       }
+
+       else if (src_lay_start == src_lay_end) {
+
                //fix the layer index of the source & dest
-               CD_src = CustomData_get_n_offset(&bm_src->ldata, CD_MLOOPCOL, 
src_lay_iter);    //get the offset of the
-               CD_dst = CustomData_get_n_offset(&bm_dst->ldata, CD_MLOOPCOL, 
dst_lay_iter);    //lay_iter(th)CD_SHAPEKEY layer
+               CD_src = CustomData_get_n_offset(&bm_src->ldata, CD_MLOOPCOL, 
src_lay_start);
+               CD_dst = CustomData_get_n_offset(&bm_dst->ldata, CD_MLOOPCOL, 
dst_lay_start);
 
                //the way we do it is by looping over each face!!
                BM_ITER_MESH (f_dst, &fiter, bm_dst, BM_FACES_OF_MESH) {
@@ -2225,13 +2334,16 @@
                        }
                }
 
+               BKE_bmbvh_free(bmtree_src);
+
+               MEM_freeN(v_co_list_src);
+               MEM_freeN(tmp_weight);
+               return true;
        }
 
-       BKE_bmbvh_free(bmtree_src);
-
-       MEM_freeN(v_co_list_src);
-       MEM_freeN(tmp_weight);
-       return true;
+       else {  //src_lay_start > src_lay_end
+               return false;
+       }
 }
 
 

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to