View | Details | Raw Unified | Return to bug 2473
Collapse All | Expand All

(-)a/src/mobility/model/disc-grid-position-allocator.cc (+173 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Author: Andrea Sacco <andrea.sacco85@gmail.com>
17
 */
18
#include "disc-grid-position-allocator.h"
19
#include "ns3/log.h"
20
#include <cmath>
21
22
namespace ns3 {
23
24
NS_OBJECT_ENSURE_REGISTERED (DiskGridPositionAllocator);
25
26
TypeId
27
DiskGridPositionAllocator::GetTypeId (void)
28
{
29
  static TypeId tid = TypeId ("ns3::DiskGridPositionAllocator")
30
    .SetParent<PositionAllocator> ()
31
    .SetGroupName ("Mobility")
32
    .AddConstructor<DiskGridPositionAllocator> ()
33
  ;
34
  return tid;
35
}
36
DiskGridPositionAllocator::DiskGridPositionAllocator ()
37
  : m_x (0),
38
  m_y (0),
39
  m_z (0),
40
  m_rho (0),
41
  m_intervals (0),
42
  m_count (0)
43
{
44
}
45
DiskGridPositionAllocator::~DiskGridPositionAllocator ()
46
{
47
}
48
void
49
DiskGridPositionAllocator::SetRho (double rho)
50
{
51
  m_rho = rho;
52
  CalculatePositions ();
53
}
54
void
55
DiskGridPositionAllocator::SetX (double x)
56
{
57
  m_x = x;
58
  CalculatePositions ();
59
}
60
void
61
DiskGridPositionAllocator::SetY (double y)
62
{
63
  m_y = y;
64
  CalculatePositions ();
65
}
66
void
67
DiskGridPositionAllocator::SetZ (double z)
68
{
69
  m_z = z;
70
  CalculatePositions ();
71
}
72
void
73
DiskGridPositionAllocator::SetIntervals (uint32_t intervals)
74
{
75
  m_intervals = intervals;
76
  CalculatePositions ();
77
}
78
double
79
DiskGridPositionAllocator::GetRho () const
80
{
81
  return m_rho;
82
}
83
double
84
DiskGridPositionAllocator::GetX () const
85
{
86
  return m_x;
87
}
88
double
89
DiskGridPositionAllocator::GetY () const
90
{
91
  return m_y;
92
}
93
double
94
DiskGridPositionAllocator::GetZ () const
95
{
96
  return m_z;
97
}
98
uint32_t
99
DiskGridPositionAllocator::GetIntervals () const
100
{
101
  return m_intervals;
102
}
103
int64_t
104
DiskGridPositionAllocator::AssignStreams (int64_t stream)
105
{
106
  return 0;
107
}
108
Vector
109
DiskGridPositionAllocator::GetNext (void) const
110
{
111
  static uint32_t count = m_count;
112
  NS_ASSERT (count > 0);
113
  Vector v = *m_current;
114
  m_current++;
115
  count--;
116
  return v;
117
}
118
uint32_t
119
DiskGridPositionAllocator::GetN () const
120
{
121
  return m_count;
122
}
123
void
124
DiskGridPositionAllocator::CalculatePositions ()
125
{
126
  uint32_t i;
127
  double x;
128
  double y;
129
130
  if (m_intervals == 0 || m_rho == 0)
131
    {
132
      return;
133
    }
134
  m_positions.clear ();
135
  m_count = 0;
136
  for ( uint32_t j = 0; j <= m_intervals; j++ )
137
    {
138
      i = 0;
139
      x = m_x;
140
      y = m_y + m_rho * ( double ) ( 2 * j ) / ( double ) ( 2 * m_intervals + 1 );
141
      m_positions.push_back (Vector (x, y, m_z));
142
      m_count++;
143
144
      if ( 0 < j )
145
        {
146
          m_positions.push_back (Vector (x, (2.0 * m_y - y), m_z));
147
          m_count++;
148
        }
149
      while (true)
150
        {
151
          i = i + 1;
152
          x = m_x + m_rho * ( double ) ( 2 * i ) / ( double ) ( 2 * m_intervals + 1 );
153
154
          if ( m_rho * m_rho < pow ( x - m_x, 2 ) + pow ( y - m_y, 2 ) )
155
            {
156
              break;
157
            }
158
          m_positions.push_back (Vector (x, y, m_z));
159
          m_positions.push_back (Vector ((2.0 * m_x - x), y, m_z));
160
          m_count += 2;
161
          if ( 0 < j )
162
            {
163
              m_positions.push_back (Vector (x, (2.0 * m_y - y), m_z));
164
              m_positions.push_back (Vector ((2.0 * m_x - x), (2.0 * m_y - y), m_z));
165
              m_count += 2;
166
            }
167
        }
168
    }
169
  m_current = m_positions.begin ();
170
}
171
172
173
} // namespace ns3
(-)a/src/mobility/model/disc-grid-position-allocator.h (+124 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Author: Andrea Sacco <andrea.sacco85@gmail.com>
17
 */
18
#ifndef AUV_POSITION_ALLOCATOR_H
19
#define AUV_POSITION_ALLOCATOR_H
20
21
#include "ns3/position-allocator.h"
22
23
namespace ns3 {
24
25
/**
26
 * \ingroup mobility
27
 * \brief Allocate positions on a rectangular 2d grid
28
 *        delimited by a circle.
29
 */
30
class DiskGridPositionAllocator : public PositionAllocator
31
{
32
public:
33
  /**
34
   * Register this type with the TypeId system.
35
   * \return the object TypeId
36
   */
37
  static TypeId GetTypeId (void);
38
  DiskGridPositionAllocator ();
39
  virtual ~DiskGridPositionAllocator ();
40
41
  /**
42
   * \brief Set the radius of the disc delimiting the grid.
43
   * \param rho The radius of the disc.
44
   */
45
  void SetRho (double rho);
46
  /**
47
   * \brief Set the X coordinate of the center of the disc.
48
   * \param x The X coordinate of the center of the disc.
49
   */
50
  void SetX (double x);
51
  /**
52
   * \brief Set the Y coordinate of the center of the disc.
53
   * \param y The Y coordinate of the center of the disc.
54
   */
55
  void SetY (double y);
56
  /**
57
   * \brief Set the Z coordinate of the center of the disc.
58
   * \param z The Z coordinate of the center of the disc.
59
   */
60
  void SetZ (double z);
61
  /**
62
   * \brief Set the number of subintervals into which the horizontal
63
   * radius should be divided.
64
   * \param intervals The number of subintervals into which the horizontal
65
   * radius should be divided.
66
   */
67
  void SetIntervals (uint32_t intervals);
68
  /**
69
   * \brief Get the radius of the disc delimiting the grid.
70
   * \return The radius of the disc.
71
   */
72
  double GetRho () const;
73
  /**
74
   * \brief Get the X coordinate of the center of the disc.
75
   * \return the X coordinate of the center of the disc.
76
   */
77
  double GetX () const;
78
  /**
79
   * \brief Get the Y coordinate of the center of the disc.
80
   * \return The Y coordinate of the center of the disc.
81
   */
82
  double GetY () const;
83
  /**
84
   * \brief Get the Z coordinate of the center of the disc.
85
   * \return The Z coordinate of the center of the disc.
86
   */
87
  double GetZ () const;
88
  /**
89
   * \brief Get the number of subintervals into which the horizontal
90
   * radius should be divided.
91
   * \return The number of subintervals into which the horizontal
92
   * radius should be divided.
93
   */
94
  uint32_t GetIntervals () const;
95
96
  /**
97
   * \brief Get the number of points in the grid.
98
   * \return The number of points in the grid.
99
   */
100
  uint32_t GetN () const;
101
102
  virtual Vector GetNext (void) const;
103
  virtual int64_t AssignStreams (int64_t stream);
104
105
private:
106
  /**
107
   * \brief calculates the positions
108
   */
109
  void CalculatePositions ();
110
111
private:
112
  std::vector<Vector> m_positions;  //!< vector of positions
113
  mutable std::vector<Vector>::const_iterator m_current; //!< vector iterator
114
  double m_x; //!< x coordinate of center of disc
115
  double m_y; //!< y coordinate of center of disc
116
  double m_z; //!< z coordinate of center of disc
117
  double m_rho; //!< value of the radius of the disc
118
  uint32_t m_intervals; //!< number of subintervals
119
  uint32_t m_count; //!< number of points
120
};
121
122
} // namespace ns3
123
124
#endif /* AUV_POSITION_ALLOCATOR_H */
(-)a/src/mobility/wscript (+2 lines)
 Lines 13-18    Link Here 
13
        'model/hierarchical-mobility-model.cc',
13
        'model/hierarchical-mobility-model.cc',
14
        'model/mobility-model.cc',
14
        'model/mobility-model.cc',
15
        'model/position-allocator.cc',
15
        'model/position-allocator.cc',
16
        'model/disc-grid-position-allocator.cc',
16
        'model/random-direction-2d-mobility-model.cc',
17
        'model/random-direction-2d-mobility-model.cc',
17
        'model/random-walk-2d-mobility-model.cc',
18
        'model/random-walk-2d-mobility-model.cc',
18
        'model/random-waypoint-mobility-model.cc',
19
        'model/random-waypoint-mobility-model.cc',
 Lines 48-53    Link Here 
48
        'model/hierarchical-mobility-model.h',
49
        'model/hierarchical-mobility-model.h',
49
        'model/mobility-model.h',
50
        'model/mobility-model.h',
50
        'model/position-allocator.h',
51
        'model/position-allocator.h',
52
        'model/disc-grid-position-allocator.h',
51
        'model/rectangle.h',
53
        'model/rectangle.h',
52
        'model/random-direction-2d-mobility-model.h',
54
        'model/random-direction-2d-mobility-model.h',
53
        'model/random-walk-2d-mobility-model.h',
55
        'model/random-walk-2d-mobility-model.h',

Return to bug 2473