Skip to content

Commit e827b39

Browse files
authored
memory usage for point cloud buffer (#176)
1 parent 8c38401 commit e827b39

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

include/glk/pointcloud_buffer.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class PointCloudBuffer : public glk::Drawable {
9999

100100
int size() const { return num_points; }
101101

102+
size_t memory_usage() const;
103+
102104
private:
103105
mutable std::atomic_uint rendering_count;
104106
int points_rendering_budget;
@@ -114,8 +116,7 @@ class PointCloudBuffer : public glk::Drawable {
114116

115117
// template methods
116118
template <typename Scalar, int Dim, typename Allocator>
117-
PointCloudBuffer::PointCloudBuffer(const std::vector<Eigen::Matrix<Scalar, Dim, 1>, Allocator>& points)
118-
: PointCloudBuffer(points.data(), points.size()) {}
119+
PointCloudBuffer::PointCloudBuffer(const std::vector<Eigen::Matrix<Scalar, Dim, 1>, Allocator>& points) : PointCloudBuffer(points.data(), points.size()) {}
119120

120121
template <int N, typename Allocator>
121122
void PointCloudBuffer::add_normals(const std::vector<Eigen::Matrix<float, N, 1>, Allocator>& normals) {

src/glk/gridmap.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ void GridMap::update_color(int width, int height, const unsigned char* values, i
4242
std::copy(values + i * 4, values + i * 4 + 4, rgba.begin() + i * 4);
4343
break;
4444
}
45-
if (mode != ColorMode::RGBA) rgba[i * 4 + 3] = alpha;
45+
if (mode != ColorMode::RGBA) {
46+
rgba[i * 4 + 3] = alpha;
47+
}
4648
}
4749

4850
texture.reset(new Texture(Eigen::Vector2i(width, height), GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, rgba.data()));
@@ -76,8 +78,13 @@ void GridMap::update_color(int width, int height, float scale, const float* valu
7678
case ColorMode::PROB_TURBO:
7779
rgb = glk::colormapf(glk::COLORMAP::TURBO, (1.0f - x)).head<3>();
7880
break;
81+
case ColorMode::RGBA:
82+
std::copy(values + i * 4, values + i * 4 + 4, rgba.begin() + i * 4);
83+
break;
84+
}
85+
if (mode != ColorMode::RGBA) {
86+
rgba[i * 4 + 3] = alpha;
7987
}
80-
rgba[i * 4 + 3] = alpha;
8188
}
8289

8390
texture.reset(new Texture(Eigen::Vector2i(width, height), GL_RGBA, GL_RGBA, GL_FLOAT, rgba.data()));

src/glk/pointcloud_buffer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,17 @@ const AuxBufferData& PointCloudBuffer::get_aux_buffer(int i) const {
346346
return aux_buffers[i];
347347
}
348348

349+
size_t PointCloudBuffer::memory_usage() const {
350+
size_t bytes = stride * num_points;
351+
if (ebo) {
352+
bytes += sizeof(unsigned int) * num_points;
353+
}
354+
355+
for (const auto& aux : aux_buffers) {
356+
bytes += aux.stride * num_points;
357+
}
358+
359+
return bytes;
360+
}
361+
349362
} // namespace glk

0 commit comments

Comments
 (0)