Loading...
Searching...
No Matches
position.c
Go to the documentation of this file.
/*!
\file lib/nviz/position.c
\brief Nviz library -- Position, focus settings
Based on visualization/nviz/src/position.c
(C) 2008, 2010 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
\author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC
2008/2010)
*/
#include <grass/glocale.h>
#include <grass/nviz.h>
/*!
Initialize view, position, lighting settings (focus)
Set position to center of view
*/
void Nviz_init_view(nv_data *data)
{
GS_init_view();
Nviz_set_focus_state(1); /* center of view */
/* set default lights (1 & 2) */
Nviz_set_light_position(data, 1, 0.68, -0.68, 0.80, 0.0);
Nviz_set_light_bright(data, 1, 0.8);
Nviz_set_light_color(data, 1, 255, 255, 255);
Nviz_set_light_ambient(data, 1, 0.2);
Nviz_set_light_position(data, 2, 0.0, 0.0, 1.0, 0.0);
Nviz_set_light_bright(data, 2, 0.5);
Nviz_set_light_color(data, 2, 255, 255, 255);
Nviz_set_light_ambient(data, 2, 0.3);
return;
}
/*!
\brief Set focus state
\param state_flag 1 for center view, 0 use viewdir
\return 1 on success
\return 0 on failure
*/
int Nviz_set_focus_state(int state_flag)
{
if (state_flag == 1)
GS_set_infocus(); /* return center of view */
else if (state_flag == 0)
GS_set_nofocus(); /* no center of view -- use viewdir */
else {
G_warning(_("Unable to set focus"));
return 0;
}
return 1;
}
/*!
\brief Set focus based on loaded map
If <i>map</i> is MAP_OBJ_UNDEFINED, set focus from first
surface/volume in the list.
\param type map object type
\param id map object id
\return 0 on no focus
\return id id of map object used for setting focus
*/
int Nviz_set_focus_map(int type, int id)
{
if (GS_num_surfs() < 0 && GVL_num_vols() < 0) {
GS_set_nofocus();
return 0;
}
if (type == MAP_OBJ_UNDEFINED) {
int *surf_list, num_surfs, *vol_list;
if (GS_num_surfs() > 0) {
surf_list = GS_get_surf_list(&num_surfs);
id = surf_list[0];
G_free(surf_list);
GS_set_focus_center_map(id);
}
if (GVL_num_vols() > 0) {
vol_list = GVL_get_vol_list(&num_surfs);
id = vol_list[0];
G_free(vol_list);
GVL_set_focus_center_map(id);
}
return id;
}
if (type == MAP_OBJ_SURF) {
GS_set_focus_center_map(id);
}
else if (type == MAP_OBJ_VOL) {
GVL_set_focus_center_map(id);
}
return id;
}
/*!
\brief Get focus
\param data nviz data [unused]
\param x,y,z focus coordinates
*/
int Nviz_get_focus(nv_data *data G_UNUSED, float *x, float *y, float *z)
{
float realto[3];
/* Get current center */
GS_get_focus(realto);
*x = realto[0];
*y = realto[1];
*z = realto[2];
/* old nviz code is more complicated and it doesn't work properly, */
/* no idea why */
return 1;
}
/*!
\brief Set focus
\param data nviz data [unused]
\param x, y, z focus coordinates
*/
int Nviz_set_focus(nv_data *data G_UNUSED, float x, float y, float z)
{
float realto[3];
realto[0] = x;
realto[1] = y;
realto[2] = z;
GS_set_focus(realto);
/* old nviz code is more complicated and it doesn't work properly, */
/* no idea why */
return 1;
}
/*!
\brief Test focus
\param data nviz data [unused]
*/
int Nviz_has_focus(nv_data *data G_UNUSED)
{
float realto[3];
if (GS_get_focus(realto))
return 1;
else
return 0;
}
/*!
\brief Get xy range
\param data nviz data
*/
float Nviz_get_xyrange(nv_data *data)
{
return data->xyrange;
}
/*!
\brief Get z range
\param data nviz data [unused]
\param min,max z range
*/
int Nviz_get_zrange(nv_data *data G_UNUSED, float *min, float *max)
{
GS_get_zrange_nz(min, max);
return 1;
}
/*!
\brief Get largest dimension
\param data nviz data [unused]
*/
float Nviz_get_longdim(nv_data *data G_UNUSED)
{
float dim;
GS_get_longdim(&dim);
return dim;
}
G_free
void G_free(void *buf)
Free allocated memory.
Definition alloc.c:147
G_warning
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition gis/error.c:203
GS_get_zrange_nz
void GS_get_zrange_nz(float *min, float *max)
Get Z extents for all loaded surfaces.
Definition gs2.c:2358
GS_set_focus
void GS_set_focus(float *realto)
Set focus.
Definition gs2.c:2520
GS_set_infocus
void GS_set_infocus(void)
Set focus.
Definition gs2.c:2965
GS_set_focus_center_map
void GS_set_focus_center_map(int id)
Set focus to map center.
Definition gs2.c:2581
GS_get_surf_list
int * GS_get_surf_list(int *numsurfs)
Get surface list.
Definition gs2.c:1532
GS_get_focus
int GS_get_focus(float *realto)
Get focus.
Definition gs2.c:2562
GS_num_surfs
int GS_num_surfs(void)
Get number of surfaces.
Definition gs2.c:1517
GS_init_view
void GS_init_view(void)
Init viewpoint.
Definition gs2.c:3346
GS_set_nofocus
void GS_set_nofocus(void)
Unset focus.
Definition gs2.c:2951
GS_get_longdim
int GS_get_longdim(float *dim)
Get largest dimension.
Definition gs2.c:140
GVL_num_vols
int GVL_num_vols(void)
Get number of loaded volume sets.
Definition gvl2.c:166
GVL_get_vol_list
int * GVL_get_vol_list(int *numvols)
Get list of loaded volume sets.
Definition gvl2.c:181
GVL_set_focus_center_map
void GVL_set_focus_center_map(int id)
Set focus on map center.
Definition gvl2.c:522
Nviz_set_light_ambient
int Nviz_set_light_ambient(nv_data *data, int num, double value)
Set light ambient.
Definition lights.c:116
Nviz_set_light_color
int Nviz_set_light_color(nv_data *data, int num, int red, int green, int blue)
Set light color.
Definition lights.c:90
Nviz_set_light_bright
int Nviz_set_light_bright(nv_data *data, int num, double value)
Set light brightness.
Definition lights.c:65
Nviz_set_light_position
int Nviz_set_light_position(nv_data *data, int num, double x, double y, double z, double w)
Set light position.
Definition lights.c:28
min
#define min(a, b)
Definition pngdriver/draw_bitmap.c:19
max
#define max(a, b)
Definition pngdriver/draw_bitmap.c:22
Nviz_init_view
void Nviz_init_view(nv_data *data)
Definition position.c:24
Nviz_set_focus_map
int Nviz_set_focus_map(int type, int id)
Set focus based on loaded map.
Definition position.c:76
Nviz_get_longdim
float Nviz_get_longdim(nv_data *data)
Get largest dimension.
Definition position.c:197
Nviz_set_focus
int Nviz_set_focus(nv_data *data, float x, float y, float z)
Set focus.
Definition position.c:141
Nviz_has_focus
int Nviz_has_focus(nv_data *data)
Test focus.
Definition position.c:160
Nviz_get_xyrange
float Nviz_get_xyrange(nv_data *data)
Get xy range.
Definition position.c:175
Nviz_get_focus
int Nviz_get_focus(nv_data *data, float *x, float *y, float *z)
Get focus.
Definition position.c:120
Nviz_get_zrange
int Nviz_get_zrange(nv_data *data, float *min, float *max)
Get z range.
Definition position.c:186
Nviz_set_focus_state
int Nviz_set_focus_state(int state_flag)
Set focus state.
Definition position.c:50
x
#define x