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

Dr. Roman Grothausmann grothausmann.roman at mh-hannover.de
Thu Feb 7 12:09:17 EST 2013


Many thanks Jeff, that did the trick, got it working now.

On 07/02/13 13:21, Jeff Baumes wrote:
> 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 <mailto: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
>         <mailto:grothausmann.roman at mh-hannover.de>
>         <mailto:grothausmann.roman at mh-__hannover.de
>         <mailto: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>
>         <tel:%2B49%20511%20532-9574>
>
>              _________________________________________________
>              Powered by www.kitware.com <http://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 <tel:%2B49%20511%20532-9574>
>
>

-- 
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



More information about the vtkusers mailing list