Commit f0d13c94 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Make test for tranlucency more robust.

When using direct scalar array mapping (without LUT), test the scalar ranges to
correctly determine if the rendering is translucent or not.

Also cleaned up the vtkActor::GetIsOpaque() test cases.
Reorganized the code to be a bit less error prone.

Change-Id: I006ef61122c4781d627356e90d77aabd0d2b231e
parent 065ee8e3
......@@ -120,25 +120,22 @@ int vtkActor::GetIsOpaque()
// force creation of a property
this->GetProperty();
}
bool is_opaque = (this->Property->GetOpacity() >= 1.0);
int result=this->Property->GetOpacity() >= 1.0;
// are we using an opaque texture, if any?
is_opaque = is_opaque &&
(this->Texture ==NULL || this->Texture->IsTranslucent() == 0);
if(result && this->Texture)
{
result = !this->Texture->IsTranslucent();
}
if(result)
{
if(this->Mapper!=0 && this->Mapper->GetLookupTable()!=0)
{
result=this->Mapper->GetLookupTable()->IsOpaque();
if (result)
{
result = this->Mapper->GetIsOpaque()? 1: 0;
}
}
}
return result;
// are we using an opaque LUT, if any?
is_opaque = is_opaque &&
(this->Mapper == NULL || this->Mapper->GetLookupTable() == NULL ||
this->Mapper->GetLookupTable()->IsOpaque() == 1);
// are we using an opaque scalar array, if any?
is_opaque = is_opaque &&
(this->Mapper == NULL || this->Mapper->GetIsOpaque());
return is_opaque? 1 : 0;
}
......
......@@ -31,6 +31,7 @@
#include "vtkRenderWindow.h"
#include "vtkScalarsToColorsPainter.h"
#include "vtkSmartPointer.h"
#include "vtkUnsignedCharArray.h"
vtkStandardNewMacro(vtkCompositePolyDataMapper2);
//----------------------------------------------------------------------------
......@@ -121,7 +122,15 @@ bool vtkCompositePolyDataMapper2::GetIsOpaque()
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
{
return false;
vtkUnsignedCharArray* colors =
static_cast<vtkUnsignedCharArray*>(scalars);
if ((colors->GetNumberOfComponents() == 4 && colors->GetValueRange(3)[0] < 255) ||
(colors->GetNumberOfComponents() == 2 && colors->GetValueRange(1)[0] < 255))
{
// If the opacity is 255, despite the fact that the user specified
// RGBA, we know that the Alpha is 100% opaque. So treat as opaque.
return false;
}
}
}
}
......
......@@ -408,7 +408,15 @@ bool vtkPainterPolyDataMapper::GetIsOpaque()
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
{
return false;
vtkUnsignedCharArray* colors =
static_cast<vtkUnsignedCharArray*>(scalars);
if ((colors->GetNumberOfComponents() == 4 && colors->GetValueRange(3)[0] < 255) ||
(colors->GetNumberOfComponents() == 2 && colors->GetValueRange(1)[0] < 255))
{
// If the opacity is 255, despite the fact that the user specified
// RGBA, we know that the Alpha is 100% opaque. So treat as opaque.
return false;
}
}
}
}
......
......@@ -226,7 +226,11 @@ void vtkPrimitivePainter::RenderInternal(vtkRenderer* renderer,
if (c)
{
idx |= VTK_PDM_COLORS;
if (c->GetNumberOfComponents() == 4 && c->GetValueRange(3)[0] == 255)
if (
/* RGBA */
(c->GetNumberOfComponents() == 4 && c->GetValueRange(3)[0] == 255) ||
/* LuminanceAlpha */
(c->GetNumberOfComponents() == 2 && c->GetValueRange(1)[0] == 255))
{
// If the opacity is 255, don't bother send the opacity values to OpenGL.
// Treat the colors are opaque colors (which they are).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment