GRASS GIS 7 Programmer's Manual
7.9.dev(2021)-e5379bbd7
|
OGSF library - functions to intersect line segments with edges of surface polygons. More...
#include <stdlib.h>
#include <grass/ogsf.h>
#include <grass/glocale.h>
#include "gsget.h"
#include "rowcol.h"
#include "math.h"
Go to the source code of this file.
Macros | |
#define | DONT_INTERSECT 0 |
#define | DO_INTERSECT 1 |
#define | COLLINEAR 2 |
#define | LERP(a, l, h) ((l)+(((h)-(l))*(a))) |
#define | EQUAL(a, b) (fabs((a)-(b))<EPSILON) |
#define | ISNODE(p, res) (fmod((double)p,(double)res)<EPSILON) |
#define | SAME_SIGNS(a, b) ((a >= 0 && b >= 0) || (a < 0 && b < 0)) |
Functions | |
int | gsdrape_set_surface (geosurf *gs) |
ADD. More... | |
int | seg_intersect_vregion (geosurf *gs, float *bgn, float *end) |
Check if segment intersect vector region. More... | |
Point3 * | gsdrape_get_segments (geosurf *gs, float *bgn, float *end, int *num) |
ADD. More... | |
Point3 * | gsdrape_get_allsegments (geosurf *gs, float *bgn, float *end, int *num) |
Get all segments. More... | |
void | interp_first_last (geosurf *gs, float *bgn, float *end, Point3 f, Point3 l) |
ADD. More... | |
int | _viewcell_tri_interp (geosurf *gs, Point3 pt) |
ADD. More... | |
int | viewcell_tri_interp (geosurf *gs, typbuff *buf, Point3 pt, int check_mask) |
ADD. More... | |
int | in_vregion (geosurf *gs, float *pt) |
ADD. More... | |
int | order_intersects (geosurf *gs, Point3 first, Point3 last, int vi, int hi, int di) |
ADD. More... | |
int | get_vert_intersects (geosurf *gs, float *bgn, float *end, float *dir) |
ADD. More... | |
int | get_horz_intersects (geosurf *gs, float *bgn, float *end, float *dir) |
Get horizontal intersects. More... | |
int | get_diag_intersects (geosurf *gs, float *bgn, float *end, float *dir) |
Get diagonal intersects. More... | |
int | segs_intersect (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float *x, float *y) |
Line intersect. More... | |
int | Point_on_plane (Point3 p1, Point3 p2, Point3 p3, Point3 unk) |
Check if point is on plane. More... | |
int | XY_intersect_plane (float *intersect, float *plane) |
Check for intersection (point and plane) More... | |
int | P3toPlane (Point3 p1, Point3 p2, Point3 p3, float *plane) |
Define plane. More... | |
int | V3Cross (Point3 a, Point3 b, Point3 c) |
Get cross product. More... | |
OGSF library - functions to intersect line segments with edges of surface polygons.
GRASS OpenGL gsurf OGSF Library
For efficiency, intersections are found without respect to which specific triangle edge is intersected, but on a broader sense with the horizontal, vertical, and diagonal seams in the grid, then the intersections are ordered. If quadstrips are used for drawing rather than tmesh, triangulation is not consistent; for diagonal intersections, the proper diagonal to intersect would need to be determined according to the algorithm used by qstrip (look at nearby normals). It may be faster to go ahead and find the intersections with the other diagonals using the same methods, then at sorting time determine which diagonal array to look at for each quad. It would also require a mechanism for throwing out unused intersections with the diagonals during the ordering phase. Do intersections in 2D, fill line structure with 3D pts (maybe calling routine will cache for redrawing). Get Z value by using linear interp between corners.
Return static pointer to 3D set of points. Max number of intersections will be rows + cols + diags, so should allocate this number to initialize. Let calling routine worry about copying points for caching.
(C) 1999-2008 by the GRASS Development Team
This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
Definition in file gsdrape.c.
#define ISNODE | ( | p, | |
res | |||
) | (fmod((double)p,(double)res)<EPSILON) |
Definition at line 63 of file gsdrape.c.
Referenced by viewcell_tri_interp().
ADD.
gs | surface (geosurf) |
pt |
Definition at line 467 of file gsdrape.c.
References ATT_TOPO, gs_get_att_typbuff(), and viewcell_tri_interp().
Referenced by GS_draw_X().
int get_diag_intersects | ( | geosurf * | gs, |
float * | bgn, | ||
float * | end, | ||
float * | dir | ||
) |
int get_horz_intersects | ( | geosurf * | gs, |
float * | bgn, | ||
float * | end, | ||
float * | dir | ||
) |
int get_vert_intersects | ( | geosurf * | gs, |
float * | bgn, | ||
float * | end, | ||
float * | dir | ||
) |
ADD.
Colinear already eliminated
gs | surface (geosurf) |
bgn | begin point |
end | end point |
dir | direction |
Definition at line 882 of file gsdrape.c.
References EPSILON, segs_intersect(), VCOL2X, VCOLS, VROWS, VXRES, VYRES, X, X2VCOL, and g_surf::yrange.
Get all segments.
gs | surface (geosurf) |
bgn | begin point |
end | end point |
num |
Definition at line 401 of file gsdrape.c.
References GS_v3eq(), gsdrape_set_surface(), interp_first_last(), NULL, and seg_intersect_vregion().
ADD.
gs | surface (geosurf) |
bgn | begin point (x,y) |
end | end point (x,y) |
num |
Definition at line 350 of file gsdrape.c.
References ATT_TOPO, CONST_ATT, gs_get_att_src(), gsdrape_set_surface(), NULL, and seg_intersect_vregion().
Referenced by gsd_line_onsurf(), gsd_nline_onsurf(), and gvd_draw_lineonsurf().
int gsdrape_set_surface | ( | geosurf * | gs | ) |
ADD.
gs | surface (geosurf) |
Definition at line 199 of file gsdrape.c.
Referenced by gsdrape_get_allsegments(), and gsdrape_get_segments().
int in_vregion | ( | geosurf * | gs, |
float * | pt | ||
) |
ADD.
gs | surface (geosurf) |
Definition at line 696 of file gsdrape.c.
References VCOL2X, VCOLS, VROW2Y, VROWS, and g_surf::yrange.
Referenced by GS_get_cat_at_xy(), GS_get_norm_at_xy(), GS_get_val_at_xy(), and seg_intersect_vregion().
ADD.
gs | surface (geosurf) |
bgn | begin point |
end | end point |
f | first |
l | last |
Definition at line 441 of file gsdrape.c.
Referenced by gsdrape_get_allsegments().
ADD.
After all the intersections between the segment and triangle edges have been found, they are in three lists. (intersections with vertical, horizontal, and diagonal triangle edges)
Each list is ordered in space from first to last segment points, but now the lists need to be woven together. This routine starts with the first point of the segment and then checks the next point in each list to find the closest, eliminating duplicates along the way and storing the result in I3d.
gs | surface (geosurf) |
first | first point |
last | last point |
vi | |
hi | |
di |
Define plane.
p1,p2,p3 | three point on plane | |
[out] | plane | plane definition |
Definition at line 1335 of file gsdrape.c.
Referenced by Point_on_plane().
Check if point is on plane.
Plane defined by three points here; user fills in unk[X] & unk[Y]
p1,p2,p3 | points defining plane |
unk | point |
Definition at line 1290 of file gsdrape.c.
References P3toPlane(), and XY_intersect_plane().
Referenced by viewcell_tri_interp().
int seg_intersect_vregion | ( | geosurf * | gs, |
float * | bgn, | ||
float * | end | ||
) |
Check if segment intersect vector region.
Clipping performed:
gs | surface (geosurf) |
bgn | begin point |
end | end point |
Definition at line 233 of file gsdrape.c.
References GS_P2distance(), in_vregion(), segs_intersect(), VCOL2X, VCOLS, VROW2Y, VROWS, X, and Y.
Referenced by gsdrape_get_allsegments(), and gsdrape_get_segments().
int segs_intersect | ( | float | x1, |
float | y1, | ||
float | x2, | ||
float | y2, | ||
float | x3, | ||
float | y3, | ||
float | x4, | ||
float | y4, | ||
float * | x, | ||
float * | y | ||
) |
Line intersect.
Author: Mukesh Prasad Modified for floating point: Bill Brown
This function computes whether two line segments, respectively joining the input points (x1,y1) – (x2,y2) and the input points (x3,y3) – (x4,y4) intersect. If the lines intersect, the output variables x, y are set to coordinates of the point of intersection.
x1,y1,x2,y2 | coordinates of endpoints of one segment | |
x3,y3,x4,y4 | coordinates of endpoints of other segment | |
[out] | x,y | coordinates of intersection point |
Definition at line 1210 of file gsdrape.c.
Referenced by get_horz_intersects(), get_vert_intersects(), and seg_intersect_vregion().
ADD.
In gsd_surf, tmesh draws polys like so:
-------------- | /| | / | | / | | / | | / | | / | | / | | / | | / | | / | | / | |/ | --------------
UNLESS the top right or bottom left point is masked, in which case a single triangle with the opposite diagonal is drawn. This case is not yet handled here & should only occur on edges. pt has X & Y coordinates in it, we interpolate Z here
This could probably be much shorter, but not much faster.
Definition at line 507 of file gsdrape.c.
References g_surf::att, ATT_TOPO, CONST_ATT, gsurf_att::constant, DRC2OFF, GET_MAPATT, gs_get_att_src(), gs_point_is_masked(), LERP, MAP_ATT, Point_on_plane(), VCOL2DCOL, VCOL2X, VCOLS, VROW2DROW, VROW2Y, VROWS, VXRES, VYRES, X, X2VCOL, Y, Y2VROW, g_surf::yrange, and Z.
Referenced by _viewcell_tri_interp().
int XY_intersect_plane | ( | float * | intersect, |
float * | plane | ||
) |
Check for intersection (point and plane)
Ax + By + Cz + D = 0, so z = (Ax + By + D) / -C
User fills in intersect[X] & intersect[Y]
[out] | intersect | intersect coordinates |
plane | plane definition |
Definition at line 1312 of file gsdrape.c.
Referenced by Point_on_plane().