void cast_ray(double mag, double theta, double far) { line cast_ray, segment; line_point inter1, inter2; double param1, param2; bool b1 = false; bool b2 = false; double dx, dy; double sintheta = sin(theta); double costheta = cos(theta); cast_ray.p1.x = get_player_x(); cast_ray.p1.y = get_player_y(); cast_ray.p2.x = get_player_x() + mag * costheta; cast_ray.p2.y = get_player_y() + mag * sintheta; //TODO: Use actual segments here instead of test values segment.p1.x = (14 + 0.5) * TILE_DIM; segment.p1.y = (0 + 0.5) * TILE_DIM; segment.p2.x = (14 + 0.5) * TILE_DIM; segment.p2.y = (9 + 0.5) * TILE_DIM; b1 = get_intersection(cast_ray, segment, &inter1, ¶m1); /*segment.p1.x = (25 + 0.5) * TILE_DIM; segment.p1.y = (0 + 0.5) * TILE_DIM; segment.p2.x = (25 + 0.5) * TILE_DIM; segment.p2.y = (9 + 0.5) * TILE_DIM; b2 = get_intersection(cast_ray, segment, &inter2, ¶m2);*/ segment.p1.x = (14 + 0.5) * TILE_DIM; segment.p1.y = (9 + 0.5) * TILE_DIM; segment.p2.x = (25 + 0.5) * TILE_DIM; segment.p2.y = (9 + 0.5) * TILE_DIM; b2 = get_intersection(cast_ray, segment, &inter2, ¶m2); //TODO END if (b1 && param1 <= param2) { RAYS[RAY_INDEX].l.p1 = cast_ray.p1; RAYS[RAY_INDEX].l.p2 = inter1; } else if (b2 && param2 < param1) { RAYS[RAY_INDEX].l.p1 = cast_ray.p1; RAYS[RAY_INDEX].l.p2 = inter2; } else { RAYS[RAY_INDEX].l.p1 = cast_ray.p1; RAYS[RAY_INDEX].l.p2.x = get_player_x() + (far ? 1000 : mag) * costheta; RAYS[RAY_INDEX].l.p2.y = get_player_y() + (far ? 1000 : mag) * sintheta; } dy = RAYS[RAY_INDEX].l.p2.y - RAYS[RAY_INDEX].l.p1.y; dx = RAYS[RAY_INDEX].l.p2.x - RAYS[RAY_INDEX].l.p1.x; RAYS[RAY_INDEX].theta = atan2(dy, dx); if (RAYS[RAY_INDEX].theta < 0) { RAYS[RAY_INDEX].theta = 2 * PI - RAYS[RAY_INDEX].theta; } RAY_INDEX++; }
bool get_intersection(const point* pol, int n, const point& p1, const point& p2, point& c1, point& c2) { int p_l = e[(lower_bound(e, e + n, edge(-1, p1 - p2)) - e) % n].id; int p_r = e[(lower_bound(e, e + n, edge(-1, p2 - p1)) - e) % n].id; if (sgn((p2 - p1) * (pol[p_l] - p1)) * sgn((p2 - p1) * (pol[p_r] - p1)) >= 0) return false; l1 = p2, l2 = p1; int k1 = (lower_bound(pol + p_l, pol + (p_r < p_l ? p_r + n : p_r) + 1, p1, is_less) - pol) % n; l1 = p1, l2 = p2; int k2 = (lower_bound(pol + p_r, pol + (p_l < p_r ? p_l + n : p_l) + 1, p2, is_less) - pol) % n; c1 = get_intersection(p1, p2, pol[k1], pol[(k1 + n - 1) % n]); c2 = get_intersection(p1, p2, pol[k2], pol[(k2 + n - 1) % n]); return true; }
TEST_P(window_intersection_test, intersect_to_partially_right1) { double end_pos = w0.get_end_pos(); sample_window w(end_pos - batch_interval*1, batch_interval, 4); std::pair<int, int> intersection = get_intersection(w0, w); ASSERT_EQ(std::max(0, n-1), intersection.first); ASSERT_EQ(n, intersection.second); }
TEST_P(window_intersection_test, intersect_to_totally_right2) { double end_pos = w0.get_end_pos(); sample_window w(end_pos + batch_interval*1.5, batch_interval, 1); std::pair<int, int> intersection = get_intersection(w0, w); ASSERT_EQ(tested.no_index(), intersection.first); ASSERT_EQ(tested.no_index(), intersection.second); }
/* Calculate Fitch cost of a subtree */ int fitch(treenode * node, int *label, int range){ int i; int cost = 0; if (node->left){ int l_left[range]; int l_right[range]; for (i=0;i<range;i++){ l_left[i] = -1; l_right[i] = -1; } int c_left = fitch(node->left,l_left,range); int c_right = fitch(node->right,l_right,range); if(!(get_intersection(l_left,l_right,range,label))){ cost++; } cost += c_left + c_right; }else{ label[0] = (*node).chars[0]; } return cost; }
TEST_P(window_intersection_test, intersect_to_overlap3) { int i = std::min(2, n); int j = std::max(i, n-1); ASSERT_LE(i, j); sample_window w(start_pos+batch_interval*(i-0.5), batch_interval, j-i); std::pair<int, int> intersection = get_intersection(w0, w); ASSERT_EQ(tested.no_index(), intersection.first); ASSERT_EQ(tested.no_index(), intersection.second); }
void get_intersection(point* pol1, int n1, const point& p1, const point& p2, point* pol2, int& n2) { n2 = 0; if (n1 == 0) return; point v = p2 - p1; int last_s = sgn(v * (pol1[n1 - 1] - p1)); for (int i = 0; i < n1; ++i) { int s = sgn(v * (pol1[i] - p1)); if (s == 0) { pol2[n2++] = pol1[i]; } else if (s < 0) { if (last_s > 0) pol2[n2++] = get_intersection(p1, p2, i == 0 ? pol1[n1 - 1] : pol1[i - 1], pol1[i]); } else if (s > 0) { if (last_s < 0) pol2[n2++] = get_intersection(p1, p2, i == 0 ? pol1[n1 - 1] : pol1[i - 1], pol1[i]); pol2[n2++] = pol1[i]; } last_s = s; } }
burst_result::burst_result( const input_window& input, double scaling_param, double gamma, double costcut_threshold, const burst_result& prev_result, int max_reuse_batches) { const std::vector<batch_input>& input_batches = input.get_batches(); const size_t n = input.get_batch_size(); const int max_reuse = (std::min)(max_reuse_batches, static_cast<int>(n)); // make vectors for engine std::vector<uint32_t> d_vec, r_vec; std::vector<double> burst_weights; d_vec.reserve(n); r_vec.reserve(n); burst_weights.reserve(n); for (size_t i = 0; i < n; ++i) { d_vec.push_back(input_batches[i].d); r_vec.push_back(input_batches[i].r); burst_weights.push_back(-1); // uncalculated } // reuse batch weights if (prev_result.p_) { const result_window& prev = *prev_result.p_; if (prev.get_start_pos() <= input.get_start_pos()) { const std::pair<int, int> intersection = get_intersection(prev, input); const std::vector<batch_result>& prev_results = prev.get_batches(); for (int i = 0, j = intersection.first; i < max_reuse && j < intersection.second; ++i, ++j) { burst_weights[i] = prev_results[j].burst_weight; } } } // doit burst::burst_detect(d_vec, r_vec, burst_weights, scaling_param, gamma, costcut_threshold); // store result p_.reset(new result_window(input, burst_weights)); }
t_intersect cylinder(t_pov pov, t_coordinate rayvector, t_object *object) { double a; double b; double c; double delta; t_intersect intersect; intersect.k = 0; intersect.object = object; transform_pov(&pov, &rayvector, object); a = SQUARE(rayvector.x) + SQUARE(rayvector.y); b = 2 * (pov.x * rayvector.x + pov.y * rayvector.y); c = SQUARE(pov.x) + SQUARE(pov.y) - SQUARE(object->parameter); delta = SQUARE(b) - 4 * a * c; get_intersection(&intersect, delta, a, b); return (intersect); }
input_window make_new_window_(double pos, const input_window& prev) const { double prev_start_pos = prev.get_start_pos(); int i = static_cast<int>( std::floor((pos - prev_start_pos) / batch_interval_)); int j = i - window_batch_size_/2; double new_start_pos = prev_start_pos + batch_interval_ * j; input_window new_window( new_start_pos, batch_interval_, window_batch_size_); // fill new_window's d&r vector std::pair<int, int> intersection = get_intersection(prev, new_window); for (int i = 0, j = intersection.first; j < intersection.second; ++i, ++j) { JUBATUS_ASSERT_LT(i, window_batch_size_, ""); new_window.get_batch_by_index(i) = prev.get_batch_by_index(j); } return new_window; // NRVO }
IMPDOMINOEXPORT CliqueGraph get_clique_graph(const InteractionGraph& cig) { InteractionGraphConstVertexName pm= boost::get(boost::vertex_name, cig); typedef base::Vector<InteractionGraphVertex> Clique; base::Vector<Clique> cliques; internal::maximal_cliques(cig, std::back_inserter(cliques)); for (unsigned int i=0; i< cliques.size(); ++i) { /*std::cout << "Clique is "; for (unsigned int j=0; j< cliques[i].size(); ++j) { std::cout << cliques[i][j] << " "; }*/ std::sort(cliques[i].begin(), cliques[i].end()); } CliqueGraph cg(cliques.size()); CliqueGraphVertexName cm = boost::get(boost::vertex_name, cg); for (unsigned int i=0; i< cliques.size(); ++i) { ParticlesTemp cur; for (unsigned int j=0; j< cliques[i].size(); ++j) { cur.push_back(pm[cliques[i][j]]); } Subset ss(cur); cm[i]=ss; } for (unsigned int i=0; i< cliques.size(); ++i) { for (unsigned int j=0; j< i; ++j) { Subset intersection= get_intersection(cm[i], cm[j]); if (intersection.size() >0) { double minus_weight=intersection.size(); /*std::cout << "edge " << i << " " << j << " has weight " << -static_cast<int>(intersection.size()) << std::endl;*/ boost::add_edge(i, j, CliqueGraph::edge_property_type(-minus_weight), cg); } } } return cg; }
int flush_results(double scaling_param, double gamma, double costcut_threshold, int max_reuse_batches, result_storage& stored) { if (inputs_.empty()) { return 0; } burst_result prev = stored.get_result_at( inputs_.back().get_start_pos() - batch_interval_/2); typedef std::deque<input_window>::reverse_iterator iterator_t; for (iterator_t iter = inputs_.rbegin(), end = inputs_.rend(); iter != end; ++iter) { burst_result r(*iter, scaling_param, gamma, costcut_threshold, prev, max_reuse_batches); stored.store(r); prev.swap(r); // more efficient than prev = r; use move when C++11/14 } // erase inputs which will no longer be modified by add_document int n = 0; for (;;) { JUBATUS_ASSERT_GT(inputs_.size(), 0, ""); std::pair<int, int> intersection = get_intersection(inputs_.back(), inputs_.front()); if (intersection.first != intersection.second) { break; // break if intersection exists } inputs_.pop_back(); ++n; } // return erased count return n; }
t_intersect cone(t_pov pov, t_coordinate rayvector, t_object *object) { double a; double b; double c; double delta; double parameter; t_intersect intersect; intersect.k = 0; intersect.object = object; transform_pov(&pov, &rayvector, object); parameter = object->parameter * (PI / 180); a = SQUARE(rayvector.x) + SQUARE(rayvector.y) - SQUARE(rayvector.z) / SQUARE(tan(parameter)); b = 2 * (pov.x * rayvector.x + pov.y * rayvector.y - pov.z * rayvector.z / SQUARE(tan(parameter))); c = SQUARE(pov.x) + SQUARE(pov.y) - SQUARE(pov.z) / SQUARE(tan(parameter)); delta = SQUARE(b) - 4 * a * c; get_intersection(&intersect, delta, a, b); return (intersect); }
int ClosestPointQuery::intersect_line_bb(simple_point b1, simple_point b2, simple_point l1, simple_point l2, simple_point &Hit) const { if (l1.x > b1.x && l1.x < b2.x && l1.y > b1.y && l1.y < b2.y && l1.z > b1.z && l1.z < b2.z) { Hit = l1; return true; } if ((get_intersection(l1.x - b1.x, l2.x - b1.x, l1, l2, Hit, "xmin") && inside_box(Hit, b1, b2, 1)) || (get_intersection(l1.y - b1.y, l2.y - b1.y, l1, l2, Hit, "ymin") && inside_box(Hit, b1, b2, 2)) || (get_intersection(l1.z - b1.z, l2.z - b1.z, l1, l2, Hit, "zmin") && inside_box(Hit, b1, b2, 3)) || (get_intersection(l1.x - b2.x, l2.x - b2.x, l1, l2, Hit, "xmax") && inside_box(Hit, b1, b2, 1)) || (get_intersection(l1.y - b2.y, l2.y - b2.y, l1, l2, Hit, "ymax") && inside_box(Hit, b1, b2, 2)) || (get_intersection(l1.z - b2.z, l2.z - b2.z, l1, l2, Hit, "zmax") && inside_box(Hit, b1, b2, 3))) return true; return false; }
bool hqend_hqstart_search_index::do_check_hqend_hqstart_ge(std::string &key, std::string &value, std::set<std::string> & search) { float end = 0; std::multimap<float, std::string>::iterator it_le, it_ge, it; std::map<std::string, std::multimap<float, std::string> > * search_index = current(); SETS_OP_TRPE tmp_ot; proc_data* p_data = proc_data::instance(); std::vector<std::string> tmp_vec; std::vector<std::set<std::string> > tmp_res_vec; if (strstr(key.c_str(), "|")) { SplitString(value.c_str(), '|', &tmp_vec, SPLIT_MODE_ALL); tmp_ot = SETS_OP_UNION; } else { SplitString(value.c_str(), '&', &tmp_vec, SPLIT_MODE_ALL); tmp_ot = SETS_OP_INTERSECTION; } if (!tmp_vec.size()) tmp_vec.push_back(value); for (uint32_t i = 0; i< tmp_vec.size(); i++) { std::vector<std::string> t_vec; SplitString(tmp_vec[i].c_str(), ':', &t_vec, SPLIT_MODE_ALL); std::string date; std::set<std::string> t_res; p_data->_hquoation_dict->current()->get_last_date(atoi(t_vec[0].c_str()), date); if (date.empty()) { tmp_res_vec.push_back(t_res); continue; } end = atof(t_vec[1].c_str()); auto ii = search_index->find(date); if (ii == search_index->end()) { tmp_res_vec.push_back(t_res); continue;; } it_le = ii->second.end(); it_ge = ii->second.begin(); it_ge = ii->second.lower_bound(end); for (it = it_ge; it != it_le; ++it) { t_res.insert(it->second); } tmp_res_vec.push_back(t_res); } if (tmp_ot == SETS_OP_INTERSECTION) get_intersection(tmp_res_vec, search); else get_union(tmp_res_vec, search); return true; }
//implemetation of functions int start_finding(int start_x, int start_y) { int inter = 0; int token = 0; int cur_x = start_x, cur_y = start_y; int dir = SOUTH; int ppath = -1; int npop = 0; //how many points should be poped struct POINT *cur_p = NULL; struct POINT *tmp_p = NULL; int ret = 0; #ifdef DEBUG inter = Robot_GetIntersections(); #else inter = get_intersection(); #endif cur_p = mark_point(cur_x, cur_y, inter); dir = get_direction(cur_p); #ifdef DEBUG printf("start point: "); print_point(cur_p); printf("\n"); #endif while(token < TOKEN_COUNT) { #ifdef DEBUG //inter = Robot_GetIntersections(); //print_intersection(inter); #endif if(points[cur_x][cur_y].detected == 0) cur_p = mark_point(cur_x, cur_y, inter); else cur_p = &points[cur_x][cur_y]; push(cur_p); //print_stack(); if(dir = get_direction(cur_p)) { //update current point switch(dir) { case EAST: cur_x += 1; break; case SOUTH: cur_y -= 1; break; case WEST: cur_x -= 1; break; case NORTH: cur_y += 1; break; } #ifdef DEBUG print_direction(cur_p, dir); ret = aud_move(cur_p, dir); #else //move one step display_clear(0); display_goto_xy(0, 0); display_int(cur_p->x, 2); display_goto_xy(3, 0); display_int(cur_p->y, 2); display_goto_xy(7, 0); display_int(cur_x, 2); display_goto_xy(10, 0); display_int(cur_y, 2); display_goto_xy(0, 1); display_int(g_dir, 3); display_goto_xy(5, 1); display_int(dir, 3); display_goto_xy(0, 2); display_int(cur_p->inter&0xF0, 3); display_update(); ret = move(cur_x, cur_y); #endif #ifdef DEBUG inter = Robot_GetIntersections(); #else inter = get_intersection(); #endif cur_p = mark_point(cur_x, cur_y, inter); #ifdef DEBUG print_point(cur_p); #endif if(ret == ROBOT_SUCCESS) { #ifndef DEBUG #endif } else if(ret == ROBOT_TOKENFOUND) { tmp_p = &points[cur_x][cur_y]; if(tmp_p->has_token == 0) { tmp_p->has_token = 1; token++; #ifdef DEBUG printf("[%d. token]\n", token); #endif } else { #ifdef DEBUG printf("[not a new token]\n"); #endif } if(token == TOKEN_COUNT) { //all token were found, go back to start point #ifdef DEBUG printf("going back to start point......\n"); #endif push(cur_p); ppath = find_shortest_path(cur_p->x, cur_p->y, START_X, START_Y); if(ppath) { //going back to last open point ppath--; while(ppath >= 0) { tmp_p = shortest_path[ppath]; dir = calc_direction(cur_p->x, cur_p->y, tmp_p->x, tmp_p->y); #ifdef DEBUG print_point(tmp_p); printf("\n"); ROBOT_MOVE(tmp_p->x, tmp_p->y); #else display_clear(0); display_goto_xy(0, 0); display_int(cur_p->x, 2); display_goto_xy(3, 0); display_int(cur_p->y, 2); display_goto_xy(7, 0); display_int(tmp_p->x, 2); display_goto_xy(10, 0); display_int(tmp_p->y, 2); display_goto_xy(0, 1); display_int(g_dir, 3); display_goto_xy(5, 1); display_int(dir, 3); display_goto_xy(0, 2); display_int(cur_p->inter&0xF0, 3); display_update(); move(tmp_p->x, tmp_p->y); #endif cur_p = tmp_p; ppath--; } //delete the path in stack pop(npop + 1); cur_p = tmp_p; cur_x = cur_p->x; cur_y = cur_p->y; } #ifdef DEBUG printf("task finished!\n"); #else beep(); #endif break; } } else { #ifdef DEBUG printf("move failed!\n"); #endif } } else { //there is no ways forward, go back to nearest open point tmp_p = get_last_open_point(); npop = stack_pointer - get_stack_index(tmp_p->x, tmp_p->y); #ifdef DEBUG printf("going back to (%d, %d)\n", tmp_p->x, tmp_p->y); #endif if(tmp_p) { if((tmp_p->x == START_X) && (tmp_p->y == START_Y) && !IS_OPEN_POINT(points[tmp_p->x][tmp_p->y])) { #ifdef DEBUG return 0; #else stop_robot(); beep(); return 0; #endif } ppath = find_shortest_path(cur_p->x, cur_p->y, tmp_p->x, tmp_p->y); if(ppath) { //going back to last open point ppath--; while(ppath >= 0) { tmp_p = shortest_path[ppath]; dir = calc_direction(cur_p->x, cur_p->y, tmp_p->x, tmp_p->y); #ifdef DEBUG ROBOT_MOVE(tmp_p->x, tmp_p->y); #else display_clear(0); display_goto_xy(0, 0); display_int(cur_p->x, 2); display_goto_xy(3, 0); display_int(cur_p->y, 2); display_goto_xy(7, 0); display_int(tmp_p->x, 2); display_goto_xy(10, 0); display_int(tmp_p->y, 2); display_goto_xy(0, 1); display_int(g_dir, 3); display_goto_xy(5, 1); display_int(dir, 3); display_goto_xy(0, 2); display_int(cur_p->inter&0xF0, 3); display_update(); move(tmp_p->x, tmp_p->y); #endif cur_p = tmp_p; ppath--; } //delete the path in stack pop(npop + 1); cur_p = tmp_p; cur_x = cur_p->x; cur_y = cur_p->y; } else { //was already at every point and back to start point //task should be ended //that means, not enough token can be found #ifdef DEBUG printf("task ended without enough token were found.\n"); #endif break; } } } #ifdef DEBUG printf("\n"); #endif } return 0; }
void grid_eval(cl::program_t& prog, size_t block0, size_t block1, size_t refine) { const size_t Nx = px.size(); const size_t Ny = py.size(); const size_t Nz = pz.size(); cl::ctx_t ctx(prog.context()); cl::queue_t queue(ctx, ctx.device(0)); init_mesh(); { cl::kernel_t kern = prog.kernel("grid"); boost::scoped_array<uint8_t> out(new uint8_t[block0 * block0 * block0]); boost::scoped_array<float> gx(new float[block0]); boost::scoped_array<float> gy(new float[block0]); boost::scoped_array<float> gz(new float[block0]); cl::mem_t gx_mem = ctx.create_buffer(CL_MEM_READ_ONLY, block0 * sizeof(float), NULL); cl::mem_t gy_mem = ctx.create_buffer(CL_MEM_READ_ONLY, block0 * sizeof(float), NULL); cl::mem_t gz_mem = ctx.create_buffer(CL_MEM_READ_ONLY, block0 * sizeof(float), NULL); cl::mem_t out_mem = ctx.create_buffer(CL_MEM_READ_WRITE, block0 * block0 * block0, NULL); const size_t Py = block0; const size_t Pz = block0 * block0; kern.arg(0, gx_mem); kern.arg(1, gy_mem); kern.arg(2, gz_mem); kern.arg(3, out_mem); kern.arg(4, Py); kern.arg(5, Pz); for (size_t _z = 0; _z < Nz; _z += block0 - 1) { const size_t Wz = std::min(block0, Nz - _z); for (size_t i = 0; i < Wz; ++i) gz[i] = (float)pz[_z + i]; queue.sync(cl::cmd_write_buffer(gz_mem, CL_FALSE, 0, Wz * sizeof(float), gz.get())); for (size_t _y = 0; _y < Ny; _y += block0 - 1) { const size_t Wy = std::min(block0, Ny - _y); for (size_t i = 0; i < Wy; ++i) gy[i] = (float)py[_y + i]; queue.sync(cl::cmd_write_buffer(gy_mem, CL_FALSE, 0, Wy * sizeof(float), gy.get())); for (size_t _x = 0; _x < Nx; _x += block0 - 1) { std::cerr << "block: " << _x << "," << _y << "," << _z << std::endl; const size_t Wx = std::min(block0, Nx - _x); for (size_t i = 0; i < Wx; ++i) gx[i] = (float)px[_x + i]; queue.sync(cl::cmd_write_buffer(gx_mem, CL_FALSE, 0, Wx * sizeof(float), gx.get())); queue.sync(cl::cmd_task(kern).wrk_sz(Wx, Wy, Wz)); queue.sync(cl::cmd_read_buffer( out_mem, CL_FALSE, 0, block0 * block0 * block0, out.get())); for (size_t z = 0; z < Wz - 1; ++z) { for (size_t y = 0; y < Wy - 1; ++y) { for (size_t x = 0; x < Wx - 1; ++x) { size_t bits = 0; if (out[(x + 0) + (y + 0) * Py + (z + 0) * Pz]) bits |= 0x01; if (out[(x + 1) + (y + 0) * Py + (z + 0) * Pz]) bits |= 0x02; if (out[(x + 0) + (y + 1) * Py + (z + 0) * Pz]) bits |= 0x04; if (out[(x + 1) + (y + 1) * Py + (z + 0) * Pz]) bits |= 0x08; if (out[(x + 0) + (y + 0) * Py + (z + 1) * Pz]) bits |= 0x10; if (out[(x + 1) + (y + 0) * Py + (z + 1) * Pz]) bits |= 0x20; if (out[(x + 0) + (y + 1) * Py + (z + 1) * Pz]) bits |= 0x40; if (out[(x + 1) + (y + 1) * Py + (z + 1) * Pz]) bits |= 0x80; const uint8_t* row = mc_table[bits]; size_t n_tri = *row++; if (n_tri == 0) continue; { for (size_t t = 0; t < n_tri; ++t) { uint8_t ea, eb, ec; size_t va, vb, vc; ea = *row++; eb = *row++; ec = *row++; va = get_intersection( decode_edge(_x + x, _y + y, _z + z, ea)); vb = get_intersection( decode_edge(_x + x, _y + y, _z + z, eb)); vc = get_intersection( decode_edge(_x + x, _y + y, _z + z, ec)); mesh->add_tri(va, vb, vc); } } } } } } } } } std::vector<std::pair<edgeint_t, size_t> > vert_calc; vert_calc.reserve(int_idx.size()); for (typename edgeint_map_t::iterator i = int_idx.begin(); i != int_idx.end(); ++i) { vert_calc.push_back(std::make_pair((*i).first, (*i).second)); } { boost::scoped_array<cl_float3> a(new cl_float3[block1]); boost::scoped_array<cl_float3> b(new cl_float3[block1]); boost::scoped_array<cl_float3> c(new cl_float3[block1]); cl::mem_t a_mem = ctx.create_buffer(CL_MEM_READ_ONLY, block1 * sizeof(cl_float3), NULL); cl::mem_t b_mem = ctx.create_buffer(CL_MEM_READ_ONLY, block1 * sizeof(cl_float3), NULL); cl::mem_t c_mem = ctx.create_buffer(CL_MEM_READ_WRITE, block1 * sizeof(cl_float3), NULL); cl::kernel_t kern = prog.kernel("chop"); kern.arg(0, a_mem); kern.arg(1, b_mem); kern.arg(2, c_mem); kern.arg(3, refine); for (size_t i = 0; i < vert_calc.size(); i += block1) { const size_t N = std::min(vert_calc.size() - i, block1); for (size_t j = 0; j < N; ++j) { edgeint_t& e = vert_calc[i + j].first; v3d_t a_pos = position_of_vertex(e.a[0], e.a[1], e.a[2]); v3d_t b_pos = position_of_vertex(e.b[0], e.b[1], e.b[2]); a[j].x = (float)a_pos.x; a[j].y = (float)a_pos.y; a[j].z = (float)a_pos.z; b[j].x = (float)b_pos.x; b[j].y = (float)b_pos.y; b[j].z = (float)b_pos.z; } queue.sync(cl::cmd_write_buffer(a_mem, CL_FALSE, 0, N * sizeof(cl_float3), a.get())); queue.sync(cl::cmd_write_buffer(b_mem, CL_FALSE, 0, N * sizeof(cl_float3), b.get())); queue.sync(cl::cmd_task(kern).wrk_sz(N)); queue.sync(cl::cmd_read_buffer(c_mem, CL_FALSE, 0, N * sizeof(cl_float3), c.get())); for (size_t j = 0; j < N; ++j) { mesh->vertices[vert_calc[i + j].second].pos = v3d_t::init(c[j].x, c[j].y, c[j].z); } } } }
TEST_P(window_intersection_test, intersect_to_empty_window) { sample_window w; std::pair<int, int> intersection = get_intersection(w0, w); ASSERT_EQ(intersection.first, intersection.second); }
int main() { std::scanf("%d", &n); rotate_sin = sinl(233.3); rotate_cos = cosl(233.3); for(int i = 0; i != n; ++i) { for(int j = 0; j != 3; ++j) { std::scanf("%Lf %Lf", &pt[i][j].x, &pt[i][j].y); pt[i][j] = rotate(pt[i][j]); coordinate[tot++] = pt[i][j].y; } for(int j = 0; j != i; ++j) { add_intersection(i, 0, 1, j, 0, 1); add_intersection(i, 0, 1, j, 0, 2); add_intersection(i, 0, 1, j, 1, 2); add_intersection(i, 0, 2, j, 0, 1); add_intersection(i, 0, 2, j, 0, 2); add_intersection(i, 0, 2, j, 1, 2); add_intersection(i, 1, 2, j, 0, 1); add_intersection(i, 1, 2, j, 0, 2); add_intersection(i, 1, 2, j, 1, 2); } } std::sort(coordinate, coordinate + tot); tot = std::unique(coordinate, coordinate + tot, cmp) - coordinate; long double area = 0.0, prev_len = 0.0; for(int i = 0; i != tot; ++i, num = 0) { long double y = coordinate[i]; for(int j = 0; j != n; ++j) { if(add_horizontal(y, j, 0, 1)) continue; if(add_horizontal(y, j, 0, 2)) continue; if(add_horizontal(y, j, 1, 2)) continue; long double d1 = get_intersection(y, pt[j][0], pt[j][1]); long double d2 = get_intersection(y, pt[j][0], pt[j][2]); long double d3 = get_intersection(y, pt[j][1], pt[j][2]); add_segment(d2, d3); add_segment(d1, d3); add_segment(d1, d2); } std::sort(data, data + num); int cnt = 0; long double prev = 0.0, len = 0.0; for(int j = 0; j != num; ++j) { if(!cnt) prev = data[j].x; cnt += data[j].cnt; if(!cnt) len += data[j].x - prev; } if(i) area += (len + prev_len) * (y - coordinate[i - 1]) * (long double)0.5; prev_len = len; } std::printf("%.2Lf\n", area); return 0; }
TEST_P(window_intersection_test, intersect_to_overlap1) { sample_window w(start_pos-batch_interval, batch_interval, n+2); std::pair<int, int> intersection = get_intersection(w0, w); ASSERT_EQ(0, intersection.first); ASSERT_EQ(n, intersection.second); }
TEST_P(window_intersection_test, intersect_to_partially_left2) { sample_window w(start_pos - batch_interval*0.5, batch_interval, 4); std::pair<int, int> intersection = get_intersection(w0, w); ASSERT_EQ(tested.no_index(), intersection.first); ASSERT_EQ(tested.no_index(), intersection.second); }
TEST_P(window_intersection_test, intersect_to_partially_left1) { sample_window w(start_pos - batch_interval*1, batch_interval, 4); std::pair<int, int> intersection = get_intersection(w0, w); ASSERT_EQ(0, intersection.first); ASSERT_EQ(std::min(n, 3), intersection.second); }
SubsetGraph get_restraint_graph(ScoringFunctionAdaptor in, const ParticleStatesTable *pst) { RestraintsTemp rs = IMP::create_decomposition(in->create_restraints()); // ScoreStatesTemp ss= get_required_score_states(rs); SubsetGraph ret(rs.size()); // + ss.size()); IMP_LOG_TERSE("Creating restraint graph on " << rs.size() << " restraints." << std::endl); boost::unordered_map<Particle *, int> map; SubsetGraphVertexName pm = boost::get(boost::vertex_name, ret); DependencyGraph dg = get_dependency_graph(rs[0]->get_model()); DependencyGraphVertexIndex index = IMP::get_vertex_index(dg); /*IMP_IF_LOG(VERBOSE) { IMP_LOG_VERBOSE( "dependency graph is \n"); IMP::internal::show_as_graphviz(dg, std::cout); }*/ Subset ps = pst->get_subset(); for (unsigned int i = 0; i < ps.size(); ++i) { ParticlesTemp t = get_dependent_particles( ps[i], ParticlesTemp(ps.begin(), ps.end()), dg, index); for (unsigned int j = 0; j < t.size(); ++j) { IMP_USAGE_CHECK(map.find(t[j]) == map.end(), "Currently particles which depend on more " << "than one particle " << "from the input set are not supported." << " Particle \"" << t[j]->get_name() << "\" depends on \"" << ps[i]->get_name() << "\" and \"" << ps[map.find(t[j])->second]->get_name() << "\""); map[t[j]] = i; } IMP_IF_LOG(VERBOSE) { IMP_LOG_VERBOSE("Particle \"" << ps[i]->get_name() << "\" controls "); for (unsigned int i = 0; i < t.size(); ++i) { IMP_LOG_VERBOSE("\"" << t[i]->get_name() << "\" "); } IMP_LOG_VERBOSE(std::endl); } } for (unsigned int i = 0; i < rs.size(); ++i) { ParticlesTemp pl = IMP::get_input_particles(rs[i]->get_inputs()); std::sort(pl.begin(), pl.end()); pl.erase(std::unique(pl.begin(), pl.end()), pl.end()); Subset os(pl); for (unsigned int j = 0; j < pl.size(); ++j) { pl[j] = ps[map[pl[j]]]; } std::sort(pl.begin(), pl.end()); pl.erase(std::unique(pl.begin(), pl.end()), pl.end()); Subset s(pl); IMP_LOG_VERBOSE("Subset for restraint " << rs[i]->get_name() << " is " << s << " from " << os << std::endl); pm[i] = s; } /*ScoreStatesTemp ss= get_required_score_states(rs); for (ScoreStatesTemp::const_iterator it= ss.begin(); it != ss.end(); ++it) { ParticlesTemp pl= (*it)->get_input_particles(); add_edges(ps, pl, map, *it, ret); ParticlesTemp opl= (*it)->get_output_particles(); add_edges(ps, opl, map, *it, ret); } IMP_INTERNAL_CHECK(boost::num_vertices(ret) == ps.size(), "Wrong number of vertices " << boost::num_vertices(ret) << " vs " << ps.size());*/ for (unsigned int i = 0; i < boost::num_vertices(ret); ++i) { for (unsigned int j = 0; j < i; ++j) { if (get_intersection(pm[i], pm[j]).size() > 0) { boost::add_edge(i, j, ret); IMP_LOG_VERBOSE("Connecting " << rs[i]->get_name() << " with " << rs[j]->get_name() << std::endl); } } } return ret; }
void add_intersection(int i, int ai, int bi, int j, int aj, int bj) { long double y = get_intersection(pt[i][ai], pt[i][bi], pt[j][aj], pt[j][bj]); if(y < 1.0e90) coordinate[tot++] = y; }
/*! \brief displays a live marker for the Y axis (horizontal Line) \param curve (MtxCurve *) pointer to curve */ void mtx_curve_set_y_marker_value (MtxCurve *curve, gfloat value) { MtxCurvePrivate *priv = NULL; gint i = 0; gfloat x = 0.0; gfloat y = 0.0; gfloat d1 = 0.0; gfloat d2 = 0.0; gboolean get_peak_cross = FALSE; g_return_if_fail (MTX_IS_CURVE (curve)); priv = MTX_CURVE_GET_PRIVATE(curve); #if GTK_MINOR_VERSION >= 18 if (!gtk_widget_is_sensitive(GTK_WIDGET(curve))) return; #else if (!GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(curve))) return; #endif if (priv->y_marker == value) return; /* IF marker is clamped beyond ranges, don't bother updating*/ if (((value < priv->lowest_y) && (priv->y_marker_clamp == LOW)) || ((value > priv->highest_y) && (priv->y_marker_clamp == HIGH))) return; /* Filter out jitter to within 1% */ if (fabs(value-priv->y_marker) < (fabs(priv->highest_y-priv->lowest_y)/100.0)) return; g_object_freeze_notify (G_OBJECT (curve)); if (value <priv->lowest_y) { priv->y_marker = priv->lowest_y; priv->y_marker_clamp = LOW; } else if (value > priv->highest_y) { priv->y_marker = priv->highest_y; priv->y_marker_clamp = HIGH; } else { priv->y_marker = value; priv->y_marker_clamp = NONE; } if (value > priv->peak_y_marker) { priv->peak_y_marker = value > priv->highest_y ? priv->highest_y:value; get_peak_cross = TRUE; if (priv->y_peak_timeout) { g_source_remove(priv->y_peak_timeout); priv->y_peak_timeout = -1; } } else { priv->y_draw_peak = TRUE; g_object_set_data(G_OBJECT(curve),"axis",GINT_TO_POINTER(_Y_)); if (priv->y_peak_timeout <= 0) priv->y_peak_timeout = g_timeout_add(5000,(GSourceFunc)cancel_peak,(gpointer)curve); } for (i = 0;i<priv->num_points - 1;i++) { if (value < priv->coords[0].y) { priv->x_at_y_marker = priv->coords[0].x; if (0 != priv->marker_proximity_vertex) { priv->marker_proximity_vertex = 0; g_signal_emit_by_name((gpointer)curve, "marker-proximity"); } } else if (value > priv->coords[priv->num_points-1].y) { priv->x_at_y_marker = priv->coords[priv->num_points-1].x; if (get_peak_cross) priv->peak_x_at_y_marker = priv->x_at_y_marker; if (priv->num_points-1 != priv->marker_proximity_vertex) { priv->marker_proximity_vertex = priv->num_points-1; g_signal_emit_by_name((gpointer)curve, "marker-proximity"); } } else if ((value > priv->coords[i].y) && (value < priv->coords[i+1].y)) { if (get_intersection(priv->coords[i].x,priv->coords[i].y,priv->coords[i+1].x,priv->coords[i+1].y,0,value,priv->w,value,&x,&y)) { priv->x_at_y_marker = x; if (get_peak_cross) priv->peak_x_at_y_marker = x; d1 = sqrt(pow((priv->coords[i].x-x),2)+ pow((priv->coords[i].y-value),2)); d2 = sqrt(pow((priv->coords[i+1].x-x),2)+ pow((priv->coords[i+1].y-value),2)); if (d1 < d2) { if (i != priv->marker_proximity_vertex) { priv->marker_proximity_vertex = i; g_signal_emit_by_name((gpointer)curve, "marker-proximity"); } } else { if (i+1 != priv->marker_proximity_vertex) { priv->marker_proximity_vertex = i+1; g_signal_emit_by_name((gpointer)curve, "marker-proximity"); } } } else printf("couldn't find intersection\n"); break; } } g_object_thaw_notify (G_OBJECT (curve)); mtx_curve_redraw(curve,FALSE); return; }