A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("Building");
33 
34 namespace ns3 {
35 
36 
38  ;
39 
40 TypeId
42 {
43  static TypeId tid = TypeId ("ns3::Building")
44  .SetParent<Object> ()
45  .AddConstructor<Building> ()
46  .AddAttribute ("NRoomsX", "The number of rooms in the X axis.",
47  UintegerValue (1),
48  MakeUintegerAccessor (&Building::GetNRoomsX, &Building::SetNRoomsX),
49  MakeUintegerChecker<uint32_t> ())
50  .AddAttribute ("NRoomsY", "The number of rooms in the Y axis.",
51  UintegerValue (1),
52  MakeUintegerAccessor (&Building::GetNRoomsY, &Building::SetNRoomsY),
53  MakeUintegerChecker<uint32_t> ())
54  .AddAttribute ("NFloors", "The number of floors of this building.",
55  UintegerValue (1),
56  MakeUintegerAccessor (&Building::GetNFloors, &Building::SetNFloors),
57  MakeUintegerChecker<uint32_t> ())
58  .AddAttribute ("Id", "The id (unique integer) of this Building.",
59  UintegerValue (0),
60  MakeUintegerAccessor (&Building::GetId),
61  MakeUintegerChecker<uint32_t> ())
62  .AddAttribute ("Boundaries", "The boundaries of this Building as a value of type ns3::Box",
63  BoxValue (Box ()),
65  MakeBoxChecker ())
66  .AddAttribute ("Type",
67  "The type of building",
70  MakeEnumChecker (Building::Residential, "Residential",
71  Building::Office, "Office",
72  Building::Commercial, "Commercial"))
73  .AddAttribute ("ExternalWallsType",
74  "The type of material of which the external walls are made",
78  Building::ConcreteWithWindows, "ConcreteWithWindows",
79  Building::ConcreteWithoutWindows, "ConcreteWithoutWindows",
80  Building::StoneBlocks, "StoneBlocks"))
81  ;
82  return tid;
83 }
84 
85 Building::Building (double xMin,
86  double xMax,
87  double yMin,
88  double yMax,
89  double zMin,
90  double zMax)
91 {
92  NS_FATAL_ERROR (std::endl << "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" << std::endl
95  << "so you can't do any more stuff like:" << std::endl
96  << "Ptr<Building> b = CreateObject<Building> ("
97  << xMin << ", "
98  << xMax << ", "
99  << yMin << ", "
100  << yMax << ", "
101  << zMin << ", "
102  << zMax << ")\n" << std::endl
103  << "Please use instead something like this:" << std::endl
104  << " Ptr<Building> b = CreateObject<Building> ();" << std::endl
105  << " b->SetBoundaries (Box ("
106  << xMin << ", "
107  << xMax << ", "
108  << yMin << ", "
109  << yMax << ", "
110  << zMin << ", "
111  << zMax << "));" << std::endl <<std::endl);
112 }
113 
114 
116 {
117  NS_LOG_FUNCTION (this);
119 }
120 
122 {
123  NS_LOG_FUNCTION (this);
124 }
125 
126 void
128 {
129  NS_LOG_FUNCTION (this);
130 }
131 
132 uint32_t
133 Building::GetId (void) const
134 {
135  NS_LOG_FUNCTION (this);
136  return m_buildingId;
137 }
138 
139 void
141 {
142  NS_LOG_FUNCTION (this << boundaries);
143  m_buildingBounds = boundaries;
144 }
145 
146 void
148 {
149  NS_LOG_FUNCTION (this << t);
150  m_buildingType = t;
151 }
152 
153 void
155 {
156  NS_LOG_FUNCTION (this << t);
157  m_externalWalls = t;
158 }
159 
160 void
161 Building::SetNFloors (uint16_t nfloors)
162 {
163  NS_LOG_FUNCTION (this << nfloors);
164  m_floors = nfloors;
165 }
166 
167 void
168 Building::SetNRoomsX (uint16_t nroomx)
169 {
170  NS_LOG_FUNCTION (this << nroomx);
171  m_roomsX = nroomx;
172 }
173 
174 void
175 Building::SetNRoomsY (uint16_t nroomy)
176 {
177  NS_LOG_FUNCTION (this << nroomy);
178  m_roomsY = nroomy;
179 }
180 
181 Box
183 {
184  NS_LOG_FUNCTION (this);
185  return m_buildingBounds;
186 }
187 
190 {
191  return (m_buildingType);
192 }
193 
196 {
197  return (m_externalWalls);
198 }
199 
200 uint16_t
202 {
203  return (m_floors);
204 }
205 
206 uint16_t
208 {
209  return (m_roomsX);
210 }
211 
212 uint16_t
214 {
215  return (m_roomsY);
216 }
217 
218 bool
219 Building::IsInside (Vector position) const
220 {
221  return m_buildingBounds.IsInside (position);
222 }
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 
289 } // namespace ns3
uint16_t GetNFloors() const
Definition: building.cc:201
double x
x coordinate of vector
Definition: vector.h:49
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
double zMin
Definition: box.h:97
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)
Definition: enum.cc:178
void SetNRoomsY(uint16_t nroomy)
Definition: building.cc:175
ExtWallsType_t GetExtWallsType() const
Definition: building.cc:195
#define NS_ASSERT(condition)
Definition: assert.h:64
uint16_t m_roomsY
Definition: building.h:217
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
uint16_t GetRoomY(Vector position) const
Definition: building.cc:247
double xMax
Definition: box.h:91
bool IsInside(Vector position) const
Definition: building.cc:219
a 3d vector
Definition: vector.h:31
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
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:33
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: building.cc:127
double yMax
Definition: box.h:95
hold variables of type 'enum'
Definition: enum.h:37
uint32_t m_buildingId
Definition: building.h:219
NS_LOG_COMPONENT_DEFINE("Building")
uint16_t GetNRoomsX() const
Definition: building.cc:207
BuildingType_t m_buildingType
Definition: building.h:220
Hold an unsigned integer type.
Definition: uinteger.h:46
void SetNFloors(uint16_t nfloors)
Definition: building.cc:161
hold objects of type ns3::Box
double yMin
Definition: box.h:93
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
void SetExtWallsType(Building::ExtWallsType_t t)
Definition: building.cc:154
static TypeId GetTypeId(void)
Definition: building.cc:41
Box m_buildingBounds
Definition: building.h:209
uint16_t m_roomsX
Definition: building.h:216
double y
y coordinate of vector
Definition: vector.h:53
double zMax
Definition: box.h:99
ExtWallsType_t m_externalWalls
Definition: building.h:221
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition: enum.h:118
static uint32_t Add(Ptr< Building > building)
uint16_t GetRoomX(Vector position) const
Definition: building.cc:226
Box GetBoundaries() const
Definition: building.cc:182
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:115
uint16_t GetNRoomsY() const
Definition: building.cc:213
void SetNRoomsX(uint16_t nroomx)
Definition: building.cc:168
virtual ~Building()
Destructor.
Definition: building.cc:121
a base class which provides memory management and object aggregation
Definition: object.h:63
uint32_t GetId(void) const
Definition: building.cc:133
uint16_t GetFloor(Vector position) const
Definition: building.cc:268
bool IsInside(const Vector &position) const
Definition: box.cc:54
a unique identifier for an interface.
Definition: type-id.h:49
void SetBoundaries(Box box)
Set the boundaries of the building.
Definition: building.cc:140
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
double xMin
Definition: box.h:89
double z
z coordinate of vector
Definition: vector.h:57
BuildingType_t GetBuildingType() const
Definition: building.cc:189
void SetBuildingType(Building::BuildingType_t t)
Definition: building.cc:147