[vtkusers] GetEdgeData->Reset() breaks EdgeData
David Doria
daviddoria+vtk at gmail.com
Tue Mar 30 16:09:03 EDT 2010
It seems that after I call Reset(), I cannot add anything to the
EdgeData. The following examples shows that I add a length 2 weight
array to the graph, prove that it was added properly, Reset() the
EdgeData, then try to add the weight array again. This time, the graph
contains 0 weights after adding the weights array. The only reason I
started calling Reset is because in my filter the number of weights is
being reported incorrectly, I believe because it used to have a
"Weights" array, and I am trying to replace it with a new one.
Any thoughts?
#include <vtkSmartPointer.h>
#include <vtkDoubleArray.h>
#include <vtkDataSetAttributes.h>
#include <vtkMutableDirectedGraph.h>
int main(int argc, char *argv[])
{
vtkSmartPointer<vtkMutableDirectedGraph> dg =
vtkSmartPointer<vtkMutableDirectedGraph>::New();
vtkIdType v1 = dg->AddVertex();
vtkIdType v2 = dg->AddChild(v1);
vtkSmartPointer<vtkDoubleArray> weights =
vtkSmartPointer<vtkDoubleArray>::New();
weights->SetNumberOfComponents(1);
weights->SetName("Weights");
//set the edge weights
weights->InsertNextValue(1.0);
weights->InsertNextValue(2.0);
cout << "Number of weights in array: " <<
weights->GetNumberOfTuples() << endl;
//add the edge weight array to the graph
dg->GetEdgeData()->AddArray(weights);
cout << "Number of weights added: " <<
vtkDoubleArray::SafeDownCast(dg->GetEdgeData()->GetArray("Weights"))->GetNumberOfTuples()
<< endl;
dg->GetEdgeData()->Reset();
cout << "Number of weights: " <<
vtkDoubleArray::SafeDownCast(dg->GetEdgeData()->GetArray("Weights"))->GetNumberOfTuples()
<< endl;
dg->GetEdgeData()->AddArray(weights);
cout << "Number of weights added: " <<
vtkDoubleArray::SafeDownCast(dg->GetEdgeData()->GetArray("Weights"))->GetNumberOfTuples()
<< endl;
return EXIT_SUCCESS;
}
Thanks,
David
More information about the vtkusers
mailing list