Ignore:
Timestamp:
02/19/07 09:16:59 (18 years ago)
Author:
gumbau
Message:
 
Location:
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi
Files:
2 added
2 deleted
19 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/camera.h

    r2090 r2127  
    1818} Camera; 
    1919 
    20 extern Camera *loadCameras(GLdouble radius, char* filename, GLuint *numCameras); 
    21 extern void saveCameras(char* filename, Camera *cameras, GLuint numCameras); 
     20extern Camera *loadCameras(GLdouble radius, char* filename, int *numCameras); 
     21extern void saveCameras(char* filename, Camera *cameras, int numCameras); 
    2222extern void copyToCameras(Camera *cameras, int numVertices, GLdouble vertices[][3]); 
    23 extern void setCameraWeights(Camera *cameras, GLuint numCameras, GLdouble *weights); 
    24 extern Camera *setCameras(GLdouble radius, GLuint type, GLuint *numCameras); 
    25 extern void printCameras(Camera *cameras, GLuint numCameras); 
     23extern void setCameraWeights(Camera *cameras, int numCameras, GLdouble *weights); 
     24extern Camera *setCameras(GLdouble radius, int type, int *numCameras); 
     25extern void printCameras(Camera *cameras, int numCameras); 
    2626 
    2727extern void drawSphere(Camera *cameras, GLdouble radius, int slices, int stacks); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/change.h

    r2090 r2127  
    6868        extern void modifyTriangle(Triangle *t, int c, int p); 
    6969        extern int isATriangleToModify(Triangle *t, int c); 
    70         extern Triangle *getTrianglesToModify(Mesh *mesh, Change *c, GLuint *numMod); 
     70        extern Triangle *getTrianglesToModify(Mesh *mesh, Change *c, int *numMod); 
    7171        extern int isATriangleToDelete(Triangle *t, int c, int p); 
    72         extern Triangle *getTrianglesToDelete(Mesh *mesh, Change *c, GLuint *numDel); 
     72        extern Triangle *getTrianglesToDelete(Mesh *mesh, Change *c, int *numDel); 
    7373 
    7474        extern void modifyTriangles(Mesh *mesh, Change *c); 
     
    8585 
    8686        extern void modifyEdges(Mesh *mesh, Change *c); 
    87   extern void deleteEdges(Mesh *mesh, Change *c); 
     87  extern int find(int *edges, int num, int v_); 
     88        extern void updateEdgeAdj(Mesh *mesh, Change *c) ; 
    8889 
    8990        //      Save simplification sequence in Geometry Game Tools format. 
     
    9293        //extern std::map<int, INTVECTOR> inversemap; 
    9394        extern void swap(int *i, int *j); 
    94         extern int hasEdge(Triangle *t, int e); 
    95         extern void getEdges(Triangle *t, Change *c, int *d, int *a); 
     95 
    9696} 
    9797#endif 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/color.h

    r2090 r2127  
    1414} Color; 
    1515 
    16 extern Color *initColors(GLuint numColors); 
    17 extern void fillAllColors(Color *colors, GLuint numColors, GLuint begin, GLuint end, GLubyte color); 
    18 extern void setColors(Color *colors, GLuint numPasses, GLuint begin, GLuint end); 
    19 extern void setColors2(Color *colors, GLuint numColors, GLuint begin, GLuint end); 
    20 extern void setColors3(Color *colors, GLuint numColors, GLubyte color); 
    21 extern void setColors4(Color *colors, GLuint numColors); 
    22 extern void viewColors(Color *colors, GLuint numColors); 
     16extern Color *initColors(int numColors); 
     17extern void fillAllColors(Color *colors, int numColors, int begin, int end, GLubyte color); 
     18extern void setColors(Color *colors, int numPasses, int begin, int end); 
     19extern void setColors2(Color *colors, int numColors, int begin, int end); 
     20extern void setColors3(Color *colors, int numColors, GLubyte color); 
     21extern void setColors4(Color *colors, int numColors); 
     22extern void viewColors(Color *colors, int numColors); 
    2323 
    2424} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/global.h

    r2090 r2127  
    6060//#define SALIENCY 
    6161 
     62#define CHECK_LOCAL_INVERSION 
     63 
    6264// Extension added into the filename 
    6365#ifdef KL // Kullback-Leibler 
     
    7375#define EXT "VCS" 
    7476#endif 
    75  
    76 //#define USE_EDGE_ADJACENCY 
    7777 
    7878#define CHECK_OPENGL_ERROR( cmd ) \ 
     
    109109 
    110110extern Camera *cameras; 
    111 extern GLuint numCameras; 
     111extern int numCameras; 
    112112 
    113113extern Color *colors; 
    114114 
    115 extern GLuint **histogram, 
    116               *queries; 
     115extern int **histogram; 
     116extern GLuint *queries; 
    117117 
    118118extern Mesh *mesh; 
     
    122122extern GLdouble  radius; 
    123123extern GLdouble  fov; 
    124 extern GLuint    numDemandedTriangles, 
     124extern int    numDemandedTriangles, 
    125125                 cameraType; 
    126126extern GLboolean bBeQuiet, 
     
    138138extern void init(void); 
    139139 
    140 extern void renderScene(GLuint **histogram, GLuint numCameras); 
    141 extern void renderSceneWin(GLuint **histogram, GLuint numCameras, Change *c); 
     140extern void resetProjectedAreas(int **histogram, int numCameras); 
     141extern void getProjectedAreas(int **histogram, int numCameras); 
     142extern void getProjectedAreasWin(int **histogram, int numCameras, Change *c); 
    142143 
    143144extern void renderGeometry(void); 
     
    150151 
    151152extern void applyHWAcceleration(void); 
     153extern void updateHWAcceleration(Change *c); 
    152154extern void setOrthographicProjection(void); 
    153155extern void resetPerspectiveProjection(void); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/histogram.h

    r2090 r2127  
    1111{ 
    1212 
    13 extern void getSubHistogram(GLuint subHistoGram[][4]); 
    14 extern void copySubHistogram(Color *colors, GLuint *histogram, GLuint begin, GLuint end, GLuint subHistoGram[][4]); 
    15 extern void printHistogram(GLuint histoGram[][4]); 
    16 extern void plotHistogram(GLuint histoGram[][4]); 
     13extern void getSubHistogram(int subHistoGram[][4]); 
     14extern void copySubHistogram(Color *colors, int *histogram, int begin, int end, int subHistoGram[][4]); 
     15extern void printHistogram(int histoGram[][4]); 
     16extern void plotHistogram(int histoGram[][4]); 
    1717 
    18 extern GLuint **initHistogram(GLuint numTriangles, GLuint numCameras); 
    19 extern void deleteHistogram(GLuint **histogram, GLuint numCameras); 
    20 extern void printFullHistogram(GLuint **histogram, GLuint numCameras, GLuint numTriangles); 
    21 extern void getSWHistogram(GLuint *histogram, GLubyte *pixels); 
    22 extern void getSWHistogramWin(GLuint *histogram, GLubyte *pixels, GLfloat min[3], GLfloat max[3], Change *c); 
    23 extern void getSWHistoByOcclusionQuery(Mesh *mesh, Color *colors, GLuint *histogram); 
     18extern int **initHistogram(int numTriangles, int numCameras); 
     19extern void deleteHistogram(int **histogram, int numCameras); 
     20extern void printFullHistogram(int **histogram, int numCameras, int numTriangles); 
     21extern void getSWHistogram(int *histogram, GLubyte *pixels); 
     22extern void getSWHistogramWin(int *histogram, GLubyte *pixels, GLfloat min[3], GLfloat max[3], Change *c); 
     23extern void getSWHistoByOcclusionQuery(Mesh *mesh, Color *colors, int *histogram); 
    2424 
    25 extern void resetSWHistogram(GLuint *histogram, GLuint numTriangles); 
     25extern void resetSWHistogram(int *histogram, int numTriangles); 
    2626extern void getBoundingBox(Change *c, GLfloat min[3], GLfloat max[3]); 
    2727extern void getWindow(GLfloat min[3], GLfloat max[3], int minw[2], int maxw[2]); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/mesh.h

    r2090 r2127  
    77 
    88typedef struct _Vertex { 
    9     GLfloat x, y, z;     // Vertex coordinates 
    10     GLuint numTriangles; // Number of triangles  
    11     GLuint *triangles;   // List of triangles 
     9    float x, y, z;     // Vertex coordinates 
     10    int numTriangles; // Number of triangles  
     11    int *triangles;   // List of triangles 
     12                int numEdges; 
     13          int *edges; 
    1214    int enable; 
    1315                int     movable;        //      If vertex is part of a border. 
     
    1517 
    1618typedef struct _Edge { 
    17     GLuint u, v;         // Edge vertices 
    18     GLuint *triangles;   // Edge triangles 
    19     GLuint numTriangles; // Number of triangles 
     19    int u, v;         // Edge vertices 
    2020    int enable; 
    2121} Edge; 
    2222 
    2323typedef struct _Triangle { 
    24     GLuint              id;         // Triangle id 
    25     GLuint  group;        // Triangle group 
    26                 GLuint          submesh;                // Triangle submesh      
    27     GLuint              indices[3]; // Triangle vertices 
    28     GLuint              edges[3];   // Triangle edges 
    29     GLfloat             normal[3];  // Triangle normal 
    30     GLdouble    area;       // Triangle area 
    31     GLdouble    saliency;   // Triangle saliency 
     24    int         id;         // Triangle id 
     25    int  group;        // Triangle group 
     26                int             submesh;                // Triangle submesh      
     27    int         indices[3]; // Triangle vertices 
     28    float               normal[3];  // Triangle normal 
     29    double      area;       // Triangle area 
     30    double      saliency;   // Triangle saliency 
    3231    int                         enable; 
    3332} Triangle; 
     
    3534typedef struct _Mesh { 
    3635    Vertex *vertices;           // Mesh vertices 
    37     GLuint numVertices;         // Number of vertices 
    38     GLuint currentNumVertices;  // Current number of vertices 
     36    int numVertices;         // Number of vertices 
     37    int currentNumVertices;  // Current number of vertices 
    3938    Edge *edges;                // Mesh edges 
    40     GLuint numEdges;            // Number of edges 
     39    int numEdges;            // Number of edges 
    4140    Triangle *triangles;        // Mesh triangles 
    42     GLuint numTriangles;        // Number of triangles 
    43     GLuint currentNumTriangles; // Current number of triangles 
     41    int numTriangles;        // Number of triangles 
     42    int currentNumTriangles; // Current number of triangles 
    4443} Mesh; 
    4544 
    4645extern GLdouble computeTriangleArea(Vertex *vertices, Triangle *t); 
     46extern double computeEdgeLength(Vertex *vertices, int u, int v); 
    4747extern void computeTriangleNormal(Vertex *vertices, Triangle *t); 
     48extern double computeTriangleVolume(Vertex *vertices, Triangle *t); 
    4849 
    4950extern Vertex *addVertex(Vertex *list, int *n, float x, float y, float z, int *pos); 
    50 extern int findEdge(Edge *e, GLuint num, GLuint _u, GLuint _v); 
     51extern int findEdge(Edge *e, int num, int _u, int _v); 
    5152extern Edge *addEdge(Edge *list, int *n, int u, int v, int *pos); 
    52 extern GLboolean findVertex(GLfloat *vertices, GLuint num, GLfloat x, GLfloat y, GLfloat z, int *pos); 
     53extern GLboolean findVertex(float *vertices, int num, float x, float y, float z, int *pos); 
    5354 
    5455extern Mesh *initMesh(GLMmodel* pmodel); 
     
    5657extern void printMesh(Mesh *mesh); 
    5758extern void saveModel(char *filename, GLMmodel* pmodel, Mesh *mesh); 
    58 extern void updateModel(GLMmodel* pmodel, Mesh *mesh, GLuint numVertices, GLuint numTriangles); 
     59extern void updateModel(GLMmodel* pmodel, Mesh *mesh, int numVertices, int numTriangles); 
    5960 
    6061extern int *trianglesAdjToEdge(Mesh *mesh, int e, int *n); 
    6162extern int *verticesAdjToVertex(Mesh *mesh, int v, int *n); 
    62 extern int *edgesAdjToVertex(Mesh *mesh, int v, int *n); 
    6363extern int *edgesAdjToVertices(Mesh *mesh, int *vertices, int numVertices, int *n); 
    6464 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/metrics.h

    r2090 r2127  
    88namespace       VMI 
    99{ 
    10 extern GLdouble computeMI(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint cam); 
    11 extern GLdouble decMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c); 
    12 extern GLdouble incMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c); 
     10extern GLdouble computeMI(Mesh *mesh, int **histogram, int numCameras, int cam); 
     11extern GLdouble decMI(GLdouble I, int **histogram, int numCameras, int cam, Change *c); 
     12extern GLdouble incMI(GLdouble I, int **histogram, int numCameras, int cam, Change *c); 
    1313 
    14 extern GLdouble computeHE(Mesh *mesh, GLuint *histogram); 
    15 extern GLdouble computeKL(Mesh *mesh, GLuint *histogram); 
    16 extern GLdouble computeCS(Mesh *mesh, GLuint *histogram); 
     14extern GLdouble computeHE(Mesh *mesh, int *histogram); 
     15extern GLdouble computeKL(Mesh *mesh, int *histogram); 
     16extern GLdouble computeCS(Mesh *mesh, int *histogram); 
    1717 
    18 extern GLdouble computeMeanProjArea(GLuint **histogram, GLuint numCameras, int t); 
    19 extern GLdouble computeJS(GLuint **histogram, GLuint numCameras, GLuint j, GLuint k); 
    20 extern GLdouble computeEntropy(GLuint **histogram, GLuint numCameras, GLuint k); 
    21 extern GLdouble computeMixedEntropy(GLdouble *mixed, GLuint numCameras); 
    22 extern GLdouble computeMeanProjAreaNoBG(GLuint **histogram, GLuint numCameras, int t); 
     18extern GLdouble computeMeanProjArea(int **histogram, int numCameras, int t); 
     19extern GLdouble computeJS(int **histogram, int numCameras, int j, int k); 
     20extern GLdouble computeEntropy(int **histogram, int numCameras, int k); 
     21extern GLdouble computeMixedEntropy(GLdouble *mixed, int numCameras); 
     22extern GLdouble computeMeanProjAreaNoBG(int **histogram, int numCameras, int t); 
    2323 
    24 extern void getProjectedAreas(GLuint **histogram, GLuint numCameras); 
    25 extern void getProjectedAreasWin(GLuint **histogram, GLuint numCameras, Change *c); 
    26 extern void resetProjectedAreas(GLuint **histogram, GLuint numCameras); 
    27  
    28 extern GLdouble *initIs(GLuint numCameras); 
    29 extern void computeCameraIs(GLuint **histogram, GLuint numCameras, GLdouble *mis); 
    30 extern void printIs(GLdouble *mis, GLuint numCameras); 
     24extern GLdouble *initIs(int numCameras); 
     25extern void computeCameraIs(int **histogram, int numCameras, GLdouble *mis); 
     26extern void printIs(GLdouble *mis, int numCameras); 
    3127} 
    3228#endif 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/saliency.h

    r2090 r2127  
    1313extern double percentile; 
    1414 
    15 extern void computeSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras); 
    16 extern void updateTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, int v); 
     15extern void computeSaliency(Mesh *mesh, int **histogram, int numCameras); 
     16extern void updateTriangleSaliency(Mesh *mesh, int **histogram, int numCameras, int v); 
    1717 
    18 extern double computeTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint k); 
     18extern double computeTriangleSaliency(Mesh *mesh, int **histogram, int numCameras, int k); 
    1919 
    2020extern double computeEdgeSaliency(Mesh *mesh, Change *c, double p); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/simplify.h

    r2090 r2127  
    1919        extern bheap_t *updateHeap(bheap_t *h, Mesh *mesh, Change *c); 
    2020 
    21         extern void simplifyModel(Mesh *mesh, GLuint numDemandedTri); 
     21        extern void simplifyModel(Mesh *mesh, int numDemandedTri); 
    2222 
    2323 
    2424        extern void bh_mydump(Mesh *mesh, bheap_t *h); 
    25         extern GLdouble computeEdgeLength(Vertex *vertices, int u, int v); 
    2625 
    2726        extern void chooseBestEndPoints(Mesh *mesh, int e); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/vmi_simplifier.h

    r983 r2127  
    1313#include "saliency.h" 
    1414#include "simplify.h" 
    15 #include "interleave.h" 
     15#include "buffers.h" 
    1616 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/camera.cpp

    r2090 r2127  
    1414//#define DRAW_DEBUG // just for debugging not necessary 
    1515 
    16 Camera *VMI::loadCameras(GLdouble radius, char* filename, GLuint *numCameras) { 
     16Camera *VMI::loadCameras(GLdouble radius, char* filename, int *numCameras) { 
    1717    FILE *fp; 
    1818    Camera *cameras; 
    19     GLuint num, i; 
     19    int num, i; 
    2020    GLfloat eyeX, eyeY, eyeZ, 
    2121        centerX, centerY, centerZ, 
     
    118118} 
    119119 
    120 void VMI::saveCameras(char* filename, Camera *cameras, GLuint numCameras) { 
     120void VMI::saveCameras(char* filename, Camera *cameras, int numCameras) { 
    121121    FILE *fp; 
    122     GLuint i; 
     122    int i; 
    123123 
    124124    if((fp= fopen(filename, "wt"))== NULL) { 
     
    170170} 
    171171 
    172 Camera *VMI::setCameras(GLdouble radius, GLuint type, GLuint *numCameras) { 
     172Camera *VMI::setCameras(GLdouble radius, int type, int *numCameras) { 
    173173    Camera *cameras = NULL; 
    174174 
     
    221221} 
    222222 
    223 void VMI::setCameraWeights(Camera *cameras, GLuint numCameras, GLdouble *weights) { 
    224     GLuint i; 
     223void VMI::setCameraWeights(Camera *cameras, int numCameras, GLdouble *weights) { 
     224    int i; 
    225225 
    226226    for (i = 0; i<numCameras; i++) { 
     
    229229} 
    230230 
    231 void VMI::printCameras(Camera *cameras, GLuint numCameras) { 
    232     GLuint i; 
     231void VMI::printCameras(Camera *cameras, int numCameras) { 
     232    int i; 
    233233     
    234234    printf("\n"); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/change.cpp

    r2090 r2127  
    157157  if (c->numMod > 0) { 
    158158      mesh->vertices[c->v].triangles =  
    159           (GLuint *)realloc(mesh->vertices[c->v].triangles,  
    160           (mesh->vertices[c->v].numTriangles + mesh->vertices[c->u].numTriangles) * sizeof(GLuint)); 
     159          (int *)realloc(mesh->vertices[c->v].triangles,  
     160          (mesh->vertices[c->v].numTriangles + mesh->vertices[c->u].numTriangles) * sizeof(int)); 
    161161  } 
    162162 
     
    193193} 
    194194 
    195 int VMI::hasEdge(Triangle *t, int e) { 
    196     int e0 = t->edges[0], 
    197         e1 = t->edges[1], 
    198         e2 = t->edges[2]; 
    199      
    200     if ((e == e0) || (e == e1) || (e == e2)) return TRUE; 
    201  
    202     return FALSE; 
    203 } 
    204  
    205 void VMI::getEdges(Triangle *t, Change *c, int *l, int *r) { 
    206  
    207     // Default edges 
    208     *l = -1; 
    209     *r = -1; 
    210  
    211     // Set edge l and r 
    212     if ((int)t->edges[0] == c->e) { 
    213         *l = t->edges[1]; 
    214         *r = t->edges[2]; 
    215         if ((int)mesh->edges[*l].u == c->v || (int)mesh->edges[*l].v == c->v) 
    216             swap(l, r); 
    217     } else if ((int)t->edges[1] == c->e) { 
    218         *l = t->edges[0]; 
    219         *r = t->edges[2]; 
    220         if ((int)mesh->edges[*l].u == c->v || (int)mesh->edges[*l].v == c->v) 
    221             swap(l, r); 
    222     } else if ((int)t->edges[2] == c->e) { 
    223         *l = t->edges[0]; 
    224         *r = t->edges[1]; 
    225         if ((int)mesh->edges[*l].u == c->v || (int)mesh->edges[*l].v == c->v) 
    226             swap(l, r); 
    227     } 
    228 } 
    229  
    230195void VMI::swap(int *i, int *j) { 
    231196    int t; 
     
    238203void VMI::deleteTriangles(Mesh *mesh, Change *c) 
    239204{ 
    240             int i, j, t, v; 
    241 #ifdef USE_EDGE_ADJACENCY 
    242     int t1, l, r; 
    243 #endif 
     205          int i, j, t, v; 
    244206     
    245207    for (i=0; i<c->numDel; i++) { 
     
    255217        } 
    256218 
    257 #ifdef USE_EDGE_ADJACENCY 
    258         // Update triangle edge adjancency 
    259         // The modified triangles have to be calculated before 
    260         // Set edge l and r 
    261         getEdges(&c->deleted[i], c, &l, &r); 
    262         //printf("e%d(%d,%d): l:%d r:%d\n", c->e, c->u, c->v, l, r); 
    263         // Find triangle that contains edge l 
    264         for (j=0; j<c->numMod; j++) 
    265             if (hasEdge(&c->modified[j], l)) { 
    266                 // Change edge l by r in the Mesh 
    267                 t1 = c->modified[j].id; 
    268                 //printf("t:%d %d %d %d\n", t1, mesh->triangles[t1].edges[0], mesh->triangles[t1].edges[1] ,mesh->triangles[t1].edges[2]); 
    269                 if (mesh->triangles[t1].edges[0] == (GLuint)l) mesh->triangles[t1].edges[0] = r; 
    270                 if (mesh->triangles[t1].edges[1] == (GLuint)l) mesh->triangles[t1].edges[1] = r; 
    271                 if (mesh->triangles[t1].edges[2] == (GLuint)l) mesh->triangles[t1].edges[2] = r; 
    272                 //printf("t:%d %d %d %d\n", t1, mesh->triangles[t1].edges[0], mesh->triangles[t1].edges[1] ,mesh->triangles[t1].edges[2]); 
    273                 break; 
    274             } 
    275  
    276         // Delete edge l 
    277         if (l != -1) mesh->edges[l].enable = FALSE; 
    278 #endif 
    279219        mesh->triangles[t].enable = FALSE; 
    280220        mesh->currentNumTriangles--; 
     
    301241            addItem((int *)mesh->vertices[v].triangles,(int *)&mesh->vertices[v].numTriangles,t); 
    302242        } 
    303 #ifdef USE_EDGE_ADJACENCY 
    304         // Enable adjacent edges 
    305         for (j=0; j<3; j++) { 
    306             mesh->edges[mesh->triangles[t].edges[j]].enable = TRUE; 
    307         } 
    308 #endif 
     243 
    309244        mesh->triangles[t].enable = TRUE; 
    310245        mesh->currentNumTriangles++; 
     
    312247} 
    313248 
    314 Triangle *VMI::getTrianglesToModify(Mesh *mesh, Change *c, GLuint *numMod) { 
     249Triangle *VMI::getTrianglesToModify(Mesh *mesh, Change *c, int *numMod) { 
    315250  int i, t; 
    316251  Triangle *modified = NULL; 
     
    336271} 
    337272 
    338 Triangle *VMI::getTrianglesToDelete(Mesh *mesh, Change *c, GLuint *numDel) { 
     273Triangle *VMI::getTrianglesToDelete(Mesh *mesh, Change *c, int *numDel) { 
    339274  int i, t; 
    340275  Triangle *deleted = NULL; 
     
    359294} 
    360295 
    361 void VMI::deleteEdges(Mesh *mesh, Change *c) { 
     296void VMI::modifyEdges(Mesh *mesh, Change *c) { 
    362297    int i, e; 
    363 #ifndef USE_EDGE_ADJACENCY 
    364     int n0, n1, n2; 
    365 #else 
    366     int j, u, v; 
    367 #endif 
    368  
    369 #ifdef USE_EDGE_ADJACENCY 
    370     for (i=0; i<c->numDel; i++) { 
     298 
     299        for(i = 0; i < mesh->vertices[c->v].numEdges; i++) { 
    371300         
    372         for (j=0; j<3; j++) { 
    373             e = c->deleted[i].edges[j]; 
    374             if (e != c->e) { 
    375                 u = mesh->edges[e].u; 
    376                 v = mesh->edges[e].v; 
    377                 if (u == c->u || v == c->u) { 
    378                     //printf("%d\n",j); 
    379                     mesh->edges[e].enable = FALSE; 
    380                 } 
    381             } 
    382         } 
    383         //getchar(); 
    384     } 
    385 #else 
    386     for (i=0; i<c->numDel; i++) { 
    387  
    388         n0 = c->deleted[i].indices[0]; 
    389         n1 = c->deleted[i].indices[1]; 
    390         n2 = c->deleted[i].indices[2]; 
    391  
    392         if ((n0 == c->u && n1 != c->v) || (n1 == c->u && n0 != c->v)) { 
    393             e = findEdge(mesh->edges, mesh->numEdges, n0, n1); 
    394  
    395             //printf("a\n"); 
    396             if (e != -1) 
    397                 mesh->edges[e].enable = FALSE; 
    398         } 
    399  
    400         if ((n1 == c->u && n2 != c->v) || (n2 == c->u && n1 != c->v)) { 
    401             e = findEdge(mesh->edges, mesh->numEdges, n1, n2); 
    402              
    403             //printf("b\n"); 
    404             if (e != -1) 
    405                 mesh->edges[e].enable = FALSE; 
    406         } 
    407  
    408         if ((n0 == c->u && n2 != c->v) || (n2 == c->u && n0 != c->v)) { 
    409             e = findEdge(mesh->edges, mesh->numEdges, n0, n2); 
    410              
    411             //printf("c\n"); 
    412             if (e != -1) 
    413                 mesh->edges[e].enable = FALSE; 
    414         } 
    415         //getchar(); 
    416     } 
    417 #endif 
    418 } 
    419  
    420 void VMI::modifyEdges(Mesh *mesh, Change *c) { 
    421     int e, u, v; 
    422      
    423     // Update mesh and heap 
    424     for(e = 0; e < (int)mesh->numEdges; e++) { 
    425          
     301                e = mesh->vertices[c->v].edges[i]; 
     302 
    426303        if (mesh->edges[e].enable == TRUE) { 
    427304             
    428305            // Modify edge 
    429             if ((int)mesh->edges[e].u == c->u) 
     306            if (mesh->edges[e].u == c->u) 
    430307                mesh->edges[e].u = c->v; 
    431308             
    432             if ((int)mesh->edges[e].v == c->u) 
     309            if (mesh->edges[e].v == c->u) 
    433310                mesh->edges[e].v = c->v; 
    434              
    435             // Check edge 
    436             u = mesh->edges[e].u; 
    437             v = mesh->edges[e].v; 
    438              
    439             // if the edge is not valid, we simply delete it 
    440             if ((u == v) ||  
    441                 (u == c->u) || (v == c->u))  
    442                  
    443                 mesh->edges[e].enable = FALSE; 
    444311        } 
    445312    } 
    446313} 
    447314 
     315int VMI::find(int *edges, int num, int v_) { 
     316        int i; 
     317 
     318        int u, v; 
     319 
     320 
     321        for(i=0; i<num; i++) { 
     322 
     323                u = mesh->edges[edges[i]].u; 
     324 
     325                v = mesh->edges[edges[i]].v; 
     326 
     327                if (u == v_ || v == v_) return TRUE; 
     328 
     329        } 
     330 
     331        return FALSE; 
     332} 
     333void VMI::updateEdgeAdj(Mesh *mesh, Change *c) { 
     334        int i; 
     335 
     336        int v, e; 
     337 
     338        mesh->vertices[c->v].edges =  
     339            (int *)realloc(mesh->vertices[c->v].edges,  
     340            (mesh->vertices[c->v].numEdges + mesh->vertices[c->u].numEdges) * sizeof(int)); 
     341 
     342        for (i=0; i<mesh->vertices[c->u].numEdges; i++) { 
     343         
     344                e = mesh->vertices[c->u].edges[i]; 
     345                if (mesh->edges[e].u == c->u) v =mesh->edges[e].v; 
     346                else v = mesh->edges[e].u; 
     347                 
     348                if (!find(mesh->vertices[c->v].edges, mesh->vertices[c->v].numEdges, v)) 
     349                        addItem(mesh->vertices[c->v].edges, &mesh->vertices[c->v].numEdges, e); 
     350                else mesh->edges[e].enable = FALSE; 
     351        } 
     352 
     353        delItem(mesh->vertices[c->v].edges, &mesh->vertices[c->v].numEdges, c->e); 
     354} 
     355 
    448356/////////////////////////////////////////////////////////////////////////////// 
    449357 
    450358// Compute the triangle mesh changes due to a heap node simplification 
    451359void VMI::computeChange(Mesh *mesh, Change *c) { 
    452   GLuint numMod, numDel; 
     360  int numMod, numDel; 
    453361  Triangle *m = getTrianglesToModify(mesh, c, &numMod), 
    454362            *d = getTrianglesToDelete(mesh, c, &numDel); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/color.cpp

    r2090 r2127  
    77using namespace VMI; 
    88 
    9 Color *VMI::initColors(GLuint numColors) { 
     9Color *VMI::initColors(int numColors) { 
    1010    Color *colors; 
    1111 
     
    2525} 
    2626 
    27 void VMI::fillAllColors(Color *colors, GLuint numColors, GLuint begin, GLuint end, GLubyte color) { 
    28     GLuint i; 
     27void VMI::fillAllColors(Color *colors, int numColors, int begin, int end, GLubyte color) { 
     28    int i; 
    2929 
    3030    if (end > numColors) return; 
     
    4040} 
    4141 
    42 void VMI::setColors(Color *colors, GLuint numPasses, GLuint begin, GLuint end) { 
    43     GLuint i, step = numPasses * MAX_NUM_COLORS; 
     42void VMI::setColors(Color *colors, int numPasses, int begin, int end) { 
     43    int i, step = numPasses * MAX_NUM_COLORS; 
    4444    GLubyte r = 1, 
    4545            g = 1, 
     
    8686} 
    8787 
    88 void VMI::setColors2(Color *colors, GLuint numColors, GLuint begin, GLuint end) { 
    89     GLuint i,  
     88void VMI::setColors2(Color *colors, int numColors, int begin, int end) { 
     89    int i,  
    9090        channel = 0, 
    9191        step = (numColors < MAX_NUM_COLORS) ? (MAX_NUM_COLORS / numColors) : 1; 
     
    133133} 
    134134 
    135 void VMI::setColors3(Color *colors, GLuint numColors, GLubyte color) { 
    136     GLuint i; 
     135void VMI::setColors3(Color *colors, int numColors, GLubyte color) { 
     136    int i; 
    137137     
    138138    for (i = 0; i < numColors; i++) { 
     
    148148} 
    149149 
    150 void VMI::setColors4(Color *colors, GLuint numColors) { 
    151     GLuint i, c = 1; 
     150void VMI::setColors4(Color *colors, int numColors) { 
     151    int i, c = 1; 
    152152     
    153153    for (i = 0; i < numColors; i++) { 
     
    164164} 
    165165 
    166 void VMI::viewColors(Color *colors, GLuint numColors) { 
    167     GLuint i; 
     166void VMI::viewColors(Color *colors, int numColors) { 
     167    int i; 
    168168 
    169169    printf("\n"); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/histogram.cpp

    r2090 r2127  
    1414using namespace VMI; 
    1515 
    16 void VMI::printHistogram(GLuint histoGram[][4]) { 
     16void VMI::printHistogram(int histoGram[][4]) { 
    1717    int i; 
    1818    
     
    2323} 
    2424 
    25 void VMI::plotHistogram(GLuint histoGram[][4]) { 
     25void VMI::plotHistogram(int histoGram[][4]) { 
    2626    int i; 
    27     GLuint iLargest = 0;  // Largest histogram value 
     27    int iLargest = 0;  // Largest histogram value 
    2828    GLfloat maxHeight = height / 2.0f; 
    2929         
     
    7272} 
    7373 
    74 GLuint **VMI::initHistogram(GLuint numTriangles, GLuint numCameras) { 
    75     GLuint i; 
    76     GLuint **histogram; 
    77  
    78     histogram = (GLuint **)malloc(sizeof(GLuint *) * numCameras); 
     74int **VMI::initHistogram(int numTriangles, int numCameras) { 
     75    int i; 
     76    int **histogram; 
     77 
     78    histogram = (int **)malloc(sizeof(int *) * numCameras); 
    7979 
    8080    if (histogram == NULL) { 
     
    8484 
    8585    for (i=0; i<numCameras; i++) 
    86     histogram[i] = (GLuint *)malloc(sizeof(GLuint) * (numTriangles + 1)); // + 1 because the last is the numPixels of the background 
     86    histogram[i] = (int *)malloc(sizeof(int) * (numTriangles + 1)); // + 1 because the last is the numPixels of the background 
    8787 
    8888    // Fill the histogram buffer with 0 
    8989    for (i=0; i<numCameras; i++) 
    90     memset(histogram[i], 0, sizeof(GLuint) * (numTriangles + 1)); 
     90    memset(histogram[i], 0, sizeof(int) * (numTriangles + 1)); 
    9191 
    9292    return histogram; 
    9393} 
    9494 
    95 void VMI::deleteHistogram(GLuint **histogram, GLuint numCameras) { 
    96     GLuint i; 
     95void VMI::deleteHistogram(int **histogram, int numCameras) { 
     96    int i; 
    9797     
    9898    for (i=0;i<numCameras;i++) 
     
    102102} 
    103103 
    104 void VMI::printFullHistogram(GLuint **histogram, GLuint numCameras, GLuint numTriangles) { 
    105     GLuint i, j; 
     104void VMI::printFullHistogram(int **histogram, int numCameras, int numTriangles) { 
     105    int i, j; 
    106106     
    107107    printf("\n"); 
     
    116116} 
    117117 
    118 void VMI::getSubHistogram(GLuint subHistoGram[][4]) { 
     118void VMI::getSubHistogram(int subHistoGram[][4]) { 
    119119    //printf("Computing histogram...\n"); 
    120120    // Define the histogram 
     
    137137} 
    138138 
    139 void VMI::copySubHistogram(Color *colors, GLuint *histogram, GLuint begin, GLuint end, GLuint subHistoGram[][4]) { 
    140     GLuint i; 
     139void VMI::copySubHistogram(Color *colors, int *histogram, int begin, int end, int subHistoGram[][4]) { 
     140    int i; 
    141141    GLubyte r, g, b, a; 
    142     GLuint h = 0; 
     142    int h = 0; 
    143143 
    144144    for (i=begin; i<end; i++) { 
     
    165165} 
    166166 
    167 void VMI::getSWHistogram(GLuint *histogram, GLubyte *pixels) { 
     167void VMI::getSWHistogram(int *histogram, GLubyte *pixels) { 
    168168    GLubyte r, g, b, a; 
    169     GLuint i, t, p, numPixels = width * height; 
     169    int i, t, p, numPixels = width * height; 
    170170 
    171171    glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 
     
    188188 
    189189void VMI::getBoundingBox(Change *c, GLfloat min[3], GLfloat max[3]) { 
    190     GLuint  i, j, t, v; 
     190    int  i, j, t, v; 
    191191    GLfloat maxx = 0.0f, minx = 0.0f,  
    192192            maxy = 0.0f, miny = 0.0f, 
     
    194194     
    195195    /* get the max/mins */ 
    196     for (i=0; i<(GLuint)c->numMod; i++) { 
     196    for (i=0; i<c->numMod; i++) { 
    197197        t = c->modified[i].id; 
    198198         
     
    217217    } 
    218218 
    219     for (i=0; i<(GLuint)c->numDel; i++) { 
     219    for (i=0; i<c->numDel; i++) { 
    220220        t = c->deleted[i].id; 
    221221         
     
    322322} 
    323323 
    324 void VMI::getSWHistogramWin(GLuint *histogram, GLubyte *pixels, GLfloat min[3], GLfloat max[3], Change *c) { 
     324void VMI::getSWHistogramWin(int *histogram, GLubyte *pixels, GLfloat min[3], GLfloat max[3], Change *c) { 
    325325    GLubyte r, g, b, a; 
    326     GLuint i, t, p, numPixels, 
    327           *histoAux = (GLuint *)calloc(mesh->numTriangles + 1, sizeof(GLuint)); 
     326    int i, t, p, numPixels, 
     327          *histoAux = (int *)calloc(mesh->numTriangles + 1, sizeof(int)); 
    328328    GLint minw[2], maxw[2], ox, oy, h, w; 
    329329 
     
    369369    } 
    370370 
    371     for (i=0; i<(GLuint)c->numMod; i++) { 
    372         t = (GLuint)c->modified[i].id; 
     371    for (i=0; i<c->numMod; i++) { 
     372        t = c->modified[i].id; 
    373373 
    374374        histogram[t + 1] = histoAux[t + 1];  
     
    379379} 
    380380 
    381 void VMI::getSWHistoByOcclusionQuery(Mesh *mesh, Color *colors, GLuint *histogram) { 
    382     GLuint i, v1, v2, v3; 
     381void VMI::getSWHistoByOcclusionQuery(Mesh *mesh, Color *colors, int *histogram) { 
     382    int i, v1, v2, v3; 
    383383    GLint area, totalArea = 0; 
    384384 
     
    432432} 
    433433 
    434 void VMI::resetSWHistogram(GLuint *histogram, GLuint numTriangles) { 
     434void VMI::resetSWHistogram(int *histogram, int numTriangles) { 
    435435 
    436436    // Fill the histogram buffer with 0 
    437     memset(histogram, 0, sizeof(GLuint) * (numTriangles + 1)); 
    438 } 
     437    memset(histogram, 0, sizeof(int) * (numTriangles + 1)); 
     438} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/main.cpp

    r2090 r2127  
    88 
    99Camera *cameras = NULL; 
    10 GLuint numCameras = 0; 
     10int numCameras = 0; 
    1111 
    1212Color *colors = NULL; 
    1313 
    14 GLuint **histogram = NULL, 
    15         *queries = NULL; 
     14int **histogram = NULL; 
     15GLuint *queries = NULL; 
    1616 
    1717Mesh *mesh = NULL; 
     
    2828          bRemoveRedundantVertices = GL_TRUE; 
    2929 
    30 GLuint cameraType = 0, 
     30int cameraType = 0, 
    3131       numDemandedTriangles = 0; 
    3232 
     
    174174} 
    175175 
     176void VMI::updateHWAcceleration(Change *c) { 
     177    
     178#ifdef VERTEX_ARRAY_INTERLEAVE 
     179    if (interleave != NULL) free(interleave); 
     180    interleave = setupInterleave(mesh, colors); 
     181#endif 
     182#ifdef VERTEX_ARRAY 
     183    updateVertexArray(mesh, c); 
     184#endif 
     185#ifdef VERTEX_BUFFER_OBJECTS 
     186    updateVertexBufferObjects(mesh, c); 
     187#endif 
     188 
     189} 
     190 
    176191void VMI::setOrthographicProjection(void) { 
    177192    // Switch to projection mode 
     
    208223void VMI::renderGeometry(void) { 
    209224#ifdef IMMEDIATE_MODE 
    210     GLuint i, v1, v2, v3; 
     225    int i, v1, v2, v3; 
    211226 
    212227    // Immediate mode 
     
    228243#else 
    229244#ifdef VERTEX_ARRAY 
    230     glDrawArrays(GL_TRIANGLES, 0, mesh->currentNumTriangles * 3); 
     245    glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 
    231246#endif 
    232247#ifdef VERTEX_ARRAY_INTERLEAVE 
     
    235250#endif 
    236251#ifdef VERTEX_BUFFER_OBJECTS 
    237     glDrawArrays(GL_TRIANGLES, 0, mesh->currentNumTriangles * 3); 
     252    glDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3); 
    238253#endif 
    239254 
     
    264279    glutSwapBuffers(); 
    265280} 
    266 void VMI::renderScene(GLuint **histogram, GLuint numCameras) 
    267 { 
    268     GLuint i; 
     281 
     282void VMI::resetProjectedAreas(int **histogram, int numCameras) { 
     283    int i = 0; 
     284 
     285    // Reset the projected areas for all cameras 
     286    for (i=0; i<numCameras; i++) 
     287        resetSWHistogram(histogram[i], mesh->numTriangles); 
     288} 
     289 
     290void VMI::getProjectedAreas(int **histogram, int numCameras) 
     291{ 
     292    int i; 
    269293 
    270294    // draw to the frame buffer 
    271295    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 
    272          
    273     // Apply HW acceleration OpenGL Technique 
    274     applyHWAcceleration();  
    275  
    276     glDrawBuffer(GL_BACK); 
    277     glReadBuffer(GL_BACK); 
     296 
     297    //glDrawBuffer(GL_BACK); 
     298    //glReadBuffer(GL_BACK); 
    278299 
    279300    // Get the projected areas for all cameras 
     
    312333    /////////////////////////////////////////////////////////////////////////// 
    313334} 
    314 void VMI::renderSceneWin(GLuint **histogram, GLuint numCameras, Change *c) 
    315 { 
    316     GLuint i, j, t, background; 
     335void VMI::getProjectedAreasWin(int **histogram, int numCameras, Change *c) 
     336{ 
     337    int i, j, t, background; 
    317338    int del_area, mod_area; 
    318339    GLfloat min[3], max[3]; 
     
    325346    //printf("\n(%f,%f,%f)-(%f,%f,%f)\n", min[0], min[1], min[2], max[0], max[1], max[2]); 
    326347     
    327     // Apply HW acceleration OpenGL Technique 
    328     applyHWAcceleration();  
    329  
    330     glDrawBuffer(GL_BACK); 
    331     glReadBuffer(GL_BACK); 
     348    // Update HW acceleration OpenGL Technique 
     349    updateHWAcceleration(c); 
     350 
     351    //glDrawBuffer(GL_BACK); 
     352    //glReadBuffer(GL_BACK); 
    332353 
    333354    // Get the projected areas for all cameras 
     
    355376        mod_area = 0; 
    356377 
    357         for (j=0; j<( GLuint)c->numDel; j++) { 
     378        for (j=0; j<c->numDel; j++) { 
    358379            t = c->deleted[j].id; 
    359380            del_area += histogram[i][t + 1]; 
     
    362383        } 
    363384 
    364         for (j=0; j<( GLuint)c->numMod; j++) { 
     385        for (j=0; j<c->numMod; j++) { 
    365386            t = c->modified[j].id; 
    366387            del_area += histogram[i][t + 1]; 
     
    371392        getSWHistogramWin(histogram[i], pixels, min, max, c);  
    372393 
    373         for (j=0; j<( GLuint)c->numMod; j++) { 
     394        for (j=0; j<c->numMod; j++) { 
    374395            t = c->modified[j].id; 
    375396            mod_area += histogram[i][t + 1]; 
     
    425446     
    426447    glDeleteBuffersARB(1, &color_buf); 
     448 
     449    //free(pbuf_vertices); 
     450    //free(pbuf_colors); 
     451 
     452                buf_vertices = NULL; 
     453    buf_colors = NULL; 
     454 
     455#endif 
     456#ifdef VERTEX_ARRAY 
     457    //free(pbuf_vertices); 
     458    //free(pbuf_colors); 
     459 
     460                buf_vertices = NULL; 
     461    buf_colors = NULL; 
    427462#endif 
    428463 
     
    457492 
    458493        start = clock(); 
     494 
     495        // Apply HW acceleration OpenGL Technique 
     496  applyHWAcceleration(); 
    459497 
    460498        getProjectedAreas(histogram, numCameras); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp

    r2090 r2127  
    5353/////////////////////////////////////////////////////////////////////////////// 
    5454 
    55 int VMI::findEdge(Edge *e, GLuint num, GLuint _u, GLuint _v) { 
    56     GLuint i, u, v; 
     55int VMI::findEdge(Edge *e, int num, int _u, int _v) { 
     56    int i, u, v; 
    5757    int found = -1;  
    5858 
     
    8585                newList[*n].u = u; 
    8686    newList[*n].v = v; 
    87  
    88                 // This edge has no triangle adjancency 
    89                 newList[*n].numTriangles = 0; 
    90                 newList[*n].triangles = NULL; 
    9187                 
    9288                // Enable the new edge 
     
    10298} 
    10399 
     100double VMI::computeEdgeLength(Vertex *vertices, int u, int v) { 
     101    float ux, uy, uz, vx, vy ,vz, rx, ry, rz; 
     102     
     103    ux = vertices[u].x; 
     104    uy = vertices[u].y; 
     105    uz = vertices[u].z; 
     106 
     107    vx = vertices[v].x; 
     108    vy = vertices[v].y; 
     109    vz = vertices[v].z; 
     110 
     111    rx = ux - vx; 
     112    ry = uy - vy; 
     113    rz = uz - vz; 
     114 
     115    return sqrt((rx * rx) + (ry * ry) + (rz * rz)); 
     116} 
     117 
     118double VMI::computeTriangleVolume(Vertex *vertices, Triangle *t) { 
     119    int i; 
     120    double m[3][3], vol; 
     121     
     122    // Compute triangle Volume 
     123    i = t->indices[0]; 
     124    m[0][0] = mesh->vertices[i].x; 
     125    m[0][1] = mesh->vertices[i].y; 
     126    m[0][2] = mesh->vertices[i].z; 
     127     
     128    i = t->indices[1]; 
     129    m[1][0] = mesh->vertices[i].x; 
     130    m[1][1] = mesh->vertices[i].y; 
     131    m[1][2] = mesh->vertices[i].z; 
     132 
     133    i = t->indices[2]; 
     134    m[2][0] = mesh->vertices[i].x; 
     135    m[2][1] = mesh->vertices[i].y; 
     136    m[2][2] = mesh->vertices[i].z; 
     137     
     138    vol = computeMatDet(m); 
     139     
     140    //printf("Triangle Volume: %f\n", vol) 
     141    return vol;   
     142} 
     143 
    104144GLdouble VMI::computeTriangleArea(Vertex *vertices, Triangle *t) { 
    105     GLuint i; 
     145    int i; 
    106146    GLdouble v0[3], v1[3], v2[3], a; 
    107147     
     
    129169 
    130170void VMI::computeTriangleNormal(Vertex *vertices, Triangle *t) { 
    131     GLuint i; 
     171    int i; 
    132172    GLfloat x0, y0, z0, 
    133173            x1, y1, z1, 
     
    175215Mesh *VMI::initMesh(GLMmodel* pmodel) { 
    176216 
    177     GLuint i, j, curGroup, v1, v2, v3, n, m, t; 
     217    int i, j, curGroup, v1, v2, v3, n, m, t; 
    178218    int e; 
    179219    Mesh *mesh; 
     
    202242     
    203243    printf("Adding vertices..."); 
    204     for (i=1; i<=pmodel->numvertices; i++) { // Vertices start at 1 
     244    for (i=1; i<=(int)pmodel->numvertices; i++) { // Vertices start at 1 
    205245        mesh->vertices[i - 1].x = pmodel->vertices[3 * i + 0]; 
    206246        mesh->vertices[i - 1].y = pmodel->vertices[3 * i + 1]; 
     
    208248        mesh->vertices[i - 1].numTriangles = 0; 
    209249        mesh->vertices[i - 1].triangles = NULL; 
     250                                mesh->vertices[i - 1].numEdges = 0; 
     251        mesh->vertices[i - 1].edges = NULL; 
    210252        mesh->vertices[i - 1].enable = GL_TRUE; 
    211253    } 
     
    221263    while(group) { 
    222264         
    223         for (i=0; i<group->numtriangles; i++) { 
     265        for (i=0; i<(int)group->numtriangles; i++) { 
    224266             
    225267            t = group->triangles[i]; 
     
    244286                // Reallocate memory for the new adjacent triangle 
    245287                mesh->vertices[v1].triangles =  
    246                                         (GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint)); 
     288                                        (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 
    247289                addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, t); 
    248290            } 
     
    254296    for (i=0; i<pmodel->numtriangles; i++) { 
    255297        mesh->triangles[i].id = i; 
    256         mesh->triangles[i].indices[0] = pmodel->triangles[i].vindices[0] - 1; 
    257         mesh->triangles[i].indices[1] = pmodel->triangles[i].vindices[1] - 1; 
    258         mesh->triangles[i].indices[2] = pmodel->triangles[i].vindices[2] - 1; 
     298        mesh->triangles[i].indices[0] = (int)pmodel->triangles[i].vindices[0] - 1; 
     299        mesh->triangles[i].indices[1] = (int)pmodel->triangles[i].vindices[1] - 1; 
     300        mesh->triangles[i].indices[2] = (int)pmodel->triangles[i].vindices[2] - 1; 
    259301        mesh->triangles[i].area = computeTriangleArea(mesh->vertices, &mesh->triangles[i]); 
    260302        //printf("\n%d a: %f",i , mesh->triangles[i].area); 
     
    271313            // Reallocate memory for the new adjacent triangle 
    272314            mesh->vertices[v1].triangles =  
    273                             (GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint)); 
     315                            (int *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(int)); 
    274316            addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, i); 
    275317        } 
     
    304346            mesh->edges[n].u = v1; 
    305347            mesh->edges[n].v = v2; 
    306                                                 mesh->edges[n].triangles    = NULL; 
    307                         mesh->edges[n].numTriangles = 0; 
    308348            mesh->edges[n].enable = GL_TRUE; 
    309349            m = n; 
    310350            n++; 
    311351        } else m = e; 
    312                 // Reallocate memory for the new adjacent triangle 
    313         mesh->edges[m].triangles =  
    314                         (GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint)); 
    315         // Adding triangle i adjacent to edge m 
    316         addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i); 
    317         //printf("n:%d i:%d\n", m, i); 
    318          
    319         // Adding edge m adjacent to triangle i 
    320         addItem((int *)mesh->triangles[i].edges, (int *)&t, m); 
    321352 
    322353        ///////////////////////////////////////////////////////////////////////////////// 
     
    325356            mesh->edges[n].u = v2; 
    326357            mesh->edges[n].v = v3; 
    327                                                 mesh->edges[n].triangles    = NULL; 
    328                         mesh->edges[n].numTriangles = 0; 
    329358            mesh->edges[n].enable = GL_TRUE; 
    330359            m = n; 
    331360            n++; 
    332361        } else m = e; 
    333                 // Reallocate memory for the new adjacent triangle 
    334         mesh->edges[m].triangles =  
    335                         (GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint)); 
    336         // Adding triangle i adjacent to edge m 
    337         addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i); 
    338         //printf("n:%d i:%d\n", m, i); 
    339          
    340         // Adding edge m adjacent to triangle i 
    341         addItem((int *)mesh->triangles[i].edges, (int *)&t, m); 
    342362 
    343363        ///////////////////////////////////////////////////////////////////////////////// 
     
    346366            mesh->edges[n].u = v3; 
    347367            mesh->edges[n].v = v1; 
    348                                                 mesh->edges[n].triangles    = NULL; 
    349                         mesh->edges[n].numTriangles = 0; 
    350368            mesh->edges[n].enable = GL_TRUE; 
    351369            m = n; 
    352370            n++; 
    353371        } else m = e; 
    354                 // Reallocate memory for the new adjacent triangle 
    355         mesh->edges[m].triangles =  
    356                         (GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint)); 
    357         // Adding triangle i adjacent to edge m 
    358         addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i); 
    359         //printf("n:%d i:%d\n", m, i); 
    360          
    361         // Adding edge m adjacent to triangle i 
    362         addItem((int *)mesh->triangles[i].edges, (int *)&t, m); 
    363372    } 
    364373    printf("Ok\n"); 
    365374    mesh->numEdges = n; 
    366375 
     376                for (i=0; i<mesh->numEdges; i++) { 
     377                        v1 = mesh->edges[i].u; 
     378                        v2 = mesh->edges[i].v; 
     379 
     380                        mesh->vertices[v1].edges =  
     381                                (int *)realloc(mesh->vertices[v1].edges, (mesh->vertices[v1].numEdges + 1) * sizeof(int)); 
     382                        // Adding edge i adjacent to vertex v1 
     383                        addItem(mesh->vertices[v1].edges, &mesh->vertices[v1].numEdges, i); 
     384 
     385                        mesh->vertices[v2].edges =  
     386                                (int *)realloc(mesh->vertices[v2].edges, (mesh->vertices[v2].numEdges + 1) * sizeof(int)); 
     387                        // Adding edge i adjacent to vertex v2 
     388                        addItem(mesh->vertices[v2].edges, &mesh->vertices[v2].numEdges, i); 
     389                } 
     390 
    367391    return mesh; 
    368392} 
    369393 
    370394void VMI::printMesh(Mesh *mesh) { 
    371     GLuint i, j; 
     395    int i, j; 
    372396 
    373397    printf("Vertices (%d)\n", mesh->numVertices); 
     
    385409        } 
    386410        printf("]\n"); 
     411 
     412                                        printf("  e(%d)[", mesh->vertices[i].numEdges); 
     413        if (mesh->vertices[i].edges != NULL) { 
     414            printf("%d", mesh->vertices[i].edges[0]); 
     415            for (j=1; j<mesh->vertices[i].numEdges; j++) { 
     416                printf(",%d", mesh->vertices[i].edges[j]); 
     417            } 
     418        } 
     419        printf("]\n"); 
    387420    } 
    388421 
     
    391424    for (i=0; i<mesh->numEdges; i++) { 
    392425        printf("e%d (%d,%d) %d\n", i, mesh->edges[i].u, mesh->edges[i].v, mesh->edges[i].enable); 
    393         printf("  t(%d)[", mesh->edges[i].numTriangles); 
    394         if (mesh->edges[i].triangles != NULL) { 
    395             printf("%d", mesh->edges[i].triangles[0]); 
    396             for (j=1; j<mesh->edges[i].numTriangles; j++) { 
    397                 printf(",%d", mesh->edges[i].triangles[j]); 
    398             } 
    399                                 } 
    400         printf("]\n"); 
    401426    } 
    402427 
     
    406431        printf("t%d (%d,%d,%d) %d\n", i, mesh->triangles[i].indices[0], mesh->triangles[i].indices[1], 
    407432                                     mesh->triangles[i].indices[2],  mesh->triangles[i].enable); 
    408         printf("  e(3)["); 
    409         printf("%d", mesh->triangles[i].edges[0]); 
    410         for (j=1; j<3; j++) { 
    411             printf(",%d", mesh->triangles[i].edges[j]); 
    412         } 
    413         printf("]\n"); 
    414433 
    415434        printf("  n(3)["); 
     
    425444 
    426445void VMI::deleteMesh(Mesh *mesh) { 
    427         GLuint i; 
     446        int i; 
    428447 
    429448        if (NULL != mesh) { 
     
    432451                                free(mesh->vertices[i].triangles); 
    433452 
     453                        if (mesh->vertices[i].edges != NULL) 
     454                                free(mesh->vertices[i].edges); 
     455 
    434456                } 
    435457                if (mesh->vertices != NULL) free(mesh->vertices); 
    436458                mesh->numVertices = 0; 
    437459 
    438                 for (i=0; i<mesh->numEdges; i++) { 
    439                         if (mesh->edges[i].triangles != NULL) 
    440                                 free(mesh->edges[i].triangles); 
    441                 } 
    442460                if (mesh->edges != NULL) free(mesh->edges); 
    443461                mesh->numEdges = 0; 
     
    525543} 
    526544 
    527 int *VMI::edgesAdjToVertex(Mesh *mesh, int v, int *n) { 
    528     int *edges = NULL; 
    529     int i, t, e; 
    530 #ifndef USE_EDGE_ADJACENCY 
    531     int n0, n1, n2; 
    532 #else 
    533     int j; 
    534 #endif 
    535     int num = 0; 
    536  
    537         if (mesh->vertices[v].numTriangles > 0)  
    538                 edges = (int*)malloc(sizeof(int) * mesh->vertices[v].numTriangles * 2); 
    539  
    540     for (i=0; i<(int)mesh->vertices[v].numTriangles; i++) { 
    541  
    542         t = mesh->vertices[v].triangles[i]; 
    543  
    544 #ifdef USE_EDGE_ADJACENCY 
    545         for (j=0; j<3; j++) { 
    546             e = mesh->triangles[t].edges[j]; 
    547              
    548             if ((int)mesh->edges[e].u == v || (int)mesh->edges[e].v == v) 
    549                  
    550                 addItem(edges, &num, e); 
    551         } 
    552 #else 
    553         n0 = mesh->triangles[t].indices[0]; 
    554         n1 = mesh->triangles[t].indices[1]; 
    555         n2 = mesh->triangles[t].indices[2]; 
    556          
    557         if (((n0 == v) || (n1 == v)) && 
    558             ((e = findEdge(mesh->edges, mesh->numEdges, n0, n1)) != -1)) addItem(edges, &num, e); 
    559   
    560         if (((n1 == v) || (n2 == v)) && 
    561             ((e = findEdge(mesh->edges, mesh->numEdges, n1, n2)) != -1)) addItem(edges, &num, e); 
    562          
    563         if (((n0 == v) || (n2 == v)) && 
    564             ((e = findEdge(mesh->edges, mesh->numEdges, n0, n2)) != -1)) addItem(edges, &num, e); 
    565  
    566 #endif 
    567     } 
    568     *n = num; 
    569  
    570     return edges; 
    571 } 
    572  
    573545int *VMI::edgesAdjToVertices(Mesh *mesh, int *vertices, int numVertices, int *n) { 
    574546    int *edges = NULL; 
     
    578550    if (numVertices > 0) { 
    579551        // Add the first 
    580         list = edgesAdjToVertex(mesh, vertices[0], &numEdges); 
     552                list = mesh->vertices[vertices[0]].edges; 
     553                numEdges = mesh->vertices[vertices[0]].numEdges; 
    581554 
    582555        // Allocate memory 
     
    585558        memcpy(edges, list, sizeof(int) * numEdges); 
    586559 
    587         free(list); 
    588  
    589560        num = numEdges; 
    590561 
     
    592563        for (i=1; i<numVertices; i++) { 
    593564 
    594             list = edgesAdjToVertex(mesh, vertices[i], &numEdges); 
     565                        list = mesh->vertices[vertices[i]].edges; 
     566                    numEdges = mesh->vertices[vertices[i]].numEdges; 
    595567 
    596568            // Reallocate memory 
    597                         if (numEdges > 0) { 
     569            if (numEdges > 0) { 
    598570 
    599571                edges = (int *)realloc(edges, (num + numEdges + 1) * sizeof(int)); 
     
    601573                for (j=0; j<numEdges; j++) 
    602574                    addItem(edges, &num, list[j]); 
    603                         } 
    604             free(list); 
     575            } 
    605576        } 
    606577    } 
     
    610581} 
    611582 
    612 GLboolean VMI::findVertex(GLfloat *vertices, GLuint num, GLfloat x, GLfloat y, GLfloat z, int *pos) { 
    613     GLuint i; 
    614     GLfloat _x, _y, _z; 
     583GLboolean VMI::findVertex(float *vertices, int num, float x, float y, float z, int *pos) { 
     584    int i; 
     585    float _x, _y, _z; 
    615586    GLboolean found = GL_FALSE;  
    616587     
     
    648619                newList[*n].numTriangles = 0; 
    649620                newList[*n].triangles = NULL; 
     621 
     622                newList[*n].numEdges= 0; 
     623                newList[*n].edges = NULL; 
    650624         
    651625    // Enable the new vertex 
     
    663637 
    664638 
    665 void VMI::updateModel(GLMmodel* pmodel, Mesh *mesh, GLuint numVertices, GLuint numTriangles) { 
    666     GLuint i , v1, v2 ,v3, numV = 1, numT = 0; 
     639void VMI::updateModel(GLMmodel* pmodel, Mesh *mesh, int numVertices, int numTriangles) { 
     640    int i , v1, v2 ,v3, numV = 1, numT = 0; 
    667641    int pos; 
    668     GLfloat x, y, z; 
     642    float x, y, z; 
    669643     
    670644    if (pmodel->vertices != NULL) free(pmodel->vertices); 
     
    726700 
    727701void VMI::saveModel(char *filename, GLMmodel* pmodel, Mesh *mesh) { 
    728     GLuint i, j, g, numT = 0; 
     702    int i, j, g, numT = 0; 
    729703    GLMgroup *group; 
    730704 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/metrics.cpp

    r2090 r2127  
    1313using namespace VMI; 
    1414 
    15 GLdouble VMI::computeMeanProjAreaNoBG(GLuint **histogram, GLuint numCameras, int t) { 
    16     GLuint i; 
     15GLdouble VMI::computeMeanProjAreaNoBG(int **histogram, int numCameras, int t) { 
     16    int i; 
    1717    GLdouble mean_proj_area = 0.0; 
    1818 
     
    2424} 
    2525 
    26 GLdouble VMI::computeMeanProjArea(GLuint **histogram, GLuint numCameras, int t) { 
    27         GLuint i; 
     26GLdouble VMI::computeMeanProjArea(int **histogram, int numCameras, int t) { 
     27        int i; 
    2828        GLdouble mean_proj_area = 0.0, total_proj_area, resolution = width * height; 
    2929 
     
    3838/////////////////////////////////////////////////////////////////////////////// 
    3939// Mutual Information 
    40 GLdouble VMI::computeMI(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint cam) { 
     40GLdouble VMI::computeMI(Mesh *mesh, int **histogram, int numCameras, int cam) { 
    4141    GLdouble I = 0.0, pov, po, total_proj_area = width * height; 
    42     GLuint i; 
     42    int i; 
    4343     
    4444    for (i=0; i<mesh->numTriangles; i++) {  
     
    6666} 
    6767 
    68 GLdouble VMI::decMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c) { 
     68GLdouble VMI::decMI(GLdouble I, int **histogram, int numCameras, int cam, Change *c) { 
    6969    GLdouble newI = I * numCameras,  
    7070             pov = 0.0, po; 
     
    109109} 
    110110 
    111 GLdouble VMI::incMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c) { 
     111GLdouble VMI::incMI(GLdouble I, int **histogram, int numCameras, int cam, Change *c) { 
    112112    GLdouble newI = I * numCameras,  
    113113             pov = 0.0, po; 
    114114    GLsizei total_proj_area = width * height; 
    115     GLuint i, t; 
     115    int i, t; 
    116116 
    117117    // increase entropy of modified triangles 
    118     for (i=0; i<(GLuint)c->numMod; i++) {  
     118    for (i=0; i<c->numMod; i++) {  
    119119         
    120120        t = c->modified[i].id; 
     
    140140/////////////////////////////////////////////////////////////////////////////// 
    141141// Kullback-Leibler divergence 
    142 GLdouble VMI::computeKL(Mesh *mesh, GLuint *histogram) { 
     142GLdouble VMI::computeKL(Mesh *mesh, int *histogram) { 
    143143    GLdouble I = 0.0,  
    144144             total_real_area = 0.0, pi, tri_area; 
    145145    GLsizei  total_proj_area = (width * height) - histogram[0]; 
    146     GLuint   i; 
     146    int   i; 
    147147 
    148148    // Compute total real area of all triangles 
     
    169169 
    170170// Hellinger divergence (square root) 
    171 GLdouble VMI::computeHE(Mesh *mesh, GLuint *histogram) { 
     171GLdouble VMI::computeHE(Mesh *mesh, int *histogram) { 
    172172    GLdouble I = 0.0, temp,  
    173173             total_real_area = 0.0, pi, qi; 
    174174    GLsizei  total_proj_area = (width * height) - histogram[0]; 
    175     GLuint i; 
     175    int i; 
    176176     
    177177    // Compute total real area of all triangles 
     
    203203 
    204204// Chi-Square divergence (square root) 
    205 GLdouble VMI::computeCS(Mesh *mesh, GLuint *histogram) { 
     205GLdouble VMI::computeCS(Mesh *mesh, int *histogram) { 
    206206    GLdouble I = 0.0,  
    207207             total_real_area = 0.0, pi, qi; 
    208208    GLsizei  total_proj_area = (width * height) - histogram[0]; 
    209     GLuint i; 
     209    int i; 
    210210     
    211211    /// Compute total real area of all triangles 
     
    231231} 
    232232/////////////////////////////////////////////////////////////////////////////// 
    233 GLdouble VMI::computeEntropy(GLuint **histogram, GLuint numCameras, GLuint k) { 
     233GLdouble VMI::computeEntropy(int **histogram, int numCameras, int k) { 
    234234        GLdouble H = 0.0, POk, pi, 
    235235                                         total_proj_area, resolution = width * height, pv = 1.0 / (GLdouble)numCameras; 
    236         GLuint i; 
     236        int i; 
    237237 
    238238        for (i=0; i<numCameras; i++) { 
     
    253253} 
    254254 
    255 GLdouble VMI::computeMixedEntropy(GLdouble *mixed, GLuint numCameras) { 
     255GLdouble VMI::computeMixedEntropy(GLdouble *mixed, int numCameras) { 
    256256    GLdouble H = 0.0, pi; 
    257     GLuint i; 
     257    int i; 
    258258     
    259259    for (i=0; i<numCameras; i++) { 
     
    269269/////////////////////////////////////////////////////////////////////////////// 
    270270// Jensen-Shannon divergence 
    271 GLdouble VMI::computeJS(GLuint **histogram, GLuint numCameras, GLuint j, GLuint k) { 
     271GLdouble VMI::computeJS(int **histogram, int numCameras, int j, int k) { 
    272272        GLdouble js, Wj = 0.0, Wk = 0.0, POj, POk, pj, pk, total_proj_area, 
    273273                                         resolution = width * height, pv = 1.0 / (GLdouble)numCameras, 
    274274                                         *mixing = (GLdouble *)malloc(numCameras * sizeof(GLdouble)); 
    275         GLuint i; 
     275        int i; 
    276276 
    277277        POj = computeMeanProjArea(histogram, numCameras, j + 1); 
     
    311311} 
    312312/////////////////////////////////////////////////////////////////////////////// 
    313 void VMI::getProjectedAreas(GLuint **histogram, GLuint numCameras) { 
    314  
    315     renderScene(histogram, numCameras); 
    316 } 
    317  
    318 void VMI::getProjectedAreasWin(GLuint **histogram, GLuint numCameras, Change *c) { 
    319  
    320     renderSceneWin(histogram, numCameras, c); 
    321 } 
    322  
    323 void VMI::resetProjectedAreas(GLuint **histogram, GLuint numCameras) { 
    324     GLuint i = 0; 
    325  
    326     // Reset the projected areas for all cameras 
    327     for (i=0; i<numCameras; i++) 
    328         resetSWHistogram(histogram[i], mesh->numTriangles); 
    329 } 
    330  
    331 GLdouble *VMI::initIs(GLuint numCameras) { 
     313 
     314GLdouble *VMI::initIs(int numCameras) { 
    332315    GLdouble *initialIs; 
    333316 
     
    346329} 
    347330 
    348 void VMI::computeCameraIs(GLuint **histogram, GLuint numCameras, GLdouble *mis) { 
    349     GLuint i = 0; 
     331void VMI::computeCameraIs(int **histogram, int numCameras, GLdouble *mis) { 
     332    int i = 0; 
    350333    GLdouble meanI = 0.0; 
    351334 
     
    374357} 
    375358 
    376 void VMI::printIs(GLdouble *mis, GLuint numCameras) { 
    377     GLuint i; 
     359void VMI::printIs(GLdouble *mis, int numCameras) { 
     360    int i; 
    378361 
    379362    printf("\n"); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/saliency.cpp

    r2090 r2127  
    2222using namespace VMI; 
    2323 
    24 void VMI::computeSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras) { 
    25         GLuint i = 0; 
     24void VMI::computeSaliency(Mesh *mesh, int **histogram, int numCameras) { 
     25        int i = 0; 
    2626        double sal; 
    2727 
     
    4646} 
    4747 
    48 void updateTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, int v) { 
     48void updateTriangleSaliency(Mesh *mesh, int **histogram, int numCameras, int v) { 
    4949        int i, t; 
    5050 
     
    5757} 
    5858 
    59 double VMI::computeTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint k) { 
    60      GLuint i, l, v0, v1, v2; 
     59double VMI::computeTriangleSaliency(Mesh *mesh, int **histogram, int numCameras, int k) { 
     60    int i, l, v0, v1, v2; 
    6161    int *triangles = NULL, n = 0; 
    6262    double sal = 0.0; 
     
    9494    //printItemList(triangles, n); 
    9595     
    96     for(i=0; i<(GLuint)n; i++) { 
     96    for(i=0; i<n; i++) { 
    9797        //printf("\n%d %d", k, triangles[i]); 
    9898        //sal += computeJS(histogram, numCameras, k, triangles[i]); 
     
    137137void VMI::saveSaliencyMap(Mesh *mesh, char* filename) { 
    138138    FILE *fp; 
    139     GLuint i; 
     139    int i; 
    140140 
    141141 
     
    162162void VMI::loadSaliencyMap(Mesh *mesh, char* filename) { 
    163163    FILE *fp; 
    164     unsigned int i, num; 
     164    int i, num; 
    165165    float s; 
    166166 
     
    202202 
    203203void VMI::viewSaliency(Mesh *mesh, Camera *cameras, int cam) { 
    204     GLuint i, v1, v2, v3; 
     204    int i, v1, v2, v3; 
    205205    float r, g, b; 
    206206     
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/simplify.cpp

    r2103 r2127  
    1010#include "../include/saliency.h" 
    1111#include "../include/histogram.h" 
     12#include "../include/buffers.h" 
    1213 
    1314//#define RECOMPUTE_THE_WHOLE_HEAP 
     
    5960 
    6061bheap_t *VMI::initHeap(Mesh *mesh) { 
    61         GLuint i; 
     62        int i; 
    6263        double cost; 
    6364        bheap_t *h = NULL; 
     
    152153 
    153154        return h; 
    154 } 
    155  
    156 GLdouble VMI::computeEdgeLength(Vertex *vertices, int u, int v) { 
    157         GLfloat ux, uy, uz, vx, vy ,vz, rx, ry, rz; 
    158  
    159         ux = vertices[u].x; 
    160         uy = vertices[u].y; 
    161         uz = vertices[u].z; 
    162  
    163         vx = vertices[v].x; 
    164         vy = vertices[v].y; 
    165         vz = vertices[v].z; 
    166  
    167         rx = ux - vx; 
    168         ry = uy - vy; 
    169         rz = uz - vz; 
    170  
    171         return sqrt((rx * rx) + (ry * ry) + (rz * rz)); 
    172155} 
    173156 
     
    243226/////////////////////////////////////////////////////////////////////////////// 
    244227 
    245 void saveProjectedAreas(GLuint **histogram, GLuint numCameras, Change *c, GLuint *dest) { 
    246         GLuint i, j, t, n = 0; 
    247  
    248         for (j=0; j<(GLuint)c->numDel; j++) { 
     228void saveProjectedAreas(int **histogram, int numCameras, Change *c, int *dest) { 
     229        int i, j, t, n = 0; 
     230 
     231        for (j=0; j<c->numDel; j++) { 
    249232 
    250233                t = c->deleted[j].id; 
     
    257240        } 
    258241 
    259         for (j=0; j<(GLuint)c->numMod; j++) {  
     242        for (j=0; j<c->numMod; j++) {  
    260243 
    261244                t = c->modified[j].id; 
     
    276259} 
    277260 
    278 void loadProjectedAreas(GLuint *src, GLuint numCameras, Change *c, GLuint **histogram) { 
    279         GLuint i, j, t, n = 0; 
    280  
    281         for (j=0; j<(GLuint)c->numDel; j++) {  
     261void loadProjectedAreas(int *src, int numCameras, Change *c, int **histogram) { 
     262        int i, j, t, n = 0; 
     263 
     264        for (j=0; j<c->numDel; j++) {  
    282265 
    283266                t = c->deleted[j].id; 
     
    290273        } 
    291274 
    292         for (j=0; j<(GLuint)c->numMod; j++) {  
     275        for (j=0; j<c->numMod; j++) {  
    293276 
    294277                t = c->modified[j].id; 
     
    308291        } 
    309292} 
    310  
    311293/////////////////////////////////////////////////////////////////////////////// 
     294#ifdef CHECK_LOCAL_INVERSION 
     295int check_local_inversion(Mesh *mesh, Change *c) { 
     296    int i, t; 
     297    int v0, v1, v2; 
     298    double vol_before; 
     299    double vol_after; 
     300    Triangle tri; 
     301     
     302    for(i=0; i<mesh->vertices[c->u].numTriangles; i++) { 
     303         
     304        t = mesh->vertices[c->u].triangles[i]; 
     305         
     306        v0 = mesh->triangles[t].indices[0]; 
     307        v1 = mesh->triangles[t].indices[1]; 
     308        v2 = mesh->triangles[t].indices[2]; 
     309         
     310        if ((v0 != c->v) && (v1 != c->v) && (v2 != c->v)) { 
     311             
     312            //printf("%d\n", t); 
     313            memcpy(&tri, &mesh->triangles[t], sizeof(Triangle)); 
     314             
     315            vol_before = computeTriangleVolume(mesh->vertices, &tri); 
     316 
     317            //printf("t:[%d,%d,%d]\n", tri.indices[0], tri.indices[1], tri.indices[2]); 
     318            //printf("v:%f\n", vol_before); 
     319           
     320            if (tri.indices[0] == c->u) tri.indices[0] = c->v; 
     321            if (tri.indices[1] == c->u) tri.indices[1] = c->v; 
     322            if (tri.indices[2] == c->u) tri.indices[2] = c->v; 
     323             
     324            vol_after = computeTriangleVolume(mesh->vertices, &tri); 
     325 
     326            //printf("t:[%d,%d,%d]\n", tri.indices[0], tri.indices[1], tri.indices[2]); 
     327            //printf("v:%f\n", vol_after); 
     328 
     329            if (((vol_before > 0) && (vol_after < 0)) ||  
     330                ((vol_before < 0) && (vol_after > 0))) 
     331 
     332                return TRUE; 
     333        } 
     334    } 
     335    return FALSE; 
     336} 
     337#endif 
    312338 
    313339GLdouble VMI::computeEdgeCost(Mesh *mesh, int e) { 
     
    318344        GLdouble newI; 
    319345#endif 
    320         GLuint i, *histoAux = NULL; 
     346        int i, *histoAux = NULL; 
    321347        Change *c; 
     348#if defined(VERTEX_BUFFER_OBJECTS) || defined(VERTEX_ARRAY) 
     349    VertexIL *vb = NULL; 
     350#endif 
     351#ifdef CHECK_LOCAL_INVERSION 
     352    int penalized; 
     353#endif 
    322354 
    323355        chooseBestEndPoints(mesh, e); 
     
    327359 
    328360        // Compute cost only for boundary or manifold edges 
    329         if (c->numDel == 2 
    330                         /*(c->numDel <3) && (c->numDel > 0)*/) { 
     361        if (/*c->numDel == 2*/ 
     362                        (c->numDel <3) && (c->numDel > 0)) { 
     363 
     364#ifdef CHECK_LOCAL_INVERSION 
     365        penalized = check_local_inversion(mesh, c); 
     366#endif 
    331367                // Allocate memory 
    332                 histoAux = (GLuint *)malloc((c->numDel + c->numMod + 1) * numCameras * sizeof(GLuint)); 
     368                histoAux = (int *)malloc((c->numDel + c->numMod + 1) * numCameras * sizeof(int)); 
     369 
     370#if defined(VERTEX_BUFFER_OBJECTS) || defined(VERTEX_ARRAY) 
     371        vb = (VertexIL *)malloc((c->numDel + c->numMod + 1) * 3 * sizeof(VertexIL)); 
     372 
     373        saveVertexBuffer(c, vb); 
     374#endif 
    333375 
    334376#ifdef MI // Mutual Information 
     
    365407                        //printf("  I0:%f Is: %f\n", auxE[i], initialIs[i]); 
    366408 
    367                         cost += (ABS(auxIs[i] - initialIs[i]) * cameras[i].weight * sal); 
     409                        cost += (ABS(auxIs[i] - initialIs[i]) * cameras[i].weight); 
    368410 
    369411                        // Restore old informations 
     
    405447                        newI = computeCS(mesh, histogram[i]); 
    406448#endif 
    407                         cost += (ABS(initialIs[i] - newI) * cameras[i].weight * sal); 
     449                        cost += (ABS(initialIs[i] - newI) * cameras[i].weight); 
    408450                } 
    409451                undoChange(mesh, c); 
     
    417459                // Free memory 
    418460                free(histoAux); 
     461#if defined(VERTEX_BUFFER_OBJECTS) || defined(VERTEX_ARRAY) 
     462        loadVertexBuffer(vb, c); 
     463        free(vb); 
     464#endif 
     465#ifdef CHECK_LOCAL_INVERSION 
     466        if (penalized) cost *= 5; 
     467#endif 
    419468 
    420469        } else cost = FLT_MAX; 
     
    422471        deleteChange(c); 
    423472 
    424         return cost; 
    425 } 
     473        return (cost * sal); 
     474} 
     475 
     476int isValidEdge_(Mesh *mesh, int e) { 
     477    int u , v; 
     478 
     479    if (mesh->edges[e].enable == FALSE) return FALSE; 
     480    else { 
     481        u = mesh->edges[e].u; 
     482        v = mesh->edges[e].v; 
     483 
     484        if (u == v) { 
     485 
     486            mesh->edges[e].enable = FALSE; 
     487            return FALSE; 
     488        } 
     489    } 
     490 
     491    return TRUE; 
     492} 
     493 
    426494/* Get a valid edge from the heap */ 
    427495int getMinValidEdge(Mesh *mesh, bheap_t *h) { 
     
    431499        e = bh_min(h); 
    432500 
    433         while (mesh->edges[e].enable == FALSE) { 
     501        while (!isValidEdge_(mesh, e)) { 
    434502                /* delete invalid edge */ 
    435503                bh_delete(h, e); 
     
    473541 
    474542/////////////////////////////////////////////////////////////////////////// 
    475 void VMI::simplifyModel(Mesh *mesh, GLuint numDemandedTri) 
     543void VMI::simplifyModel(Mesh *mesh, int numDemandedTri) 
    476544{ 
    477545        int                     e; 
     
    558626                bh_delete(h, e); 
    559627 
     628                updateHWAcceleration(c); 
     629 
    560630                // Get projected areas after the edge collapse 
    561631                getProjectedAreas(histogram, numCameras); 
     
    563633                computeCameraIs(histogram, numCameras, initialIs); 
    564634 
    565                 deleteEdges(mesh, c); 
    566                 modifyEdges(mesh, c); 
     635                updateEdgeAdj(mesh, c); 
     636 
     637    modifyEdges(mesh, c); 
    567638 
    568639                // Update the heap according to the edge collapse 
     
    751822 
    752823        Edge            *econ; 
    753         float           x,y,z; 
    754824        int                     *lv1; 
    755825        int                     v0; 
     
    797867                        v1      =       (*lb1).second; 
    798868 
    799                         lv1     =       edgesAdjToVertex(mesh,v1,&num_edges); 
     869                        lv1     =       mesh->vertices[v1].edges; 
     870                        num_edges = mesh->vertices[v1].numEdges; 
    800871 
    801872                        //      Edje iterator. 
     
    857928 
    858929                        deleteVertexOfMap(mesh, c->u); 
    859                         deleteEdges(mesh, c); 
    860                         modifyEdges(mesh, c); 
     930                        updateEdgeAdj(mesh, c); 
     931      modifyEdges(mesh, c); 
    861932                        deleteChange(c); 
    862933 
     
    910981                        lonely_vert     =       (*it).second; 
    911982 
    912                         le      =       edgesAdjToVertex(mesh,lonely_vert,&num_edges); 
     983                        le      =       mesh->vertices[lonely_vert].edges; 
     984 
     985                        num_edges = mesh->vertices[lonely_vert].numEdges; 
    913986 
    914987                        //      Find an edge width v coordinates. 
     
    9771050 
    9781051                                deleteVertexOfMap(mesh, c->u); 
    979                                 deleteEdges(mesh, c); 
    980                                 modifyEdges(mesh, c); 
     1052                                updateEdgeAdj(mesh, c); 
     1053        modifyEdges(mesh, c); 
    9811054                                deleteChange(c); 
    9821055                        } 
     
    10691142 
    10701143                                deleteVertexOfMap(mesh, c->u); 
    1071                                 deleteEdges(mesh, c); 
    1072                                 modifyEdges(mesh, c); 
     1144                                updateEdgeAdj(mesh, c); 
     1145        modifyEdges(mesh, c); 
    10731146                                deleteChange(c); 
    10741147                        } 
Note: See TracChangeset for help on using the changeset viewer.