[Bf-blender-cvs] [5aac8ee] soc-2014-remesh: Clean code. Completed all methods to compute flow lines.
Alexander Pinzon Fernandez
noreply at git.blender.org
Wed Aug 27 04:26:11 CEST 2014
Commit: 5aac8ee281ebbe0fece3fdb20d84a236c0922602
Author: Alexander Pinzon Fernandez
Date: Mon Aug 25 09:21:59 2014 -0500
Branches: soc-2014-remesh
https://developer.blender.org/rB5aac8ee281ebbe0fece3fdb20d84a236c0922602
Clean code.
Completed all methods to compute flow lines.
===================================================================
M source/blender/modifiers/intern/MOD_quadremesh.c
M source/blender/modifiers/intern/MOD_quadremesh_geom.c
M source/blender/modifiers/intern/MOD_quadremesh_geom.h
===================================================================
diff --git a/source/blender/modifiers/intern/MOD_quadremesh.c b/source/blender/modifiers/intern/MOD_quadremesh.c
index a04b1af..1aaffb8 100644
--- a/source/blender/modifiers/intern/MOD_quadremesh.c
+++ b/source/blender/modifiers/intern/MOD_quadremesh.c
@@ -33,59 +33,16 @@
#include "MEM_guardedalloc.h"
-#include "BKE_mesh_mapping.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_particle.h"
#include "BKE_deform.h"
#include "MOD_util.h"
+#include "MOD_quadremesh_geom.h"
#ifdef WITH_OPENNL
-#include "ONL_opennl.h"
-
-typedef struct GradientFlowLine {
- int *edges; /* Pointer to a edge */
- int *index; /* Pointer to a coordinate in cogfl*/
- int total_verts; /* Total number of points in a flow line */
- int total_allocated; /* Total number of points in memory */
-} GradientFlowLine;
-
-typedef struct LaplacianSystem {
- bool command_compute_flow;
- bool has_solution;
- bool command_remesh;
- int total_verts;
- int total_edges;
- int total_faces;
- int total_features;
- int total_gflines;
- int total_gfverts;
- char features_grp_name[64]; /* Vertex Group name */
- float(*co)[3]; /* Original vertex coordinates */
- float(*cogfl)[3]; /* Vertex coordinate Gradient flow line */
- float(*no)[3]; /* Original face normal */
- float(*gf1)[3]; /* Gradient Field g1 */
- float(*gf2)[3]; /* Gradient Field g2 */
- float *weights; /* Feature points weights*/
- float *U_field; /* Initial scalar field*/
- float *h1; /* Sampling distance function h1*/
- float *h2; /* Sampling distance function h2*/
- int *constraints; /* Feature points constraints*/
- int *ringf_indices; /* Indices of faces per vertex */
- int *ringv_indices; /* Indices of neighbors(vertex) per vertex */
- int *ringe_indices; /* Indices of edges per vertex */
- unsigned int(*faces)[4]; /* Copy of MFace (tessface) v1-v4 */
- unsigned int(*edges)[2]; /* Copy of edges v1-v2 */
- unsigned int(*faces_edge)[2]; /* Faces by edges */
- GradientFlowLine *gflines; /* Gradien flow lines of field g1*/
- MeshElemMap *ringf_map; /* Map of faces per vertex */
- MeshElemMap *ringv_map; /* Map of vertex per vertex */
- MeshElemMap *ringe_map; /* Map of edges per vertex */
- NLContext *context; /* System for solve general implicit rotations */
-} LaplacianSystem;
-
static LaplacianSystem *newLaplacianSystem(void)
{
@@ -133,7 +90,6 @@ static LaplacianSystem *initLaplacianSystem(int totalVerts, int totalEdges, int
static void deleteLaplacianSystem(LaplacianSystem *sys)
{
- int i;
MEM_SAFE_FREE(sys->faces);
MEM_SAFE_FREE(sys->edges);
MEM_SAFE_FREE(sys->faces_edge);
@@ -153,51 +109,12 @@ static void deleteLaplacianSystem(LaplacianSystem *sys)
MEM_SAFE_FREE(sys->ringf_map);
MEM_SAFE_FREE(sys->ringv_map);
MEM_SAFE_FREE(sys->ringe_map);
- for (i = 0; i < sys->total_gflines; i++) {
- MEM_SAFE_FREE(sys->gflines[i].edges);
- MEM_SAFE_FREE(sys->gflines[i].index);
- }
- MEM_SAFE_FREE(sys->gflines);
if (sys->context) {
nlDeleteContext(sys->context);
}
MEM_SAFE_FREE(sys);
}
-static int insertNewGradienFlowLine(LaplacianSystem *sys, int total_allocated, int delta){
- int total;
- total = total_allocated;
- if (sys->total_gflines == total_allocated){
- total += delta;
- sys->gflines = MEM_reallocN(sys->gflines, sizeof(GradientFlowLine)* total);
- }
-
- return total;
-}
-
-static int insertVertToGradientFlowLine(LaplacianSystem *sys, GradientFlowLine *gfl, int inedge, float v[3], int total_allocated, int delta){
- int total;
- total = total_allocated;
- if (sys->total_gfverts == total_allocated){
- total += delta;
- sys->cogfl = MEM_reallocN(sys->cogfl, sizeof(float)* 3 * total);
- }
-
- if (gfl->total_allocated == gfl->total_verts) {
- gfl->total_allocated += delta;
- gfl->edges = MEM_reallocN(gfl->edges, sizeof(int)* gfl->total_allocated);
- gfl->index = MEM_reallocN(gfl->index, sizeof(int)* gfl->total_allocated);
- }
-
- copy_v3_v3(sys->cogfl[sys->total_gfverts], v);
-
- gfl->edges[gfl->total_verts] = inedge;
- gfl->index[gfl->total_verts] = sys->total_gfverts;
- sys->total_gfverts = sys->total_gfverts + 1;
- gfl->total_verts = gfl->total_verts + 1;
- return total;
-}
-
static void createFaceRingMap(
const int mvert_tot, const MFace *mface, const int mface_tot,
MeshElemMap **r_map, int **r_indices)
@@ -495,60 +412,6 @@ static void computeScalarField(LaplacianSystem *sys)
#endif
}
-/*
-* Return 1 if the intersections exist
-* Return -1 if the intersections does not exist
-*/
-static int computeIsectLineWithEdge(float r[3], float p1[3], float p2[3], float ori[3], float dir[3])
-{
- float v[3], i1[3], i2[3];
- int i;
- //isect_line_line_v3
-
- add_v3_v3v3(v, ori, dir);
- i = isect_line_line_v3(p1, p2, ori, v, i1, i2);
- if (i == 0) {
- sub_v3_v3v3(i1, p1, ori);
- normalize_v3(i1);
- if (equals_v3v3(i1, dir)) {
- copy_v3_v3(r, p1);
- }
- else {
- copy_v3_v3(r, p2);
- }
- }
- else {
- sub_v3_v3v3(v, i1, ori);
- normalize_v3(v);
- if (equals_v3v3(v, dir)) {
- copy_v3_v3(r, i1);
- }
- else {
- return -1;
- }
- }
- return 1;
-}
-
-/*
-* Return 1 if the intersections exist
-* Return -1 if the intersections does not exist
-*/
-static int computeIsectLineWithTriangle(float r[3], float p1[3], float p2[3], float p3[3], float ori[3], float dir[3])
-{
- if (computeIsectLineWithEdge(r, p1, p2, ori, dir) == 1) {
- return 1;
- }
- else if (computeIsectLineWithEdge(r, p2, p3, ori, dir) == 1) {
- return 1;
- }
- else if (computeIsectLineWithEdge(r, p3, p1, ori, dir) == 1) {
- return 1;
- }
- return -1;
-
-}
-
/**
* Compute the gradient fields
*
@@ -630,393 +493,6 @@ static void uniformRandomPointWithinFace(float r[3], LaplacianSystem *sys, int i
uniformRandomPointWithinTriangle(r, sys->co[vin[0]], sys->co[vin[1]], sys->co[vin[2]]);
}
-static int getEdgeFromVerts(LaplacianSystem *sys, int v1, int v2)
-{
- int *eidn, nume, i;
- nume = sys->ringe_map[v1].count;
- eidn = sys->ringe_map[v1].indices;
- for (i = 0; i < nume; i++) {
- if (sys->edges[eidn[i]][0] == v2 || sys->edges[eidn[i]][1] == v2){
- return eidn[i];
- }
- }
- return -1;
-}
-
-static bool isBetweenLine(float p1[3], float p2[3], float q[3]){
- if ( (q[0] >= min_ff(p1[0], p2[0]))
- && (q[1] >= min_ff(p1[1], p2[1]))
- && (q[2] >= min_ff(p1[2], p2[2]))
- && (q[0] <= max_ff(p1[0], p2[0]))
- && (q[1] <= max_ff(p1[1], p2[1]))
- && (q[2] <= max_ff(p1[2], p2[2]))
- ) {
- return true;
- }
- return false;
-}
-
-static int getDifferentVertexFaceEdge(LaplacianSystem *sys, int oldface, int inde)
-{
- int i1, i2, i3;
- i1 = sys->edges[inde][0];
- i2 = sys->edges[inde][1];
-
- if (i1 == sys->faces[oldface][0]) {
- if (i2 == sys->faces[oldface][1]) {
- i3 = sys->faces[oldface][2];
- }
- else {
- i3 = sys->faces[oldface][1];
- }
- }
- else if (i1 == sys->faces[oldface][1]) {
- if (i2 == sys->faces[oldface][2]) {
- i3 = sys->faces[oldface][0];
- }
- else {
- i3 = sys->faces[oldface][2];
- }
- }
- else {
- if (i2 == sys->faces[oldface][0]) {
- i3 = sys->faces[oldface][1];
- }
- else {
- i3 = sys->faces[oldface][0];
- }
- }
-
- return i3;
-}
-
-/**
-* return -1 if max U was found
-* float r[3] vertex with next point on flow line
-* float q[3] actual point on flow line.
-* int olface index of old face
-* int inde edge from origin of actual point
-*/
-static int nextPointFlowLine(float r[3], LaplacianSystem *sys, float q[3], int oldface, int inde)
-{
- float v1[3], v2[3], dir[3], dq[3], res[3], r2[3];
- float u1, u2, u3, u4, maxu;
- int i1, i2, i3, i4, ix;
- int newface, fs[2];
- int numv, *vidn;
- int i, iu, ie, isect;
- i1 = sys->edges[inde][0];
- i2 = sys->edges[inde][1];
- copy_v3_v3(v1, sys->co[i1]);
- copy_v3_v3(v2, sys->co[i2]);
- i3 = getDifferentVertexFaceEdge(sys, oldface, inde);
- u1 = sys->U_field[i1];
- u2 = sys->U_field[i2];
- u3 = sys->U_field[i3];
- copy_v2_v2_int(fs, sys->faces_edge[inde]);
- //getFacesAdjacentToEdge(fs, sys, inde);
- newface = fs[0] == oldface ? fs[1] : fs [0];
- i4 = getDifferentVertexFaceEdge(sys, newface, inde);
- u4 = sys->U_field[i4];
-
- /* The actual point on flow line correspond to a vertex in a mesh */
- if (equals_v3v3(q, v1) || equals_v3v3(q, v2)) {
- ix = equals_v3v3(q, v1) ? i1 : i2;
- numv = sys->ringv_map[ix].count;
- vidn = sys->ringf_map[ix].indices;
- iu = -1;
- maxu = -1000000;
- for (i = 0; i < numv; i++) {
- if (vidn[i] != ix) {
- if (sys->U_field[ix] < sys->U_field[vidn[i]]) {
- if (maxu < sys->U_field[vidn[i]]){
- iu = vidn[i];
- maxu = sys->U_field[vidn[i]];
- }
-
- }
- }
- }
- /*Max U found*/
- if (iu == -1) {
- printf("/*Max U found*/\n");
- return -1;
- }
-
- ie = getEdgeFromVerts(sys, ix, iu);
-
- //getFacesAdjacentToEdge(fs, sys, ie);
- copy_v2_v2_int(fs, sys->faces_edge[ie]);
- i1 = ix;
- i2 = iu;
- i3 = getDifferentVertexFaceEdge(sys, fs[0], ie);
- i4 = getDifferentVertexFaceEdge(sys, fs[1], ie);
- u1 = sys->U_field[i1];
- u2 = sys->U_field[i2];
- u3 = sys->U_field[i3];
- u3 = sys->U_field[i4];
-
- /* the next point is the opposite vertex in the edge*/
- if (u2 >= u3 && u2 >= u4 && u1 >= u3 && u1 >= u4) {
- copy_v3_v3(r, sys->co[iu]);
- return ie;
-
- /* the next point is on face fs[0]*/
- } else if (u3 >= u4) {
- copy_v3_v3(dir, sys->gf1[fs[0]]);
- //projectGradientOnFace(dir, sys, sys->gf1, fs[0]);
- mul_v3_fl(dir, 100);
- add_v3_v3v3(dq, q, dir);
- isect = isect_line_line_v3(sys->co[i3], sys->co[i2], q, dq, res, r2);
- copy_v3_v3(r, res);
- return ie;
- /* the next point is on face fs[1]*/
- } else {
- copy_v3_v3(dir, sys->gf1[fs[1]]);
- //projectGradientOnFace(dir, sys, sys->gf1, fs[1]);
- mul_v3_fl(dir, 100);
- add_v3_v3v3(dq, q, dir);
- isect = isect_line_line_v3(sys->co[i4], sys->co[i2], q, dq, res, r2);
- copy_v3_v3(r, res);
- return ie;
- }
-
- /* There is simple intersection on new face adjacent to inde */
- } else if (u1 <= u3 && u2 <= u3) {
- copy_v3_v3(dir, sys->gf1[newface]);
- //projectGradientOnFace(dir, sys, sys->gf1, newface);
- mul_v3_fl(dir, 100);
- add_v3_v3v3(dq, q, dir);
- if (u1 >= u2) {
- isect = isect_line_line_v3(sys->co[i3], sys->co[i1], q, dq, res, r2);
- copy_v3_v3(r, res);
- return getEdgeFromVerts(sys, i3,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list