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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Marco Miozzo <marco.miozzo@cttc.es>
18 *
19 */
20
22
23#include "building-list.h"
24
25#include <ns3/assert.h>
26#include <ns3/log.h>
27#include <ns3/pointer.h>
28#include <ns3/position-allocator.h>
29#include <ns3/simulator.h>
30
31namespace ns3
32{
33
34NS_LOG_COMPONENT_DEFINE("MobilityBuildingInfo");
35
36NS_OBJECT_ENSURE_REGISTERED(MobilityBuildingInfo);
37
38TypeId
40{
41 static TypeId tid = TypeId("ns3::MobilityBuildingInfo")
43 .SetGroupName("Buildings")
44 .AddConstructor<MobilityBuildingInfo>();
45
46 return tid;
47}
48
49void
51{
52 NS_LOG_FUNCTION(this);
53 Ptr<MobilityModel> mm = this->GetObject<MobilityModel>();
55}
56
58{
59 NS_LOG_FUNCTION(this);
60 m_indoor = false;
61 m_nFloor = 1;
62 m_roomX = 1;
63 m_roomY = 1;
64 m_cachedPosition = Vector(0, 0, 0);
65}
66
68 : m_myBuilding(building)
69{
70 NS_LOG_FUNCTION(this);
71 m_indoor = false;
72 m_nFloor = 1;
73 m_roomX = 1;
74 m_roomY = 1;
75}
76
77bool
79{
80 NS_LOG_FUNCTION(this);
81 Ptr<MobilityModel> mm = this->GetObject<MobilityModel>();
82 Vector currentPosition = mm->GetPosition();
83 bool posNotEqual = (currentPosition < m_cachedPosition) || (m_cachedPosition < currentPosition);
84 if (posNotEqual)
85 {
87 }
88
89 return m_indoor;
90}
91
92void
94 uint8_t nfloor,
95 uint8_t nroomx,
96 uint8_t nroomy)
97{
98 NS_LOG_FUNCTION(this);
99 m_indoor = true;
100 m_myBuilding = building;
101 m_nFloor = nfloor;
102 m_roomX = nroomx;
103 m_roomY = nroomy;
104
105 NS_ASSERT(m_roomX > 0);
106 NS_ASSERT(m_roomX <= building->GetNRoomsX());
107 NS_ASSERT(m_roomY > 0);
108 NS_ASSERT(m_roomY <= building->GetNRoomsY());
109 NS_ASSERT(m_nFloor > 0);
110 NS_ASSERT(m_nFloor <= building->GetNFloors());
111}
112
113void
114MobilityBuildingInfo::SetIndoor(uint8_t nfloor, uint8_t nroomx, uint8_t nroomy)
115{
116 NS_LOG_FUNCTION(this);
117 m_indoor = true;
118 m_nFloor = nfloor;
119 m_roomX = nroomx;
120 m_roomY = nroomy;
121
122 NS_ASSERT_MSG(m_myBuilding, "Node does not have any building defined");
123 NS_ASSERT(m_roomX > 0);
124 NS_ASSERT(m_roomX <= m_myBuilding->GetNRoomsX());
125 NS_ASSERT(m_roomY > 0);
126 NS_ASSERT(m_roomY <= m_myBuilding->GetNRoomsY());
127 NS_ASSERT(m_nFloor > 0);
128 NS_ASSERT(m_nFloor <= m_myBuilding->GetNFloors());
129}
130
131void
133{
134 NS_LOG_FUNCTION(this);
135 m_indoor = false;
136}
137
138uint8_t
140{
141 NS_LOG_FUNCTION(this);
142 return m_nFloor;
143}
144
145uint8_t
147{
148 NS_LOG_FUNCTION(this);
149 return m_roomX;
150}
151
152uint8_t
154{
155 NS_LOG_FUNCTION(this);
156 return m_roomY;
157}
158
161{
162 NS_LOG_FUNCTION(this);
163 return m_myBuilding;
164}
165
166void
168{
169 bool found = false;
170 Vector pos = mm->GetPosition();
171 for (auto bit = BuildingList::Begin(); bit != BuildingList::End(); ++bit)
172 {
173 NS_LOG_LOGIC("checking building " << (*bit)->GetId() << " with boundaries "
174 << (*bit)->GetBoundaries());
175 if ((*bit)->IsInside(pos))
176 {
177 NS_LOG_LOGIC("MobilityBuildingInfo " << this << " pos " << pos
178 << " falls inside building " << (*bit)->GetId());
179 NS_ABORT_MSG_UNLESS(found == false,
180 " MobilityBuildingInfo already inside another building!");
181 found = true;
182 uint16_t floor = (*bit)->GetFloor(pos);
183 uint16_t roomX = (*bit)->GetRoomX(pos);
184 uint16_t roomY = (*bit)->GetRoomY(pos);
185 SetIndoor(*bit, floor, roomX, roomY);
186 }
187 }
188 if (!found)
189 {
190 NS_LOG_LOGIC("MobilityBuildingInfo " << this << " pos " << pos << " is outdoor");
191 SetOutdoor();
192 }
193
194 m_cachedPosition = pos;
195}
196
197} // 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:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition: abort.h:144
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.