| 1 | #ifndef CDRIZZLEMAP_H |
| 2 | #define CDRIZZLEMAP_H |
| 3 | |
| 4 | #include "driz_portability.h" |
| 5 | #include "cdrizzleutil.h" |
| 6 | |
| 7 | /* Line segment structure, used for computing overlap |
| 8 | * The first index on line is the endpoint |
| 9 | * The second index is {x, y) coordinate of the point |
| 10 | * The valid flag is non-zero if it does not intersect the image |
| 11 | */ |
| 12 | |
| 13 | struct segment { |
| 14 | double point[2][2]; |
| 15 | int invalid; |
| 16 | }; |
| 17 | |
| 18 | // IMAGE_OUTLINE_NPTS - maximum number of vertices in the bounding polygon |
| 19 | // for input and resampled images |
| 20 | #define IMAGE_OUTLINE_NPTS 4 |
| 21 | |
| 22 | /** vertex structure. |
| 23 | * |
| 24 | * This structure holds coordinates of a polygon vertex. |
| 25 | * |
| 26 | */ |
| 27 | struct vertex { |
| 28 | double x; /**< x-coordinate */ |
| 29 | double y; /**< y-coordinate */ |
| 30 | }; |
| 31 | |
| 32 | /** polygon structure. |
| 33 | * |
| 34 | * This structure holds information about polygon vertices. The maximum number |
| 35 | * of vertices that this structure can hold is determined by the constant |
| 36 | * IMAGE_OUTLINE_NPTS and it is double of IMAGE_OUTLINE_NPTS value. |
| 37 | * |
| 38 | * NOTE: polygons must not be closed (that is last vertex != first vertex). |
| 39 | * |
| 40 | */ |
| 41 | struct polygon { |
| 42 | struct vertex v[2 * IMAGE_OUTLINE_NPTS]; /**< polygon vertices */ |
| 43 | int npv; /**< actual number of polygon vertices */ |
| 44 | }; |
| 45 | |
| 46 | /** edge structure. |
| 47 | * |
| 48 | * This structure holds invormation about vertices of the edge, edge position |
| 49 | * in the polygon (left or right of the line going through the top and bottom |
| 50 | * vertices), slope, and interceipts. |
| 51 | * |
| 52 | */ |
| 53 | struct edge { |
| 54 | struct vertex v1; /**< first vertex */ |
| 55 | struct vertex v2; /**< second vertex */ |
| 56 | double m; /**< edge's slope */ |
| 57 | double b; /**< edge's interceipt */ |
| 58 | double c; /**< modified interceipt */ |
| 59 | int p; /**< edge's position: -1 for left-side edge and +1 for right-side |
| 60 | edge */ |
| 61 | }; |
| 62 | |
| 63 | /** scanner structure. |
| 64 | * |
| 65 | * This structure holds information needed to "scan" or rasterize the |
| 66 | * intersection polygon formed by intersecting the bounding box of the output |
| 67 | * frame with the bounding box of the input frame in the input frame's |
| 68 | * coordinate system. |
| 69 | * |
| 70 | */ |
| 71 | struct scanner { |
| 72 | struct edge left_edges[2 * IMAGE_OUTLINE_NPTS]; /**< left edges */ |
| 73 | struct edge right_edges[2 * IMAGE_OUTLINE_NPTS]; /**< right edges */ |
| 74 | struct edge *left; /**< pointer to the current left edge; NULL when top |
| 75 | polygon vertex was reached */ |
| 76 | struct edge *right; /**< pointer to the current right edge; NULL when top |
| 77 | polygon vertex was reached */ |
| 78 | int nleft; /**< number of left edges */ |
| 79 | int nright; /**< number of right edges */ |
| 80 | double min_y; /**< minimum y-coordinate of all polygon vertices */ |
| 81 | double max_y; /**< maximum y-coordinate of all polygon vertices */ |
| 82 | int xmin; /**< min valid pixels' x-coord in pixmap (from bounding box |
| 83 | carried over from driz_param_t) rounded to int */ |
| 84 | int xmax; /**< max valid pixels' x-coord in pixmap (from bounding box |
| 85 | carried over from driz_param_t) rounded to int */ |
| 86 | int ymin; /**< min valid pixels' y-coord in pixmap (from bounding box |
| 87 | carried over from driz_param_t) rounded to int */ |
| 88 | int ymax; /**< max valid pixels' y-coord in pixmap (from bounding box |
| 89 | carried over from driz_param_t) rounded to int */ |
| 90 | // overlap_valid: 1 if polygon intersection and coord inversion worked; |
| 91 | // 0 if computation of xmin, xmax, ymin, ymax has |
| 92 | // failed in which case they are carried over from |
| 93 | // driz_param_t. |
| 94 | int overlap_valid; /**< 1 if x/y min/max updated from polygon intersection |
| 95 | and 0 if carried over from driz_param_t */ |
| 96 | struct polygon bounding_polygon; /**< bounding polygon in input image |
| 97 | outlining the scan region */ |
| 98 | }; |
| 99 | |
| 100 | int |
| 101 | interpolate_point(struct driz_param_t *par, double xin, double yin, double *xout, double *yout); |
| 102 | |
| 103 | int |
| 104 | interpolate_four_points( |
| 105 | struct driz_param_t *par, int ixcen, int iycen, double h, double *x1, double *x2, double *x3, |
| 106 | double *x4, double *y1, double *y2, double *y3, double *y4); |
| 107 | |
| 108 | int |
| 109 | map_point(struct driz_param_t *par, double xin, double yin, double *xout, double *yout); |
| 110 | |
| 111 | int |
| 112 | map_pixel(PyArrayObject *pixmap, int i, int j, double *x, double *y); |
| 113 | |
| 114 | int |
| 115 | shrink_image_section(PyArrayObject *pixmap, int *xmin, int *xmax, int *ymin, int *ymax); |
| 116 | |
| 117 | int |
| 118 | invert_pixmap(struct driz_param_t *par, double xout, double yout, double *xin, double *yin); |
| 119 | |
| 120 | int |
| 121 | clip_polygon_to_window(const struct polygon *p, const struct polygon *wnd, struct polygon *cp); |
| 122 | |
| 123 | int |
| 124 | init_scanner(struct polygon *p, struct driz_param_t *par, struct scanner *s); |
| 125 | |
| 126 | int |
| 127 | get_scanline_limits(struct scanner *s, int y, int *x1, int *x2); |
| 128 | |
| 129 | int |
| 130 | init_image_scanner(struct driz_param_t *par, struct scanner *s, int *ymin, int *ymax); |
| 131 | |
| 132 | int |
| 133 | polygon_centroid(const struct polygon *p, double *cx, double *cy); |
| 134 | |
| 135 | #endif /* CDRIZZLEMAP_H */ |