1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*=========================================================================
Program: ParaView
Module: vtkPVParallelCoordinatesRepresentation.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 "vtkPVParallelCoordinatesRepresentation.h"
#include "vtkChartParallelCoordinates.h"
#include "vtkCSVExporter.h"
#include "vtkObjectFactory.h"
#include "vtkPen.h"
#include "vtkPlot.h"
#include "vtkPVContextView.h"
#include "vtkTable.h"
#include "vtkStdString.h"
#include <map>
#include <string>
class vtkPVParallelCoordinatesRepresentation::vtkInternals
{
public:
// Refer to vtkPVPlotMatrixRepresentation when time comes to update this
// representation to respect the order in which the series are listed.
std::map<std::string, bool> SeriesVisibilities;
};
vtkStandardNewMacro(vtkPVParallelCoordinatesRepresentation);
//----------------------------------------------------------------------------
vtkPVParallelCoordinatesRepresentation::vtkPVParallelCoordinatesRepresentation()
: LineThickness(1),
LineStyle(0),
Opacity(0.1)
{
this->Internals = new vtkInternals();
this->Color[0] = this->Color[1] = this->Color[2] = 0.0;
}
//----------------------------------------------------------------------------
vtkPVParallelCoordinatesRepresentation::~vtkPVParallelCoordinatesRepresentation()
{
delete this->Internals;
this->Internals = NULL;
}
//----------------------------------------------------------------------------
void vtkPVParallelCoordinatesRepresentation::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
bool vtkPVParallelCoordinatesRepresentation::AddToView(vtkView* view)
{
if (!this->Superclass::AddToView(view))
{
return false;
}
if (this->GetChart())
{
this->GetChart()->SetVisible(this->GetVisibility());
}
return true;
}
//----------------------------------------------------------------------------
bool vtkPVParallelCoordinatesRepresentation::RemoveFromView(vtkView* view)
{
if (this->GetChart())
{
this->GetChart()->GetPlot(0)->SetInputData(0);
this->GetChart()->SetVisible(false);
}
return this->Superclass::RemoveFromView(view);
}
//----------------------------------------------------------------------------
vtkChartParallelCoordinates* vtkPVParallelCoordinatesRepresentation::GetChart()
{
if (this->ContextView)
{
return vtkChartParallelCoordinates::SafeDownCast(
this->ContextView->GetContextItem());
}
return 0;
}
//----------------------------------------------------------------------------
void vtkPVParallelCoordinatesRepresentation::SetVisibility(bool visible)
{
this->Superclass::SetVisibility(visible);
vtkChartParallelCoordinates* chart = this->GetChart();
if (chart && !visible)
{
// Refer to vtkChartRepresentation::PrepareForRendering() documentation to
// know why this is cannot be done in PrepareForRendering();
chart->SetVisible(false);
}
this->Modified();
}
//----------------------------------------------------------------------------
void vtkPVParallelCoordinatesRepresentation::SetSeriesVisibility(
const char* series, bool visibility)
{
assert(series != NULL);
this->Internals->SeriesVisibilities[series] = visibility;
this->Modified();
}
//----------------------------------------------------------------------------
void vtkPVParallelCoordinatesRepresentation::ClearSeriesVisibilities()
{
this->Internals->SeriesVisibilities.clear();
this->Modified();
}
//----------------------------------------------------------------------------
void vtkPVParallelCoordinatesRepresentation::PrepareForRendering()
{
this->Superclass::PrepareForRendering();
vtkChartParallelCoordinates* chart = this->GetChart();
vtkTable* plotInput = this->GetLocalOutput();
chart->SetVisible(plotInput != NULL && this->GetVisibility());
chart->GetPlot(0)->GetPen()->SetWidth(this->LineThickness);
chart->GetPlot(0)->GetPen()->SetLineType(this->LineStyle);
chart->GetPlot(0)->GetPen()->SetColorF(this->Color[0], this->Color[1], this->Color[2]);
chart->GetPlot(0)->GetPen()->SetOpacityF(this->Opacity);
if (plotInput)
{
// only consider the first vtkTable.
chart->GetPlot(0)->SetInputData(plotInput);
vtkIdType numCols = plotInput->GetNumberOfColumns();
for (vtkIdType cc=0; cc < numCols; cc++)
{
std::string name = plotInput->GetColumnName(cc);
std::map<std::string, bool>::iterator iter =
this->Internals->SeriesVisibilities.find(name);
if (iter != this->Internals->SeriesVisibilities.end() &&
iter->second == true)
{
chart->SetColumnVisibility(name, true);
}
else
{
chart->SetColumnVisibility(name, false);
}
}
}
}
//----------------------------------------------------------------------------
bool vtkPVParallelCoordinatesRepresentation::Export(vtkCSVExporter* exporter)
{
vtkChartParallelCoordinates* chart = this->GetChart();
vtkTable* plotInput = this->GetLocalOutput();
if (!plotInput || this->GetVisibility() == false)
{
return false;
}
const vtkIdType numCols = plotInput->GetNumberOfColumns();
for (vtkIdType cc=0; cc < numCols; cc++)
{
std::string name = plotInput->GetColumnName(cc);
if (chart->GetColumnVisibility(name))
{
exporter->AddColumn(plotInput->GetColumnByName(name.c_str()), name.c_str());
}
}
return true;
}
|