These are chat archives for glue-viz/glue-vispy-viewers

6th
May 2016
Thomas Robitaille
@astrofrog
May 06 2016 06:59
np.array is a function and np.ndarray is the type for arrays - indeed confusing!
@PennyQ - so all other values give exactly the same answer? or they are all different but more sensible?
Penny Qian
@PennyQ
May 06 2016 14:01
The are all the same, and actually that crazy large number seems the correct ending point. I set the start point as the camera pos as in glue-viz/glue-3d-selection#9 and also a problem listed there :( Can you help check it? Thanks!
Thomas Robitaille
@astrofrog
May 06 2016 15:20
Huh that's weird, will take a look at that PR
Penny Qian
@PennyQ
May 06 2016 15:23
@astrofrog I am thinking how to get the data in the volume visual intersected by the ray line, i tried to get the line function and 6 surface function and then use spicy.optimize.fslove to get the start&end point of the ray line in the Volume, then do the loop from one dim of the vol_data to find those intersected points… but this sounds so trouble… do you have any good ideas?
Thomas Robitaille
@astrofrog
May 06 2016 15:26
@PennyQ - regarding the transformation, I think you should see a different position for each input position - for example if I do:
````
import numpy as np
from vispy import scene, app
from vispy.scene import visuals

canvas = scene.SceneCanvas(keys='interactive', show=True, size=(400,400))
view = canvas.central_widget.add_view()

pos_scatter = np.random.uniform(-0.2, 0.2, size=(100000, 3))

scatter = visuals.Markers()
scatter.set_data(pos_scatter, edge_color=None, face_color=(1, 1, 1, .5), size=5)
view.add(scatter)

view.camera = scene.cameras.TurntableCamera(parent=view.scene,
                                                 distance=2.0, fov=0)

tr = scatter.get_transform(map_from='canvas', map_to='visual')

pos = np.zeros((100, 3))
pos[:,0] = 100
pos[:,1] = 100
pos[:,2] = np.linspace(-10, 10, 100)

trpos = tr.map(pos)
trpos = trpos[:,:3] / trpos[:,3:4]

print(trpos)
I get e.g.
[[ 4330127.66381565 -7500001.51327258  5000001.17159669]
 [ 4242650.35030207 -7348486.36175742  4898991.07058659]
 [ 4155173.03678849 -7196971.21024227  4797980.96957649]
 [ 4067695.72327491 -7045456.05872712  4696970.86856639]
 [ 3980218.40976133 -6893940.90721197  4595960.76755629]
 [ 3892741.09624775 -6742425.75569682  4494950.66654619]
 [ 3805263.78273417 -6590910.60418167  4393940.56553609]
 [ 3717786.46922059 -6439395.45266652  4292930.46452599]
 [ 3630309.15570701 -6287880.30115136  4191920.36351589]
 [ 3542831.84219343 -6136365.14963621  4090910.26250579]
 [ 3455354.52867985 -5984849.99812106  3989900.16149568]
 [ 3367877.21516627 -5833334.84660591  3888890.06048558]
 [ 3280399.90165269 -5681819.69509076  3787879.95947548]
 [ 3192922.58813911 -5530304.54357561  3686869.85846538]
 [ 3105445.27462553 -5378789.39206045  3585859.75745528]
 [ 3017967.96111195 -5227274.2405453   3484849.65644518]
 [ 2930490.64759837 -5075759.08903015  3383839.55543508]
 [ 2843013.33408479 -4924243.937515    3282829.45442498]
 [ 2755536.02057121 -4772728.78599985  3181819.35341488]
 [ 2668058.70705763 -4621213.6344847   3080809.25240478]
...
they are all different
Penny Qian
@PennyQ
May 06 2016 15:28
Hmmm, that’s wired, let me see
Thomas Robitaille
@astrofrog
May 06 2016 15:28
To find the pixels intersected by the ray, the easiest might be to make sure you ray is in pixel coordinates, then you can do a loop over for example the z values and for each z value you can find the x and y from the ray equation, then convert them to integers
so for example say you have a 10x10x10 cube
you can loop over z=0 to 9
and for each one find x and y
then that gives you 10 pixels that the ray goes through
Penny Qian
@PennyQ
May 06 2016 15:31
yes, but how to get the intesected point on one channel? any package can do this without line/surface functions?
Thomas Robitaille
@astrofrog
May 06 2016 15:31
for a ray, if you know z you also know x and y exactly
Penny Qian
@PennyQ
May 06 2016 15:31
oh yeah!
Thomas Robitaille
@astrofrog
May 06 2016 15:31
and you can just round them to find the nearest integer value
Penny Qian
@PennyQ
May 06 2016 15:32
:) I was totally stuck in the math calculations...
ok got it
Thomas Robitaille
@astrofrog
May 06 2016 15:32
ok :)
Penny Qian
@PennyQ
May 06 2016 15:57

@astrofrog here is my output that except the large one (when z=1), others look very similar so I think they don’t really matter?

[  52.48334211   52.50486503  160.08773137]
[  52.48182776   52.50530731  160.08453021]
[  52.48001053   52.50583804  160.08068882]
[  52.47778948   52.50648671  160.07599379]
[  52.47501316   52.50729755  160.070125  ]
[  52.47144362   52.50834006  160.06257942]
[  52.46668422   52.50973007  160.05251864]
[  52.46002107   52.51167608  160.03843355]
[  52.45002634   52.5145951   160.01730591]
[  52.43336846   52.51946013  159.9820932 ]
[  52.4000527    52.52919019  159.91166778]
[  52.30010553   52.55838035  159.70039172]
[-165295.47738349   48343.34379134 -349365.21038923]
[  52.69989496   52.44161951  160.54549751]
[  52.59994742   52.47080977  160.33422068]
[  52.5666316    52.48053985  160.26379513]
[  52.54997369   52.48540489  160.22858236]
[  52.53997895   52.48832391  160.20745471]
[  52.53331579   52.49026993  160.1933696 ]
[  52.52855639   52.49165994  160.18330882]
[  52.52498684   52.49270245  160.17576323]
[  52.52221053   52.49351329  160.16989443]
[  52.51998947   52.49416196  160.1651994 ]

and when I draw those ‘normal’ value point it’s like from a view outside the canvas, but not the camera direction, but anyway, I think setting start point as the camera pos makes more sense :)

Thomas Robitaille
@astrofrog
May 06 2016 16:01
When you say "it’s like from a view outside the canvas", the points are still along the ray, right?
Penny Qian
@PennyQ
May 06 2016 17:14
This message was deleted
without that super large point, there is no line showed in the view with other normal point value
Penny Qian
@PennyQ
May 06 2016 17:19
they might just stand for one starting point, coz the change between is very tiny
Penny Qian
@PennyQ
May 06 2016 19:31

@astrofrog I don’t understand why

>>> data = np.zeros((53, 106, 106))
>>> data[1, 2, 3] = 0.0
>>> data[[2, 3, 4]]
array([[[ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        ...,
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.]],

       [[ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        ...,
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.]],

       [[ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        ...,
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.]]])

:worried:

I got a mask = [[1,2,3], [4,5,6]], and how can I get data[mask] with the two value with the index in mask… thanks!