A Discrete-Event Network Simulator
API
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 
21 #include <ns3/assert.h>
22 #include <ns3/building-list.h>
23 #include <ns3/log.h>
24 #include <ns3/mobility-building-info.h>
25 #include <ns3/pointer.h>
26 #include <ns3/position-allocator.h>
27 #include <ns3/simulator.h>
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("MobilityBuildingInfo");
33 
34 NS_OBJECT_ENSURE_REGISTERED(MobilityBuildingInfo);
35 
36 TypeId
38 {
39  static TypeId tid = TypeId("ns3::MobilityBuildingInfo")
40  .SetParent<Object>()
41  .SetGroupName("Buildings")
42  .AddConstructor<MobilityBuildingInfo>();
43 
44  return tid;
45 }
46 
47 void
49 {
50  NS_LOG_FUNCTION(this);
51  Ptr<MobilityModel> mm = this->GetObject<MobilityModel>();
52  MakeConsistent(mm);
53 }
54 
56 {
57  NS_LOG_FUNCTION(this);
58  m_indoor = false;
59  m_nFloor = 1;
60  m_roomX = 1;
61  m_roomY = 1;
62  m_cachedPosition = Vector(0, 0, 0);
63 }
64 
66  : m_myBuilding(building)
67 {
68  NS_LOG_FUNCTION(this);
69  m_indoor = false;
70  m_nFloor = 1;
71  m_roomX = 1;
72  m_roomY = 1;
73 }
74 
75 bool
77 {
78  NS_LOG_FUNCTION(this);
79  Ptr<MobilityModel> mm = this->GetObject<MobilityModel>();
80  Vector currentPosition = mm->GetPosition();
81  bool posNotEqual = (currentPosition < m_cachedPosition) || (m_cachedPosition < currentPosition);
82  if (posNotEqual)
83  {
84  MakeConsistent(mm);
85  }
86 
87  return m_indoor;
88 }
89 
90 void
92  uint8_t nfloor,
93  uint8_t nroomx,
94  uint8_t nroomy)
95 {
96  NS_LOG_FUNCTION(this);
97  m_indoor = true;
98  m_myBuilding = building;
99  m_nFloor = nfloor;
100  m_roomX = nroomx;
101  m_roomY = nroomy;
102 
103  NS_ASSERT(m_roomX > 0);
104  NS_ASSERT(m_roomX <= building->GetNRoomsX());
105  NS_ASSERT(m_roomY > 0);
106  NS_ASSERT(m_roomY <= building->GetNRoomsY());
107  NS_ASSERT(m_nFloor > 0);
108  NS_ASSERT(m_nFloor <= building->GetNFloors());
109 }
110 
111 void
112 MobilityBuildingInfo::SetIndoor(uint8_t nfloor, uint8_t nroomx, uint8_t nroomy)
113 {
114  NS_LOG_FUNCTION(this);
115  m_indoor = true;
116  m_nFloor = nfloor;
117  m_roomX = nroomx;
118  m_roomY = nroomy;
119 
120  NS_ASSERT_MSG(m_myBuilding, "Node does not have any building defined");
121  NS_ASSERT(m_roomX > 0);
122  NS_ASSERT(m_roomX <= m_myBuilding->GetNRoomsX());
123  NS_ASSERT(m_roomY > 0);
124  NS_ASSERT(m_roomY <= m_myBuilding->GetNRoomsY());
125  NS_ASSERT(m_nFloor > 0);
126  NS_ASSERT(m_nFloor <= m_myBuilding->GetNFloors());
127 }
128 
129 void
131 {
132  NS_LOG_FUNCTION(this);
133  m_indoor = false;
134 }
135 
136 uint8_t
138 {
139  NS_LOG_FUNCTION(this);
140  return (m_nFloor);
141 }
142 
143 uint8_t
145 {
146  NS_LOG_FUNCTION(this);
147  return (m_roomX);
148 }
149 
150 uint8_t
152 {
153  NS_LOG_FUNCTION(this);
154  return (m_roomY);
155 }
156 
159 {
160  NS_LOG_FUNCTION(this);
161  return (m_myBuilding);
162 }
163 
164 void
166 {
167  bool found = false;
168  Vector pos = mm->GetPosition();
169  for (BuildingList::Iterator bit = BuildingList::Begin(); bit != BuildingList::End(); ++bit)
170  {
171  NS_LOG_LOGIC("checking building " << (*bit)->GetId() << " with boundaries "
172  << (*bit)->GetBoundaries());
173  if ((*bit)->IsInside(pos))
174  {
175  NS_LOG_LOGIC("MobilityBuildingInfo " << this << " pos " << pos
176  << " falls inside building " << (*bit)->GetId());
177  NS_ABORT_MSG_UNLESS(found == false,
178  " MobilityBuildingInfo already inside another building!");
179  found = true;
180  uint16_t floor = (*bit)->GetFloor(pos);
181  uint16_t roomX = (*bit)->GetRoomX(pos);
182  uint16_t roomY = (*bit)->GetRoomY(pos);
183  SetIndoor(*bit, floor, roomX, roomY);
184  }
185  }
186  if (!found)
187  {
188  NS_LOG_LOGIC("MobilityBuildingInfo " << this << " pos " << pos << " is outdoor");
189  SetOutdoor();
190  }
191 
192  m_cachedPosition = pos;
193 }
194 
195 } // namespace ns3
std::vector< Ptr< Building > >::const_iterator Iterator
Const Iterator.
Definition: building-list.h:41
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.
Vector GetPosition() const
A base class which provides memory management and object aggregation.
Definition: object.h:89
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#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.