[vtkusers] Transparent NaN color with OpenGL2

Karsten Tausche karsten.tausche at student.hpi.uni-potsdam.de
Thu Sep 17 04:14:40 EDT 2015


Hi,

I'm using vtkLookupTable::SetNanColor to hide cells with NaN scalar
values in my data sets (alpha value set to zero). This worked fine with
the old OpenGL backend, but seems to break the depth test with OpenGL2.

See the attached images: the red/blue quad is always rendered in the
foreground, no matter how you rotate the camera. This happens when you
set the alpha value for NaN-values to something different to 1 for both
planes.

I tested this with today's nightly branch, but it seems to be broken in
the OpenGL2 backend since a while. (On Nvidia, Windows 8.1x64, MSVC2015)

Is this a bug in the new backend, or is there some parameter that I have
to configure for this setup?

Thanks,
Karsten

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pos1 - correct.png
Type: image/png
Size: 11627 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150917/9a9df539/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pos2 - wrong depth order.png
Type: image/png
Size: 12410 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150917/9a9df539/attachment-0001.png>
-------------- next part --------------
#include <cmath>

#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>

#include <vtkLookupTable.h>
#include <vtkFloatArray.h>
#include <vtkCellData.h>
#include <vtkPolyData.h>
#include <vtkPlaneSource.h>


int main()
{
    int resolution = 5;
    vtkSmartPointer<vtkPlaneSource> planeSource = vtkSmartPointer<vtkPlaneSource>::New();
    planeSource->SetXResolution(resolution);
    planeSource->SetYResolution(resolution);
    planeSource->Update();

    vtkPolyData * plane = planeSource->GetOutput();

    vtkSmartPointer<vtkFloatArray> cellData = vtkSmartPointer<vtkFloatArray>::New();
    int numValues = resolution * resolution;
    for (int i = 0; i < numValues; i++)
    {
        float value = (i % (resolution - 1) == 0)
            ? std::nanf(0)
            : float(i) / (numValues - 1);
        cellData->InsertNextValue(value);
    }

    plane->GetCellData()->SetScalars(cellData);


    vtkSmartPointer<vtkLookupTable> lut1 = vtkSmartPointer<vtkLookupTable>::New();
    lut1->SetTableRange(0, 1);
    lut1->SetHueRange(0, 0.5);
    lut1->SetNumberOfTableValues(numValues);
    lut1->Build();
    lut1->SetNanColor(1, 1, 1, 0);

    vtkSmartPointer<vtkLookupTable> lut2 = vtkSmartPointer<vtkLookupTable>::New();
    lut2->SetTableRange(0, 1);
    lut2->SetHueRange(0.5, 1.0);
    lut2->SetNumberOfTableValues(numValues);
    lut2->Build();
    lut2->SetNanColor(1, 1, 1, 0);

    vtkSmartPointer<vtkPolyDataMapper> mapper1 = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper1->SetInputData(plane);
    mapper1->SetLookupTable(lut1);

    vtkSmartPointer<vtkPolyDataMapper> mapper2 = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper2->SetInputData(plane);
    mapper2->SetLookupTable(lut2);

    vtkSmartPointer<vtkActor> actor1 = vtkSmartPointer<vtkActor>::New();
    actor1->SetMapper(mapper1);
    actor1->SetPosition(0, 0, -0.2);
    actor1->GetProperty()->LightingOff();

    vtkSmartPointer<vtkActor> actor2 = vtkSmartPointer<vtkActor>::New();
    actor2->SetMapper(mapper2);
    actor2->SetPosition(0, 0, 0.2);
    actor2->GetProperty()->LightingOff();

    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer(renderer);
    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow(renderWindow);
    renderer->AddActor(actor1);
    renderer->AddActor(actor2);
    renderWindow->Render();
    renderWindowInteractor->Start();

    return EXIT_SUCCESS;
}


More information about the vtkusers mailing list