9 Eigen::Vector2i numPoints,
10 std::function<viz::Color(
size_t,
size_t,
const Eigen::Vector3f&)> colorFunc)
13 std::vector<std::vector<Eigen::Vector3f>>
vertices =
17 std::vector<std::vector<viz::data::Color>>
colors =
25 const std::vector<std::vector<viz::data::Color>>&
colors)
28 <<
"Numbers of vertices and colors must match.";
35 const size_t num_x =
vertices.size();
36 const size_t num_y =
vertices.front().size();
45 <<
"All nested vectors must have equal length.";
50 <<
"All nested vectors must have equal length.";
61 std::vector<std::vector<Eigen::Vector3f>>
64 const Eigen::Vector2f minimum = -extents / 2;
67 const Eigen::Vector2f step =
68 (extents.array() / (numPoints.array() - 1).cast<
float>()).matrix();
71 <<
"Number of points must be positive. " <<
VAROUT(numPoints);
72 const size_t num_x = size_t(numPoints.x());
73 const size_t num_y = size_t(numPoints.y());
76 std::vector<std::vector<Eigen::Vector3f>> gridVertices(
77 num_x, std::vector<Eigen::Vector3f>(num_y, Eigen::Vector3f::Zero()));
79 for (
size_t i = 0; i < num_x; i++)
81 for (
size_t j = 0; j < num_y; j++)
83 gridVertices[i][j].x() = minimum.x() + i * step.x();
84 gridVertices[i][j].y() = minimum.y() + j * step.y();
85 gridVertices[i][j].z() = height;
92 std::vector<std::vector<viz::data::Color>>
94 const std::vector<std::vector<Eigen::Vector3f>>& vertices,
95 std::function<
viz::Color(
size_t x,
size_t y,
const Eigen::Vector3f& p)> colorFunc)
97 size_t num_x = vertices.size();
98 size_t num_y = vertices.front().size();
100 std::vector<std::vector<viz::data::Color>> colors(
101 num_x, std::vector<viz::data::Color>(num_y, viz::Color::black()));
103 for (
size_t i = 0; i < num_x; i++)
105 for (
size_t j = 0; j < num_y; j++)
107 colors[i][j] = colorFunc(i, j, vertices[i][j]);
114 std::vector<viz::data::Face>
117 std::vector<viz::data::Face> faces(2 * (num_x - 1) * (num_y - 1));
120 for (
size_t x = 0;
x < num_x - 1;
x++)
122 for (
size_t y = 0; y < num_y - 1; y++)
131 faces[
index].v0 = faces[
index].c0 = int(
x * num_y + y);
132 faces[
index].v1 = faces[
index].c1 = int((
x + 1) * num_y + (y + 1));
133 faces[
index].v2 = faces[
index].c2 = int((
x + 1) * num_y + y);
136 faces[
index].v0 = faces[
index].c0 = int(
x * num_y + y);
137 faces[
index].v1 = faces[
index].c1 = int(
x * num_y + (y + 1));
138 faces[
index].v2 = faces[
index].c2 = int((
x + 1) * num_y + (y + 1));
Mesh & grid2D(Eigen::Vector2f extents, Eigen::Vector2i numPoints, std::function< viz::Color(size_t i, size_t j, const Eigen::Vector3f &p)> colorFunc)
Builds a regular 2D grid in the xy-plane.
Mesh & colors(const data::Color *cs, std::size_t size)
Mesh & vertices(const Eigen::Vector3f *vs, std::size_t size)
Mesh & faces(const data::Face *fs, std::size_t size)
#define ARMARX_CHECK_POSITIVE(number)
This macro evaluates whether number is positive (> 0) and if it turns out to be false it will throw a...
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
std::vector< viz::data::Face > makeGrid2DFaces(size_t num_x, size_t num_y)
Builds faces of a 2D grid.
std::vector< std::vector< viz::data::Color > > makeGrid2DColors(const std::vector< std::vector< Eigen::Vector3f > > &vertices, std::function< viz::Color(size_t x, size_t y, const Eigen::Vector3f &p)> colorFunc)
Build colors of a 2D grid.
std::vector< std::vector< Eigen::Vector3f > > makeGrid2DVertices(Eigen::Vector2f extents, Eigen::Vector2i numPoints, float height=0)
Builds vertices of a regular 2D grid in the xy-plane.
std::vector< T > flatten(const std::vector< std::vector< T > > &vector)
Flattens a 2D vector of nested vectors to a 1D vector.
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.