Commit caae8297 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

Cleaning up pqDisplayPolicy.

Deprecating pqDisplayPolicy for the most part.
vtkSMParaViewPipelineControllerWithRendering is now the class that
manages all the logic in pqDisplayPolicy instead.

Updating vtkSMViewProxy API to add CanDisplayData() which is needed for
vtkSMParaViewPipelineControllerWithRendering to work correctly.

Fixed usage of pqDisplayPolicy is core ParaView. Plugins and examples
still need to be updated.

Change-Id: I4188acaceedde2e0fe8e927e142b9a62615515f9
parent 1b918c8f
......@@ -19,6 +19,7 @@
#include "vtkProcessModuleAutoMPI.h"
#include "vtkSISourceProxy.h"
#include "vtkSMInputArrayDomain.h"
#include "vtkSMParaViewPipelineControllerWithRendering.h"
#include <cassert>
......@@ -40,7 +41,7 @@ vtkPVGeneralSettings::vtkPVGeneralSettings()
AutoApplyActiveOnly(false),
DefaultViewType(NULL),
TransferFunctionResetMode(vtkPVGeneralSettings::GROW_ON_APPLY),
ScalarBarMode(vtkPVGeneralSettings::AUTOMATICALLY_SHOW_AND_HIDE_SCALAR_BARS),
ScalarBarMode(vtkPVGeneralSettings::AUTOMATICALLY_HIDE_SCALAR_BARS),
CacheGeometryForAnimation(false),
AnimationGeometryCacheLimit(0)
{
......@@ -152,6 +153,33 @@ void vtkPVGeneralSettings::SetAnimationGeometryCacheLimit(unsigned long val)
}
}
//----------------------------------------------------------------------------
void vtkPVGeneralSettings::SetScalarBarMode(int val)
{
switch (val)
{
case AUTOMATICALLY_HIDE_SCALAR_BARS:
vtkSMParaViewPipelineControllerWithRendering::SetShowScalarBarOnShow(false);
vtkSMParaViewPipelineControllerWithRendering::SetHideScalarBarOnHide(true);
break;
case AUTOMATICALLY_SHOW_AND_HIDE_SCALAR_BARS:
vtkSMParaViewPipelineControllerWithRendering::SetShowScalarBarOnShow(true);
vtkSMParaViewPipelineControllerWithRendering::SetHideScalarBarOnHide(true);
break;
default:
vtkSMParaViewPipelineControllerWithRendering::SetShowScalarBarOnShow(false);
vtkSMParaViewPipelineControllerWithRendering::SetHideScalarBarOnHide(false);
}
if (val != this->ScalarBarMode)
{
this->ScalarBarMode = val;
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkPVGeneralSettings::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -100,7 +100,7 @@ public:
MANUAL_SCALAR_BARS=2
};
vtkGetMacro(ScalarBarMode, int);
vtkSetMacro(ScalarBarMode, int);
void SetScalarBarMode(int);
// Description:
// Set when animation geometry caching is enabled.
......
......@@ -143,10 +143,10 @@ void vtkSMComparativeViewProxy::MarkDirty(vtkSMProxy* modifiedProxy)
}
//----------------------------------------------------------------------------
vtkSMRepresentationProxy* vtkSMComparativeViewProxy::CreateDefaultRepresentation(
vtkSMProxy* src, int outputport)
const char* vtkSMComparativeViewProxy::GetRepresentationType(
vtkSMSourceProxy* src, int outputport)
{
return this->GetRootView()->CreateDefaultRepresentation(src, outputport);
return this->GetRootView()->GetRepresentationType(src, outputport);
}
//----------------------------------------------------------------------------
......
......@@ -40,12 +40,6 @@ public:
// Updates the data pipelines for all visible representations.
virtual void Update();
// Description:
// Create a default representation for the given source proxy.
// Returns a new proxy.
// Overridden to forward the call to the internal root view proxy.
virtual vtkSMRepresentationProxy* CreateDefaultRepresentation(vtkSMProxy*, int);
// Description:
// Get all the internal views. The views should only be used to be layed out
// by the GUI. It's not recommended to directly change the properties of the
......@@ -70,12 +64,17 @@ public:
// This all marks all consumers as dirty.
virtual void MarkDirty(vtkSMProxy* modifiedProxy);
// Description:
// Overridden to forward the call to the internal root view proxy.
virtual const char* GetRepresentationType(
vtkSMSourceProxy* producer, int outputPort);
protected:
vtkSMComparativeViewProxy();
~vtkSMComparativeViewProxy();
void InvokeConfigureEvent();
void InvokeConfigureEvent();
// Description:
virtual void CreateVTKObjects();
......
......@@ -25,13 +25,17 @@
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPVContextView.h"
#include "vtkPVDataInformation.h"
#include "vtkPVXMLElement.h"
#include "vtkProcessModule.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMUtilities.h"
#include "vtkStructuredData.h"
#include "vtkWeakPointer.h"
#include "vtkWindowToImageFilter.h"
#include "vtkProcessModule.h"
//****************************************************************************
// vtkSMContextViewInteractorStyle makes it possible for us to call
......@@ -271,6 +275,42 @@ void vtkSMContextViewProxy::ResetDisplay()
}
}
//----------------------------------------------------------------------------
bool vtkSMContextViewProxy::CanDisplayData(vtkSMSourceProxy* producer, int outputPort)
{
if (!this->Superclass::CanDisplayData(producer, outputPort))
{
return false;
}
if (producer->GetHints() &&
producer->GetHints()->FindNestedElementByName("Plotable"))
{
return true;
}
vtkPVDataInformation* dataInfo = producer->GetDataInformation(outputPort);
if (dataInfo->DataSetTypeIsA("vtkTable"))
{
return true;
}
// also accept 1D structured datasets.
if (dataInfo->DataSetTypeIsA("vtkImageData") ||
dataInfo->DataSetTypeIsA("vtkRectilinearGrid"))
{
int extent[6];
dataInfo->GetExtent(extent);
int temp[6]={0, 0, 0, 0, 0, 0};
int dimensionality = vtkStructuredData::GetDataDimension(
vtkStructuredData::SetExtent(extent, temp));
if (dimensionality == 1)
{
return true;
}
}
return false;
}
//----------------------------------------------------------------------------
void vtkSMContextViewProxy::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -54,6 +54,15 @@ public:
// be accessed
virtual vtkRenderWindow* GetRenderWindow();
// Description:
// Overridden to report to applications that producers producing non-table
// datasets are only viewable if they have the "Plottable" hint. This avoid
// applications from inadvertently showing large data in charts.
// CreateDefaultRepresentation() will still work without regard for this
// Plottable hint.
virtual bool CanDisplayData(vtkSMSourceProxy* producer, int outputPort);
//BTX
protected:
vtkSMContextViewProxy();
......
......@@ -39,10 +39,10 @@ vtkSMMultiSliceViewProxy::~vtkSMMultiSliceViewProxy()
}
//----------------------------------------------------------------------------
vtkSMRepresentationProxy* vtkSMMultiSliceViewProxy::CreateDefaultRepresentation(
vtkSMProxy* source, int opport)
const char* vtkSMMultiSliceViewProxy::GetRepresentationType(
vtkSMSourceProxy* producer, int outputPort)
{
if (!source)
if (!producer)
{
return 0;
}
......@@ -50,33 +50,33 @@ vtkSMRepresentationProxy* vtkSMMultiSliceViewProxy::CreateDefaultRepresentation(
assert("Session should be valid" && this->GetSession());
vtkSMSessionProxyManager* pxm = this->GetSessionProxyManager();
// Update with time to avoid domains updating without time later.
vtkSMSourceProxy* sproxy = vtkSMSourceProxy::SafeDownCast(source);
if (sproxy)
{
double view_time = vtkSMPropertyHelper(this, "ViewTime").GetAsDouble();
sproxy->UpdatePipeline(view_time);
}
// Choose which type of representation proxy to create.
vtkSMProxy* prototype = pxm->GetPrototypeProxy("representations",
"CompositeMultiSliceRepresentation");
vtkSMInputProperty* pp = vtkSMInputProperty::SafeDownCast(
prototype->GetProperty("Input"));
pp->RemoveAllUncheckedProxies();
pp->AddUncheckedInputConnection(source, opport);
pp->AddUncheckedInputConnection(producer, outputPort);
bool sg = (pp->IsInDomains()>0);
pp->RemoveAllUncheckedProxies();
if (sg)
return sg? "CompositeMultiSliceRepresentation" : NULL;
}
//----------------------------------------------------------------------------
vtkSMRepresentationProxy* vtkSMMultiSliceViewProxy::CreateDefaultRepresentation(
vtkSMProxy* proxy, int outputPort)
{
vtkSMRepresentationProxy* repr = this->Superclass::CreateDefaultRepresentation(
proxy,outputPort);
if (repr)
{
vtkSMRepresentationProxy* repr = vtkSMRepresentationProxy::SafeDownCast(
pxm->NewProxy("representations", "CompositeMultiSliceRepresentation"));
this->InitDefaultSlices(sproxy, opport);
this->InitDefaultSlices(vtkSMSourceProxy::SafeDownCast(proxy), outputPort);
return repr;
}
// Currently only images can be shown
vtkErrorMacro("This view only supports Multi-Slice representation.");
// vtkErrorMacro("This view only supports Multi-Slice representation.");
return 0;
}
......
......@@ -32,21 +32,29 @@ public:
vtkTypeMacro(vtkSMMultiSliceViewProxy, vtkSMRenderViewProxy);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Create a default representation for the given source proxy.
// Returns a new proxy.
virtual vtkSMRepresentationProxy* CreateDefaultRepresentation(vtkSMProxy*, int);
// Description:
// Similar to IsSelectionAvailable(), however, on failure returns the
// error message otherwise 0.
virtual const char* IsSelectVisiblePointsAvailable();
// Description:
// Overridden to set initial default slices when a representation is created.
// Not sure that's the best way to do this, but leaving the logic unchanged in
// this pass.
virtual vtkSMRepresentationProxy* CreateDefaultRepresentation(
vtkSMProxy* proxy, int outputPort);
// Description:
// Overridden to forward the call to the internal root view proxy.
virtual const char* GetRepresentationType(
vtkSMSourceProxy* producer, int outputPort);
//BTX
protected:
vtkSMMultiSliceViewProxy();
~vtkSMMultiSliceViewProxy();
// Description:
// Use the center of the source to initialize the view with three orthogonal
// slices in x, y, z.
......
......@@ -16,11 +16,79 @@
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkSMPVRepresentationProxy.h"
#include "vtkPVDataInformation.h"
#include "vtkPVXMLElement.h"
#include "vtkSmartPointer.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMPVRepresentationProxy.h"
#include "vtkSMSessionProxyManager.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMTransferFunctionManager.h"
#include "vtkSMViewProxy.h"
#include <cassert>
namespace
{
//---------------------------------------------------------------------------
const char* vtkFindViewTypeFromHints(vtkPVXMLElement* hints, const int outputPort)
{
if (!hints)
{
return NULL;
}
for (unsigned int cc=0, max=hints->GetNumberOfNestedElements(); cc < max; cc++)
{
vtkPVXMLElement* child = hints->GetNestedElement(cc);
if (child && child->GetName() && strcmp(child->GetName(), "View") == 0)
{
int port;
// If port exists, then it must match the port number for this port.
if (child->GetScalarAttribute("port", &port) && (port != outputPort))
{
continue;
}
if (const char* viewtype = child->GetAttribute("type"))
{
return viewtype;
}
}
}
return NULL;
}
//---------------------------------------------------------------------------
bool vtkTreatDataAsText(vtkPVXMLElement* hints, const int outputPort)
{
if (!hints)
{
return false;
}
for (unsigned int cc=0, max=hints->GetNumberOfNestedElements(); cc < max; cc++)
{
vtkPVXMLElement* child = hints->GetNestedElement(cc);
if (child && child->GetName() && strcmp(child->GetName(), "OutputPort") == 0)
{
int port;
// If port exists, then it must match the port number for this port.
if (child->GetScalarAttribute("port", &port) && (port != outputPort))
{
continue;
}
if (const char* type = child->GetAttribute("type"))
{
return (strcmp(type, "text") == 0);
}
}
}
return false;
}
}
vtkStandardNewMacro(vtkSMParaViewPipelineControllerWithRendering);
bool vtkSMParaViewPipelineControllerWithRendering::ShowScalarBarOnShow = false;
bool vtkSMParaViewPipelineControllerWithRendering::HideScalarBarOnHide = true;
vtkObjectFactoryNewMacro(vtkSMParaViewPipelineControllerWithRendering);
//----------------------------------------------------------------------------
vtkSMParaViewPipelineControllerWithRendering::vtkSMParaViewPipelineControllerWithRendering()
{
......@@ -31,6 +99,18 @@ vtkSMParaViewPipelineControllerWithRendering::~vtkSMParaViewPipelineControllerWi
{
}
//----------------------------------------------------------------------------
void vtkSMParaViewPipelineControllerWithRendering::SetShowScalarBarOnShow(bool val)
{
vtkSMParaViewPipelineControllerWithRendering::ShowScalarBarOnShow = val;
}
//----------------------------------------------------------------------------
void vtkSMParaViewPipelineControllerWithRendering::SetHideScalarBarOnHide(bool val)
{
vtkSMParaViewPipelineControllerWithRendering::HideScalarBarOnHide = val;
}
//----------------------------------------------------------------------------
bool vtkSMParaViewPipelineControllerWithRendering::RegisterRepresentationProxy(vtkSMProxy* proxy)
{
......@@ -65,6 +145,222 @@ bool vtkSMParaViewPipelineControllerWithRendering::RegisterRepresentationProxy(v
return true;
}
//----------------------------------------------------------------------------
vtkSMProxy* vtkSMParaViewPipelineControllerWithRendering::Show(
vtkSMSourceProxy* producer, int outputPort, vtkSMViewProxy* view)
{
if (producer == NULL || producer->GetNumberOfOutputPorts() <= outputPort)
{
vtkErrorMacro("Invalid producer (" << producer << ") or outputPort ("
<< outputPort << ")");
return NULL;
}
if (view == NULL)
{
view = this->ShowInPreferredView(producer, outputPort, NULL);
return (view? view->FindRepresentation(producer, outputPort) : NULL);
}
// find is there's already a representation in this view.
if (vtkSMProxy* repr = view->FindRepresentation(producer, outputPort))
{
vtkSMPropertyHelper(repr, "Visibility").Set(1);
repr->UpdateVTKObjects();
if (vtkSMParaViewPipelineControllerWithRendering::ShowScalarBarOnShow)
{
vtkSMPVRepresentationProxy::SetScalarBarVisibility(repr, view, true);
}
return repr;
}
double time = vtkSMPropertyHelper(view, "ViewTime").GetAsDouble();
producer->UpdatePipeline(time);
// Since no repr exists, create a new one if possible.
if (vtkSMProxy* repr = view->CreateDefaultRepresentation(producer, outputPort))
{
this->PreInitializeProxy(repr);
vtkSMPropertyHelper(repr, "Visibility").Set(1);
vtkSMPropertyHelper(repr, "Input").Set(producer, outputPort);
this->PostInitializeProxy(repr);
this->RegisterRepresentationProxy(repr);
repr->UpdateVTKObjects();
vtkSMPropertyHelper(view, "Representations").Add(repr);
view->UpdateVTKObjects();
repr->FastDelete();
if (vtkSMParaViewPipelineControllerWithRendering::ShowScalarBarOnShow)
{
vtkSMPVRepresentationProxy::SetScalarBarVisibility(repr, view, true);
}
return repr;
}
// give up.
return NULL;
}
//----------------------------------------------------------------------------
vtkSMProxy* vtkSMParaViewPipelineControllerWithRendering::Hide(
vtkSMSourceProxy* producer, int outputPort, vtkSMViewProxy* view)
{
if (producer == NULL || producer->GetNumberOfOutputPorts() <= outputPort)
{
vtkErrorMacro("Invalid producer (" << producer << ") or outputPort ("
<< outputPort << ")");
return NULL;
}
if (view == NULL)
{
// already hidden, I guess :).
return NULL;
}
// find is there's already a representation in this view.
if (vtkSMProxy* repr = view->FindRepresentation(producer, outputPort))
{
vtkSMPropertyHelper(repr, "Visibility").Set(0);
repr->UpdateVTKObjects();
if (vtkSMParaViewPipelineControllerWithRendering::HideScalarBarOnHide)
{
vtkNew<vtkSMTransferFunctionManager> tmgr;
tmgr->UpdateScalarBars(view, vtkSMTransferFunctionManager::HIDE_UNUSED_SCALAR_BARS);
}
return repr;
}
return NULL;
}
//----------------------------------------------------------------------------
bool vtkSMParaViewPipelineControllerWithRendering::GetVisibility(
vtkSMSourceProxy* producer, int outputPort, vtkSMViewProxy* view)
{
if (producer == NULL || producer->GetNumberOfOutputPorts() <= outputPort)
{
return false;
}
if (view == NULL)
{
return false;
}
if (vtkSMRepresentationProxy* repr = view->FindRepresentation(producer, outputPort))
{
return vtkSMPropertyHelper(repr, "Visibility").GetAsInt() != 0;
}
return false;
}
//----------------------------------------------------------------------------
vtkSMViewProxy* vtkSMParaViewPipelineControllerWithRendering::ShowInPreferredView(
vtkSMSourceProxy* producer, int outputPort, vtkSMViewProxy* view)
{
if (producer == NULL || producer->GetNumberOfOutputPorts() <= outputPort)
{
vtkErrorMacro("Invalid producer (" << producer << ") or outputPort ("
<< outputPort << ")");
return NULL;
}
vtkSMSessionProxyManager* pxm = producer->GetSessionProxyManager();
if (const char* preferredViewType = this->GetPreferredViewType(producer, outputPort))
{
if (// no view is specified.
view == NULL ||
// the "view" is not of the preferred type.
strcmp(preferredViewType, view->GetXMLName()) != 0)
{
vtkSmartPointer<vtkSMProxy> targetView;
targetView.TakeReference(pxm->NewProxy("views", preferredViewType));
if (vtkSMViewProxy* preferredView = vtkSMViewProxy::SafeDownCast(targetView))
{
this->InitializeProxy(preferredView);
this->RegisterViewProxy(preferredView);
if (this->Show(producer, outputPort, preferredView) == NULL)
{
vtkErrorMacro("Data cannot be shown in the preferred view!!");
return NULL;
}
return preferredView;
}
else
{
vtkErrorMacro(
"Failed to create preferred view (" << preferredViewType << ")");
return NULL;
}
}
else
{
assert(view);
if (!this->Show(producer, outputPort, view))
{
vtkErrorMacro("Data cannot be shown in the preferred view!!");
return NULL;
}
return view;
}
}
else if (view)
{
// If there's no preferred view, check if active view can show the data. If
// so, show it in that view.
if (view->CanDisplayData(producer, outputPort))
{
if (this->Show(producer, outputPort, view))
{
return view;
}
vtkErrorMacro("View should have been able to show the data, "
"but it failed to do so. This may point to a development bug.");
return NULL;
}
}
// No preferred view is found and active view cannot show the data,
// ParaView's default behavior is to create a render view, in that case.
vtkSmartPointer<vtkSMProxy> renderView;
renderView.TakeReference(pxm->NewProxy("views", "RenderView"));
if (vtkSMViewProxy* preferredView = vtkSMViewProxy::SafeDownCast(renderView))
{
this->InitializeProxy(preferredView);
this->RegisterViewProxy(preferredView);