[GRASS-SVN] r46778 - in grass/trunk: include lib/ogsf
visualization/nviz2/cmd
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jun 25 17:32:43 EDT 2011
Author: martinl
Date: 2011-06-25 14:32:43 -0700 (Sat, 25 Jun 2011)
New Revision: 46778
Modified:
grass/trunk/include/gstypes.h
grass/trunk/include/nviz.h
grass/trunk/include/ogsf_proto.h
grass/trunk/lib/ogsf/GP2.c
grass/trunk/lib/ogsf/Gp3.c
grass/trunk/lib/ogsf/gp.c
grass/trunk/lib/ogsf/gpd.c
grass/trunk/visualization/nviz2/cmd/Makefile
grass/trunk/visualization/nviz2/cmd/args.c
grass/trunk/visualization/nviz2/cmd/local_proto.h
grass/trunk/visualization/nviz2/cmd/main.c
grass/trunk/visualization/nviz2/cmd/vector.c
Log:
wxNviz: ogsflib - initial support for thematic mapping (points-color)
nviz_cmd - add parameters for thematic mapping (points)
Modified: grass/trunk/include/gstypes.h
===================================================================
--- grass/trunk/include/gstypes.h 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/include/gstypes.h 2011-06-25 21:32:43 UTC (rev 46778)
@@ -1,8 +1,18 @@
-/* gstypes.h
- Bill Brown, USACERL
- January 1993
- */
+/*!
+ \file include/gstypes.c
+ \brief OGSF header file (structures)
+
+ This program is free software under the GNU General
+ Public License (>=v2). Read the file COPYING that
+ comes with GRASS for details.
+
+ \author Original author Bill Brown, USACERL (January 1993)
+ \author Thematic mapping enabled by Martin Landa <landa.martin gmail.com) (06/2011)
+
+ (C) 2011 by the GRASS Development Team
+*/
+
#ifndef _GSTYPES_H
#define _GSTYPES_H
@@ -78,6 +88,10 @@
#define OGSF_LINE 2
#define OGSF_POLYGON 3
+#define RED_MASK 0x000000FF
+#define GRN_MASK 0x0000FF00
+#define BLU_MASK 0x00FF0000
+
typedef float Point4[4];
typedef float Point3[3];
typedef float Point2[2];
@@ -166,17 +180,30 @@
/* Struct for vector feature displaying attributes */
typedef struct g_vect_style
{
- int color; /* Line color */
- int symbol; /* Point symbol/line type */
- float size; /* Symbol size. Unset for lines. */
- int width; /* Line width. Also used for lines forming symbols i.e. X */
+ int color; /* Line color */
+ int symbol; /* Point symbol/line type */
+ float size; /* Symbol size. Unset for lines. */
+ int width; /* Line width. Also used for lines forming symbols i.e. X */
+
/*TODO:fill; Area fill pattern */
/*TODO:falpha; Area fill transparency */
/*TODO:lalpha; Line/boundary/point transparency */
/*TODO:struct *orientation; Symbol orientation */
- struct g_vect_style *next; /* Point to next gvstyle struct if single point has multiple styles. In such case feature with next style should be shifted. */
+ struct g_vect_style *next; /* Point to next gvstyle struct if single point has multiple styles.
+ In such case feature with next style should be shifted. */
} gvstyle;
+/* Struct for vector map (thematic mapping) */
+typedef struct g_vect_style_thematic
+{
+ int layer;
+
+ char *color_column;
+ char *symbol_column;
+ char *size_column;
+ char *width_column;
+} gvstyle_thematic;
+
/* Line instance */
typedef struct g_line
{
@@ -193,7 +220,7 @@
struct g_line *next;
} geoline;
-/* Vector line layer */
+/* Vector map (lines) */
typedef struct g_vect
{
int gvect_id;
@@ -211,8 +238,8 @@
void *clientdata;
int thematic_layer; /* Layer number to use for thematic mapping. <0 == no thematic mapping;
- 0 == thematic mapping is unset but initialized;
- >0 use specified layer */
+ 0 == thematic mapping is unset but initialized;
+ >0 use specified layer */
gvstyle *style; /* Vector default look&feel */
gvstyle *hstyle; /* IMHO highlight should be per layer basis. */
} geovect;
@@ -225,12 +252,12 @@
struct line_cats *cats; /* Store information about all layers/cats for thematic display */
gvstyle *style;
- signed char highlighted; /* >0 Feature is highlighted */
+ signed char highlighted; /* >0 Feature is highlighted */
struct g_point *next;
} geopoint;
-/* Point layer */
+/* Vector map (points) */
typedef struct g_site
{
int gsite_id;
@@ -247,9 +274,9 @@
struct g_site *next;
void *clientdata;
- int thematic_layer; /* Layer number to use for thematic mapping. */
- gvstyle *style; /* Vector default look&feel */
- gvstyle *hstyle; /* IMHO highlight should be per layer basis. */
+ gvstyle_thematic *tstyle; /* thematic mapping */
+ gvstyle *style; /* points default look&feel */
+ gvstyle *hstyle; /* IMHO highlight should be per layer basis */
} geosite;
typedef struct
Modified: grass/trunk/include/nviz.h
===================================================================
--- grass/trunk/include/nviz.h 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/include/nviz.h 2011-06-25 21:32:43 UTC (rev 46778)
@@ -59,10 +59,6 @@
#define DEFAULT_SURF_COLOR 0x33BBFF
-#define RED_MASK 0x000000FF
-#define GRN_MASK 0x0000FF00
-#define BLU_MASK 0x00FF0000
-
#define FORMAT_PPM 1
#define FORMAT_TIF 2
Modified: grass/trunk/include/ogsf_proto.h
===================================================================
--- grass/trunk/include/ogsf_proto.h 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/include/ogsf_proto.h 2011-06-25 21:32:43 UTC (rev 46778)
@@ -33,7 +33,7 @@
/*========================== Function Prototypes ===========================*/
-/* From GK2.c */
+/* GK2.c */
int GK_set_interpmode(int);
void GK_set_tension(float);
void GK_showtension_start(void);
@@ -53,7 +53,7 @@
void GK_show_vol(int);
void GK_show_list(int);
-/* From GP2.c */
+/* GP2.c */
int GP_site_exists(int);
int GP_new_site(void);
int GP_num_sites(void);
@@ -63,6 +63,7 @@
int GP_get_sitename(int, char **);
int GP_get_style(int, int *, int *, float *, int *);
int GP_set_style(int, int, int, float, int);
+int GP_set_style_thematic(int, int, const char *, const char *, const char *, const char *);
int GP_attmode_color(int, const char *);
int GP_attmode_none(int);
int GP_set_zmode(int, int);
@@ -77,7 +78,7 @@
int GP_Set_ClientData(int, void *);
void *GP_Get_ClientData(int);
-/* From GS2.c */
+/* GS2.c */
void void_func(void);
void GS_libinit(void);
int GS_get_longdim(float *);
@@ -202,13 +203,13 @@
void GS_getlight_color(int, float *, float *, float *);
void GS_getlight_ambient(int, float *, float *, float *);
-/* From GSX.c */
+/* GSX.c */
int GS_check_cancel(void);
void GS_set_cancel(int);
void GS_set_cxl_func(void (*)(void));
void GS_set_swap_func(void (*)(void));
-/* From GS_util.c */
+/* GS_util.c */
double GS_geodistance(double *, double *, const char *);
float GS_distance(float *, float *);
float GS_P2distance(float *, float *);
@@ -226,7 +227,7 @@
void GS_v3mag(float *, float *);
int GS_coordpair_repeats(float *, float *, int);
-/* From GV2.c */
+/* GV2.c */
int GV_vect_exists(int);
int GV_new_vector(void);
int GV_num_vects(void);
@@ -248,7 +249,7 @@
int GV_Set_ClientData(int, void *);
void *GV_Get_ClientData(int);
-/* From GVL2.c */
+/* GVL2.c */
void GVL_libinit(void);
int GVL_get_region(float *, float *, float *, float *, float *, float *);
void *GVL_get_window();
@@ -304,11 +305,12 @@
int GVL_slice_set_pos(int, int, float, float, float, float, float, float,
int);
-/* From Gp3.c */
+/* Gp3.c */
int Gp_set_color(const char *, geopoint *);
geopoint *Gp_load_sites(const char *, int *, int *);
+int Gp_load_sites_thematic(geosite *);
-/* From Gs3.c */
+/* Gs3.c */
double Gs_distance(double *, double *);
int Gs_loadmap_as_float(struct Cell_head *, const char *, float *,
struct BM *, int *);
@@ -330,11 +332,11 @@
geosurf *);
int Gs_update_attrange(geosurf *, int);
-/* From Gv3.c */
+/* Gv3.c */
geoline *Gv_load_vect(const char *, int *);
void sub_Vectmem(int);
-/* From gk.c */
+/* gk.c */
Keylist *gk_copy_key(Keylist *);
unsigned long gk_get_mask_sofar(float, Keylist *);
int gk_viable_keys_for_mask(unsigned long, Keylist *, Keylist **);
@@ -352,7 +354,7 @@
void correct_twist(Keylist *);
int gk_draw_path(Viewnode *, int, Keylist *);
-/* From gp.c */
+/* gp.c */
geosite *gp_get_site(int);
geosite *gp_get_prev_site(int);
int gp_num_sites(void);
@@ -367,13 +369,13 @@
void gp_free_sitemem(geosite *);
void gp_set_drapesurfs(geosite *, int *, int);
-/* From gpd.c */
+/* gpd.c */
int gs_point_in_region(geosurf *, float *, float *);
void gpd_obj(geosurf *, gvstyle *, Point3);
int gpd_2dsite(geosite *, geosurf *, int);
int gpd_3dsite(geosite *, float, float, int);
-/* From gs.c */
+/* gs.c */
void gs_err(const char *);
void gs_init(void);
geosurf *gs_get_surf(int);
@@ -420,7 +422,7 @@
int gs_point_is_masked(geosurf *, float *);
int gs_distance_onsurf(geosurf *, float *, float *, float *, int);
-/* From gs_bm.c */
+/* gs_bm.c */
struct BM *gsbm_make_mask(typbuff *, float, int, int);
void gsbm_zero_mask(struct BM *);
int gsbm_or_masks(struct BM *, struct BM *);
@@ -430,12 +432,12 @@
int gs_update_curmask(geosurf *);
void print_bm(struct BM *);
-/* From gs_norms.c */
+/* gs_norms.c */
void init_vars(geosurf *);
int gs_calc_normals(geosurf *);
int calc_norm(geosurf *, int, int, unsigned int);
-/* From gs_query.c */
+/* gs_query.c */
int gs_los_intersect1(int, float (*)[3], float *);
int gs_los_intersect(int, float **, float *);
int RayCvxPolyhedronInt(Point3, Point3, double, Point4 *, int, double *,
@@ -443,7 +445,7 @@
void gs_get_databounds_planes(Point4 *);
int gs_setlos_enterdata(Point3 *);
-/* From gsd_cplane.c */
+/* gsd_cplane.c */
void gsd_def_cplane(int, float *, float *);
void gsd_update_cplanes(void);
void gsd_cplane_on(int);
@@ -456,7 +458,7 @@
void gsd_draw_cplane_fence(geosurf *, geosurf *, int);
void gsd_draw_cplane(int);
-/* From gsd_fonts.c */
+/* gsd_fonts.c */
GLuint gsd_set_font(const char *);
int gsd_get_txtwidth(const char *, int);
int gsd_get_txtheight(int size);
@@ -464,22 +466,22 @@
int get_txtdescender(void);
int get_txtxoffset(void);
-/* From gsd_img_ppm.c */
+/* gsd_img_ppm.c */
int GS_write_ppm(const char *);
int gsd_init_mpeg(const char *);
int gsd_write_mpegframe(void);
int gsd_close_mpeg(void);
-/* From gsd_img_tif.c */
+/* gsd_img_tif.c */
int GS_write_tif(const char *);
-/* From gsd_label.c */
+/* gsd_label.c */
void gs_put_label(const char *, GLuint, int, unsigned long, int *);
void gsd_remove_curr(void);
void gsd_remove_all(void);
void gsd_call_label(void);
-/* From gsd_objs.c */
+/* gsd_objs.c */
void gsd_box(float *, int, float *);
void gsd_plus(float *, int, float);
void gsd_line_onsurf(geosurf *, float *, float *);
@@ -502,7 +504,7 @@
void primitive_cone(unsigned long);
void primitive_cylinder(unsigned long, int);
-/* From gsd_prim.c */
+/* gsd_prim.c */
void gsd_flush(void);
void gsd_colormode(int);
void show_colormode(void);
@@ -561,7 +563,7 @@
void gsd_getwindow(int *, int *, double *, double *);
int gsd_writeView(unsigned char **, unsigned int, unsigned int);
-/* From gsd_surf.c */
+/* gsd_surf.c */
int gsd_surf(geosurf *);
int gsd_surf_map(geosurf *);
int gsd_surf_const(geosurf *, float);
@@ -574,7 +576,7 @@
int gsd_wall(float *, float *, float *);
int gsd_norm_arrows(geosurf *);
-/* From gsd_views.c */
+/* gsd_views.c */
int gsd_get_los(float (*)[3], short, short);
void gsd_set_view(geoview *, geodisplay *);
void gsd_check_focus(geoview *);
@@ -587,7 +589,7 @@
void gsd_surf2real(geosurf *, Point3);
void gsd_real2surf(geosurf *, Point3);
-/* From gsd_wire.c */
+/* gsd_wire.c */
int gsd_wire_surf(geosurf *);
int gsd_wire_surf_map(geosurf *);
int gsd_coarse_surf_map(geosurf *);
@@ -595,14 +597,14 @@
int gsd_wire_surf_func(geosurf *, int (*)());
int gsd_wire_arrows(geosurf *);
-/* From gsdiff.c */
+/* gsdiff.c */
void gsdiff_set_SDscale(float);
float gsdiff_get_SDscale(void);
void gsdiff_set_SDref(geosurf *);
geosurf *gsdiff_get_SDref(void);
float gsdiff_do_SD(float, int);
-/* From gsdrape.c */
+/* gsdrape.c */
int gsdrape_set_surface(geosurf *);
int seg_intersect_vregion(geosurf *, float *, float *);
Point3 *gsdrape_get_segments(geosurf *, float *, float *, int *);
@@ -622,7 +624,7 @@
int P3toPlane(Point3, Point3, Point3, float *);
int V3Cross(Point3, Point3, Point3);
-/* From gsds.c */
+/* gsds.c */
int gsds_findh(const char *, IFLAG *, IFLAG *, int);
int gsds_newh(const char *);
typbuff *gsds_get_typbuff(int, IFLAG);
@@ -635,10 +637,10 @@
int gsds_set_changed(int, IFLAG);
int gsds_get_type(int);
-/* From gsget.c */
+/* gsget.c */
int get_mapatt(typbuff *, int, float *);
-/* From gv.c */
+/* gv.c */
geovect *gv_get_vect(int);
geovect *gv_get_prev_vect(int);
int gv_num_vects(void);
@@ -652,18 +654,18 @@
void gv_free_vectmem(geovect *);
void gv_set_drapesurfs(geovect *, int *, int);
-/* From gv_quick.c */
+/* gv_quick.c */
float gv_line_length(geoline *);
int gln_num_points(geoline *);
int gv_num_points(geovect *);
int gv_decimate_lines(geovect *);
-/* From gvd.c */
+/* gvd.c */
int gs_clip_segment(geosurf *, float *, float *, float *);
int gvd_vect(geovect *, geosurf *, int);
void gvd_draw_lineonsurf(geosurf *, float *, float *, int);
-/* From gvl.c */
+/* gvl.c */
geovol *gvl_get_vol(int);
geovol *gvl_get_prev_vol(int);
int gvl_getall_vols(geovol **);
@@ -696,14 +698,14 @@
geovol_slice *gvl_slice_get_slice(int, int);
int gvl_slice_freemem(geovol_slice *);
-/* From trans.c */
+/* trans.c */
void P_scale(float, float, float);
void P_transform(int, float (*)[4], float (*)[4]);
int P_pushmatrix(void);
int P_popmatrix(void);
void P_rot(float, char);
-/* From gvl_file.c */
+/* gvl_file.c */
geovol_file *gvl_file_get_volfile(int);
char *gvl_file_get_name(int);
int gvl_file_get_file_type(geovol_file *);
@@ -718,19 +720,19 @@
int gvl_file_set_slices_param(geovol_file *, int, int);
void gvl_file_get_min_max(geovol_file *, double *, double *);
-/* From Gvl3.c */
+/* Gvl3.c */
int Gvl_load_colors_data(void **, const char *);
int Gvl_unload_colors_data(void *);
int Gvl_get_color_for_value(void *, float *);
-/* From gvl_calc.c */
+/* gvl_calc.c */
int gvl_isosurf_calc(geovol *);
int gvl_slices_calc(geovol *);
void gvl_write_char(int, unsigned char **, unsigned char);
unsigned char gvl_read_char(int, const unsigned char *);
void gvl_align_data(int, unsigned char *);
-/* From gvld.c */
+/* gvld.c */
int gvld_vol(geovol *);
int gvld_wire_vol(geovol *);
int gvld_isosurf(geovol *);
Modified: grass/trunk/lib/ogsf/GP2.c
===================================================================
--- grass/trunk/lib/ogsf/GP2.c 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/lib/ogsf/GP2.c 2011-06-25 21:32:43 UTC (rev 46778)
@@ -3,15 +3,11 @@
\brief OGSF library - loading and manipulating point sets (higher level functions)
- GRASS OpenGL gsurf OGSF Library
+ (C) 1999-2008, 2011 by the GRASS Development Team
- (C) 1999-2008 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.
- This program is free software under the
- GNU General Public License (>=v2).
- Read the file COPYING that comes with GRASS
- for details.
-
\author Bill Brown USACERL (January 1994)
\author Doxygenized by Martin landa <landa.martin gmail.com> (May 2008)
*/
@@ -42,7 +38,7 @@
G_debug(4, "GP_site_exists(%d)", id);
if (NULL == gp_get_site(id)) {
- return (0);
+ return 0;
}
for (i = 0; i < Next_site && !found; i++) {
@@ -53,7 +49,7 @@
G_debug(3, "GP_site_exists(): found=%d", found);
- return (found);
+ return found;
}
/*!
@@ -74,10 +70,10 @@
G_debug(3, "GP_new_site() id=%d", np->gsite_id);
- return (np->gsite_id);
+ return np->gsite_id;
}
- return (-1);
+ return -1;
}
/*!
@@ -87,7 +83,7 @@
*/
int GP_num_sites(void)
{
- return (gp_num_sites());
+ return gp_num_sites();
}
/*!
@@ -109,17 +105,17 @@
if (Next_site) {
ret = (int *)G_malloc(Next_site * sizeof(int)); /* G_fatal_error */
if (!ret) {
- return (NULL);
+ return NULL;
}
for (i = 0; i < Next_site; i++) {
ret[i] = Site_ID[i];
}
- return (ret);
+ return ret;
}
- return (NULL);
+ return NULL;
}
/*!
@@ -150,21 +146,20 @@
if (found) {
--Next_site;
- return (1);
+ return 1;
}
}
- return (-1);
+ return -1;
}
/*!
\brief Load point set from file
- Check to see if handle already loaded, if so - free before loading new
- for now, always load to memory
+ Check to see if handle already loaded, if so - free before loading
+ new for now, always load to memory.
- \todo load file handle & ready for reading instead of using
- memory
+ \todo load file handle & ready for reading instead of using memory
\param id point set id
\param filename point set filename
@@ -176,10 +171,10 @@
{
geosite *gp;
- G_debug(3, "GP_load_site(%d, %s)", id, filename);
+ G_debug(3, "GP_load_site(id=%d, name=%s)", id, filename);
if (NULL == (gp = gp_get_site(id))) {
- return (-1);
+ return -1;
}
if (gp->points) {
@@ -189,12 +184,12 @@
gp->filename = G_store(filename);
gp->points = Gp_load_sites(filename, &(gp->n_sites), &(gp->has_z));
-
+
if (gp->points) {
- return (1);
+ return 1;
}
- return (-1);
+ return -1;
}
/*!
@@ -215,12 +210,12 @@
G_debug(4, "GP_get_sitename(%d)", id);
if (NULL == (gp = gp_get_site(id))) {
- return (-1);
+ return -1;
}
*filename = G_store(gp->filename);
- return (1);
+ return 1;
}
/*!
@@ -237,7 +232,7 @@
G_debug(4, "GP_get_style(%d)", id);
if (NULL == (gp = gp_get_site(id))) {
- return (-1);
+ return -1;
}
*color = gp->style->color;
@@ -245,7 +240,7 @@
*symbol = gp->style->symbol;
*size = gp->style->size;
- return (1);
+ return 1;
}
/*!
@@ -257,17 +252,18 @@
\param size icon size
\param symbol icon symbol
+ \return 1 on success
\return -1 on error (point set not found)
*/
int GP_set_style(int id, int color, int width, float size, int symbol)
{
geosite *gp;
- G_debug(4, "GP_set_style(%d, %d, %d, %f, %d)", id, color, width, size,
+ G_debug(4, "GP_set_style(id=%d, color=%d, width=%d, size=%f, symbol=%d)", id, color, width, size,
symbol);
if (NULL == (gp = gp_get_site(id))) {
- return (-1);
+ return -1;
}
gp->style->color = color;
@@ -275,10 +271,50 @@
gp->style->size = size;
gp->style->width = width;
- return (1);
+ return 1;
}
/*!
+ \brief Set point set style for thematic mapping
+
+ Updates also style for each geopoint.
+
+ \param id point set id
+ \param layer layer number for thematic mapping
+ \param color icon color
+ \param width icon line width
+ \param size icon size
+ \param symbol icon symbol
+
+ \return 1 on success
+ \return -1 on error (point set not found)
+ */
+int GP_set_style_thematic(int id, int layer, const char* color, const char* width, const char* size, const char* symbol)
+{
+ geosite *gp;
+
+ G_debug(4, "GP_set_style_thematic(id=%d, layer=%d, color=%s, width=%s, size=%s, symbol=%s)", id, layer,
+ color, width, size, symbol);
+
+ if (NULL == (gp = gp_get_site(id))) {
+ return -1;
+ }
+
+ if(!gp->tstyle)
+ gp->tstyle = (gvstyle_thematic *)G_malloc(sizeof(gvstyle_thematic));
+
+ gp->tstyle->layer = layer;
+ gp->tstyle->color_column = G_store(color);
+ gp->tstyle->symbol_column = G_store(symbol);
+ gp->tstyle->size_column = G_store(size);
+ gp->tstyle->width_column = G_store(width);
+
+ Gp_load_sites_thematic(gp);
+
+ return 1;
+}
+
+/*!
\brief Set z-mode
\param id poin set id
@@ -296,20 +332,20 @@
G_debug(3, "GP_set_zmode(%d,%d)", id, use_z);
if (NULL == (gp = gp_get_site(id))) {
- return (-1);
+ return -1;
}
if (use_z) {
if (gp->has_z) {
gp->use_z = 1;
- return (1);
+ return 1;
}
- return (0);
+ return 0;
}
gp->use_z = 0;
- return (1);
+ return 1;
}
/*!
@@ -329,11 +365,11 @@
G_debug(4, "GP_get_zmode(%d)", id);
if (NULL == (gp = gp_get_site(id))) {
- return (-1);
+ return -1;
}
*use_z = gp->use_z;
- return (1);
+ return 1;
}
/*!
@@ -407,10 +443,10 @@
if (gp && GS_surf_exists(hs)) {
gp->drape_surf_id[gp->n_surfs] = hs;
gp->n_surfs += 1;
- return (1);
+ return 1;
}
- return (-1);
+ return -1;
}
/*!
@@ -430,7 +466,7 @@
G_debug(3, "GP_unselect_surf(%d,%d)", hp, hs);
if (!GP_surf_is_selected(hp, hs)) {
- return (1);
+ return 1;
}
gp = gp_get_site(hp);
@@ -443,12 +479,12 @@
}
gp->n_surfs -= 1;
- return (1);
+ return 1;
}
}
}
- return (-1);
+ return -1;
}
/*!
@@ -472,12 +508,12 @@
if (gp) {
for (i = 0; i < gp->n_surfs; i++) {
if (hs == gp->drape_surf_id[i]) {
- return (1);
+ return 1;
}
}
}
- return (0);
+ return 0;
}
/*!
@@ -547,10 +583,10 @@
if (gp) {
gp->clientdata = clientd;
- return (1);
+ return 1;
}
- return (-1);
+ return -1;
}
/*!
@@ -570,5 +606,5 @@
return (gp->clientdata);
}
- return (NULL);
+ return NULL;
}
Modified: grass/trunk/lib/ogsf/Gp3.c
===================================================================
--- grass/trunk/lib/ogsf/Gp3.c 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/lib/ogsf/Gp3.c 2011-06-25 21:32:43 UTC (rev 46778)
@@ -19,9 +19,10 @@
#include <stdlib.h>
#include <grass/gis.h>
+#include <grass/colors.h>
#include <grass/raster.h>
-#include <grass/site.h>
#include <grass/vector.h>
+#include <grass/dbmi.h>
#include <grass/glocale.h>
#include <grass/gstypes.h>
@@ -30,14 +31,14 @@
The other alternative may be to load to a tmp file.
- \param grassname vector point map
- \param nsites
- \param has_z 2D or 3D points?
+ \param name name of vector map to be loaded
+ \param[out] nsites number of loaded points
+ \param[out] has_z 2D or 3D points data loaded?
- \return pointer to geopoint struct
+ \return pointer to geopoint struct (array)
\return NULL on failure
*/
-geopoint *Gp_load_sites(const char *grassname, int *nsites, int *has_z)
+geopoint *Gp_load_sites(const char *name, int *nsites, int *has_z)
{
struct Map_info map;
static struct line_pnts *Points = NULL;
@@ -45,52 +46,50 @@
geopoint *top, *gpt, *prev;
int np, ltype, eof;
struct Cell_head wind;
- RASTER_MAP_TYPE rtype;
int ndim;
const char *mapset;
np = 0;
eof = 0;
- *has_z = 0;
-
- mapset = G_find_vector2(grassname, "");
+
+ mapset = G_find_vector2(name, "");
if (!mapset) {
- G_warning(_("Vector map <%s> not found"), grassname);
+ G_warning(_("Vector map <%s> not found"), name);
return NULL;
}
-
- Vect_set_open_level(2);
- if (Vect_open_old(&map, grassname, "") == -1) {
+
+ Vect_set_open_level(1);
+ if (Vect_open_old(&map, name, "") == -1) {
G_fatal_error(_("Unable to open vector map <%s>"),
- G_fully_qualified_name(grassname, mapset));
+ G_fully_qualified_name(name, mapset));
}
-
+
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
-
+
top = gpt = (geopoint *) G_malloc(sizeof(geopoint));
+ G_zero(gpt, sizeof(geopoint));
if (!top) {
- return (NULL);
+ return NULL;
}
G_get_set_window(&wind);
/* get ndim */
+ *has_z = 0;
ndim = 2;
if (Vect_is_3d(&map)) {
+ *has_z = 1;
ndim = 3;
}
- /* set rtype */
- rtype = CELL_TYPE;
-
while (eof == 0) {
ltype = Vect_read_next_line(&map, Points, Cats);
switch (ltype) {
case -1:
{
G_warning(_("Unable to read vector map <%s>"),
- G_fully_qualified_name(grassname, mapset));
+ G_fully_qualified_name(name, mapset));
return (NULL);
}
case -2: /* EOF */
@@ -105,13 +104,11 @@
gpt->p3[Y] = Points->y[0];
if (ndim > 2) {
- *has_z = 1;
gpt->dims = 3;
gpt->p3[Z] = Points->z[0];
}
else {
gpt->dims = 2;
- *has_z = 0;
}
/* Store category info for thematic display */
@@ -120,18 +117,16 @@
Cats = Vect_new_cats_struct();
}
else {
- gpt->cats = NULL;
Vect_reset_cats(Cats);
}
- gpt->highlighted = 0;
-
-
- G_debug(3, "loading vector point %d %f %f -- %d",
+
+ G_debug(5, "loading vector point %d x=%f y=%f ncats=%d",
np, Points->x[0], Points->y[0], Cats->n_cats);
gpt->next = (geopoint *) G_malloc(sizeof(geopoint)); /* G_fatal_error */
+ G_zero(gpt->next, sizeof(geopoint));
if (!gpt->next) {
- return (NULL);
+ return NULL;
}
prev = gpt;
@@ -148,15 +143,102 @@
if (!np) {
G_warning(_("No points from vector map <%s> fall within current region"),
- G_fully_qualified_name(grassname, mapset));
+ G_fully_qualified_name(name, mapset));
return (NULL);
}
else {
G_message(_("Vector map <%s> loaded (%d points)"),
- G_fully_qualified_name(grassname, mapset), np);
+ G_fully_qualified_name(name, mapset), np);
}
*nsites = np;
- return (top);
+ return top;
}
+
+/*!
+ \brief Load styles for geopoints based on thematic mapping
+
+ \todo Currently only supports color settings
+
+ \param gp pointer to geosite structure
+
+ \return number of points defined by thematic mapping
+ \return -1 on error
+*/
+int Gp_load_sites_thematic(geosite *gp)
+{
+ geopoint *gpt;
+
+ struct Map_info Map;
+ struct field_info *Fi;
+
+ int nvals, cat, npts;
+ int red, blu, grn;
+ const char *str;
+ const char *mapset;
+
+ dbDriver *driver;
+ dbValue value;
+
+ if(!gp || !gp->tstyle || !gp->filename)
+ return -1;
+
+ mapset = G_find_vector2(gp->filename, "");
+ if (!mapset) {
+ G_fatal_error(_("Vector map <%s> not found"), gp->filename);
+ }
+
+ Vect_set_open_level(1);
+ if (Vect_open_old(&Map, gp->filename, "") == -1) {
+ G_fatal_error(_("Unable to open vector map <%s>"),
+ G_fully_qualified_name(gp->filename, mapset));
+ }
+
+ Fi = Vect_get_field(&Map, gp->tstyle->layer);
+ if (!Fi)
+ G_fatal_error(_("Database connection not defined for layer %d"),
+ gp->tstyle->layer);
+
+ driver = db_start_driver_open_database(Fi->driver, Fi->database);
+ if (!driver)
+ G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+ Fi->database, Fi->driver);
+
+ gpt = gp->points;
+ npts = 0;
+ G_message(_("Loading thematic points layer <%s>..."),
+ G_fully_qualified_name(gp->filename, mapset));
+ for(;gpt; gpt = gpt->next) {
+ gpt->style = (gvstyle *) G_malloc(sizeof(gvstyle));
+ G_zero(gpt->style, sizeof(gvstyle));
+ /* use default style */
+ gpt->style->color = gp->style->color;
+ gpt->style->symbol = gp->style->symbol;
+ gpt->style->size = gp->style->size;
+ gpt->style->width = gp->style->width;
+
+ Vect_cat_get(gpt->cats, gp->tstyle->layer, &cat);
+ if (cat < 0)
+ continue;
+
+ /* color */
+ nvals = db_select_value(driver, Fi->table, Fi->key, cat, gp->tstyle->color_column, &value);
+ if (nvals < 1)
+ continue;
+ str = db_get_value_string(&value);
+ if (G_str_to_color(str, &red, &grn, &blu) != 1) {
+ G_warning(_("Invalid color definition (%s)"),
+ str);
+ gpt->style->color = gp->style->color;
+ }
+ else {
+ gpt->style->color = (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) +
+ ((int)((blu) << 16) & BLU_MASK);
+ }
+
+ npts++;
+ }
+
+ return npts;
+}
Modified: grass/trunk/lib/ogsf/gp.c
===================================================================
--- grass/trunk/lib/ogsf/gp.c 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/lib/ogsf/gp.c 2011-06-25 21:32:43 UTC (rev 46778)
@@ -127,7 +127,8 @@
if (!np) {
return (NULL);
}
-
+ G_zero(np, sizeof(geosite));
+
lp = gp_get_last_site();
if (lp) {
lp->next = np;
@@ -137,14 +138,14 @@
Site_top = np;
np->gsite_id = FIRST_SITE_ID;
}
-
- np->next = NULL;
np->style = (gvstyle *) G_malloc(sizeof(gvstyle));
if (!np->style)
return NULL;
+ G_zero(np->style, sizeof (gvstyle));
np->hstyle = (gvstyle *) G_malloc(sizeof(gvstyle));
if (!np->hstyle)
return NULL;
+ G_zero(np->hstyle, sizeof (gvstyle));
return (np);
}
@@ -188,38 +189,24 @@
*/
int gp_set_defaults(geosite * gp)
{
- int i;
float dim;
G_debug(5, "gp_set_defaults");
if (!gp) {
- return (-1);
+ return -1;
}
-
GS_get_longdim(&dim);
- gp->filename = NULL;
- gp->n_sites = gp->use_z = gp->n_surfs = gp->use_mem = 0;
- gp->x_trans = gp->y_trans = gp->z_trans = 0.0;
- gp->points = NULL;
- gp->has_z = 0;
- gp->thematic_layer = -1;
gp->style->color = 0xF0F0F0;
gp->style->size = dim / 100.;
gp->style->width = 1;
gp->style->symbol = ST_X;
- gp->style->next = NULL;
gp->hstyle->color = 0xFF0000;
gp->hstyle->size = dim / 150.;
gp->hstyle->symbol = ST_X;
- gp->hstyle->next = NULL;
- gp->next = NULL;
- for (i = 0; i < MAX_SURFS; i++) {
- gp->drape_surf_id[i] = 0;
- }
- return (1);
+ return 1;
}
/*!
@@ -262,7 +249,7 @@
}
/*!
- \brief Free geosite struct
+ \brief Free allocated geosite struct
\param fp pointer to geosite struct
@@ -274,7 +261,7 @@
geosite *gp;
int found = 0;
- G_debug(5, "gp_free_site");
+ G_debug(5, "gp_free_site(id=%d)", fp->gsite_id);
if (Site_top) {
if (fp == Site_top) {
@@ -321,34 +308,38 @@
void gp_free_sitemem(geosite * fp)
{
geopoint *gpt, *tmp;
- gvstyle *gvs, *tmpstyle;
-
+
G_free((void *)fp->filename);
fp->filename = NULL;
- if (fp->style)
+ if (fp->style) {
G_free(fp->style);
- if (fp->hstyle)
+ }
+ if (fp->hstyle) {
G_free(fp->hstyle);
+ }
if (fp->points) {
for (gpt = fp->points; gpt;) {
G_free(gpt->cats);
- if (fp->thematic_layer > -1) { /* Style also exists for features */
- for (gvs = fp->style; gvs;) {
- tmpstyle = gvs;
- gvs = gvs->next;
- G_free(tmpstyle);
+ if(gpt->style) {
+ G_free(gpt->style);
}
- }
-
+
tmp = gpt;
gpt = gpt->next;
G_free(tmp);
}
-
+
fp->n_sites = 0;
fp->points = NULL;
}
+ if(fp->tstyle) {
+ G_free(fp->tstyle->color_column);
+ G_free(fp->tstyle->symbol_column);
+ G_free(fp->tstyle->size_column);
+ G_free(fp->tstyle->width_column);
+ }
+
return;
}
Modified: grass/trunk/lib/ogsf/gpd.c
===================================================================
--- grass/trunk/lib/ogsf/gpd.c 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/lib/ogsf/gpd.c 2011-06-25 21:32:43 UTC (rev 46778)
@@ -1,21 +1,17 @@
/*!
- \file gpd.c
+ \file lib/ogsf/gpd.c
+
+ \brief OGSF library - loading and manipulating point sets (lower level)
+
+ (C) 1999-2008, 2011 by the GRASS Development Team
- \brief OGSF library - loading and manipulating point sets
+ This program is free software under the GNU General Public License
+ (>=v2). Read the file COPYING that comes with GRASS for details.
+
+ \author Bill Brown USACERL, GMSL/University of Illinois (December 1993)
+ \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
+*/
- GRASS OpenGL gsurf OGSF Library
-
- (C) 1999-2008 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 Bill Brown USACERL, GMSL/University of Illinois (December 1993)
- \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
- */
-
#include <stdlib.h>
#include <math.h>
@@ -29,17 +25,17 @@
#define v_border 50
/*!
- \brief Check if point is in region
-
- Check for cancel every CHK_FREQ points
-
- \param gs surface (geosurf)
- \param pt point (array(X,Y,Z))
- \param region region settings (array (top,bottom,left,right))
-
- \return 0 point outside of region
- \return 1 point inside region
- */
+ \brief Check if point is in region
+
+ Check for cancel every CHK_FREQ points
+
+ \param gs surface (geosurf)
+ \param pt point (array(X,Y,Z))
+ \param region region settings (array (top,bottom,left,right))
+
+ \return 0 point outside of region
+ \return 1 point inside region
+*/
int gs_point_in_region(geosurf * gs, float *pt, float *region)
{
float top, bottom, left, right;
@@ -62,15 +58,15 @@
}
/*!
- \brief Draw point representing object
-
- Do normal transforms before calling
-
- Note gs: NULL if 3d obj or const elev surface
-
- \param gs surface (geosurf)
- \param style object displaying style (highlighted or not)
- \param pt 3d point (Point3)
+ \brief Draw point representing object
+
+ Do normal transforms before calling
+
+ Note gs: NULL if 3d obj or const elev surface
+
+ \param gs surface (geosurf)
+ \param style object displaying style (highlighted or not)
+ \param pt 3d point (Point3)
*/
void gpd_obj(geosurf * gs, gvstyle * style, Point3 pt)
{
@@ -200,23 +196,23 @@
}
/*!
- \brief ADD
-
- Need to think about translations - If user translates surface,
- sites should automatically go with it, but translating sites should
- translate it relative to surface on which it's displayed
-
- Handling mask checking here
-
- \todo prevent scaling by 0
-
- \param gp site (geosite)
- \param gs surface (geosurf)
- \param do_fast (unused)
-
- \return 0
- \return 1
- */
+ \brief Draw 2D point set
+
+ Need to think about translations - If user translates surface,
+ sites should automatically go with it, but translating sites should
+ translate it relative to surface on which it's displayed
+
+ Handling mask checking here
+
+ \todo prevent scaling by 0
+
+ \param gp site (geosite)
+ \param gs surface (geosurf)
+ \param do_fast (unused)
+
+ \return 0 on failure
+ \return 1 on success
+*/
int gpd_2dsite(geosite * gp, geosurf * gs, int do_fast)
{
float site[3], konst;
@@ -227,9 +223,8 @@
GLint viewport[4];
GLint window[4];
-
if (GS_check_cancel()) {
- return (0);
+ return 0;
}
if (gs) {
@@ -263,7 +258,7 @@
gsd_linewidth(1);
gsd_popmatrix();
- return (0);
+ return 0;
}
}
@@ -279,54 +274,54 @@
/* returns 0 if outside or masked */
site[Z] += gp->z_trans;
- if (gsd_checkpoint
- (site, window, viewport, modelMatrix, projMatrix))
+ if (gsd_checkpoint(site, window,
+ viewport, modelMatrix, projMatrix))
continue;
else {
if (gpt->highlighted > 0)
gpd_obj(gs, gp->hstyle, site);
- else if (gp->thematic_layer > 0)
+ else if (gp->tstyle)
gpd_obj(gs, gpt->style, site);
- else
+ else
gpd_obj(gs, gp->style, site);
+ }
}
}
- }
else if (src == CONST_ATT) {
if (gs_point_in_region(gs, site, NULL)) {
site[Z] += gp->z_trans;
- if (gsd_checkpoint
- (site, window, viewport, modelMatrix, projMatrix))
+ if (gsd_checkpoint(site, window,
+ viewport, modelMatrix, projMatrix))
continue;
else {
if (gpt->highlighted > 0)
gpd_obj(gs, gp->hstyle, site);
- else if (gp->thematic_layer > 0)
+ else if (gp->tstyle)
gpd_obj(gs, gpt->style, site);
- else
+ else
gpd_obj(gs, gp->style, site);
+ }
}
}
}
- }
gsd_linewidth(1);
gsd_popmatrix();
}
- return (1);
+ return 1;
}
/*!
- \brief ADD
-
- \param gp site (geosite)
- \param xo,yo
- \param do_fast (unused)
-
- \return 0
- \return 1
- */
+ \brief Draw 3D point set
+
+ \param gp site (geosite)
+ \param xo,yo
+ \param do_fast (unused)
+
+ \return 0 on success
+ \return 1 on failure
+*/
int gpd_3dsite(geosite * gp, float xo, float yo, int do_fast)
{
float site[3], tz;
@@ -377,15 +372,15 @@
{
if (gpt->highlighted > 0)
gpd_obj(NULL, gp->hstyle, site);
- else if (gp->thematic_layer > 0)
+ else if (gp->tstyle)
gpd_obj(NULL, gpt->style, site);
else
gpd_obj(NULL, gp->style, site);
+ }
}
- }
gsd_linewidth(1);
gsd_popmatrix();
- return (1);
+ return 1;
}
Modified: grass/trunk/visualization/nviz2/cmd/Makefile
===================================================================
--- grass/trunk/visualization/nviz2/cmd/Makefile 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/visualization/nviz2/cmd/Makefile 2011-06-25 21:32:43 UTC (rev 46778)
@@ -15,7 +15,8 @@
EXTRA_INC = $(VECT_INC)
EXTRA_CFLAGS = $(INC) \
$(TIFFINCPATH) $(DSPINC) \
- $(VECT_CFLAGS) $(OPENGLINC)
+ $(VECT_CFLAGS) $(OPENGLINC) \
+ $(VECT_CFLAGS)
ifeq ($(OPENGL_X11),1)
EXTRA_CFLAGS += $(XCFLAGS)
@@ -23,8 +24,8 @@
EXTRA_LDFLAGS = $(OGL_LIBS)
-LIBES = $(GISLIB) $(OGSFLIB) $(NVIZLIB) $(G3DLIB)
-DEPENDENCIES = $(GISDEP) $(NVIZDEP)
+LIBES = $(GISLIB) $(OGSFLIB) $(NVIZLIB) $(G3DLIB) $(VECTORLIB) $(DBMILIB)
+DEPENDENCIES = $(GISDEP) $(NVIZDEP) $(VECTORDEP) $(DBMIDEP)
include $(MODULE_TOPDIR)/include/Make/Module.make
Modified: grass/trunk/visualization/nviz2/cmd/args.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/args.c 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/visualization/nviz2/cmd/args.c 2011-06-25 21:32:43 UTC (rev 46778)
@@ -3,7 +3,7 @@
\brief Parse command
- (C) 2008, 2010 by the GRASS Development Team
+ (C) 2008, 2010-2011 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
@@ -368,6 +368,14 @@
params->vpoints->guisection = _("Vector points");
params->vpoints->key = "vpoint";
+ params->vpoint_layer = G_define_standard_option(G_OPT_V_FIELD);
+ params->vpoint_layer->multiple = YES;
+ params->vpoint_layer->required = NO;
+ params->vpoint_layer->description = _("Layer number or name for thematic mapping");
+ params->vpoint_layer->guisection = _("Vector points");
+ params->vpoint_layer->key = "vpoint_layer";
+ params->vpoint_layer->answer = "1";
+
/* point width */
params->vpoint_size = G_define_option();
params->vpoint_size->key = "vpoint_size";
@@ -380,6 +388,13 @@
params->vpoint_size->options = "1-1000";
params->vpoint_size->answer = "100";
+ params->vpoint_size_column = G_define_standard_option(G_OPT_DB_COLUMN);
+ params->vpoint_size_column->multiple = YES;
+ params->vpoint_size_column->required = NO;
+ params->vpoint_size_column->label = _("Name of size definition column");
+ params->vpoint_size_column->key = "vpoint_size_column";
+ params->vpoint_size_column->guisection = _("Vector points");
+
/* point width */
params->vpoint_width = G_define_option();
params->vpoint_width->key = "vpoint_width";
@@ -392,6 +407,13 @@
params->vpoint_width->options = "1-1000";
params->vpoint_width->answer = "2";
+ params->vpoint_width_column = G_define_standard_option(G_OPT_DB_COLUMN);
+ params->vpoint_width_column->multiple = YES;
+ params->vpoint_width_column->required = NO;
+ params->vpoint_width_column->label = _("Name of width definition column");
+ params->vpoint_width_column->key = "vpoint_width_column";
+ params->vpoint_width_column->guisection = _("Vector points");
+
/* point color */
params->vpoint_color = G_define_standard_option(G_OPT_C_FG);
params->vpoint_color->multiple = YES;
@@ -401,6 +423,13 @@
params->vpoint_color->answer = "blue";
params->vpoint_color->guisection = _("Vector points");
+ params->vpoint_color_column = G_define_standard_option(G_OPT_DB_COLUMN);
+ params->vpoint_color_column->multiple = YES;
+ params->vpoint_color_column->required = NO;
+ params->vpoint_color_column->label = _("Name of color definition column");
+ params->vpoint_color_column->key = "vpoint_color_column";
+ params->vpoint_color_column->guisection = _("Vector points");
+
/* point mode */
params->vpoint_marker = G_define_option();
params->vpoint_marker->key = "vpoint_marker";
@@ -414,6 +443,13 @@
params->vpoint_marker->answer = "sphere";
params->vpoint_marker->guisection = _("Vector points");
+ params->vpoint_marker_column = G_define_standard_option(G_OPT_DB_COLUMN);
+ params->vpoint_marker_column->multiple = YES;
+ params->vpoint_marker_column->required = NO;
+ params->vpoint_marker_column->label = _("Name of marker definition column");
+ params->vpoint_marker_column->key = "vpoint_marker_column";
+ params->vpoint_marker_column->guisection = _("Vector points");
+
/* position */
params->vpoint_pos = G_define_option();
params->vpoint_pos->key = "vpoint_position";
@@ -656,8 +692,10 @@
int nelev_map, nelev_const, nelevs;
int nmaps, nconsts;
- int nvects;
+ int nvlines;
+ int nvpoints;
+
/* topography */
nelev_map = opt_get_num_answers(params->elev_map);
nelev_const = opt_get_num_answers(params->elev_const);
@@ -744,39 +782,46 @@
}
/*
- * vector
+ * vector lines
*/
- nvects = opt_get_num_answers(params->vlines);
+ nvlines = opt_get_num_answers(params->vlines);
/* width */
nconsts = opt_get_num_answers(params->vline_width);
- if (nvects > 0 && nconsts != nvects)
+ if (nvlines > 0 && nconsts != nvlines)
G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d)"),
- params->vlines->key, nvects, params->vline_width->key,
+ params->vlines->key, nvlines, params->vline_width->key,
nconsts);
/* color */
nconsts = opt_get_num_answers(params->vline_color);
- if (nvects > 0 && nconsts != nvects)
+ if (nvlines > 0 && nconsts != nvlines)
G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d"),
- params->vlines->key, nvects, params->vline_color->key,
+ params->vlines->key, nvlines, params->vline_color->key,
nconsts);
/* mode */
nconsts = opt_get_num_answers(params->vline_mode);
- if (nvects > 0 && nconsts != nvects)
+ if (nvlines > 0 && nconsts != nvlines)
G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d)"),
- params->vlines->key, nvects, params->vline_mode->key,
+ params->vlines->key, nvlines, params->vline_mode->key,
nconsts);
/* height */
nconsts = opt_get_num_answers(params->vline_height);
- if (nvects > 0 && nconsts != nvects)
+ if (nvlines > 0 && nconsts != nvlines)
G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d)"),
- params->vlines->key, nvects, params->vline_height->key,
+ params->vlines->key, nvlines, params->vline_height->key,
nconsts);
return;
+
+ /*
+ * vector points
+ */
+ nvpoints = opt_get_num_answers(params->vpoints);
+
+ /* TODO */
}
void print_error(int nmaps, int nconsts, int nelevs,
Modified: grass/trunk/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass/trunk/visualization/nviz2/cmd/local_proto.h 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/visualization/nviz2/cmd/local_proto.h 2011-06-25 21:32:43 UTC (rev 46778)
@@ -19,6 +19,7 @@
*vlines, *vline_width, *vline_color, *vline_mode, *vline_height, *vline_pos,
/* vector points */
*vpoints, *vpoint_size, *vpoint_marker, *vpoint_color, *vpoint_width, *vpoint_pos,
+ *vpoint_layer, *vpoint_size_column, *vpoint_marker_column, *vpoint_color_column, *vpoint_width_column,
/* volumes */
*volume, *volume_mode, *volume_shade, *volume_pos, *volume_res, *isosurf_level,
/* misc */
@@ -48,6 +49,7 @@
int load_vpoints(const struct GParams *, nv_data *);
int vlines_set_attrb(const struct GParams *);
int vpoints_set_attrb(const struct GParams *);
+int check_thematic(const struct GParams *, int);
/* volume.c */
int load_rasters3d(const struct GParams *, nv_data *);
Modified: grass/trunk/visualization/nviz2/cmd/main.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/main.c 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/visualization/nviz2/cmd/main.c 2011-06-25 21:32:43 UTC (rev 46778)
@@ -7,7 +7,7 @@
*
* PURPOSE: Renders GIS data in 3D space.
*
- * COPYRIGHT: (C) 2008,2010 by the GRASS Development Team
+ * COPYRIGHT: (C) 2008, 2010-2011 by the GRASS Development Team
*
* This program is free software under the GNU General
* Public License (>=v2). Read the file COPYING that
@@ -105,7 +105,7 @@
/* load point vector maps */
if (params->vpoints->answer) {
load_vpoints(params, &data);
- /* set attributes for 2d lines */
+ /* set attributes for points */
vpoints_set_attrb(params);
}
Modified: grass/trunk/visualization/nviz2/cmd/vector.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/vector.c 2011-06-25 13:52:47 UTC (rev 46777)
+++ grass/trunk/visualization/nviz2/cmd/vector.c 2011-06-25 21:32:43 UTC (rev 46778)
@@ -3,7 +3,7 @@
\brief Vector subroutines
- (C) 2008, 2010 by the GRASS Development Team
+ (C) 2008, 2010-2011 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
@@ -15,6 +15,8 @@
#include <stdlib.h>
#include <string.h>
+#include <grass/vector.h>
+#include <grass/dbmi.h>
#include <grass/glocale.h>
#include "local_proto.h"
@@ -136,7 +138,7 @@
}
/*!
- \brief Set vector points mode
+ \brief Set vector points style
\param params parameters
@@ -145,19 +147,28 @@
*/
int vpoints_set_attrb(const struct GParams *params)
{
- int i;
+ int i, layer;
int *site_list, nsites;
int marker, color, width;
float size;
- char *marker_str;
+ char *marker_str, *color_column, *size_column, *width_column, *marker_column;
site_list = GP_get_site_list(&nsites);
for (i = 0; i < nsites; i++) {
+ layer = check_thematic(params, FALSE);
color = Nviz_color_from_str(params->vpoint_color->answers[i]);
+ color_column = params->vpoint_color_column->answers ?
+ params->vpoint_color_column->answers[i] : NULL;
size = atof(params->vpoint_size->answers[i]);
+ size_column = params->vpoint_size_column->answers ?
+ params->vpoint_size_column->answers[i] : NULL;
width = atoi(params->vpoint_width->answers[i]);
+ width_column = params->vpoint_width_column->answers ?
+ params->vpoint_width_column->answers[i] : NULL;
marker_str = params->vpoint_marker->answers[i];
+ marker_column = params->vpoint_marker_column->answers ?
+ params->vpoint_marker_column->answers[i] : NULL;
if (strcmp(marker_str, "x") == 0)
marker = ST_X;
@@ -179,7 +190,94 @@
G_fatal_error(_("Unknown icon marker"));
GP_set_style(site_list[i], color, width, size, marker);
+ if (color_column || width_column || size_column || marker_column) {
+ GP_set_style_thematic(site_list[i], layer, color_column, width_column,
+ size_column, marker_column);
+ }
}
return 1;
}
+
+int check_thematic(const struct GParams *params, int vlines)
+{
+ int i, type;
+ struct Map_info Map;
+ struct Option *map, *layer, *color, *size, *width, *marker;
+ struct field_info *Fi;
+
+ dbDriver *driver;
+ dbColumn *column;
+
+ if (vlines) {
+ map = params->vlines; /*TODO */
+ layer = NULL;
+ color = NULL;
+ size = NULL;
+ width = NULL;
+ marker = NULL;
+ }
+ else {
+ map = params->vpoints;
+ layer = params->vpoint_layer;
+ color = params->vpoint_color_column;
+ size = params->vpoint_size_column;
+ width = params->vpoint_width_column;
+ marker = params->vpoint_marker_column;
+ }
+ for (i = 0; map->answers[i]; i++) {
+ if (1 > Vect_open_old(&Map, map->answer, ""))
+ G_fatal_error(_("Unable to open vector map <%s>"), map->answer);
+ Fi = Vect_get_field2(&Map, layer->answer);
+ if (!Fi)
+ G_fatal_error(_("Database connection not defined for layer %s"),
+ layer->answer);
+
+ driver = db_start_driver_open_database(Fi->driver, Fi->database);
+ if (!driver)
+ G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+ Fi->database, Fi->driver);
+
+ if (color->answers && color->answers[i]) {
+ db_get_column(driver, Fi->table, color->answers[i], &column);
+ if (!column)
+ G_fatal_error(_("Column <%s> in table <%s> not found"),
+ color->answers[i], Fi->table);
+
+ if (db_column_Ctype(driver, Fi->table, color->answers[i]) != DB_C_TYPE_STRING)
+ G_fatal_error(_("Data type of color column must be character"));
+ }
+ if (size->answers && size->answers[i]) {
+ db_get_column(driver, Fi->table, size->answers[i], &column);
+ if (!column)
+ G_fatal_error(_("Column <%s> in table <%s> not found"),
+ size->answers[i], Fi->table);
+
+ type = db_column_Ctype(driver, Fi->table, size->answers[i]);
+ if (type != DB_C_TYPE_INT && type != DB_C_TYPE_DOUBLE)
+ G_fatal_error(_("Data type of size column must be numeric"));
+ }
+ if (width->answers && width->answers[i]) {
+ db_get_column(driver, Fi->table, width->answers[i], &column);
+ if (!column)
+ G_fatal_error(_("Column <%s> in table <%s> not found"),
+ width->answers[i], Fi->table);
+
+ type = db_column_Ctype(driver, Fi->table, width->answers[i]);
+ if (type != DB_C_TYPE_INT && type != DB_C_TYPE_DOUBLE)
+ G_fatal_error(_("Data type of width column must be numeric"));
+ }
+ if (marker->answers && marker->answers[i]) {
+ db_get_column(driver, Fi->table, marker->answers[i], &column);
+ if (!column)
+ G_fatal_error(_("Column <%s> in table <%s> not found"),
+ marker->answers[i], Fi->table);
+
+ type = db_column_Ctype(driver, Fi->table, width->answers[i]);
+ if (db_column_Ctype(driver, Fi->table, marker->answers[i]) != DB_C_TYPE_STRING)
+ G_fatal_error(_("Data type of marker column must be character"));
+ }
+ }
+
+ return Fi->number;
+}
More information about the grass-commit
mailing list