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

Revision 2087, 5.2 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                bool operator<(const _float3_ &f) const
39                {
40                        if (x<f.x) return true;
41                        if (x>f.x) return false;
42                        if (y<f.y) return true;
43                        if (y>f.y) return false;
44                        if (z<f.z) return true;
45                        if (z>f.z) return false;
46                        return false;
47                }
48};
49
50//-------------------------------------------------------------------------
51// Class to perform mesh simplification.
52//-------------------------------------------------------------------------
53class SimplificationMethod
54{
55        private:
56
57                Geometry::Mesh  *mGeoMesh;
58
59                void compute_pair_info(simplif::pair_info*);
60
61                simplif::Model M0;
62
63                simplif::buffer<simplif::vert_info> vinfo;
64
65                simplif::Heap *heap;
66                simplif::real proximity_limit;    // distance threshold squared
67
68                int initialVertCount;
69                int initialEdgeCount;
70                int initialFaceCount;
71
72                //      Simplification sequence.
73                MeshSimplificationSequence      *msimpseq;
74
75                //      Stores the simplification step.
76                MeshSimplificationSequence::Step simplifstep;
77
78                inline simplif::vert_info& vertex_info(simplif::Vertex *v)
79                {
80                        return vinfo(v->validID());
81                }
82
83                simplif::real pair_mesh_penalty(simplif::Model& M,
84                                simplif::Vertex *v1,
85                                simplif::Vertex *v2,
86                                simplif::Vec3& vnew);
87
88                int predict_face(simplif::Face& F,
89                                simplif::Vertex *v1,
90                                simplif::Vertex *v2,
91                                simplif::Vec3& vnew,
92                                simplif::Vec3& f1,
93                                simplif::Vec3& f2,
94                                simplif::Vec3& f3);
95
96                bool check_for_pair(simplif::Vertex *v0, simplif::Vertex *v1);
97
98                simplif::pair_info *new_pair(simplif::Vertex *v0, simplif::Vertex *v1);
99
100                void delete_pair(simplif::pair_info *pair);
101
102                void do_contract(simplif::Model& m, simplif::pair_info *pair);
103
104                bool decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q);
105
106                void decimate_contract(simplif::Model& m);
107
108                simplif::real decimate_error(simplif::Vertex *v);
109
110                simplif::real decimate_min_error();
111
112                simplif::real decimate_max_error(simplif::Model& m);
113
114                void decimate_init(simplif::Model& m, simplif::real limit);
115
116                bool pair_is_valid(simplif::Vertex *u, simplif::Vertex *v);
117
118                void simplifmethod_run(int,     Geometry::TIPOFUNC      upb=0);
119
120                void simplifmethod_runv(int,    Geometry::TIPOFUNC      upb=0);
121
122                void simplifmethod_init(void);
123
124                //      To map the mesh with de simplification method structure.
125                //      Submeshes which pertains each vertex.
126                std::map< int,  std::vector<int> > submeshmap;
127
128                //      Vertices of the VertexBuffer that point
129                //      at this vertex of the simplification method.
130                std::map< int,  std::vector<int> > vertexbuffermap;
131
132                //      Multimap to store current vertex in a simplification state.
133                typedef multimap<_float3_,      int>    vertex_map;
134                typedef vertex_map::iterator                    vertex_map_str;
135                typedef vertex_map::value_type          vertex_pair;
136
137                //      Store unique vertices by submesh (without repetitions).
138                typedef std::map<int,int> MAPAINDIND;
139
140                //      Store all the indices by submesh (with repetitions).
141                typedef std::vector<int> REPINDLIST;
142
143                vertex_map      vertexMultimap;
144
145                //      Simplification sequence of the simplification method.
146                std::vector<Geometry::MeshSimplificationSequence::Step> decim_data;
147
148                std::string meshName;
149
150                unsigned int *first_index_submesh;
151
152                //std::vector<simplif::pair_info *> pointers_to_remove;
153
154                int indexMeshLeaves;
155
156                //      Contract lonely vertices that have same coords
157                //      than the contracted one.
158                void    contractLonelyVertices( simplif::Model  &m,
159                                                                                                                                        simplif::Vertex *v0,
160                                                                                                                                        simplif::Vertex *v1,
161                                                                                                                                        simplif::Vec3           candidate);
162
163                //      Find twin vertices to the contracted one and contract them.
164                void    removeTwinVertices(     simplif::Model  &m,
165                                                                                                                        simplif::Vertex *v0,
166                                                                                                                        simplif::Vertex *v1,
167                                                                                                                        simplif::Vec3           candidate);
168
169                void    fillUpSharedVertices(   MAPAINDIND      &shared_vertex_map,
170                                                                                                                                REPINDLIST *ver_inds_rep_by_geo);
171
172                void    fillUpVertices( MAPAINDIND      *unique_verts_inds_by_geo,
173                                                                                                        REPINDLIST *ver_inds_rep_by_geo);
174
175                void    addNewBoneAssignments();
176
177                void    eraseVoidSubMeshes(Mesh *geoMesh);
178
179        public:
180
181                Mesh *mInitialMesh;
182
183                //      Total number of triangles of all the submeshes.
184                int number_of_triangles;
185
186                ///     Constructor.
187                SimplificationMethod(const Mesh *m);
188
189                ///     Destructor.
190                ~SimplificationMethod();
191
192                void    generateSimplifModel(void);
193
194                MeshSimplificationSequence *Decimate(   float                   lod,
195                                                                                                                                                                        int                             simpliftype,
196                                                                                                                                                                        TIPOFUNC        upb=0);
197
198                void setMeshLeaves(int meshLeaves);
199
200                ///     Gets mesh simplified.
201                Mesh    *       GetMesh();
202
203};
204
Note: See TracBrowser for help on using the repository browser.