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

Method GetSelectedCompositeIds

Common/DataModel/vtkDataAssemblyUtilities.cxx:654–736  ·  view source on GitHub ↗

----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

652
653//----------------------------------------------------------------------------
654std::vector<unsigned int> vtkDataAssemblyUtilities::GetSelectedCompositeIds(
655 const std::vector<std::string>& selectors, vtkDataAssembly* hierarchyOrAssembly,
656 vtkPartitionedDataSetCollection* data, bool leaf_nodes_only)
657{
658 if (hierarchyOrAssembly == nullptr || selectors.empty())
659 {
660 return {};
661 }
662
663 const auto root = vtkDataAssembly::GetRootNode();
664 const bool isHierarchy =
665 (strcmp(hierarchyOrAssembly->GetAttributeOrDefault(root, CATEGORY_ATTRIBUTE_NAME, ""),
666 CATEGORY_HIERARCHY) == 0);
667 if (!isHierarchy && data == nullptr)
668 {
669 vtkLogF(ERROR, "Missing required `data` argument.");
670 return {};
671 }
672
673 if (isHierarchy && leaf_nodes_only)
674 {
675 const auto dataType = hierarchyOrAssembly->GetAttributeOrDefault(root, "vtk_type", -1);
676 // for now we only support MBs. we could support AMR and PDC,
677 // but I don't see the point in doing so right now.
678 if (!vtkDataObjectTypes::TypeIdIsA(dataType, VTK_MULTIBLOCK_DATA_SET))
679 {
680 vtkLogF(ERROR, "Hierarchy does not represent a supported composite dataset type (%s)",
681 vtkDataObjectTypes::GetClassNameFromTypeId(dataType));
682 return {};
683 }
684
685 // the worst case: we need to traverse the hierarchy and determine composite
686 // ids.
687 const auto nodes = hierarchyOrAssembly->SelectNodes(selectors);
688 vtkNew<vtkGenerateIdsVisitor> visitor;
689 std::copy(nodes.begin(), nodes.end(),
690 std::inserter(visitor->SelectedNodes, visitor->SelectedNodes.end()));
691 hierarchyOrAssembly->Visit(visitor);
692 return visitor->CompositeIndices;
693 }
694
695 // here, we only traverse the subtree if not a hierarchy. Otherwise, the
696 // dataset indices are directly composite ids so we don't need to traverse
697 // substree.
698 auto dsIndices = hierarchyOrAssembly->GetDataSetIndices(
699 hierarchyOrAssembly->SelectNodes(selectors), /*traverse_subtree=*/!isHierarchy);
700
701 if (isHierarchy)
702 {
703 assert(leaf_nodes_only == false);
704
705 // in this case, dsIndices directly correspond to the composite ids;
706 // nothing more to do.
707 return dsIndices;
708 }
709 else if (!isHierarchy && !leaf_nodes_only)
710 {
711 // convert partitioned dataset index to composite index.

Callers

nothing calls this directly

Calls 15

GetRootNodeFunction · 0.85
GetAttributeOrDefaultMethod · 0.80
SelectNodesMethod · 0.80
GetDataSetIndicesMethod · 0.80
copyFunction · 0.50
assertFunction · 0.50
TransformFunction · 0.50
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
VisitMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected