void mitk::ConnectomicsSyntheticNetworkGenerator::GenerateSyntheticCenterToSurfaceNetwork(
  mitk::ConnectomicsNetwork::Pointer network, int numberOfPoints, double radius )
{
  //the random number generators
  unsigned int randomOne = (unsigned int) rand();
  unsigned int randomTwo = (unsigned int) rand();

  vnl_random rng( (unsigned int) rand() );
  vnl_random rng2( (unsigned int) rand() );

  mitk::ConnectomicsNetwork::VertexDescriptorType centerVertex;
  int vertexID(0);
  { //add center vertex
    std::vector< float > position;
    std::string label;
    std::stringstream labelStream;
    labelStream << vertexID;
    label = labelStream.str();

    position.push_back( 0 );
    position.push_back( 0 );
    position.push_back( 0 );

    centerVertex = network->AddVertex( vertexID );
    network->SetLabel( centerVertex, label );
    network->SetCoordinates( centerVertex, position );
  }//end add center vertex

  // uniform weight of one
  int edgeWeight(1);

  mitk::ConnectomicsNetwork::VertexDescriptorType source;
  mitk::ConnectomicsNetwork::VertexDescriptorType target;

  //add vertices on sphere surface
  for( int loopID( 1 ); loopID < numberOfPoints; loopID++  )
  {

    std::vector< float > position;
    std::string label;
    std::stringstream labelStream;
    labelStream << loopID;
    label = labelStream.str();

    //generate random, uniformly distributed points on a sphere surface
    const double uVariable = rng.drand64( 0.0 , 1.0);
    const double vVariable = rng.drand64( 0.0 , 1.0);
    const double phi = 2 * vnl_math::pi * uVariable;
    const double theta = std::acos( 2 * vVariable - 1 );

    double xpos = radius * std::cos( phi ) * std::sin( theta );
    double ypos = radius * std::sin( phi ) * std::sin( theta );
    double zpos = radius * std::cos( theta );

    position.push_back( xpos );
    position.push_back( ypos );
    position.push_back( zpos );

    mitk::ConnectomicsNetwork::VertexDescriptorType newVertex = network->AddVertex( loopID );
    network->SetLabel( newVertex, label );
    network->SetCoordinates( newVertex, position );

    network->AddEdge( newVertex, centerVertex, loopID, 0, edgeWeight);
  }
  m_LastGenerationWasSuccess = true;
}
void mitk::ConnectomicsSyntheticNetworkGenerator::GenerateSyntheticRandomNetwork(
  mitk::ConnectomicsNetwork::Pointer network, int numberOfPoints, double threshold )
{
  // as the surface is proportional to the square of the radius the density stays the same
  double radius = 5 * std::sqrt( (float) numberOfPoints );

  //the random number generators
  unsigned int randomOne = (unsigned int) rand();
  unsigned int randomTwo = (unsigned int) rand();

  vnl_random rng( (unsigned int) rand() );
  vnl_random rng2( (unsigned int) rand() );

  // map for storing the conversion from indices to vertex descriptor
  std::map< int, mitk::ConnectomicsNetwork::VertexDescriptorType > idToVertexMap;

  //add vertices on sphere surface
  for( int loopID( 0 ); loopID < numberOfPoints; loopID++  )
  {

    std::vector< float > position;
    std::string label;
    std::stringstream labelStream;
    labelStream << loopID;
    label = labelStream.str();

    //generate random, uniformly distributed points on a sphere surface
    const double uVariable = rng.drand64( 0.0 , 1.0);
    const double vVariable = rng.drand64( 0.0 , 1.0);
    const double phi = 2 * vnl_math::pi * uVariable;
    const double theta = std::acos( 2 * vVariable - 1 );

    double xpos = radius * std::cos( phi ) * std::sin( theta );
    double ypos = radius * std::sin( phi ) * std::sin( theta );
    double zpos = radius * std::cos( theta );

    position.push_back( xpos );
    position.push_back( ypos );
    position.push_back( zpos );

    mitk::ConnectomicsNetwork::VertexDescriptorType newVertex = network->AddVertex( loopID );
    network->SetLabel( newVertex, label );
    network->SetCoordinates( newVertex, position );

    if ( idToVertexMap.count( loopID ) > 0 )
    {
      MITK_ERROR << "Aborting network creation, duplicate vertex ID generated.";
      m_LastGenerationWasSuccess = false;
      return;
    }
    idToVertexMap.insert( std::pair< int, mitk::ConnectomicsNetwork::VertexDescriptorType >( loopID, newVertex) );
  }

  int edgeID(0);
  // uniform weight of one
  int edgeWeight(1);

  mitk::ConnectomicsNetwork::VertexDescriptorType source;
  mitk::ConnectomicsNetwork::VertexDescriptorType target;

  for( int loopID( 0 ); loopID < numberOfPoints; loopID++  )
  {
    // to avoid creating an edge twice (this being an undirected graph) we only
    // potentially generate edges with all nodes with a bigger ID
    for( int innerLoopID( loopID ); innerLoopID < numberOfPoints; innerLoopID++  )
    {
      if( rng.drand64( 0.0 , 1.0) > threshold)
      {
        // do nothing
      }
      else
      {
        source = idToVertexMap.find( loopID )->second;
        target = idToVertexMap.find( innerLoopID )->second;
        network->AddEdge( source, target, loopID, innerLoopID, edgeWeight);

        edgeID++;
      }
    } // end for( int innerLoopID( loopID ); innerLoopID < numberOfPoints; innerLoopID++  )
  } // end for( int loopID( 0 ); loopID < numberOfPoints; loopID++  )
  m_LastGenerationWasSuccess = true;
}
void mitk::ConnectomicsSyntheticNetworkGenerator::GenerateSyntheticCubeNetwork(
  mitk::ConnectomicsNetwork::Pointer network, int cubeExtent, double distance )
{
  // map for storing the conversion from indices to vertex descriptor
  std::map< int, mitk::ConnectomicsNetwork::VertexDescriptorType > idToVertexMap;

  int vertexID(0);
  for( int loopX( 0 ); loopX < cubeExtent; loopX++  )
  {
    for( int loopY( 0 ); loopY < cubeExtent; loopY++  )
    {
      for( int loopZ( 0 ); loopZ < cubeExtent; loopZ++  )
      {
        std::vector< float > position;
        std::string label;
        std::stringstream labelStream;
        labelStream << vertexID;
        label = labelStream.str();

        position.push_back( loopX * distance );
        position.push_back( loopY * distance );
        position.push_back( loopZ * distance );

        mitk::ConnectomicsNetwork::VertexDescriptorType newVertex = network->AddVertex( vertexID );
        network->SetLabel( newVertex, label );
        network->SetCoordinates( newVertex, position );

        if ( idToVertexMap.count( vertexID ) > 0 )
        {
          MITK_ERROR << "Aborting network creation, duplicate vertex ID generated.";
          m_LastGenerationWasSuccess = false;
          return;
        }
        idToVertexMap.insert( std::pair< int, mitk::ConnectomicsNetwork::VertexDescriptorType >( vertexID, newVertex) );

        vertexID++;
      }
    }
  }

  int edgeID(0), edgeSourceID(0), edgeTargetID(0);
  // uniform weight of one
  int edgeWeight(1);

  mitk::ConnectomicsNetwork::VertexDescriptorType source;
  mitk::ConnectomicsNetwork::VertexDescriptorType target;

  for( int loopX( 0 ); loopX < cubeExtent; loopX++  )
  {
    for( int loopY( 0 ); loopY < cubeExtent; loopY++  )
    {
      for( int loopZ( 0 ); loopZ < cubeExtent; loopZ++  )
      {
        // to avoid creating an edge twice (this being an undirected graph) we only generate
        // edges in three directions, the others will be supplied by the corresponding nodes
        if( loopX != 0 )
        {
          edgeTargetID = edgeSourceID - cubeExtent * cubeExtent;

          source = idToVertexMap.find( edgeSourceID )->second;
          target = idToVertexMap.find( edgeTargetID )->second;
          network->AddEdge( source, target, edgeSourceID, edgeTargetID, edgeWeight);

          edgeID++;
        }
        if( loopY != 0 )
        {
          edgeTargetID = edgeSourceID - cubeExtent;

          source = idToVertexMap.find( edgeSourceID )->second;
          target = idToVertexMap.find( edgeTargetID )->second;
          network->AddEdge( source, target, edgeSourceID, edgeTargetID, edgeWeight);

          edgeID++;
        }
        if( loopZ != 0 )
        {
          edgeTargetID = edgeSourceID - 1;

          source = idToVertexMap.find( edgeSourceID )->second;
          target = idToVertexMap.find( edgeTargetID )->second;
          network->AddEdge( source, target, edgeSourceID, edgeTargetID, edgeWeight);

          edgeID++;
        }

        edgeSourceID++;
      } // end for( int loopZ( 0 ); loopZ < cubeExtent; loopZ++  )
    } // end for( int loopY( 0 ); loopY < cubeExtent; loopY++  )
  } // end for( int loopX( 0 ); loopX < cubeExtent; loopX++  )
  m_LastGenerationWasSuccess = true;
}