[vtkusers] vtkRenderWindowInteractor with custom render loop
elainejiang8
elainejiang8 at gmail.com
Mon Aug 21 12:27:04 EDT 2017
Hi all,
I'm writing a program that integrates vtk with an external VR program. This
requires that I use the VR program's render loop instead of vtk's. However,
I'm hoping to still be able to use vtkRenderWindowInteractor as it will make
interacting with vtk objects much easier. I saw a post on stackoverflow that
said that I could just call vtkRenderWindowInteractor::Initialize() for the
interactor to become enabled, but when I call the function, I can't seem to
interact with the vtk objects. Does anyone have any insight into this issue?
I'll attach my initialization and render functions below:
void initialize() {
vtkNew<vtkExternalOpenGLRenderWindow> renWin;
externalVTKWidget->SetRenderWindow(renWin.GetPointer());
renWin->AddRenderer(ren);
/**********************************************************/
std::string files[7] = {"../data/cco-ascii.vtk",
"../data/newjets-ascii.vtk", "../data/fekcorr-ascii.vtk",
"../data/newar-ascii.vtk", "../data/newhetg-ascii.vtk",
"../data/newopt-ascii.vtk", "../data/newsi-ascii.vtk"};
for(int i = 0; i < NUM_ACTORS; i++) {
vtkSmartPointer<vtkPolyDataReader> reader =
vtkSmartPointer<vtkPolyDataReader>::New();
reader->SetFileName(files[i].c_str());
reader->Update();
vtkSmartPointer<vtkPolyData> inputPolyData = reader->GetOutput();
// Merge duplicate points, and/or remove unused points and/or remove
degenerate cells
vtkSmartPointer<vtkCleanPolyData> clean =
vtkSmartPointer<vtkCleanPolyData>::New();
clean->SetInputData(inputPolyData);
vtkSmartPointer<vtkSmoothPolyDataFilter> smoothFilter =
vtkSmartPointer<vtkSmoothPolyDataFilter>::New();
smoothFilter->SetInputConnection(clean->GetOutputPort());
smoothFilter->SetNumberOfIterations(15);
smoothFilter->SetRelaxationFactor(0.1);
smoothFilter->FeatureEdgeSmoothingOff();
smoothFilter->BoundarySmoothingOn();
smoothFilter->Update();
// Update normals on newly smoothed polydata
vtkSmartPointer<vtkPolyDataNormals> normals =
vtkSmartPointer<vtkPolyDataNormals>::New();
normals->SetInputConnection(smoothFilter->GetOutputPort());
normals->ComputePointNormalsOn();
normals->ComputeCellNormalsOn();
normals->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(normals->GetOutputPort());
mapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetInterpolationToFlat();
actor->GetProperty()->SetOpacity(0.8);
ren->AddActor(actor);
actors.push_back(actor);
}
/**********************************************************/
// Set the custom type to use for interaction.
vtkSmartPointer<MouseInteractorHighLightActor> style =
vtkSmartPointer<MouseInteractorHighLightActor>::New();
style->SetDefaultRenderer(ren);
interactor->SetRenderWindow(renWin.GetPointer());
interactor->SetInteractorStyle(style);
/**********************************************************/
ren->SetBackground(0.87, 0.88, 0.91);
ren->ResetCamera();
*interactor->Initialize();*
vtkOpenGLCamera *camera = (vtkOpenGLCamera *)ren->GetActiveCamera();
// camera default position set at (4.68744, 2.67252, 360.229)
camera->SetPosition(4, 2, 360);
camera->SetViewUp(0,1,0); // controls "up" direction for camera
}
void display() {
// Enable depth testing. Demonstrates OpenGL context being managed by
external
// application i.e. GLUT in this case.
glEnable(GL_DEPTH_TEST);
// Buffers being managed by external application i.e. GLUT in this case.
glClearColor(0.87f, 0.88f, 0.91f, 1.0f); // Set background color to gray
and opaque
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the color
buffer
glFlush(); // Render now
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
//interactor->Render();
externalVTKWidget->GetRenderWindow()->Render();
glutSwapBuffers();
}
Thanks,
Elaine
--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkRenderWindowInteractor-with-custom-render-loop-tp5744540.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list