[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60220] branches/ soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c : code rewrite: transfer by topology: using BM_face_find_best_tan_match_loop instead() of BM_match_loops()
Walid Shouman
eng.walidshouman at gmail.com
Wed Sep 18 16:46:01 CEST 2013
Revision: 60220
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60220
Author: walid
Date: 2013-09-18 14:46:01 +0000 (Wed, 18 Sep 2013)
Log Message:
-----------
code rewrite: transfer by topology: using BM_face_find_best_tan_match_loop instead() of BM_match_loops()
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-09-18 13:32:57 UTC (rev 60219)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c 2013-09-18 14:46:01 UTC (rev 60220)
@@ -36,68 +36,37 @@
//----------------------*
//******************
-/**
- * @brief BM_match_loops fill the source and destination loop groups in order
- * according to the best tangential fit, a good result is guaranteed only for matching loop number faces
- * @param f_src
- * @param f_dst
- * @param loops_mapping should be pre-allocated with
- * 1) the bm_dst->totloops if index_per_mesh == true
- * 2) the f_dst->len if the index_per_mesh == false
- * @param index_per_mesh true if the loops_matching should be filled for the whole bmesh
- * used to speed up and avoid adding extra loop --> use it only if the loops are indexed!!,
- * false if the matching is per face instead of per mesh
- * @return
- */
+BMLoop* BM_face_find_best_tan_match_loop(BMFace *f_src, BMLoop *l_dst);
-bool BM_match_loops(BMFace *f_src, BMFace *f_dst, int* loops_mapping, bool index_per_mesh);
+BMLoop* BM_face_find_best_tan_match_loop(BMFace *f_src, BMLoop *l_dst) {
-bool BM_match_loops(BMFace *f_src, BMFace *f_dst, int* loops_mapping, bool index_per_mesh) {
+ BMLoop *l, *l_src;
+ BMIter liter;
+ float l_dst_tan[3], l_src_tan[3];
- BMLoop *l_src, *l_dst;
- BMIter liter, liter2;
- int a, b;
float dot_product, prev_dot_product;
- //if the source and destination doesn't have the same number of loops: either multimapping or dropping would happen
- /*
- if (f_dst->len != f_src->len)
- return false;
- */
- if (f_src->len == 0) //
- return false;
+ if (f_src->len == 0)
+ return NULL;
- BM_ITER_ELEM_INDEX (l_dst, &liter, f_dst, BM_LOOPS_OF_FACE, a) {
+ dot_product = -1;
+ prev_dot_product = -2;
- dot_product = -1;
- //using -2 => assert: falling back to any loop, in the worst case: all the loops have tan=-1 the first would be taken
- prev_dot_product = -2;
- BM_ITER_ELEM_INDEX (l_src, &liter2, f_src, BM_LOOPS_OF_FACE, b) {
+ BM_loop_calc_face_tangent(l_dst, l_dst_tan);
- float l_src_tan[3];
- float l_dst_tan[3];
+ BM_ITER_ELEM (l_src, &liter, f_src, BM_LOOPS_OF_FACE) {
+ BM_loop_calc_face_tangent(l_src, l_src_tan);
- BM_loop_calc_face_tangent(l_src, l_src_tan);
- BM_loop_calc_face_tangent(l_dst, l_dst_tan);
+ dot_product = dot_v3v3(l_src_tan, l_dst_tan);
- dot_product = dot_v3v3(l_src_tan, l_dst_tan);
-
- if (dot_product > prev_dot_product) {
- if (index_per_mesh == true) {
- loops_mapping[l_dst->head.index] = l_src->head.index;
- }
-
- else {//false index_per_mesh (could be called) index_per_face
- loops_mapping[a] = b;
- }
-
- prev_dot_product = dot_product;
- }
-
+ if (dot_product > prev_dot_product) {
+ l = l_src;
+ prev_dot_product = dot_product;
}
+
}
- return true;
+ return l;
}
typedef struct BMFace_match {
@@ -481,7 +450,7 @@
{
BMVert *v_src, *v_dst;
BMFace *f_src, *f_dst;
- BMLoop *l_dst;
+ BMLoop *l_dst, *l_src;
BMIter iter, fiter, liter;
int a;
int *index_mapping;
@@ -521,10 +490,12 @@
f_src = BKE_bmbvh_find_face_closest(bmtree_src, f_mid_dst, FLT_MAX);
if (f_src != NULL) {
- //map each face's loops
- if (!BM_match_loops(f_src, f_dst, index_mapping, true))
- return false;
-
+ BM_ITER_ELEM (l_dst, &liter, f_dst, BM_LOOPS_OF_FACE) {
+ l_src = BM_face_find_best_tan_match_loop(f_src, l_dst);
+ if (l_src != NULL) {
+ index_mapping[l_dst->head.index] = l_src->head.index;
+ }
+ }
}
else {
BM_ITER_ELEM (l_dst, &liter, f_dst, BM_LOOPS_OF_FACE) {
More information about the Bf-blender-cvs
mailing list