Visibility, camera and mesh

Hello everyone, I have a problem to be solved.
There is a triangular mesh of STL format and 3 cameras in my scene.
I need to get the index ID of all the mesh faces that is visible to each camera.
Since there are close to 100w faces, I also have requirements for efficiency.
I use python 3.8 and vtk 9.2.6. Thank you.
I’m interested to fund this question, please reach out privately if interested.
It seems the vtk example can be used but it should be acceleracted.

#!/usr/bin/env python

# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonDataModel import vtkDataObject
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkHardwareSelector,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer
)

# Callback for when selection is changed

# This is global - fix later.
ren1 = vtkRenderer()


def selectionCallback(caller, eventId):
    hsel = vtkHardwareSelector()
    hsel.SetFieldAssociation(vtkDataObject.FIELD_ASSOCIATION_CELLS)
    hsel.SetRenderer(ren1)

    x, y = caller.GetRenderWindow().GetSize()

    # Create a small area around clicked point for selector area
    hsel.SetArea(0, 0, x, y)
    res = hsel.Select()

    numNodes = res.GetNumberOfNodes()
    if (numNodes < 1):
        print("No visible cells")
    else:
        sel_node = res.GetNode(0)
        print('Visible cell IDs: ', VN.vtk_to_numpy(sel_node.GetSelectionList()).tolist())


def main():
    colors = vtkNamedColors()

    sphere = vtkSphereSource()
    sphere.SetCenter(0, 0, 0)
    sphere.SetRadius(5.0)

    sphereMapper = vtkPolyDataMapper()
    sphereMapper.SetInputConnection(sphere.GetOutputPort())

    sphereActor = vtkActor()
    sphereActor.SetMapper(sphereMapper)
    sphereActor.GetProperty().SetColor(colors.GetColor3d('Bisque'))

    ren1.AddActor(sphereActor)
    ren1.GetActiveCamera().ParallelProjectionOn()
    ren1.SetBackground(colors.GetColor3d('Navy'))

    renWin = vtkRenderWindow()
    renWin.AddRenderer(ren1)
    renWin.SetSize(300, 300)
    renWin.SetWindowName('HardwareSelector')

    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    iren.AddObserver("UserEvent", selectionCallback)

    style = vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(style)
    renWin.GetInteractor().SetInteractorStyle(style)

    ren1.ResetCamera()
    renWin.Render()

    iren.Initialize()
    iren.Start()


if __name__ == '__main__':
    main()

Hi @Victor, what you mean by a paid question?

This means I’m interested to fund someone to help me, please reach out privately.

Dear @Victor, here we help each other without expecting any rewards. I strongly believe these kind of post are not good for the community, however it is up to the mods to the decide.

You should contact Kitware directly to get fast answer via a support contract: https://www.kitware.com/contact/

1 Like

Hey, a free spirit is perfect, but knowledge is also valuable. I’m a researcher, but I don’t know much about VTK. This question has been bothering me for a long time. I have applied various methods, but nothing works.

No comments.

For your question, I think you are looking for ray casting. My suggestion would be to cast rays from the location of each camera to the object. You can get cell ids where these rays hit.

To get cells along a line you can use vtkCellLocator vtkCellLocator.FindCellsAlongLine method.

Based on the distance of your camera to the object and object dimension, you can customize how many rays to cast and in which all direction.

Thank you. I would try it.

Hey Jishnu,
Thank you for your suggestion.
There is no doubt that raycasting can solve this problem, but there seems to be a problem.
Raycasting will discretize space leading to some regions could not be extracted, and this requires us to control the density of rays. Besides, raycasting can take more time if not optimized. I’m sensitive to time consumption because one iteration of my research takes a long time.

Thanks again for your reply and suggestion.

@Victor , I’ve edited your message to avoid mentionning actual pricing. Please use private communication for such exchanges in the future.