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

#include <QuadTreeNeighborCache.h>

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

Classes

class  QuadTreeNeighborCacheVisitor
 

Public Types

typedef std::vector< const IRadio * > Radios
 
- Public Types inherited from inet::physicallayer::IPrintableObject
enum  PrintLevel {
  PRINT_LEVEL_TRACE, PRINT_LEVEL_DEBUG, PRINT_LEVEL_DETAIL, PRINT_LEVEL_INFO,
  PRINT_LEVEL_COMPLETE = INT_MIN
}
 

Public Member Functions

 QuadTreeNeighborCache ()
 
 ~QuadTreeNeighborCache ()
 
virtual std::ostream & printToStream (std::ostream &stream, int level) 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 IRadioFrame *frame, 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::physicallayer::IPrintableObject
virtual ~IPrintableObject ()
 
virtual std::string getInfoStringRepresentation () const
 
virtual std::string getDetailStringRepresentation () const
 
virtual std::string getDebugStringRepresentation () const
 
virtual std::string getTraceStringRepresentation () const
 
virtual std::string getCompleteStringRepresentation () 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
 
RadioMediumradioMedium
 
cMessage * rebuildQuadTreeTimer
 
Coord constraintAreaMax
 
Coord constraintAreaMin
 
unsigned int maxNumOfPointsPerQuadrant
 
double refillPeriod
 
double maxSpeed
 

Member Typedef Documentation

Constructor & Destructor Documentation

inet::physicallayer::QuadTreeNeighborCache::QuadTreeNeighborCache ( )
27  :
28  quadTree(nullptr),
29  radioMedium(nullptr),
30  rebuildQuadTreeTimer(nullptr),
35  maxSpeed(NaN)
36 {
37 }
cMessage * rebuildQuadTreeTimer
Definition: QuadTreeNeighborCache.h:51
unsigned int maxNumOfPointsPerQuadrant
Definition: QuadTreeNeighborCache.h:53
QuadTree * quadTree
Definition: QuadTreeNeighborCache.h:48
static const Coord NIL
Constant with all values set to 0.
Definition: Coord.h:40
double maxSpeed
Definition: QuadTreeNeighborCache.h:55
double refillPeriod
Definition: QuadTreeNeighborCache.h:54
#define NaN
Definition: INETMath.h:103
RadioMedium * radioMedium
Definition: QuadTreeNeighborCache.h:50
Coord constraintAreaMax
Definition: QuadTreeNeighborCache.h:52
Coord constraintAreaMin
Definition: QuadTreeNeighborCache.h:52
inet::physicallayer::QuadTreeNeighborCache::~QuadTreeNeighborCache ( )
145 {
146  delete quadTree;
147  cancelAndDelete(rebuildQuadTreeTimer);
148 }
cMessage * rebuildQuadTreeTimer
Definition: QuadTreeNeighborCache.h:51
QuadTree * quadTree
Definition: QuadTreeNeighborCache.h:48

Member Function Documentation

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

Implements inet::physicallayer::INeighborCache.

76 {
77  radios.push_back(radio);
78  Coord radioPos = radio->getAntenna()->getMobility()->getCurrentPosition();
80  if (maxSpeed != 0 && !rebuildQuadTreeTimer->isScheduled() && initialized())
81  scheduleAt(simTime() + refillPeriod, rebuildQuadTreeTimer);
82  Coord newConstraintAreaMin = radioMedium->getMediumLimitCache()->getMinConstraintArea();
83  Coord newConstraintAreaMax = radioMedium->getMediumLimitCache()->getMaxConstraintArea();
84  // If the constraintArea changed we must rebuild the QuadTree
85  if (newConstraintAreaMin != constraintAreaMin || newConstraintAreaMax != constraintAreaMax)
86  {
87  constraintAreaMin = newConstraintAreaMin;
88  constraintAreaMax = newConstraintAreaMax;
89  if (initialized())
91  }
92  else if (initialized())
93  quadTree->insert(check_and_cast<const cObject *>(radio), radioPos);
94 }
virtual Coord getMinConstraintArea() const =0
Returns the minimum possible position among the radios, the coordinate values are in the range (-infi...
cMessage * rebuildQuadTreeTimer
Definition: QuadTreeNeighborCache.h:51
QuadTree * quadTree
Definition: QuadTreeNeighborCache.h:48
void rebuildQuadTree()
Definition: QuadTreeNeighborCache.cc:137
const value_type & get() const
Definition: Units.h:89
double maxSpeed
Definition: QuadTreeNeighborCache.h:55
double refillPeriod
Definition: QuadTreeNeighborCache.h:54
RadioMedium * radioMedium
Definition: QuadTreeNeighborCache.h:50
Coord constraintAreaMax
Definition: QuadTreeNeighborCache.h:52
Radios radios
Definition: QuadTreeNeighborCache.h:49
Coord constraintAreaMin
Definition: QuadTreeNeighborCache.h:52
virtual const IMediumLimitCache * getMediumLimitCache() const override
Definition: RadioMedium.h:328
bool insert(const cObject *point, const Coord &pos)
Definition: QuadTree.cc:22
virtual Coord getMaxConstraintArea() const =0
Returns the maximum possible position among the radios, the coordinate values are in the range (-infi...
virtual mps getMaxSpeed() const =0
Returns the maximum possible speed among the radios, the value is in the range [0, +infinity) or NaN if unspecified.
void inet::physicallayer::QuadTreeNeighborCache::fillQuadTreeWithRadios ( )
protected

Referenced by rebuildQuadTree().

129 {
130  for (auto & elem : radios) {
131  Coord radioPos = elem->getAntenna()->getMobility()->getCurrentPosition();
132  if (!quadTree->insert(check_and_cast<const cObject *>(elem), radioPos))
133  throw cRuntimeError("Unsuccessful QuadTree building");
134  }
135 }
QuadTree * quadTree
Definition: QuadTreeNeighborCache.h:48
Radios radios
Definition: QuadTreeNeighborCache.h:49
bool insert(const cObject *point, const Coord &pos)
Definition: QuadTree.cc:22
void inet::physicallayer::QuadTreeNeighborCache::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
58 {
59  if (!msg->isSelfMessage())
60  throw cRuntimeError("This module only handles self messages");
62  scheduleAt(simTime() + refillPeriod, msg);
63 }
void rebuildQuadTree()
Definition: QuadTreeNeighborCache.cc:137
double refillPeriod
Definition: QuadTreeNeighborCache.h:54
void inet::physicallayer::QuadTreeNeighborCache::initialize ( int  stage)
overrideprotectedvirtual
40 {
41  if (stage == INITSTAGE_LOCAL) {
42  radioMedium = getModuleFromPar<RadioMedium>(par("radioMediumModule"), this);
43  rebuildQuadTreeTimer = new cMessage("rebuildQuadTreeTimer");
44  refillPeriod = par("refillPeriod");
45  maxNumOfPointsPerQuadrant = par("maxNumOfPointsPerQuadrant");
46  }
47  else if (stage == INITSTAGE_LINK_LAYER_2) {
53  scheduleAt(simTime() + refillPeriod, rebuildQuadTreeTimer);
54  }
55 }
virtual Coord getMinConstraintArea() const =0
Returns the minimum possible position among the radios, the coordinate values are in the range (-infi...
cMessage * rebuildQuadTreeTimer
Definition: QuadTreeNeighborCache.h:51
unsigned int maxNumOfPointsPerQuadrant
Definition: QuadTreeNeighborCache.h:53
QuadTree * quadTree
Definition: QuadTreeNeighborCache.h:48
void rebuildQuadTree()
Definition: QuadTreeNeighborCache.cc:137
const value_type & get() const
Definition: Units.h:89
double maxSpeed
Definition: QuadTreeNeighborCache.h:55
double refillPeriod
Definition: QuadTreeNeighborCache.h:54
Local initializations.
Definition: InitStages.h:35
RadioMedium * radioMedium
Definition: QuadTreeNeighborCache.h:50
Coord constraintAreaMax
Definition: QuadTreeNeighborCache.h:52
Coord constraintAreaMin
Definition: QuadTreeNeighborCache.h:52
virtual const IMediumLimitCache * getMediumLimitCache() const override
Definition: RadioMedium.h:328
virtual Coord getMaxConstraintArea() const =0
Returns the maximum possible position among the radios, the coordinate values are in the range (-infi...
Additional link-layer initializations that depend on the previous stage.
Definition: InitStages.h:64
virtual mps getMaxSpeed() const =0
Returns the maximum possible speed among the radios, the value is in the range [0, +infinity) or NaN if unspecified.
virtual int inet::physicallayer::QuadTreeNeighborCache::numInitStages ( ) const
inlineoverrideprotectedvirtual
58 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
std::ostream & inet::physicallayer::QuadTreeNeighborCache::printToStream ( std::ostream &  stream,
int  level 
) const
overridevirtual

Prints this object to the provided output stream.

Function calls to operator<< with pointers or references either const or not are all forwarded to this function.

Reimplemented from inet::physicallayer::IPrintableObject.

66 {
67  stream << "QuadTreeNeighborCache";
68  if (level <= PRINT_LEVEL_TRACE)
69  stream << ", maxNumOfPointsPerQuadrant = " << maxNumOfPointsPerQuadrant
70  << ", refillPeriod = " << refillPeriod
71  << ", maxSpeed = " << maxSpeed;
72  return stream;
73 }
unsigned int maxNumOfPointsPerQuadrant
Definition: QuadTreeNeighborCache.h:53
double maxSpeed
Definition: QuadTreeNeighborCache.h:55
double refillPeriod
Definition: QuadTreeNeighborCache.h:54
void inet::physicallayer::QuadTreeNeighborCache::rebuildQuadTree ( )
protected

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

138 {
139  delete quadTree;
142 }
unsigned int maxNumOfPointsPerQuadrant
Definition: QuadTreeNeighborCache.h:53
QuadTree * quadTree
Definition: QuadTreeNeighborCache.h:48
void fillQuadTreeWithRadios()
Definition: QuadTreeNeighborCache.cc:128
Coord constraintAreaMax
Definition: QuadTreeNeighborCache.h:52
Coord constraintAreaMin
Definition: QuadTreeNeighborCache.h:52
void inet::physicallayer::QuadTreeNeighborCache::removeRadio ( const IRadio radio)
overridevirtual

Implements inet::physicallayer::INeighborCache.

97 {
98  auto it = find(radios.begin(), radios.end(), radio);
99  if (it != radios.end()) {
100  radios.erase(it);
101  Coord newConstraintAreaMin = radioMedium->getMediumLimitCache()->getMinConstraintArea();
102  Coord newConstraintAreaMax = radioMedium->getMediumLimitCache()->getMaxConstraintArea();
103  if (newConstraintAreaMin != constraintAreaMin || newConstraintAreaMax != constraintAreaMax)
104  {
105  constraintAreaMin = newConstraintAreaMin;
106  constraintAreaMax = newConstraintAreaMax;
107  if (initialized())
108  rebuildQuadTree();
109  }
110  else if (initialized())
111  quadTree->remove(check_and_cast<const cObject *>(radio));
113  if (maxSpeed == 0 && initialized())
114  cancelEvent(rebuildQuadTreeTimer);
115  }
116  else
117  throw cRuntimeError("You can't remove radio: %d because it is not in our radio container", radio->getId());
118 }
virtual Coord getMinConstraintArea() const =0
Returns the minimum possible position among the radios, the coordinate values are in the range (-infi...
cMessage * rebuildQuadTreeTimer
Definition: QuadTreeNeighborCache.h:51
QuadTree * quadTree
Definition: QuadTreeNeighborCache.h:48
void rebuildQuadTree()
Definition: QuadTreeNeighborCache.cc:137
bool remove(const cObject *point)
Definition: QuadTree.cc:152
const value_type & get() const
Definition: Units.h:89
double maxSpeed
Definition: QuadTreeNeighborCache.h:55
RadioMedium * radioMedium
Definition: QuadTreeNeighborCache.h:50
Coord constraintAreaMax
Definition: QuadTreeNeighborCache.h:52
Radios radios
Definition: QuadTreeNeighborCache.h:49
Coord constraintAreaMin
Definition: QuadTreeNeighborCache.h:52
virtual const IMediumLimitCache * getMediumLimitCache() const override
Definition: RadioMedium.h:328
virtual Coord getMaxConstraintArea() const =0
Returns the maximum possible position among the radios, the coordinate values are in the range (-infi...
virtual mps getMaxSpeed() const =0
Returns the maximum possible speed among the radios, the value is in the range [0, +infinity) or NaN if unspecified.
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
void inet::physicallayer::QuadTreeNeighborCache::sendToNeighbors ( IRadio transmitter,
const IRadioFrame frame,
double  range 
) const
overridevirtual

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

Implements inet::physicallayer::INeighborCache.

121 {
122  double radius = range + refillPeriod * maxSpeed;
123  Coord transmitterPos = transmitter->getAntenna()->getMobility()->getCurrentPosition();
124  QuadTreeNeighborCacheVisitor visitor(radioMedium, transmitter, frame);
125  quadTree->rangeQuery(transmitterPos, radius, &visitor);
126 }
void rangeQuery(const Coord &pos, double range, const IVisitor *visitor) const
Definition: QuadTree.cc:106
QuadTree * quadTree
Definition: QuadTreeNeighborCache.h:48
double maxSpeed
Definition: QuadTreeNeighborCache.h:55
double refillPeriod
Definition: QuadTreeNeighborCache.h:54
RadioMedium * radioMedium
Definition: QuadTreeNeighborCache.h:50

Member Data Documentation

Coord inet::physicallayer::QuadTreeNeighborCache::constraintAreaMax
protected
Coord inet::physicallayer::QuadTreeNeighborCache::constraintAreaMin
protected
unsigned int inet::physicallayer::QuadTreeNeighborCache::maxNumOfPointsPerQuadrant
protected
double inet::physicallayer::QuadTreeNeighborCache::maxSpeed
protected
QuadTree* inet::physicallayer::QuadTreeNeighborCache::quadTree
protected
RadioMedium* inet::physicallayer::QuadTreeNeighborCache::radioMedium
protected
Radios inet::physicallayer::QuadTreeNeighborCache::radios
protected
cMessage* inet::physicallayer::QuadTreeNeighborCache::rebuildQuadTreeTimer
protected
double inet::physicallayer::QuadTreeNeighborCache::refillPeriod
protected

The documentation for this class was generated from the following files: