[GRASS-dev] more NVIZ updates

Hamish hamish_nospam at yahoo.com
Tue Dec 5 04:14:00 EST 2006


Michael Barton wrote:
> I took out the scale panel. It had no functionality at all. It was
> just a set of widgets that didn't do anything. In the docs it is
> listed as not implemented.

note: the nviz docs are notoriously out of date, don't take their word
for it that something is or isn't implemented.

I'm playing around with adapting the north arrow code, but I see in the
code comments that there is a TODO for better scaling. I don't want to 
enable a scale which is known to be incorrect. (see attached patch
[crude, using north arrow Tcl controls to draw it. "Nset_Narrow" C code
will be the same, so reused it (need to migrate to wrapper fn)])

> I also took out the label sites panel. It has some related code, but
> it is not functional. In the docs it is listed as not implemented.
> Looking at the code, it seems to apply to the old sites format. I
> don't know what it would take to make it work with current vector
> formats.

It would be nice to be able to label vector points, I suggest v.label as
an easy method of doing this.

> I kept all other panels, but split some up (e.g., separated labels and
> legend into separate panels). I took out a very few non-functional
> widgets: the clear screen checkbutton on the main panel, the lower
> entry in the fringe panel, and I think one other (can't remember right
> now). None of these had any functional commands attached. I kept in
> the z-coord slider for the cutting planes. It doesn't seem to do
> anything, but it has code attached. Maybe I should have cut it out
> too.
>
> Having an interface with a bunch of controls that do nothing is really
> frustrating. So I tried to avoid this. NVIZ does a lot anyway. Taking
> out the non-functional parts helps people make better use of the parts
> that do work.

ok.

> I also got the auto draw toggle checkbox to actually work in most
> panels.

where's that? ah I see, top right pulldown menu from the main controls




some comments/suggestions:

* "Visualize->Volumes" is confusing as vector volumes can exist too
(watertower, dinosaur)

* make the green text of "DRAW", DRAW CURRENT darker. It's hard to read
against the grey window background. the NSEW placement arrow isn't as
bad, but I'd still make it and the blue text a bit less bright.

* In Vis->Vect points get rid of the empty space when no map is loaded.
when a map is loaded, have the thematic controls toggle down instead of
always there. aka hide the advanced options so not to overwhelm the
user with a 747 cockpit of controls.

* Rast/Vol panels: don't bother with drop down menus for lists of 2 or 3
items (Drawmode, Style, Shading ; Vis type, Shading) You can have all
opts on the main panel + a column title without losing much real estate.
There's plenty of vertical space in those two panels to play with.

* If you go Vis->Vector pts then Vis->Scaled diff, the points panel
doesn't close automatically. Same with a number of other combinations of
panels.

* fringe: fix the positioning of the fringe corners. Setting the Raster
fine resolution to "1" helps a bit. the error depends on that setting.

* default Label text size is very small. Suggest default font size of
17? (16 doesn't exist for me  "Cannot Load Font\nTrying default Font")



thanks for the updats, NVIZ has long lingered in a semi-finished state,
especially the various decorations.


Hamish
-------------- next part --------------
? lib/ogsf/OBJ.i686-pc-linux-gnu
? include/config.h
? include/version.h
? include/winname.h
? include/Make/Grass.make
? include/Make/Platform.make
? visualization/nviz/src/OBJ.i686-pc-linux-gnu
? visualization/nviz/src/map_obj.c.WORKING
Index: visualization/nviz/scripts/panel_arrow.tcl
===================================================================
RCS file: /home/grass/grassrepository/grass6/visualization/nviz/scripts/panel_arrow.tcl,v
retrieving revision 1.3
diff -u -r1.3 panel_arrow.tcl
--- visualization/nviz/scripts/panel_arrow.tcl	28 Nov 2006 18:01:56 -0000	1.3
+++ visualization/nviz/scripts/panel_arrow.tcl	5 Dec 2006 09:03:31 -0000
@@ -43,9 +43,9 @@
 	
     set n_arrow_size 100
 
-    set panel [St_create {window name size priority} $BASE "North arrow" 2 5]
+    set panel [St_create {window name size priority} $BASE "North arrow and Scalebar" 2 5]
     frame $BASE -relief flat -borderwidth 0
-    Nv_mkPanelname $BASE "North Arrow Panel"
+    Nv_mkPanelname $BASE "North Arrow and Scalebar Panel"
 
     # This section contains widgets for placing the north arrow
     set rbase1 [frame $BASE.arrow]
@@ -70,7 +70,8 @@
 
 proc bind_mouse { W } {
 	bind $W <1> {
-		place_narrow %W %x %y 
+#		place_narrow %W %x %y
+		place_scalebar %W %x %y
 		if {$Nauto_draw == 1} {
 			#Nset_cancel 0
 			Ndraw_all
@@ -102,13 +103,33 @@
 
 #remove canvas binding
     bind $W <1> {}
-
 }
 
 
 
+###########################
+proc place_scalebar {W x y} {
 
+global Nv_ n_arrow n_arrow_size
+global n_arrow_x n_arrow_y n_arrow_z
+global Nauto_draw
 
+set y [expr $Nv_(height) - $y]
+
+#Draw Scalebar at selected point
+    set curr [Nget_current surf]
+    if {$curr} {
+        set location [Nset_Narrow $x $y $curr $n_arrow_size]
+        set n_arrow_x [lindex $location 0]
+        set n_arrow_y [lindex $location 1]
+        set n_arrow_z [lindex $location 2]
 
+        Ndraw_ScaleBar $n_arrow_x $n_arrow_y $n_arrow_z $n_arrow_size
+        #set chuckbutton
+#        set n_arrow 1
+    }
 
+#remove canvas binding
+    bind $W <1> {}
+}
 
Index: lib/ogsf/gsd_objs.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/lib/ogsf/gsd_objs.c,v
retrieving revision 2.7
diff -u -r2.7 gsd_objs.c
--- lib/ogsf/gsd_objs.c	5 May 2006 23:28:59 -0000	2.7
+++ lib/ogsf/gsd_objs.c	5 Dec 2006 09:03:32 -0000
@@ -1002,6 +1002,67 @@
     return;
 }
 
+
+/**************************************************************
+ * Function to draw Scalebar takes OpenGL coords and size
+ *  adapted from gsd_north_arrow Hamish Bowman Dec 2006
+ *************************************************************/
+int gsd_scalebar (float *pos2, float len, GLuint fontbase)
+{
+    char *txt;
+    float base[4][3];
+    float Ntop[] = { 0.0, 0.0, 1.0 };
+
+
+    base[0][Z] = base[1][Z] = base[2][Z] = base[3][Z] = pos2[Z];
+
+    base[0][X] = base[3][X] = pos2[X] - len / 16.;
+    base[1][X] = base[2][X] = pos2[X] + len / 16.;
+
+    base[0][Y] = base[1][Y] = pos2[Y] - len / 2.;
+    base[2][Y] = base[3][Y] = pos2[Y] + len / 2.;
+
+
+    /* make sure we are drawing in front buffer */
+    GS_set_draw(GSD_FRONT);
+
+    gsd_pushmatrix();
+    gsd_do_scale(1);
+
+    glNormal3fv(Ntop);
+    gsd_color_func(0x000000);
+
+    gsd_bgnpolygon();
+    glVertex3fv(base[0]);
+    glVertex3fv(base[1]);
+    glVertex3fv(base[2]);
+    glVertex3fv(base[3]);
+    glVertex3fv(base[0]);
+    gsd_endpolygon();
+
+/* draw units */
+/* Need to pick a nice generic font */
+/* TODO -- project text position off bar bottom along azimuth */
+
+    gsd_color_func(0x000000);
+    txt = "n map units";  /* %g? G_format_res()? , len) */
+    /* adjust position of N text */
+    base[0][X] -= gsd_get_txtwidth(txt, 18) - 20.;
+    base[0][Y] -= gsd_get_txtheight(18) - 20. ;
+
+    glRasterPos3fv(base[0]);
+    glListBase(fontbase);
+    glCallLists(strlen(txt), GL_BYTE, (GLubyte *) txt);
+    GS_done_draw();
+
+    gsd_popmatrix();        
+    gsd_flush();
+
+    return (1);
+}
+
+
+
 /* primitives only called after transforms */
 /* center is actually center at base of 8 sided cone */
 void primitive_cone(unsigned long col)
Index: include/ogsf_proto.h
===================================================================
RCS file: /home/grass/grassrepository/grass6/include/ogsf_proto.h,v
retrieving revision 1.5
diff -u -r1.5 ogsf_proto.h
--- include/ogsf_proto.h	21 Nov 2006 00:13:30 -0000	1.5
+++ include/ogsf_proto.h	5 Dec 2006 09:03:32 -0000
@@ -495,6 +495,7 @@
 int gsd_arrow(float *, unsigned long, float, float *, float, geosurf *);
 int gsd_arrow_onsurf(float *, float *, unsigned long, int, geosurf *);
 void gsd_3darrow(float *, unsigned long, float, float, float *, float);
+int gsd_scalebar (float *, float, GLuint);
 void primitive_cone(unsigned long);
 void primitive_cylinder(unsigned long, int);
 
Index: visualization/nviz/src/draw.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/visualization/nviz/src/draw.c,v
retrieving revision 1.10
diff -u -r1.10 draw.c
--- visualization/nviz/src/draw.c	20 Nov 2006 18:54:44 -0000	1.10
+++ visualization/nviz/src/draw.c	5 Dec 2006 09:03:33 -0000
@@ -274,6 +274,38 @@
 
     return (TCL_OK);
 }
+
+
+
+
+/*****************************************************
+ * Ndraw_ScaleBar
+ * Draws the Scalebar. Adaped from Ndraw_Narrow_cmd()
+ *****************************************************/
+int Ndraw_ScaleBar_cmd(Nv_data * data, Tcl_Interp * interp, /* Current interpreter. */
+                     int argc,     /* Number of arguments. */
+                     char **argv   /* Argument strings. */
+    )
+{
+    float coords[3];
+    double len;
+
+    if (argc != 5)
+        return (TCL_ERROR);
+    coords[0] = (int) atof(argv[1]); /* X */
+    coords[1] = (int) atof(argv[2]); /* Y */
+    coords[2] = (int) atof(argv[3]); /* Z */
+    len = (atof(argv[4]));
+
+    FontBase = load_font(TOGL_BITMAP_HELVETICA_18);
+    if (FontBase)
+            gsd_scalebar(coords, (float) len, FontBase);
+     else
+            fprintf(stderr, "Unable to load font\n");
+
+    return (TCL_OK);
+}
+
             
 
 int Ndraw_line_on_surf_cmd(Nv_data * data, Tcl_Interp * interp,	/* Current interpreter. */
Index: visualization/nviz/src/init_commands.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/visualization/nviz/src/init_commands.c,v
retrieving revision 1.8
diff -u -r1.8 init_commands.c
--- visualization/nviz/src/init_commands.c	18 Jun 2006 22:05:12 -0000	1.8
+++ visualization/nviz/src/init_commands.c	5 Dec 2006 09:03:33 -0000
@@ -73,6 +73,7 @@
 Ndraw_X_cmd(),
 Nset_Narrow_cmd(),
 Ndraw_Narrow_cmd(),
+Ndraw_ScaleBar_cmd(),
 Ndraw_legend_cmd(),
 Ndraw_fringe_cmd(),
 Nset_viewport_cmd(),
@@ -282,6 +283,7 @@
     Tcl_CreateCommand(interp, "Ndraw_X", (Tcl_CmdProc *)Ndraw_X_cmd, data, NULL);
     Tcl_CreateCommand(interp, "Nset_Narrow", (Tcl_CmdProc *)Nset_Narrow_cmd, data, NULL);
     Tcl_CreateCommand(interp, "Ndraw_Narrow", (Tcl_CmdProc *)Ndraw_Narrow_cmd, data, NULL);
+    Tcl_CreateCommand(interp, "Ndraw_ScaleBar", (Tcl_CmdProc *)Ndraw_ScaleBar_cmd, data, NULL);
     Tcl_CreateCommand(interp, "Ndraw_legend", (Tcl_CmdProc *)Ndraw_legend_cmd, data, NULL);
     Tcl_CreateCommand(interp, "Ndraw_fringe", (Tcl_CmdProc *)Ndraw_fringe_cmd, data, NULL);
     Tcl_CreateCommand(interp, "Nset_viewport", (Tcl_CmdProc *)Nset_viewport_cmd, data, NULL);


More information about the grass-dev mailing list