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 
288 } // namespace ns3
#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:174
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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
uint16_t GetFloor(Vector position) const
Definition: building.cc:267
BuildingType_t GetBuildingType() const
Definition: building.cc:188
#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
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:202
uint16_t GetRoomY(Vector position) const
Definition: building.cc:246
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
double xMax
The x coordinate of the right bound of the box.
Definition: box.h:95
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:126
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
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:160
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
void SetExtWallsType(Building::ExtWallsType_t t)
Definition: building.cc:153
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
Box GetBoundaries() const
Definition: building.cc:181
double zMax
The z coordinate of the up bound of the box.
Definition: box.h:103
ExtWallsType_t m_externalWalls
Definition: building.h:221
uint16_t GetNRoomsY() const
Definition: building.cc:212
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
static uint32_t Add(Ptr< Building > building)
uint16_t GetRoomX(Vector position) const
Definition: building.cc:225
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 GetNFloors() const
Definition: building.cc:200
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
ExtWallsType_t GetExtWallsType() const
Definition: building.cc:194
void SetNRoomsX(uint16_t nroomx)
Definition: building.cc:167
virtual ~Building()
Destructor.
Definition: building.cc:120
A base class which provides memory management and object aggregation.
Definition: object.h:87
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:58
bool IsInside(const Vector &position) const
Definition: box.cc:54
void SetBoundaries(Box box)
Set the boundaries of the building.
Definition: building.cc:139
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
uint32_t GetId(void) const
Definition: building.cc:132
uint16_t GetNRoomsX() const
Definition: building.cc:206
double xMin
The x coordinate of the left bound of the box.
Definition: box.h:93
bool IsInside(Vector position) const
Definition: building.cc:218
void SetBuildingType(Building::BuildingType_t t)
Definition: building.cc:146