8 Mesh&
Mesh::grid2D(Eigen::Vector2f extents, Eigen::Vector2i numPoints,
9 std::function<
viz::Color(
size_t,
size_t,
const Eigen::Vector3f&)> colorFunc)
21 Mesh&
Mesh::grid2D(
const std::vector<std::vector<Eigen::Vector3f> >& vertices,
22 const std::vector<std::vector<viz::data::Color>>& colors)
31 const size_t num_x =
vertices.size();
32 const size_t num_y =
vertices.front().size();
57 Eigen::Vector2f extents, Eigen::Vector2i numPoints,
float height)
59 const Eigen::Vector2f minimum = - extents / 2;
62 const Eigen::Vector2f step = (extents.array() / (numPoints.array() - 1).cast<float>()).matrix();
65 const size_t num_x = size_t(numPoints.x());
66 const size_t num_y = size_t(numPoints.y());
69 std::vector<std::vector<Eigen::Vector3f>> gridVertices(
70 num_x, std::vector<Eigen::Vector3f>(num_y, Eigen::Vector3f::Zero()));
72 for (
size_t i = 0; i < num_x; i++)
74 for (
size_t j = 0; j < num_y; j++)
76 gridVertices[i][j].x() = minimum.x() + i * step.x();
77 gridVertices[i][j].y() = minimum.y() + j * step.y();
78 gridVertices[i][j].z() = height;
87 const std::vector<std::vector<Eigen::Vector3f> >& vertices,
88 std::function<
viz::Color(
size_t x,
size_t y,
const Eigen::Vector3f& p)> colorFunc)
90 size_t num_x = vertices.size();
91 size_t num_y = vertices.front().size();
93 std::vector<std::vector<viz::data::Color>> colors(
96 for (
size_t i = 0; i < num_x; i++)
98 for (
size_t j = 0; j < num_y; j++)
100 colors[i][j] = colorFunc(i, j, vertices[i][j]);
110 std::vector<viz::data::Face> faces(2 * (num_x - 1) * (num_y - 1));
113 for (
size_t x = 0; x < num_x - 1; x++)
115 for (
size_t y = 0; y < num_y - 1; y++)
124 faces[
index].v0 = faces[
index].c0 = int(x * num_y + y);
125 faces[
index].v1 = faces[
index].c1 = int((x + 1) * num_y + (y + 1));
126 faces[
index].v2 = faces[
index].c2 = int((x + 1) * num_y + y);
129 faces[
index].v0 = faces[
index].c0 = int(x * num_y + y);
130 faces[
index].v1 = faces[
index].c1 = int(x * num_y + (y + 1));
131 faces[
index].v2 = faces[
index].c2 = int((x + 1) * num_y + (y + 1));