|
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 |