COVISE Core
RainAlgorithm.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9// TEMPLATE FUNCTION
10//
11// RainAlgorithm classifies cells in a grid tagging each cell
12// with a number, in a such a way that regions separated by a border
13// will get a different tag, which is constant within one region.
14// These tags may be eventually used to generate a group of smaller
15// grids for the cells sharing a common tag.
16//
17// As you can see from the code, class Grid should define some
18// typedefs and the involved classes are expected to support some
19// interfaces.
20//
21// Initial version: 29.02.2004 Sergio Leseduarte
22// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23// (C) 2004 by VirCinity IT Consulting
24// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25// Changes: 24.3.2004, performance was enhanced
26
27#include "covise/covise.h"
28
29namespace covise
30{
31
32template <class Grid>
33void RainAlgorithm(const Grid &grid,
34 const typename Grid::Border &border,
35 std::vector<int> &tags)
36{
37 std::vector<int> local_tags(grid.CellSize(), -1);
38
39 int no_cells = grid.CellSize(); // get number of cells
40 int tag_label = 0;
41 int progress_size = no_cells / 100;
42 if (progress_size == 0)
43 progress_size = 1;
44
45 vector<int> unclassified_v(no_cells);
46 for (int i = 0; i < no_cells; ++i)
47 {
48 unclassified_v[i] = i;
49 }
50 std::set<int> unclassified(unclassified_v.begin(), unclassified_v.end());
51
52 while (!unclassified.empty())
53 {
54 int start = *(unclassified.begin());
55 local_tags[start] = tag_label;
56 unclassified.erase(unclassified.begin());
57 set<int> active;
58 active.insert(start);
59 while (!active.empty())
60 {
61 // look for unmarked neighbours
62 // of active within the domain
63 set<int>::iterator active_it = active.begin();
64 set<int>::iterator active_it_end = active.end();
65 set<int> new_active;
66 for (; active_it != active_it_end; ++active_it)
67 {
68 std::vector<int> neighbourLabels; // cells touched by this drop of rain
69 // get neighbour cells
70 typename Grid::NeighbourhoodContainer nc;
71 grid.GetEdgeNeighbours(*active_it, nc);
72 // filter out neighbours for which the common edge belongs to border
73 typename Grid::NeighbourhoodContainer::iterator ncit = nc.begin();
74 typename Grid::NeighbourhoodContainer::iterator ncend = nc.end();
75 for (; ncit != ncend; ++ncit)
76 {
77 // continue if neighbour was already marked
78 if (local_tags[ncit->CellLabel()] != -1)
79 {
80 continue;
81 }
82 // continue if neighbourhood crosses the border
83 if (border.IsIn((*ncit)))
84 {
85 continue;
86 }
87 // add to new_active
88 new_active.insert(ncit->CellLabel());
89 }
90 }
91 // update unclassified and local_tags
92 // using new_active -> active
93 new_active.swap(active);
94 active_it = active.begin();
95 active_it_end = active.end();
96 for (; active_it != active_it_end; ++active_it)
97 {
98 local_tags[*active_it] = tag_label;
99 unclassified.erase(*active_it);
100 }
101 }
102 ++tag_label;
103 }
104 local_tags.swap(tags);
105}
106}
GLuint start
Definition: khronos-glext.h:6343
list of all chemical elements
Definition: coConfig.h:27
void RainAlgorithm(const Grid &grid, const typename Grid::Border &border, std::vector< int > &tags)
Definition: RainAlgorithm.h:33
Definition: coCuttingSurface.h:52