Commit 043de2d1 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

Changed to fit the VTK style, separated some logic

Changed to use VTK naming conventions for variables, fixed one or two
stule issues and separated the logic in the CopyToPoints functions in
preparation for adding the scaling logic.

Change-Id: I2057ef5c0b27d19cb024c8a004c4e794fd2faef5
parent da970a2b
...@@ -45,50 +45,69 @@ namespace { ...@@ -45,50 +45,69 @@ namespace {
// Copy the two arrays into the points array // Copy the two arrays into the points array
template<class A, class B> template<class A, class B>
void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previous_points, A *a, B *b, void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a, B *b,
int n, int logScale) int n, int logScale)
{ {
points->SetNumberOfPoints(n); 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) for (int i = 0; i < n; ++i)
{ {
double prev[] = {0.0,0.0}; if (prevData)
if (previous_points) {
previous_points->GetPoint(i,prev); prev = prevData[2 * i + 1];
points->SetPoint(i, }
(logScale & 1) ? log10(static_cast<double>(a[i])) : a[i], data[2 * i] = static_cast<float>((logScale & 1) ?
(logScale & 2) ? log10(static_cast<double>(a[i]))
log10(static_cast<double>(b[i] + prev[1])) : (b[i] + prev[1])); : a[i]);
data[2 * i + 1] = static_cast<float>((logScale & 2) ?
log10(static_cast<double>(b[i] + prev))
: (b[i] + prev));
} }
} }
// Copy one array into the points array, use the index of that array as x // Copy one array into the points array, use the index of that array as x
template<class A> template<class A>
void CopyToPoints( void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a, int n,
vtkPoints2D *points, vtkPoints2D *previous_points, A *a, int n, int logScale) int logScale)
{ {
points->SetNumberOfPoints(n); 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) for (int i = 0; i < n; ++i)
{ {
double prev[] = {0.0,0.0}; if (prevData)
if (previous_points) {
previous_points->GetPoint(i,prev); prev = prevData[2 * i + 1];
points->SetPoint(i, i, a[i] + prev[1]); }
points->SetPoint(i, data[2 * i] = static_cast<float>((logScale & 1) ?
(logScale & 1) ? log10(static_cast<double>(i + 1.0)) : i, log10(static_cast<double>(i + 1.0))
(logScale & 2) ? : i);
log10(static_cast<double>(a[i] + prev[1])) : (a[i] + prev[1])); data[2 * i + 1] = static_cast<float>((logScale & 2) ?
log10(static_cast<double>(a[i] + prev))
: (a[i] + prev));
} }
} }
// Copy the two arrays into the points array // Copy the two arrays into the points array
template<class A> template<class A>
void CopyToPointsSwitch(vtkPoints2D *points, vtkPoints2D *previous_points, A *a, void CopyToPointsSwitch(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a,
vtkDataArray *b, int n, int logScale) vtkDataArray *b, int n, int logScale)
{ {
switch(b->GetDataType()) switch(b->GetDataType())
{ {
vtkTemplateMacro( vtkTemplateMacro(
CopyToPoints(points,previous_points, a, CopyToPoints(points,previousPoints, a,
static_cast<VTK_TT*>(b->GetVoidPointer(0)), n, logScale)); static_cast<VTK_TT*>(b->GetVoidPointer(0)), n, logScale));
} }
} }
...@@ -156,8 +175,8 @@ class vtkPlotBarSegment : public vtkObject { ...@@ -156,8 +175,8 @@ class vtkPlotBarSegment : public vtkObject {
} }
void Configure( void Configure(
vtkPlotBar* bar, vtkDataArray* x_array, vtkDataArray* y_array, vtkPlotBar* bar, vtkDataArray* xArray, vtkDataArray* yArray,
vtkAxis* x_axis, vtkAxis* y_axis, vtkPlotBarSegment* prev) vtkAxis* xAxis, vtkAxis* yAxis, vtkPlotBarSegment* prev)
{ {
this->Bar = bar; this->Bar = bar;
this->Previous = prev; this->Previous = prev;
...@@ -170,26 +189,26 @@ class vtkPlotBarSegment : public vtkObject { ...@@ -170,26 +189,26 @@ class vtkPlotBarSegment : public vtkObject {
delete this->SelectionSet; delete this->SelectionSet;
int logScale = int logScale =
(x_axis->GetLogScaleActive() ? 1 : 0) + (xAxis->GetLogScaleActive() ? 1 : 0) +
(y_axis->GetLogScaleActive() ? 2 : 0); (yAxis->GetLogScaleActive() ? 2 : 0);
if (x_array) if (xArray)
{ {
switch (x_array->GetDataType()) switch (xArray->GetDataType())
{ {
vtkTemplateMacro( vtkTemplateMacro(
CopyToPointsSwitch(this->Points,this->Previous ? this->Previous->Points : 0, CopyToPointsSwitch(this->Points,this->Previous ? this->Previous->Points : 0,
static_cast<VTK_TT*>(x_array->GetVoidPointer(0)), static_cast<VTK_TT*>(xArray->GetVoidPointer(0)),
y_array,x_array->GetNumberOfTuples(), logScale)); yArray, xArray->GetNumberOfTuples(), logScale));
} }
} }
else else
{ // Using Index for X Series { // Using Index for X Series
switch (y_array->GetDataType()) switch (yArray->GetDataType())
{ {
vtkTemplateMacro( vtkTemplateMacro(
CopyToPoints(this->Points, this->Previous ? this->Previous->Points : 0, CopyToPoints(this->Points, this->Previous ? this->Previous->Points : 0,
static_cast<VTK_TT*>(y_array->GetVoidPointer(0)), static_cast<VTK_TT*>(yArray->GetVoidPointer(0)),
y_array->GetNumberOfTuples(), logScale)); yArray->GetNumberOfTuples(), logScale));
} }
} }
} }
...@@ -405,12 +424,12 @@ public: ...@@ -405,12 +424,12 @@ public:
} }
vtkPlotBarSegment* AddSegment( vtkPlotBarSegment* AddSegment(
vtkDataArray *x_array, vtkDataArray *y_array, vtkDataArray *xArray, vtkDataArray *yArray,
vtkAxis* x_axis, vtkAxis* y_axis, vtkPlotBarSegment *prev=0) vtkAxis* xAxis, vtkAxis* yAxis, vtkPlotBarSegment *prev = 0)
{ {
vtkSmartPointer<vtkPlotBarSegment> segment = vtkSmartPointer<vtkPlotBarSegment> segment =
vtkSmartPointer<vtkPlotBarSegment>::New(); vtkSmartPointer<vtkPlotBarSegment>::New();
segment->Configure(this->Bar, x_array, y_array, x_axis, y_axis, prev); segment->Configure(this->Bar, xArray, yArray, xAxis, yAxis, prev);
this->Segments.push_back(segment); this->Segments.push_back(segment);
return segment; return segment;
} }
...@@ -607,7 +626,7 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled) ...@@ -607,7 +626,7 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled)
vtkDataArray *y = this->Data->GetInputArrayToProcess(1, table); vtkDataArray *y = this->Data->GetInputArrayToProcess(1, table);
if (!y) if (!y)
{ {
return; return;
} }
if (this->UseIndexForXSeries) if (this->UseIndexForXSeries)
...@@ -629,14 +648,14 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled) ...@@ -629,14 +648,14 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled)
y->GetRange(&bounds[valuesLow]); y->GetRange(&bounds[valuesLow]);
double y_range[2]; double yRange[2];
std::map< int, std::string >::iterator it; std::map< int, std::string >::iterator it;
for ( it = this->Private->AdditionalSeries.begin(); it != for ( it = this->Private->AdditionalSeries.begin(); it !=
this->Private->AdditionalSeries.end(); ++it ) this->Private->AdditionalSeries.end(); ++it )
{ {
y = vtkDataArray::SafeDownCast(table->GetColumnByName((*it).second.c_str())); y = vtkDataArray::SafeDownCast(table->GetColumnByName((*it).second.c_str()));
y->GetRange(y_range); y->GetRange(yRange);
bounds[valuesHigh] += y_range[1]; bounds[valuesHigh] += yRange[1];
} }
// Bar plots always have one of the value bounds at the origin // Bar plots always have one of the value bounds at the origin
...@@ -804,7 +823,8 @@ bool vtkPlotBar::UpdateTableCache(vtkTable *table) ...@@ -804,7 +823,8 @@ bool vtkPlotBar::UpdateTableCache(vtkTable *table)
this->Private->Update(); 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; 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