48 #define OPENMESH_SUBDIVIDER_UNIFORM_CATMULLCLARK_CC 53 #include <OpenMesh/Tools/Utils/MeshCheckerT.hh> 58 namespace Subdivider {
63 template <
typename MeshType,
typename RealType>
67 _m.add_property( vp_pos_ );
68 _m.add_property( ep_pos_ );
69 _m.add_property( fp_pos_ );
70 _m.add_property( creaseWeights_ );
73 for( EdgeIter e_it = _m.edges_begin(); e_it != _m.edges_end(); ++e_it)
74 _m.property(creaseWeights_, *e_it ) = 0.0;
81 template <
typename MeshType,
typename RealType>
85 _m.remove_property( vp_pos_ );
86 _m.remove_property( ep_pos_ );
87 _m.remove_property( fp_pos_ );
88 _m.remove_property( creaseWeights_ );
94 template <
typename MeshType,
typename RealType>
99 for (
size_t i = 0; i < _n; ++i)
103 FaceIter f_itr = _m.faces_begin();
104 FaceIter f_end = _m.faces_end();
105 for ( ; f_itr != f_end; ++f_itr)
108 _m.calc_face_centroid( *f_itr, centroid);
109 _m.property( fp_pos_, *f_itr ) = centroid;
113 EdgeIter e_itr = _m.edges_begin();
114 EdgeIter e_end = _m.edges_end();
115 for ( ; e_itr != e_end; ++e_itr)
116 compute_midpoint( _m, *e_itr, _update_points );
122 VertexIter v_itr = _m.vertices_begin();
123 VertexIter v_end = _m.vertices_end();
124 for ( ; v_itr != v_end; ++v_itr)
125 update_vertex( _m, *v_itr );
128 v_itr = _m.vertices_begin();
129 for ( ; v_itr != v_end; ++v_itr)
130 _m.set_point(*v_itr, _m.property( vp_pos_, *v_itr ) );
135 e_itr = _m.edges_begin();
136 for ( ; e_itr != e_end; ++e_itr)
137 split_edge( _m, *e_itr );
141 f_itr = _m.faces_begin();
142 for ( ; f_itr != f_end; ++f_itr)
143 split_face( _m, *f_itr);
146 #if defined(_DEBUG) || defined(DEBUG) 159 template <
typename MeshType,
typename RealType>
173 size_t valence = _m.valence(_fh)/2;
176 VertexHandle vh = _m.add_vertex(_m.property( fp_pos_, _fh ));
178 HalfedgeHandle hend = _m.halfedge_handle(_fh);
179 HalfedgeHandle hh = _m.next_halfedge_handle(hend);
181 HalfedgeHandle hold = _m.new_edge(_m.to_vertex_handle(hend), vh);
183 _m.set_next_halfedge_handle(hend, hold);
184 _m.set_face_handle(hold, _fh);
186 hold = _m.opposite_halfedge_handle(hold);
188 for(
size_t i = 1; i < valence; i++)
190 HalfedgeHandle hnext = _m.next_halfedge_handle(hh);
192 FaceHandle fnew = _m.new_face();
194 _m.set_halfedge_handle(fnew, hh);
196 HalfedgeHandle hnew = _m.new_edge(_m.to_vertex_handle(hnext), vh);
198 _m.set_face_handle(hnew, fnew);
199 _m.set_face_handle(hold, fnew);
200 _m.set_face_handle(hh, fnew);
201 _m.set_face_handle(hnext, fnew);
203 _m.set_next_halfedge_handle(hnew, hold);
204 _m.set_next_halfedge_handle(hold, hh);
205 _m.set_next_halfedge_handle(hh, hnext);
206 hh = _m.next_halfedge_handle(hnext);
207 _m.set_next_halfedge_handle(hnext, hnew);
209 hold = _m.opposite_halfedge_handle(hnew);
212 _m.set_next_halfedge_handle(hold, hh);
213 _m.set_next_halfedge_handle(hh, hend);
214 hh = _m.next_halfedge_handle(hend);
215 _m.set_next_halfedge_handle(hend, hh);
216 _m.set_next_halfedge_handle(hh, hold);
218 _m.set_face_handle(hold, _fh);
220 _m.set_halfedge_handle(vh, hold);
225 template <
typename MeshType,
typename RealType>
229 HalfedgeHandle heh = _m.halfedge_handle(_eh, 0);
230 HalfedgeHandle opp_heh = _m.halfedge_handle(_eh, 1);
232 HalfedgeHandle new_heh, opp_new_heh, t_heh;
234 VertexHandle vh1( _m.to_vertex_handle(heh));
238 vh = _m.new_vertex( zero );
239 _m.set_point( vh, _m.property( ep_pos_, _eh ) );
242 if (_m.is_boundary(_eh))
245 _m.next_halfedge_handle(t_heh) != opp_heh;
246 t_heh = _m.opposite_halfedge_handle(_m.next_halfedge_handle(t_heh)))
251 for (t_heh = _m.next_halfedge_handle(opp_heh);
252 _m.next_halfedge_handle(t_heh) != opp_heh;
253 t_heh = _m.next_halfedge_handle(t_heh) )
257 new_heh = _m.new_edge(vh, vh1);
258 opp_new_heh = _m.opposite_halfedge_handle(new_heh);
259 _m.set_vertex_handle( heh, vh );
261 _m.set_next_halfedge_handle(t_heh, opp_new_heh);
262 _m.set_next_halfedge_handle(new_heh, _m.next_halfedge_handle(heh));
263 _m.set_next_halfedge_handle(heh, new_heh);
264 _m.set_next_halfedge_handle(opp_new_heh, opp_heh);
266 if (_m.face_handle(opp_heh).is_valid())
268 _m.set_face_handle(opp_new_heh, _m.face_handle(opp_heh));
269 _m.set_halfedge_handle(_m.face_handle(opp_new_heh), opp_new_heh);
272 if( _m.face_handle(heh).is_valid())
274 _m.set_face_handle( new_heh, _m.face_handle(heh) );
275 _m.set_halfedge_handle( _m.face_handle(heh), heh );
278 _m.set_halfedge_handle( vh, new_heh);
279 _m.set_halfedge_handle( vh1, opp_new_heh );
282 _m.adjust_outgoing_halfedge( vh );
283 _m.adjust_outgoing_halfedge( vh1 );
288 template <
typename MeshType,
typename RealType>
292 HalfedgeHandle heh, opp_heh;
294 heh = _m.halfedge_handle( _eh, 0);
295 opp_heh = _m.halfedge_handle( _eh, 1);
297 Point pos( _m.point( _m.to_vertex_handle( heh)));
299 pos += _m.point( _m.to_vertex_handle( opp_heh));
303 if (_m.is_boundary(_eh) || !_update_points)
305 pos *=
static_cast<RealType
>(0.5);
315 pos += _m.property(fp_pos_, _m.face_handle(heh));
316 pos += _m.property(fp_pos_, _m.face_handle(opp_heh));
317 pos *=
static_cast<RealType
>(0.25);
319 _m.property( ep_pos_, _eh ) = pos;
324 template <
typename MeshType,
typename RealType>
328 Point pos(0.0,0.0,0.0);
334 if ( _m.is_boundary( _vh))
338 VertexEdgeIter ve_itr;
339 for ( ve_itr = _m.ve_iter( _vh); ve_itr.is_valid(); ++ve_itr)
340 if ( _m.is_boundary( *ve_itr))
341 pos += _m.property( ep_pos_, *ve_itr);
368 RealType valence(0.0);
369 VOHIter voh_it = _m.voh_iter( _vh );
370 for( ; voh_it.is_valid(); ++voh_it )
372 pos += _m.point( _m.to_vertex_handle( *voh_it ) );
375 pos /= valence*valence;
377 VertexFaceIter vf_itr;
380 for ( vf_itr = _m.vf_iter( _vh); vf_itr.is_valid(); ++vf_itr)
382 Q += _m.property(fp_pos_, *vf_itr);
385 Q /= valence*valence;
387 pos += _m.point(_vh) * (valence - RealType(2.0) )/valence + Q;
391 _m.property( vp_pos_, _vh ) = pos;
virtual bool prepare(MeshType &_m)
Initialize properties and weights.
Definition: CatmullClarkT_impl.hh:65
Based on code from Leon Kos, CAD lab, Mech.Eng., University of Ljubljana, Slovenia (http://www...
Definition: CatmullClarkT.hh:85
virtual bool cleanup(MeshType &_m)
Remove properties and weights.
Definition: CatmullClarkT_impl.hh:83
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
virtual bool subdivide(MeshType &_m, size_t _n, const bool _update_points=true)
Execute n subdivision steps.
Definition: CatmullClarkT_impl.hh:96
Check integrity of mesh.
Definition: MeshCheckerT.hh:73
T::value_type value_type
Type of the scalar value.
Definition: vector_traits.hh:94