sciapp / gr

GR framework: a graphics library for visualisation applications
Other
329 stars 54 forks source link

No PNG output for GR 0.37.0 #77

Closed v0dro closed 5 years ago

v0dro commented 5 years ago

I've made a Ruby wrapper for GR 0.37, and while it displays properly to a window, when saving to PNG I get the following error:

➜  gr_wrapper git:(master) ✗ ruby simple_scatter.rb 
0.37.0.post2%                                                                                                                                                                                                      ➜  gr_wrapper git:(master) ✗ l
total 12K
drwxr-xr-x 2 sameer sameer 4.0K Jan 29 11:18 .
drwxr-xr-x 4 sameer sameer 4.0K Jan 26 18:04 ..
-rw-r--r-- 1 sameer sameer    0 Jan 29 11:18 hello.png
-rw-r--r-- 1 sameer sameer  582 Jan 29 11:18 simple_scatter.rb
➜  gr_wrapper git:(master) ✗ feh hello.png 
feh WARNING: hello.png - No Imlib2 loader for that file format
feh: No loadable images specified.
See 'man feh' for detailed usage information

Here's my script:

require_relative '../../lib/grruby.so'

x1 = [-10, 0, 5, 28]
y1 = [1, 2, 3, 4]
x2 = [2, 4, 16]
y2 = [10, 20, -40]

print(Rubyplot::GR.version)
Rubyplot::GR.beginprint("hello.png")
Rubyplot::GR.setviewport(0, 0.5, 0, 0.5)
Rubyplot::GR.setwindow(-100, 100, -100, 100)
Rubyplot::GR.axes(1, 1, -100, -100, 10, 10, 0.01)
Rubyplot::GR.polyline(x1,y1)
Rubyplot::GR.setviewport(0.5, 1, 0.5, 1)
Rubyplot::GR.setwindow(-100, 100, -100, 100)
Rubyplot::GR.axes(1, 1, 0, 0, 10, 10, 0.01)
Rubyplot::GR.polymarker(x2,y2)
Rubyplot::GR.endprint()
jheinen commented 5 years ago

Which GR run-time are you using? Did you build GR from source?

v0dro commented 5 years ago

No. I downloaded the Debian binaries from here: https://gr-framework.org/c.html

v0dro commented 5 years ago

On a side note: what sort of information do you expect me to post with an error?

IngoMeyer441 commented 5 years ago

On a side note: what sort of information do you expect me to post with an error?

In order to reproduce the problem, the following pieces of information are helpful:

Till now we could not reproduce your particular issue. Could you post a list of your installed Debian packages? You get a list of manually installed packages by running:

apt-mark show manual

Maybe we can setup an environment that leads to a break of the PNG output.

IngoMeyer441 commented 5 years ago

Could you try to run a minimal C example? main.c:

#include <gr.h>

int main(void) {
    double x[] = {0.1, 0.9};

    gr_clearws();
    gr_polyline(sizeof(x) / sizeof(x[0]), x, x);
    gr_updatews();

    return 0;
}

Makefile:

GRDIR = /usr/local/gr
INCLUDES = -I$(GRDIR)/include
CFLAGS = -Wall -g $(INCLUDES)
LIBS = -L$(GRDIR)/lib -lGR
LDFLAGS = $(LIBS) -Wl,-rpath,$(GRDIR)/lib

main: main.o
    $(CC) -o $@ $^ $(LDFLAGS)

%.o: %.c
    $(CC) -c $(CFLAGS) $<

clean:
    rm -f main *.o

.PRECIOUS: %.o
.PHONY: clean

You can run

make GRDIR=<path-to-your-gr-directory>
export GKS_WSTYPE=png
export GKS_FONTPATH=<path-to-your-gr-directory>
./main

and should get a gks.png file.

v0dro commented 5 years ago

Sure. Let me try it out and get back to you.

v0dro commented 5 years ago

Ah. The example that you have elaborated works for me. However, when I use beginprint it fails to ouput anything.

Here's the C example I used:

#include <gr.h>

int main(void) {
    double x[] = {0.1, 0.9};

    gr_beginprint("hello.png");
    gr_polyline(sizeof(x) / sizeof(x[0]), x, x);
    gr_endprint();

    return 0;
}

Might there be some issue with beginprint?

v0dro commented 5 years ago

The way the GKS workspaces work is very confusing. Is there any documentation that points to the exact behavior? How can I output a file with a given filename using the workspaces approach?

On a side note, it would be great if the PNG output could be determined via a C API call rather than ENV variables.

jheinen commented 5 years ago

You can always define a file path and an output type from your shell:

export GKS_FILEPATH="<path>"
export GKS_WSTYPE="<type>"

e.g.

export GKS_FILEPATH="hello.png"
export GKS_WSTYPE="png"
IngoMeyer441 commented 5 years ago

The way the GKS workspaces work is very confusing. Is there any documentation that points to the exact behavior? How can I output a file with a given filename using the workspaces approach?

You can find the documentation for workstation types at https://gr-framework.org/workstations.html.

Ah. The example that you have elaborated works for me. However, when I use beginprint it fails to ouput anything.

I tried your example in a fresh Debian stretch Docker container with our latest GR runtime (https://gr-framework.org/downloads/gr-latest-Debian-x86_64.tar.gz). For me, both versions (environment variables and beginprint/endprint) work. Which version of Debian do you use? Maybe our runtime does not work on older or very new Debian branches.

v0dro commented 5 years ago

Here you go:

➜  gr git:(axeslbl-docs)  cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
IngoMeyer441 commented 5 years ago

Ok, currently I have no idea why it does not work for you...

IngoMeyer441 commented 5 years ago

Could you set the GRDIR variable before running your example with beginprint/endprint?

export GRDIR=<path-to-your-gr-directory>

Maybe GR tries to load a plugin of another GR installation or does not find the PNG output plugin at all.

IngoMeyer441 commented 5 years ago

This is a complete test script:

#!/bin/bash

get_gr () {
    local GR_BINARY_URL="https://gr-framework.org/downloads/gr-latest-Debian-x86_64.tar.gz"

    curl -O -L "${GR_BINARY_URL}" && \
    tar -xvf "gr-latest-Debian-x86_64.tar.gz"
}

run_example1 () (
    cat << 'EOF' > Makefile
GRDIR = /usr/local/gr
INCLUDES = -I$(GRDIR)/include
CFLAGS = -Wall -g $(INCLUDES)
LIBS = -L$(GRDIR)/lib -lGR
LDFLAGS = $(LIBS) -Wl,-rpath,$(GRDIR)/lib

test1: test1.o
    $(CC) -o $@ $^ $(LDFLAGS)

%.o: %.c
    $(CC) -c $(CFLAGS) $<

clean:
    rm -f test1 *.o

.PRECIOUS: %.o
.PHONY: clean
EOF

    cat << 'EOF' > test1.c
#include <gr.h>
int main(void) {
    double x[] = {0.1, 0.9};

    gr_clearws();
    gr_polyline(sizeof(x) / sizeof(x[0]), x, x);
    gr_updatews();

    return 0;
}
EOF

export GRDIR="$(pwd)/gr"
export GKS_WSTYPE="png"
export GKS_FILEPATH="test1.png"

make GRDIR="${GRDIR}" && \
./test1 && \
make clean
)

run_example2 () (
    cat << 'EOF' > Makefile
GRDIR = /usr/local/gr
INCLUDES = -I$(GRDIR)/include
CFLAGS = -Wall -g $(INCLUDES)
LIBS = -L$(GRDIR)/lib -lGR
LDFLAGS = $(LIBS) -Wl,-rpath,$(GRDIR)/lib

test2: test2.o
    $(CC) -o $@ $^ $(LDFLAGS)

%.o: %.c
    $(CC) -c $(CFLAGS) $<

clean:
    rm -f test2 *.o

.PRECIOUS: %.o
.PHONY: clean
EOF

    cat << 'EOF' > test2.c
#include <gr.h>
int main(void) {
    double x[] = {0.1, 0.9};

    gr_beginprint("test2.png");
    gr_polyline(sizeof(x) / sizeof(x[0]), x, x);
    gr_endprint();

    return 0;
}
EOF

export GRDIR="$(pwd)/gr"

make GRDIR="${GRDIR}" && \
./test2 && \
make clean
)

main () {
    local GR_TMP_DIR="$(mktemp -d)"

    cd "${GR_TMP_DIR}" && \
    get_gr && \
    run_example1 && \
    run_example2 && \
    if [[ -s "test1.png" ]] && diff -q "test1.png" "test2.png"; then
        echo "Both tests created the same graphics output."
    else
        echo "The tests wrote different graphics files."
    fi

    if [[ -n "${GR_TMP_DIR}" ]]; then
        rm -rf "${GR_TMP_DIR}"
    fi
}

main "$@"

Could you try to run that?

v0dro commented 5 years ago

OK. I'll investigate and get back to you.

v0dro commented 5 years ago

The example you showed worked. I used those settings for my code and it worked too. Thank you very much for your patience.