Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 16:26
    kmuehlbauer commented #1568
  • Jan 31 2019 16:15
    kmuehlbauer commented #1568
  • Jan 31 2019 15:53
    djhoese commented #1568
  • Jan 31 2019 15:46
    kmuehlbauer edited #1568
  • Jan 31 2019 15:44
    kmuehlbauer opened #1568
  • Jan 31 2019 15:32
    djhoese commented #1566
  • Jan 31 2019 15:30
    djhoese commented #1567
  • Jan 31 2019 14:18
    GuillaumeFavelier commented #1561
  • Jan 31 2019 14:15
    GuillaumeFavelier commented #1561
  • Jan 31 2019 12:46
    opekar synchronize #1130
  • Jan 31 2019 09:54
    kmuehlbauer commented #1567
  • Jan 31 2019 09:53
    kmuehlbauer synchronize #1567
  • Jan 31 2019 09:37
    kmuehlbauer labeled #1567
  • Jan 31 2019 09:37
    kmuehlbauer labeled #1567
  • Jan 31 2019 09:37
    kmuehlbauer labeled #1563
  • Jan 31 2019 09:36
    kmuehlbauer labeled #1563
  • Jan 31 2019 09:28
    kmuehlbauer commented #1567
  • Jan 31 2019 09:27
    kmuehlbauer synchronize #1567
  • Jan 31 2019 09:19
    kmuehlbauer assigned #1563
  • Jan 31 2019 09:17
    kmuehlbauer opened #1567
Kai Mühlbauer
@kmuehlbauer
So the PolarTransform which I've tweaked a bit only works because my arrays consist of 360 deg in theta dimension. If less you get only parts of the circle and if more it gets overplotted. I remember that I didn't find a possibility to somehow normalize sizes/positions.
glsl_imap = """
        vec4 polar_transform_map(vec4 pos) {
            float theta = atan(pos.y, pos.x);
            theta = degrees(theta) + 180;
            float r = length(pos.xy);
            return vec4(theta, r, pos.z, 1);
        }
        """
This gets theta in degrees between (0, 360). The r value is evaluated correct so far I can tell from my output.
Screenshot_20210702_135945.png
Kai Mühlbauer
@kmuehlbauer
Upper left, the image as is. The other four are the four polar representations, when one side is "collapsed" to the center. You see the two left (size=360) it works nicely. On the right side (size=180) only half is displayed. I would need somehow have access to the image_size to normalize it to 360deg but this seems not accessible from the glsl_map function. Any ideas? Otherwise we could advertise this workaround, but a real solution would be better.
Kai Mühlbauer
@kmuehlbauer
Unfortunately I can't get it working without having the the size of dimension over which the image is "collapsed" to the center at 360. Somehow, the PolarTransform needs prior knowledge of the visual (ImageVisual) sizes and orientation to correctly normalize. Maybe we will be happier with a PolarImage? So, if any of you can point me into the right direction, I very much appreciate it.
David Hoese
@djhoese
@kmuehlbauer Can't you use an STTransform like the image_transforms.py example uses? It chains multiple transforms together and I believe the first one (or maybe last one) is to normalize the image size
Kai Mühlbauer
@kmuehlbauer
@djhoese I have a matrix rotation and a sttranslation right before the polar transform (to make the four positions possible. I 'think' the problem is how the image visual maps to texture coords. I'll try to make a simple example
Kai Mühlbauer
@kmuehlbauer
import numpy as np
import vispy.app
from vispy import gloo
from vispy import visuals
from vispy.visuals.transforms import (MatrixTransform, STTransform,
                                      PolarTransform)

class MyPolarTransform(PolarTransform):
    glsl_map = """
            vec4 polar_transform_map(vec4 pos) {
                return vec4(pos.y * cos(pos.x), pos.y * sin(pos.x), pos.z, 1.);
            }
            """
    glsl_imap = """
            vec4 polar_transform_map(vec4 pos) {
                float theta = atan(pos.y, pos.x);
                //theta = theta + 3.14159265358979323846;// + 180;
                theta = degrees(theta) + 180;
                float r = length(pos.xy);
                return vec4(theta, r, pos.z, 1);
           }
            """

class Canvas(vispy.app.Canvas):
    def __init__(self):
        csize = 360 * 3

        vispy.app.Canvas.__init__(self, keys='interactive', size=(csize, csize))

        # Create image
        image = np.ones((360, 360, 3), dtype=np.uint8)
        grad = np.linspace(0, 255, 360, dtype=np.uint8)[None, :, None]
        image *= grad
        image[:, 310:360, :] = 0
        image[5:40] = 255
        image[:, 10:50, :] = 255
        #image = np.swapaxes(image, 0, 1)
        image2 = image


        self.images = [visuals.ImageVisual(image, method='impostor') for i in range(4)]
        self.images2 = [visuals.ImageVisual(image2, method='impostor') for i in range(4)]

        for i, im in enumerate(self.images):
            tx = 0
            ty = 0

            if i == 1:
                tx = self.images[0].size[1]
                xoff = csize / 4 * 3
                yoff = csize / 4
            elif i == 2:
                tx = self.images[0].size[0]
                ty = self.images[0].size[1]
                xoff = csize / 4
                yoff = csize / 4 * 3
            elif i == 3:
                ty = self.images[0].size[0]
                xoff = csize / 4 * 3
                yoff = csize / 4 * 3
            else:
                xoff = csize / 4
                yoff = csize / 4
            r0 = MatrixTransform()
            off = i * 90
            r0.rotate(off, (0, 0, 1))
            roti = (
                    STTransform(translate=(tx, ty, 0)) *
                    r0
            )
            tr1 = (STTransform(scale=(0.5, 0.5, 1), translate=(xoff, yoff, 0)) *
                   #r0 *
                   MyPolarTransform() *
                   roti
                   )
            tr2 = (STTransform(scale=(1.0, 1.0, 1), translate=(xoff-csize/4, yoff-csize/4, 0)) #*
                   )
            self.images[i].transform = tr1
            self.images2[i].transform = tr2

        self.visuals = [*self.images, *self.images2]
        self.show()

    def on_draw(self, ev):
        gloo.clear(color='w', depth=True)
        for vis in self.visuals:
            vis.draw()

    def on_resize(self, event):
        # Set canvas viewport and reconfigure visual transforms to match.
        vp = (0, 0, self.physical_size[0], self.physical_size[1])
        self.context.set_viewport(*vp)
        for vis in self.visuals:
            vis.transforms.configure(canvas=self, viewport=vp)


if __name__ == '__main__':
    win = Canvas()
    import sys
    if sys.flags.interactive != 1:
        vispy.app.run()
Kai Mühlbauer
@kmuehlbauer
Simple example showing a window with divided into 4 squares. Each square shows the original image and on top it's PolarTransformed representation. (UL- top is center, UR left is center, LL - bottom is center, LR - right is center. As you can see, somehow x and y axes are inverted for the Transformed representation. This makes me a bit nervous as this means that somewhere something fishy is going on (or I do not understand it yet). If you swap pos.x/pos.y in the atan-call in glsl_imap the output is correct, but then the atan function uses inverted coordinates. I'm not sure where the problem lies. So in case it is in front of the screen, please let me know.
BTW, working with latest github main branch.
David Hoese
@djhoese
@kmuehlbauer I'm on vacation this week so not sure I'll have time to help you investigate.
Kai Mühlbauer
@kmuehlbauer
@djhoese No worries. I'll have to let this sink in a bit anyway
ViNOJ DAViS
@ViNOJ-DAViS
@kmuehlbauer I tried running your example, Its giving error to me when I run from the terminal "AttributeError: 'ImageVisual' object has no attribute 'transforms'"
What am I missing?
Kai Mühlbauer
@kmuehlbauer
@ViNOJ-DAViS That sounds a strange error. How did you install vispy and which version?
ViNOJ DAViS
@ViNOJ-DAViS
python3 version is 3.6.9
vispy is 0.4.0
I will upgrade vispy and check
Kai Mühlbauer
@kmuehlbauer
Are you able to install the latest version 0.7.0? Vispy has changed massively between 0.4.0 and 0.7.0.
ViNOJ DAViS
@ViNOJ-DAViS
@kmuehlbauer Yeah after upgrade it works. Thanks
Kai Mühlbauer
@kmuehlbauer
@ViNOJ-DAViS Great!
Philipp Schlegel
@schlegelp
Hi there! Great job on 0.7.0! I have a quick question re Volumes: is there a straight forward way to scale them? For example, I would like each voxel to have a isometric (or perhaps even non-isometric) size for easier co-visualization with other data. Perhaps with some kind of transform?
2 replies
Kai Mühlbauer
@kmuehlbauer
@ViNOJ-DAViS Please have a look here: vispy/vispy#2133 If we can add tests to this, this might go in for version 0.8.0 (next month)
ViNOJ DAViS
@ViNOJ-DAViS
Hi can anyone explain or direct me to a reference which explains (M, N, 3), or (M, N, 4) for ImageVisual data
Kai Mühlbauer
@kmuehlbauer
3 - RGB, 4 - RGBA IIRC
@ViNOJ-DAViS While you are here, I've added a new example here, which fiddles with the polar transform ( https://github.com/vispy/vispy/pull/2133#issuecomment-879854314)
David Hoese
@djhoese
@ViNOJ-DAViS To put even more detail on that: RGBA stands for Red, Green, Blue, Alpha where RGB are your normal image data making up the multi-color image and Alpha controls the transparency of the image where the lowest value (0) is fully transparent and the highest value (1 or 255 depending on data type) is fully opaque
ViNOJ DAViS
@ViNOJ-DAViS
@kmuehlbauer @djhoese Thank you....
@kmuehlbauer I am testing vispy/vispy#2133 with some test data
kmuehlbauer
@kmuehlbauer:matrix.org
[m]
Please have a look at my last example without that PR. That will do what you want without any changes to imsgevisual
ViNOJ DAViS
@ViNOJ-DAViS
@kmuehlbauer as per my understanding location is working in completely opposite manner i.e. it starts from E when W is selected and vice-versa
Kai Mühlbauer
@kmuehlbauer
@ViNOJ-DAViS I can't reproduce this. Could you elaborate a bit more?
I've found an issue with the "direction" cw/ccw but no issue with the location.
Kai Mühlbauer
@kmuehlbauer
polar_image_01.png
In the above image you see the original image (top left) and the polar representation (center). For the polar representation the original image is spread over 360 deg from left to right, with range=0 at the top and range=max at the bottom in clockwise fashion.
Kai Mühlbauer
@kmuehlbauer
polar_image_02.png
The image above shows the polar representation, from left to right, when r=max at the top and r=0 at the bottom.
ViNOJ DAViS
@ViNOJ-DAViS
Screenshot from 2021-07-15 13-02-16.png
Zhao Liang
@neozhaoliang
Hi, I have a question about using framebuffers in vispy. Is it possible to use framebuffers without using "pingpong"? I want to port some shadertoy code with bufferA/bufferB/.../bufferD to vispy, but I can't find any example on this.
1 reply
ViNOJ DAViS
@ViNOJ-DAViS

Why am I getting mirror image when compared to @kmuehlbauer image

Screenshot from 2021-07-15 13-02-16.png

What could be the issue?
Kai Mühlbauer
@kmuehlbauer
@ViNOJ-DAViS I've fixed the cw/ccw issue already in my code. Wait a minute.
                    # 4
                    # direction switch via inverting scale.x
                    * STTransform(scale=(-dir0, 1.0))
change the sign of dir0 at this line
ViNOJ DAViS
@ViNOJ-DAViS
Great @kmuehlbauer this fixes for both N & S
Screenshot from 2021-07-15 13-20-47.png
But for W & E i think its still showing opp. Can you please confirm
Kai Mühlbauer
@kmuehlbauer
Yes, you are right. Let me fix this, hang on.
                   # 3
                    # location change via translate.x
                    * STTransform(translate=(self.image.size[0] * (-loc0 - 0.25), 0.0))
Change sign of loc0 at this line.
Please note, that this only works for subdivide method. impostor needs a bit more thought.