Commit a7d31f98 authored by Zack Galbreath's avatar Zack Galbreath Committed by Code Review

Merge topic 'improve_big_tree_reader' into master

907df317 improve performance when reading a large Newick tree
parents 9ad49843 907df317
...@@ -774,25 +774,28 @@ vtkTree* vtkRAdapter::RToVTKTree(SEXP variable) ...@@ -774,25 +774,28 @@ vtkTree* vtkRAdapter::RToVTKTree(SEXP variable)
trueWeights->SetNumberOfTuples(tree->GetNumberOfVertices()); trueWeights->SetNumberOfTuples(tree->GetNumberOfVertices());
double maxWeight = 0.0; double maxWeight = 0.0;
for (vtkIdType vertex = 0; vertex < tree->GetNumberOfVertices(); ++vertex) vtkNew<vtkTreeDFSIterator> treeIterator;
{ treeIterator->SetStartVertex(tree->GetRoot());
double weight = 0.0; treeIterator->SetTree(tree);
vtkIdType node = vertex; while (treeIterator->HasNext())
vtkIdType parent = tree->GetParent(node); {
while (parent != -1) vtkIdType vertex = treeIterator->Next();
{ vtkIdType parent = tree->GetParent(vertex);
weight += weights->GetValue(tree->GetEdgeId(parent, node)); double weight = 0.0;
node = parent; if (parent >= 0)
parent = tree->GetParent(node); {
} weight = weights->GetValue(tree->GetEdgeId(parent, vertex));
}
weight += nodeWeights->GetValue(parent);
if (weight > maxWeight) if (weight > maxWeight)
{ {
maxWeight = weight; maxWeight = weight;
} }
nodeWeights->SetValue(vertex, weight); nodeWeights->SetValue(vertex, weight);
trueWeights->SetValue(vertex, weight); trueWeights->SetValue(vertex, weight);
} }
for (vtkIdType vertex = 0; vertex < tree->GetNumberOfVertices(); ++vertex) for (vtkIdType vertex = 0; vertex < tree->GetNumberOfVertices(); ++vertex)
{ {
if (tree->IsLeaf(vertex)) if (tree->IsLeaf(vertex))
...@@ -800,7 +803,6 @@ vtkTree* vtkRAdapter::RToVTKTree(SEXP variable) ...@@ -800,7 +803,6 @@ vtkTree* vtkRAdapter::RToVTKTree(SEXP variable)
nodeWeights->SetValue(vertex, maxWeight); nodeWeights->SetValue(vertex, maxWeight);
} }
} }
nodeWeights->SetName("node weight"); nodeWeights->SetName("node weight");
tree->GetVertexData()->AddArray(nodeWeights.GetPointer()); tree->GetVertexData()->AddArray(nodeWeights.GetPointer());
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "vtkFieldData.h" #include "vtkFieldData.h"
#include "vtkNew.h" #include "vtkNew.h"
#include "vtkTree.h" #include "vtkTree.h"
#include "vtkTreeDFSIterator.h"
#include "vtkInformation.h" #include "vtkInformation.h"
#include "vtkInformationVector.h" #include "vtkInformationVector.h"
#include "vtkMutableDirectedGraph.h" #include "vtkMutableDirectedGraph.h"
...@@ -140,25 +141,28 @@ int vtkNewickTreeReader:: ReadNewickTree( char * const buffer, vtkTree & tree) ...@@ -140,25 +141,28 @@ int vtkNewickTreeReader:: ReadNewickTree( char * const buffer, vtkTree & tree)
//set node weights //set node weights
double maxWeight = 0.0; double maxWeight = 0.0;
for (vtkIdType vertex = 0; vertex < tree.GetNumberOfVertices(); ++vertex) vtkNew<vtkTreeDFSIterator> treeIterator;
treeIterator->SetStartVertex(tree.GetRoot());
treeIterator->SetTree(&tree);
while (treeIterator->HasNext())
{ {
double weight = 0.0; vtkIdType vertex = treeIterator->Next();
vtkIdType node = vertex; vtkIdType parent = tree.GetParent(vertex);
vtkIdType parent = tree.GetParent(node); double weight = 0.0;
while (parent != -1) if (parent >= 0)
{ {
weight += weights->GetValue(tree.GetEdgeId(parent, node)); weight = weights->GetValue(tree.GetEdgeId(parent, vertex));
node = parent; }
parent = tree.GetParent(node); weight += nodeWeights->GetValue(parent);
}
if (weight > maxWeight)
if (weight > maxWeight) {
{ maxWeight = weight;
maxWeight = weight; }
} nodeWeights->SetValue(vertex, weight);
nodeWeights->SetValue(vertex, weight); trueWeights->SetValue(vertex, weight);
trueWeights->SetValue(vertex, weight);
} }
for (vtkIdType vertex = 0; vertex < tree.GetNumberOfVertices(); ++vertex) for (vtkIdType vertex = 0; vertex < tree.GetNumberOfVertices(); ++vertex)
{ {
if (tree.IsLeaf(vertex)) if (tree.IsLeaf(vertex))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment