Subversion Repositories gelsvn

Rev

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

Rev 182 Rev 183
Line 256... Line 256...
256
				pot_edges.pop();
256
				pot_edges.pop();
257
      }
257
      }
258
 
258
 
259
  }
259
  }
260
 
260
 
-
 
261
		void shortest_edge_triangulate(Manifold& m)
-
 
262
		{
-
 
263
			int work;
-
 
264
			do
-
 
265
				{
-
 
266
					// For every face.
-
 
267
					work = 0;
-
 
268
					for(FaceIter fi =m.faces_begin(); fi != m.faces_end(); ++fi)
-
 
269
						{
-
 
270
							// Create a vector of vertices.
-
 
271
							vector<VertexIter> verts;
-
 
272
							for(FaceCirculator fc(fi); !fc.end(); ++fc)
-
 
273
								verts.push_back(fc.get_vertex());
-
 
274
								
-
 
275
							// If there are just three we are done.
-
 
276
							if(verts.size() == 3) continue;
-
 
277
										
-
 
278
							// Find vertex pairs that may be connected.
-
 
279
							vector<pair<int,int> > vpairs;
-
 
280
							const int N = verts.size();
-
 
281
							for(int i=0;i<N-2;++i)
-
 
282
								for(int j=i+2;j<N; ++j)
-
 
283
									if(!is_connected(verts[i], verts[j]))
-
 
284
										vpairs.push_back(pair<int,int>(i,j));
-
 
285
										
-
 
286
							if(vpairs.empty())
-
 
287
								{
-
 
288
									cout << "Warning: could not triangulate a face." 
-
 
289
											 << "Probably a vertex appears more than one time in other vertex's one-ring" << endl;
-
 
290
									continue;
-
 
291
								}
-
 
292
									
-
 
293
							/* For all vertex pairs, find the edge lengths. Combine the
-
 
294
								 vertices forming the shortest edge. */
-
 
295
											 
-
 
296
							float min_len=FLT_MAX;
-
 
297
							int min_k = -1;
-
 
298
							for(size_t k=0;k<vpairs.size(); ++k)
-
 
299
								{
-
 
300
									int i = vpairs[k].first;
-
 
301
									int j = vpairs[k].second;
-
 
302
									float len = sqr_length(verts[i]->pos-verts[j]->pos);
-
 
303
												
-
 
304
									if(len<min_len)
-
 
305
										{
-
 
306
											min_len = len;
-
 
307
											min_k = k;
-
 
308
										}
-
 
309
								}
-
 
310
							assert(min_k != -1);
-
 
311
										
-
 
312
							{
-
 
313
								// Split faces along edge whose midpoint is closest to isovalue
-
 
314
								int i = vpairs[min_k].first;
-
 
315
								int j = vpairs[min_k].second;
-
 
316
								m.split_face(fi, verts[i], verts[j]);
-
 
317
							}
-
 
318
							++work;
-
 
319
										
-
 
320
						}
-
 
321
				}
-
 
322
			while(work);
-
 
323
		}
-
 
324
 
-
 
325
 
-
 
326
 
-
 
327
 
261
}
328
}