A Discrete-Event Network Simulator
API
building.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  * Authors: Marco Miozzo <marco.miozzo@cttc.es>
19  * Nicola Baldo <nbaldo@cttc.es>
20  *
21  */
22 
23 #include "building.h"
24 #include "building-list.h"
25 
26 #include <ns3/enum.h>
27 #include <ns3/uinteger.h>
28 #include <ns3/log.h>
29 #include <ns3/assert.h>
30 #include <cmath>
31 
32 namespace ns3 {
33 
34 NS_LOG_COMPONENT_DEFINE ("Building");
35 
37 
38 TypeId
40 {
41  static TypeId tid = TypeId ("ns3::Building")
42  .SetParent<Object> ()
43  .AddConstructor<Building> ()
44  .SetGroupName ("Buildings")
45  .AddAttribute ("NRoomsX", "The number of rooms in the X axis.",
46  UintegerValue (1),
48  MakeUintegerChecker<uint32_t> ())
49  .AddAttribute ("NRoomsY", "The number of rooms in the Y axis.",
50  UintegerValue (1),
52  MakeUintegerChecker<uint32_t> ())
53  .AddAttribute ("NFloors", "The number of floors of this building.",
54  UintegerValue (1),
56  MakeUintegerChecker<uint32_t> ())
57  .AddAttribute ("Id", "The id (unique integer) of this Building.",
58  UintegerValue (0),
60  MakeUintegerChecker<uint32_t> ())
61  .AddAttribute ("Boundaries", "The boundaries of this Building as a value of type ns3::Box",
62  BoxValue (Box ()),
64  MakeBoxChecker ())
65  .AddAttribute ("Type",
66  "The type of building",
69  MakeEnumChecker (Building::Residential, "Residential",
70  Building::Office, "Office",
71  Building::Commercial, "Commercial"))
72  .AddAttribute ("ExternalWallsType",
73  "The type of material of which the external walls are made",
77  Building::ConcreteWithWindows, "ConcreteWithWindows",
78  Building::ConcreteWithoutWindows, "ConcreteWithoutWindows",
79  Building::StoneBlocks, "StoneBlocks"))
80  ;
81  return tid;
82 }
83 
84 Building::Building (double xMin,
85  double xMax,
86  double yMin,
87  double yMax,
88  double zMin,
89  double zMax)
90 {
91  NS_FATAL_ERROR (std::endl << "this function is not supported any more:" << std::endl
92  << " Building::Building (double xMin, double xMax, double yMin, " << std::endl
93  << " double yMax, double zMin, double zMax)\n" << std::endl
94  << "so you can't do any more stuff like:" << std::endl
95  << "Ptr<Building> b = CreateObject<Building> ("
96  << xMin << ", "
97  << xMax << ", "
98  << yMin << ", "
99  << yMax << ", "
100  << zMin << ", "
101  << zMax << ")\n" << std::endl
102  << "Please use instead something like this:" << std::endl
103  << " Ptr<Building> b = CreateObject<Building> ();" << std::endl
104  << " b->SetBoundaries (Box ("
105  << xMin << ", "
106  << xMax << ", "
107  << yMin << ", "
108  << yMax << ", "
109  << zMin << ", "
110  << zMax << "));" << std::endl <<std::endl);
111 }
112 
113 
115 {
116  NS_LOG_FUNCTION (this);
118 }
119 
121 {
122  NS_LOG_FUNCTION (this);
123 }
124 
125 void
127 {
128  NS_LOG_FUNCTION (this);
129 }
130 
131 uint32_t
132 Building::GetId (void) const
133 {
134  NS_LOG_FUNCTION (this);
135  return m_buildingId;
136 }
137 
138 void
140 {
141  NS_LOG_FUNCTION (this << boundaries);
142  m_buildingBounds = boundaries;
143 }
144 
145 void
147 {
148  NS_LOG_FUNCTION (this << t);
149  m_buildingType = t;
150 }
151 
152 void
154 {
155  NS_LOG_FUNCTION (this << t);
156  m_externalWalls = t;
157 }
158 
159 void
160 Building::SetNFloors (uint16_t nfloors)
161 {
162  NS_LOG_FUNCTION (this << nfloors);
163  m_floors = nfloors;
164 }
165 
166 void
167 Building::SetNRoomsX (uint16_t nroomx)
168 {
169  NS_LOG_FUNCTION (this << nroomx);
170  m_roomsX = nroomx;
171 }
172 
173 void
174 Building::SetNRoomsY (uint16_t nroomy)
175 {
176  NS_LOG_FUNCTION (this << nroomy);
177  m_roomsY = nroomy;
178 }
179 
180 Box
182 {
183  NS_LOG_FUNCTION (this);
184  return m_buildingBounds;
185 }
186 
189 {
190  return (m_buildingType);
191 }
192 
195 {
196  return (m_externalWalls);
197 }
198 
199 uint16_t
201 {
202  return (m_floors);
203 }
204 
205 uint16_t
207 {
208  return (m_roomsX);
209 }
210 
211 uint16_t
213 {
214  return (m_roomsY);
215 }
216 
217 bool
218 Building::IsInside (Vector position) const
219 {
220  return m_buildingBounds.IsInside (position);
221 }
222 
223 
224 uint16_t
225 Building::GetRoomX (Vector position) const
226 {
227  NS_ASSERT (IsInside (position));
228  uint16_t n;
229 
230  if (position.x == m_buildingBounds.xMax)
231  {
232  n = m_roomsX;
233  }
234  else
235  {
236  double xLength = m_buildingBounds.xMax - m_buildingBounds.xMin;
237  double x = position.x - m_buildingBounds.xMin;
238  n = floor (m_roomsX * x/xLength) + 1;
239  NS_LOG_LOGIC ("xLength=" << xLength << ", x=" << x << ", m_roomsX=" << m_roomsX);
240  }
241  NS_LOG_LOGIC ("RoomX: " << n);
242  return n;
243 }
244 
245 uint16_t
246 Building::GetRoomY (Vector position) const
247 {
248  NS_ASSERT (IsInside (position));
249  uint16_t n;
250 
251  if (position.y == m_buildingBounds.yMax)
252  {
253  n = m_roomsY;
254  }
255  else
256  {
257  double yLength = m_buildingBounds.yMax - m_buildingBounds.yMin;
258  double y = position.y - m_buildingBounds.yMin;
259  n = floor (m_roomsY * y/yLength) + 1;
260  NS_LOG_LOGIC ("yLength=" << yLength << ", y=" << y << ", m_roomsY=" << m_roomsY);
261  }
262  NS_LOG_LOGIC ("RoomY: " << n);
263  return n;
264 }
265 
266 uint16_t
267 Building::GetFloor (Vector position) const
268 {
269  NS_ASSERT (IsInside (position));
270  uint16_t n;
271 
272  if (position.z == m_buildingBounds.zMax)
273  {
274  n = m_floors;
275  }
276  else
277  {
278  double zLength = m_buildingBounds.zMax - m_buildingBounds.zMin;
279  double z = position.z - m_buildingBounds.zMin;
280  n = floor (m_floors * z/zLength) + 1;
281  NS_LOG_LOGIC ("zLength=" << zLength << ", z=" << z << ", m_floors=" << m_floors);
282  }
283  NS_LOG_LOGIC ("floor: " << n);
284  return n;
285 }
286 
287 bool
288 Building::IsIntersect (const Vector &l1, const Vector &l2) const
289 {
290  return m_buildingBounds.IsIntersect (l1, l2);
291 }
292 
293 
294 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::Building::ConcreteWithoutWindows
@ ConcreteWithoutWindows
Definition: building.h:52
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#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
ns3::Building::m_externalWalls
ExtWallsType_t m_externalWalls
Definition: building.h:230
ns3::Building::m_roomsX
uint16_t m_roomsX
Definition: building.h:225
ns3::Building::GetBoundaries
Box GetBoundaries() const
Definition: building.cc:181
ns3::Building::Commercial
@ Commercial
Definition: building.h:48
ns3::Building::m_buildingBounds
Box m_buildingBounds
Definition: building.h:218
ns3::Building::SetExtWallsType
void SetExtWallsType(Building::ExtWallsType_t t)
Definition: building.cc:153
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::BuildingList::Add
static uint32_t Add(Ptr< Building > building)
Definition: building-list.cc:168
ns3::Box::zMin
double zMin
The z coordinate of the down bound of the box.
Definition: box.h:118
ns3::MakeEnumChecker
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:161
ns3::Building::Residential
@ Residential
Definition: building.h:48
ns3::Building::GetRoomX
uint16_t GetRoomX(Vector position) const
Definition: building.cc:225
ns3::Box::xMin
double xMin
The x coordinate of the left bound of the box.
Definition: box.h:110
ns3::Building::GetNFloors
uint16_t GetNFloors() const
Definition: building.cc:200
ns3::Building::ExtWallsType_t
ExtWallsType_t
Definition: building.h:51
ns3::Building::GetExtWallsType
ExtWallsType_t GetExtWallsType() const
Definition: building.cc:194
ns3::Building::GetNRoomsY
uint16_t GetNRoomsY() const
Definition: building.cc:212
ns3::MakeBoxChecker
Ptr< const AttributeChecker > MakeBoxChecker(void)
Definition: box.cc:207
ns3::Box::yMin
double yMin
The y coordinate of the bottom bound of the box.
Definition: box.h:114
ns3::Building::SetNRoomsX
void SetNRoomsX(uint16_t nroomx)
Definition: building.cc:167
ns3::Building::Building
Building()
Create a zero-sized building located at coordinates (0.0,0.0,0.0) and with 1 floors and 1 room.
Definition: building.cc:114
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::Building::~Building
virtual ~Building()
Destructor.
Definition: building.cc:120
ns3::EnumValue
Hold variables of type enum.
Definition: enum.h:55
ns3::Building::IsIntersect
bool IsIntersect(const Vector &l1, const Vector &l2) const
Checks if a line-segment between position l1 and position l2 intersects a building.
Definition: building.cc:288
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
ns3::Building::SetBuildingType
void SetBuildingType(Building::BuildingType_t t)
Definition: building.cc:146
ns3::Box::IsIntersect
bool IsIntersect(const Vector &l1, const Vector &l2) const
Checks if a line-segment between position l1 and position l2 intersects a box.
Definition: box.cc:147
ns3::Building::IsInside
bool IsInside(Vector position) const
Definition: building.cc:218
ns3::Building::Wood
@ Wood
Definition: building.h:52
ns3::Building::GetId
uint32_t GetId(void) const
Definition: building.cc:132
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
ns3::Building::Office
@ Office
Definition: building.h:48
ns3::Building::SetBoundaries
void SetBoundaries(Box box)
Set the boundaries of the building.
Definition: building.cc:139
ns3::Building::GetNRoomsX
uint16_t GetNRoomsX() const
Definition: building.cc:206
ns3::Building::SetNRoomsY
void SetNRoomsY(uint16_t nroomy)
Definition: building.cc:174
ns3::Box::zMax
double zMax
The z coordinate of the up bound of the box.
Definition: box.h:120
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
ns3::Building::m_roomsY
uint16_t m_roomsY
Definition: building.h:226
ns3::Building::GetFloor
uint16_t GetFloor(Vector position) const
Definition: building.cc:267
ns3::Building::BuildingType_t
BuildingType_t
Definition: building.h:47
ns3::Building::ConcreteWithWindows
@ ConcreteWithWindows
Definition: building.h:52
ns3::MakeEnumAccessor
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: enum.h:203
ns3::Building::GetBuildingType
BuildingType_t GetBuildingType() const
Definition: building.cc:188
ns3::Box
a 3d box
Definition: box.h:35
ns3::BoxValue
AttributeValue implementation for Box.
Definition: box.h:126
sample-rng-plot.x
list x
Definition: sample-rng-plot.py:34
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::Building::GetRoomY
uint16_t GetRoomY(Vector position) const
Definition: building.cc:246
ns3::Building::DoDispose
virtual void DoDispose()
Destructor implementation.
Definition: building.cc:126
ns3::Building::StoneBlocks
@ StoneBlocks
Definition: building.h:52
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::Building::m_buildingId
uint32_t m_buildingId
Definition: building.h:228
building.h
ns3::MakeUintegerAccessor
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
ns3::Building::m_floors
uint16_t m_floors
number of floors, must be greater than 0, and 1 means only one floor (i.e., groundfloor)
Definition: building.h:224
ns3::Box::IsInside
bool IsInside(const Vector &position) const
Definition: box.cc:54
ns3::Box::xMax
double xMax
The x coordinate of the right bound of the box.
Definition: box.h:112
building-list.h
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37
ns3::Building::m_buildingType
BuildingType_t m_buildingType
Definition: building.h:229
ns3::MakeBoxAccessor
Ptr< const AttributeAccessor > MakeBoxAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: box.h:126
ns3::Building::GetTypeId
static TypeId GetTypeId(void)
Definition: building.cc:39
ns3::Box::yMax
double yMax
The y coordinate of the top bound of the box.
Definition: box.h:116
ns3::Building::SetNFloors
void SetNFloors(uint16_t nfloors)
Definition: building.cc:160