MCPcopy Create free account
hub / github.com/Kitware/VTK / Sort

Method Sort

Rendering/Image/vtkImageSliceCollection.cxx:89–149  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Sorts the vtkImageSliceCollection by layer number. Smaller layer numbers are first. Layer numbers can be any integer value.

Source from the content-addressed store, hash-verified

87// Sorts the vtkImageSliceCollection by layer number. Smaller layer
88// numbers are first. Layer numbers can be any integer value.
89void vtkImageSliceCollection::Sort()
90{
91 // Create a temporary array of pointers to images
92 int numElems = this->GetNumberOfItems();
93 vtkImageSliceLayerPair defaultLayerArray[8];
94 vtkImageSliceLayerPair* layerArray = defaultLayerArray;
95 if (numElems > 8)
96 {
97 layerArray = new vtkImageSliceLayerPair[numElems];
98 }
99
100 // Start at the beginning of the collection
101 vtkCollectionSimpleIterator ait;
102 this->InitTraversal(ait);
103
104 // Fill the image array with the items in the collection
105 for (int ii = 0; ii < numElems; ii++)
106 {
107 vtkImageSlice* image = this->GetNextImage(ait);
108 layerArray[ii].image = image;
109 layerArray[ii].layer = image->GetProperty()->GetLayerNumber();
110 }
111
112 // The collection will be small (often with n=2) so do a brute-force
113 // selection sort, which also keeps items with the same layer number
114 // in the same order as before the sort.
115 for (int i = 0; i < numElems - 1; i++)
116 {
117 int imin = i;
118 int lmin = layerArray[imin].layer;
119 int j = i + 1;
120
121 do
122 {
123 int l = layerArray[j].layer;
124 if (l < lmin)
125 {
126 imin = j;
127 lmin = l;
128 }
129 } while (++j < numElems);
130
131 vtkImageSliceLayerPair t = layerArray[imin];
132 layerArray[imin] = layerArray[i];
133 layerArray[i] = t;
134 }
135
136 // Now move the items around in the linked list -
137 // keep the links the same, but swap around the items
138 vtkCollectionElement* elem = this->Top;
139 for (int jj = 0; jj < numElems; jj++)
140 {
141 elem->Item = layerArray[jj].image;
142 elem = elem->Next;
143 }
144
145 if (layerArray != defaultLayerArray)
146 {

Callers 1

RenderOpaqueGeometryMethod · 0.45

Calls 4

GetNextImageMethod · 0.95
GetNumberOfItemsMethod · 0.45
InitTraversalMethod · 0.45
GetPropertyMethod · 0.45

Tested by

no test coverage detected