Changeset 2090


Ignore:
Timestamp:
02/05/07 13:29:55 (17 years ago)
Author:
gumbau
Message:
 
Location:
GTP/trunk/Lib/Geom/shared
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshSimpSequence.h

    r1526 r2090  
    3232        struct  GeoVertex 
    3333        { 
    34                 Index   id; 
    35                 Index   bonefrom; 
     34                Index           id; 
     35                Index           bonefrom; 
    3636                Vector3 position; 
    3737                Vector2 texcoord; 
     
    8888                        void Save(Serializer &s); 
    8989 
    90                         // 'Inserts the mesh name into the meshsimplificationsequence 
     90                        // Inserts the mesh name into the meshsimplificationsequence. 
    9191                        void putMeshName(char *); 
    9292 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshSimplifier.h

    r1070 r2090  
    22#define __GEO_MESH_SIMPLIFIER__ 
    33 
     4#include <map> 
    45#include        <math.h> 
    56#include        "GeoMesh.h" 
     
    1011//#include "SimplificationMethod.h" 
    1112 
     13using   namespace       Geometry; 
     14 
    1215namespace Geometry 
    1316{ 
     17 
     18        //----------------------------------------------------------------------- 
     19        //      Class for join triangle holes. 
     20        //----------------------------------------------------------------------- 
     21        class _coord_ 
     22        { 
     23                public: 
     24                        float x,y,z; 
     25                        inline _coord_( float x =       0.0f, 
     26                                        float y =       0.0f, 
     27                                        float z =       0.0f) 
     28                        { this->x = x; this->y = y; this->z = z; } 
     29 
     30                        inline _coord_(const _coord_ &f) 
     31                        { 
     32                                x       =       f.x; 
     33                                y=f.y; 
     34                                z=f.z; 
     35                        } 
     36 
     37                        inline _coord_ & operator=(const _coord_ &f) 
     38                        { 
     39                                x       =       f.x; 
     40                                y       =       f.y; 
     41                                z       =       f.z; 
     42 
     43                                return *this; 
     44                        } 
     45 
     46                        inline bool operator<(const _coord_ &f) const 
     47                        { 
     48                                if (x<f.x-0.0001) return true; 
     49                                if (x>f.x+0.0001) return false; 
     50                                if (y<f.y-0.0001) return true; 
     51                                if (y>f.y+0.0001) return false; 
     52                                if (z<f.z-0.0001) return true; 
     53                                if (z>f.z+0.0001) return false; 
     54 
     55                                return  false; 
     56                        } 
     57        }; 
     58 
     59        //----------------------------------------------------------------------- 
     60        //      Class tha implements a double-linked map. 
     61        //----------------------------------------------------------------------- 
     62        class   EdgesMultimap 
     63        { 
     64                private: 
     65                        multimap<int,int>       edges; 
     66                public: 
     67                        EdgesMultimap(); 
     68                        ~EdgesMultimap(); 
     69                        void    insert(int v1,int v2); 
     70                        void    remove(int v1,int v2); 
     71                        void    contract(int v1,int v2); 
     72                        bool    exists(int v1,int v2); 
     73        }; 
     74 
     75        //----------------------------------------------------------------------- 
     76        //      Class that conserves textures adding new vertices to mesh. 
     77        //----------------------------------------------------------------------- 
     78        class   TextureConserver 
     79        { 
     80                private: 
     81                        EdgesMultimap                   *mEdges; 
     82                        Mesh                                                    *mGeoMesh; 
     83 
     84                public: 
     85                        multimap<int,int>       mVertices; 
     86 
     87                        TextureConserver(); 
     88                        ~TextureConserver(); 
     89 
     90                        void    JoinVertices(Mesh *mesh); 
     91 
     92                        MeshSimplificationSequence * 
     93                                WriteRealSimpSeq(MeshSimplificationSequence *simpseq); 
     94 
     95                        Mesh    *GetMesh(); 
     96        }; 
     97 
    1498        /// Mesh simplificator interface. 
    1599        /** This module is used by both models, general mesh models and the plant and tree models for the trunk and the branches. It contains functions that generate simplified versions of 3D objects made out of triangles. Given a 3D object, this module computes a sequence of geometric transformations that reduce the object’s geometric detail while preserving its appearance. For each simplification step, returns a simplification sequence containing the edge to be collapse, the two triangles being removed and the new triangles remapped to the model.\n\n 
    16100 
    17101Inputs:\n 
    18         - A pointer to the Geometry::Mesh object containing the 3D model to be simplified. 
    19         . 
    20          
     102- A pointer to the Geometry::Mesh object containing the 3D model to be simplified. 
     103. 
     104 
    21105Outputs:\n 
    22         -# The simplified mesh, contained in a Geometry::Mesh object. 
    23         -# Simplification sequence, represented by a Geometry::MeshSimplificationSequence object. 
    24         */ 
     106-# The simplified mesh, contained in a Geometry::Mesh object. 
     107-# Simplification sequence, represented by a Geometry::MeshSimplificationSequence object. 
     108*/ 
    25109 
    26110        class MeshSimplifier 
     
    29113                        /// Class constructor. Retrieves a pointer to a valid Geometry::Mesh object to simplify. 
    30114                        MeshSimplifier( const Geometry::Mesh    *, 
    31                                                                                         Geometry::TIPOFUNC              upb=0); 
     115                                        Geometry::TIPOFUNC              upb=0); 
    32116 
    33117                        /// Virtual class destructor. 
     
    76160        class ViewPointDrivenSimplifier : public MeshSimplifier 
    77161        { 
    78         private: 
    79                  
    80                 //      Auxiliar vertex buffer. 
    81                 Geometry::VertexBuffer  *mVB; 
    82                  
    83                 //      Loads a vmi mesh with a given geometry mesh. 
    84                 VMI::Mesh * initMeshStructure(Geometry::Mesh    *geoMesh); 
    85  
    86                 //      Loads a geometry mesh with a given vmi mesh. 
    87                 void    loadMesh(); 
    88  
    89                 //      Find vertex in auxiliar vertex buffer. 
    90                 void    findVertex(size_t       submesh, size_t index); 
    91                  
    92                 //      Gets the VMI mesh simplification sequence. 
    93                 void    GetMeshSimpSequence(); 
    94  
    95         public: 
    96  
    97                 /// Class constructor. Will call Simplifier class constructor. 
    98                 ViewPointDrivenSimplifier(      const Geometry::Mesh    *geoMesh, 
    99                                                                                                                                 Geometry::TIPOFUNC              upb=0); 
    100  
    101                 /// Class destructor. 
    102                 ~ViewPointDrivenSimplifier(void); 
    103  
    104                 /// Copy constructor 
    105                 //ViewPointDrivenSimplifier(const ViewPointDrivenSimplifier&); 
    106  
    107                 /// Assignment operator 
    108                 //ViewPointDrivenSimplifier& operator =(const ViewPointDrivenSimplifier&); 
    109  
    110                 /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. Implements the Simplifier::Simplify method to perform an image based simplification. 
    111                 void Simplify(Geometry::Real); 
    112  
    113                 /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. Implements the Simplifier::Simplify method to perform an image based simplification. 
    114                 void Simplify(Geometry::uint32); 
    115  
    116                 // Returns the simplified mesh. 
    117                 //Mesh *GetMesh(); 
     162                private: 
     163 
     164                        //      Vectors of positions, normals and texture coordinates. 
     165                        vector<Vector3> vPositions; 
     166                        vector<Vector3> vNormals; 
     167                        vector<Vector2> vTexCoords; 
     168 
     169                        //      Auxiliar vertex buffer. 
     170                        Geometry::VertexBuffer  *mVB; 
     171 
     172                        //      Set of indices. 
     173                        map<int,int>    mIndexMap; 
     174 
     175                        //      Join and split vertices to matain texture aspect. 
     176                        TextureConserver        *mTexConserver; 
     177 
     178                        //      Loads a vmi mesh with a given geometry mesh. 
     179                        VMI::Mesh * initMeshStructure(Geometry::Mesh    *geoMesh); 
     180 
     181                        //      Loads a geometry mesh with a given vmi mesh. 
     182                        void    loadMesh(); 
     183 
     184                        //      Find vertex in auxiliar vertex buffer. 
     185                        void    findVertex(size_t       submesh, size_t index); 
     186 
     187                        //      Gets the VMI mesh simplification sequence. 
     188                        void    GetMeshSimpSequence(); 
     189 
     190                        //      Fill up vectors of positions, normals and texture coordinates. 
     191                        void    fillUpPosNorTC(Mesh     *geoMesh); 
     192 
     193                        //      Reassigns bones. 
     194                        void bonesReassignament(); 
     195 
     196                public: 
     197 
     198                        /// Class constructor. Will call Simplifier class constructor. 
     199                        ViewPointDrivenSimplifier(      const Geometry::Mesh    *geoMesh, 
     200                                        Geometry::TIPOFUNC              upb=0); 
     201 
     202                        /// Class destructor. 
     203                        ~ViewPointDrivenSimplifier(void); 
     204 
     205                        /// Copy constructor 
     206                        //ViewPointDrivenSimplifier(const ViewPointDrivenSimplifier&); 
     207 
     208                        /// Assignment operator 
     209                        //ViewPointDrivenSimplifier& operator =(const ViewPointDrivenSimplifier&); 
     210 
     211                        /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. Implements the Simplifier::Simplify method to perform an image based simplification. 
     212                        void Simplify(Geometry::Real); 
     213 
     214                        /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. Implements the Simplifier::Simplify method to perform an image based simplification. 
     215                        void Simplify(Geometry::uint32); 
     216 
     217                        // Returns the simplified mesh. 
     218                        //Mesh *GetMesh(); 
    118219        }; 
    119220 
     
    122223        class GeometryBasedSimplifier : public MeshSimplifier 
    123224        { 
    124         public: 
    125                 /// Class constructor. Will call Simplifier class constructor. 
    126                 GeometryBasedSimplifier(        const Geometry::Mesh    *geoMesh, 
    127                                                                                                                         Geometry::TIPOFUNC              upb=0); 
    128  
    129                 /// Class destructor. 
    130                 ~GeometryBasedSimplifier(void); 
    131  
    132                 /// Copy constructor 
    133                 //GeometryBasedSimplifier(const GeometryBasedSimplifier&); 
    134  
    135                 /// Assignment operator 
    136                 //GeometryBasedSimplifier& operator =(const GeometryBasedSimplifier&); 
    137  
    138                 /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. Implements the Simplifier::Simplify method to perform an image based simplification. 
    139                 void Simplify(Geometry::Real); 
    140  
    141                 /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. Implements the Simplifier::Simplify method to perform an image based simplification. 
    142                 void Simplify(Geometry::uint32); 
     225                public: 
     226                        /// Class constructor. Will call Simplifier class constructor. 
     227                        GeometryBasedSimplifier(        const Geometry::Mesh    *geoMesh, 
     228                                        Geometry::TIPOFUNC              upb=0); 
     229 
     230                        /// Class destructor. 
     231                        ~GeometryBasedSimplifier(void); 
     232 
     233                        /// Copy constructor 
     234                        //GeometryBasedSimplifier(const GeometryBasedSimplifier&); 
     235 
     236                        /// Assignment operator 
     237                        //GeometryBasedSimplifier& operator =(const GeometryBasedSimplifier&); 
     238 
     239                        /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. Implements the Simplifier::Simplify method to perform an image based simplification. 
     240                        void Simplify(Geometry::Real); 
     241 
     242                        /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. Implements the Simplifier::Simplify method to perform an image based simplification. 
     243                        void Simplify(Geometry::uint32); 
    143244        }; 
    144245} // end of Geometry namespace; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Buffer.h

    r1526 r2090  
    3232        { 
    3333                if( fill == len ) 
    34                 resize( len*2 ); 
     34                { 
     35                        resize( len*2 ); 
     36                } 
    3537 
    3638                data[fill] = t; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/bheap.h

    r983 r2090  
    1515 */ 
    1616typedef struct { 
    17     int item;  /* vertex number is used for the item. */ 
     17    int dirty;  /* dirty flag if used for the lazy evaluation */ 
     18    int item;  /* edge number is used for the item. */ 
    1819    double key;  /* distance is used as the key. */ 
    1920} bheap_item_t; 
    2021 
    2122/* Binary heap structure for frontier set in Dijkstra's algorithm. 
    22  * a[] - stores (distance, vertex) pairs of the binary heap. 
     23 * a[] - stores (distance, edge) pairs of the binary heap. 
    2324 * p[] - stores the positions of vertices in the binary heap a[]. 
    2425 * n - is the size of the binary heap. 
     
    5859 */ 
    5960void bh_delete(bheap_t *h, int item); 
     61/* bh_mark() marks an item from the binary heap pointed to by h. 
     62 */ 
     63void bh_mark(bheap_t *h, int item, int flag); 
     64 
     65/* bh_get_key() returns the key value of an item from the binary heap pointed  
     66 * to by h. 
     67 */ 
     68double bh_get_key(bheap_t *h, int item); 
     69 
     70/* bh_is_dirty() returns the dirty value of an item from the binary heap pointed 
     71 * to by h. 
     72 */ 
     73int bh_is_dirty(bheap_t *h, int item); 
    6074 
    6175/* bh_decrease_key() decreases the value of 'item's key and then performs 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/camera.h

    r983 r2090  
    55 
    66#define OCTAHEDRON     6  // number of vertices 
     7#define CUBE           8 
    78#define ICOSAHEDRON   12 
    89#define DODECAHEDRON  20 
     
    2627extern void drawSphere(Camera *cameras, GLdouble radius, int slices, int stacks); 
    2728extern void drawOctahedron(Camera *cameras, GLdouble r); 
     29extern void drawCube(Camera *cameras, GLdouble r); 
    2830extern void drawIcosahedron(Camera *cameras, GLdouble r); 
    2931extern void drawDodecahedron(Camera *cameras, GLdouble r); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/change.h

    r1024 r2090  
    55#include        <vector> 
    66#include        <map> 
     7#include        <GeoMeshSimpSequence.h> 
    78 
    89namespace       VMI 
     
    2021        } Change; 
    2122 
     23        /* 
    2224        // Represents a simplification step in the sequence. 
    2325        struct vmiStep 
     
    4143        extern  std::vector<vmiStep> mVMISteps; 
    4244 
     45        //      Vertex info. 
     46        struct  GeoVertex 
     47        { 
     48                Index           id; 
     49                Index           bonefrom; 
     50                Vector3 position; 
     51                Vector2 texcoord; 
     52                Vector3 normal; 
     53        }; 
     54 
     55        //      Vertices added in simplification. 
     56        std::vector<GeoVertex>  mNewVertices; 
     57        */ 
     58 
     59        // Stores all the simplification steps. 
     60        extern  Geometry::MeshSimplificationSequence *mSequence; 
     61 
    4362        extern Change *createChange (Mesh *mesh, int e); 
     63        extern Change *newChange (Mesh *mesh, int u, int v); 
    4464        extern void writeChange(FILE* file, Change *c); 
    4565        extern void deleteChange(Change *c); 
     
    4767 
    4868        extern void modifyTriangle(Triangle *t, int c, int p); 
    49         extern int isATriangleToModify(Triangle *t, int c, int p); 
    50         extern int getTrianglesToModify(Mesh *mesh, int c, int p, Triangle *modified); 
     69        extern int isATriangleToModify(Triangle *t, int c); 
     70        extern Triangle *getTrianglesToModify(Mesh *mesh, Change *c, GLuint *numMod); 
    5171        extern int isATriangleToDelete(Triangle *t, int c, int p); 
    52         extern int getTrianglesToDelete(Mesh *mesh, int numMod, Triangle *modified, Triangle *deleted, int c, int p); 
     72        extern Triangle *getTrianglesToDelete(Mesh *mesh, Change *c, GLuint *numDel); 
    5373 
    5474        extern void modifyTriangles(Mesh *mesh, Change *c); 
     
    6282        extern void doChange(Mesh *mesh, Change *c); 
    6383        extern void undoChange(Mesh *mesh, Change *c); 
    64         extern void computeChanges(Mesh *mesh, Change *c); 
     84        extern void computeChange(Mesh *mesh, Change *c); 
     85 
     86        extern void modifyEdges(Mesh *mesh, Change *c); 
     87  extern void deleteEdges(Mesh *mesh, Change *c); 
    6588 
    6689        //      Save simplification sequence in Geometry Game Tools format. 
    67         extern void     saveSimplificationSequence(Change       *c); 
     90        extern void     saveSimplificationSequence(Change       *c, int obligatory); 
    6891 
    69         extern std::map<int, INTVECTOR> inversemap; 
     92        //extern std::map<int, INTVECTOR> inversemap; 
     93        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); 
    7096} 
    71  
    7297#endif 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/color.h

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

    r983 r2090  
    88#include "mesh.h" 
    99#include "color.h" 
     10#include "change.h" 
    1011 
    1112//      For progress update. 
     
    5859 
    5960//#define SALIENCY 
     61 
     62// Extension added into the filename 
     63#ifdef KL // Kullback-Leibler 
     64#define EXT "VKL" 
     65#endif 
     66#ifdef MI // Mutual Information 
     67#define EXT "VMI" 
     68#endif 
     69#ifdef HE // Hellinger 
     70#define EXT "VHE" 
     71#endif 
     72#ifdef CS // Chi-Square 
     73#define EXT "VCS" 
     74#endif 
     75 
     76//#define USE_EDGE_ADJACENCY 
    6077 
    6178#define CHECK_OPENGL_ERROR( cmd ) \ 
     
    110127                 bEnableOffScreen, 
    111128                 bSaveLog, 
    112                  bLoadCamerasFromFile; 
     129                 bLoadCamerasFromFile, 
     130                                                                 bRemoveRedundantVertices; 
    113131 
    114132extern GLsizei width, height; 
     
    121139 
    122140extern void renderScene(GLuint **histogram, GLuint numCameras); 
     141extern void renderSceneWin(GLuint **histogram, GLuint numCameras, Change *c); 
    123142 
    124143extern void renderGeometry(void); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/histogram.h

    r983 r2090  
    2020extern void printFullHistogram(GLuint **histogram, GLuint numCameras, GLuint numTriangles); 
    2121extern void getSWHistogram(GLuint *histogram, GLubyte *pixels); 
     22extern void getSWHistogramWin(GLuint *histogram, GLubyte *pixels, GLfloat min[3], GLfloat max[3], Change *c); 
    2223extern void getSWHistoByOcclusionQuery(Mesh *mesh, Color *colors, GLuint *histogram); 
    2324 
    2425extern void resetSWHistogram(GLuint *histogram, GLuint numTriangles); 
    25  
     26extern void getBoundingBox(Change *c, GLfloat min[3], GLfloat max[3]); 
     27extern void getWindow(GLfloat min[3], GLfloat max[3], int minw[2], int maxw[2]); 
    2628} 
    2729 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/interleave.h

    r983 r2090  
    2020    GLfloat x, y, z;    // position 
    2121} Vertex_; 
     22extern GLuint vertex_buf, color_buf; 
    2223 
    2324extern void setupInterleave(Mesh *mesh, Color *colors); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/mesh.h

    r983 r2090  
    1111    GLuint *triangles;   // List of triangles 
    1212    int enable; 
     13                int     movable;        //      If vertex is part of a border. 
    1314} Vertex; 
    1415 
     
    2223typedef struct _Triangle { 
    2324    GLuint              id;         // Triangle id 
     25    GLuint  group;        // Triangle group 
    2426                GLuint          submesh;                // Triangle submesh      
    2527    GLuint              indices[3]; // Triangle vertices 
     
    4547extern void computeTriangleNormal(Vertex *vertices, Triangle *t); 
    4648 
     49extern Vertex *addVertex(Vertex *list, int *n, float x, float y, float z, int *pos); 
    4750extern int findEdge(Edge *e, GLuint num, GLuint _u, GLuint _v); 
     51extern Edge *addEdge(Edge *list, int *n, int u, int v, int *pos); 
    4852extern GLboolean findVertex(GLfloat *vertices, GLuint num, GLfloat x, GLfloat y, GLfloat z, int *pos); 
    4953 
     
    5559 
    5660extern int *trianglesAdjToEdge(Mesh *mesh, int e, int *n); 
    57 extern int *trianglesAdjToVertex(Mesh *mesh, int v, int *n); 
    5861extern int *verticesAdjToVertex(Mesh *mesh, int v, int *n); 
    5962extern int *edgesAdjToVertex(Mesh *mesh, int v, int *n); 
    6063extern int *edgesAdjToVertices(Mesh *mesh, int *vertices, int numVertices, int *n); 
    6164 
     65// list of integers 
    6266extern void printItemList(int *list, int n); 
    6367extern int findItem(int *list, int n, int item); 
    6468extern void addItem(int *list, int *n, int item); 
     69extern void delItem(int *list, int *n, int item); 
    6570 
    6671 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/metrics.h

    r983 r2090  
    88namespace       VMI 
    99{ 
    10 extern GLuint computeBackgroundArea(Mesh *mesh, GLuint *histogram); 
    11 extern GLdouble computeMeanProjArea(GLuint **histogram, GLuint numCameras, int t); 
    1210extern GLdouble computeMI(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint cam); 
     11extern GLdouble decMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c); 
     12extern GLdouble incMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c); 
     13 
    1314extern GLdouble computeHE(Mesh *mesh, GLuint *histogram); 
    1415extern GLdouble computeKL(Mesh *mesh, GLuint *histogram); 
    1516extern GLdouble computeCS(Mesh *mesh, GLuint *histogram); 
    1617 
     18extern GLdouble computeMeanProjArea(GLuint **histogram, GLuint numCameras, int t); 
    1719extern GLdouble computeJS(GLuint **histogram, GLuint numCameras, GLuint j, GLuint k); 
    1820extern GLdouble computeEntropy(GLuint **histogram, GLuint numCameras, GLuint k); 
     
    2123 
    2224extern void getProjectedAreas(GLuint **histogram, GLuint numCameras); 
     25extern void getProjectedAreasWin(GLuint **histogram, GLuint numCameras, Change *c); 
    2326extern void resetProjectedAreas(GLuint **histogram, GLuint numCameras); 
    2427 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/saliency.h

    r983 r2090  
    1414 
    1515extern void computeSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras); 
     16extern void updateTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, int v); 
    1617 
    1718extern double computeTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint k); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/simplify.h

    r1007 r2090  
    77#include "bheap.h" 
    88 
     9#include        <map> 
     10 
     11using   namespace       std; 
     12 
    913namespace       VMI 
    1014{ 
    11 extern GLdouble computeEdgeCost(Mesh *mesh, int e); 
     15        extern GLdouble computeEdgeCost(Mesh *mesh, int e); 
    1216 
    13 extern bheap_t *initHeap(Mesh *mesh); 
     17        extern bheap_t *initHeap(Mesh *mesh); 
    1418 
    15 extern bheap_t *updateHeap(bheap_t *h, Mesh *mesh, Change *c); 
     19        extern bheap_t *updateHeap(bheap_t *h, Mesh *mesh, Change *c); 
    1620 
    17 extern void simplifyModel(Mesh *mesh, GLuint numDemandedTri); 
     21        extern void simplifyModel(Mesh *mesh, GLuint numDemandedTri); 
    1822 
    1923 
    20 extern void bh_mydump(Mesh *mesh, bheap_t *h); 
    21 extern GLdouble computeEdgeLength(Vertex *vertices, int u, int v); 
     24        extern void bh_mydump(Mesh *mesh, bheap_t *h); 
     25        extern GLdouble computeEdgeLength(Vertex *vertices, int u, int v); 
    2226 
    23 extern void swap(unsigned int *i, unsigned int *j); 
    24 extern void chooseBestEndPoints(Mesh *mesh, int e); 
     27        extern void chooseBestEndPoints(Mesh *mesh, int e); 
    2528 
     29        extern void     initVertexMultimap(     Mesh *mesh, 
     30                                                                                                                                        multimap<int,int> &vertexMultimap); 
     31        ///////////////////////////////////////////////////////////////////////////// 
     32        //      Coordinates class. 
     33        ///////////////////////////////////////////////////////////////////////////// 
     34        class _float3_ 
     35        { 
     36                public: 
     37 
     38                        float x,y,z; 
     39 
     40                        _float3_(float x=0.0f, float y=0.0f, float z=0.0f) 
     41                        { 
     42                                this->x = x; this->y = y; this->z = z; 
     43                        } 
     44 
     45                        _float3_(const _float3_ &f) 
     46                        { 
     47                                x=f.x; y=f.y; z=f.z; 
     48                        } 
     49 
     50                        _float3_ & operator=(const _float3_ &f) 
     51                        { 
     52                                x=f.x; y=f.y; z=f.z; return *this; 
     53                        } 
     54 
     55                        bool operator<(const _float3_ &f) const 
     56                        { 
     57                                if (x<f.x) return true; 
     58                                if (x>f.x) return false; 
     59                                if (y<f.y) return true; 
     60                                if (y>f.y) return false; 
     61                                if (z<f.z) return true; 
     62                                if (z>f.z) return false; 
     63                                return false; 
     64                        } 
     65        }; 
     66 
     67        extern int extractValidEdge(Mesh *mesh, bheap_t *h); 
     68 
     69        extern int      isValidEdge(Mesh        *mesh,  int edge); 
     70 
     71        void    deleteVertexOfMap(Mesh  *mesh, int u); 
     72        bool    compareVertices(Vertex *vertices,int    u,      int v); 
     73        void    contractInitialMesh(Mesh        *mesh); 
     74        void    contractTwinVertices(Mesh       *mesh,  int     u,      int     v); 
     75 
     76        //      Vectors of positions, normals and texture coordinates. 
     77        extern  vector<Geometry::Vector3>       vPositions; 
     78        extern  vector<Geometry::Vector3>       vNormals; 
     79        extern  vector<Geometry::Vector2>       vTexCoords; 
    2680} 
    2781 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/bheap.cpp

    r983 r2090  
    154154        } 
    155155    } 
     156} 
     157/* bh_mark() marks an item from the binary heap pointed to by h. 
     158 */ 
     159void bh_mark(bheap_t *h, int item, int flag) 
     160{ 
     161    h->a[h->p[item]].dirty = flag; 
     162} 
     163/* bh_get_key() returns the key value of an item from the binary heap h. 
     164 */ 
     165double bh_get_key(bheap_t *h, int item) 
     166{ 
     167    return h->a[h->p[item]].key; 
     168} 
     169/* bh_is_dirty() returns the dirty value of an item from the binary heap h. 
     170 */ 
     171int bh_is_dirty(bheap_t *h, int item) 
     172{ 
     173    return h->a[h->p[item]].dirty; 
    156174} 
    157175 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/camera.cpp

    r983 r2090  
    174174 
    175175    switch (type) { 
    176     case OCTAHEDRON: 
    177         cameras = (Camera *)malloc(sizeof(Camera) * type); 
     176    case 0: 
     177        cameras = (Camera *)malloc(sizeof(Camera) * OCTAHEDRON); 
    178178        if (cameras == NULL) { 
    179179            fprintf(stderr, "Error allocating memory\n"); 
    180180            exit(1); 
    181181        } 
    182         *numCameras = type; 
     182        *numCameras = OCTAHEDRON; 
    183183        drawOctahedron(cameras, radius); 
    184184        break; 
    185     case ICOSAHEDRON: 
    186         cameras = (Camera *)malloc(sizeof(Camera) * type); 
     185    case 1: 
     186        cameras = (Camera *)malloc(sizeof(Camera) * CUBE); 
    187187        if (cameras == NULL) { 
    188188            fprintf(stderr, "Error allocating memory\n"); 
    189189            exit(1); 
    190190        } 
    191         *numCameras = type; 
    192         drawIcosahedron(cameras, radius); 
     191        *numCameras = CUBE; 
     192        drawCube(cameras, radius); 
    193193        break; 
    194     case DODECAHEDRON: 
    195         cameras = (Camera *)malloc(sizeof(Camera) * type); 
     194    case 2: 
     195        cameras = (Camera *)malloc(sizeof(Camera) * ICOSAHEDRON); 
    196196        if (cameras == NULL) { 
    197197            fprintf(stderr, "Error allocating memory\n"); 
    198198            exit(1); 
    199199        } 
    200         *numCameras = type; 
     200        *numCameras = ICOSAHEDRON; 
     201        drawIcosahedron(cameras, radius); 
     202        break; 
     203    case 3: 
     204        cameras = (Camera *)malloc(sizeof(Camera) * DODECAHEDRON); 
     205        if (cameras == NULL) { 
     206            fprintf(stderr, "Error allocating memory\n"); 
     207            exit(1); 
     208        } 
     209        *numCameras = DODECAHEDRON; 
    201210        drawDodecahedron(cameras, radius); 
    202211        break; 
    203212    default: 
    204         printf("Error cameras not defined\n"); 
     213        printf("Error, cameras not defined\n"); 
    205214        exit(1); 
    206215        break; 
    207216    } 
     217 
     218    printf("Number of cameras: %d\n", *numCameras); 
    208219 
    209220    return cameras; 
     
    506517    copyToCameras(cameras, 12, vertices); 
    507518} 
     519 
     520void VMI::drawCube(Camera *cameras, GLdouble r) // any radius in which the polyhedron is inscribed 
     521{ 
     522    GLdouble vertices[8][3] = { 
     523        {-1, -1, 1},   // vertex v0 
     524        {1,  -1, 1},   // vertex v1 
     525        {1,  -1, -1},  // vertex v2 
     526        {-1, -1, -1},  // vertex v3 
     527        {-1, 1,  1},   // vertex v4 
     528        {1,  1,  1},   // vertex v5 
     529        {1,  1,  -1},  // vertex v6  
     530        {-1, 1,  -1},  // vertex v7 
     531    }; // 8 vertices with x, y, z coordinates 
     532    int i; 
     533#ifdef DRAW_DEBUG 
     534    int tindex[12][3] = { 
     535         
     536        {0, 1, 4}, //polygon v0,v1,v4 
     537        {1, 5, 4}, //polygon v1,v5,v4 
     538        {1, 2, 5}, //polygon v1,v2,v5 
     539        {2, 6, 5}, //polygon v2,v6,v5 
     540        {2, 3, 6}, //polygon v2,v3,v6 
     541        {3, 7, 6}, //polygon v3,v7,v6 
     542        {3, 0, 7}, //polygon v3,v0,v7 
     543        {0, 4, 7}, //polygon v0,v4,v7 
     544        {4, 5, 7}, //polygon v4,v5,v7 
     545        {5, 6, 7}, //polygon v5,v6,v7 
     546        {3, 2, 0}, //polygon v3,v2,v0 
     547        {2, 1, 0}, //polygon v2,v1,v0 
     548    }; 
     549#endif 
     550     
     551    for(i=0; i<8; i++) 
     552    { 
     553        vertices[i][0]*=r; 
     554        vertices[i][1]*=r; 
     555        vertices[i][2]*=r; 
     556    } 
     557 
     558    // map vertices to 12 faces  
     559#ifdef DRAW_DEBUG 
     560     
     561    for (i=0; i<12; i++) {  
     562         
     563        glBegin(GL_POINTS ); 
     564        glVertex3fv(&vertices[tindex[i][0]][0]);  
     565        glVertex3fv(&vertices[tindex[i][1]][0]);  
     566        glVertex3fv(&vertices[tindex[i][2]][0]);     
     567        glEnd();  
     568    } 
     569 
     570#endif 
     571     
     572    copyToCameras(cameras, 8, vertices); 
     573} 
     574 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/change.cpp

    r1024 r2090  
    66#include "../include/change.h" 
    77 
    8 #define MAX_NUM_TRI 250 
    9  
    108using namespace VMI; 
    11  
    12 std::vector<VMI::vmiStep> VMI::mVMISteps; 
    13  
    14 Change *VMI::createChange (Mesh *mesh, int e) { 
    15     Change *c; 
    16      
    17     c = (Change*) malloc (sizeof(Change)); 
    18     if (NULL == c) { 
    19         fprintf (stderr, "no more memory for mesh changes"); 
    20         exit(1); 
    21     } 
    22     c->e = e; 
    23     c->u = mesh->edges[e].u; 
    24     c->v = mesh->edges[e].v; 
    25     c->modified = NULL; 
    26     c->deleted = NULL; 
    27     c->numDel = 0; 
    28     c->numMod = 0; 
    29      
    30     return c; 
     9using namespace std; 
     10 
     11Geometry::MeshSimplificationSequence *VMI::mSequence    =       NULL; 
     12 
     13Change *VMI::createChange(Mesh *mesh, int e) { 
     14        Change *c; 
     15 
     16        c = (Change*) malloc (sizeof(Change)); 
     17        if (NULL == c) { 
     18                fprintf (stderr, "no more memory for a mesh change\n"); 
     19                exit(1); 
     20        } 
     21        c->e = e; 
     22        c->u = mesh->edges[e].u; 
     23        c->v = mesh->edges[e].v; 
     24        c->modified = NULL; 
     25        c->deleted = NULL; 
     26        c->numDel = 0; 
     27        c->numMod = 0; 
     28 
     29        computeChange(mesh, c); 
     30 
     31        return c; 
     32} 
     33 
     34Change *VMI::newChange(Mesh *mesh, int u, int v) { 
     35        Change *c; 
     36 
     37        c = (Change*) malloc (sizeof(Change)); 
     38        if (NULL == c) { 
     39                fprintf (stderr, "no more memory for a mesh change\n"); 
     40                exit(1); 
     41        } 
     42        c->e = -1; // Default edge, not used 
     43        c->u = u; 
     44        c->v = v; 
     45        c->modified = NULL; 
     46        c->deleted = NULL; 
     47        c->numDel = 0; 
     48        c->numMod = 0; 
     49 
     50        computeChange(mesh, c); 
     51 
     52        return c; 
    3153} 
    3254 
     
    91113void VMI::modifyTriangle(Triangle *t, int c, int p) 
    92114{ 
    93  
    94115        if ((int)t->indices[0] == c) 
    95116                t->indices[0]= p; 
     
    100121} 
    101122 
    102 int VMI::isATriangleToModify(Triangle *t, int c, int p) 
     123int VMI::isATriangleToModify(Triangle *t, int c) 
    103124{ 
    104125        int u = t->indices[0], 
     
    109130 
    110131        return FALSE; 
    111 } 
    112  
    113 void VMI::modifyTriangles(Mesh *mesh, Change *c) 
    114 { 
    115         int i, t; 
    116  
    117         for (i=0; i<c->numMod; i++) 
    118         { 
    119                 t = c->modified[i].id; 
    120                 modifyTriangle(&mesh->triangles[t], c->u, c->v); 
    121  
    122                 //printf("New area of triangle %d:\n", t); 
    123                 mesh->triangles[t].area = computeTriangleArea(mesh->vertices, &mesh->triangles[t]); 
    124  
    125                 computeTriangleNormal(mesh->vertices, &mesh->triangles[t]); 
    126         } 
    127 } 
    128  
    129 void VMI::unmodifyTriangles(Mesh *mesh, Change *c) 
    130 { 
    131         int i, t; 
    132  
    133         for (i=0; i<c->numMod; i++) { 
    134                 t = c->modified[i].id; 
    135  
    136                 memcpy(&mesh->triangles[t], &c->modified[i], sizeof(Triangle)); 
    137                 /*printf("t(%d %d %d)\n", mesh->triangles[t].indices[0],  
    138                         mesh->triangles[t].indices[1], 
    139                         mesh->triangles[t].indices[2]);*/ 
    140         } 
    141 } 
    142  
    143 void VMI::deleteTriangles(Mesh *mesh, Change *c) 
    144 { 
    145         int i, t; 
    146  
    147         for (i=0; i<c->numDel; i++) 
    148         { 
    149                 t = c->deleted[i].id; 
    150  
    151                 //printf("Deleting triangle %d\n",t); 
    152                 mesh->triangles[t].enable = FALSE; 
    153                 mesh->currentNumTriangles--; 
    154         } 
    155 } 
    156  
    157 void VMI::undeleteTriangles(Mesh *mesh, Change *c) 
    158 { 
    159         int i, t; 
    160  
    161         for (i=0; i<c->numDel; i++) 
    162         { 
    163                 t = c->deleted[i].id; 
    164  
    165                 memcpy(&mesh->triangles[t], &c->deleted[i], sizeof(Triangle)); 
    166                 /*printf("t(%d %d %d)\n", mesh->triangles[t].indices[0],  
    167                         mesh->triangles[t].indices[1],  
    168                         mesh->triangles[t].indices[2]);*/ 
    169  
    170                 mesh->triangles[t].enable = TRUE; 
    171                 mesh->currentNumTriangles++; 
    172         } 
    173 } 
    174  
    175 int VMI::getTrianglesToModify(Mesh *mesh, int c, int p, Triangle *modified) 
    176 { 
    177         GLuint i, num = 0; 
    178  
    179         for (i=0; i<mesh->numTriangles; i++) 
    180         { 
    181                 if ((mesh->triangles[i].enable == TRUE) &&  
    182                                 isATriangleToModify(&mesh->triangles[i], c, p)) 
    183                 { 
    184  
    185                         //printf("Triangle to modify %d\n", i); 
    186                         // Save the original values of the triangle 
    187                         memcpy(&modified[num], &mesh->triangles[i], sizeof(Triangle)); 
    188                         num++; 
    189                 } 
    190         } 
    191  
    192         return num; 
    193132} 
    194133 
     
    211150} 
    212151 
    213 int VMI::getTrianglesToDelete(Mesh *mesh, int numMod, Triangle *modified, Triangle *deleted, int c, int p) 
    214 { 
    215         int i, num = 0; 
    216         GLuint t; 
    217  
    218         for (i=0; i<numMod; i++) 
    219         { 
    220                 t = modified[i].id; 
    221  
    222                 if (isATriangleToDelete(&mesh->triangles[t], c, p)) 
    223                 {                                              
    224                         //printf("Triangle to delete %d\n",t);                     
    225                         memcpy(&deleted[num], &modified[i], sizeof(Triangle)); 
    226                         num++; 
    227                 } 
    228         } 
    229         return num; 
    230 } 
    231  
    232 void VMI::printList(Triangle *list, int n) 
    233 { 
    234         int i; 
    235  
    236         for (i=0; i<n; i++) 
    237                 printf("%d ",list[i].id); 
    238  
    239         printf("\n"); 
    240 } 
    241  
    242 void VMI::deleteItem(Triangle *list, int *n, int item) 
    243 { 
    244         int i, j; 
    245  
    246         for (i=0; i<*n; i++) 
    247         { 
    248                 if (list[i].id == (GLuint)item) 
    249                 { 
    250                         // delete it 
    251                         for (j =i + 1 ; j<*n; j++) 
    252                                 list[j - 1] = list[j]; 
    253                         (*n)--; 
    254                         i--; // Delete all ocurrencies of an item 
    255                 } 
    256         } 
     152void VMI::modifyTriangles(Mesh *mesh, Change *c) 
     153{ 
     154        int i, t; 
     155 
     156        // Reallocate memory for new adjacent triangles from vertex v 
     157  if (c->numMod > 0) { 
     158      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)); 
     161  } 
     162 
     163        for (i=0; i<c->numMod; i++) { 
     164                t = c->modified[i].id; 
     165                modifyTriangle(&mesh->triangles[t], c->u, c->v); 
     166 
     167                //printf("New area of triangle %d:\n", t); 
     168                mesh->triangles[t].area = computeTriangleArea(mesh->vertices, &mesh->triangles[t]); 
     169 
     170                computeTriangleNormal(mesh->vertices, &mesh->triangles[t]); 
     171 
     172                // Update vertex adjacency c->v 
     173                addItem((int *)mesh->vertices[c->v].triangles, (int *)&mesh->vertices[c->v].numTriangles, t); 
     174        } 
     175} 
     176 
     177void VMI::unmodifyTriangles(Mesh *mesh, Change *c) 
     178{ 
     179        int i, t; 
     180 
     181        for (i=0; i<c->numMod; i++) { 
     182                t = c->modified[i].id; 
     183 
     184                memcpy(&mesh->triangles[t], &c->modified[i], sizeof(Triangle)); 
     185                /*printf("t(%d %d %d)\n", mesh->triangles[t].indices[0],  
     186                        mesh->triangles[t].indices[1], 
     187                        mesh->triangles[t].indices[2]);*/ 
     188 
     189                // Update vertex adjacency c->v 
     190                delItem((int *)mesh->vertices[c->v].triangles, (int *)&mesh->vertices[c->v].numTriangles, t); 
     191        } 
     192 
     193} 
     194 
     195int 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 
     205void 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 
     230void VMI::swap(int *i, int *j) { 
     231    int t; 
     232 
     233    t = *i; 
     234    *i = *j; 
     235    *j = t; 
     236} 
     237 
     238void VMI::deleteTriangles(Mesh *mesh, Change *c) 
     239{ 
     240            int i, j, t, v; 
     241#ifdef USE_EDGE_ADJACENCY 
     242    int t1, l, r; 
     243#endif 
     244     
     245    for (i=0; i<c->numDel; i++) { 
     246        t = c->deleted[i].id; 
     247 
     248        //printf("%d(%d,%d) Deleting triangle %d\n",c->e, c->u, c->v, t); 
     249 
     250        // Update vertex adjacency 
     251        for (j=0; j<3; j++) { 
     252            v = c->deleted[i].indices[j]; 
     253             
     254            delItem((int *)mesh->vertices[v].triangles,(int *)&mesh->vertices[v].numTriangles,t); 
     255        } 
     256 
     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 
     279        mesh->triangles[t].enable = FALSE; 
     280        mesh->currentNumTriangles--; 
     281    } 
     282} 
     283 
     284void VMI::undeleteTriangles(Mesh *mesh, Change *c) { 
     285    int i, j, t, v; 
     286     
     287    for (i=0; i<c->numDel; i++) { 
     288        t = c->deleted[i].id; 
     289         
     290        //printf("Undeleting triangle %d\n",t); 
     291 
     292        memcpy(&mesh->triangles[t], &c->deleted[i], sizeof(Triangle)); 
     293        /*printf("t(%d %d %d)\n", mesh->triangles[t].indices[0],  
     294                                  mesh->triangles[t].indices[1],  
     295                                  mesh->triangles[t].indices[2]);*/ 
     296 
     297        // Update vertex adjacency 
     298        for (j=0; j<3; j++) { 
     299            v = c->deleted[i].indices[j]; 
     300             
     301            addItem((int *)mesh->vertices[v].triangles,(int *)&mesh->vertices[v].numTriangles,t); 
     302        } 
     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 
     309        mesh->triangles[t].enable = TRUE; 
     310        mesh->currentNumTriangles++; 
     311    } 
     312} 
     313 
     314Triangle *VMI::getTrianglesToModify(Mesh *mesh, Change *c, GLuint *numMod) { 
     315  int i, t; 
     316  Triangle *modified = NULL; 
     317 
     318  // Allocating memory 
     319  modified = (Triangle *)malloc(mesh->vertices[c->u].numTriangles * sizeof(Triangle)); 
     320  *numMod = 0; 
     321   
     322  for (i=0; i<(int)mesh->vertices[c->u].numTriangles; i++) { 
     323       
     324      t = mesh->vertices[c->u].triangles[i]; 
     325       
     326      if ((mesh->triangles[t].enable == TRUE) &&  
     327          !isATriangleToDelete(&mesh->triangles[t], c->u, c->v)) { 
     328           
     329          //printf("Triangle to modify %d\n", t); 
     330          // Save the original values of the triangle 
     331          memcpy(&modified[*numMod], &mesh->triangles[t], sizeof(Triangle)); 
     332          (*numMod)++; 
     333      } 
     334  } 
     335  return modified; 
     336} 
     337 
     338Triangle *VMI::getTrianglesToDelete(Mesh *mesh, Change *c, GLuint *numDel) { 
     339  int i, t; 
     340  Triangle *deleted = NULL; 
     341   
     342  // Allocating memory 
     343  deleted = (Triangle *)malloc(mesh->vertices[c->u].numTriangles * sizeof(Triangle)); 
     344  *numDel = 0; 
     345 
     346  for (i=0; i<(int)mesh->vertices[c->u].numTriangles; i++) { 
     347       
     348      t = mesh->vertices[c->u].triangles[i]; 
     349 
     350      if ((mesh->triangles[t].enable == TRUE) && 
     351          isATriangleToDelete(&mesh->triangles[t], c->u, c->v)) { 
     352                                                     
     353          //printf("Triangle to delete %d\n",t);                     
     354          memcpy(&deleted[*numDel], &mesh->triangles[t], sizeof(Triangle)); 
     355          (*numDel)++; 
     356      } 
     357  } 
     358  return deleted; 
     359} 
     360 
     361void VMI::deleteEdges(Mesh *mesh, Change *c) { 
     362    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++) { 
     371         
     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 
     420void 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         
     426        if (mesh->edges[e].enable == TRUE) { 
     427             
     428            // Modify edge 
     429            if ((int)mesh->edges[e].u == c->u) 
     430                mesh->edges[e].u = c->v; 
     431             
     432            if ((int)mesh->edges[e].v == c->u) 
     433                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; 
     444        } 
     445    } 
    257446} 
    258447 
     
    260449 
    261450// Compute the triangle mesh changes due to a heap node simplification 
    262 void VMI::computeChanges(Mesh *mesh, Change *c) 
    263 { 
    264         Triangle m[MAX_NUM_TRI], d[MAX_NUM_TRI/2]; 
    265         int numMod = getTrianglesToModify(mesh, c->u, c->v, m); 
    266         int numDel = getTrianglesToDelete(mesh, numMod, m, d, c->u, c->v); 
    267         int i; 
    268  
    269         //printf("d %d\n",numDel); 
    270         //printList(d, numDel); 
    271  
    272         for (i=0; i<numDel; i++) 
    273                 deleteItem(m, &numMod, d[i].id); 
    274  
    275         //printf("m %d\n",numMod); 
    276         //printList(m, numMod); 
    277         //getchar(); 
    278  
    279         c->numDel = numDel; 
    280         // Free memory 
    281         if (c->deleted != NULL) free(c->deleted); 
    282         // Allocate memory 
    283         c->deleted = (Triangle *)malloc(sizeof(Triangle) * numDel); 
    284          
    285         if (c->deleted == NULL) 
    286         { 
    287                 fprintf(stderr, "Error allocating memory\n"); 
    288                 exit(1); 
    289         } 
    290          
    291         memcpy(c->deleted, d, sizeof(Triangle) * numDel); 
    292  
    293         c->numMod = numMod; 
    294          
    295         // Free memory 
    296         if (c->modified != NULL) free(c->modified); 
    297          
    298         // Allocate memory 
    299         c->modified = (Triangle *)malloc(sizeof(Triangle) * numMod); 
    300          
    301         if (c->modified == NULL) 
    302         { 
    303                 fprintf(stderr, "Error allocating memory\n"); 
    304                 exit(1); 
    305         } 
    306          
    307         memcpy(c->modified, m, sizeof(Triangle) * numMod); 
    308  
    309         //printChange(c); 
    310         //getchar(); 
     451void VMI::computeChange(Mesh *mesh, Change *c) { 
     452  GLuint numMod, numDel; 
     453  Triangle *m = getTrianglesToModify(mesh, c, &numMod), 
     454            *d = getTrianglesToDelete(mesh, c, &numDel); 
     455   
     456  c->numDel   = numDel; 
     457  c->deleted  = d; 
     458   
     459  c->numMod   = numMod; 
     460  c->modified = m; 
     461 
     462  //printChange(c); 
     463  //getchar(); 
    311464} 
    312465 
     
    316469        modifyTriangles(mesh, c); 
    317470 
     471        // This function must be called after modifyTriangles() 
    318472        deleteTriangles(mesh, c); 
    319473 
     474        // Delete vertex u 
    320475        mesh->vertices[c->u].enable = FALSE; 
    321476        mesh->currentNumVertices--; 
     477 
     478        //printMesh(mesh); 
     479        //getchar(); 
    322480} 
    323481 
    324482void VMI::undoChange(Mesh *mesh, Change *c) 
    325 {     
     483{ 
    326484        unmodifyTriangles(mesh, c); 
    327485 
     
    330488        mesh->vertices[c->u].enable = TRUE; 
    331489        mesh->currentNumVertices++; 
    332 } 
    333  
     490 
     491        //printMesh(mesh); 
     492        //getchar(); 
     493} 
     494 
     495/* 
    334496namespace VMI{ 
    335497std::map<int, INTVECTOR> inversemap; 
    336498} 
     499*/ 
    337500 
    338501//      Save simplification sequence in Geometry Game Tools format. 
    339 extern void     VMI::saveSimplificationSequence(Change  *c) 
    340 { 
    341  
    342         int stepnum= 1; 
    343         for(INTVECTOR::iterator it= inversemap[c->u].begin(); it!=inversemap[c->u].end(); it++) 
     502extern void     VMI::saveSimplificationSequence(Change  *c,int obligatory) 
     503{ 
     504        Geometry::MeshSimplificationSequence::Step      step; 
     505 
     506        if (mSequence == NULL) 
    344507        { 
    345                 vmiStep step; 
    346                 step.mV0        =       *it; 
    347                 step.mV1        =       c->v; 
    348  
    349                 //      If only one triangle has been deleted. 
    350                 if (c->numDel == 1) 
    351                 { 
    352                         step.mT0        =       c->deleted[0].id; 
    353                         step.mT1        =       c->deleted[0].id; 
    354                 } 
    355                 //      If two triangles have been deleted. 
    356                 else 
    357                 { 
    358                         step.mT0        =       c->deleted[0].id; 
    359                         step.mT1        =       c->deleted[1].id; 
    360                 } 
    361  
    362                 step.x  =       0.0; 
    363                 step.y  =       0.0; 
    364                 step.z  =       0.0; 
    365  
    366                 //      Write obligatory field. 
    367                 if (stepnum==inversemap[c->u].size()) 
    368                         step.obligatory =       0; 
    369                 else 
    370                         step.obligatory =       1; 
    371                 stepnum++; 
    372  
    373                 //      List of new triangles. 
    374                 //      For each modified triangle. 
    375                 for (int        i = 0;  i < c->numMod;  i++) 
    376                 { 
    377                         step.mModfaces.push_back(c->modified[i].id); 
    378                 } 
    379  
    380                 //      Add step to list of changes. 
    381                 mVMISteps.push_back(step); 
    382         } 
    383 } 
     508                mSequence       =       new Geometry::MeshSimplificationSequence(); 
     509        } 
     510 
     511        step.mV0        =       c->v; 
     512        step.mV1        =       c->u; 
     513 
     514        //      Debug. 
     515        cout    <<      "----> V0: " 
     516                                <<      step.mV0 
     517                                <<      " V1: " 
     518                                <<      step.mV1 
     519                                <<      endl; 
     520 
     521        //      If only one triangle has been deleted. 
     522        if (c->numDel == 1) 
     523        { 
     524                step.mT0        =       c->deleted[0].id; 
     525                step.mT1        =       c->deleted[0].id; 
     526        } 
     527        //      If two triangles have been deleted. 
     528        else 
     529        { 
     530                step.mT0        =       c->deleted[0].id; 
     531                step.mT1        =       c->deleted[1].id; 
     532        } 
     533 
     534        step.x  =       0.0; 
     535        step.y  =       0.0; 
     536        step.z  =       0.0; 
     537 
     538        //      Write obligatory field. 
     539        step.obligatory =       obligatory; 
     540 
     541        //      List of new triangles. 
     542        //      For each modified triangle. 
     543        for (int        i = 0;  i < c->numMod;  i++) 
     544        { 
     545                step.mModfaces.push_back(c->modified[i].id); 
     546        } 
     547 
     548        //      Add step to list of changes. 
     549        mSequence->mSteps.push_back(step); 
     550} 
     551 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/color.cpp

    r983 r2090  
    77using namespace VMI; 
    88 
    9 Color *VMI::initColors(GLuint numTriangles) { 
     9Color *VMI::initColors(GLuint numColors) { 
    1010    Color *colors; 
    1111 
    12     colors = (Color *)malloc(sizeof(Color) * (numTriangles + 1)); // Triangles start at 1 
     12    colors = (Color *)malloc(sizeof(Color) * (numColors + 1)); 
     13                /* The 0 position is reserved for the BACKGROUND, thus color of triangle 0 
     14       is at 1 position and so on */ 
    1315 
    1416    if (colors == NULL) { 
     
    1719    } 
    1820 
    19     // Fill the color buffer with BACKGROUND 
    20     memset(colors, BACKGROUND, sizeof(Color) * (numTriangles + 1)); 
     21    /* Fill the color buffer with the BACKGROUND color */ 
     22    memset(colors, BACKGROUND, sizeof(Color) * (numColors + 1)); 
    2123 
    2224    return colors; 
    2325} 
    2426 
    25 void VMI::fillAllColors(Color *colors, GLuint numTriangles, GLuint begin, GLuint end, GLubyte color) { 
     27void VMI::fillAllColors(Color *colors, GLuint numColors, GLuint begin, GLuint end, GLubyte color) { 
    2628    GLuint i; 
    2729 
    28     if (end > numTriangles) return; 
     30    if (end > numColors) return; 
    2931 
    3032    for (i=begin; i<end; i++) { 
     
    8486} 
    8587 
    86 void VMI::setColors2(Color *colors, GLuint numTriangles, GLuint begin, GLuint end) { 
     88void VMI::setColors2(Color *colors, GLuint numColors, GLuint begin, GLuint end) { 
    8789    GLuint i,  
    8890        channel = 0, 
    89         step = (numTriangles < MAX_NUM_COLORS) ? (MAX_NUM_COLORS / numTriangles) : 1; 
     91        step = (numColors < MAX_NUM_COLORS) ? (MAX_NUM_COLORS / numColors) : 1; 
    9092    GLubyte r = 1; 
    9193 
    92     if (end > numTriangles) return; 
     94    if (end > numColors) return; 
    9395 
    9496    for (i = begin; i < end; i++) { 
     
    126128            channel = 0; 
    127129        } 
    128         //printf("c:%d (%d,%d,%d,%d)\n",i, colors[i].r, colors[i].g, colors[i].b,  colors[i].a); 
     130        //printf("c:%d (%d,%d,%d,%d)\n", i, colors[i].r, colors[i].g, colors[i].b,  colors[i].a); 
    129131        //getchar(); 
    130132    } 
    131133} 
    132134 
    133 void VMI::setColors3(Color *colors, GLuint numTriangles, GLubyte color) { 
     135void VMI::setColors3(Color *colors, GLuint numColors, GLubyte color) { 
    134136    GLuint i; 
    135137     
    136     for (i = 0; i < numTriangles; i++) { 
     138    for (i = 0; i < numColors; i++) { 
    137139 
    138140        colors[i].r = color; 
     
    141143        colors[i].a = 0; 
    142144 
    143         //printf("c:%d (%d,%d,%d,%d)\n",i, colors[i].r, colors[i].g, colors[i].b,  colors[i].a); 
     145        //printf("c:%d (%d,%d,%d,%d)\n", i, colors[i].r, colors[i].g, colors[i].b,  colors[i].a); 
    144146        //getchar(); 
    145147    } 
    146148} 
    147149 
    148 void VMI::setColors4(Color *colors, GLuint numTriangles) { 
     150void VMI::setColors4(Color *colors, GLuint numColors) { 
    149151    GLuint i, c = 1; 
    150152     
    151     for (i = 0; i < numTriangles; i++) { 
     153    for (i = 0; i < numColors; i++) { 
    152154 
    153155        colors[i].r = c & 0xFF; 
     
    156158        colors[i].a = (c & 0xFF000000) >> 24; 
    157159 
    158         //printf("c:%d (%d,%d,%d,%d)\n",i, colors[i].r, colors[i].g, colors[i].b,  colors[i].a); 
     160        //printf("c:%d (%d,%d,%d,%d)\n", i, colors[i].r, colors[i].g, colors[i].b,  colors[i].a); 
    159161        c++;  
    160162    } 
     
    162164} 
    163165 
    164 void VMI::viewColors(Color *colors, GLuint numTriangles) { 
     166void VMI::viewColors(Color *colors, GLuint numColors) { 
    165167    GLuint i; 
    166168 
    167169    printf("\n"); 
    168     for (i=0; i<numTriangles; i++)  
    169         printf("c:%d (%d,%d,%d,%d)\n",i, colors[i].r, colors[i].g, colors[i].b,  colors[i].a); 
     170    for (i=0; i<numColors; i++)  
     171        printf("c:%d (%d,%d,%d,%d)\n", i, colors[i].r, colors[i].g, colors[i].b,  colors[i].a); 
    170172} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/glm.c

    r983 r2090  
    135135    copied = 1; 
    136136    for (i = 1; i <= *numvectors; i++) { 
    137         for (j = 1; j <= copied; j++) { 
     137        for (j = 1; j </*=*/ copied; j++) { 
    138138            if (glmEqual(&vectors[3 * i], &copies[3 * j], epsilon)) { 
    139139                goto duplicate; 
     
    17231723    vectors  = model->vertices; 
    17241724    copies = glmWeldVectors(vectors, &numvectors, epsilon); 
    1725      
    1726 #if 0 
     1725 
     1726//#if 0 
    17271727    printf("glmWeld(): %d redundant vertices.\n",  
    1728         model->numvertices - numvectors - 1); 
    1729 #endif 
     1728        model->numvertices - numvectors /* - 1*/); 
     1729//#endif 
    17301730     
    17311731    for (i = 0; i < model->numtriangles; i++) { 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/histogram.cpp

    r983 r2090  
    99#include "../include/histogram.h" 
    1010#include "../include/metrics.h" 
     11 
     12#define WIN_MARGIN 2 
    1113 
    1214using namespace VMI; 
     
    185187} 
    186188 
     189void VMI::getBoundingBox(Change *c, GLfloat min[3], GLfloat max[3]) { 
     190    GLuint  i, j, t, v; 
     191    GLfloat maxx = 0.0f, minx = 0.0f,  
     192            maxy = 0.0f, miny = 0.0f, 
     193            maxz = 0.0f, minz = 0.0f; 
     194     
     195    /* get the max/mins */ 
     196    for (i=0; i<(GLuint)c->numMod; i++) { 
     197        t = c->modified[i].id; 
     198         
     199        for (j=0; j<3; j++) { 
     200            v = mesh->triangles[t].indices[j]; 
     201            // v 
     202            if (maxx < mesh->vertices[v].x) 
     203                maxx = mesh->vertices[v].x; 
     204            if (minx > mesh->vertices[v].x) 
     205                minx = mesh->vertices[v].x; 
     206             
     207            if (maxy < mesh->vertices[v].y) 
     208                maxy = mesh->vertices[v].y; 
     209            if (miny > mesh->vertices[v].y) 
     210                miny = mesh->vertices[v].y; 
     211             
     212            if (maxz < mesh->vertices[v].z) 
     213                maxz = mesh->vertices[v].z; 
     214            if (minz > mesh->vertices[v].z) 
     215                minz = mesh->vertices[v].z; 
     216        } 
     217    } 
     218 
     219    for (i=0; i<(GLuint)c->numDel; i++) { 
     220        t = c->deleted[i].id; 
     221         
     222        for (j=0; j<3; j++) { 
     223            v = mesh->triangles[t].indices[j]; 
     224            // v 
     225            if (maxx < mesh->vertices[v].x) 
     226                maxx = mesh->vertices[v].x; 
     227            if (minx > mesh->vertices[v].x) 
     228                minx = mesh->vertices[v].x; 
     229             
     230            if (maxy < mesh->vertices[v].y) 
     231                maxy = mesh->vertices[v].y; 
     232            if (miny > mesh->vertices[v].y) 
     233                miny = mesh->vertices[v].y; 
     234             
     235            if (maxz < mesh->vertices[v].z) 
     236                maxz = mesh->vertices[v].z; 
     237            if (minz > mesh->vertices[v].z) 
     238                minz = mesh->vertices[v].z; 
     239        } 
     240    } 
     241 
     242    min[0] = minx; 
     243    min[1] = miny; 
     244    min[2] = minz; 
     245 
     246    max[0] = maxx; 
     247    max[1] = maxy; 
     248    max[2] = maxz; 
     249} 
     250 
     251void VMI::getWindow(GLfloat min[3], GLfloat max[3], int minw[2], int maxw[2]) { 
     252    GLdouble winx, winy, winz, 
     253             mv[16], pm[16]; 
     254    GLint vp[4], minx, miny, maxx, maxy; 
     255 
     256    glGetDoublev(GL_MODELVIEW_MATRIX, mv); 
     257    glGetDoublev(GL_PROJECTION_MATRIX, pm); 
     258    glGetIntegerv(GL_VIEWPORT, vp); 
     259     
     260    /* The eight points of the bounding box */ 
     261    /* Point 1 (min,min,min) */ 
     262    gluProject((GLdouble)min[0], (GLdouble)min[1], (GLdouble)min[2], mv, pm, vp, &winx, &winy, &winz); 
     263    minx = winx; 
     264    maxx = winx; 
     265    miny = winy; 
     266    maxy = winy; 
     267 
     268    /* Point 2 (max,min,min) */ 
     269    gluProject((GLdouble)max[0], (GLdouble)min[1], (GLdouble)min[2], mv, pm, vp, &winx, &winy, &winz); 
     270    if (winx < minx) minx =winx; 
     271    if (winx > maxx) maxx =winx; 
     272    if (winy < miny) miny =winy; 
     273    if (winy > maxy) maxy =winy; 
     274 
     275    /* Point 3 (min,max,min) */ 
     276    gluProject((GLdouble)min[0], (GLdouble)max[1], (GLdouble)min[2], mv, pm, vp, &winx, &winy, &winz); 
     277    if (winx < minx) minx =winx; 
     278    if (winx > maxx) maxx =winx; 
     279    if (winy < miny) miny =winy; 
     280    if (winy > maxy) maxy =winy; 
     281 
     282    /* Point 4 (max,max,min) */ 
     283    gluProject((GLdouble)max[0], (GLdouble)max[1], (GLdouble)min[2], mv, pm, vp, &winx, &winy, &winz); 
     284    if (winx < minx) minx =winx; 
     285    if (winx > maxx) maxx =winx; 
     286    if (winy < miny) miny =winy; 
     287    if (winy > maxy) maxy =winy; 
     288 
     289    /* Point 5 (min,min,max) */ 
     290    gluProject((GLdouble)min[0], (GLdouble)min[1], (GLdouble)max[2], mv, pm, vp, &winx, &winy, &winz); 
     291    if (winx < minx) minx =winx; 
     292    if (winx > maxx) maxx =winx; 
     293    if (winy < miny) miny =winy; 
     294    if (winy > maxy) maxy =winy; 
     295 
     296    /* Point 6 (max,min,max) */ 
     297    gluProject((GLdouble)max[0], (GLdouble)min[1], (GLdouble)max[2], mv, pm, vp, &winx, &winy, &winz); 
     298    if (winx < minx) minx =winx; 
     299    if (winx > maxx) maxx =winx; 
     300    if (winy < miny) miny =winy; 
     301    if (winy > maxy) maxy =winy; 
     302 
     303    /* Point 7 (min,max,max) */ 
     304    gluProject((GLdouble)min[0], (GLdouble)max[1], (GLdouble)max[2], mv, pm, vp, &winx, &winy, &winz); 
     305    if (winx < minx) minx =winx; 
     306    if (winx > maxx) maxx =winx; 
     307    if (winy < miny) miny =winy; 
     308    if (winy > maxy) maxy =winy; 
     309 
     310    /* Point 8 (max,max,max) */ 
     311    gluProject((GLdouble)max[0], (GLdouble)max[1], (GLdouble)max[2], mv, pm, vp, &winx, &winy, &winz); 
     312    if (winx < minx) minx =winx; 
     313    if (winx > maxx) maxx =winx; 
     314    if (winy < miny) miny =winy; 
     315    if (winy > maxy) maxy =winy; 
     316 
     317    minw[0] = minx; 
     318    minw[1] = miny; 
     319 
     320    maxw[0] = maxx; 
     321    maxw[1] = maxy; 
     322} 
     323 
     324void VMI::getSWHistogramWin(GLuint *histogram, GLubyte *pixels, GLfloat min[3], GLfloat max[3], Change *c) { 
     325    GLubyte r, g, b, a; 
     326    GLuint i, t, p, numPixels, 
     327          *histoAux = (GLuint *)calloc(mesh->numTriangles + 1, sizeof(GLuint)); 
     328    GLint minw[2], maxw[2], ox, oy, h, w; 
     329 
     330    getWindow(min, max, minw, maxw); 
     331 
     332    w = ABS(maxw[0] - minw[0]); 
     333    h = ABS(maxw[1] - minw[1]); 
     334    //printf("w:%d h:%d\n", w, h); 
     335 
     336    ox = minw[0]; 
     337    oy = minw[1]; 
     338 
     339    ox -= WIN_MARGIN; 
     340    if (ox < 0)  ox = 0; 
     341    oy -= WIN_MARGIN; 
     342    if (oy < 0)  oy = 0; 
     343 
     344    w += (WIN_MARGIN * 2); 
     345    if (w > width)  w = width; 
     346    h += (WIN_MARGIN * 2); 
     347    if (h > height) h = height; 
     348 
     349    //printf("(%d,%d)\n", ox, oy); 
     350    //printf("w:%d h:%d\n", w, h); 
     351    //getchar(); 
     352 
     353    numPixels = w * h; 
     354    //printf("NumPixels: %d\n", numPixels); 
     355 
     356    glReadPixels(ox, oy, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 
     357 
     358    for (i=0; i<numPixels; i++) { // pixel i 
     359        p = i << 2; // 4 * i 
     360        r = pixels[p]; 
     361        g = pixels[p + 1]; 
     362        b = pixels[p + 2]; 
     363        a = pixels[p + 3]; 
     364 
     365        t = r + (g << 8) + (b << 16) + (a << 24); // triangle color 
     366        //printf("pixel:%d (%d,%d,%d,%d) t %d\n", i, r, g, b, a, t); 
     367 
     368        histoAux[t]++;    
     369    } 
     370 
     371    for (i=0; i<(GLuint)c->numMod; i++) { 
     372        t = (GLuint)c->modified[i].id; 
     373 
     374        histogram[t + 1] = histoAux[t + 1];  
     375    } 
     376 
     377    free(histoAux); 
     378    //getchar(); 
     379} 
     380 
    187381void VMI::getSWHistoByOcclusionQuery(Mesh *mesh, Color *colors, GLuint *histogram) { 
    188382    GLuint i, v1, v2, v3; 
    189     GLint area; 
     383    GLint area, totalArea = 0; 
    190384 
    191385    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
     
    196390            glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries[i]); 
    197391             
    198             // Render triangle i 
     392            /* Render triangle i */ 
    199393            glBegin(GL_TRIANGLES); 
    200394            v1= mesh->triangles[i].indices[0]; 
     
    226420            } else { 
    227421                histogram[i + 1] = area; 
     422 
     423                totalArea += area; 
    228424            } 
    229425        } 
    230426    } 
    231     histogram[0] = computeBackgroundArea(mesh, histogram); // Compute area of the background 
    232  
     427 
     428    /* Compute the background area */ 
     429    histogram[0] = (width * height) - totalArea; 
     430 
     431    //printf("background area: %d\n", histogram[0]); 
    233432} 
    234433 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/interleave.cpp

    r983 r2090  
    1717static Color   *buf_colors = NULL; 
    1818 
    19 static GLuint vertex_buf = 0, 
     19GLuint vertex_buf = 0, 
    2020       color_buf = 0; 
    2121} 
     
    100100    setupVertexArray(mesh, colors); 
    101101     
    102     // Disable the vertex array functionality: 
    103     glDisableClientState(GL_VERTEX_ARRAY); 
    104     glDisableClientState(GL_COLOR_ARRAY); 
    105      
    106     glDeleteBuffersARB(1, &vertex_buf); 
    107      
    108     glGenBuffersARB(1, &vertex_buf); 
    109102    glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); 
    110103    glBufferDataARB(GL_ARRAY_BUFFER_ARB, mesh->currentNumTriangles * 3 * 3 * sizeof(float), buf_vertices, GL_STATIC_DRAW_ARB); //upload data 
    111104     
    112     glDeleteBuffersARB(1, &color_buf); 
    113      
    114     glGenBuffersARB(1, &color_buf); 
    115105    glBindBufferARB(GL_ARRAY_BUFFER_ARB, color_buf); 
    116106    glBufferDataARB(GL_ARRAY_BUFFER_ARB, mesh->currentNumTriangles * 3 * sizeof(Color), buf_colors, GL_STATIC_DRAW_ARB); //upload data 
     
    182172    updateVertexArray(mesh); 
    183173     
    184     // Disable the vertex array functionality: 
    185     glDisableClientState(GL_VERTEX_ARRAY); 
    186      
    187     glDeleteBuffersARB(1, &vertex_buf); 
    188      
    189     glGenBuffersARB(1, &vertex_buf); 
    190174    glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); 
    191175    glBufferDataARB(GL_ARRAY_BUFFER_ARB, mesh->currentNumTriangles * 3 * 3 * sizeof(float), buf_vertices, GL_STATIC_DRAW_ARB); //upload data 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/main.cpp

    r983 r2090  
    2525          bBeQuiet         = GL_FALSE, 
    2626          bSaveLog         = GL_FALSE, 
    27           bLoadCamerasFromFile = GL_FALSE; 
     27          bLoadCamerasFromFile = GL_FALSE, 
     28          bRemoveRedundantVertices = GL_TRUE; 
    2829 
    2930GLuint cameraType = 0, 
     
    5556    gluPerspective(fov, (GLdouble)width / height, 0.1, 40.0); 
    5657     
    57     glPixelStorei(GL_PACK_ALIGNMENT, 1); 
    58     glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
     58    //glPixelStorei(GL_PACK_ALIGNMENT, 1); 
     59    //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
    5960     
    6061    glShadeModel(GL_FLAT); 
     
    6263    glDisable(GL_BLEND); 
    6364 
    64     //glEnable(GL_CULL_FACE); // important 
     65    glEnable(GL_CULL_FACE); // important 
    6566 
    6667    glEnable(GL_DEPTH_TEST); 
    67     glDepthFunc(GL_LEQUAL); 
    6868 
    6969    if (GL_TRUE != glewIsSupported((const char*) "GL_EXT_framebuffer_object")) 
     
    117117    { 
    118118        fprintf(stderr,"GL_ARB_vertex_buffer_object extension is not available!\n"); 
     119    } else { 
     120#ifdef VERTEX_BUFFER_OBJECTS 
     121         
     122        glGenBuffersARB(1, &vertex_buf); 
     123         
     124        glGenBuffersARB(1, &color_buf); 
     125#endif 
    119126    } 
    120127    if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_occlusion_query")) 
     
    238245    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    239246 
    240     // Switch to projection mode 
    241     glMatrixMode(GL_PROJECTION); 
    242     // Save previous matrix which contains the  
    243     // settings for the perspective projection 
    244     glPushMatrix(); 
    245     // Reset matrix 
    246     glLoadIdentity(); 
    247     glOrtho(0.0, (GLdouble)width, 0.0, (GLdouble)height, 1.0, 1.0); 
    248     glMatrixMode(GL_MODELVIEW); 
    249     glLoadIdentity(); 
     247    setOrthographicProjection(); 
    250248 
    251249    glEnable(GL_TEXTURE_2D); 
    252250    glBindTexture(GL_TEXTURE_2D, color_tex); 
    253251    glBegin(GL_QUADS); 
    254     glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); 
    255     glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 0.0); 
    256     glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0, 0.0); 
    257     glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, 0.0); 
     252     
     253    glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); 
     254    glTexCoord2f(1.0f, 0.0f); glVertex2f(width, 0.0f);  
     255    glTexCoord2f(1.0f, 1.0f); glVertex2f(width, height); 
     256    glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, height); 
     257 
    258258    glEnd(); 
    259259    glFlush(); 
     
    312312    /////////////////////////////////////////////////////////////////////////// 
    313313} 
     314void VMI::renderSceneWin(GLuint **histogram, GLuint numCameras, Change *c) 
     315{ 
     316    GLuint i, j, t, background; 
     317    int del_area, mod_area; 
     318    GLfloat min[3], max[3]; 
     319 
     320    // draw to the frame buffer 
     321    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 
     322 
     323    //printChange(c); 
     324    getBoundingBox(c, min, max); 
     325    //printf("\n(%f,%f,%f)-(%f,%f,%f)\n", min[0], min[1], min[2], max[0], max[1], max[2]); 
     326     
     327    // Apply HW acceleration OpenGL Technique 
     328    applyHWAcceleration();  
     329 
     330    glDrawBuffer(GL_BACK); 
     331    glReadBuffer(GL_BACK); 
     332 
     333    // Get the projected areas for all cameras 
     334    for (i=0; i<numCameras; i++) { 
     335         
     336        // Clear color and depth buffers 
     337        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     338         
     339        glMatrixMode(GL_MODELVIEW); 
     340        glLoadIdentity(); 
     341         
     342        // Camera  i 
     343        gluLookAt(cameras[i].eyeX, cameras[i].eyeY, cameras[i].eyeZ, 
     344                  cameras[i].centerX, cameras[i].centerY, cameras[i].centerZ, 
     345                  cameras[i].upX, cameras[i].upY, cameras[i].upZ); 
     346         
     347        renderGeometry(); 
     348        glFlush(); 
     349         
     350        /////////////////////////////////////////////////////////////////////////// 
     351        background = histogram[i][0]; 
     352        //printf("b: %d\n", histogram[i][0]); 
     353 
     354        del_area = 0; 
     355        mod_area = 0; 
     356 
     357        for (j=0; j<( GLuint)c->numDel; j++) { 
     358            t = c->deleted[j].id; 
     359            del_area += histogram[i][t + 1]; 
     360 
     361            histogram[i][t + 1] = 0; 
     362        } 
     363 
     364        for (j=0; j<( GLuint)c->numMod; j++) { 
     365            t = c->modified[j].id; 
     366            del_area += histogram[i][t + 1]; 
     367 
     368            histogram[i][t + 1] = 0; 
     369        } 
     370         
     371        getSWHistogramWin(histogram[i], pixels, min, max, c);  
     372 
     373        for (j=0; j<( GLuint)c->numMod; j++) { 
     374            t = c->modified[j].id; 
     375            mod_area += histogram[i][t + 1]; 
     376 
     377            //printf("t%d: %d\n",t, histogram[i][t + 1]); 
     378        } 
     379        histogram[i][0] = background + (del_area - mod_area); 
     380        //printf("b: %d\n", histogram[i][0]); 
     381    } 
     382    //getchar(); 
     383 
     384    // draw to the window, reading from the color texture 
     385    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
     386 
     387    if (!bEnableOffScreen) drawTexture(); 
     388     
     389    /////////////////////////////////////////////////////////////////////////// 
     390} 
    314391 
    315392void VMI::freeMemory(void) { 
     
    339416#endif 
    340417 
    341                 glutDestroyWindow(vmiWin); 
     418                if (vmiWin != 0) 
     419                { 
     420                        glutDestroyWindow(vmiWin); 
     421                } 
     422 
     423#ifdef VERTEX_BUFFER_OBJECTS 
     424    glDeleteBuffersARB(1, &vertex_buf); 
     425     
     426    glDeleteBuffersARB(1, &color_buf); 
     427#endif 
     428 
     429        pmodel = NULL; // The .obj model 
     430 
     431        pixels = NULL; 
     432 
     433        cameras = NULL; 
     434        numCameras = 0; 
     435 
     436        colors = NULL; 
     437 
     438        histogram = NULL; 
     439  queries = NULL; 
     440 
     441        mesh = NULL; 
     442 
     443        initialIs = NULL; 
     444 
     445        vmiWin = 0; 
    342446} 
    343447 
     
    391495 
    392496#ifdef SALIENCY 
    393 #ifdef KL // Kullback-Leibler 
    394         sprintf(s,"%s_%d_%d_VKL_S.obj", filename, numCameras, mesh->currentNumTriangles); 
    395 #endif 
    396 #ifdef MI // Mutual Information 
    397         sprintf(s,"%s_%d_%d_VMI_S.obj", filename, numCameras, mesh->currentNumTriangles); 
    398 #endif 
    399 #ifdef HE // Hellinger 
    400         sprintf(s,"%s_%d_%d_VHE_S.obj", filename, numCameras, mesh->currentNumTriangles); 
    401 #endif 
    402 #ifdef CS // Chi-Square 
    403         sprintf(s,"%s_%d_%d_VCS_S.obj", filename, numCameras, mesh->currentNumTriangles); 
    404 #endif 
     497    sprintf(s,"%s_%d_%d_%s_S.obj", filename, numCameras, mesh->currentNumTriangles, EXT); 
    405498#else 
    406 #ifdef KL // Kullback-Leibler 
    407         sprintf(s,"%s_%d_%d_VKL.obj", filename, numCameras, mesh->currentNumTriangles); 
    408 #endif 
    409 #ifdef MI // Mutual Information 
    410         sprintf(s,"%s_%d_%d_VMI.obj", filename, numCameras, mesh->currentNumTriangles); 
    411 #endif 
    412 #ifdef HE // Hellinger 
    413         sprintf(s,"%s_%d_%d_VHE.obj", filename, numCameras, mesh->currentNumTriangles); 
    414 #endif 
    415 #ifdef CS // Chi-Square 
    416         sprintf(s,"%s_%d_%d_VCS.obj", filename, numCameras, mesh->currentNumTriangles); 
    417 #endif 
     499    sprintf(s,"%s_%d_%d_%s.obj", filename, numCameras, mesh->currentNumTriangles, EXT); 
    418500#endif 
    419501 
     
    454536 *  RGBA display mode, and handle input events. 
    455537 */ 
    456 //int main(int argc, char** argv) 
    457 //{ 
    458 //    char s[MAX_CHAR]; 
    459 // 
    460 //    process_cmdline(argc, argv); 
    461 //     
    462 //    // Load a .obj model 
    463 //    pmodel = glmReadOBJ(argv[argc-1]); 
    464 //    if (!pmodel) exit(0); 
    465 //    glmUnitize(pmodel); 
    466 //    //glmFacetNormals(pmodel); 
    467 //    //glmVertexNormals(pmodel, 90.0); 
    468 // 
    469 //    mesh = initMesh(pmodel); 
    470 //    //printMesh(mesh); 
    471 //    //getchar(); 
    472 // 
    473 //    if ((numDemandedTriangles == 0) || (numDemandedTriangles >= mesh->currentNumTriangles)) 
    474 //        usage_error("Illegal number of triangles."); 
    475 // 
    476 //    printf("w: %d h: %d\n", width, height); 
    477 //    printf("t: %d c: %d o: %d r: %f\n", numDemandedTriangles, cameraType, bEnableOffScreen, radius); 
    478 //    //getchar(); 
    479 // 
    480 //    // Get a filename without extension 
    481 //    strncpy(filename, argv[argc - 1], strlen(argv[argc - 1]) - 4); 
    482 //     
    483 //    glutInit(&argc, argv); 
    484 //    glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA); /* RGB and Alpha */ 
    485 //    glutInitWindowSize(width, height); 
    486 //    glutInitWindowPosition(100, 100); 
    487 // 
    488 //#ifdef KL // Kullback-Leibler 
    489 //    sprintf(s, "VKL - [%s]", argv[argc-1]);  
    490 //#endif 
    491 //#ifdef MI // Mutual Information 
    492 //    sprintf(s, "VMI - [%s]", argv[argc-1]);  
    493 //#endif 
    494 //#ifdef HE // Hellinger 
    495 //    sprintf(s, "VHE - [%s]", argv[argc-1]);  
    496 //#endif 
    497 //#ifdef CS // Chi-Square 
    498 //    sprintf(s, "VCS - [%s]", argv[argc-1]);  
    499 //#endif 
    500 //     
    501 //    vmiWin = glutCreateWindow(s); 
    502 // 
    503 //    glewInit(); 
    504 // 
    505 //    init(); 
    506 // 
    507 //    if (bLoadCamerasFromFile == GL_FALSE) { 
    508 //        switch (cameraType) { 
    509 //        case 0: 
    510 //            cameras = setCameras(radius, OCTAHEDRON, &numCameras); 
    511 //            printf("Number of cameras: %d\n", OCTAHEDRON); 
    512 //            break; 
    513 //        case 1: 
    514 //            cameras = setCameras(radius, ICOSAHEDRON, &numCameras); 
    515 //            printf("Number of cameras: %d\n", ICOSAHEDRON); 
    516 //            break; 
    517 //        case 2: 
    518 //            cameras = setCameras(radius, DODECAHEDRON, &numCameras); 
    519 //            printf("Number of cameras: %d\n", DODECAHEDRON); 
    520 //            break; 
    521 //        default: 
    522 //            break; 
    523 //        } 
    524 //    } else { 
    525 //        sprintf(s,"%s.cam", filename); 
    526 //         
    527 //        cameras = loadCameras(radius, s, &numCameras); 
    528 //        //getchar(); 
    529 //    } 
    530 // 
    531 //              histogram = initHistogram(mesh->currentNumTriangles, numCameras); 
    532 // 
    533 //    initialIs = initIs(numCameras); 
    534 //     
    535 //              if (!bEnableOffScreen) { 
    536 //                        glutReshapeFunc(reshape); 
    537 //        glutKeyboardFunc(keyboard); 
    538 //                        glutDisplayFunc(display); 
    539 //              } 
    540 //              else { 
    541 //        display(); 
    542 //              freeMemory();            
    543 //    } 
    544 //    exit(0); 
    545 // 
    546 //    glutMainLoop(); 
    547 //    return 0; 
    548 //} 
     538/*int main(int argc, char** argv) 
     539{ 
     540    char s[MAX_CHAR]; 
     541 
     542    process_cmdline(argc, argv); 
     543     
     544    // Load a .obj model 
     545    pmodel = glmReadOBJ(argv[argc-1]); 
     546    if (!pmodel) exit(0); 
     547    glmUnitize(pmodel); 
     548    if (bRemoveRedundantVertices == GL_TRUE) 
     549        glmWeld(pmodel, 0.00001); 
     550    //glmFacetNormals(pmodel); 
     551    //glmVertexNormals(pmodel, 90.0); 
     552 
     553    mesh = initMesh(pmodel); 
     554    //printMesh(mesh); 
     555    //getchar(); 
     556 
     557    if ((numDemandedTriangles == 0) || (numDemandedTriangles >= mesh->numTriangles)) 
     558        usage_error("Illegal number of triangles."); 
     559 
     560    printf("w: %d h: %d\n", width, height); 
     561    printf("t: %d c: %d o: %d r: %f\n", numDemandedTriangles, cameraType, bEnableOffScreen, radius); 
     562    //getchar(); 
     563 
     564    // Get a filename without extension 
     565    strncpy(filename, argv[argc - 1], strlen(argv[argc - 1]) - 4); 
     566     
     567    glutInit(&argc, argv); 
     568    glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA); // RGB and Alpha 
     569    glutInitWindowSize(width, height); 
     570    glutInitWindowPosition(100, 100); 
     571 
     572    sprintf(s, "%sW - [%s]", EXT, argv[argc-1]); 
     573     
     574    glutCreateWindow(s); 
     575 
     576    glewInit(); 
     577 
     578    init(); 
     579 
     580    if (bLoadCamerasFromFile == GL_FALSE) 
     581        cameras = setCameras(radius, cameraType, &numCameras); 
     582    else { 
     583        sprintf(s,"%s.cam", filename); 
     584         
     585        cameras = loadCameras(radius, s, &numCameras); 
     586        //getchar(); 
     587    } 
     588 
     589    histogram = initHistogram(mesh->numTriangles, numCameras); 
     590 
     591    initialIs = initIs(numCameras); 
     592     
     593    // Allocate memory for colors 
     594    colors = initColors(mesh->numTriangles); 
     595 
     596    // Set a different color for every triangle  
     597    setColors4(colors, mesh->numTriangles); 
     598 
     599    if (!bEnableOffScreen){ 
     600        glutReshapeFunc(reshape); 
     601        glutKeyboardFunc(keyboard); 
     602        glutDisplayFunc(display); 
     603 
     604        glutMainLoop(); 
     605    } else display(); 
     606 
     607    return 0; 
     608}*/ 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp

    r983 r2090  
    1111using namespace VMI; 
    1212 
    13 #define MAX_NUM_TRI 450 
    14  
     13#define OUTPUT_SEVERAL_GROUPS 
     14 
     15/////////////////////////////////////////////////////////////////////////////// 
     16// list of integers 
    1517void VMI::printItemList(int *list, int n) { 
    1618    int i; 
     
    3537        list[(*n)++] = item; 
    3638} 
     39 
     40void VMI::delItem(int *list, int *n, int item) { 
     41    int i, j; 
     42     
     43    for (i=0; i<*n; i++) { 
     44        if (list[i] == item) { 
     45            // delete it 
     46            for (j =i + 1 ; j<*n; j++) 
     47                list[j - 1] = list[j]; 
     48            (*n)--; 
     49            i--; // Delete all ocurrencies of an item 
     50        } 
     51    } 
     52} 
     53/////////////////////////////////////////////////////////////////////////////// 
    3754 
    3855int VMI::findEdge(Edge *e, GLuint num, GLuint _u, GLuint _v) { 
     
    5673 
    5774    return found; 
     75} 
     76 
     77// Adds a new edge at the end of the mesh edge list 
     78Edge *VMI::addEdge(Edge *list, int *n, int u, int v, int *pos) { 
     79          Edge *newList; 
     80 
     81                // Reallocate memory for the new edge 
     82    newList = (Edge *)realloc(list, ((*n) + 1) * sizeof(Edge)); 
     83 
     84                // New vertex indices 
     85                newList[*n].u = u; 
     86    newList[*n].v = v; 
     87 
     88                // This edge has no triangle adjancency 
     89                newList[*n].numTriangles = 0; 
     90                newList[*n].triangles = NULL; 
     91                 
     92                // Enable the new edge 
     93                newList[*n].enable = TRUE; 
     94 
     95                // New edge position 
     96                *pos = *n; 
     97 
     98                // New number of edges 
     99          (*n)++; 
     100 
     101                return newList; 
    58102} 
    59103 
     
    131175Mesh *VMI::initMesh(GLMmodel* pmodel) { 
    132176 
    133     GLuint i, j, v1, v2, v3, n, e, t; 
     177    GLuint i, j, curGroup, v1, v2, v3, n, m, t; 
     178    int e; 
    134179    Mesh *mesh; 
     180    GLMgroup *group; 
    135181 
    136182    mesh = (Mesh *)malloc (sizeof(Mesh)); 
     
    157203    printf("Adding vertices..."); 
    158204    for (i=1; i<=pmodel->numvertices; i++) { // Vertices start at 1 
    159  
    160205        mesh->vertices[i - 1].x = pmodel->vertices[3 * i + 0]; 
    161206        mesh->vertices[i - 1].y = pmodel->vertices[3 * i + 1]; 
     
    170215 
    171216    printf("Adding triangles..."); 
     217 
     218#ifdef OUTPUT_SEVERAL_GROUPS 
     219    group = pmodel->groups; 
     220    curGroup=0; // current group 
     221    while(group) { 
     222         
     223        for (i=0; i<group->numtriangles; i++) { 
     224             
     225            t = group->triangles[i]; 
     226 
     227            mesh->triangles[t].id = t; 
     228            mesh->triangles[t].group = curGroup; // set group 
     229            mesh->triangles[t].indices[0] = pmodel->triangles[t].vindices[0] - 1; 
     230            mesh->triangles[t].indices[1] = pmodel->triangles[t].vindices[1] - 1; 
     231            mesh->triangles[t].indices[2] = pmodel->triangles[t].vindices[2] - 1; 
     232            mesh->triangles[t].area = computeTriangleArea(mesh->vertices, &mesh->triangles[t]); 
     233            //printf("\n%d a: %f",i , mesh->triangles[i].area); 
     234            computeTriangleNormal(mesh->vertices, &mesh->triangles[t]); 
     235             
     236            mesh->triangles[t].saliency = 0.0; 
     237             
     238            mesh->triangles[t].enable = GL_TRUE; 
     239             
     240            for (j=0; j<3; j++) { 
     241                // Adding triangle i adjacent to 3 vertices 
     242                v1 = mesh->triangles[t].indices[j]; 
     243                 
     244                // Reallocate memory for the new adjacent triangle 
     245                mesh->vertices[v1].triangles =  
     246                                        (GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint)); 
     247                addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, t); 
     248            } 
     249        } 
     250        curGroup++; 
     251        group = group->next; 
     252    } 
     253#else // One single group 
    172254    for (i=0; i<pmodel->numtriangles; i++) { 
    173255        mesh->triangles[i].id = i; 
     
    188270    
    189271            // Reallocate memory for the new adjacent triangle 
    190             mesh->vertices[v1].triangles = (GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint)); 
     272            mesh->vertices[v1].triangles =  
     273                            (GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint)); 
    191274            addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, i); 
    192275        } 
    193276    } 
    194     //printf("\n"); 
     277    printf("\n"); 
     278#endif 
    195279    printf("Ok\n"); 
    196280 
    197281    mesh->numTriangles = pmodel->numtriangles; 
    198282    mesh->currentNumTriangles = pmodel->numtriangles; 
     283    printf("Number of triangles: %d\n", mesh->numTriangles); 
    199284 
    200285    mesh->edges = (Edge *)malloc (sizeof(Edge) * mesh->numTriangles * 3);  // E = 3 T / 2 
     
    205290    } 
    206291     
    207     // Init edges 
    208     for (i=0; i<mesh->numTriangles * 3; i++) { 
    209          
    210         mesh->edges[i].triangles    = NULL; 
    211         mesh->edges[i].numTriangles = 0; 
    212     } 
    213  
    214292    printf("Adding edges..."); 
    215293    n = 0; 
     
    221299        v3 = mesh->triangles[i].indices[2]; 
    222300         
     301        ///////////////////////////////////////////////////////////////////////////////// 
     302                // edge (v1,v2) 
    223303        if ((e = findEdge(mesh->edges, n, v1, v2)) == -1) { 
    224304            mesh->edges[n].u = v1; 
    225305            mesh->edges[n].v = v2; 
     306                                                mesh->edges[n].triangles    = NULL; 
     307                        mesh->edges[n].numTriangles = 0; 
    226308            mesh->edges[n].enable = GL_TRUE; 
    227              
    228             // Reallocate memory for the new adjacent triangle 
    229             mesh->edges[n].triangles = (GLuint *)realloc(mesh->edges[n].triangles, (mesh->edges[n].numTriangles + 1) * sizeof(GLuint)); 
    230             // Adding triangle i adjacent to edge n 
    231             addItem((int *)mesh->edges[n].triangles, (int *)&mesh->edges[n].numTriangles, i); 
    232             //printf("n:%d i:%d\n", n, i); 
    233              
    234             // Adding edge n adjacent to triangle i 
    235             addItem((int *)mesh->triangles[i].edges, (int *)&t, n); 
     309            m = n; 
    236310            n++; 
    237         } else { 
    238             // Reallocate memory for the new adjacent triangle 
    239             mesh->edges[e].triangles = (GLuint *)realloc(mesh->edges[e].triangles, (mesh->edges[e].numTriangles + 1) * sizeof(GLuint)); 
    240             // Adding triangle i adjacent to edge e 
    241             addItem((int *)mesh->edges[e].triangles, (int *)&mesh->edges[e].numTriangles, i); 
    242             //printf("n:%d i:%d\n", e, i); 
    243              
    244             // Adding edge e adjacent to triangle i 
    245             addItem((int *)mesh->triangles[i].edges, (int *)&t, e); 
    246         } 
     311        } 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); 
     321 
     322        ///////////////////////////////////////////////////////////////////////////////// 
     323        // edge (v2,v3) 
    247324        if (( e = findEdge(mesh->edges, n, v2, v3)) == -1) { 
    248325            mesh->edges[n].u = v2; 
    249326            mesh->edges[n].v = v3; 
     327                                                mesh->edges[n].triangles    = NULL; 
     328                        mesh->edges[n].numTriangles = 0; 
    250329            mesh->edges[n].enable = GL_TRUE; 
    251              
    252             // Reallocate memory for the new adjacent triangle 
    253             mesh->edges[n].triangles = (GLuint *)realloc(mesh->edges[n].triangles, (mesh->edges[n].numTriangles + 1) * sizeof(GLuint)); 
    254             // Adding triangle i adjacent to edge n 
    255             addItem((int *)mesh->edges[n].triangles, (int *)&mesh->edges[n].numTriangles, i); 
    256             //printf("n:%d i:%d\n", n, i); 
    257              
    258             // Adding edge n adjacent to triangle i 
    259             addItem((int *)mesh->triangles[i].edges, (int *)&t, n); 
     330            m = n; 
    260331            n++; 
    261         } else { 
    262             // Reallocate memory for the new adjacent triangle 
    263             mesh->edges[e].triangles = (GLuint *)realloc(mesh->edges[e].triangles, (mesh->edges[e].numTriangles + 1) * sizeof(GLuint)); 
    264             // Adding triangle i adjacent to edge e 
    265             addItem((int *)mesh->edges[e].triangles, (int *)&mesh->edges[e].numTriangles, i); 
    266             //printf("n:%d i:%d\n", e, i); 
    267              
    268             // Adding edge e adjacent to triangle i 
    269             addItem((int *)mesh->triangles[i].edges, (int *)&t, e); 
    270         } 
     332        } 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); 
     342 
     343        ///////////////////////////////////////////////////////////////////////////////// 
     344        // edge (v3,v1) 
    271345        if ((e = findEdge(mesh->edges, n, v3, v1)) == -1) { 
    272346            mesh->edges[n].u = v3; 
    273347            mesh->edges[n].v = v1; 
     348                                                mesh->edges[n].triangles    = NULL; 
     349                        mesh->edges[n].numTriangles = 0; 
    274350            mesh->edges[n].enable = GL_TRUE; 
    275              
    276             // Reallocate memory for the new adjacent triangle 
    277             mesh->edges[n].triangles = (GLuint *)realloc(mesh->edges[n].triangles, (mesh->edges[n].numTriangles + 1) * sizeof(GLuint)); 
    278             // Adding triangle i adjacent to edge n 
    279             addItem((int *)mesh->edges[n].triangles, (int *)&mesh->edges[n].numTriangles, i); 
    280             //printf("n:%d i:%d\n", n, i); 
    281              
    282             // Adding edge n adjacent to triangle i 
    283             addItem((int *)mesh->triangles[i].edges, (int *)&t, n); 
     351            m = n; 
    284352            n++; 
    285         } else  { 
    286             // Reallocate memory for the new adjacent triangle 
    287             mesh->edges[e].triangles = (GLuint *)realloc(mesh->edges[e].triangles, (mesh->edges[e].numTriangles + 1) * sizeof(GLuint)); 
    288             // Adding triangle i adjacent to edge e 
    289             addItem((int *)mesh->edges[e].triangles, (int *)&mesh->edges[e].numTriangles, i); 
    290             //printf("n:%d i:%d\n", e, i); 
    291              
    292             // Adding edge e adjacent to triangle i 
    293             addItem((int *)mesh->triangles[i].edges, (int *)&t, e); 
    294         } 
     353        } 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); 
    295363    } 
    296364    printf("Ok\n"); 
     
    322390    printf("------------------------\n"); 
    323391    for (i=0; i<mesh->numEdges; i++) { 
    324         printf("e%d (%d,%d)\n", i, mesh->edges[i].u, mesh->edges[i].v); 
     392        printf("e%d (%d,%d) %d\n", i, mesh->edges[i].u, mesh->edges[i].v, mesh->edges[i].enable); 
    325393        printf("  t(%d)[", mesh->edges[i].numTriangles); 
    326394        if (mesh->edges[i].triangles != NULL) { 
     
    329397                printf(",%d", mesh->edges[i].triangles[j]); 
    330398            } 
    331         } 
     399                                } 
    332400        printf("]\n"); 
    333401    } 
     
    336404    printf("------------------------\n"); 
    337405    for (i=0; i<mesh->numTriangles; i++) { 
    338         printf("t%d (%d,%d,%d)\n", i, mesh->triangles[i].indices[0], mesh->triangles[i].indices[1], 
    339                                      mesh->triangles[i].indices[2]); 
     406        printf("t%d (%d,%d,%d) %d\n", i, mesh->triangles[i].indices[0], mesh->triangles[i].indices[1], 
     407                                     mesh->triangles[i].indices[2],  mesh->triangles[i].enable); 
    340408        printf("  e(3)["); 
    341409        printf("%d", mesh->triangles[i].edges[0]); 
     
    385453 
    386454int *VMI::trianglesAdjToEdge(Mesh *mesh, int e, int *n) { 
    387     int triangles[MAX_NUM_TRI]; 
    388     int i, n0, n1, n2,  
     455    int i, n0, n1, n2, num = 0, t,  
    389456        u = mesh->edges[e].u,  
    390457        v = mesh->edges[e].v; 
    391     int *list, num = 0; 
    392  
    393     for (i=0; i<(int)mesh->numTriangles; i++) { 
    394          
    395         if (mesh->triangles[i].enable == TRUE) { 
    396              
    397             n0 = mesh->triangles[i].indices[0]; 
    398             n1 = mesh->triangles[i].indices[1]; 
    399             n2 = mesh->triangles[i].indices[2]; 
     458    int *triangles = NULL; 
     459 
     460        if ((mesh->vertices[u].numTriangles +  
     461         mesh->vertices[v].numTriangles) > 0) 
     462                 triangles = (int *)malloc((mesh->vertices[u].numTriangles +  
     463                                    mesh->vertices[v].numTriangles) * sizeof(int)); 
     464 
     465    for (i=0; i<(int)mesh->vertices[u].numTriangles; i++) { 
     466 
     467        t = mesh->vertices[u].triangles[i]; 
     468         
     469        if (mesh->triangles[t].enable == TRUE) { 
     470             
     471            n0 = mesh->triangles[t].indices[0]; 
     472            n1 = mesh->triangles[t].indices[1]; 
     473            n2 = mesh->triangles[t].indices[2]; 
    400474             
    401475            if ((n0 == v) || (n1 == v) || (n2 == v) || 
    402476                (n0 == u) || (n1 == u) || (n2 == u)) 
    403477                 
    404                 triangles[num++] = i; 
    405         } 
    406     } 
    407  
    408     list = (int*) malloc (sizeof(int) * num); 
    409     if (NULL == list) { 
    410         fprintf (stderr, "no more memory for list"); 
    411         exit(1); 
    412     } 
    413  
    414     memcpy(list, triangles, sizeof(int) * num); 
    415  
     478                addItem(triangles, &num, t); 
     479        } 
     480    } 
     481 
     482    for (i=0; i<(int)mesh->vertices[v].numTriangles; i++) { 
     483 
     484        t = mesh->vertices[v].triangles[i]; 
     485         
     486        if (mesh->triangles[t].enable == TRUE) { 
     487             
     488            n0 = mesh->triangles[t].indices[0]; 
     489            n1 = mesh->triangles[t].indices[1]; 
     490            n2 = mesh->triangles[t].indices[2]; 
     491             
     492            if ((n0 == v) || (n1 == v) || (n2 == v) || 
     493                (n0 == u) || (n1 == u) || (n2 == u)) 
     494                 
     495                addItem(triangles, &num, t); 
     496        } 
     497    } 
    416498    *n = num; 
    417499 
    418     return list; 
    419 } 
    420  
    421 int *VMI::trianglesAdjToVertex(Mesh *mesh, int v, int *n) { 
    422     int triangles[MAX_NUM_TRI]; 
    423     int i, n0, n1, n2; 
    424     int *list, num = 0; 
    425  
    426     for (i=0; i<(int)mesh->numTriangles; i++) { 
    427          
    428         if (mesh->triangles[i].enable == TRUE) { 
    429              
    430             n0 = mesh->triangles[i].indices[0]; 
    431             n1 = mesh->triangles[i].indices[1]; 
    432             n2 = mesh->triangles[i].indices[2]; 
    433              
    434             if ((n0 == v) || (n1 == v) || (n2 == v)) 
    435                  
    436                 triangles[num++] = i; 
    437         } 
    438     } 
    439  
    440     list = (int*) malloc (sizeof(int) * num); 
    441     if (NULL == list) { 
    442         fprintf (stderr, "no more memory for list"); 
    443         exit(1); 
    444     } 
    445  
    446     memcpy(list, triangles, sizeof(int) * num); 
    447  
    448     *n = num; 
    449  
    450     return list; 
     500    return triangles; 
    451501} 
    452502 
    453503int *VMI::verticesAdjToVertex(Mesh *mesh, int v, int *n) { 
    454     int numTr; 
    455     int *triangles = trianglesAdjToVertex(mesh, v, &numTr); 
    456     int *vertices = (int*) malloc (sizeof(int) * numTr * 2); 
     504    int *vertices = NULL; 
    457505    int i, t, n0, n1, n2; 
    458506    int num = 0; 
    459507 
    460     for (i=0; i<numTr; i++) { 
    461         t = triangles[i]; 
     508        if (mesh->vertices[v].numTriangles > 0) 
     509                vertices = (int*)malloc(sizeof(int) * mesh->vertices[v].numTriangles * 2); 
     510 
     511    for (i=0; i<(int)mesh->vertices[v].numTriangles; i++) { 
     512        t = mesh->vertices[v].triangles[i]; 
    462513 
    463514        n0 = mesh->triangles[t].indices[0]; 
     
    469520        if (n2 != v) addItem(vertices, &num, n2); 
    470521    } 
    471  
    472522    *n = num; 
    473523 
    474     free(triangles); 
    475  
    476524    return vertices; 
    477525} 
    478526 
    479527int *VMI::edgesAdjToVertex(Mesh *mesh, int v, int *n) { 
    480     int numTr; 
    481     int *triangles = trianglesAdjToVertex(mesh, v, &numTr); 
    482     int *edges = (int*) malloc (sizeof(int) * numTr * 2); 
    483     int i, t, n0, n1, n2, e; 
     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 
    484535    int num = 0; 
    485536 
    486     for (i=0; i<numTr; i++) { 
    487         t = triangles[i]; 
    488  
     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 
    489553        n0 = mesh->triangles[t].indices[0]; 
    490554        n1 = mesh->triangles[t].indices[1]; 
     
    498562         
    499563        if (((n0 == v) || (n2 == v)) && 
    500             ((e = findEdge(mesh->edges, mesh->numEdges, n0, n2)) != -1)) addItem(edges, &num, e);   
    501     } 
    502  
     564            ((e = findEdge(mesh->edges, mesh->numEdges, n0, n2)) != -1)) addItem(edges, &num, e); 
     565 
     566#endif 
     567    } 
    503568    *n = num; 
    504569 
    505     free(triangles); 
    506  
    507570    return edges; 
    508571} 
    509572 
    510573int *VMI::edgesAdjToVertices(Mesh *mesh, int *vertices, int numVertices, int *n) { 
    511     int edges[MAX_NUM_TRI*2]; 
    512     int i, j, v, num = 0, e; 
    513     int *list, numEdges; 
    514  
    515     for (i=0; i<numVertices; i++) { 
    516         v = vertices[i]; 
    517  
    518         list = edgesAdjToVertex(mesh, v, &numEdges); 
    519  
    520         for (j=0; j<numEdges; j++) { 
    521             e = list[j]; 
    522              
    523             addItem(edges, &num, e); 
    524         } 
     574    int *edges = NULL; 
     575    int i, j, num = 0; 
     576    int *list = NULL, numEdges; 
     577 
     578    if (numVertices > 0) { 
     579        // Add the first 
     580        list = edgesAdjToVertex(mesh, vertices[0], &numEdges); 
     581 
     582        // Allocate memory 
     583        edges = (int *)malloc(numEdges * sizeof(int)); 
     584 
     585        memcpy(edges, list, sizeof(int) * numEdges); 
    525586 
    526587        free(list); 
    527     } 
    528  
    529     list = (int*) malloc (sizeof(int) * num); 
    530     if (NULL == list) { 
    531         fprintf (stderr, "no more memory for list"); 
    532         exit(1); 
    533     } 
    534  
    535     memcpy(list, edges, sizeof(int) * num); 
    536  
     588 
     589        num = numEdges; 
     590 
     591        // Add the rest 
     592        for (i=1; i<numVertices; i++) { 
     593 
     594            list = edgesAdjToVertex(mesh, vertices[i], &numEdges); 
     595 
     596            // Reallocate memory 
     597                        if (numEdges > 0) { 
     598 
     599                edges = (int *)realloc(edges, (num + numEdges + 1) * sizeof(int)); 
     600                 
     601                for (j=0; j<numEdges; j++) 
     602                    addItem(edges, &num, list[j]); 
     603                        } 
     604            free(list); 
     605        } 
     606    } 
    537607    *n = num; 
    538608 
    539     return list; 
     609    return edges; 
    540610} 
    541611 
     
    563633} 
    564634 
     635// Adds a new vertex at the end of the mesh vertex list 
     636Vertex *VMI::addVertex(Vertex *list, int *n, float x, float y, float z, int *pos) { 
     637          Vertex *newList; 
     638 
     639                // Reallocate memory for the new vertex 
     640    newList = (Vertex *)realloc(list, ((*n) + 1) * sizeof(Vertex)); 
     641 
     642                // New Vertex coordinates 
     643                newList[*n].x = x; 
     644    newList[*n].y = y; 
     645    newList[*n].z = z; 
     646 
     647                // This vertex has no triangle adjancency 
     648                newList[*n].numTriangles = 0; 
     649                newList[*n].triangles = NULL; 
     650         
     651    // Enable the new vertex 
     652                newList[*n].enable = TRUE; 
     653 
     654                // New vertex position 
     655                *pos = *n; 
     656 
     657                // New number of vertices 
     658          (*n)++; 
     659                 
     660                return newList; 
     661} 
     662 
     663 
     664 
    565665void VMI::updateModel(GLMmodel* pmodel, Mesh *mesh, GLuint numVertices, GLuint numTriangles) { 
    566666    GLuint i , v1, v2 ,v3, numV = 1, numT = 0; 
     
    569669     
    570670    if (pmodel->vertices != NULL) free(pmodel->vertices); 
    571  
    572671    pmodel->vertices = (GLfloat *)calloc ((numVertices + 1) * 3,  sizeof(GLfloat)); 
    573      
    574672 
    575673    if (pmodel->triangles != NULL) free(pmodel->triangles); 
    576  
    577674    pmodel->triangles = (GLMtriangle *)malloc (numTriangles * sizeof(GLMtriangle)); 
    578675 
    579      
    580676    for (i=0; i<mesh->numTriangles; i++) { 
    581677        if (mesh->triangles[i].enable) { 
     
    630726 
    631727void VMI::saveModel(char *filename, GLMmodel* pmodel, Mesh *mesh) { 
    632     GLuint i; 
    633  
     728    GLuint i, j, g, numT = 0; 
     729    GLMgroup *group; 
     730 
     731#ifdef OUTPUT_SEVERAL_GROUPS 
     732    // The output model maintains groups 
     733 
     734    // Empty all groups 
     735    group = pmodel->groups; 
     736    while(group) { 
     737        // Free memory for triangles 
     738        free(group->triangles); 
     739 
     740        // Reset group 
     741        group->triangles = NULL; 
     742        group->numtriangles = 0; 
     743 
     744        group = group->next; 
     745    } 
     746    // Fill all groups 
     747    for (i=0; i<mesh->numTriangles; i++) { 
     748 
     749        if (mesh->triangles[i].enable) { 
     750            g = mesh->triangles[i].group; 
     751 
     752            // Get group 
     753            group = pmodel->groups; 
     754            for (j=0; j <g; j++) 
     755                group = group->next; 
     756 
     757            // Reallocate memory for triangles 
     758            group->triangles = (GLuint *)realloc(group->triangles, (group->numtriangles + 1) * sizeof(GLuint)); 
     759            // Add triangle into group 
     760            addItem((int *)group->triangles, (int *)&group->numtriangles, numT); 
     761 
     762            numT++; 
     763        } 
     764    } 
     765#else 
    634766    // The output model contains only one group 
    635767    pmodel->numgroups = 1; 
     
    646778    for (i=0; i<mesh->currentNumTriangles; i++) 
    647779        pmodel->groups->triangles[i] = i; 
     780#endif 
    648781 
    649782    updateModel(pmodel, mesh, mesh->currentNumTriangles * 3, mesh->currentNumTriangles); 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/metrics.cpp

    r983 r2090  
    1313using namespace VMI; 
    1414 
    15 GLuint VMI::computeBackgroundArea(Mesh *mesh, GLuint *histogram) { 
    16     GLuint i, area = 0; 
    17  
    18     for (i=0; i<mesh->numTriangles; i++) { // Triangles start at 1 
    19         if (mesh->triangles[i].enable == TRUE) { 
    20             area += histogram[i + 1]; 
    21         } 
    22     } 
    23  
    24     return ((GLuint)(width * height) - area); 
    25 } 
    26  
    2715GLdouble VMI::computeMeanProjAreaNoBG(GLuint **histogram, GLuint numCameras, int t) { 
    2816    GLuint i; 
     
    3725 
    3826GLdouble VMI::computeMeanProjArea(GLuint **histogram, GLuint numCameras, int t) { 
    39     GLuint i; 
    40     GLdouble mean_proj_area = 0.0, total_proj_area, resolution = width * height; 
    41  
    42     for (i=0; i<numCameras; i++) { 
     27        GLuint i; 
     28        GLdouble mean_proj_area = 0.0, total_proj_area, resolution = width * height; 
     29 
     30        for (i=0; i<numCameras; i++) { 
    4331                total_proj_area = resolution - histogram[i][0]; 
    4432 
    45         mean_proj_area += histogram[i][t] / total_proj_area; 
    46     } 
    47  
    48     return (mean_proj_area / (GLdouble)numCameras); 
    49 } 
     33                mean_proj_area += histogram[i][t] / total_proj_area; 
     34        } 
     35 
     36        return (mean_proj_area / (GLdouble)numCameras); 
     37} 
     38/////////////////////////////////////////////////////////////////////////////// 
    5039// Mutual Information 
    5140GLdouble VMI::computeMI(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint cam) { 
     
    7665    return (I / numCameras); 
    7766} 
     67 
     68GLdouble VMI::decMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c) { 
     69    GLdouble newI = I * numCameras,  
     70             pov = 0.0, po; 
     71    GLsizei total_proj_area = width * height; 
     72    GLint i, t; 
     73 
     74    // decrease entropy of deleted triangles 
     75    for (i=0; i<c->numDel; i++) {  
     76         
     77        t = c->deleted[i].id; 
     78        // projected pixels of triangle t is at t + 1 position 
     79        pov = (GLdouble)histogram[cam][t + 1] / total_proj_area; 
     80         
     81        po = computeMeanProjAreaNoBG(histogram, numCameras, t + 1) / total_proj_area; 
     82         
     83        if ((pov > 0.0) && (po > 0.0)) 
     84            newI -= (pov * log2(pov / po)); 
     85    } 
     86 
     87    // decrease entropy of modified triangles 
     88    for (i=0; i<c->numMod; i++) {  
     89         
     90        t = c->modified[i].id; 
     91        // projected pixels of triangle t is at t + 1 position 
     92        pov = (GLdouble)histogram[cam][t + 1] / total_proj_area; 
     93         
     94        po = computeMeanProjAreaNoBG(histogram, numCameras, t + 1) / total_proj_area; 
     95         
     96        if ((pov > 0.0) && (po > 0.0)) 
     97            newI -= (pov * log2(pov / po)); 
     98    } 
     99 
     100    // take into account the background 
     101    pov = (GLdouble)histogram[cam][0] / total_proj_area; 
     102     
     103    po = computeMeanProjAreaNoBG(histogram, numCameras, 0) / total_proj_area; 
     104     
     105    if ((pov > 0.0) && (po > 0.0)) 
     106        newI -= (pov * log2(pov / po)); 
     107 
     108    return (newI / numCameras); 
     109} 
     110 
     111GLdouble VMI::incMI(GLdouble I, GLuint **histogram, GLuint numCameras, GLuint cam, Change *c) { 
     112    GLdouble newI = I * numCameras,  
     113             pov = 0.0, po; 
     114    GLsizei total_proj_area = width * height; 
     115    GLuint i, t; 
     116 
     117    // increase entropy of modified triangles 
     118    for (i=0; i<(GLuint)c->numMod; i++) {  
     119         
     120        t = c->modified[i].id; 
     121        // projected pixels of triangle t is at t + 1 position 
     122        pov = (GLdouble)histogram[cam][t + 1] / total_proj_area; 
     123         
     124        po = computeMeanProjAreaNoBG(histogram, numCameras, t + 1) / total_proj_area; 
     125         
     126        if ((pov > 0.0) && (po > 0.0)) 
     127            newI += (pov * log2(pov / po)); 
     128    } 
     129 
     130    // take into account the background 
     131    pov = (GLdouble)histogram[cam][0] / total_proj_area; 
     132     
     133    po = computeMeanProjAreaNoBG(histogram, numCameras, 0) / total_proj_area; 
     134     
     135    if ((pov > 0.0) && (po > 0.0)) 
     136        newI += (pov * log2(pov / po)); 
     137 
     138    return (newI / numCameras); 
     139} 
     140/////////////////////////////////////////////////////////////////////////////// 
    78141// Kullback-Leibler divergence 
    79142GLdouble VMI::computeKL(Mesh *mesh, GLuint *histogram) { 
     
    107170// Hellinger divergence (square root) 
    108171GLdouble VMI::computeHE(Mesh *mesh, GLuint *histogram) { 
    109     GLdouble I = 0.0, t,  
     172    GLdouble I = 0.0, temp,  
    110173             total_real_area = 0.0, pi, qi; 
    111174    GLsizei  total_proj_area = (width * height) - histogram[0]; 
     
    128191            if ((pi > 0.0) && (qi > 0.0)) { 
    129192                 
    130                 t = sqrt(pi) - sqrt(qi); 
     193                temp = sqrt(pi) - sqrt(qi); 
    131194                 
    132                 I += (t * t); 
     195                I += (temp * temp); 
    133196            } 
    134197        } 
    135198    } 
    136199 
    137     return (sqrt(I / 2.0)); 
     200    return sqrt(I / 2.0); 
     201 
    138202} 
    139203 
     
    168232/////////////////////////////////////////////////////////////////////////////// 
    169233GLdouble VMI::computeEntropy(GLuint **histogram, GLuint numCameras, GLuint k) { 
    170     GLdouble H = 0.0, POk, pi, 
    171                      total_proj_area, resolution = width * height, pv = 1.0 / (GLdouble)numCameras; 
     234        GLdouble H = 0.0, POk, pi, 
     235                                         total_proj_area, resolution = width * height, pv = 1.0 / (GLdouble)numCameras; 
     236        GLuint i; 
     237 
     238        for (i=0; i<numCameras; i++) { 
     239 
     240                total_proj_area = resolution - histogram[i][0]; 
     241 
     242                POk = computeMeanProjArea(histogram, numCameras, k + 1); 
     243 
     244                if (POk > 0.0) 
     245                        pi = (pv * ((double)histogram[i][k + 1]) / total_proj_area ) / POk; 
     246                else pi = 0.0; 
     247 
     248                if (pi > 0.0) 
     249                        H += (pi * log2(pi)); 
     250        } 
     251 
     252        return -H; 
     253} 
     254 
     255GLdouble VMI::computeMixedEntropy(GLdouble *mixed, GLuint numCameras) { 
     256    GLdouble H = 0.0, pi; 
    172257    GLuint i; 
    173258     
    174259    for (i=0; i<numCameras; i++) { 
    175  
    176                 total_proj_area = resolution - histogram[i][0]; 
    177          
    178         POk = computeMeanProjArea(histogram, numCameras, k + 1); 
    179          
    180         if (POk > 0.0) 
    181             pi = (pv * ((double)histogram[i][k + 1]) / total_proj_area ) / POk; 
    182         else pi = 0.0; 
     260         
     261        pi = mixed[i]; 
    183262         
    184263        if (pi > 0.0) 
     
    188267    return -H; 
    189268} 
    190  
    191 GLdouble VMI::computeMixedEntropy(GLdouble *mixed, GLuint numCameras) { 
    192     GLdouble H = 0.0, pi; 
    193     GLuint i; 
    194      
    195     for (i=0; i<numCameras; i++) { 
    196          
    197         pi = mixed[i]; 
    198          
    199         if (pi > 0.0) 
    200             H += (pi * log2(pi)); 
    201     } 
    202      
    203     return -H; 
    204 } 
    205269/////////////////////////////////////////////////////////////////////////////// 
    206270// Jensen-Shannon divergence 
    207271GLdouble VMI::computeJS(GLuint **histogram, GLuint numCameras, GLuint j, GLuint k) { 
    208     GLdouble js, Wj = 0.0, Wk = 0.0, POj, POk, pj, pk, total_proj_area, 
    209                     resolution = width * height, pv = 1.0 / (GLdouble)numCameras, 
    210                         *mixing = (GLdouble *)malloc(numCameras * sizeof(GLdouble)); 
    211     GLuint i; 
    212      
    213     POj = computeMeanProjArea(histogram, numCameras, j + 1); 
    214     POk = computeMeanProjArea(histogram, numCameras, k + 1); 
    215  
    216     //printf("%f %f\n", POj, POk); 
    217      
    218     // weights 
    219     if ((POj + POk) > 0.0) { 
    220         Wj = POj / (POj + POk); 
    221         Wk = POk / (POj + POk); 
    222     } 
    223  
    224     //printf("%f %f\n", Wj, Wk); 
    225      
    226     // Compute mixing distribution 
    227     for (i=0; i<numCameras; i++) { 
    228          
     272        GLdouble js, Wj = 0.0, Wk = 0.0, POj, POk, pj, pk, total_proj_area, 
     273                                        resolution = width * height, pv = 1.0 / (GLdouble)numCameras, 
     274                                        *mixing = (GLdouble *)malloc(numCameras * sizeof(GLdouble)); 
     275        GLuint i; 
     276 
     277        POj = computeMeanProjArea(histogram, numCameras, j + 1); 
     278        POk = computeMeanProjArea(histogram, numCameras, k + 1); 
     279 
     280        //printf("%f %f\n", POj, POk); 
     281 
     282        // weights 
     283        if ((POj + POk) > 0.0) { 
     284                Wj = POj / (POj + POk); 
     285                Wk = POk / (POj + POk); 
     286        } 
     287 
     288        //printf("%f %f\n", Wj, Wk); 
     289 
     290        // Compute mixing distribution 
     291        for (i=0; i<numCameras; i++) { 
     292 
    229293                total_proj_area = resolution - histogram[i][0]; 
    230294 
    231         if (POj > 0.0) pj = (pv * ((double)histogram[i][j + 1] / total_proj_area)) / POj; 
    232         else pj = 0.0; 
    233              
    234         if (POk > 0.0) pk = (pv * ((double)histogram[i][k + 1] / total_proj_area)) / POk; 
    235         else pk = 0.0; 
    236              
    237         mixing[i] = (Wj * pj) + (Wk * pk); 
    238     } 
    239      
    240     js = /*(POj + POk) * */(computeMixedEntropy(mixing, numCameras)  
    241                 - (Wj * computeEntropy(histogram, numCameras, j))  
    242                 - (Wk * computeEntropy(histogram, numCameras, k))); 
     295                if (POj > 0.0) pj = (pv * ((double)histogram[i][j + 1] / total_proj_area)) / POj; 
     296                else pj = 0.0; 
     297 
     298                if (POk > 0.0) pk = (pv * ((double)histogram[i][k + 1] / total_proj_area)) / POk; 
     299                else pk = 0.0; 
     300 
     301                mixing[i] = (Wj * pj) + (Wk * pk); 
     302        } 
     303 
     304        js = /*(POj + POk) * */(computeMixedEntropy(mixing, numCameras)  
     305                        - (Wj * computeEntropy(histogram, numCameras, j))  
     306                        - (Wk * computeEntropy(histogram, numCameras, k))); 
    243307 
    244308        free(mixing); 
    245309 
    246     return js; 
     310        return js; 
    247311} 
    248312/////////////////////////////////////////////////////////////////////////////// 
     
    250314 
    251315    renderScene(histogram, numCameras); 
     316} 
     317 
     318void VMI::getProjectedAreasWin(GLuint **histogram, GLuint numCameras, Change *c) { 
     319 
     320    renderSceneWin(histogram, numCameras, c); 
    252321} 
    253322 
     
    301370    meanI /= numCameras; 
    302371#endif 
    303     printIs(mis, numCameras); 
     372    //printIs(mis, numCameras); 
    304373    printf("I0= %f\n", meanI);  
    305374} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/saliency.cpp

    r983 r2090  
    2323 
    2424void VMI::computeSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras) { 
    25     GLuint i = 0; 
    26     double sal; 
    27      
    28     maxSal = minSal = computeTriangleSaliency(mesh, histogram, numCameras, 0); 
    29  
    30     mesh->triangles[0].saliency = maxSal; 
    31  
    32     for (i=1; i<mesh->numTriangles; i++) { 
    33  
    34         sal = computeTriangleSaliency(mesh, histogram, numCameras, i); 
    35  
    36         if (sal > maxSal) maxSal = sal; 
    37         if (sal < minSal) minSal = sal; 
    38          
    39         mesh->triangles[i].saliency = sal; 
    40     } 
    41  
    42     printf("\nMax Sal: %f  Min Sal: %f\n", maxSal, minSal); 
    43  
    44     percentile = computePercentile(alpha, mesh->triangles, mesh->numTriangles); 
    45     printf("\n%dth percentile: %f\n", alpha, percentile); 
     25        GLuint i = 0; 
     26        double sal; 
     27 
     28        maxSal = minSal = computeTriangleSaliency(mesh, histogram, numCameras, 0); 
     29 
     30        mesh->triangles[0].saliency = maxSal; 
     31 
     32        for (i=1; i<mesh->numTriangles; i++) { 
     33 
     34                sal = computeTriangleSaliency(mesh, histogram, numCameras, i); 
     35 
     36                if (sal > maxSal) maxSal = sal; 
     37                if (sal < minSal) minSal = sal; 
     38 
     39                mesh->triangles[i].saliency = sal; 
     40        } 
     41 
     42        printf("\nMax Sal: %f  Min Sal: %f\n", maxSal, minSal); 
     43 
     44        percentile = computePercentile(alpha, mesh->triangles, mesh->numTriangles); 
     45        printf("\n%dth percentile: %f\n", alpha, percentile); 
     46} 
     47 
     48void updateTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, int v) { 
     49        int i, t; 
     50 
     51        for(i=0; i<(int)mesh->vertices[v].numTriangles; i++) { 
     52 
     53                t = mesh->vertices[v].triangles[i]; 
     54 
     55                mesh->triangles[t].saliency = computeTriangleSaliency(mesh, histogram, numCameras, t); 
     56        } 
    4657} 
    4758 
    4859double VMI::computeTriangleSaliency(Mesh *mesh, GLuint **histogram, GLuint numCameras, GLuint k) { 
    49     GLuint i, l, v0, v1, v2; 
    50     int triangles[MAX_NUM_TRI], n = 0; 
     60     GLuint i, l, v0, v1, v2; 
     61    int *triangles = NULL, n = 0; 
    5162    double sal = 0.0; 
    5263     
     
    5566    v2 = mesh->triangles[k].indices[2]; 
    5667     
     68    /* Allocating memory */ 
     69    triangles = (int *)malloc((mesh->vertices[v0].numTriangles + 
     70                               mesh->vertices[v1].numTriangles + 
     71                               mesh->vertices[v2].numTriangles) * sizeof(int)); 
     72 
    5773    for(i=0; i<mesh->vertices[v0].numTriangles; i++) { 
    5874        l = mesh->vertices[v0].triangles[i]; 
     
    86102    //getchar(); 
    87103     
     104    free(triangles); 
     105 
    88106    return (sal /*/ n*/); 
    89107} 
     
    150168    if((fp= fopen(filename, "rt"))== NULL) { 
    151169        printf("Can't open file %s\n", filename); 
    152         exit(1); 
     170                                getchar(); 
     171                                exit(1); 
    153172    } 
    154173 
     
    219238void VMI::computeRGB(double min, double max,double value,float *r,float *g,float *b) 
    220239{ 
    221     //Dados el valor máximo, el mínimo y el valor que le quieres calcular el color te devuelve el respectivo RGB. 
    222     if(value>max) value=max; 
    223     if(value<min) value=min; 
    224      
    225     if(max==min) value=1; 
    226     else value=(float)(value-min)/(float)(max-min); 
    227      
    228     if (value<=0.25) 
    229     { 
    230         (*r)=0; 
    231         (*g)=4*value; 
    232         (*b)=1; 
    233     } 
    234     else if (value<=0.50) 
    235     { 
    236         (*r)=0; 
    237         (*g)=1; 
    238         (*b)=2-4*value; 
    239     } 
    240     else if (value<=0.75) 
    241     { 
    242         (*r)=4*value-2; 
    243         (*g)=1; 
    244         (*b)=0; 
    245     } 
    246     else 
    247     { 
    248         (*r)=1; 
    249         (*g)=4-4*value; 
    250         (*b)=0; 
    251     } 
     240        /* Given the maximum, the minimum value and the demanded color value returns 
     241         * the respective RGB color 
     242         */ 
     243        if(value>max) value=max; 
     244        if(value<min) value=min; 
     245 
     246        if(max==min) value=1; 
     247        else value=(float)(value-min)/(float)(max-min); 
     248 
     249        if (value<=0.25) 
     250        { 
     251                (*r)=0; 
     252                (*g)=4*value; 
     253                (*b)=1; 
     254        } 
     255        else if (value<=0.50) 
     256        { 
     257                (*r)=0; 
     258                (*g)=1; 
     259                (*b)=2-4*value; 
     260        } 
     261        else if (value<=0.75) 
     262        { 
     263                (*r)=4*value-2; 
     264                (*g)=1; 
     265                (*b)=0; 
     266        } 
     267        else 
     268        { 
     269                (*r)=1; 
     270                (*g)=4-4*value; 
     271                (*b)=0; 
     272        } 
    252273} 
    253274 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/simplify.cpp

    r1007 r2090  
    99#include "../include/simplify.h" 
    1010#include "../include/saliency.h" 
     11#include "../include/histogram.h" 
    1112 
    1213//#define RECOMPUTE_THE_WHOLE_HEAP 
    13 //#define MAKE_FULL_COPY 
    1414 
    1515using namespace VMI; 
     16using   namespace       std; 
     17 
     18//      Multimap to store current vertex in a simplification state. 
     19typedef multimap<_float3_,      int>    t_map; 
     20typedef t_map::iterator                                         t_map_str; 
     21typedef t_map::value_type                                       t_pair; 
     22t_map                                                                                                                   mVertexMap; 
     23multimap<int,int>                                                                       mVertices; 
     24 
     25vector<Geometry::Vector3>       VMI::vPositions; 
     26vector<Geometry::Vector3>       VMI::vNormals; 
     27vector<Geometry::Vector2>       VMI::vTexCoords; 
    1628 
    1729/////////////////////////////////////////////////////////////////////////////// 
    1830 
    1931void VMI::bh_mydump(Mesh *mesh, bheap_t *h) { 
    20     int i, d; 
    21  
    22     printf("Heap status.\n"); 
    23     for(i = 1; i <= h->n; i++) { 
    24         d = h->a[i].item; 
    25         printf ("Heap [%d] = pri %f, e%d(%d, %d)\n", i, 
    26                   h->a[i].key,d, 
    27                   mesh->edges[d].u, 
    28                   mesh->edges[d].v); 
    29     } 
    30  
    31     printf("\n"); 
    32      
    33     for(i = 2; i <= h->n; i++) { 
    34         if(h->a[i].key < h->a[i/2].key) { 
    35             printf("key error at entry %d, value %f\n", i, h->a[i].key); 
    36             exit(1); 
    37         } 
    38     } 
    39     for(i = 1; i <= h->n; i++) { 
    40         if(h->p[h->a[i].item] != i) { 
    41             printf("indexing error at entry %d", i); exit(1); 
    42         } 
    43     }     
     32        int i, d; 
     33 
     34        printf("Heap status.\n"); 
     35        for(i = 1; i <= h->n; i++) { 
     36                d = h->a[i].item; 
     37                printf ("Heap [%d] = pri %f, e%d(%d, %d) d:%d\n", 
     38                                i, 
     39                                h->a[i].key,d, 
     40                                mesh->edges[d].u, 
     41                                mesh->edges[d].v,  
     42                                h->a[i].dirty); 
     43        } 
     44        printf("\n"); 
     45 
     46        for(i = 2; i <= h->n; i++) { 
     47                if(h->a[i].key < h->a[i/2].key) { 
     48                        printf("key error at entry %d, value %f\n", i, h->a[i].key); 
     49                        exit(1); 
     50                } 
     51        } 
     52        for(i = 1; i <= h->n; i++) { 
     53                if(h->p[h->a[i].item] != i) { 
     54                        printf("indexing error at entry %d", i); 
     55                        exit(1); 
     56                } 
     57        }     
    4458} 
    4559 
    4660bheap_t *VMI::initHeap(Mesh *mesh) { 
    47     GLuint i; 
    48     double cost; 
    49     bheap_t *h = NULL; 
    50 #ifdef MAKE_FULL_COPY 
    51     Triangle *triangleCopy = NULL; 
    52     GLuint lastNumTriangles = mesh->numTriangles; 
    53  
    54     // Allocate memory 
    55     triangleCopy = (Triangle *)malloc(lastNumTriangles * sizeof(Triangle));   
    56     if (triangleCopy == NULL) { 
    57         fprintf(stderr, "Error allocating memory\n"); 
    58         exit(1); 
    59     } 
    60     // Make a copy of current triangle list 
    61     memcpy(triangleCopy, mesh->triangles, lastNumTriangles * sizeof(Triangle)); 
    62 #endif 
    63      
    64     printf("Creating a heap for simplification..."); 
    65      
    66     h = bh_alloc(mesh->numEdges); 
    67  
    68                 //      Init percent update count. 
    69                 float   percent =       60.0 / mesh->numEdges; 
    70  
    71     for (i = 0; i <mesh->numEdges; i++) { 
    72  
    73                                 //      Update progress bar. 
    74                                 mUPB(percent); 
    75  
    76         if (mesh->edges[i].enable == TRUE) { 
    77  
    78             cost = computeEdgeCost(mesh, i); 
    79          
    80             // Add only valid edges 
    81             if (cost != FLT_MAX) 
    82                 bh_insert(h, i, cost); 
    83  
    84 #ifdef MAKE_FULL_COPY 
    85             // Restore initial triangle list 
    86             memcpy(mesh->triangles, triangleCopy, lastNumTriangles * sizeof(Triangle)); 
    87             mesh->numTriangles = lastNumTriangles; 
    88 #endif 
    89         } 
    90     } 
    91      
    92 #ifdef MAKE_FULL_COPY 
    93     // Free memory 
    94     if (triangleCopy != NULL) free(triangleCopy); 
    95 #endif 
    96     printf("Ok\n"); 
     61        GLuint i; 
     62        double cost; 
     63        bheap_t *h = NULL; 
     64 
     65        printf("Creating a heap for simplification..."); 
     66 
     67        h = bh_alloc(mesh->numEdges); 
     68 
     69        //      Init percent update count. 
     70        float   percent =       60.0 / mesh->numEdges; 
     71 
     72        for (i = 0; i <mesh->numEdges; i++) { 
     73 
     74                //      Update progress bar. 
     75                mUPB(percent); 
     76 
     77                if (mesh->edges[i].enable == TRUE) { 
     78 
     79                        cost = computeEdgeCost(mesh, i); 
     80 
     81                        // Add only valid edges 
     82                        if (cost != FLT_MAX) { 
     83                                bh_insert(h, i, cost); 
     84                                /* set dirty flag to FALSE */ 
     85                                bh_mark(h, i, FALSE); 
     86                        } 
     87                } 
     88        } 
     89 
     90        printf("Ok\n"); 
    9791 
    9892#ifdef DEBUG  
    99     bh_mydump(mesh, h); 
    100     //getchar(); 
    101 #endif 
    102  
    103     return h; 
     93        bh_mydump(mesh, h); 
     94        //getchar(); 
     95#endif 
     96 
     97        return h; 
    10498} 
    10599 
    106100bheap_t *VMI::updateHeap(bheap_t *h, Mesh *mesh, Change *c) { 
    107     int e, i, n0, n1, n2, u, v; 
     101        int e, i; 
    108102#ifdef RECOMPUTE_THE_WHOLE_HEAP 
    109     bheap_t *nh; 
     103        bheap_t *nh; 
     104        double cost; 
    110105#else 
    111     int *lv, *le, numV, numE; 
    112 #endif 
    113     double cost; 
    114 #ifdef MAKE_FULL_COPY 
    115     GLuint lastNumTriangles = mesh->numTriangles; 
    116     Triangle *triangleCopy = NULL; 
    117      
    118     // Allocate memory 
    119     triangleCopy = (Triangle *)malloc(lastNumTriangles * sizeof(Triangle));   
    120     if (triangleCopy == NULL) { 
    121         fprintf(stderr, "Error allocating memory\n"); 
    122         exit(1); 
    123     } 
    124     // Make a copy of current triangle list 
    125     memcpy(triangleCopy, mesh->triangles, lastNumTriangles * sizeof(Triangle)); 
    126 #endif 
    127  
    128     for (i=0; i<c->numDel; i++) { 
    129  
    130         n0 = c->deleted[i].indices[0]; 
    131         n1 = c->deleted[i].indices[1]; 
    132         n2 = c->deleted[i].indices[2]; 
    133  
    134         if (((n0 == c->u) || (n1 == c->u)) && 
    135             ((e = findEdge(mesh->edges, mesh->numEdges, n0, n1)) != -1)) { 
    136  
    137             mesh->edges[e].enable = FALSE; 
    138             bh_delete(h, e); 
    139         } 
    140  
    141         if (((n1 == c->u) || (n2 == c->u)) && 
    142             ((e = findEdge(mesh->edges, mesh->numEdges, n1, n2)) != -1)) { 
    143               
    144             mesh->edges[e].enable = FALSE; 
    145             bh_delete(h, e); 
    146         } 
    147  
    148         if (((n0 == c->u) || (n2 == c->u)) && 
    149             ((e = findEdge(mesh->edges, mesh->numEdges, n0, n2)) != -1)) { 
    150                
    151             mesh->edges[e].enable = FALSE; 
    152             bh_delete(h, e); 
    153         } 
    154     } 
    155  
    156     // Update mesh and heap 
    157     for(i = 1; i <= h->n; i++) { 
    158         e = h->a[i].item; 
    159  
    160         if ((int)mesh->edges[e].u == c->u) 
    161             mesh->edges[e].u = c->v; 
    162  
    163         if ((int)mesh->edges[e].v == c->u) 
    164             mesh->edges[e].v = c->v; 
    165          
    166         // Check edge 
    167         u = mesh->edges[e].u; 
    168         v = mesh->edges[e].v; 
    169      
    170         // if it is not a valid edge we simply delete it 
    171         if ((u == v) ||  
    172             (u == c->u) || (v == c->u)) { 
    173  
    174             mesh->edges[e].enable = FALSE; 
    175             bh_delete(h, e); 
    176         } 
    177     } 
     106        int *lv, *le, numV, numE; 
     107#endif 
    178108 
    179109#ifdef RECOMPUTE_THE_WHOLE_HEAP 
    180110 
    181     nh = bh_alloc(mesh->numEdges); 
    182  
    183     // Recompute heap 
    184     for(i = 1; i <= h->n; i++) { 
    185         e = h->a[i].item; 
    186          
    187         cost = computeEdgeCost(mesh, e); 
    188          
    189         // Add only valid edges 
    190         if (cost != FLT_MAX) 
    191             bh_insert(nh, e, cost); 
    192          
    193 #ifdef MAKE_FULL_COPY 
    194         // Restore initial triangle list 
    195         memcpy(mesh->triangles, triangleCopy, lastNumTriangles * sizeof(Triangle)); 
    196         mesh->numTriangles = lastNumTriangles; 
    197 #endif 
    198     } 
    199  
    200 #ifdef MAKE_FULL_COPY 
    201     // Free memory 
    202     if (triangleCopy != NULL) free(triangleCopy); 
    203 #endif 
    204     bh_free(h); 
    205  
    206     h = nh; 
     111        nh = bh_alloc(mesh->numEdges); 
     112 
     113        // Recompute heap 
     114        for(i = 1; i <= h->n; i++) { 
     115                e = h->a[i].item; 
     116 
     117                cost = computeEdgeCost(mesh, e); 
     118 
     119                // Add only valid edges 
     120                if (cost != FLT_MAX) 
     121                        bh_insert(nh, e, cost); 
     122        } 
     123 
     124        bh_free(h); 
     125 
     126        h = nh; 
    207127 
    208128#else 
    209129 
    210     // Compute vertices adjacent to a vertex 
    211     lv = verticesAdjToVertex(mesh, c->v, &numV); 
    212  
    213     // Compute edges adjacent to vertices 
    214     le = edgesAdjToVertices(mesh, lv, numV, &numE); 
    215  
    216     free(lv); 
    217  
    218     // Delete adjacent edges from the heap 
    219     for(i = 0; i <numE; i++) { 
    220         e = le[i]; 
    221  
    222         mesh->edges[e].enable = FALSE; 
    223         bh_delete(h, e); 
    224     } 
    225  
    226     // Recompute cost only for the adjacent edges 
    227     for(i = 0; i <numE; i++) { 
    228         e = le[i]; 
    229          
    230         cost = computeEdgeCost(mesh, e); 
    231  
    232         // Add only valid edges 
    233         if (cost != FLT_MAX) { 
    234             bh_insert(h, e, cost); 
    235             mesh->edges[e].enable = TRUE; 
    236         } 
    237          
    238 #ifdef MAKE_FULL_COPY 
    239         // Restore initial triangle list 
    240         memcpy(mesh->triangles, triangleCopy, lastNumTriangles * sizeof(Triangle)); 
    241         mesh->numTriangles = lastNumTriangles; 
    242 #endif 
    243  
    244     } 
    245  
    246 #ifdef MAKE_FULL_COPY 
    247     // Free memory 
    248     if (triangleCopy != NULL) free(triangleCopy); 
    249 #endif 
    250  
    251     free(le); 
     130        // Compute vertices adjacent to a vertex 
     131        lv = verticesAdjToVertex(mesh, c->v, &numV); 
     132 
     133        // Compute edges adjacent to vertices 
     134        le = edgesAdjToVertices(mesh, lv, numV, &numE); 
     135 
     136        free(lv); 
     137 
     138        // Set a dirty flag to adjacent edges from the heap 
     139        for(i = 0; i <numE; i++) { 
     140                e = le[i]; 
     141 
     142                bh_mark(h, e, TRUE); 
     143        } 
     144 
     145        free(le); 
    252146#endif 
    253147 
    254148#ifdef DEBUG  
    255     bh_mydump(mesh, h); 
    256     //getchar(); 
    257 #endif 
    258  
    259     return h; 
     149        bh_mydump(mesh, h); 
     150        //getchar(); 
     151#endif 
     152 
     153        return h; 
    260154} 
    261155 
    262156GLdouble VMI::computeEdgeLength(Vertex *vertices, int u, int v) { 
    263     GLfloat ux, uy, uz, vx, vy ,vz, rx, ry, rz; 
    264      
    265     ux = vertices[u].x; 
    266     uy = vertices[u].y; 
    267     uz = vertices[u].z; 
    268  
    269     vx = vertices[v].x; 
    270     vy = vertices[v].y; 
    271     vz = vertices[v].z; 
    272  
    273     rx = ux - vx; 
    274     ry = uy - vy; 
    275     rz = uz - vz; 
    276  
    277     return sqrt((rx * rx) + (ry * ry) + (rz * rz)); 
     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)); 
    278172} 
    279173 
    280174/////////////////////////////////////////////////////////////////////////////// 
    281175 
    282 void VMI::swap(unsigned int *i, unsigned int *j) { 
    283     unsigned int t; 
    284  
    285     t = *i; 
    286     *i = *j; 
    287     *j = t; 
    288 } 
    289  
    290176void VMI::chooseBestEndPoints(Mesh *mesh, int e) { 
    291     int v = mesh->edges[e].v; 
    292     int u = mesh->edges[e].u; 
    293     int numTu; 
    294     int *Tu  = trianglesAdjToVertex(mesh, u, &numTu); 
    295     int numTuv = 0; 
    296     int *Tuv = (int *)malloc(numTu * sizeof(int)); 
    297     int numTv; 
    298     int *Tv  = trianglesAdjToVertex(mesh, v, &numTv); 
    299     int i, j, f, n, n0, n1, n2; 
    300     float cost_u_v, cost_v_u, mincurve, curve, dot; 
    301      
    302     //printItemList(Tv, numTv); 
    303     //printItemList(Tu, numTu); 
    304      
    305     // Compute Tuv 
    306     for (i=0; i<(int)numTu; i++) { 
    307          
    308         n = Tu[i]; 
    309          
    310         n0 = mesh->triangles[n].indices[0]; 
    311         n1 = mesh->triangles[n].indices[1]; 
    312         n2 = mesh->triangles[n].indices[2]; 
    313          
    314         if ((n0 == v) || (n1 == v) || (n2 == v)) 
    315              
    316             Tuv[numTuv++] = n; 
    317     } 
    318     //printItemList(Tuv, numTuv); 
    319      
    320     curve = 0.0f; 
    321     for (i=0; i<numTu; i++) { 
    322         n = Tu[i]; 
    323         mincurve = 1.0f; 
    324         for (j=0; j<numTuv; j++) { 
    325             f = Tuv[j]; 
    326             dot = glmDot(mesh->triangles[f].normal, mesh->triangles[n].normal); 
    327             //printf("dot: %f \n", dot); 
    328             mincurve = MIN(mincurve, (1.0f - dot) / 2.0f); 
    329         } 
    330         //printf("mincurve: %f \n", mincurve); 
    331         curve = MAX(curve, mincurve); 
    332     } 
    333     cost_u_v = curve; 
    334      
    335     curve = 0.0f; 
    336     for (i=0; i<numTv; i++) { 
    337         n = Tv[i]; 
    338         mincurve = 1.0f; 
    339         for (j=0; j<numTuv; j++) { 
    340             f = Tuv[j]; 
    341             dot = glmDot(mesh->triangles[f].normal, mesh->triangles[n].normal); 
    342             //printf("%f \n", dot); 
    343             mincurve = MIN(mincurve, (1.0f - dot) / 2.0f); 
    344         } 
    345         curve = MAX(curve, mincurve); 
    346     } 
    347     cost_v_u = curve; 
    348      
    349     //printf("e%d(%d,%d) cost: %f \n", e, u, v, cost_u_v); 
    350     //printf("e%d(%d,%d) cost: %f \n", e, v, u, cost_v_u); 
    351      
    352     if ( (cost_v_u + 0.000001) < cost_u_v) { 
    353         //printf("Swap edge\n"); 
    354         //printf("e%d(%d,%d) cost: %f \n", e, u, v, cost_u_v); 
    355         //printf("e%d(%d,%d) cost: %f \n", e, v, u, cost_v_u); 
    356         swap(&mesh->edges[e].u, &mesh->edges[e].v); 
    357     } 
    358  
    359     free(Tuv); 
    360     free(Tu); 
    361     free(Tv); 
     177        int v = mesh->edges[e].v; 
     178        int u = mesh->edges[e].u; 
     179        int numTu = mesh->vertices[u].numTriangles; 
     180        int numTuv = 0; 
     181        int *Tuv = (int *)malloc(numTu * sizeof(int)); 
     182        int i, j, f, n, n0, n1, n2; 
     183        float cost_u_v, cost_v_u, mincurve, curve, dot; 
     184 
     185        // Compute Tuv 
     186        for (i=0; i<(int)numTu; i++) { 
     187 
     188                n = mesh->vertices[u].triangles[i]; 
     189 
     190                n0 = mesh->triangles[n].indices[0]; 
     191                n1 = mesh->triangles[n].indices[1]; 
     192                n2 = mesh->triangles[n].indices[2]; 
     193 
     194                if ((n0 == v) || (n1 == v) || (n2 == v)) 
     195 
     196                        Tuv[numTuv++] = n; 
     197        } 
     198        //printItemList(Tuv, numTuv); 
     199 
     200        curve = 0.0f; 
     201        for (i=0; i<numTu; i++) { 
     202                n = mesh->vertices[u].triangles[i]; 
     203                mincurve = 1.0f; 
     204                for (j=0; j<numTuv; j++) { 
     205                        f = Tuv[j]; 
     206                        dot = glmDot(mesh->triangles[f].normal, mesh->triangles[n].normal); 
     207                        //printf("dot: %f \n", dot); 
     208                        mincurve = MIN(mincurve, (1.0f - dot) / 2.0f); 
     209                } 
     210                //printf("mincurve: %f \n", mincurve); 
     211                curve = MAX(curve, mincurve); 
     212        } 
     213        cost_u_v = curve; 
     214 
     215        curve = 0.0f; 
     216        for (i=0; i<(int)mesh->vertices[v].numTriangles; i++) { 
     217                n = mesh->vertices[v].triangles[i]; 
     218                mincurve = 1.0f; 
     219                for (j=0; j<numTuv; j++) { 
     220                        f = Tuv[j]; 
     221                        dot = glmDot(mesh->triangles[f].normal, mesh->triangles[n].normal); 
     222                        //printf("%f \n", dot); 
     223                        mincurve = MIN(mincurve, (1.0f - dot) / 2.0f); 
     224                } 
     225                curve = MAX(curve, mincurve); 
     226        } 
     227 
     228        cost_v_u = curve; 
     229 
     230        //printf("e%d(%d,%d) cost: %f \n", e, u, v, cost_u_v); 
     231        //printf("e%d(%d,%d) cost: %f \n", e, v, u, cost_v_u); 
     232 
     233        if ( (cost_v_u + 0.000001) < cost_u_v) { 
     234                //printf("Swap edge\n"); 
     235                //printf("e%d(%d,%d) cost: %f \n", e, u, v, cost_u_v); 
     236                //printf("e%d(%d,%d) cost: %f \n", e, v, u, cost_v_u); 
     237                 
     238                swap((int *)&mesh->edges[e].u, (int *)&mesh->edges[e].v); 
     239        } 
     240 
     241        free(Tuv); 
    362242} 
    363243/////////////////////////////////////////////////////////////////////////////// 
    364244 
     245void 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++) { 
     249 
     250                t = c->deleted[j].id; 
     251 
     252                for (i=0; i<numCameras; i++) { 
     253 
     254                        dest[n] = histogram[i][t + 1]; 
     255                        n++; 
     256                } 
     257        } 
     258 
     259        for (j=0; j<(GLuint)c->numMod; j++) {  
     260 
     261                t = c->modified[j].id; 
     262 
     263                for (i=0; i<numCameras; i++) { 
     264 
     265                        dest[n] = histogram[i][t + 1]; 
     266                        n++; 
     267                }    
     268        } 
     269 
     270        // Save background area 
     271        for (i=0; i<numCameras; i++) { 
     272 
     273                dest[n] = histogram[i][0]; 
     274                n++; 
     275        } 
     276} 
     277 
     278void 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++) {  
     282 
     283                t = c->deleted[j].id; 
     284 
     285                for (i=0; i<numCameras; i++) { 
     286 
     287                        histogram[i][t + 1] = src[n]; 
     288                        n++; 
     289                } 
     290        } 
     291 
     292        for (j=0; j<(GLuint)c->numMod; j++) {  
     293 
     294                t = c->modified[j].id; 
     295 
     296                for (i=0; i<numCameras; i++) { 
     297 
     298                        histogram[i][t + 1] = src[n]; 
     299                        n++; 
     300                } 
     301        } 
     302 
     303        // Load background area 
     304        for (i=0; i<numCameras; i++) { 
     305 
     306                histogram[i][0] = src[n]; 
     307                n++; 
     308        } 
     309} 
     310 
     311/////////////////////////////////////////////////////////////////////////////// 
     312 
    365313GLdouble VMI::computeEdgeCost(Mesh *mesh, int e) { 
    366     GLdouble cost = 0.0, newI, sal = 1.0, /*length,*/ error; 
    367     GLuint i; 
    368     Change *c; 
    369  
    370     chooseBestEndPoints(mesh, e); 
    371     //getchar(); 
    372  
    373     c = createChange(mesh, e); 
    374      
     314        GLdouble cost = 0.0, sal = 1.0; 
     315#ifdef MI 
     316        GLdouble *auxIs = NULL; 
     317#else 
     318        GLdouble newI; 
     319#endif 
     320        GLuint i, *histoAux = NULL; 
     321        Change *c; 
     322 
     323        chooseBestEndPoints(mesh, e); 
     324        //getchar(); 
     325 
     326        c = createChange(mesh, e); 
     327 
     328        // Compute cost only for boundary or manifold edges 
     329        if (c->numDel == 2 
     330                        /*(c->numDel <3) && (c->numDel > 0)*/) { 
     331                // Allocate memory 
     332                histoAux = (GLuint *)malloc((c->numDel + c->numMod + 1) * numCameras * sizeof(GLuint)); 
     333 
     334#ifdef MI // Mutual Information 
     335                /////////////////////////////////////////////////////////////////////////////// 
     336                // Allocate memory 
     337                auxIs = (GLdouble *)malloc(numCameras * sizeof(GLdouble)); 
     338 
     339                //printFullHistogram(histogram, numCameras, mesh->numTriangles); 
     340 
     341                for (i=0; i<numCameras; i++) { 
     342                        // Copy old informations 
     343                        auxIs[i] = initialIs[i]; 
     344 
     345                        initialIs[i] = decMI(initialIs[i], histogram, numCameras, i, c); 
     346                } 
     347 
     348                saveProjectedAreas(histogram, numCameras, c, histoAux); 
    375349    // Apply the edge collapse 
    376     computeChanges(mesh, c); 
    377      
    378     // Compute cost only for boundary or manifold edges 
    379     if ((c->numDel <3) && (c->numDel > 0)) { 
    380  
    381         //length = computeEdgeLength(mesh->vertices, c->u, c->v); 
    382  
    383         doChange(mesh, c); 
    384          
    385         // Compute the cost of an edge collapse 
    386         getProjectedAreas(histogram, numCameras); 
    387         //printFullHistogram(histogram, numCameras, mesh->numTriangles); 
    388         //getchar(); 
     350                doChange(mesh, c); 
     351 
     352                // Compute the cost of an edge collapse 
     353                getProjectedAreasWin(histogram, numCameras, c); 
     354                //printFullHistogram(histogram, numCameras, mesh->numTriangles); 
     355                //getchar(); 
     356 
    389357#ifdef SALIENCY 
    390         sal = computeEdgeSaliency(mesh, c, percentile); 
    391         //printf("  e:%d s: %f\n", c->e, sal); 
    392 #endif 
    393         for (i=0;i <numCameras; i++) { 
     358                sal = computeEdgeSaliency(mesh, c, percentile); 
     359                //printf("  e:%d s: %f\n", c->e, sal); 
     360#endif 
     361 
     362                for (i=0; i<numCameras; i++) { 
     363 
     364                        initialIs[i] = incMI(initialIs[i], histogram, numCameras, i, c); 
     365                        //printf("  I0:%f Is: %f\n", auxE[i], initialIs[i]); 
     366 
     367                        cost += (ABS(auxIs[i] - initialIs[i]) * cameras[i].weight * sal); 
     368 
     369                        // Restore old informations 
     370                        initialIs[i] = auxIs[i]; 
     371                } 
     372 
     373                undoChange(mesh, c); 
     374 
     375                loadProjectedAreas(histoAux, numCameras, c, histogram); 
     376                //printFullHistogram(histogram, numCameras, mesh->numTriangles); 
     377                //exit(1); 
     378 
     379                // Free memory 
     380                free(auxIs); 
     381#else 
     382                /////////////////////////////////////////////////////////////////////////////// 
     383 
     384                saveProjectedAreas(histogram, numCameras, c, histoAux); 
     385 
     386                doChange(mesh, c); 
     387 
     388                // Compute the cost of an edge collapse 
     389                getProjectedAreasWin(histogram, numCameras, c); 
     390                //printFullHistogram(histogram, numCameras, mesh->numTriangles); 
     391 
     392#ifdef SALIENCY 
     393                sal = computeEdgeSaliency(mesh, c, percentile); 
     394                //printf("  e:%d s: %f\n", c->e, sal); 
     395#endif 
     396                for (i=0;i <numCameras; i++) { 
    394397 
    395398#ifdef KL // Kullback-Leibler 
    396             newI = computeKL(mesh, histogram[i]); 
    397 #endif 
    398 #ifdef MI // Mutual Information 
    399             newI = computeMI(mesh, histogram, numCameras, i); 
     399                        newI = computeKL(mesh, histogram[i]); 
    400400#endif 
    401401#ifdef HE // Hellinger 
    402             newI = computeHE(mesh, histogram[i]); 
     402                        newI = computeHE(mesh, histogram[i]); 
    403403#endif 
    404404#ifdef CS // Chi-Square 
    405             newI = computeCS(mesh, histogram[i]); 
    406 #endif 
    407  
    408             error = ABS(initialIs[i] - newI); 
    409              
    410             if (error > 0.0)  
    411                 cost += ((error * cameras[i].weight * sal) /*+ (length * 0.05)*/); 
    412         } 
    413  
    414         undoChange(mesh, c); 
    415  
    416     } else cost = FLT_MAX; 
    417  
    418  
    419     deleteChange(c); 
    420  
    421     return cost; 
    422 } 
    423  
    424 /////////////////////////////////////////////////////////////////////////////// 
    425  
     405                        newI = computeCS(mesh, histogram[i]); 
     406#endif 
     407                        cost += (ABS(initialIs[i] - newI) * cameras[i].weight * sal); 
     408                } 
     409                undoChange(mesh, c); 
     410 
     411                loadProjectedAreas(histoAux, numCameras, c, histogram); 
     412                //printFullHistogram(histogram, numCameras, mesh->numTriangles); 
     413                //exit(1); 
     414 
     415                /////////////////////////////////////////////////////////////////////////////// 
     416#endif 
     417                // Free memory 
     418                free(histoAux); 
     419 
     420        } else cost = FLT_MAX; 
     421 
     422        deleteChange(c); 
     423 
     424        return cost; 
     425} 
     426/* Get a valid edge from the heap */ 
     427int getMinValidEdge(Mesh *mesh, bheap_t *h) { 
     428        int e; 
     429 
     430        /* pick the minimum-cost valid edge from heap */ 
     431        e = bh_min(h); 
     432 
     433        while (mesh->edges[e].enable == FALSE) { 
     434                /* delete invalid edge */ 
     435                bh_delete(h, e); 
     436                /* pick again*/ 
     437                e = bh_min(h); 
     438        } 
     439 
     440        return e; 
     441} 
     442 
     443/* Get the mininum edge cost from the heap using lazy evaluation */ 
     444int getMinEdge(Mesh *mesh, bheap_t *h) { 
     445        double cost; 
     446        int e; 
     447 
     448        /* pick the minimum-cost edge from heap */ 
     449        e = getMinValidEdge(mesh, h); 
     450 
     451        while (bh_is_dirty(h, e)) { 
     452                /* delete edge from heap */ 
     453                bh_delete(h, e); 
     454                mesh->edges[e].enable = FALSE; 
     455                /* recompute cost*/ 
     456                cost = computeEdgeCost(mesh, e); 
     457 
     458                // Add only valid edges 
     459                if (cost != FLT_MAX) { 
     460                        /* reinsert into the heap */ 
     461                        bh_insert(h, e, cost); 
     462                        mesh->edges[e].enable = TRUE; 
     463                        /* set dirty flag to FALSE */ 
     464                        bh_mark(h, e, FALSE); 
     465                } 
     466 
     467                /* pick again */ 
     468                e = getMinValidEdge(mesh, h); 
     469        } 
     470 
     471        return e; 
     472} 
     473 
     474/////////////////////////////////////////////////////////////////////////// 
    426475void VMI::simplifyModel(Mesh *mesh, GLuint numDemandedTri) 
    427476{ 
     
    444493        { 
    445494#ifdef SALIENCY        
    446 #ifdef KL // Kullback-Leibler 
    447                 sprintf(s,"%s_VKL_S.log", filename); 
    448 #endif 
    449 #ifdef MI // Mutual Information 
    450                 sprintf(s,"%s_VMI_S.log", filename); 
    451 #endif 
    452 #ifdef HE // Hellinger 
    453                 sprintf(s,"%s_VHE_S.log", filename); 
    454 #endif 
    455 #ifdef CS // Chi-Square 
    456                 sprintf(s,"%s_VCS_S.log", filename); 
    457 #endif 
     495                sprintf(s,"%s_%s_S.log", filename, EXT); 
    458496#else 
    459 #ifdef KL // Kullback-Leibler 
    460                 sprintf(s,"%s_VKL.log", filename); 
    461 #endif 
    462 #ifdef MI // Mutual Information 
    463                 sprintf(s,"%s_VMI.log", filename); 
    464 #endif 
    465 #ifdef HE // Hellinger 
    466                 sprintf(s,"%s_VHE.log", filename); 
    467 #endif 
    468 #ifdef CS // Chi-Square 
    469                 sprintf(s,"%s_VCS.log", filename); 
    470 #endif 
     497                sprintf(s,"%s_%s.log", filename, EXT); 
    471498#endif 
    472499 
     
    475502                /* open the file */ 
    476503                file = fopen(s, "a+"); 
    477                  
     504 
    478505                if (!file) 
    479506                { 
     
    485512        //      Open file of simplification sequence. 
    486513        file_simp_seq   =       fopen("SimplifSequence.txt", "w"); 
    487          
     514 
    488515        if (!file_simp_seq) 
    489516        { 
    490517                fprintf(stderr, 
    491                                                 "simplifyModel() failed: ", 
    492                                                 "can't open file \"SimplifSequence\" to write.\n"); 
    493         } 
    494          
     518                                "simplifyModel() failed: ", 
     519                                "can't open file \"SimplifSequence\" to write.\n"); 
     520        } 
     521 
    495522        h = initHeap(mesh); 
    496523 
     
    500527        { 
    501528                // Get the edge that has the minimum cost 
    502                 e = bh_min(h); 
     529                //e = getMinEdge(mesh, h); 
     530                e = extractValidEdge(mesh, h); 
    503531 
    504532                c = createChange(mesh, e); 
    505533 
    506534                // Apply the edge collapse 
    507                 computeChanges(mesh, c); 
    508535                doChange(mesh, c); 
     536                //deleteVertexOfMap(mesh, c->u); 
     537 
     538                // Write Simplification sequence. 
     539                saveSimplificationSequence(c,0); 
     540 
     541                //contractTwinVertices(mesh, c->u, c->v); // vertex u is removed 
    509542 
    510543                if (bSaveLog == TRUE) writeChange(file, c); 
    511544 
    512                 //      Write Simplification sequence. 
    513                 saveSimplificationSequence(c); 
    514                  
    515545                cost = h->a[h->p[e]].key; 
    516                  
     546 
     547                /* 
    517548                printf( "Edge collapse e%d(%d,%d) %f MIN d %d m %d\n", 
    518                                                 c->e, 
    519                                                 c->u, 
    520                                                 c->v, 
    521                                                 cost, 
    522                                                 c->numDel, 
    523                                                 c->numMod); 
     549                                c->e, 
     550                                c->u, 
     551                                c->v, 
     552                                cost, 
     553                                c->numDel, 
     554                                c->numMod); 
     555                */ 
    524556 
    525557                mesh->edges[e].enable = FALSE; 
    526                  
    527558                bh_delete(h, e); 
    528559 
     
    532563                computeCameraIs(histogram, numCameras, initialIs); 
    533564 
     565                deleteEdges(mesh, c); 
     566                modifyEdges(mesh, c); 
     567 
    534568                // Update the heap according to the edge collapse 
    535569                h = updateHeap(h, mesh, c); 
     
    539573                deleteChange(c); 
    540574 
    541                 printf("t %d\n", mesh->currentNumTriangles); 
    542         } 
     575                //printf("t %d\n", mesh->currentNumTriangles); 
     576        } 
     577 
     578        //      Debug. 
     579        cout    <<      "Number of vertices: " 
     580                <<      mesh->currentNumVertices 
     581                <<      endl; 
    543582 
    544583        if (bSaveLog == TRUE) 
     
    554593} 
    555594 
     595/////////////////////////////////////////////////////////////////////////////// 
     596//      Extract a correct edge of the heap. 
     597/////////////////////////////////////////////////////////////////////////////// 
     598int VMI::extractValidEdge(Mesh *mesh,   bheap_t *h) 
     599{ 
     600        int     e; 
     601 
     602        while((e        =       isValidEdge(mesh,getMinEdge(mesh, h))) == -1); 
     603 
     604        return  e; 
     605} 
     606 
     607/////////////////////////////////////////////////////////////////////////////// 
     608//      Indicates if an edge is valid. 
     609/////////////////////////////////////////////////////////////////////////////// 
     610int     VMI::isValidEdge(Mesh   *mesh,  int edge) 
     611{ 
     612        int     result; 
     613        Vertex  *u; 
     614        Vertex  *v; 
     615        _float3_        fu; 
     616        _float3_        fv; 
     617 
     618        u       =       &mesh->vertices[mesh->edges[edge].u]; 
     619        v       =       &mesh->vertices[mesh->edges[edge].v]; 
     620 
     621        fu      =       _float3_(u->x,u->y,u->z); 
     622        fv      =       _float3_(v->x,v->y,v->z); 
     623 
     624        if ((mVertexMap.find(fu) != mVertexMap.end()) 
     625                        || 
     626                        (mVertexMap.find(fv) != mVertexMap.end())) 
     627        { 
     628                result  = edge; 
     629        } 
     630        //      Edge is not valid. 
     631        else 
     632        { 
     633                result  =       -1; 
     634        } 
     635 
     636        return  result; 
     637} 
     638 
     639//------------------------------------------------------------------------- 
     640//      Inits the multimap of vertices. 
     641//------------------------------------------------------------------------- 
     642void    VMI::initVertexMultimap(Mesh *mesh,multimap<int,int> &vertexMultimap) 
     643{ 
     644        Vertex  *vertex; 
     645        float           x,y,z; 
     646 
     647        //      Clears multimap of vertices. 
     648        mVertexMap.clear(); 
     649        mVertices.clear(); 
     650 
     651        mVertices       =       vertexMultimap; 
     652 
     653        //      Debug. 
     654        cout    <<      "Vertex Map Elements: " 
     655                                <<      mVertices.size() 
     656                                <<      endl; 
     657 
     658        //      For each vertex. 
     659        for (int        i       =       0;      i < mesh->numVertices;  i++) 
     660        { 
     661                vertex  =       &mesh->vertices[i]; 
     662 
     663                x       =       vertex->x; 
     664                y       =       vertex->y; 
     665                z       =       vertex->z; 
     666 
     667                mVertexMap.insert(t_pair(_float3_(x,y,z),i)); 
     668        } 
     669} 
     670 
     671//------------------------------------------------------------------------- 
     672//      Deletes a vertex in the multimap. 
     673//------------------------------------------------------------------------- 
     674void    VMI::deleteVertexOfMap(Mesh     *mesh, int u) 
     675{ 
     676        _float3_        removed_vert; 
     677        t_map_str       lb; 
     678        t_map_str       ub; 
     679 
     680        //      Position of the vertex removed. 
     681        removed_vert    =       _float3_(       mesh->vertices[u].x, 
     682                                                                                                                mesh->vertices[u].y, 
     683                                                                                                                mesh->vertices[u].z); 
     684 
     685        //      If position of the removed vertex is found. 
     686        if (mVertexMap.end() != mVertexMap.find(removed_vert)) 
     687        { 
     688                lb      =       mVertexMap.lower_bound(removed_vert); 
     689                ub      =       mVertexMap.upper_bound(removed_vert); 
     690 
     691                //      For each vertex. 
     692                while   (lb != ub) 
     693                { 
     694                        //      If removed vertex is found. 
     695                        if ((*lb).second == u) 
     696                        { 
     697                                //      Debug. 
     698                                cout    <<      "Vertex erased: " 
     699                                                        <<      (*lb).second 
     700                                                        <<      endl; 
     701 
     702                                //      Delete vertex that disappears. 
     703                                mVertexMap.erase(lb); 
     704                                 
     705                                //      Break while. 
     706                                lb      =       ub; 
     707                        } 
     708                        else 
     709                        { 
     710                                //      Next iteration. 
     711                                lb++; 
     712                        } 
     713                } 
     714        } 
     715} 
     716 
     717//------------------------------------------------------------------------- 
     718//      Compare the coordinates of two vertices. 
     719//------------------------------------------------------------------------- 
     720bool    VMI::compareVertices(Vertex *vertices,int       u,      int v) 
     721{ 
     722        if ((vertices[u].x == vertices[v].x) 
     723                        && 
     724                        (vertices[u].y == vertices[v].y) 
     725                        && 
     726                        (vertices[u].z == vertices[v].z)) 
     727        { 
     728                return  true; 
     729        } 
     730        else 
     731        { 
     732                return  false; 
     733        } 
     734} 
     735 
     736//------------------------------------------------------------------------- 
     737//      Find edge of the simplification sequence. 
     738//------------------------------------------------------------------------- 
     739void    VMI::contractInitialMesh(Mesh   *mesh) 
     740{ 
     741        bool            edge_found; 
     742        Geometry::MeshSimplificationSequence::Step      step; 
     743 
     744        multimap<int,int>::iterator     it0; 
     745        multimap<int,int>::iterator     lb0; 
     746        multimap<int,int>::iterator     ub0; 
     747        multimap<int,int>::iterator     lb1; 
     748        multimap<int,int>::iterator     ub1; 
     749 
     750        std::vector<Geometry::MeshSimplificationSequence::Step> steps; 
     751 
     752        Edge            *econ; 
     753        float           x,y,z; 
     754        int                     *lv1; 
     755        int                     v0; 
     756        int                     v1; 
     757        int                     edge; 
     758        int                     num_edges; 
     759        Change  *c; 
     760 
     761        //      Copy simplification steps of the joined mesh. 
     762        steps   =       mSequence->mSteps; 
     763 
     764        mSequence->mSteps.clear(); 
     765 
     766        for     (size_t i       =       0;      i < steps.size(); i++) 
     767        { 
     768                step    =       steps[i]; 
     769 
     770                lb0     =       mVertices.lower_bound(steps[i].mV0); 
     771                ub0     =       mVertices.upper_bound(steps[i].mV0); 
     772                lb1     =       mVertices.lower_bound(steps[i].mV1); 
     773                ub1     =       mVertices.upper_bound(steps[i].mV1); 
     774 
     775                edge_found      =       false; 
     776 
     777                //      Debug. 
     778                cout    <<      "step " 
     779                                        <<      i 
     780                                        <<      " V0: " 
     781                                        <<      steps[i].mV0 
     782                                        <<      " V1: " 
     783                                        <<      steps[i].mV1 
     784                                        <<      endl; 
     785 
     786                //      Removed vertex. 
     787                while ((lb1 != ub1) && !edge_found) 
     788                { 
     789                        //      Real index. 
     790                        v1      =       (*lb1).second; 
     791 
     792                        lv1     =       edgesAdjToVertex(mesh,v1,&num_edges); 
     793 
     794                        //      Edje iterator. 
     795                        edge    =       0; 
     796 
     797                        while   ((edge < num_edges) &&  !edge_found) 
     798                        { 
     799                                econ    =       &mesh->edges[lv1[edge]]; 
     800 
     801                                //      Begin of iteration v0. 
     802                                it0     =       lb0; 
     803 
     804                                //      Remaining vertex. 
     805                                while ((it0 != ub0) &&  !edge_found) 
     806                                { 
     807                                        //      Real index. 
     808                                        v0      =       (*it0).second; 
     809                                         
     810                                        if (compareVertices(mesh->vertices,econ->v,v0)) 
     811                                        { 
     812                                                c = newChange(mesh, econ->u, econ->v); 
     813 
     814                                                edge_found      =       true; 
     815                                        } 
     816                                        else if (compareVertices(mesh->vertices,econ->u,v0)) 
     817                                        { 
     818                                                c = newChange(mesh, econ->v, econ->u); 
     819 
     820                                                edge_found      =       true; 
     821                                        } 
     822                                        else 
     823                                        { 
     824                                                it0++; 
     825                                        } 
     826                                } 
     827 
     828                                edge++; 
     829                        } 
     830 
     831                        lb1++; 
     832                } 
     833 
     834                if (edge_found) 
     835                { 
     836                        //      Debug. 
     837                        cout    <<      "Contracting edge of the initial mesh..."        
     838                                                <<      endl 
     839                                                <<      "u: " 
     840                                                <<      c->u 
     841                                                <<      " v: " 
     842                                                <<      c->v 
     843                                                <<      endl; 
     844         
     845                        // Collapse new edge. 
     846                        doChange(mesh, c); // the mesh has been updated. 
     847 
     848                        // Write Simplification sequence. 
     849                        saveSimplificationSequence(c,0); 
     850 
     851                        deleteVertexOfMap(mesh, c->u); 
     852                        deleteEdges(mesh, c); 
     853                        modifyEdges(mesh, c); 
     854                        deleteChange(c); 
     855 
     856                        //      Contract twin vertices. 
     857                        contractTwinVertices(mesh,v1,v0); 
     858                } 
     859        } 
     860} 
     861 
     862//------------------------------------------------------------------------- 
     863//      Find twin vertices and contract them. 
     864//------------------------------------------------------------------------- 
     865void VMI::contractTwinVertices( Mesh    *mesh, 
     866                                                                                                                                int             u, 
     867                                                                                                                                int             v) 
     868{ 
     869        bool                                    twin_found; 
     870        int                                             edge; 
     871        int                                             lonely_vert; 
     872        int                                             new_vert; 
     873        t_map_str                       lb; 
     874        t_map_str                       ub; 
     875        t_map_str                       it; 
     876        _float3_                        fu; 
     877        _float3_                        fv; 
     878        Edge                                    *econ; 
     879        float                                   x,y,z; 
     880        int                                             *le; 
     881        int                                             num_edges; 
     882        Change                          *c; 
     883 
     884        Geometry::GeoVertex     vertex_added; 
     885 
     886        if (!compareVertices(mesh->vertices,u,v)) 
     887        { 
     888                //take_bone_from_vert = v; 
     889 
     890                fu      =       _float3_(       mesh->vertices[u].x, 
     891                                                                                mesh->vertices[u].y, 
     892                                                                                mesh->vertices[u].z); 
     893 
     894                fv      =       _float3_(       mesh->vertices[v].x, 
     895                                                                                mesh->vertices[v].y, 
     896                                                                                mesh->vertices[v].z); 
     897 
     898                //      Find vertices width u coordinates. 
     899                while ((it = mVertexMap.find(fu)) != mVertexMap.end()) 
     900                { 
     901                        twin_found      =       false; 
     902 
     903                        lonely_vert     =       (*it).second; 
     904 
     905                        le      =       edgesAdjToVertex(mesh,lonely_vert,&num_edges); 
     906 
     907                        //      Find an edge width v coordinates. 
     908                        int     i       =       0; 
     909 
     910                        while((i < num_edges) && !twin_found) 
     911                        { 
     912                                econ    =       &mesh->edges[le[i]]; 
     913 
     914                                if (compareVertices(mesh->vertices,econ->u,v) 
     915                                                || 
     916                                                compareVertices(mesh->vertices,econ->v,v)) 
     917                                { 
     918                                        lb      =       mVertexMap.lower_bound(fv); 
     919                                        ub      =       mVertexMap.upper_bound(fv); 
     920 
     921                                        //      For each vertex. 
     922                                        while   (lb != ub) 
     923                                        { 
     924                                                //      If removed vertex is found. 
     925                                                if (((*lb).second == econ->u) 
     926                                                                || 
     927                                                                ((*lb).second == econ->v)) 
     928                                                { 
     929                                                        twin_found      =       true; 
     930 
     931                                                        //      Break while. 
     932                                                        lb      =       ub; 
     933                                                } 
     934                                                else 
     935                                                { 
     936                                                        //      Next iteration. 
     937                                                        lb++; 
     938                                                } 
     939                                        } 
     940                                } 
     941                                i++; 
     942                        } 
     943 
     944                        //      If a twin edge has been found. 
     945                        if (twin_found) 
     946                        { 
     947                                //      Debug. 
     948                                cout    <<      "Twin Collapsed..."     <<      endl; 
     949 
     950                                //      Compare vertices coordinates. 
     951                                if (compareVertices(mesh->vertices,econ->u,v)) 
     952                                { 
     953                                        // New edge for the change 
     954                                        c = newChange(mesh, econ->v, econ->u); 
     955 
     956                                        //      Debug. 
     957                                        cout    <<      "--Reverse--"   <<      endl; 
     958                                } 
     959                                else 
     960                                { 
     961                                        // New edge for the change 
     962                                        c = newChange (mesh, econ->u, econ->v); 
     963                                } 
     964 
     965                                // Collapse new edge. 
     966                                doChange(mesh, c); // the mesh has been updated. 
     967 
     968                                // Write Simplification sequence. 
     969                                saveSimplificationSequence(c,1); 
     970 
     971                                deleteVertexOfMap(mesh, c->u); 
     972                                deleteEdges(mesh, c); 
     973                                modifyEdges(mesh, c); 
     974                                deleteChange(c); 
     975                        } 
     976                        else 
     977                        { 
     978                                //      Debug. 
     979                                cout    <<      "Collapsing new edge..."        <<      endl; 
     980 
     981                                x       =       mesh->vertices[v].x; 
     982                                y       =       mesh->vertices[v].y; 
     983                                z       =       mesh->vertices[v].z; 
     984 
     985                                mesh->vertices = addVertex(     mesh->vertices, 
     986                                                                                                                                                (int *)&mesh->numVertices, 
     987                                                                                                                                                x, 
     988                                                                                                                                                y, 
     989                                                                                                                                                z, 
     990                                                                                                                                                &new_vert); 
     991                                 
     992                                // When a new vertex is added to the mesh, not only the 
     993                                // total number of vertices is increased but also current number 
     994                                mesh->currentNumVertices++; 
     995 
     996                                //      Adds new vertex to multimap. 
     997                                mVertexMap.insert(t_pair(_float3_(x,y,z),new_vert)); 
     998 
     999                                //      Creates new edge. 
     1000                                mesh->edges     =       addEdge(mesh->edges, 
     1001                                                                                                                        (int *)&mesh->numEdges, 
     1002                                                                                                                        lonely_vert, 
     1003                                                                                                                        new_vert, 
     1004                                                                                                                        &edge); 
     1005 
     1006                                /* 
     1007                                //      Debug. 
     1008                                cout    <<      "lonely_vert" 
     1009                                        <<      lonely_vert 
     1010                                        <<      "(" 
     1011                                        <<      mesh->vertices[lonely_vert].x 
     1012                                        <<      "," 
     1013                                        <<      mesh->vertices[lonely_vert].y 
     1014                                        <<      "," 
     1015                                        <<      mesh->vertices[lonely_vert].z 
     1016                                        <<      ")" 
     1017                                        <<      endl; 
     1018                                //      Debug. 
     1019                                cout    <<      "new_vert" 
     1020                                        <<      new_vert 
     1021                                        <<      "(" 
     1022                                        <<      mesh->vertices[new_vert].x 
     1023                                        <<      "," 
     1024                                        <<      mesh->vertices[new_vert].y 
     1025                                        <<      "," 
     1026                                        <<      mesh->vertices[new_vert].z 
     1027                                        <<      ")" 
     1028                                        <<      endl; 
     1029                                */ 
     1030 
     1031                                //      We assume here there are the same number of vertices 
     1032                                //      and texture coordinates and normals. 
     1033 
     1034                                //      Assigns the position of the vertex. 
     1035                                vPositions.push_back(Geometry::Vector3(x,y,z)); 
     1036 
     1037                                //      Assigns a texture coordinate for the vertex. 
     1038                                vTexCoords.push_back(vTexCoords[lonely_vert]); 
     1039 
     1040                                //      Assigns a normal coordinate for the vertex. 
     1041                                vNormals.push_back(vNormals[lonely_vert]); 
     1042 
     1043                                //      Adds new vertex information to simplification sequence. 
     1044                                vertex_added.id                         =       new_vert; 
     1045                                vertex_added.bonefrom   =       v; 
     1046 
     1047                                vertex_added.position   =       vPositions[new_vert]; 
     1048 
     1049                                vertex_added.texcoord   =       vTexCoords[new_vert]; 
     1050 
     1051                                vertex_added.normal     =       vNormals[new_vert]; 
     1052 
     1053                                mSequence->mNewVertices.push_back(vertex_added); 
     1054 
     1055                                // Collapse new edge 
     1056                                c = newChange(mesh, lonely_vert, new_vert); 
     1057 
     1058                                doChange(mesh, c); // the mesh has been updated 
     1059 
     1060                                // Write Simplification sequence. 
     1061                                saveSimplificationSequence(c,1); 
     1062 
     1063                                deleteVertexOfMap(mesh, c->u); 
     1064                                deleteEdges(mesh, c); 
     1065                                modifyEdges(mesh, c); 
     1066                                deleteChange(c); 
     1067                        } 
     1068                } 
     1069        } 
     1070} 
     1071 
  • GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshView.h

    r1549 r2090  
    3434        bool            mWire; 
    3535        bool            mSolid; 
     36        bool            mLighting; 
    3637        bool            mCW; 
    3738        bool            mCCW; 
     
    9596        void    activeSolid(){mSolid    =       true;}; 
    9697        void    deactiveSolid(){mSolid  =       false;}; 
     98 
     99        //      Lighting. 
     100        void    activeLighting(){mLighting      =       true;}; 
     101        void    deactiveLighting(){mLighting    =       false;}; 
    97102 
    98103        //      Clockwise mode. 
  • GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshViewUI.h

    r1554 r2090  
    8888using   namespace       std; 
    8989 
     90//----------------------------------------------------------------------------- 
     91//----------------------------------------------------------------------------- 
    9092class GeoToolIndexData : public Geometry::IndexData 
    9193{ 
     
    131133}; 
    132134 
     135//----------------------------------------------------------------------------- 
     136//      Class User Interface of GeoTool. 
     137//----------------------------------------------------------------------------- 
    133138class GeoMeshViewUI 
    134139{ 
     
    198203        inline void cb_menuRenderSolid_i(fltk::Item*, void*); 
    199204        static void cb_menuRenderSolid(fltk::Item*, void*); 
     205        inline void cb_menuRenderLighting_i(fltk::Item*, void*); 
     206        static void cb_menuRenderLighting(fltk::Item*, void*); 
    200207        inline void cb_menuRenderCW_i(fltk::Item*, void*); 
    201208        static void cb_menuRenderCW(fltk::Item*, void*); 
     
    361368        fltk::Item                                      *menuRenderWire; 
    362369        fltk::Item                                      *menuRenderSolid; 
     370        fltk::Item                                      *menuRenderLighting; 
    363371        fltk::Item                                      *menuRenderCW; 
    364372        fltk::Item                                      *menuRenderCCW; 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp

    r1554 r2090  
    66 
    77//--------------------------------------------------------------------------- 
    8 //      Hanle events. 
     8//      Handle events. 
    99//--------------------------------------------------------------------------- 
    1010int     GeoMeshView::handle(int event) 
     
    4646                                                if (mPan) 
    4747                                                { 
    48                                                         xshift  =       xshift  +       (x      -       mMouseX); 
     48                                                        xshift  =       xshift  +       0.01; 
    4949                                                } 
    5050                                                else 
     
    5959                                                        if (mPan) 
    6060                                                        { 
    61                                                                 xshift  =       xshift  -       (mMouseX        -       x); 
     61                                                                xshift  =       xshift  -       0.01; 
    6262                                                        } 
    6363                                                        else 
     
    7272                                                if (mPan) 
    7373                                                { 
    74                                                         yshift  =       yshift  -       (y - mMouseY); 
     74                                                        yshift  =       yshift  -       0.01; 
    7575                                                } 
    7676                                                else 
     
    8585                                                        if (mPan) 
    8686                                                        { 
    87                                                                 yshift  =       yshift  +       (mMouseY        -       y); 
     87                                                                yshift  =       yshift  +       0.01; 
    8888                                                        } 
    8989                                                        else 
     
    884884                        geosubmesh->mIndexCount, 
    885885                        GL_UNSIGNED_INT, 
     886 
    886887                        mIndexArray[submesh]); 
    887888 
     
    11461147        glLoadIdentity(); 
    11471148 
    1148         glEnable(GL_LIGHTING); 
    1149  
    11501149        //      Frustrum. 
    11511150        glViewport(0,0,w(),h()); 
     
    12131212        { 
    12141213                enableColorStrips(); 
    1215                 //glDisable(GL_LIGHTING); 
    12161214                glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 
    12171215                drawGeoMesh(false); 
    12181216        } 
     1217 
     1218        if (mLighting) 
     1219        { 
     1220                glEnable(GL_LIGHTING); 
     1221        } 
    12191222        else 
    12201223        { 
    1221                 glEnable(GL_LIGHTING); 
     1224                glDisable(GL_LIGHTING); 
    12221225        } 
    12231226 
     
    12251228        { 
    12261229                disableColorStrips(); 
    1227  
    1228                 //glDisable(GL_LIGHTING); 
    12291230 
    12301231                GLfloat color[4]; 
     
    12571258                { 
    12581259                        disableColorStrips(); 
    1259                         //glEnable(GL_LIGHTING); 
    12601260                        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
    12611261                        drawGeoMesh(false); 
     
    12791279        current_texture = ilutGLLoadImage((const ILstring)imgfile); 
    12801280 
    1281         if (!current_texture) 
    1282         { 
    1283                 fltk::alert("Error loading texture!"); 
    1284         } 
     1281//      if (!current_texture) 
     1282//      { 
     1283//              fltk::alert("Error loading texture!"); 
     1284//      } 
    12851285 
    12861286        ilShutDown(); 
     
    12951295        current_texture_submesh[isubmesh] = ilutGLLoadImage((const ILstring)imgfile); 
    12961296 
    1297         if (!current_texture_submesh[isubmesh]) 
    1298         { 
    1299                 fltk::alert("Error loading texture!"); 
    1300         } 
     1297//      if (!current_texture_submesh[isubmesh]) 
     1298//      { 
     1299//              fltk::alert("Error loading texture!"); 
     1300//      } 
    13011301 
    13021302        ilShutDown(); 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp

    r1560 r2090  
    44#include "resource.h" 
    55#include "GeoLodTreeConstructor.h" 
     6#include <string.h> 
    67 
    78using   namespace       Geometry; 
    89using   namespace       std; 
    910 
    10 //--------------------------------------------------------------------------- 
     11//------------------------------------------------------------------------- 
    1112//      Menu File Open Callback 
    12 //--------------------------------------------------------------------------- 
     13//------------------------------------------------------------------------- 
    1314inline void GeoMeshViewUI::cb_menuFileOpen_i(fltk::Item*, void*) 
    1415{ 
     
    101102 
    102103 
    103 //--------------------------------------------------------------------------- 
     104//------------------------------------------------------------------------- 
    104105//      Repaint the FPS label. 
    105 //--------------------------------------------------------------------------- 
     106//------------------------------------------------------------------------- 
    106107void    GeoMeshViewUI::refreshFPS(int fps) 
    107108{ 
     
    124125} 
    125126 
    126 //--------------------------------------------------------------------------- 
     127//------------------------------------------------------------------------- 
    127128//      Save callback 
    128 //--------------------------------------------------------------------------- 
     129//------------------------------------------------------------------------- 
    129130inline void GeoMeshViewUI::cb_menuFileSave_i(fltk::Item*, void*) 
    130131{ 
     
    152153} 
    153154 
    154 //--------------------------------------------------------------------------- 
     155//------------------------------------------------------------------------- 
    155156//      Save As Callback 
    156 //--------------------------------------------------------------------------- 
     157//------------------------------------------------------------------------- 
    157158inline void GeoMeshViewUI::cb_menuFileSaveAs_i(fltk::Item*, void*) 
    158159{ 
     
    215216                                //------------------------------------- 
    216217 
    217                                 mesh_saver->save(mGeoMesh,filename_name(file_name)); 
     218                                mesh_saver->save(mGeoMesh,file_name); 
    218219 
    219220                                delete  mesh_saver; 
     
    234235} 
    235236 
    236 //--------------------------------------------------------------------------- 
     237//------------------------------------------------------------------------- 
    237238//      Mesh info callback 
    238 //--------------------------------------------------------------------------- 
     239//------------------------------------------------------------------------- 
    239240inline void GeoMeshViewUI::cb_menuMeshInfo_i(fltk::Item*, void*) 
    240241{ 
     
    253254} 
    254255 
    255 //--------------------------------------------------------------------------- 
     256//------------------------------------------------------------------------- 
    256257//      Mesh Export to OBJ callback 
    257 //--------------------------------------------------------------------------- 
     258//------------------------------------------------------------------------- 
    258259inline void GeoMeshViewUI::cb_menuMeshExportOBJ_i(fltk::Item*, void*) 
    259260{ 
     
    278279} 
    279280 
    280 //--------------------------------------------------------------------------- 
     281//------------------------------------------------------------------------- 
    281282//      Transform to Shared Vertex callback 
    282 //--------------------------------------------------------------------------- 
     283//------------------------------------------------------------------------- 
    283284inline void GeoMeshViewUI::cb_menuTransformSharedVertex_i(fltk::Item*, void*) 
    284285{ 
     
    323324} 
    324325 
    325 //--------------------------------------------------------------------------- 
     326//------------------------------------------------------------------------- 
    326327//      Quit Callback 
    327 //--------------------------------------------------------------------------- 
     328//------------------------------------------------------------------------- 
    328329inline void GeoMeshViewUI::cb_menuFileQuit_i(fltk::Item*, void*) 
    329330{ 
     
    338339} 
    339340 
    340 //--------------------------------------------------------------------------- 
     341//------------------------------------------------------------------------- 
    341342//      Undo Callback 
    342 //--------------------------------------------------------------------------- 
     343//------------------------------------------------------------------------- 
    343344inline void GeoMeshViewUI::cb_menuEditUndo_i(fltk::Item*, void*) 
    344345{ 
     
    354355} 
    355356 
    356 //--------------------------------------------------------------------------- 
     357//------------------------------------------------------------------------- 
    357358//      Fit Callback 
    358 //--------------------------------------------------------------------------- 
     359//------------------------------------------------------------------------- 
    359360inline void GeoMeshViewUI::cb_menuEditFit_i(fltk::Item*, void*) 
    360361{ 
     
    370371} 
    371372 
    372 //--------------------------------------------------------------------------- 
     373//------------------------------------------------------------------------- 
    373374//      Rotate Callback 
    374 //--------------------------------------------------------------------------- 
     375//------------------------------------------------------------------------- 
    375376inline void GeoMeshViewUI::cb_menuEditRotate_i(fltk::Item       *item, void*) 
    376377{        
     
    402403} 
    403404 
    404 //--------------------------------------------------------------------------- 
     405//------------------------------------------------------------------------- 
    405406//      Pan Callback 
    406 //--------------------------------------------------------------------------- 
     407//------------------------------------------------------------------------- 
    407408inline void GeoMeshViewUI::cb_menuEditPan_i(fltk::Item  *item, void*) 
    408409{        
     
    434435} 
    435436 
    436 //--------------------------------------------------------------------------- 
     437//------------------------------------------------------------------------- 
    437438//      Zoom Callback 
    438 //--------------------------------------------------------------------------- 
     439//------------------------------------------------------------------------- 
    439440inline void GeoMeshViewUI::cb_menuEditZoom_i(fltk::Item*, void*) 
    440441{ 
     
    448449} 
    449450 
    450 //--------------------------------------------------------------------------- 
     451//------------------------------------------------------------------------- 
    451452//      Wire Callback 
    452 //--------------------------------------------------------------------------- 
     453//------------------------------------------------------------------------- 
    453454inline void GeoMeshViewUI::cb_menuRenderWire_i(fltk::Item *item, void*) 
    454455{ 
     
    476477} 
    477478 
    478 //--------------------------------------------------------------------------- 
     479//------------------------------------------------------------------------- 
    479480//      Solid Callback 
    480 //--------------------------------------------------------------------------- 
     481//------------------------------------------------------------------------- 
    481482inline void GeoMeshViewUI::cb_menuRenderSolid_i(fltk::Item      *item, void*) 
    482483{ 
     
    504505} 
    505506 
    506 //--------------------------------------------------------------------------- 
     507//------------------------------------------------------------------------- 
     508//      Lighting Callback 
     509//------------------------------------------------------------------------- 
     510inline void GeoMeshViewUI::cb_menuRenderLighting_i(fltk::Item   *item, void*) 
     511{ 
     512        if (item->value()) 
     513        { 
     514                geoMeshView->activeLighting(); 
     515        } 
     516        else 
     517        { 
     518                geoMeshView->deactiveLighting(); 
     519        } 
     520                                                                         
     521        //      Repaint the main window. 
     522        mMainWindow->redraw(); 
     523} 
     524 
     525void GeoMeshViewUI::cb_menuRenderLighting(fltk::Item* o, void* v) 
     526{ 
     527  ((GeoMeshViewUI*)     (o->parent()->parent()->parent()->user_data())) 
     528                                                                                -> 
     529                                                                                cb_menuRenderLighting_i(o,v); 
     530} 
     531 
     532//------------------------------------------------------------------------- 
    507533//      CW callback 
    508 //--------------------------------------------------------------------------- 
     534//------------------------------------------------------------------------- 
    509535inline void GeoMeshViewUI::cb_menuRenderCW_i(fltk::Item *item, void*) 
    510536{ 
     
    534560} 
    535561 
    536 //--------------------------------------------------------------------------- 
     562//------------------------------------------------------------------------- 
    537563//      CCW callback 
    538 //--------------------------------------------------------------------------- 
     564//------------------------------------------------------------------------- 
    539565inline void GeoMeshViewUI::cb_menuRenderCCW_i(fltk::Item        *item, void*) 
    540566{ 
     
    564590} 
    565591 
    566 //--------------------------------------------------------------------------- 
     592//------------------------------------------------------------------------- 
    567593//      Flat callback 
    568 //--------------------------------------------------------------------------- 
     594//------------------------------------------------------------------------- 
    569595inline void GeoMeshViewUI::cb_menuRenderFlat_i(fltk::Item*, void*) 
    570596{ 
     
    586612} 
    587613 
    588 //--------------------------------------------------------------------------- 
     614//------------------------------------------------------------------------- 
    589615//      Smooth Callback 
    590 //--------------------------------------------------------------------------- 
     616//------------------------------------------------------------------------- 
    591617inline void GeoMeshViewUI::cb_menuRenderSmooth_i(fltk::Item*, void*) 
    592618{ 
     
    608634} 
    609635 
    610 //--------------------------------------------------------------------------- 
     636//------------------------------------------------------------------------- 
    611637//      Textures callback 
    612 //--------------------------------------------------------------------------- 
     638//------------------------------------------------------------------------- 
    613639inline void GeoMeshViewUI::cb_menuRenderTextures_i(fltk::Item*, void*) 
    614640{ 
     
    628654} 
    629655 
    630 //--------------------------------------------------------------------------- 
     656//------------------------------------------------------------------------- 
    631657//      Stripify Callback 
    632 //--------------------------------------------------------------------------- 
     658//------------------------------------------------------------------------- 
    633659inline void GeoMeshViewUI::cb_menuStripify_i(fltk::Item*, void*) 
    634660{ 
     
    657683} 
    658684 
    659 //--------------------------------------------------------------------------- 
     685//------------------------------------------------------------------------- 
    660686//      Simplify Callback 
    661 //--------------------------------------------------------------------------- 
     687//------------------------------------------------------------------------- 
    662688inline void GeoMeshViewUI::cb_menuSimplify_i(fltk::ItemGroup*, void*) 
    663689{ 
     
    671697} 
    672698 
    673 //--------------------------------------------------------------------------- 
     699//------------------------------------------------------------------------- 
    674700//      Edge collapse Callback 
    675 //--------------------------------------------------------------------------- 
     701//------------------------------------------------------------------------- 
    676702inline void GeoMeshViewUI::cb_menuSimplifyEdgeCollapse_i(fltk::Item*, void*) 
    677703{ 
     
    701727} 
    702728 
    703 //--------------------------------------------------------------------------- 
     729//------------------------------------------------------------------------- 
    704730//      Leaves collapse Callback 
    705 //--------------------------------------------------------------------------- 
     731//------------------------------------------------------------------------- 
    706732inline void GeoMeshViewUI::cb_menuSimplifyLeavesCollapse_i(fltk::Item*, void*) 
    707733{ 
     
    730756} 
    731757 
    732 //--------------------------------------------------------------------------- 
     758//------------------------------------------------------------------------- 
    733759//      Tree select leaves simplification Callback 
    734 //--------------------------------------------------------------------------- 
     760//------------------------------------------------------------------------- 
    735761inline void GeoMeshViewUI::cb_menuSelectLeaves_i(fltk::Item*, void*) 
    736762{ 
     
    751777} 
    752778 
    753 //--------------------------------------------------------------------------- 
     779//------------------------------------------------------------------------- 
    754780//      Auto Generate LodStrips Callback 
    755 //--------------------------------------------------------------------------- 
     781//------------------------------------------------------------------------- 
    756782inline void GeoMeshViewUI::cb_menuLodStripsGenerate_i(fltk::Item*, void*) 
    757783{ 
     
    781807} 
    782808 
    783 //--------------------------------------------------------------------------- 
     809//------------------------------------------------------------------------- 
    784810//      Auto Generate LodStrips Callback 
    785 //--------------------------------------------------------------------------- 
     811//------------------------------------------------------------------------- 
    786812inline void GeoMeshViewUI::cb_menuLodTreesGenerate_i(fltk::Item*, void*) 
    787813{ 
     
    812838 
    813839 
    814 //--------------------------------------------------------------------------- 
     840//------------------------------------------------------------------------- 
    815841//      Visualize LodStrips Callback 
    816 //--------------------------------------------------------------------------- 
     842//------------------------------------------------------------------------- 
    817843inline void GeoMeshViewUI::cb_menuLodStripsVisualize_i(fltk::Item*, void*) 
    818844{ 
     
    874900                if (geoMeshLoader->GetTreeSimpSeq() && geoMeshLoader->GetLodStripsData()) 
    875901                { 
    876 /*                      // select the first triangle-list submesh as leaves submesh 
    877                         int leafsSubMeshID = -1; 
    878  
    879                         for (int i=0; i<mGeoMesh->mSubMeshCount; i++) 
    880                         { 
    881                                 if (mGeoMesh->mSubMesh[i].mType==GEO_TRIANGLE_LIST) 
    882                                 { 
    883                                         leafsSubMeshID=i; 
    884                                         break; 
    885                                 } 
    886                         }*/ 
    887  
    888                         setLodTreesLibrary(geoMeshLoader->GetLodStripsData(), geoMeshLoader->GetTreeSimpSeq(), mGeoMesh/*, leafsSubMeshID*/); 
     902                        setLodTreesLibrary(     geoMeshLoader->GetLodStripsData(), 
     903                                                                                                        geoMeshLoader->GetTreeSimpSeq(), 
     904                                                                                                        mGeoMesh); 
    889905 
    890906                        //      Sets the aplication mode. 
     
    923939} 
    924940 
    925 //--------------------------------------------------------------------------- 
     941//------------------------------------------------------------------------- 
    926942//      Open LodStrip trunk Callback 
    927 //--------------------------------------------------------------------------- 
     943//------------------------------------------------------------------------- 
    928944inline void GeoMeshViewUI::cb_menuLodTreesOpenLodStripTrunk_i(fltk::Item*, void*) 
    929945{ 
     
    937953} 
    938954 
    939 //--------------------------------------------------------------------------- 
     955//------------------------------------------------------------------------- 
    940956//      Open leaves simplification Callback 
    941 //--------------------------------------------------------------------------- 
     957//------------------------------------------------------------------------- 
    942958inline void GeoMeshViewUI::cb_menuLodTreesOpenLeavesSimplification_i(fltk::Item*, void*) 
    943959{ 
     
    964980 
    965981 
    966 //--------------------------------------------------------------------------- 
     982//------------------------------------------------------------------------- 
    967983//      About Callback 
    968 //--------------------------------------------------------------------------- 
     984//------------------------------------------------------------------------- 
    969985inline void GeoMeshViewUI::cb_menuHelpAbout_i(fltk::Item*, void*) 
    970986{ 
     
    983999Index *orig_indices                                     =       NULL; 
    9841000 
    985 //--------------------------------------------------------------------------- 
     1001//------------------------------------------------------------------------- 
    9861002//      Button Process Callback 
    987 //--------------------------------------------------------------------------- 
     1003//------------------------------------------------------------------------- 
    9881004inline void GeoMeshViewUI::cb_mButtonProcess_i(fltk::Button*, void*) 
    9891005{ 
     
    10431059                                        mGeoMesh        =       mesh_aux; 
    10441060 
    1045                                         // Visualize mesh. 
    1046                                         geoMeshView->setMesh(mGeoMesh); 
    1047  
    10481061                                        //      Simplify the mesh object. 
    10491062                                        if(simplifyEdgeCollapse()) 
     
    10511064                                                geoMeshView->restoreContext(); 
    10521065                                        } 
     1066 
     1067                                        // Visualize mesh. 
     1068                                        geoMeshView->setMesh(mGeoMesh); 
     1069 
    10531070                                } 
    10541071                                break; 
     
    10741091                                else 
    10751092                                { 
    1076                                         origSubMeshVB=mGeoMesh->mSubMesh[idMeshLeaves].mVertexBuffer->Clone(); 
    1077                                         orig_numindices=mGeoMesh->mSubMesh[idMeshLeaves].mIndexCount; 
    1078                                         orig_indices=new Index[orig_numindices]; 
    1079                                         for (int i=0; i<orig_numindices; i++) 
     1093                                        origSubMeshVB   =       mGeoMesh-> 
     1094                                                                                                                mSubMesh[idMeshLeaves].mVertexBuffer->Clone(); 
     1095 
     1096                                        orig_numindices =       mGeoMesh->mSubMesh[idMeshLeaves].mIndexCount; 
     1097                                        orig_indices            =       new Index[orig_numindices]; 
     1098 
     1099                                        for (int i = 0; i < orig_numindices; i++) 
     1100                                        { 
    10801101                                                orig_indices[i]=mGeoMesh->mSubMesh[idMeshLeaves].mIndex[i]; 
     1102                                        } 
    10811103 
    10821104                                        std::cout << "Simplificando hojas..."; 
     
    11021124                                        //      Gets the mesh Shared Vertex. 
    11031125                                        mGeoMesh        =       mesh_aux; 
    1104  
    1105                                         geoMeshView->setMesh(mGeoMesh); 
    11061126 
    11071127                                        //      Simplify the mesh object. 
     
    11151135                                        } 
    11161136 
     1137                                        geoMeshView->setMesh(mGeoMesh); 
    11171138                                } 
    11181139                                 
     
    11471168                                        mGeoMesh        =       mesh_aux; 
    11481169 
    1149                                         // Visualize mesh. 
    1150                                         geoMeshView->setMesh(mGeoMesh); 
    1151  
    11521170                                        //      Simplify the mesh object. 
    11531171                                        if (simplifyEdgeCollapse()) 
     
    11591177                                                activeBuildProcess(); 
    11601178                                        } 
     1179 
     1180                                        // Visualize mesh. 
     1181                                        geoMeshView->setMesh(mGeoMesh); 
    11611182                                } 
    11621183 
     
    12591280                                        delete mUndoMesh; 
    12601281 
     1282 
    12611283                                        mUndoMesh       =       new Mesh(); 
    12621284 
     
    14541476        mViewPointDriven->set_visible(); 
    14551477        mViewPointDriven->activate(); 
     1478        mViewPointDriven->clear(); 
    14561479 
    14571480        /* 
     
    14721495        mVerticesNumber->set_visible(); 
    14731496        mVerticesNumber->activate(); 
     1497        mVerticesNumber->clear(); 
    14741498 
    14751499        mMeshReduction->set_visible(); 
     1500        mMeshReduction->value(100); 
    14761501 
    14771502        // Allows floating point. 
     
    16581683 
    16591684        //      Deactive VMI option. 
    1660         mViewPointDriven->deactivate(); 
     1685        //mViewPointDriven->deactivate(); 
    16611686 
    16621687        mButtonBuild->set_visible(); 
     
    17451770} 
    17461771 
    1747 //--------------------------------------------------------------------------- 
     1772//-------------------------------------------------------------------------- 
    17481773//      Show the mesh info browser. 
    1749 //--------------------------------------------------------------------------- 
     1774//-------------------------------------------------------------------------- 
    17501775void    GeoMeshViewUI::showMeshInfo() 
    17511776{ 
    1752         char    type[10]; 
     1777        char                                            type[10]; 
     1778        unsigned        int             group_index; 
     1779        unsigned        int             group_count; 
     1780        unsigned        int             bone_count; 
     1781        fltk::ItemGroup **info_group; 
     1782         
     1783        group_index     =       0; 
    17531784         
    17541785        if (mGeoMesh) 
     
    17591790                ogeometry->begin(); 
    17601791 
    1761                 fltk::ItemGroup **oprueba; 
    1762                 oprueba=new fltk::ItemGroup*[mGeoMesh->mSubMeshCount]; 
     1792                group_count     =       mGeoMesh->mSubMeshCount; 
     1793 
     1794                //      Add one group for skeleton info. 
     1795                if (mGeoMesh->hasSkeleton) 
     1796                { 
     1797                        group_count++; 
     1798                } 
     1799 
     1800                info_group      =       new fltk::ItemGroup*[group_count]; 
     1801 
     1802                //      Write skeleton info. 
     1803                if (mGeoMesh->hasSkeleton) 
     1804                { 
     1805                        char    *group_name             =       new char[256]; 
     1806                        char    *skel_name              =       new char[256]; 
     1807                        char    *bone_assig             =       new char[256]; 
     1808                        sprintf(group_name,"Skeleton"); 
     1809                        info_group[group_index] = new fltk::ItemGroup(group_name); 
     1810 
     1811                        info_group[group_index]->begin(); 
     1812                        sprintf(skel_name,"Name: %s",mGeoMesh->mSkeletonName); 
     1813                        new fltk::Item(skel_name); 
     1814                        bone_count      =       mGeoMesh->mBones.size(); 
     1815                         
     1816                        for (int i      =       0;      i < mGeoMesh->mSubMeshCount;    i++) 
     1817                        { 
     1818                                bone_count      +=      mGeoMesh->mSubMesh[i].mBones.size(); 
     1819                        } 
     1820                        sprintf(bone_assig,"Bone assignamets: %d",bone_count); 
     1821                        new fltk::Item(bone_assig); 
     1822                        info_group[group_index]->end(); 
     1823 
     1824                        group_index++; 
     1825                } 
     1826 
    17631827                for(int i=0; i<mGeoMesh->mSubMeshCount;i++) 
    17641828                { 
    1765                         char *cadena=new char[256]; 
     1829                        char    *group_name     =       new char[256]; 
    17661830 
    17671831                        if (geoMeshView->getLeavesSubMesh() >= 0) 
     
    17821846 
    17831847                        //      Submesh identifier. 
    1784                         sprintf(cadena,"SubMesh %d %s",i,type); 
     1848                        sprintf(group_name,"SubMesh %d %s",i,type); 
    17851849                         
    1786                         oprueba[i] = new fltk::ItemGroup(cadena); 
    1787                         oprueba[i]->begin(); 
     1850                        info_group[group_index] = new fltk::ItemGroup(group_name); 
     1851                        info_group[group_index]->begin(); 
    17881852                        fltk::Item *sharedGeometry; 
    17891853                        if (mGeoMesh->mSubMesh[i].mSharedVertexBuffer) 
     
    18381902 
    18391903 
    1840                         oprueba[i]->end(); 
     1904                        info_group[group_index]->end(); 
    18411905                } 
    18421906                ogeometry->end(); 
     
    18511915} 
    18521916 
    1853 //--------------------------------------------------------------------------- 
     1917//-------------------------------------------------------------------------- 
    18541918//      Hide the mesh info browser. 
    1855 //--------------------------------------------------------------------------- 
     1919//-------------------------------------------------------------------------- 
    18561920void    GeoMeshViewUI::hideMeshInfo() 
    18571921{ 
     
    18601924} 
    18611925 
    1862 //--------------------------------------------------------------------------- 
     1926//-------------------------------------------------------------------------- 
    18631927//      Hide the right panel. 
    1864 //--------------------------------------------------------------------------- 
     1928//-------------------------------------------------------------------------- 
    18651929void    GeoMeshViewUI::hideRightPanel() 
    18661930{ 
     
    18751939} 
    18761940 
    1877 //--------------------------------------------------------------------------- 
     1941//-------------------------------------------------------------------------- 
    18781942//      Get the number of vertices. 
    1879 //--------------------------------------------------------------------------- 
     1943//-------------------------------------------------------------------------- 
    18801944size_t  GeoMeshViewUI::getVertexCount(Mesh      *geoMesh) 
    18811945{ 
     
    20132077        } 
    20142078 
     2079        //      Saves OpenGL contex. 
    20152080        geoMeshView->saveContext(); 
    20162081 
     
    20462111 
    20472112                        //      Simplifica el geomesh -> Parámetro es un factor LOD [0,1]. 
     2113 
    20482114                        mMeshSimplifier->Simplify(percent); 
    20492115 
     
    20592125 
    20602126                        mGeoMesh        =       mMeshSimplifier->GetMesh(); 
    2061  
    2062                         //      Visualize mesh. 
    2063                         geoMeshView->setMesh(mGeoMesh); 
    20642127                } 
    20652128                else 
     
    20902153 
    20912154                mGeoMesh        =       mMeshSimplifier->GetMesh(); 
    2092  
    2093                 //      Visualize the mesh. 
    2094                 geoMeshView->setMesh(mGeoMesh); 
    20952155        } 
    20962156 
     
    22632323void    GeoMeshViewUI::undo() 
    22642324{ 
     2325        Mesh    *aux_mesh; 
     2326 
    22652327        //      if the undo mesh is not initialized. 
    22662328        if      (mUndoMesh != NULL) 
    22672329        { 
    2268                 //      Deletes the actual mesh. 
    2269                 delete  mGeoMesh; 
    2270  
    2271                 mGeoMesh        =       new Mesh(); 
    2272  
    2273                 //      Restore the previous mesh. 
    2274                 *mGeoMesh       =       *mUndoMesh; 
     2330                aux_mesh        =       mGeoMesh; 
     2331                mGeoMesh        =       mUndoMesh; 
    22752332 
    22762333                //      Visualize the mesh. 
     
    22822339                //      Repaint the window. 
    22832340                mMainWindow->redraw(); 
     2341 
     2342                //      Deletes the actual mesh. 
     2343                delete  aux_mesh; 
     2344 
     2345                mUndoMesh       =       NULL; 
    22842346        } 
    22852347} 
     
    24662528                        menuRenderSolid->clear_value(); 
    24672529                        menuRenderWire->clear_value(); 
     2530                        menuRenderLighting->set_value(); 
    24682531                        geoMeshView->deactiveSolid(); 
    24692532                        geoMeshView->deactiveWire(); 
     2533                        geoMeshView->activeLighting(); 
    24702534 
    24712535                        //      Fit model in midle. 
     
    28082872 
    28092873                                { 
     2874                                        fltk::Item* o = new fltk::Item("Transform to SV"); 
     2875                                        o->callback((fltk::Callback*)cb_menuFileTransformSharedVertex); 
     2876                                } 
     2877 
     2878                                { 
    28102879                                        menuLoadTextures = new fltk::ItemGroup("Load Textures"); 
    28112880                                        o->add(menuLoadTextures); 
     
    28332902                                        fltk::Item* o = menuEditFit = new fltk::Item("Fit"); 
    28342903                                        o->callback((fltk::Callback*)cb_menuEditFit); 
    2835  
    28362904                                } 
    28372905 
     
    28792947                                        o->type(fltk::Item::RADIO); 
    28802948                                        o->callback((fltk::Callback*)cb_menuRenderSolid); 
     2949                                } 
     2950 
     2951                                { 
     2952                                        fltk::Item* o = menuRenderLighting = new fltk::Item("Lighting"); 
     2953                                        o->type(fltk::Item::RADIO); 
     2954                                        o->callback((fltk::Callback*)cb_menuRenderLighting); 
    28812955                                } 
    28822956 
Note: See TracChangeset for help on using the changeset viewer.