Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

bug in 2d lines #47

Closed
CarloLucibello opened this issue Dec 14, 2015 · 15 comments
Closed

bug in 2d lines #47

CarloLucibello opened this issue Dec 14, 2015 · 15 comments

Comments

@CarloLucibello
Copy link

I'm trying to plot a graph using GLVisualize, and I was trying to display an edge as a line, that is something like

w, r = glscreen()
@async r()

s = Vec2f0(50)
N = nv(g)
v_pos = Point2f0[Point2f0((N*s[1]*rand(2))...) for i=1:N]
v = visualize(v_pos[1:2], :lines, scale=s)
view(v, method=:orthographic_pixel)

but all I get is a blank window. I'm on next2 branch

The same goes for v = visualize(v_pos[1:3], :lines, scale=s) while for 4 or more the piecewise line is displayed correctly.

PS
I tried to view a LineSegment from GeometryTypes but it didn't worked out

PPS
I've in mind to write something like

function plot(g::SimpleGraph)
    srand(17)
    w, r = glscreen()
    @async r()

    s = Vec2f0(50)
    N = nv(g)
    v_pos = Point2f0[Point2f0((N*s[1]*rand(2))...) for i=1:N]
    v_img = HyperSphere(Point2f0(0), 30f0)
    vis_nodes = visualize((v_img, v_pos), :lines, scale=s)
    view(vis_nodes, method=:orthographic_pixel)

    for e in edges(g)
        epos = [v_pos[src(e)], v_pos[dst(e)]]
        v = visualize(epos, :lines, scale=s)
        view(v, method=:orthographic_pixel)
    end
end

Since I'm new to GLVisualize (and to graphics in general) probably I"m doing it wrong, any suggestion is appreciated

@SimonDanisch
Copy link
Member

Is N very big? Because then the points would be outside the window area...

@CarloLucibello
Copy link
Author

It is small, N=10

Defining this function

function plot(m)
    srand(17)
    w, r = glscreen()
    @async r()
    s = Vec2f0(50)
    N = 10
    v_pos = Point2f0[Point2f0((N*s[1]*rand(2))...) for i=1:N]
    v_img = HyperSphere(Point2f0(0), 30f0)
    vis_nodes = visualize((v_img, v_pos), :lines, scale=s)
    view(vis_nodes, method=:orthographic_pixel)

    # m used here
    v = visualize(v_pos[1:m], :lines, scale=s)

    view(v, method=:orthographic_pixel)
end

I obtain

plot(5)
glvisualize_005

plot(4)
glvisualize_007

plot(3)
glvisualize_008

@SimonDanisch
Copy link
Member

I guess your problem is that the primitives are not centered?
I should have fixed this in a newer commit, if you dare to checkout.
Also, when given a primitive with dimensions, you don't need to supply the scale!
In the newer commit, you can define the centering yourself. With the circle, it's centered at the middle point.

@CarloLucibello
Copy link
Author

Oh yes, that was a problem, but the real problem is that with plot(3) I was expecting to see two segments

@SimonDanisch
Copy link
Member

Ah yeah... That's actually what I wanted to work on today. That's a peculiarity of OpenGL and I want to make a proper work around and fix another issue while at it (being able to add a list of indexes and specifying which points are connected). The only work around you can use right away is, to never have less than 4 points...
There is this annoying temporary fix:

a,b = points 
ab = b-a
points = vcat(a-(ab*0.00001f0),a,b,b+(ab*0.00001f0)) #start and end have to be slightly different

@CarloLucibello
Copy link
Author

ok thanks.

As an alternative, there is a way to visualize types from GeometryTypes.jl, like LineSegment?

@CarloLucibello
Copy link
Author

(being able to add a list of indexes and specifying which points are connected).

that's exactly what I need to visualize a graph

@SimonDanisch
Copy link
Member

Well, that's basically what I will be implementing.

@SimonDanisch
Copy link
Member

Great! I can't promise anything, but I'm working on it ;)

@SimonDanisch
Copy link
Member

Okay I fixed the line endings and made a step forward towards the segments ;) I just need to integrate a few changes into the rest of the infrastructure to make it work for the generic case.

@CarloLucibello
Copy link
Author

nice!

still some sprites' offset after last patches
glvisualize_001

@SimonDanisch
Copy link
Member

uh...have you removed scale=s ?

@CarloLucibello
Copy link
Author

ouch, right, sorry, it works perfectly!

@musm
Copy link
Contributor

musm commented Dec 14, 2015

@SimonDanisch
Any idea why I keep getting this?
julia julia> Pkg.checkout("GeometryTypes", "sd/typealias") INFO: Checking out GeometryTypes sd/typealias... WARNING: Cannot perform fast-forward merge. INFO: Pulling GeometryTypes latest sd/typealias... WARNING: Cannot perform fast-forward merge. INFO: No packages to install, update or remove

@SimonDanisch
Copy link
Member

that's a julia/github issue. Sometimes it helped to first do Pkg.checkout("GeometryTypes", "master").
You can also try doing it manually. Just go into the GeometryTypes folder with your terminal and type:

git checkout sd/typealias

You might need to throw in a:

git reset --hard HEAD

If there have been changes in the sources.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants