--- a/src/buildings/helper/building-allocator.cc Tue Mar 20 18:02:56 2012 +0100
+++ b/src/buildings/helper/building-allocator.cc Tue Mar 20 18:33:42 2012 +0100
@@ -190,7 +190,9 @@
}
double bxmax = bxmin + m_lengthX;
double bymax = bymin + m_lengthY;
- BoxValue boxValue (Box (bxmin, bxmax, bymin, bymax, 0, m_height));
+ Box box (bxmin, bxmax, bymin, bymax, 0, m_height);
+ NS_LOG_LOGIC ("new building : " << box);
+ BoxValue boxValue (box);
m_buildingFactory.Set ("Boundaries", boxValue);
Ptr<Building> b = m_buildingFactory.Create<Building> ();
//b->SetAttribute ("Boundaries", boxValue);
--- a/src/buildings/helper/building-position-allocator.cc Tue Mar 20 18:02:56 2012 +0100
+++ b/src/buildings/helper/building-position-allocator.cc Tue Mar 20 18:33:42 2012 +0100
@@ -18,6 +18,7 @@
* Author: Nicola Baldo <nbaldo@cttc.es>
*/
#include "building-position-allocator.h"
+#include "ns3/buildings-mobility-model.h"
#include "ns3/random-variable.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
@@ -177,4 +178,77 @@
+
+
+NS_OBJECT_ENSURE_REGISTERED (SameRoomPositionAllocator);
+
+SameRoomPositionAllocator::SameRoomPositionAllocator ()
+{
+ NS_FATAL_ERROR (" Constructor \"SameRoomPositionAllocator ()\" should not be used");
+}
+
+
+SameRoomPositionAllocator::SameRoomPositionAllocator (NodeContainer c)
+ : m_nodes (c),
+ m_nodeIt (c.Begin ())
+{
+}
+
+TypeId
+SameRoomPositionAllocator::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::SameRoomPositionAllocator")
+ .SetParent<PositionAllocator> ()
+ .SetGroupName ("Mobility")
+ .AddConstructor<SameRoomPositionAllocator> ();
+ return tid;
+}
+
+Vector
+SameRoomPositionAllocator::GetNext () const
+{
+ NS_LOG_FUNCTION (this);
+ UniformVariable rand;
+ if (m_nodeIt == m_nodes.End ())
+ {
+ m_nodeIt = m_nodes.Begin ();
+ }
+
+ NS_ASSERT_MSG (m_nodeIt != m_nodes.End (), "no node in container");
+
+ Ptr<BuildingsMobilityModel> bmm = (*m_nodeIt)->GetObject<BuildingsMobilityModel> ();
+ uint32_t roomx = bmm->GetRoomNumberX ();
+ uint32_t roomy = bmm->GetRoomNumberY ();
+ uint32_t floor = bmm->GetFloorNumber ();
+ NS_LOG_LOGIC ("considering room (" << roomx << ", " << roomy << ", " << floor << ")");
+
+ Ptr<Building> b = bmm->GetBuilding ();
+ Ptr<RandomBoxPositionAllocator> pa = CreateObject<RandomBoxPositionAllocator> ();
+ UniformVariable v;
+ BoxValue bv;
+ b->GetAttribute ("Boundaries", bv);
+ Box box = bv.Get ();
+ double rdx = (box.xMax - box.xMin) / b->GetNRoomsX ();
+ double rdy = (box.yMax - box.yMin) / b->GetNRoomsY ();
+ double rdz = (box.zMax - box.zMin) / b->GetNFloors ();
+ double x1 = box.xMin + rdx * roomx;
+ double x2 = box.xMin + rdx * (roomx + 1);
+ double y1 = box.yMin + rdy * roomy;
+ double y2 = box.yMin + rdy * (roomy + 1);
+ double z1 = box.zMin + rdz * floor;
+ double z2 = box.zMin + rdz * (floor + 1);
+ NS_LOG_LOGIC ("randomly allocating position in "
+ << " (" << x1 << "," << x2 << ") "
+ << "x (" << y1 << "," << y2 << ") "
+ << "x (" << z1 << "," << z2 << ") ");
+
+ double x = v.GetValue (x1, x2);
+ double y = v.GetValue (y1, y2);
+ double z = v.GetValue (z1, z2);
+
+ return Vector (x, y, z);
+}
+
+
+
} // namespace ns3
--- a/src/buildings/helper/building-position-allocator.h Tue Mar 20 18:02:56 2012 +0100
+++ b/src/buildings/helper/building-position-allocator.h Tue Mar 20 18:33:42 2012 +0100
@@ -22,6 +22,7 @@
#include <ns3/ptr.h>
#include <ns3/position-allocator.h>
+#include <ns3/node-container.h>
namespace ns3 {
@@ -82,6 +83,29 @@
};
+/**
+ * Walks a given NodeContainer sequentially, and for each node allocate a new
+ * position randomly in the same room of that node
+ *
+ */
+class SameRoomPositionAllocator : public PositionAllocator
+{
+public:
+ SameRoomPositionAllocator ();
+ SameRoomPositionAllocator (NodeContainer c);
+
+ // inherited from Object
+ static TypeId GetTypeId (void);
+
+ // inherited from PositionAllocator
+ virtual Vector GetNext (void) const;
+
+private:
+
+ NodeContainer m_nodes;
+ mutable NodeContainer::Iterator m_nodeIt;
+};
+
} // namespace ns3