[vtkusers] converting vtkGraph to boostGraph to use with OpenGraphFixedTracking from D. Doria

Jeff Baumes jeff.baumes at kitware.com
Thu Feb 7 07:21:01 EST 2013


It appears graph_copy does not support the graph_traits<> template
specialization to retrieve associated types for a graph, but instead relies
on typedefs being defined directly in the class, which vtkGraph does not
have.

Looks like you may need to traverse manually to do the conversion.
Something like the following:

for (vtkIdType i = 0; i < graph->GetNumberOfVertices(); ++i)
{
  add_vertex(g);
}

for (vtkIdType i = 0; i < graph->GetNumberOfEdges(); ++i)
{
  add_edge(graph->GetSourceVertex(i), graph->GetTargetVertex(i), g);
}


On Thu, Feb 7, 2013 at 4:45 AM, Dr. Roman Grothausmann <
grothausmann.roman at mh-hannover.de> wrote:

> Dear Jeff,
>
>
> Many thanks for Your reply.
>
>
> On 06/02/13 15:45, Jeff Baumes wrote:
>
>> You may want to try making an instance of this specific
>> graph type and use copy_graph
>> <http://www.boost.org/doc/**libs/1_53_0/libs/graph/doc/**copy_graph.html<http://www.boost.org/doc/libs/1_53_0/libs/graph/doc/copy_graph.html>>
>> to convert
>>
>> the vtkGraph to the type the library expects.
>>
>
> I tried the following:
>
>
>
>   vtkGraph* graph= polyDataToGraphFilter->**GetOutput();
>
>   //vtkBoostUndirectedGraph g(graph);
>
>   Graph g;
>   boost::copy_graph(graph, g);
>
>
> but it fails with:
>
> In file included from /home/grothama/vtk/**GraphOpening-master/**
> GraphOpeningTrackingExample_**01.cxx:29:0:
> /usr/include/boost/graph/copy.**hpp: In instantiation of ‘struct
> boost::detail::choose_graph_**copy<vtkGraph*>’:
> /usr/include/boost/graph/copy.**hpp:347:7:   required from ‘void
> boost::copy_graph(const VertexListGraph&, MutableGraph&) [with
> VertexListGraph = vtkGraph*; MutableGraph = boost::adjacency_list<boost::*
> *vecS, boost::vecS, boost::undirectedS, boost::no_property,
> EdgeVisibility>]’
> /home/grothama/vtk/**GraphOpening-master/**GraphOpeningTrackingExample_**01.cxx:87:29:
>   required from here
> /usr/include/boost/graph/copy.**hpp:251:50: error: ‘vtkGraph*’ is not a
> class, struct, or union type
>
> Do all these problems arise of the property EdgeVisibility (which I would
> not need at all) or am I using vtkBoostGraphAdapter.h and boost::copy_graph
> in the wrong way?
>
> Thanks for any help or hints
> Roman
>
>
> If copy_graph doesn't work you may
>
>> need to manually iterate over vertices/edges to construct the graph.
>>
>>
>> On Wed, Feb 6, 2013 at 9:30 AM, Dr. Roman Grothausmann
>> <grothausmann.roman at mh-**hannover.de <grothausmann.roman at mh-hannover.de><mailto:
>> grothausmann.roman at mh-**hannover.de <grothausmann.roman at mh-hannover.de>>>
>>
>> wrote:
>>
>>     Dear mailing list members,
>>
>>
>>     How can I use a vtkGraph as a boostGraph which is needed for
>>     OpenGraphFixedTracking from D. Doria
>>     (http://www.midasjournal.org/_**_browse/publication/828<http://www.midasjournal.org/__browse/publication/828>
>>     <http://www.midasjournal.org/**browse/publication/828<http://www.midasjournal.org/browse/publication/828>
>> >)?
>>
>>     I looked at vtkBoostBreadthFirstSearch.cxx and included
>>     vtkBoostGraphAdapter.h (see below) and copied it to the project dir
>> (seems
>>     this header-file is not installed with VTK, why?) but I still get an
>> error:
>>
>>     error: invalid user-defined conversion from ‘vtkGraph*’ to ‘const
>> Graph&
>>     {aka const boost::adjacency_list<boost::_**_vecS, boost::vecS,
>>
>>     boost::undirectedS, boost::no_property, EdgeVisibility>&}’
>> [-fpermissive]
>>
>>     What am I missing?
>>
>>     Any help or hints are very much appreciated
>>     Roman
>>
>>     ______________________________**__________
>>
>>
>>
>>     #include "vtkBoostGraphAdapter.h"
>>
>>     #include <vtkXMLPolyDataReader.h>//for vtp-files (cannot contain 3D
>> cells?)
>>     #include <vtkPolyDataToGraph.h>
>>
>>     #include <vtkGraphToPolyData.h>
>>     #include <vtkXMLPolyDataWriter.h>//for vtp-files
>>
>>     ...
>>
>>        // Read the graph
>>        //Graph graph = ReadGraph(inputFileName);
>>
>>        vtkSmartPointer<__**vtkXMLPolyDataReader> reader =
>>     vtkSmartPointer<__**vtkXMLPolyDataReader>::New();
>>
>>        //reader->SetFileName(__**inputFileName);
>>
>>        reader->SetFileName(argv[1]);
>>        reader->Update();
>>
>>        vtkSmartPointer<__**vtkPolyDataToGraph> polyDataToGraphFilter=
>>     vtkSmartPointer<__**vtkPolyDataToGraph>::New();
>>        polyDataToGraphFilter->__**SetInputConnection(reader->__**
>> GetOutputPort());
>>        polyDataToGraphFilter->Update(**__);
>>
>>        vtkGraph* graph= polyDataToGraphFilter->__**GetOutput();
>>
>>        //vtkBoostUndirectedGraph g(graph);
>>
>>        //vtkUndirectedGraph *g = vtkUndirectedGraph::__**
>> SafeDownCast(graph);
>>
>>        //Graph openedGraph = OpenGraphFixedTracking(g,
>> numberOfIterations);
>>        //Graph openedGraph =
>>     OpenGraphFixedTracking(boost::**__graph_traits<graph>,
>> numberOfIterations);
>>
>>        Graph openedGraph = OpenGraphFixedTracking(graph,
>> numberOfIterations);
>>        //WriteGraph(openedGraph, outputFileName);
>>
>>        vtkSmartPointer<__**vtkGraphToPolyData> graphToPolyData=
>>     vtkSmartPointer<__**vtkGraphToPolyData>::New();
>>        graphToPolyData->SetInput(__**openedGraph);
>>        graphToPolyData->Update();
>>
>>        vtkSmartPointer<__**vtkXMLPolyDataWriter> writer=
>>     vtkSmartPointer<__**vtkXMLPolyDataWriter>::New();
>>        //writer->SetFileName(__**outputFileName);
>>        writer->SetFileName(argv[2]);
>>        writer->SetInputConnection(__**graphToPolyData->__**
>> GetOutputPort());
>>
>>        writer->Write();
>>
>>
>>     --
>>     Dr. Roman Grothausmann
>>
>>     Tomographie und Digitale Bildverarbeitung
>>     Tomography and Digital Image Analysis
>>
>>     Institut für Funktionelle und Angewandte Anatomie, OE 4120
>>     Medizinische Hochschule Hannover
>>     Carl-Neuberg-Str. 1
>>     D-30625 Hannover
>>
>>     Tel. +49 511 532-9574 <tel:%2B49%20511%20532-9574>
>>
>>     ______________________________**_________________
>>     Powered by www.kitware.com <http://www.kitware.com>
>>
>>
>>     Visit other Kitware open-source projects at
>>     http://www.kitware.com/**opensource/opensource.html<http://www.kitware.com/opensource/opensource.html>
>>
>>     Please keep messages on-topic and check the VTK FAQ at:
>>     http://www.vtk.org/Wiki/VTK_**FAQ <http://www.vtk.org/Wiki/VTK_FAQ>
>>
>>     Follow this link to subscribe/unsubscribe:
>>     http://www.vtk.org/mailman/**listinfo/vtkusers<http://www.vtk.org/mailman/listinfo/vtkusers>
>>
>>
>>
> --
> Dr. Roman Grothausmann
>
> Tomographie und Digitale Bildverarbeitung
> Tomography and Digital Image Analysis
>
> Institut für Funktionelle und Angewandte Anatomie, OE 4120
> Medizinische Hochschule Hannover
> Carl-Neuberg-Str. 1
> D-30625 Hannover
>
> Tel. +49 511 532-9574
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130207/5f4f5495/attachment.htm>


More information about the vtkusers mailing list