[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48246] branches/soc-2011-tomato: Merging r48241 through r48245 from trunk into soc-2011-tomato
Sergey Sharybin
sergey.vfx at gmail.com
Sun Jun 24 20:01:47 CEST 2012
Revision: 48246
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48246
Author: nazgul
Date: 2012-06-24 18:01:46 +0000 (Sun, 24 Jun 2012)
Log Message:
-----------
Merging r48241 through r48245 from trunk into soc-2011-tomato
Revision Links:
--------------
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48241
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48245
Modified Paths:
--------------
branches/soc-2011-tomato/intern/raskter/raskter.c
branches/soc-2011-tomato/source/blender/blenlib/BLI_math_vector.h
branches/soc-2011-tomato/source/blender/blenlib/intern/math_vector.c
branches/soc-2011-tomato/source/blender/bmesh/intern/bmesh_polygon.c
branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.cpp
branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
Property Changed:
----------------
branches/soc-2011-tomato/
branches/soc-2011-tomato/source/blender/editors/interface/interface.c
branches/soc-2011-tomato/source/blender/editors/space_outliner/
Property changes on: branches/soc-2011-tomato
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/ge_harmony:42255,42279-42282,42286,42302,42338,42349,42616,42620,42698-42699,42739,42753,42773-42774,42832,44568,44597-44598,44793-44794
/branches/soc-2011-cucumber:37517,38166-38167,38177,38179-38180,38187,38242,38384,38387,38403-38404,38407,38968,38970,38973,39045,40845,42997-42998,43439
/branches/vgroup_modifiers:38694-39989
/trunk/blender:36831-48240
+ /branches/ge_harmony:42255,42279-42282,42286,42302,42338,42349,42616,42620,42698-42699,42739,42753,42773-42774,42832,44568,44597-44598,44793-44794
/branches/soc-2011-cucumber:37517,38166-38167,38177,38179-38180,38187,38242,38384,38387,38403-38404,38407,38968,38970,38973,39045,40845,42997-42998,43439
/branches/vgroup_modifiers:38694-39989
/trunk/blender:36831-48245
Modified: branches/soc-2011-tomato/intern/raskter/raskter.c
===================================================================
--- branches/soc-2011-tomato/intern/raskter/raskter.c 2012-06-24 18:00:14 UTC (rev 48245)
+++ branches/soc-2011-tomato/intern/raskter/raskter.c 2012-06-24 18:01:46 UTC (rev 48246)
@@ -31,6 +31,8 @@
#include <stdlib.h>
#include "raskter.h"
+#define __PLX__FAKE_AA__
+
/* from BLI_utildefines.h */
#define MIN2(x, y) ( (x) < (y) ? (x) : (y) )
#define MAX2(x, y) ( (x) > (y) ? (x) : (y) )
@@ -759,12 +761,14 @@
return i; /* Return the value returned by the rasterizer. */
}
-int get_range_expanded_pixel_coord(float normalized_value, int max_value)
+#ifndef __PLX__FAKE_AA__
+
+static int get_range_expanded_pixel_coord(float normalized_value, int max_value)
{
return (int)((normalized_value * (float)(max_value)) + 0.5f);
}
-float get_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y)
+static float get_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y)
{
if(pos_x < 0 || pos_x >= buf_x || pos_y < 0 || pos_y >= buf_y) {
return 0.0f;
@@ -772,7 +776,7 @@
return buf[(pos_y * buf_y) + buf_x];
}
-float get_pixel_intensity_bilinear(float *buf, int buf_x, int buf_y, float u, float v)
+static float get_pixel_intensity_bilinear(float *buf, int buf_x, int buf_y, float u, float v)
{
int a;
int b;
@@ -799,14 +803,15 @@
}
-void set_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y, float intensity)
+static void set_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y, float intensity)
{
if(pos_x < 0 || pos_x >= buf_x || pos_y < 0 || pos_y >= buf_y) {
return;
}
buf[(pos_y * buf_y) + buf_x] = intensity;
}
-#define __PLX__FAKE_AA__
+#endif
+
int PLX_antialias_buffer(float *buf, int buf_x, int buf_y)
{
#ifdef __PLX__FAKE_AA__
Modified: branches/soc-2011-tomato/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/BLI_math_vector.h 2012-06-24 18:00:14 UTC (rev 48245)
+++ branches/soc-2011-tomato/source/blender/blenlib/BLI_math_vector.h 2012-06-24 18:01:46 UTC (rev 48246)
@@ -191,6 +191,7 @@
float angle_normalized_v2v2(const float a[2], const float b[2]);
float angle_v3v3(const float a[3], const float b[3]);
float angle_v3v3v3(const float a[3], const float b[3], const float c[3]);
+float cos_v3v3v3(const float p1[3], const float p2[3], const float p3[3]);
float angle_normalized_v3v3(const float v1[3], const float v2[3]);
float angle_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]);
void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]);
Modified: branches/soc-2011-tomato/source/blender/blenlib/intern/math_vector.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/intern/math_vector.c 2012-06-24 18:00:14 UTC (rev 48245)
+++ branches/soc-2011-tomato/source/blender/blenlib/intern/math_vector.c 2012-06-24 18:01:46 UTC (rev 48246)
@@ -136,6 +136,19 @@
return angle_normalized_v3v3(vec1, vec2);
}
+/* Quicker than full angle computation */
+float cos_v3v3v3(const float p1[3], const float p2[3], const float p3[3])
+{
+ float vec1[3], vec2[3];
+
+ sub_v3_v3v3(vec1, p2, p1);
+ sub_v3_v3v3(vec2, p2, p3);
+ normalize_v3(vec1);
+ normalize_v3(vec2);
+
+ return dot_v3v3(vec1, vec2);
+}
+
/* Return the shortest angle in radians between the 2 vectors */
float angle_v3v3(const float v1[3], const float v2[3])
{
Modified: branches/soc-2011-tomato/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- branches/soc-2011-tomato/source/blender/bmesh/intern/bmesh_polygon.c 2012-06-24 18:00:14 UTC (rev 48245)
+++ branches/soc-2011-tomato/source/blender/bmesh/intern/bmesh_polygon.c 2012-06-24 18:01:46 UTC (rev 48246)
@@ -642,7 +642,7 @@
//if (linecrossesf(pv1, pv2, v1, v3)) return FALSE;
if (isect_point_tri_v2(pv1, v1, v2, v3) ||
- isect_point_tri_v2(pv1, v3, v2, v1))
+ isect_point_tri_v2(pv2, v3, v2, v1))
{
return FALSE;
}
@@ -658,18 +658,22 @@
* of a polygon while tessellating.
*
* \param use_beauty Currently only applies to quads, can be extended later on.
+ * \param abscoss Must be allocated by caller, and at least f->len length
+ * (allow to avoid allocating a new one for each tri!).
*/
-static BMLoop *find_ear(BMFace *f, float (*verts)[3], const int nvert, const int use_beauty)
+static BMLoop *find_ear(BMFace *f, float (*verts)[3], const int nvert, const int use_beauty, float *abscoss)
{
BMLoop *bestear = NULL;
BMLoop *l_iter;
BMLoop *l_first;
+ const float cos_threshold = 0.9f;
+
if (f->len == 4) {
BMLoop *larr[4];
- int i = 0;
-
+ int i = 0, i4;
+ float cos1, cos2;
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
do {
larr[i] = l_iter;
@@ -677,24 +681,68 @@
} while ((l_iter = l_iter->next) != l_first);
/* pick 0/1 based on best lenth */
- bestear = larr[(((len_squared_v3v3(larr[0]->v->co, larr[2]->v->co) >
- len_squared_v3v3(larr[1]->v->co, larr[3]->v->co))) != use_beauty)];
+ /* XXX Can't only rely on such test, also must check we do not get (too much) degenerated triangles!!! */
+ i = (((len_squared_v3v3(larr[0]->v->co, larr[2]->v->co) >
+ len_squared_v3v3(larr[1]->v->co, larr[3]->v->co))) != use_beauty);
+ i4 = (i + 3) % 4;
+ /* Check produced tris aren’t too flat/narrow...
+ * Probably not the best test, but is quite efficient and should at least avoid null-area faces! */
+ cos1 = fabsf(cos_v3v3v3(larr[i4]->v->co, larr[i]->v->co, larr[i + 1]->v->co));
+ cos2 = fabsf(cos_v3v3v3(larr[i4]->v->co, larr[i + 2]->v->co, larr[i + 1]->v->co));
+#if 0
+ printf("%d, (%f, %f), (%f, %f)\n", i, cos1, cos2,
+ fabsf(cos_v3v3v3(larr[i]->v->co, larr[i4]->v->co, larr[i + 2]->v->co)),
+ fabsf(cos_v3v3v3(larr[i]->v->co, larr[i + 1]->v->co, larr[i + 2]->v->co)));
+#endif
+ if (cos1 < cos2)
+ cos1 = cos2;
+ if (cos1 > cos_threshold) {
+ if (cos1 > fabsf(cos_v3v3v3(larr[i]->v->co, larr[i4]->v->co, larr[i + 2]->v->co)) &&
+ cos1 > fabsf(cos_v3v3v3(larr[i]->v->co, larr[i + 1]->v->co, larr[i + 2]->v->co)))
+ i = !i;
+ }
+ /* Last check we do not get overlapping triangles
+ * (as much as possible, ther are some cases with no good solution!) */
+ i4 = (i + 3) % 4;
+ if (!bm_face_goodline((float const (*)[3])verts, f, BM_elem_index_get(larr[i4]->v), BM_elem_index_get(larr[i]->v),
+ BM_elem_index_get(larr[i + 1]->v), nvert))
+ i = !i;
+/* printf("%d\n", i);*/
+ bestear = larr[i];
}
else {
BMVert *v1, *v2, *v3;
/* float angle, bestangle = 180.0f; */
- int isear /*, i = 0 */;
+ float cos, tcos, bestcos = 1.0f;
+ float *tcoss;
+ int isear, i = 0, j, len;
+ /* Compute cos of all corners! */
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
+ len = l_iter->f->len;
+ tcoss = abscoss;
do {
+ v1 = l_iter->prev->v;
+ v2 = l_iter->v;
+ v3 = l_iter->next->v;
+
+ *tcoss = fabsf(cos_v3v3v3(v1->co, v2->co, v3->co));
+/* printf("tcoss: %f\n", *tcoss);*/
+ tcoss++;
+ } while ((l_iter = l_iter->next) != l_first);
+
+ l_iter = l_first;
+ tcoss = abscoss;
+ do {
isear = TRUE;
v1 = l_iter->prev->v;
v2 = l_iter->v;
v3 = l_iter->next->v;
+ /* We may have already internal edges... */
if (BM_edge_exists(v1, v3)) {
isear = FALSE;
}
@@ -706,7 +754,7 @@
}
if (isear) {
- #if 0
+#if 0 /* Old, already commented code */
/* if this code comes back, it needs to be converted to radians */
angle = angle_v3v3v3(verts[v1->head.eflag2], verts[v2->head.eflag2], verts[v3->head.eflag2]);
if (!bestear || ABS(angle - 45.0f) < bestangle) {
@@ -717,11 +765,46 @@
if (angle > 20 && angle < 90) break;
if (angle < 100 && i > 5) break;
i += 1;
- #endif
+#endif
- bestear = l_iter;
- break;
+ /* Compute highest cos (i.e. narrowest angle) of this tri. */
+ cos = *tcoss;
+ tcos = fabsf(cos_v3v3v3(v2->co, v3->co, v1->co));
+ if (tcos > cos)
+ cos = tcos;
+ tcos = fabsf(cos_v3v3v3(v3->co, v1->co, v2->co));
+ if (tcos > cos)
+ cos = tcos;
+
+ /* Compare to prev best (i.e. lowest) cos. */
+ if (cos < bestcos) {
+ /* We must check this tri would not leave a (too much) degenerated remaining face! */
+ /* For now just assume if the average of cos of all "remaining face"'s corners is below a given threshold, it’s OK. */
+ float avgcos = fabsf(cos_v3v3v3(v1->co, v3->co, l_iter->next->next->v->co));
+ const int i_limit = (i - 1 + len) % len;
+ avgcos += fabsf(cos_v3v3v3(l_iter->prev->prev->v->co, v1->co, v3->co));
+ j = (i + 2) % len;
+ do {
+ avgcos += abscoss[j];
+ } while ((j = (j + 1) % len) != i_limit);
+ avgcos /= len - 1;
+
+ /* We need a best ear in any case... */
+ if (avgcos < cos_threshold || (!bestear && avgcos < 1.0f)) {
+ /* OKI, keep this ear (corner...) as a potential best one! */
+ bestear = l_iter;
+ bestcos = cos;
+ }
+#if 0
+ else
+ printf("Had a nice tri (higest cos of %f, current bestcos is %f), "
+ "but average cos of all \"remaining face\"'s corners is too high (%f)!\n",
+ cos, bestcos, avgcos);
+#endif
+ }
}
+ tcoss++;
+ i++;
} while ((l_iter = l_iter->next) != l_first);
}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list