vector<pair<double,double> > PoissonDiskSampling::Generate(){ point first_point(rand() % m_width, rand() % m_height); m_process.push_back(first_point); m_sample.push_back(make_pair(first_point.x, first_point.y)); int first_point_x = first_point.x/m_cell_size; int first_point_y = first_point.y/m_cell_size; m_grid[first_point_x][first_point_y] = new point(first_point); while( !m_process.empty() ){ int new_point_index = rand() % m_process.size(); point new_point = m_process[new_point_index]; m_process.erase(m_process.begin() + new_point_index); for(int i = 0; i < m_point_count; i++){ point new_point_around = generatePointAround(new_point); if(inRectangle(new_point_around) && !inNeighbourhood(new_point_around)){ // cout << "Nuevo punto: (" << new_point_around.x << ", " << new_point_around.y << ")" << endl; m_process.push_back(new_point_around); m_sample.push_back(make_pair(new_point_around.x, new_point_around.y)); int new_point_x = new_point_around.x/m_cell_size; int new_point_y = new_point_around.y/m_cell_size; m_grid[new_point_x][new_point_y] = new point(new_point_around); } } } return m_sample; }
bool QcMapGestureArea::can_start_pinch() { // qInfo(); int number_of_points = m_all_points.count(); const int start_drag_distance = qApp->styleHints()->startDragDistance(); if (number_of_points >= 2) { QcVectorDouble p1 = first_point().pos(); QcVectorDouble p2 = second_point().pos(); if (qAbs(p1.x() - m_start_position1.x()) > start_drag_distance or qAbs(p1.y() - m_start_position1.y()) > start_drag_distance or qAbs(p2.x() - m_start_position2.x()) > start_drag_distance or qAbs(p2.y() - m_start_position2.y()) > start_drag_distance) { m_pinch.m_event.set_angle(m_two_touch_angle); m_pinch.m_event.set_center(m_current_position); m_pinch.m_event.set_number_of_points(number_of_points); m_pinch.m_event.set_point1(p1); m_pinch.m_event.set_point2(p2); m_pinch.m_event.set_accepted(true); emit pinch_started(&m_pinch.m_event); return m_pinch.m_event.accepted(); } } return false; }
bool QcMapGestureArea::can_start_pan() { qInfo() << first_point().pos() << m_start_position1; if (m_all_points.count() == 0 or (m_accepted_gestures & PanGesture) == 0) // Fixme: to func ? return false; // Check if thresholds for normal panning are met. // (normal panning vs flicking: flicking will start from mouse release event). const int start_drag_distance = qApp->styleHints()->startDragDistance() * 2; QcVectorDouble p1 = first_point().pos(); QcVectorDouble delta_from_press = p1 - m_start_position1; return (qAbs(delta_from_press.x()) >= start_drag_distance or qAbs(delta_from_press.y()) >= start_drag_distance); }
void QcMapGestureArea::update_one_touch_point() { qInfo(); m_current_position = first_point().pos(); update_velocity_list(m_current_position); }
IShape* UICircle::LoadShape(std::vector<std::string> i_load_data) { Point first_point(atof(i_load_data[1].c_str()), atof(i_load_data[2].c_str())); Point second_point(atof(i_load_data[3].c_str()), atof(i_load_data[4].c_str())); UICircle* p_circle = new UICircle(first_point, second_point); p_circle->SetOutlineColor((COLORREF)atof(i_load_data[5].c_str())); p_circle->SetBrushColor((COLORREF)atof(i_load_data[6].c_str())); return p_circle; }
void QcMapGestureArea::start_pinch() { // qInfo(); m_pinch.m_last_angle = m_two_touch_angle; m_pinch.m_last_point1 = first_point().pos(); m_pinch.m_last_point2 = second_point().pos(); m_pinch.m_start_distance = m_distance_between_touch_points; m_pinch.m_zoom.m_previous = m_map->zoom_level(); m_pinch.m_zoom.m_start = m_map->zoom_level(); }
void QcMapGestureArea::start_one_touch_point() { qInfo(); m_start_position1 = first_point().pos(); m_last_position_for_velocity = m_start_position1; m_last_position_for_velocity_time.start(); QcWgsCoordinate start_coordinate = m_map->to_coordinate(m_start_position1, false); // Ensures a smooth transition for panning (m_start_coordinate and m_touch_center_coordinate are cleared in clear_touch_data) // Fixme: ??? m_start_coordinate.set_longitude(start_coordinate.longitude() + m_start_coordinate.longitude() - m_touch_center_coordinate.longitude()); m_start_coordinate.set_latitude(start_coordinate.latitude() + m_start_coordinate.latitude() - m_touch_center_coordinate.latitude()); }
//sample sphere void sampleSphere(Point cenPoint, float r, float grid_length, MyPointCloud& mpt){ int woof_num=(int)((PII*r)/grid_length); PointCloudPtr sample_clound(new PointCloud); PointCloudPtr cloud_woof_points(new PointCloud); PointCloudPtr cloud_cen_points(new PointCloud); Point startPoint(cenPoint.x,cenPoint.y,cenPoint.z+r); sample_clound->push_back(startPoint); /*Eigen::Vector3d normal0; normal0 << 0, 0, r; normal0.normalize(); Eigen::Vector3d normal1; normal1 << 0, 1, 0; normal1.normalize();*/ float ang=grid_length/r; for(int i=0;i<woof_num;i++){ float new_z=0; float new_x=0; rotatePoint2ByPoint2(startPoint.z,startPoint.x,cenPoint.z,cenPoint.x,ang*(i+1),&new_z,&new_x); cloud_woof_points->push_back(Point(new_x,cenPoint.y,new_z)); cloud_cen_points->push_back(Point(cenPoint.x,cenPoint.y,new_z)); } for(int i=0;i<woof_num;i++){ Point cen_cir(cloud_cen_points->at(i).x,cloud_cen_points->at(i).y,cloud_cen_points->at(i).z); Point first_point(cloud_woof_points->at(i).x,cloud_woof_points->at(i).y,cloud_woof_points->at(i).z); float cir_r=sqrt(pow(first_point.x-cen_cir.x, 2)+pow(first_point.y-cen_cir.y, 2)+pow(first_point.z-cen_cir.z, 2)); int num=(int)((2*PII*cir_r)/grid_length); float ang_tem=grid_length/cir_r; for(int j=0;j<num;j++){ float new_x=0; float new_y=0; rotatePoint2ByPoint2(first_point.x,first_point.y,cen_cir.x,cen_cir.y,ang_tem*j,&new_x,&new_y); sample_clound->push_back(Point(new_x,new_y,cen_cir.z)); } } PointCloud2MyPointCloud(sample_clound, mpt); }
void QcMapGestureArea::start_two_touch_points() { // qInfo(); m_start_position1 = first_point().pos(); m_start_position2 = second_point().pos(); QcVectorDouble start_position = middle(m_start_position1, m_start_position2); // Fixme: duplicated code, excepted middle m_last_position_for_velocity = start_position; m_last_position_for_velocity_time.start(); QcWgsCoordinate start_coordinate = m_map->to_coordinate(start_position, false); m_start_coordinate.set_longitude(start_coordinate.longitude() + m_start_coordinate.longitude() - m_touch_center_coordinate.longitude()); m_start_coordinate.set_latitude(start_coordinate.latitude() + m_start_coordinate.latitude() - m_touch_center_coordinate.latitude()); }
void QcMapGestureArea::update_pinch() { // qInfo(); // Calculate the new zoom level if we have distance (>= 2 touchpoints), otherwise stick with old. qreal new_zoom_level = m_pinch.m_zoom.m_previous; if (m_distance_between_touch_points) { new_zoom_level = // How much further/closer the current touchpoints are (in pixels) compared to pinch start ((m_distance_between_touch_points - m_pinch.m_start_distance) * // How much one pixel corresponds in units of zoomlevel (and multiply by above delta) (m_pinch.m_zoom.maximum_change / ((width() + height()) / 2))) + // Add to starting zoom level. Sign of (dist-pinchstartdist) takes care of zoom in / out m_pinch.m_zoom.m_start; } // qreal delta_angle = m_pinch.m_last_angle - m_two_touch_angle; // if (delta_angle > 180) // delta_angle -= 360; // else if (delta_angle < -180) // delta_angle += 360; m_pinch.m_last_angle = m_two_touch_angle; m_pinch.m_last_point1 = first_point().pos(); m_pinch.m_last_point2 = second_point().pos(); m_pinch.m_event.set_angle(m_two_touch_angle); m_pinch.m_event.set_center(m_current_position); m_pinch.m_event.set_number_of_points(m_all_points.count()); m_pinch.m_event.set_point1(m_pinch.m_last_point1); m_pinch.m_event.set_point2(m_pinch.m_last_point2); m_pinch.m_event.set_accepted(true); emit pinch_updated(&m_pinch.m_event); if (m_accepted_gestures & PinchGesture) { // Take maximum and minimumzoomlevel into account qreal per_pinch_minimum_zoom_level = qMax(m_pinch.m_zoom.m_start - m_pinch.m_zoom.maximum_change, static_cast<qreal>(m_pinch.m_zoom.m_interval.inf())); qreal per_pinch_maximum_zoom_level = qMin(m_pinch.m_zoom.m_start + m_pinch.m_zoom.maximum_change, static_cast<qreal>(m_pinch.m_zoom.m_interval.sup())); new_zoom_level = qMin(qMax(per_pinch_minimum_zoom_level, new_zoom_level), per_pinch_maximum_zoom_level); m_map->set_zoom_level(new_zoom_level); m_pinch.m_zoom.m_previous = new_zoom_level; } }
void QcMapGestureArea::update_two_touch_points() { // qInfo(); QcVectorDouble p1 = first_point().pos(); QcVectorDouble p2 = second_point().pos(); QcVectorDouble delta = p2 - p1; m_distance_between_touch_points = delta.magnitude(); m_current_position = middle(p1, p2); update_velocity_list(m_current_position); m_two_touch_angle = delta.orientation(); // Fixme: required ? if (m_two_touch_angle > 180) m_two_touch_angle -= 360; }
void parse_input(std::vector<std::shared_ptr<line_segment>>& polygon, std::ifstream& in) { std::string temp = ""; std::getline(in, temp); int n = std::atoi(temp.c_str()); std::getline(in, temp); std::shared_ptr<point> first_point(new point(temp)); std::shared_ptr<point> previous_point = first_point; for (int i = 0; i < n - 1; ++i) { std::getline(in, temp); std::shared_ptr<point> current_point(new point(temp)); polygon.push_back(std::shared_ptr<line_segment>(new line_segment(previous_point, current_point))); previous_point = current_point; } polygon.push_back(std::shared_ptr<line_segment>(new line_segment(previous_point, first_point))); }
void MainPlanner:: writeValue(vector<vector<int> > digitsVector, float omega){ float scale = 1.5; float x0 = -80; vector<vector<vector<PointNode> > > digits = genDigits(scale); vector<vector<vector<PointNode> > > digit_traj; vector<PointNode> current_traj; int dt = 4; //vector<PointNode> zero_digit = get_rotated(digits[0], 0, 1, millisecondsNow()); for (int i = 0; i < digitsVector.size(); i++){ for (int j = 0; j < digitsVector[i].size(); ++j) { digit_traj.push_back(digits[digitsVector[i][j]]); } } LONGLONG baseT = millisecondsNow(); // 1.256 for (int k = 0; k < digitsVector.size(); ++k) { for (int i = 0; i < digit_traj.size(); i++){ for (int j = 0; j < digit_traj[i].size(); ++j) { float offsetX = (i * (2 + 0.3)) * scale + x0; baseT = millisecondsNow(); current_traj = get_rotated(digit_traj[i][j], 0.566, dt, baseT, offsetX, k * 15 * scale - 30); vec2 first_point(current_traj[0].point.x, current_traj[0].point.y); arm.moveToPoint(first_point); Sleep(MOTOR_DELAY); arm.lowerArm(); Sleep(DROP_TIME); arm.followTrajectory(current_traj); Sleep(MOTOR_DELAY); arm.raiseArm(); Sleep(DROP_TIME); } }//baseT += current_traj.size() * dt + 2 * DROP_TIME + 2 * MOTOR_DELAY; } }
bool QcMapGestureArea::is_press_and_hold() { qInfo(); // if (!m_map) // return false; if (!m_all_points.size()) return false; if (is_pan_active() or is_pinch_active()) return false; // if (m_press_time.isValid() and m_press_time.elapsed() > MINIMUM_PRESS_AND_HOLD_TIME) { QcVectorDouble p1 = first_point().pos(); QcVectorDouble delta_from_press = p1 - m_start_position1; return (qAbs(delta_from_press.x()) <= MAXIMUM_PRESS_AND_HOLD_JITTER or qAbs(delta_from_press.y()) <= MAXIMUM_PRESS_AND_HOLD_JITTER); // } else // return false; }
Point last_point() const { assert(first_point() == this->paths.back().polyline.points.back()); return first_point(); }