55 #define OPENMESH_SUBDIVIDER_UNIFORM_CATMULLCLARK_CC 60 #include <OpenMesh/Tools/Utils/MeshCheckerT.hh> 65 namespace Subdivider {
70 template <
typename MeshType,
typename RealType>
74 _m.add_property( vp_pos_ );
75 _m.add_property( ep_pos_ );
76 _m.add_property( fp_pos_ );
77 _m.add_property( creaseWeights_ );
80 for( EdgeIter e_it = _m.edges_begin(); e_it != _m.edges_end(); ++e_it)
81 _m.property(creaseWeights_, *e_it ) = 0.0;
88 template <
typename MeshType,
typename RealType>
92 _m.remove_property( vp_pos_ );
93 _m.remove_property( ep_pos_ );
94 _m.remove_property( fp_pos_ );
95 _m.remove_property( creaseWeights_ );
101 template <
typename MeshType,
typename RealType>
106 for (
size_t i = 0; i < _n; ++i)
110 FaceIter f_itr = _m.faces_begin();
111 FaceIter f_end = _m.faces_end();
112 for ( ; f_itr != f_end; ++f_itr)
115 _m.calc_face_centroid( *f_itr, centroid);
116 _m.property( fp_pos_, *f_itr ) = centroid;
120 EdgeIter e_itr = _m.edges_begin();
121 EdgeIter e_end = _m.edges_end();
122 for ( ; e_itr != e_end; ++e_itr)
123 compute_midpoint( _m, *e_itr, _update_points );
129 VertexIter v_itr = _m.vertices_begin();
130 VertexIter v_end = _m.vertices_end();
131 for ( ; v_itr != v_end; ++v_itr)
132 update_vertex( _m, *v_itr );
135 v_itr = _m.vertices_begin();
136 for ( ; v_itr != v_end; ++v_itr)
137 _m.set_point(*v_itr, _m.property( vp_pos_, *v_itr ) );
142 e_itr = _m.edges_begin();
143 for ( ; e_itr != e_end; ++e_itr)
144 split_edge( _m, *e_itr );
148 f_itr = _m.faces_begin();
149 for ( ; f_itr != f_end; ++f_itr)
150 split_face( _m, *f_itr);
153 #if defined(_DEBUG) || defined(DEBUG) 166 template <
typename MeshType,
typename RealType>
180 size_t valence = _m.valence(_fh)/2;
183 VertexHandle vh = _m.add_vertex(_m.property( fp_pos_, _fh ));
185 HalfedgeHandle hend = _m.halfedge_handle(_fh);
186 HalfedgeHandle hh = _m.next_halfedge_handle(hend);
188 HalfedgeHandle hold = _m.new_edge(_m.to_vertex_handle(hend), vh);
190 _m.set_next_halfedge_handle(hend, hold);
191 _m.set_face_handle(hold, _fh);
193 hold = _m.opposite_halfedge_handle(hold);
195 for(
size_t i = 1; i < valence; i++)
197 HalfedgeHandle hnext = _m.next_halfedge_handle(hh);
199 FaceHandle fnew = _m.new_face();
201 _m.set_halfedge_handle(fnew, hh);
203 HalfedgeHandle hnew = _m.new_edge(_m.to_vertex_handle(hnext), vh);
205 _m.set_face_handle(hnew, fnew);
206 _m.set_face_handle(hold, fnew);
207 _m.set_face_handle(hh, fnew);
208 _m.set_face_handle(hnext, fnew);
210 _m.set_next_halfedge_handle(hnew, hold);
211 _m.set_next_halfedge_handle(hold, hh);
212 _m.set_next_halfedge_handle(hh, hnext);
213 hh = _m.next_halfedge_handle(hnext);
214 _m.set_next_halfedge_handle(hnext, hnew);
216 hold = _m.opposite_halfedge_handle(hnew);
219 _m.set_next_halfedge_handle(hold, hh);
220 _m.set_next_halfedge_handle(hh, hend);
221 hh = _m.next_halfedge_handle(hend);
222 _m.set_next_halfedge_handle(hend, hh);
223 _m.set_next_halfedge_handle(hh, hold);
225 _m.set_face_handle(hold, _fh);
227 _m.set_halfedge_handle(vh, hold);
232 template <
typename MeshType,
typename RealType>
236 HalfedgeHandle heh = _m.halfedge_handle(_eh, 0);
237 HalfedgeHandle opp_heh = _m.halfedge_handle(_eh, 1);
239 HalfedgeHandle new_heh, opp_new_heh, t_heh;
241 VertexHandle vh1( _m.to_vertex_handle(heh));
245 vh = _m.new_vertex( zero );
246 _m.set_point( vh, _m.property( ep_pos_, _eh ) );
249 if (_m.is_boundary(_eh))
252 _m.next_halfedge_handle(t_heh) != opp_heh;
253 t_heh = _m.opposite_halfedge_handle(_m.next_halfedge_handle(t_heh)))
258 for (t_heh = _m.next_halfedge_handle(opp_heh);
259 _m.next_halfedge_handle(t_heh) != opp_heh;
260 t_heh = _m.next_halfedge_handle(t_heh) )
264 new_heh = _m.new_edge(vh, vh1);
265 opp_new_heh = _m.opposite_halfedge_handle(new_heh);
266 _m.set_vertex_handle( heh, vh );
268 _m.set_next_halfedge_handle(t_heh, opp_new_heh);
269 _m.set_next_halfedge_handle(new_heh, _m.next_halfedge_handle(heh));
270 _m.set_next_halfedge_handle(heh, new_heh);
271 _m.set_next_halfedge_handle(opp_new_heh, opp_heh);
273 if (_m.face_handle(opp_heh).is_valid())
275 _m.set_face_handle(opp_new_heh, _m.face_handle(opp_heh));
276 _m.set_halfedge_handle(_m.face_handle(opp_new_heh), opp_new_heh);
279 if( _m.face_handle(heh).is_valid())
281 _m.set_face_handle( new_heh, _m.face_handle(heh) );
282 _m.set_halfedge_handle( _m.face_handle(heh), heh );
285 _m.set_halfedge_handle( vh, new_heh);
286 _m.set_halfedge_handle( vh1, opp_new_heh );
289 _m.adjust_outgoing_halfedge( vh );
290 _m.adjust_outgoing_halfedge( vh1 );
295 template <
typename MeshType,
typename RealType>
299 HalfedgeHandle heh, opp_heh;
301 heh = _m.halfedge_handle( _eh, 0);
302 opp_heh = _m.halfedge_handle( _eh, 1);
304 Point pos( _m.point( _m.to_vertex_handle( heh)));
306 pos += _m.point( _m.to_vertex_handle( opp_heh));
310 if (_m.is_boundary(_eh) || !_update_points)
322 pos += _m.property(fp_pos_, _m.face_handle(heh));
323 pos += _m.property(fp_pos_, _m.face_handle(opp_heh));
326 _m.property( ep_pos_, _eh ) = pos;
331 template <
typename MeshType,
typename RealType>
335 Point pos(0.0,0.0,0.0);
341 if ( _m.is_boundary( _vh))
345 VertexEdgeIter ve_itr;
346 for ( ve_itr = _m.ve_iter( _vh); ve_itr.is_valid(); ++ve_itr)
347 if ( _m.is_boundary( *ve_itr))
348 pos += _m.property( ep_pos_, *ve_itr);
375 RealType valence(0.0);
376 VOHIter voh_it = _m.voh_iter( _vh );
377 for( ; voh_it.is_valid(); ++voh_it )
379 pos += _m.point( _m.to_vertex_handle( *voh_it ) );
382 pos /= valence*valence;
384 VertexFaceIter vf_itr;
387 for ( vf_itr = _m.vf_iter( _vh); vf_itr.is_valid(); ++vf_itr)
389 Q += _m.property(fp_pos_, *vf_itr);
392 Q /= valence*valence;
394 pos += _m.point(_vh) * (valence - RealType(2.0) )/valence + Q;
398 _m.property( vp_pos_, _vh ) = pos;
virtual bool subdivide(MeshType &_m, size_t _n, const bool _update_points=true)
Execute n subdivision steps.
virtual bool prepare(MeshType &_m)
Initialize properties and weights.
virtual bool cleanup(MeshType &_m)
Remove properties and weights.