GRASS GIS 7 Programmer's Manual
7.8.2(2019)-exported
|
Go to the documentation of this file.
22 #include <grass/gis.h>
23 #include <grass/glocale.h>
24 #include <grass/ogsf.h>
26 static float spl3(
float,
double,
double,
double,
double,
double,
double,
29 static float spl3(
float tension,
double data0,
double data1,
double x,
30 double x2,
double x3,
double lderiv,
double rderiv)
33 (data0 * (2 * x3 - 3 * x2 + 1) + data1 * (-2 * x3 + 3 * x2) +
34 (
double)tension * lderiv * (x3 - 2 * x2 +
x) +
35 (
double)tension * rderiv * (x3 - x2)));
50 newk = (Keylist *) G_malloc(
sizeof(Keylist));
55 for (i = 0; i < KF_NUMFIELDS; i++) {
56 newk->fields[i] = k->fields[i];
60 newk->look_ahead = k->look_ahead;
61 newk->fieldmask = k->fieldmask;
62 newk->next = newk->prior =
NULL;
82 float startpos, endpos, curpos;
83 unsigned long mask = 0xFFFFFFFF;
87 for (k = keys; k->next; k = k->next) ;
91 curpos = startpos + time * (endpos - startpos);
93 for (k = keys; k->next; k = k->next) {
94 if (k->pos <= curpos) {
118 for (k = keys; k; k = k->next) {
119 if ((mask & k->fieldmask) == mask) {
142 int onestep,
int render,
unsigned long mode)
151 for (frame = step - 1; frame < numsteps; frame++) {
161 if ((mask & KF_FROMX_MASK)) {
162 tmp[
X] = v->fields[KF_FROMX];
164 if ((mask & KF_FROMY_MASK)) {
165 tmp[
Y] = v->fields[KF_FROMY];
167 if ((mask & KF_FROMZ_MASK)) {
168 tmp[Z] = v->fields[KF_FROMZ];
174 G_debug(3,
"gk_follow_frames():");
175 G_debug(3,
" MASK: %lx", mask);
176 G_debug(3,
" FROM: %f %f %f", tmp[
X], tmp[
Y], tmp[Z]);
183 if ((mask & KF_DIRX_MASK)) {
184 tmp[
X] = v->fields[KF_DIRX];
186 if ((mask & KF_DIRY_MASK)) {
187 tmp[
Y] = v->fields[KF_DIRY];
189 if ((mask & KF_DIRZ_MASK)) {
190 tmp[Z] = v->fields[KF_DIRZ];
198 G_debug(3,
"gk_follow_frames():");
200 G_debug(3,
" DIR: %f %f %f\n", tmp[
X], tmp[
Y], tmp[Z]);
202 if ((mask & KF_TWIST_MASK)) {
206 if ((mask & KF_FOV_MASK)) {
236 if (mode & FM_PATH) {
240 if (mode & FM_VECT) {
244 if (mode & FM_SITE) {
254 if (mode & FM_LABEL) {
305 Viewnode *v, *newview;
306 Keylist *k, *kp1, *kp2, *km1, **tkeys;
307 float startpos, endpos;
308 double dt1, dt2,
x, x2, x3, range, time, time_step, len, rderiv, lderiv;
311 tkeys = (Keylist **) G_malloc(keysteps *
sizeof(Keylist *));
318 if (keys && keysteps) {
320 G_warning(_(
"Need at least 3 keyframes for spline"));
326 for (k = keys; k->next; k = k->next) ;
328 startpos = keys->pos;
330 range = endpos - startpos;
331 time_step = range / (newsteps - 1);
333 newview = (Viewnode *) G_malloc(newsteps *
sizeof(Viewnode));
339 for (i = 0; i < newsteps; i++) {
344 time = startpos + i * time_step;
346 if (i == newsteps - 1) {
350 for (field = 0; field < KF_NUMFIELDS; field++) {
354 k = kp1 = kp2 = km1 =
NULL;
359 loop, tkeys, &k, &kp1, &kp2, &km1,
366 if (len == 0.0 || nvk == 0) {
370 v->fields[field] = keys->fields[field];
374 v->fields[field] = k->fields[field];
379 else if (!km1 && !kp2) {
381 v->fields[field] =
lin_interp((time - k->pos) / len,
387 x = (time - k->pos) / len;
393 rderiv = (kp2->fields[field] - k->fields[field]) / dt2;
394 lderiv = (3 * (kp1->fields[field] -
395 k->fields[field]) / dt1 - rderiv) / 2.0;
396 v->fields[field] = spl3(
t, k->fields[field],
397 kp1->fields[field],
x, x2, x3,
402 lderiv = (kp1->fields[field] - km1->fields[field]) / dt1;
403 rderiv = (3 * (kp1->fields[field] -
404 k->fields[field]) / dt2 - lderiv) / 2.0;
405 v->fields[field] = spl3(
t, k->fields[field],
406 kp1->fields[field],
x, x2, x3,
411 lderiv = (kp1->fields[field] - km1->fields[field]) / dt1;
412 rderiv = (kp2->fields[field] - k->fields[field]) / dt2;
413 v->fields[field] = spl3(
t, k->fields[field],
414 kp1->fields[field],
x, x2, x3,
456 Keylist * karray[], Keylist ** km1, Keylist ** kp1,
457 Keylist ** kp2, Keylist ** km2,
double *dt1,
463 *km1 = *kp1 = *kp2 = *km2 =
NULL;
466 for (i = 0; i < nvk; i++) {
467 if (time < karray[i]->pos) {
478 *km1 = karray[nvk - 1];
483 *km1 = karray[i - 1];
485 len = karray[i]->pos - karray[i - 1]->pos;
490 *km2 = karray[nvk - 2];
491 *kp2 = karray[(i + 1) % nvk];
495 *kp2 = karray[i + 1];
499 else if (i == nvk - 1) {
502 *km2 = nvk > 2 ? karray[i - 2] : karray[1];
507 *km2 = karray[i - 2];
512 *km2 = karray[i - 2];
513 *kp2 = karray[i + 1];
516 *dt1 = (*km2) ? (*kp1)->pos - (*km2)->pos : len;
517 *dt2 = (*kp2) ? (*kp2)->pos - (*km1)->pos : len;
519 if (i == 1 && loop) {
523 if (i == nvk - 1 && loop) {
541 return ((
double)(val1 + dt * (val2 - val1)));
559 Keylist * karray[], Keylist ** km1, Keylist ** kp1)
566 for (i = 0; i < nvk; i++) {
567 if (time < karray[i]->pos) {
578 *km1 = karray[nvk - 1];
583 *km1 = karray[i - 1];
585 len = karray[i]->pos - karray[i - 1]->pos;
605 int newsteps,
int loop)
608 Viewnode *v, *newview;
609 Keylist *k, *k1, *k2, **tkeys;
610 float startpos, endpos, dt, range, time, time_step, len;
613 tkeys = (Keylist **) G_malloc(keysteps *
sizeof(Keylist *));
620 if (keys && keysteps) {
622 G_warning(_(
"Need at least 2 keyframes for interpolation"));
628 for (k = keys; k->next; k = k->next) ;
630 startpos = keys->pos;
632 range = endpos - startpos;
633 time_step = range / (newsteps - 1);
635 newview = (Viewnode *) G_malloc(newsteps *
sizeof(Viewnode));
641 for (i = 0; i < newsteps; i++) {
646 time = startpos + i * time_step;
647 if (i == newsteps - 1) {
651 for (field = 0; field < KF_NUMFIELDS; field++) {
656 v->fields[field] = keys->fields[field];
666 if (len == 0.0 || nvk == 0) {
670 v->fields[field] = keys->fields[field];
674 v->fields[field] = k1->fields[field];
678 dt = (time - k1->pos) / len;
707 for (c = k; c; c = c->next) {
709 if ((c->fields[KF_TWIST] - p->fields[KF_TWIST]) > 1800.) {
710 for (
t = c;
t;
t =
t->next) {
711 t->fields[KF_TWIST] -= 3600.;
714 else if ((p->fields[KF_TWIST] - c->fields[KF_TWIST]) > 1800.) {
715 for (
t = k, j = 0; j < cnt; j++,
t =
t->next) {
716 t->fields[KF_TWIST] -= 3600.;
745 if (!views || !keys) {
759 for (frame = 0; frame < steps; frame++) {
769 for (k = keys; k; k = k->next) {
int gk_viable_keys_for_mask(unsigned long mask, Keylist *keys, Keylist **keyret)
ADD.
int G_put_window(const struct Cell_head *window)
Writes the region (window)
int G_open_new(const char *element, const char *name)
Open a new database file.
const char * G_program_name(void)
Return module name.
double G_ellipsoid_polygon_area(const double *lon, const double *lat, int n)
Area of lat-long polygon.
void gsd_color_func(unsigned int col)
Set current color.
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
void G_plot_fx(double(*f)(double), double east1, double east2)
Plot f(east1) to f(east2)
void GS_set_twist(int t)
Set viewpoint twist value.
double G_adjust_east_longitude(double east, double west)
Adjust east longitude.
int G_strncasecmp(const char *x, const char *y, int n)
String compare ignoring case (upper or lower) - limited number of characters.
int G_remove_vector_timestamp(const char *name, const char *layer)
Remove timestamp from vector map.
void G_get_window(struct Cell_head *window)
Get the current region.
double G_area_for_zone_on_sphere(double north, double south)
Calculates area between latitudes.
void G_begin_zone_area_on_ellipsoid(double a, double e2, double s)
Begin area calculations for ellipsoid.
int G_scan_timestamp(struct TimeStamp *ts, const char *buf)
Fill a TimeStamp structure from a datetime string.
struct Flag * G_define_flag(void)
Initializes a Flag struct.
void output(const char *fmt,...)
double G_geodesic_distance_lon_to_lon(double lon1, double lon2)
Calculates geodesic distance.
void G_set_timestamp(struct TimeStamp *ts, const DateTime *dt)
Set timestamp (single)
int G_begin_cell_area_calculations(void)
Begin cell area calculations.
int G_scan_easting(const char *buf, double *easting, int projection)
ASCII easting to double.
void correct_twist(Keylist *k)
Correct twist value.
int G_get_ellipsoid_parameters(double *a, double *e2)
get ellipsoid parameters
char * G_store(const char *s)
Copy string to allocated memory.
void GV_alldraw_vect(void)
Draw all loaded vector sets.
void GS_set_viewdir(float *dir)
Set viewdir.
void G_begin_geodesic_distance(double a, double e2)
Begin geodesic distance.
double G_area_of_polygon(const double *x, const double *y, int n)
Area in square meters of polygon.
const char * G_find_file(const char *element, char *name, const char *mapset)
Searches for a file from the mapset search list or in a specified mapset.
void G_init_timestamp(struct TimeStamp *ts)
Initialize timestamp structure.
int G_begin_distance_calculations(void)
Begin distance calculations.
void GS_clear(int col)
Clear view.
int G_zone(void)
Query cartographic zone.
void G_get_timestamps(const struct TimeStamp *ts, DateTime *dt1, DateTime *dt2, int *count)
Copy TimeStamp into [two] Datetimes structs.
unsigned long gk_get_mask_sofar(float time, Keylist *keys)
Get mask value.
int G_read_vector_timestamp(const char *name, const char *layer, const char *mapset, struct TimeStamp *ts)
Read timestamp from vector map.
double G_transverse_radius_of_curvature(double lon, double a, double e2)
Transverse radius of curvature.
char * G_chop(char *line)
Chop leading and trailing white spaces.
void gsd_x(geosurf *gs, float *center, int colr, float siz)
Draw X symbol.
const char * G_mapset(void)
Get current mapset name.
void G_set_geodesic_distance_lat2(double lat2)
Sets geodesic distance lat2.
int G_spawn(const char *command,...)
Spawn new process based on command.
int G_rename(const char *element, const char *oldname, const char *newname)
Rename a database file.
char * G_strchg(char *bug, char character, char new)
Replace all occurrences of character in string bug with new.
int G_get_ellipsoid_by_name(const char *name, double *a, double *e2)
Get ellipsoid parameters by name.
void gsd_colormode(int cm)
Set color mode.
const char * G_whoami(void)
Gets user's name.
FILE * G_fopen_append(const char *element, const char *name)
Open a database file for update (append mode)
const char * G_home(void)
Get user's home directory.
void GVL_alldraw_vol(void)
Draw all volume sets.
void gsd_endline(void)
End line.
double G_database_units_to_meters_factor(void)
Conversion to meters.
int G_scan_northing(const char *buf, double *northing, int projection)
ASCII northing to double.
Keylist * gk_copy_key(Keylist *k)
Copy keyframes.
unsigned int GS_background_color(void)
Get background color.
int G_read_raster_timestamp(const char *name, const char *mapset, struct TimeStamp *ts)
Read timestamp from raster map.
int GS_get_longdim(float *dim)
Get largest dimension.
void GS_set_draw(int where)
Sets which buffer to draw to.
void GS_get_from(float *fr)
Get viewpoint 'from' position.
int G_write_vector_timestamp(const char *name, const char *layer, const struct TimeStamp *ts)
Write timestamp of vector map.
double get_2key_neighbors(int nvk, float time, float range, int loop, Keylist *karray[], Keylist **km1, Keylist **kp1)
Finds interval containing time, putting left (or equal) key at km1, right at kp1.
void G_squeeze(char *line)
Remove superfluous white space.
void G_plot_line(double east1, double north1, double east2, double north2)
Plot line between latlon coordinates (fastline)
void G_get_default_window(struct Cell_head *window)
Get the default region.
double G_radius_of_conformal_tangent_sphere(double lon, double a, double e2)
Radius of conformal tangent sphere.
FILE * G_popen_write(struct Popen *state, const char *program, const char **args)
void GS_set_fov(int fov)
Set field of view.
int G_spawn_ex(const char *command,...)
Spawn new process based on command.
char * G_tolcase(char *string)
convert string to lower case
void G_shortest_way(double *east1, double *east2)
Shortest way between two eastings.
void G_message(const char *msg,...)
Print a message to stderr.
double G_planimetric_polygon_area(const double *x, const double *y, int n)
Calculates planimetric polygon area.
void G_set_window(struct Cell_head *window)
Establishes window as the current working window (region).
int order(int i_x, int i_y, int yNum)
char * G_toucase(char *string)
convert string to upper case
void gsd_bgnline(void)
Begin line.
int G_plot_polygon(const double *x, const double *y, int n)
Plot filled polygon with n vertices.
void G_plot_where_xy(double east, double north, int *x, int *y)
Converts east,north to x,y.
void G_free(void *buf)
Free allocated memory.
void G_set_timestamp_range(struct TimeStamp *ts, const DateTime *dt1, const DateTime *dt2)
Set timestamp (range)
int G_pole_in_polygon(const double *x, const double *y, int n)
Check if pole is in polygon.
void GS_alldraw_cplane_fences(void)
Draw all cplace fences ?
void gsd_vert_func(float *pt)
ADD.
void G_percent(long n, long d, int s)
Print percent complete messages.
FILE * G_fopen_new(const char *element, const char *name)
Open a new database file.
void G_disable_interactive(void)
Disables the ability of the parser to operate interactively.
void gk_free_key(Keylist *ok)
Free keyframe list.
void G_bresenham_line(int x0, int y0, int x1, int y1, int(*point)(int, int))
Bresenham line algorithm.
const char * G_date(void)
Current date and time.
double G_meridional_radius_of_curvature(double lon, double a, double e2)
Meridional radius of curvature.
cairo_surface_t * surface
void GP_alldraw_site(void)
Draw all available point sets.
int G_scan_resolution(const char *buf, double *res, int projection)
ASCII resolution to double.
double G_area_of_cell_at_row(int row)
Cell area in specified row.
Viewnode * gk_make_linear_framesfromkeys(Keylist *keys, int keysteps, int newsteps, int loop)
Generate viewnode from keyframe list (linear interpolation)
int main(int argc, char *argv[])
int G_projection(void)
Query cartographic projection.
void G_trim_decimal(char *buf)
Removes trailing zeros from decimal number.
const char * G_database_projection_name(void)
Query cartographic projection for the current location.
const char * G_ellipsoid_name(int n)
Get ellipsoid name.
void gsd_linewidth(short n)
Set width of rasterized lines.
const char * G_database_unit_name(int plural)
Get units (localized) name for the current location.
int G_begin_polygon_area_calculations(void)
Begin polygon area calculations.
int G_parser(int argc, char **argv)
Parse command line.
void GS_setlight_position(int num, float xpos, float ypos, float zpos, int local)
Set light position.
void G_setup_plot(double t, double b, double l, double r, int(*Move)(int, int), int(*Cont)(int, int))
Initialize plotting routines.
void G_set_geodesic_distance_lat1(double lat1)
Sets geodesic distance lat1.
struct Option * G_define_option(void)
Initializes an Option struct.
void gsd_zwritemask(unsigned long n)
Write out z-mask.
void G_get_set_window(struct Cell_head *window)
Get the current working window (region)
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
void GS_alldraw_wire(void)
Draw all wires.
struct Option * G_define_standard_option(int opt)
Create standardised Option structure.
Viewnode * gk_make_framesfromkeys(Keylist *keys, int keysteps, int newsteps, int loop, float t)
Generate viewnode from keyframes.
int G_legal_filename(const char *s)
Check for legal database file name.
if(!DBFLoadRecord(psDBF, hEntity)) return NULL
int G_debug(int level, const char *msg,...)
Print debugging message.
char * G_tempfile(void)
Returns a temporary file name.
int G_remove(const char *element, const char *name)
Remove a database file.
int G_open_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
int G_format_timestamp(const struct TimeStamp *ts, char *buf)
Create text string from TimeStamp structure.
void G_begin_zone_area_on_sphere(double r, double s)
Initialize calculations for sphere.
double G_distance(double e1, double n1, double e2, double n2)
Returns distance in meters.
void G_begin_ellipsoid_polygon_area(double a, double e2)
Begin area calculations.
void G_usage(void)
Command line help/usage message.
double G_geodesic_distance(double lon1, double lat1, double lon2, double lat2)
Calculates geodesic distance.
void GS_moveto(float *pt)
Move viewpoint.
char * G_strcasestr(const char *str, const char *substr)
Finds the first occurrence of the sub-string in the null-terminated string ignoring case (upper or lo...
int gk_draw_path(Viewnode *views, int steps, Keylist *keys)
Draw path.
int G_is_little_endian(void)
Tests for little ENDIAN.
double lin_interp(float dt, float val1, float val2)
Linear interpolation.
double get_key_neighbors(int nvk, double time, double range, int loop, Keylist *karray[], Keylist **km1, Keylist **kp1, Keylist **kp2, Keylist **km2, double *dt1, double *dt2)
Find interval containing time.
FILE * G_popen_read(struct Popen *state, const char *program, const char **args)
int G_open_update(const char *element, const char *name)
Open a database file for update.
int G_plot_area(double *const *xs, double *const *ys, int *rpnts, int rings)
Plot multiple polygons.
void G_strip(char *buf)
Removes all leading and trailing white space from string.
void GS_get_viewdir(float *dir)
Get viewdir.
void G_warning(const char *msg,...)
Print a warning message to stderr.
void GS_getlight_position(int num, float *xpos, float *ypos, float *zpos, int *local)
Get light position.
struct Flag * G_define_standard_flag(int flag)
Create standardised Flag structure.
int G_write_raster_timestamp(const char *name, const struct TimeStamp *ts)
Write timestamp of raster map.
double G_area_for_zone_on_ellipsoid(double north, double south)
Calculates area between latitudes.
unsigned int GS_default_draw_color(void)
Get default draw color.
double G_adjust_easting(double east, const struct Cell_head *window)
Returns east not smaller than west.
void G_plot_where_en(int x, int y, double *east, double *north)
Converts x,y to east,north.
void gk_follow_frames(Viewnode *view, int numsteps, Keylist *keys, int step, int onestep, int render, unsigned long mode)
Checks key masks.
void GS_alldraw_surf(void)
Draw all surfaces.
void GS_done_draw(void)
Draw done, swap buffers.
void GS_draw_all_list(void)
Draw all glLists.
int G_remove_raster_timestamp(const char *name)
Remove timestamp from raster map.