os/ossrv/ossrv_pub/boost_apis/boost/graph/circle_layout.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright 2004 The Trustees of Indiana University.
sl@0
     2
sl@0
     3
// Distributed under the Boost Software License, Version 1.0.
sl@0
     4
// (See accompanying file LICENSE_1_0.txt or copy at
sl@0
     5
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     6
sl@0
     7
//  Authors: Douglas Gregor
sl@0
     8
//           Andrew Lumsdaine
sl@0
     9
#ifndef BOOST_GRAPH_CIRCLE_LAYOUT_HPP
sl@0
    10
#define BOOST_GRAPH_CIRCLE_LAYOUT_HPP
sl@0
    11
#include <cmath>
sl@0
    12
#include <utility>
sl@0
    13
#include <boost/graph/graph_traits.hpp>
sl@0
    14
sl@0
    15
namespace boost {
sl@0
    16
  /** 
sl@0
    17
   * \brief Layout the graph with the vertices at the points of a regular
sl@0
    18
   * n-polygon. 
sl@0
    19
   *
sl@0
    20
   * The distance from the center of the polygon to each point is
sl@0
    21
   * determined by the @p radius parameter. The @p position parameter
sl@0
    22
   * must be an Lvalue Property Map whose value type is a class type
sl@0
    23
   * containing @c x and @c y members that will be set to the @c x and
sl@0
    24
   * @c y coordinates.
sl@0
    25
   */
sl@0
    26
  template<typename VertexListGraph, typename PositionMap, typename Radius>
sl@0
    27
  void 
sl@0
    28
  circle_graph_layout(const VertexListGraph& g, PositionMap position,
sl@0
    29
                      Radius radius)
sl@0
    30
  {
sl@0
    31
    const double pi = 3.14159;
sl@0
    32
sl@0
    33
#ifndef BOOST_NO_STDC_NAMESPACE
sl@0
    34
    using std::sin;
sl@0
    35
    using std::cos;
sl@0
    36
#endif // BOOST_NO_STDC_NAMESPACE
sl@0
    37
sl@0
    38
    typedef typename graph_traits<VertexListGraph>::vertices_size_type 
sl@0
    39
      vertices_size_type;
sl@0
    40
sl@0
    41
    vertices_size_type n = num_vertices(g);
sl@0
    42
    
sl@0
    43
    typedef typename graph_traits<VertexListGraph>::vertex_iterator 
sl@0
    44
      vertex_iterator;
sl@0
    45
sl@0
    46
    vertices_size_type i = 0;
sl@0
    47
    for(std::pair<vertex_iterator, vertex_iterator> v = vertices(g); 
sl@0
    48
        v.first != v.second; ++v.first, ++i) {
sl@0
    49
      position[*v.first].x = radius * cos(i * 2 * pi / n);
sl@0
    50
      position[*v.first].y = radius * sin(i * 2 * pi / n);
sl@0
    51
    }
sl@0
    52
  }
sl@0
    53
} // end namespace boost
sl@0
    54
sl@0
    55
#endif // BOOST_GRAPH_CIRCLE_LAYOUT_HPP