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",
76  MakeEnumAccessor<BuildingType_t>(&Building::GetBuildingType,
79  "Residential",
81  "Office",
83  "Commercial"))
84  .AddAttribute("ExternalWallsType",
85  "The type of material of which the external walls are made",
87  MakeEnumAccessor<ExtWallsType_t>(&Building::GetExtWallsType,
90  "Wood",
92  "ConcreteWithWindows",
94  "ConcreteWithoutWindows",
96  "StoneBlocks"));
97  return tid;
98 }
99 
100 Building::Building(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax)
101 {
102  NS_FATAL_ERROR(std::endl
103  << "this function is not supported any more:" << std::endl
104  << " Building::Building (double xMin, double xMax, double yMin, " << std::endl
105  << " double yMax, double zMin, double zMax)\n"
106  << std::endl
107  << "so you can't do any more stuff like:" << std::endl
108  << "Ptr<Building> b = CreateObject<Building> (" << xMin << ", " << xMax << ", "
109  << yMin << ", " << yMax << ", " << zMin << ", " << zMax << ")\n"
110  << std::endl
111  << "Please use instead something like this:" << std::endl
112  << " Ptr<Building> b = CreateObject<Building> ();" << std::endl
113  << " b->SetBoundaries (Box (" << xMin << ", " << xMax << ", " << yMin << ", "
114  << yMax << ", " << zMin << ", " << zMax << "));" << std::endl
115  << std::endl);
116 }
117 
119 {
120  NS_LOG_FUNCTION(this);
122 }
123 
125 {
126  NS_LOG_FUNCTION(this);
127 }
128 
129 void
131 {
132  NS_LOG_FUNCTION(this);
133 }
134 
135 uint32_t
137 {
138  NS_LOG_FUNCTION(this);
139  return m_buildingId;
140 }
141 
142 void
144 {
145  NS_LOG_FUNCTION(this << boundaries);
146  m_buildingBounds = boundaries;
147 }
148 
149 void
151 {
152  NS_LOG_FUNCTION(this << t);
153  m_buildingType = t;
154 }
155 
156 void
158 {
159  NS_LOG_FUNCTION(this << t);
160  m_externalWalls = t;
161 }
162 
163 void
164 Building::SetNFloors(uint16_t nfloors)
165 {
166  NS_LOG_FUNCTION(this << nfloors);
167  m_floors = nfloors;
168 }
169 
170 void
171 Building::SetNRoomsX(uint16_t nroomx)
172 {
173  NS_LOG_FUNCTION(this << nroomx);
174  m_roomsX = nroomx;
175 }
176 
177 void
178 Building::SetNRoomsY(uint16_t nroomy)
179 {
180  NS_LOG_FUNCTION(this << nroomy);
181  m_roomsY = nroomy;
182 }
183 
184 Box
186 {
187  NS_LOG_FUNCTION(this);
188  return m_buildingBounds;
189 }
190 
193 {
194  return (m_buildingType);
195 }
196 
199 {
200  return (m_externalWalls);
201 }
202 
203 uint16_t
205 {
206  return (m_floors);
207 }
208 
209 uint16_t
211 {
212  return (m_roomsX);
213 }
214 
215 uint16_t
217 {
218  return (m_roomsY);
219 }
220 
221 bool
222 Building::IsInside(Vector position) const
223 {
224  return m_buildingBounds.IsInside(position);
225 }
226 
227 uint16_t
228 Building::GetRoomX(Vector position) const
229 {
230  NS_ASSERT(IsInside(position));
231  uint16_t n;
232 
233  if (position.x == m_buildingBounds.xMax)
234  {
235  n = m_roomsX;
236  }
237  else
238  {
239  double xLength = m_buildingBounds.xMax - m_buildingBounds.xMin;
240  double x = position.x - m_buildingBounds.xMin;
241  n = floor(m_roomsX * x / xLength) + 1;
242  NS_LOG_LOGIC("xLength=" << xLength << ", x=" << x << ", m_roomsX=" << m_roomsX);
243  }
244  NS_LOG_LOGIC("RoomX: " << n);
245  return n;
246 }
247 
248 uint16_t
249 Building::GetRoomY(Vector position) const
250 {
251  NS_ASSERT(IsInside(position));
252  uint16_t n;
253 
254  if (position.y == m_buildingBounds.yMax)
255  {
256  n = m_roomsY;
257  }
258  else
259  {
260  double yLength = m_buildingBounds.yMax - m_buildingBounds.yMin;
261  double y = position.y - m_buildingBounds.yMin;
262  n = floor(m_roomsY * y / yLength) + 1;
263  NS_LOG_LOGIC("yLength=" << yLength << ", y=" << y << ", m_roomsY=" << m_roomsY);
264  }
265  NS_LOG_LOGIC("RoomY: " << n);
266  return n;
267 }
268 
269 uint16_t
270 Building::GetFloor(Vector position) const
271 {
272  NS_ASSERT(IsInside(position));
273  uint16_t n;
274 
275  if (position.z == m_buildingBounds.zMax)
276  {
277  n = m_floors;
278  }
279  else
280  {
281  double zLength = m_buildingBounds.zMax - m_buildingBounds.zMin;
282  double z = position.z - m_buildingBounds.zMin;
283  n = floor(m_floors * z / zLength) + 1;
284  NS_LOG_LOGIC("zLength=" << zLength << ", z=" << z << ", m_floors=" << m_floors);
285  }
286  NS_LOG_LOGIC("floor: " << n);
287  return n;
288 }
289 
290 bool
291 Building::IsIntersect(const Vector& l1, const Vector& l2) const
292 {
293  return m_buildingBounds.IsIntersect(l1, l2);
294 }
295 
296 } // 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
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:118
uint32_t GetId() const
Definition: building.cc:136
uint16_t GetNRoomsY() const
Definition: building.cc:216
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:198
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:150
uint16_t GetNFloors() const
Definition: building.cc:204
void SetBoundaries(Box box)
Set the boundaries of the building.
Definition: building.cc:143
BuildingType_t GetBuildingType() const
Definition: building.cc:192
void SetNRoomsX(uint16_t nroomx)
Definition: building.cc:171
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:291
uint16_t GetRoomY(Vector position) const
Definition: building.cc:249
void SetExtWallsType(Building::ExtWallsType_t t)
Definition: building.cc:157
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:130
void SetNRoomsY(uint16_t nroomy)
Definition: building.cc:178
Box GetBoundaries() const
Definition: building.cc:185
uint16_t m_roomsX
X Room coordinate.
Definition: building.h:229
~Building() override
Destructor.
Definition: building.cc:124
uint16_t GetFloor(Vector position) const
Definition: building.cc:270
uint16_t GetNRoomsX() const
Definition: building.cc:210
uint16_t m_roomsY
Y Room coordinate.
Definition: building.h:230
bool IsInside(Vector position) const
Definition: building.cc:222
void SetNFloors(uint16_t nfloors)
Definition: building.cc:164
Box m_buildingBounds
Building boundaries.
Definition: building.h:222
uint16_t GetRoomX(Vector position) const
Definition: building.cc:228
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:62
A base class which provides memory management and object aggregation.
Definition: object.h:89
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
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
#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(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:194
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46