Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. void CDibView::OnL6Chaincode()
  2. {
  3. BYTE dir;
  4. int currentI = 0;
  5. int currentJ = 0;
  6. vector<int> contourI;
  7. vector<int> contourJ;
  8. vector<int> directions;
  9.  
  10. BEGIN_PROCESSING();
  11. bool first = false;
  12. for (int i = dwHeight - 1; i >= 0; i--) {
  13. for (int j = 0; j < dwWidth; j++) {
  14. if (lpSrc[i*w + j] == 0) {
  15. currentI = i;
  16. currentJ = j;
  17. contourI.push_back(currentI);
  18. contourJ.push_back(currentJ);
  19. first = true;
  20. dir = 7;
  21. break;
  22. }
  23. }
  24. if (first) break;
  25. }
  26.  
  27. int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
  28. int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
  29.  
  30. bool stop = false;
  31. while (!stop) {
  32. if (dir % 2 == 0) {
  33. dir = (dir + 7) % 8;
  34. }
  35. else {
  36. dir = (dir + 6) % 8;
  37. }
  38.  
  39. for (int i = 0; i < 8; i++) {
  40. int newDir = (dir + i) % 8;
  41. if (lpSrc[(currentI + di[newDir])*w + currentJ + dj[newDir]] == 0) {
  42. directions.push_back(newDir);
  43. if (contourI.size() > 2
  44. && currentI == contourI.front() && currentJ == contourJ.front()
  45. && currentI + di[newDir] == contourI[1] && currentJ + dj[newDir] == contourJ[1]) {
  46. stop = true;
  47. break;
  48. }
  49. currentI += di[newDir];
  50. currentJ += dj[newDir];
  51. contourI.push_back(currentI);
  52. contourJ.push_back(currentJ);
  53. dir = newDir;
  54. break;
  55. }
  56. }
  57. }
  58.  
  59. int initialI = contourI[0];
  60. int initialJ = contourJ[0];
  61. for (int direction : directions) {
  62. initialI += di[direction];
  63. initialJ += dj[direction];
  64. lpDst[initialI*w + initialJ] = 1;
  65. }
  66.  
  67. bmiColorsDst[1].rgbBlue = rand() % 256;
  68. bmiColorsDst[1].rgbGreen = rand() % 256;
  69. bmiColorsDst[1].rgbRed = rand() % 256;
  70. END_PROCESSING("Border trancing");
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement