51 #ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_RULEINTERFACET_HH 52 #define OPENMESH_SUBDIVIDER_ADAPTIVE_RULEINTERFACET_HH 63 namespace Subdivider {
69 template <
typename M>
class CompositeT;
70 template <
typename M>
class RuleInterfaceT;
82 template <
typename R >
83 struct RuleHandleT :
public BaseHandle
85 explicit RuleHandleT(
int _idx=-1) : BaseHandle(_idx) {}
88 operator bool()
const {
return is_valid(); }
95 #define COMPOSITE_RULE( classname, mesh_type ) \ 97 friend class CompositeT<mesh_type>; \ 99 const char *type() const { return #classname; } \ 100 typedef classname<mesh_type> Self; \ 101 typedef RuleHandleT< Self > Handle 108 template <
typename M>
class RuleInterfaceT
113 typedef RuleInterfaceT<M> Self;
114 typedef RuleHandleT< Self > Rule;
116 typedef typename M::Scalar scalar_t;
131 virtual const char *type()
const = 0;
137 virtual void raise(
typename M::FaceHandle& _fh,
state_t _target_state)
140 if (mesh_.data(_fh).state() < _target_state) {
141 update(_fh, _target_state);
142 mesh_.data(_fh).inc_state();
146 virtual void raise(
typename M::EdgeHandle& _eh,
state_t _target_state)
148 if (mesh_.data(_eh).state() < _target_state) {
149 update(_eh, _target_state);
150 mesh_.data(_eh).inc_state();
154 virtual void raise(
typename M::VertexHandle& _vh,
state_t _target_state)
156 if (mesh_.data(_vh).state() < _target_state) {
157 update(_vh, _target_state);
158 mesh_.data(_vh).inc_state();
163 void update(
typename M::FaceHandle& _fh,
state_t _target_state)
165 typename M::FaceHandle opp_fh;
167 while (mesh_.data(_fh).state() < _target_state - 1) {
168 prev_rule()->raise(_fh, _target_state - 1);
172 if (subdiv_type() == 3) {
174 if (mesh_.face_handle(mesh_.opposite_halfedge_handle(mesh_.halfedge_handle(_fh))).is_valid()) {
176 while (!mesh_.data(_fh).final()) {
178 opp_fh = mesh_.face_handle(mesh_.opposite_halfedge_handle(mesh_.halfedge_handle(_fh)));
180 assert (mesh_.data(_fh).state() >=
181 mesh_.data(opp_fh).state());
184 if (mesh_.data(_fh).state() > mesh_.data(opp_fh).state()){
187 prev_rule()->raise(opp_fh, _target_state - 1);
228 assert( subdiv_type() != 4 ||
229 mesh_.data(_fh).final() ||
230 _target_state%n_rules() == (subdiv_rule()->number() + 1)%n_rules() );
232 typename M::FaceEdgeIter fe_it;
233 typename M::FaceVertexIter fv_it;
234 typename M::EdgeHandle eh;
235 typename M::VertexHandle vh;
237 std::vector<typename M::FaceHandle> face_vector;
240 if (_target_state > 1) {
242 for (fe_it = mesh_.fe_iter(_fh); fe_it.is_valid(); ++fe_it) {
245 prev_rule()->raise(eh, _target_state - 1);
248 for (fv_it = mesh_.fv_iter(_fh); fv_it.is_valid(); ++fv_it) {
251 prev_rule()->raise(vh, _target_state - 1);
257 void update(
typename M::EdgeHandle& _eh,
state_t _target_state)
259 state_t state(mesh_.data(_eh).state());
262 if (state + 1 < _target_state && _target_state > 0) {
264 prev_rule()->raise(_eh, _target_state - 1);
267 typename M::VertexHandle vh;
268 typename M::FaceHandle fh;
270 if (_target_state > 1)
272 vh = mesh_.to_vertex_handle(mesh_.halfedge_handle(_eh, 0));
273 prev_rule()->raise(vh, _target_state - 1);
275 vh = mesh_.to_vertex_handle(mesh_.halfedge_handle(_eh, 1));
276 prev_rule()->raise(vh, _target_state - 1);
278 fh = mesh_.face_handle(mesh_.halfedge_handle(_eh, 0));
280 prev_rule()->raise(fh, _target_state - 1);
282 fh = mesh_.face_handle(mesh_.halfedge_handle(_eh, 1));
284 prev_rule()->raise(fh, _target_state - 1);
289 void update(
typename M::VertexHandle& _vh,
state_t _target_state) {
291 state_t state(mesh_.data(_vh).state());
294 if (state + 1 < _target_state)
296 prev_rule()->raise(_vh, _target_state - 1);
299 std::vector<typename M::HalfedgeHandle> halfedge_vector;
300 halfedge_vector.clear();
302 typename M::VertexOHalfedgeIter voh_it;
303 typename M::EdgeHandle eh;
304 typename M::FaceHandle fh;
306 if (_target_state > 1)
309 for (voh_it = mesh_.voh_iter(_vh); voh_it.is_valid(); ++voh_it) {
310 halfedge_vector.push_back(*voh_it);
313 while ( !halfedge_vector.empty() ) {
314 eh = mesh_.edge_handle(halfedge_vector.back());
315 halfedge_vector.pop_back();
317 prev_rule()->raise(eh, _target_state - 1);
320 for (voh_it = mesh_.voh_iter(_vh); voh_it.is_valid(); ++voh_it) {
321 halfedge_vector.push_back(*voh_it);
324 while ( !halfedge_vector.empty() ) {
325 fh = mesh_.face_handle(halfedge_vector.back());
326 halfedge_vector.pop_back();
329 prev_rule()->raise(fh, _target_state - 1);
348 virtual void set_coeff( scalar_t _coeff ) { coeff_ = _coeff; }
351 scalar_t
coeff()
const {
return coeff_; }
357 void set_prev_rule(Self*& _p) { prev_rule_ = _p; }
358 Self* prev_rule() {
return prev_rule_; }
360 void set_subdiv_rule(Self*& _n) { subdiv_rule_ = _n; }
361 Self* subdiv_rule() {
return subdiv_rule_; }
363 void set_number(
int _n) { number_ = _n; }
365 void set_n_rules(
int _n) { n_rules_ = _n; }
366 int n_rules() {
return n_rules_; }
368 void set_subdiv_type(
int _n)
369 { assert(_n == 3 || _n == 4); subdiv_type_ = _n; }
400 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_RULEINTERFACET_HH defined virtual ~RuleInterfaceT()
Destructor.
Definition: RuleInterfaceT.hh:126
Base class for adaptive composite subdivision rules.
Definition: CompositeT.hh:79
RuleInterfaceT(Mesh &_mesh)
Default constructor.
Definition: RuleInterfaceT.hh:121
Mesh traits for adaptive composite subdivider.
scalar_t coeff() const
Get coefficient - ignored by non-parameterized rules.
Definition: RuleInterfaceT.hh:351
int subdiv_type() const
Type of split operation, if it is a topological operator.
Definition: RuleInterfaceT.hh:338
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
int number() const
Position in rule sequence.
Definition: RuleInterfaceT.hh:342
virtual void set_coeff(scalar_t _coeff)
Set coefficient - ignored by non-parameterized rules.
Definition: RuleInterfaceT.hh:348
Adaptive Composite Subdivision framework.
Definition: CompositeT.hh:133
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:72
CompositeTraits::state_t state_t
Adaptive Composite Subdivision framework.
Definition: CompositeTraits.hh:250