Subversion Repositories gelsvn

Rev

Rev 363 | Rev 373 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 363 Rev 367
Line 54... Line 54...
54
			Manifold& m;
54
			Manifold& m;
55
			HalfEdgeVec halfedge_vec;
55
			HalfEdgeVec halfedge_vec;
56
			QEMVec qem_vec;
56
			QEMVec qem_vec;
57
			SimplifyQueue sim_queue;
57
			SimplifyQueue sim_queue;
58
			double singular_thresh;
58
			double singular_thresh;
59
			bool relocate_origin;
59
			bool choose_optimal_positions;
60
			
60
			
61
			/* Compute the error associated with contraction of he and the
61
			/* Compute the error associated with contraction of he and the
62
				optimal position of resulting vertex. */
62
				optimal position of resulting vertex. */
63
			void push_simplify_rec(HalfEdgeIter he);
63
			void push_simplify_rec(HalfEdgeIter he);
64
			
64
			
Line 85... Line 85...
85
			int collapse(SimplifyRec& simplify_rec);
85
			int collapse(SimplifyRec& simplify_rec);
86
			
86
			
87
		public:
87
		public:
88
				
88
				
89
				/* Create a simplifier for a manifold */
89
				/* Create a simplifier for a manifold */
90
				QuadricSimplifier(Manifold& _m, double _singular_thresh, bool _relocate_origin): 
90
				QuadricSimplifier(Manifold& _m, double _singular_thresh, bool _choose_optimal_positions): 
91
				m(_m), 
91
				m(_m), 
92
				halfedge_vec(m.no_halfedges()), 
92
				halfedge_vec(m.no_halfedges()), 
93
				qem_vec(m.no_vertices()),
93
				qem_vec(m.no_vertices()),
94
				singular_thresh(_singular_thresh),
94
				singular_thresh(_singular_thresh),
95
				relocate_origin(_relocate_origin)
95
				choose_optimal_positions(_choose_optimal_positions)
96
			{
96
			{
97
					// Enumerate vertices
97
					// Enumerate vertices
98
					m.enumerate_vertices();
98
					m.enumerate_vertices();
99
					
99
					
100
					// Enumerate halfedges
100
					// Enumerate halfedges
Line 155... Line 155...
155
			q += Q2;
155
			q += Q2;
156
			
156
			
157
			float err;
157
			float err;
158
			Vec3d opt_pos(0);
158
			Vec3d opt_pos(0);
159
			Vec3d opt_origin = Vec3d(he->vert->pos+he->opp->vert->pos)/2.0;
159
			Vec3d opt_origin = Vec3d(he->vert->pos+he->opp->vert->pos)/2.0;
160
			if(relocate_origin)
160
			if(choose_optimal_positions)
161
				opt_pos = q.opt_pos(singular_thresh,opt_origin);
161
				opt_pos = q.opt_pos(singular_thresh,opt_origin);
162
			else
162
			else
-
 
163
			{
163
				opt_pos = q.opt_pos(singular_thresh,Vec3d(0));
164
				Vec3d p1(he->vert->pos), p2(he->opp->vert->pos);
-
 
165
				float err1 = q.error(p1);
-
 
166
				float err2 = q.error(p2);
-
 
167
				if(err1<err2) 
-
 
168
				{
-
 
169
					err = err1;
-
 
170
					opt_pos = p1;
-
 
171
				}
-
 
172
				else
-
 
173
				{
-
 
174
					err = err2;
-
 
175
					opt_pos = p2;				
-
 
176
				}
-
 
177
			}
164
			
178
			
165
			err = q.error(opt_pos);
179
			err = q.error(opt_pos);
166
			
180
			
167
			// Create SimplifyRec
181
			// Create SimplifyRec
168
			int he_index = he->touched;
182
			int he_index = he->touched;
Line 327... Line 341...
327
				}
341
				}
328
			}
342
			}
329
		}
343
		}
330
	}
344
	}
331
	
345
	
332
	void quadric_simplify(Manifold& m, double keep_fraction, double singular_thresh, bool relocate_origin)
346
	void quadric_simplify(Manifold& m, double keep_fraction, double singular_thresh, bool choose_optimal_positions)
333
	{
347
	{
334
		srand(1210);
348
		srand(1210);
335
		int F = m.no_faces();
349
		int F = m.no_faces();
336
		int max_work = max(0, F- static_cast<int>(keep_fraction * F));
350
		int max_work = max(0, F- static_cast<int>(keep_fraction * F));
337
		QuadricSimplifier qsim(m, singular_thresh, relocate_origin);
351
		QuadricSimplifier qsim(m, singular_thresh, choose_optimal_positions);
338
		qsim.reduce(max_work);
352
		qsim.reduce(max_work);
339
	}
353
	}
340
	
354
	
341
}
355
}