Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CDibView::OnL6Chaincode()
- {
- BYTE dir;
- int currentI = 0;
- int currentJ = 0;
- vector<int> contourI;
- vector<int> contourJ;
- vector<int> directions;
- BEGIN_PROCESSING();
- bool first = false;
- for (int i = dwHeight - 1; i >= 0; i--) {
- for (int j = 0; j < dwWidth; j++) {
- if (lpSrc[i*w + j] == 0) {
- currentI = i;
- currentJ = j;
- contourI.push_back(currentI);
- contourJ.push_back(currentJ);
- first = true;
- dir = 7;
- break;
- }
- }
- if (first) break;
- }
- int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
- int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
- bool stop = false;
- while (!stop) {
- if (dir % 2 == 0) {
- dir = (dir + 7) % 8;
- }
- else {
- dir = (dir + 6) % 8;
- }
- for (int i = 0; i < 8; i++) {
- int newDir = (dir + i) % 8;
- if (lpSrc[(currentI + di[newDir])*w + currentJ + dj[newDir]] == 0) {
- directions.push_back(newDir);
- if (contourI.size() > 2
- && currentI == contourI.front() && currentJ == contourJ.front()
- && currentI + di[newDir] == contourI[1] && currentJ + dj[newDir] == contourJ[1]) {
- stop = true;
- break;
- }
- currentI += di[newDir];
- currentJ += dj[newDir];
- contourI.push_back(currentI);
- contourJ.push_back(currentJ);
- dir = newDir;
- break;
- }
- }
- }
- int initialI = contourI[0];
- int initialJ = contourJ[0];
- for (int direction : directions) {
- initialI += di[direction];
- initialJ += dj[direction];
- lpDst[initialI*w + initialJ] = 1;
- }
- bmiColorsDst[1].rgbBlue = rand() % 256;
- bmiColorsDst[1].rgbGreen = rand() % 256;
- bmiColorsDst[1].rgbRed = rand() % 256;
- END_PROCESSING("Border trancing");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement