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

Method FactorElementsInternal

IO/XMLParser/vtkXMLUtilities.cxx:562–631  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

560
561//------------------------------------------------------------------------------
562int vtkXMLUtilities::FactorElementsInternal(
563 vtkXMLDataElement* tree, vtkXMLDataElement* root, vtkXMLDataElement* pool)
564{
565 if (!tree || !root || !pool)
566 {
567 return 0;
568 }
569
570 // Do not bother factoring something already factored
571
572 if (tree->GetName() && !strcmp(tree->GetName(), VTK_XML_UTILITIES_FACTORED_REF_NAME))
573 {
574 return 0;
575 }
576
577 // Try to find all trees similar to the current tree
578
579 vtkXMLDataElement** similar_trees;
580 int nb_of_similar_trees = vtkXMLUtilities::FindSimilarElements(tree, root, &similar_trees);
581
582 // None was found, try to factor the sub-trees
583
584 if (!nb_of_similar_trees)
585 {
586 int res = 0;
587 for (int i = 0; i < tree->GetNumberOfNestedElements(); i++)
588 {
589 res += vtkXMLUtilities::FactorElementsInternal(tree->GetNestedElement(i), root, pool);
590 }
591 return res ? 1 : 0;
592 }
593
594 // Otherwise replace those trees with factored refs
595
596 auto buffer = vtk::format("{:02d}_", pool->GetNumberOfNestedElements());
597
598 std::ostringstream id;
599 id << buffer << tree->GetName();
600
601 vtkXMLDataElement* factored = vtkXMLDataElement::New();
602 factored->SetName(VTK_XML_UTILITIES_FACTORED_NAME);
603 factored->SetAttributeEncoding(pool->GetAttributeEncoding());
604 factored->SetAttribute("Id", id.str().c_str());
605 pool->AddNestedElement(factored);
606 factored->Delete();
607
608 vtkXMLDataElement* tree_copy = vtkXMLDataElement::New();
609 tree_copy->DeepCopy(tree);
610 factored->AddNestedElement(tree_copy);
611 tree_copy->Delete();
612
613 for (int i = 0; i < nb_of_similar_trees; i++)
614 {
615 similar_trees[i]->RemoveAllAttributes();
616 similar_trees[i]->RemoveAllNestedElements();
617 similar_trees[i]->SetCharacterData(nullptr, 0);
618 similar_trees[i]->SetName(VTK_XML_UTILITIES_FACTORED_REF_NAME);
619 similar_trees[i]->SetAttribute("Id", id.str().c_str());

Callers

nothing calls this directly

Calls 15

GetNestedElementMethod · 0.80
AddNestedElementMethod · 0.80
RemoveAllAttributesMethod · 0.80
SetCharacterDataMethod · 0.80
DeleteMethod · 0.65
formatFunction · 0.50
NewFunction · 0.50
GetNameMethod · 0.45
SetNameMethod · 0.45
SetAttributeMethod · 0.45

Tested by

no test coverage detected