Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update scalars does not applies correct alpha values #5989

Open
ZZaphodd opened this issue Apr 27, 2024 · 1 comment
Open

update scalars does not applies correct alpha values #5989

ZZaphodd opened this issue Apr 27, 2024 · 1 comment
Labels
bug Uh-oh! Something isn't working as expected.

Comments

@ZZaphodd
Copy link

Describe the bug, what's wrong, and what you expected.

Whole mesh goes partially transparent
if i give non 1.0 as alpha value only one of cell_data

Steps to reproduce the bug.

import numpy as np
import pyvista
import random

def cube_3_3_3():
    _coords: set[tuple[float, float, float]] = set()
    cubes: list[tuple[int, int, int, int]] = list()
    coords: list[tuple[float, float, float]] = None
    coords_to_index: dict[tuple[float, float, float], int] = dict()
    cells: list[list[int]] = list()

    dim0 = 3
    dim1 = 3
    dim2 = 3

    for i0 in range(dim0):
        for i1 in range(dim1):
            for i2 in range(dim2):
                cubes.append((float(i0), float(i1), float(i2), 1))

    for cube in cubes:
        i0, i1, i2, cs = cube
        _coords.add((i0, i1, i2))
        _coords.add((i0, i1, i2+cs))
        _coords.add((i0, i1+cs, i2))
        _coords.add((i0, i1+cs, i2+cs))
        _coords.add((i0+cs, i1, i2))
        _coords.add((i0+cs, i1, i2+1))
        _coords.add((i0+cs, i1+cs, i2))
        _coords.add((i0+cs, i1+cs, i2+cs))

    coords = list(_coords)
    for idx, key in enumerate(coords):
        coords_to_index[key] = idx

    for cube in cubes:
        i0, i1, i2, cs = cube
        cells.append([8,
                      coords_to_index[(i0, i1, i2)],
                      coords_to_index[(i0+cs, i1, i2)],
                      coords_to_index[(i0+cs, i1+cs, i2)],
                      coords_to_index[(i0, i1+cs, i2)],
                      coords_to_index[(i0, i1, i2+cs)],
                      coords_to_index[(i0+cs, i1, i2+cs)],
                      coords_to_index[(i0+cs, i1+cs, i2+cs)],
                      coords_to_index[(i0, i1+cs, i2+cs)]
                      ])

    cell_types = np.array([pyvista.CellType.HEXAHEDRON] * len(cells), np.int8)

    return pyvista.UnstructuredGrid(cells, cell_types, coords)

def main():
    random_generator = random.Random(42)    
    
    plotter = pyvista.Plotter()

    grid1 = cube_3_3_3()
    colors = [[random_generator.uniform(0.0, 1.0),
               random_generator.uniform(0.0, 1.0),  
                random_generator.uniform(0.0, 1.0,), 
                    1.0
                    ] for _ in range(grid1.n_cells)]
    grid1.cell_data['colors_rgba'] = colors

    #plotter.add_mesh(grid1, scalars="colors_rgba", rgb=True)
    plotter.add_mesh(grid1, scalars="colors_rgba")

    def flip_opacity_only_one_cell():
        nonlocal colors, grid1, plotter
        # random cell
        colors[8][3] = 1.0 - colors[8][3]

        print("colors where 0<a<1: ", end="") # no entries will shows
        for rgba in colors:
            if 0<rgba[3]<1:
                print(rgba, end="")
        print()

        grid1.cell_data['colors_rgba'] = colors
        plotter.render()

    plotter.add_key_event("7",flip_opacity_only_one_cell)

    plotter.show()



if __name__ == '__main__':
    main()

System Information

--------------------------------------------------------------------------------
  Date: Sun Apr 28 08:49:41 2024 대한민국 표준시

                OS : Windows
            CPU(s) : 24
           Machine : AMD64
      Architecture : 64bit
               RAM : 32.0 GiB
       Environment : Python
        GPU Vendor : NVIDIA Corporation
      GPU Renderer : NVIDIA GeForce GTX 1060 3GB/PCIe/SSE2
       GPU Version : 4.5.0 NVIDIA 546.12
  MathText Support : False

  Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23)
  [MSC v.1916 64 bit (AMD64)]

           pyvista : 0.43.5
               vtk : 9.3.0
             numpy : 1.26.2
        matplotlib : 3.8.4
            scooby : 0.9.2
             pooch : 1.8.1
            pillow : 10.3.0
             PyQt5 : 5.15.10
           IPython : 8.15.0
              tqdm : 4.66.1
      nest_asyncio : 1.5.6
--------------------------------------------------------------------------------

Screenshots

screenshot of initial state
image

after '7' key pressed
image

@ZZaphodd ZZaphodd added the bug Uh-oh! Something isn't working as expected. label Apr 27, 2024
@ZZaphodd
Copy link
Author

ZZaphodd commented May 2, 2024

tying to figure out when mesh really updated, #5158
not sure same problem, #5204

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Uh-oh! Something isn't working as expected.
Projects
None yet
Development

No branches or pull requests

1 participant