Commit e43e157d authored by Kyle Lutz's avatar Kyle Lutz

Add per-block color support to vtkCompositePainter

This adds support for per-block coloring to vtkCompositePainter.

Change-Id: I4f357107c06c565ad5878501e573b8e3b9c0668c
parent 7d053afd
......@@ -62,6 +62,52 @@ void vtkCompositeDataDisplayAttributes::RemoveBlockVisibilites()
this->BlockVisibilities.clear();
}
void vtkCompositeDataDisplayAttributes::SetBlockColor(
unsigned int flat_index, const double color[3])
{
this->BlockColors[flat_index] = vtkColor3d(color[0], color[1], color[2]);
}
void vtkCompositeDataDisplayAttributes::GetBlockColor(
unsigned int flat_index, double color[3]) const
{
std::map<unsigned int, vtkColor3d>::const_iterator
iter = this->BlockColors.find(flat_index);
if(iter != this->BlockColors.end())
{
std::copy(&iter->second[0], &iter->second[3], color);
}
}
vtkColor3d vtkCompositeDataDisplayAttributes::GetBlockColor(
unsigned int flat_index) const
{
std::map<unsigned int, vtkColor3d>::const_iterator
iter = this->BlockColors.find(flat_index);
if(iter != this->BlockColors.end())
{
return iter->second;
}
return vtkColor3d();
}
bool vtkCompositeDataDisplayAttributes::HasBlockColor(
unsigned int flat_index) const
{
return this->BlockColors.count(flat_index) == size_t(1);
}
void vtkCompositeDataDisplayAttributes::RemoveBlockColor(
unsigned int flat_index)
{
this->BlockColors.erase(flat_index);
}
void vtkCompositeDataDisplayAttributes::RemoveBlockColors()
{
this->BlockColors.clear();
}
void vtkCompositeDataDisplayAttributes::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
......
......@@ -23,6 +23,7 @@
#include "vtkRenderingCoreModule.h" // for export macro
#include "vtkObject.h"
#include "vtkColor.h" // for vtkColor3d
#include <map> // for std::map
......@@ -52,6 +53,24 @@ public:
// for all blocks to true.
void RemoveBlockVisibilites();
// Description:
// Set/get the color for the block with \p flat_index.
void SetBlockColor(unsigned int flat_index, const double color[3]);
void GetBlockColor(unsigned int flat_index, double color[3]) const;
vtkColor3d GetBlockColor(unsigned int flat_index) const;
// Description:
// Returns true if the block with the given \p flat_index has a color.
bool HasBlockColor(unsigned int flat_index) const;
// Description:
// Removes the block color for the block with \p flat_index.
void RemoveBlockColor(unsigned int flat_index);
// Description:
// Removes all block colors.
void RemoveBlockColors();
protected:
vtkCompositeDataDisplayAttributes();
~vtkCompositeDataDisplayAttributes();
......@@ -62,6 +81,7 @@ private:
private:
std::map<unsigned int, bool> BlockVisibilities;
std::map<unsigned int, vtkColor3d> BlockColors;
};
#endif // __vtkCompositeDataDisplayAttributes_h
......@@ -24,6 +24,19 @@
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiPieceDataSet.h"
#include "vtkCompositeDataDisplayAttributes.h"
#include "vtkPainterDeviceAdapter.h"
#include "vtkRenderWindow.h"
#include "vtkColor.h"
namespace {
void SendColor(vtkPainterDeviceAdapter *adapter, const vtkColor3d &color)
{
const double *c = reinterpret_cast<const double *>(&color[0]);
adapter->SendMaterialProperties(3, VTK_DOUBLE, c, c, c, 0);
}
} // end anonymous namespace
vtkStandardNewMacro(vtkCompositePainter);
//----------------------------------------------------------------------------
......@@ -64,7 +77,15 @@ void vtkCompositePainter::RenderInternal(vtkRenderer* renderer,
// render using the composite data attributes
unsigned int flat_index = 0;
bool visible = true;
this->RenderBlock(renderer, actor, typeflags, forceCompileOnly, input, flat_index, visible);
vtkColor3d color(0.5, 0.5, 0.5);
this->RenderBlock(renderer,
actor,
typeflags,
forceCompileOnly,
input,
flat_index,
visible,
color);
}
else
{
......@@ -106,7 +127,8 @@ void vtkCompositePainter::RenderBlock(vtkRenderer *renderer,
bool forceCompileOnly,
vtkDataObject *dobj,
unsigned int &flat_index,
bool &visible)
bool &visible,
vtkColor3d &color)
{
vtkHardwareSelector *selector = renderer->GetSelector();
......@@ -119,6 +141,21 @@ void vtkCompositePainter::RenderBlock(vtkRenderer *renderer,
pop_visibility = true;
}
bool pop_color = false;
vtkColor3d prev_color = color;
if(this->CompositeDataDisplayAttributes->HasBlockColor(flat_index))
{
color = this->CompositeDataDisplayAttributes->GetBlockColor(flat_index);
pop_color = true;
vtkPainterDeviceAdapter* deviceAdapter =
renderer->GetRenderWindow()->GetPainterDeviceAdapter();
if(deviceAdapter)
{
SendColor(deviceAdapter, color);
}
}
vtkMultiBlockDataSet *mbds = vtkMultiBlockDataSet::SafeDownCast(dobj);
vtkMultiPieceDataSet *mpds = vtkMultiPieceDataSet::SafeDownCast(dobj);
if(mbds || mpds)
......@@ -137,7 +174,8 @@ void vtkCompositePainter::RenderBlock(vtkRenderer *renderer,
forceCompileOnly,
mbds ? mbds->GetBlock(i) : mpds->GetPiece(i),
flat_index,
visible);
visible,
color);
}
}
else if(dobj)
......@@ -179,6 +217,18 @@ void vtkCompositePainter::RenderBlock(vtkRenderer *renderer,
{
visible = prev_visible;
}
if(pop_color)
{
color = prev_color;
vtkPainterDeviceAdapter* deviceAdapter =
renderer->GetRenderWindow()->GetPainterDeviceAdapter();
if(deviceAdapter)
{
SendColor(deviceAdapter, prev_color);
}
}
}
//-----------------------------------------------------------------------------
......
......@@ -25,6 +25,8 @@
#include "vtkRenderingCoreModule.h" // For export macro
#include "vtkPainter.h"
class vtkColor3d;
class VTKRENDERINGCORE_EXPORT vtkCompositePainter : public vtkPainter
{
public:
......@@ -61,7 +63,8 @@ protected:
bool forceCompileOnly,
vtkDataObject *dobj,
unsigned int &flat_index,
bool &visible);
bool &visible,
vtkColor3d &color);
vtkDataObject* OutputData;
private:
......
......@@ -183,6 +183,44 @@ void vtkCompositePolyDataMapper2::RemoveBlockVisibilites()
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::SetBlockColor(unsigned int index, double color[3])
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->SetBlockColor(index, color);
this->Modified();
}
}
//----------------------------------------------------------------------------
double* vtkCompositePolyDataMapper2::GetBlockColor(unsigned int index)
{
(void) index;
return 0;
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::RemoveBlockColor(unsigned int index)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockColor(index);
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::RemoveBlockColors()
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockColors();
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::SetCompositeDataDisplayAttributes(
vtkCompositeDataDisplayAttributes *attributes)
......
......@@ -58,6 +58,13 @@ public:
void RemoveBlockVisibility(unsigned int index);
void RemoveBlockVisibilites();
// Description:
// Set/get the color for a block given its flat index.
void SetBlockColor(unsigned int index, double color[3]);
double* GetBlockColor(unsigned int index);
void RemoveBlockColor(unsigned int index);
void RemoveBlockColors();
//BTX
protected:
vtkCompositePolyDataMapper2();
......
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