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