cleanup: remove files
This commit is contained in:
parent
175f6d84d1
commit
5e4095dddb
@ -1,487 +0,0 @@
|
|||||||
#include <jni.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <alloca.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
//#ifndef uintptr_t
|
|
||||||
//typedef unsigned long uintptr_t;
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
#ifndef M_PI
|
|
||||||
#define M_PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
#include <GLES2/gl2.h>
|
|
||||||
#include <GLES2/gl2ext.h>
|
|
||||||
#include <android/log.h>
|
|
||||||
|
|
||||||
#define JNI(X) JNIEXPORT Java_org_oscim_utils_GlUtils_##X
|
|
||||||
|
|
||||||
|
|
||||||
#define COLOR_R(C) (((C >> 16) & 0xff) / 255.0f)
|
|
||||||
#define COLOR_G(C) (((C >> 8) & 0xff) / 255.0f)
|
|
||||||
#define COLOR_B(C) (((C >> 0) & 0xff) / 255.0f)
|
|
||||||
#define COLOR_A(C) (((C >> 24) & 0xff) / 255.0f)
|
|
||||||
|
|
||||||
void JNI(setColor)(JNIEnv *env, jclass* clazz, jint location, jint c, jfloat alpha)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (alpha >= 1)
|
|
||||||
alpha = COLOR_A(c);
|
|
||||||
else if (alpha < 0)
|
|
||||||
alpha = 0;
|
|
||||||
else
|
|
||||||
alpha *= COLOR_A(c);
|
|
||||||
|
|
||||||
if (alpha == 1)
|
|
||||||
{
|
|
||||||
glUniform4f((GLint) location,
|
|
||||||
(GLfloat) COLOR_R(c),
|
|
||||||
(GLfloat) COLOR_G(c),
|
|
||||||
(GLfloat) COLOR_B(c),
|
|
||||||
(GLfloat) alpha);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
glUniform4f((GLint) location,
|
|
||||||
(GLfloat) (COLOR_R(c) * alpha),
|
|
||||||
(GLfloat) (COLOR_G(c) * alpha),
|
|
||||||
(GLfloat) (COLOR_B(c) * alpha),
|
|
||||||
(GLfloat) alpha);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(setColorBlend)(JNIEnv *env, jclass* clazz, jint location, jint c1, jint c2, jfloat mix)
|
|
||||||
{
|
|
||||||
float a1 = COLOR_A(c1) * (1 - mix);
|
|
||||||
float a2 = COLOR_A(c2) * mix;
|
|
||||||
|
|
||||||
glUniform4f((GLint) location,
|
|
||||||
(GLfloat) (COLOR_R(c1) * a1 + COLOR_R(c2) * a2),
|
|
||||||
(GLfloat) (COLOR_G(c1) * a1 + COLOR_G(c2) * a2),
|
|
||||||
(GLfloat) (COLOR_B(c1) * a1 + COLOR_B(c2) * a2),
|
|
||||||
(GLfloat) (a1 + a2));
|
|
||||||
}
|
|
||||||
#endif // __ANDROID__
|
|
||||||
#endif // 0
|
|
||||||
|
|
||||||
#undef JNI
|
|
||||||
#define JNI(X) JNIEXPORT Java_org_oscim_utils_Matrix4_##X
|
|
||||||
|
|
||||||
#define CAST(x) (float *)(uintptr_t) x
|
|
||||||
#define MAT_SIZE 16 * sizeof(float)
|
|
||||||
|
|
||||||
static const float identity[] =
|
|
||||||
{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
multiplyMM(float* r, const float* lhs, const float* rhs);
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
setRotateM(float* rm, int rmOffset, float a, float x, float y, float z);
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
transposeM(float* mTrans, int mTransOffset, float* m, int mOffset);
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
matrix4_proj(float* mat, float* vec);
|
|
||||||
|
|
||||||
jlong JNI(alloc)(JNIEnv *env, jclass* clazz)
|
|
||||||
{
|
|
||||||
return (long) calloc(16, sizeof(float));
|
|
||||||
}
|
|
||||||
|
|
||||||
jobject JNI(getBuffer)(JNIEnv *env, jclass* clazz,jlong ptr){
|
|
||||||
return (*env)->NewDirectByteBuffer(env,(char*)(uintptr_t)ptr, 16*sizeof(float));
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(delete)(JNIEnv* env, jclass* clazz, jlong ptr)
|
|
||||||
{
|
|
||||||
free(CAST(ptr));
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
void JNI(setAsUniform)(JNIEnv* env, jclass* clazz, jlong ptr, jint location)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
|
|
||||||
glUniformMatrix4fv((GLint) location, (GLsizei) 1, (GLboolean) 0, (GLfloat *) m);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void JNI(setValueAt)(JNIEnv* env, jclass* clazz, jlong ptr, jint pos, jfloat value)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
if (pos > -1 && pos < 16)
|
|
||||||
m[pos] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(identity)(JNIEnv* env, jclass* clazz, jlong ptr)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
memcpy(m, identity, MAT_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(setScale)(JNIEnv* env, jclass* clazz, jlong ptr, jfloat sx, jfloat sy, jfloat sz)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
memcpy(m, identity, MAT_SIZE);
|
|
||||||
m[0] = sx;
|
|
||||||
m[5] = sy;
|
|
||||||
m[10] = sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(setTranslation)(JNIEnv* env, jclass* clazz, jlong ptr, jfloat x, jfloat y, jfloat z)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
memcpy(m, identity, MAT_SIZE);
|
|
||||||
m[12] = x;
|
|
||||||
m[13] = y;
|
|
||||||
m[14] = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(setRotation)(JNIEnv* env, jclass* clazz, jlong ptr, jfloat a, jfloat x, jfloat y, jfloat z)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
setRotateM(m, 0, a, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(setTransScale)(JNIEnv* env, jclass* clazz, jlong ptr, jfloat tx, jfloat ty, jfloat scale)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
memcpy(m, identity, MAT_SIZE);
|
|
||||||
m[0] = scale;
|
|
||||||
m[5] = scale;
|
|
||||||
m[12] = tx;
|
|
||||||
m[13] = ty;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set matrix from float array
|
|
||||||
void JNI(set)(JNIEnv* env, jclass* clazz, jlong ptr, jfloatArray obj_mat)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
float* mat = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_mat, 0);
|
|
||||||
|
|
||||||
memcpy(m, mat, MAT_SIZE);
|
|
||||||
|
|
||||||
(*env)->ReleasePrimitiveArrayCritical(env, obj_mat, mat, JNI_ABORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get float array from matrix
|
|
||||||
void JNI(get)(JNIEnv* env, jclass* clazz, jlong ptr, jfloatArray obj_mat)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
float* mat = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_mat, 0);
|
|
||||||
|
|
||||||
memcpy(mat, m, MAT_SIZE);
|
|
||||||
|
|
||||||
(*env)->ReleasePrimitiveArrayCritical(env, obj_mat, mat, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(mul)(JNIEnv* env, jclass* clazz, jlong ptr_a, jlong ptr_b)
|
|
||||||
{
|
|
||||||
float* mata = CAST(ptr_a);
|
|
||||||
float* matb = CAST(ptr_b);
|
|
||||||
|
|
||||||
multiplyMM(mata, mata, matb);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(copy)(JNIEnv* env, jclass* clazz, jlong ptr_dst, jlong ptr_src)
|
|
||||||
{
|
|
||||||
float* dst = CAST(ptr_dst);
|
|
||||||
float* src = CAST(ptr_src);
|
|
||||||
|
|
||||||
memcpy(dst, src, MAT_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(smul)(JNIEnv* env, jclass* clazz, jlong ptr_r, jlong ptr_a, jlong ptr_b)
|
|
||||||
{
|
|
||||||
float* matr = CAST(ptr_r);
|
|
||||||
float* mata = CAST(ptr_a);
|
|
||||||
float* matb = CAST(ptr_b);
|
|
||||||
|
|
||||||
multiplyMM(matr, mata, matb);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(smulrhs)(JNIEnv* env, jclass* clazz, jlong ptr_r, jlong ptr_rhs)
|
|
||||||
{
|
|
||||||
float* matr = CAST(ptr_r);
|
|
||||||
float* mata = alloca(16 * sizeof(float));
|
|
||||||
float* matb = CAST(ptr_rhs);
|
|
||||||
|
|
||||||
memcpy(mata, matr, 16 * sizeof(float));
|
|
||||||
|
|
||||||
multiplyMM(matr, mata, matb);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(smullhs)(JNIEnv* env, jclass* clazz, jlong ptr_r, jlong ptr_lhs)
|
|
||||||
{
|
|
||||||
float* matr = CAST(ptr_r);
|
|
||||||
float* mata = CAST(ptr_lhs);
|
|
||||||
float* matb = alloca(16 * sizeof(float));
|
|
||||||
|
|
||||||
memcpy(matb, matr, 16 * sizeof(float));
|
|
||||||
|
|
||||||
multiplyMM(matr, mata, matb);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void JNI(strans)(JNIEnv* env, jclass* clazz, jlong ptr_r, jlong ptr_a)
|
|
||||||
{
|
|
||||||
float* matr = CAST(ptr_r);
|
|
||||||
float* mata = CAST(ptr_a);
|
|
||||||
|
|
||||||
transposeM(matr, 0, mata, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JNI(prj)(JNIEnv* env, jclass* clazz, jlong ptr, jfloatArray obj_vec)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
float* vec = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_vec, 0);
|
|
||||||
|
|
||||||
matrix4_proj(m, vec);
|
|
||||||
|
|
||||||
(*env)->ReleasePrimitiveArrayCritical(env, obj_vec, vec, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static float someRandomEpsilon = 1.0f / (1 << 11);
|
|
||||||
|
|
||||||
void JNI(addDepthOffset)(JNIEnv* env, jclass* clazz, jlong ptr, jint delta)
|
|
||||||
{
|
|
||||||
float* m = CAST(ptr);
|
|
||||||
|
|
||||||
// from http://www.mathfor3dgameprogramming.com/code/Listing9.1.cpp
|
|
||||||
// float n = MapViewPosition.VIEW_NEAR;
|
|
||||||
// float f = MapViewPosition.VIEW_FAR;
|
|
||||||
// float pz = 1;
|
|
||||||
// float epsilon = -2.0f * f * n * delta / ((f + n) * pz * (pz + delta));
|
|
||||||
|
|
||||||
m[10] *= 1.0f + someRandomEpsilon * delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2007, The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// from android/platform_frameworks_base/blob/master/core/jni/android/opengl/util.cpp
|
|
||||||
#define I(_i, _j) ((_j)+ 4*(_i))
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
multiplyMM(float* r, const float* lhs, const float* rhs)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
register const float rhs_i0 = rhs[I(i,0)];
|
|
||||||
register float ri0 = lhs[I(0,0)] * rhs_i0;
|
|
||||||
register float ri1 = lhs[I(0,1)] * rhs_i0;
|
|
||||||
register float ri2 = lhs[I(0,2)] * rhs_i0;
|
|
||||||
register float ri3 = lhs[I(0,3)] * rhs_i0;
|
|
||||||
for (int j = 1; j < 4; j++)
|
|
||||||
{
|
|
||||||
register const float rhs_ij = rhs[I(i,j)];
|
|
||||||
ri0 += lhs[I(j,0)] * rhs_ij;
|
|
||||||
ri1 += lhs[I(j,1)] * rhs_ij;
|
|
||||||
ri2 += lhs[I(j,2)] * rhs_ij;
|
|
||||||
ri3 += lhs[I(j,3)] * rhs_ij;
|
|
||||||
}
|
|
||||||
r[I(i,0)] = ri0;
|
|
||||||
r[I(i,1)] = ri1;
|
|
||||||
r[I(i,2)] = ri2;
|
|
||||||
r[I(i,3)] = ri3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//static inline
|
|
||||||
//void
|
|
||||||
//mx4transform(float x, float y, float z, float w, const float* pM, float* pDest)
|
|
||||||
//{
|
|
||||||
// pDest[0] = pM[0 + 4 * 0] * x + pM[0 + 4 * 1] * y + pM[0 + 4 * 2] * z + pM[0 + 4 * 3] * w;
|
|
||||||
// pDest[1] = pM[1 + 4 * 0] * x + pM[1 + 4 * 1] * y + pM[1 + 4 * 2] * z + pM[1 + 4 * 3] * w;
|
|
||||||
// pDest[2] = pM[2 + 4 * 0] * x + pM[2 + 4 * 1] * y + pM[2 + 4 * 2] * z + pM[2 + 4 * 3] * w;
|
|
||||||
//
|
|
||||||
// pDest[3] = pM[3 + 4 * 0] * x + pM[3 + 4 * 1] * y + pM[3 + 4 * 2] * z + pM[3 + 4 * 3] * w;
|
|
||||||
//}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Computes the length of a vector
|
|
||||||
*
|
|
||||||
* @param x x coordinate of a vector
|
|
||||||
* @param y y coordinate of a vector
|
|
||||||
* @param z z coordinate of a vector
|
|
||||||
* @return the length of a vector
|
|
||||||
*/
|
|
||||||
static inline float
|
|
||||||
length(float x, float y, float z)
|
|
||||||
{
|
|
||||||
return (float) sqrt(x * x + y * y + z * z);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Rotates matrix m by angle a (in degrees) around the axis (x, y, z)
|
|
||||||
* @param rm returns the result
|
|
||||||
* @param rmOffset index into rm where the result matrix starts
|
|
||||||
* @param a angle to rotate in degrees
|
|
||||||
* @param x scale factor x
|
|
||||||
* @param y scale factor y
|
|
||||||
* @param z scale factor z
|
|
||||||
*/
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
setRotateM(float* rm, int rmOffset, float a, float x, float y, float z)
|
|
||||||
{
|
|
||||||
rm[rmOffset + 3] = 0;
|
|
||||||
rm[rmOffset + 7] = 0;
|
|
||||||
rm[rmOffset + 11] = 0;
|
|
||||||
rm[rmOffset + 12] = 0;
|
|
||||||
rm[rmOffset + 13] = 0;
|
|
||||||
rm[rmOffset + 14] = 0;
|
|
||||||
rm[rmOffset + 15] = 1;
|
|
||||||
a *= (float) (M_PI / 180.0f);
|
|
||||||
float s = (float) sin(a);
|
|
||||||
float c = (float) cos(a);
|
|
||||||
if (1.0f == x && 0.0f == y && 0.0f == z)
|
|
||||||
{
|
|
||||||
rm[rmOffset + 5] = c;
|
|
||||||
rm[rmOffset + 10] = c;
|
|
||||||
rm[rmOffset + 6] = s;
|
|
||||||
rm[rmOffset + 9] = -s;
|
|
||||||
rm[rmOffset + 1] = 0;
|
|
||||||
rm[rmOffset + 2] = 0;
|
|
||||||
rm[rmOffset + 4] = 0;
|
|
||||||
rm[rmOffset + 8] = 0;
|
|
||||||
rm[rmOffset + 0] = 1;
|
|
||||||
}
|
|
||||||
else if (0.0f == x && 1.0f == y && 0.0f == z)
|
|
||||||
{
|
|
||||||
rm[rmOffset + 0] = c;
|
|
||||||
rm[rmOffset + 10] = c;
|
|
||||||
rm[rmOffset + 8] = s;
|
|
||||||
rm[rmOffset + 2] = -s;
|
|
||||||
rm[rmOffset + 1] = 0;
|
|
||||||
rm[rmOffset + 4] = 0;
|
|
||||||
rm[rmOffset + 6] = 0;
|
|
||||||
rm[rmOffset + 9] = 0;
|
|
||||||
rm[rmOffset + 5] = 1;
|
|
||||||
}
|
|
||||||
else if (0.0f == x && 0.0f == y && 1.0f == z)
|
|
||||||
{
|
|
||||||
rm[rmOffset + 0] = c;
|
|
||||||
rm[rmOffset + 5] = c;
|
|
||||||
rm[rmOffset + 1] = s;
|
|
||||||
rm[rmOffset + 4] = -s;
|
|
||||||
rm[rmOffset + 2] = 0;
|
|
||||||
rm[rmOffset + 6] = 0;
|
|
||||||
rm[rmOffset + 8] = 0;
|
|
||||||
rm[rmOffset + 9] = 0;
|
|
||||||
rm[rmOffset + 10] = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
float len = length(x, y, z);
|
|
||||||
if (1.0f != len)
|
|
||||||
{
|
|
||||||
float recipLen = 1.0f / len;
|
|
||||||
x *= recipLen;
|
|
||||||
y *= recipLen;
|
|
||||||
z *= recipLen;
|
|
||||||
}
|
|
||||||
float nc = 1.0f - c;
|
|
||||||
float xy = x * y;
|
|
||||||
float yz = y * z;
|
|
||||||
float zx = z * x;
|
|
||||||
float xs = x * s;
|
|
||||||
float ys = y * s;
|
|
||||||
float zs = z * s;
|
|
||||||
rm[rmOffset + 0] = x * x * nc + c;
|
|
||||||
rm[rmOffset + 4] = xy * nc - zs;
|
|
||||||
rm[rmOffset + 8] = zx * nc + ys;
|
|
||||||
rm[rmOffset + 1] = xy * nc + zs;
|
|
||||||
rm[rmOffset + 5] = y * y * nc + c;
|
|
||||||
rm[rmOffset + 9] = yz * nc - xs;
|
|
||||||
rm[rmOffset + 2] = zx * nc - ys;
|
|
||||||
rm[rmOffset + 6] = yz * nc + xs;
|
|
||||||
rm[rmOffset + 10] = z * z * nc + c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transposes a 4 x 4 matrix.
|
|
||||||
*
|
|
||||||
* @param mTrans the array that holds the output inverted matrix
|
|
||||||
* @param mTransOffset an offset into mInv where the inverted matrix is
|
|
||||||
* stored.
|
|
||||||
* @param m the input array
|
|
||||||
* @param mOffset an offset into m where the matrix is stored.
|
|
||||||
*/
|
|
||||||
static inline void
|
|
||||||
transposeM(float* mTrans, int mTransOffset, float* m, int mOffset)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
int mBase = i * 4 + mOffset;
|
|
||||||
mTrans[i + mTransOffset] = m[mBase];
|
|
||||||
mTrans[i + 4 + mTransOffset] = m[mBase + 1];
|
|
||||||
mTrans[i + 8 + mTransOffset] = m[mBase + 2];
|
|
||||||
mTrans[i + 12 + mTransOffset] = m[mBase + 3];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright 2011 See libgdx AUTHORS file.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
******************************************************************************/
|
|
||||||
// from /gdx/src/com/badlogic/gdx/math/Matrix4.java
|
|
||||||
#define M00 0
|
|
||||||
#define M01 4
|
|
||||||
#define M02 8
|
|
||||||
#define M03 12
|
|
||||||
#define M10 1
|
|
||||||
#define M11 5
|
|
||||||
#define M12 9
|
|
||||||
#define M13 13
|
|
||||||
#define M20 2
|
|
||||||
#define M21 6
|
|
||||||
#define M22 10
|
|
||||||
#define M23 14
|
|
||||||
#define M30 3
|
|
||||||
#define M31 7
|
|
||||||
#define M32 11
|
|
||||||
#define M33 15
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
matrix4_proj(float* mat, float* vec)
|
|
||||||
{
|
|
||||||
float inv_w = 1.0f / (vec[0] * mat[M30] + vec[1] * mat[M31] + vec[2] * mat[M32] + mat[M33]);
|
|
||||||
float x = (vec[0] * mat[M00] + vec[1] * mat[M01] + vec[2] * mat[M02] + mat[M03]) * inv_w;
|
|
||||||
float y = (vec[0] * mat[M10] + vec[1] * mat[M11] + vec[2] * mat[M12] + mat[M13]) * inv_w;
|
|
||||||
float z = (vec[0] * mat[M20] + vec[1] * mat[M21] + vec[2] * mat[M22] + mat[M23]) * inv_w;
|
|
||||||
vec[0] = x;
|
|
||||||
vec[1] = y;
|
|
||||||
vec[2] = z;
|
|
||||||
}
|
|
||||||
@ -1,308 +0,0 @@
|
|||||||
#include <jni.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include "triangle.h"
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
#include <android/log.h>
|
|
||||||
#define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "Triangle", __VA_ARGS__)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// from www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
|
||||||
#if 0
|
|
||||||
int pnpoly(int nvert, float *vert, float testx, float testy)
|
|
||||||
{
|
|
||||||
int i, j, c = 0;
|
|
||||||
for (i = 0, j = (nvert-1)*2; i < nvert * 2; j = i++)
|
|
||||||
{
|
|
||||||
if ( ((vert[i*2+1] > testy) != (vert[j*j+1] > testy)) &&
|
|
||||||
(testx < (vert[j*2]-vert[i*2])
|
|
||||||
* (testy - vert[i*2+1])
|
|
||||||
/ (vert[j*2+1]-vert[i*2+1]) + vert[i*2]) )
|
|
||||||
c = !c;
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
int compare_dups(const void *a, const void *b) {
|
|
||||||
int da = *((const long*) a);
|
|
||||||
int db = *((const long*) b);
|
|
||||||
return (da > db) - (da < db);
|
|
||||||
}
|
|
||||||
|
|
||||||
void shiftSegment(TriangleIO *in, int *seg, int pos) {
|
|
||||||
int size = (in->numberofsegments - pos - 1) * sizeof(int) * 2;
|
|
||||||
printf("shift %d - %d %d\n", size, in->numberofsegments, pos);
|
|
||||||
if (size > 0)
|
|
||||||
memmove(seg, seg + 2, size);
|
|
||||||
|
|
||||||
in->numberofsegments -= 1;
|
|
||||||
}
|
|
||||||
struct {
|
|
||||||
int p1;
|
|
||||||
int p2;
|
|
||||||
} segment;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void printPoly(TriangleIO *in) {
|
|
||||||
// print poly format to check with triangle/showme
|
|
||||||
printf("%d 2 0 0\n", in->numberofpoints);
|
|
||||||
for (int j = 0; j < in->numberofpoints; j++)
|
|
||||||
printf("%d %f %f\n", j, in->pointlist[j*2], in->pointlist[j*2+1]);
|
|
||||||
|
|
||||||
int *seg = in->segmentlist;
|
|
||||||
printf("%d 0\n", in->numberofsegments);
|
|
||||||
for (int j = 0; j < in->numberofsegments; j++, seg += 2)
|
|
||||||
printf("%d %d %d\n", j, *seg, *(seg+1));
|
|
||||||
|
|
||||||
printf("%d 0\n", in->numberofholes);
|
|
||||||
for (int j = 0; j < in->numberofholes; j++) {
|
|
||||||
printf("%d %f %f\n", j, in->holelist[j*2], in->holelist[j*2+1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
jint Java_org_oscim_renderer_sublayers_ExtrusionLayer_triangulate(JNIEnv *env, jclass c,
|
|
||||||
jfloatArray obj_points, jint pos, jint len, jint num_rings, jobject indice_buf, jint offset) {
|
|
||||||
|
|
||||||
jshort* indices = (jshort*) (*env)->GetDirectBufferAddress(env, indice_buf);
|
|
||||||
jboolean isCopy;
|
|
||||||
|
|
||||||
float* orig_points = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_points, &isCopy);
|
|
||||||
if (orig_points == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
float *points = orig_points + pos;
|
|
||||||
|
|
||||||
TriangleIO in, out;
|
|
||||||
|
|
||||||
memset(&in, 0, sizeof(TriangleIO));
|
|
||||||
|
|
||||||
in.numberofpoints = len >> 1;
|
|
||||||
in.pointlist = (float *) points;
|
|
||||||
|
|
||||||
// check if explicitly closed
|
|
||||||
if (in.pointlist[0] == in.pointlist[indices[0] - 2]
|
|
||||||
&& in.pointlist[1] == in.pointlist[indices[0] - 1]) {
|
|
||||||
int point = 0;
|
|
||||||
for (int i = 0; i < num_rings; i++) {
|
|
||||||
// remove last point in ring
|
|
||||||
indices[i] -= 2;
|
|
||||||
int last = point + (indices[i] >> 1);
|
|
||||||
|
|
||||||
if (in.numberofpoints - last > 1)
|
|
||||||
memmove(in.pointlist + (last * 2), in.pointlist + ((last + 1) * 2),
|
|
||||||
(in.numberofpoints - last - 1) * 2 * sizeof(float));
|
|
||||||
|
|
||||||
in.numberofpoints--;
|
|
||||||
point = last;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int dups = 0;
|
|
||||||
|
|
||||||
float *i_points = points;
|
|
||||||
int *skip_list = NULL;
|
|
||||||
|
|
||||||
// check for duplicate vertices and keep a list
|
|
||||||
// of dups and the first occurence
|
|
||||||
for (int i = 0; i < in.numberofpoints - 1; i++) {
|
|
||||||
float x = *i_points++;
|
|
||||||
float y = *i_points++;
|
|
||||||
float *j_points = i_points;
|
|
||||||
|
|
||||||
for (int j = i + 1; j < in.numberofpoints; j++, j_points += 2) {
|
|
||||||
if ((*j_points == x) && (*(j_points + 1) == y)) {
|
|
||||||
skip_list = realloc(skip_list, (dups + 2) * 2 * sizeof(int));
|
|
||||||
skip_list[dups * 2 + 0] = j;
|
|
||||||
skip_list[dups * 2 + 1] = i;
|
|
||||||
dups++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
in.segmentlist = (int *) malloc(in.numberofpoints * 2 * sizeof(int));
|
|
||||||
in.numberofsegments = in.numberofpoints;
|
|
||||||
in.numberofholes = num_rings - 1;
|
|
||||||
|
|
||||||
int *rings = NULL;
|
|
||||||
if (in.numberofholes > 0) {
|
|
||||||
in.holelist = (float *) malloc(in.numberofholes * 2 * sizeof(float));
|
|
||||||
rings = (int*) malloc(num_rings * sizeof(int));
|
|
||||||
}
|
|
||||||
|
|
||||||
int *seg = in.segmentlist;
|
|
||||||
float *hole = in.holelist;
|
|
||||||
|
|
||||||
// counter going through all points
|
|
||||||
int point;
|
|
||||||
// counter going through all rings
|
|
||||||
int ring;
|
|
||||||
|
|
||||||
// assign all points to segments for each ring
|
|
||||||
for (ring = 0, point = 0; ring < num_rings; ring++, point++) {
|
|
||||||
int len;
|
|
||||||
int num_points = indices[ring] >> 1;
|
|
||||||
|
|
||||||
if (rings)
|
|
||||||
rings[ring] = num_points;
|
|
||||||
|
|
||||||
// add holes: we need a point inside the hole...
|
|
||||||
// this is just a heuristic, assuming that two
|
|
||||||
// 'parallel' lines have a distance of at least
|
|
||||||
// 1 unit. you'll notice when things went wrong
|
|
||||||
// when the hole is rendered instead of the poly
|
|
||||||
if (ring > 0) {
|
|
||||||
int k = point * 2;
|
|
||||||
|
|
||||||
float nx = in.pointlist[k++];
|
|
||||||
float ny = in.pointlist[k++];
|
|
||||||
|
|
||||||
float cx = 0, cy = 0, vx = 0, vy = 0;
|
|
||||||
|
|
||||||
// try to find a large enough segment
|
|
||||||
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 ux = -vy / a;
|
|
||||||
float uy = vx / a;
|
|
||||||
|
|
||||||
float centerx = cx + vx / 2.0 - (ux * 0.1);
|
|
||||||
float centery = cy + vy / 2.0 - (uy * 0.1);
|
|
||||||
|
|
||||||
*hole++ = centerx;
|
|
||||||
*hole++ = centery;
|
|
||||||
}
|
|
||||||
|
|
||||||
// close ring
|
|
||||||
int last = point + (num_points - 1);
|
|
||||||
*seg++ = last;
|
|
||||||
*seg++ = point;
|
|
||||||
|
|
||||||
for (len = point + num_points - 1; point < len; point++) {
|
|
||||||
*seg++ = point;
|
|
||||||
*seg++ = point + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dups) {
|
|
||||||
for (int i = 0; i < dups; i++) {
|
|
||||||
printf("duplicate points at %d, %d: %f,%f\n",
|
|
||||||
skip_list[i*2], skip_list[i*2+1],
|
|
||||||
in.pointlist[skip_list[i*2+1]*2],
|
|
||||||
in.pointlist[skip_list[i*2+1]*2+1]);
|
|
||||||
}
|
|
||||||
printPoly(&in);
|
|
||||||
|
|
||||||
// replace duplicate positions with first occurence
|
|
||||||
for (int i = 0; i < dups; i++) {
|
|
||||||
// position of the duplicate vertex
|
|
||||||
int pos = skip_list[i * 2] - i;
|
|
||||||
// first vertex
|
|
||||||
int replacement = skip_list[i * 2 + 1];
|
|
||||||
|
|
||||||
seg = in.segmentlist;
|
|
||||||
for (int j = 0; j < in.numberofsegments * 2; j++, seg++) {
|
|
||||||
if (*seg == pos) {
|
|
||||||
printf("%d: %d <- %d", j, pos, replacement);
|
|
||||||
*seg = replacement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&out, 0, sizeof(TriangleIO));
|
|
||||||
out.trianglelist = (INDICE*) indices;
|
|
||||||
|
|
||||||
// p - use polygon input, for CDT
|
|
||||||
// z - zero offset array offsets...
|
|
||||||
// P - no poly output
|
|
||||||
// N - no node output
|
|
||||||
// B - no bound output
|
|
||||||
// Q - be quiet!
|
|
||||||
|
|
||||||
TriangleOptions opt;
|
|
||||||
memset(&opt, 0, sizeof(TriangleOptions));
|
|
||||||
|
|
||||||
opt.dwyer = 1;
|
|
||||||
opt.steiner = -1;
|
|
||||||
opt.order = 1;
|
|
||||||
opt.maxarea = -1.0;
|
|
||||||
|
|
||||||
opt.poly = 1;
|
|
||||||
opt.usesegments = 1;
|
|
||||||
opt.nopolywritten = 1;
|
|
||||||
opt.nonodewritten = 1;
|
|
||||||
opt.nobound = 1;
|
|
||||||
opt.quiet = 1;
|
|
||||||
|
|
||||||
triangulate(&opt, &in, &out, (TriangleIO *) NULL);
|
|
||||||
|
|
||||||
if (in.numberofpoints < out.numberofpoints) {
|
|
||||||
// TODO rerun with 'nonodewritten = 0'
|
|
||||||
printf( "polygon input is bad! points in:%d out%d\n", in.numberofpoints, out.numberofpoints);
|
|
||||||
out.numberoftriangles = 0;
|
|
||||||
}
|
|
||||||
else if (out.trianglelist)
|
|
||||||
{
|
|
||||||
// scale to stride and add offset
|
|
||||||
short stride = 2;
|
|
||||||
|
|
||||||
if (offset < 0)
|
|
||||||
offset = 0;
|
|
||||||
|
|
||||||
INDICE *tri = out.trianglelist;
|
|
||||||
|
|
||||||
for (int n = out.numberoftriangles * 3; n > 0; n--, tri++)
|
|
||||||
*tri = *tri * stride + offset;
|
|
||||||
|
|
||||||
// when a ring has an odd number of points one (or rather two)
|
|
||||||
// additional vertices will be added. so the following rings
|
|
||||||
// needs extra offset...
|
|
||||||
int start = offset;
|
|
||||||
for (int j = 0, m = in.numberofholes; j < m; j++) {
|
|
||||||
start += rings[j] * stride;
|
|
||||||
|
|
||||||
// even number of points?
|
|
||||||
if (!(rings[j] & 1))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
tri = out.trianglelist;
|
|
||||||
int n = out.numberoftriangles * 3;
|
|
||||||
|
|
||||||
for (; n-- > 0; tri++)
|
|
||||||
if (*tri >= start)
|
|
||||||
*tri += stride;
|
|
||||||
|
|
||||||
start += stride;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf( "triangle failed %d\n", out.numberofpoints);
|
|
||||||
}
|
|
||||||
|
|
||||||
(*env)->ReleasePrimitiveArrayCritical(env, obj_points, orig_points, JNI_ABORT);
|
|
||||||
|
|
||||||
free(in.segmentlist);
|
|
||||||
free(in.holelist);
|
|
||||||
free(rings);
|
|
||||||
free(skip_list);
|
|
||||||
|
|
||||||
return out.numberoftriangles;
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,441 +0,0 @@
|
|||||||
#include "triangle_private.h"
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* quality_statistics() Print statistics about the quality of the mesh. */
|
|
||||||
/* */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void quality_statistics(struct mesh *m, struct behavior *b) {
|
|
||||||
struct otri triangleloop;
|
|
||||||
vertex p[3];
|
|
||||||
REAL cossquaretable[8];
|
|
||||||
REAL ratiotable[16];
|
|
||||||
REAL dx[3], dy[3];
|
|
||||||
REAL edgelength[3];
|
|
||||||
REAL dotproduct;
|
|
||||||
REAL cossquare;
|
|
||||||
REAL triarea;
|
|
||||||
REAL shortest, longest;
|
|
||||||
REAL trilongest2;
|
|
||||||
REAL smallestarea, biggestarea;
|
|
||||||
REAL triminaltitude2;
|
|
||||||
REAL minaltitude;
|
|
||||||
REAL triaspect2;
|
|
||||||
REAL worstaspect;
|
|
||||||
REAL smallestangle, biggestangle;
|
|
||||||
REAL radconst, degconst;
|
|
||||||
int angletable[18];
|
|
||||||
int aspecttable[16];
|
|
||||||
int aspectindex;
|
|
||||||
int tendegree;
|
|
||||||
int acutebiggest;
|
|
||||||
int i, ii, j, k;
|
|
||||||
|
|
||||||
printf("Mesh quality statistics:\n\n");
|
|
||||||
radconst = PI / 18.0;
|
|
||||||
degconst = 180.0 / PI;
|
|
||||||
for (i = 0; i < 8; i++) {
|
|
||||||
cossquaretable[i] = cos(radconst * (REAL) (i + 1));
|
|
||||||
cossquaretable[i] = cossquaretable[i] * cossquaretable[i];
|
|
||||||
}
|
|
||||||
for (i = 0; i < 18; i++) {
|
|
||||||
angletable[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ratiotable[0] = 1.5;
|
|
||||||
ratiotable[1] = 2.0;
|
|
||||||
ratiotable[2] = 2.5;
|
|
||||||
ratiotable[3] = 3.0;
|
|
||||||
ratiotable[4] = 4.0;
|
|
||||||
ratiotable[5] = 6.0;
|
|
||||||
ratiotable[6] = 10.0;
|
|
||||||
ratiotable[7] = 15.0;
|
|
||||||
ratiotable[8] = 25.0;
|
|
||||||
ratiotable[9] = 50.0;
|
|
||||||
ratiotable[10] = 100.0;
|
|
||||||
ratiotable[11] = 300.0;
|
|
||||||
ratiotable[12] = 1000.0;
|
|
||||||
ratiotable[13] = 10000.0;
|
|
||||||
ratiotable[14] = 100000.0;
|
|
||||||
ratiotable[15] = 0.0;
|
|
||||||
for (i = 0; i < 16; i++) {
|
|
||||||
aspecttable[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
worstaspect = 0.0;
|
|
||||||
minaltitude = m->xmax - m->xmin + m->ymax - m->ymin;
|
|
||||||
minaltitude = minaltitude * minaltitude;
|
|
||||||
shortest = minaltitude;
|
|
||||||
longest = 0.0;
|
|
||||||
smallestarea = minaltitude;
|
|
||||||
biggestarea = 0.0;
|
|
||||||
worstaspect = 0.0;
|
|
||||||
smallestangle = 0.0;
|
|
||||||
biggestangle = 2.0;
|
|
||||||
acutebiggest = 1;
|
|
||||||
|
|
||||||
traversalinit(&m->triangles);
|
|
||||||
triangleloop.tri = triangletraverse(m);
|
|
||||||
triangleloop.orient = 0;
|
|
||||||
while (triangleloop.tri != (triangle *) NULL) {
|
|
||||||
org(triangleloop, p[0]);
|
|
||||||
dest(triangleloop, p[1]);
|
|
||||||
apex(triangleloop, p[2]);
|
|
||||||
trilongest2 = 0.0;
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
|
||||||
j = plus1mod3[i];
|
|
||||||
k = minus1mod3[i];
|
|
||||||
dx[i] = p[j][0] - p[k][0];
|
|
||||||
dy[i] = p[j][1] - p[k][1];
|
|
||||||
edgelength[i] = dx[i] * dx[i] + dy[i] * dy[i];
|
|
||||||
if (edgelength[i] > trilongest2) {
|
|
||||||
trilongest2 = edgelength[i];
|
|
||||||
}
|
|
||||||
if (edgelength[i] > longest) {
|
|
||||||
longest = edgelength[i];
|
|
||||||
}
|
|
||||||
if (edgelength[i] < shortest) {
|
|
||||||
shortest = edgelength[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
triarea = counterclockwise(m, b, p[0], p[1], p[2]);
|
|
||||||
if (triarea < smallestarea) {
|
|
||||||
smallestarea = triarea;
|
|
||||||
}
|
|
||||||
if (triarea > biggestarea) {
|
|
||||||
biggestarea = triarea;
|
|
||||||
}
|
|
||||||
triminaltitude2 = triarea * triarea / trilongest2;
|
|
||||||
if (triminaltitude2 < minaltitude) {
|
|
||||||
minaltitude = triminaltitude2;
|
|
||||||
}
|
|
||||||
triaspect2 = trilongest2 / triminaltitude2;
|
|
||||||
if (triaspect2 > worstaspect) {
|
|
||||||
worstaspect = triaspect2;
|
|
||||||
}
|
|
||||||
aspectindex = 0;
|
|
||||||
while ((triaspect2 > ratiotable[aspectindex] * ratiotable[aspectindex]) && (aspectindex < 15)) {
|
|
||||||
aspectindex++;
|
|
||||||
}
|
|
||||||
aspecttable[aspectindex]++;
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
|
||||||
j = plus1mod3[i];
|
|
||||||
k = minus1mod3[i];
|
|
||||||
dotproduct = dx[j] * dx[k] + dy[j] * dy[k];
|
|
||||||
cossquare = dotproduct * dotproduct / (edgelength[j] * edgelength[k]);
|
|
||||||
tendegree = 8;
|
|
||||||
for (ii = 7; ii >= 0; ii--) {
|
|
||||||
if (cossquare > cossquaretable[ii]) {
|
|
||||||
tendegree = ii;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dotproduct <= 0.0) {
|
|
||||||
angletable[tendegree]++;
|
|
||||||
if (cossquare > smallestangle) {
|
|
||||||
smallestangle = cossquare;
|
|
||||||
}
|
|
||||||
if (acutebiggest && (cossquare < biggestangle)) {
|
|
||||||
biggestangle = cossquare;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
angletable[17 - tendegree]++;
|
|
||||||
if (acutebiggest || (cossquare > biggestangle)) {
|
|
||||||
biggestangle = cossquare;
|
|
||||||
acutebiggest = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
triangleloop.tri = triangletraverse(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
shortest = sqrt(shortest);
|
|
||||||
longest = sqrt(longest);
|
|
||||||
minaltitude = sqrt(minaltitude);
|
|
||||||
worstaspect = sqrt(worstaspect);
|
|
||||||
smallestarea *= 0.5;
|
|
||||||
biggestarea *= 0.5;
|
|
||||||
if (smallestangle >= 1.0) {
|
|
||||||
smallestangle = 0.0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
smallestangle = degconst * acos(sqrt(smallestangle));
|
|
||||||
}
|
|
||||||
if (biggestangle >= 1.0) {
|
|
||||||
biggestangle = 180.0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (acutebiggest) {
|
|
||||||
biggestangle = degconst * acos(sqrt(biggestangle));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
biggestangle = 180.0 - degconst * acos(sqrt(biggestangle));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf(" Smallest area: %16.5g | Largest area: %16.5g\n", smallestarea, biggestarea);
|
|
||||||
printf(" Shortest edge: %16.5g | Longest edge: %16.5g\n", shortest, longest);
|
|
||||||
printf(
|
|
||||||
" Shortest altitude: %12.5g | Largest aspect ratio: %8.5g\n\n", minaltitude, worstaspect);
|
|
||||||
|
|
||||||
printf(" Triangle aspect ratio histogram:\n");
|
|
||||||
printf(
|
|
||||||
" 1.1547 - %-6.6g : %8d | %6.6g - %-6.6g : %8d\n", ratiotable[0], aspecttable[0], ratiotable[7], ratiotable[8], aspecttable[8]);
|
|
||||||
for (i = 1; i < 7; i++) {
|
|
||||||
printf(
|
|
||||||
" %6.6g - %-6.6g : %8d | %6.6g - %-6.6g : %8d\n", ratiotable[i - 1], ratiotable[i], aspecttable[i], ratiotable[i + 7], ratiotable[i + 8], aspecttable[i + 8]);
|
|
||||||
}
|
|
||||||
printf(
|
|
||||||
" %6.6g - %-6.6g : %8d | %6.6g - : %8d\n", ratiotable[6], ratiotable[7], aspecttable[7], ratiotable[14], aspecttable[15]);
|
|
||||||
printf(" (Aspect ratio is longest edge divided by shortest altitude)\n\n");
|
|
||||||
|
|
||||||
printf(" Smallest angle: %15.5g | Largest angle: %15.5g\n\n", smallestangle, biggestangle);
|
|
||||||
|
|
||||||
printf(" Angle histogram:\n");
|
|
||||||
for (i = 0; i < 9; i++) {
|
|
||||||
printf(
|
|
||||||
" %3d - %3d degrees: %8d | %3d - %3d degrees: %8d\n", i * 10, i * 10 + 10, angletable[i], i * 10 + 90, i * 10 + 100, angletable[i + 9]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* statistics() Print all sorts of cool facts. */
|
|
||||||
/* */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void statistics(struct mesh *m, struct behavior *b) {
|
|
||||||
printf("\nStatistics:\n\n");
|
|
||||||
printf(" Input vertices: %d\n", m->invertices);
|
|
||||||
if (b->refine) {
|
|
||||||
printf(" Input triangles: %d\n", m->inelements);
|
|
||||||
}
|
|
||||||
if (b->poly) {
|
|
||||||
printf(" Input segments: %d\n", m->insegments);
|
|
||||||
if (!b->refine) {
|
|
||||||
printf(" Input holes: %d\n", m->holes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\n Mesh vertices: %ld\n", m->vertices.items - m->undeads);
|
|
||||||
printf(" Mesh triangles: %ld\n", m->triangles.items);
|
|
||||||
printf(" Mesh edges: %ld\n", m->edges);
|
|
||||||
printf(" Mesh exterior boundary edges: %ld\n", m->hullsize);
|
|
||||||
if (b->poly || b->refine) {
|
|
||||||
printf(" Mesh interior boundary edges: %ld\n", m->subsegs.items - m->hullsize);
|
|
||||||
printf(" Mesh subsegments (constrained edges): %ld\n", m->subsegs.items);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
if (b->verbose) {
|
|
||||||
quality_statistics(m, b);
|
|
||||||
printf("Memory allocation statistics:\n\n");
|
|
||||||
printf(" Maximum number of vertices: %ld\n", m->vertices.maxitems);
|
|
||||||
printf(" Maximum number of triangles: %ld\n", m->triangles.maxitems);
|
|
||||||
if (m->subsegs.maxitems > 0) {
|
|
||||||
printf(" Maximum number of subsegments: %ld\n", m->subsegs.maxitems);
|
|
||||||
}
|
|
||||||
if (m->viri.maxitems > 0) {
|
|
||||||
printf(" Maximum number of viri: %ld\n", m->viri.maxitems);
|
|
||||||
}
|
|
||||||
if (m->badsubsegs.maxitems > 0) {
|
|
||||||
printf(" Maximum number of encroached subsegments: %ld\n", m->badsubsegs.maxitems);
|
|
||||||
}
|
|
||||||
if (m->badtriangles.maxitems > 0) {
|
|
||||||
printf(" Maximum number of bad triangles: %ld\n", m->badtriangles.maxitems);
|
|
||||||
}
|
|
||||||
if (m->flipstackers.maxitems > 0) {
|
|
||||||
printf(" Maximum number of stacked triangle flips: %ld\n", m->flipstackers.maxitems);
|
|
||||||
}
|
|
||||||
if (m->splaynodes.maxitems > 0) {
|
|
||||||
printf(" Maximum number of splay tree nodes: %ld\n", m->splaynodes.maxitems);
|
|
||||||
}
|
|
||||||
printf(
|
|
||||||
" Approximate heap memory use (bytes): %ld\n\n", m->vertices.maxitems * m->vertices.itembytes + m->triangles.maxitems * m->triangles.itembytes + m->subsegs.maxitems * m->subsegs.itembytes + m->viri.maxitems * m->viri.itembytes + m->badsubsegs.maxitems * m->badsubsegs.itembytes + m->badtriangles.maxitems * m->badtriangles.itembytes + m->flipstackers.maxitems * m->flipstackers.itembytes + m->splaynodes.maxitems * m->splaynodes.itembytes);
|
|
||||||
|
|
||||||
printf("Algorithmic statistics:\n\n");
|
|
||||||
if (!b->weighted) {
|
|
||||||
printf(" Number of incircle tests: %ld\n", m->incirclecount);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(" Number of 3D orientation tests: %ld\n", m->orient3dcount);
|
|
||||||
}
|
|
||||||
printf(" Number of 2D orientation tests: %ld\n", m->counterclockcount);
|
|
||||||
if (m->hyperbolacount > 0) {
|
|
||||||
printf(" Number of right-of-hyperbola tests: %ld\n", m->hyperbolacount);
|
|
||||||
}
|
|
||||||
if (m->circletopcount > 0) {
|
|
||||||
printf(" Number of circle top computations: %ld\n", m->circletopcount);
|
|
||||||
}
|
|
||||||
if (m->circumcentercount > 0) {
|
|
||||||
printf(" Number of triangle circumcenter computations: %ld\n", m->circumcentercount);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/********* Debugging routines begin here *********/
|
|
||||||
/** **/
|
|
||||||
/** **/
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* printtriangle() Print out the details of an oriented triangle. */
|
|
||||||
/* */
|
|
||||||
/* I originally wrote this procedure to simplify debugging; it can be */
|
|
||||||
/* called directly from the debugger, and presents information about an */
|
|
||||||
/* oriented triangle in digestible form. It's also used when the */
|
|
||||||
/* highest level of verbosity (`-VVV') is specified. */
|
|
||||||
/* */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void printtriangle(struct mesh *m, struct behavior *b, struct otri *t) {
|
|
||||||
struct otri printtri;
|
|
||||||
struct osub printsh;
|
|
||||||
vertex printvertex;
|
|
||||||
|
|
||||||
printf("triangle x%lx with orientation %d:\n", (unsigned long) t->tri, t->orient);
|
|
||||||
decode(t->tri[0], printtri);
|
|
||||||
if (printtri.tri == m->dummytri) {
|
|
||||||
printf(" [0] = Outer space\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(" [0] = x%lx %d\n", (unsigned long) printtri.tri, printtri.orient);
|
|
||||||
}
|
|
||||||
decode(t->tri[1], printtri);
|
|
||||||
if (printtri.tri == m->dummytri) {
|
|
||||||
printf(" [1] = Outer space\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(" [1] = x%lx %d\n", (unsigned long) printtri.tri, printtri.orient);
|
|
||||||
}
|
|
||||||
decode(t->tri[2], printtri);
|
|
||||||
if (printtri.tri == m->dummytri) {
|
|
||||||
printf(" [2] = Outer space\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(" [2] = x%lx %d\n", (unsigned long) printtri.tri, printtri.orient);
|
|
||||||
}
|
|
||||||
|
|
||||||
org(*t, printvertex);
|
|
||||||
if (printvertex == (vertex) NULL)
|
|
||||||
printf(" Origin[%d] = NULL\n", (t->orient + 1) % 3 + 3);
|
|
||||||
else
|
|
||||||
printf(
|
|
||||||
" Origin[%d] = x%lx (%.12g, %.12g)\n", (t->orient + 1) % 3 + 3, (unsigned long) printvertex, printvertex[0], printvertex[1]);
|
|
||||||
dest(*t, printvertex);
|
|
||||||
if (printvertex == (vertex) NULL)
|
|
||||||
printf(" Dest [%d] = NULL\n", (t->orient + 2) % 3 + 3);
|
|
||||||
else
|
|
||||||
printf(
|
|
||||||
" Dest [%d] = x%lx (%.12g, %.12g)\n", (t->orient + 2) % 3 + 3, (unsigned long) printvertex, printvertex[0], printvertex[1]);
|
|
||||||
apex(*t, printvertex);
|
|
||||||
if (printvertex == (vertex) NULL)
|
|
||||||
printf(" Apex [%d] = NULL\n", t->orient + 3);
|
|
||||||
else
|
|
||||||
printf(
|
|
||||||
" Apex [%d] = x%lx (%.12g, %.12g)\n", t->orient + 3, (unsigned long) printvertex, printvertex[0], printvertex[1]);
|
|
||||||
|
|
||||||
if (b->usesegments) {
|
|
||||||
sdecode(t->tri[6], printsh);
|
|
||||||
if (printsh.ss != m->dummysub) {
|
|
||||||
printf(" [6] = x%lx %d\n", (unsigned long) printsh.ss, printsh.ssorient);
|
|
||||||
}
|
|
||||||
sdecode(t->tri[7], printsh);
|
|
||||||
if (printsh.ss != m->dummysub) {
|
|
||||||
printf(" [7] = x%lx %d\n", (unsigned long) printsh.ss, printsh.ssorient);
|
|
||||||
}
|
|
||||||
sdecode(t->tri[8], printsh);
|
|
||||||
if (printsh.ss != m->dummysub) {
|
|
||||||
printf(" [8] = x%lx %d\n", (unsigned long) printsh.ss, printsh.ssorient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b->vararea) {
|
|
||||||
printf(" Area constraint: %.4g\n", areabound(*t));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* printsubseg() Print out the details of an oriented subsegment. */
|
|
||||||
/* */
|
|
||||||
/* I originally wrote this procedure to simplify debugging; it can be */
|
|
||||||
/* called directly from the debugger, and presents information about an */
|
|
||||||
/* oriented subsegment in digestible form. It's also used when the highest */
|
|
||||||
/* level of verbosity (`-VVV') is specified. */
|
|
||||||
/* */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void printsubseg(struct mesh *m, struct behavior *b, struct osub *s) {
|
|
||||||
struct osub printsh;
|
|
||||||
struct otri printtri;
|
|
||||||
vertex printvertex;
|
|
||||||
|
|
||||||
printf(
|
|
||||||
"subsegment x%lx with orientation %d and mark %d:\n", (unsigned long) s->ss, s->ssorient, mark(*s));
|
|
||||||
sdecode(s->ss[0], printsh);
|
|
||||||
if (printsh.ss == m->dummysub) {
|
|
||||||
printf(" [0] = No subsegment\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(" [0] = x%lx %d\n", (unsigned long) printsh.ss, printsh.ssorient);
|
|
||||||
}
|
|
||||||
sdecode(s->ss[1], printsh);
|
|
||||||
if (printsh.ss == m->dummysub) {
|
|
||||||
printf(" [1] = No subsegment\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(" [1] = x%lx %d\n", (unsigned long) printsh.ss, printsh.ssorient);
|
|
||||||
}
|
|
||||||
|
|
||||||
sorg(*s, printvertex);
|
|
||||||
if (printvertex == (vertex) NULL)
|
|
||||||
printf(" Origin[%d] = NULL\n", 2 + s->ssorient);
|
|
||||||
else
|
|
||||||
printf(
|
|
||||||
" Origin[%d] = x%lx (%.12g, %.12g)\n", 2 + s->ssorient, (unsigned long) printvertex, printvertex[0], printvertex[1]);
|
|
||||||
sdest(*s, printvertex);
|
|
||||||
if (printvertex == (vertex) NULL)
|
|
||||||
printf(" Dest [%d] = NULL\n", 3 - s->ssorient);
|
|
||||||
else
|
|
||||||
printf(
|
|
||||||
" Dest [%d] = x%lx (%.12g, %.12g)\n", 3 - s->ssorient, (unsigned long) printvertex, printvertex[0], printvertex[1]);
|
|
||||||
|
|
||||||
decode(s->ss[6], printtri);
|
|
||||||
if (printtri.tri == m->dummytri) {
|
|
||||||
printf(" [6] = Outer space\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(" [6] = x%lx %d\n", (unsigned long) printtri.tri, printtri.orient);
|
|
||||||
}
|
|
||||||
decode(s->ss[7], printtri);
|
|
||||||
if (printtri.tri == m->dummytri) {
|
|
||||||
printf(" [7] = Outer space\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(" [7] = x%lx %d\n", (unsigned long) printtri.tri, printtri.orient);
|
|
||||||
}
|
|
||||||
|
|
||||||
segorg(*s, printvertex);
|
|
||||||
if (printvertex == (vertex) NULL)
|
|
||||||
printf(" Segment origin[%d] = NULL\n", 4 + s->ssorient);
|
|
||||||
else
|
|
||||||
printf(
|
|
||||||
" Segment origin[%d] = x%lx (%.12g, %.12g)\n", 4 + s->ssorient, (unsigned long) printvertex, printvertex[0], printvertex[1]);
|
|
||||||
segdest(*s, printvertex);
|
|
||||||
if (printvertex == (vertex) NULL)
|
|
||||||
printf(" Segment dest [%d] = NULL\n", 5 - s->ssorient);
|
|
||||||
else
|
|
||||||
printf(
|
|
||||||
" Segment dest [%d] = x%lx (%.12g, %.12g)\n", 5 - s->ssorient, (unsigned long) printvertex, printvertex[0], printvertex[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** **/
|
|
||||||
/** **/
|
|
||||||
/********* Debugging routines end here *********/
|
|
||||||
Loading…
x
Reference in New Issue
Block a user