[GRASS-dev] Re: [GRASS-user] [bug #3041] nviz max resolution ppm image dump

Hi Hamish,

I suspect there are a few bugs with some of the math in this. The best
place to start looking is Nstart_zoom_cmd in do_zoom.c (nviz/src). The
off-screen stuff was generating the MALLOC error for me this morning.
After the off-screen buffer was created the maxx and maxy returned were
incorrect which resulted in negative numbers being passed to malloc
which of course produced an error. I disabled the off-screen stuff and
it worked fine.

To debug this I would first start by disabling the off-screen stuff in
Nstart_zoom and draw the images directly. Also, check the dimensions
that are being calculated and passed to GS_write_zoom.

Hope this helps.

--
Bob

On Tue, 2006-08-29 at 18:06 +1200, Hamish wrote:

William Hargrove wrote:
> >>My nviz dies with a segfault when I try to dump an image as maximum
> >>resolution ppm.
> >>
> >>I have this same problem with grass 6.1 under FC 5, and under grass
> >>5.4 under FC 4.
..
> >>I can dump the other formats just fine.
> >>
> >>The map products look great on the screen, but aren't much use if I
> >>can't get them into a high-res image file.
> >>
> >>Does anyone have any advice on this problem?

Hamish wrote:
> >what's the date on the 6.1? 6.1.0 or 6.1-cvs? This was an old known
> >problem on 64bit &/or big endian (Mac G5), I had thought that it was
> >fixed by Glynn & crew some months ago.

I guess it is this bug after all:

> > http://intevation.de/rt/webrt?serial_num=3041

William Hargrove wrote:
> This is 6.1.0 built from source, running under 64-bit FC 5.
>
> Here is what happens when I try to dump a max-res ppm:
>
> recalculating normals...
> recalculating normals...
> Diagnostic: invalid command name "Nviz_animation_save" -- Save
> procedure for panel animation may not be defined
> Diagnostic: invalid command name "Nviz_kanimator_save" -- Save
> procedure for panel kanimator may not be defined
> Diagnostic: invalid command name "Nviz_query_save" -- Save procedure
> for panel query may not be defined
> Diagnostic: invalid command name "Nviz_sdiff_save" -- Save procedure
> for panel sdiff may not be defined
> Diagnostic: invalid command name "Nviz_label_save" -- Save procedure
> for panel label may not be defined
> Diagnostic: invalid command name "Nviz_scale_save" -- Save procedure
> for panel scale may not be defined
> Diagnostic: invalid command name "Nviz_pos_save" -- Save procedure
> for panel pos may not be defined
> Diagnostic: invalid command name "Nviz_resize_save" -- Save procedure
>
> for panel resize may not be defined
> Diagnostic: invalid command name "Nviz_pick_save" -- Save procedure
> for panel pick may not be defined
> Diagnostic: invalid command name "Nviz_highlight_save" -- Save
> procedure for panel highlight may not be defined
> Creating PBuffer Using GLX 1.3
> Final Assembled Image will be 1 x 1
> Writing Tile 1 of 1
> Assembling Tiles
> GLX -- destroy pbuffer
> ./donviz: line 2: 10088 Segmentation fault nviz
> elevation=elev48.new color=neon2.25
> vector=states100,neondomains_states
>
> Any ideas?

I get a segfault too: (32bit P4, 2gig RAM, Debian/stable)

Speafish with nviz window made to be large:

G63> nviz elevation.10m
Loading Data
Update elev null mask
Loading Data
translating colors from fp
recalculating normals...
r200_makeX86Normal3fv/197 CVAL 0 OFFSET 14 VAL 8260df0
r200_makeX86Normal3fv/198 CVAL 4 OFFSET 20 VAL 8260df4
r200_makeX86Normal3fv/199 CVAL 8 OFFSET 25 VAL 8260df8
r200_makeX86Normal3fv done
% recalculating normals...
Creating PBuffer Using GLX 1.3
Create PixMap Using GLX 1.1
Final Assembled Image will be 1935 x 2048
Writing Tile 1 of 9
Writing Tile 2 of 9
Writing Tile 3 of 9
MALLOC Failed
Segmentation fault

(hard to replicate)

The "MALLOC Failed" message comes from lib/ogsf/gsd_prim.c

/************************************************************************/
int gsd_writeView(unsigned char **pixbuf, unsigned int xsize,
                  unsigned int ysize)
{

    /* Malloc Buffer for image */
    *pixbuf = malloc(xsize * ysize * 4);

    if (!*pixbuf) {
        fprintf(stderr, "MALLOC Failed\n");
        return (0);
    }

    /* Read image buffer */
    glReadBuffer(GL_FRONT);

    /* Read Pixels into Buffer */
    glReadPixels(0, 0, xsize, ysize, GL_RGBA, GL_UNSIGNED_BYTE, *pixbuf);
    return (1);
}

/************************************************************************/

with window left at starting size: [note larger "Final Assembled Size"]

G63> nviz elevation.10m
Loading Data
Update elev null mask
Loading Data
translating colors from fp
recalculating normals...
r200_makeX86Normal3fv/197 CVAL 0 OFFSET 14 VAL 82613f8
r200_makeX86Normal3fv/198 CVAL 4 OFFSET 20 VAL 82613fc
r200_makeX86Normal3fv/199 CVAL 8 OFFSET 25 VAL 8261400
r200_makeX86Normal3fv done
% Creating PBuffer Using GLX 1.3
Create PixMap Using GLX 1.1
Final Assembled Image will be 2048 x 2048
Writing Tile 1 of 9
Writing Tile 2 of 9
Writing Tile 3 of 9
Writing Tile 4 of 9
Writing Tile 5 of 9
Writing Tile 6 of 9
Writing Tile 7 of 9
Writing Tile 8 of 9
Writing Tile 9 of 9
Assembling Tiles
pnmcat: Zero byte allocation
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set
pnmcat: Zero byte allocation
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set
pnmcat: Zero byte allocation
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set
pnmcat: EOF / read error reading magic number
pnmcat failed to create assembled images
Check that pnmcat is installed and path is set
Destroy Pixmap and GLXPixmap

no segfault, NVIZ keeps running, these files are left behind:
(easy to replicate)

      0 Aug 29 17:24 spearNVhi2.ppm
3145745 Aug 29 17:24 spearNVhi2_1_1.ppm
3145745 Aug 29 17:24 spearNVhi2_1_2.ppm
     14 Aug 29 17:24 spearNVhi2_1_3.ppm
3145745 Aug 29 17:24 spearNVhi2_2_1.ppm
3145745 Aug 29 17:24 spearNVhi2_2_2.ppm
     14 Aug 29 17:24 spearNVhi2_2_3.ppm
     14 Aug 29 17:24 spearNVhi2_3_1.ppm
     14 Aug 29 17:24 spearNVhi2_3_2.ppm
     11 Aug 29 17:24 spearNVhi2_3_3.ppm
      0 Aug 29 17:24 spearNVhi2tmp1.ppm
      0 Aug 29 17:24 spearNVhi2tmp2.ppm
      0 Aug 29 17:24 spearNVhi2tmp3.ppm
      0 Aug 29 17:30 spearNVhi3.ppm.ppm

assembly of rows then full image fail as partials are not valid images
(14 byte ones). Images with data assemble, but contain random x-window
buffer weirdness: multi-virtual-desktop collages.

Summary: the partial tiles are broken.

I haven't tried it with just one workspace.

minimizing the NVIZ window (before clicking "ok" for the output
filename) gives the same result.

at the end of the bug report Glynn offers a reason, but I have no idea
where to go from there. Dumb debugging effort: I still get the broken
result if I comment out "Nset_cancel_func update" in
  visualization/nviz/scripts/nviz2.2_script
and rebuild nviz.

?
Hamish

Just to confuse the issue somewhat, the max resolution PPM dump almost works
on my Mac (18 August build). As you can see below, it is failing because I
apparently do not have an external command - pnmcat.

Is this required for nviz and grass? Is it supposed to be a dependency? Or
is it just assumed to be present on systems

Here is what I get...

Writing Tile 1 of 16
Writing Tile 2 of 16
Writing Tile 3 of 16
Writing Tile 4 of 16
Writing Tile 5 of 16
Writing Tile 6 of 16
Writing Tile 7 of 16
Writing Tile 8 of 16
Writing Tile 9 of 16
Writing Tile 10 of 16
Writing Tile 11 of 16
Writing Tile 12 of 16
Writing Tile 13 of 16
Writing Tile 14 of 16
Writing Tile 15 of 16
Writing Tile 16 of 16
Assembling Tiles
sh: line 1: pnmcat: command not found
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set
sh: line 1: pnmcat: command not found
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set
sh: line 1: pnmcat: command not found
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set
sh: line 1: pnmcat: command not found
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set
sh: line 1: pnmcat: command not found
pnmcat failed to create assembled images
Check that pnmcat is installed and path is set

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Bob Covill <bcovill@tekmap.ns.ca>
Date: Tue, 29 Aug 2006 08:57:37 -0300
To: Hamish <hamish_nospam@yahoo.com>
Cc: GRASS developers list <grass-dev@grass.itc.it>
Subject: [GRASS-dev] Re: [GRASS-user] [bug #3041] nviz max resolution ppm
image dump

Hi Hamish,

I suspect there are a few bugs with some of the math in this. The best
place to start looking is Nstart_zoom_cmd in do_zoom.c (nviz/src). The
off-screen stuff was generating the MALLOC error for me this morning.
After the off-screen buffer was created the maxx and maxy returned were
incorrect which resulted in negative numbers being passed to malloc
which of course produced an error. I disabled the off-screen stuff and
it worked fine.

To debug this I would first start by disabling the off-screen stuff in
Nstart_zoom and draw the images directly. Also, check the dimensions
that are being calculated and passed to GS_write_zoom.

Hope this helps.

--
Bob

On Tue, 2006-08-29 at 18:06 +1200, Hamish wrote:

William Hargrove wrote:

My nviz dies with a segfault when I try to dump an image as maximum
resolution ppm.

I have this same problem with grass 6.1 under FC 5, and under grass
5.4 under FC 4.

..

I can dump the other formats just fine.

The map products look great on the screen, but aren't much use if I
can't get them into a high-res image file.

Does anyone have any advice on this problem?

Hamish wrote:

what's the date on the 6.1? 6.1.0 or 6.1-cvs? This was an old known
problem on 64bit &/or big endian (Mac G5), I had thought that it was
fixed by Glynn & crew some months ago.

I guess it is this bug after all:

http://intevation.de/rt/webrt?serial_num=3041

William Hargrove wrote:

This is 6.1.0 built from source, running under 64-bit FC 5.

Here is what happens when I try to dump a max-res ppm:

recalculating normals...
recalculating normals...
Diagnostic: invalid command name "Nviz_animation_save" -- Save
procedure for panel animation may not be defined
Diagnostic: invalid command name "Nviz_kanimator_save" -- Save
procedure for panel kanimator may not be defined
Diagnostic: invalid command name "Nviz_query_save" -- Save procedure
for panel query may not be defined
Diagnostic: invalid command name "Nviz_sdiff_save" -- Save procedure
for panel sdiff may not be defined
Diagnostic: invalid command name "Nviz_label_save" -- Save procedure
for panel label may not be defined
Diagnostic: invalid command name "Nviz_scale_save" -- Save procedure
for panel scale may not be defined
Diagnostic: invalid command name "Nviz_pos_save" -- Save procedure
for panel pos may not be defined
Diagnostic: invalid command name "Nviz_resize_save" -- Save procedure

for panel resize may not be defined
Diagnostic: invalid command name "Nviz_pick_save" -- Save procedure
for panel pick may not be defined
Diagnostic: invalid command name "Nviz_highlight_save" -- Save
procedure for panel highlight may not be defined
Creating PBuffer Using GLX 1.3
Final Assembled Image will be 1 x 1
Writing Tile 1 of 1
Assembling Tiles
GLX -- destroy pbuffer
./donviz: line 2: 10088 Segmentation fault nviz
elevation=elev48.new color=neon2.25
vector=states100,neondomains_states

Any ideas?

I get a segfault too: (32bit P4, 2gig RAM, Debian/stable)

Speafish with nviz window made to be large:

G63> nviz elevation.10m
Loading Data
Update elev null mask
Loading Data
translating colors from fp
recalculating normals...
r200_makeX86Normal3fv/197 CVAL 0 OFFSET 14 VAL 8260df0
r200_makeX86Normal3fv/198 CVAL 4 OFFSET 20 VAL 8260df4
r200_makeX86Normal3fv/199 CVAL 8 OFFSET 25 VAL 8260df8
r200_makeX86Normal3fv done
% recalculating normals...
Creating PBuffer Using GLX 1.3
Create PixMap Using GLX 1.1
Final Assembled Image will be 1935 x 2048
Writing Tile 1 of 9
Writing Tile 2 of 9
Writing Tile 3 of 9
MALLOC Failed
Segmentation fault

(hard to replicate)

The "MALLOC Failed" message comes from lib/ogsf/gsd_prim.c

/************************************************************************/
int gsd_writeView(unsigned char **pixbuf, unsigned int xsize,
                  unsigned int ysize)
{

    /* Malloc Buffer for image */
    *pixbuf = malloc(xsize * ysize * 4);

    if (!*pixbuf) {
        fprintf(stderr, "MALLOC Failed\n");
        return (0);
    }

    /* Read image buffer */
    glReadBuffer(GL_FRONT);

    /* Read Pixels into Buffer */
    glReadPixels(0, 0, xsize, ysize, GL_RGBA, GL_UNSIGNED_BYTE, *pixbuf);
    return (1);
}

/************************************************************************/

with window left at starting size: [note larger "Final Assembled Size"]

G63> nviz elevation.10m
Loading Data
Update elev null mask
Loading Data
translating colors from fp
recalculating normals...
r200_makeX86Normal3fv/197 CVAL 0 OFFSET 14 VAL 82613f8
r200_makeX86Normal3fv/198 CVAL 4 OFFSET 20 VAL 82613fc
r200_makeX86Normal3fv/199 CVAL 8 OFFSET 25 VAL 8261400
r200_makeX86Normal3fv done
% Creating PBuffer Using GLX 1.3
Create PixMap Using GLX 1.1
Final Assembled Image will be 2048 x 2048
Writing Tile 1 of 9
Writing Tile 2 of 9
Writing Tile 3 of 9
Writing Tile 4 of 9
Writing Tile 5 of 9
Writing Tile 6 of 9
Writing Tile 7 of 9
Writing Tile 8 of 9
Writing Tile 9 of 9
Assembling Tiles
pnmcat: Zero byte allocation
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set
pnmcat: Zero byte allocation
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set
pnmcat: Zero byte allocation
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set
pnmcat: EOF / read error reading magic number
pnmcat failed to create assembled images
Check that pnmcat is installed and path is set
Destroy Pixmap and GLXPixmap

no segfault, NVIZ keeps running, these files are left behind:
(easy to replicate)

      0 Aug 29 17:24 spearNVhi2.ppm
3145745 Aug 29 17:24 spearNVhi2_1_1.ppm
3145745 Aug 29 17:24 spearNVhi2_1_2.ppm
     14 Aug 29 17:24 spearNVhi2_1_3.ppm
3145745 Aug 29 17:24 spearNVhi2_2_1.ppm
3145745 Aug 29 17:24 spearNVhi2_2_2.ppm
     14 Aug 29 17:24 spearNVhi2_2_3.ppm
     14 Aug 29 17:24 spearNVhi2_3_1.ppm
     14 Aug 29 17:24 spearNVhi2_3_2.ppm
     11 Aug 29 17:24 spearNVhi2_3_3.ppm
      0 Aug 29 17:24 spearNVhi2tmp1.ppm
      0 Aug 29 17:24 spearNVhi2tmp2.ppm
      0 Aug 29 17:24 spearNVhi2tmp3.ppm
      0 Aug 29 17:30 spearNVhi3.ppm.ppm

assembly of rows then full image fail as partials are not valid images
(14 byte ones). Images with data assemble, but contain random x-window
buffer weirdness: multi-virtual-desktop collages.

Summary: the partial tiles are broken.

I haven't tried it with just one workspace.

minimizing the NVIZ window (before clicking "ok" for the output
filename) gives the same result.

at the end of the bug report Glynn offers a reason, but I have no idea
where to go from there. Dumb debugging effort: I still get the broken
result if I comment out "Nset_cancel_func update" in
  visualization/nviz/scripts/nviz2.2_script
and rebuild nviz.

?
Hamish

Michael Barton wrote:

Just to confuse the issue somewhat, the max resolution PPM dump almost
works on my Mac (18 August build). As you can see below, it is failing
because I apparently do not have an external command - pnmcat.

Is this required for nviz and grass? Is it supposed to be a
dependency? Or is it just assumed to be present on systems

pnmcat is a standard Netpbm tool (like those used in d.out.file).

Here is what I get...

Writing Tile 1 of 16

..

Writing Tile 16 of 16
Assembling Tiles
sh: line 1: pnmcat: command not found
pnmcat failed to create assembled image
Check that pnmcat is installed and path is set

Check if you have it: from the grass terminal prompt
  which pnmcat
or just try running it with no options and see if you get a response.

I'd be surprised if it wasn't installed, they're pretty standard & I'm
pretty sure they've been on every Mac system I've looked at.

d.out.gpsdrive also needs netpbm (but doesn't test for it), d.out.file
uses gdal_translate.

Hamish

At least I don't have it on my PB G4, running 10.4.7 and developer's tools.
That is, no response from the terminal, xterminal, or GRASS prompt. I
haven't tried to compile on this (at least not in several years).

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Hamish <hamish_nospam@yahoo.com>
Date: Wed, 30 Aug 2006 11:41:59 +1200
To: Michael Barton <michael.barton@asu.edu>
Cc: <grass-dev@grass.itc.it>
Subject: Re: [GRASS-dev] Re: [GRASS-user] [bug #3041] nviz max resolution ppm
image dump

Check if you have it: from the grass terminal prompt
  which pnmcat
or just try running it with no options and see if you get a response.

I'd be surprised if it wasn't installed, they're pretty standard & I'm
pretty sure they've been on every Mac system I've looked at.

adding in some more debug statements: [Before|After row x col]

Writing Tile 2 of 9
D0/0: Nstart_zoom_cmd(): [B1x3] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x3] maxx=2048 XX=-2048 maxy=2048 YY=0 c=1024
  /* Re-set image width or height if required */
D0/0: Nstart_zoom_cmd(): [A1x3] img_width=0 img_height=1024

!! XX=-2048

      if ((maxx + XX) < c)
    img_width = maxx + XX;
      if ((maxy + YY) < d)
    img_height = maxy + YY;

XX,YY start as:

/* Set X & Y to zero for lower left corner */
    XX = YY = 0;

then in the for loops:

      XX -= c;
      cnt++;
   } /* Done col */
  /* Reset XX and img_width */
  XX = 0;
  img_width = c;
  YY -= d;
    } /* done row */

Final Assembled Image will be 2048 x 2048
D0/0: Nstart_zoom_cmd(): XX=0 YY=0
D0/0: gsd_viewport(): l=0,b=0,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=0 YY=0
D0/0: Nstart_zoom_cmd(): [B1x1] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x1] maxx=2048 XX=0 maxy=2048 YY=0 c=1024
D0/0: Nstart_zoom_cmd(): [A1x1] img_width=1024 img_height=1024
Writing Tile 1 of 9
D0/0: Nstart_zoom_cmd(): XX=-1024 YY=0
D0/0: gsd_viewport(): l=-1024,b=0,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=-1024 YY=0
D0/0: Nstart_zoom_cmd(): [B1x2] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x2] maxx=2048 XX=-1024 maxy=2048 YY=0 c=1024
D0/0: Nstart_zoom_cmd(): [A1x2] img_width=1024 img_height=1024
Writing Tile 2 of 9
D0/0: Nstart_zoom_cmd(): XX=-2048 YY=0
D0/0: gsd_viewport(): l=-2048,b=0,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=-2048 YY=0
D0/0: Nstart_zoom_cmd(): [B1x3] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x3] maxx=2048 XX=-2048 maxy=2048 YY=0 c=1024
D0/0: Nstart_zoom_cmd(): [A1x3] img_width=0 img_height=1024
Writing Tile 3 of 9
D0/0: Nstart_zoom_cmd(): XX=0 YY=-1024
D0/0: gsd_viewport(): l=0,b=-1024,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=0 YY=-1024
D0/0: Nstart_zoom_cmd(): [B2x1] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B2x1] maxx=2048 XX=0 maxy=2048 YY=-1024 c=1024
D0/0: Nstart_zoom_cmd(): [A2x1] img_width=1024 img_height=1024
Writing Tile 4 of 9
...

if I change the XX and YY -= to += (just a guess) I don't get any errors
and it creates a single test.ppm which is 3072x3072, but the contents
are still bogus.

Hamish

Hamish,

Are any of the image tiles coming out correctly? If not than the fault
(in your case) may be with GS_write_zoom. Is your computer using a 64
bit processor?

If the problem is not the above, have you tried adjusting the nviz
screen aspect slightly? This may correct any math errors that are being
passed to the output images, such as 0 pixels wide.

I had a version of this from a while back where I moved all of the
pnmcat stuff to the TCL side of nviz. This would get rid of the system
commands in do_zoom.c and allow easier control in the script. For
example you could check to see if pnmcat is installed, and if not pop-up
a message box.

--
Bob

On Wed, 2006-08-30 at 17:14 +1200, Hamish wrote:

adding in some more debug statements: [Before|After row x col]

Writing Tile 2 of 9
D0/0: Nstart_zoom_cmd(): [B1x3] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x3] maxx=2048 XX=-2048 maxy=2048 YY=0 c=1024
  /* Re-set image width or height if required */
D0/0: Nstart_zoom_cmd(): [A1x3] img_width=0 img_height=1024

!! XX=-2048

      if ((maxx + XX) < c)
    img_width = maxx + XX;
      if ((maxy + YY) < d)
    img_height = maxy + YY;

XX,YY start as:

/* Set X & Y to zero for lower left corner */
    XX = YY = 0;

then in the for loops:

      XX -= c;
      cnt++;
   } /* Done col */
  /* Reset XX and img_width */
  XX = 0;
  img_width = c;
  YY -= d;
    } /* done row */

Final Assembled Image will be 2048 x 2048
D0/0: Nstart_zoom_cmd(): XX=0 YY=0
D0/0: gsd_viewport(): l=0,b=0,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=0 YY=0
D0/0: Nstart_zoom_cmd(): [B1x1] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x1] maxx=2048 XX=0 maxy=2048 YY=0 c=1024
D0/0: Nstart_zoom_cmd(): [A1x1] img_width=1024 img_height=1024
Writing Tile 1 of 9
D0/0: Nstart_zoom_cmd(): XX=-1024 YY=0
D0/0: gsd_viewport(): l=-1024,b=0,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=-1024 YY=0
D0/0: Nstart_zoom_cmd(): [B1x2] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x2] maxx=2048 XX=-1024 maxy=2048 YY=0 c=1024
D0/0: Nstart_zoom_cmd(): [A1x2] img_width=1024 img_height=1024
Writing Tile 2 of 9
D0/0: Nstart_zoom_cmd(): XX=-2048 YY=0
D0/0: gsd_viewport(): l=-2048,b=0,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=-2048 YY=0
D0/0: Nstart_zoom_cmd(): [B1x3] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x3] maxx=2048 XX=-2048 maxy=2048 YY=0 c=1024
D0/0: Nstart_zoom_cmd(): [A1x3] img_width=0 img_height=1024
Writing Tile 3 of 9
D0/0: Nstart_zoom_cmd(): XX=0 YY=-1024
D0/0: gsd_viewport(): l=0,b=-1024,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=0 YY=-1024
D0/0: Nstart_zoom_cmd(): [B2x1] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B2x1] maxx=2048 XX=0 maxy=2048 YY=-1024 c=1024
D0/0: Nstart_zoom_cmd(): [A2x1] img_width=1024 img_height=1024
Writing Tile 4 of 9
...

if I change the XX and YY -= to += (just a guess) I don't get any errors
and it creates a single test.ppm which is 3072x3072, but the contents
are still bogus.

Hamish

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

Hamish wrote:

adding in some more debug statements: [Before|After row x col]

Writing Tile 2 of 9
D0/0: Nstart_zoom_cmd(): [B1x3] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x3] maxx=2048 XX=-2048 maxy=2048 YY=0 c=1024
  /* Re-set image width or height if required */
D0/0: Nstart_zoom_cmd(): [A1x3] img_width=0 img_height=1024

!! XX=-2048

      if ((maxx + XX) < c)
    img_width = maxx + XX;
      if ((maxy + YY) < d)
    img_height = maxy + YY;

XX,YY start as:

/* Set X & Y to zero for lower left corner */
    XX = YY = 0;

then in the for loops:

      XX -= c;
      cnt++;
   } /* Done col */
  /* Reset XX and img_width */
  XX = 0;
  img_width = c;
  YY -= d;
    } /* done row */

Final Assembled Image will be 2048 x 2048
D0/0: Nstart_zoom_cmd(): XX=0 YY=0
D0/0: gsd_viewport(): l=0,b=0,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=0 YY=0
D0/0: Nstart_zoom_cmd(): [B1x1] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x1] maxx=2048 XX=0 maxy=2048 YY=0 c=1024
D0/0: Nstart_zoom_cmd(): [A1x1] img_width=1024 img_height=1024
Writing Tile 1 of 9
D0/0: Nstart_zoom_cmd(): XX=-1024 YY=0
D0/0: gsd_viewport(): l=-1024,b=0,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=-1024 YY=0
D0/0: Nstart_zoom_cmd(): [B1x2] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x2] maxx=2048 XX=-1024 maxy=2048 YY=0 c=1024
D0/0: Nstart_zoom_cmd(): [A1x2] img_width=1024 img_height=1024
Writing Tile 2 of 9
D0/0: Nstart_zoom_cmd(): XX=-2048 YY=0
D0/0: gsd_viewport(): l=-2048,b=0,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=-2048 YY=0
D0/0: Nstart_zoom_cmd(): [B1x3] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B1x3] maxx=2048 XX=-2048 maxy=2048 YY=0 c=1024
D0/0: Nstart_zoom_cmd(): [A1x3] img_width=0 img_height=1024
Writing Tile 3 of 9
D0/0: Nstart_zoom_cmd(): XX=0 YY=-1024
D0/0: gsd_viewport(): l=0,b=-1024,r=2048,t=2048
D0/0: Nstart_zoom_cmd(): XX=0 YY=-1024
D0/0: Nstart_zoom_cmd(): [B2x1] img_width=1024 img_height=1024
D0/0: Nstart_zoom_cmd(): [B2x1] maxx=2048 XX=0 maxy=2048 YY=-1024 c=1024
D0/0: Nstart_zoom_cmd(): [A2x1] img_width=1024 img_height=1024
Writing Tile 4 of 9
...

if I change the XX and YY -= to += (just a guess) I don't get any errors
and it creates a single test.ppm which is 3072x3072, but the contents
are still bogus.

The values are meant to be negative; they are shifts which are applied
to the view transformation. The view is shifted down and left so that
the desired tile has its bottom-left at the bottom-left of the drawing
surface.

The problem appears to be that it computes the number of tiles as:

      var_i = (int) (maxx/(c-a)) + 1;

when it should probably be:

      var_i = (int) ((maxx + c-a - 1)/(c-a));

I.e. it rounds down then adds 1 rather than rounding up, resulting in
one too many tiles when the total size is an exact multiple of the
window size.

Note that the technique used (setting a viewport larger than the
window) is an ugly hack which may be very inefficient (the OpenGL
implementation may clip 3D operations to the viewport rather than the
visible portion of it).

However, this is due to a limitation of the OGSF library: the only
mechanism for setting a perspective projection uses gluPerspective(),
which doesn't allow an oblique projection.

--
Glynn Clements <glynn@gclements.plus.com>

Bob Covill wrote:

Are any of the image tiles coming out correctly?

No.

If not than the fault (in your case) may be with GS_write_zoom.

?

William Hargrove wrote:

The 6.1.0 version of nviz dumps high res ppms perfectly after I
comment out the off-screen section.

same here (it works!), GRASS 6.3-cvs:
[do_zoom.c]
/* create off-screen context if possible */
//#if defined(OPENGL_X11) && (defined(HAVE_PBUFFERS) ||
defined(HAVE_PIXMAPS))
#if 0

Bob:

Is your computer using a 64 bit processor?

No. Plain old Pentium 4 32 bit.

Bob:

If the problem is not the above, have you tried adjusting the nviz
screen aspect slightly? This may correct any math errors that are
being passed to the output images, such as 0 pixels wide.

I tried this, same error. All corner partial panels are broken.

Bob:

I had a version of this from a while back where I moved all of the
pnmcat stuff to the TCL side of nviz. This would get rid of the system
commands in do_zoom.c and allow easier control in the script. For
example you could check to see if pnmcat is installed, and if not
pop-up a message box.

I had thought all versions of Mac came with netpbm, apparently not.
So I guess it's a problem.

Glynn Clements wrote:

The problem appears to be that it computes the number of tiles as:

      var_i = (int) (maxx/(c-a)) + 1;

when it should probably be:

      var_i = (int) ((maxx + c-a - 1)/(c-a));

I.e. it rounds down then adds 1 rather than rounding up, resulting in
one too many tiles when the total size is an exact multiple of the
window size.

That may be correct, and by adding that change for x and y,

- var_i = (int) (maxx/(c-a)) + 1;
+ var_i = (int) ((maxx + c-a - 1)/(c-a));

- var_i = (int)(maxy/(d-b)) + 1;
+ var_i = (int) ((maxy + d-b - 1)/(d-b));

I get a constucted image, but it is still full of random bits of
yesterday's X. (GLX is enabled; GRASS_GLX* is not set)

With off-screen rendering disabled, I get good results with either of
the above var_i calculations.

Hamish

Hamish wrote:

> Are any of the image tiles coming out correctly?

No.

> If not than the fault (in your case) may be with GS_write_zoom.

?

I get a constucted image, but it is still full of random bits of
yesterday's X. (GLX is enabled; GRASS_GLX* is not set)

With off-screen rendering disabled, I get good results with either of
the above var_i calculations.

The off-screen rendering draws to the back-buffer, GS_write_zoom()
dumps the front buffer. Also, Create_OS_Ctx() hides the Togl canvas
(presumably to prevent expose events from trashing the OpenGL state
during off-screen rendering), so it probably isn't usable for
rendering.

Does this help?

diff -u -r2.6 do_zoom.c
--- visualization/nviz/src/do_zoom.c 9 Jul 2006 08:58:40 -0000 2.6
+++ visualization/nviz/src/do_zoom.c 31 Aug 2006 12:58:16 -0000
@@ -325,6 +325,9 @@
     }
#endif

+ if (!pbuffer && !glxpixmap)
+ return 1;
+
     /* hide togl canvas before init_ctx
      * This prevents bindings from re-initializing
      * togl */

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

> With off-screen rendering disabled, I get good results with either
> of the above var_i calculations.

The off-screen rendering draws to the back-buffer, GS_write_zoom()
dumps the front buffer. Also, Create_OS_Ctx() hides the Togl canvas
(presumably to prevent expose events from trashing the OpenGL state
during off-screen rendering), so it probably isn't usable for
rendering.

Does this help?

diff -u -r2.6 do_zoom.c
--- visualization/nviz/src/do_zoom.c 9 Jul 2006 08:58:40 -0000 2.6
+++ visualization/nviz/src/do_zoom.c 31 Aug 2006 12:58:16 -0000
@@ -325,6 +325,9 @@
     }
#endif

+ if (!pbuffer && !glxpixmap)
+ return 1;
+
     /* hide togl canvas before init_ctx
      * This prevents bindings from re-initializing
      * togl */

Nope. No change.

Does max res PPM dump work for anybody? (ie is it a platform dependent
thing)

Shall we disable offscreen rendering for the 6.2 release branch in case
it doesn't get fixed in time for release?

Hamish

Hamish wrote:

> > With off-screen rendering disabled, I get good results with either
> > of the above var_i calculations.
>
> The off-screen rendering draws to the back-buffer, GS_write_zoom()
> dumps the front buffer. Also, Create_OS_Ctx() hides the Togl canvas
> (presumably to prevent expose events from trashing the OpenGL state
> during off-screen rendering), so it probably isn't usable for
> rendering.
>
> Does this help?
>
> diff -u -r2.6 do_zoom.c
> --- visualization/nviz/src/do_zoom.c 9 Jul 2006 08:58:40 -0000 2.6
> +++ visualization/nviz/src/do_zoom.c 31 Aug 2006 12:58:16 -0000
> @@ -325,6 +325,9 @@
> }
> #endif
>
> + if (!pbuffer && !glxpixmap)
> + return 1;
> +
> /* hide togl canvas before init_ctx
> * This prevents bindings from re-initializing
> * togl */

Nope. No change.

Did you try with GRASS_NO_GLX_{PBUFFERS,PIXMAPS} set?

With those set, and the above patch, Create_OS_Ctx() should
essentially be a no-op.

Does max res PPM dump work for anybody? (ie is it a platform dependent
thing)

Shall we disable offscreen rendering for the 6.2 release branch in case
it doesn't get fixed in time for release?

It should suffice to ensure that it can be disabled at run time.

--
Glynn Clements <glynn@gclements.plus.com>

> > > With off-screen rendering disabled, I get good results with
> > > either of the above var_i calculations.
> >
> > The off-screen rendering draws to the back-buffer, GS_write_zoom()
> > dumps the front buffer. Also, Create_OS_Ctx() hides the Togl
> > canvas (presumably to prevent expose events from trashing the
> > OpenGL state during off-screen rendering), so it probably isn't
> > usable for rendering.
> >
> > Does this help?
> >
> > diff -u -r2.6 do_zoom.c
> > --- visualization/nviz/src/do_zoom.c 9 Jul 2006 08:58:40 -0000 2.6
> > +++ visualization/nviz/src/do_zoom.c 31 Aug 2006 12:58:16 -0000
> > @@ -325,6 +325,9 @@
> > }
> > #endif
> >
> > + if (!pbuffer && !glxpixmap)
> > + return 1;
> > +
> > /* hide togl canvas before init_ctx
> > * This prevents bindings from re-initializing
> > * togl */
>
> Nope. No change.

Did you try with GRASS_NO_GLX_{PBUFFERS,PIXMAPS} set?

With those set, and the above patch, Create_OS_Ctx() should
essentially be a no-op.

I didn't. I have now and it renders correctly; you see each panel being
rendered in the NVIZ window.

i.e. : This works
+ if (!pbuffer && !glxpixmap)
+ return 1;
and
export GRASS_NO_GLX_PIXMAPS=TRUE
export GRASS_NO_GLX_PBUFFERS=TRUE

OR making this test always false makes it work:

/* create off-screen context if possible */
#if defined(OPENGL_X11) && (defined(HAVE_PBUFFERS) || defined(HAVE_PIXMAPS))

it fails with: (random bits of old windows in built panels)
+ if (!pbuffer && !glxpixmap)
+ return 1;
  and
unset GRASS_NO_GLX_PIXMAPS
export GRASS_NO_GLX_PBUFFERS=TRUE

it fails with: (mostly black with some color stripes in built panels)
+ if (!pbuffer && !glxpixmap)
+ return 1;
  and
export GRASS_NO_GLX_PIXMAPS=TRUE
unset GRASS_NO_GLX_PBUFFERS

> Does max res PPM dump work for anybody? (ie is it a platform
> dependent thing)
>
> Shall we disable offscreen rendering for the 6.2 release branch in
> case it doesn't get fixed in time for release?

It should suffice to ensure that it can be disabled at run time.

or by packagers (say if it's broken for all MacOSX)

Hamish

Hamish wrote:

> > > > With off-screen rendering disabled, I get good results with
> > > > either of the above var_i calculations.
> > >
> > > The off-screen rendering draws to the back-buffer, GS_write_zoom()
> > > dumps the front buffer. Also, Create_OS_Ctx() hides the Togl
> > > canvas (presumably to prevent expose events from trashing the
> > > OpenGL state during off-screen rendering), so it probably isn't
> > > usable for rendering.
> > >
> > > Does this help?
> > >
> > > diff -u -r2.6 do_zoom.c
> > > --- visualization/nviz/src/do_zoom.c 9 Jul 2006 08:58:40 -0000 2.6
> > > +++ visualization/nviz/src/do_zoom.c 31 Aug 2006 12:58:16 -0000
> > > @@ -325,6 +325,9 @@
> > > }
> > > #endif
> > >
> > > + if (!pbuffer && !glxpixmap)
> > > + return 1;
> > > +
> > > /* hide togl canvas before init_ctx
> > > * This prevents bindings from re-initializing
> > > * togl */
> >
> > Nope. No change.
>
> Did you try with GRASS_NO_GLX_{PBUFFERS,PIXMAPS} set?
>
> With those set, and the above patch, Create_OS_Ctx() should
> essentially be a no-op.

I didn't. I have now and it renders correctly; you see each panel being
rendered in the NVIZ window.

i.e. : This works
+ if (!pbuffer && !glxpixmap)
+ return 1;
and
export GRASS_NO_GLX_PIXMAPS=TRUE
export GRASS_NO_GLX_PBUFFERS=TRUE

OR making this test always false makes it work:

/* create off-screen context if possible */
#if defined(OPENGL_X11) && (defined(HAVE_PBUFFERS) || defined(HAVE_PIXMAPS))

it fails with: (random bits of old windows in built panels)
+ if (!pbuffer && !glxpixmap)
+ return 1;
  and
unset GRASS_NO_GLX_PIXMAPS
export GRASS_NO_GLX_PBUFFERS=TRUE

it fails with: (mostly black with some color stripes in built panels)
+ if (!pbuffer && !glxpixmap)
+ return 1;
  and
export GRASS_NO_GLX_PIXMAPS=TRUE
unset GRASS_NO_GLX_PBUFFERS

IOW, neither pBuffers nor GLX Pixmaps work. FWIW, they don't work for
me either.

The existing code (minus the patch) doesn't correctly handle the case
where off-screen rendering is requested but both mechanisms fail (or
are disabled by the environment variables).

I'll commit the patch, so that disabling off-screen rendering at
run time works.

I could invert the sense of the tests, so that you have to
specifically request it. However, that essentially guarantees that the
off-screen rendering won't get any significant amount of testing.

> > Does max res PPM dump work for anybody? (ie is it a platform
> > dependent thing)
> >
> > Shall we disable offscreen rendering for the 6.2 release branch in
> > case it doesn't get fixed in time for release?
>
> It should suffice to ensure that it can be disabled at run time.

or by packagers (say if it's broken for all MacOSX)

There's no way of knowing that. Even if you tested it on every
possible software/hardware combination currently available, you don't
know whether it will start working with the next update.

So long as might work for someone, and everyone for whom it doesn't
work can effectively disable it, it should remain.

The only valid reason for using compile-time tests is to prevent
errors which cannot be prevented at run-time, i.e. loading errors due
to the use of functions which may not exist on specific systems.

--
Glynn Clements <glynn@gclements.plus.com>

> > > > > With off-screen rendering disabled, I get good results

..

IOW, neither pBuffers nor GLX Pixmaps work. FWIW, they don't work for
me either.

The NO_GLX_PIXMAPS case comes close (see attached, made up of 36 tiles)
export GRASS_NO_GLX_PIXMAPS=TRUE
unset GRASS_NO_GLX_PBUFFERS

I'll commit the patch, so that disabling off-screen rendering at
run time works.

Ok, tested. now it is possible to get good output if you know those
envi. vars.

I could invert the sense of the tests, so that you have to
specifically request it. However, that essentially guarantees that the
off-screen rendering won't get any significant amount of testing.

For the release branch the default mode could be on-screen but
probably working, and for 6.3-HEAD it could be left with off-screen
rendering enabled & FIXME?

Hamish

(attachments)

no_glx_pixmaps_6x6.png