forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkActor2DCollection.cxx
194 lines (144 loc) · 4.85 KB
/
vtkActor2DCollection.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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkActor2DCollection.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 "vtkActor2DCollection.h"
#include "vtkObjectFactory.h"
vtkStandardNewMacro(vtkActor2DCollection);
// protected function to delete an element. Internal use only.
void vtkActor2DCollection::DeleteElement(vtkCollectionElement *e)
{
vtkCollection::DeleteElement(e);
}
// Desctructor for the vtkActor2DCollection class. This removes all
// objects from the collection.
vtkActor2DCollection::~vtkActor2DCollection()
{
this->RemoveAllItems();
}
// Sort and then render the collection of 2D actors.
void vtkActor2DCollection::RenderOverlay(vtkViewport* viewport)
{
if (this->NumberOfItems != 0)
{
this->Sort();
vtkActor2D* tempActor;
vtkCollectionSimpleIterator adit;
for ( this->InitTraversal(adit);
(tempActor = this->GetNextActor2D(adit));)
{
// Make sure that the actor is visible before rendering
if (tempActor->GetVisibility() == 1)
{
tempActor->RenderOverlay(viewport);
}
}
}
}
// Add an actor to the list. The new actor is
// inserted in the list according to it's layer
// number.
void vtkActor2DCollection::AddItem(vtkActor2D *a)
{
vtkCollectionElement* indexElem;
vtkCollectionElement* elem = new vtkCollectionElement;
// Check if the top item is NULL
if (this->Top == NULL)
{
vtkDebugMacro(<<"vtkActor2DCollection::AddItem - Adding item to top of the list");
this->Top = elem;
elem->Item = a;
elem->Next = NULL;
this->Bottom = elem;
this->NumberOfItems++;
a->Register(this);
return;
}
for (indexElem = this->Top;
indexElem != NULL;
indexElem = indexElem->Next)
{
vtkActor2D* tempActor = static_cast<vtkActor2D*>(indexElem->Item);
if (a->GetLayerNumber() < tempActor->GetLayerNumber())
{
// The indexElem item's layer number is larger, so swap
// the new item and the indexElem item.
vtkDebugMacro(<<"vtkActor2DCollection::AddItem - Inserting item");
elem->Item = indexElem->Item;
elem->Next = indexElem->Next;
indexElem->Item = a;
indexElem->Next = elem;
this->NumberOfItems++;
a->Register(this);
return;
}
}
//End of list found before a larger layer number
vtkDebugMacro(<<"vtkActor2DCollection::AddItem - Adding item to end of the list");
elem->Item = a;
elem->Next = NULL;
this->Bottom->Next = elem;
this->Bottom = elem;
this->NumberOfItems++;
a->Register(this);
}
// Sorts the vtkActor2DCollection by layer number. Smaller layer
// numbers are first. Layer numbers can be any integer value.
void vtkActor2DCollection::Sort()
{
int index;
vtkDebugMacro(<<"vtkActor2DCollection::Sort");
int numElems = this->GetNumberOfItems();
// Create an array of pointers to actors
vtkActor2D** actorPtrArr = new vtkActor2D* [numElems];
vtkDebugMacro(<<"vtkActor2DCollection::Sort - Getting actors from collection");
// Start at the beginning of the collection
vtkCollectionSimpleIterator ait;
this->InitTraversal(ait);
// Fill the actor array with the items in the collection
for (index = 0; index < numElems; index++)
{
actorPtrArr[index] = this->GetNextActor2D(ait);
}
vtkDebugMacro(<<"vtkActor2DCollection::Sort - Starting selection sort");
// Start the sorting - selection sort
int i, j, min;
vtkActor2D* t;
for (i = 0; i < numElems - 1; i++)
{
min = i;
for (j = i + 1; j < numElems ; j++)
{
if(actorPtrArr[j]->GetLayerNumber() < actorPtrArr[min]->GetLayerNumber())
{
min = j;
}
}
t = actorPtrArr[min];
actorPtrArr[min] = actorPtrArr[i];
actorPtrArr[i] = t;
}
vtkDebugMacro(<<"vtkActor2DCollection::Sort - Selection sort done.");
for (index = 0; index < numElems; index++)
{
vtkDebugMacro(<<"vtkActor2DCollection::Sort - actorPtrArr["<<index<<"] layer: " <<
actorPtrArr[index]->GetLayerNumber());
}
vtkDebugMacro(<<"vtkActor2DCollection::Sort - Rearraging the linked list.");
// Now move the items around in the linked list -
// keep the links the same, but swap around the items
vtkCollectionElement* elem = this->Top;
elem->Item = actorPtrArr[0];
for (i = 1; i < numElems; i++)
{
elem = elem->Next;
elem->Item = actorPtrArr[i];
}
delete[] actorPtrArr;
}