Commit 74a6ad91 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Add support for scalar opacity when scalars are no being mapped.

When scalar coloring, if the mapper decides that it can directly render the
input scalar array as RGBA, or LA etc., then the mapper should use the opacity
specified in the scalar array for rendering. However, that was not the case. The
mappper simply ignored the scalar opacity.

This patch fixes the issue when not mapping scalars. It's possible that when
mapping scalars, the LUT would return a range for alpha. That case is not
handled by this.
parent 73ab66ba
......@@ -132,6 +132,10 @@ int vtkActor::GetIsOpaque()
if(this->Mapper!=0 && this->Mapper->GetLookupTable()!=0)
{
result=this->Mapper->GetLookupTable()->IsOpaque();
if (result)
{
result = this->Mapper->GetIsOpaque()? 1: 0;
}
}
}
return result;
......
......@@ -55,7 +55,6 @@ public:
// Release the underlying resources associated with this mapper
void ReleaseGraphicsResources(vtkWindow *);
protected:
vtkCompositePolyDataMapper();
~vtkCompositePolyDataMapper();
......
......@@ -30,6 +30,7 @@
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkScalarsToColorsPainter.h"
#include "vtkSmartPointer.h"
vtkStandardNewMacro(vtkCompositePolyDataMapper2);
//----------------------------------------------------------------------------
......@@ -97,6 +98,37 @@ void vtkCompositePolyDataMapper2::ComputeBounds()
// this->BoundsMTime.Modified();
}
//-----------------------------------------------------------------------------
bool vtkCompositePolyDataMapper2::GetIsOpaque()
{
vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(
this->GetInputDataObject(0, 0));
if (this->ScalarVisibility &&
this->ColorMode == VTK_COLOR_MODE_DEFAULT && input)
{
vtkSmartPointer<vtkCompositeDataIterator> iter;
iter.TakeReference(input->NewIterator());
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
vtkPolyData *pd = vtkPolyData::SafeDownCast(iter->GetCurrentDataObject());
if (pd)
{
int cellFlag;
vtkDataArray* scalars = this->GetScalars(pd,
this->ScalarMode, this->ArrayAccessMode, this->ArrayId,
this->ArrayName, cellFlag);
if (scalars && scalars->IsA("vtkUnsignedCharArray") &&
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
{
return false;
}
}
}
}
return this->Superclass::GetIsOpaque();
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -31,6 +31,17 @@ public:
vtkTypeMacro(vtkCompositePolyDataMapper2, vtkPainterPolyDataMapper);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Returns if the mapper does not expect to have translucent geometry. This
// may happen when using ScalarMode is set to not map scalars i.e. render the
// scalar array directly as colors and the scalar array has opacity i.e. alpha
// component. Note that even if this method returns true, an actor may treat
// the geometry as translucent since a constant translucency is set on the
// property, for example.
// Overridden to use the actual data and ScalarMode to determine if we have
// opaque geometry.
virtual bool GetIsOpaque();
//BTX
protected:
vtkCompositePolyDataMapper2();
......
......@@ -364,6 +364,15 @@ public:
// Return the light-model color mode.
const char *GetScalarMaterialModeAsString();
// Description:
// Returns if the mapper does not expect to have translucent geometry. This
// may happen when using ColorMode is set to not map scalars i.e. render the
// scalar array directly as colors and the scalar array has opacity i.e. alpha
// component. Default implementation simply returns true. Note that even if
// this method returns true, an actor may treat the geometry as translucent
// since a constant translucency is set on the property, for example.
virtual bool GetIsOpaque() { return true; }
// Description:
// WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
// DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS
......
......@@ -390,6 +390,31 @@ void vtkPainterPolyDataMapper::ComputeBounds()
}
}
//-----------------------------------------------------------------------------
bool vtkPainterPolyDataMapper::GetIsOpaque()
{
if (this->ScalarVisibility &&
this->ColorMode == VTK_COLOR_MODE_DEFAULT)
{
vtkPolyData* input =
vtkPolyData::SafeDownCast(this->GetInputDataObject(0, 0));
if (input)
{
int cellFlag;
vtkDataArray* scalars = this->GetScalars(input,
this->ScalarMode, this->ArrayAccessMode, this->ArrayId,
this->ArrayName, cellFlag);
if (scalars && scalars->IsA("vtkUnsignedCharArray") &&
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
{
return false;
}
}
}
return this->Superclass::GetIsOpaque();
}
//-----------------------------------------------------------------------------
void vtkPainterPolyDataMapper::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -91,6 +91,17 @@ public:
virtual bool GetSupportsSelection()
{ return (this->SelectionPainter != 0); }
// Description:
// Returns if the mapper does not expect to have translucent geometry. This
// may happen when using ScalarMode is set to not map scalars i.e. render the
// scalar array directly as colors and the scalar array has opacity i.e. alpha
// component. Note that even if this method returns true, an actor may treat
// the geometry as translucent since a constant translucency is set on the
// property, for example.
// Overridden to use the actual data and ScalarMode to determine if we have
// opaque geometry.
virtual bool GetIsOpaque();
protected:
vtkPainterPolyDataMapper();
~vtkPainterPolyDataMapper();
......
......@@ -226,14 +226,11 @@ void vtkPrimitivePainter::RenderInternal(vtkRenderer* renderer,
if (c)
{
idx |= VTK_PDM_COLORS;
if (!fieldScalars && c->GetName())
if (!c->GetName())
{
// In the future, I will look at the number of components.
// All paths will have to handle 3 component colors.
// When using field colors, the c->GetName() condition is not valid,
// since field data arrays always have names. In that case we
// forfeit the speed improvement gained by using RGB colors instead
// or RGBA.
// If the array has a name (hence directly coming with MAP_SCALARS),
// it means that it has 4 components and we should use the alpha.
// Otherwise, we know that alpha is constant so we ignore it.
idx |= VTK_PDM_OPAQUE_COLORS;
}
if (cellScalars)
......
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