[vtkusers] Strange results with MST filter

David Doria daviddoria+vtk at gmail.com
Wed Apr 14 10:38:39 EDT 2010


> As a check, try running vtkBoostKruskalMinimumSpanningTree instead of
> Prim's algorithm and compare the results.
>
> Jeff
>

Jeff,

Trying another algorithm is a good idea. I'm curious why Kruskal's
algorithm is a vtkSelectionAlgorithm subclass, while Prim's algorithm
is a vtkTreeAlgorithm subclass? Wouldn't it be nice to be able to
exchange the two directly?

Trying to get Kruskal's algorithm working, I tried this:

  vtkSmartPointer<vtkBoostKruskalMinimumSpanningTree> kruskalFilter =
     vtkSmartPointer<vtkBoostKruskalMinimumSpanningTree>::New();
  kruskalFilter->SetInputConnection(reader->GetOutputPort());
  kruskalFilter->SetEdgeWeightArrayName("Weights");
  kruskalFilter->Update();

  vtkSmartPointer<vtkExtractSelection> extractSelection =
      vtkSmartPointer<vtkExtractSelection>::New();
  extractSelection->SetInput(0, reader->GetOutput());
  extractSelection->SetInput(1, kruskalFilter->GetOutput());
  extractSelection->Update();

  cout << "selection output is type: " <<
extractSelection->GetOutput()->GetClassName() << endl;

  //output information about the minimum spanning tree
  vtkDataObject* dataObject = extractSelection->GetOutput();
  vtkGraph* mst = vtkGraph::SafeDownCast(dataObject);

I tried to cast this 'dataObject' to a vtkGraph and a vtkTree, and
both failed (mst was NULL).

How would I get the Kruskal MST into a vtkTree?

Thanks,

David



More information about the vtkusers mailing list