A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
building.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Marco Miozzo <marco.miozzo@cttc.es>
7 * Nicola Baldo <nbaldo@cttc.es>
8 *
9 */
10
11#include "building.h"
12
13#include "building-list.h"
14
15#include <ns3/assert.h>
16#include <ns3/enum.h>
17#include <ns3/log.h>
18#include <ns3/uinteger.h>
19
20#include <cmath>
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("Building");
26
28
29TypeId
31{
32 static TypeId tid =
33 TypeId("ns3::Building")
35 .AddConstructor<Building>()
36 .SetGroupName("Buildings")
37 .AddAttribute("NRoomsX",
38 "The number of rooms in the X axis.",
42 .AddAttribute("NRoomsY",
43 "The number of rooms in the Y axis.",
47 .AddAttribute("NFloors",
48 "The number of floors of this building.",
52 .AddAttribute("Id",
53 "The id (unique integer) of this Building.",
57 .AddAttribute("Boundaries",
58 "The boundaries of this Building as a value of type ns3::Box",
59 BoxValue(Box()),
62 .AddAttribute("Type",
63 "The type of building",
68 "Residential",
70 "Office",
72 "Commercial"))
73 .AddAttribute("ExternalWallsType",
74 "The type of material of which the external walls are made",
79 "Wood",
81 "ConcreteWithWindows",
83 "ConcreteWithoutWindows",
85 "StoneBlocks"));
86 return tid;
87}
88
89Building::Building(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax)
90{
91 NS_FATAL_ERROR(std::endl
92 << "this function is not supported any more:" << std::endl
93 << " Building::Building (double xMin, double xMax, double yMin, " << std::endl
94 << " double yMax, double zMin, double zMax)\n"
95 << std::endl
96 << "so you can't do any more stuff like:" << std::endl
97 << "Ptr<Building> b = CreateObject<Building> (" << xMin << ", " << xMax << ", "
98 << yMin << ", " << yMax << ", " << zMin << ", " << zMax << ")\n"
99 << std::endl
100 << "Please use instead something like this:" << std::endl
101 << " Ptr<Building> b = CreateObject<Building> ();" << std::endl
102 << " b->SetBoundaries (Box (" << xMin << ", " << xMax << ", " << yMin << ", "
103 << yMax << ", " << zMin << ", " << zMax << "));" << std::endl
104 << std::endl);
105}
106
112
117
118void
123
126{
127 NS_LOG_FUNCTION(this);
128 return m_buildingId;
129}
130
131void
133{
134 NS_LOG_FUNCTION(this << boundaries);
135 m_buildingBounds = boundaries;
136}
137
138void
144
145void
151
152void
153Building::SetNFloors(uint16_t nfloors)
154{
155 NS_LOG_FUNCTION(this << nfloors);
156 m_floors = nfloors;
157}
158
159void
160Building::SetNRoomsX(uint16_t nroomx)
161{
162 NS_LOG_FUNCTION(this << nroomx);
163 m_roomsX = nroomx;
164}
165
166void
167Building::SetNRoomsY(uint16_t nroomy)
168{
169 NS_LOG_FUNCTION(this << nroomy);
170 m_roomsY = nroomy;
171}
172
173Box
175{
176 NS_LOG_FUNCTION(this);
177 return m_buildingBounds;
178}
179
182{
183 return (m_buildingType);
184}
185
188{
189 return (m_externalWalls);
190}
191
192uint16_t
194{
195 return (m_floors);
196}
197
198uint16_t
200{
201 return (m_roomsX);
202}
203
204uint16_t
206{
207 return (m_roomsY);
208}
209
210bool
211Building::IsInside(Vector position) const
212{
213 return m_buildingBounds.IsInside(position);
214}
215
216uint16_t
217Building::GetRoomX(Vector position) const
218{
219 NS_ASSERT(IsInside(position));
220 uint16_t n;
221
222 if (position.x == m_buildingBounds.xMax)
223 {
224 n = m_roomsX;
225 }
226 else
227 {
228 double xLength = m_buildingBounds.xMax - m_buildingBounds.xMin;
229 double x = position.x - m_buildingBounds.xMin;
230 n = floor(m_roomsX * x / xLength) + 1;
231 NS_LOG_LOGIC("xLength=" << xLength << ", x=" << x << ", m_roomsX=" << m_roomsX);
232 }
233 NS_LOG_LOGIC("RoomX: " << n);
234 return n;
235}
236
237uint16_t
238Building::GetRoomY(Vector position) const
239{
240 NS_ASSERT(IsInside(position));
241 uint16_t n;
242
243 if (position.y == m_buildingBounds.yMax)
244 {
245 n = m_roomsY;
246 }
247 else
248 {
249 double yLength = m_buildingBounds.yMax - m_buildingBounds.yMin;
250 double y = position.y - m_buildingBounds.yMin;
251 n = floor(m_roomsY * y / yLength) + 1;
252 NS_LOG_LOGIC("yLength=" << yLength << ", y=" << y << ", m_roomsY=" << m_roomsY);
253 }
254 NS_LOG_LOGIC("RoomY: " << n);
255 return n;
256}
257
258uint16_t
259Building::GetFloor(Vector position) const
260{
261 NS_ASSERT(IsInside(position));
262 uint16_t n;
263
264 if (position.z == m_buildingBounds.zMax)
265 {
266 n = m_floors;
267 }
268 else
269 {
270 double zLength = m_buildingBounds.zMax - m_buildingBounds.zMin;
271 double z = position.z - m_buildingBounds.zMin;
272 n = floor(m_floors * z / zLength) + 1;
273 NS_LOG_LOGIC("zLength=" << zLength << ", z=" << z << ", m_floors=" << m_floors);
274 }
275 NS_LOG_LOGIC("floor: " << n);
276 return n;
277}
278
279bool
280Building::IsIntersect(const Vector& l1, const Vector& l2) const
281{
282 return m_buildingBounds.IsIntersect(l1, l2);
283}
284
285} // namespace ns3
a 3d box
Definition box.h:24
double yMax
The y coordinate of the top bound of the box.
Definition box.h:105
bool IsInside(const Vector &position) const
Definition box.cc:43
double xMin
The x coordinate of the left bound of the box.
Definition box.h:99
double yMin
The y coordinate of the bottom bound of the box.
Definition box.h:103
double xMax
The x coordinate of the right bound of the box.
Definition box.h:101
double zMin
The z coordinate of the down bound of the box.
Definition box.h:107
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:133
double zMax
The z coordinate of the up bound of the box.
Definition box.h:109
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:107
uint32_t GetId() const
Definition building.cc:125
uint16_t GetNRoomsY() const
Definition building.cc:205
uint32_t m_buildingId
Building ID number.
Definition building.h:227
BuildingType_t m_buildingType
Building type.
Definition building.h:228
ExtWallsType_t GetExtWallsType() const
Definition building.cc:187
ExtWallsType_t
External building wall type enum.
Definition building.h:56
@ ConcreteWithWindows
Definition building.h:58
@ ConcreteWithoutWindows
Definition building.h:59
ExtWallsType_t m_externalWalls
External building wall type.
Definition building.h:229
void SetBuildingType(Building::BuildingType_t t)
Definition building.cc:139
uint16_t GetNFloors() const
Definition building.cc:193
void SetBoundaries(Box box)
Set the boundaries of the building.
Definition building.cc:132
BuildingType_t GetBuildingType() const
Definition building.cc:181
void SetNRoomsX(uint16_t nroomx)
Definition building.cc:160
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:280
uint16_t GetRoomY(Vector position) const
Definition building.cc:238
void SetExtWallsType(Building::ExtWallsType_t t)
Definition building.cc:146
uint16_t m_floors
number of floors, must be greater than 0, and 1 means only one floor (i.e., groundfloor)
Definition building.h:223
void DoDispose() override
Destructor implementation.
Definition building.cc:119
void SetNRoomsY(uint16_t nroomy)
Definition building.cc:167
Box GetBoundaries() const
Definition building.cc:174
uint16_t m_roomsX
X Room coordinate.
Definition building.h:224
~Building() override
Destructor.
Definition building.cc:113
uint16_t GetFloor(Vector position) const
Definition building.cc:259
uint16_t GetNRoomsX() const
Definition building.cc:199
uint16_t m_roomsY
Y Room coordinate.
Definition building.h:225
bool IsInside(Vector position) const
Definition building.cc:211
void SetNFloors(uint16_t nfloors)
Definition building.cc:153
Box m_buildingBounds
Building boundaries.
Definition building.h:217
uint16_t GetRoomX(Vector position) const
Definition building.cc:217
BuildingType_t
Building type enum.
Definition building.h:46
static TypeId GetTypeId()
Get the type ID.
Definition building.cc:30
static uint32_t Add(Ptr< Building > building)
Hold variables of type enum.
Definition enum.h:52
A base class which provides memory management and object aggregation.
Definition object.h:78
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeAccessor > MakeBoxAccessor(T1 a1)
Definition box.h:115
Ptr< const AttributeChecker > MakeBoxChecker()
Definition box.cc:191
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition enum.h:179
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition enum.h:221