Advertisement
Ladies_Man

#CG LAB4 (rasterization) COMPLETE

Apr 29th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.49 KB | None | 0 0
  1. //закраска упорядоченным списком ребер и сглаживание усредненной постфильтрацией 3х3
  2. //управление: мышь, q-толщина линий, d-рисовать, a-замкнуть контур, f-заливка, s-постфильтрация, t-распечатать упорядоченный список ребер
  3.  
  4. // glfw_30.cpp : Defines the entry point for the console application.
  5.  
  6. #include "stdafx.h"
  7. #include <time.h>
  8. #define _USE_MATH_DEFINES
  9. #include <cmath>
  10. #include <GL/glew.h>
  11. #include <GL\glut.h>
  12. #include <GLFW/glfw3.h>
  13. #include <vector>
  14. #include <algorithm>
  15. #include <cstdlib>
  16.  
  17. int SCREEN_WIDTH = 800, SCREEN_HEIGHT = 600;
  18.  
  19. #define SCREEN_POS_X        100
  20. #define SCREEN_POS_Y        100
  21.  
  22. #define DATA_FORMAT         3
  23. #define BUFFER_SIZE         SCREEN_WIDTH*SCREEN_HEIGHT*DATA_FORMAT
  24. #define PXL_INDX(X,Y,COMP) (((Y)*SCREEN_WIDTH+(X))*DATA_FORMAT+(COMP))
  25.  
  26. typedef struct point{
  27.     int x, y;
  28.     bool extremum;
  29.     point* incident_next;
  30.     point* incident_prev;
  31. } point;
  32.  
  33. typedef struct edge{
  34.     point a, b;
  35.     edge* incident_e_next;
  36.     edge* incident_e_prev;
  37. }edge;
  38.  
  39. bool draw_flag, fill_flag, anti_aliacing_flag, update_flag, thick_flag, clear_flag;
  40. int x_max, x_min, y_max, y_min;
  41.  
  42. GLfloat *contour;
  43. GLfloat *intrails;
  44. GLfloat *blur;
  45.  
  46. std::vector<point> vertices;
  47. std::vector<edge> edges;
  48. std::vector<std::vector<int>> edge_table;
  49.  
  50.  
  51.  
  52. bool extremum(int x, int y)
  53. {
  54.     for (int i = 0; i < vertices.size(); i++) {
  55.         if (vertices[i].x == x && vertices[i].y == y) {
  56.             return vertices[i].extremum;
  57.         }
  58.     }
  59.  
  60.     return false;
  61. }
  62.  
  63. void changeSize(int w, int h)
  64. {
  65.     if (0 == h) h = 1;
  66.  
  67.     float ratio = w * 1.0 / h;
  68.  
  69.     // Use the Projection Matrix
  70.     glMatrixMode(GL_PROJECTION);
  71.  
  72.     // Reset Matrix
  73.     glLoadIdentity();
  74.  
  75.     // Set the viewport to be the entire window
  76.     glViewport(0, 0, w, h);
  77.  
  78.     // Set the correct perspective.
  79.     gluOrtho2D(0, (GLdouble)w, 0, (GLdouble)h);
  80.  
  81.     // Get Back to the Modelview
  82.     glMatrixMode(GL_MODELVIEW);
  83. }
  84.  
  85. void clear_vector(std::vector<point>& vector)
  86. {
  87.     vector.clear();
  88.     vector.shrink_to_fit();
  89. }
  90.  
  91. void clear_buffers()
  92. {
  93.     delete[] contour;
  94.     delete[] intrails;
  95.     delete[] blur;
  96. }
  97.  
  98. void copy_buffer(GLfloat *buff_source, GLfloat *buff_dest)
  99. {
  100.     for (int i = 0; i < BUFFER_SIZE; i++) {
  101.         buff_dest[i] = buff_source[i];
  102.     }
  103. }
  104.  
  105. void create_buffers()
  106. {
  107.     contour = new GLfloat[BUFFER_SIZE];
  108.     intrails = new GLfloat[BUFFER_SIZE];
  109.     blur = new GLfloat[BUFFER_SIZE];
  110. }
  111.  
  112. void figure_pos()
  113. {
  114.     int max_x = 0, min_x = SCREEN_WIDTH;
  115.     int max_y = 0, min_y = SCREEN_HEIGHT;
  116.  
  117.     for (int i = 0; i < vertices.size(); i++) {
  118.         if (vertices[i].x > max_x) max_x = vertices[i].x;
  119.         if (vertices[i].x < min_x) min_x = vertices[i].x;
  120.         if (vertices[i].y > max_y) max_y = vertices[i].y;
  121.         if (vertices[i].y < min_y) min_y = vertices[i].y;
  122.     }
  123.  
  124.     x_max = max_x;
  125.     x_min = min_x;
  126.     y_max = max_y;
  127.     y_min = min_y;
  128. }
  129.  
  130.  
  131. //===========================DRAWING===========================
  132. void Bresenham(int x1, int y1, int const x2, int const y2)
  133. {
  134.     int delta_x(x2 - x1);
  135.     // if x1 == x2, then it does not matter what we set here
  136.     signed char const ix((delta_x > 0) - (delta_x < 0));
  137.     delta_x = std::abs(delta_x) << 1;
  138.  
  139.     int delta_y(y2 - y1);
  140.     // if y1 == y2, then it does not matter what we set here
  141.     signed char const iy((delta_y > 0) - (delta_y < 0));
  142.     delta_y = std::abs(delta_y) << 1;
  143.  
  144.  
  145.  
  146.     //plot(x1, y1);
  147.     for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1, i)] = 1;
  148.     //========================================
  149.     if (thick_flag) {
  150.         for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 + 1, i)] = 1;
  151.         for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 + 1, i)] = 1;
  152.         for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 + 1, i)] = 1;
  153.         for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1, i)] = 1;
  154.         for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1, i)] = 1;
  155.         for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 - 1, i)] = 1;
  156.         for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 - 1, i)] = 1;
  157.         for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 - 1, i)] = 1;
  158.     }
  159.     //========================================
  160.  
  161.  
  162.  
  163.     if (delta_x >= delta_y)
  164.     {
  165.         // error may go below zero
  166.         int error(delta_y - (delta_x >> 1));
  167.  
  168.         while (x1 != x2)
  169.         {
  170.             if ((error >= 0) && (error || (ix > 0)))
  171.             {
  172.                 error -= delta_x;
  173.                 y1 += iy;
  174.             }
  175.             // else do nothing
  176.  
  177.             error += delta_y;
  178.             x1 += ix;
  179.  
  180.  
  181.             //plot(x1, y1);
  182.             for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1, i)] = 1;
  183.             //========================================
  184.             if (thick_flag) {
  185.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 + 1, i)] = 1;
  186.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 + 1, i)] = 1;
  187.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 + 1, i)] = 1;
  188.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1, i)] = 1;
  189.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1, i)] = 1;
  190.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 - 1, i)] = 1;
  191.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 - 1, i)] = 1;
  192.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 - 1, i)] = 1;
  193.             }
  194.             //========================================
  195.         }
  196.     }
  197.     else
  198.     {
  199.         // error may go below zero
  200.         int error(delta_x - (delta_y >> 1));
  201.  
  202.         while (y1 != y2)
  203.         {
  204.             if ((error >= 0) && (error || (iy > 0)))
  205.             {
  206.                 error -= delta_y;
  207.                 x1 += ix;
  208.             }
  209.             // else do nothing
  210.  
  211.             error += delta_x;
  212.             y1 += iy;
  213.  
  214.  
  215.  
  216.             //plot(x1, y1);
  217.             for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1, i)] = 1;
  218.             //========================================
  219.             if (thick_flag) {
  220.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 + 1, i)] = 1;
  221.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 + 1, i)] = 1;
  222.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 + 1, i)] = 1;
  223.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1, i)] = 1;
  224.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1, i)] = 1;
  225.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 - 1, i)] = 1;
  226.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 - 1, i)] = 1;
  227.                 for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 - 1, i)] = 1;
  228.             }
  229.             //========================================
  230.         }
  231.     }
  232. }
  233.  
  234. void set_contour()//D
  235. {
  236.     for (int i = 0; i < vertices.size() - 1; i++)
  237.         Bresenham(vertices[i].x, vertices[i].y, vertices[i + 1].x, vertices[i + 1].y);
  238. }
  239.  
  240. void draw_contour()
  241. {
  242.     glDrawPixels(SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_FLOAT, (void*)contour);
  243. }
  244.  
  245.  
  246. //===========================FILLING===========================
  247. void intersect_counter(int x1, int y1, int const x2, int const y2)
  248. {
  249.     int prev, curr;
  250.     prev = y1;
  251.     curr = y1;
  252.  
  253.     int delta_x(x2 - x1);
  254.     signed char const ix((delta_x > 0) - (delta_x < 0));
  255.     delta_x = std::abs(delta_x) << 1;
  256.  
  257.     int delta_y(y2 - y1);
  258.     signed char const iy((delta_y > 0) - (delta_y < 0));
  259.     delta_y = std::abs(delta_y) << 1;
  260.  
  261.     if (extremum(x1, y1)) {
  262.         //edge_table[y1 - y_min].push_back(x1);
  263.         //edge_table[y1 - y_min].push_back(x1);
  264.     }
  265.     else {
  266.         //edge_table[y1 - y_min].push_back(x1);
  267.     }
  268.  
  269.     if (delta_x >= delta_y)
  270.     {
  271.         int error(delta_y - (delta_x >> 1));
  272.         while (x1 != x2)
  273.         {
  274.             if ((error >= 0) && (error || (ix > 0)))
  275.             {
  276.                 error -= delta_x;
  277.                 y1 += iy;
  278.                 curr = y1;
  279.             }
  280.             error += delta_y;
  281.             x1 += ix;
  282.  
  283.             if (curr != prev) {
  284.                 if (extremum(x1, y1)) {
  285.                     edge_table[y1 - y_min].push_back(x1);
  286.                     edge_table[y1 - y_min].push_back(x1);
  287.                 }
  288.                 else {
  289.                     edge_table[y1 - y_min].push_back(x1);
  290.                 }
  291.             }
  292.             prev = curr;
  293.         }
  294.     }
  295.     else
  296.     {
  297.         int error(delta_x - (delta_y >> 1));
  298.         while (y1 != y2)
  299.         {
  300.             if ((error >= 0) && (error || (iy > 0)))
  301.             {
  302.                 error -= delta_y;
  303.                 x1 += ix;
  304.             }
  305.             error += delta_x;
  306.             y1 += iy;
  307.  
  308.             if (extremum(x1, y1)) {
  309.                 edge_table[y1 - y_min].push_back(x1);
  310.                 edge_table[y1 - y_min].push_back(x1);
  311.             }
  312.             else {
  313.                 edge_table[y1 - y_min].push_back(x1);
  314.             }
  315.         }
  316.     }
  317. }
  318.  
  319. void set_vertices()
  320. {
  321.     int i;
  322.  
  323.     //for 0th vertex
  324.     vertices[0].extremum = false;
  325.     vertices[0].incident_next = &vertices[1];
  326.     vertices[0].incident_prev = &vertices[vertices.size() - 1];
  327.  
  328.     //for other vertices
  329.     for (i = 1; i < vertices.size(); i++) {
  330.         vertices[i].incident_next = &vertices[(i + 1) % vertices.size()];
  331.         vertices[i].incident_prev = &vertices[i - 1];
  332.         vertices[i].extremum = false;
  333.     }
  334.  
  335.     //find extermums
  336.     for (i = 0; i < vertices.size(); i++) {
  337.         if (
  338.             ((*vertices[i].incident_next).y > vertices[i].y && (*vertices[i].incident_prev).y > vertices[i].y) ||
  339.             ((*vertices[i].incident_next).y < vertices[i].y && (*vertices[i].incident_prev).y < vertices[i].y)
  340.             ) {
  341.             vertices[i].extremum = true;
  342.         }
  343.  
  344.     }
  345. }
  346.  
  347. void init_edges()
  348. {
  349.     edge temp_edge;
  350.  
  351.     for (int i = 0; i < vertices.size(); i++) {
  352.         temp_edge.a = vertices[i];
  353.         temp_edge.b = vertices[(i + 1) % vertices.size()];
  354.  
  355.         edges.push_back(temp_edge);
  356.     }
  357. }
  358.  
  359. void set_edges()//F
  360. {
  361.     set_vertices();
  362.  
  363.     init_edges();
  364.  
  365.     int i;
  366.    
  367.     edge_table.resize(y_max);
  368.  
  369.     for (i = 0; i < edge_table.size(); i++)
  370.         edge_table[i].resize(0);
  371.    
  372.     for (i = 0; i < vertices.size(); i++)
  373.         intersect_counter(vertices[i].x, vertices[i].y, vertices[(i + 1) % vertices.size()].x, vertices[(i + 1) % vertices.size()].y);
  374.  
  375.     for (i = 0; i < edge_table.size(); i++)
  376.         std::sort(edge_table[i].begin(), edge_table[i].end());
  377. }
  378.  
  379. void set_intrails_pixels()
  380. {
  381.     int i, j, z, a;
  382.  
  383.     for (i = 0; i < edge_table.size(); i++) {
  384.         if (edge_table[i].size() % 2 == 0 && 0 != edge_table[i].size()) {
  385.             for (j = 0; j < edge_table[i].size() - 1; j += 2) {
  386.                 int start_filling = edge_table[i][j];
  387.                 int stop_filling = edge_table[i][j + 1];
  388.                 for (z = start_filling; z < stop_filling; z++) {
  389.                     for (a = 0; a < 3; a++) {
  390.                         intrails[PXL_INDX(z, i + y_min, a)] = 1;
  391.                     }
  392.                 }
  393.             }
  394.         }
  395.     }
  396. }
  397.  
  398. void draw_intrails()
  399. {
  400.     glDrawPixels(SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_FLOAT, (void*)intrails);
  401. }
  402.  
  403.  
  404. //===========================BLUR===========================
  405. void postfiltration()//S
  406. {
  407.     int i, j, k, x, y, num;
  408.     GLfloat r, g, b;
  409.  
  410.     //copy_buffer(contour, blur);
  411.  
  412.     for (y = 0; y < SCREEN_HEIGHT; y++) {
  413.         for (x = 0; x < SCREEN_WIDTH; x++) {
  414.             r = 0;
  415.             g = 0;
  416.             b = 0;
  417.             num = 0;
  418.  
  419.             if (x + 1 < SCREEN_WIDTH && y + 1 < SCREEN_HEIGHT) {
  420.                 num++;
  421.                 r += intrails[PXL_INDX(x + 1, y + 1, 0)];
  422.                 g += intrails[PXL_INDX(x + 1, y + 1, 1)];
  423.                 b += intrails[PXL_INDX(x + 1, y + 1, 2)];
  424.             }
  425.             if (y + 1 < SCREEN_HEIGHT) {
  426.                 num++;
  427.                 r += intrails[PXL_INDX(x, y + 1, 0)];
  428.                 g += intrails[PXL_INDX(x, y + 1, 1)];
  429.                 b += intrails[PXL_INDX(x, y + 1, 2)];
  430.             }
  431.             if (x - 1 > 0 && y + 1 < SCREEN_HEIGHT) {
  432.                 num++;
  433.                 r += intrails[PXL_INDX(x - 1, y + 1, 0)];
  434.                 g += intrails[PXL_INDX(x - 1, y + 1, 1)];
  435.                 b += intrails[PXL_INDX(x - 1, y + 1, 2)];
  436.             }
  437.  
  438.             if (x + 1 < SCREEN_WIDTH) {
  439.                 num++;
  440.                 r += intrails[PXL_INDX(x + 1, y, 0)];
  441.                 g += intrails[PXL_INDX(x + 1, y, 1)];
  442.                 b += intrails[PXL_INDX(x + 1, y, 2)];
  443.             }
  444.             if (1) {
  445.                 num++;
  446.                 r += intrails[PXL_INDX(x, y, 0)];
  447.                 g += intrails[PXL_INDX(x, y, 1)];
  448.                 b += intrails[PXL_INDX(x, y, 2)];
  449.             }
  450.             if (x - 1 > 0) {
  451.                 num++;
  452.                 r += intrails[PXL_INDX(x - 1, y, 0)];
  453.                 g += intrails[PXL_INDX(x - 1, y, 1)];
  454.                 b += intrails[PXL_INDX(x - 1, y, 2)];
  455.             }
  456.  
  457.             if (x + 1 < SCREEN_WIDTH && y - 1 > 0) {
  458.                 num++;
  459.                 r += intrails[PXL_INDX(x + 1, y - 1, 0)];
  460.                 g += intrails[PXL_INDX(x + 1, y - 1, 1)];
  461.                 b += intrails[PXL_INDX(x + 1, y - 1, 2)];
  462.             }
  463.             if (y - 1 > 0) {
  464.                 num++;
  465.                 r += intrails[PXL_INDX(x, y - 1, 0)];
  466.                 g += intrails[PXL_INDX(x, y - 1, 1)];
  467.                 b += intrails[PXL_INDX(x, y - 1, 2)];
  468.             }
  469.             if (x - 1 > 0 && y - 1 > 0) {
  470.                 num++;
  471.                 r += intrails[PXL_INDX(x - 1, y - 1, 0)];
  472.                 g += intrails[PXL_INDX(x - 1, y - 1, 1)];
  473.                 b += intrails[PXL_INDX(x - 1, y - 1, 2)];
  474.             }
  475.  
  476.             blur[PXL_INDX(x, y, 0)] = r / (GLfloat)num;
  477.             blur[PXL_INDX(x, y, 1)] = g / (GLfloat)num;
  478.             blur[PXL_INDX(x, y, 2)] = b / (GLfloat)num;
  479.            
  480.         }
  481.  
  482.     }
  483.  
  484.  
  485. //radiance goes here. its not necessary for lab
  486.     /*
  487.     for (y = 0; y < SCREEN_HEIGHT; y++) {
  488.         for (x = 0; x < SCREEN_WIDTH; x++) {
  489.             if (contour[PXL_INDX(x, y, 0)] == 1 &&
  490.                 contour[PXL_INDX(x, y, 1)] == 1 &&
  491.                 contour[PXL_INDX(x, y, 2)] == 1
  492.                 ) {
  493.                 for (i = 0; i < 3; i++) {
  494.                     blur[PXL_INDX(x, y, i)] = 1;
  495.                 }
  496.             }
  497.         }
  498.     }*/
  499. }
  500.  
  501. void draw_blur()//S
  502. {
  503.     glDrawPixels(SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_FLOAT, (void*)blur);
  504. }
  505.  
  506.  
  507. //===========================MAIN===========================
  508. void renderScene(void)
  509. {
  510.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  511.  
  512.     if (draw_flag) {
  513.         if (0 != vertices.size()) {
  514.             set_contour();
  515.             draw_contour();
  516.         }
  517.     }
  518.  
  519.     if (fill_flag) {
  520.         set_edges();
  521.         set_intrails_pixels();
  522.         draw_intrails();
  523.     }
  524.  
  525.     if (anti_aliacing_flag) {
  526.         postfiltration();
  527.         draw_blur();
  528.     }
  529.     if (clear_flag) {
  530.         clear_buffers();
  531.         clear_vector(vertices);
  532.     }
  533.  
  534.     glutSwapBuffers();
  535. }
  536.  
  537. void mouseButton(int button, int state, int x, int y)
  538. {
  539.     if (GLUT_LEFT_BUTTON == button) {
  540.         point a;
  541.         if (GLUT_DOWN == state) {
  542.             a.x = x;
  543.             a.y = SCREEN_HEIGHT - y;
  544.             printf("%d %d\n", a.x, a.y);
  545.             vertices.push_back(a);
  546.             figure_pos();
  547.             glutPostRedisplay();
  548.         }
  549.         if (GLUT_UP == state) {
  550.             glutPostRedisplay();
  551.         }
  552.     }
  553. }
  554.  
  555. void keyboardButton(unsigned char key, int x, int y)
  556. {
  557.     if ('d' == key || 'D' == key) {
  558.         draw_flag = !draw_flag;
  559.         figure_pos();
  560.         printf("x_min=%d x_max=%d\ny_min=%d y_max=%d\n", x_min, x_max, y_min, y_max);
  561.         draw_flag ? printf("drawing:ON\n") : printf("drawing:OFF\n");
  562.         glutPostRedisplay();
  563.     }
  564.     if ('s' == key || 'S' == key) {
  565.         anti_aliacing_flag = !anti_aliacing_flag;
  566.         anti_aliacing_flag ? printf("PS4 / Xbox ONE mode\n") : printf("PC mode\n");
  567.         glutPostRedisplay();
  568.     }
  569.     if ('f' == key || 'F' == key) {
  570.         fill_flag = !fill_flag;
  571.         figure_pos();
  572.         fill_flag ? printf("filling:ON\n") : printf("filling:OFF\n");
  573.         glutPostRedisplay();
  574.     }
  575.     /*if ('z' == key || 'Z' == key) {
  576.         if (0 < vertices.size()) {
  577.             vertices.pop_back();
  578.             figure_pos();
  579.             glutPostRedisplay();
  580.         }
  581.     }*/
  582.     if ('a' == key || 'A' == key) {
  583.         Bresenham(vertices[vertices.size() - 1].x, vertices[vertices.size() - 1].y, vertices[0].x, vertices[0].y);
  584.         glutPostRedisplay();
  585.     }
  586.     if ('q' == key || 'Q' == key) {
  587.         thick_flag = !thick_flag;
  588.         thick_flag ? printf("thick lines:ON\n") : printf("thick lines:OFF\n");
  589.         glutPostRedisplay();
  590.     }
  591.     if ('w' == key || 'W' == key) {
  592.         clear_flag = !clear_flag;
  593.         printf("cleared\n");
  594.         glutPostRedisplay();
  595.     }
  596.     if ('t' == key || 'T' == key) {
  597.         printf("table_size=%d\n", edge_table.size());
  598.         for (int i = 0; i < edge_table.size(); i++) {
  599.             printf("[%d](%d):", i, edge_table[i].size());
  600.             for (int j = 0; j < edge_table[i].size(); j++) {
  601.                 printf("%d ", edge_table[i][j]);
  602.             }
  603.             printf(" -> ");
  604.             if (edge_table[i].size() % 2 == 0 && 0 != edge_table[i].size()) {
  605.                 for (int j = 0; j < edge_table[i].size() - 1; j += 2) {
  606.                     int start = edge_table[i][j];
  607.                     int stop = edge_table[i][j + 1];
  608.                     printf("%d..%d ", start, stop);
  609.                 }
  610.                
  611.             }
  612.             else {
  613.                 printf("MISTAKE");
  614.             }
  615.             printf("\n");
  616.         }
  617.  
  618.         printf("vertices:\n");
  619.         for (int i = 0; i < vertices.size(); i++) {
  620.             printf("(%d)", i);
  621.             if (vertices[i].extremum == true) {
  622.                 printf("extremum\n");
  623.             }
  624.             else {
  625.                 printf("normal\n");
  626.             }
  627.         }
  628.         glutPostRedisplay();
  629.     }
  630. }
  631.  
  632. void initial_state()
  633. {
  634.     glClearColor(0, 0, 0, 1);
  635.  
  636.     draw_flag = false;
  637.     fill_flag = false;
  638.     anti_aliacing_flag = false;
  639.     update_flag = false;
  640.     thick_flag = false;
  641.  
  642.     thick_flag ? printf("thick lines:ON\n") : printf("thick lines:OFF\n");
  643.  
  644.     x_max = 0;
  645.     x_min = SCREEN_WIDTH;
  646.     y_max = 0;
  647.     y_min = SCREEN_HEIGHT;
  648.  
  649.     create_buffers();
  650.     clear_buffers();
  651. }
  652.  
  653. int main(int argc, char **argv)
  654. {
  655.     glutInit(&argc, argv);
  656.     glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  657.     glutInitWindowPosition(SCREEN_POS_X, SCREEN_POS_Y);
  658.     glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  659.     glutCreateWindow("Anthony's Project: Lab 4");
  660.  
  661.     glutDisplayFunc(renderScene);
  662.     glutReshapeFunc(changeSize);
  663.     glutIdleFunc(renderScene);
  664.  
  665.     glutMouseFunc(mouseButton);
  666.     glutKeyboardFunc(keyboardButton);
  667.  
  668.     initial_state();
  669.  
  670.     glutMainLoop();
  671.  
  672.     return 0;
  673. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement