forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkAnnotationLayers.cxx
236 lines (208 loc) · 6.21 KB
/
vtkAnnotationLayers.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAnnotationLayers.cxx
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
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 "vtkAnnotationLayers.h"
#include "vtkAnnotation.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
#include <vtkstd/vector>
/* Fix for BORLAND 5.6 bug where it wrongly chooses remove(const char *) in stdio
instead of the remove stl algorithm. */
#if defined (__BORLANDC__) && (__BORLANDC__ == 0x0560)
# define remove borland_remove
#endif
/* Include algorithm last so "remove" macro Borland hack does not
affect other headers. */
#include <vtkstd/algorithm>
vtkStandardNewMacro(vtkAnnotationLayers);
vtkCxxSetObjectMacro(vtkAnnotationLayers, CurrentAnnotation, vtkAnnotation);
class vtkAnnotationLayers::Internals
{
public:
vtkstd::vector<vtkSmartPointer<vtkAnnotation> > Annotations;
};
vtkAnnotationLayers::vtkAnnotationLayers() :
Implementation(new Internals())
{
this->CurrentAnnotation = vtkAnnotation::New();
// Start with an empty index selection
vtkSmartPointer<vtkSelection> sel =
vtkSmartPointer<vtkSelection>::New();
vtkSmartPointer<vtkSelectionNode> node =
vtkSmartPointer<vtkSelectionNode>::New();
node->SetContentType(vtkSelectionNode::INDICES);
vtkSmartPointer<vtkIdTypeArray> ids =
vtkSmartPointer<vtkIdTypeArray>::New();
node->SetSelectionList(ids);
sel->AddNode(node);
this->CurrentAnnotation->SetSelection(sel);
}
vtkAnnotationLayers::~vtkAnnotationLayers()
{
delete this->Implementation;
if (this->CurrentAnnotation)
{
this->CurrentAnnotation->Delete();
}
}
void vtkAnnotationLayers::SetCurrentSelection(vtkSelection* sel)
{
if (this->CurrentAnnotation)
{
this->CurrentAnnotation->SetSelection(sel);
this->Modified();
}
}
vtkSelection* vtkAnnotationLayers::GetCurrentSelection()
{
if (this->CurrentAnnotation)
{
return this->CurrentAnnotation->GetSelection();
}
return 0;
}
unsigned int vtkAnnotationLayers::GetNumberOfAnnotations()
{
return static_cast<unsigned int>(this->Implementation->Annotations.size());
}
vtkAnnotation* vtkAnnotationLayers::GetAnnotation(unsigned int idx)
{
if (idx >= this->Implementation->Annotations.size())
{
return 0;
}
return this->Implementation->Annotations[idx];
}
void vtkAnnotationLayers::AddAnnotation(vtkAnnotation* annotation)
{
this->Implementation->Annotations.push_back(annotation);
this->Modified();
}
void vtkAnnotationLayers::RemoveAnnotation(vtkAnnotation* annotation)
{
this->Implementation->Annotations.erase(
vtkstd::remove(
this->Implementation->Annotations.begin(),
this->Implementation->Annotations.end(),
annotation),
this->Implementation->Annotations.end());
this->Modified();
}
void vtkAnnotationLayers::Initialize()
{
this->Implementation->Annotations.clear();
this->Modified();
}
void vtkAnnotationLayers::ShallowCopy(vtkDataObject* other)
{
this->Superclass::ShallowCopy(other);
vtkAnnotationLayers* obj = vtkAnnotationLayers::SafeDownCast(other);
if (!obj)
{
return;
}
this->Implementation->Annotations.clear();
for (unsigned int a = 0; a < obj->GetNumberOfAnnotations(); ++a)
{
vtkAnnotation* ann = obj->GetAnnotation(a);
this->AddAnnotation(ann);
}
this->SetCurrentAnnotation(obj->GetCurrentAnnotation());
}
void vtkAnnotationLayers::DeepCopy(vtkDataObject* other)
{
this->Superclass::DeepCopy(other);
vtkAnnotationLayers* obj = vtkAnnotationLayers::SafeDownCast(other);
if (!obj)
{
return;
}
this->Implementation->Annotations.clear();
for (unsigned int a = 0; a < obj->GetNumberOfAnnotations(); ++a)
{
vtkSmartPointer<vtkAnnotation> ann =
vtkSmartPointer<vtkAnnotation>::New();
ann->DeepCopy(obj->GetAnnotation(a));
this->AddAnnotation(ann);
}
}
unsigned long vtkAnnotationLayers::GetMTime()
{
unsigned long mtime = this->Superclass::GetMTime();
for (unsigned int a = 0; a < this->GetNumberOfAnnotations(); ++a)
{
vtkAnnotation* ann = this->GetAnnotation(a);
if (ann)
{
unsigned long atime = ann->GetMTime();
if (atime > mtime)
{
mtime = atime;
}
}
}
vtkAnnotation* s = this->GetCurrentAnnotation();
if (s)
{
unsigned long stime = this->GetCurrentAnnotation()->GetMTime();
if (stime > mtime)
{
mtime = stime;
}
}
return mtime;
}
void vtkAnnotationLayers::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
vtkIndent next = indent.GetNextIndent();
for (unsigned int a = 0; a < this->GetNumberOfAnnotations(); ++a)
{
os << next << "Annotation " << a << ":";
vtkAnnotation* ann = this->GetAnnotation(a);
if (ann)
{
os << "\n";
ann->PrintSelf(os, next.GetNextIndent());
}
else
{
os << "(none)\n";
}
}
os << indent << "CurrentAnnotation: ";
if (this->CurrentAnnotation)
{
os << "\n";
this->CurrentAnnotation->PrintSelf(os, indent.GetNextIndent());
}
else
{
os << "(none)\n";
}
}
vtkAnnotationLayers* vtkAnnotationLayers::GetData(vtkInformation* info)
{
return info ? vtkAnnotationLayers::SafeDownCast(info->Get(DATA_OBJECT())) : 0;
}
vtkAnnotationLayers* vtkAnnotationLayers::GetData(vtkInformationVector* v, int i)
{
return vtkAnnotationLayers::GetData(v->GetInformationObject(i));
}