diff --git a/samples/main-grid-topology.cc b/samples/main-grid-topology.cc index 41ca3c638..f2837d4cf 100644 --- a/samples/main-grid-topology.cc +++ b/samples/main-grid-topology.cc @@ -29,7 +29,7 @@ int main (int argc, char *argv[]) // finalize the setup by attaching to each object // in the input array a position and initializing // this position with the calculated coordinates. - grid.Create (nodes); + grid.ArrangeHorizontally (nodes); // iterate our nodes and print their position. diff --git a/src/node/grid-topology.cc b/src/node/grid-topology.cc index 3e809e324..d4e637f95 100644 --- a/src/node/grid-topology.cc +++ b/src/node/grid-topology.cc @@ -23,10 +23,10 @@ namespace ns3 { -GridTopology::GridTopology (double xMin, double yMin, uint32_t nCols, double deltaX, double deltaY) +GridTopology::GridTopology (double xMin, double yMin, uint32_t n, double deltaX, double deltaY) : m_xMin (xMin), m_yMin (yMin), - m_nCols (nCols), + m_n (n), m_deltaX (deltaX), m_deltaY (deltaY), m_positionClassId (StaticPosition::cid) @@ -39,7 +39,7 @@ GridTopology::SetPositionModel (ClassId classId) } void -GridTopology::Create (std::vector > objects) +GridTopology::ArrangeHorizontally (std::vector > objects) { double x, y; uint32_t col; @@ -53,7 +53,7 @@ GridTopology::Create (std::vector > objects) object->AddInterface (ComponentManager::Create (m_positionClassId, x, y)); x += m_deltaX; col++; - if (col == m_nCols) + if (col == m_n) { col = 0; x = m_xMin; @@ -62,4 +62,28 @@ GridTopology::Create (std::vector > objects) } } +void +GridTopology::ArrangeVertically (std::vector > objects) +{ + double x, y; + uint32_t row; + x = m_xMin; + y = m_yMin; + row = 0; + for (std::vector >::const_iterator i = objects.begin (); + i != objects.end (); i++) + { + Ptr object = *i; + object->AddInterface (ComponentManager::Create (m_positionClassId, x, y)); + y += m_deltaY; + row++; + if (row == m_n) + { + row = 0; + y = m_yMin; + x += m_deltaX; + } + } +} + } // namespace ns3 diff --git a/src/node/grid-topology.h b/src/node/grid-topology.h index 2ff50031b..822024038 100644 --- a/src/node/grid-topology.h +++ b/src/node/grid-topology.h @@ -36,7 +36,7 @@ class GridTopology /** * \param xMin the left boundary where the objects will start being arranged. * \param yMin the lower boundary where the objects will start being arranged. - * \param nCols number of objects for each row + * \param n number of objects for each row or column * \param deltaX distance separating two adjacent objects along the x axis. * \param deltaY distance separating two adjacent objects along the y axis. * @@ -56,14 +56,26 @@ class GridTopology * Attach a position (the type of position is specified through * the ClassId given to SetPositionModel) to each object present * in the input vector and configure its initial location with a set - * of coordinates arranged according to a regular rectangular grid. + * of coordinates arranged according to a regular rectangular grid, + * one row after the other. */ - void Create (std::vector > objects); + void ArrangeHorizontally (std::vector > objects); + + /** + * \param objects a vector of objects + * + * Attach a position (the type of position is specified through + * the ClassId given to SetPositionModel) to each object present + * in the input vector and configure its initial location with a set + * of coordinates arranged according to a regular rectangular grid, + * one column after the other. + */ + void ArrangeVertically (std::vector > objects); private: GridTopology (); double m_xMin; double m_yMin; - uint32_t m_nCols; + uint32_t m_n; double m_deltaX; double m_deltaY; ClassId m_positionClassId;