vtkPlotArea.cxx 20.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkPlotArea.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 "vtkPlotArea.h"

17
#include "vtkArrayDispatch.h"
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include "vtkAxis.h"
#include "vtkBoundingBox.h"
#include "vtkBrush.h"
#include "vtkCharArray.h"
#include "vtkContext2D.h"
#include "vtkContextMapper2D.h"
#include "vtkFloatArray.h"
#include "vtkMath.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPen.h"
#include "vtkPoints2D.h"
#include "vtkTable.h"
#include "vtkWeakPointer.h"
#include "vtkVectorOperators.h"

#include <vector>
#include <set>
#include <cmath>
#include <algorithm>

namespace
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
41
  inline bool vtkIsBadPoint(const vtkVector2f& vec)
42
    {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
43 44
    return (vtkMath::IsNan(vec.GetX()) || vtkMath::IsInf(vec.GetX()) ||
      vtkMath::IsNan(vec.GetY()) || vtkMath::IsInf(vec.GetY()));
45
    }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
46 47 48 49 50 51 52 53
} // end of namespace

// Keeps all data-dependent meta-data that's updated in
// vtkPlotArea::Update.
class vtkPlotArea::vtkTableCache
{
  // PIMPL for STL vector...
  struct vtkIndexedVector2f
54
    {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
55 56 57 58
    size_t index;
    vtkVector2f pos;
    static bool compVector3fX(
      const vtkIndexedVector2f& v1, const vtkIndexedVector2f& v2)
59
      {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
60 61 62 63 64 65 66 67
      if (v1.pos.GetX() < v2.pos.GetX())
        {
        return true;
        }
      else
        {
        return false;
        }
68
      }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
69 70 71
    // See if the point is within tolerance.
    static bool inRange(const vtkVector2f& point, const vtkVector2f& tol,
      const vtkVector2f& current)
72
      {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
73 74 75 76 77 78 79 80 81
      if (current.GetX() > point.GetX() - tol.GetX() && current.GetX() < point.GetX() + tol.GetX() &&
        current.GetY() > point.GetY() - tol.GetY() && current.GetY() < point.GetY() + tol.GetY())
        {
        return true;
        }
      else
        {
        return false;
        }
82
      }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
83
    };
84

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
85 86 87
  // DataStructure used to store sorted points.
  class VectorPIMPL : public std::vector<vtkIndexedVector2f>
  {
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
public:
  void Initialize(vtkVector2f* array, size_t n)
    {
    this->reserve(n);
    for (size_t i = 0; i < n; ++i)
      {
      vtkIndexedVector2f tmp;
      tmp.index = i;
      tmp.pos = array[i];
      this->push_back(tmp);
      }
    }

  //-----------------------------------------------------------------------------
  vtkIdType GetNearestPoint(
    const vtkVector2f& point, const vtkVector2f& tol, vtkVector2f* location)
    {
    // Set up our search array, use the STL lower_bound algorithm
    VectorPIMPL::iterator low;
    VectorPIMPL &v = *this;

    // Get the lowest point we might hit within the supplied tolerance
    vtkIndexedVector2f lowPoint;
    lowPoint.index = 0;
    lowPoint.pos = vtkVector2f(point.GetX()-tol.GetX(), 0.0f);
    low = std::lower_bound(v.begin(), v.end(), lowPoint, vtkIndexedVector2f::compVector3fX);

    // Now consider the y axis
    float highX = point.GetX() + tol.GetX();
    while (low != v.end())
      {
      if (vtkIndexedVector2f::inRange(point, tol, (*low).pos))
        {
        *location = (*low).pos;
        return static_cast<int>((*low).index);
        }
      else if (low->pos.GetX() > highX)
        {
        break;
        }
      ++low;
      }
    return -1;
    }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
132 133
  };
private:
134 135 136 137 138 139 140 141 142
  vtkTimeStamp DataMTime;
  vtkTimeStamp BoundsMTime;

  // Unscaled data bounds.
  vtkBoundingBox DataBounds;

  vtkRectd ShiftScale;

  vtkTuple<double, 2> GetDataRange(vtkDataArray* array)
143
  {
144 145 146 147 148
    assert(array);

    if (this->ValidPointMask)
      {
      assert(array->GetNumberOfTuples() == this->ValidPointMask->GetNumberOfTuples());
149 150 151 152 153 154 155 156 157
      assert(array->GetNumberOfComponents() == this->ValidPointMask->GetNumberOfComponents());

      vtkArrayDispatch::Dispatch2ByArray<
          vtkArrayDispatch::Arrays, // First array is input, can be anything.
          vtkTypeList_Create_1(vtkCharArray) // Second is always vtkCharArray.
          > dispatcher;
      ComputeArrayRange worker;

      if (!dispatcher.Execute(array, this->ValidPointMask, worker))
158
        {
159 160 161 162
        vtkGenericWarningMacro(
              <<"Error computing range. Unsupported array type: "
              << array->GetClassName()
              << " (" << array->GetDataTypeAsString() << ").");
163
        }
164 165

      return worker.Result;
166 167 168
      }
    else
      {
169 170 171 172
      vtkArrayDispatch::Dispatch dispatcher;
      ComputeArrayRange worker;

      if (!dispatcher.Execute(array, worker))
173
        {
174 175 176 177
        vtkGenericWarningMacro(
              <<"Error computing range. Unsupported array type: "
              << array->GetClassName()
              << " (" << array->GetDataTypeAsString() << ").");
178
        }
179 180

      return worker.Result;
181
      }
182 183 184 185 186 187 188 189 190 191 192

  }

  struct ComputeArrayRange
  {
    vtkTuple<double, 2> Result;

    ComputeArrayRange()
    {
      Result[0] = VTK_DOUBLE_MAX;
      Result[1] = VTK_DOUBLE_MIN;
193 194
    }

195 196 197
    // Use mask:
    template <class ArrayT>
    void operator()(ArrayT *array, vtkCharArray* mask)
198
    {
199 200 201 202
      vtkIdType numTuples = array->GetNumberOfTuples();
      int numComps = array->GetNumberOfComponents();

      for (vtkIdType tupleIdx = 0; tupleIdx < numTuples; ++tupleIdx)
203
        {
204 205
        for (int compIdx = 0; compIdx < numComps; ++compIdx)
          {
David C. Lonie's avatar
David C. Lonie committed
206
          if (mask->GetTypedComponent(tupleIdx, compIdx) != 0)
207
            {
David C. Lonie's avatar
David C. Lonie committed
208 209
            typename ArrayT::ValueType val =
                array->GetTypedComponent(tupleIdx, compIdx);
210 211 212 213
            Result[0] = std::min(Result[0], static_cast<double>(val));
            Result[1] = std::max(Result[1], static_cast<double>(val));
            }
          }
214 215 216
        }
    }

217 218 219
    // No mask:
    template <class ArrayT>
    void operator()(ArrayT *array)
220
    {
221 222 223 224 225 226 227
      vtkIdType numTuples = array->GetNumberOfTuples();
      int numComps = array->GetNumberOfComponents();

      for (vtkIdType tupleIdx = 0; tupleIdx < numTuples; ++tupleIdx)
        {
        for (int compIdx = 0; compIdx < numComps; ++compIdx)
          {
David C. Lonie's avatar
David C. Lonie committed
228 229
          typename ArrayT::ValueType val =
              array->GetTypedComponent(tupleIdx, compIdx);
230 231 232 233
          Result[0] = std::min(Result[0], static_cast<double>(val));
          Result[1] = std::max(Result[1], static_cast<double>(val));
          }
        }
234 235
    }

236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
  };

  struct CopyToPoints
  {
    float *Data;
    int DataIncrement;
    vtkIdType NumValues;
    vtkVector2d Transform;
    bool UseLog;

    CopyToPoints(float *data, int data_increment, vtkIdType numValues,
                 const vtkVector2d &ss, bool useLog)
      : Data(data),
        DataIncrement(data_increment),
        NumValues(numValues),
        Transform(ss),
        UseLog(useLog)
    {}

255
    CopyToPoints& operator=(const CopyToPoints &) VTK_DELETE_FUNCTION;
256

257 258 259
    // Use input array:
    template <class ArrayT>
    void operator()(ArrayT *array)
260
    {
261
    if (this->UseLog)
262
      {
263 264 265
      float *data = this->Data;
      for (vtkIdType valIdx = 0; valIdx < this->NumValues;
           ++valIdx, data += this->DataIncrement)
266
        {
267 268 269
        *data = log10(static_cast<float>(
                        (array->GetValue(valIdx) + this->Transform[0])
                        * this->Transform[1]));
270 271 272 273
        }
      }
    else
      {
274 275 276
      float *data = this->Data;
      for (vtkIdType valIdx = 0; valIdx < this->NumValues;
           ++valIdx, data += this->DataIncrement)
277
        {
278 279 280
        *data = static_cast<float>(
              (array->GetValue(valIdx) + this->Transform[0])
              * this->Transform[1]);
281 282 283 284
        }
      }
    }

285 286
    // No array, just iterate to number of values
    void operator()()
287
    {
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
    if (this->UseLog)
      {
      float *data = this->Data;
      for (vtkIdType valIdx = 0; valIdx < this->NumValues;
           ++valIdx, data += this->DataIncrement)
        {
        *data = log10(static_cast<float>((valIdx + this->Transform[0])
                                         * this->Transform[1]));
        }
      }
    else
      {
      float *data = this->Data;
      for (vtkIdType valIdx = 0; valIdx < this->NumValues;
           ++valIdx, data += this->DataIncrement)
        {
        *data = static_cast<float>((valIdx + this->Transform[0])
                                   * this->Transform[1]);
        }
      }
    }
  };
310

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
311
  VectorPIMPL SortedPoints;
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
public:
  // Array which marks valid points in the array. If NULL (the default), all
  // points in the input array are considered valid.
  vtkWeakPointer<vtkCharArray> ValidPointMask;

  // References to input arrays.
  vtkTuple<vtkWeakPointer<vtkDataArray>, 3> InputArrays;

  // Array for the points. These maintain the points that form the QuadStrip for
  // the area plot.
  vtkNew<vtkPoints2D> Points;

  // Set of point ids that are invalid or masked out.
  std::vector<vtkIdType> BadPoints;


  vtkTableCache()
    {
    this->Reset();
    }

  void Reset()
    {
    this->ValidPointMask = NULL;
    this->Points->Initialize();
    this->Points->SetDataTypeToFloat();
    this->BadPoints.clear();
    }

  bool IsInputDataValid() const
    {
    return this->InputArrays[1] != NULL && this->InputArrays[2] != NULL;
    }

  bool SetPoints(vtkDataArray* x, vtkDataArray* y1, vtkDataArray* y2)
    {
    if (y1 == NULL || y2 == NULL)
      {
      return false;
      }

    vtkIdType numTuples = y1->GetNumberOfTuples();

    // sanity check.
    assert((x == NULL || x->GetNumberOfTuples() == numTuples) && y2->GetNumberOfTuples() == numTuples);

    this->InputArrays[0] = x;
    this->InputArrays[1] = y1;
    this->InputArrays[2] = y2;
    this->Points->SetNumberOfPoints(numTuples * 2);
    this->SortedPoints.clear();
    this->DataMTime.Modified();
    return true;
    }

  void GetDataBounds(double bounds[4])
    {
    if (this->DataMTime > this->BoundsMTime)
      {
      vtkTuple<double, 2> rangeX, rangeY1, rangeY2;
      if (this->InputArrays[0])
        {
        rangeX = this->GetDataRange(this->InputArrays[0]);
        }
      else
        {
        rangeX[0] = 0; rangeX[1] = (this->Points->GetNumberOfPoints()/2-1);
        }
      rangeY1 = this->GetDataRange(this->InputArrays[1]);
      rangeY2 = this->GetDataRange(this->InputArrays[2]);

      this->DataBounds.Reset();
      this->DataBounds.SetMinPoint(rangeX[0], std::min(rangeY1[0], rangeY2[0]), 0);
      this->DataBounds.SetMaxPoint(rangeX[1], std::max(rangeY1[1], rangeY2[1]), 0);
      this->BoundsMTime.Modified();
      }
    double bds[6];
    this->DataBounds.GetBounds(bds);
    std::copy(bds, bds+4, bounds);
    }

  void UpdateCache(vtkPlotArea* self)
    {
    const vtkRectd& ss = self->GetShiftScale();
    vtkAxis* xaxis = self->GetXAxis();
    vtkAxis* yaxis = self->GetYAxis();

    if (this->Points->GetMTime()> this->DataMTime &&
      this->Points->GetMTime() > xaxis->GetMTime() &&
      this->Points->GetMTime() > yaxis->GetMTime() &&
      ss == this->ShiftScale)
      {
      // nothing to do.
      return;
      }

    vtkTuple<bool, 2> useLog;
    useLog[0] = xaxis->GetLogScaleActive();
    useLog[1] = yaxis->GetLogScaleActive();

    vtkIdType numTuples = this->InputArrays[1]->GetNumberOfTuples();
    assert(this->Points->GetNumberOfPoints() == 2*numTuples);

    float* data = reinterpret_cast<float*>(this->Points->GetVoidPointer(0));
    if (this->InputArrays[0])
      {
418 419 420 421 422 423 424 425 426 427 428 429 430
      vtkDataArray *array = this->InputArrays[0].GetPointer();
      vtkIdType numValues = array->GetNumberOfTuples() *
                            array->GetNumberOfComponents();

      CopyToPoints worker1(data, 4, numValues, vtkVector2d(ss[0], ss[2]),
                           useLog[0]);
      CopyToPoints worker2(&data[2], 4, numValues, vtkVector2d(ss[0], ss[2]),
                           useLog[0]);

      vtkArrayDispatch::Dispatch dispatcher;

      if (!dispatcher.Execute(array, worker1) ||
          !dispatcher.Execute(array, worker2))
431
        {
432 433 434
        vtkGenericWarningMacro("Error creating points, unsupported array type: "
                               << array->GetClassName()
                               << " (" << array->GetDataTypeAsString() << ").");
435 436 437 438
        }
      }
    else
      {
439 440 441 442 443 444 445
      CopyToPoints worker1(data, 4, numTuples, vtkVector2d(ss[0], ss[2]),
                           useLog[0]);
      CopyToPoints worker2(&data[2], 4, numTuples, vtkVector2d(ss[0], ss[2]),
                           useLog[0]);
      // No array, no need to dispatch:
      worker1();
      worker2();
446 447
      }

448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
    vtkDataArray *array1 = this->InputArrays[1].GetPointer();
    vtkDataArray *array2 = this->InputArrays[2].GetPointer();
    vtkIdType numValues1 = array1->GetNumberOfTuples() *
                           array1->GetNumberOfComponents();
    vtkIdType numValues2 = array2->GetNumberOfTuples() *
                           array2->GetNumberOfComponents();

    CopyToPoints worker1(&data[1], 4, numValues1, vtkVector2d(ss[1], ss[3]),
                         useLog[1]);
    CopyToPoints worker2(&data[3], 4, numValues2, vtkVector2d(ss[1], ss[3]),
                         useLog[1]);

    vtkArrayDispatch::Dispatch dispatcher;

    if (!dispatcher.Execute(array1, worker1) ||
        !dispatcher.Execute(array2, worker2))
464
      {
465
      vtkGenericWarningMacro("Error creating points: Array dispatch failed.");
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
      }

    // Set the bad-points mask.
    vtkVector2f* vec2f = reinterpret_cast<vtkVector2f*>(this->Points->GetVoidPointer(0));
    for (vtkIdType cc=0; cc < numTuples; cc++)
      {
      bool is_bad = (this->ValidPointMask && this->ValidPointMask->GetValue(cc) == 0);
      is_bad =  is_bad || vtkIsBadPoint(vec2f[2*cc]);
      is_bad =  is_bad || vtkIsBadPoint(vec2f[2*cc + 1]);
      if (is_bad)
        {
        // this ensures that the GetNearestPoint() fails for masked out points.
        vec2f[2*cc] = vtkVector2f(vtkMath::Nan(), vtkMath::Nan());
        vec2f[2*cc + 1] = vtkVector2f(vtkMath::Nan(), vtkMath::Nan());
        this->BadPoints.push_back(cc);
        }
      }

    this->ShiftScale = ss;
    this->Points->Modified();
    this->SortedPoints.clear();
    }

  vtkIdType GetNearestPoint(
    const vtkVector2f& point, const vtkVector2f& tol, vtkVector2f* location)
    {
    if (this->Points->GetNumberOfPoints() == 0)
      {
      return -1;
      }

    if (this->SortedPoints.size() == 0)
      {
      float* data = reinterpret_cast<float*>(this->Points->GetVoidPointer(0));
      this->SortedPoints.Initialize(reinterpret_cast<vtkVector2f*>(data),
        this->Points->GetNumberOfPoints());
      std::sort(this->SortedPoints.begin(), this->SortedPoints.end(),
        vtkIndexedVector2f::compVector3fX);
      }
    return this->SortedPoints.GetNearestPoint(point, tol, location);
    }
};

vtkStandardNewMacro(vtkPlotArea);
//----------------------------------------------------------------------------
vtkPlotArea::vtkPlotArea()
  : TableCache(new vtkPlotArea::vtkTableCache())
{
  this->TooltipDefaultLabelFormat = "%l: %x:(%a, %b)";
}

//----------------------------------------------------------------------------
vtkPlotArea::~vtkPlotArea()
{
  delete this->TableCache;
  this->TableCache = NULL;
}

//----------------------------------------------------------------------------
void vtkPlotArea::Update()
{
  if (!this->Visible)
    {
    return;
    }

  vtkTable* table = this->GetInput();
  if (!table)
    {
    vtkDebugMacro("Update event called with no input table set.");
    this->TableCache->Reset();
    return;
    }

  if (this->Data->GetMTime() > this->UpdateTime ||
    table->GetMTime() > this->UpdateTime ||
    this->GetMTime() > this->UpdateTime)
    {
    vtkTableCache& cache = (*this->TableCache);

    cache.Reset();
    cache.ValidPointMask = (this->ValidPointMaskName.empty() == false)?
548
      vtkArrayDownCast<vtkCharArray>(table->GetColumnByName(this->ValidPointMaskName)) : NULL;
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
    cache.SetPoints(
      this->UseIndexForXSeries? NULL: this->Data->GetInputArrayToProcess(0, table),
      this->Data->GetInputArrayToProcess(1, table),
      this->Data->GetInputArrayToProcess(2, table));
    this->UpdateTime.Modified();
    }
}

//----------------------------------------------------------------------------
void vtkPlotArea::UpdateCache()
{
  vtkTableCache& cache = (*this->TableCache);
  if (!this->Visible || !cache.IsInputDataValid())
    {
    return;
    }
  cache.UpdateCache(this);
}

//----------------------------------------------------------------------------
void vtkPlotArea::GetBounds(double bounds[4])
{
  vtkTableCache& cache = (*this->TableCache);
  if (!this->Visible || !cache.IsInputDataValid())
    {
    return;
    }
  cache.GetDataBounds(bounds);
}

//----------------------------------------------------------------------------
bool vtkPlotArea::Paint(vtkContext2D *painter)
{
  vtkTableCache& cache = (*this->TableCache);
  if (!this->Visible || !cache.IsInputDataValid() || cache.Points->GetNumberOfPoints() == 0)
    {
    return false;
    }
  painter->ApplyPen(this->Pen);
  painter->ApplyBrush(this->Brush);

  vtkIdType start = 0;
  for (std::vector<vtkIdType>::iterator iter = cache.BadPoints.begin();
    iter != cache.BadPoints.end(); ++iter)
    {
    vtkIdType end = *iter;
    if ((end-start) >= 2)
      {
      painter->DrawQuadStrip(
        reinterpret_cast<float*>(cache.Points->GetVoidPointer(2*2*start)),
        (end-start)*2);
      }
    start = end;
    }
  if (cache.Points->GetNumberOfPoints() - (2*start) > 4)
    {
    painter->DrawQuadStrip(
      reinterpret_cast<float*>(cache.Points->GetVoidPointer(2*2*start)),
      cache.Points->GetNumberOfPoints() - (2*start));
    }
  return true;
}

//-----------------------------------------------------------------------------
bool vtkPlotArea::PaintLegend(vtkContext2D *painter, const vtkRectf& rect,
                              int vtkNotUsed(legendIndex))
{
  painter->ApplyPen(this->Pen);
  painter->ApplyBrush(this->Brush);
  painter->DrawRect(rect[0], rect[1], rect[2], rect[3]);
  return true;
}

//----------------------------------------------------------------------------
vtkIdType vtkPlotArea::GetNearestPoint(
  const vtkVector2f& point, const vtkVector2f& tolerance, vtkVector2f* location)
{
  vtkTableCache& cache = (*this->TableCache);
  if (!this->Visible || !cache.IsInputDataValid() || cache.Points->GetNumberOfPoints() == 0)
    {
    return -1;
    }
  return cache.GetNearestPoint(point, tolerance, location);
}


//-----------------------------------------------------------------------------
vtkStdString vtkPlotArea::GetTooltipLabel(const vtkVector2d &plotPos,
                                      vtkIdType seriesIndex,
                                      vtkIdType segmentIndex)
{
  vtkStdString tooltipLabel;
  vtkStdString format = this->Superclass::GetTooltipLabel(plotPos, seriesIndex, segmentIndex);

  vtkIdType idx = (seriesIndex / 2) * 2;

  vtkTableCache& cache = (*this->TableCache);
  const vtkVector2f* data = reinterpret_cast<vtkVector2f*>(cache.Points->GetVoidPointer(0));

  // Parse TooltipLabelFormat and build tooltipLabel
  bool escapeNext = false;
  for (size_t i = 0; i < format.length(); ++i)
    {
    if (escapeNext)
      {
      switch (format[i])
        {
        case 'a':
          tooltipLabel += this->GetNumber(data[idx].GetY(), this->YAxis);
          break;
        case 'b':
          tooltipLabel += this->GetNumber(data[idx+1].GetY(), this->YAxis);
          break;
        default: // If no match, insert the entire format tag
          tooltipLabel += "%";
          tooltipLabel += format[i];
          break;
        }
      escapeNext = false;
      }
    else
      {
      if (format[i] == '%')
        {
        escapeNext = true;
        }
      else
        {
        tooltipLabel += format[i];
        }
      }
    }
  return tooltipLabel;
}

//----------------------------------------------------------------------------
void vtkPlotArea::SetColor(
  unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
  this->Brush->SetColor(r, g, b, a);
  this->Superclass::SetColor(r, g, b, a);
}

//----------------------------------------------------------------------------
void vtkPlotArea::SetColor(double r,  double g, double b)
{
  this->Brush->SetColorF(r, g, b);
  this->Superclass::SetColor(r, g, b);
}

//----------------------------------------------------------------------------
void vtkPlotArea::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}