vtkPlotGrid.cxx 2.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*=========================================================================

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

#include "vtkContext2D.h"
#include "vtkPoints2D.h"
#include "vtkPen.h"
#include "vtkAxis.h"
22
#include "vtkFloatArray.h"
23
#include "vtkVector.h"
24 25 26 27 28 29 30 31 32 33 34 35

#include "vtkObjectFactory.h"

//-----------------------------------------------------------------------------
vtkCxxSetObjectMacro(vtkPlotGrid, XAxis, vtkAxis);
vtkCxxSetObjectMacro(vtkPlotGrid, YAxis, vtkAxis);
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotGrid);

//-----------------------------------------------------------------------------
vtkPlotGrid::vtkPlotGrid()
{
36 37
  this->XAxis = nullptr;
  this->YAxis = nullptr;
38 39 40 41 42
}

//-----------------------------------------------------------------------------
vtkPlotGrid::~vtkPlotGrid()
{
43 44
  this->SetXAxis(nullptr);
  this->SetYAxis(nullptr);
45 46 47 48 49 50
}

//-----------------------------------------------------------------------------
bool vtkPlotGrid::Paint(vtkContext2D *painter)
{
  if (!this->XAxis || !this->YAxis)
51
  {
52 53 54
    // Need axes to define where our grid lines should be drawn
    vtkDebugMacro(<<"No axes set and so grid lines cannot be drawn.");
    return false;
55
  }
56 57 58 59 60 61

  vtkVector2f x1, x2, y1, y2;
  this->XAxis->GetPoint1(x1.GetData());
  this->XAxis->GetPoint2(x2.GetData());
  this->YAxis->GetPoint1(y1.GetData());
  this->YAxis->GetPoint2(y2.GetData());
62 63

  // in x
64
  if (this->XAxis->GetVisible() && this->XAxis->GetGridVisible())
65
  {
66
    vtkFloatArray *xLines = this->XAxis->GetTickScenePositions();
67
    painter->ApplyPen(this->XAxis->GetGridPen());
68 69
    float *xPositions = xLines->GetPointer(0);
    for (int i = 0; i < xLines->GetNumberOfTuples(); ++i)
70
    {
71
      painter->DrawLine(xPositions[i], y1.GetY(), xPositions[i], y2.GetY());
72
    }
73
  }
74 75

  // in y
76
  if (this->YAxis->GetVisible() && this->YAxis->GetGridVisible())
77
  {
78
    vtkFloatArray *yLines = this->YAxis->GetTickScenePositions();
79
    painter->ApplyPen(this->YAxis->GetGridPen());
80 81
    float *yPositions = yLines->GetPointer(0);
    for (int i = 0; i < yLines->GetNumberOfTuples(); ++i)
82
    {
83
      painter->DrawLine(x1.GetX(), yPositions[i], x2.GetX(), yPositions[i]);
84
    }
85
  }
86

87
  return true;
88 89 90 91 92 93 94
}

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