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.
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.