25 #include <grass/gis.h>
26 #include <grass/gstypes.h>
40 static geoline *copy_line(geoline *);
41 static geoline *thin_line(geoline *,
float);
51 static geoline *copy_line(geoline * gln)
56 newln = (geoline *) G_malloc(
sizeof(geoline));
61 np = newln->npts = gln->npts;
63 if (2 == (newln->dims = gln->dims)) {
64 newln->p2 = (Point2 *) G_calloc(np,
sizeof(Point2));
69 for (i = 0; i < np; i++) {
70 newln->p2[i][
X] = gln->p2[i][
X];
71 newln->p2[i][
Y] = gln->p2[i][
Y];
75 newln->p3 = (Point3 *) G_calloc(np,
sizeof(Point3));
80 for (i = 0; i < np; i++) {
81 newln->p3[i][
X] = gln->p3[i][
X];
82 newln->p3[i][
Y] = gln->p3[i][
Y];
83 newln->p3[i][Z] = gln->p3[i][Z];
104 static geoline *thin_line(geoline * gln,
float factor)
109 newln = (geoline *) G_malloc(
sizeof(geoline));
114 targp = (
int)(gln->npts / factor);
122 if (2 == (newln->dims = gln->dims)) {
123 newln->p2 = (Point2 *) G_calloc(targp,
sizeof(Point2));
128 for (i = 0; i < targp; i++) {
129 if (i == targp - 1) {
130 nextp = gln->npts - 1;
133 nextp = (
int)((i * (gln->npts - 1)) / (targp - 1));
136 newln->p2[i][
X] = gln->p2[nextp][
X];
137 newln->p2[i][
Y] = gln->p2[nextp][
Y];
141 newln->p3 = (Point3 *) G_calloc(targp,
sizeof(Point3));
146 for (i = 0; i < targp; i++) {
147 if (i == targp - 1) {
148 nextp = gln->npts - 1;
151 nextp = (
int)((i * (gln->npts - 1)) / (targp - 1));
154 newln->p3[i][
X] = gln->p3[nextp][
X];
155 newln->p3[i][
Y] = gln->p3[nextp][
Y];
156 newln->p3[i][Z] = gln->p3[nextp][Z];
177 for (n = 0; n < gln->npts - 1; n++) {
201 for (tln = gln; tln; tln = tln->next) {
234 int T_pts, A_ppl, N_s;
235 float decim_factor, slength[
MFAST_LNS], T_slength, A_slength;
240 gv->fastlines = gv->lines;
248 A_ppl = T_pts / gv->n_lines;
252 for (gln = gv->lines; gln; gln = gln->next) {
253 if (gln->npts > A_ppl) {
255 prev->next = thin_line(gln, decim_factor);
259 prev = gv->fastlines = thin_line(gln, decim_factor);
267 A_slength = T_slength / N_s;
270 for (gln = gv->lines; gln; gln = gln->next) {
271 if (gln->npts <= A_ppl) {
273 if (slength[N_s++] > A_slength) {
275 prev->next = copy_line(gln);
279 prev = gv->fastlines = copy_line(gln);
286 G_debug(3,
"Decimated lines have %d points.",
#define TFAST_PTS
target number of desired points to represent entire file
float gv_line_length(geoline *gln)
Get line width.
int gv_decimate_lines(geovect *gv)
Decimate line.
int gln_num_points(geoline *gln)
Get number of line vertices.
int gv_num_points(geovect *gv)
Get number of points in vector.
int G_debug(int level, const char *msg,...)
Print debugging message.
#define MFAST_LNS
max number of lines desired
float GS_distance(float *from, float *to)
Calculate distance.
float GS_P2distance(float *from, float *to)
Calculate distance in plane.