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,17 +774,19 @@ vtkTree* vtkRAdapter::RToVTKTree(SEXP variable)
trueWeights->SetNumberOfTuples(tree->GetNumberOfVertices());
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())
{
vtkIdType vertex = treeIterator->Next();
vtkIdType parent = tree->GetParent(vertex);
double weight = 0.0;
vtkIdType node = vertex;
vtkIdType parent = tree->GetParent(node);
while (parent != -1)
if (parent >= 0)
{
weight += weights->GetValue(tree->GetEdgeId(parent, node));
node = parent;
parent = tree->GetParent(node);
weight = weights->GetValue(tree->GetEdgeId(parent, vertex));
}
weight += nodeWeights->GetValue(parent);
if (weight > maxWeight)
{
......@@ -793,6 +795,7 @@ vtkTree* vtkRAdapter::RToVTKTree(SEXP variable)
nodeWeights->SetValue(vertex, weight);
trueWeights->SetValue(vertex, weight);
}
for (vtkIdType vertex = 0; vertex < tree->GetNumberOfVertices(); ++vertex)
{
if (tree->IsLeaf(vertex))
......@@ -800,7 +803,6 @@ vtkTree* vtkRAdapter::RToVTKTree(SEXP variable)
nodeWeights->SetValue(vertex, maxWeight);
}
}
nodeWeights->SetName("node weight");
tree->GetVertexData()->AddArray(nodeWeights.GetPointer());
......
......@@ -21,6 +21,7 @@
#include "vtkFieldData.h"
#include "vtkNew.h"
#include "vtkTree.h"
#include "vtkTreeDFSIterator.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMutableDirectedGraph.h"
......@@ -140,17 +141,19 @@ int vtkNewickTreeReader:: ReadNewickTree( char * const buffer, vtkTree & tree)
//set node weights
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())
{
vtkIdType vertex = treeIterator->Next();
vtkIdType parent = tree.GetParent(vertex);
double weight = 0.0;
vtkIdType node = vertex;
vtkIdType parent = tree.GetParent(node);
while (parent != -1)
if (parent >= 0)
{
weight += weights->GetValue(tree.GetEdgeId(parent, node));
node = parent;
parent = tree.GetParent(node);
weight = weights->GetValue(tree.GetEdgeId(parent, vertex));
}
weight += nodeWeights->GetValue(parent);
if (weight > maxWeight)
{
......@@ -159,6 +162,7 @@ int vtkNewickTreeReader:: ReadNewickTree( char * const buffer, vtkTree & tree)
nodeWeights->SetValue(vertex, weight);
trueWeights->SetValue(vertex, weight);
}
for (vtkIdType vertex = 0; vertex < tree.GetNumberOfVertices(); ++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