Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkConnectomicsBetweennessHistogram.cpp
Go to the documentation of this file.
1 
2 /*===================================================================
3 
4 The Medical Imaging Interaction Toolkit (MITK)
5 
6 Copyright (c) German Cancer Research Center,
7 Division of Medical and Biological Informatics.
8 All rights reserved.
9 
10 This software is distributed WITHOUT ANY WARRANTY; without
11 even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE.
13 
14 See LICENSE.txt or http://www.mitk.org for details.
15 
16 ===================================================================*/
17 
19 
20 #include <boost/numeric/conversion/converter.hpp>
21 
23 
25 : m_Mode( UnweightedUndirectedMode )
26 , m_CentralityMap()
27 {
28  m_Subject = "Node Betweenness";
29 }
30 
32 {
33 }
34 
37 {
38  m_Mode = mode;
39 }
40 
42 {
43  return m_Mode;
44 }
45 
47 {
48  NetworkType* boostGraph = source->GetBoostGraph();
49  IteratorType vertex_iterator_begin, vertex_iterator_end;
50 
51  m_CentralityMap.clear();
52  m_CentralityMap.resize( source->GetNumberOfVertices() );
53 
54  switch( m_Mode )
55  {
56  case UnweightedUndirectedMode:
57  {
58  CalculateUnweightedUndirectedBetweennessCentrality( boostGraph, vertex_iterator_begin, vertex_iterator_end );
59  break;
60  }
61  case WeightedUndirectedMode:
62  {
63  CalculateWeightedUndirectedBetweennessCentrality( boostGraph, vertex_iterator_begin, vertex_iterator_end );
64  break;
65  }
66  }
67 
68  ConvertCentralityMapToHistogram();
69 }
70 
72  NetworkType* boostGraph, IteratorType /*vertex_iterator_begin*/, IteratorType /*vertex_iterator_end*/ )
73 {
74  boost::brandes_betweenness_centrality(
75  *boostGraph,
76  boost::centrality_map(
77  boost::make_iterator_property_map( m_CentralityMap.begin(), boost::get( &mitk::ConnectomicsNetwork::NetworkNode::id, *boostGraph ), double() )
78  ).vertex_index_map( boost::get( &mitk::ConnectomicsNetwork::NetworkNode::id, *boostGraph ) )
79  );
80 
81 }
82 
84  NetworkType* /*boostGraph*/, IteratorType /*vertex_iterator_begin*/, IteratorType /*vertex_iterator_end*/ )
85 {
87 }
88 
90 {
91  double maximumFloat( 0.0 );
92 
93  for ( unsigned int index( 0 ); index < m_CentralityMap.size(); index++ )
94  {
95  if( m_CentralityMap[ index ] > maximumFloat )
96  {
97  maximumFloat = m_CentralityMap[ index ];
98  }
99  }
100 
101  // use the boost double to int converter
102  // it defaults to trunc
103  typedef boost::numeric::converter<int,double> Double2Int ;
104 
105  // for rounding, reduces the number of nodes classed as zero
106  maximumFloat += 0.5;
107 
108  int maximumInt( 0 );
109  try
110  {
111  maximumInt = Double2Int::convert( maximumFloat );
112  }
113  catch ( boost::numeric::positive_overflow const& )
114  {
116  }
117 
118  m_HistogramVector.resize( maximumInt + 1 );
119 
120  for ( unsigned int index( 0 ); index < m_CentralityMap.size(); index++ )
121  {
122  int value( 0 );
123  value = Double2Int::convert( ( m_CentralityMap[index ] + 0.5 ) );
124  m_HistogramVector[ value ]++;
125  }
126 
127  UpdateYMax();
128 
129  m_Valid = true;
130 }
void SetBetweennessCalculationMode(const BetweennessCalculationMode &)
boost::graph_traits< NetworkType >::vertex_iterator IteratorType
void CalculateWeightedUndirectedBetweennessCentrality(NetworkType *, IteratorType, IteratorType)
virtual void ComputeFromConnectomicsNetwork(ConnectomicsNetwork *source) override
Creates a new histogram from the network source.
void CalculateUnweightedUndirectedBetweennessCentrality(NetworkType *, IteratorType, IteratorType)
mitk::ConnectomicsNetwork::NetworkType NetworkType
Connectomics Network Class.
#define MBI_WARN
Definition: mbilog.h:222
std::string m_Subject
Subject of the histogram as a string.