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

(-)a/src/mobility/model/position-allocator.h (+74 lines)
 Lines 356-361   private: Link Here 
356
  double m_y;  //!< y coordinate of center of disc
356
  double m_y;  //!< y coordinate of center of disc
357
};
357
};
358
358
359
/**
360
 * \ingroup mobility
361
 * \brief Allocate positions on a rectangular 2d grid.
362
 */
363
class DiskGridPositionAllocator : public PositionAllocator
364
{
365
public:
366
  /**
367
   * Register this type with the TypeId system.
368
   * \return the object TypeId
369
   */
370
  static TypeId GetTypeId (void);
371
  DiskGridPositionAllocator ();
372
  virtual ~DiskGridPositionAllocator ();
373
  
374
  /** 
375
   * \param rho the radius of the disc
376
   */
377
  void SetRho (double rho);
378
  /** 
379
   * \param x the X coordinate of the center of the disc
380
   */
381
  void SetX (double x);
382
  /** 
383
   * \param y the Y coordinate of the center of the disc
384
   */
385
  void SetY (double y);
386
  /** 
387
   * \param intervals the number of subintervals into which the horizontal
388
   * radius should be divided
389
   */
390
  void SetIntervals (uint32_t intervals);
391
  /** 
392
   * \return the radius of the disc
393
   */
394
  double GetRho () const;
395
  /** 
396
   * \return the X coordinate of the center of the disc
397
   */
398
  double GetX () const;
399
  /** 
400
   * \return the Y coordinate of the center of the disc
401
   */
402
  double GetY () const;
403
  /** 
404
   * \return the number of subintervals into which the horizontal
405
   * radius should be divided
406
   */
407
  uint32_t GetIntervals () const;
408
  
409
  /** 
410
   * \return the number of points in the grid
411
   */
412
  uint32_t GetN () const;
413
  
414
  virtual Vector GetNext (void) const;
415
  virtual int64_t AssignStreams (int64_t stream);
416
  
417
private:
418
  /**
419
   * \brief calculates the positions
420
   */
421
  void CalculatePositions ();
422
  
423
private:
424
  std::vector<Vector> m_positions;  //!< vector of positions
425
  mutable std::vector<Vector>::const_iterator m_current; //!< vector iterator
426
  double m_x; //!< x coordinate of center of disc
427
  double m_y; //!< y coordinate of center of disc
428
  double m_rho; //!< value of the radius of the disc
429
  uint32_t m_intervals; //!< number of subintervals
430
  uint32_t m_count; //!< number of points
431
};
432
359
} // namespace ns3
433
} // namespace ns3
360
434
361
#endif /* RANDOM_POSITION_H */
435
#endif /* RANDOM_POSITION_H */
(-)a/src/mobility/model/position-allocator.cc (+135 lines)
 Lines 494-497   UniformDiscPositionAllocator::AssignStreams (int64_t stream) Link Here 
494
}
494
}
495
495
496
496
497
498
NS_OBJECT_ENSURE_REGISTERED (DiskGridPositionAllocator);
499
500
TypeId
501
DiskGridPositionAllocator::GetTypeId (void)
502
{
503
  static TypeId tid = TypeId ("ns3::DiskGridPositionAllocator")
504
    .SetParent<PositionAllocator> ()
505
    .SetGroupName ("Mobility")
506
    .AddConstructor<DiskGridPositionAllocator> ()
507
  ;
508
  return tid;
509
}
510
DiskGridPositionAllocator::DiskGridPositionAllocator ()
511
  : m_x (0),
512
    m_y (0),
513
    m_rho (0),
514
    m_intervals (0),
515
    m_count (0)
516
{
517
}
518
DiskGridPositionAllocator::~DiskGridPositionAllocator ()
519
{
520
}
521
void
522
DiskGridPositionAllocator::SetRho (double rho)
523
{
524
  m_rho = rho;
525
  CalculatePositions ();
526
}
527
void
528
DiskGridPositionAllocator::SetX (double x)
529
{
530
  m_x = x;
531
  CalculatePositions ();
532
}
533
void
534
DiskGridPositionAllocator::SetY (double y)
535
{
536
  m_y = y;
537
  CalculatePositions ();
538
}
539
void
540
DiskGridPositionAllocator::SetIntervals (uint32_t intervals)
541
{
542
  m_intervals = intervals;
543
  CalculatePositions ();
544
}
545
double
546
DiskGridPositionAllocator::GetRho () const
547
{
548
  return m_rho;
549
}
550
double
551
DiskGridPositionAllocator::GetX () const
552
{
553
  return m_x;
554
}
555
double
556
DiskGridPositionAllocator::GetY () const
557
{
558
  return m_y;
559
}
560
uint32_t
561
DiskGridPositionAllocator::GetIntervals () const
562
{
563
  return m_intervals;
564
}
565
int64_t
566
DiskGridPositionAllocator::AssignStreams (int64_t stream)
567
{
568
  return 0;
569
}
570
Vector
571
DiskGridPositionAllocator::GetNext (void) const
572
{
573
  static uint32_t count = m_count;
574
  NS_ASSERT (count > 0);
575
  Vector v = *m_current;
576
  m_current++;
577
  count--;
578
  return v;
579
}
580
uint32_t
581
DiskGridPositionAllocator::GetN () const
582
{
583
  return m_count;
584
}
585
void
586
DiskGridPositionAllocator::CalculatePositions ()
587
{
588
  uint32_t i;
589
  double x;
590
  double y;
591
  if(m_intervals == 0 || m_rho == 0)
592
    return;
593
  m_positions.clear ();
594
  m_count = 0;
595
  for ( uint32_t j = 0; j <= m_intervals; j++ )
596
  {
597
    i = 0;
598
    x = m_x;
599
    y = m_y + m_rho * ( double ) ( 2 * j ) / ( double ) ( 2 * m_intervals + 1 );
600
    m_positions.push_back (Vector (x, y, 0));
601
    m_count++;
602
603
    if ( 0 < j )
604
    {
605
      m_positions.push_back (Vector (x, (2.0 * m_y - y), 0));
606
      m_count++;
607
    }
608
    while (true)
609
    {
610
      i = i + 1;
611
      x = m_x + m_rho * ( double ) ( 2 * i ) / ( double ) ( 2 * m_intervals + 1 );
612
613
      if ( m_rho * m_rho < pow ( x - m_x, 2 ) + pow ( y - m_y, 2 ) )
614
      {
615
        break;
616
      }
617
      m_positions.push_back (Vector (x, y, 0));
618
      m_positions.push_back (Vector ((2.0 * m_x - x), y, 0));
619
      m_count += 2;
620
      if ( 0 < j )
621
      {
622
        m_positions.push_back (Vector (x, (2.0 * m_y - y), 0));
623
        m_positions.push_back (Vector ((2.0 * m_x - x), (2.0 * m_y - y), 0));
624
        m_count += 2;
625
      }
626
    }
627
  }
628
  m_current = m_positions.begin ();
629
}
630
631
497
} // namespace ns3 
632
} // namespace ns3 

Return to bug 2391