A Discrete-Event Network Simulator
API
mobility-building-info.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Marco Miozzo <marco.miozzo@cttc.es>
19  *
20  */
21 
22 #include <ns3/simulator.h>
23 #include <ns3/position-allocator.h>
24 #include <ns3/building-list.h>
25 #include <ns3/mobility-building-info.h>
26 #include <ns3/pointer.h>
27 #include <ns3/log.h>
28 #include <ns3/assert.h>
29 
30 namespace ns3 {
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 
55 
57 {
58  NS_LOG_FUNCTION (this);
59  m_indoor = false;
60  m_nFloor = 1;
61  m_roomX = 1;
62  m_roomY = 1;
63  m_cachedPosition = Vector (0, 0, 0);
64 }
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 
77 bool
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  {
86  MakeConsistent (mm);
87  }
88 
89  return m_indoor;
90 }
91 
92 bool
94 {
95  NS_LOG_FUNCTION (this);
96  bool isIndoor = IsIndoor ();
97  return (!isIndoor);
98 }
99 
100 void
101 MobilityBuildingInfo::SetIndoor (Ptr<Building> building, uint8_t nfloor, uint8_t nroomx, uint8_t nroomy)
102 {
103  NS_LOG_FUNCTION (this);
104  m_indoor = true;
105  m_myBuilding = building;
106  m_nFloor = nfloor;
107  m_roomX = nroomx;
108  m_roomY = nroomy;
109 
110 
111  NS_ASSERT (m_roomX > 0);
112  NS_ASSERT (m_roomX <= building->GetNRoomsX ());
113  NS_ASSERT (m_roomY > 0);
114  NS_ASSERT (m_roomY <= building->GetNRoomsY ());
115  NS_ASSERT (m_nFloor > 0);
116  NS_ASSERT (m_nFloor <= building->GetNFloors ());
117 
118 }
119 
120 
121 void
122 MobilityBuildingInfo::SetIndoor (uint8_t nfloor, uint8_t nroomx, uint8_t nroomy)
123 {
124  NS_LOG_FUNCTION (this);
125  m_indoor = true;
126  m_nFloor = nfloor;
127  m_roomX = nroomx;
128  m_roomY = nroomy;
129 
130  NS_ASSERT_MSG (m_myBuilding, "Node does not have any building defined");
131  NS_ASSERT (m_roomX > 0);
132  NS_ASSERT (m_roomX <= m_myBuilding->GetNRoomsX ());
133  NS_ASSERT (m_roomY > 0);
134  NS_ASSERT (m_roomY <= m_myBuilding->GetNRoomsY ());
135  NS_ASSERT (m_nFloor > 0);
136  NS_ASSERT (m_nFloor <= m_myBuilding->GetNFloors ());
137 
138 }
139 
140 
141 void
143 {
144  NS_LOG_FUNCTION (this);
145  m_indoor = false;
146 }
147 
148 uint8_t
150 {
151  NS_LOG_FUNCTION (this);
152  return (m_nFloor);
153 }
154 
155 uint8_t
157 {
158  NS_LOG_FUNCTION (this);
159  return (m_roomX);
160 }
161 
162 uint8_t
164 {
165  NS_LOG_FUNCTION (this);
166  return (m_roomY);
167 }
168 
169 
172 {
173  NS_LOG_FUNCTION (this);
174  return (m_myBuilding);
175 }
176 
177 void
179 {
180  bool found = false;
181  Vector pos = mm->GetPosition ();
182  for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit)
183  {
184  NS_LOG_LOGIC ("checking building " << (*bit)->GetId () << " with boundaries " << (*bit)->GetBoundaries ());
185  if ((*bit)->IsInside (pos))
186  {
187  NS_LOG_LOGIC ("MobilityBuildingInfo " << this << " pos " << pos << " falls inside building " << (*bit)->GetId ());
188  NS_ABORT_MSG_UNLESS (found == false, " MobilityBuildingInfo already inside another building!");
189  found = true;
190  uint16_t floor = (*bit)->GetFloor (pos);
191  uint16_t roomX = (*bit)->GetRoomX (pos);
192  uint16_t roomY = (*bit)->GetRoomY (pos);
193  SetIndoor (*bit, floor, roomX, roomY);
194  }
195  }
196  if (!found)
197  {
198  NS_LOG_LOGIC ("MobilityBuildingInfo " << this << " pos " << pos << " is outdoor");
199  SetOutdoor ();
200  }
201 
202  m_cachedPosition = pos;
203 
204 }
205 
206 
207 } // namespace
#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:45
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
void SetOutdoor()
Mark this MobilityBuildingInfo instance as outdoor.
uint8_t m_nFloor
The floor number at which the MobilityBuildingInfo instance is located.
static Iterator End(void)
uint8_t m_roomY
The room number along y-axis at which the MobilityBuildingInfo instance is located.
uint8_t m_roomX
The room number along x-axis at which the MobilityBuildingInfo instance is located.
static Iterator Begin(void)
uint8_t GetFloorNumber(void)
Get the floor number at which the MobilityBuildingInfo instance is located.
uint8_t GetRoomNumberX(void)
Get the room number along x-axis at which the MobilityBuildingInfo instance is located.
bool IsIndoor(void)
Is indoor method.
void SetIndoor(Ptr< Building > building, uint8_t nfloor, uint8_t nroomx, uint8_t nroomy)
Mark this MobilityBuildingInfo instance as indoor.
Vector m_cachedPosition
The node position cached after making its mobility model consistent.
Ptr< Building > m_myBuilding
Building.
std::vector< Ptr< Building > >::const_iterator Iterator
Definition: building-list.h:36
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void DoInitialize()
Initialize() implementation.
NS_DEPRECATED_3_31 bool IsOutdoor(void)
Is outdoor function.
static TypeId GetTypeId(void)
Get the type ID.
#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:88
Vector GetPosition(void) const
Ptr< Building > GetBuilding()
Get the building in which the MobilityBuildingInfo instance is located.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition: abort.h:144
mobility buildings information (to be used by mobility models)
A base class which provides memory management and object aggregation.
Definition: object.h:87
void MakeConsistent(Ptr< MobilityModel > mm)
Make the given mobility model consistent, by determining whether its position falls inside any of the...
bool m_indoor
Node position (indoor/outdoor) ?
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
uint8_t GetRoomNumberY(void)
Get the room number along y-axis at which the MobilityBuildingInfo instance is located.