Esempio n. 1
0
/*!
   \brief Update ranges

   Call whenever a new surface is added, deleted, or exag changes

   \return 1
 */
int Nviz_update_ranges(nv_data * dc)
{
    float zmin, zmax, exag;

    GS_get_longdim(&(dc->xyrange));

    dc->zrange = 0.;

    /* Zrange is based on a minimum of Longdim */
    if (GS_global_exag()) {
	exag = GS_global_exag();
	dc->zrange = dc->xyrange / exag;
    }
    else {
	exag = 1.0;
    }

    GS_get_zrange_nz(&zmin, &zmax);	/* actual */

    zmax = zmin + (3. * dc->xyrange / exag);
    zmin = zmin - (2. * dc->xyrange / exag);

    if ((zmax - zmin) > dc->zrange)
	dc->zrange = zmax - zmin;

    return 1;
}
Esempio n. 2
0
/*!
   \brief Init variables

   for optimization

   \param gs surface (geosurf)
 */
void init_vars(geosurf * gs)
{
    /* optimized - these are static - global to this file */
    norm = gs->norms;
    elbuf = gs_get_att_typbuff(gs, ATT_TOPO, 0);

#ifdef USE_GL_NORMALIZE
    c_z2 =
	2.0 * gs->xres * gs->yres * gs->x_mod * gs->y_mod / GS_global_exag();
    c_z2_sq = c_z2 * c_z2;
    x_res_z2 = 2.0 * gs->xres * gs->z_exag * gs->x_mod;
    y_res_z2 = 2.0 * gs->yres * gs->z_exag * gs->y_mod;
#else

    {
	float sx, sy, sz;

	GS_get_scale(&sx, &sy, &sz, 1);

	c_z2 = 2.0 * gs->xres * gs->yres * gs->x_mod * gs->y_mod;
	c_z2_sq = c_z2 * c_z2;
	x_res_z2 = 2.0 * gs->xres * gs->z_exag * gs->x_mod;
	y_res_z2 = 2.0 * gs->yres * gs->z_exag * gs->y_mod;
    }
#endif

    slice = gs->y_mod * gs->cols;

    return;
}
Esempio n. 3
0
/*!
   \brief Change z-exag value

   \param data nviz data
   \param exag exag value

   \return 1
 */
int Nviz_change_exag(nv_data * data, double exag)
{
    double temp;

    G_debug(1, "Nviz_change_exag(): value = %f", exag);
    temp = GS_global_exag();

    if (exag != temp) {
	GS_set_global_exag(exag);
	Nviz_update_ranges(data);

	/* Nviz_draw_quick(data); */
    }

    return 1;
}
Esempio n. 4
0
File: gs.c Progetto: caomw/grass
/*!
   \brief Calculate distance on surface

   \param gs pointer to geosurf struct
   \param p1 from point
   \param p2 to point
   \param[out] dist distnace
   \param use_exag use exag for calculation

   \return 0 on error (points not in region)
   \return 1 on success
 */
int gs_distance_onsurf(geosurf * gs, float *p1, float *p2, float *dist,
		       int use_exag)
{
    Point3 *tmp;
    int np, i;
    float exag, length;

    if (in_vregion(gs, p1) && in_vregion(gs, p2)) {
	if (NULL == (tmp = gsdrape_get_segments(gs, p1, p2, &np))) {
	    return (0);
	}

	length = 0.;

	if (use_exag) {
	    exag = GS_global_exag();
	    tmp[0][Z] *= exag;

	    for (i = 0; i < (np - 1); i++) {
		tmp[i + 1][Z] *= exag;
		length += GS_distance(tmp[i], tmp[i + 1]);
	    }
	}
	else {
	    for (i = 0; i < (np - 1); i++) {
		length += GS_distance(tmp[i], tmp[i + 1]);
	    }
	}

	*dist = length;

	return (1);
    }

    return (0);
}
Esempio n. 5
0
/*!                                                            
   \brief ADD

   \param gp site (geosite)
   \param xo,yo
   \param do_fast (unused)

   \return 0
   \return 1
 */
int gpd_3dsite(geosite * gp, float xo, float yo, int do_fast)
{
    float site[3], tz;
    float size;
    int check, color, marker;
    geopoint *gpt;
    GLdouble modelMatrix[16], projMatrix[16];
    GLint viewport[4];
    GLint window[4];

    if (GS_check_cancel()) {
	return (0);
    }

    gsd_getwindow(window, viewport, modelMatrix, projMatrix);

    gsd_pushmatrix();

    gsd_do_scale(1);

    tz = GS_global_exag();
    site[Z] = 0.0;

    check = 0;
    color = gp->color;
    marker = gp->marker;
    size = gp->size;

    gsd_linewidth(gp->width);

    for (gpt = gp->points; gpt; gpt = gpt->next) {
	if (!(++check % CHK_FREQ)) {
	    if (GS_check_cancel()) {
		gsd_linewidth(1);
		gsd_popmatrix();

		return (0);
	    }
	}

	site[X] = gpt->p3[X] + gp->x_trans - xo;
	site[Y] = gpt->p3[Y] + gp->y_trans - yo;

	if (tz) {
	    site[Z] = gpt->p3[Z] + gp->z_trans;
	}

	/* TODO: set other dynamic attributes */
	if (gp->attr_mode & ST_ATT_COLOR) {
	    color = gpt->iattr;
	}

	if (gsd_checkpoint(site, window, viewport, modelMatrix, projMatrix))
	    continue;
	else
	    /* clip points outside default region? */
	    /* ACS_MODIFY_OneLine site_attr management - was: gpd_obj(NULL, color, size, marker, site); */
	    gpd_obj_site_attr(NULL, gp, gpt, site);
    }

    gsd_linewidth(1);
    gsd_popmatrix();

    return (1);
}
Esempio n. 6
0
/*!
   \brief Substitutes gpd_obj()

   \param gs surface (geosurf)
   \param gp site (geosite)
   \param gpt point (point)
   \param site point

   \return 0
 */
int gpd_obj_site_attr(geosurf * gs, geosite * gp, geopoint * gpt, Point3 site)
{
    float size, z, y, x, z_scale, z_offset;
    int marker, color, i, ii, iii;
    int use_attr, has_drawn;
    int _put_aside_;

    _put_aside_ = 0;
    _cur_size_ = gp->size;

    z_scale = GS_global_exag();
    z_offset = 0.0;

    has_drawn = 0;

    for (i = 0; i < GPT_MAX_ATTR; i++) {
	color = gp->color;
	marker = gp->marker;
	size = gp->size;
	use_attr = 0;

	if (gp->use_attr[i] & ST_ATT_COLOR) {
	    use_attr = 1;
	    color = gpt->color[i];
	}

	if (gp->use_attr[i] & ST_ATT_MARKER) {
	    use_attr = 1;
	    marker = gpt->marker[i];
	}

	if (gp->use_attr[i] & ST_ATT_SIZE) {
	    use_attr = 1;
	    size = gpt->size[i] * gp->size;
	    if (gp->marker == ST_HISTOGRAM)
		_put_aside_ = 1;
	}

	/* ACS_MODIFY_BEGIN site_highlight management ********************************* */
	if (gpt->highlight_color)
	    color = gpt->highlight_color_value;
	if (gpt->highlight_marker)
	    marker = gpt->highlight_marker_value;
	if (gpt->highlight_size)
	    size *= gpt->highlight_size_value;
	/* ACS_MODIFY_END site_highlight management *********************************** */

	if (_put_aside_) {
	    if (use_attr == 1) {
		has_drawn = 1;

/*******************************************************************************
		fixed size = gp->size
		this is mailny intended for "histograms" that grow in z, but not in xy

        square filling to right and then up

         15 14 13 12
          8  7  6 11
          3  2  5 10
          0  1  4  9

*******************************************************************************/
		x = site[X];
		y = site[Y];

		ii = (int)(sqrt(i));
		iii = ii * ii + ii;

		if (i <= iii) {
		    site[X] += ii * 2.2 * gp->size;
		    site[Y] += (i - ii) * 2.2 * gp->size;
		}
		else {
		    site[X] += (ii - (i - iii)) * 2.2 * gp->size;
		    site[Y] += ii * 2.2 * gp->size;

		}

		gpd_obj(gs, color, size, marker, site);

		site[X] = x;
		site[Y] = y;
	    }
	}
	else {
	    if (i > 0)
		z_offset += size;
	    if (use_attr == 1) {
		has_drawn = 1;

		z = site[Z];
		site[Z] += z_offset / z_scale;

		gpd_obj(gs, color, size, marker, site);

		site[Z] = z;
	    }

	    z_offset += size;
	}
    }

    if (has_drawn == 0)
	gpd_obj(gs, color, size, marker, site);

    return (0);
}
Esempio n. 7
0
/*!
   \brief ADD

   Do normal transforms before calling

   Note gs: NULL if 3d obj or const elev surface

   \todo add size1, size2 & dir1, dir2 (eg azimuth, elevation) variables

   \param gs surface (geosurf)
   \param size
   \param marker
   \param pt 3d point (Point3)
 */
void gpd_obj(geosurf * gs, int color, float size, int marker, Point3 pt)
{
    float sz, lpt[3];
    float siz[3];

    gsd_color_func(color);
    sz = GS_global_exag();
    GS_v3eq(lpt, pt);		/* CHANGING Z OF POINT PASSED, so use copy */

    switch (marker) {
	/* ACS_MODIFY_BEGIN site_attr management ************************************** */
    case ST_HISTOGRAM:
	gsd_colormode(CM_DIFFUSE);
	gsd_pushmatrix();

	if (sz) {
	    lpt[Z] *= sz;
	    gsd_scale(1.0, 1.0, 1. / sz);
	}

	siz[0] = _cur_size_;
	siz[1] = _cur_size_;
	siz[2] = size;

	gsd_box(lpt, color, siz);

	gsd_popmatrix();
	gsd_colormode(CM_COLOR);

	break;
	/* ACS_MODIFY_END   site_attr management ************************************** */
    case ST_DIAMOND:
	/*
	   gsd_colormode(CM_AD);
	 */
	gsd_colormode(CM_DIFFUSE);
	gsd_pushmatrix();

	if (sz) {
	    lpt[Z] *= sz;
	    gsd_scale(1.0, 1.0, 1. / sz);
	}

	gsd_diamond(lpt, color, size);
	gsd_popmatrix();
	gsd_colormode(CM_COLOR);

	break;
    case ST_BOX:
	gsd_colormode(CM_COLOR);
	gsd_pushmatrix();

	if (sz) {
	    lpt[Z] *= sz;
	    gsd_scale(1.0, 1.0, 1. / sz);
	}

	gsd_draw_box(lpt, color, size);
	gsd_popmatrix();

	break;
    case ST_SPHERE:
	/*
	   gsd_colormode(CM_AD);
	 */
	gsd_colormode(CM_DIFFUSE);
	gsd_pushmatrix();

	if (sz) {
	    lpt[Z] *= sz;
	    gsd_scale(1.0, 1.0, 1. / sz);
	}

	gsd_sphere(lpt, size);
	gsd_popmatrix();
	gsd_colormode(CM_COLOR);

	break;
    case ST_GYRO:
	gsd_colormode(CM_COLOR);
	gsd_pushmatrix();

	if (sz) {
	    lpt[Z] *= sz;
	    gsd_scale(1.0, 1.0, 1. / sz);
	}

	gsd_draw_gyro(lpt, color, size);
	gsd_popmatrix();

	break;
    case ST_ASTER:
	gsd_colormode(CM_COLOR);
	gsd_pushmatrix();

	if (sz) {
	    lpt[Z] *= sz;
	    gsd_scale(1.0, 1.0, 1. / sz);
	}

	gsd_draw_asterisk(lpt, color, size);
	gsd_popmatrix();

	break;
    case ST_CUBE:
	gsd_colormode(CM_DIFFUSE);
	gsd_pushmatrix();

	if (sz) {
	    lpt[Z] *= sz;
	    gsd_scale(1.0, 1.0, 1. / sz);
	}

	gsd_cube(lpt, color, size);
	gsd_popmatrix();
	gsd_colormode(CM_COLOR);

	break;
    default:
    case ST_X:
	gsd_colormode(CM_COLOR);
	gsd_x(gs, lpt, color, size);

	break;
    }

    return;
}