56 #ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_RULEINTERFACET_HH 57 #define OPENMESH_SUBDIVIDER_ADAPTIVE_RULEINTERFACET_HH 68 namespace Subdivider {
74 template <
typename M>
class CompositeT;
75 template <
typename M>
class RuleInterfaceT;
87 template <
typename R >
88 struct RuleHandleT :
public BaseHandle
90 explicit RuleHandleT(
int _idx=-1) : BaseHandle(_idx) {}
93 operator bool()
const {
return is_valid(); }
100 #define COMPOSITE_RULE( classname, mesh_type ) \ 102 friend class CompositeT<mesh_type>; \ 104 const char *type() const { return #classname; } \ 105 typedef classname<mesh_type> Self; \ 106 typedef RuleHandleT< Self > Handle 113 template <
typename M>
class RuleInterfaceT
118 typedef RuleInterfaceT<M> Self;
119 typedef RuleHandleT< Self > Rule;
121 typedef typename M::Scalar scalar_t;
136 virtual const char *type()
const = 0;
142 virtual void raise(
typename M::FaceHandle& _fh,
state_t _target_state)
145 if (mesh_.data(_fh).state() < _target_state) {
146 update(_fh, _target_state);
147 mesh_.data(_fh).inc_state();
151 virtual void raise(
typename M::EdgeHandle& _eh,
state_t _target_state)
153 if (mesh_.data(_eh).state() < _target_state) {
154 update(_eh, _target_state);
155 mesh_.data(_eh).inc_state();
159 virtual void raise(
typename M::VertexHandle& _vh,
state_t _target_state)
161 if (mesh_.data(_vh).state() < _target_state) {
162 update(_vh, _target_state);
163 mesh_.data(_vh).inc_state();
168 void update(
typename M::FaceHandle& _fh,
state_t _target_state)
170 typename M::FaceHandle opp_fh;
172 while (mesh_.data(_fh).state() < _target_state - 1) {
173 prev_rule()->raise(_fh, _target_state - 1);
177 if (subdiv_type() == 3) {
179 if (mesh_.face_handle(mesh_.opposite_halfedge_handle(mesh_.halfedge_handle(_fh))).is_valid()) {
181 while (!mesh_.data(_fh).final()) {
183 opp_fh = mesh_.face_handle(mesh_.opposite_halfedge_handle(mesh_.halfedge_handle(_fh)));
185 assert (mesh_.data(_fh).state() >=
186 mesh_.data(opp_fh).state());
189 if (mesh_.data(_fh).state() > mesh_.data(opp_fh).state()){
192 prev_rule()->raise(opp_fh, _target_state - 1);
233 assert( subdiv_type() != 4 ||
234 mesh_.data(_fh).final() ||
235 _target_state%n_rules() == (subdiv_rule()->number() + 1)%n_rules() );
237 typename M::FaceEdgeIter fe_it;
238 typename M::FaceVertexIter fv_it;
239 typename M::EdgeHandle eh;
240 typename M::VertexHandle vh;
242 std::vector<typename M::FaceHandle> face_vector;
245 if (_target_state > 1) {
247 for (fe_it = mesh_.fe_iter(_fh); fe_it.is_valid(); ++fe_it) {
250 prev_rule()->raise(eh, _target_state - 1);
253 for (fv_it = mesh_.fv_iter(_fh); fv_it.is_valid(); ++fv_it) {
256 prev_rule()->raise(vh, _target_state - 1);
262 void update(
typename M::EdgeHandle& _eh,
state_t _target_state)
264 state_t state(mesh_.data(_eh).state());
267 if (state + 1 < _target_state && _target_state > 0) {
269 prev_rule()->raise(_eh, _target_state - 1);
272 typename M::VertexHandle vh;
273 typename M::FaceHandle fh;
275 if (_target_state > 1)
277 vh = mesh_.to_vertex_handle(mesh_.halfedge_handle(_eh, 0));
278 prev_rule()->raise(vh, _target_state - 1);
280 vh = mesh_.to_vertex_handle(mesh_.halfedge_handle(_eh, 1));
281 prev_rule()->raise(vh, _target_state - 1);
283 fh = mesh_.face_handle(mesh_.halfedge_handle(_eh, 0));
285 prev_rule()->raise(fh, _target_state - 1);
287 fh = mesh_.face_handle(mesh_.halfedge_handle(_eh, 1));
289 prev_rule()->raise(fh, _target_state - 1);
294 void update(
typename M::VertexHandle& _vh,
state_t _target_state) {
296 state_t state(mesh_.data(_vh).state());
299 if (state + 1 < _target_state)
301 prev_rule()->raise(_vh, _target_state - 1);
304 std::vector<typename M::HalfedgeHandle> halfedge_vector;
305 halfedge_vector.clear();
307 typename M::VertexOHalfedgeIter voh_it;
308 typename M::EdgeHandle eh;
309 typename M::FaceHandle fh;
311 if (_target_state > 1)
314 for (voh_it = mesh_.voh_iter(_vh); voh_it.is_valid(); ++voh_it) {
315 halfedge_vector.push_back(*voh_it);
318 while ( !halfedge_vector.empty() ) {
319 eh = mesh_.edge_handle(halfedge_vector.back());
320 halfedge_vector.pop_back();
322 prev_rule()->raise(eh, _target_state - 1);
325 for (voh_it = mesh_.voh_iter(_vh); voh_it.is_valid(); ++voh_it) {
326 halfedge_vector.push_back(*voh_it);
329 while ( !halfedge_vector.empty() ) {
330 fh = mesh_.face_handle(halfedge_vector.back());
331 halfedge_vector.pop_back();
334 prev_rule()->raise(fh, _target_state - 1);
353 virtual void set_coeff( scalar_t _coeff ) { coeff_ = _coeff; }
356 scalar_t
coeff()
const {
return coeff_; }
362 void set_prev_rule(Self*& _p) { prev_rule_ = _p; }
363 Self* prev_rule() {
return prev_rule_; }
365 void set_subdiv_rule(Self*& _n) { subdiv_rule_ = _n; }
366 Self* subdiv_rule() {
return subdiv_rule_; }
368 void set_number(
int _n) { number_ = _n; }
370 void set_n_rules(
int _n) { n_rules_ = _n; }
371 int n_rules() {
return n_rules_; }
373 void set_subdiv_type(
int _n)
374 { assert(_n == 3 || _n == 4); subdiv_type_ = _n; }
405 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_RULEINTERFACET_HH defined int number() const
Position in rule sequence.
Definition: RuleInterfaceT.hh:347
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
int subdiv_type() const
Type of split operation, if it is a topological operator.
Definition: RuleInterfaceT.hh:343
Mesh traits for adaptive composite subdivider.
RuleInterfaceT(Mesh &_mesh)
Default constructor.
Definition: RuleInterfaceT.hh:126
scalar_t coeff() const
Get coefficient - ignored by non-parameterized rules.
Definition: RuleInterfaceT.hh:356
CompositeTraits::state_t state_t
Adaptive Composite Subdivision framework.
Definition: CompositeTraits.hh:255
Adaptive Composite Subdivision framework.
Definition: CompositeT.hh:138
virtual ~RuleInterfaceT()
Destructor.
Definition: RuleInterfaceT.hh:131
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:77
Base class for adaptive composite subdivision rules.
Definition: CompositeT.hh:84
virtual void set_coeff(scalar_t _coeff)
Set coefficient - ignored by non-parameterized rules.
Definition: RuleInterfaceT.hh:353