A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mobility-building-info.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Marco Miozzo <marco.miozzo@cttc.es>
7 *
8 */
9
11
12#include "building-list.h"
13
14#include <ns3/assert.h>
15#include <ns3/log.h>
16#include <ns3/pointer.h>
17#include <ns3/position-allocator.h>
18#include <ns3/simulator.h>
19
20namespace ns3
21{
22
23NS_LOG_COMPONENT_DEFINE("MobilityBuildingInfo");
24
25NS_OBJECT_ENSURE_REGISTERED(MobilityBuildingInfo);
26
27TypeId
29{
30 static TypeId tid = TypeId("ns3::MobilityBuildingInfo")
32 .SetGroupName("Buildings")
33 .AddConstructor<MobilityBuildingInfo>();
34
35 return tid;
36}
37
38void
45
47{
48 NS_LOG_FUNCTION(this);
49 m_indoor = false;
50 m_nFloor = 1;
51 m_roomX = 1;
52 m_roomY = 1;
53 m_cachedPosition = Vector(0, 0, 0);
54}
55
57 : m_myBuilding(building)
58{
59 NS_LOG_FUNCTION(this);
60 m_indoor = false;
61 m_nFloor = 1;
62 m_roomX = 1;
63 m_roomY = 1;
64}
65
66bool
68{
69 NS_LOG_FUNCTION(this);
71 Vector currentPosition = mm->GetPosition();
72 bool posNotEqual = (currentPosition < m_cachedPosition) || (m_cachedPosition < currentPosition);
73 if (posNotEqual)
74 {
76 }
77
78 return m_indoor;
79}
80
81void
83 uint8_t nfloor,
84 uint8_t nroomx,
85 uint8_t nroomy)
86{
87 NS_LOG_FUNCTION(this);
88 m_indoor = true;
89 m_myBuilding = building;
90 m_nFloor = nfloor;
91 m_roomX = nroomx;
92 m_roomY = nroomy;
93
94 NS_ASSERT(m_roomX > 0);
96 NS_ASSERT(m_roomY > 0);
100}
101
102void
103MobilityBuildingInfo::SetIndoor(uint8_t nfloor, uint8_t nroomx, uint8_t nroomy)
104{
105 NS_LOG_FUNCTION(this);
106 m_indoor = true;
107 m_nFloor = nfloor;
108 m_roomX = nroomx;
109 m_roomY = nroomy;
110
111 NS_ASSERT_MSG(m_myBuilding, "Node does not have any building defined");
112 NS_ASSERT(m_roomX > 0);
114 NS_ASSERT(m_roomY > 0);
116 NS_ASSERT(m_nFloor > 0);
118}
119
120void
126
127uint8_t
133
134uint8_t
140
141uint8_t
147
154
155void
157{
158 bool found = false;
159 Vector pos = mm->GetPosition();
160 for (auto bit = BuildingList::Begin(); bit != BuildingList::End(); ++bit)
161 {
162 NS_LOG_LOGIC("checking building " << (*bit)->GetId() << " with boundaries "
163 << (*bit)->GetBoundaries());
164 if ((*bit)->IsInside(pos))
165 {
166 NS_LOG_LOGIC("MobilityBuildingInfo " << this << " pos " << pos
167 << " falls inside building " << (*bit)->GetId());
168 NS_ABORT_MSG_UNLESS(found == false,
169 " MobilityBuildingInfo already inside another building!");
170 found = true;
171 uint16_t floor = (*bit)->GetFloor(pos);
172 uint16_t roomX = (*bit)->GetRoomX(pos);
173 uint16_t roomY = (*bit)->GetRoomY(pos);
174 SetIndoor(*bit, floor, roomX, roomY);
175 }
176 }
177 if (!found)
178 {
179 NS_LOG_LOGIC("MobilityBuildingInfo " << this << " pos " << pos << " is outdoor");
180 SetOutdoor();
181 }
182
183 m_cachedPosition = pos;
184}
185
186} // namespace ns3
static Iterator End()
static Iterator Begin()
mobility buildings information (to be used by mobility models)
uint8_t GetFloorNumber()
Get the floor number at which the MobilityBuildingInfo instance is located.
bool IsIndoor()
Is indoor method.
Ptr< Building > GetBuilding()
Get the building in which the MobilityBuildingInfo instance is located.
uint8_t m_roomX
The room number along x-axis at which the MobilityBuildingInfo instance is located.
Ptr< Building > m_myBuilding
Building.
uint8_t m_roomY
The room number along y-axis at which the MobilityBuildingInfo instance is located.
static TypeId GetTypeId()
Get the type ID.
bool m_indoor
Node position (indoor/outdoor) ?
void DoInitialize() override
Initialize() implementation.
uint8_t GetRoomNumberX()
Get the room number along x-axis at which the MobilityBuildingInfo instance is located.
uint8_t GetRoomNumberY()
Get the room number along y-axis at which the MobilityBuildingInfo instance is located.
void SetIndoor(Ptr< Building > building, uint8_t nfloor, uint8_t nroomx, uint8_t nroomy)
Mark this MobilityBuildingInfo instance as indoor.
uint8_t m_nFloor
The floor number at which the MobilityBuildingInfo instance is located.
void SetOutdoor()
Mark this MobilityBuildingInfo instance as outdoor.
void MakeConsistent(Ptr< MobilityModel > mm)
Make the given mobility model consistent, by determining whether its position falls inside any of the...
Vector m_cachedPosition
The node position cached after making its mobility model consistent.
A base class which provides memory management and object aggregation.
Definition object.h:78
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition abort.h:133
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.