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

Method SubsetCopy

Common/DataModel/vtkDataAssembly.cxx:1324–1412  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1322
1323//------------------------------------------------------------------------------
1324void vtkDataAssembly::SubsetCopy(vtkDataAssembly* other, const std::vector<int>& selected_branches)
1325{
1326 this->Initialize();
1327 if (other == nullptr)
1328 {
1329 return;
1330 }
1331
1332 auto& internals = (*this->Internals);
1333 const auto& ointernals = (*other->Internals);
1334
1335 if (selected_branches.empty())
1336 {
1337 auto src = ointernals.Document.first_child();
1338 auto dest = internals.Document.first_child();
1339
1340 dest.set_name(src.name());
1341 for (const auto& attribute : src.attributes())
1342 {
1343 dest.append_copy(attribute);
1344 }
1345 return;
1346 }
1347
1348 std::unordered_set<int> complete_subtree;
1349 std::unordered_set<int> partial_subtree;
1350
1351 for (const auto& id : selected_branches)
1352 {
1353 auto node = ointernals.FindNode(id);
1354 if (node)
1355 {
1356 complete_subtree.insert(id);
1357 }
1358 while ((node = node.parent()))
1359 {
1360 if (!partial_subtree.insert(node.attribute("id").as_int(-1)).second)
1361 {
1362 // parent already inserted, short-cut traversal.
1363 break;
1364 }
1365 }
1366 }
1367
1368 if (complete_subtree.find(0) != complete_subtree.end())
1369 {
1370 this->DeepCopy(other);
1371 return;
1372 }
1373
1374 // ensure root is always in the partial_subtree
1375 assert(partial_subtree.find(0) != partial_subtree.end());
1376
1377 std::function<void(const pugi::xml_node&, pugi::xml_node)> subset_copier;
1378 subset_copier = [&partial_subtree, &complete_subtree, &subset_copier](
1379 const pugi::xml_node& src, pugi::xml_node dest) -> void
1380 {
1381 // first, copy src attributes over.

Callers 3

RequestDataMethod · 0.80
TestDataAssemblyFunction · 0.80
ExecuteMethod · 0.80

Calls 15

InitializeMethod · 0.95
DeepCopyMethod · 0.95
IsAssemblyNodeFunction · 0.85
IsDataSetNodeFunction · 0.85
first_childMethod · 0.80
set_nameMethod · 0.80
attributesMethod · 0.80
append_copyMethod · 0.80
FindNodeMethod · 0.80
as_intMethod · 0.80
attributeMethod · 0.80
childrenMethod · 0.80

Tested by 1

TestDataAssemblyFunction · 0.64