A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
buildings-helper.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 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  * Author: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 #include "buildings-helper.h"
22 
23 #include <ns3/node-list.h>
24 #include <ns3/building.h>
25 #include <ns3/building-list.h>
26 #include <ns3/mobility-model.h>
27 #include <ns3/buildings-mobility-model.h>
28 #include <ns3/abort.h>
29 #include <ns3/log.h>
30 
31 
32 NS_LOG_COMPONENT_DEFINE ("BuildingsHelper");
33 
34 namespace ns3 {
35 
36 void
37 BuildingsHelper::MakeMobilityModelConsistent ()
38 {
40  for (NodeList::Iterator nit = NodeList::Begin (); nit != NodeList::End (); ++nit)
41  {
42  Ptr<MobilityModel> mm = (*nit)->GetObject<MobilityModel> ();
43  if (mm != 0)
44  {
45  Ptr<BuildingsMobilityModel> bmm = DynamicCast<BuildingsMobilityModel> (mm);
46  NS_ABORT_MSG_UNLESS (0 != bmm, "node " << (*nit)->GetId () << " has a MobilityModel but it is not a BuildingsMobilityModel");
47  MakeConsistent (bmm);
48  }
49  }
50 }
51 
52 
53 void
54 BuildingsHelper::MakeConsistent (Ptr<BuildingsMobilityModel> bmm)
55 {
56  bool found = false;
57  for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit)
58  {
59  NS_LOG_LOGIC ("checking building " << (*bit)->GetId () << " with boundaries " << (*bit)->GetBoundaries ());
60  Vector pos = bmm->GetPosition ();
61  if ((*bit)->IsInside (pos))
62  {
63  NS_LOG_LOGIC ("BuildingsMobilityModel " << bmm << " pos " << bmm->GetPosition () << " falls inside building " << (*bit)->GetId ());
64  NS_ABORT_MSG_UNLESS (found == false, " BuildingsMobilityModel already inside another building!");
65  found = true;
66  uint16_t floor = (*bit)->GetFloor (pos);
67  uint16_t roomX = (*bit)->GetRoomX (pos);
68  uint16_t roomY = (*bit)->GetRoomY (pos);
69  bmm->SetIndoor (*bit, floor, roomX, roomY);
70  }
71  }
72  if (!found)
73  {
74  NS_LOG_LOGIC ("BuildingsMobilityModel " << bmm << " pos " << bmm->GetPosition () << " is outdoor");
75  bmm->SetOutdoor ();
76  }
77 
78 }
79 
80 } // namespace ns3
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
static Iterator End(void)
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
static Iterator Begin(void)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
Definition: abort.h:131
static Iterator End(void)
Definition: node-list.cc:186
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
static Iterator Begin(void)
Definition: node-list.cc:180