# From one execution to another, application may work normally or show nothing

**URL:** https://discourse.vtk.org/t/from-one-execution-to-another-application-may-work-normally-or-show-nothing/12136
**Category:** Support
**Created:** [August 11, 2023, 11:44am UTC](https://discourse.vtk.org/t/from-one-execution-to-another-application-may-work-normally-or-show-nothing/12136 "2023-08-11T11:44:09Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Bktero](https://discourse.vtk.org/user_avatar/discourse.vtk.org/bktero/32/7598_2.png) [@Bktero](https://discourse.vtk.org/u/Bktero)
#### Post date: [August 11, 2023, 11:44am UTC](https://discourse.vtk.org/t/from-one-execution-to-another-application-may-work-normally-or-show-nothing/12136/1 "2023-08-11T11:44:09Z")

</div>

Hello

I have a Python script that displays some actors in a window. It’s quite simple (more or less what you can find in the examples).

Sometimes, I run my script and everything works normally: I see the 2 actors and I can interact with the scene.

Sometimes, the window is empty.

How can I investigate this issue? Is there any logs or traces that I can enabled?  
Do you have any idea of the cause of such an issue?

Thanks a lot!

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [August 16, 2023, 2:41pm UTC](https://discourse.vtk.org/t/from-one-execution-to-another-application-may-work-normally-or-show-nothing/12136/2 "2023-08-16T14:41:15Z")

</div>

Please share your script

---

<div class="post-metadata">

### Author: ![Bktero](https://discourse.vtk.org/user_avatar/discourse.vtk.org/bktero/32/7598_2.png) [@Bktero](https://discourse.vtk.org/u/Bktero)
#### Post date: [August 18, 2023, 9:35am UTC](https://discourse.vtk.org/t/from-one-execution-to-another-application-may-work-normally-or-show-nothing/12136/3 "2023-08-18T09:35:22Z")

</div>

Hello

I have created a simplified version of my application, that reproduces the issue.

- This script first loads definitions for points, triangles and tetrahedrons, from a [BDF file](https://help.hexagonmi.com/fr-FR/bundle/MSC_Nastran_2021/page/Nastran_Combined_Book/getstart/GS-Files/TOC.MSC.Nastran.Input.Files.xhtml). This is the `load_bdf_file()` function.
- Then, in the function `create_mappers()`, I create two mappers: one to render for the triangles, one for the tetrahedrons, the points being common.
- Final, I render the mappers with 2 actors.

```python
import collections
import dataclasses

import vtk
from bulkdata import Deck
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonCore import (
    vtkPoints
)
from vtkmodules.vtkCommonDataModel import (
    vtkCellArray,
    vtkPolyData,
    vtkTetra,
    vtkTriangle, vtkUnstructuredGrid,
)
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkMapper,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer, vtkDataSetMapper,
)

@dataclasses.dataclass
class Grid:
    id: int
    x: float
    y: float
    z: float

@dataclasses.dataclass
class Ctria3:
    eid: int
    pid: int
    g1: int
    g2: int
    g3: int

@dataclasses.dataclass
class Ctetra:
    eid: int
    pid: int
    g1: int
    g2: int
    g3: int
    g4: int

@dataclasses.dataclass
class Bdf:
    grids: list[Grid]
    ctria3s: list[Ctria3]
    ctetras: list[Ctetra]

def load_bdf_file(filename: str) -> Bdf:
    # Load bdf model
    with open(filename, encoding='utf-8') as bdf_file:
        deck = Deck.load(bdf_file)
        names = collections.Counter([c.name for c in deck.cards])
        print(names)

    grids = []
    for card in deck.find({'name': 'GRID'}):
        grid = Grid(card[0], card[2], card[3], card[4])
        grids.append(grid)

    ctria3s = []
    for card in deck.find({'name': 'CTRIA3'}):
        ctria3 = Ctria3(card[0], card[1], card[2], card[3], card[4])
        ctria3s.append(ctria3)

    ctetras = []
    for card in deck.find({'name': 'CTETRA'}):
        ctetra = Ctetra(card[0], card[1], card[2], card[3], card[4], card[5])
        ctetras.append(ctetra)

    return Bdf(grids, ctria3s, ctetras)

def create_mappers(bdf: Bdf) -> (vtkMapper, vtkMapper):
    # Create points
    points = vtkPoints()
    for grid in bdf.grids:
        points.InsertPoint(grid.id, (grid.x, grid.y, grid.z))

    # Transform triangles
    triangles = vtkCellArray()

    for ctria3 in bdf.ctria3s:
        triangle = vtkTriangle()
        triangle.GetPointIds().SetId(0, ctria3.g1)
        triangle.GetPointIds().SetId(1, ctria3.g2)
        triangle.GetPointIds().SetId(2, ctria3.g3)
        triangles.InsertNextCell(triangle)

    data = vtkPolyData()
    data.SetPoints(points)
    data.SetPolys(triangles)

    mapper_triangles = vtkPolyDataMapper()
    mapper_triangles.SetInputData(data)

    # Create tetras
    tetras = vtkCellArray()

    for ctetra in bdf.ctetras:
        tetra = vtkTetra()
        tetra.GetPointIds().SetId(0, ctetra.g1)
        tetra.GetPointIds().SetId(1, ctetra.g2)
        tetra.GetPointIds().SetId(2, ctetra.g3)
        tetra.GetPointIds().SetId(3, ctetra.g4)
        tetras.InsertNextCell(tetra)

    unstructured_grid = vtkUnstructuredGrid()
    unstructured_grid.SetPoints(points)
    unstructured_grid.SetCells(vtk.VTK_TETRA, tetras)

    mapper_tetrahedrons = vtkDataSetMapper()
    mapper_tetrahedrons.SetInputData(unstructured_grid)

    return mapper_triangles, mapper_tetrahedrons

def render(mapper1, mapper2) -> None:
    colors = vtkNamedColors()

    # Triangles
    actor1 = vtkActor()
    actor1.SetMapper(mapper1)
    actor1.GetProperty().SetColor(colors.GetColor3d('turquoise'))

    # Tetrahedrons
    actor2 = vtkActor()
    actor2.SetMapper(mapper2)
    actor2.GetProperty().SetColor(colors.GetColor3d('salmon'))

    # Create a renderer, render window, and interactor
    renderer = vtkRenderer()
    renderer.SetBackground(colors.GetColor3d('black'))
    renderer.ResetCamera()

    window = vtkRenderWindow()
    window.SetWindowName('VisualSEA2')
    window.AddRenderer(renderer)

    interactor = vtkRenderWindowInteractor()
    interactor.SetRenderWindow(window)
    style = vtk.vtkInteractorStyleTrackballCamera()
    interactor.SetInteractorStyle(style)

    # Add the actors to the scene
    renderer.AddActor(actor1)
    renderer.AddActor(actor2)

    # Render and interact
    window.Render()
    interactor.Start()

if __name__ == ' __main__':
    bdf_model = load_bdf_file('Cube_new_template.bdf')
    m1, m2 = create_mappers(bdf_model)
    render(m1, m2)

```

Unfortunately, I can’t upload the BDF file as I am a new user.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [August 18, 2023, 9:37am UTC](https://discourse.vtk.org/t/from-one-execution-to-another-application-may-work-normally-or-show-nothing/12136/4 "2023-08-18T09:37:54Z")

</div>

> [@Bktero](#):
>
> Unfortunately, I can’t upload the BDF file as I am a new user.

You can now 🙂

---

<div class="post-metadata">

### Author: ![Bktero](https://discourse.vtk.org/user_avatar/discourse.vtk.org/bktero/32/7598_2.png) [@Bktero](https://discourse.vtk.org/u/Bktero)
#### Post date: [August 18, 2023, 9:39am UTC](https://discourse.vtk.org/t/from-one-execution-to-another-application-may-work-normally-or-show-nothing/12136/5 "2023-08-18T09:39:03Z")

</div>

[Cube\_new\_template.bdf](https://discourse.vtk.org/uploads/short-url/xWBwc5IjS4yZrectr7GdSgQ6VvT.bdf) (28.1 KB)

Here it is!

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [August 18, 2023, 9:40am UTC](https://discourse.vtk.org/t/from-one-execution-to-another-application-may-work-normally-or-show-nothing/12136/6 "2023-08-18T09:40:32Z")

</div>

I dont see anything out of place in your program, you may want to check that when tthe bug shows up, there is actually some data pass to the rendering stack, eg print the number of points.

---

<div class="post-metadata">

### Author: ![Bktero](https://discourse.vtk.org/user_avatar/discourse.vtk.org/bktero/32/7598_2.png) [@Bktero](https://discourse.vtk.org/u/Bktero)
#### Post date: [August 28, 2023, 1:48pm UTC](https://discourse.vtk.org/t/from-one-execution-to-another-application-may-work-normally-or-show-nothing/12136/7 "2023-08-28T13:48:09Z")

</div>

I should do that simply by adding `print(len(points))` in the function `create_mappers()`?

Or should it be something closer to the rendering core (in that case, what woud you suggest)?
