source: GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshSimplifier.h @ 2127

Revision 2127, 7.8 KB checked in by gumbau, 17 years ago (diff)
Line 
1#ifndef __GEO_MESH_SIMPLIFIER__
2#define __GEO_MESH_SIMPLIFIER__
3
4#include <map>
5#include        <math.h>
6#include        "GeoMesh.h"
7#include        "GeoMeshSimpSequence.h"
8#include        "vmi_simplifier.h"
9#include        "change.h"
10
11//#include "SimplificationMethod.h"
12
13using   namespace       Geometry;
14
15namespace Geometry
16{
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                        Mesh    *GetMesh();
93        };
94
95        /// Mesh simplificator interface.
96        /** 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
97
98Inputs:\n
99- A pointer to the Geometry::Mesh object containing the 3D model to be simplified.
100.
101
102Outputs:\n
103-# The simplified mesh, contained in a Geometry::Mesh object.
104-# Simplification sequence, represented by a Geometry::MeshSimplificationSequence object.
105*/
106
107        class MeshSimplifier
108        {
109                public:
110                        /// Class constructor. Retrieves a pointer to a valid Geometry::Mesh object to simplify.
111                        MeshSimplifier( const Geometry::Mesh    *,
112                                        Geometry::TIPOFUNC              upb=0);
113
114                        /// Virtual class destructor.
115                        virtual ~MeshSimplifier (void);
116
117                        /// Copy constructor
118                        //MeshSimplifier(const MeshSimplifier&);
119
120                        /// Assignment operator
121                        //MeshSimplifier& operator =(const MeshSimplifier&);
122
123                        /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. This is a pure virtual method and must be overloaded in a derived class that implements a simplification algorithm.
124                        virtual void Simplify(Geometry::Real)=0;
125
126                        /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. This is a pure virtual method and must be overloaded in a derived class that implements a simplification algorithm.
127                        virtual void Simplify(Geometry::uint32)=0;
128
129                        /// Returns the simplified mesh.
130                        Mesh *GetMesh();
131
132                        /// Returns the simplification sequence for general meshes.
133                        MeshSimplificationSequence *GetSimplificationSequence();
134
135                        // Sets what is the mesh that stores the leaves
136                        void setMeshLeaves(Geometry::Index);
137
138                protected:
139
140                        //private: // fer protected
141                        Mesh                                                                                            *mGeoMesh;
142                        Mesh                                                                                            *mInitialMesh;
143                        MeshSimplificationSequence      *msimpsequence;
144                        const Mesh                                                                      *objmesh;
145
146                        Geometry::Index indexMeshLeaves;
147
148                        //      Progress bar function.
149                        Geometry::TIPOFUNC      mUPB;
150
151                        //      Sort mesh bones.
152                        void    sortBones();
153        };
154
155        /// Implementation of a simplification algorithm based on viewpoint.
156        /** This class implements a simplification algorithm based on a viewpoint evaluation technique. */
157        class ViewPointDrivenSimplifier : public MeshSimplifier
158        {
159                private:
160
161                        //      Vectors of positions, normals and texture coordinates.
162                        vector<Vector3> vPositions;
163                        vector<Vector3> vNormals;
164                        vector<Vector2> vTexCoords;
165
166                        //      Auxiliar vertex buffer.
167                        Geometry::VertexBuffer  *mVB;
168
169                        //      Set of indices.
170                        map<int,int>    mIndexMap;
171
172                        //      Join and split vertices to matain texture aspect.
173                        TextureConserver        *mTexConserver;
174
175                        //      Loads a vmi mesh with a given geometry mesh.
176                        VMI::Mesh * initMeshStructure(Geometry::Mesh    *geoMesh);
177
178                        //      Loads a geometry mesh with a given vmi mesh.
179                        void    loadMesh();
180
181                        //      Find vertex in auxiliar vertex buffer.
182                        void    findVertex(size_t       submesh, size_t index);
183
184                        //      Gets the VMI mesh simplification sequence.
185                        void    GetMeshSimpSequence();
186
187                        //      Fill up vectors of positions, normals and texture coordinates.
188                        void    fillUpPosNorTC(Mesh     *geoMesh);
189
190                        //      Reassigns bones.
191                        void bonesReassignament();
192
193                public:
194
195                        /// Class constructor. Will call Simplifier class constructor.
196                        ViewPointDrivenSimplifier(      const Geometry::Mesh    *geoMesh,
197                                        Geometry::TIPOFUNC              upb=0);
198
199                        /// Class destructor.
200                        ~ViewPointDrivenSimplifier(void);
201
202                        /// Copy constructor
203                        //ViewPointDrivenSimplifier(const ViewPointDrivenSimplifier&);
204
205                        /// Assignment operator
206                        //ViewPointDrivenSimplifier& operator =(const ViewPointDrivenSimplifier&);
207
208                        /// 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.
209                        void Simplify(Geometry::Real);
210
211                        /// 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.
212                        void Simplify(Geometry::uint32);
213
214                        // Returns the simplified mesh.
215                        //Mesh *GetMesh();
216        };
217
218        /// Implementation of a simplification algorithm based on geometry information.
219        /** This class implements a simplification algorithm based on a classic geometry evaluation technique. */
220        class GeometryBasedSimplifier : public MeshSimplifier
221        {
222                public:
223                        /// Class constructor. Will call Simplifier class constructor.
224                        GeometryBasedSimplifier(        const Geometry::Mesh    *geoMesh,
225                                        Geometry::TIPOFUNC              upb=0);
226
227                        /// Class destructor.
228                        ~GeometryBasedSimplifier(void);
229
230                        /// Copy constructor
231                        //GeometryBasedSimplifier(const GeometryBasedSimplifier&);
232
233                        /// Assignment operator
234                        //GeometryBasedSimplifier& operator =(const GeometryBasedSimplifier&);
235
236                        /// 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.
237                        void Simplify(Geometry::Real);
238
239                        /// 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.
240                        void Simplify(Geometry::uint32);
241        };
242} // end of Geometry namespace;
243
244#endif
245
Note: See TracBrowser for help on using the repository browser.