void YSlim::decimate(int target_num_vert) { init_border(); pack_vertex(); int t1 = clock(); init_quadrics(); select_pair(); int id_v1, id_v2; double vx, vy, vz; vert_cnt_ = 0; for(int i=0; i<vertices.size(); ++i) { if(find(i) == i) vert_cnt_++; } while(vert_cnt_ > target_num_vert) { //assert(!errors.empty()); //assert(false); if(errors.empty()) break; Error nd = errors.top(); errors.pop(); if(is_merged(nd.u_, nd.v_)) continue; if(nd.error_ > Bound_Constraint * 3) continue; id_v1 = find(nd.u_); id_v2 = find(nd.v_); if(id_v1 >= vertices.size() || id_v2 >= vertices.size())continue; if(id_v1 != nd.u_ || id_v2 != nd.v_) continue; //merge the smaller set to the bigger set //make id_v1 the bigger one if(adj[id_v1].size() < adj[id_v2].size()) swap(id_v1, id_v2); //update quadric of v1 quadrics[id_v1] = quadrics[id_v1] + quadrics[id_v2]; //merge the errors of id_v2 to id_v1 while(adj[id_v2].size() > 0) { int x = adj[id_v2].back(); if(find(x) == x && x != id_v2) add_error(x, id_v1); adj[id_v2].pop_back(); } //printf("merging %d %d\n", id_v1, id_v2); //merge the point of id_v2 to id_v1 p_[id_v2] = p_[id_v1]; //decrease the vertex count vert_cnt_--; } update_faces(); int t2 = clock(); decimate_time_ = t2 - t1; //Log::log("decimate: %d ms\n", t2 - t1); }
bool cell::garbage_collectible() const { return !(get_data_type() != type::null || is_merged() || has_comment() || has_formula() || has_style()); }