Strange behavior. If camera is far away, VTK only renders upon clicking on the render window.

Hi. I am new to VTK and I just encountered a strange behavior. If the camera is far away from the focal point, that is, if I set camera position as SetPosition(700,700,700) in the code below, VTK only produces a blank window with blue background without any actors. Only upon clicking the window that I see the actors.

#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkConeSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkPolyDataMapper.h>
#include <vtkCamera.h>


int main(int, char *[])
{
  //Create a cone
  vtkNew<vtkConeSource> cone;
  cone->SetHeight(400.0);
  cone->SetRadius(200.0);
  cone->SetResolution(10);

  //Create a mapper and actor
  vtkNew<vtkPolyDataMapper> coneMapper; 
  coneMapper->SetInputConnection(cone->GetOutputPort());

  vtkNew<vtkActor> coneActor; 
  coneActor->SetMapper(coneMapper);

  //Create a renderer and add cone to it.
  vtkNew<vtkRenderer> ren1;
  ren1->AddActor(coneActor);

  // Set background color of the renderer
  vtkNew<vtkNamedColors> colors;
  ren1->SetBackground(colors->GetColor3d("MidnightBlue").GetData()); 

  // Create a new visualization window and add the renderer to it.
  vtkNew<vtkRenderWindow> renWin;
  renWin->AddRenderer(ren1);
  renWin->SetSize(300,300);

  // Create a virtual camera
  vtkNew<vtkCamera> orientation;
  orientation->SetFocalPoint(0,0,0);
  orientation->SetPosition(700,700,700);
  ren1->SetActiveCamera(orientation);

  // Make the render window interacting

  vtkNew<vtkRenderWindowInteractor> renWinInteractor;
  renWinInteractor->SetRenderWindow(renWin);

  
  //Render and interact
    renWin->Render();
    renWinInteractor->Start();
  
  return EXIT_SUCCESS;
}

If I set the position as SetPosition(500,500,500) in the code above, I get a nice cone, but I get no cone with SetPosition(700,700,700) (it only shows when I click on the window). This is really confusing and is making it very difficult for me to use VTK for large datasets, since the PNG writer produces the PNG file without any actors in it. Thank you for all the help.

This has to do with the locations of your camera’s clipping planes set by default.

Instead of making a new camera, use the renderer’s active camera and/or perhaps tweak the Thickness attribute of the camera:

...
orientation = ren1->GetActiveCamera();
orientation->SetFocalPoint(0,0,0);
orientation->SetPosition(700,700,700);
orientation->SetThickness(1000);
...

Thanks a lot, Bane. That solved the problem for me. VTK is a bit overwhelming and so I am missing things even after reading the user guide.

Have you looked at the VTK Examples Project: https://lorensen.github.io/VTKExamples/site/

I find it difficult to prototype with C++, perhaps give Python a try - I’ve helped build vtki which aims to make VTK accessible to a wide audience and incredibly intuitive to use.

Hi, Bill. Thanks for the response. Yes, I have been going through the user-guide, VTK textbook, and VTK Examples website. I have finally managed to write a complete volume rendering example for myself. I am a physics student and so not the most competent person with computers, which is why I am missing small but important things.

Awesome! I would love to see the types of data you are visualizing!

One final solicitation: vtki was built for people in your situation! I’m a geophysics researcher and helped build up vtki to make 3D visualization more accessible to researchers in my domain (and non-computer scientists across the board). It helps you focus on your data and the underlying science rather than the nuances of common tasks in 3D viz.

I would certainly look into vtki. I will have to learn python a bit before I can do that. I do cosmology/particle physics and have been looking for an efficient rendering tool. I was using mathematica for 3d plots but it is extremely slow. During my test, yesterday, VTK seemed many many times faster than mathematica.

Oh yes! VTK is super fast and scalable! In vtki we maintain that speed by wrapping common tasks in VTK with VTK’s python bindings