/
vtkCursorShapes.cxx
134 lines (104 loc) · 3.78 KB
/
vtkCursorShapes.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
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
132
133
/*=========================================================================
Program: ToolCursor
Module: vtkCursorShapes.cxx
Copyright (c) 2010 David Gobbi
All rights reserved.
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 "vtkCursorShapes.h"
#include "vtkObjectFactory.h"
#include "vtkToolCursor.h"
#include "vtkDataSet.h"
#include "vtkSmartPointer.h"
#include <string>
#include <vector>
vtkStandardNewMacro(vtkCursorShapes);
// A simple container for cursor data
class vtkToolCursorShape
{
public:
vtkToolCursorShape(const char *name,
vtkDataSet *data,
int flags) : Name(name), Data(data), Flags(flags) {};
std::string Name;
vtkSmartPointer<vtkDataSet> Data;
int Flags;
};
// A vector of the above, with a VTK-like interface
class vtkToolCursorShapeArray
{
private:
typedef std::vector<vtkToolCursorShape> VectorType;
VectorType Vector;
public:
static vtkToolCursorShapeArray *New() {
return new vtkToolCursorShapeArray; };
void Delete() {
delete this; };
void AddItem(const char *name, vtkDataSet *shape, int flags) {
this->Vector.push_back(vtkToolCursorShape(name, shape, flags)); };
int GetIndex(const char *name) {
if (name) {
for (VectorType::size_type i = 0; i < this->Vector.size(); i++) {
if (this->Vector[i].Name.compare(name) == 0) {
return static_cast<int>(i); } } } return -1; };
const char *GetName(int i) {
VectorType::size_type j = static_cast<VectorType::size_type>(i);
if (i < 0 || j >= this->Vector.size()) { return 0; }
else { return this->Vector[j].Name.c_str(); } };
vtkDataSet *GetData(int i) {
VectorType::size_type j = static_cast<VectorType::size_type>(i);
if (i < 0 || j >= this->Vector.size()) { return 0; }
else {return this->Vector[j].Data; } };
int GetFlags(int i) {
VectorType::size_type j = static_cast<VectorType::size_type>(i);
if (i < 0 || j >= this->Vector.size()) { return 0; }
else {return this->Vector[j].Flags; } };
};
//----------------------------------------------------------------------------
vtkCursorShapes::vtkCursorShapes()
{
this->NumberOfShapes = 0;
this->Shapes = vtkToolCursorShapeArray::New();
}
//----------------------------------------------------------------------------
vtkCursorShapes::~vtkCursorShapes()
{
this->Shapes->Delete();
}
//----------------------------------------------------------------------------
void vtkCursorShapes::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "NumberOfShapes: " << this->NumberOfShapes << "\n";
}
//----------------------------------------------------------------------------
int vtkCursorShapes::AddShape(const char *name, vtkDataSet *data,
int flags)
{
this->Shapes->AddItem(name, data, flags);
this->NumberOfShapes++;
return (this->NumberOfShapes - 1);
}
//----------------------------------------------------------------------------
int vtkCursorShapes::GetShapeIndex(const char *name)
{
return this->Shapes->GetIndex(name);
}
//----------------------------------------------------------------------------
const char *vtkCursorShapes::GetShapeName(int i)
{
return this->Shapes->GetName(i);
}
//----------------------------------------------------------------------------
vtkDataSet *vtkCursorShapes::GetShapeData(int i)
{
return this->Shapes->GetData(i);
}
//----------------------------------------------------------------------------
int vtkCursorShapes::GetShapeFlags(int i)
{
return this->Shapes->GetFlags(i);
}