[vtkusers] opengl2 vtk rendering back end and Qt
Ken Martin
ken.martin at kitware.com
Wed Dec 21 08:03:33 EST 2016
If your LUT has transparent values then VTK will assume your object is
transparent and turn of depth testing so that alpha blending can be used.
If you want your object to be treated as Opaque even though it may have
translucent values then set SetForceOpaque(true) ala
actor->SetForceOpaque(true);
On Tue, Dec 20, 2016 at 9:21 PM, Alexandre Boucher <afboucher at gmail.com>
wrote:
> Quick update.
>
> The depth issue manifests itself when I set a alpha value to the NaN.
>
> lut->SetNanColor(0.803, 0.788, 0.788, 0.8); // depth issue
> lut->SetNanColor(0.803, 0.788, 0.788,1.0); // NO depth issue
>
> Not sure the reason, but the problem is right there.
>
> see the code below:
>
> #include <QApplication>
> #include <QFrame>
> #include <QLabel>
> #include <QVBoxLayout>
> #include <QVTKWidget.h>
> #include <vtkImageData.h>
> #include <vtkSmartPointer.h>
> #include <vtkFloatArray.h>
> #include <vtkCellData.h>
> #include <vtkRenderWindow.h>
> #include <vtkActor.h>
> #include <vtkDataSetMapper.h>
> #include <vtkRenderer.h>
> #include <vtkProperty.h>
> #include <vtkThreshold.h>
> #include <vtkPassThrough.h>
> #include <vtkLookupTable.h>
>
>
>
> int main(int argc, char *argv[])
> {
> QApplication app(argc, argv);
>
> vtkSmartPointer<vtkImageData> im_data = vtkSmartPointer<vtkImageData>:
> :New();
> im_data->SetDimensions(21, 21, 21);
> im_data->SetSpacing(1.0, 1.0, 1.0);
> im_data->SetOrigin(0.0, 0.0, 0.0);
>
>
> vtkSmartPointer<vtkFloatArray> data = vtkSmartPointer<vtkFloatArray>
> ::New();
> data->SetNumberOfValues(20 * 20 * 20);
> for (int i = 0; i < data->GetNumberOfValues(); ++i) {
> data->SetValue(i, (float)i/20.0/20./20.0);
> }
> im_data->GetCellData()->SetScalars(data);
>
> vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::
> New();
>
> vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<
> vtkDataSetMapper>::New();
> mapper->SetInputData(im_data);
>
> vtkSmartPointer<vtkProperty> vtk_property =
> vtkSmartPointer<vtkProperty>::New();
>
> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
> actor->SetMapper(mapper);
> renderer->AddActor(actor);
>
> vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<
> vtkLookupTable>::New();
> int n_colors = 8;
> lut->SetNumberOfTableValues(n_colors);
> lut->Build();
>
> for (int i = 0; i < n_colors; i++) {
> lut->SetTableValue(i, 1.0-(0.125*i), 0.125*i, 0.125*i, 1.0);
> }
> lut->SetRampToLinear();
> // lut->SetNanColor(0.803, 0.788, 0.788, 1.0);
> lut->SetNanColor(0.803, 0.788, 0.788, 0.8);
> mapper->SetScalarRange(0, 2);
> mapper->SetLookupTable(lut);
> mapper->Modified();
> QFrame* frame = new QFrame();
> frame->setLayout(new QVBoxLayout(frame));
> frame->layout()->addWidget(new QLabel("TEST TEST TEST TEST ... ...
> TEST"));
> QVTKWidget* vtk_widget = new QVTKWidget(frame);
> frame->layout()->addWidget(vtk_widget);
> vtk_widget->GetRenderWindow()->AddRenderer(renderer);
>
> frame->show();
> return app.exec();
>
> }
>
>
>
>
> On Tue, Dec 20, 2016 at 6:17 PM, Alexandre Boucher <afboucher at gmail.com>
> wrote:
>
>> Sorry, This is on Windows 10, NVIDIA GTX 1080 (but tried with a few
>> older NVIDIA card).
>>
>> I have been looking at it in more details today without success. The
>> QSurfaceFormat approach mentioned above did not work.
>>
>> I tried to isolate the issue in a stand alone code but could not
>> reproduce the depth issue. The closest I have been in isolating the
>> problem is by not setting the look up table to the mapper, in that case the
>> imageData is displayed correctly (no depth issue).
>>
>> without these two lines, I do not have depth issue.
>> mapper->SetScalarRange(cmap_->lower_bound(), cmap_->upper_bound());
>> mapper->SetLookupTable(cmap_->color_table());
>>
>> I'll further dig into that and let you know if I get closer to any
>> solution. That same code is working fine on opengl1 backend.
>>
>> Thank you all for the help
>>
>>
>> On Tue, Dec 20, 2016 at 5:42 PM, Marcus D. Hanwell <
>> marcus.hanwell at kitware.com> wrote:
>>
>>> On Tue, Dec 20, 2016 at 12:47 AM, Alexandre Boucher <afboucher at gmail.com>
>>> wrote:
>>> >
>>> > I am having a problem using the opengl2 backend with QVTKWidget (I
>>> tried Qt 5.4 to 5.7 and vtk 7.0 and 7.1). When looking at a simple
>>> vtkImageData for instance some of the faces of the grid are not properly
>>> displayed, see image below. Everything works fine with the opengl1 backend.
>>> >
>>> > I also try using QVTKWidget2, but I am getting a crash when the widget
>>> call OpenGLInitState().
>>> >
>>> > Is there a trick to use Qt and opengl2?
>>> >
>>> You don't mention what OS/graphics card you are using. I have been
>>> tracking a problem with OpenGL2 and Mesa/Intel DRI driver (based on
>>> Mesa) with Qt 5. It looks just like this, no working depth buffer. I
>>> proposed a patch that made it work, but it made the NVIDIA-based Linux
>>> systems segfault.
>>>
>>> I am hoping that we can come up with something that will work on both,
>>> but I haven't had time to revisit it since I looked at it in November.
>>> I can dig up the merge request if this sounds like your set up.
>>>
>>> Marcus
>>>
>>
>>
>
> _______________________________________________
> 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
>
>
--
Ken Martin PhD
Chairman & CFO
Kitware Inc.
28 Corporate Drive
Clifton Park NY 12065
518 371 3971
This communication, including all attachments, contains confidential and
legally privileged information, and it is intended only for the use of the
addressee. Access to this email by anyone else is unauthorized. If you are
not the intended recipient, any disclosure, copying, distribution or any
action taken in reliance on it is prohibited and may be unlawful. If you
received this communication in error please notify us immediately and
destroy the original message. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20161221/8c803175/attachment.html>
More information about the vtkusers
mailing list