[vtkusers] vtkRenderWindowInteractor with custom render loop
Elaine Jiang
elainejiang8 at gmail.com
Mon Aug 21 13:49:22 EDT 2017
Hi Sankhesh,
Yes, I want users to be able to interact with the VTK objects with a VR
wand. I can test whether the wand works by temporarily using keyboard
buttons to zoom, pan, rotate, and select the VTK objects. I would need to
use a vtkRenderWindowInteractor in this case, right?
Thanks,
Elaine
On Mon, Aug 21, 2017 at 1:28 PM, Sankhesh Jhaveri <
sankhesh.jhaveri at kitware.com> wrote:
> Hi Elaine,
>
> By using the ExternalVTKWidget and all the vtkExternal* classes, you get
> interaction by default. The external widget ensures that the VTK camera is
> synchronized with the VR camera. Is there some special kind of interaction
> that you are looking for?
>
> Sankhesh
>
>
> On Mon, Aug 21, 2017 at 12:27 PM elainejiang8 <elainejiang8 at gmail.com>
> wrote:
>
>> 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.
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/
>> opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
> --
> Sankhesh Jhaveri *Sr. Research & Development Engineer* | Kitware
> <http://www.kitware.com/> | (518) 881-4417
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170821/a385c00b/attachment.html>
More information about the vtkusers
mailing list