INET Framework for OMNeT++/OMNEST
inet::physicallayer::QuadTreeNeighborCache Class Reference

#include <QuadTreeNeighborCache.h>

Inheritance diagram for inet::physicallayer::QuadTreeNeighborCache:
inet::physicallayer::INeighborCache inet::IPrintableObject

Classes

class  QuadTreeNeighborCacheVisitor
 

Public Types

typedef std::vector< const IRadio * > Radios
 
- Public Types inherited from inet::IPrintableObject
enum  PrintLevel {
  PRINT_LEVEL_TRACE, PRINT_LEVEL_DEBUG, PRINT_LEVEL_DETAIL, PRINT_LEVEL_INFO,
  PRINT_LEVEL_COMPLETE = INT_MIN
}
 
enum  PrintFlag { PRINT_FLAG_FORMATTED = (1 << 0), PRINT_FLAG_MULTILINE = (1 << 1) }
 

Public Member Functions

 QuadTreeNeighborCache ()
 
 ~QuadTreeNeighborCache ()
 
virtual std::ostream & printToStream (std::ostream &stream, int level, int evFlags=0) const override
 Prints this object to the provided output stream. More...
 
virtual void addRadio (const IRadio *radio) override
 
virtual void removeRadio (const IRadio *radio) override
 
virtual void sendToNeighbors (IRadio *transmitter, const IWirelessSignal *signal, double range) const override
 Sends the provided frame (using the radio medium) to all neighbors within the given range. More...
 
- Public Member Functions inherited from inet::IPrintableObject
virtual ~IPrintableObject ()
 
virtual std::string printToString () const
 
virtual std::string printToString (int level, int evFlags=0) const
 
virtual std::string getInfoStringRepresentation (int evFlags=0) const
 
virtual std::string getDetailStringRepresentation (int evFlags=0) const
 
virtual std::string getDebugStringRepresentation (int evFlags=0) const
 
virtual std::string getTraceStringRepresentation (int evFlags=0) const
 
virtual std::string getCompleteStringRepresentation (int evFlags=0) const
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
void fillQuadTreeWithRadios ()
 
void rebuildQuadTree ()
 

Protected Attributes

QuadTreequadTree
 
Radios radios
 
ModuleRefByPar< RadioMediumradioMedium
 
cMessage * rebuildQuadTreeTimer
 
Coord constraintAreaMax
 
Coord constraintAreaMin
 
unsigned int maxNumOfPointsPerQuadrant
 
double refillPeriod
 
double maxSpeed
 

Member Typedef Documentation

◆ Radios

Constructor & Destructor Documentation

◆ QuadTreeNeighborCache()

inet::physicallayer::QuadTreeNeighborCache::QuadTreeNeighborCache ( )
18  :
19  quadTree(nullptr),
20  rebuildQuadTreeTimer(nullptr),
25  maxSpeed(NaN)
26 {
27 }

◆ ~QuadTreeNeighborCache()

inet::physicallayer::QuadTreeNeighborCache::~QuadTreeNeighborCache ( )
133 {
134  delete quadTree;
135  cancelAndDelete(rebuildQuadTreeTimer);
136 }

Member Function Documentation

◆ addRadio()

void inet::physicallayer::QuadTreeNeighborCache::addRadio ( const IRadio radio)
overridevirtual

Implements inet::physicallayer::INeighborCache.

66 {
67  radios.push_back(radio);
68  Coord radioPos = radio->getAntenna()->getMobility()->getCurrentPosition();
69  maxSpeed = radioMedium->getMediumLimitCache()->getMaxSpeed().get();
70  if (maxSpeed != 0 && !rebuildQuadTreeTimer->isScheduled() && initialized())
71  scheduleAfter(refillPeriod, rebuildQuadTreeTimer);
72  Coord newConstraintAreaMin = radioMedium->getMediumLimitCache()->getMinConstraintArea();
73  Coord newConstraintAreaMax = radioMedium->getMediumLimitCache()->getMaxConstraintArea();
74  // If the constraintArea changed we must rebuild the QuadTree
75  if (newConstraintAreaMin != constraintAreaMin || newConstraintAreaMax != constraintAreaMax) {
76  constraintAreaMin = newConstraintAreaMin;
77  constraintAreaMax = newConstraintAreaMax;
78  if (initialized())
80  }
81  else if (initialized())
82  quadTree->insert(check_and_cast<const cObject *>(radio), radioPos);
83 }

◆ fillQuadTreeWithRadios()

void inet::physicallayer::QuadTreeNeighborCache::fillQuadTreeWithRadios ( )
protected
117 {
118  for (auto& elem : radios) {
119  Coord radioPos = elem->getAntenna()->getMobility()->getCurrentPosition();
120  if (!quadTree->insert(check_and_cast<const cObject *>(elem), radioPos))
121  throw cRuntimeError("Unsuccessful QuadTree building");
122  }
123 }

Referenced by rebuildQuadTree().

◆ handleMessage()

void inet::physicallayer::QuadTreeNeighborCache::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
48 {
49  if (!msg->isSelfMessage())
50  throw cRuntimeError("This module only handles self messages");
52  scheduleAfter(refillPeriod, msg);
53 }

◆ initialize()

void inet::physicallayer::QuadTreeNeighborCache::initialize ( int  stage)
overrideprotectedvirtual
30 {
31  if (stage == INITSTAGE_LOCAL) {
32  radioMedium.reference(this, "radioMediumModule", true);
33  rebuildQuadTreeTimer = new cMessage("rebuildQuadTreeTimer");
34  refillPeriod = par("refillPeriod");
35  maxNumOfPointsPerQuadrant = par("maxNumOfPointsPerQuadrant");
36  }
37  else if (stage == INITSTAGE_PHYSICAL_LAYER_NEIGHBOR_CACHE) {
38  constraintAreaMin = radioMedium->getMediumLimitCache()->getMinConstraintArea();
39  constraintAreaMax = radioMedium->getMediumLimitCache()->getMaxConstraintArea();
41  maxSpeed = radioMedium->getMediumLimitCache()->getMaxSpeed().get();
43  scheduleAfter(refillPeriod, rebuildQuadTreeTimer);
44  }
45 }

◆ numInitStages()

virtual int inet::physicallayer::QuadTreeNeighborCache::numInitStages ( ) const
inlineoverrideprotectedvirtual
47 { return NUM_INIT_STAGES; }

◆ printToStream()

std::ostream & inet::physicallayer::QuadTreeNeighborCache::printToStream ( std::ostream &  stream,
int  level,
int  evFlags = 0 
) const
overridevirtual

Prints this object to the provided output stream.

Reimplemented from inet::IPrintableObject.

56 {
57  stream << "QuadTreeNeighborCache";
58  if (level <= PRINT_LEVEL_TRACE)
61  << EV_FIELD(maxSpeed);
62  return stream;
63 }

◆ rebuildQuadTree()

void inet::physicallayer::QuadTreeNeighborCache::rebuildQuadTree ( )
protected
126 {
127  delete quadTree;
130 }

Referenced by addRadio(), handleMessage(), initialize(), and removeRadio().

◆ removeRadio()

void inet::physicallayer::QuadTreeNeighborCache::removeRadio ( const IRadio radio)
overridevirtual

Implements inet::physicallayer::INeighborCache.

86 {
87  auto it = find(radios, radio);
88  if (it != radios.end()) {
89  radios.erase(it);
90  Coord newConstraintAreaMin = radioMedium->getMediumLimitCache()->getMinConstraintArea();
91  Coord newConstraintAreaMax = radioMedium->getMediumLimitCache()->getMaxConstraintArea();
92  if (newConstraintAreaMin != constraintAreaMin || newConstraintAreaMax != constraintAreaMax) {
93  constraintAreaMin = newConstraintAreaMin;
94  constraintAreaMax = newConstraintAreaMax;
95  if (initialized())
97  }
98  else if (initialized())
99  quadTree->remove(check_and_cast<const cObject *>(radio));
100  maxSpeed = radioMedium->getMediumLimitCache()->getMaxSpeed().get();
101  if (maxSpeed == 0 && initialized())
102  cancelEvent(rebuildQuadTreeTimer);
103  }
104  else
105  throw cRuntimeError("You can't remove radio: %d because it is not in our radio container", radio->getId());
106 }

◆ sendToNeighbors()

void inet::physicallayer::QuadTreeNeighborCache::sendToNeighbors ( IRadio transmitter,
const IWirelessSignal signal,
double  range 
) const
overridevirtual

Sends the provided frame (using the radio medium) to all neighbors within the given range.

Implements inet::physicallayer::INeighborCache.

109 {
110  double radius = range + refillPeriod * maxSpeed;
111  Coord transmitterPos = transmitter->getAntenna()->getMobility()->getCurrentPosition();
112  QuadTreeNeighborCacheVisitor visitor(radioMedium, transmitter, signal);
113  quadTree->rangeQuery(transmitterPos, radius, &visitor);
114 }

Member Data Documentation

◆ constraintAreaMax

Coord inet::physicallayer::QuadTreeNeighborCache::constraintAreaMax
protected

◆ constraintAreaMin

Coord inet::physicallayer::QuadTreeNeighborCache::constraintAreaMin
protected

◆ maxNumOfPointsPerQuadrant

unsigned int inet::physicallayer::QuadTreeNeighborCache::maxNumOfPointsPerQuadrant
protected

◆ maxSpeed

double inet::physicallayer::QuadTreeNeighborCache::maxSpeed
protected

◆ quadTree

QuadTree* inet::physicallayer::QuadTreeNeighborCache::quadTree
protected

◆ radioMedium

ModuleRefByPar<RadioMedium> inet::physicallayer::QuadTreeNeighborCache::radioMedium
protected

◆ radios

Radios inet::physicallayer::QuadTreeNeighborCache::radios
protected

◆ rebuildQuadTreeTimer

cMessage* inet::physicallayer::QuadTreeNeighborCache::rebuildQuadTreeTimer
protected

◆ refillPeriod

double inet::physicallayer::QuadTreeNeighborCache::refillPeriod
protected

The documentation for this class was generated from the following files:
inet::physicallayer::QuadTreeNeighborCache::constraintAreaMin
Coord constraintAreaMin
Definition: QuadTreeNeighborCache.h:41
inet::physicallayer::QuadTreeNeighborCache::rebuildQuadTreeTimer
cMessage * rebuildQuadTreeTimer
Definition: QuadTreeNeighborCache.h:40
inet::physicallayer::QuadTreeNeighborCache::maxNumOfPointsPerQuadrant
unsigned int maxNumOfPointsPerQuadrant
Definition: QuadTreeNeighborCache.h:42
inet::physicallayer::QuadTreeNeighborCache::fillQuadTreeWithRadios
void fillQuadTreeWithRadios()
Definition: QuadTreeNeighborCache.cc:116
inet::find
std::vector< T >::iterator find(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:44
inet::physicallayer::QuadTreeNeighborCache::radioMedium
ModuleRefByPar< RadioMedium > radioMedium
Definition: QuadTreeNeighborCache.h:39
inet::physicallayer::QuadTreeNeighborCache::constraintAreaMax
Coord constraintAreaMax
Definition: QuadTreeNeighborCache.h:41
inet::QuadTree::rangeQuery
void rangeQuery(const Coord &pos, double range, const IVisitor *visitor) const
Definition: QuadTree.cc:96
inet::QuadTree::remove
bool remove(const cObject *point)
Definition: QuadTree.cc:142
EV_FIELD
#define EV_FIELD(...)
Definition: INETDefs.h:112
inet::physicallayer::QuadTreeNeighborCache::radios
Radios radios
Definition: QuadTreeNeighborCache.h:38
NaN
#define NaN
Definition: INETMath.h:91
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::physicallayer::QuadTreeNeighborCache::refillPeriod
double refillPeriod
Definition: QuadTreeNeighborCache.h:43
inet::IPrintableObject::PRINT_LEVEL_TRACE
@ PRINT_LEVEL_TRACE
Definition: IPrintableObject.h:22
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::physicallayer::QuadTreeNeighborCache::maxSpeed
double maxSpeed
Definition: QuadTreeNeighborCache.h:44
inet::physicallayer::QuadTreeNeighborCache::quadTree
QuadTree * quadTree
Definition: QuadTreeNeighborCache.h:37
inet::INITSTAGE_PHYSICAL_LAYER_NEIGHBOR_CACHE
INET_API InitStage INITSTAGE_PHYSICAL_LAYER_NEIGHBOR_CACHE
Initialization of physical layer neighbor cache.
inet::QuadTree::insert
bool insert(const cObject *point, const Coord &pos)
Definition: QuadTree.cc:14
inet::Coord::NIL
static const Coord NIL
Constant with all values set to 0.
Definition: Coord.h:26
inet::physicallayer::QuadTreeNeighborCache::rebuildQuadTree
void rebuildQuadTree()
Definition: QuadTreeNeighborCache.cc:125