Commit 6de46c18 authored by Kyle Lutz's avatar Kyle Lutz

Add composite data display attributes

This adds new functionality to specify renderering attributes
for specific blocks in a multi-block dataset.

This also updates the vtkCompositePainter to make use of the
composite data attributes if available.

Change-Id: I3240564f2570ab41530421aefd1a3bb77fbfa628
parent 42cea1fc
......@@ -16,6 +16,7 @@ set(Module_SRCS
vtkClipPlanesPainter.cxx
vtkCoincidentTopologyResolutionPainter.cxx
vtkColorTransferFunction.cxx
vtkCompositeDataDisplayAttributes.cxx
vtkCompositePainter.cxx
vtkCompositePolyDataMapper2.cxx
vtkCompositePolyDataMapper.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCompositeDataDisplayAttributes.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkCompositeDataDisplayAttributes.h"
#include "vtkObjectFactory.h"
vtkStandardNewMacro(vtkCompositeDataDisplayAttributes)
vtkCompositeDataDisplayAttributes::vtkCompositeDataDisplayAttributes()
{
}
vtkCompositeDataDisplayAttributes::~vtkCompositeDataDisplayAttributes()
{
}
void vtkCompositeDataDisplayAttributes::SetBlockVisibility(unsigned int flat_index, bool visible)
{
this->BlockVisibilities[flat_index] = visible;
}
bool vtkCompositeDataDisplayAttributes::GetBlockVisibility(unsigned int flat_index) const
{
std::map<unsigned int, bool>::const_iterator iter =
this->BlockVisibilities.find(flat_index);
if(iter != this->BlockVisibilities.end())
{
return iter->second;
}
else
{
// default to true
return true;
}
}
bool vtkCompositeDataDisplayAttributes::HasBlockVisibility(unsigned int flat_index) const
{
return this->BlockVisibilities.count(flat_index) == size_t(1);
}
void vtkCompositeDataDisplayAttributes::RemoveBlockVisibility(unsigned int flat_index)
{
this->BlockVisibilities.erase(flat_index);
}
void vtkCompositeDataDisplayAttributes::RemoveBlockVisibilites()
{
this->BlockVisibilities.clear();
}
void vtkCompositeDataDisplayAttributes::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCompositeDataDisplayAttributes.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkCompositeDataDisplayAttributes - rendering attributes for a
// multi-block dataset.
// .SECTION Description
// The vtkCompositeDataDisplayAttributes class stores display attributes
// for individual blocks in a multi-block dataset.
#ifndef __vtkCompositeDataDisplayAttributes_h
#define __vtkCompositeDataDisplayAttributes_h
#include "vtkRenderingCoreModule.h" // for export macro
#include "vtkObject.h"
#include <map> // for std::map
class VTKRENDERINGCORE_EXPORT vtkCompositeDataDisplayAttributes : public vtkObject
{
public:
static vtkCompositeDataDisplayAttributes* New();
vtkTypeMacro(vtkCompositeDataDisplayAttributes, vtkObject)
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Set/get the visibility for the block with \p flat_index.
void SetBlockVisibility(unsigned int flat_index, bool visible);
bool GetBlockVisibility(unsigned int flat_index) const;
// Description:
// Returns true if the block with the given flat_index has a visiblity
// set.
bool HasBlockVisibility(unsigned int flat_index) const;
// Description:
// Removes the block visibility flag for the block with flat_index.
void RemoveBlockVisibility(unsigned int flat_index);
// Description:
// Removes all block visibility flags. The effectively sets the visibility
// for all blocks to true.
void RemoveBlockVisibilites();
protected:
vtkCompositeDataDisplayAttributes();
~vtkCompositeDataDisplayAttributes();
private:
vtkCompositeDataDisplayAttributes(const vtkCompositeDataDisplayAttributes&); // Not implemented.
void operator=(const vtkCompositeDataDisplayAttributes&); // Not implemented.
private:
std::map<unsigned int, bool> BlockVisibilities;
};
#endif // __vtkCompositeDataDisplayAttributes_h
......@@ -20,6 +20,9 @@
#include "vtkHardwareSelector.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkPolyData.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkCompositeDataDisplayAttributes.h"
vtkStandardNewMacro(vtkCompositePainter);
//----------------------------------------------------------------------------
......@@ -54,33 +57,115 @@ void vtkCompositePainter::RenderInternal(vtkRenderer* renderer,
}
vtkHardwareSelector* selector = renderer->GetSelector();
vtkCompositeDataIterator* iter = input->NewIterator();
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
if(this->CompositeDataDisplayAttributes)
{
// render using the composite data attributes
unsigned int flat_index = 0;
bool visible = true;
this->RenderBlock(renderer, actor, typeflags, forceCompileOnly, input, flat_index, visible);
}
else
{
vtkDataObject* dobj = iter->GetCurrentDataObject();
if (dobj)
// render using the multi-block structure itself
vtkCompositeDataIterator* iter = input->NewIterator();
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
if (selector)
vtkDataObject* dobj = iter->GetCurrentDataObject();
if (dobj)
{
selector->BeginRenderProp();
// If hardware selection is in progress, we need to pass the composite
// index to the selection framework,
selector->RenderCompositeIndex(iter->GetCurrentFlatIndex());
if (selector)
{
selector->BeginRenderProp();
// If hardware selection is in progress, we need to pass the composite
// index to the selection framework,
selector->RenderCompositeIndex(iter->GetCurrentFlatIndex());
}
this->DelegatePainter->SetInput(dobj);
this->OutputData = dobj;
this->Superclass::RenderInternal(renderer, actor, typeflags,
forceCompileOnly);
this->OutputData = 0;
if (selector)
{
selector->EndRenderProp();
}
}
}
iter->Delete();
}
}
this->DelegatePainter->SetInput(dobj);
this->OutputData = dobj;
this->Superclass::RenderInternal(renderer, actor, typeflags,
forceCompileOnly);
this->OutputData = 0;
//-----------------------------------------------------------------------------
void vtkCompositePainter::RenderBlock(vtkRenderer *renderer,
vtkActor *actor,
unsigned long typeflags,
bool forceCompileOnly,
vtkDataObject *dobj,
unsigned int &flat_index,
bool &visible)
{
vtkHardwareSelector *selector = renderer->GetSelector();
// push display attributes
bool prev_visible = visible;
if(this->CompositeDataDisplayAttributes->HasBlockVisibility(flat_index))
{
visible = this->CompositeDataDisplayAttributes->GetBlockVisibility(flat_index);
}
if (selector)
vtkMultiBlockDataSet *mbds = vtkMultiBlockDataSet::SafeDownCast(dobj);
if(mbds)
{
// recurse down to child blocks
for(unsigned int i = 0; i < mbds->GetNumberOfBlocks(); i++)
{
selector->EndRenderProp();
flat_index++;
this->RenderBlock(renderer, actor, typeflags, forceCompileOnly, mbds->GetBlock(i), flat_index, visible);
}
// pop display attributes
if(this->CompositeDataDisplayAttributes->HasBlockVisibility(flat_index))
{
visible = prev_visible;
}
flat_index++;
}
else if(dobj)
{
// render leaf-node
if(visible)
{
if(selector)
{
selector->BeginRenderProp();
// If hardware selection is in progress, we need to pass the composite
// index to the selection framework,
selector->RenderCompositeIndex(flat_index);
}
this->DelegatePainter->SetInput(dobj);
this->OutputData = dobj;
this->Superclass::RenderInternal(renderer,
actor,
typeflags,
forceCompileOnly);
this->OutputData = 0;
if(selector)
{
selector->EndRenderProp();
}
}
// pop display attributes
if(this->CompositeDataDisplayAttributes->HasBlockVisibility(flat_index))
{
visible = prev_visible;
}
}
}
iter->Delete();
}
//-----------------------------------------------------------------------------
......
......@@ -55,6 +55,14 @@ protected:
virtual void RenderInternal(vtkRenderer* renderer, vtkActor* actor,
unsigned long typeflags, bool forceCompileOnly);
void RenderBlock(vtkRenderer *renderer,
vtkActor *actor,
unsigned long typeflags,
bool forceCompileOnly,
vtkDataObject *dobj,
unsigned int &flat_index,
bool &visible);
vtkDataObject* OutputData;
private:
vtkCompositePainter(const vtkCompositePainter&); // Not implemented.
......
......@@ -19,6 +19,7 @@
#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkCompositeDataSet.h"
#include "vtkCompositeDataDisplayAttributes.h"
#include "vtkCompositePainter.h"
#include "vtkDefaultPainter.h"
#include "vtkDisplayListPainter.h"
......@@ -138,6 +139,78 @@ bool vtkCompositePolyDataMapper2::GetIsOpaque()
return this->Superclass::GetIsOpaque();
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::SetBlockVisibility(unsigned int index, bool visible)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->SetBlockVisibility(index, visible);
this->Modified();
}
}
//----------------------------------------------------------------------------
bool vtkCompositePolyDataMapper2::GetBlockVisibility(unsigned int index) const
{
if(this->CompositeAttributes)
{
return this->CompositeAttributes->GetBlockVisibility(index);
}
else
{
return true;
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::RemoveBlockVisibility(unsigned int index)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockVisibility(index);
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::RemoveBlockVisibilites()
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockVisibilites();
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::SetCompositeDataDisplayAttributes(
vtkCompositeDataDisplayAttributes *attributes)
{
if(this->CompositeAttributes != attributes)
{
this->CompositeAttributes = attributes;
// set composite display attributes on the composite painter
vtkDefaultPainter *defaultPainter =
vtkDefaultPainter::SafeDownCast(this->Painter);
if(defaultPainter)
{
vtkCompositePainter *compositePainter =
defaultPainter->GetCompositePainter();
compositePainter->
SetCompositeDataDisplayAttributes(this->CompositeAttributes);
}
}
}
//----------------------------------------------------------------------------
vtkCompositeDataDisplayAttributes*
vtkCompositePolyDataMapper2::GetCompositeDataDisplayAttributes()
{
return this->CompositeAttributes;
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -24,6 +24,9 @@
#include "vtkRenderingCoreModule.h" // For export macro
#include "vtkPainterPolyDataMapper.h"
#include "vtkSmartPointer.h" // for vtkSmartPointer
class vtkCompositeDataDisplayAttributes;
class VTKRENDERINGCORE_EXPORT vtkCompositePolyDataMapper2 : public vtkPainterPolyDataMapper
{
......@@ -43,6 +46,18 @@ public:
// opaque geometry.
virtual bool GetIsOpaque();
// Description:
// Set/get the composite data set attributes.
void SetCompositeDataDisplayAttributes(vtkCompositeDataDisplayAttributes *attributes);
vtkCompositeDataDisplayAttributes* GetCompositeDataDisplayAttributes();
// Description:
// Set/get the visibility for a block given its flat index.
void SetBlockVisibility(unsigned int index, bool visible);
bool GetBlockVisibility(unsigned int index) const;
void RemoveBlockVisibility(unsigned int index);
void RemoveBlockVisibilites();
//BTX
protected:
vtkCompositePolyDataMapper2();
......@@ -66,6 +81,10 @@ protected:
// Time stamp for computation of bounds.
vtkTimeStamp BoundsMTime;
// Description:
// Composite data set attributes.
vtkSmartPointer<vtkCompositeDataDisplayAttributes> CompositeAttributes;
private:
vtkCompositePolyDataMapper2(const vtkCompositePolyDataMapper2&); // Not implemented.
void operator=(const vtkCompositePolyDataMapper2&); // Not implemented.
......
......@@ -26,6 +26,7 @@
#include "vtkCellData.h"
#include "vtkCommand.h"
#include "vtkCompositeDataDisplayAttributes.h"
#include "vtkDataSet.h"
#include "vtkDebugLeaks.h"
#include "vtkGarbageCollector.h"
......@@ -39,6 +40,7 @@
vtkCxxSetObjectMacro(vtkPainter, Input, vtkDataObject);
vtkCxxSetObjectMacro(vtkPainter, Information, vtkInformation);
vtkCxxSetObjectMacro(vtkPainter, CompositeDataDisplayAttributes, vtkCompositeDataDisplayAttributes)
vtkInformationKeyMacro(vtkPainter, STATIC_DATA, Integer);
vtkInformationKeyMacro(vtkPainter, CONSERVE_MEMORY, Integer);
vtkInformationKeyMacro(vtkPainter, HIGH_QUALITY, Integer);
......@@ -87,6 +89,8 @@ vtkPainter::vtkPainter()
vtkPainter::STATIC_DATA()->Set(this->Information, 0);
vtkPainter::CONSERVE_MEMORY()->Set(this->Information, 0);
vtkPainter::HIGH_QUALITY()->Set(this->Information, 1);
this->CompositeDataDisplayAttributes = 0;
}
//-----------------------------------------------------------------------------
......@@ -106,6 +110,8 @@ vtkPainter::~vtkPainter()
}
this->Timer->Delete();
this->SetCompositeDataDisplayAttributes(0);
}
//-----------------------------------------------------------------------------
......@@ -367,5 +373,14 @@ void vtkPainter::PrintSelf(ostream &os, vtkIndent indent)
os << "(none)" << endl;
}
os << indent << "CompositeDataDisplayAttributes: " ;
if (this->CompositeDataDisplayAttributes)
{
os << endl;
this->CompositeDataDisplayAttributes->PrintSelf(os, indent.GetNextIndent());
}
else
{
os << "(none)" << endl;
}
}
......@@ -46,6 +46,7 @@
class vtkAbstractArray;
class vtkActor;
class vtkCompositeDataDisplayAttributes;
class vtkDataObject;
class vtkDataSet;
class vtkInformation;
......@@ -150,6 +151,13 @@ public:
virtual vtkDataObject* GetOutput()
{ return this->Input; }
// Description:
// Set/get the composite data set display attributes. If set, these attributes
// can be used by the painter to control specific rendering attributes on a
// per-block basis for a multi-block dataset.
void SetCompositeDataDisplayAttributes(vtkCompositeDataDisplayAttributes *attributes);
vtkGetObjectMacro(CompositeDataDisplayAttributes, vtkCompositeDataDisplayAttributes)
//BTX
protected:
vtkPainter();
......@@ -238,6 +246,8 @@ protected:
double TimeToDraw;
vtkTimerLog* Timer;
vtkCompositeDataDisplayAttributes *CompositeDataDisplayAttributes;
vtkWeakPointer<vtkWindow> LastWindow; // Window used for previous render.
// This is not reference counted.
private:
......
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