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

Method SetTree

Views/Infovis/vtkDendrogramItem.cxx:93–165  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

91
92//------------------------------------------------------------------------------
93void vtkDendrogramItem::SetTree(vtkTree* tree)
94{
95 if (tree == nullptr || tree->GetNumberOfVertices() == 0)
96 {
97 this->Tree = vtkSmartPointer<vtkTree>::New();
98 this->PrunedTree = vtkSmartPointer<vtkTree>::New();
99 this->LayoutTree = vtkSmartPointer<vtkTree>::New();
100 return;
101 }
102
103 this->Tree = tree;
104
105 vtkSmartPointer<vtkUnsignedIntArray> originalVertexIsPruned =
106 vtkArrayDownCast<vtkUnsignedIntArray>(this->Tree->GetVertexData()->GetArray("VertexIsPruned"));
107
108 // initialize some additional arrays for the tree's vertex data
109 vtkNew<vtkUnsignedIntArray> vertexIsPruned;
110 vertexIsPruned->SetNumberOfComponents(1);
111 vertexIsPruned->SetName("VertexIsPruned");
112 vertexIsPruned->SetNumberOfValues(this->Tree->GetNumberOfVertices());
113 vertexIsPruned->FillComponent(0, 0.0);
114 this->Tree->GetVertexData()->AddArray(vertexIsPruned);
115
116 vtkNew<vtkIdTypeArray> originalId;
117 originalId->SetNumberOfComponents(1);
118 originalId->SetName("OriginalId");
119 vtkIdType numVertices = this->Tree->GetNumberOfVertices();
120 originalId->SetNumberOfValues(numVertices);
121 for (vtkIdType i = 0; i < numVertices; ++i)
122 {
123 originalId->SetValue(i, i);
124 }
125 this->Tree->GetVertexData()->AddArray(originalId);
126
127 // make a copy of the full tree for later pruning
128 this->PrunedTree->DeepCopy(this->Tree);
129
130 // If the tree already had an array named VertexIsPruned,
131 // use that array to construct the pruned tree.
132 if (originalVertexIsPruned)
133 {
134 for (vtkIdType i = 0; i < originalVertexIsPruned->GetNumberOfValues(); ++i)
135 {
136 if (originalVertexIsPruned->GetValue(i))
137 {
138 this->CollapseSubTree(i);
139 }
140 }
141 }
142
143 // setup the lookup table that's used to color the triangles representing
144 // collapsed subtrees. First we find maximum possible value.
145 vtkIdType root = this->Tree->GetRoot();
146 if (this->Tree->GetNumberOfChildren(root) == 1)
147 {
148 root = this->Tree->GetChild(root, 0);
149 }
150 int numLeavesInBiggestSubTree = 0;

Callers 15

ReadNewickTreeMethod · 0.45
ReadXMLDataMethod · 0.45
SetTree1Method · 0.45
SetTree2Method · 0.45
ReorderTreeMethod · 0.45
TestColumnTreeFunction · 0.45
TestDendrogramItemFunction · 0.45
TestTreeHeatmapItemFunction · 0.45
LabelTreeMethod · 0.45
LayoutMethod · 0.45

Calls 15

CollapseSubTreeMethod · 0.95
CountLeafNodesMethod · 0.95
GetNumberOfVerticesMethod · 0.80
GetVertexDataMethod · 0.80
FillComponentMethod · 0.80
NewFunction · 0.50
maxFunction · 0.50
GetArrayMethod · 0.45
SetNumberOfComponentsMethod · 0.45
SetNameMethod · 0.45
SetNumberOfValuesMethod · 0.45

Tested by 4

TestColumnTreeFunction · 0.36
TestDendrogramItemFunction · 0.36
TestTreeHeatmapItemFunction · 0.36