Commit 4e259972 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit Committed by Kitware Robot
Browse files

Merge topic 'chart-selection-representation'

35235114 Refactoring SelectionRepresentation for charts.
899fac34 Fix ResetDisplay for charts.
parents 7d7546cf 35235114
......@@ -35,6 +35,7 @@ set (Module_SRCS
vtkAMRStreamingVolumeRepresentation.cxx
vtkCaveSynchronizedRenderers.cxx
vtkChartRepresentation.cxx
vtkChartSelectionRepresentation.cxx
vtkClientServerMoveData.cxx
vtkCompositeRepresentation.cxx
vtkCompositeSliceRepresentation.cxx
......
......@@ -19,6 +19,7 @@
#include "vtkBlockDeliveryPreprocessor.h"
#include "vtkChart.h"
#include "vtkChartNamedOptions.h"
#include "vtkChartSelectionRepresentation.h"
#include "vtkClientServerMoveData.h"
#include "vtkCommand.h"
#include "vtkContextView.h"
......@@ -34,21 +35,17 @@
#include "vtkPVMergeTables.h"
#include "vtkReductionFilter.h"
#include "vtkScatterPlotMatrix.h"
#include "vtkSelectionDeliveryFilter.h"
#include "vtkSelection.h"
#include "vtkSelectionSerializer.h"
#include "vtkTable.h"
#include <vtksys/ios/sstream>
vtkStandardNewMacro(vtkChartRepresentation);
vtkCxxSetObjectMacro(vtkChartRepresentation, Options, vtkChartNamedOptions);
//----------------------------------------------------------------------------
vtkChartRepresentation::vtkChartRepresentation()
{
this->SetNumberOfInputPorts(2);
this->SelectionRepresentation = 0;
vtkNew<vtkChartSelectionRepresentation> selectionRepr;
this->SetSelectionRepresentation(selectionRepr.GetPointer());
this->AnnLink = vtkAnnotationLink::New();
this->Options = 0;
this->Preprocessor = vtkBlockDeliveryPreprocessor::New();
......@@ -70,8 +67,6 @@ vtkChartRepresentation::vtkChartRepresentation()
this->DeliveryFilter = vtkClientServerMoveData::New();
this->DeliveryFilter->SetOutputDataType(VTK_TABLE);
this->SelectionDeliveryFilter = vtkSelectionDeliveryFilter::New();
this->EnableServerSideRendering = false;
}
......@@ -79,14 +74,28 @@ vtkChartRepresentation::vtkChartRepresentation()
vtkChartRepresentation::~vtkChartRepresentation()
{
this->SetOptions(0);
this->AnnLink->Delete();
this->Preprocessor->Delete();
this->CacheKeeper->Delete();
this->ReductionFilter->Delete();
this->DeliveryFilter->Delete();
this->SetSelectionRepresentation(NULL);
}
this->SelectionDeliveryFilter->Delete();
//----------------------------------------------------------------------------
void vtkChartRepresentation::SetSelectionRepresentation(
vtkChartSelectionRepresentation* repr)
{
if (this->SelectionRepresentation && (repr != this->SelectionRepresentation))
{
this->SelectionRepresentation->SetChartRepresentation(NULL);
}
vtkSetObjectBodyMacro(SelectionRepresentation,
vtkChartSelectionRepresentation, repr);
if (repr)
{
repr->SetChartRepresentation(this);
}
}
//----------------------------------------------------------------------------
......@@ -121,6 +130,8 @@ bool vtkChartRepresentation::AddToView(vtkView* view)
}
this->Options->SetTableVisibility(this->GetVisibility());
}
view->AddRepresentation(this->SelectionRepresentation);
return true;
}
......@@ -140,6 +151,7 @@ bool vtkChartRepresentation::RemoveFromView(vtkView* view)
this->Options->SetPlotMatrix(0);
}
this->ContextView = 0;
view->RemoveRepresentation(this->SelectionRepresentation);
return true;
}
......@@ -152,11 +164,6 @@ int vtkChartRepresentation::FillInputPortInformation(
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject");
info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
}
else
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkSelection");
info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
}
return 1;
}
......@@ -183,6 +190,7 @@ vtkTable* vtkChartRepresentation::GetLocalOutput()
int vtkChartRepresentation::RequestData(vtkInformation* request,
vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
cout << "vtkChartRepresentation::RequestData" << endl;
if (vtkProcessModule::GetProcessType() == vtkProcessModule::PROCESS_RENDER_SERVER)
{
return this->Superclass::RequestData(request, inputVector, outputVector);
......@@ -190,7 +198,6 @@ int vtkChartRepresentation::RequestData(vtkInformation* request,
this->ReductionFilter->Modified();
this->DeliveryFilter->Modified();
this->SelectionDeliveryFilter->Modified();
// remove the "cached" delivered data.
if (this->LocalOutput)
......@@ -208,8 +215,7 @@ int vtkChartRepresentation::RequestData(vtkInformation* request,
if (inputVector[0]->GetNumberOfInformationObjects()==1)
{
this->Preprocessor->SetInputConnection(
this->GetInternalOutputPort(0));
this->Preprocessor->SetInputData(vtkDataObject::GetData(inputVector[0], 0));
this->Preprocessor->Update();
this->DeliveryFilter->SetInputConnection(this->ReductionFilter->GetOutputPort());
this->ReductionFilter->Update();
......@@ -245,74 +251,6 @@ int vtkChartRepresentation::RequestData(vtkInformation* request,
this->Options->SetTable(this->GetLocalOutput());
}
// Now deliver the selection.
vtkSmartPointer<vtkSelection> sel;
if (inputVector[1]->GetNumberOfInformationObjects()==1)
{
this->SelectionDeliveryFilter->SetInputConnection(
this->GetInternalOutputPort(1, 0));
this->SelectionDeliveryFilter->Update();
if (this->EnableServerSideRendering)
{
if (numProcs > 1)
{
vtkMultiProcessController* controller = pm->GetGlobalController();
if (myId == 0)
{
sel = vtkSelection::SafeDownCast(
this->GetInternalOutputPort(1, 0)->GetProducer()->
GetOutputDataObject(0));
vtksys_ios::ostringstream res;
vtkSelectionSerializer::PrintXML(res, vtkIndent(), 1, sel);
// Send the size of the string.
int size = static_cast<int>(res.str().size());
controller->Broadcast(&size, 1, 0);
// Send the XML string.
controller->Broadcast(
const_cast<char*>(res.str().c_str()), size, 0);
}
else
{
int size = 0;
controller->Broadcast(&size, 1, 0);
char* xml = new char[size+1];
// Get the string itself.
controller->Broadcast(xml, size, 0);
xml[size] = 0;
// Parse the XML.
sel = vtkSmartPointer<vtkSelection>::New();
vtkSelectionSerializer::Parse(xml, sel);
delete[] xml;
}
}
}
else
{
sel = vtkSelection::SafeDownCast(
this->SelectionDeliveryFilter->GetOutputDataObject(0));
}
}
else
{
this->SelectionDeliveryFilter->RemoveAllInputs();
this->SelectionDeliveryFilter->Update();
sel = vtkSelection::SafeDownCast(
this->SelectionDeliveryFilter->GetOutputDataObject(0));
}
if (this->ContextView)
{
if(vtkChart *chart = vtkChart::SafeDownCast(this->ContextView->GetContextItem()))
{
this->AnnLink->SetCurrentSelection(sel);
chart->SetAnnotationLink(this->AnnLink);
}
}
return this->Superclass::RequestData(request, inputVector, outputVector);
}
......@@ -330,6 +268,7 @@ void vtkChartRepresentation::MarkModified()
// Cleanup caches when not using cache.
this->CacheKeeper->RemoveAllCaches();
}
this->SelectionRepresentation->MarkModified();
this->Superclass::MarkModified();
}
......@@ -341,6 +280,8 @@ void vtkChartRepresentation::SetVisibility(bool visible)
{
this->Options->SetTableVisibility(visible);
}
this->SelectionRepresentation->SetVisibility(
this->GetVisibility() && visible);
}
//----------------------------------------------------------------------------
......@@ -390,3 +331,11 @@ void vtkChartRepresentation::SetCompositeDataSetIndex(unsigned int v)
this->Preprocessor->SetCompositeDataSetIndex(v);
this->MarkModified();
}
//----------------------------------------------------------------------------
unsigned int vtkChartRepresentation::Initialize(
unsigned int minId, unsigned int maxId)
{
minId = this->SelectionRepresentation->Initialize(minId, maxId);
return this->Superclass::Initialize(minId, maxId);
}
......@@ -31,7 +31,6 @@
#include "vtkWeakPointer.h" // needed for vtkWeakPointer
#include "vtkSmartPointer.h" // needed for vtkSmartPointer
class vtkAnnotationLink;
class vtkBlockDeliveryPreprocessor;
class vtkClientServerMoveData;
class vtkChartNamedOptions;
......@@ -40,6 +39,7 @@ class vtkPVContextView;
class vtkReductionFilter;
class vtkSelectionDeliveryFilter;
class vtkTable;
class vtkChartSelectionRepresentation;
class VTKPVCLIENTSERVERCORERENDERING_EXPORT vtkChartRepresentation : public vtkPVDataRepresentation
{
......@@ -48,6 +48,11 @@ public:
vtkTypeMacro(vtkChartRepresentation, vtkPVDataRepresentation);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// These must only be set during initialization before adding the
// representation to any views or calling Update().
void SetSelectionRepresentation(vtkChartSelectionRepresentation*);
// Description:
// Set the options object. This must be done before any other state is
// updated.
......@@ -83,6 +88,12 @@ public:
void SetFieldAssociation(int);
void SetCompositeDataSetIndex(unsigned int);
// Description:
// Override because of internal selection representations that need to be
// initilized as well.
virtual unsigned int Initialize(unsigned int minIdAvailable, unsigned int maxIdAvailable);
//BTX
protected:
vtkChartRepresentation();
......@@ -135,13 +146,11 @@ protected:
vtkWeakPointer<vtkPVContextView> ContextView;
vtkChartNamedOptions* Options;
vtkSelectionDeliveryFilter* SelectionDeliveryFilter;
vtkAnnotationLink* AnnLink;
bool EnableServerSideRendering;
vtkSmartPointer<vtkTable> LocalOutput;
vtkChartSelectionRepresentation* SelectionRepresentation;
private:
vtkChartRepresentation(const vtkChartRepresentation&); // Not implemented
void operator=(const vtkChartRepresentation&); // Not implemented
......
/*=========================================================================
Program: ParaView
Module: vtkChartSelectionRepresentation.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtkChartSelectionRepresentation.h"
#include "vtkChartRepresentation.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMultiProcessController.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkProcessModule.h"
#include "vtkProperty.h"
#include "vtkPVContextView.h"
#include "vtkSelectionDeliveryFilter.h"
#include "vtkSelection.h"
#include "vtkSelectionSerializer.h"
#include <assert.h>
#include <vtksys/ios/sstream>
vtkStandardNewMacro(vtkChartSelectionRepresentation);
//----------------------------------------------------------------------------
vtkChartSelectionRepresentation::vtkChartSelectionRepresentation()
{
this->EnableServerSideRendering = false;
}
//----------------------------------------------------------------------------
vtkChartSelectionRepresentation::~vtkChartSelectionRepresentation()
{
}
//----------------------------------------------------------------------------
void vtkChartSelectionRepresentation::SetChartRepresentation(
vtkChartRepresentation* repr)
{
this->ChartRepresentation = repr;
}
//----------------------------------------------------------------------------
void vtkChartSelectionRepresentation::SetVisibility(bool val)
{
this->Superclass::SetVisibility(val);
}
//----------------------------------------------------------------------------
bool vtkChartSelectionRepresentation::AddToView(vtkView* view)
{
vtkPVContextView* pvview = vtkPVContextView::SafeDownCast(view);
if (pvview)
{
this->View = pvview;
this->EnableServerSideRendering = pvview->InTileDisplayMode();
return true;
}
return false;
}
//----------------------------------------------------------------------------
bool vtkChartSelectionRepresentation::RemoveFromView(vtkView* view)
{
if (view == this->View.GetPointer())
{
this->View = NULL;
this->EnableServerSideRendering = false;
return true;
}
return false;
}
//----------------------------------------------------------------------------
int vtkChartSelectionRepresentation::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkSelection");
info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
return 1;
}
//----------------------------------------------------------------------------
int vtkChartSelectionRepresentation::RequestData(vtkInformation* request,
vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
cout << "vtkChartSelectionRepresentation::RequestData" << endl;
if (vtkProcessModule::GetProcessType() == vtkProcessModule::PROCESS_RENDER_SERVER)
{
return this->Superclass::RequestData(request, inputVector, outputVector);
}
vtkSmartPointer<vtkSelection> localSelection;
if (inputVector[0]->GetNumberOfInformationObjects()==1)
{
vtkSelection* inputSelection = vtkSelection::GetData(inputVector[0], 0);
assert(inputSelection);
vtkNew<vtkSelectionDeliveryFilter> courier;
courier->SetInputDataObject(inputSelection);
courier->Update();
localSelection = vtkSelection::SafeDownCast(courier->GetOutputDataObject(0));
if (this->EnableServerSideRendering)
{
// distribute the selection from the root node to all processes.
vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
int myId = pm->GetPartitionId();
int numProcs = pm->GetNumberOfLocalPartitions();
if (numProcs > 1)
{
vtkMultiProcessController* controller = pm->GetGlobalController();
if (myId == 0)
{
vtksys_ios::ostringstream res;
vtkSelectionSerializer::PrintXML(res, vtkIndent(), 1, inputSelection);
// Send the size of the string.
int size = static_cast<int>(res.str().size());
controller->Broadcast(&size, 1, 0);
// Send the XML string.
controller->Broadcast(
const_cast<char*>(res.str().c_str()), size, 0);
localSelection = inputSelection;
}
else
{
int size = 0;
controller->Broadcast(&size, 1, 0);
char* xml = new char[size+1];
// Get the string itself.
controller->Broadcast(xml, size, 0);
xml[size] = 0;
// Parse the XML.
vtkNew<vtkSelection> sel;
vtkSelectionSerializer::Parse(xml, sel.GetPointer());
delete[] xml;
localSelection = sel.GetPointer();
}
}
}
}
else
{
vtkNew<vtkSelectionDeliveryFilter> courier;
courier->Update();
localSelection = vtkSelection::SafeDownCast(courier->GetOutputDataObject(0));
}
if (this->View)
{
this->View->SetSelection(this->ChartRepresentation, localSelection);
}
return this->Superclass::RequestData(request, inputVector, outputVector);
}
//----------------------------------------------------------------------------
void vtkChartSelectionRepresentation::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "ChartRepresentation: "
<< this->ChartRepresentation.GetPointer() << endl;
os << indent << "EnableServerSideRendering: " <<
this->EnableServerSideRendering << endl;
}
/*=========================================================================
Program: ParaView
Module: vtkChartSelectionRepresentation.h
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 vtkChartSelectionRepresentation - representation for a cube-axes.
// .SECTION Description
// vtkChartSelectionRepresentation is a representation for the Cube-Axes that shows a
// bounding box with labels around any input dataset.
#ifndef __vtkChartSelectionRepresentation_h
#define __vtkChartSelectionRepresentation_h
#include "vtkPVClientServerCoreRenderingModule.h" //needed for exports
#include "vtkPVDataRepresentation.h"
#include "vtkWeakPointer.h" // needed for vtkWeakPointer.
#include "vtkSmartPointer.h" // needed for vtkWeakPointer.
class vtkChartRepresentation;
class vtkPVContextView;
class VTKPVCLIENTSERVERCORERENDERING_EXPORT vtkChartSelectionRepresentation : public vtkPVDataRepresentation
{
public:
static vtkChartSelectionRepresentation* New();
vtkTypeMacro(vtkChartSelectionRepresentation, vtkPVDataRepresentation);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// This needs to be called on all instances of vtkChartSelectionRepresentation when
// the input is modified.
virtual void MarkModified()
{ this->Superclass::MarkModified(); }
// Description:
// Set visibility of the representation.
virtual void SetVisibility(bool visible);
// Description:
// Get/Set the chart representation for which this is a selection
// representation. This is not reference counted.
void SetChartRepresentation(vtkChartRepresentation* repr);
//BTX
protected:
vtkChartSelectionRepresentation();
~vtkChartSelectionRepresentation();
virtual int FillInputPortInformation(int port, vtkInformation* info);
virtual int RequestData(vtkInformation*,
vtkInformationVector** inputVector, vtkInformationVector*);
// Description:
// Adds the representation to the view. This is called from
// vtkView::AddRepresentation(). Subclasses should override this method.
// Returns true if the addition succeeds.
virtual bool AddToView(vtkView* view);
// Description:
// Removes the representation to the view. This is called from
// vtkView::RemoveRepresentation(). Subclasses should override this method.
// Returns true if the removal succeeds.
virtual bool RemoveFromView(vtkView* view);
vtkWeakPointer<vtkPVContextView> View;
vtkWeakPointer<vtkChartRepresentation> ChartRepresentation;
// Flag updated in AddToView to indicate if the configuration requires
// server-side rendering.
bool EnableServerSideRendering;
private:
vtkChartSelectionRepresentation(const vtkChartSelectionRepresentation&); // Not implemented
void operator=(const vtkChartSelectionRepresentation&); // Not implemented
//ETX
};
#endif
......@@ -28,7 +28,6 @@ vtkCxxSetObjectMacro(vtkPVCompositeRepresentation, CubeAxesRepresentation,
//----------------------------------------------------------------------------
vtkPVCompositeRepresentation::vtkPVCompositeRepresentation()
{
this->SetNumberOfInputPorts(2);
this->SelectionRepresentation = vtkSelectionRepresentation::New();
this->CubeAxesRepresentation = vtkCubeAxesRepresentation::New();
......@@ -71,21 +70,13 @@ void vtkPVCompositeRepresentation::SetSelectionVisibility(bool visible)
//----------------------------------------------------------------------------
void vtkPVCompositeRepresentation::SetInputConnection(int port, vtkAlgorithmOutput* input)
{
if (port == 0)
{
this->CubeAxesRepresentation->SetInputConnection(0, input);
this->Superclass::SetInputConnection(0, input);
}
else if (port == 1)
{
this->SelectionRepresentation->SetInputConnection(0, input);
}
this->CubeAxesRepresentation->SetInputConnection(port, input);
this->Superclass::SetInputConnection(port, input);
}
//----------------------------------------------------------------------------
void vtkPVCompositeRepresentation::SetInputConnection(vtkAlgorithmOutput* input)