Commit 167a9950 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell Committed by Code Review
Browse files

Merge topic 'charts-double-precision' into master

dd403de2 STYLE: Minor fixes to documentation strings
dc73d916 Added scaling to the vtkPlotBar class (and a test)
043de2d1 Changed to fit the VTK style, separated some logic
da970a2b COMP: Fixed warning about signed/unsigned comparison
parents 72dd633d dd403de2
......@@ -14,6 +14,7 @@ vtk_add_test_cxx(
TestBarGraph.cxx
TestBarGraphHorizontal.cxx
TestColorTransferFunction.cxx,-E80
TestChartDouble.cxx
TestChartMatrix.cxx
TestChartUnicode.cxx,-E25
TestChartsOn3D.cxx,-E16
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestChartDouble.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 "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
#include "vtkChartXY.h"
#include "vtkPlot.h"
#include "vtkTable.h"
#include "vtkDoubleArray.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkNew.h"
#include "vtkAxis.h"
//----------------------------------------------------------------------------
int TestChartDouble(int, char *[])
{
// Set up a 2D scene, add an XY chart to it
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(400, 300);
vtkNew<vtkChartXY> chart;
view->GetScene()->AddItem(chart.GetPointer());
// Create a table with some points in it...
vtkNew<vtkTable> table;
vtkNew<vtkDoubleArray> arrX;
arrX->SetName("X");
table->AddColumn(arrX.GetPointer());
vtkNew<vtkDoubleArray> arrC;
arrC->SetName("f1");
table->AddColumn(arrC.GetPointer());
vtkNew<vtkDoubleArray> arrS;
arrS->SetName("f2");
table->AddColumn(arrS.GetPointer());
vtkNew<vtkDoubleArray> arrS2;
arrS2->SetName("f3");
table->AddColumn(arrS2.GetPointer());
// Test charting with a few more points...
int numPoints = 69;
float inc = 7.5 / (numPoints - 1);
table->SetNumberOfRows(numPoints);
for (int i = 0; i < numPoints; ++i)
{
double x(i * inc + 0.2);
table->SetValue(i, 0, x);
table->SetValue(i, 1, 1.0e-80 * (cos(x - 1.0) + sin(x - 3.14 / 4.0)));
table->SetValue(i, 2, 1.0e-80 * sin(x) * 1e-12);
table->SetValue(i, 3, 1.0e-80 * sin(x - 1.0));
}
// Add multiple line plots, setting the colors etc
vtkPlot *line = chart->AddPlot(vtkChart::POINTS);
line->SetInputData(table.GetPointer(), 0, 1);
line = chart->AddPlot(vtkChart::LINE);
line->SetInputData(table.GetPointer(), 0, 2);
// Put this plot in a different corner - it is orders of magnitude smaller.
chart->SetPlotCorner(line, 1);
line = chart->AddPlot(vtkChart::BAR);
line->SetInputData(table.GetPointer(), 0, 3);
chart->GetAxis(vtkAxis::LEFT)->SetTitle("A tiny range");
chart->GetAxis(vtkAxis::BOTTOM)->SetTitle("A normal range");
chart->GetAxis(vtkAxis::RIGHT)->SetTitle("An even tinier range");
// Render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestLinePlot.cxx
Module: TestLinePlot3D.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestLinePlot.cxx
Module: TestLinePlotDouble.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......
......@@ -497,7 +497,7 @@ void vtkChartXY::RecalculatePlotTransforms()
// Now we need to set the scale factor on the plots to ensure they rescale
// their input data when necessary.
vtkVector2d factor(xAxis->GetScalingFactor(), yAxis->GetScalingFactor());
for (vtkIdType j = 0;
for (unsigned int j = 0;
j < this->ChartPrivate->PlotCorners[i]->GetNumberOfItems(); ++j)
{
vtkPlot *plot =
......
......@@ -32,6 +32,7 @@
#include "vtkSmartPointer.h"
#include "vtkColorSeries.h"
#include "vtkStringArray.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
......@@ -45,51 +46,75 @@ namespace {
// Copy the two arrays into the points array
template<class A, class B>
void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previous_points, A *a, B *b,
int n, int logScale)
void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a, B *b,
int n, int logScale, const vtkVector2d &scale)
{
points->SetNumberOfPoints(n);
float* data = static_cast<float*>(points->GetVoidPointer(0));
float* prevData = NULL;
if (previousPoints && static_cast<int>(previousPoints->GetNumberOfPoints()) == n)
{
prevData = static_cast<float*>(previousPoints->GetVoidPointer(0));
}
float prev = 0.0;
for (int i = 0; i < n; ++i)
{
double prev[] = {0.0,0.0};
if (previous_points)
previous_points->GetPoint(i,prev);
points->SetPoint(i,
(logScale & 1) ? log10(static_cast<double>(a[i])) : a[i],
(logScale & 2) ?
log10(static_cast<double>(b[i] + prev[1])) : (b[i] + prev[1]));
if (prevData)
{
prev = prevData[2 * i + 1];
}
A tmpA(a[i] * scale[0]);
B tmpB(b[i] * scale[1]);
data[2 * i] = static_cast<float>((logScale & 1) ?
log10(static_cast<double>(tmpA))
: tmpA);
data[2 * i + 1] = static_cast<float>((logScale & 2) ?
log10(static_cast<double>(tmpB + prev))
: (tmpB + prev));
}
}
// Copy one array into the points array, use the index of that array as x
template<class A>
void CopyToPoints(
vtkPoints2D *points, vtkPoints2D *previous_points, A *a, int n, int logScale)
void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a, int n,
int logScale, const vtkVector2d &scale)
{
points->SetNumberOfPoints(n);
float* data = static_cast<float*>(points->GetVoidPointer(0));
float* prevData = NULL;
if (previousPoints && static_cast<int>(previousPoints->GetNumberOfPoints()) == n)
{
prevData = static_cast<float*>(previousPoints->GetVoidPointer(0));
}
float prev = 0.0;
for (int i = 0; i < n; ++i)
{
double prev[] = {0.0,0.0};
if (previous_points)
previous_points->GetPoint(i,prev);
points->SetPoint(i, i, a[i] + prev[1]);
points->SetPoint(i,
(logScale & 1) ? log10(static_cast<double>(i + 1.0)) : i,
(logScale & 2) ?
log10(static_cast<double>(a[i] + prev[1])) : (a[i] + prev[1]));
if (prevData)
{
prev = prevData[2 * i + 1];
}
A tmpA(a[i] * scale[1]);
data[2 * i] = static_cast<float>((logScale & 1) ?
log10(static_cast<double>(i + 1.0))
: i);
data[2 * i + 1] = static_cast<float>((logScale & 2) ?
log10(static_cast<double>(tmpA + prev))
: (tmpA + prev));
}
}
// Copy the two arrays into the points array
template<class A>
void CopyToPointsSwitch(vtkPoints2D *points, vtkPoints2D *previous_points, A *a,
vtkDataArray *b, int n, int logScale)
void CopyToPointsSwitch(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a,
vtkDataArray *b, int n, int logScale,
const vtkVector2d &scale)
{
switch(b->GetDataType())
{
vtkTemplateMacro(
CopyToPoints(points,previous_points, a,
static_cast<VTK_TT*>(b->GetVoidPointer(0)), n, logScale));
CopyToPoints(points,previousPoints, a,
static_cast<VTK_TT*>(b->GetVoidPointer(0)), n, logScale,
scale));
}
}
......@@ -155,9 +180,8 @@ class vtkPlotBarSegment : public vtkObject {
delete this->SelectionSet;
}
void Configure(
vtkPlotBar* bar, vtkDataArray* x_array, vtkDataArray* y_array,
vtkAxis* x_axis, vtkAxis* y_axis, vtkPlotBarSegment* prev)
void Configure(vtkPlotBar* bar, vtkDataArray* xArray, vtkDataArray* yArray,
vtkAxis* xAxis, vtkAxis* yAxis, vtkPlotBarSegment* prev)
{
this->Bar = bar;
this->Previous = prev;
......@@ -169,27 +193,28 @@ class vtkPlotBarSegment : public vtkObject {
delete this->Sorted;
delete this->SelectionSet;
int logScale =
(x_axis->GetLogScaleActive() ? 1 : 0) +
(y_axis->GetLogScaleActive() ? 2 : 0);
if (x_array)
int logScale = (xAxis->GetLogScaleActive() ? 1 : 0) +
(yAxis->GetLogScaleActive() ? 2 : 0);
if (xArray)
{
switch (x_array->GetDataType())
switch (xArray->GetDataType())
{
vtkTemplateMacro(
CopyToPointsSwitch(this->Points,this->Previous ? this->Previous->Points : 0,
static_cast<VTK_TT*>(x_array->GetVoidPointer(0)),
y_array,x_array->GetNumberOfTuples(), logScale));
static_cast<VTK_TT*>(xArray->GetVoidPointer(0)),
yArray, xArray->GetNumberOfTuples(), logScale,
this->Bar->GetScalingFactor()));
}
}
else
{ // Using Index for X Series
switch (y_array->GetDataType())
switch (yArray->GetDataType())
{
vtkTemplateMacro(
CopyToPoints(this->Points, this->Previous ? this->Previous->Points : 0,
static_cast<VTK_TT*>(y_array->GetVoidPointer(0)),
y_array->GetNumberOfTuples(), logScale));
static_cast<VTK_TT*>(yArray->GetVoidPointer(0)),
yArray->GetNumberOfTuples(), logScale,
this->Bar->GetScalingFactor()));
}
}
}
......@@ -390,6 +415,7 @@ class vtkPlotBarSegment : public vtkObject {
vtkPlotBar *Bar;
VectorPIMPL* Sorted;
std::set<vtkIdType>* SelectionSet;
vtkVector2d ScalingFactor;
};
vtkStandardNewMacro(vtkPlotBarSegment);
......@@ -405,14 +431,13 @@ public:
}
vtkPlotBarSegment* AddSegment(
vtkDataArray *x_array, vtkDataArray *y_array,
vtkAxis* x_axis, vtkAxis* y_axis, vtkPlotBarSegment *prev=0)
vtkDataArray *xArray, vtkDataArray *yArray,
vtkAxis* xAxis, vtkAxis* yAxis, vtkPlotBarSegment *prev = 0)
{
vtkSmartPointer<vtkPlotBarSegment> segment =
vtkSmartPointer<vtkPlotBarSegment>::New();
segment->Configure(this->Bar, x_array, y_array, x_axis, y_axis, prev);
this->Segments.push_back(segment);
return segment;
vtkNew<vtkPlotBarSegment> segment;
segment->Configure(this->Bar, xArray, yArray, xAxis, yAxis, prev);
this->Segments.push_back(segment.GetPointer());
return segment.GetPointer();
}
void PaintSegments(vtkContext2D *painter, vtkColorSeries *colorSeries,
......@@ -607,7 +632,7 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled)
vtkDataArray *y = this->Data->GetInputArrayToProcess(1, table);
if (!y)
{
return;
return;
}
if (this->UseIndexForXSeries)
......@@ -629,14 +654,14 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled)
y->GetRange(&bounds[valuesLow]);
double y_range[2];
double yRange[2];
std::map< int, std::string >::iterator it;
for ( it = this->Private->AdditionalSeries.begin(); it !=
this->Private->AdditionalSeries.end(); ++it )
{
y = vtkDataArray::SafeDownCast(table->GetColumnByName((*it).second.c_str()));
y->GetRange(y_range);
bounds[valuesHigh] += y_range[1];
y->GetRange(yRange);
bounds[valuesHigh] += yRange[1];
}
// Bar plots always have one of the value bounds at the origin
......@@ -804,7 +829,8 @@ bool vtkPlotBar::UpdateTableCache(vtkTable *table)
this->Private->Update();
vtkPlotBarSegment *prev = this->Private->AddSegment(x, y, this->GetXAxis(), this->GetYAxis());
vtkPlotBarSegment *prev = this->Private->AddSegment(x, y, this->GetXAxis(),
this->GetYAxis());
std::map< int, std::string >::iterator it;
......
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