------------------------------------------------------------------------------
| 413 | |
| 414 | //------------------------------------------------------------------------------ |
| 415 | void vtkDataSetAttributesFieldList::IntersectFieldList(vtkDataSetAttributes* dsa) |
| 416 | { |
| 417 | auto& internals = *this->Internals; |
| 418 | if (internals.NumberOfInputs == 0) |
| 419 | { |
| 420 | // called without calling InitializeFieldList, just call it. |
| 421 | this->InitializeFieldList(dsa); |
| 422 | internals.Mode = vtkInternals::INTERSECTION; |
| 423 | return; |
| 424 | } |
| 425 | |
| 426 | if (internals.Mode == vtkInternals::UNION) |
| 427 | { |
| 428 | vtkGenericWarningMacro("Mixing of `IntersectFieldList` and `UnionFieldList` " |
| 429 | "calls is not supported!"); |
| 430 | return; |
| 431 | } |
| 432 | internals.Mode = vtkInternals::INTERSECTION; |
| 433 | internals.NumberOfTuples += dsa->GetNumberOfTuples(); |
| 434 | |
| 435 | const auto curfields = detail::GetFields(dsa); |
| 436 | auto& accfields = internals.Fields; |
| 437 | |
| 438 | // first, find the array names in the intersection set. |
| 439 | // we build set of keys for the accumulated fields (accfields) and current |
| 440 | // fields (curfields). |
| 441 | std::set<std::string> acckeys; |
| 442 | for (const auto& pair : accfields) |
| 443 | { |
| 444 | acckeys.insert(pair.first); |
| 445 | } |
| 446 | |
| 447 | std::set<std::string> curkeys; |
| 448 | for (const auto& pair : curfields) |
| 449 | { |
| 450 | curkeys.insert(pair.first); |
| 451 | } |
| 452 | |
| 453 | std::set<std::string> rkeys; |
| 454 | std::set_intersection(acckeys.begin(), acckeys.end(), curkeys.begin(), curkeys.end(), |
| 455 | std::inserter(rkeys, rkeys.end())); |
| 456 | |
| 457 | // second, remove fields from accumulate collection with names not in the |
| 458 | // intersection set. |
| 459 | detail::remove_if(accfields, accfields.begin(), accfields.end(), |
| 460 | [&](const std::pair<std::string, detail::FieldInfo>& pair) |
| 461 | { return rkeys.find(pair.first) == rkeys.end(); }); |
| 462 | |
| 463 | // now, since multiple fields can have same name (including empty names), |
| 464 | // we do second intersection for fields with same names (or no names). |
| 465 | for (const auto& fname : rkeys) |
| 466 | { |
| 467 | decltype(accfields.begin()) acciter, accend; |
| 468 | std::tie(acciter, accend) = accfields.equal_range(fname); |
| 469 | |
| 470 | decltype(curfields.begin()) niter, nend; |
| 471 | std::tie(niter, nend) = curfields.equal_range(fname); |
| 472 |