A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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 <math.h>
31
32
NS_LOG_COMPONENT_DEFINE
(
"Building"
);
33
34
namespace
ns3 {
35
36
37
NS_OBJECT_ENSURE_REGISTERED
(Building);
38
39
TypeId
40
Building::GetTypeId
(
void
)
41
{
42
static
TypeId
tid =
TypeId
(
"ns3::Building"
)
43
.
SetParent
<
Object
> ()
44
.AddConstructor<Building> ()
45
.AddAttribute (
"NRoomsX"
,
"The number of rooms in the X axis."
,
46
UintegerValue
(1),
47
MakeUintegerAccessor (&
Building::GetNRoomsX
, &
Building::SetNRoomsX
),
48
MakeUintegerChecker<uint32_t> ())
49
.AddAttribute (
"NRoomsY"
,
"The number of rooms in the Y axis."
,
50
UintegerValue
(1),
51
MakeUintegerAccessor (&
Building::GetNRoomsY
, &
Building::SetNRoomsY
),
52
MakeUintegerChecker<uint32_t> ())
53
.AddAttribute (
"NFloors"
,
"The number of floors of this building."
,
54
UintegerValue
(1),
55
MakeUintegerAccessor (&
Building::GetNFloors
, &
Building::SetNFloors
),
56
MakeUintegerChecker<uint32_t> ())
57
.AddAttribute (
"Id"
,
"The id (unique integer) of this Building."
,
58
UintegerValue
(0),
59
MakeUintegerAccessor (&
Building::GetId
),
60
MakeUintegerChecker<uint32_t> ())
61
.AddAttribute (
"Boundaries"
,
"The boundaries of this Building as a value of type ns3::Box"
,
62
BoxValue
(
Box
()),
63
MakeBoxAccessor (&
Building::GetBoundaries
, &
Building::SetBoundaries
),
64
MakeBoxChecker ())
65
.AddAttribute (
"Type"
,
66
"The type of building"
,
67
EnumValue
(
Building::Residential
),
68
MakeEnumAccessor
(&
Building::GetBuildingType
, &
Building::SetBuildingType
),
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"
,
74
EnumValue
(
Building::ConcreteWithWindows
),
75
MakeEnumAccessor
(&
Building::GetExtWallsType
, &
Building::SetExtWallsType
),
76
MakeEnumChecker
(
Building::Wood
,
"Wood"
,
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
114
Building::Building
()
115
{
116
NS_LOG_FUNCTION
(
this
);
117
m_buildingId
=
BuildingList::Add
(
this
);
118
}
119
120
Building::~Building
()
121
{
122
NS_LOG_FUNCTION
(
this
);
123
}
124
125
void
126
Building::DoDispose
()
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
139
Building::SetBoundaries
(
Box
boundaries)
140
{
141
NS_LOG_FUNCTION
(
this
<< boundaries);
142
m_buildingBounds
= boundaries;
143
}
144
145
void
146
Building::SetBuildingType
(
Building::BuildingType_t
t)
147
{
148
NS_LOG_FUNCTION
(
this
<< t);
149
m_buildingType
= t;
150
}
151
152
void
153
Building::SetExtWallsType
(
Building::ExtWallsType_t
t)
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
181
Building::GetBoundaries
()
const
182
{
183
NS_LOG_FUNCTION
(
this
);
184
return
m_buildingBounds
;
185
}
186
187
Building::BuildingType_t
188
Building::GetBuildingType
()
const
189
{
190
return
(
m_buildingType
);
191
}
192
193
Building::ExtWallsType_t
194
Building::GetExtWallsType
()
const
195
{
196
return
(
m_externalWalls
);
197
}
198
199
uint16_t
200
Building::GetNFloors
()
const
201
{
202
return
(
m_floors
);
203
}
204
205
uint16_t
206
Building::GetNRoomsX
()
const
207
{
208
return
(
m_roomsX
);
209
}
210
211
uint16_t
212
Building::GetNRoomsY
()
const
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
src
buildings
model
building.cc
Generated on Tue Oct 9 2012 16:45:33 for ns-3 by
1.8.1.2