Code Monkey home page Code Monkey logo

Comments (3)

djhoese avatar djhoese commented on June 14, 2024

I don't think I have time to debug this, but if I did/do I would need a minimal example that reproduces it for me and doesn't require any input data files (ex. numpy.random instead). If you can simplify this down as much as possible it would really help me track down what's going on in the internals.

from vispy.

JintaoLee-Roger avatar JintaoLee-Roger commented on June 14, 2024

Sure, here is a simple example:

from vispy import app, scene
import numpy as np
from vispy.scene.cameras import TurntableCamera
from vispy.io import load_data_file, read_png


class Blending_image(scene.visuals.Image):

    def __init__(self):
        scene.visuals.Image.__init__(self, parent=None)
        self.unfreeze()
        self.overlaid_images = [self]

        # NOTE: Here, I set img2's parent as img1.
        # So when apply some transform on img1, 
        # img2 can be add the same effect.
        img2 = scene.visuals.Image(parent=self) 
        self.overlaid_images.append(img2)
        # Set GL state. Must check depth test, otherwise weird in 3D.
        self.set_gl_state(depth_test=True,
                          depth_func='lequal',
                          blend_func=('src_alpha', 'one_minus_src_alpha'))
        self.freeze()

    def set_data2(self, img1, img2):
        self.set_data(img1)
        self.overlaid_images[1].set_data(img2)

canvas = scene.SceneCanvas(keys='interactive', bgcolor='white')

vb1 = scene.widgets.ViewBox(parent=canvas.scene)
vb2 = scene.widgets.ViewBox(parent=canvas.scene)

grid = canvas.central_widget.add_grid()
grid.padding = 20
grid.add_widget(vb1, 0, 0)
grid.add_widget(vb2, 0, 1)

vb1.camera = TurntableCamera(fov=45, azimuth=0, elevation=-90)
vb2.camera = TurntableCamera(fov=45, azimuth=0, elevation=-90)

# Create the image
root = 'mona_lisa/mona_lisa_sm.png'
img_data1 = read_png(load_data_file(root))[:500, :500, :]
img_data2 = read_png(load_data_file(root))[-500:, :500, :]

img_ov1data = np.ones((500, 500, 4)).astype(np.float32)
img_ov1data[:, :, 3] = 0.5
img_ov2data = np.random.rand(500, 500, 4).astype(np.float32)
img_ov2data[:, :, 3] = 0.5

image1 = Blending_image()
image1.set_data2(img_data1, img_ov1data)
image2 = Blending_image()
image2.set_data2(img_data2, img_ov2data)

vb1.add(image1)
vb2.add(image2)

vb1.camera.set_range()
vb2.camera.set_range()
vb1.camera.link(vb2.camera)

canvas.show()
app.run()
image

from vispy.

JintaoLee-Roger avatar JintaoLee-Roger commented on June 14, 2024

I have solved this problem. There are two way to solve it

  1. Just add Blending_image 's children into viewbox
vb1.add(image1)
vb1.add(image1.overlaid_images[-1])
vb2.add(image2)
vb2.add(image2.overlaid_images[-1])
  1. modify _set_clipperof Blending_image
class Blending_image(scene.visuals.Image):
    ......
    ......
    def _set_clipper(self, node, clipper):
        """
        To clipper its children

        Assign a clipper that is inherited from a parent node.

        If *clipper* is None, then remove any clippers for *node*.
        """
        super()._set_clipper(node, clipper)

        for im in self.children:
            if isinstance(im, scene.visuals.Image):
                if node in im._clippers:
                    im.detach(self._clippers.pop(node))
                if clipper is not None:
                    im.attach(clipper)
                    im._clippers[node] = clipper

from vispy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.