| 181 | } |
| 182 | |
| 183 | vtkIdTypeArray* vtkCellCenterDepthSort::GetNextCells() |
| 184 | { |
| 185 | if (this->ToSort->Stack.empty()) |
| 186 | { |
| 187 | // Already sorted and returned everything. |
| 188 | return nullptr; |
| 189 | } |
| 190 | |
| 191 | vtkIdType* cellIds = this->SortedCells->GetPointer(0); |
| 192 | float* cellDepths = this->CellDepths->GetPointer(0); |
| 193 | vtkIdPair partition; |
| 194 | |
| 195 | partition = this->ToSort->Stack.top(); |
| 196 | this->ToSort->Stack.pop(); |
| 197 | while (partition.second - partition.first > this->MaxCellsReturned) |
| 198 | { |
| 199 | vtkIdType left = partition.first; |
| 200 | vtkIdType right = partition.second - 1; |
| 201 | float pivot = cellDepths[static_cast<vtkIdType>(vtkMath::Random(left, right))]; |
| 202 | while (left <= right) |
| 203 | { |
| 204 | while ((left <= right) && (cellDepths[left] < pivot)) |
| 205 | left++; |
| 206 | while ((left <= right) && (cellDepths[right] > pivot)) |
| 207 | right--; |
| 208 | |
| 209 | if (left > right) |
| 210 | break; |
| 211 | |
| 212 | std::swap(cellIds[left], cellIds[right]); |
| 213 | std::swap(cellDepths[left], cellDepths[right]); |
| 214 | |
| 215 | left++; |
| 216 | right--; |
| 217 | } |
| 218 | |
| 219 | this->ToSort->Stack.emplace(left, partition.second); |
| 220 | partition.second = left; |
| 221 | } |
| 222 | |
| 223 | if (partition.second <= partition.first) |
| 224 | { |
| 225 | // Got a partition of zero size. Just recurse to get the next one. |
| 226 | return this->GetNextCells(); |
| 227 | } |
| 228 | |
| 229 | vtkIdType firstcell = partition.first; |
| 230 | vtkIdType numcells = partition.second - partition.first; |
| 231 | |
| 232 | this->SortedCellPartition->SetArray(cellIds + firstcell, numcells, 1); |
| 233 | this->SortedCellPartition->SetNumberOfTuples(numcells); |
| 234 | this->CellPartitionDepths->SetArray(cellDepths + firstcell, numcells, 1); |
| 235 | this->CellPartitionDepths->SetNumberOfTuples(numcells); |
| 236 | |
| 237 | vtkSortDataArray::Sort(this->CellPartitionDepths, this->SortedCellPartition); |
| 238 | return this->SortedCellPartition; |
| 239 | } |
| 240 | VTK_ABI_NAMESPACE_END |
no test coverage detected