struct mrpt::imgui::ImageViewTransform

Overview

Mapping between image pixel coordinates and widget coordinates of a zoomable, pannable image view: widget = (image - offset) * zoom.

#include <mrpt/imgui/CImGuiImageView.h>

struct ImageViewTransform
{
    // fields

    float zoom = 1.0f;
    float offsetX = 0.0f;
    float offsetY = 0.0f;
    float minZoom = 1.0f / 64;
    float maxZoom = 64.0f;

    // methods

    std::pair<float, float> imageToWidget(
        float u,
        float v
        ) const;

    std::pair<float, float> widgetToImage(
        float x,
        float y
        ) const;

    void fit(float imgW, float imgH, float widgetW, float widgetH);
    void zoomAt(float x, float y, float factor);
    void pan(float dx, float dy);
};

Fields

float zoom = 1.0f

Widget pixels per image pixel.

float offsetX = 0.0f

Image coordinates at the widget top-left corner.

Methods

void fit(float imgW, float imgH, float widgetW, float widgetH)

Scales the image to fit the widget, keeping its aspect ratio, centered.

void zoomAt(float x, float y, float factor)

Zooms by factor keeping the image point under widget point (x,y) still.

void pan(float dx, float dy)

Pans by a displacement in widget pixels.