Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void drawContourMarchingBetter(UI& ui, Blob& blob, float threshold = 0.015)
- {
- bool bool_array[4];
- Point temppoint;
- Point temppoint2;
- Point point;
- std::queue<Point> worklist;
- std::set<Point> visited;
- const int sizeX = ui.sizeX;
- const int sizeY = ui.sizeY;
- float current_value = 0;
- bool previous_value = false;
- int k = 0;
- int l = 0;
- int i = 0;
- int j = 0;
- int new_size_x = 0;
- int new_size_y = 0;
- ui.drawPixel(0, 0);
- for (j = -sizeX; j < sizeX; j++) {
- for (i = -sizeY; i < sizeY; i++) {
- current_value = blob.potential(i, j);
- if (i == -sizeY) {
- if (current_value >= threshold) {
- previous_value = true;
- }
- else {
- previous_value = false;
- }
- }
- if ((current_value >= threshold) && (previous_value == false) || (current_value <= threshold) && (previous_value == true)) {
- ui.drawPixel(i, j);
- std::cout << "Value of i: " << i << "and value of j: " << j << std::endl;
- temppoint.x = i;
- temppoint.y = j;
- worklist.push(temppoint);
- if ((j <= 0) && (i <= 0)) {
- k = 0;
- l = 0;
- new_size_x = sizeY;
- new_size_y = sizeX;
- }
- else if ((j > 0) && (i > 0)) {
- l = -sizeX;
- k = -sizeY;
- new_size_x = 0;
- new_size_y = 0;
- }
- else if ((j < 0) && (i > 0)) {
- l = 0;
- k = -sizeY;
- new_size_x = 0;
- new_size_y = sizeX;
- }
- else if ((j > 0) && (i < 0)) {
- l = -sizeY;
- k = 0;
- new_size_x = sizeY;
- new_size_y = 0;
- }
- j = sizeX;
- i = sizeY;
- }
- }
- }
- float current_value2 = 0;
- bool previous_value2 = false;
- int original_k = k;
- for (l; l < new_size_y; l++) {
- for (k; k < new_size_x; k++) {
- current_value2 = blob.potential(k, l);
- if (k == original_k) {
- if (current_value2 >= threshold) {
- previous_value2 = true;
- }
- else {
- previous_value2 = false;
- }
- }
- else {
- if ((current_value2 >= threshold) && (previous_value2 == false) || (current_value2 < threshold) && (previous_value2 == true)) {
- std::cout << "Value of k: " << k << "and value of l: " << l;
- temppoint2.x = k;
- temppoint2.y = l;
- if ((k == i) && (l == j)){
- std::cout << "I'm going to continue!";
- continue;
- }
- else {
- ui.drawPixel(k, l);
- worklist.push({ temppoint2.x,temppoint2.y });
- k = new_size_x;
- l = new_size_y;
- }
- if (current_value2 >= threshold) {
- previous_value2 = true;
- }
- else if (current_value2 < threshold) {
- previous_value2 = false;
- }
- }
- }
- }
- }
- while (!worklist.empty()) {
- temppoint = worklist.front();
- worklist.pop();
- if (visited.find(temppoint) != visited.end()) {
- //drawContourMarching(ui, blob, threshold = 0.015);
- }
- else {
- float p1, p2, p3, p4;
- int position_y = temppoint.y;
- int position_x = temppoint.x;
- visited.insert(temppoint);
- p1 = blob.potential(position_x + 0.5, position_y + 0.5);
- p2 = blob.potential(position_x + 0.5, position_y - 0.5);
- p3 = blob.potential(position_x - 0.5, position_y + 0.5);
- p4 = blob.potential(position_x - 0.5, position_y - 0.5);
- bool_array[0] = p1 < threshold;
- bool_array[1] = p2 < threshold;
- bool_array[2] = p3 < threshold;
- bool_array[3] = p4 < threshold;
- if (bool_array[0] != bool_array[1] || bool_array[1] != bool_array[2] || bool_array[2] != bool_array[3]) {
- ui.drawPixel(position_x, position_y);
- worklist.push({ temppoint.x - 1, temppoint.y - 1 });
- worklist.push({ temppoint.x, temppoint.y - 1 });
- worklist.push({ temppoint.x + 1, temppoint.y - 1 });
- worklist.push({ temppoint.x - 1, temppoint.y });
- worklist.push({ temppoint.x + 1, temppoint.y });
- worklist.push({ temppoint.x - 1, temppoint.y + 1 });
- worklist.push({ temppoint.x, temppoint.y + 1 });
- worklist.push({ temppoint.x + 1, temppoint.y + 1 });
- //drawContourMarching(ui, blob, threshold = 0.015);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment