145 Colormap() : cmapsize(0), minval(0.0f), maxval(1.0f) {};
147 Colormap(
const std::vector<helios::RGBcolor> &ctable,
const std::vector<float> &clocs,
int size,
float minval_,
float maxval_) : cmapsize(size), minval(minval_), maxval(maxval_) {
148 set(ctable, clocs, size, minval_, maxval_);
151 void set(
const std::vector<helios::RGBcolor> &ctable,
const std::vector<float> &clocs,
int size,
float a_minval,
float a_maxval) {
156 size_t Ncolors = ctable.size();
158 assert(clocs.size() == Ncolors && minval < maxval);
160 cmap.resize(Ncolors);
162 std::vector<float> cinds;
163 cinds.resize(Ncolors);
165 for (
uint i = 0; i < Ncolors; i++) {
166 cinds.at(i) = clocs.at(i) *
static_cast<float>(cmapsize - 1);
169 cmap.resize(cmapsize);
170 for (
uint c = 0; c < Ncolors - 1; c++) {
171 float cmin = cinds.at(c);
172 float cmax = cinds.at(c + 1);
174 for (
uint i = 0; i < cmapsize; i++) {
175 auto i_f =
static_cast<float>(i);
177 if (i_f >= cmin && i_f <= cmax) {
178 cmap.at(i).r = ctable.at(c).r + (i_f - cmin) / (cmax - cmin) * (ctable.at(c + 1).r - ctable.at(c).r);
179 cmap.at(i).g = ctable.at(c).g + (i_f - cmin) / (cmax - cmin) * (ctable.at(c + 1).g - ctable.at(c).g);
180 cmap.at(i).b = ctable.at(c).b + (i_f - cmin) / (cmax - cmin) * (ctable.at(c + 1).b - ctable.at(c).b);
187 assert(cmapsize > 0 && !cmap.empty());
192 if (minval == maxval) {
195 float normalized_pos = (x - minval) / (maxval - minval) * float(cmapsize - 1);
198 if (normalized_pos < 0) {
202 else if (normalized_pos >
float(cmapsize - 1)) {
203 color_ind = cmapsize - 1;
207 color_ind = std::round(normalized_pos);
211 color.
r = cmap.at(color_ind).r;
212 color.
g = cmap.at(color_ind).g;
213 color.
b = cmap.at(color_ind).b;
218 void setRange(
float min,
float max) {
224 return {minval, maxval};
227 [[nodiscard]]
float getLowerLimit()
const {
231 [[nodiscard]]
float getUpperLimit()
const {
236 std::vector<helios::RGBcolor> cmap;
237 unsigned int cmapsize;
238 float minval, maxval;
362 Visualizer(
uint Wdisplay,
uint Hdisplay,
int aliasing_samples,
bool window_decorations,
bool headless);
368 static int selfTest(
int argc = 0,
char **argv =
nullptr);
907 void setColormap(
const std::vector<helios::RGBcolor> &colors,
const std::vector<float> &divisions);
918 static double niceNumber(
double value,
bool round);
927 static std::string
formatTickLabel(
double value,
double spacing,
bool isIntegerData);
937 static std::vector<float>
generateNiceTicks(
float dataMin,
float dataMax,
bool isIntegerData,
int targetTicks = 5);
1078 void printWindow(
const char *outfile,
const std::string &image_format =
"jpeg");
1091 void displayImage(
const std::vector<unsigned char> &pixel_data,
uint width_pixels,
uint height_pixels);
1116 void getDepthMap(std::vector<float> &depth_pixels,
uint &width_pixels,
uint &height_pixels);
1213 [[nodiscard]] std::vector<uint> getFrameBufferSize()
const;
1216 std::vector<helios::RGBcolor> readOffscreenPixels()
const;
1223 std::vector<helios::RGBAcolor> readOffscreenPixelsRGBA(
bool read_alpha)
const;
1231 void setFrameBufferSize(
int width,
int height);
1238 [[nodiscard]]
Shader getPrimaryShader()
const;
1245 [[nodiscard]] glm::mat4 getViewMatrix()
const;
1259 [[nodiscard]]
uint getDepthTexture()
const;
1263 void createOffscreenContext();
1266 void removeBackgroundRectangle();
1269 void setBackgroundGradient();
1272 static void framebufferResizeCallback(GLFWwindow *window,
int width,
int height);
1281 static void windowResizeCallback(GLFWwindow *window,
int width,
int height);
1292 void initialize(
uint window_width_pixels,
uint window_height_pixels,
int aliasing_samples,
bool window_decorations,
bool headless_mode);
1299 void render(
bool shadow)
const;
1307 void transferBufferData();
1310 void transferTextureData();
1318 [[nodiscard]]
uint registerTextureImage(
const std::string &texture_file);
1328 [[nodiscard]]
uint registerTextureImage(
const std::vector<unsigned char> &texture_data,
const helios::uint2 &image_resolution);
1336 [[nodiscard]]
uint registerTextureTransparencyMask(
const std::string &texture_file);
1344 [[nodiscard]]
uint registerTextureGlyph(
const Glyph *glyph);
1356 std::string colorPrimitivesByObjectData, colorPrimitivesByData;
1357 std::map<uint, uint> colorPrimitives_UUIDs, colorPrimitives_objIDs;
1359 std::vector<uint> contextUUIDs_build;
1361 std::vector<float> depth_buffer_data;
1377 void updateDepthBuffer();
1394 bool buffers_swapped_since_render;
1407 float minimum_view_radius;
1424 uint offscreenFramebufferID;
1425 uint offscreenColorTexture;
1426 uint offscreenDepthTexture;
1431 float lightintensity = 1.f;
1433 bool isWatermarkVisible;
1436 size_t watermark_ID;
1442 bool background_is_transparent;
1445 bool watermark_was_visible_before_transparent;
1448 bool navigation_gizmo_was_enabled_before_image_display;
1451 size_t background_rectangle_ID;
1452 std::vector<size_t> background_sky_IDs;
1458 std::vector<size_t> coordinate_axes_IDs;
1461 bool navigation_gizmo_enabled;
1470 std::vector<size_t> navigation_gizmo_IDs;
1473 int hovered_gizmo_bubble;
1481 std::string colorbar_title;
1484 uint colorbar_fontsize;
1490 bool point_culling_enabled;
1491 size_t point_culling_threshold;
1492 float point_max_render_distance;
1493 float point_lod_factor;
1496 mutable size_t points_total_count;
1497 mutable size_t points_rendered_count;
1498 mutable float last_culling_time_ms;
1510 float colorbar_intended_aspect_ratio;
1513 std::vector<size_t> colorbar_IDs;
1516 std::vector<GLuint> face_index_buffer, vertex_buffer, uv_buffer;
1518 std::vector<GLuint> color_buffer, normal_buffer, texture_flag_buffer, texture_ID_buffer, coordinate_flag_buffer, sky_geometry_flag_buffer, hidden_flag_buffer;
1520 std::vector<GLuint> color_texture_object, normal_texture_object, texture_flag_texture_object, texture_ID_texture_object, coordinate_flag_texture_object, sky_geometry_flag_texture_object, hidden_flag_texture_object;
1523 GLuint uv_rescale_buffer;
1524 GLuint uv_rescale_texture_object;
1527 std::vector<GLint> rectangle_vertex_group_firsts;
1528 std::vector<GLint> rectangle_vertex_group_counts;
1535 [[nodiscard]] glm::mat4 computeShadowDepthMVP()
const;
1537 void updatePerspectiveTransformation(
bool shadow);
1540 void cullPointsByFrustum();
1541 void cullPointsByDistance(
float maxDistance,
float lodFactor);
1542 void updatePointCulling();
1543 std::vector<glm::vec4> extractFrustumPlanes()
const;
1545 glm::mat4 perspectiveTransformationMatrix;
1547 glm::mat4 cameraViewMatrix;
1548 glm::mat4 cameraProjectionMatrix;
1550 void updateCustomTransformation(
const glm::mat4 &matrix);
1552 glm::mat4 customTransformationMatrix;
1557 bool build_all_context_geometry =
false;
1559 bool primitiveColorsNeedUpdate;
1564 void buildContextGeometry_private();
1567 void updateNavigationGizmo();
1570 void updateColorbar();
1578 [[nodiscard]]
bool testGizmoBubbleHit(
const helios::vec2 &normalized_pos,
int bubble_index)
const;
1584 void reorientCameraToAxis(
int axis_index);
1587 [[nodiscard]]
bool cameraHasChanged()
const;
1591 std::vector<float> colorbar_ticks;
1592 bool colorbar_integer_data;
1626 size_t texture_array_layers;
1627 bool textures_dirty;
1631 const glm::mat4 biasMatrix = {0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0};
1651 explicit Texture(
const std::string &texture_file,
uint textureID,
const helios::uint2 &maximum_texture_size,
bool loadalphaonly =
false);
1678 explicit Texture(
const std::vector<unsigned char> &pixel_data,
uint textureID,
const helios::uint2 &image_resolution,
const helios::uint2 &maximum_texture_size);
1681 std::string texture_file;
1689 std::vector<unsigned char> texture_data;
1691 unsigned char num_channels;
1701 void resizeTexture(
const helios::uint2 &new_image_resolution);
1709 std::unordered_map<uint, Texture> texture_manager;
1712 friend struct Texture;