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 void
93 MobilityBuildingInfo::SetIndoor (Ptr<Building> building, uint8_t nfloor, uint8_t nroomx, uint8_t nroomy)
94 {
95  NS_LOG_FUNCTION (this);
96  m_indoor = true;
97  m_myBuilding = building;
98  m_nFloor = nfloor;
99  m_roomX = nroomx;
100  m_roomY = nroomy;
101 
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 
112 
113 void
114 MobilityBuildingInfo::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 }
131 
132 
133 void
135 {
136  NS_LOG_FUNCTION (this);
137  m_indoor = false;
138 }
139 
140 uint8_t
142 {
143  NS_LOG_FUNCTION (this);
144  return (m_nFloor);
145 }
146 
147 uint8_t
149 {
150  NS_LOG_FUNCTION (this);
151  return (m_roomX);
152 }
153 
154 uint8_t
156 {
157  NS_LOG_FUNCTION (this);
158  return (m_roomY);
159 }
160 
161 
164 {
165  NS_LOG_FUNCTION (this);
166  return (m_myBuilding);
167 }
168 
169 void
171 {
172  bool found = false;
173  Vector pos = mm->GetPosition ();
174  for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit)
175  {
176  NS_LOG_LOGIC ("checking building " << (*bit)->GetId () << " with boundaries " << (*bit)->GetBoundaries ());
177  if ((*bit)->IsInside (pos))
178  {
179  NS_LOG_LOGIC ("MobilityBuildingInfo " << this << " pos " << pos << " falls inside building " << (*bit)->GetId ());
180  NS_ABORT_MSG_UNLESS (found == false, " 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 
198 
199 } // namespace
std::vector< Ptr< Building > >::const_iterator Iterator
Const Iterator.
Definition: building-list.h:40
static Iterator End(void)
static Iterator Begin(void)
mobility buildings information (to be used by mobility models)
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.
bool IsIndoor(void)
Is indoor method.
static TypeId GetTypeId(void)
Get the type ID.
bool m_indoor
Node position (indoor/outdoor) ?
uint8_t GetRoomNumberY(void)
Get the room number along y-axis at which the MobilityBuildingInfo instance is located.
virtual void DoInitialize()
Initialize() implementation.
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.
uint8_t GetRoomNumberX(void)
Get the room number along x-axis at which the MobilityBuildingInfo instance is located.
void MakeConsistent(Ptr< MobilityModel > mm)
Make the given mobility model consistent, by determining whether its position falls inside any of the...
uint8_t GetFloorNumber(void)
Get the floor number at which the MobilityBuildingInfo instance is located.
Vector m_cachedPosition
The node position cached after making its mobility model consistent.
Vector GetPosition(void) const
A base class which provides memory management and object aggregation.
Definition: object.h:88
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#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_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
#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:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.