22 #include <grass/gstypes.h>
23 #include <grass/glocale.h>
28 #define FIRST_SURF_ID 110658
30 static geosurf *Surf_top;
31 static int Invertmask;
68 for (gs = Surf_top; gs; gs = gs->next) {
69 if (gs->gsurf_id ==
id) {
90 G_debug(5,
"gs_get_prev_surface");
92 for (ps = Surf_top; ps; ps = ps->next) {
93 if (ps->gsurf_id ==
id - 1) {
113 for (i = 0, gs = Surf_top; gs; gs = gs->next, i++) {
117 G_debug(5,
"gs_num_surfaces(): num=%d", i);
132 for (i = 0, gs = Surf_top; gs; gs = gs->next, i++) ;
134 G_debug(5,
"gs_num_surfaces(): num=%d", i);
154 return (NOTSET_ATT != surf->att[att].att_src);
158 for (gs = Surf_top; gs; gs = gs->next) {
159 if (NOTSET_ATT != gs->att[att].att_src) {
180 for (ls = Surf_top; ls->next; ls = ls->next) ;
182 G_debug(5,
"gs_get_last_surface(): last surface id=%d", ls->gsurf_id);
197 ns = (geosurf *) G_malloc(
sizeof(geosurf));
204 ns->gsurf_id = ls->gsurf_id + 1;
213 G_debug(5,
"gs_get_new_surface(): id=%d", ns->gsurf_id);
233 double xres,
double yres)
242 G_debug(5,
"gs_init_surf() id=%d", gs->gsurf_id);
245 for (i = 0; i < MAX_ATTS; i++) {
246 gs->att[i].att_src = NOTSET_ATT;
247 gs->att[i].att_type = ATTY_INT;
248 gs->att[i].hdata = -1;
249 gs->att[i].user_func =
NULL;
250 gs->att[i].constant = 0.;
251 gs->att[i].lookup =
NULL;
252 gs->att[i].min_nz = gs->att[i].max_nz = gs->att[i].range_nz = 0;
253 gs->att[i].default_null = 0.;
265 gs->x_modw = rows / 30;
266 gs->y_modw = rows / 30;
268 gs->xmax = ox + (cols - 1) * xres;
269 gs->xrange = gs->xmax - gs->xmin;
271 gs->ymax = oy + (rows - 1) * yres;
272 gs->yrange = gs->ymax - gs->ymin;
273 gs->zmin = gs->zmin_nz = gs->zminmasked = 0;
274 gs->zmax = gs->zmax_nz = 0;
275 gs->zrange = gs->zrange_nz = 0;
276 gs->wire_color = 0x00888888;
277 gs->x_trans = gs->y_trans = gs->z_trans = 0.0;
278 gs->nz_topo = gs->nz_color = 0;
279 gs->norm_needupdate = 1;
280 gs->mask_needupdate = 1;
284 gs->draw_mode = DM_GOURAUD;
292 gs->z_exag = ps->z_exag;
318 size = gs->rows * gs->cols *
sizeof(
unsigned long);
320 gs->norms = (
unsigned long *)G_malloc(size);
325 gs->norm_needupdate = 1;
339 fprintf(stderr,
"FROM: %f, %f, %f\n", ft[
FROM][
X], ft[
FROM][
Y],
341 fprintf(stderr,
"TO: %f, %f, %f\n", ft[TO][X], ft[TO][Y], ft[TO][Z]);
355 fprintf(stderr,
"REAL TO: %f, %f, %f\n", rt[
X], rt[
Y], rt[Z]);
371 for (i = 0; i < 256; i++) {
373 fprintf(stderr,
"\n");
376 fprintf(stderr,
"%x ", buff[i]);
379 fprintf(stderr,
"\n");
393 fprintf(stderr,
"ID: %d\n", s->gsurf_id);
394 fprintf(stderr,
"rows: %d cols: %d\n", s->rows, s->cols);
395 fprintf(stderr,
"draw_mode: %x\n", s->draw_mode);
396 fprintf(stderr,
"wire_color: %lx\n", s->wire_color);
397 fprintf(stderr,
"ox: %lf oy: %lf\n", s->ox, s->oy);
398 fprintf(stderr,
"xres: %lf yres: %lf\n", s->xres, s->yres);
399 fprintf(stderr,
"z_exag: %f \n", s->z_exag);
400 fprintf(stderr,
"x_trans: %f y_trans: %f z_trans: %f\n",
401 s->x_trans, s->y_trans, s->z_trans);
402 fprintf(stderr,
"xmin: %f ymin: %f zmin: %f\n",
403 s->xmin, s->ymin, s->zmin);
404 fprintf(stderr,
"xmax: %f ymax: %f zmax: %f\n",
405 s->xmax, s->ymax, s->zmax);
406 fprintf(stderr,
"x_mod: %d y_mod: %d x_modw: %d y_modw: %d\n",
407 s->x_mod, s->y_mod, s->x_modw, s->y_modw);
421 fprintf(stderr,
"coord_sys: %d\n", gv->coord_sys);
422 fprintf(stderr,
"view_proj: %d\n", gv->view_proj);
423 fprintf(stderr,
"infocus: %d\n", gv->infocus);
425 fprintf(stderr,
"twist: %d fov: %d\n", gv->twist, gv->fov);
426 fprintf(stderr,
"incl: %d look: %d\n", gv->incl, gv->look);
427 fprintf(stderr,
"real_to: %f %f %f\n",
428 gv->real_to[
X], gv->real_to[
Y], gv->real_to[Z]);
429 fprintf(stderr,
"vert_exag: %f scale: %f \n", gv->vert_exag, gv->scale);
445 G_debug(5,
"gs_set_defaults(): id=%d", gs->gsurf_id);
447 for (i = 0; i < MAX_ATTS; i++) {
448 gs->att[i].constant = defs[i];
449 gs->att[i].default_null = null_defs[i];
450 gs->att[i].lookup =
NULL;
451 gs->att[i].hdata = -1;
452 gs->att[i].att_src = NOTSET_ATT;
495 if (fs == Surf_top) {
496 if (Surf_top->next) {
517 for (gs = Surf_top; gs && !found; gs = gs->next) {
519 if (gs->next == fs) {
563 G_debug(5,
"gs_free_unshared_buffs");
568 for (i = 0; i < MAX_ATTS; i++) {
571 if (0 < (old_datah = fs->att[i].hdata)) {
573 for (gs = Surf_top; gs; gs = gs->next) {
574 for (j = 0; j < MAX_ATTS; j++) {
575 if ((old_datah == gs->att[j].hdata) && (fs != gs)) {
602 G_debug(5,
"gs_num_datah_reused");
610 for (gs = Surf_top; gs; gs = gs->next) {
611 for (j = 0; j < MAX_ATTS; j++) {
612 if (dh == gs->att[j].hdata) {
634 if (!LEGAL_ATT(desc)) {
639 if (gs->att[desc].att_src != NOTSET_ATT) {
640 return (gs->att[desc].att_type);
659 G_debug(5,
"gs_get_att_src(): id=%d, desc=%d", gs->gsurf_id, desc);
660 if (!LEGAL_ATT(desc)) {
665 return (gs->att[desc].att_src);
687 G_debug(5,
"gs_get_att_typbuff(): id=%d desc=%d to_write=%d",
688 gs->gsurf_id, desc, to_write);
692 if (desc == ATT_TOPO) {
695 if (gsref && gsref != gs) {
719 int hdata, dims[2], ndims;
721 G_debug(5,
"gs_malloc_att_buff");
724 if (0 < (hdata = gs->att[desc].hdata)) {
750 G_debug(5,
"gs_malloc_lookup");
753 if (gs->att[desc].lookup) {
754 G_free(gs->att[desc].lookup);
755 gs->att[desc].lookup =
NULL;
758 switch (gs->att[desc].att_type) {
760 size = 32768 *
sizeof(
int);
763 gs->att[desc].lookup = (
int *)G_malloc(size);
764 if (!gs->att[desc].lookup) {
770 size = 256 *
sizeof(
int);
773 gs->att[desc].lookup = (
int *)G_malloc(size);
774 if (!gs->att[desc].lookup) {
784 if (gs->att[desc].lookup) {
806 G_debug(5,
"gs_set_att_type(): desc=%d, type=%d", desc, type);
808 if (gs && LEGAL_TYPE(type)) {
809 gs->att[desc].att_type =
type;
830 G_debug(5,
"gs_set_att_src(): id=%d desc=%d src=%d",
831 gs->gsurf_id, desc, src);
837 G_debug(5,
"gs_set_att_src(): replacing existing map");
841 if (ATT_TOPO == desc) {
847 gs->norm_needupdate = 0;
851 if (gs && LEGAL_SRC(src)) {
852 gs->att[desc].att_src = src;
876 G_debug(5,
"gs_set_att_const(): id=%d, desc=%d, const=%f",
877 gs->gsurf_id, desc, constant);
878 gs->att[desc].constant = constant;
880 if (ATT_MASK == desc) {
881 gs->mask_needupdate = 1;
917 return (gs->att[ATT_MASK].att_src != NOTSET_ATT);
933 int gs_masked(typbuff * tb,
int col,
int row,
int offset)
940 ret =
BM_get(tb->bm, col, row);
943 ret = tb->cb[offset];
946 ret = tb->sb[offset];
949 ret = tb->ib[offset];
952 ret = tb->fb[offset];
955 return (Invertmask ? ret : !ret);
969 int gs_mapcolor(typbuff * cobuff, gsurf_att * coloratt,
int offset)
971 if (coloratt->lookup) {
974 return (coloratt->lookup[cobuff->cb[offset]]);
977 return (cobuff->ib[offset]);
1000 *min = gs->zmin + gs->z_trans;
1001 *max = gs->zmax + gs->z_trans;
1002 *mid = (*max + *
min) / 2.;
1018 *min = gs->xmin + gs->x_trans;
1019 *max = gs->xmax + gs->x_trans;
1035 *min = gs->ymin + gs->y_trans;
1036 *max = gs->ymax + gs->y_trans;
1059 *min = Surf_top->zmin;
1060 *max = Surf_top->zmax;
1066 for (gs = Surf_top->next; gs; gs = gs->next) {
1067 if (gs->zmin < *min) {
1071 if (gs->zmax > *max) {
1091 float tmin, tmax, tmid;
1102 for (gs = Surf_top->next; gs; gs = gs->next) {
1140 for (gs = Surf_top->next; gs; gs = gs->next) {
1178 for (gs = Surf_top->next; gs; gs = gs->next) {
1209 zmax = *azmax = 0.0;
1212 for (i = 0, gs = Surf_top; gs; i++, gs = gs->next) {
1213 zmax += (gs->zmax + gs->z_trans);
1238 zmin = Surf_top->zmin;
1239 zmax = Surf_top->zmax;
1240 ymin = Surf_top->ymin;
1241 ymax = Surf_top->ymax;
1242 xmin = Surf_top->xmin;
1243 xmax = Surf_top->xmax;
1245 for (gs = Surf_top->next; gs; gs = gs->next) {
1246 if (gs->zmin < zmin) {
1250 if (gs->zmax > zmax) {
1254 if (gs->ymin < ymin) {
1258 if (gs->ymax > ymax) {
1262 if (gs->xmin < xmin) {
1266 if (gs->xmax > xmax) {
1271 cen[
X] = (xmin +
xmax) / 2. - xmin;
1272 cen[
Y] = (ymin +
ymax) / 2. - ymin;
1273 cen[Z] = (zmin + zmax) / 2.;
1278 cen[
X] = cen[
Y] = cen[Z] = 0.0;
1295 Surf_top->norm_needupdate = 1;
1301 for (gs = Surf_top->next; gs; gs = gs->next) {
1302 gs->norm_needupdate = 1;
1319 int vrow, vcol, drow, dcol;
1320 int retmask = 0, npts = 0;
1344 if (
BM_get(gs->curmask, dcol, drow)) {
1351 if (
BM_get(gs->curmask, dcol, drow)) {
1358 if (
BM_get(gs->curmask, dcol, drow)) {
1365 if (
BM_get(gs->curmask, dcol, drow)) {
1372 return (retmask | npts);
1380 if ((pt[X] - p2[X]) /
VXRES(gs) > (pt[Y] - p2[Y]) /
VYRES(gs)) {
1385 return (retmask | npts);
1388 return (retmask | npts);
1390 if ((pt[X] - p2[X]) /
VXRES(gs) <= (pt[Y] - p2[Y]) /
VYRES(gs)) {
1395 return (retmask | npts);
1398 return (retmask | npts);
1435 for (i = 0; i < (np - 1); i++) {
1436 tmp[i + 1][Z] *= exag;
1441 for (i = 0; i < (np - 1); i++) {
int gs_init_surf(geosurf *gs, double ox, double oy, int rows, int cols, double xres, double yres)
Initialize allocated geosurf struct.
int BM_get(struct BM *map, int x, int y)
Gets 'val' from the bitmap.
void G_free(void *buf)
Free allocated memory.
int gs_num_datah_reused(int dh)
Get number of reused values.
void gs_delete_surf(int id)
Remove geosurf struct from list.
int gs_get_datacenter(float *cen)
Get data center point.
void gs_set_maskmode(int invert)
Set geosurf mask mode.
int gs_get_data_avg_zmax(float *azmax)
Get average z-max value.
int in_vregion(geosurf *gs, float *pt)
ADD.
int gs_point_is_masked(geosurf *gs, float *pt)
Check if point is masked.
int gs_mask_defined(geosurf *gs)
Check if mask is defined.
int gs_malloc_att_buff(geosurf *gs, int desc, int type)
Allocate attribute buffer.
int gs_get_yextents(geosurf *gs, float *min, float *max)
Get y-extent values.
geosurf * gs_get_prev_surface(int id)
Get previous geosurf struct.
int gs_get_yrange(float *min, float *max)
Get y-range.
int gs_att_is_set(geosurf *surf, IFLAG att)
Check if attribute is set.
typbuff * gsds_get_typbuff(int id, IFLAG change_flag)
Get data buffer.
void print_frto(float(*ft)[4])
Debugging, print 'from/to' model coordinates to stderr.
void gs_set_defaults(geosurf *gs, float *defs, float *null_defs)
Set default attribute values.
int gsds_alloc_typbuff(int id, int *dims, int ndims, int type)
Allocates correct buffer according to type, keeps track of total mem.
void gs_init(void)
Initialize library.
int Gs_update_attrange(geosurf *gs, int desc)
Update no_zero ranges for attribute (actually no_null now)
int gs_set_att_type(geosurf *gs, int desc, int type)
Set attribute type.
void print_view_fields(geoview *gv)
Debugging, print geoview fields to stderr.
geosurf * gsdiff_get_SDref(void)
ADD.
void print_surf_fields(geosurf *s)
Debugging, print geosurf fields to stderr.
typbuff * gs_get_att_typbuff(geosurf *gs, int desc, int to_write)
Get attribute data buffer.
void gs_err(const char *msg)
int gs_num_surfaces(void)
Get number of surfaces.
int gs_masked(typbuff *tb, int col, int row, int offset)
Should only be called when setting up the current mask (gs_bm.c)
void print_realto(float *rt)
Debugging, print 'to' real coordinates to stderr.
int gs_set_att_const(geosurf *gs, int desc, float constant)
Set attribute constant value.
int gs_getall_surfaces(geosurf **gsurfs)
Get array of geosurf structs.
int gs_free_surf(geosurf *fs)
Free geosurf struct.
int gs_get_xrange(float *min, float *max)
Get x-range.
int gs_get_zextents(geosurf *gs, float *min, float *max, float *mid)
Get z-extent values.
int gs_set_att_src(geosurf *gs, int desc, int src)
Set attribute source.
int gs_malloc_lookup(geosurf *gs, int desc)
Allocate attribute lookup.
int gs_get_xextents(geosurf *gs, float *min, float *max)
Get x-extent values.
void print_256lookup(int *buff)
Debugging, 256 interger values from buffer.
int gs_get_att_type(geosurf *gs, int desc)
Get attribute type.
geosurf * gs_get_surf(int id)
Get geosurf struct.
int gs_get_zrange0(float *min, float *max)
Get z-range.
int gs_setall_norm_needupdate(void)
Set for geosurf need-to-update mark.
Point3 * gsdrape_get_segments(geosurf *gs, float *bgn, float *end, int *num)
ADD.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
geosurf * gs_get_last_surface(void)
Get last allocated geosurf struct from list.
int G_debug(int level, const char *msg,...)
Print debugging message.
int gs_get_att_src(geosurf *gs, int desc)
Get attribute source.
float gsdiff_do_SD(float val, int offset)
ADD.
#define VCOL2DCOL(gs, vcol)
int gs_init_normbuff(geosurf *gs)
Init geosurf normbuff.
float GS_distance(float *from, float *to)
Calculate distance.
geosurf * gs_get_new_surface(void)
Allocate new geosurf struct.
void gs_free_unshared_buffs(geosurf *fs)
Free unshared buffers of geosurf struct.
int gs_mapcolor(typbuff *cobuff, gsurf_att *coloratt, int offset)
Call this one when you already know att_src is MAP_ATT.
#define VROW2DROW(gs, vrow)
int gs_get_zrange(float *min, float *max)
Get z-range.
int gs_distance_onsurf(geosurf *gs, float *p1, float *p2, float *dist, int use_exag)
Calculate distance on surface.
int gsds_free_datah(int id)
Free allocated dataset.
float GS_global_exag(void)
Get global z-exag value.