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)
90template <
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
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)
209 struct compute_weight
211 compute_weight() : valence(-1) { }
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));
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 );
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))
264 vh1 = _m.to_vertex_handle(heh1),
265 vh2 = _m.to_vertex_handle(heh5);
268 heh2(_m.next_halfedge_handle(heh5)),
269 heh3(_m.new_edge( vh1, vh2)),
270 heh4(_m.opposite_halfedge_handle(heh3));
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);
314 heh = _m.halfedge_handle(_eh, 0),
315 opp_heh = _m.halfedge_handle(_eh, 1);
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);
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 );
380#define V( X ) vector_cast< typename mesh_t::Normal >( X )
383 heh = _m.halfedge_handle( _eh, 0);
384 opp_heh = _m.halfedge_handle( _eh, 1);
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;
411 if (_m.is_boundary(_vh) )
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 );
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 ) );
444 for (vvit=_m.vv_iter(_vh); vvit.is_valid(); ++vvit) {
446 pos += vector_cast< Vec >( _m.point(*vvit) );
448 pos *= weights_[valence].second;
449 pos += weights_[valence].first
450 * vector_cast<Vec>(_m.point(_vh));
453 _m.property( vp_pos_, _vh ) = pos;
463 const real_t _1over8;
464 const real_t _3over8;
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Triangle mesh based on the ArrayKernel.
Definition: TriMesh_ArrayKernelT.hh:96
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136
Kernel::EdgeHandle EdgeHandle
Scalar type.
Definition: PolyMeshT.hh:138
Kernel::FaceIter FaceIter
Scalar type.
Definition: PolyMeshT.hh:146
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:114
SmartVertexHandle new_vertex()
Uses default copy and assignment operator.
Definition: PolyMeshT.hh:201
Kernel::FaceHandle FaceHandle
Scalar type.
Definition: PolyMeshT.hh:139
Kernel::HalfedgeHandle HalfedgeHandle
Scalar type.
Definition: PolyMeshT.hh:137
Kernel::EdgeIter EdgeIter
Scalar type.
Definition: PolyMeshT.hh:145
Kernel::VertexVertexIter VertexVertexIter
Circulator.
Definition: PolyMeshT.hh:162
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
Kernel::VertexIter VertexIter
Scalar type.
Definition: PolyMeshT.hh:143
Uniform Loop subdivision algorithm.
Definition: LoopT.hh:92
bool cleanup(mesh_t &_m) override
Cleanup mesh after usage, e.g. remove added properties.
Definition: LoopT.hh:141
const char * name() const override
Return name of subdivision algorithm.
Definition: LoopT.hh:119
void init_weights(size_t _max_valence=50)
Pre-compute weights.
Definition: LoopT.hh:123
bool prepare(mesh_t &_m) override
Prepare mesh, e.g.
Definition: LoopT.hh:133
bool subdivide(mesh_t &_m, size_t _n, const bool _update_points=true) override
Subdivide mesh _m _n times.
Definition: LoopT.hh:149
Abstract base class for uniform subdivision algorithms.
Definition: SubdividerT.hh:89
bool operator()(MeshType &_m, size_t _n, const bool _update_points=true)
Subdivide the mesh _m _n times.
Definition: SubdividerT.hh:122
Check integrity of mesh.
Definition: MeshCheckerT.hh:74