21 #include <grass/gis.h>
22 #include <grass/Vect.h>
23 #include <grass/glocale.h>
24 #include <grass/gstypes.h>
31 static int Tot_mem = 0;
48 struct line_pnts *points;
49 geoline *top, *gln, *prev;
50 int np, i, n, nareas, nl = 0, area,
type, is3d;
51 struct Cell_head wind;
57 G_warning(_(
"Vector map <%s> not found"), grassname);
63 G_warning(_(
"Unable to open vector map <%s>"),
68 top = gln = (geoline *) G_malloc(
sizeof(geoline));
76 Tot_mem +=
sizeof(geoline);
83 wind.west, PORT_DOUBLE_MAX, -PORT_DOUBLE_MAX);
90 G_debug(3,
"Reading vector areas (nareas = %d)", n);
91 for (area = 1; area <= n; area++) {
95 if (points->n_points < 3)
97 gln->type = OGSF_POLYGON;
98 gln->npts = np = points->n_points;
103 gln->p3 = (Point3 *) G_calloc(np,
sizeof(Point3));
108 Tot_mem += (np *
sizeof(Point3));
113 gln->p2 = (Point2 *) G_calloc(np,
sizeof(Point2));
118 Tot_mem += (np *
sizeof(Point2));
122 for (i = 0; i < np; i++) {
124 gln->p3[i][
X] = points->x[i];
125 gln->p3[i][
Y] = points->y[i];
126 gln->p3[i][Z] = points->z[i];
129 gln->p2[i][
X] = points->x[i];
130 gln->p2[i][
Y] = points->y[i];
135 vect[0][
X] = (float)(gln->p3[0][
X] - gln->p3[1][
X]);
136 vect[0][
Y] = (float)(gln->p3[0][
Y] - gln->p3[1][
Y]);
137 vect[0][Z] = (float)(gln->p3[0][Z] - gln->p3[1][Z]);
138 vect[1][
X] = (float)(gln->p3[2][
X] - gln->p3[1][
X]);
139 vect[1][
Y] = (float)(gln->p3[2][
Y] - gln->p3[1][
Y]);
140 vect[1][Z] = (float)(gln->p3[2][Z] - gln->p3[1][Z]);
145 gln->next = (geoline *) G_malloc(
sizeof(geoline));
151 Tot_mem +=
sizeof(geoline);
158 G_debug(3,
"%d areas loaded", nareas);
161 G_debug(3,
"Reading vector lines ...");
163 G_debug(3,
"line type = %d", type);
167 gln->type = OGSF_LINE;
170 gln->type = OGSF_POLYGON;
174 gln->npts = np = points->n_points;
179 gln->p3 = (Point3 *) G_calloc(np,
sizeof(Point3));
184 Tot_mem += (np *
sizeof(Point3));
189 gln->p2 = (Point2 *) G_calloc(np,
sizeof(Point2));
194 Tot_mem += (np *
sizeof(Point2));
198 for (i = 0; i < np; i++) {
200 gln->p3[i][
X] = points->x[i];
201 gln->p3[i][
Y] = points->y[i];
202 gln->p3[i][Z] = points->z[i];
205 gln->p2[i][
X] = points->x[i];
206 gln->p2[i][
Y] = points->y[i];
210 if (is3d && gln->type == OGSF_POLYGON) {
211 vect[0][
X] = (float)(gln->p3[0][
X] - gln->p3[1][
X]);
212 vect[0][
Y] = (float)(gln->p3[0][
Y] - gln->p3[1][
Y]);
213 vect[0][Z] = (float)(gln->p3[0][Z] - gln->p3[1][Z]);
214 vect[1][
X] = (float)(gln->p3[2][
X] - gln->p3[1][
X]);
215 vect[1][
Y] = (float)(gln->p3[2][
Y] - gln->p3[1][
Y]);
216 vect[1][Z] = (float)(gln->p3[2][Z] - gln->p3[1][Z]);
218 G_debug(3,
"norm %f %f %f", gln->norm[0], gln->norm[1],
222 gln->next = (geoline *) G_malloc(
sizeof(geoline));
227 Tot_mem +=
sizeof(geoline);
235 G_debug(3,
"%d lines loaded", nl);
243 Tot_mem -=
sizeof(geoline);
249 G_warning(_(
"No features from vector map <%s> fall within current region"),
254 G_message(_(
"Vector map <%s> loaded (%d features)"),
261 G_debug(3,
"Total vect memory = %d Kbytes", Tot_mem / 1000);