SHARE
TWEET

Untitled

a guest May 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. surface::surface(const grid_info &grid,
  2.                  std::function<double(double, double)> &f)
  3.     : m_grid(grid) {
  4.   m_geom_ptr = new triangle();
  5.  
  6.   double ratio, log_ratio;
  7.   if (grid.n > RESOLUTION) {
  8.     m_grid.n = grid.n;
  9.     m_grid.n_cut = grid.n_cut;
  10.   } else {
  11.     ratio = (RESOLUTION * 1.) / grid.n;
  12.     log_ratio = log2(ratio);
  13.     m_grid.n = grid.n * (int)(pow(2., ceil(log_ratio)));
  14.     m_grid.n_cut = grid.n_cut * (int)(pow(2., ceil(log_ratio)));
  15.   }
  16.  
  17.   if (grid.m > RESOLUTION) {
  18.     m_grid.m = grid.m;
  19.     m_grid.m_cut = grid.m_cut;
  20.   } else {
  21.     ratio = (RESOLUTION * 1.) / grid.m;
  22.     log_ratio = log2(ratio);
  23.     m_grid.m = grid.m * (int)(pow(2., ceil(log_ratio)));
  24.     m_grid.m_cut = grid.m_cut * (int)(pow(2., ceil(log_ratio)));
  25.   }
  26.  
  27.   point_numb = get_matrix_size(m_grid.n, m_grid.n_cut, m_grid.m, m_grid.m_cut);
  28.  
  29.   int i, j;
  30.   float dx = m_grid.w.x() / m_grid.n;
  31.   float dy = m_grid.w.y() / m_grid.m;
  32.   printf("m %d n %d\n", m_grid.m, m_grid.n);
  33.   bool is_first = true;
  34.   float f0, f1, f2, f3;
  35.   for (i = 0; i < m_grid.n; i++) {
  36.     if (i < m_grid.n_cut)
  37.       j = m_grid.m_cut;
  38.     else
  39.       j = 0;
  40.     for (; j < m_grid.m; j++) {
  41.       float x = i * dx;
  42.       float y = j * dy;
  43.       f0 = (float)f(x, y);
  44.       f1 = (float)f(x + dx, y);
  45.       f2 = (float)f(x + dx, y + dy);
  46.       f3 = (float)f(x, y + dy);
  47.  
  48.       if (is_first) {
  49.         max_val = f0;
  50.         min_val = f0;
  51.         is_first = false;
  52.       }
  53.  
  54.       if (f1 > max_val)
  55.         max_val = f1;
  56.       if (f1 < min_val)
  57.         min_val = f1;
  58.  
  59.       if (f2 > max_val)
  60.         max_val = f2;
  61.       if (f2 < min_val)
  62.         min_val = f2;
  63.  
  64.       if (f3 > max_val)
  65.         max_val = f3;
  66.       if (f3 < min_val)
  67.         min_val = f3;
  68.  
  69.       if (f0 > max_val)
  70.         max_val = f0;
  71.       if (f0 < min_val)
  72.         min_val = f0;
  73.  
  74.       m_geom_ptr->add_triangle({x, y, f0}, {x + dx, y, f1},
  75.                                {x + dx, y + dy, f2});
  76.       m_geom_ptr->add_triangle({x, y, f0}, {x + dx, y + dy, f2},
  77.                                {x, y + dy, f3});
  78.  
  79.     }
  80.   }
  81.   printf("aaaaaaaaaaaaa\n");
  82. }
  83.  
  84. void surface::change_triangle(int i, int j, QVector4D &vals) {
  85.   QVector3D *a, *b, *c;
  86.   int pos = get_triangle_pos_in_buffer_by_i_j(m_grid, i, j);
  87.   a = m_geom_ptr->get_point_at_index(pos);
  88.   b = m_geom_ptr->get_point_at_index(pos + 1);
  89.   c = m_geom_ptr->get_point_at_index(pos + 2);
  90.   a->setZ(vals.x());
  91.   b->setZ(vals.y());
  92.   c->setZ(vals.z());
  93.   QVector3D normal = QVector3D::normal(*a, *b, *c);
  94.   *(m_geom_ptr->get_normal_at_index(pos)) = normal;
  95.   *(m_geom_ptr->get_normal_at_index(pos + 1)) = normal;
  96.   *(m_geom_ptr->get_normal_at_index(pos + 2)) = normal;
  97.  
  98.   a = m_geom_ptr->get_point_at_index(pos + 3);
  99.   b = m_geom_ptr->get_point_at_index(pos + 4);
  100.   c = m_geom_ptr->get_point_at_index(pos + 5);
  101.   a->setZ(vals.x());
  102.   b->setZ(vals.z());
  103.   c->setZ(vals.w());
  104.   normal = QVector3D::normal(*a, *b, *c);
  105.   *(m_geom_ptr->get_normal_at_index(pos + 3)) = normal;
  106.   *(m_geom_ptr->get_normal_at_index(pos + 4)) = normal;
  107.   *(m_geom_ptr->get_normal_at_index(pos + 5)) = normal;
  108. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top