summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorperepelits.m <perepelits.m@samsung.com>2016-01-04 14:50:42 -0800
committerCedric BAIL <cedric@osg.samsung.com>2016-01-04 14:50:45 -0800
commite6ccfcedd80d4ede8d3482947b8e81500b356e62 (patch)
tree9e8b02ab44486ab62c264605f82c63a8dda12ed8
parent728eff8836163a7c24c10ad8e1ce6e21eca13b01 (diff)
evas: fix convex hull.
Summary: There were some problems with second and third vertices in the first triangle of convex hull. It is very hard to see this errors because it could cause an excess of triangles inside of convex hull, I have used blender to find them. Reviewers: raster, Hermet, cedric Reviewed By: cedric Subscribers: jpeg, artem.popov Differential Revision: https://phab.enlightenment.org/D3491 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/lib/evas/include/evas_3d_utils.h85
1 files changed, 32 insertions, 53 deletions
diff --git a/src/lib/evas/include/evas_3d_utils.h b/src/lib/evas/include/evas_3d_utils.h
index 319c599209..96b8c74af7 100644
--- a/src/lib/evas/include/evas_3d_utils.h
+++ b/src/lib/evas/include/evas_3d_utils.h
@@ -1366,11 +1366,11 @@ convex_hull_first_tr_get(float *data, int count, int stride)
1366 Evas_Vec3 triangle1; 1366 Evas_Vec3 triangle1;
1367 Evas_Vec3 triangle2, triangle2_candidate; 1367 Evas_Vec3 triangle2, triangle2_candidate;
1368 Evas_Vec3 triangle3, triangle3_candidate; 1368 Evas_Vec3 triangle3, triangle3_candidate;
1369 Evas_Vec3 first, second, complanar1, complanar2, candidate; 1369 Evas_Vec3 first, diagonal, complanar1, complanar2, candidate;
1370 Eina_Quaternion normal_a, normal_b; 1370 Eina_Quaternion normal_a, normal_b;
1371 1371
1372 Evas_Real cos = 0.0, new_cos = 0.0, tan = 0.0, new_tan = 0.0, cos_2d = 0.0, new_cos_2d = 0.0; 1372 Evas_Real cos = 0.0, new_cos = 0.0, sin = 0.0, new_sin = 0.0, cos_2d = 0.0, new_cos_2d = 0.0;
1373 int first_num = 0, second_num = 0; 1373 int first_num = 0;
1374 int i = 0, j = 0; 1374 int i = 0, j = 0;
1375 1375
1376 evas_vec3_set(&triangle1, data[0], data[1], data[2]); 1376 evas_vec3_set(&triangle1, data[0], data[1], data[2]);
@@ -1389,12 +1389,10 @@ convex_hull_first_tr_get(float *data, int count, int stride)
1389 if (first_num) 1389 if (first_num)
1390 evas_vec3_set(&triangle2, data[0], data[1], data[2]); 1390 evas_vec3_set(&triangle2, data[0], data[1], data[2]);
1391 else 1391 else
1392 { 1392 evas_vec3_set(&triangle2, data[3], data[4], data[5]);
1393 evas_vec3_set(&triangle2, data[3], data[4], data[5]);
1394 second_num = 1;
1395 }
1396 1393
1397 tan = fabs(triangle2.z - triangle1.z) / fabs(triangle2.y - triangle1.y); 1394 evas_vec3_subtract(&diagonal, &triangle2, &triangle1);
1395 sin = fabs(triangle2.z - triangle1.z) / evas_vec3_length_get(&diagonal);
1398 1396
1399#define COMPARE_ANGLES(trigonom, triangle, previous, big, little) \ 1397#define COMPARE_ANGLES(trigonom, triangle, previous, big, little) \
1400 if (little > big + FLT_EPSILON) \ 1398 if (little > big + FLT_EPSILON) \
@@ -1416,48 +1414,23 @@ convex_hull_first_tr_get(float *data, int count, int stride)
1416 FLT_COMPARISON(data[j + 1], triangle1.y) || 1414 FLT_COMPARISON(data[j + 1], triangle1.y) ||
1417 FLT_COMPARISON(data[j + 2], triangle1.z)) 1415 FLT_COMPARISON(data[j + 2], triangle1.z))
1418 { 1416 {
1419 new_tan = fabs(data[j + 2] - triangle1.z) / fabs(data[j + 1] - triangle1.y); 1417 evas_vec3_set(&triangle2_candidate, data[j], data[j + 1], data[j + 2]);
1418 evas_vec3_subtract(&diagonal, &triangle2_candidate, &triangle1);
1419 new_sin = fabs(data[j + 2] - triangle1.z) / evas_vec3_length_get(&diagonal);
1420 1420
1421 if (FLT_COMPARISON(data[j + 1], triangle1.y) && 1421 if (sin > new_sin + FLT_EPSILON)
1422 FLT_COMPARISON(triangle2.y, triangle1.y))
1423 { 1422 {
1424 if (tan > new_tan + FLT_EPSILON) 1423 sin = new_sin;
1425 { 1424 evas_vec3_set(&triangle2, data[j], data[j + 1], data[j + 2]);
1426 tan = new_tan; 1425 evas_vec3_subtract(&diagonal, &triangle2, &triangle1);
1427 evas_vec3_set(&triangle2, data[j], data[j + 1], data[j + 2]); 1426 cos_2d = evas_vec3_angle_get(&complanar1, &diagonal);
1428 second_num = i;
1429 evas_vec3_subtract(&first, &complanar1, &triangle1);
1430 evas_vec3_subtract(&second, &triangle2, &triangle1);
1431 cos_2d = evas_vec3_angle_get(&complanar1, &second);
1432 }
1433 else if (!FLT_COMPARISON(tan, new_tan))
1434 {
1435 evas_vec3_subtract(&first, &complanar1, &triangle2);
1436 evas_vec3_set(&triangle2_candidate, data[j], data[j + 1], data[j + 2]);
1437 evas_vec3_subtract(&first, &complanar1, &triangle1);
1438 evas_vec3_subtract(&second, &triangle2_candidate, &triangle1);
1439 new_cos_2d = evas_vec3_angle_get(&complanar1, &second);
1440 if (new_cos_2d > cos_2d + FLT_EPSILON)
1441 second_num = i;
1442
1443 COMPARE_ANGLES(cos, triangle2, triangle1, cos_2d, new_cos_2d)
1444 }
1445 } 1427 }
1446 1428 else if (!FLT_COMPARISON(sin, new_sin))
1447 else if (!FLT_COMPARISON(data[j + 1], triangle1.y) &&
1448 !FLT_COMPARISON(data[j + 2], triangle1.z) &&
1449 FLT_COMPARISON(triangle2.y, triangle1.y))
1450 evas_vec3_set(&triangle2, data[j], data[j + 1], data[j + 2]);
1451
1452 else if (!FLT_COMPARISON(data[j + 1], triangle1.y) &&
1453 !FLT_COMPARISON(data[j + 2], triangle1.z) &&
1454 !FLT_COMPARISON(triangle2.z, triangle1.z) &&
1455 !FLT_COMPARISON(triangle2.y, triangle1.y))
1456 { 1429 {
1457 evas_vec3_set(&triangle2_candidate, data[j], data[j + 1], data[j + 2]); 1430 evas_vec3_subtract(&diagonal, &triangle2_candidate, &triangle1);
1458 if (evas_vec3_distance_get(&triangle2_candidate, &triangle1) > 1431 new_cos_2d = evas_vec3_angle_get(&complanar1, &diagonal);
1459 evas_vec3_distance_get(&triangle2, &triangle1)) 1432
1460 evas_vec3_set(&triangle2, data[j], data[j + 1], data[j + 2]); 1433 COMPARE_ANGLES(cos, triangle2, triangle1, cos_2d, new_cos_2d)
1461 } 1434 }
1462 } 1435 }
1463 } 1436 }
@@ -1476,9 +1449,15 @@ convex_hull_first_tr_get(float *data, int count, int stride)
1476 1449
1477 for (i = 0, j = 0; i < count; i++, j += stride) 1450 for (i = 0, j = 0; i < count; i++, j += stride)
1478 { 1451 {
1479 if ((i != first_num) && (i != second_num)) 1452 evas_vec3_set(&candidate, data[j], data[j + 1], data[j + 2]);
1453
1454 if ((FLT_COMPARISON(data[j], triangle1.x) ||
1455 FLT_COMPARISON(data[j + 1], triangle1.y) ||
1456 FLT_COMPARISON(data[j + 2], triangle1.z)) &&
1457 (FLT_COMPARISON(data[j], triangle2.x) ||
1458 FLT_COMPARISON(data[j + 1], triangle2.y) ||
1459 FLT_COMPARISON(data[j + 2], triangle2.z)))
1480 { 1460 {
1481 evas_vec3_set(&candidate, data[j], data[j + 1], data[j + 2]);
1482 evas_vec3_plain_by_points(&normal_b, &triangle1, &candidate, &triangle2); 1461 evas_vec3_plain_by_points(&normal_b, &triangle1, &candidate, &triangle2);
1483 1462
1484 if (normal_b.z < 0) 1463 if (normal_b.z < 0)
@@ -1490,19 +1469,19 @@ convex_hull_first_tr_get(float *data, int count, int stride)
1490 { 1469 {
1491 evas_vec3_set(&triangle3_candidate, data[j], data[j + 1], data[j + 2]); 1470 evas_vec3_set(&triangle3_candidate, data[j], data[j + 1], data[j + 2]);
1492 evas_vec3_subtract(&first, &triangle2, &triangle1); 1471 evas_vec3_subtract(&first, &triangle2, &triangle1);
1493 evas_vec3_subtract(&second, &triangle3, &triangle1); 1472 evas_vec3_subtract(&diagonal, &triangle3, &triangle1);
1494 cos = new_cos; 1473 cos = new_cos;
1495 evas_vec3_set(&triangle3, data[j], data[j + 1], data[j + 2]); 1474 evas_vec3_set(&triangle3, data[j], data[j + 1], data[j + 2]);
1496 cos_2d = evas_vec3_angle_get(&second, &first); 1475 cos_2d = evas_vec3_angle_get(&diagonal, &first);
1497 } 1476 }
1498 else if (!FLT_COMPARISON(new_cos, cos)) 1477 else if (!FLT_COMPARISON(new_cos, cos))
1499 { 1478 {
1500 evas_vec3_set(&triangle3_candidate, data[j], data[j + 1], data[j + 2]); 1479 evas_vec3_set(&triangle3_candidate, data[j], data[j + 1], data[j + 2]);
1501 evas_vec3_subtract(&first, &triangle1, &triangle2); 1480 evas_vec3_subtract(&first, &triangle1, &triangle2);
1502 evas_vec3_subtract(&second, &triangle3_candidate, &triangle2); 1481 evas_vec3_subtract(&diagonal, &triangle3_candidate, &triangle2);
1503 new_cos_2d = evas_vec3_angle_get(&first, &second); 1482 new_cos_2d = evas_vec3_angle_get(&first, &diagonal);
1504 1483
1505 COMPARE_ANGLES(tan, triangle3, triangle2, new_cos_2d, cos_2d) 1484 COMPARE_ANGLES(cos, triangle3, triangle2, new_cos_2d, cos_2d)
1506 } 1485 }
1507 } 1486 }
1508 } 1487 }