54 #ifndef OPENMESH_SUBDIVIDER_UNIFORM_LOOPT_HH 55 #define OPENMESH_SUBDIVIDER_UNIFORM_LOOPT_HH 60 #include <OpenMesh/Core/System/config.hh> 62 #include <OpenMesh/Core/Utils/vector_cast.hh> 63 #include <OpenMesh/Core/Utils/Property.hh> 66 #if defined(OM_CC_MIPS) 76 namespace Subdivider {
90 template <
typename MeshType,
typename RealType =
double>
95 typedef RealType real_t;
96 typedef MeshType mesh_t;
99 typedef std::pair< real_t, real_t > weight_t;
100 typedef std::vector< std::pair<real_t,real_t> > weights_t;
105 LoopT(
void) : parent_t(), _1over8( 1.0/8.0 ), _3over8( 3.0/8.0 )
109 explicit LoopT( mesh_t& _m ) : parent_t(_m), _1over8( 1.0/8.0 ), _3over8( 3.0/8.0 )
119 const char *
name()
const override {
return "Uniform Loop"; }
125 weights_.resize(_max_valence);
126 std::generate(weights_.begin(), weights_.end(),
compute_weight());
135 _m.add_property( vp_pos_ );
136 _m.add_property( ep_pos_ );
143 _m.remove_property( vp_pos_ );
144 _m.remove_property( ep_pos_ );
149 bool subdivide( mesh_t& _m,
size_t _n,
const bool _update_points =
true)
override 154 typename mesh_t::FaceIter fit, f_end;
155 typename mesh_t::EdgeIter eit, e_end;
156 typename mesh_t::VertexIter vit;
159 for (
size_t i=0; i < _n; ++i)
164 for (vit = _m.vertices_begin(); vit != _m.vertices_end(); ++vit) {
170 for (eit=_m.edges_begin(); eit != _m.edges_end(); ++eit)
171 compute_midpoint( _m, *eit );
177 for (
auto eh : _m.edges())
184 for (
auto fh : _m.faces())
189 for ( vit = _m.vertices_begin();
190 vit != _m.vertices_end(); ++vit) {
191 _m.set_point(*vit, _m.property( vp_pos_, *vit ) );
196 #if defined(_DEBUG) || defined(DEBUG) 212 weight_t operator() (
void)
214 #if !defined(OM_CC_MIPS) 223 double inv_v = 1.0/double(valence);
224 double t = (3.0 + 2.0 * cos( 2.0 * M_PI * inv_v) );
225 double alpha = (40.0 - t * t)/64.0;
227 return weight_t( static_cast<real_t>(1.0-alpha), static_cast<real_t>(inv_v*alpha) );
229 return weight_t(static_cast<real_t>(0.0), static_cast<real_t>(0.0));
236 void split_face(mesh_t& _m,
const typename mesh_t::FaceHandle& _fh)
238 typename mesh_t::HalfedgeHandle
239 heh1(_m.halfedge_handle(_fh)),
240 heh2(_m.next_halfedge_handle(_m.next_halfedge_handle(heh1))),
241 heh3(_m.next_halfedge_handle(_m.next_halfedge_handle(heh2)));
244 corner_cutting( _m, heh1 );
245 corner_cutting( _m, heh2 );
246 corner_cutting( _m, heh3 );
250 void corner_cutting(mesh_t& _m,
const typename mesh_t::HalfedgeHandle& _he)
253 typename mesh_t::HalfedgeHandle
256 heh6(_m.next_halfedge_handle(heh1));
259 for (; _m.next_halfedge_handle(_m.next_halfedge_handle(heh5)) != heh1;
260 heh5 = _m.next_halfedge_handle(heh5))
263 typename mesh_t::VertexHandle
264 vh1 = _m.to_vertex_handle(heh1),
265 vh2 = _m.to_vertex_handle(heh5);
267 typename mesh_t::HalfedgeHandle
268 heh2(_m.next_halfedge_handle(heh5)),
269 heh3(_m.new_edge( vh1, vh2)),
270 heh4(_m.opposite_halfedge_handle(heh3));
286 typename mesh_t::FaceHandle fh_old(_m.face_handle(heh6));
287 typename mesh_t::FaceHandle fh_new(_m.new_face());
291 _m.set_next_halfedge_handle(heh4, heh6);
292 _m.set_next_halfedge_handle(heh5, heh4);
294 _m.set_face_handle(heh4, fh_old);
295 _m.set_face_handle(heh5, fh_old);
296 _m.set_face_handle(heh6, fh_old);
297 _m.set_halfedge_handle(fh_old, heh4);
300 _m.set_next_halfedge_handle(heh1, heh3);
301 _m.set_next_halfedge_handle(heh3, heh2);
303 _m.set_face_handle(heh1, fh_new);
304 _m.set_face_handle(heh2, fh_new);
305 _m.set_face_handle(heh3, fh_new);
307 _m.set_halfedge_handle(fh_new, heh1);
311 void split_edge(mesh_t& _m,
const typename mesh_t::EdgeHandle& _eh)
313 typename mesh_t::HalfedgeHandle
314 heh = _m.halfedge_handle(_eh, 0),
315 opp_heh = _m.halfedge_handle(_eh, 1);
317 typename mesh_t::HalfedgeHandle new_heh, opp_new_heh, t_heh;
318 typename mesh_t::VertexHandle vh;
319 typename mesh_t::VertexHandle vh1(_m.to_vertex_handle(heh));
320 typename mesh_t::Point midP(_m.point(_m.to_vertex_handle(heh)));
321 midP += _m.point(_m.to_vertex_handle(opp_heh));
322 midP *=
static_cast<RealType
>(0.5);
325 vh = _m.new_vertex( midP );
328 _m.property( vp_pos_, vh ) = _m.property( ep_pos_, _eh );
332 if (_m.is_boundary(_eh))
335 _m.next_halfedge_handle(t_heh) != opp_heh;
336 t_heh = _m.opposite_halfedge_handle(_m.next_halfedge_handle(t_heh)))
341 for (t_heh = _m.next_halfedge_handle(opp_heh);
342 _m.next_halfedge_handle(t_heh) != opp_heh;
343 t_heh = _m.next_halfedge_handle(t_heh) )
347 new_heh = _m.new_edge(vh, vh1);
348 opp_new_heh = _m.opposite_halfedge_handle(new_heh);
349 _m.set_vertex_handle( heh, vh );
351 _m.set_next_halfedge_handle(t_heh, opp_new_heh);
352 _m.set_next_halfedge_handle(new_heh, _m.next_halfedge_handle(heh));
353 _m.set_next_halfedge_handle(heh, new_heh);
354 _m.set_next_halfedge_handle(opp_new_heh, opp_heh);
356 if (_m.face_handle(opp_heh).is_valid())
358 _m.set_face_handle(opp_new_heh, _m.face_handle(opp_heh));
359 _m.set_halfedge_handle(_m.face_handle(opp_new_heh), opp_new_heh);
362 _m.set_face_handle( new_heh, _m.face_handle(heh) );
363 _m.set_halfedge_handle( vh, new_heh);
366 if ( !_m.is_boundary(heh) )
367 _m.set_halfedge_handle( _m.face_handle(heh), heh );
369 _m.set_halfedge_handle( vh1, opp_new_heh );
372 _m.adjust_outgoing_halfedge( vh );
373 _m.adjust_outgoing_halfedge( vh1 );
378 void compute_midpoint(mesh_t& _m,
const typename mesh_t::EdgeHandle& _eh)
380 #define V( X ) vector_cast< typename mesh_t::Normal >( X ) 381 typename mesh_t::HalfedgeHandle heh, opp_heh;
383 heh = _m.halfedge_handle( _eh, 0);
384 opp_heh = _m.halfedge_handle( _eh, 1);
386 typename mesh_t::Point
387 pos(_m.point(_m.to_vertex_handle(heh)));
389 pos += V( _m.point(_m.to_vertex_handle(opp_heh)) );
392 if (_m.is_boundary(_eh) )
394 pos *=
static_cast<RealType
>(0.5);
399 pos += V(_m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh))));
400 pos += V(_m.point(_m.to_vertex_handle(_m.next_halfedge_handle(opp_heh))));
403 _m.property( ep_pos_, _eh ) = pos;
407 void smooth(mesh_t& _m,
const typename mesh_t::VertexHandle& _vh)
409 typename mesh_t::Point pos(0.0,0.0,0.0);
411 if (_m.is_boundary(_vh) )
413 typename mesh_t::HalfedgeHandle heh, prev_heh;
414 heh = _m.halfedge_handle( _vh );
416 if ( heh.is_valid() )
418 assert( _m.is_boundary( _m.edge_handle( heh ) ) );
420 prev_heh = _m.prev_halfedge_handle( heh );
422 typename mesh_t::VertexHandle
423 to_vh = _m.to_vertex_handle( heh ),
424 from_vh = _m.from_vertex_handle( prev_heh );
427 pos = _m.point( _vh );
429 pos +=
vector_cast<
typename mesh_t::Normal >( _m.point( to_vh ) );
430 pos +=
vector_cast<
typename mesh_t::Normal >( _m.point( from_vh ) );
439 typedef typename mesh_t::Normal Vec;
440 typename mesh_t::VertexVertexIter vvit;
444 for (vvit=_m.vv_iter(_vh); vvit.is_valid(); ++vvit) {
448 pos *= weights_[valence].second;
449 pos += weights_[valence].first
453 _m.property( vp_pos_, _vh ) = pos;
463 const real_t _1over8;
464 const real_t _3over8;
474 #endif // OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITELOOPT_HH defined void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.