forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkPlotGrid.cxx
94 lines (78 loc) · 2.85 KB
/
vtkPlotGrid.cxx
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
/*=========================================================================
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"
#include "vtkFloatArray.h"
#include "vtkVector.h"
#include "vtkObjectFactory.h"
//-----------------------------------------------------------------------------
vtkCxxSetObjectMacro(vtkPlotGrid, XAxis, vtkAxis);
vtkCxxSetObjectMacro(vtkPlotGrid, YAxis, vtkAxis);
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotGrid);
//-----------------------------------------------------------------------------
vtkPlotGrid::vtkPlotGrid()
{
this->XAxis = nullptr;
this->YAxis = nullptr;
}
//-----------------------------------------------------------------------------
vtkPlotGrid::~vtkPlotGrid()
{
this->SetXAxis(nullptr);
this->SetYAxis(nullptr);
}
//-----------------------------------------------------------------------------
bool vtkPlotGrid::Paint(vtkContext2D *painter)
{
if (!this->XAxis || !this->YAxis)
{
// Need axes to define where our grid lines should be drawn
vtkDebugMacro(<<"No axes set and so grid lines cannot be drawn.");
return false;
}
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());
// in x
if (this->XAxis->GetVisible() && this->XAxis->GetGridVisible())
{
vtkFloatArray *xLines = this->XAxis->GetTickScenePositions();
painter->ApplyPen(this->XAxis->GetGridPen());
float *xPositions = xLines->GetPointer(0);
for (int i = 0; i < xLines->GetNumberOfTuples(); ++i)
{
painter->DrawLine(xPositions[i], y1.GetY(), xPositions[i], y2.GetY());
}
}
// in y
if (this->YAxis->GetVisible() && this->YAxis->GetGridVisible())
{
vtkFloatArray *yLines = this->YAxis->GetTickScenePositions();
painter->ApplyPen(this->YAxis->GetGridPen());
float *yPositions = yLines->GetPointer(0);
for (int i = 0; i < yLines->GetNumberOfTuples(); ++i)
{
painter->DrawLine(x1.GetX(), yPositions[i], x2.GetX(), yPositions[i]);
}
}
return true;
}
//-----------------------------------------------------------------------------
void vtkPlotGrid::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}