Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- surface::surface(const grid_info &grid,
- std::function<double(double, double)> &f)
- : m_grid(grid) {
- m_geom_ptr = new triangle();
- double ratio, log_ratio;
- if (grid.n > RESOLUTION) {
- m_grid.n = grid.n;
- m_grid.n_cut = grid.n_cut;
- } else {
- ratio = (RESOLUTION * 1.) / grid.n;
- log_ratio = log2(ratio);
- m_grid.n = grid.n * (int)(pow(2., ceil(log_ratio)));
- m_grid.n_cut = grid.n_cut * (int)(pow(2., ceil(log_ratio)));
- }
- if (grid.m > RESOLUTION) {
- m_grid.m = grid.m;
- m_grid.m_cut = grid.m_cut;
- } else {
- ratio = (RESOLUTION * 1.) / grid.m;
- log_ratio = log2(ratio);
- m_grid.m = grid.m * (int)(pow(2., ceil(log_ratio)));
- m_grid.m_cut = grid.m_cut * (int)(pow(2., ceil(log_ratio)));
- }
- point_numb = get_matrix_size(m_grid.n, m_grid.n_cut, m_grid.m, m_grid.m_cut);
- int i, j;
- float dx = m_grid.w.x() / m_grid.n;
- float dy = m_grid.w.y() / m_grid.m;
- printf("m %d n %d\n", m_grid.m, m_grid.n);
- bool is_first = true;
- float f0, f1, f2, f3;
- for (i = 0; i < m_grid.n; i++) {
- if (i < m_grid.n_cut)
- j = m_grid.m_cut;
- else
- j = 0;
- for (; j < m_grid.m; j++) {
- float x = i * dx;
- float y = j * dy;
- f0 = (float)f(x, y);
- f1 = (float)f(x + dx, y);
- f2 = (float)f(x + dx, y + dy);
- f3 = (float)f(x, y + dy);
- if (is_first) {
- max_val = f0;
- min_val = f0;
- is_first = false;
- }
- if (f1 > max_val)
- max_val = f1;
- if (f1 < min_val)
- min_val = f1;
- if (f2 > max_val)
- max_val = f2;
- if (f2 < min_val)
- min_val = f2;
- if (f3 > max_val)
- max_val = f3;
- if (f3 < min_val)
- min_val = f3;
- if (f0 > max_val)
- max_val = f0;
- if (f0 < min_val)
- min_val = f0;
- m_geom_ptr->add_triangle({x, y, f0}, {x + dx, y, f1},
- {x + dx, y + dy, f2});
- m_geom_ptr->add_triangle({x, y, f0}, {x + dx, y + dy, f2},
- {x, y + dy, f3});
- }
- }
- printf("aaaaaaaaaaaaa\n");
- }
- void surface::change_triangle(int i, int j, QVector4D &vals) {
- QVector3D *a, *b, *c;
- int pos = get_triangle_pos_in_buffer_by_i_j(m_grid, i, j);
- a = m_geom_ptr->get_point_at_index(pos);
- b = m_geom_ptr->get_point_at_index(pos + 1);
- c = m_geom_ptr->get_point_at_index(pos + 2);
- a->setZ(vals.x());
- b->setZ(vals.y());
- c->setZ(vals.z());
- QVector3D normal = QVector3D::normal(*a, *b, *c);
- *(m_geom_ptr->get_normal_at_index(pos)) = normal;
- *(m_geom_ptr->get_normal_at_index(pos + 1)) = normal;
- *(m_geom_ptr->get_normal_at_index(pos + 2)) = normal;
- a = m_geom_ptr->get_point_at_index(pos + 3);
- b = m_geom_ptr->get_point_at_index(pos + 4);
- c = m_geom_ptr->get_point_at_index(pos + 5);
- a->setZ(vals.x());
- b->setZ(vals.z());
- c->setZ(vals.w());
- normal = QVector3D::normal(*a, *b, *c);
- *(m_geom_ptr->get_normal_at_index(pos + 3)) = normal;
- *(m_geom_ptr->get_normal_at_index(pos + 4)) = normal;
- *(m_geom_ptr->get_normal_at_index(pos + 5)) = normal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement