[vtkusers] opengl2 vtk rendering back end and Qt
Alexandre Boucher
afboucher at gmail.com
Tue Dec 20 21:21:36 EST 2016
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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20161220/1b53ad13/attachment.html>
More information about the vtkusers
mailing list