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 |
|
---|
11 | using namespace Geometry;
|
---|
12 |
|
---|
13 | class SimplificationMethod
|
---|
14 | {
|
---|
15 | private:
|
---|
16 |
|
---|
17 | Geometry::Mesh *mGeoMesh;
|
---|
18 |
|
---|
19 | void compute_pair_info(simplif::pair_info*);
|
---|
20 |
|
---|
21 | simplif::Model M0;
|
---|
22 |
|
---|
23 | simplif::array<simplif::vert_info> vinfo;
|
---|
24 |
|
---|
25 | simplif::Heap *heap;
|
---|
26 | simplif::real proximity_limit; // distance threshold squared
|
---|
27 |
|
---|
28 | int initialVertCount;
|
---|
29 | int initialEdgeCount;
|
---|
30 | int initialFaceCount;
|
---|
31 |
|
---|
32 | // Simplification sequence.
|
---|
33 | MeshSimplificationSequence *msimpseq;
|
---|
34 |
|
---|
35 | // Stores the simplification step.
|
---|
36 | MeshSimplificationSequence::Step simplifstep;
|
---|
37 |
|
---|
38 | inline simplif::vert_info& vertex_info(simplif::Vertex *v)
|
---|
39 | {
|
---|
40 | return vinfo(v->validID());
|
---|
41 | }
|
---|
42 |
|
---|
43 | simplif::real pair_mesh_penalty(simplif::Model& M,
|
---|
44 | simplif::Vertex *v1,
|
---|
45 | simplif::Vertex *v2,
|
---|
46 | simplif::Vec3& vnew);
|
---|
47 |
|
---|
48 | int predict_face(simplif::Face& F,
|
---|
49 | simplif::Vertex *v1,
|
---|
50 | simplif::Vertex *v2,
|
---|
51 | simplif::Vec3& vnew,
|
---|
52 | simplif::Vec3& f1,
|
---|
53 | simplif::Vec3& f2,
|
---|
54 | simplif::Vec3& f3);
|
---|
55 |
|
---|
56 | bool check_for_pair(simplif::Vertex *v0, simplif::Vertex *v1);
|
---|
57 |
|
---|
58 | simplif::pair_info *new_pair(simplif::Vertex *v0, simplif::Vertex *v1);
|
---|
59 |
|
---|
60 | void delete_pair(simplif::pair_info *pair);
|
---|
61 |
|
---|
62 | void do_contract(simplif::Model& m, simplif::pair_info *pair);
|
---|
63 |
|
---|
64 | bool decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q);
|
---|
65 |
|
---|
66 | void decimate_contract(simplif::Model& m);
|
---|
67 |
|
---|
68 | simplif::real decimate_error(simplif::Vertex *v);
|
---|
69 |
|
---|
70 | simplif::real decimate_min_error();
|
---|
71 |
|
---|
72 | simplif::real decimate_max_error(simplif::Model& m);
|
---|
73 |
|
---|
74 | void decimate_init(simplif::Model& m, simplif::real limit);
|
---|
75 |
|
---|
76 | bool pair_is_valid(simplif::Vertex *u, simplif::Vertex *v);
|
---|
77 |
|
---|
78 | void simplifmethod_run(int, Geometry::TIPOFUNC upb=0);
|
---|
79 |
|
---|
80 | void simplifmethod_runv(int, Geometry::TIPOFUNC upb=0);
|
---|
81 |
|
---|
82 | void simplifmethod_init(void);
|
---|
83 |
|
---|
84 | // To map the mesh with de simplification method structure.
|
---|
85 | // Submeshes which pertains each vertex.
|
---|
86 | std::map< int, std::vector<int> > submeshmap;
|
---|
87 |
|
---|
88 | // Vertices of the VertexBuffer that point
|
---|
89 | // at this vertex of the simplification method.
|
---|
90 | std::map< int, std::vector<int> > vertexbuffermap;
|
---|
91 |
|
---|
92 | // Simplification sequence of the simplification method.
|
---|
93 | std::vector<Geometry::MeshSimplificationSequence::Step> decim_data;
|
---|
94 |
|
---|
95 | std::string meshName;
|
---|
96 |
|
---|
97 | unsigned int *first_index_submesh;
|
---|
98 |
|
---|
99 | //std::vector<simplif::pair_info *> pointers_to_remove;
|
---|
100 |
|
---|
101 | int indexMeshLeaves;
|
---|
102 |
|
---|
103 | // Contract lonely vertices that have same coords than the contracted one.
|
---|
104 | void contractLonelyVertices( simplif::Model &m,
|
---|
105 | simplif::Vertex *v0,
|
---|
106 | simplif::Vertex *v1,
|
---|
107 | simplif::Vec3 candidate);
|
---|
108 |
|
---|
109 | // Remove twin edges.
|
---|
110 | void removeTwinEdges(simplif::Model &m,
|
---|
111 | simplif::Vertex *v0,
|
---|
112 | simplif::Vertex *v1,
|
---|
113 | simplif::Vec3 candidate);
|
---|
114 |
|
---|
115 | public:
|
---|
116 |
|
---|
117 | const Geometry::Mesh *objmesh;
|
---|
118 |
|
---|
119 | // Total number of triangles of all the submeshes.
|
---|
120 | int number_of_triangles;
|
---|
121 |
|
---|
122 | SimplificationMethod(const Geometry::Mesh *m);
|
---|
123 |
|
---|
124 | void generateSimplifModel(void);
|
---|
125 |
|
---|
126 | Geometry::MeshSimplificationSequence *Decimate( float lod,
|
---|
127 | int simpliftype,
|
---|
128 | Geometry::TIPOFUNC upb=0);
|
---|
129 |
|
---|
130 | void setMeshLeaves(int meshLeaves);
|
---|
131 |
|
---|
132 | /// Gets mesh simplified.
|
---|
133 | Geometry::Mesh * GetMesh();
|
---|
134 |
|
---|
135 | /// Destructor.
|
---|
136 | ~SimplificationMethod();
|
---|
137 | };
|
---|
138 |
|
---|