namespace mrpt::opengl::testing

Overview

Helpers to inspect the pixels of a rendered frame in the offscreen render tests that assert geometric or color invariants.

Shared helpers for the offscreen-rendering tests, which compare a freshly rendered frame against a reference (“golden”) image stored in tests/.

namespace testing {

// structs

struct RGB;

// global functions

RGB pixelRGB(const mrpt::img::CImage& im, int x, int y);

bool isNear(
    const RGB& a,
    const RGB& b,
    int tol = 40
    );

int countColor(const mrpt::img::CImage& im, int x0, int y0, int x1, int y1, const RGB& c, int tol = 40);
float imageDiff(const mrpt::img::CImage& im1, const mrpt::img::CImage& im2);

void expectMatchesReference(
    const mrpt::img::CImage& rendered,
    const std::string& referenceFile,
    float maxDiff,
    const std::string& label
    );

} // namespace testing

Global Functions

RGB pixelRGB(const mrpt::img::CImage& im, int x, int y)

The color of a pixel, whatever the channel order of the image is.

int countColor(
    const mrpt::img::CImage& im,
    int x0,
    int y0,
    int x1,
    int y1,
    const RGB& c,
    int tol = 40
    )

Number of pixels in [x0,x1) x [y0,y1) that are close to the color c.

float imageDiff(const mrpt::img::CImage& im1, const mrpt::img::CImage& im2)

Sum of the per-channel absolute differences between two RGB images.

void expectMatchesReference(
    const mrpt::img::CImage& rendered,
    const std::string& referenceFile,
    float maxDiff,
    const std::string& label
    )

Compares rendered against the reference image in referenceFile.

Setting the environment variable MRPT_UPDATE_RENDER_REFERENCES=1 overwrites the reference image with the rendered one instead of comparing, which is how these files are regenerated after an intended change in any of the visual objects they exercise.