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

Revision 2090, 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                        MeshSimplificationSequence *
93                                WriteRealSimpSeq(MeshSimplificationSequence *simpseq);
94
95                        Mesh    *GetMesh();
96        };
97
98        /// Mesh simplificator interface.
99        /** 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
100
101Inputs:\n
102- A pointer to the Geometry::Mesh object containing the 3D model to be simplified.
103.
104
105Outputs:\n
106-# The simplified mesh, contained in a Geometry::Mesh object.
107-# Simplification sequence, represented by a Geometry::MeshSimplificationSequence object.
108*/
109
110        class MeshSimplifier
111        {
112                public:
113                        /// Class constructor. Retrieves a pointer to a valid Geometry::Mesh object to simplify.
114                        MeshSimplifier( const Geometry::Mesh    *,
115                                        Geometry::TIPOFUNC              upb=0);
116
117                        /// Virtual class destructor.
118                        virtual ~MeshSimplifier (void);
119
120                        /// Copy constructor
121                        //MeshSimplifier(const MeshSimplifier&);
122
123                        /// Assignment operator
124                        //MeshSimplifier& operator =(const MeshSimplifier&);
125
126                        /// 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.
127                        virtual void Simplify(Geometry::Real)=0;
128
129                        /// 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.
130                        virtual void Simplify(Geometry::uint32)=0;
131
132                        /// Returns the simplified mesh.
133                        Mesh *GetMesh();
134
135                        /// Returns the simplification sequence for general meshes.
136                        MeshSimplificationSequence *GetSimplificationSequence();
137
138                        // Sets what is the mesh that stores the leaves
139                        void setMeshLeaves(Geometry::Index);
140
141                protected:
142
143                        //private: // fer protected
144                        Mesh                                                                                            *mGeoMesh;
145                        Mesh                                                                                            *mInitialMesh;
146                        MeshSimplificationSequence      *msimpsequence;
147                        const Mesh                                                                      *objmesh;
148
149                        Geometry::Index indexMeshLeaves;
150
151                        //      Progress bar function.
152                        Geometry::TIPOFUNC      mUPB;
153
154                        //      Sort mesh bones.
155                        void    sortBones();
156        };
157
158        /// Implementation of a simplification algorithm based on viewpoint.
159        /** This class implements a simplification algorithm based on a viewpoint evaluation technique. */
160        class ViewPointDrivenSimplifier : public MeshSimplifier
161        {
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();
219        };
220
221        /// Implementation of a simplification algorithm based on geometry information.
222        /** This class implements a simplification algorithm based on a classic geometry evaluation technique. */
223        class GeometryBasedSimplifier : public MeshSimplifier
224        {
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);
244        };
245} // end of Geometry namespace;
246
247#endif
248
Note: See TracBrowser for help on using the repository browser.