| 225 | } |
| 226 | |
| 227 | int vtkCellGrid::GetAttributeTypeForArray(vtkAbstractArray* arr) |
| 228 | { |
| 229 | // First, see if the array is marked with a group for fast lookup. |
| 230 | if (arr->HasInformation()) |
| 231 | { |
| 232 | auto* info = arr->GetInformation(); |
| 233 | if (info->Has(ARRAY_GROUP_IDS())) |
| 234 | { |
| 235 | int numGroups = info->Length(vtkCellGrid::ARRAY_GROUP_IDS()); |
| 236 | int* groupIds = info->Get(vtkCellGrid::ARRAY_GROUP_IDS()); |
| 237 | for (int gg = 0; gg < numGroups; ++gg) |
| 238 | { |
| 239 | if (auto* group = this->FindAttributes(groupIds[gg])) |
| 240 | { |
| 241 | if (auto* array = group->GetAbstractArray(arr->GetName())) |
| 242 | { |
| 243 | if (array != arr) |
| 244 | { |
| 245 | // NB: We might update info by rewriting ARRAY_GROUP_IDS to |
| 246 | // exclude groupIds[gg], but it is possible – because |
| 247 | // arrays are shallow-copied – that they may end up in |
| 248 | // multiple groups across multiple instances of |
| 249 | // vtkCellGrid and we do not necessarily want to de-index |
| 250 | // arr across all cell-grids. |
| 251 | continue; |
| 252 | } |
| 253 | return groupIds[gg]; |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | // Next, search through DOF arrays: |
| 261 | for (auto it = this->ArrayGroups.begin(); it != this->ArrayGroups.end(); ++it) |
| 262 | { |
| 263 | for (int ii = 0; ii < it->second->GetNumberOfArrays(); ++ii) |
| 264 | { |
| 265 | if (it->second->GetAbstractArray(ii) == arr) |
| 266 | { |
| 267 | // Accelerate next lookup by adding the result. |
| 268 | arr->GetInformation()->Append(ARRAY_GROUP_IDS(), it->first); |
| 269 | return it->first; |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | // If not a DOF array, perhaps it is field data: |
| 275 | for (int ii = 0; ii < this->FieldData->GetNumberOfArrays(); ++ii) |
| 276 | { |
| 277 | if (this->FieldData->GetAbstractArray(ii) == arr) |
| 278 | { |
| 279 | return FIELD; |
| 280 | } |
| 281 | } |
| 282 | // No such array is owned by this vtkCellGrid: |
| 283 | return -1; |
| 284 | } |
no test coverage detected