Revision: 42501
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42501
Author:   campbellbarton
Date:     2011-12-07 21:54:14 +0000 (Wed, 07 Dec 2011)
Log Message:
-----------
split BM_Collapse_Vert into 2 functions
* BM_Collapse_Vert_Faces
* BM_Collapse_Vert_Edges

since these are both quite different operations and callers where checking for 
one case or another anyway.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/bmesh/bmesh.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_iterators_inline.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
    branches/bmesh/blender/source/blender/bmesh/operators/dissolveops.c

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h 2011-12-07 20:55:28 UTC 
(rev 42500)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h 2011-12-07 21:54:14 UTC 
(rev 42501)
@@ -207,10 +207,14 @@
                                            struct BMVert *v1, struct BMVert 
*v2,
                                            struct BMLoop **nl, struct BMEdge 
*example );
 
-/*dissolves a vert shared only by two edges*/
-BMEdge* BM_Collapse_Vert ( struct BMesh *bm, struct BMEdge *ke, struct BMVert 
*kv,
-                        float fac );
+/* these 2 functions are very similar */
+BMEdge* BM_Collapse_Vert_Faces(struct BMesh *bm,
+                         struct BMEdge *ke, struct BMVert *kv,
+                         float fac);
+BMEdge* BM_Collapse_Vert_Edges(struct BMesh *bm,
+                         struct BMEdge *ke, struct BMVert *kv);
 
+
 /*splits an edge.  ne is set to the new edge created.*/
 struct BMVert *BM_Split_Edge ( struct BMesh *bm, struct BMVert *v,
                                            struct BMEdge *e, struct BMEdge 
**ne,
@@ -369,12 +373,12 @@
 
 /*include the rest of the API*/
 #include "bmesh_filters.h"
-#include "bmesh_iterators.h"
 #include "bmesh_marking.h"
 #include "bmesh_operator_api.h"
 #include "bmesh_operators.h"
 #include "bmesh_error.h"
 #include "bmesh_queries.h"
+#include "bmesh_iterators.h"
 #include "bmesh_walkers.h"
 #include "intern/bmesh_inline.c"
 

Modified: 
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_iterators_inline.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_iterators_inline.c 
2011-12-07 20:55:28 UTC (rev 42500)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_iterators_inline.c 
2011-12-07 21:54:14 UTC (rev 42501)
@@ -31,10 +31,6 @@
 
 #include "bmesh.h"
 
-#ifndef NULL
-#  define NULL (void *)0
-#endif
-
 /* inline here optimizes out the switch statement when called with
  * constant values (which is very common), nicer for loop-in-loop situations */
 
@@ -161,4 +157,4 @@
 }
 
 
-#endif
+#endif /* BM_ITERATORS_INLINE_C */

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c     
2011-12-07 20:55:28 UTC (rev 42500)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c     
2011-12-07 21:54:14 UTC (rev 42501)
@@ -138,7 +138,7 @@
                return 1;
        } else if (keepedge == NULL && len == 2) {
                /*collapse the vertex*/
-               e = BM_Collapse_Vert(bm, v->e, v, 1.0);
+               e = BM_Collapse_Vert_Faces(bm, v->e, v, 1.0);
 
                if (!e) {
                        return 0;
@@ -181,7 +181,7 @@
                }
 
                /*collapse the vertex*/
-               e = BM_Collapse_Vert(bm, baseedge, v, 1.0);
+               e = BM_Collapse_Vert_Faces(bm, baseedge, v, 1.0);
 
                if (!e) {
                        return 0;
@@ -384,7 +384,7 @@
 }
 
 /**
- *                     bmesh_collapse_vert
+ *                     BM_Collapse_Vert_Faces
  *
  *  Collapses a vertex that has only two manifold edges
  *  onto a vertex it shares an edge with. Fac defines
@@ -392,21 +392,27 @@
  *
  *  Note that this is not a general edge collapse function.
  *
+ * Note this function is very close to 'BM_Collapse_Vert_Edges', both collapse
+ * a vertex and return a new edge. Except this takes a factor and merges
+ * custom data.
+ *
  *  BMESH_TODO:
  *    Insert error checking for KV valance.
  *
  *  Returns -
- *     Nothing
+ *     The New Edge
  */
- 
-BMEdge* BM_Collapse_Vert(BMesh *bm, BMEdge *ke, BMVert *kv, float fac)
+
+BMEdge* BM_Collapse_Vert_Faces(BMesh *bm, BMEdge *ke, BMVert *kv, float fac)
 {
+       BMEdge *ne = NULL;
+       BMVert *tv = bmesh_edge_getothervert(ke, kv);
+
+
+       BMIter iter;
+       BMLoop *l=NULL, *kvloop=NULL, *tvloop=NULL;
        BMFace **faces = NULL, *f;
        BLI_array_staticdeclare(faces, 8);
-       BMIter iter;
-       BMLoop *l=NULL, *kvloop=NULL, *tvloop=NULL;
-       BMEdge *ne = NULL;
-       BMVert *tv = bmesh_edge_getothervert(ke,kv);
        void *src[2];
        float w[2];
 
@@ -416,7 +422,7 @@
        w[0] = 1.0f - fac;
        w[1] = fac;
 
-       if(ke->l){
+       if (ke->l) {
                l = ke->l;
                do{
                        if(l->v == tv && l->next->v == kv) {
@@ -427,36 +433,23 @@
                                src[1] = tvloop->head.data;
                                CustomData_bmesh_interp(&bm->ldata, src,w, 
NULL, 2, kvloop->head.data);
                        }
-                       l=l->radial_next;
-               }while(l!=ke->l);
+                       l= l->radial_next;
+               } while (l != ke->l);
        }
 
        BM_ITER(f, &iter, bm, BM_FACES_OF_VERT, kv) {
                BLI_array_append(faces, f);
        }
-       
-       BM_Data_Interp_From_Verts(bm, kv, tv, kv, fac);
 
-       if (BM_Vert_EdgeCount(kv) == 2) {
-               /* in this case we want to keep all faces and not join them,
-                * rather just get rid of the veretex - see bug [#28645] */
+       /* Collapse between 2+ faces */
+       if (faces && BLI_array_count(faces) > 1) {
+               BMFace *f2;
                BMEdge *e2;
                BMVert *tv2;
 
-               /* no need to check for null, we know the vert has 2 edes */
-               e2 = bmesh_disk_nextedge(ke, kv);
-               tv2 = BM_OtherEdgeVert(e2, kv);
+               /* only call when making real changes */
+               BM_Data_Interp_From_Verts(bm, kv, tv, kv, fac);
 
-               /* only action, other calls here only get the edge to return */
-               bmesh_jekv(bm, ke, kv);
-
-               ne= BM_Edge_Exist(tv, tv2);
-       }
-       else if (faces && BLI_array_count(faces) > 1) {
-               BMFace *f2;
-               BMEdge *e2;
-               BMVert *tv2;
-
                e2 = bmesh_disk_nextedge(ke, kv);
                tv2 = BM_OtherEdgeVert(e2, kv);
 
@@ -468,12 +461,57 @@
                        }
                }
        }
+       /* else we cant do anything! */
 
        BLI_array_free(faces);
+
        return ne;
 }
 
+
 /**
+ *                     BM_Collapse_Vert_Edges
+ *
+ * Collapses a vertex onto another vertex it shares an edge with. Fac defines
+ * the amount of interpolation for Custom Data.
+ *
+ * Note that this is not a general edge collapse function.
+ *
+ * Note this function is very close to 'BM_Collapse_Vert_Faces', both collapse
+ * a vertex and return a new edge. Except this doesn't merge customdata.
+ *
+ * Returns -
+ * The New Edge
+ */
+
+BMEdge* BM_Collapse_Vert_Edges(BMesh *bm, BMEdge *ke, BMVert *kv)
+{
+       BMEdge *ne = NULL;
+
+       /* Collapse between 2 edges */
+
+       /* in this case we want to keep all faces and not join them,
+        * rather just get rid of the veretex - see bug [#28645] */
+       BMVert *tv  = bmesh_edge_getothervert(ke, kv);
+       if (tv) {
+               BMEdge *e2 = bmesh_disk_nextedge(ke, kv);
+               if (e2) {
+                       BMVert *tv2 = BM_OtherEdgeVert(e2, kv);
+                       if (tv2) {
+                               /* only action, other calls here only get the 
edge to return */
+                               bmesh_jekv(bm, ke, kv);
+
+                               ne= BM_Edge_Exist(tv, tv2);
+                       }
+               }
+       }
+
+       return ne;
+}
+
+#undef DO_V_INTERP
+
+/**
  *                     BM_split_edge
  *     
  *     Splits an edge. v should be one of the vertices in e and

Modified: branches/bmesh/blender/source/blender/bmesh/operators/dissolveops.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/dissolveops.c 
2011-12-07 20:55:28 UTC (rev 42500)
+++ branches/bmesh/blender/source/blender/bmesh/operators/dissolveops.c 
2011-12-07 21:54:14 UTC (rev 42501)
@@ -169,7 +169,7 @@
        /*clean up extreneous 2-valence vertices*/
        for (i=0; i<BLI_array_count(verts); i++) {
                if (verts[i]->e)
-                       BM_Collapse_Vert(bm, verts[i]->e, verts[i], 1.0);
+                       BM_Collapse_Vert_Faces(bm, verts[i]->e, verts[i], 1.0);
        }
        
        BLI_array_free(verts);
@@ -224,8 +224,8 @@
                        BMVert *v1= e->v1, *v2= e->v2;
 
                        /*collapse the vert*/
-                       if (BM_Vert_EdgeCount(v1) == 2) BM_Collapse_Vert(bm, 
v1->e, v1, 0.5f);
-                       if (BM_Vert_EdgeCount(v2) == 2) BM_Collapse_Vert(bm, 
v2->e, v2, 0.5f);
+                       if (BM_Vert_EdgeCount(v1) == 2) 
BM_Collapse_Vert_Edges(bm, v1->e, v1);
+                       if (BM_Vert_EdgeCount(v2) == 2) 
BM_Collapse_Vert_Edges(bm, v2->e, v2);
 
                }
        }
@@ -298,7 +298,7 @@
                        if (BM_Vert_EdgeCount(v) == 2) {
 
                                /*collapse the vert*/
-                               BM_Collapse_Vert(bm, v->e, v, 0.5f);
+                               BM_Collapse_Vert_Edges(bm, v->e, v);
                                continue;
                        }
 

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

Reply via email to