Revision: 58977 http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58977 Author: walid Date: 2013-08-06 23:14:48 +0000 (Tue, 06 Aug 2013) Log Message: ----------- Code cleaning: repositioning code pieces to be more meaningful
Modified Paths: -------------- 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.h 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-06 22:58:40 UTC (rev 58976) +++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c 2013-08-06 23:14:48 UTC (rev 58977) @@ -1204,6 +1204,216 @@ return true; } + +//--------------------------end of WIP fucntions and beginning of Projection based functions--------------------// + +typedef struct coord_pool { + float (*coord)[3]; //used as the offset coordinates for shapekeys + int count; //used to keep track of the coordinate to be filled +} coord_pool; + +bool BM_mesh_shapekey_copy3(BMesh *bm_src, BMesh *bm_dst, const struct ReplaceLayerInfo replace_info, bool relative_to_target, + float tmp_mat[4][4]) +{ + //-----algorithm definitions start + struct BMBVHTree *bmtree_src = NULL; + float *tmp_weight = NULL; + float tmp_co[3]; + BMIter fiter, fiter2; + BMVert *v2; + + int a; + float v_src_offset[3] = {0, 0, 0}; + float v_dst_offset[3] = {0, 0, 0}; + + BMIter viter; + BMFace *f_dst, *f_src; + int v_dst_count, v_src_count; + float (*v_co_list_dst)[3], (*v_co_list_src)[3]; + float f_mid_dst[3], f_mid_src[3]; + coord_pool *offsets_grp; //stores all the gathered offsets/vert to be averaged at the end of interpolation + const int exp_vert_per_face = 10; + int v_src_max_count, v_dst_max_count; + //====algorithm definitions end + + int CD_offset_src, CD_offset_dst; + int CD_basis_src, CD_basis_dst; + + //used for iterating the destination's verts + BMVert *v; + //iter => vertex iterator + BMIter iter; + int src_lay_iter, dst_lay_iter; + + //tree variables + BMEditMesh *em_src; + + //replace mode variables + int src_lay_start, src_lay_end; + int dst_lay_start; + +// float v_co[3]; + + //Is that good to support edit mesh mode at the cost of receiving me_src too ? + //if (me_src->edit_btmesh != NULL) em_src = me_src->edit_btmesh; //edit mesh mode + //else + em_src = BKE_editmesh_create(bm_src, true); //create editmesh data from bm WITH tess. + //if it was false ... data other than + //em->bm won't be copied + + CD_basis_src = CustomData_get_n_offset(&bm_src->vdata, CD_SHAPEKEY, 0); //get the offset of the basis + CD_basis_dst = CustomData_get_n_offset(&bm_dst->vdata, CD_SHAPEKEY, 0); + + //get the faces tree + bmtree_src = BKE_bmbvh_new(em_src, 0, NULL, false); + + v_co_list_dst = MEM_mallocN(sizeof(*v_co_list_dst) * exp_vert_per_face, "v_co_list_dst bmesh_data_transfer.c"); + v_co_list_src = MEM_mallocN(sizeof(*v_co_list_src) * exp_vert_per_face, "v_co_list_src bmesh_data_transfer.c"); + + offsets_grp = MEM_mallocN(sizeof(*offsets_grp) * bm_dst->totvert, "offsets_grp bmesh_data_transfer.c"); + BM_ITER_MESH (v, &iter, bm_dst, BM_VERTS_OF_MESH) { + + BM_ITER_ELEM_INDEX (f_dst, &viter, v, BM_FACES_OF_VERT, a) {} + offsets_grp[v->head.index].coord = MEM_mallocN(sizeof(*(offsets_grp[v->head.index].coord)) * a, + "offsets_grp[v->head.index].coord bmesh_data_transfer.c"); + + offsets_grp[v->head.index].count = 0; //if that wasn't fast enf we may use calloc for the offsets_grp + } + + tmp_weight = MEM_mallocN(sizeof(*tmp_weight) * exp_vert_per_face, "tmp_weight bmesh_data_transfer.c"); + + src_lay_start = replace_info.src_lay_start; + 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++) { + + //fix the layer index of the source & dest + CD_offset_src = CustomData_get_n_offset(&bm_src->vdata, CD_SHAPEKEY,src_lay_iter); //get the offset of the + CD_offset_dst = CustomData_get_n_offset(&bm_dst->vdata, CD_SHAPEKEY,dst_lay_iter); //lay_iter(th)CD_SHAPEKEY layer + + //the way we do it is by looping over each face!! + BM_ITER_MESH (f_dst, &iter, bm_dst, BM_FACES_OF_MESH) { + + //get a coordinate list of the f_dst verts + //used to get the the f_mid_dst for mid_poly_v3 + BM_ITER_ELEM_INDEX (v, &fiter, f_dst, BM_VERTS_OF_FACE, v_dst_count) { + if (v_dst_count > exp_vert_per_face) { + if (v_dst_count > v_dst_max_count) { + v_co_list_dst = MEM_reallocN(v_co_list_dst, sizeof(*v_co_list_dst) * (v_dst_count + 1)); + v_dst_max_count = v_dst_count; + } + } + + copy_v3_v3(v_co_list_dst[v_dst_count], v->co); + } + + zero_v3(f_mid_dst); + mid_poly_v3(f_mid_dst, v_co_list_dst, v_dst_count); + + if (relative_to_target == true) { + // Transform into target space. + mul_v3_m4v3(tmp_co, tmp_mat, f_mid_dst); //to start searching for a match + + // Node tree accelerated search for closest face. + f_src = BKE_bmbvh_find_face_closest(bmtree_src, tmp_co, FLT_MAX); //would return null if the source didn't + //have faces within the radius range!! + } + + else { + // Node tree accelerated search for closest face. + f_src = BKE_bmbvh_find_face_closest(bmtree_src, f_mid_dst, FLT_MAX); //would return null if the source didn't + //have faces within the radius range!! + } + + //deprecated comment + ///fork from here to map each vertex into the projection + + //get a coordinate list of the f verts + BM_ITER_ELEM_INDEX (v2, &fiter, f_src, BM_VERTS_OF_FACE, v_src_count) { + //reallocate if the verts/faces were more than expected + if (v_src_count > exp_vert_per_face) { + //and according to the previous records only allocate if that more than max already allocated + if (v_src_count > v_src_max_count) { + v_co_list_src = MEM_reallocN(v_co_list_src, sizeof(*v_co_list_src) * (v_src_count + 1)); + + // Prepare memory for later interpolation + tmp_weight = MEM_reallocN(tmp_weight, sizeof(*tmp_weight) * v_src_count); + + v_src_max_count = v_src_count; + } + } + + copy_v3_v3(v_co_list_src[v_src_count], v2->co); + } + + zero_v3(f_mid_src); + mid_poly_v3(f_mid_src, v_co_list_src, v_src_count); //get the mid point of the source face + + BM_ITER_ELEM (v, &fiter, f_dst, BM_VERTS_OF_FACE) { + if (relative_to_target == true) { + zero_v3(tmp_co); + + // Transform into target space. + mul_v3_m4v3(tmp_co, tmp_mat, v->co); + } + + else { + copy_v3_v3(tmp_co, v->co); + } + + // Project each vertex onto face. + project_v3_plane(tmp_co, f_src->no, f_mid_src); + //project_v3_plane(tmp_co, f->no, f->l_first->v->co);//not sure, do we really have to use an actual vertex ? + + // Interpolate weights over face. + + //spatially finding the weights from the face's vertices + interp_weights_poly_v3(tmp_weight, v_co_list_src, v_src_count, tmp_co); + + // Interpolating according to the spatially found weights + // Get weights from face. + zero_v3(v_dst_offset); + BM_ITER_ELEM_INDEX (v2, &fiter2, f_src, BM_VERTS_OF_FACE, a) { + sub_v3_v3v3(v_src_offset, BM_ELEM_CD_GET_VOID_P(v2, CD_offset_src), + BM_ELEM_CD_GET_VOID_P(v2, CD_basis_src)); + madd_v3_v3fl(v_dst_offset, v_src_offset, tmp_weight[a]); + } + + copy_v3_v3(offsets_grp[v->head.index].coord[offsets_grp[v->head.index].count], v_dst_offset); + (offsets_grp[v->head.index].count)++; + + //shall we verify the indices!? + //we interpolate vertix weights instead + } + } + + BM_ITER_MESH (v, &iter, bm_dst, BM_VERTS_OF_MESH) { + zero_v3(v_dst_offset); + mid_poly_v3(v_dst_offset, offsets_grp[v->head.index].coord, offsets_grp[v->head.index].count); + + add_v3_v3v3(BM_ELEM_CD_GET_VOID_P(v, CD_offset_dst), BM_ELEM_CD_GET_VOID_P(v, CD_basis_dst), + v_dst_offset); + offsets_grp[v->head.index].count = 0; //reset for the upcoming layer + } + + } + + BM_ITER_MESH (v, &iter, bm_dst, BM_VERTS_OF_MESH) { + MEM_freeN(offsets_grp[v->head.index].coord); + } + + MEM_freeN(offsets_grp); + + BKE_bmbvh_free(bmtree_src); + + MEM_freeN(v_co_list_dst); + MEM_freeN(v_co_list_src); + MEM_freeN(tmp_weight); + return true; +} + //callback used for the island finding /* static bool check_e_table_cb(BMEdge *e, void *user_data) { @@ -1854,213 +2064,6 @@ return true; } -typedef struct coord_pool { - float (*coord)[3]; //used as the offset coordinates for shapekeys - int count; //used to keep track of the coordinate to be filled -} coord_pool; - -bool BM_mesh_shapekey_copy3(BMesh *bm_src, BMesh *bm_dst, const struct ReplaceLayerInfo replace_info, bool relative_to_target, - float tmp_mat[4][4]) -{ - //-----algorithm definitions start - struct BMBVHTree *bmtree_src = NULL; - float *tmp_weight = NULL; - float tmp_co[3]; - BMIter fiter, fiter2; - BMVert *v2; - - int a; - float v_src_offset[3] = {0, 0, 0}; - float v_dst_offset[3] = {0, 0, 0}; - - BMIter viter; - BMFace *f_dst, *f_src; - int v_dst_count, v_src_count; - float (*v_co_list_dst)[3], (*v_co_list_src)[3]; - float f_mid_dst[3], f_mid_src[3]; - coord_pool *offsets_grp; //stores all the gathered offsets/vert to be averaged at the end of interpolation - const int exp_vert_per_face = 10; - int v_src_max_count, v_dst_max_count; - //====algorithm definitions end - - int CD_offset_src, CD_offset_dst; - int CD_basis_src, CD_basis_dst; - - //used for iterating the destination's verts - BMVert *v; - //iter => vertex iterator - BMIter iter; - int src_lay_iter, dst_lay_iter; - - //tree variables - BMEditMesh *em_src; - - //replace mode variables - int src_lay_start, src_lay_end; - int dst_lay_start; - -// float v_co[3]; - - //Is that good to support edit mesh mode at the cost of receiving me_src too ? - //if (me_src->edit_btmesh != NULL) em_src = me_src->edit_btmesh; //edit mesh mode - //else - em_src = BKE_editmesh_create(bm_src, true); //create editmesh data from bm WITH tess. - //if it was false ... data other than - //em->bm won't be copied - - CD_basis_src = CustomData_get_n_offset(&bm_src->vdata, CD_SHAPEKEY, 0); //get the offset of the basis - CD_basis_dst = CustomData_get_n_offset(&bm_dst->vdata, CD_SHAPEKEY, 0); - - //get the faces tree - bmtree_src = BKE_bmbvh_new(em_src, 0, NULL, false); - - v_co_list_dst = MEM_mallocN(sizeof(*v_co_list_dst) * exp_vert_per_face, "v_co_list_dst bmesh_data_transfer.c"); - v_co_list_src = MEM_mallocN(sizeof(*v_co_list_src) * exp_vert_per_face, "v_co_list_src bmesh_data_transfer.c"); - @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs