[vtkusers] translucent trouble with external OpenGL render window

Mike Guttman mguttman at yahoo.com
Wed Mar 9 04:54:45 EST 2016


Greetings,



Having trouble with a simple set of polygon data, read from an STL file, rendering in an ExternalVTKWidget.  I am migrating from VTK 6.2 with OpenGL1 back-end, and having trouble with 6.3 (OpenGL1 or 2) and 7.0.

I've tried a few configurations using ExternalVTKWidget and deriving a class from QOpenGLWidget:
With 6.2/OpenGL1, the polydata looks how I expect, with some normals, lighting depth sorting and transparency (see 1st picture).  In 6.3/OpenGL1, the surface was not visible.  With 6.3/OpenGL2, surface quality is bad, as if some normals or translucency info is gone or ignored (see 2nd picture).  Same result with 7.0.

I then tried QVTKWidget2 and the surface looked fine.  But I need more control over the rendering process which I can't get with this class.  For example, rendering other things before or after the render() call, and having my own control over mouse behavior.  I also want to display the same rendering in multiple windows.  Deriving a class from QOpenGLWidget seems to offer the control I need, and seems more amenable to context sharing.
So I'm wondering what is going wrong with the vtkExternalOpenGLRenderWindow that it's not rendering the surface as in QVTKWidget2.  Is there some initialization step missing?  Hopefully it is something silly I missed.

Here are relevant code snippets:

In initializeGL():
  externalVTKWidget = vtkSmartPointer<ExternalVTKWidget>::New();
  mRenWin = externalVTKWidget->GetRenderWindow();
  mRenWin->Start();

  vtkSmartPointer<vtkCallbackCommand> callback = vtkSmartPointer<vtkCallbackCommand>::New();
  callback->SetClientData(this);
  callback->SetCallback(makeCurrentCallback);
  mRenWin->AddObserver(vtkCommand::WindowMakeCurrentEvent, callback);

In resizeGL():
  mRenWin->SetSize(w, h);  // not needed anymore, I think
  renderer = externalVTKWidget->AddRenderer();

This is how the polydata is read, nothing unusual here, I think:
    vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
    reader->SetFileName(fileName.c_str());
    reader->Update();
    polydata = reader->GetOutput();
    vtkSmartPointer<vtkPolyDataNormals> normalGenerator = vtkSmartPointer<vtkPolyDataNormals>::New();
    normalGenerator->SetInputData(polydata);
    vtkSmartPointer<vtkDepthSortPolyData> depthSort = vtkSmartPointer<vtkDepthSortPolyData>::New();
    depthSort->SetInputConnection(normalGenerator->GetOutputPort());
    depthSort->SetDirectionToBackToFront();
    depthSort->SetVector(1, 1, 1);
    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(depthSort->GetOutputPort());
    mapper->ScalarVisibilityOff();
    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetOpacity(0.7);
    mRenWin->renderer->AddActor(actor);

I'm using depth sorter b/c I was having trouble getting depth peeling working.  This is what got me started trying to migrate.

BTW, the VTK folks seem to say that QVTKWidget2 is the way to go for the future of VTK within Qt.  However, it is derived from QGLWidget, which the Qt folks say is deprecated.  I wonder what is going to happen here.

Thank you in advance for any help you can offer,
Mike
PS: 1st picture is the way it's supposed to look (as I get in 6.2/OpenGL1).  2nd picture is the way it's looking in 6.3/OpenGL2 and 7.0.





  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160309/82a5f349/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtk6.3-opengl2-externwidget.jpg
Type: image/jpeg
Size: 4851 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160309/82a5f349/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtk6.2-opengl1.jpg
Type: image/jpeg
Size: 6794 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160309/82a5f349/attachment-0001.jpg>


More information about the vtkusers mailing list