Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkConnectomicsNetworkConverter.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
20 {
21 }
22 
24 {
25 }
26 
28 {
29  int numberOfNodes = boost::num_vertices( *(m_Network->GetBoostGraph()) );
30 
31  //initialize a matrix N by N
32  vnl_matrix<double> matrix(numberOfNodes, numberOfNodes, 0);
33 
34  //Define the vertex iterators
35  VertexIteratorType vi, vi_end;
36  for(boost::tie(vi, vi_end) = boost::vertices( *(m_Network->GetBoostGraph()) ); vi != vi_end; ++vi)
37  {
38  //Define the neighbor iterator
39  AdjacencyIteratorType neighbors, neighbors_end;
40  for(boost::tie(neighbors, neighbors_end) = boost::adjacent_vertices(*vi, *(m_Network->GetBoostGraph()) );
41  neighbors != neighbors_end; ++neighbors )
42  {
43  //Set the i,j element of the matrix to 1.
44  matrix.put(*vi, *neighbors, 1);
45  }
46  }
47  return matrix;
48 }
49 
51 {
52  int numberOfNodes = boost::num_vertices( *(m_Network->GetBoostGraph()) );
53 
54  vnl_matrix<double> matrix( numberOfNodes, numberOfNodes, 0);
55 
56  //Define the vertex iterators
57  VertexIteratorType vi, vi_end;
58  for(boost::tie(vi, vi_end) = boost::vertices( *(m_Network->GetBoostGraph()) ); vi != vi_end; ++vi)
59  {
60  double numberOfNeighbors = 0;
61  //Define the neighbor iterator
62  AdjacencyIteratorType neighbors, neighbors_end;
63  for( boost::tie(neighbors, neighbors_end) = adjacent_vertices(*vi, *(m_Network->GetBoostGraph()) );
64  neighbors != neighbors_end; ++neighbors )
65  {
66  numberOfNeighbors++;
67  }
68  matrix.put(*vi, *vi, numberOfNeighbors);
69  }
70  return matrix;
71 }
boost::graph_traits< NetworkType >::adjacency_iterator AdjacencyIteratorType
boost::graph_traits< NetworkType >::vertex_iterator VertexIteratorType