improve finding point inside holes
This commit is contained in:
parent
def840b482
commit
2e7a827117
@ -75,20 +75,29 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
{
|
{
|
||||||
int k = point * 2;
|
int k = point * 2;
|
||||||
|
|
||||||
float cx = in.pointlist[k+0];
|
float nx = in.pointlist[k++];
|
||||||
float cy = in.pointlist[k+1];
|
float ny = in.pointlist[k++];
|
||||||
|
|
||||||
float nx = in.pointlist[k+2];
|
float cx, cy, vx, vy;
|
||||||
float ny = in.pointlist[k+3];
|
|
||||||
|
|
||||||
float vx = nx - cx;
|
// try to find a large enough segment
|
||||||
float vy = ny - cy;
|
for (len = (point + num_points) * 2; k < len;)
|
||||||
|
{
|
||||||
|
cx = nx;
|
||||||
|
cy = ny;
|
||||||
|
|
||||||
|
nx = in.pointlist[k++];
|
||||||
|
ny = in.pointlist[k++];
|
||||||
|
|
||||||
|
vx = nx - cx;
|
||||||
|
vy = ny - cy;
|
||||||
|
|
||||||
|
if (vx > 4 || vx < -4 || vy > 4 || vy < -4)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
float a = sqrt(vx*vx + vy*vy);
|
float a = sqrt(vx*vx + vy*vy);
|
||||||
|
|
||||||
// fixme: need to check a == 0?
|
|
||||||
//if (a > 0.00001 || a < -0.0001)
|
|
||||||
|
|
||||||
float ux = -vy / a;
|
float ux = -vy / a;
|
||||||
float uy = vx / a;
|
float uy = vx / a;
|
||||||
|
|
||||||
@ -108,7 +117,7 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
*seg++ = point + (num_points - 1);
|
*seg++ = point + (num_points - 1);
|
||||||
*seg++ = point;
|
*seg++ = point;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
for (len = point + num_points - 1; point < len; point++)
|
for (len = point + num_points - 1; point < len; point++)
|
||||||
{
|
{
|
||||||
*seg++ = point;
|
*seg++ = point;
|
||||||
@ -136,11 +145,6 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
|
|
||||||
triangulate("pzPNBQ", &in, &out, (TriangleIO *) NULL);
|
triangulate("pzPNBQ", &in, &out, (TriangleIO *) NULL);
|
||||||
|
|
||||||
//if (offset || stride)
|
|
||||||
//{
|
|
||||||
// if (stride <= 0)
|
|
||||||
// stride = 1;
|
|
||||||
|
|
||||||
#ifdef TESTING
|
#ifdef TESTING
|
||||||
snprintf(buf, 128, "triangles: %d\n", out.numberoftriangles);
|
snprintf(buf, 128, "triangles: %d\n", out.numberoftriangles);
|
||||||
mylog(buf);
|
mylog(buf);
|
||||||
@ -169,8 +173,6 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
while (n-- > 0)
|
while (n-- > 0)
|
||||||
*tri++ = *tri * stride + offset;
|
*tri++ = *tri * stride + offset;
|
||||||
|
|
||||||
// correct offsetting is tricky (but this is probably not a
|
|
||||||
// general case):
|
|
||||||
// when a ring has an odd number of points one (or rather two)
|
// when a ring has an odd number of points one (or rather two)
|
||||||
// additional vertices will be added. so the following rings
|
// additional vertices will be added. so the following rings
|
||||||
// needs extra offset...
|
// needs extra offset...
|
||||||
@ -180,7 +182,8 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
for (j = 0, m = in.numberofholes; j < m; j++)
|
for (j = 0, m = in.numberofholes; j < m; j++)
|
||||||
{
|
{
|
||||||
start += rings[j] * stride;
|
start += rings[j] * stride;
|
||||||
if (rings[j] % 2 == 0)
|
// even number of points?
|
||||||
|
if (!(rings[j] & 1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tri = out.trianglelist;
|
tri = out.trianglelist;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user