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

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

18
#include "vtkAxis.h"
19
#include "vtkPen.h"
20
#include "vtkBrush.h"
21
22
23
24
25
26
27
28
29
#include "vtkTable.h"
#include "vtkDataObject.h"
#include "vtkIdTypeArray.h"
#include "vtkContextMapper2D.h"
#include "vtkObjectFactory.h"

#include "vtkStdString.h"

vtkCxxSetObjectMacro(vtkPlot, Selection, vtkIdTypeArray);
30
31
vtkCxxSetObjectMacro(vtkPlot, XAxis, vtkAxis);
vtkCxxSetObjectMacro(vtkPlot, YAxis, vtkAxis);
32
33
34
35

//-----------------------------------------------------------------------------
vtkPlot::vtkPlot()
{
36
37
  this->Pen = vtkPen::New();
  this->Pen->SetWidth(2.0);
38
  this->Brush = vtkBrush::New();
39
40
  this->Label = NULL;
  this->UseIndexForXSeries = false;
41
42
  this->Data = vtkContextMapper2D::New();
  this->Selection = NULL;
43
44
  this->XAxis = NULL;
  this->YAxis = NULL;
45
46
47
48
49
}

//-----------------------------------------------------------------------------
vtkPlot::~vtkPlot()
{
50
51
52
53
54
  if (this->Pen)
    {
    this->Pen->Delete();
    this->Pen = NULL;
    }
55
56
57
58
59
  if (this->Brush)
    {
    this->Brush->Delete();
    this->Brush = NULL;
    }
60
61
62
63
64
  if (this->Data)
    {
    this->Data->Delete();
    this->Data = NULL;
    }
65
  this->SetLabel(NULL);
66
67
  this->SetXAxis(NULL);
  this->SetYAxis(NULL);
68
69
}

70
//-----------------------------------------------------------------------------
71
bool vtkPlot::PaintLegend(vtkContext2D*, float*)
72
73
74
75
{
  return false;
}

76
//-----------------------------------------------------------------------------
77
78
79
80
81
82
83
bool vtkPlot::GetNearestPoint(const vtkVector2f&, const vtkVector2f&,
                              vtkVector2f*)
{
  return false;
}

//-----------------------------------------------------------------------------
84
85
86
void vtkPlot::SetColor(unsigned char r, unsigned char g, unsigned char b,
                       unsigned char a)
{
87
  this->Pen->SetColor(r, g, b, a);
88
89
}

90
91
92
//-----------------------------------------------------------------------------
void vtkPlot::SetColor(double r, double g, double b)
{
93
94
95
  this->Pen->SetColorF(r, g, b);
}

96
97
98
99
100
//-----------------------------------------------------------------------------
void vtkPlot::GetColor(double rgb[3])
{
  this->Pen->GetColorF(rgb);
}
101
102
103
104
105
106
107
108
109
110
111

//-----------------------------------------------------------------------------
void vtkPlot::SetWidth(float width)
{
  this->Pen->SetWidth(width);
}

//-----------------------------------------------------------------------------
float vtkPlot::GetWidth()
{
  return this->Pen->GetWidth();
112
113
}

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//-----------------------------------------------------------------------------
const char* vtkPlot::GetLabel()
{
  // If the label string is empty, return the y column name
  if (this->Label)
    {
    return this->Label;
    }
  else if (this->Data->GetInput() &&
           this->Data->GetInputArrayToProcess(1, this->Data->GetInput()))
    {
    return this->Data->GetInputArrayToProcess(1, this->Data->GetInput())->GetName();
    }
  else
    {
    return NULL;
    }
}

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//-----------------------------------------------------------------------------
void vtkPlot::SetInput(vtkTable *table)
{
  this->Data->SetInput(table);
}

//-----------------------------------------------------------------------------
void vtkPlot::SetInput(vtkTable *table, const char *xColumn,
                       const char *yColumn)
{
  if (!xColumn || !yColumn)
    {
    vtkErrorMacro(<< "Called with null arguments for X or Y column.")
    }
  vtkDebugMacro(<< "Setting input, X column = \"" << vtkstd::string(xColumn)
                << "\", " << "Y column = \"" << vtkstd::string(yColumn) << "\"");

  this->Data->SetInput(table);
151
152
  this->Data->SetInputArrayToProcess(0, 0, 0,
                                     vtkDataObject::FIELD_ASSOCIATION_ROWS,
153
                                     xColumn);
154
155
  this->Data->SetInputArrayToProcess(1, 0, 0,
                                     vtkDataObject::FIELD_ASSOCIATION_ROWS,
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
                                     yColumn);
}

//-----------------------------------------------------------------------------
void vtkPlot::SetInput(vtkTable *table, vtkIdType xColumn,
                       vtkIdType yColumn)
{
  this->SetInput(table,
                 table->GetColumnName(xColumn),
                 table->GetColumnName(yColumn));
}

//-----------------------------------------------------------------------------
void vtkPlot::SetInputArray(int index, const char *name)
{
  this->Data->SetInputArrayToProcess(index, 0, 0,
                                     vtkDataObject::FIELD_ASSOCIATION_ROWS,
                                     name);
}

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