[vtkusers] Minimum Spanning Trees Re: Building VTK-BGL algorithms (using cmake)

Jeff Baumes jeff.baumes at kitware.com
Tue Dec 30 17:52:06 EST 2008


While BFS outputs a vtkTree, MST outputs a vtkSelection, which selects
the edges that are in the MST. This selection itself cannot be
displayed in a graph view, it is simply a list of edge indices. What
you need to do is to use vtkExtractSelectedGraph, with the original
graph as the first input and the vtkSelection output of MST as the
second input. This will extract the MST from the graph. The output of
vtkExtractSelectedGraph can be sent to the graph view.

Jeff

On Tue, Dec 30, 2008 at 2:54 PM, Aytekin Vargun <varguna at gmail.com> wrote:
>
> I am posting some more code here. I use this in order to display the trees I
> generate in 2D.
> The vertex array, ChannelColors, and Edge Weights are defined somewhere
> else. This code displays the bfs tree. But if I replace the code under LINE
> X below in order to display Kruskal's MST with:
>
> view->AddRepresentationFromInput(mst->GetOutput());
>
> I am getting the following error message:
> "Need input data to render labels (2)"
>
> But I am not getting any error messages for the same labels while displaying
> the bfs tree.
>
> I tried other ways of displaying too.
> Please help.
> Thanks alot.
>
> ---- Display Code ---
>
>    VTK_CREATE(vtkBoostBreadthFirstSearchTree, bfsTree);
>     bfsTree->SetInput(g);
>
>     //Create a graph layout view
>
>     vtkGraphLayoutView* view = vtkGraphLayoutView::New();
>     view->SetLayoutStrategyToPassThrough();
>
>     //LINE X
> ----->    view->AddRepresentationFromInput(bfsTree->GetOutput());
>     view->SetVertexLabelArrayName("Label");
>     view->SetVertexLabelVisibility(true);
>     view->SetVertexColorArrayName("ChannelColors");
>     view->SetColorVertices(true);
>     view->SetEdgeColorArrayName("ChannelColors");
>     view->SetColorEdges(true);
>     //view->SetLayoutStrategyToSimple2D();
>
>     VTK_CREATE(vtkRenderWindow, window);
>     window->SetSize(1000, 1000);
>
>     view->SetupRenderWindow(window);
>     view->GetRenderer()->ResetCamera();
>     window->GetInteractor()->Start();
>
>
>
> On Tue, Dec 30, 2008 at 10:42 AM, Aytekin Vargun <varguna at gmail.com> wrote:
>>
>> Thanks a lot Jeff,
>> It looks like I had several versions of VTK and this was causing problems.
>>
>> Now I have another problem. I am trying to use minimum spanning tree
>> programs. I first tried to use vtkBoostPrimMinimumSpanningTree but I am
>> getting the following error message:
>>
>> "The Prim minimal spanning tree filter is still under development...  Use
>> at your own risk."
>>
>> I checked where the error message is and then assumed that I was getting
>> this message since the implementation is not complete yet. But should I
>> still see some output on the screen?
>>
>> I then tried to use vtkKruskalMinimumSpanningTree which looks like in
>> better shape (whose output is a vtkSelectionAlgorithm). But I am failed to
>> display its output since its output is not a tree but a forest whereas
>> Prim's version produces a vtkTree . Then how can I display each subtree? One
>> way of doing this probably is to cast the result to a graph and then display
>> the resulting graph.
>>
>> I will greatly appreciate if anyone shares his/her experiences.
>> Thanks a lot.
>>
>> Here is a simplified piece of code I am trying to run:
>>
>>   vtkMutableUndirectedGraph* g=vtkMutableUndirectedGraph::New();
>>
>>     // This is used for finding minimum-spanning trees
>>     vtkIntArray* edgeWeightsArr = vtkIntArray::New();
>>     edgeWeightsArr->SetName("EdgeWeights");
>>
>>   VTK_CREATE(vtkRenderer, ren);
>>
>>   VTK_CREATE(vtkPoints, pts);
>>   g->AddVertex();
>>   pts->InsertNextPoint(0, 1, 0);
>>   g->AddVertex();
>>   pts->InsertNextPoint(0.5, 1, 0);
>>   g->AddVertex();
>>   pts->InsertNextPoint(0.25, 0.5, 0);
>>   g->AddVertex();
>>   pts->InsertNextPoint(0, 0, 0);
>>   g->AddVertex();
>>   pts->InsertNextPoint(0.5, 0, 0);
>>   g->AddVertex();
>>   pts->InsertNextPoint(1, 0, 0);
>>   g->AddVertex();
>>   pts->InsertNextPoint(0.75, 0.5, 0);
>>   g->SetPoints(pts);
>>
>>   g->AddEdge(0, 1);
>>   edgeWeightsArr->InsertNextValue(1);
>>   g->AddEdge(0, 2);
>>   edgeWeightsArr->InsertNextValue(1);
>>   g->AddEdge(1, 2);
>>   edgeWeightsArr->InsertNextValue(1);
>>   g->AddEdge(2, 3);
>>   edgeWeightsArr->InsertNextValue(1);
>>   g->AddEdge(2, 4);
>>   edgeWeightsArr->InsertNextValue(1);
>>   g->AddEdge(3, 4);
>>   edgeWeightsArr->InsertNextValue(1);
>>
>>   g->GetEdgeData()->AddArray(edgeWeightsArr);
>>
>>   //VTK_CREATE(vtkBoostPrimMinimumSpanningTree,mst);
>>   VTK_CREATE(vtkBoostKruskalMinimumSpanningTree,mst);
>>   mst->SetInput(g);
>>   mst->SetEdgeWeightArrayName("EdgeWeights");
>>   mst->Update();
>>
>>   // HOW TO DISPLAY
>>
>>
>>
>> On Tue, Dec 23, 2008 at 3:14 PM, Jeff Baumes <jeff.baumes at kitware.com>
>> wrote:
>>>
>>> > When I compile the sample file, I get the first error for the following
>>> > line:
>>> >   VTK_CREATE(vtkBoostBiconnectedComponents, biconn);
>>> >
>>> > (On CMake, I had set VTK_USE_BOOST set to ON when building VTK)
>>>
>>> First, make sure that your app is linking against vtkInfovis. If it
>>> is, it appears that the Boost algorithms are not being compiled into
>>> the vtkInfovis library you are using. Ensure that the vtkInfovis you
>>> are linking against is the one in the build where you turned
>>> VTK_USE_BOOST on. In Visual Studio, you can check your VTK build by
>>> looking at the source files under vtkInfovis. Make sure the vtkBoost*
>>> files are there.
>>>
>>> Jeff
>>
>>
>>
>> --
>> My web page: http://www.cs.rpi.edu/~vargua
>
>
>
> --
> My web page: http://www.cs.rpi.edu/~vargua
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



-- 
Jeff Baumes, Ph.D.
R&D Engineer, Kitware Inc.
(518) 371-3971 x132
jeff.baumes at kitware.com



More information about the vtkusers mailing list