Code cleanup: de-duplicate cotangent weight function & add arg sizes

This commit is contained in:
2014-03-30 11:08:33 +11:00
parent 23ef10c705
commit 1f58bfb8be
19 changed files with 67 additions and 131 deletions

View File

@@ -74,7 +74,7 @@ void multitestapp_exit(MultiTestApp *app);
/**/
void rect_bevel_side(int rect[2][2], int side, float *lt, float *dk, float *col, int width)
void rect_bevel_side(int rect[2][2], int side, float *lt, float *dk, const float col[3], int width)
{
int ltidx = (side / 2) % 4;
int dkidx = (ltidx + 1 + (side & 1)) % 4;

View File

@@ -250,7 +250,7 @@ void testhandles_fcurve(struct FCurve *fcu, const bool use_handle);
void sort_time_fcurve(struct FCurve *fcu);
short test_time_fcurve(struct FCurve *fcu);
void correct_bezpart(float *v1, float *v2, float *v3, float *v4);
void correct_bezpart(float v1[2], float v2[2], float v3[2], float v4[2]);
/* -------- Evaluation -------- */

View File

@@ -129,7 +129,7 @@ bool BKE_boundbox_ray_hit_check(struct BoundBox *bb, const float ray_start[3], c
struct BoundBox *BKE_object_boundbox_get(struct Object *ob);
void BKE_object_dimensions_get(struct Object *ob, float vec[3]);
void BKE_object_dimensions_set(struct Object *ob, const float *value);
void BKE_object_dimensions_set(struct Object *ob, const float value[3]);
void BKE_object_empty_draw_type_set(struct Object *ob, const int value);
void BKE_object_boundbox_flag(struct Object *ob, int flag, int set);
void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);

View File

@@ -1929,7 +1929,8 @@ static int vergxcobev(const void *a1, const void *a2)
/* this function cannot be replaced with atan2, but why? */
static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *sina, float *cosa)
static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2,
float *r_sina, float *r_cosa)
{
float t01, t02, x3, y3;
@@ -1967,8 +1968,8 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
y3 /= t01;
}
*sina = -y3 / t02;
*cosa = x3 / t02;
*r_sina = -y3 / t02;
*r_cosa = x3 / t02;
}

View File

@@ -2519,7 +2519,7 @@ void BKE_object_dimensions_get(Object *ob, float vec[3])
}
}
void BKE_object_dimensions_set(Object *ob, const float *value)
void BKE_object_dimensions_set(Object *ob, const float value[3])
{
BoundBox *bb = NULL;

View File

@@ -57,6 +57,7 @@ float area_tri_signed_v3(const float v1[3], const float v2[3], const float v3[3]
float area_quad_v3(const float a[3], const float b[3], const float c[3], const float d[3]);
float area_poly_v3(const float verts[][3], unsigned int nr, const float normal[3]);
float area_poly_v2(const float verts[][2], unsigned int nr);
float cotangent_tri_weight_v3(const float v1[3], const float v2[3], const float v3[3]);
MINLINE float cross_tri_v2(const float v1[2], const float v2[2], const float v3[2]);
float cross_poly_v2(const float verts[][2], unsigned int nr);

View File

@@ -57,7 +57,7 @@ float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity
void voronoi(float x, float y, float z, float *da, float *pa, float me, int dtype);
/* newnoise: cellNoise & cellNoiseV (for vector/point/color) */
float cellNoise(float x, float y, float z);
void cellNoiseV(float x, float y, float z, float *ca);
void cellNoiseV(float x, float y, float z, float r_ca[3]);
#ifdef __cplusplus
}

View File

@@ -179,6 +179,24 @@ float area_poly_v2(const float verts[][2], unsigned int nr)
return fabsf(0.5f * cross_poly_v2(verts, nr));
}
float cotangent_tri_weight_v3(const float v1[3], const float v2[3], const float v3[3])
{
float a[3], b[3], c[3], c_len;
sub_v3_v3v3(a, v2, v1);
sub_v3_v3v3(b, v3, v1);
cross_v3_v3v3(c, a, b);
c_len = len_v3(c);
if (c_len > FLT_EPSILON) {
return dot_v3v3(a, b) / c_len;
}
else {
return 0.0f;
}
}
/********************************* Planes **********************************/
/**

View File

@@ -1407,7 +1407,7 @@ float cellNoise(float x, float y, float z)
}
/* returns a vector/point/color in ca, using point hasharray directly */
void cellNoiseV(float x, float y, float z, float *ca)
void cellNoiseV(float x, float y, float z, float ca[3])
{
int xi = (int)(floor(x));
int yi = (int)(floor(y));

View File

@@ -66,7 +66,6 @@ struct BLaplacianSystem {
};
typedef struct BLaplacianSystem LaplacianSystem;
static float cotan_weight(float *v1, float *v2, float *v3);
static bool vert_is_boundary(BMVert *v);
static LaplacianSystem *init_laplacian_system(int a_numEdges, int a_numFaces, int a_numVerts);
static void init_laplacian_matrix(LaplacianSystem *sys);
@@ -261,9 +260,9 @@ static void init_laplacian_matrix(LaplacianSystem *sys)
v3 = vf[(j + 2) % 4]->co;
v4 = vf[(j + 3) % 4]->co;
w2 = cotan_weight(v4, v1, v2) + cotan_weight(v3, v1, v2);
w3 = cotan_weight(v2, v3, v1) + cotan_weight(v4, v1, v3);
w4 = cotan_weight(v2, v4, v1) + cotan_weight(v3, v4, v1);
w2 = cotangent_tri_weight_v3(v4, v1, v2) + cotangent_tri_weight_v3(v3, v1, v2);
w3 = cotangent_tri_weight_v3(v2, v3, v1) + cotangent_tri_weight_v3(v4, v1, v3);
w4 = cotangent_tri_weight_v3(v2, v4, v1) + cotangent_tri_weight_v3(v3, v4, v1);
sys->vweights[idv1] += (w2 + w3 + w4) / 4.0f;
}
@@ -271,9 +270,9 @@ static void init_laplacian_matrix(LaplacianSystem *sys)
else {
i = BM_elem_index_get(f);
w1 = cotan_weight(v1, v2, v3);
w2 = cotan_weight(v2, v3, v1);
w3 = cotan_weight(v3, v1, v2);
w1 = cotangent_tri_weight_v3(v1, v2, v3);
w2 = cotangent_tri_weight_v3(v2, v3, v1);
w3 = cotangent_tri_weight_v3(v3, v1, v2);
sys->fweights[i][0] += w1;
sys->fweights[i][1] += w2;
@@ -325,9 +324,9 @@ static void fill_laplacian_matrix(LaplacianSystem *sys)
v3 = vf[(j + 2) % 4]->co;
v4 = vf[(j + 3) % 4]->co;
w2 = cotan_weight(v4, v1, v2) + cotan_weight(v3, v1, v2);
w3 = cotan_weight(v2, v3, v1) + cotan_weight(v4, v1, v3);
w4 = cotan_weight(v2, v4, v1) + cotan_weight(v3, v4, v1);
w2 = cotangent_tri_weight_v3(v4, v1, v2) + cotangent_tri_weight_v3(v3, v1, v2);
w3 = cotangent_tri_weight_v3(v2, v3, v1) + cotangent_tri_weight_v3(v4, v1, v3);
w4 = cotangent_tri_weight_v3(v2, v4, v1) + cotangent_tri_weight_v3(v3, v4, v1);
w2 = w2 / 4.0f;
w3 = w3 / 4.0f;
@@ -376,22 +375,6 @@ static void fill_laplacian_matrix(LaplacianSystem *sys)
}
}
static float cotan_weight(float *v1, float *v2, float *v3)
{
float a[3], b[3], c[3], clen;
sub_v3_v3v3(a, v2, v1);
sub_v3_v3v3(b, v3, v1);
cross_v3_v3v3(c, a, b);
clen = len_v3(c);
if (clen == 0.0f)
return 0.0f;
return dot_v3v3(a, b) / clen;
}
static bool vert_is_boundary(BMVert *v)
{
BMEdge *ed;

View File

@@ -140,22 +140,6 @@ static int laplacian_edge_count(EdgeHash *edgehash, int v1, int v2)
return (int)(intptr_t)BLI_edgehash_lookup(edgehash, v1, v2);
}
static float cotan_weight(float *v1, float *v2, float *v3)
{
float a[3], b[3], c[3], clen;
sub_v3_v3v3(a, v2, v1);
sub_v3_v3v3(b, v3, v1);
cross_v3_v3v3(c, a, b);
clen = len_v3(c);
if (clen == 0.0f)
return 0.0f;
return dot_v3v3(a, b) / clen;
}
static void laplacian_triangle_area(LaplacianSystem *sys, int i1, int i2, int i3)
{
float t1, t2, t3, len1, len2, len3, area;
@@ -166,9 +150,9 @@ static void laplacian_triangle_area(LaplacianSystem *sys, int i1, int i2, int i3
v2 = sys->verts[i2];
v3 = sys->verts[i3];
t1 = cotan_weight(v1, v2, v3);
t2 = cotan_weight(v2, v3, v1);
t3 = cotan_weight(v3, v1, v2);
t1 = cotangent_tri_weight_v3(v1, v2, v3);
t2 = cotangent_tri_weight_v3(v2, v3, v1);
t3 = cotangent_tri_weight_v3(v3, v1, v2);
if (angle_v3v3v3(v2, v1, v3) > DEG2RADF(90.0f)) obtuse = 1;
else if (angle_v3v3v3(v1, v2, v3) > DEG2RADF(90.0f)) obtuse = 2;
@@ -207,9 +191,9 @@ static void laplacian_triangle_weights(LaplacianSystem *sys, int f, int i1, int
/* instead of *0.5 we divided by the number of faces of the edge, it still
* needs to be verified that this is indeed the correct thing to do! */
t1 = cotan_weight(v1, v2, v3) / laplacian_edge_count(sys->edgehash, i2, i3);
t2 = cotan_weight(v2, v3, v1) / laplacian_edge_count(sys->edgehash, i3, i1);
t3 = cotan_weight(v3, v1, v2) / laplacian_edge_count(sys->edgehash, i1, i2);
t1 = cotangent_tri_weight_v3(v1, v2, v3) / laplacian_edge_count(sys->edgehash, i2, i3);
t2 = cotangent_tri_weight_v3(v2, v3, v1) / laplacian_edge_count(sys->edgehash, i3, i1);
t3 = cotangent_tri_weight_v3(v3, v1, v2) / laplacian_edge_count(sys->edgehash, i1, i2);
nlMatrixAdd(i1, i1, (t2 + t3) * varea[i1]);
nlMatrixAdd(i2, i2, (t1 + t3) * varea[i2]);

View File

@@ -2497,32 +2497,16 @@ int weightFromLoc(EditMesh *em, int axis)
return 1;
}
static float cotan_weight(float *v1, float *v2, float *v3)
{
float a[3], b[3], c[3], clen;
sub_v3_v3v3(a, v2, v1);
sub_v3_v3v3(b, v3, v1);
cross_v3_v3v3(c, a, b);
clen = len_v3(c);
if (clen == 0.0f)
return 0.0f;
return dot_v3v3(a, b) / clen;
}
static void addTriangle(EditVert *v1, EditVert *v2, EditVert *v3, int e1, int e2, int e3)
{
/* Angle opposite e1 */
float t1 = cotan_weight(v1->co, v2->co, v3->co) / e2;
float t1 = cotangent_tri_weight_v3(v1->co, v2->co, v3->co) / e2;
/* Angle opposite e2 */
float t2 = cotan_weight(v2->co, v3->co, v1->co) / e3;
float t2 = cotangent_tri_weight_v3(v2->co, v3->co, v1->co) / e3;
/* Angle opposite e3 */
float t3 = cotan_weight(v3->co, v1->co, v2->co) / e1;
float t3 = cotangent_tri_weight_v3(v3->co, v1->co, v2->co) / e1;
int i1 = indexData(v1);
int i2 = indexData(v2);

View File

@@ -1671,7 +1671,7 @@ static void scale_tri(float insetCos[4][3], float *origCos[4], const float inset
}
#endif //PROJ_DEBUG_NOSEAMBLEED
static float len_squared_v2v2_alt(const float *v1, const float v2_1, const float v2_2)
static float len_squared_v2v2_alt(const float v1[2], const float v2_1, const float v2_2)
{
float x, y;

View File

@@ -166,7 +166,7 @@ static void find_nearest_tracking_knot_cb(void *userdata, MovieTrackingTrack *tr
}
static void mouse_select_init_data(MouseSelectUserData *userdata, float *co)
static void mouse_select_init_data(MouseSelectUserData *userdata, const float co[2])
{
memset(userdata, 0, sizeof(MouseSelectUserData));
userdata->min_dist = FLT_MAX;

View File

@@ -584,7 +584,7 @@ static void node_draw_mute_line(View2D *v2d, SpaceNode *snode, bNode *node)
}
/* this might have some more generic use */
static void node_circle_draw(float x, float y, float size, float *col, int highlight)
static void node_circle_draw(float x, float y, float size, const float col[4], int highlight)
{
/* 16 values of sin function */
static float si[16] = {

View File

@@ -498,8 +498,8 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2]);
void projectFloatViewEx(TransInfo *t, const float vec[3], float adr[2], const eV3DProjTest flag);
void projectFloatView(TransInfo *t, const float vec[3], float adr[2]);
void applyAspectRatio(TransInfo *t, float *vec);
void removeAspectRatio(TransInfo *t, float *vec);
void applyAspectRatio(TransInfo *t, float vec[2]);
void removeAspectRatio(TransInfo *t, float vec[2]);
void drawPropCircle(const struct bContext *C, TransInfo *t);

View File

@@ -138,24 +138,6 @@ static void deleteLaplacianSystem(LaplacianSystem *sys)
MEM_SAFE_FREE(sys);
}
static float cotan_weight(const float v1[3], const float v2[3], const float v3[3])
{
float a[3], b[3], c[3], clen;
sub_v3_v3v3(a, v2, v1);
sub_v3_v3v3(b, v3, v1);
cross_v3_v3v3(c, a, b);
clen = len_v3(c);
if (clen > FLT_EPSILON) {
return dot_v3v3(a, b) / clen;
}
else {
return 0.0f;
}
}
static void createFaceRingMap(
const int mvert_tot, const MFace *mface, const int mface_tot,
MeshElemMap **r_map, int **r_indices)
@@ -306,9 +288,9 @@ static void initLaplacianMatrix(LaplacianSystem *sys)
if (has_4_vert) {
w2 = (cotan_weight(v4, v1, v2) + cotan_weight(v3, v1, v2)) / 2.0f;
w3 = (cotan_weight(v2, v3, v1) + cotan_weight(v4, v1, v3)) / 2.0f;
w4 = (cotan_weight(v2, v4, v1) + cotan_weight(v3, v4, v1)) / 2.0f;
w2 = (cotangent_tri_weight_v3(v4, v1, v2) + cotangent_tri_weight_v3(v3, v1, v2)) / 2.0f;
w3 = (cotangent_tri_weight_v3(v2, v3, v1) + cotangent_tri_weight_v3(v4, v1, v3)) / 2.0f;
w4 = (cotangent_tri_weight_v3(v2, v4, v1) + cotangent_tri_weight_v3(v3, v4, v1)) / 2.0f;
sys->delta[idv1][0] -= v4[0] * w4;
sys->delta[idv1][1] -= v4[1] * w4;
@@ -321,8 +303,8 @@ static void initLaplacianMatrix(LaplacianSystem *sys)
nlMatrixAdd(idv1, idv4, -w4);
}
else {
w2 = cotan_weight(v3, v1, v2);
w3 = cotan_weight(v2, v3, v1);
w2 = cotangent_tri_weight_v3(v3, v1, v2);
w3 = cotangent_tri_weight_v3(v2, v3, v1);
w4 = 0.0f;
}

View File

@@ -88,7 +88,6 @@ static CustomDataMask required_data_mask(Object *ob, ModifierData *md);
static bool is_disabled(ModifierData *md, int useRenderParams);
static float average_area_quad_v3(float *v1, float *v2, float *v3, float *v4);
static float compute_volume(float (*vertexCos)[3], MFace *mfaces, int numFaces);
static float cotan_weight(float *v1, float *v2, float *v3);
static LaplacianSystem *init_laplacian_system(int a_numEdges, int a_numFaces, int a_numVerts);
static void copy_data(ModifierData *md, ModifierData *target);
static void delete_laplacian_system(LaplacianSystem *sys);
@@ -204,22 +203,6 @@ static float average_area_quad_v3(float *v1, float *v2, float *v3, float *v4)
return areaq / 2.0f;
}
static float cotan_weight(float *v1, float *v2, float *v3)
{
float a[3], b[3], c[3], clen;
sub_v3_v3v3(a, v2, v1);
sub_v3_v3v3(b, v3, v1);
cross_v3_v3v3(c, a, b);
clen = len_v3(c);
if (clen == 0.0f)
return 0.0f;
return dot_v3v3(a, b) / clen;
}
static float compute_volume(float (*vertexCos)[3], MFace *mfaces, int numFaces)
{
float vol = 0.0f;
@@ -367,17 +350,17 @@ static void init_laplacian_matrix(LaplacianSystem *sys)
v3 = sys->vertexCos[idv3];
v4 = sys->vertexCos[idv4];
w2 = cotan_weight(v4, v1, v2) + cotan_weight(v3, v1, v2);
w3 = cotan_weight(v2, v3, v1) + cotan_weight(v4, v1, v3);
w4 = cotan_weight(v2, v4, v1) + cotan_weight(v3, v4, v1);
w2 = cotangent_tri_weight_v3(v4, v1, v2) + cotangent_tri_weight_v3(v3, v1, v2);
w3 = cotangent_tri_weight_v3(v2, v3, v1) + cotangent_tri_weight_v3(v4, v1, v3);
w4 = cotangent_tri_weight_v3(v2, v4, v1) + cotangent_tri_weight_v3(v3, v4, v1);
sys->vweights[idv1] += (w2 + w3 + w4) / 4.0f;
}
}
else {
w1 = cotan_weight(v1, v2, v3) / 2.0f;
w2 = cotan_weight(v2, v3, v1) / 2.0f;
w3 = cotan_weight(v3, v1, v2) / 2.0f;
w1 = cotangent_tri_weight_v3(v1, v2, v3) / 2.0f;
w2 = cotangent_tri_weight_v3(v2, v3, v1) / 2.0f;
w3 = cotangent_tri_weight_v3(v3, v1, v2) / 2.0f;
sys->fweights[i][0] = sys->fweights[i][0] + w1;
sys->fweights[i][1] = sys->fweights[i][1] + w2;
@@ -430,9 +413,9 @@ static void fill_laplacian_matrix(LaplacianSystem *sys)
v3 = sys->vertexCos[idv3];
v4 = sys->vertexCos[idv4];
w2 = cotan_weight(v4, v1, v2) + cotan_weight(v3, v1, v2);
w3 = cotan_weight(v2, v3, v1) + cotan_weight(v4, v1, v3);
w4 = cotan_weight(v2, v4, v1) + cotan_weight(v3, v4, v1);
w2 = cotangent_tri_weight_v3(v4, v1, v2) + cotangent_tri_weight_v3(v3, v1, v2);
w3 = cotangent_tri_weight_v3(v2, v3, v1) + cotangent_tri_weight_v3(v4, v1, v3);
w4 = cotangent_tri_weight_v3(v2, v4, v1) + cotangent_tri_weight_v3(v3, v4, v1);
w2 = w2 / 4.0f;
w3 = w3 / 4.0f;

View File

@@ -130,7 +130,7 @@ static void updateDepgraph(ModifierData *md, DagForest *forest,
}
}
static float meshdeform_dynamic_bind(MeshDeformModifierData *mmd, float (*dco)[3], float *vec)
static float meshdeform_dynamic_bind(MeshDeformModifierData *mmd, float (*dco)[3], float vec[3])
{
MDefCell *cell;
MDefInfluence *inf;