[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19308] branches/bmesh/blender/source/ blender/bmesh: some cleanup of bmesh_polygon.c.
Joseph Eagar
joeedh at gmail.com
Mon Mar 16 11:12:52 CET 2009
Revision: 19308
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19308
Author: joeedh
Date: 2009-03-16 11:12:52 +0100 (Mon, 16 Mar 2009)
Log Message:
-----------
some cleanup of bmesh_polygon.c. there were three winding functions, now there's just one, the original testedgeside, that has some additional tests that might fix some issues I was having. still need to decided if bmesh_polygon.c stuff should be entirely double or entire floats, right now there's a little half-and-half going on.
Modified Paths:
--------------
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
branches/bmesh/blender/source/blender/bmesh/operators/extrudeops.c
Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c 2009-03-16 09:43:47 UTC (rev 19307)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c 2009-03-16 10:12:52 UTC (rev 19308)
@@ -52,6 +52,22 @@
return 1;
}
+static short testedgesidef(float *v1, float *v2, float *v3)
+/* is v3 to the right of v1-v2 ? With exception: v3==v1 || v3==v2 */
+{
+ double inp;
+
+ //inp= (v2[cox]-v1[cox])*(v1[coy]-v3[coy]) +(v1[coy]-v2[coy])*(v1[cox]-v3[cox]);
+ inp= (v2[0]-v1[0])*(v1[1]-v3[1]) +(v1[1]-v2[1])*(v1[0]-v3[0]);
+
+ if(inp<0.0) return 0;
+ else if(inp==0) {
+ if(v1[0]==v3[0] && v1[1]==v3[1]) return 0;
+ if(v2[0]==v3[0] && v2[1]==v3[1]) return 0;
+ }
+ return 1;
+}
+
static int point_in_triangle(double *v1, double *v2, double *v3, double *pt)
{
if(testedgeside(v1,v2,pt) && testedgeside(v2,v3,pt) && testedgeside(v3,v1,pt))
@@ -60,31 +76,6 @@
}
/*
- * CONVEX ANGLE
- *
- * Tests whether or not a given angle in
- * a polygon is convex or not. Note that
- * this assumes that the polygon has been
- * projected to the x/y plane
- *
-*/
-static int convexangle(float *v1t, float *v2t, float *v3t)
-{
- float v1[3], v3[3], n[3];
- VecSubf(v1, v1t, v2t);
- VecSubf(v3, v3t, v2t);
-
- Normalize(v1);
- Normalize(v3);
- Crossf(n, v1, v3);
-
- if(n[2] < 0.0)
- return 0;
-
- return 1;
-}
-
-/*
* COMPUTE POLY NORMAL
*
* Computes the normal of a planar
@@ -107,15 +98,7 @@
for(i = 0; i < nverts; i++){
u = verts[i];
v = verts[(i+1) % nverts];
- /*w = verts[(i+2) % nverts];
-
- VecSubf(v1, u, v);
- VecSubf(v2, w, v);
- Crossf(normal, v1, v2);
- Normalize(normal);
- return;*/
-
/* newell's method
so thats?:
@@ -433,29 +416,6 @@
bmesh_loop_reverse(bm, f);
}
-
-
-int winding(double *a, double *b, double *c)
-{
- double v1[3], v2[3], v[3];
-
- VECSUB(v1, b, a);
- VECSUB(v2, b, c);
-
- v1[2] = 0;
- v2[2] = 0;
-
- Normalize_d(v1);
- Normalize_d(v2);
-
- Crossd(v, v1, v2);
-
- /*!! (turns nonzero into 1) is likely not necassary,
- since '>' I *think* should always
- return 0 or 1, but I'm not totally sure. . .*/
- return !!(v[2] > 0);
-}
-
/* detects if two line segments cross each other (intersects).
note, there could be more winding cases then there needs to be. */
int linecrosses(double *v1, double *v2, double *v3, double *v4)
@@ -469,35 +429,14 @@
return (w1 == w2) && (w3 == w4);*/
- w1 = winding(v1, v3, v2);
- w2 = winding(v2, v4, v1);
- w3 = !winding(v1, v2, v3);
- w4 = winding(v3, v2, v4);
- w5 = !winding(v3, v1, v4);
+ w1 = testedgesidef(v1, v3, v2);
+ w2 = testedgesidef(v2, v4, v1);
+ w3 = !testedgesidef(v1, v2, v3);
+ w4 = testedgesidef(v3, v2, v4);
+ w5 = !testedgesidef(v3, v1, v4);
return w1 == w2 && w2 == w3 && w3 == w4 && w4==w5;
}
-int windingf(float *a, float *b, float *c)
-{
- float v1[3], v2[3], v[3];
-
- VECSUB(v1, b, a);
- VECSUB(v2, b, c);
-
- v1[2] = 0;
- v2[2] = 0;
-
- Normalize(v1);
- Normalize(v2);
-
- Crossf(v, v1, v2);
-
- /*!! (turns nonzero into 1) is likely not necassary,
- since '>' I *think* should always
- return 0 or 1, but I'm not totally sure. . .*/
- return !!(v[2] > 0);
-}
-
/* detects if two line segments cross each other (intersects).
note, there could be more winding cases then there needs to be. */
int linecrossesf(float *v1, float *v2, float *v3, float *v4)
@@ -511,11 +450,11 @@
return (w1 == w2) && (w3 == w4);*/
- w1 = windingf(v1, v3, v2);
- w2 = windingf(v2, v4, v1);
- w3 = !windingf(v1, v2, v3);
- w4 = windingf(v3, v2, v4);
- w5 = !windingf(v3, v1, v4);
+ w1 = testedgesidef(v1, v3, v2);
+ w2 = testedgesidef(v2, v4, v1);
+ w3 = !testedgesidef(v1, v2, v3);
+ w4 = testedgesidef(v3, v2, v4);
+ w5 = !testedgesidef(v3, v1, v4);
return w1 == w2 && w2 == w3 && w3 == w4 && w4==w5;
}
@@ -732,7 +671,7 @@
VECCOPY(v1, loops[i][0]->v->co);
VECCOPY(v2, loops[i][1]->v->co);
- shrink_edgef(v1, v2, 0.999f);
+ shrink_edgef(v1, v2, 0.9999f);
VECCOPY(edgeverts[a], v1);
a++;
@@ -776,7 +715,7 @@
VECCOPY(v1, p1);
VECCOPY(v2, p2);
- shrink_edgef(v1, v2, 1.0001f);
+ shrink_edgef(v1, v2, 1.00001f);
if (linecrossesf(p1, p2, mid, out)) clen++;
//else if (linecrossesf(p2, p1, out, mid)) clen++;
Modified: branches/bmesh/blender/source/blender/bmesh/operators/extrudeops.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/extrudeops.c 2009-03-16 09:43:47 UTC (rev 19307)
+++ branches/bmesh/blender/source/blender/bmesh/operators/extrudeops.c 2009-03-16 10:12:52 UTC (rev 19308)
@@ -29,8 +29,9 @@
BMO_Init_Op(&dupeop, BMOP_DUPE);
BMO_Flag_Buffer(bm, op, BMOP_EXFACE_EDGEFACEIN, EXT_INPUT);
-
-#if 1
+
+ /*if one flagged face is bordered by an unflagged face, then we delete
+ original geometry.*/
for (e=BMIter_New(&iter, bm, BM_EDGES, NULL);e;e=BMIter_Step(&iter)) {
if (!BMO_TestFlag(bm, e, EXT_INPUT)) continue;
@@ -74,7 +75,6 @@
if (BMO_TestFlag(bm, f, EXT_INPUT))
BMO_SetFlag(bm, f, EXT_DEL);
}
-#endif
if (delorig) BMO_InitOpf(bm, &delop, "del geom=%fvef context=%d",
EXT_DEL, DEL_ONLYTAGGED);
@@ -152,6 +152,6 @@
/*cleanup*/
- BMO_Finish_Op(bm, &delop);
+ if (delorig) BMO_Finish_Op(bm, &delop);
BMO_Finish_Op(bm, &dupeop);
}
More information about the Bf-blender-cvs
mailing list