Index: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp	(revision 2090)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp	(revision 2127)
@@ -53,6 +53,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 
-int VMI::findEdge(Edge *e, GLuint num, GLuint _u, GLuint _v) {
-    GLuint i, u, v;
+int VMI::findEdge(Edge *e, int num, int _u, int _v) {
+    int i, u, v;
     int found = -1; 
 
@@ -85,8 +85,4 @@
 		newList[*n].u = u;
     newList[*n].v = v;
-
-		// This edge has no triangle adjancency
-		newList[*n].numTriangles = 0;
-		newList[*n].triangles = NULL;
 		
 		// Enable the new edge
@@ -102,6 +98,50 @@
 }
 
+double VMI::computeEdgeLength(Vertex *vertices, int u, int v) {
+    float ux, uy, uz, vx, vy ,vz, rx, ry, rz;
+    
+    ux = vertices[u].x;
+    uy = vertices[u].y;
+    uz = vertices[u].z;
+
+    vx = vertices[v].x;
+    vy = vertices[v].y;
+    vz = vertices[v].z;
+
+    rx = ux - vx;
+    ry = uy - vy;
+    rz = uz - vz;
+
+    return sqrt((rx * rx) + (ry * ry) + (rz * rz));
+}
+
+double VMI::computeTriangleVolume(Vertex *vertices, Triangle *t) {
+    int i;
+    double m[3][3], vol;
+    
+    // Compute triangle Volume
+    i = t->indices[0];
+    m[0][0] = mesh->vertices[i].x;
+    m[0][1] = mesh->vertices[i].y;
+    m[0][2] = mesh->vertices[i].z;
+    
+    i = t->indices[1];
+    m[1][0] = mesh->vertices[i].x;
+    m[1][1] = mesh->vertices[i].y;
+    m[1][2] = mesh->vertices[i].z;
+
+    i = t->indices[2];
+    m[2][0] = mesh->vertices[i].x;
+    m[2][1] = mesh->vertices[i].y;
+    m[2][2] = mesh->vertices[i].z;
+    
+    vol = computeMatDet(m);
+    
+    //printf("Triangle Volume: %f\n", vol)
+    return vol;  
+}
+
 GLdouble VMI::computeTriangleArea(Vertex *vertices, Triangle *t) {
-    GLuint i;
+    int i;
     GLdouble v0[3], v1[3], v2[3], a;
     
@@ -129,5 +169,5 @@
 
 void VMI::computeTriangleNormal(Vertex *vertices, Triangle *t) {
-    GLuint i;
+    int i;
     GLfloat x0, y0, z0,
             x1, y1, z1,
@@ -175,5 +215,5 @@
 Mesh *VMI::initMesh(GLMmodel* pmodel) {
 
-    GLuint i, j, curGroup, v1, v2, v3, n, m, t;
+    int i, j, curGroup, v1, v2, v3, n, m, t;
     int e;
     Mesh *mesh;
@@ -202,5 +242,5 @@
     
     printf("Adding vertices...");
-    for (i=1; i<=pmodel->numvertices; i++) { // Vertices start at 1
+    for (i=1; i<=(int)pmodel->numvertices; i++) { // Vertices start at 1
         mesh->vertices[i - 1].x = pmodel->vertices[3 * i + 0];
         mesh->vertices[i - 1].y = pmodel->vertices[3 * i + 1];
@@ -208,4 +248,6 @@
         mesh->vertices[i - 1].numTriangles = 0;
         mesh->vertices[i - 1].triangles = NULL;
+				mesh->vertices[i - 1].numEdges = 0;
+        mesh->vertices[i - 1].edges = NULL;
         mesh->vertices[i - 1].enable = GL_TRUE;
     }
@@ -221,5 +263,5 @@
     while(group) {
         
-        for (i=0; i<group->numtriangles; i++) {
+        for (i=0; i<(int)group->numtriangles; i++) {
             
             t = group->triangles[i];
@@ -244,5 +286,5 @@
                 // Reallocate memory for the new adjacent triangle
                 mesh->vertices[v1].triangles = 
-					(GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint));
+					(int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int));
                 addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, t);
             }
@@ -254,7 +296,7 @@
     for (i=0; i<pmodel->numtriangles; i++) {
         mesh->triangles[i].id = i;
-        mesh->triangles[i].indices[0] = pmodel->triangles[i].vindices[0] - 1;
-        mesh->triangles[i].indices[1] = pmodel->triangles[i].vindices[1] - 1;
-        mesh->triangles[i].indices[2] = pmodel->triangles[i].vindices[2] - 1;
+        mesh->triangles[i].indices[0] = (int)pmodel->triangles[i].vindices[0] - 1;
+        mesh->triangles[i].indices[1] = (int)pmodel->triangles[i].vindices[1] - 1;
+        mesh->triangles[i].indices[2] = (int)pmodel->triangles[i].vindices[2] - 1;
         mesh->triangles[i].area = computeTriangleArea(mesh->vertices, &mesh->triangles[i]);
         //printf("\n%d a: %f",i , mesh->triangles[i].area);
@@ -271,5 +313,5 @@
             // Reallocate memory for the new adjacent triangle
             mesh->vertices[v1].triangles = 
-			    (GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint));
+			    (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int));
             addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, i);
         }
@@ -304,19 +346,8 @@
             mesh->edges[n].u = v1;
             mesh->edges[n].v = v2;
-						mesh->edges[n].triangles    = NULL;
-        		mesh->edges[n].numTriangles = 0;
             mesh->edges[n].enable = GL_TRUE;
             m = n;
             n++;
         } else m = e;
-		// Reallocate memory for the new adjacent triangle
-        mesh->edges[m].triangles = 
-			(GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint));
-        // Adding triangle i adjacent to edge m
-        addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i);
-        //printf("n:%d i:%d\n", m, i);
-        
-        // Adding edge m adjacent to triangle i
-        addItem((int *)mesh->triangles[i].edges, (int *)&t, m);
 
         /////////////////////////////////////////////////////////////////////////////////
@@ -325,19 +356,8 @@
             mesh->edges[n].u = v2;
             mesh->edges[n].v = v3;
-						mesh->edges[n].triangles    = NULL;
-        		mesh->edges[n].numTriangles = 0;
             mesh->edges[n].enable = GL_TRUE;
             m = n;
             n++;
         } else m = e;
-		// Reallocate memory for the new adjacent triangle
-        mesh->edges[m].triangles = 
-			(GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint));
-        // Adding triangle i adjacent to edge m
-        addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i);
-        //printf("n:%d i:%d\n", m, i);
-        
-        // Adding edge m adjacent to triangle i
-        addItem((int *)mesh->triangles[i].edges, (int *)&t, m);
 
         /////////////////////////////////////////////////////////////////////////////////
@@ -346,28 +366,32 @@
             mesh->edges[n].u = v3;
             mesh->edges[n].v = v1;
-						mesh->edges[n].triangles    = NULL;
-        		mesh->edges[n].numTriangles = 0;
             mesh->edges[n].enable = GL_TRUE;
             m = n;
             n++;
         } else m = e;
-		// Reallocate memory for the new adjacent triangle
-        mesh->edges[m].triangles = 
-			(GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint));
-        // Adding triangle i adjacent to edge m
-        addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i);
-        //printf("n:%d i:%d\n", m, i);
-        
-        // Adding edge m adjacent to triangle i
-        addItem((int *)mesh->triangles[i].edges, (int *)&t, m);
     }
     printf("Ok\n");
     mesh->numEdges = n;
 
+		for (i=0; i<mesh->numEdges; i++) {
+			v1 = mesh->edges[i].u;
+			v2 = mesh->edges[i].v;
+
+			mesh->vertices[v1].edges = 
+				(int *)realloc(mesh->vertices[v1].edges, (mesh->vertices[v1].numEdges + 1) * sizeof(int));
+			// Adding edge i adjacent to vertex v1
+			addItem(mesh->vertices[v1].edges, &mesh->vertices[v1].numEdges, i);
+
+			mesh->vertices[v2].edges = 
+				(int *)realloc(mesh->vertices[v2].edges, (mesh->vertices[v2].numEdges + 1) * sizeof(int));
+			// Adding edge i adjacent to vertex v2
+			addItem(mesh->vertices[v2].edges, &mesh->vertices[v2].numEdges, i);
+		}
+
     return mesh;
 }
 
 void VMI::printMesh(Mesh *mesh) {
-    GLuint i, j;
+    int i, j;
 
     printf("Vertices (%d)\n", mesh->numVertices);
@@ -385,4 +409,13 @@
         }
         printf("]\n");
+
+					printf("  e(%d)[", mesh->vertices[i].numEdges);
+        if (mesh->vertices[i].edges != NULL) {
+            printf("%d", mesh->vertices[i].edges[0]);
+            for (j=1; j<mesh->vertices[i].numEdges; j++) {
+                printf(",%d", mesh->vertices[i].edges[j]);
+            }
+        }
+        printf("]\n");
     }
 
@@ -391,12 +424,4 @@
     for (i=0; i<mesh->numEdges; i++) {
         printf("e%d (%d,%d) %d\n", i, mesh->edges[i].u, mesh->edges[i].v, mesh->edges[i].enable);
-        printf("  t(%d)[", mesh->edges[i].numTriangles);
-        if (mesh->edges[i].triangles != NULL) {
-            printf("%d", mesh->edges[i].triangles[0]);
-            for (j=1; j<mesh->edges[i].numTriangles; j++) {
-                printf(",%d", mesh->edges[i].triangles[j]);
-            }
-				}
-        printf("]\n");
     }
 
@@ -406,10 +431,4 @@
         printf("t%d (%d,%d,%d) %d\n", i, mesh->triangles[i].indices[0], mesh->triangles[i].indices[1],
                                      mesh->triangles[i].indices[2],  mesh->triangles[i].enable);
-        printf("  e(3)[");
-        printf("%d", mesh->triangles[i].edges[0]);
-        for (j=1; j<3; j++) {
-            printf(",%d", mesh->triangles[i].edges[j]);
-        }
-        printf("]\n");
 
         printf("  n(3)[");
@@ -425,5 +444,5 @@
 
 void VMI::deleteMesh(Mesh *mesh) {
-	GLuint i;
+	int i;
 
 	if (NULL != mesh) {
@@ -432,12 +451,11 @@
 				free(mesh->vertices[i].triangles);
 
+			if (mesh->vertices[i].edges != NULL)
+				free(mesh->vertices[i].edges);
+
 		}
 		if (mesh->vertices != NULL) free(mesh->vertices);
 		mesh->numVertices = 0;
 
-		for (i=0; i<mesh->numEdges; i++) {
-			if (mesh->edges[i].triangles != NULL)
-				free(mesh->edges[i].triangles);
-		}
 		if (mesh->edges != NULL) free(mesh->edges);
 		mesh->numEdges = 0;
@@ -525,50 +543,4 @@
 }
 
-int *VMI::edgesAdjToVertex(Mesh *mesh, int v, int *n) {
-    int *edges = NULL;
-    int i, t, e;
-#ifndef USE_EDGE_ADJACENCY
-    int n0, n1, n2;
-#else
-    int j;
-#endif
-    int num = 0;
-
-	if (mesh->vertices[v].numTriangles > 0) 
-		edges = (int*)malloc(sizeof(int) * mesh->vertices[v].numTriangles * 2);
-
-    for (i=0; i<(int)mesh->vertices[v].numTriangles; i++) {
-
-        t = mesh->vertices[v].triangles[i];
-
-#ifdef USE_EDGE_ADJACENCY
-        for (j=0; j<3; j++) {
-            e = mesh->triangles[t].edges[j];
-            
-            if ((int)mesh->edges[e].u == v || (int)mesh->edges[e].v == v)
-                
-                addItem(edges, &num, e);
-        }
-#else
-        n0 = mesh->triangles[t].indices[0];
-        n1 = mesh->triangles[t].indices[1];
-        n2 = mesh->triangles[t].indices[2];
-        
-        if (((n0 == v) || (n1 == v)) &&
-            ((e = findEdge(mesh->edges, mesh->numEdges, n0, n1)) != -1)) addItem(edges, &num, e);
- 
-        if (((n1 == v) || (n2 == v)) &&
-            ((e = findEdge(mesh->edges, mesh->numEdges, n1, n2)) != -1)) addItem(edges, &num, e);
-        
-        if (((n0 == v) || (n2 == v)) &&
-            ((e = findEdge(mesh->edges, mesh->numEdges, n0, n2)) != -1)) addItem(edges, &num, e);
-
-#endif
-    }
-    *n = num;
-
-    return edges;
-}
-
 int *VMI::edgesAdjToVertices(Mesh *mesh, int *vertices, int numVertices, int *n) {
     int *edges = NULL;
@@ -578,5 +550,6 @@
     if (numVertices > 0) {
         // Add the first
-        list = edgesAdjToVertex(mesh, vertices[0], &numEdges);
+		list = mesh->vertices[vertices[0]].edges;
+		numEdges = mesh->vertices[vertices[0]].numEdges;
 
         // Allocate memory
@@ -585,6 +558,4 @@
         memcpy(edges, list, sizeof(int) * numEdges);
 
-        free(list);
-
         num = numEdges;
 
@@ -592,8 +563,9 @@
         for (i=1; i<numVertices; i++) {
 
-            list = edgesAdjToVertex(mesh, vertices[i], &numEdges);
+			list = mesh->vertices[vertices[i]].edges;
+		    numEdges = mesh->vertices[vertices[i]].numEdges;
 
             // Reallocate memory
-			if (numEdges > 0) {
+            if (numEdges > 0) {
 
                 edges = (int *)realloc(edges, (num + numEdges + 1) * sizeof(int));
@@ -601,6 +573,5 @@
                 for (j=0; j<numEdges; j++)
                     addItem(edges, &num, list[j]);
-			}
-            free(list);
+            }
         }
     }
@@ -610,7 +581,7 @@
 }
 
-GLboolean VMI::findVertex(GLfloat *vertices, GLuint num, GLfloat x, GLfloat y, GLfloat z, int *pos) {
-    GLuint i;
-    GLfloat _x, _y, _z;
+GLboolean VMI::findVertex(float *vertices, int num, float x, float y, float z, int *pos) {
+    int i;
+    float _x, _y, _z;
     GLboolean found = GL_FALSE; 
     
@@ -648,4 +619,7 @@
 		newList[*n].numTriangles = 0;
 		newList[*n].triangles = NULL;
+
+		newList[*n].numEdges= 0;
+		newList[*n].edges = NULL;
 	
     // Enable the new vertex
@@ -663,8 +637,8 @@
 
 
-void VMI::updateModel(GLMmodel* pmodel, Mesh *mesh, GLuint numVertices, GLuint numTriangles) {
-    GLuint i , v1, v2 ,v3, numV = 1, numT = 0;
+void VMI::updateModel(GLMmodel* pmodel, Mesh *mesh, int numVertices, int numTriangles) {
+    int i , v1, v2 ,v3, numV = 1, numT = 0;
     int pos;
-    GLfloat x, y, z;
+    float x, y, z;
     
     if (pmodel->vertices != NULL) free(pmodel->vertices);
@@ -726,5 +700,5 @@
 
 void VMI::saveModel(char *filename, GLMmodel* pmodel, Mesh *mesh) {
-    GLuint i, j, g, numT = 0;
+    int i, j, g, numT = 0;
     GLMgroup *group;
 
