| ... | ... |
@@ -436,97 +436,97 @@ |
| 436 | 436 |
(n._id / _width) * (_width - 1) - 1) << 1); |
| 437 | 437 |
} else {
|
| 438 | 438 |
return INVALID; |
| 439 | 439 |
} |
| 440 | 440 |
} |
| 441 | 441 |
|
| 442 | 442 |
Arc up(Node n) const {
|
| 443 | 443 |
if (n._id < _edge_limit) {
|
| 444 | 444 |
return Arc((n._id << 1) | 1); |
| 445 | 445 |
} else {
|
| 446 | 446 |
return INVALID; |
| 447 | 447 |
} |
| 448 | 448 |
} |
| 449 | 449 |
|
| 450 | 450 |
Arc down(Node n) const {
|
| 451 | 451 |
if (n._id >= _width) {
|
| 452 | 452 |
return Arc((n._id - _width) << 1); |
| 453 | 453 |
} else {
|
| 454 | 454 |
return INVALID; |
| 455 | 455 |
} |
| 456 | 456 |
} |
| 457 | 457 |
|
| 458 | 458 |
private: |
| 459 | 459 |
int _width, _height; |
| 460 | 460 |
int _node_num, _edge_num; |
| 461 | 461 |
int _edge_limit; |
| 462 | 462 |
}; |
| 463 | 463 |
|
| 464 | 464 |
|
| 465 | 465 |
typedef GraphExtender<GridGraphBase> ExtendedGridGraphBase; |
| 466 | 466 |
|
| 467 | 467 |
/// \ingroup graphs |
| 468 | 468 |
/// |
| 469 | 469 |
/// \brief Grid graph class |
| 470 | 470 |
/// |
| 471 | 471 |
/// This class implements a special graph type. The nodes of the |
| 472 | 472 |
/// graph can be indexed by two integer \c (i,j) value where \c i is |
| 473 | 473 |
/// in the \c [0..width()-1] range and j is in the \c |
| 474 | 474 |
/// [0..height()-1] range. Two nodes are connected in the graph if |
| 475 | 475 |
/// the indexes differ exactly on one position and exactly one is |
| 476 | 476 |
/// the difference. The nodes of the graph can be indexed by position |
| 477 | 477 |
/// with the \c operator()() function. The positions of the nodes can be |
| 478 | 478 |
/// get with \c pos(), \c col() and \c row() members. The outgoing |
| 479 | 479 |
/// arcs can be retrieved with the \c right(), \c up(), \c left() |
| 480 | 480 |
/// and \c down() functions, where the bottom-left corner is the |
| 481 | 481 |
/// origin. |
| 482 | 482 |
/// |
| 483 | 483 |
/// \image html grid_graph.png |
| 484 |
/// \image latex grid_graph.eps "Grid graph" |
|
| 484 |
/// \image latex grid_graph.eps "Grid graph" width=\textwidth |
|
| 485 | 485 |
/// |
| 486 | 486 |
/// A short example about the basic usage: |
| 487 | 487 |
///\code |
| 488 | 488 |
/// GridGraph graph(rows, cols); |
| 489 | 489 |
/// GridGraph::NodeMap<int> val(graph); |
| 490 | 490 |
/// for (int i = 0; i < graph.width(); ++i) {
|
| 491 | 491 |
/// for (int j = 0; j < graph.height(); ++j) {
|
| 492 | 492 |
/// val[graph(i, j)] = i + j; |
| 493 | 493 |
/// } |
| 494 | 494 |
/// } |
| 495 | 495 |
///\endcode |
| 496 | 496 |
/// |
| 497 | 497 |
/// This graph type is fully conform to the \ref concepts::Graph |
| 498 | 498 |
/// "Graph" concept, and it also has an important extra feature |
| 499 | 499 |
/// that its maps are real \ref concepts::ReferenceMap |
| 500 | 500 |
/// "reference map"s. |
| 501 | 501 |
class GridGraph : public ExtendedGridGraphBase {
|
| 502 | 502 |
public: |
| 503 | 503 |
|
| 504 | 504 |
typedef ExtendedGridGraphBase Parent; |
| 505 | 505 |
|
| 506 | 506 |
/// \brief Map to get the indices of the nodes as dim2::Point<int>. |
| 507 | 507 |
/// |
| 508 | 508 |
/// Map to get the indices of the nodes as dim2::Point<int>. |
| 509 | 509 |
class IndexMap {
|
| 510 | 510 |
public: |
| 511 | 511 |
/// \brief The key type of the map |
| 512 | 512 |
typedef GridGraph::Node Key; |
| 513 | 513 |
/// \brief The value type of the map |
| 514 | 514 |
typedef dim2::Point<int> Value; |
| 515 | 515 |
|
| 516 | 516 |
/// \brief Constructor |
| 517 | 517 |
/// |
| 518 | 518 |
/// Constructor |
| 519 | 519 |
IndexMap(const GridGraph& graph) : _graph(graph) {}
|
| 520 | 520 |
|
| 521 | 521 |
/// \brief The subscript operator |
| 522 | 522 |
/// |
| 523 | 523 |
/// The subscript operator. |
| 524 | 524 |
Value operator[](Key key) const {
|
| 525 | 525 |
return _graph.pos(key); |
| 526 | 526 |
} |
| 527 | 527 |
|
| 528 | 528 |
private: |
| 529 | 529 |
const GridGraph& _graph; |
| 530 | 530 |
}; |
| 531 | 531 |
|
| 532 | 532 |
/// \brief Map to get the column of the nodes. |
0 comments (0 inline)