mod_geo-tp/src/quad_patch.cpp

47 lines
1.5 KiB
C++
Raw Normal View History

2021-11-12 17:08:19 +01:00
#include "quad_patch.h"
MyMesh quad_patch(MyQuad q, MyMesh mesh, VertexHandle vh) {
MyMesh patch;
Eigen::Vector3d point
(mesh.point(vh)[0], mesh.point(vh)[1], mesh.point(vh)[2]);
Eigen::Transform<double, 3, Eigen::Affine> ch_base = q._r * q._t;
Eigen::Transform<double, 3, Eigen::Affine> inv_ch_base = ch_base.inverse();
point = ch_base * point;
double xmin = point[0], xmax = point[0];
double ymin = point[1], ymax = point[1];
for (VertexHandle vi : mesh.vv_range(vh)) {
Eigen::Vector3d point
(mesh.point(vi)[0], mesh.point(vi)[1], mesh.point(vi)[2]);
point = ch_base * point;
xmin = std::min(xmin, point[0]);
xmax = std::max(xmax, point[0]);
ymin = std::min(ymin, point[1]);
ymax = std::max(ymax, point[1]);
}
double xstep = (xmax-xmin)/64.;
double ystep = (ymax-ymin)/64.;
for (size_t y = 0; y < 64; y++) {
for (size_t x = 0; x < 64; x++) {
double dx = xmin + x * xstep;
double dy = ymin + y * ystep;
Eigen::Vector3d point(dx, dy, -q.quad_fun(dx, dy));
point = inv_ch_base * point;
patch.new_vertex(Point(point[0], point[1], point[2]));
}
}
for (VertexHandle vhi : patch.vertices()) {
patch.set_color(vhi, MyMesh::Color(0, 1, .2));
size_t i = vhi.idx();
size_t x = i % 64;
size_t y = i / 64;
if (x == 63 || y == 63) continue;
patch.add_face(vhi, patch.vertex_handle(i + 64),
patch.vertex_handle(i + 1));
patch.add_face(patch.vertex_handle(i + 1),
patch.vertex_handle(i + 64),
patch.vertex_handle(i + 65));
}
return patch;
}