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
David Hoese
@djhoese
although that isn't accurate, it is kind of a cool effect
I'll try to find time to look into this more today or sometime this week
David Hoese
@djhoese
There has to be math operation (np.dot or something) but it isn't coming to me.
Surprisingly doing self.backgroundLabelMax.transform.matrix = self.view.camera.transform.matrix and self.backgroundLabelMax.transform.translate(self.xyz_top) gets it pretty close...somehow
Omicron91
@Omicron91
Oh nice, that's what I was looking for. This should be enough. Thanks for helping!
Omicron91
@Omicron91
Now it's working. I think this is very usefull when u want to visualize annotations over 3D things
import numpy as np
import vispy.scene
from vispy.scene import visuals
from vispy.visuals import text

class CustomCanvas(vispy.scene.SceneCanvas):

    def __init__(self):
        super(CustomCanvas, self).__init__(keys='interactive', show=True)

        self.unfreeze()

        self.view = self.central_widget.add_view()

        self.xyz_top = None
        self.textLabelMax = None
        self.backgroundLabelMax = None
        self.bgScale = [1, 1, 1]
        self.events.mouse_move.connect(self.on_mouse_move)
        self.events.mouse_wheel.connect(self.on_mouse_wheel)

        self.freeze()

    def on_mouse_move(self, event):

        if(event.button == 1 and event.is_dragging):
            self.backgroundLabelMax.transform.reset()
            self.backgroundLabelMax.transform.matrix = self.view.camera.transform.matrix
            self.backgroundLabelMax.transform.translate(self.xyz_top)


    def on_mouse_wheel(self, event):
        pass
    """
        self.backgroundLabelMax.transform.reset()
        delta = event.delta[1]

        if(delta < 0):
            print(delta)
            if self.view.camera.scale_factor >= 30:
                self.view.camera.scale_factor = 30

        else:

            if self.view.camera.scale_factor <= 10:
                self.view.camera.scale_factor = 10

        self.backgroundLabelMax.transform.matrix = self.view.camera.transform.matrix
        self.backgroundLabelMax.transform.scale(self.bgScale)    
        self.backgroundLabelMax.transform.translate(self.xyz_top)
    """

    def draw_cloud_points(self):

        pos = np.random.normal(size=(100000, 3), scale=0.2)
        # one could stop here for the data generation, the rest is just to make the
        # data look more interesting. Copied over from magnify.py
        centers = np.random.normal(size=(50, 3))
        indexes = np.random.normal(size=100000, loc=centers.shape[0]/2.,
                                scale=centers.shape[0]/3.)
        indexes = np.clip(indexes, 0, centers.shape[0]-1).astype(int)
        scales = 10**(np.linspace(-2, 0.5, centers.shape[0]))[indexes][:, np.newaxis]
        pos *= scales
        pos += centers[indexes]

        # create scatter object and fill in the data
        scatter = visuals.Markers()
        scatter.set_data(pos, edge_color=None, face_color=(1, 1, 1, .5), size=5)
        self.view.add(scatter)

        # Adding turntable with ortographic view
        self.view.camera = vispy.scene.TurntableCamera(fov=0)

        # Adding plane as background for texts
        self.backgroundLabelMax = visuals.Rectangle(center = (0, 0, 0), width=3.5, height = 1, color=(1, 0, 0, 0.4), radius=0.3, parent=self.view.scene)
        # Adding text label at center / top (Z axis)

        self.xyz_top = (pos[:,0].max(), pos[:,1].max(), pos[:,2].max())
        self.textLabelMax = visuals.Text(pos=(0, 0, 0), text="Test_Label_Max", font_size=18, color="white", parent=self.backgroundLabelMax)

        self.backgroundLabelMax.transform = vispy.scene.transforms.STTransform(
            scale=(1, 1, 1),
            translate=(0, 0, 0)
        ).as_matrix()
        self.backgroundLabelMax.transform.matrix = self.view.camera.transform.matrix
        self.backgroundLabelMax.transform.translate(self.xyz_top)
        # Auto focus
        self.view.camera.set_range()

def main():
    custom_canvas = CustomCanvas()
    custom_canvas.draw_cloud_points()

if __name__ == '__main__':
    import sys
    if sys.flags.interactive != 1:
        main()
        vispy.app.run()
m3atwad
@m3atwad
Do we have to build the documentation like this example recommends?
m3atwad
@m3atwad
if so what directory do I need to be in to do this?
David Hoese
@djhoese
@m3atwad What do you mean "like this example recommends"? Are you making a contribution to the documentation and want to verify it? Otherwise, is there a reason you want to generate the documentation locally?
Looking at the README in that directory, that command is probably out dated. It should be as "easy" as running make html in the docdirectory. Note however that by default it will run all of the gallery examples which can take a long time. There is a way to make it not do that but I don't remember off the top of my head
m3atwad
@m3atwad
@djhoese Really I'm just looking for documentation to read and it seems sparse. I stumbled on that folder in the repo and thought I had to build the docs myself to get documentation I can learn from. Where would you say the best docs to learn vispy are? I also noticed multiple blogs and wiki's on the website are linked but the links are dead.
sreenath1994s
@sreenath1994s

Screenshot 2022-01-26 170245.png

Hello devs, I have a problem that after updating vispy from 0.6.6 to 0.9.4 my surfaceplot looks very dark.

Lorenzo Gaifas
@brisvag
@m3atwad yeah the documentation is sometimes a bit outdated. The generated one you can find on vispy.org; the most complete is probably in the API section. In terms of tutorials and guides your best bet is probably the examples folder!
@sreenath1994s a lot of things have changed since then, so it's hard to tell what's the issue without some code. Can you reproduce the change with a small snippet of code?
sreenath1994s
@sreenath1994s
# -*- coding: utf-8 -*-
# vispy: gallery 30
# -----------------------------------------------------------------------------
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
"""
Draw a SurfacePlot
==================
This example demonstrates the use of the SurfacePlot visual.
"""

import sys
import numpy as np

from vispy import app, scene
from vispy.util.filter import gaussian_filter


canvas = scene.SceneCanvas(keys='interactive', bgcolor='w')
view = canvas.central_widget.add_view()
view.camera = scene.TurntableCamera(up='z', fov=60)

# Simple surface plot example
# x, y values are not specified, so assumed to be 0:50
z = np.random.normal(size=(250, 250), scale=200)
z[100, 100] += 50000
z = gaussian_filter(z, (10, 10))
p1 = scene.visuals.SurfacePlot(z=z, color=(0.3, 0.3, 1, 1), shading='smooth')
p1.transform = scene.transforms.MatrixTransform()
p1.transform.scale([1/249., 1/249., 1/249.])
p1.transform.translate([-0.5, -0.5, 0])

view.add(p1)

xax = scene.Axis(pos=[[-0.5, -0.5], [0.5, -0.5]], tick_direction=(0, -1),
                 font_size=16, axis_color='k', tick_color='k', text_color='k',
                 parent=view.scene)
xax.transform = scene.STTransform(translate=(0, 0, -0.2))

yax = scene.Axis(pos=[[-0.5, -0.5], [-0.5, 0.5]], tick_direction=(-1, 0),
                 font_size=16, axis_color='k', tick_color='k', text_color='k',
                 parent=view.scene)
yax.transform = scene.STTransform(translate=(0, 0, -0.2))

# Add a 3D axis to keep us oriented
axis = scene.visuals.XYZAxis(parent=view.scene)

if __name__ == '__main__':
    canvas.show()
    if sys.flags.interactive == 0:
        app.run()
@brisvag The above is a sample code from vispy github and these are the results with old and new versions of the library.
sreenath1994s
@sreenath1994s
Screenshot 2022-01-26 184247.png
These are the results with the 'Old' and 'New' library. Can somebody kindly help me in modifying the code so that the output from the 'New' version looks similar to the 'Old' version.
Lorenzo Gaifas
@brisvag

@sreenath1994s it seems that the crux of the issue is that the default light direction changed. Not sure why or when; you problem can be easily fixed by changing the light direction to something better. In the example above:

p1.shading_filter.light_dir = 1, 1, 1

this should be close enought to what you had before. If not, play around with the number until you're happy :)

sreenath1994s
@sreenath1994s
Thank you so much @brisvag it worked. One more question. In the old version, some kind of beautiful reflection exists. Which parameter I must adjust to enable that reflection.
Lorenzo Gaifas
@brisvag
Great! Not sure what you mean. Can you show me a screenshot with/without?
You can probably get what you want by playign around with the shading filter parameters
if you're in ipython, you can do p1.shading_filter? and it will give you the documentation for it
you can change specular light, shininess and so on
sreenath1994s
@sreenath1994s
Screenshot 2022-01-26 184247.png
@brisvag I was referring to the above reflection in the old version. I will go through the documentaion of shading_filter.
Thank you for the suggestion.
Lorenzo Gaifas
@brisvag
I see; that indeed looks like a specular highlight, so you can probably get it by changing those parameters.
David Hoese
@djhoese
@brisvag The lighting changes were mostly by @asnt after a huge refactor to the MeshVisual. I wonder if the SurfacePlot should be updated to have a different default light direction
Lorenzo Gaifas
@brisvag
Seems reasonable!
David Hoese
@djhoese
VisPy 0.9.5 has been released on PyPI! conda-forge should be later tonight
Lorenzo Gaifas
@brisvag
<3
David Hoese
@djhoese
I ended making a 0.9.6 release too. Hopefully fixes an issue @jni was seeing
are the individual plots considered vertex and are the individual plot locations set by the 'index' variable on line 39? I would like to build on this example for a basic real time stream plotter from a USB link. Also, have you guys ever tested this with pyinstaller so it can be packaged up with a python application and deployed as an exe?
David Hoese
@djhoese
@m3atwad There are multiple issues discussing pyinstaller use. See vispy/vispy#1643 and vispy/vispy#2300
for that example and what you're doing, how many signals do you want to plot at once? I personally really dislike this example and want to rename it or remove it. It creates these many plots by "cheating" and doesn't resemble what a real world maintainable and flexible application would look like.
m3atwad
@m3atwad
@djhoese thank you very much for you reply! I see, I'm ok with python but very new to the GPU situation and am trying to at most plot 4 different plots from an ADC. I am using matplot lib now and get a decent frame rate using blitting with ~2048 16 bit integers. I am trying to upgrade this to maybe 1M points of floats. I would at most just do 4 of these plots and am just nervous about investing a lot of my dev time in another platform that ultimately is a dead end. This approach looks awesome but I'm so new I don't know what I don't know yet to pull the trigger in commiting dev time to this library. Is it possible to elaborate on what this example is missing? Also, is the individual plot location and settings (not data points / y values but actual size, location etc...) set by the shader code (FRAG and VERT shader lines)?
Nicolas P. Rougier
@rougier
@m3atwad @djhoese This example fits a real time signal that need to update only one data point at eah time step. Instead of reuploading 1M points, you only update the new point and the shader knows how to display it properly.
m3atwad
@m3atwad
is it possible to have a vector where you update a block say in 1M points you update 512 or 1024 or 60 etc...?
Nicolas P. Rougier
@rougier
Theoretically yes as long as they are displayed continuously on screen. The trick is to use a moving index to make the upload. for large chunk, thi may need to be split into two upload. You can test the trick with matplotlib only.
m3atwad
@m3atwad
@rougier I apologize if asking this many questions on here is inappropriate for this forum. Please let me know if so. My goal is to effectively create a vector of data and refresh a plot. In an ideal situation I'm trying to end up with a software window that mimics an oscilloscope to view electrical signals. So with this said I'm looking to get a decent framerate for a data vector and plot (1 to 4) that I can manipulate. What do you mean "continuously displayed on screen" and are you recommending I have a giant data vector I append to and just move the index for plotting rather than create a new data vector every time that I would submit to vispy?
Nicolas P. Rougier
@rougier
For an oscilloscope-like display, you don't need much data since the resolution of the screen limits what you can display. Let's say you want to display 2000 vertices, you need a vertex buffer of 2000 floats but you need to update only one at each timestep (unless your data refresh rate is faster than the display refresh rate). The trick to update the vertex buffer is to have an index that is incremented by one at each time step adn this where you upload your new data. Now, the shader must be aware of this index to properly display the line, that is actually two lines. Best is to test using matplotlib. For example, let's pretend a numpy array is a vertex buffer holding y value only and plot it using a mpl.plot. You'll need to split it in two line plots I think.
m3atwad
@m3atwad
so as an example right now I have 60 bytes coming in as a block rather than a byte data stream. This will yield 30 16bit values. So would I need to loop through all 30 and added them individually to the vertex buffer? It looks like this example is doing just what I'm referring to with a chunk of 10 values.
Nicolas P. Rougier
@rougier
You can upload any contiguous chunk of data with a single call, no need to loop. In numpy, you would write something like Z[index:index+chunk_size] = chunk, index += chunk_size But you have to take care of the case where index is close to the end of Z. in such case, you need to split your data in two parts and make 2 uploads.
m3atwad
@m3atwad
oh ok, yea i'm thinking about it more as a hardware digital guy....i'd shift data out of the array at one end and shift data in at the other....OR create a new frame every time.
Nicolas P. Rougier
@rougier
David Hoese
@djhoese
@m3atwad The key in the glumpy example is the np.roll. You could also do this kind of thing on a numpy array that's 2 times the size of the buffer you need and treat it like a circular buffer. You update the array in two places with your new chunk, but the data you upload to matplotlib/vispy is the slice of the large array that represents the current N data points.
The key point of this whole discussion is that you could use vispy or matplotlib for this, but since you're already using matplotlib with blitting you should be fine. If you reduce the resolution of your data (ex. average or only show some of the data) and/or reduce how often you try to update the display then you should see better results while not effecting what you/the user actually sees
Omicron91
@Omicron91
Hello guys. I'm trying to rotate a point cloud aplying a SSTTransform to the scatter plot. The origin of the transform component is always on center by default i think, how could I move it?
Omicron91
@Omicron91
reference.png
Nicolas P. Rougier
@rougier
Can't you first apply a translation then a rotation ?