source: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.h @ 2194

Revision 2194, 5.4 KB checked in by gumbau, 17 years ago (diff)
Line 
1#pragma once
2
3#include <set>
4#include <map>
5#include <vector>
6#include <list>
7#include <iostream>
8#include <simplif.h>
9#include <GeoMeshSimplifier.h>
10
11using   namespace       Geometry;
12using   namespace       std;
13
14//-------------------------------------------------------------------------
15// Class to create a map without repeated vertices
16//-------------------------------------------------------------------------
17class _float3_
18{
19        public:
20
21                float x,y,z;
22
23                _float3_(float x=0.0f, float y=0.0f, float z=0.0f)
24                {
25                        this->x = x; this->y = y; this->z = z;
26                }
27
28                _float3_(const _float3_ &f)
29                {
30                        x=f.x; y=f.y; z=f.z;
31                }
32
33                _float3_ & operator=(const _float3_ &f)
34                {
35                        x=f.x; y=f.y; z=f.z; return *this;
36                }
37
38                /*
39                bool operator==(const _float3_  &f) const
40                {
41                        float   F3_EPS;
42                        float dx;
43                        float dy;
44                        float dz;
45                       
46                        F3_EPS  =       1e-12;
47                        dx                      =       x - f.x;
48                        dy                      =       y - f.y;
49                        dz                      =       z - f.z;
50
51                        return (dx*dx + dy*dy + dz*dz) < F3_EPS;
52                }
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//-------------------------------------------------------------------------
68// Class to perform mesh simplification.
69//-------------------------------------------------------------------------
70class SimplificationMethod
71{
72        private:
73
74                Geometry::Mesh  *mGeoMesh;
75
76                void compute_pair_info(simplif::pair_info*);
77
78                simplif::Model M0;
79
80                simplif::buffer<simplif::vert_info> vinfo;
81
82                simplif::Heap *heap;
83                simplif::real proximity_limit;    // distance threshold squared
84
85                int initialVertCount;
86                int initialEdgeCount;
87                int initialFaceCount;
88
89                //      Simplification sequence.
90                MeshSimplificationSequence      *msimpseq;
91
92                inline simplif::vert_info& vertex_info(simplif::Vertex *v)
93                {
94                        return vinfo(v->validID());
95                }
96
97                simplif::real pair_mesh_penalty(simplif::Model& M,
98                                simplif::Vertex *v1,
99                                simplif::Vertex *v2,
100                                simplif::Vec3& vnew);
101
102                int predict_face(simplif::Face& F,
103                                simplif::Vertex *v1,
104                                simplif::Vertex *v2,
105                                simplif::Vec3& vnew,
106                                simplif::Vec3& f1,
107                                simplif::Vec3& f2,
108                                simplif::Vec3& f3);
109
110                bool check_for_pair(simplif::Vertex *v0, simplif::Vertex *v1);
111
112                simplif::pair_info *new_pair(simplif::Vertex *v0, simplif::Vertex *v1);
113
114                void delete_pair(simplif::pair_info *pair);
115
116                void do_contract(       simplif::Model&                 m,
117                                                                                        simplif::pair_info      *pair,
118                                                                                        int                                                                     obligatory);
119
120                bool decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q);
121
122                void decimate_contract(simplif::Model& m);
123
124                simplif::real decimate_error(simplif::Vertex *v);
125
126                simplif::real decimate_min_error();
127
128                simplif::real decimate_max_error(simplif::Model& m);
129
130                void decimate_init(simplif::Model& m, simplif::real limit);
131
132                bool pair_is_valid(simplif::Vertex *u, simplif::Vertex *v);
133
134                void simplifmethod_run(int,     Geometry::TIPOFUNC      upb=0);
135
136                void simplifmethod_runv(int,    Geometry::TIPOFUNC      upb=0);
137
138                void simplifmethod_init(void);
139
140                //      To map the mesh with de simplification method structure.
141                //      Submeshes which pertains each vertex.
142                std::map< int,  std::vector<int> > submeshmap;
143
144                //      Vertices of the VertexBuffer that point
145                //      at this vertex of the simplification method.
146                std::map< int,  std::vector<int> > vertexbuffermap;
147
148                //      Multimap to store current vertex in a simplification state.
149                typedef multimap<_float3_,      int>    vertex_map;
150                typedef vertex_map::iterator                    vertex_map_str;
151                typedef vertex_map::value_type          vertex_pair;
152
153                //      Store unique vertices by submesh (without repetitions).
154                typedef std::map<int,int> MAPAINDIND;
155
156                //      Store all the indices by submesh (with repetitions).
157                typedef std::vector<int> REPINDLIST;
158
159                vertex_map      vertexMultimap;
160
161                //      Simplification sequence of the simplification method.
162                std::vector<Geometry::MeshSimplificationSequence::Step> decim_data;
163
164                std::string meshName;
165
166                unsigned int *first_index_submesh;
167
168                //std::vector<simplif::pair_info *> pointers_to_remove;
169
170                int indexMeshLeaves;
171
172                //      Contract lonely vertices that have same coords
173                //      than the contracted one.
174                void    contractLonelyVertices( simplif::Model  &m,
175                                                                                                                                        simplif::Vertex *v0,
176                                                                                                                                        simplif::Vertex *v1,
177                                                                                                                                        simplif::Vec3           candidate);
178
179                //      Find twin vertices to the contracted one and contract them.
180                void    removeTwinVertices(     simplif::Model  &m,
181                                                                                                                        simplif::Vertex *v0,
182                                                                                                                        simplif::Vertex *v1,
183                                                                                                                        simplif::Vec3           candidate);
184
185                void    fillUpSharedVertices(   MAPAINDIND      &shared_vertex_map,
186                                                                                                                                REPINDLIST *ver_inds_rep_by_geo);
187
188                void    fillUpVertices( MAPAINDIND      *unique_verts_inds_by_geo,
189                                                                                                        REPINDLIST *ver_inds_rep_by_geo);
190
191                void    addNewBoneAssignments();
192
193                void    eraseVoidSubMeshes(Mesh *geoMesh);
194
195        public:
196
197                Mesh *mInitialMesh;
198
199                //      Total number of triangles of all the submeshes.
200                int number_of_triangles;
201
202                ///     Constructor.
203                SimplificationMethod(const Mesh *m);
204
205                ///     Destructor.
206                ~SimplificationMethod();
207
208                void    generateSimplifModel(void);
209
210                MeshSimplificationSequence *Decimate(   float                   lod,
211                                                                                                                                                                        int                             simpliftype,
212                                                                                                                                                                        TIPOFUNC        upb=0);
213
214                void setMeshLeaves(int meshLeaves);
215
216                ///     Gets mesh simplified.
217                Mesh    *       GetMesh();
218
219};
220
Note: See TracBrowser for help on using the repository browser.