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  .AddAttribute ("NRoomsX", "The number of rooms in the X axis.",
45  UintegerValue (1),
47  MakeUintegerChecker<uint32_t> ())
48  .AddAttribute ("NRoomsY", "The number of rooms in the Y axis.",
49  UintegerValue (1),
51  MakeUintegerChecker<uint32_t> ())
52  .AddAttribute ("NFloors", "The number of floors of this building.",
53  UintegerValue (1),
55  MakeUintegerChecker<uint32_t> ())
56  .AddAttribute ("Id", "The id (unique integer) of this Building.",
57  UintegerValue (0),
59  MakeUintegerChecker<uint32_t> ())
60  .AddAttribute ("Boundaries", "The boundaries of this Building as a value of type ns3::Box",
61  BoxValue (Box ()),
63  MakeBoxChecker ())
64  .AddAttribute ("Type",
65  "The type of building",
68  MakeEnumChecker (Building::Residential, "Residential",
69  Building::Office, "Office",
70  Building::Commercial, "Commercial"))
71  .AddAttribute ("ExternalWallsType",
72  "The type of material of which the external walls are made",
76  Building::ConcreteWithWindows, "ConcreteWithWindows",
77  Building::ConcreteWithoutWindows, "ConcreteWithoutWindows",
78  Building::StoneBlocks, "StoneBlocks"))
79  ;
80  return tid;
81 }
82 
83 Building::Building (double xMin,
84  double xMax,
85  double yMin,
86  double yMax,
87  double zMin,
88  double zMax)
89 {
90  NS_FATAL_ERROR (std::endl << "this function is not supported any more:" << std::endl
91  << " Building::Building (double xMin, double xMax, double yMin, " << std::endl
92  << " double yMax, double zMin, double zMax)\n" << std::endl
93  << "so you can't do any more stuff like:" << std::endl
94  << "Ptr<Building> b = CreateObject<Building> ("
95  << xMin << ", "
96  << xMax << ", "
97  << yMin << ", "
98  << yMax << ", "
99  << zMin << ", "
100  << zMax << ")\n" << std::endl
101  << "Please use instead something like this:" << std::endl
102  << " Ptr<Building> b = CreateObject<Building> ();" << std::endl
103  << " b->SetBoundaries (Box ("
104  << xMin << ", "
105  << xMax << ", "
106  << yMin << ", "
107  << yMax << ", "
108  << zMin << ", "
109  << zMax << "));" << std::endl <<std::endl);
110 }
111 
112 
114 {
115  NS_LOG_FUNCTION (this);
117 }
118 
120 {
121  NS_LOG_FUNCTION (this);
122 }
123 
124 void
126 {
127  NS_LOG_FUNCTION (this);
128 }
129 
130 uint32_t
131 Building::GetId (void) const
132 {
133  NS_LOG_FUNCTION (this);
134  return m_buildingId;
135 }
136 
137 void
139 {
140  NS_LOG_FUNCTION (this << boundaries);
141  m_buildingBounds = boundaries;
142 }
143 
144 void
146 {
147  NS_LOG_FUNCTION (this << t);
148  m_buildingType = t;
149 }
150 
151 void
153 {
154  NS_LOG_FUNCTION (this << t);
155  m_externalWalls = t;
156 }
157 
158 void
159 Building::SetNFloors (uint16_t nfloors)
160 {
161  NS_LOG_FUNCTION (this << nfloors);
162  m_floors = nfloors;
163 }
164 
165 void
166 Building::SetNRoomsX (uint16_t nroomx)
167 {
168  NS_LOG_FUNCTION (this << nroomx);
169  m_roomsX = nroomx;
170 }
171 
172 void
173 Building::SetNRoomsY (uint16_t nroomy)
174 {
175  NS_LOG_FUNCTION (this << nroomy);
176  m_roomsY = nroomy;
177 }
178 
179 Box
181 {
182  NS_LOG_FUNCTION (this);
183  return m_buildingBounds;
184 }
185 
188 {
189  return (m_buildingType);
190 }
191 
194 {
195  return (m_externalWalls);
196 }
197 
198 uint16_t
200 {
201  return (m_floors);
202 }
203 
204 uint16_t
206 {
207  return (m_roomsX);
208 }
209 
210 uint16_t
212 {
213  return (m_roomsY);
214 }
215 
216 bool
217 Building::IsInside (Vector position) const
218 {
219  return m_buildingBounds.IsInside (position);
220 }
221 
222 
223 uint16_t
224 Building::GetRoomX (Vector position) const
225 {
226  NS_ASSERT (IsInside (position));
227  uint16_t n;
228 
229  if (position.x == m_buildingBounds.xMax)
230  {
231  n = m_roomsX;
232  }
233  else
234  {
235  double xLength = m_buildingBounds.xMax - m_buildingBounds.xMin;
236  double x = position.x - m_buildingBounds.xMin;
237  n = floor (m_roomsX * x/xLength) + 1;
238  NS_LOG_LOGIC ("xLength=" << xLength << ", x=" << x << ", m_roomsX=" << m_roomsX);
239  }
240  NS_LOG_LOGIC ("RoomX: " << n);
241  return n;
242 }
243 
244 uint16_t
245 Building::GetRoomY (Vector position) const
246 {
247  NS_ASSERT (IsInside (position));
248  uint16_t n;
249 
250  if (position.y == m_buildingBounds.yMax)
251  {
252  n = m_roomsY;
253  }
254  else
255  {
256  double yLength = m_buildingBounds.yMax - m_buildingBounds.yMin;
257  double y = position.y - m_buildingBounds.yMin;
258  n = floor (m_roomsY * y/yLength) + 1;
259  NS_LOG_LOGIC ("yLength=" << yLength << ", y=" << y << ", m_roomsY=" << m_roomsY);
260  }
261  NS_LOG_LOGIC ("RoomY: " << n);
262  return n;
263 }
264 
265 uint16_t
266 Building::GetFloor (Vector position) const
267 {
268  NS_ASSERT (IsInside (position));
269  uint16_t n;
270 
271  if (position.z == m_buildingBounds.zMax)
272  {
273  n = m_floors;
274  }
275  else
276  {
277  double zLength = m_buildingBounds.zMax - m_buildingBounds.zMin;
278  double z = position.z - m_buildingBounds.zMin;
279  n = floor (m_floors * z/zLength) + 1;
280  NS_LOG_LOGIC ("zLength=" << zLength << ", z=" << z << ", m_floors=" << m_floors);
281  }
282  NS_LOG_LOGIC ("floor: " << n);
283  return n;
284 }
285 
286 
287 } // namespace ns3
uint16_t GetNFloors() const
Definition: building.cc:199
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
double zMin
The z coordinate of the down bound of the box.
Definition: box.h:101
void SetNRoomsY(uint16_t nroomy)
Definition: building.cc:173
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
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:209
ExtWallsType_t GetExtWallsType() const
Definition: building.cc:193
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
uint16_t m_roomsY
Definition: building.h:217
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint16_t GetRoomY(Vector position) const
Definition: building.cc:245
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
double xMax
The x coordinate of the right bound of the box.
Definition: box.h:95
bool IsInside(Vector position) const
Definition: building.cc:217
uint16_t m_floors
number of floors, must be greater than 0, and 1 means only one floor (i.e., groundfloor) ...
Definition: building.h:215
a 3d box
Definition: box.h:34
virtual void DoDispose()
Destructor implementation.
Definition: building.cc:125
double yMax
The y coordinate of the top bound of the box.
Definition: box.h:99
Hold variables of type enum.
Definition: enum.h:54
uint32_t m_buildingId
Definition: building.h:219
uint16_t GetNRoomsX() const
Definition: building.cc:205
BuildingType_t m_buildingType
Definition: building.h:220
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetNFloors(uint16_t nfloors)
Definition: building.cc:159
Ptr< const AttributeChecker > MakeBoxChecker(void)
Definition: box.cc:146
AttributeValue implementation for Box.
Definition: box.h:109
double yMin
The y coordinate of the bottom bound of the box.
Definition: box.h:97
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
void SetExtWallsType(Building::ExtWallsType_t t)
Definition: building.cc:152
static TypeId GetTypeId(void)
Definition: building.cc:39
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:109
Box m_buildingBounds
Definition: building.h:209
uint16_t m_roomsX
Definition: building.h:216
double zMax
The z coordinate of the up bound of the box.
Definition: box.h:103
ExtWallsType_t m_externalWalls
Definition: building.h:221
static uint32_t Add(Ptr< Building > building)
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
uint16_t GetRoomX(Vector position) const
Definition: building.cc:224
Box GetBoundaries() const
Definition: building.cc:180
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:113
uint16_t GetNRoomsY() const
Definition: building.cc:211
void SetNRoomsX(uint16_t nroomx)
Definition: building.cc:166
virtual ~Building()
Destructor.
Definition: building.cc:119
A base class which provides memory management and object aggregation.
Definition: object.h:87
uint32_t GetId(void) const
Definition: building.cc:131
uint16_t GetFloor(Vector position) const
Definition: building.cc:266
bool IsInside(const Vector &position) const
Definition: box.cc:54
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
a unique identifier for an interface.
Definition: type-id.h:51
void SetBoundaries(Box box)
Set the boundaries of the building.
Definition: building.cc:138
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
double xMin
The x coordinate of the left bound of the box.
Definition: box.h:93
BuildingType_t GetBuildingType() const
Definition: building.cc:187
void SetBuildingType(Building::BuildingType_t t)
Definition: building.cc:145