Skip to content
Snippets Groups Projects
Commit da0126c0 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

Added back in rendering of selected points

This was lost when the point plotting was moved to a dedicated class out
of the vtkChartXYZ class. Restore this behavior, which is used in the
scatter plot matrix animations for example.

Change-Id: I1f69b4d45aef25566f8e8cd644f72245506b975e
parent 9ae3b4c1
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,9 @@
#include "vtkTransform.h"
#include "vtkVector.h"
#include "vtkVectorOperators.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkIdTypeArray.h"
#include "vtkObjectFactory.h"
......@@ -206,12 +209,34 @@ void vtkChartXYZ::PrintSelf(ostream &os, vtkIndent indent)
Superclass::PrintSelf(os, indent);
}
//-----------------------------------------------------------------------------
void vtkChartXYZ::Update()
{
if (this->Link)
{
vtkSelection *selection =
vtkSelection::SafeDownCast(this->Link->GetOutputDataObject(2));
if (selection->GetNumberOfNodes())
{
vtkSelectionNode *node = selection->GetNode(0);
vtkIdTypeArray *idArray =
vtkIdTypeArray::SafeDownCast(node->GetSelectionList());
for (size_t i = 0; i < this->Plots.size(); ++i)
{
this->Plots[i]->SetSelection(idArray);
}
}
}
}
//-----------------------------------------------------------------------------
bool vtkChartXYZ::Paint(vtkContext2D *painter)
{
if (!this->Visible)
return false;
this->Update();
// Get the 3D context.
vtkContext3D *context = painter->GetContext3D();
......
......@@ -90,6 +90,10 @@ public:
// the scene. Default value is true.
void SetFitToScene(bool b);
// Description:
// Perform any updates to the item that may be necessary before rendering.
virtual void Update();
// Description:
// Paint event for the chart, called whenever the chart needs to be drawn.
virtual bool Paint(vtkContext2D *painter);
......
......@@ -17,6 +17,7 @@
#include "vtkChartXYZ.h"
#include "vtkDataArray.h"
#include "vtkIdTypeArray.h"
#include "vtkLookupTable.h"
#include "vtkObjectFactory.h"
#include "vtkPen.h"
......@@ -326,6 +327,23 @@ std::string vtkPlot3D::GetZAxisLabel()
return this->ZAxisLabel;
}
// ----------------------------------------------------------------------------
void vtkPlot3D::SetSelection(vtkIdTypeArray *id)
{
if (id == this->Selection)
{
return;
}
this->Selection = id;
this->Modified();
}
// ----------------------------------------------------------------------------
vtkIdTypeArray* vtkPlot3D::GetSelection()
{
return this->Selection.GetPointer();
}
// ----------------------------------------------------------------------------
std::vector<vtkVector3f> vtkPlot3D::GetPoints()
{
......
......@@ -33,6 +33,7 @@
class vtkChartXYZ;
class vtkDataArray;
class vtkIdTypeArray;
class vtkTable;
class vtkUnsignedCharArray;
class vtkPen;
......@@ -92,6 +93,11 @@ public:
// Get the bounding cube surrounding the currently rendered data points.
std::vector<vtkVector3f> GetDataBounds() { return this->DataBounds; }
// Description:
// Set/get the selection array for the plot.
virtual void SetSelection(vtkIdTypeArray *id);
virtual vtkIdTypeArray* GetSelection();
//BTX
protected:
vtkPlot3D();
......@@ -142,6 +148,10 @@ protected:
// A bounding cube surrounding the currently rendered data points.
std::vector<vtkVector3f> DataBounds;
// Description:
// Selected indices for the table the plot is rendering
vtkSmartPointer<vtkIdTypeArray> Selection;
private:
vtkPlot3D(const vtkPlot3D &); // Not implemented.
void operator=(const vtkPlot3D &); // Not implemented.
......
......@@ -21,6 +21,7 @@
#include "vtkPen.h"
#include "vtkPlotPoints3D.h"
#include "vtkUnsignedCharArray.h"
#include "vtkIdTypeArray.h"
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotPoints3D)
......@@ -30,6 +31,8 @@ vtkPlotPoints3D::vtkPlotPoints3D()
{
this->Pen->SetWidth(5);
this->Pen->SetColor(0, 0, 0, 255);
this->SelectedPen->SetWidth(7);
this->SelectedPen->SetColor(255, 50, 0, 150);
}
//-----------------------------------------------------------------------------
......@@ -81,5 +84,29 @@ bool vtkPlotPoints3D::Paint(vtkContext2D *painter)
}
// Now add some decorations for our selected points...
if (this->Selection && this->Selection->GetNumberOfTuples())
{
if (this->Selection->GetMTime() > this->SelectedPointsBuildTime ||
this->GetMTime() > this->SelectedPointsBuildTime)
{
size_t nSelected(static_cast<size_t>(this->Selection->GetNumberOfTuples()));
this->SelectedPoints.reserve(nSelected);
for (int i = 0; i < nSelected; ++i)
{
this->SelectedPoints.push_back(this->Points[this->Selection->GetValue(i)]);
}
this->SelectedPointsBuildTime.Modified();
}
// Now to render the selected points.
if (!this->SelectedPoints.empty())
{
context->ApplyPen(this->SelectedPen.GetPointer());
context->DrawPoints(this->SelectedPoints[0].GetData(),
static_cast<int>(this->SelectedPoints.size()));
}
}
return true;
}
......@@ -47,6 +47,16 @@ protected:
vtkPlotPoints3D();
~vtkPlotPoints3D();
// Description:
// The selected points.
std::vector<vtkVector3f> SelectedPoints;
// Description:
// The selected points.
vtkTimeStamp SelectedPointsBuildTime;
vtkNew<vtkPen> SelectedPen;
private:
vtkPlotPoints3D(const vtkPlotPoints3D &); // Not implemented.
void operator=(const vtkPlotPoints3D &); // Not implemented.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment