59 #define OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_CC
64 #include <OpenMesh/Core/System/config.hh>
68 #include <OpenMesh/Tools/Subdivider/Adaptive/Composite/RuleInterfaceT.hh>
74 namespace Subdivider {
86 typename Mesh::VertexIter v_it;
87 typename Mesh::FaceIter f_it;
88 typename Mesh::EdgeIter e_it;
89 const typename Mesh::Point zero_point(0.0, 0.0, 0.0);
92 for (v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it)
94 mesh_.data(*v_it).set_state(0);
95 mesh_.data(*v_it).set_final();
96 mesh_.data(*v_it).set_position(0, mesh_.point(*v_it));
100 for (f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it)
102 mesh_.data(*f_it).set_state(0);
103 mesh_.data(*f_it).set_final();
104 mesh_.data(*f_it).set_position(0, zero_point);
108 for (e_it = mesh_.edges_begin(); e_it != mesh_.edges_end(); ++e_it)
110 mesh_.data(*e_it).set_state(0);
111 mesh_.data(*e_it).set_final();
112 mesh_.data(*e_it).set_position(0, zero_point);
118 int n_subdiv_rules_ = 0;
122 for (
size_t i=0; i < n_rules(); ++i) {
124 if (rule_sequence_[i]->type()[0] ==
'T' ||
125 rule_sequence_[i]->type()[0] ==
't')
128 subdiv_rule_ = rule_sequence_[i];
129 subdiv_type_ = rule_sequence_[i]->subdiv_type();
135 assert(n_subdiv_rules_ == 1);
137 if (n_subdiv_rules_ != 1)
139 ::omerr() <<
"Error! More than one subdivision rules not allowed!\n";
144 assert(subdiv_type_ == 3 || subdiv_type_ == 4);
146 if (subdiv_type_ != 3 && subdiv_type_ != 4)
148 ::omerr() <<
"Error! Unknown subdivision type in sequence!" << std::endl;
157 for (
size_t i = 0; i < n_rules(); ++i)
159 rule_sequence_[i]->set_subdiv_type(subdiv_type_);
160 rule_sequence_[i]->set_n_rules(n_rules());
161 rule_sequence_[i]->set_number(i);
162 rule_sequence_[i]->set_prev_rule(rule_sequence_[(i+n_rules()-1)%n_rules()]);
163 rule_sequence_[i]->set_subdiv_rule(subdiv_rule_);
171 #define MOBJ mesh_.deref
172 #define TVH to_vertex_handle
173 #define HEH halfedge_handle
174 #define NHEH next_halfedge_handle
175 #define PHEH prev_halfedge_handle
176 #define OHEH opposite_halfedge_handle
183 std::vector<typename Mesh::HalfedgeHandle> hh_vector;
187 t_rule()->number() + 1 +
188 ((int)floor((
float)(mesh_.data(_fh).state() - t_rule()->number() - 1)/n_rules()) + 1) * n_rules();
190 int new_vertex_level =
191 new_face_level + l_rule()->number() - t_rule()->number();
197 vh[0] = mesh_.TVH(mesh_.HEH(_fh));
198 vh[1] = mesh_.TVH(mesh_.NHEH(mesh_.HEH(_fh)));
199 vh[2] = mesh_.TVH(mesh_.PHEH(mesh_.HEH(_fh)));
203 if (subdiv_type_ == 4)
208 if (mesh_.data(_fh).final())
212 for (; fh_it.is_valid(); ++fh_it)
214 hh_vector.push_back(mesh_.PHEH(mesh_.OHEH(*fh_it)));
222 typename Mesh::HalfedgeHandle red_hh(mesh_.data(_fh).red_halfedge());
224 hh_vector.push_back(mesh_.PHEH(mesh_.OHEH(mesh_.NHEH(red_hh))));
225 hh_vector.push_back(mesh_.PHEH(mesh_.OHEH(mesh_.PHEH(mesh_.OHEH(red_hh)))));
231 if (t_rule()->number() > 0)
232 t_rule()->prev_rule()->raise(_fh, new_face_level-1);
235 t_rule()->raise(_fh, new_face_level);
237 #if 0 // original code
238 assert(MOBJ(_fh).state() >=
239 subdiv_rule_->number()+1+(int) (MOBJ(_fh).state()/n_rules())*n_rules());
240 #else // improved code (use % operation and avoid floating point division)
241 assert( mesh_.data(_fh).state() >= ( t_rule()->number()+1+generation(_fh) ) );
245 if (subdiv_type_ == 3)
250 l_rule()->raise(new_vh, new_vertex_level);
253 if (subdiv_type_ == 4)
255 typename Mesh::HalfedgeHandle hh;
258 while (!hh_vector.empty()) {
260 hh = hh_vector.back();
261 hh_vector.pop_back();
264 new_vh = mesh_.TVH(mesh_.NHEH(hh));
267 l_rule()->raise(new_vh, new_vertex_level);
272 l_rule()->raise(vh[0], new_vertex_level);
273 l_rule()->raise(vh[1], new_vertex_level);
274 l_rule()->raise(vh[2], new_vertex_level);
285 int new_vertex_state = generation(_vh) + l_rule()->number() + 1;
288 l_rule()->raise(_vh, new_vertex_state);
299 typename RuleSequence::const_iterator it = rule_sequence_.begin();
301 if ( it != rule_sequence_.end() )
304 for (++it; it != rule_sequence_.end(); ++it )
307 seq += (*it)->type();
bool initialize(void)
Initialize faces, edges, vertices, and rules.
std::string rules_as_string(const std::string &_sep=" * ") const
Return the sequence as string.
void refine(typename M::FaceHandle &_fh)
Refine one face.
Kernel::Point Point
Coordinate type.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Kernel::FaceHalfedgeIter FaceHalfedgeIter
Circulator.