Bitmap.cpp
Go to the documentation of this file.
1 #include "Bitmap.h"
2 #include <iostream>
3 #include <fstream>
4 #include <sstream>
5 #include <iomanip>
6 #include "Grid.h"
7 #include <algorithm>
8 #include <GfxTL/VectorXD.h>
9 #include <MiscLib/Performance.h>
10 using namespace MiscLib;
12 
14  size_t uextent, size_t vextent, bool uwrap, bool vwrap,
15  MiscLib::Vector< char >* dilated)
16 {
17  // first pixel is special
18  (*dilated)[0] = bitmap[0] || bitmap[1] ||
19  bitmap[uextent] || bitmap[uextent + 1];
20  if (vwrap)
21  (*dilated)[0] = (*dilated)[0] ||
22  bitmap[(vextent - 1) * uextent] ||
23  bitmap[(vextent - 1) * uextent + 1];
24  if (uwrap)
25  (*dilated)[0] = (*dilated)[0] || bitmap[uextent - 1]
26  || bitmap[2 * uextent - 1];
27  if (vwrap && uwrap)
28  (*dilated)[0] = (*dilated)[0] ||
29  bitmap[(vextent - 1) * uextent + uextent - 1];
30  // first row is special
31  if (!vwrap)
32  {
33  for (size_t i = 1; i < uextent - 1; ++i)
34  {
35  (*dilated)[i] = bitmap[i - 1] || bitmap[i] || bitmap[i + 1] ||
36  bitmap[uextent + i - 1] || bitmap[uextent + i] ||
37  bitmap[uextent + i + 1];
38  }
39  }
40  else
41  {
42  for (size_t i = 1; i < uextent - 1; ++i)
43  {
44  (*dilated)[i] = bitmap[i - 1] || bitmap[i] || bitmap[i + 1] ||
45  bitmap[uextent + i - 1] || bitmap[uextent + i] ||
46  bitmap[uextent + i + 1] ||
47  bitmap[(vextent - 1) * uextent + i - 1] ||
48  bitmap[(vextent - 1) * uextent + i] ||
49  bitmap[(vextent - 1) * uextent + i + 1];
50  }
51  }
52  // last pixel of first row is special
53  (*dilated)[uextent - 1] = bitmap[uextent - 1] || bitmap[uextent - 2] ||
54  bitmap[2 * uextent - 1] || bitmap[2 * uextent - 2];
55  if (vwrap)
56  (*dilated)[uextent - 1] = (*dilated)[uextent - 1] ||
57  bitmap[vextent * uextent - 1] ||
58  bitmap[vextent * uextent - 2];
59  if (uwrap)
60  (*dilated)[uextent - 1] = (*dilated)[uextent - 1] ||
61  bitmap[uextent] || bitmap[0];
62  if (uwrap && vwrap)
63  (*dilated)[uextent - 1] = (*dilated)[uextent - 1] ||
64  bitmap[(vextent - 1) * uextent];
65  size_t row = 0, prevRow, nextRow = uextent;
66  for (size_t j = 1; j < vextent - 1; ++j)
67  {
68  prevRow = row;
69  row = nextRow;
70  nextRow = row + uextent;
71  // first pixel in row is special
72  (*dilated)[row] = bitmap[prevRow] || bitmap[prevRow + 1] ||
73  bitmap[row] || bitmap[row + 1] || bitmap[nextRow] ||
74  bitmap[nextRow + 1];
75  if (uwrap)
76  (*dilated)[row] = (*dilated)[row] || bitmap[row - 1] ||
77  bitmap[nextRow - 1] || bitmap[nextRow + uextent - 1];
78  for (size_t i = 1; i < uextent - 1; ++i)
79  {
80  (*dilated)[row + i] = bitmap[prevRow + i - 1] ||
81  bitmap[prevRow + i ] || bitmap[prevRow + i + 1] ||
82  bitmap[row + i - 1] || bitmap[row + i] ||
83  bitmap[row + i + 1] || bitmap[nextRow + i - 1] ||
84  bitmap[nextRow + i] || bitmap[nextRow + i + 1];
85  }
86  // last pixel in row is special
87  (*dilated)[row + uextent - 1] = bitmap[prevRow + uextent - 2] ||
88  bitmap[prevRow + uextent - 1] ||
89  bitmap[row + uextent - 2] || bitmap[row + uextent - 1] ||
90  bitmap[nextRow + uextent - 2] || bitmap[nextRow + uextent - 1];
91  if (uwrap)
92  (*dilated)[row + uextent - 1] = (*dilated)[row + uextent - 1] ||
93  bitmap[prevRow] || bitmap[row] || bitmap[nextRow];
94  }
95  // first pixel of last row is special
96  (*dilated)[(vextent - 1) * uextent] = bitmap[(vextent - 1) * uextent] ||
97  bitmap[(vextent - 1) * uextent + 1] ||
98  bitmap[(vextent - 2) * uextent] || bitmap[(vextent - 2) * uextent + 1];
99  if (vwrap)
100  (*dilated)[(vextent - 1) * uextent] =
101  (*dilated)[(vextent - 1) * uextent] || bitmap[0] || bitmap[1];
102  if (uwrap)
103  (*dilated)[(vextent - 1) * uextent] =
104  (*dilated)[(vextent - 1) * uextent] ||
105  bitmap[vextent * uextent - 1] ||
106  bitmap[(vextent - 1) * uextent - 1];
107  if (vwrap && uwrap)
108  (*dilated)[(vextent - 1) * uextent] =
109  (*dilated)[(vextent - 1) * uextent] || bitmap[uextent - 1];
110  // last row is special
111  if (!vwrap)
112  {
113  for (size_t i = 1; i < uextent - 1; ++i)
114  {
115  (*dilated)[(vextent - 1) * uextent + i] =
116  bitmap[(vextent - 1) * uextent + i] ||
117  bitmap[(vextent - 1) * uextent + i - 1] ||
118  bitmap[(vextent - 1) * uextent + i + 1] ||
119  bitmap[(vextent - 2) * uextent + i] ||
120  bitmap[(vextent - 2) * uextent + i - 1] ||
121  bitmap[(vextent - 2) * uextent + i + 1];
122  }
123  }
124  else
125  {
126  for (size_t i = 1; i < uextent - 1; ++i)
127  {
128  (*dilated)[(vextent - 1) * uextent + i] =
129  bitmap[(vextent - 1) * uextent + i] ||
130  bitmap[(vextent - 1) * uextent + i - 1] ||
131  bitmap[(vextent - 1) * uextent + i + 1] ||
132  bitmap[(vextent - 2) * uextent + i] ||
133  bitmap[(vextent - 2) * uextent + i - 1] ||
134  bitmap[(vextent - 2) * uextent + i + 1] ||
135  bitmap[i - 1] || bitmap[i] || bitmap[i + 1];
136  }
137  }
138  // last pixel
139  (*dilated)[bitmap.size() - 1] = bitmap[bitmap.size() - 1] ||
140  bitmap[bitmap.size() - 2] || bitmap[bitmap.size() - uextent - 1] ||
141  bitmap[bitmap.size() - uextent - 2];
142  if (vwrap)
143  (*dilated)[bitmap.size() - 1] = (*dilated)[bitmap.size() - 1] ||
144  bitmap[uextent - 1] || bitmap[uextent - 2];
145  if (uwrap)
146  (*dilated)[bitmap.size() - 1] = (*dilated)[bitmap.size() - 1] ||
147  bitmap[bitmap.size() - uextent] ||
148  bitmap[bitmap.size() - 2 * uextent];
149  if (uwrap && vwrap)
150  (*dilated)[bitmap.size() - 1] = (*dilated)[bitmap.size() - 1] ||
151  bitmap[0];
152 }
153 
155  size_t uextent, size_t vextent, bool uwrap, bool vwrap,
156  MiscLib::Vector< char >* dilated)
157 {
158  // first pixel is special
159  (*dilated)[0] = bitmap[0] || bitmap[1] ||
160  bitmap[uextent];
161  if (vwrap)
162  (*dilated)[0] = (*dilated)[0] ||
163  bitmap[(vextent - 1) * uextent];
164  if (uwrap)
165  {
166  (*dilated)[0] = (*dilated)[0] || bitmap[uextent - 1];
167  }
168  // first row is special
169  if (!vwrap)
170  {
171  for (size_t i = 1; i < uextent - 1; ++i)
172  {
173  (*dilated)[i] = bitmap[i - 1] || bitmap[i] || bitmap[i + 1] ||
174  bitmap[uextent + i];
175  }
176  }
177  else
178  {
179  for (size_t i = 1; i < uextent - 1; ++i)
180  {
181  (*dilated)[i] = bitmap[i - 1] || bitmap[i] || bitmap[i + 1] ||
182  bitmap[uextent + i] || bitmap[(vextent - 1) * uextent + i];
183  }
184  }
185  // last pixel of first row is special
186  (*dilated)[uextent - 1] = bitmap[uextent - 1] || bitmap[uextent - 2] ||
187  bitmap[2 * uextent - 1];
188  if (vwrap)
189  (*dilated)[uextent - 1] = (*dilated)[uextent - 1] ||
190  bitmap[vextent * uextent - 1];
191  if (uwrap)
192  {
193  (*dilated)[uextent - 1] = (*dilated)[uextent - 1] || bitmap[0];
194  }
195  size_t row = 0, prevRow, nextRow = uextent;
196  for (size_t j = 1; j < vextent - 1; ++j)
197  {
198  prevRow = row;
199  row = nextRow;
200  nextRow = row + uextent;
201  // first pixel in row is special
202  (*dilated)[row] = bitmap[prevRow] ||
203  bitmap[row] || bitmap[row + 1] || bitmap[nextRow];
204  if (uwrap)
205  {
206  (*dilated)[row] = (*dilated)[row] || bitmap[nextRow - 1];
207  }
208  for (size_t i = 1; i < uextent - 1; ++i)
209  {
210  (*dilated)[row + i] = bitmap[prevRow + i ] ||
211  bitmap[row + i - 1] || bitmap[row + i] ||
212  bitmap[row + i + 1] || bitmap[nextRow + i];
213  }
214  // last pixel in row is special
215  (*dilated)[row + uextent - 1] = bitmap[prevRow + uextent - 1] ||
216  bitmap[row + uextent - 2] || bitmap[row + uextent - 1] ||
217  bitmap[nextRow + uextent - 1];
218  if (uwrap)
219  (*dilated)[row + uextent - 1] = (*dilated)[row + uextent - 1] ||
220  bitmap[row];
221  }
222  // first pixel of last row is special
223  (*dilated)[(vextent - 1) * uextent] = bitmap[(vextent - 1) * uextent] ||
224  bitmap[(vextent - 1) * uextent + 1] ||
225  bitmap[(vextent - 2) * uextent];
226  if (vwrap)
227  (*dilated)[(vextent - 1) * uextent] =
228  (*dilated)[(vextent - 1) * uextent] || bitmap[0];
229  if (uwrap)
230  (*dilated)[(vextent - 1) * uextent] =
231  (*dilated)[(vextent - 1) * uextent] ||
232  bitmap[vextent * uextent - 1];
233  // last row is special
234  if (!vwrap)
235  {
236  for (size_t i = 1; i < uextent - 1; ++i)
237  {
238  (*dilated)[(vextent - 1) * uextent + i] =
239  bitmap[(vextent - 1) * uextent + i] ||
240  bitmap[(vextent - 1) * uextent + i - 1] ||
241  bitmap[(vextent - 1) * uextent + i + 1] ||
242  bitmap[(vextent - 2) * uextent + i];
243  }
244  }
245  else
246  {
247  for (size_t i = 1; i < uextent - 1; ++i)
248  {
249  (*dilated)[(vextent - 1) * uextent + i] =
250  bitmap[(vextent - 1) * uextent + i] ||
251  bitmap[(vextent - 1) * uextent + i - 1] ||
252  bitmap[(vextent - 1) * uextent + i + 1] ||
253  bitmap[(vextent - 2) * uextent + i] ||
254  bitmap[i];
255  }
256  }
257  // last pixel
258  (*dilated)[bitmap.size() - 1] = bitmap[bitmap.size() - 1] ||
259  bitmap[bitmap.size() - 2] || bitmap[bitmap.size() - uextent - 1];
260  if (vwrap)
261  (*dilated)[bitmap.size() - 1] = (*dilated)[bitmap.size() - 1] ||
262  bitmap[uextent - 1];
263  if (uwrap)
264  (*dilated)[bitmap.size() - 1] = (*dilated)[bitmap.size() - 1] ||
265  bitmap[bitmap.size() - uextent];
266 }
267 
269  size_t uextent, size_t vextent, bool uwrap, bool vwrap,
270  MiscLib::Vector< char >* eroded)
271 {
272  // first pixel is special
273  (*eroded)[0] = /*bitmap[0] && bitmap[1] &&
274  bitmap[uextent] && bitmap[uextent + 1]*/ false;
275  //if(vwrap)
276  // (*eroded)[0] = (*eroded)[0] &&
277  // bitmap[(vextent - 1) * uextent] &&
278  // bitmap[(vextent - 1) * uextent + 1];
279  //if(uwrap)
280  // (*eroded)[0] = (*eroded)[0] && bitmap[uextent - 1]
281  // && bitmap[2 * uextent - 1];
282  if (vwrap && uwrap)
283  {
284  (*eroded)[0] = bitmap[0]
285  && bitmap[1]
286  && bitmap[uextent]
287  && bitmap[uextent + 1]
288  && bitmap[(vextent - 1) * uextent]
289  && bitmap[(vextent - 1) * uextent + 1]
290  && bitmap[uextent - 1]
291  && bitmap[2 * uextent - 1]
292  && bitmap[(vextent - 1) * uextent + uextent - 1];
293  //(*eroded)[0] = (*eroded)[0] &&
294  // bitmap[(vextent - 1) * uextent + uextent - 1];
295  }
296  // first row is special
297  if (!vwrap)
298  {
299  for (size_t i = 1; i < uextent - 1; ++i)
300  {
301  (*eroded)[i] = /*bitmap[i - 1] && bitmap[i] && bitmap[i + 1] &&
302  bitmap[uextent + i - 1] && bitmap[uextent + i] &&
303  bitmap[uextent + i + 1];*/ false;
304  }
305  }
306  else
307  {
308  for (size_t i = 1; i < uextent - 1; ++i)
309  {
310  (*eroded)[i] = bitmap[i - 1] && bitmap[i] && bitmap[i + 1] &&
311  bitmap[uextent + i - 1] && bitmap[uextent + i] &&
312  bitmap[uextent + i + 1] &&
313  bitmap[(vextent - 1) * uextent + i - 1] &&
314  bitmap[(vextent - 1) * uextent + i] &&
315  bitmap[(vextent - 1) * uextent + i + 1];
316  }
317  }
318  // last pixel of first row is special
319  (*eroded)[uextent - 1] = /*bitmap[uextent - 1] && bitmap[uextent - 2] &&
320  bitmap[2 * uextent - 1] && bitmap[2 * uextent - 2]*/ false;
321  //if(vwrap)
322  // (*eroded)[uextent - 1] = (*eroded)[uextent - 1] &&
323  // bitmap[vextent * uextent - 1] &&
324  // bitmap[vextent * uextent - 2];
325  //if(uwrap)
326  // (*eroded)[uextent - 1] = (*eroded)[uextent - 1] &&
327  // bitmap[uextent] && bitmap[0];
328  if (uwrap && vwrap)
329  {
330  (*eroded)[uextent - 1] = bitmap[uextent - 1]
331  && bitmap[uextent - 2]
332  && bitmap[2 * uextent - 1]
333  && bitmap[2 * uextent - 2]
334  && bitmap[vextent * uextent - 1]
335  && bitmap[vextent * uextent - 2]
336  && bitmap[uextent]
337  && bitmap[0]
338  && bitmap[(vextent - 1) * uextent];
339  }
340  size_t row = 0, prevRow, nextRow = uextent;
341  for (size_t j = 1; j < vextent - 1; ++j)
342  {
343  prevRow = row;
344  row = nextRow;
345  nextRow = row + uextent;
346  // first pixel in row is special
347  (*eroded)[row] = /*bitmap[prevRow] && bitmap[prevRow + 1] &&
348  bitmap[row] && bitmap[row + 1] && bitmap[nextRow] &&
349  bitmap[nextRow + 1]*/ false;
350  if (uwrap)
351  {
352  (*eroded)[row] = bitmap[prevRow]
353  && bitmap[prevRow + 1]
354  && bitmap[row]
355  && bitmap[row + 1]
356  && bitmap[nextRow]
357  && bitmap[nextRow + 1]
358  && bitmap[row - 1]
359  && bitmap[nextRow - 1]
360  && bitmap[nextRow + uextent - 1];
361  }
362  for (size_t i = 1; i < uextent - 1; ++i)
363  {
364  (*eroded)[row + i] = bitmap[prevRow + i - 1] &&
365  bitmap[prevRow + i ] && bitmap[prevRow + i + 1] &&
366  bitmap[row + i - 1] && bitmap[row + i] &&
367  bitmap[row + i + 1] && bitmap[nextRow + i - 1] &&
368  bitmap[nextRow + i] && bitmap[nextRow + i + 1];
369  }
370  // last pixel in row is special
371  (*eroded)[row + uextent - 1] = /*bitmap[prevRow + uextent - 2] &&
372  bitmap[prevRow + uextent - 1] &&
373  bitmap[row + uextent - 2] && bitmap[row + uextent - 1] &&
374  bitmap[nextRow + uextent - 2] && bitmap[nextRow + uextent - 1]*/ false;
375  if (uwrap)
376  {
377  (*eroded)[row + uextent - 1] = bitmap[prevRow + uextent - 2]
378  && bitmap[prevRow + uextent - 1]
379  && bitmap[row + uextent - 2]
380  && bitmap[row + uextent - 1]
381  && bitmap[nextRow + uextent - 2]
382  && bitmap[nextRow + uextent - 1]
383  && bitmap[prevRow]
384  && bitmap[row]
385  && bitmap[nextRow];
386  }
387  }
388  // first pixel of last row is special
389  (*eroded)[(vextent - 1) * uextent] = /*bitmap[(vextent - 1) * uextent] &&
390  bitmap[(vextent - 1) * uextent + 1] &&
391  bitmap[(vextent - 2) * uextent] && bitmap[(vextent - 2) * uextent + 1]*/ false;
392  //if(vwrap)
393  // (*eroded)[(vextent - 1) * uextent] =
394  // (*eroded)[(vextent - 1) * uextent] && bitmap[0] && bitmap[1];
395  //if(uwrap)
396  // (*eroded)[(vextent - 1) * uextent] =
397  // (*eroded)[(vextent - 1) * uextent] &&
398  // bitmap[vextent * uextent - 1] &&
399  // bitmap[(vextent - 1) * uextent - 1];
400  if (vwrap && uwrap)
401  {
402  (*eroded)[(vextent - 1) * uextent] = bitmap[(vextent - 1) * uextent]
403  && bitmap[(vextent - 1) * uextent + 1]
404  && bitmap[(vextent - 2) * uextent]
405  && bitmap[(vextent - 2) * uextent + 1]
406  && bitmap[0]
407  && bitmap[1]
408  && bitmap[vextent * uextent - 1]
409  && bitmap[(vextent - 1) * uextent - 1]
410  && bitmap[uextent - 1];
411  }
412  // last row is special
413  if (!vwrap)
414  {
415  for (size_t i = 1; i < uextent - 1; ++i)
416  {
417  (*eroded)[(vextent - 1) * uextent + i] = false
418  /*bitmap[(vextent - 1) * uextent + i] &&
419  bitmap[(vextent - 1) * uextent + i - 1] &&
420  bitmap[(vextent - 1) * uextent + i + 1] &&
421  bitmap[(vextent - 2) * uextent + i] &&
422  bitmap[(vextent - 2) * uextent + i - 1] &&
423  bitmap[(vextent - 2) * uextent + i + 1]*/;
424  }
425  }
426  else
427  {
428  for (size_t i = 1; i < uextent - 1; ++i)
429  {
430  (*eroded)[(vextent - 1) * uextent + i] =
431  bitmap[(vextent - 1) * uextent + i] &&
432  bitmap[(vextent - 1) * uextent + i - 1] &&
433  bitmap[(vextent - 1) * uextent + i + 1] &&
434  bitmap[(vextent - 2) * uextent + i] &&
435  bitmap[(vextent - 2) * uextent + i - 1] &&
436  bitmap[(vextent - 2) * uextent + i + 1] &&
437  bitmap[i - 1] && bitmap[i] && bitmap[i + 1];
438  }
439  }
440  // last pixel
441  (*eroded)[bitmap.size() - 1] = false/*bitmap[bitmap.size() - 1] &&
442  bitmap[bitmap.size() - 2] && bitmap[bitmap.size() - uextent - 1] &&
443  bitmap[bitmap.size() - uextent - 2]*/;
444  //if(vwrap)
445  // (*eroded)[bitmap.size() - 1] = (*eroded)[bitmap.size() - 1] &&
446  // bitmap[uextent - 1] && bitmap[uextent - 2];
447  //if(uwrap)
448  // (*eroded)[bitmap.size() - 1] = (*eroded)[bitmap.size() - 1] &&
449  // bitmap[bitmap.size() - uextent] &&
450  // bitmap[bitmap.size() - 2 * uextent];
451  if (uwrap && vwrap)
452  {
453  (*eroded)[bitmap.size() - 1] = bitmap[bitmap.size() - 1]
454  && bitmap[bitmap.size() - 2]
455  && bitmap[bitmap.size() - uextent - 1]
456  && bitmap[bitmap.size() - uextent - 2]
457  && bitmap[uextent - 1]
458  && bitmap[uextent - 2]
459  && bitmap[bitmap.size() - uextent]
460  && bitmap[bitmap.size() - 2 * uextent]
461  && bitmap[0];
462  }
463 }
464 
466  size_t uextent, size_t vextent, bool uwrap, bool vwrap,
467  MiscLib::Vector< char >* eroded)
468 {
469  // first pixel is special
470  (*eroded)[0] = bitmap[0] && bitmap[1] &&
471  bitmap[uextent];
472  if (vwrap)
473  (*eroded)[0] = (*eroded)[0] &&
474  bitmap[(vextent - 1) * uextent];
475  if (uwrap)
476  {
477  (*eroded)[0] = (*eroded)[0] && bitmap[uextent - 1];
478  }
479  // first row is special
480  if (!vwrap)
481  {
482  for (size_t i = 1; i < uextent - 1; ++i)
483  {
484  (*eroded)[i] = bitmap[i - 1] && bitmap[i] && bitmap[i + 1] &&
485  bitmap[uextent + i];
486  }
487  }
488  else
489  {
490  for (size_t i = 1; i < uextent - 1; ++i)
491  {
492  (*eroded)[i] = bitmap[i - 1] && bitmap[i] && bitmap[i + 1] &&
493  bitmap[uextent + i] && bitmap[(vextent - 1) * uextent + i];
494  }
495  }
496  // last pixel of first row is special
497  (*eroded)[uextent - 1] = bitmap[uextent - 1] && bitmap[uextent - 2] &&
498  bitmap[2 * uextent - 1];
499  if (vwrap)
500  (*eroded)[uextent - 1] = (*eroded)[uextent - 1] &&
501  bitmap[vextent * uextent - 1];
502  if (uwrap)
503  {
504  (*eroded)[uextent - 1] = (*eroded)[uextent - 1] && bitmap[0];
505  }
506  size_t row = 0, prevRow, nextRow = uextent;
507  for (size_t j = 1; j < vextent - 1; ++j)
508  {
509  prevRow = row;
510  row = nextRow;
511  nextRow = row + uextent;
512  // first pixel in row is special
513  (*eroded)[row] = bitmap[prevRow] &&
514  bitmap[row] && bitmap[row + 1] && bitmap[nextRow];
515  if (uwrap)
516  {
517  (*eroded)[row] = (*eroded)[row] && bitmap[nextRow - 1];
518  }
519  for (size_t i = 1; i < uextent - 1; ++i)
520  {
521  (*eroded)[row + i] = bitmap[prevRow + i ] &&
522  bitmap[row + i - 1] && bitmap[row + i] &&
523  bitmap[row + i + 1] && bitmap[nextRow + i];
524  }
525  // last pixel in row is special
526  (*eroded)[row + uextent - 1] = bitmap[prevRow + uextent - 1] &&
527  bitmap[row + uextent - 2] && bitmap[row + uextent - 1] &&
528  bitmap[nextRow + uextent - 1];
529  if (uwrap)
530  (*eroded)[row + uextent - 1] = (*eroded)[row + uextent - 1] &&
531  bitmap[row];
532  }
533  // first pixel of last row is special
534  (*eroded)[(vextent - 1) * uextent] = bitmap[(vextent - 1) * uextent] &&
535  bitmap[(vextent - 1) * uextent + 1] &&
536  bitmap[(vextent - 2) * uextent];
537  if (vwrap)
538  (*eroded)[(vextent - 1) * uextent] =
539  (*eroded)[(vextent - 1) * uextent] && bitmap[0];
540  if (uwrap)
541  (*eroded)[(vextent - 1) * uextent] =
542  (*eroded)[(vextent - 1) * uextent] &&
543  bitmap[vextent * uextent - 1];
544  // last row is special
545  if (!vwrap)
546  {
547  for (size_t i = 1; i < uextent - 1; ++i)
548  {
549  (*eroded)[(vextent - 1) * uextent + i] =
550  bitmap[(vextent - 1) * uextent + i] &&
551  bitmap[(vextent - 1) * uextent + i - 1] &&
552  bitmap[(vextent - 1) * uextent + i + 1] &&
553  bitmap[(vextent - 2) * uextent + i];
554  }
555  }
556  else
557  {
558  for (size_t i = 1; i < uextent - 1; ++i)
559  {
560  (*eroded)[(vextent - 1) * uextent + i] =
561  bitmap[(vextent - 1) * uextent + i] &&
562  bitmap[(vextent - 1) * uextent + i - 1] &&
563  bitmap[(vextent - 1) * uextent + i + 1] &&
564  bitmap[(vextent - 2) * uextent + i] &&
565  bitmap[i];
566  }
567  }
568  // last pixel
569  (*eroded)[bitmap.size() - 1] = bitmap[bitmap.size() - 1] &&
570  bitmap[bitmap.size() - 2] && bitmap[bitmap.size() - uextent - 1];
571  if (vwrap)
572  (*eroded)[bitmap.size() - 1] = (*eroded)[bitmap.size() - 1] &&
573  bitmap[uextent - 1];
574  if (uwrap)
575  (*eroded)[bitmap.size() - 1] = (*eroded)[bitmap.size() - 1] &&
576  bitmap[bitmap.size() - uextent];
577 }
578 
579 void PreWrappedComponents(const MiscLib::Vector< char >& bitmap, size_t uextent,
580  size_t vextent, MiscLib::Vector< int >* preWrappedComponentsImg,
581  MiscLib::Vector< int >* relabelComponentsImg,
582  const MiscLib::Vector< std::pair< int, size_t > >& inLabels,
583  MiscLib::Vector< std::pair< int, size_t > >* labels)
584 {
585  MiscLib::Vector< std::pair< int, size_t > > tempLabels(inLabels);
586  tempLabels.reserve(bitmap.size() / 2 + 1); // this is the maximum of possible tempLabels
587  if (!tempLabels.size())
588  {
589  tempLabels.push_back(std::make_pair(0, size_t(0)));
590  }
591  int curLabel = tempLabels.size() - 1;
592  size_t prevRow, row = 0, nextRow = uextent;
593  for (size_t j = 1; j < vextent - 1; ++j)
594  {
595  prevRow = row;
596  row = nextRow;
597  nextRow = row + uextent;
598  for (size_t i = 1; i < uextent - 1; ++i)
599  {
600  if (!bitmap[row + i])
601  {
602  (*preWrappedComponentsImg)[row + i] = 0;
603  ++tempLabels[0].second;
604  continue;
605  }
606  // get neighborhood
607  int n[8];
608  n[0] = (*preWrappedComponentsImg)[prevRow + i - 1];
609  n[1] = (*preWrappedComponentsImg)[prevRow + i];
610  n[2] = (*preWrappedComponentsImg)[prevRow + i + 1];
611  n[3] = (*preWrappedComponentsImg)[row + i - 1];
612  n[4] = (*preWrappedComponentsImg)[row + i + 1];
613  n[5] = (*preWrappedComponentsImg)[nextRow + i - 1];
614  n[6] = (*preWrappedComponentsImg)[nextRow + i];
615  n[7] = (*preWrappedComponentsImg)[nextRow + i + 1];
616  (*preWrappedComponentsImg)[row + i] = Label(n, 8,
617  &curLabel, &tempLabels);
618  }
619  }
620 
621  // reduce the tempLabels
622  for (size_t i = tempLabels.size() - 1; i > 0; --i)
623  {
624  tempLabels[i].first = ReduceLabel(i, tempLabels);
625  }
626  MiscLib::Vector< int > condensed(tempLabels.size());
627  labels->clear();
628  labels->reserve(condensed.size());
629  int count = 0;
630  for (size_t i = 0; i < tempLabels.size(); ++i)
631  if (i == (size_t)tempLabels[i].first)
632  {
633  labels->push_back(std::make_pair(count, tempLabels[i].second));
634  condensed[i] = count;
635  ++count;
636  }
637  else
638  (*labels)[condensed[tempLabels[i].first]].second
639  += tempLabels[i].second;
640  // set new component ids
641  for (size_t i = 0; i < preWrappedComponentsImg->size(); ++i)
642  (*preWrappedComponentsImg)[i] =
643  condensed[tempLabels[(*preWrappedComponentsImg)[i]].first];
644  for (size_t i = 0; i < relabelComponentsImg->size(); ++i)
645  (*relabelComponentsImg)[i] =
646  condensed[tempLabels[(*relabelComponentsImg)[i]].first];
647 }
648 
650  size_t uextent, size_t vextent, bool uwrap, bool vwrap,
651  MiscLib::Vector< int >* componentsImg,
652  MiscLib::Vector< std::pair< int, size_t > >* labels)
653 {
654  componentsImg->resize(uextent * vextent);
656  tempLabels.reserve(componentsImg->size() / 2 + 1); // this is the maximum of possible tempLabels
657  tempLabels.push_back(std::make_pair(0, size_t(0)));
658  // use an eight neighborhood
659  // first row is special
660  // first pixel is special
661  // wrapping does not make sense in the first row: no pixels have been
662  // assigned components yet
663  int curLabel = 0;
664  if (bitmap[0])
665  {
666  (*componentsImg)[0] = ++curLabel;
667  tempLabels.push_back(std::make_pair(curLabel, size_t(1)));
668  }
669  else
670  {
671  (*componentsImg)[0] = 0;
672  ++tempLabels[0].second;
673  }
674  // handle first row
675  for (size_t i = 1; i < uextent; ++i)
676  {
677  // in the first row only the previous pixel has to be considered
678  if (bitmap[i])
679  {
680  if ((*componentsImg)[i - 1])
681  {
682  (*componentsImg)[i] = (*componentsImg)[i - 1];
683  ++tempLabels[(*componentsImg)[i]].second;
684  }
685  else
686  {
687  (*componentsImg)[i] = ++curLabel;
688  tempLabels.push_back(std::make_pair(curLabel, size_t(1)));
689  }
690  }
691  else
692  {
693  (*componentsImg)[i] = 0;
694  ++tempLabels[0].second;
695  }
696  }
697  size_t prevRow, row = 0;
698  size_t jend = vwrap ? vextent - 1 : vextent;
699  for (size_t j = 1; j < jend; ++j)
700  {
701  prevRow = row;
702  row = prevRow + uextent;
703  // first pixel in row gets different treatment
704  if (bitmap[row])
705  {
706  if ((*componentsImg)[prevRow]) // pixel above in component?
707  {
708  (*componentsImg)[row] = (*componentsImg)[prevRow];
709  ++tempLabels[(*componentsImg)[row]].second;
710  }
711  else
712  {
713  int n[2];
714  n[0] = (*componentsImg)[prevRow + 1];
715  if (uwrap)
716  {
717  n[1] = (*componentsImg)[prevRow + uextent - 1];
718  }
719  (*componentsImg)[row] = Label(n, uwrap ? 2 : 1, &curLabel,
720  &tempLabels);
721  }
722  }
723  else
724  {
725  (*componentsImg)[row] = 0;
726  ++tempLabels[0].second;
727  }
728  for (size_t i = 1; i < uextent - 1; ++i)
729  {
730  if (!bitmap[row + i])
731  {
732  (*componentsImg)[row + i] = 0;
733  ++tempLabels[0].second;
734  continue;
735  }
736  int n[4];
737  n[0] = (*componentsImg)[row + i - 1];
738  n[1] = (*componentsImg)[prevRow + i - 1];
739  n[2] = (*componentsImg)[prevRow + i];
740  n[3] = (*componentsImg)[prevRow + i + 1];
741  (*componentsImg)[row + i] = Label(n, 4, &curLabel, &tempLabels);
742  }
743  // last pixel in the row
744  if (!bitmap[row + uextent - 1])
745  {
746  (*componentsImg)[row + uextent - 1] = 0;
747  ++tempLabels[0].second;
748  continue;
749  }
750  int n[5];
751  n[0] = (*componentsImg)[row + uextent - 2];
752  n[1] = (*componentsImg)[prevRow + uextent - 2];
753  n[2] = (*componentsImg)[prevRow + uextent - 1];
754  if (uwrap)
755  {
756  n[3] = (*componentsImg)[prevRow];
757  n[4] = (*componentsImg)[row];
758  }
759  (*componentsImg)[row + uextent - 1] = Label(n, uwrap ? 5 : 3, &curLabel,
760  &tempLabels);
761  }
762  // last row
763  if (vwrap) // in case of vwrapping the last row is computed with almost full
764  // neighborhood
765  {
766  prevRow = (vextent - 2) * uextent;
767  row = (vextent - 1) * uextent;
768  // first pixel
769  if (bitmap[row])
770  {
771  int n[6];
772  n[0] = (*componentsImg)[prevRow];
773  n[1] = (*componentsImg)[prevRow + 1];
774  n[2] = (*componentsImg)[0];
775  n[3] = (*componentsImg)[1];
776  if (uwrap)
777  {
778  n[4] = (*componentsImg)[prevRow + uextent - 1];
779  n[5] = (*componentsImg)[uextent - 1];
780  }
781  (*componentsImg)[row] = Label(n, uwrap ? 6 : 4, &curLabel,
782  &tempLabels);
783  }
784  else
785  {
786  (*componentsImg)[row] = 0;
787  ++tempLabels[0].second;
788  }
789  for (size_t i = 1; i < uextent - 1; ++i)
790  {
791  if (!bitmap[row + i])
792  {
793  (*componentsImg)[row + i] = 0;
794  ++tempLabels[0].second;
795  continue;
796  }
797  int n[7];
798  n[0] = (*componentsImg)[row + i - 1];
799  n[1] = (*componentsImg)[prevRow + i - 1];
800  n[2] = (*componentsImg)[prevRow + i];
801  n[3] = (*componentsImg)[prevRow + i + 1];
802  n[4] = (*componentsImg)[i - 1];
803  n[5] = (*componentsImg)[i];
804  n[6] = (*componentsImg)[i + 1];
805  (*componentsImg)[row + i] = Label(n, 7, &curLabel, &tempLabels);
806  }
807  // last pixel
808  if (!bitmap[row + uextent - 1])
809  {
810  (*componentsImg)[row + uextent - 1] = 0;
811  ++tempLabels[0].second;
812  }
813  else
814  {
815  int n[8];
816  n[0] = (*componentsImg)[row + uextent - 2];
817  n[1] = (*componentsImg)[prevRow + uextent - 2];
818  n[2] = (*componentsImg)[prevRow + uextent - 1];
819  n[3] = (*componentsImg)[uextent - 2];
820  n[4] = (*componentsImg)[uextent - 1];
821  if (uwrap)
822  {
823  n[5] = (*componentsImg)[prevRow];
824  n[6] = (*componentsImg)[row];
825  n[7] = (*componentsImg)[0];
826  }
827  (*componentsImg)[row + uextent - 1] = Label(n, uwrap ? 8 : 5,
828  &curLabel, &tempLabels);
829  }
830  }
831  // reduce the tempLabels
832  for (size_t i = tempLabels.size() - 1; i > 0; --i)
833  {
834  tempLabels[i].first = ReduceLabel(i, tempLabels);
835  }
836  MiscLib::Vector< int > condensed(tempLabels.size());
837  labels->clear();
838  labels->reserve(condensed.size());
839  int count = 0;
840  for (size_t i = 0; i < tempLabels.size(); ++i)
841  if (i == (size_t)tempLabels[i].first)
842  {
843  labels->push_back(std::make_pair(count, tempLabels[i].second));
844  condensed[i] = count;
845  ++count;
846  }
847  else
848  (*labels)[condensed[tempLabels[i].first]].second
849  += tempLabels[i].second;
850  // set new component ids
851  for (size_t i = 0; i < componentsImg->size(); ++i)
852  (*componentsImg)[i] =
853  condensed[tempLabels[(*componentsImg)[i]].first];
854 }
855 
856 int Label(int n[], int size, int* curLabel,
857  MiscLib::Vector< std::pair< int, size_t > >* labels)
858 {
859  // check if components are set
860  int count = 0, found;
861  for (int i = 0; i < size; ++i)
862  {
863  if (n[i])
864  {
865  ++count;
866  found = n[i];
867  }
868  }
869  if (!count)
870  {
871  ++(*curLabel);
872  labels->push_back(std::make_pair(*curLabel, size_t(1)));
873  return *curLabel;
874  }
875  else if (count == 1)
876  {
877  ++(*labels)[found].second;
878  return found;
879  }
880  else
881  {
882  ++(*labels)[found].second;
883  // associate the remaining labels
884  for (int i = 0; i < size; ++i)
885  {
886  if (n[i] && n[i] != found)
887  {
888  AssociateLabel(n[i], found, labels);
889  }
890  }
891  return found;
892  }
893 }
894 
895 void AssociateLabel(int a, int b,
896  MiscLib::Vector< std::pair< int, size_t > >* labels)
897 {
898  if (a > b)
899  {
900  AssociateLabel(b, a, labels);
901  return;
902  }
903  if ((a == b) || ((*labels)[b].first == a))
904  {
905  return;
906  }
907  if ((*labels)[b].first == b)
908  {
909  (*labels)[b].first = a;
910  }
911  else
912  {
913  AssociateLabel((*labels)[b].first, a, labels);
914  if ((*labels)[b].first > a)
915  {
916  (*labels)[b].first = a;
917  }
918  }
919 }
920 
921 int ReduceLabel(int a,
922  const MiscLib::Vector< std::pair< int, size_t > >& labels)
923 {
924  if (labels[a].first == a)
925  {
926  return labels[a].first;
927  }
928  return ReduceLabel(labels[a].first, labels);
929 }
930 
931 bool IsEdge(const MiscLib::Vector< int >& componentImg, size_t uextent,
932  size_t vextent, int label, bool uwrap, bool vwrap,
933  int startx, int starty, int dirx, int diry,
934  size_t* targetx, size_t* targety)
935 {
936  if (dirx > 0)
937  {
938  if ((size_t)startx == uextent)
939  {
940  return false;
941  }
942  if ((size_t)starty == vextent)
943  {
944  return false;
945  }
946  *targetx = (uwrap && (size_t)startx == uextent - 1) ? 0 : startx + 1;
947  *targety = starty;
948  return componentImg[starty * uextent + startx] == label
949  && ((starty > 0 && componentImg[(starty - 1) * uextent + startx] != label)
950  || (!vwrap && starty == 0)
951  || (vwrap && starty == 0 && componentImg[(vextent - 1) * uextent + startx] != label));
952  }
953  if (dirx < 0)
954  {
955  if (!uwrap && startx == 0)
956  {
957  return false;
958  }
959  *targetx = (startx == 0) ? uextent - 1 : startx - 1;
960  *targety = starty;
961  return (!vwrap && (size_t)starty == vextent && componentImg[(starty - 1) * uextent + (*targetx)] == label)
962  || ((size_t)starty != vextent && (componentImg[starty * uextent + (*targetx)] != label
963  && ((starty > 0 && componentImg[(starty - 1) * uextent + (*targetx)] == label)
964  || (vwrap && starty == 0 && componentImg[(vextent - 1) * uextent + (*targetx)] == label))));
965  }
966  if (diry > 0)
967  {
968  if ((size_t)starty == vextent)
969  {
970  return false;
971  }
972  *targetx = startx;
973  *targety = (vwrap && (size_t)starty == vextent - 1) ? 0 : starty + 1;
974  return (!uwrap && (size_t)startx == uextent && componentImg[starty * uextent + (startx - 1)] == label)
975  || ((size_t)startx != uextent && (componentImg[starty * uextent + startx] != label
976  && (((size_t)startx > 0 && componentImg[starty * uextent + (startx - 1)] == label)
977  || (uwrap && startx == 0 && componentImg[starty * uextent + (uextent - 1)] == label))));
978  }
979  if (diry < 0)
980  {
981  if (!vwrap && starty == 0)
982  {
983  return false;
984  }
985  if ((size_t)startx == uextent)
986  {
987  return false;
988  }
989  *targetx = startx;
990  *targety = (starty == 0) ? vextent - 1 : starty - 1;
991  return componentImg[(*targety) * uextent + startx] == label
992  && ((startx > 0 && componentImg[(*targety) * uextent + (startx - 1)] != label)
993  || (!uwrap && startx == 0)
994  || (uwrap && startx == 0 && componentImg[(*targety) * uextent + (uextent - 1)] != label));
995  }
996  return false;
997 }
998 
999 // finds the loops around a connected component as polygons
1000 void ComponentLoops(const MiscLib::Vector< int >& componentImg, size_t uextent,
1001  size_t vextent, int label, bool uwrap, bool vwrap,
1003 {
1004  typedef GfxTL::VectorXD< 2, size_t > Vec2;
1005  // find first point of component
1006  size_t firsti = 0;
1007  int x, y, prevx, prevy;
1008  // the corners of our pixels will be the vertices of our polygons
1009  // (x, y) is the upper left corner of the pixel y * uextent + x
1010  HashGrid< bool, 4 > edges;
1011  unsigned int edgesExtent[] = { uextent + 1, vextent + 1, 3, 3 };
1012  edges.Extent(edgesExtent);
1013  bool prevPixelWasWhite = true;
1014  do
1015  {
1016  // find the first edge in the polygon
1017  // edges are oriented so that the "black" pixels are on the right
1018  // black pixels are pixels == label
1019  for (; firsti < componentImg.size(); ++firsti)
1020  {
1021  if (prevPixelWasWhite && componentImg[firsti] == label)
1022  {
1023  prevPixelWasWhite = false;
1024  x = firsti % uextent;
1025  y = firsti / uextent;
1026  break;
1027  }
1028  prevPixelWasWhite = componentImg[firsti] != label;
1029  }
1030  if (firsti >= componentImg.size()) // unable to find a pixel -> good bye
1031  {
1032  // if there is a uwrap, then the last row could be an outer loop
1033  // this outer loop could be missed of all pixels in the last
1034  // row are black
1035  // to find that out we spawn another trial at the first
1036  // pixel in the last row (if it is black)
1037  // if the loop has already been detected, than this
1038  // edge should already be in edges
1039  if (!uwrap)
1040  {
1041  break;
1042  }
1043  if (componentImg[(vextent - 1) * uextent] == label)
1044  {
1045  x = 0;
1046  y = vextent - 1;
1047  }
1048  }
1050  // we initialize the path with an oriented edge
1051  // since the black pixel is on the right the edge goes from
1052  // bottom to top, i.e. from (x, y + 1) to (x, y)
1053  if ((x > 0 && (size_t)y < vextent - 1)
1054  || (!uwrap && !vwrap) || (vwrap && !uwrap && y == 0))
1055  {
1056  // on the left of pixel
1057  // check if edge was visited already
1058  unsigned int edgeIndex[] = { x, y, 1, 2 };
1059  if (edges.find(edgeIndex))
1060  {
1061  continue;
1062  }
1063  prevx = 0;
1064  prevy = 1;
1065  }
1066  else if (uwrap && !vwrap && x == 0 && (size_t)y != vextent - 1)
1067  {
1068  size_t dx, dy;
1069  if (!IsEdge(componentImg, uextent, vextent, label, uwrap, vwrap,
1070  x, y, 1, 0, &dx, &dy))
1071  {
1072  continue;
1073  }
1074  // check if edge was visited already
1075  unsigned int edgeIndex[] = { x + 1, y, 0, 1 };
1076  if (edges.find(edgeIndex))
1077  {
1078  continue;
1079  }
1080  // on top of pixel
1081  prevx = -1;
1082  prevy = 0;
1083  ++x;
1084  }
1085  else if (uwrap && !vwrap && x == 0 && (size_t)y == vextent - 1)
1086  {
1087  size_t dx, dy;
1088  if (!IsEdge(componentImg, uextent, vextent, label, uwrap, vwrap,
1089  x + 1, y + 1, -1, 0, &dx, &dy))
1090  {
1091  continue;
1092  }
1093  // on bottom of pixel
1094  // check if edge was visited already
1095  unsigned int edgeIndex[] = { x + 1, y + 1, 0, 1 };
1096  if (edges.find(edgeIndex))
1097  {
1098  continue;
1099  }
1100  prevx = -1;
1101  prevy = 0;
1102  ++y;
1103  }
1104  else if (!uwrap && vwrap && (size_t)x == uextent - 1)
1105  {
1106  // on right of pixel
1107  size_t dx, dy;
1108  if (!IsEdge(componentImg, uextent, vextent, label, uwrap, vwrap,
1109  x + 1, y + 1, 0, -1, &dx, &dy))
1110  {
1111  continue;
1112  }
1113  // on bottom of pixel
1114  // check if edge was visited already
1115  unsigned int edgeIndex[] = { x + 1, y + 1, 1, 0 };
1116  if (edges.find(edgeIndex))
1117  {
1118  continue;
1119  }
1120  prevx = 0;
1121  prevy = 1;
1122  ++y;
1123  }
1124  else
1125  {
1126  continue; // we are unable to start a loop at this position
1127  }
1128  poly.push_back(Vec2(x + prevx, y + prevy));
1129  edges[x][y][prevx + 1][prevy + 1] = true;
1130  do
1131  {
1132  poly.push_back(Vec2(x, y));
1133  // check the four neighbors of (x, y) from left to right
1134  // starting from where we came from
1135  // we take the first edge that we encounter
1136  size_t nextx, nexty;
1137  size_t checkEdge;
1138  for (checkEdge = 0; checkEdge < 3; ++checkEdge)
1139  {
1140  std::swap(prevx, prevy);
1141  prevx *= -1;
1142  if (IsEdge(componentImg, uextent, vextent, label, uwrap, vwrap,
1143  x, y, prevx, prevy, &nextx, &nexty))
1144  {
1145  break;
1146  }
1147  }
1148  if (checkEdge > 3)
1149  {
1150  return;
1151  }
1152  x = nextx;
1153  y = nexty;
1154  prevx = -prevx;
1155  prevy = -prevy;
1156  edges[x][y][prevx + 1][prevy + 1] = true;
1157  }
1158  while (poly[0] != Vec2(x, y));
1159  polys->push_back(poly);
1160  }
1161  while (firsti < componentImg.size());
1162 #ifdef _DEBUG
1163  static int fname_int = 0;
1164  std::ostringstream fn;
1165  fn << "ComponentLoopsInput" << fname_int << ".txt";
1166  std::ofstream file;
1167  file.open(fn.str().c_str(), std::ios::out);
1168  for (size_t j = 0; j < vextent; ++j)
1169  {
1170  for (size_t i = 0; i < uextent; ++i)
1171  {
1172  file /*<< std::setw(3)*/ << componentImg[j * uextent + i]/* << " "*/;
1173  }
1174  file << std::endl;
1175  }
1176  file.close();
1177  MiscLib::Vector< int > loopsImg((uextent + 1) * (vextent + 1), 0);
1178  std::ostringstream fn2;
1179  fn2 << "ComponentLoopsOutput" << fname_int++ << ".txt";
1180  for (size_t i = 0; i < polys->size(); ++i)
1181  for (size_t j = 0; j < (*polys)[i].size(); ++j)
1182  {
1183  loopsImg[(*polys)[i][j][1] * (uextent + 1) + (*polys)[i][j][0]] = i + 1;
1184  }
1185  file.open(fn2.str().c_str(), std::ios::out);
1186  for (size_t j = 0; j < vextent + 1; ++j)
1187  {
1188  for (size_t i = 0; i < uextent + 1; ++i)
1189  {
1190  file /*<< std::setw(3)*/ << loopsImg[j * (uextent + 1) + i]/* << " "*/;
1191  }
1192  file << std::endl;
1193  }
1194  file.close();
1195 #endif
1196 }
PreWrappedComponents
void PreWrappedComponents(const MiscLib::Vector< char > &bitmap, size_t uextent, size_t vextent, MiscLib::Vector< int > *preWrappedComponentsImg, MiscLib::Vector< int > *relabelComponentsImg, const MiscLib::Vector< std::pair< int, size_t > > &inLabels, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition: Bitmap.cpp:579
GfxTL::VectorXD
Definition: MatrixXX.h:21
ErodeSquare
void ErodeSquare(const MiscLib::Vector< char > &bitmap, size_t uextent, size_t vextent, bool uwrap, bool vwrap, MiscLib::Vector< char > *eroded)
Definition: Bitmap.cpp:268
DilateCross
void DilateCross(const MiscLib::Vector< char > &bitmap, size_t uextent, size_t vextent, bool uwrap, bool vwrap, MiscLib::Vector< char > *dilated)
Definition: Bitmap.cpp:154
ReduceLabel
int ReduceLabel(int a, const MiscLib::Vector< std::pair< int, size_t > > &labels)
Definition: Bitmap.cpp:921
MiscLib::Vector::push_back
void push_back(const T &v)
Definition: Vector.h:346
Performance.h
MiscLib::Vector::resize
void resize(size_type s, const value_type &v)
Definition: Vector.h:222
Bitmap.h
DilateSquare
void DilateSquare(const MiscLib::Vector< char > &bitmap, size_t uextent, size_t vextent, bool uwrap, bool vwrap, MiscLib::Vector< char > *dilated)
Definition: Bitmap.cpp:13
Label
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition: Bitmap.cpp:856
HashGrid
Definition: Grid.h:307
MiscLib::Vector< char >
VectorXD.h
Grid.h
armarx::armem::client::util::swap
void swap(SubscriptionHandle &first, SubscriptionHandle &second)
Definition: SubscriptionHandle.cpp:66
MiscLib::Vector::size
size_type size() const
Definition: Vector.h:212
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
MiscLib::performance_t
clock_t performance_t
Definition: Performance.h:27
MiscLib
Definition: AlignedAllocator.h:11
IsEdge
bool IsEdge(const MiscLib::Vector< int > &componentImg, size_t uextent, size_t vextent, int label, bool uwrap, bool vwrap, int startx, int starty, int dirx, int diry, size_t *targetx, size_t *targety)
Definition: Bitmap.cpp:931
ErodeCross
void ErodeCross(const MiscLib::Vector< char > &bitmap, size_t uextent, size_t vextent, bool uwrap, bool vwrap, MiscLib::Vector< char > *eroded)
Definition: Bitmap.cpp:465
MiscLib::Vector::reserve
void reserve(size_type s)
Definition: Vector.h:187
Components
void Components(const MiscLib::Vector< char > &bitmap, size_t uextent, size_t vextent, bool uwrap, bool vwrap, MiscLib::Vector< int > *componentsImg, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition: Bitmap.cpp:649
AssociateLabel
void AssociateLabel(int a, int b, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition: Bitmap.cpp:895
ComponentLoops
void ComponentLoops(const MiscLib::Vector< int > &componentImg, size_t uextent, size_t vextent, int label, bool uwrap, bool vwrap, MiscLib::Vector< MiscLib::Vector< GfxTL::VectorXD< 2, size_t > > > *polys)
Definition: Bitmap.cpp:1000
totalTime_components
MiscLib::performance_t totalTime_components
HashGrid::find
CellT * find(const IndexT &index)
Definition: Grid.h:364
HashGrid::Extent
void Extent(const ExtentT &extent)
Definition: Grid.h:328