From 3105bb5417106c4332d837d59659b6e296a561b1 Mon Sep 17 00:00:00 2001 From: Oliver Gloth Date: Wed, 22 Aug 2012 20:18:03 +0200 Subject: [PATCH] iterate through all nodes of a graph respecting recursions ... --- src/libengrid/checkerboardgraphiterator.h | 94 +++++++++++++++++++++++++++++++ src/libengrid/globalnodegraphinterface.h | 48 ++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 src/libengrid/checkerboardgraphiterator.h create mode 100644 src/libengrid/globalnodegraphinterface.h diff --git a/src/libengrid/checkerboardgraphiterator.h b/src/libengrid/checkerboardgraphiterator.h new file mode 100644 index 0000000..25b7d9f --- /dev/null +++ b/src/libengrid/checkerboardgraphiterator.h @@ -0,0 +1,94 @@ +// +// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// + + +// + This file is part of enGrid. + +// + + +// + Copyright 2008-2012 enGits GmbH + +// + + +// + enGrid is free software: you can redistribute it and/or modify + +// + it under the terms of the GNU General Public License as published by + +// + the Free Software Foundation, either version 3 of the License, or + +// + (at your option) any later version. + +// + + +// + enGrid is distributed in the hope that it will be useful, + +// + but WITHOUT ANY WARRANTY; without even the implied warranty of + +// + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + +// + GNU General Public License for more details. + +// + + +// + You should have received a copy of the GNU General Public License + +// + along with enGrid. If not, see . + +// + + +// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// + +#ifndef CHECKERBOARDGRAPHITERATOR_H +#define CHECKERBOARDGRAPHITERATOR_H + +#include + +using namespace std; + +template +class CheckerBoardGraphIterator +{ + + typedef typename TGraph::index_type index_t; + + TGraph* m_Graph; + index_t m_CurrentIndex; + index_t m_DoneCount; + vector m_Available; + vector m_Done; + +public: + + CheckerBoardGraphIterator() { m_Graph = NULL; } + CheckerBoardGraphIterator(TGraph* graph) { m_Graph = graph; } + void setGraph(TGraph* graph) { m_Graph = graph; } + virtual void update() = 0; + void operator=(index_t i); + bool operator==(index_t i) { return m_CurrentIndex == i; } + index_t operator++(); + index_t operator*() { return m_CurrentIndex; } + +}; + +template +void CheckerBoardGraphIterator::operator=(index_t i) +{ + m_CurrentIndex = i; + m_Available.resize(m_Graph->size(), true); + m_Done.resize(m_Graph->size(), false); + m_DoneCount = 0; + update(); +} + +template +typename CheckerBoardGraphIterator::index_t CheckerBoardGraphIterator::operator++() +{ + if (m_Graph->size() > 0) { + m_Done[m_CurrentIndex] = true; + ++m_DoneCount; + for (int i = 0; i < m_Graph->getNumLinks(m_CurrentIndex); ++i) { + m_Available[m_Graph->getLink(m_CurrentIndex,i)] = false; + } + do { + ++m_CurrentIndex; + if (m_CurrentIndex >= m_Graph->size()) { + if (m_DoneCount == m_Graph->size()) { + break; + } + for (size_t i = 0; i < m_Available.size(); ++i) { + m_Available[i] = !m_Done[i]; + } + m_CurrentIndex = 0; + update(); + } + } while (!m_Available[m_CurrentIndex]); + } + return m_CurrentIndex; +} + + + +#endif // CHECKERBOARDGRAPHITERATOR_H diff --git a/src/libengrid/globalnodegraphinterface.h b/src/libengrid/globalnodegraphinterface.h new file mode 100644 index 0000000..9177539 --- /dev/null +++ b/src/libengrid/globalnodegraphinterface.h @@ -0,0 +1,48 @@ +// +// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// + + +// + This file is part of enGrid. + +// + + +// + Copyright 2008-2012 enGits GmbH + +// + + +// + enGrid is free software: you can redistribute it and/or modify + +// + it under the terms of the GNU General Public License as published by + +// + the Free Software Foundation, either version 3 of the License, or + +// + (at your option) any later version. + +// + + +// + enGrid is distributed in the hope that it will be useful, + +// + but WITHOUT ANY WARRANTY; without even the implied warranty of + +// + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + +// + GNU General Public License for more details. + +// + + +// + You should have received a copy of the GNU General Public License + +// + along with enGrid. If not, see . + +// + + +// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// + +#ifndef GLOBALNODEGRAPHINTERFACE_H +#define GLOBALNODEGRAPHINTERFACE_H + +#include "meshpartition.h" + +/** + * @brief An interface to run generic algorithms on the node graph of a grid. + */ +class GlobalNodeGraphInterface +{ + + MeshPartition* m_Part; + +public: + + typedef vtkIdType index_type; + + void setMeshPartition(MeshPartition* part) { m_Part = part; } + size_t size() { return m_Part->getGrid()->GetNumberOfPoints(); } + size_t getNumLinks(size_t i) { return m_Part->n2nGSize(i); } + size_t getLink(size_t i, size_t j) { return m_Part->n2nGG(i,j); } + +}; + +#endif // GLOBALNODEGRAPHINTERFACE_H -- 2.11.4.GIT