void plot_lines(double *xd, double *yd, long n, int line_type, int line_thickness) { int i; /* point index */ int x,y; /* point in terminal coordinates */ struct termentry *t = &term_tbl[term]; int prev = UNDEFINED; /* type of previous point */ double ex, ey; /* an edge point */ double lx[2], ly[2]; /* two edge points */ check_scales("plot_lines"); line_type = set_linetype(line_type); set_linethickness(line_thickness); for (i = 0; i < n; i++) { x = map_x(xd[i]); y = map_y(yd[i]); if ((!clip_lines1 && !clip_lines2) || (inrange(xd[i], xmin, xmax) && inrange(yd[i], ymin, ymax))) { if (prev == INRANGE) { (*t->vector)(x,y); } else if (prev == OUTRANGE) { /* from outrange to inrange */ if (!clip_lines1) { (*t->move)(x,y); } else { edge_intersect(xd[i-1], yd[i-1], xd[i], yd[i], &ex, &ey); (*t->move)(map_x(ex), map_y(ey)); (*t->vector)(x,y); } } else { /* prev == UNDEFINED */ (*t->move)(x,y); (*t->vector)(x,y); } prev = INRANGE; } else { if (prev == INRANGE) { /* from inrange to outrange */ if (clip_lines1) { edge_intersect(xd[i-1], yd[i-1], xd[i], yd[i], &ex, &ey); (*t->vector)(map_x(ex), map_y(ey)); } } else if (prev == OUTRANGE) { /* from outrange to outrange */ if (clip_lines2) { if (two_edge_intersect(xd[i-1], yd[i-1], xd[i], yd[i], lx, ly)) { (*t->move)(map_x(lx[0]), map_y(ly[0])); (*t->vector)(map_x(lx[1]), map_y(ly[1])); } } } prev = OUTRANGE; } } xu_pos = xd[n-1]; yu_pos = yd[n-1]; set_linetype(line_type); }
int main() { cv::Mat img = cv::imread("lena.jpg"); cv::Mat map_x(img.size(), CV_32FC1), map_y(img.size(), CV_32FC1); std::vector<double> timings; std::cout << benchmark( [&]() { #pragma omp parallel for num_threads(4) for (int i = 0; i < img.rows; i++) { for (int j = 0; j < img.cols; j++) { int x = j - img.cols / 2; int y = i - img.rows / 2; float r = sqrt(x * x + y * y); float a = atan2(y, x); float a2 = a + r * 0.004; map_x.at<float>(i, j) = r * cos(a2) + img.cols / 2; map_y.at<float>(i, j) = r * sin(a2) + img.rows / 2; } } }, 10) << std::endl; cv::Mat img_processed; cv::remap(img, img_processed, map_x, map_y, cv::INTER_LINEAR); cv::imshow("img", img_processed); cv::waitKey(0); }
void vdpoly_(float x_array[], float y_array[], int *npts) { int i, iend; vflush(); if (*npts > (int)dev_cap[24]) { vdicgi_errh(" SVDI Shell (VDPOLY) exceeded max points for - device limit "); iend = (int)dev_cap[24]; } else if (*npts > VBUF_SIZE) { vdicgi_errh(" SVDI Shell (VDPOLY) exceeded max points - internal buffer limit "); iend = VBUF_SIZE; } else iend = *npts; for (i = 0; i < iend; i++) { vlist_x[nvert] = map_x(x_array[i]); vlist_y[nvert] = map_y(y_array[i]); nvert++; } cpg_(&nvert, vlist_x, vlist_y); nvert = 0; xcp = x_array[0]; ycp = y_array[0]; }
void vdmova_(float *x, float *y) { vflush(); vlist_x[nvert] = map_x(*x); vlist_y[nvert] = map_y(*y); nvert++; xcp = *x; ycp = *y; }
int julia_point(int res_x, int res_y, int image_x, int image_y, float zoom, int max_iteration) { // Get the index of the current element float pos_x = map_x_julia(image_x, res_x, 1.0); float pos_y = map_y(image_y, res_y, 1.0); float x = pos_x; float y = pos_y; float xtemp, xx, yy; #ifdef CACHE int storeable = 1; #endif int iteration = 0; #ifdef CACHE // Look up our cache iteration = cached_iteration(pos_x, pos_y); if (iteration > 0) { x = get_cached_x(pos_x, pos_y); y = get_cached_y(pos_x, pos_y); yy = y * y; } if (iteration < 0) storeable = 0; #endif while (iteration < max_iteration) { xx = x * x; yy = y * y; if ((xx) + (yy) > (4.0)) break; y = pow((x + y), 2) - xx - yy; y = y + 0.288; xtemp = xx - yy + 0.353 + zoom; x = xtemp; iteration++; } if (iteration >= max_iteration) { return 0; } else { #ifdef CACHE if (storeable == 1) { store_iteration(pos_x, pos_y, iteration, x, y); } #endif return iteration; } }
void vdlina_(float *x, float *y) { /* if a move hasn't already been done, doit it now */ if (nvert == 0) { vlist_x[nvert] = map_x(xcp); vlist_y[nvert] = map_y(ycp); nvert++; } /* append to polyline buffer (if full, flush it first) */ if (nvert >= VBUF_SIZE) { vflush(); nvert = 0; /* vflush sets this, but static analysis still warns. */ } vlist_x[nvert] = map_x(*x); vlist_y[nvert] = map_y(*y); nvert++; xcp = *x; ycp = *y; }
void vdpnta_(float *x, float *y) { float new_x, new_y; int temp; new_x = map_x(*x); new_y = map_y(*y); temp = 1; vflush(); vlist_x[nvert] = new_x; vlist_y[nvert] = new_y; nvert++; cpm_(&temp, &new_x, &new_y); xcp = *x; ycp = *y; }
void vdstcs_(float *y_size) { float new_size, x, y, xconc, yconc, x1, y1, x2, y2, x3, y3, x4, y4; float temp3; int vstat, vconc, temp1, temp2; xconc = 0.0; yconc = 0.0; x1 = 0.0; y1 = 0.0; x2 = 0.0; y2 = 0.0; x3 = 0.0; y3 = 0.0; x4 = 0.0; y4 = 0.0; new_size = map_x(*y_size); if (alpha_mode) { temp1 = XEAGMD; temp2 = 1; temp3 = 1.; /* graphics */ cesc2_(&temp1, &temp2, &temp3); alpha_mode = FALSE; } cchh_(&new_size); /* inquire what the realized size is and stuff it here */ x = map_x(xcp); y = map_y(ycp); cgtxx2_(&x, &y, &vstat, &vconc, &xconc, &yconc, &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4); if (vstat == CVAL) { /* mod## y value being stored incorrectyl; swapped x & y */ vector[5] = ndc_map_y(y4 - y1); vector[6] = ndc_map_x(x2 - x1); } else vdicgi_errh(" SVDI Shell (VDSTCS) inquire error from cgtxx "); }
static void draw_full_sets_on_grid ( bitmap_t * fset_mask, /* IN - mask of valid FSTs */ struct cinfo * cip /* IN - compatibility info */ ) { int i; int j; int u, v, ux, uy, vx, vy; int nt; int ns; struct full_set * fsp; struct pset * terms; struct pset * steins; struct edge * ep; int * xi; int * yi; xi = grid.xindex; yi = grid.yindex; for (i = 0; i < cip -> num_edges; i++) { if (NOT BITON (fset_mask, i)) continue; fsp = cip -> full_trees [i]; ep = fsp -> edges; terms = fsp -> terminals; steins = fsp -> steiners; nt = terms -> n; ns = steins -> n; for (j = 0; j < fsp -> nedges; j++, ep++) { u = ep -> p1; if (u < 0) { fatal ("draw_full_sets_on_grid: Bug 1."); } if (u < nt) { u = terms -> a [u].pnum; ux = xi [u]; uy = yi [u]; } else { u -= nt; if (u >= ns) { fatal ("draw_full_sets_on_grid: Bug 2."); } ux = map_x (steins -> a [u].x); uy = map_y (steins -> a [u].y); } v = ep -> p2; if (v < 0) { fatal ("draw_full_sets_on_grid: Bug 3."); } if (v < nt) { v = terms -> a [v].pnum; vx = xi [v]; vy = yi [v]; } else { v -= nt; if (v >= ns) { fatal ("draw_full_sets_on_grid: Bug 4."); } vx = map_x (steins -> a [v].x); vy = map_y (steins -> a [v].y); } draw_bb_grid (ux, uy, vx, vy); } } }
void vdtext_(int *length, int char_array[]) { int i, lenout, len, temp1, temp2; float dx, dy, temp_xcp, temp_ycp, temp3; int strout[150]; len = *length; if (len < 1) { vdicgi_errh(" SVDI Shell (VDTEXT) Error Number 212, Severity Code 5 "); return; } if (len > 136) { vdicgi_errh(" SVDI Shell (VDTEXT) Error Number 213, Severity Code 5 "); len = 136; } if (alpha_mode) { temp1 = XEAGMD; temp2 = 1; temp3 = 1.; /* graphics */ cesc2_(&temp1, &temp2, &temp3); alpha_mode = FALSE; } lenout = 0; /*count characters in string output buffer "strout" */ for (i = 0; i < len; i++) { if (char_array[i] < 32 || char_array[i] > 126) { switch (char_array[i]) { case 8: dx = -vector[6]; dy = 0.; break; case 10: dx = 0.; dy = -vector[5]; break; case 13: dx = -xcp; dy = 0.; break; default: dx = 0.; dy = 0.; vdicgi_errh(" SVDI Shell (VDTEXT) Error Number 208, Severity Code 5 "); break; } /* Stuff to send, finish the string */ if (lenout != 0) { temp_xcp = map_x(xcp); temp_ycp = map_y(ycp); ctx2_(&temp_xcp, &temp_ycp, strout, &lenout); xcp += lenout * vector[6]; lenout = 0; } xcp += dx; ycp += dy; vdmova_(&xcp, &ycp); } else strout[lenout++] = char_array[i]; } /* All done, get rid of them */ if (lenout != 0) { temp_xcp = map_x(xcp); temp_ycp = map_y(ycp); ctx2_(&temp_xcp, &temp_ycp, strout, &lenout); xcp += lenout * vector[6]; lenout = 0; } }
void vdinit_(float *aspect, int *justif) { float asp; int just, temp, temp2, vstat, vconc; float xconc, yconc, x1, y1, x2, y2, x3, y3, x4, y4, temp_xcp, temp_ycp; float scaled_ndc_xmax, scaled_ndc_ymax; float rtemp = 0.0; xconc = 0.0; yconc = 0.0; x1 = 0.0; y1 = 0.0; x2 = 0.0; y2 = 0.0; x3 = 0.0; y3 = 0.0; x4 = 0.0; y4 = 0.0; asp = *aspect; just = *justif; if (asp < 0.) { vdicgi_errh(" SVDI Shell (VDINIT) Error Number 721 Severity 5: "); asp = 0.; } if (just < 0 || just > 9) { vdicgi_errh(" SVDI Shell (VDINIT) Error Number 720 Severity 5: "); just = 0; } /* Initialize CGI */ temp = CACT; alpha_mode = FALSE; ci_(&temp); /* Inquire everything you always wanted to know about */ vbinq(); /* Turn off clip indicators */ temp = CDCOFF; cdscl_(&temp); temp = COFF; ccl_(&temp); /* Set up proper scaling to take advantage of whole device (not just square) */ if (asp == 0.) asp = dev_cap[14] / dev_cap[15]; if (asp > 1.) { ndc_xmax = 1.; ndc_ymax = 1. / asp; } else { ndc_xmax = asp; ndc_ymax = 1.; } scale = 32767.; scaled_ndc_xmax = map_x(ndc_xmax); scaled_ndc_ymax = map_y(ndc_ymax); rtemp = 0.0; cvdcx_(&rtemp, &rtemp, &scaled_ndc_xmax, &scaled_ndc_ymax); /* Set color mode to index, and set color index precision to 8 bits */ temp = CINDEX; ccsm_(&temp); temp = 8; ccixp_(&temp); color_scale = 255.; /* set up the standard 8 colors in indices 2 - 9 (0 reserved for background, 1 reserved for default foreground) */ temp = 2; temp2 = 8; cct_(&temp, &temp2, init_colors); /* Set default marker type to dot */ temp = 1; cmkt_(&temp); /* Set default interior style to solid */ temp = CSOLID; cis_(&temp); /* Inquire what the default character size is - use cgtxx instead of cqtxa because need both x and y size (may have to adjust for inter character/line spacing later */ temp_xcp = map_x(xcp); temp_ycp = map_y(ycp); cgtxx2_(&temp_xcp, &temp_ycp, &vstat, &vconc, &xconc, &yconc, &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4); if (vstat == CVAL) { vector[5] = ndc_map_x(x2 - x1); vector[6] = ndc_map_y(y4 - y1); } else vdicgi_errh(" SVDI Shell (VDINIT) inquire error from cgtxx "); /* Initialize locator device */ temp = CLOCAT; temp2 = 1; cili_(&temp, &temp2); }
int mandelbrot_point(int res_x, int res_y, int image_x, int image_y, float zoom, int max_iteration) { // Get the index of the current element float pos_x = map_x_mandelbrot(image_x, res_x, zoom); float pos_y = map_y(image_y, res_y, zoom); float x = 0.0; float y = 0.0; float q, x_term, pos_y2; float xtemp, xx, yy, xplusy; #ifdef CACHE int storeable = 1; #endif int iteration = 0; // Period-2 bulb check x_term = pos_x + 1.0; pos_y2 = pos_y * pos_y; if ((x_term * x_term + pos_y2) < 0.0625) return 0; // Cardioid check x_term = pos_x - 0.25; q = x_term * x_term + pos_y2; q = q * (q + x_term); if (q < (0.25 * pos_y2)) return 0; #ifdef CACHE // Look up our cache iteration = cached_iteration(pos_x, pos_y); if (iteration > 0) { x = get_cached_x(pos_x, pos_y); y = get_cached_y(pos_x, pos_y); yy = y * y; } if (iteration < 0) storeable = 0; #endif while (iteration < max_iteration) { xx = x * x; yy = y * y; xplusy = x + y; if ((xx) + (yy) > (4.0)) break; y = xplusy * xplusy - xx - yy; y = y + pos_y; xtemp = xx - yy + pos_x; x = xtemp; iteration++; } if (iteration >= max_iteration) { return 0; } else { #ifdef CACHE if (storeable == 1) { store_iteration(pos_x, pos_y, iteration, x, y); } #endif return iteration; } }