void append_triangle (const uvector &a, const uvector &b, const uvector &c) { size_t ida = insert_point(a); size_t idb = insert_point(b); size_t idc = insert_point(c); _triangles.push_back(Mesh_triangle(ida, idb, idc)); }
void insert(int ii_live, VectorType new_point, double new_lhood){ /// :TODO: Assert size (Also below) insert_point(ii_live,new_point); insert_lhood(ii_live,new_lhood); }
LOCAL int sort_bins P2C(IVIEW_WINDOW, w, LVAL, hdata) { IViewHist h = getinternals(hdata); int i, k, low, high, val, x, y, n = IViewNumPoints(w); int changed = FALSE; StGWWinInfo *gwinfo; gwinfo = IViewWindowWinInfo(w); StGrGetContentVariables(gwinfo, &x, &y); IViewGetScreenRange(w, x, &low, &high); if (high <= low) return(FALSE); if (remove_non_showing_points(w, hdata)) changed = TRUE; for (i = 0; i < h->num_bins; i++) h->bins[i].count = 0; h->num_showing = 0; for (i = 0; i < n; i++) { if (! IViewPointMasked(w, i) && IViewPointState(w, i) != pointInvisible) { val = IViewPointScreenValue(w, x, i); k = (h->num_bins * (val - low)) / (high - low); if (k == h->num_bins && val == high) k--; /* on boundary of last bin */ if (k >= 0 && k < h->num_bins) { h->bins[k].count++; if (insert_point(w, hdata, x, i, k)) changed = TRUE; h->num_showing++; } } } return(changed); }
void arrangement::keep_arc(Arrangement_2::Edge_iterator &e, Arrangement_2 ©, Walk_pl &walk_pl) { e->set_data("none"); Conic_point_2 p; // if it is a segment if (e->curve().orientation() == CGAL::COLLINEAR) { Conic_point_2 source = e->curve().source(); Conic_point_2 target = e->curve().target(); double x = CGAL::to_double((target.x() + source.x()) /2); double y = CGAL::to_double((target.y() + source.y()) /2); Rational x_(x); Rational y_(y); p = Conic_point_2(x_,y_); } else // if it is an arc { int n = 2; approximated_point_2* points = new approximated_point_2[n + 1]; e->curve().polyline_approximation(n, points); // there is 3 points p = Conic_point_2(Rational(points[1].first),Rational(points[1].second)); } Arrangement_2::Vertex_handle v = insert_point(copy, p, walk_pl); try { if (v->face()->data() != 1) nonCriticalRegions.remove_edge(e, false, false); copy.remove_isolated_vertex(v); } catch (const std::exception exn) {} }
void sweep(elementptr head, nodeptr root){ while(head != NULL){ #ifdef DEMO draw_LineScanning(head->p1.y); cv::waitKey(0); #endif if(head->p1.y < head->p2.y) insert_point(head->p1); else if(head->p1.y > head->p2.y) delete_point(head->p2); else{ if(head->p1.x < head->p2.x) treeInterval(root, head->p1.x, head->p2.x, head->p1.y); else treeInterval(root, head->p2.x, head->p1.x, head->p1.y); } head = head->next; } }
void GraphicCanvas::process(int buttonpress, int motion, int draw) { int got_button = 0; int center_y = get_h() / 2; int out_of_order = 0; ArrayList<GraphicPoint*> *points; double *envelope; const int debug = 0; if(state == GraphicCanvas::NONE) { points = &plugin->config.points; envelope = plugin->envelope; } else { points = &temp_points; envelope = temp_envelope; } plugin->calculate_envelope(points, envelope); // spectrogram if(draw) { clear_box(0, 0, get_w(), get_h()); int niquist = plugin->PluginAClient::project_sample_rate / 2; int total_frames = plugin->get_gui_update_frames(); GraphicGUIFrame *frame = (GraphicGUIFrame*)plugin->get_gui_frame(); if(frame) { delete plugin->last_frame; plugin->last_frame = frame; } else { frame = plugin->last_frame; } // Draw most recent frame if(frame) { set_color(MEGREY); int y1 = 0; int y2 = 0; for(int i = 0; i < get_w(); i++) { int freq = Freq::tofreq(i * TOTALFREQS / get_w()); int index = (int64_t)freq * (int64_t)frame->window_size / 2 / niquist; if(index < frame->window_size / 2) { double magnitude = frame->data[index] / frame->freq_max * frame->time_max; y2 = (int)(get_h() - (DB::todb(magnitude) - INFINITYGAIN) * get_h() / -INFINITYGAIN); CLAMP(y2, 0, get_h() - 1); if(i > 0) { draw_line(i - 1, y1, i, y2); //printf(" %.0f", frame->data[index]); } y1 = y2; } } //printf( "\n"); total_frames--; } // Delete remaining frames while(total_frames > 0) { PluginClientFrame *frame = plugin->get_gui_frame(); if(frame) delete frame; total_frames--; } } // Determine if active point is out of order if(plugin->active_point_exists()) { GraphicPoint *active_point = points->get(plugin->active_point); for(int i = 0; i < points->size(); i++) { if(i == plugin->active_point) { if(i < points->size() - 1 && active_point->freq >= points->get(i + 1)->freq || i > 0 && active_point->freq <= points->get(i - 1)->freq) { out_of_order = 1; } break; } } } if(motion) { if(state == GraphicCanvas::DRAG_POINT) { int point_x = get_cursor_x() + x_diff; int point_y = get_cursor_y() + y_diff; CLAMP(point_x, 0, get_w()); CLAMP(point_y, 0, get_h()); int frequency = Freq::tofreq(point_x * TOTALFREQS / get_w()); double magnitude_db = (double)(center_y - point_y) * MAXMAGNITUDE / center_y; int minfreq = Freq::tofreq(0); int maxfreq = Freq::tofreq(TOTALFREQS - 1); CLAMP(frequency, minfreq, maxfreq); CLAMP(magnitude_db, -MAXMAGNITUDE, MAXMAGNITUDE); if(plugin->active_point >= 0) { GraphicPoint *active_point = points->get(plugin->active_point); active_point->freq = frequency; active_point->value = magnitude_db; } // Redraw with new value process(0, 0, 1); save_temps(); plugin->send_configure_change(); gui->update_textboxes(); return; } } // Magnitude bars if(draw) { set_color(GREEN); set_line_dashes(1); for(int i = 1; i < MAJOR_DIVISIONS; i++) { int y = i * get_h() / (MAJOR_DIVISIONS - 1); draw_line(0, y, get_w(), y); } set_line_dashes(0); } int y1 = 0; if(draw) set_color(WHITE); // Control points, cursor change and control point selection int new_cursor = CROSS_CURSOR; for(int i = 0; i < points->size(); i++) { GraphicPoint *point = points->get(i); int x = Freq::fromfreq(point->freq) * get_w() / TOTALFREQS; int y = freq_to_y(point->freq, points, envelope); if(draw) { y1 = y; // Draw point under cursor if out of order if(i == plugin->active_point && out_of_order) y1 = get_cursor_y() + y_diff; if(i == plugin->active_point) draw_box(x - BOX_SIZE / 2, y1 - BOX_SIZE / 2, BOX_SIZE, BOX_SIZE); else draw_rectangle(x - BOX_SIZE / 2, y1 - BOX_SIZE / 2, BOX_SIZE, BOX_SIZE); } if(motion && state == GraphicCanvas::NONE && is_event_win() && cursor_inside()) { if(get_cursor_x() >= x - BOX_SIZE / 2 && get_cursor_y() >= y - BOX_SIZE / 2 && get_cursor_x() < x + BOX_SIZE / 2 && get_cursor_y() < y + BOX_SIZE / 2) { new_cursor = UPRIGHT_ARROW_CURSOR; } } if(buttonpress && state == GraphicCanvas::NONE && is_event_win() && cursor_inside() && !got_button) { if(get_cursor_x() >= x - BOX_SIZE / 2 && get_cursor_y() >= y - BOX_SIZE / 2 && get_cursor_x() < x + BOX_SIZE / 2 && get_cursor_y() < y + BOX_SIZE / 2) { plugin->active_point = i; state = GraphicCanvas::DRAG_POINT; new_temps(); points = &temp_points; envelope = temp_envelope; x_diff = x - get_cursor_x(); y_diff = y - get_cursor_y(); got_button = 1; process(0, 0, 1); save_temps(); plugin->send_configure_change(); gui->update_textboxes(); } } } if(motion && new_cursor != get_cursor()) { set_cursor(new_cursor, 0, 1); } // Envelope line; y1 = 0; set_line_width(2); for(int i = 0; i < get_w(); i++) { int y = freq_to_y(Freq::tofreq(i * TOTALFREQS / get_w()), points, envelope); if(draw) { if(i > 0) draw_line(i - 1, y1, i, y); } y1 = y; } set_line_width(1); if(buttonpress && !got_button) { if(is_event_win() && cursor_inside()) { GraphicPoint *new_point = new GraphicPoint; new_point->freq = Freq::tofreq(get_cursor_x() * TOTALFREQS / get_w()); new_point->value = (double)(center_y - get_cursor_y()) * MAXMAGNITUDE / center_y; state = GraphicCanvas::DRAG_POINT; new_temps(); points = &temp_points; envelope = temp_envelope; insert_point(new_point); plugin->active_point = points->number_of(new_point); x_diff = 0; y_diff = 0; // Redraw with new point process(0, 0, 1); save_temps(); plugin->send_configure_change(); gui->update_textboxes(); } } if(draw) { flash(); } }
void arrangement::compute_ACScellBeginEnd() { int ncr_begin = -1; int ncr_end = -1; Walk_pl walk_pl(nonCriticalRegions); // get NCR start Rational xt(target_centre.x()); Rational yt(target_centre.y()); Conic_point_2 pt(xt,yt); Arrangement_2::Vertex_handle v = insert_point(nonCriticalRegions, pt, walk_pl); try { ncr_begin = v->face()->data(); nonCriticalRegions.remove_isolated_vertex(v); } catch (const std::exception exn) { target_centre = QPoint(target_centre.x()+1, target_centre.y()+1); compute_ACScellBeginEnd(); return; } // get NCR end Rational xe(target_centre_end.x()); Rational ye(target_centre_end.y()); Conic_point_2 pe(xe,ye); Arrangement_2::Vertex_handle w = insert_point(nonCriticalRegions, pe, walk_pl); try { ncr_end = w->face()->data(); nonCriticalRegions.remove_isolated_vertex(w); } catch (const std::exception exn) { target_centre_end = QPoint(target_centre_end.x()+1, target_centre_end.y()+1); compute_ACScellBeginEnd(); return; } // retrieve ACScell for (int i = 0; i < (int) ACScells.size(); i++) if (ACScells[i].NCR == ncr_begin) { Rational x(manipulator_centre.x()); Rational y(manipulator_centre.y()); Conic_point_2 p(x,y); Walk_pl walk(ACScells[i].arr); Arrangement_2::Vertex_handle u = insert_point(ACScells[i].arr, p, walk); try { if (!u->face()->is_unbounded()) { ACScells[i].arr.remove_isolated_vertex(u); AcscellBegin = i; break; } } catch (const std::exception exn) { manipulator_centre = QPoint(manipulator_centre.x()+1, manipulator_centre.y()+1); compute_ACScellBeginEnd(); return; } } for (int i = 0; i < (int) ACScells.size(); i++) if (ACScells[i].NCR == ncr_end) { Rational x(manipulator_centre_end.x()); Rational y(manipulator_centre_end.y()); Conic_point_2 p(x,y); Walk_pl walk(ACScells[i].arr); Arrangement_2::Vertex_handle u = insert_point(ACScells[i].arr, p, walk); try { if (!u->face()->is_unbounded()) { ACScells[i].arr.remove_isolated_vertex(u); AcscellEnd = i; break; } } catch (const std::exception exn) { manipulator_centre_end = QPoint(manipulator_centre_end.x()+1, manipulator_centre_end.y()+1); compute_ACScellBeginEnd(); return; } } }
void arrangement::compute_ACScell() { /* for (int i = 0; i < (int)convolutions.size(); ++i) for (Arrangement_2::Edge_iterator edge = convolutions[i].edges_begin(); edge != convolutions[i].edges_end(); ++edge) { convolution_r_all = Arrangement_2(convolutions[i]); insert(convolution_r_all, edge->curve()); Arrangement_2::Edge_iterator e = convolution_r_all.edges_end(); e->set_data(edge->data()); } */ /* std::cout << "edge label convo : "; for (Arrangement_2::Edge_iterator edge = convolution_r_all.edges_begin(); edge != convolution_r_all.edges_end(); ++edge) std::cout << edge->data() << " "; std::cout << std::endl; */ for (int i = 0; i < (int)point_in_faces.size(); ++i) { // do a copy Arrangement_2 copy(convolutions[0]); Observer observer(copy); // add a circle Rat_point_2 center(point_in_faces[i][0], point_in_faces[i][1]); Rat_circle_2 circle(center, r1r2 * r1r2); Conic_curve_2 conic_arc(circle); insert(copy, conic_arc); // then add rho label for arc for (Arrangement_2::Edge_iterator edge = copy.edges_begin(); edge != copy.edges_end(); ++edge) { if (edge->data().compare("") == 0) { edge->set_data("rho_"); edge->twin()->set_data("rho_"); } } Walk_pl walk_pl(copy); std::vector<std::vector<double> > points; compute_pointInCells(copy, points); for (int j = 0; j < (int)points.size(); ++j) { double _x = point_in_faces[i][0] - points[j][0]; double _y = point_in_faces[i][1] - points[j][1]; if (r1r2 < sqrt(_x * _x + _y * _y)) { Rational x_(points[j][0]); Rational y_(points[j][1]); Conic_point_2 p(x_,y_); Arrangement_2::Vertex_handle v = insert_point(copy, p, walk_pl); try { ACScell cell(i); Arrangement_2::Ccb_halfedge_circulator first_outer_ccb = v->face()->outer_ccb(); Arrangement_2::Ccb_halfedge_circulator outer_ccb = v->face()->outer_ccb(); do { // for retrieving ACScell Begin and End insert(cell.arr, outer_ccb->curve()); // then continue cell.addLabel(outer_ccb->data()); ++outer_ccb; } while (outer_ccb != first_outer_ccb); ACScells.push_back(cell); } catch (const std::exception exn) {} } } } // clean ACScells for (int i = 0; i < (int)ACScells.size(); ++i) ACScells[i].cleanLabels(); // compute ACScells id int cpt = 0; int previous = 0; for (int i = 0; i < (int)ACScells.size(); ++i) { if (previous != ACScells[i].NCR) { cpt = 0; previous = ACScells[i].NCR; } ACScells[i].id = std::to_string(ACScells[i].NCR) + "." + std::to_string(cpt); ++cpt; } }
void arrangement::compute_pointInCells(Arrangement_2 &arr, std::vector<std::vector<double> > &points) { Walk_pl walk_pl(arr); int cpt = 0; for (Arrangement_2::Face_iterator face = arr.faces_begin(); face != arr.faces_end(); ++face) { if (face->is_unbounded()) face->set_data(-1); else { // set data to each face face->set_data(cpt++); // find a point in this face Arrangement_2::Ccb_halfedge_circulator previous = face->outer_ccb(); Arrangement_2::Ccb_halfedge_circulator first_edge = face->outer_ccb(); Arrangement_2::Ccb_halfedge_circulator edge = face->outer_ccb(); ++edge; do { std::vector<double> p1 = getPointMiddle(previous); std::vector<double> p2 = getPointMiddle(edge); std::vector<double> m; m.push_back((p1[0]+p2[0])/2); m.push_back((p1[1]+p2[1])/2); Rational x_(m[0]); Rational y_(m[1]); Conic_point_2 p(x_,y_); Arrangement_2::Vertex_handle v = insert_point(arr, p, walk_pl); try { if (v->face()->data() == (cpt-1)) { bool flag = false; // test if it is not in holes and not in unbounded face for (int i = 0; i < (int) convolutions_o.size(); ++i) { Walk_pl wpl(convolutions_o[i]); Arrangement_2::Vertex_handle t = insert_point(convolutions_o[i], p, wpl); if (t->face()->data() == 1) { convolutions_o[i].remove_isolated_vertex(t); break; } else if (t->face()->data() == 2 || t->face()->data() == 0) { flag = true; convolutions_o[i].remove_isolated_vertex(t); break; } } // then continue if (!flag) points.push_back(m); else { --cpt; face->set_data(-1); } arr.remove_isolated_vertex(v); break; } arr.remove_isolated_vertex(v); } catch (const std::exception exn) {} previous = edge; ++edge; } while (edge != first_edge); } } }
void pcmPlay(struct pcmConf *ipcmPlay, char buff[], int len) { int i = 0; int k; int ret; int cValid = 0; int cInvalid = 0; int cbit = 0; int bi = ipcmPlay->frames; char *pb = ipcmPlay->buffer; memset(pb,0,sizeof(ipcmPlay->size)); /* 人为插入一个补足点,用于平滑初始音频 */ cInvalid++; insert_point(ipcmPlay,INVALID_LEVEL, pb, bi,cValid, cInvalid); //printf("*"); pb+=bi; cbit +=bi; #ifdef PADDING_INVALID_CODE for(i = len-1; i >= 0; i--){ for(k=7; k>=0; k--){ if( (cbit + bi) > ipcmPlay->size){ /* 防止数组越界,需要先清空数据 */ fork_play(ipcmPlay, cbit, 0); pb = ipcmPlay->buffer; cbit = 0; } if((buff[i] & (1<<k)) == 0){ /* 有效电平 */ cValid++; cInvalid = 0; insert_point(ipcmPlay,VALID_LEVEL, pb, bi, cValid, cInvalid); printf("."); }else{ /* 无效电平或间隔 */ cValid = 0; cInvalid++; insert_point(ipcmPlay,INVALID_LEVEL, pb, bi,cValid, cInvalid); printf("*"); } cbit += bi; pb += bi; } } printf("\n"); if(cbit != 0){ fork_play(ipcmPlay, cbit, 1); // the last player } #else unsigned short bitLen = *(unsigned short *)buff; char remainderBit = bitLen % 8; if(remainderBit > 0){ k = remainderBit - 1; }else{ k = 7; } for(i = len-1; i >=2; i--){ for(; k>=0; k--){ if( (cbit + bi) > ipcmPlay->size){ /* 防止数组越界,需要先清空数据 */ fork_play(ipcmPlay, cbit,0); pb = ipcmPlay->buffer; cbit = 0; } if((buff[i] & (1<<k)) == 0){ /* 有效电平 */ cValid++; cInvalid = 0; insert_point(ipcmPlay,VALID_LEVEL, pb, bi, cValid, cInvalid); //printf("."); }else{ /* 无效电平或间隔 */ cValid = 0; cInvalid++; insert_point(ipcmPlay,INVALID_LEVEL, pb, bi,cValid, cInvalid); //printf("*"); } cbit += bi; pb += bi; } k = 7; } //printf("\n"); if(cbit != 0){ fork_play(ipcmPlay, cbit, 1); } #endif }
void qshape_create_tool_t::mouse_press_event( ui::image_view_t& view, QMouseEvent *event) { push_x_ = last_x_ = event->x(); push_y_ = last_y_ = event->y(); Imath::V2f p( view.screen_to_world( Imath::V2i( event->x(), event->y()))); insert_point_mode_ = false; if( !new_shape_) { if( parent_->selected()) { float max_dist = 4.0f / view.pixel_scale(); if(( IECore::closestPointInBox( p, parent_->selected()->control_points_bounding_box()) - p).length2() <= max_dist) { float t = param_closest_to_point( parent_->selected(), p, max_dist * max_dist); if( t >= 0) { insert_point_mode_ = true; if( t - std::floor( t) != 0.0f) { std::auto_ptr<undo::command_t> c( new undo::modify_qshape_command_t( parent_, true)); insert_point( t); ui::anim_editor_t::Instance().recreate_tracks( parent_); ui::anim_editor_t::Instance().update(); ui::anim_editor_t::Instance().update_tree(); if( parent_->selected()->active()) { parent()->notify(); parent()->notify_dependents(); } undo::undo_stack_t::Instance().push_back( c); ui::user_interface_t::Instance().update(); } return; } } } parent_->deselect_all(); std::auto_ptr<shape_t> p( parent()->create_shape()); new_shape_ = p.release(); new_shape_->create_params(); new_shape_->select( true); view.update(); } if( !new_shape_->empty()) { Imath::V2i q( push_x_, push_y_); Imath::V2i r( view.world_to_screen( new_shape_->front().p1())); int f = ( q - r).length2(); if( f < 25) { close_shape(); view.update(); return; } } new_shape_->push_back( qshape::triple_t( p)); triple_p_ = &new_shape_->back(); view.update(); return; }
int main () { Arrangement_2 arr; Point_2 ps[N_POINTS]; Vertex_handle vhs[N_POINTS]; bool valid; int k; ps[0] = Point_2 (2, 2); ps[1] = Point_2 (2, 7); ps[2] = Point_2 (4, 9); ps[3] = Point_2 (4, 5); ps[4] = Point_2 (5, 3); ps[5] = Point_2 (7, 1); ps[6] = Point_2 (7, 5); ps[7] = Point_2 (7, 7); ps[8] = Point_2 (9, 3); ps[9] = Point_2 (9, 6); for (k = 0; k < N_POINTS; k++) { vhs[k] = insert_point (arr, ps[k]); } arr.insert_from_left_vertex (Segment_2 (Point_2 (2, 7), Point_2 (4, 7)), vhs[1]); TEST_VALIDITY(1); arr.insert_from_right_vertex (Segment_2 (Point_2 (6, 6), Point_2 (7, 5)), vhs[6]); TEST_VALIDITY(2); arr.insert_at_vertices (Segment_2 (Point_2 (7, 1), Point_2 (9, 3)), vhs[5], vhs[8]); TEST_VALIDITY(3); arr.insert_at_vertices (Segment_2 (Point_2 (7, 5), Point_2 (9, 3)), vhs[6], vhs[8]); TEST_VALIDITY(4); arr.insert_from_right_vertex (Segment_2 (Point_2 (1, 1), Point_2 (2, 7)), vhs[1]); TEST_VALIDITY(5); insert_non_intersecting_curve (arr, Segment_2 (Point_2 (1, 1), Point_2 (7, 1))); TEST_VALIDITY(6); insert_non_intersecting_curve (arr, Segment_2 (Point_2 (4, 7), Point_2 (6, 6))); TEST_VALIDITY(7); insert_non_intersecting_curve (arr, Segment_2 (Point_2 (2, 7), Point_2 (3, 3))); TEST_VALIDITY(8); insert_non_intersecting_curve (arr, Segment_2 (Point_2 (3, 3), Point_2 (7, 1))); TEST_VALIDITY(9); arr.insert_at_vertices (Segment_2 (Point_2 (7, 5), Point_2 (9, 6)), vhs[6], vhs[9]); TEST_VALIDITY(10); std::cout << "Arrangement size:" << " V = " << arr.number_of_vertices() << " (" << arr.number_of_isolated_vertices() << " isolated)" << ", E = " << arr.number_of_edges() << ", F = " << arr.number_of_faces() << std::endl; // Check the validity more thoroughly. valid = is_valid(arr); std::cout << "Arrangement is " << (valid ? "valid." : "NOT valid!") << std::endl; return (0); }