ReUseX  0.0.1
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
ReUseX::vision::osd::LabelLayoutSolver Class Reference

Greedy iterative label placement solver. More...

#include <labelLayoutSolver.hpp>

Classes

struct  Candidate
 Internal representation of a single placement candidate for a label. More...

Public Member Functions

template<typename Func>
 LabelLayoutSolver (int w, int h, Func &&func, const LayoutConfig &cfg=LayoutConfig())
 Construct a solver for a canvas of the given dimensions.
void setConfig (const LayoutConfig &cfg)
 Update the layout configuration.
void setCanvasSize (int w, int h)
 Change the canvas dimensions (e.g. after a resize).
void clear ()
 Remove all items from the solver (allows reuse across frames).
void add (float l, float t, float r, float b, const std::string &text, int baseFontSize)
 Register a new label to be placed.
void solve ()
 Run the iterative placement optimisation.
std::vector< LayoutResultgetResults () const
 Retrieve the placement result for each label in insertion order.

Detailed Description

Greedy iterative label placement solver.

Given a set of object bounding boxes and their text labels, LabelLayoutSolver finds a non-overlapping placement for each label by minimising a cost function that penalises:

  • departure from the preferred anchor position (top of the object),
  • overlap with other object boxes, and
  • overlap with other already-placed labels.

The solver generates a set of discrete placement candidates for each label (four anchor positions × several font-scale tiers + sliding variants) and then iteratively re-assigns labels to reduce total cost.

Usage example:

LabelLayoutSolver solver(imgW, imgH, [&](const std::string &t, int sz) {
int w, h, base;
renderer.getTextSize(t, sz, &w, &h, &base);
return TextSize{w, h, base};
});
solver.add(box.left, box.top, box.right, box.bottom, label, fontSize);
solver.solve();
for (const auto &res : solver.getResults()) { /* draw */ }
LabelLayoutSolver(int w, int h, Func &&func, const LayoutConfig &cfg=LayoutConfig())
Construct a solver for a canvas of the given dimensions.
Measured bounding box of a rendered text string.

Definition at line 214 of file labelLayoutSolver.hpp.

Constructor & Destructor Documentation

◆ LabelLayoutSolver()

template<typename Func>
ReUseX::vision::osd::LabelLayoutSolver::LabelLayoutSolver ( int w,
int h,
Func && func,
const LayoutConfig & cfg = LayoutConfig() )
inline

Construct a solver for a canvas of the given dimensions.

Parameters
wCanvas width in pixels.
hCanvas height in pixels.
funcCallable that measures a text string at a given font size and returns a TextSize. Signature: TextSize(const std::string &text, int fontSize).
cfgOptional tuning parameters.

Definition at line 262 of file labelLayoutSolver.hpp.

Member Function Documentation

◆ add()

void ReUseX::vision::osd::LabelLayoutSolver::add ( float l,
float t,
float r,
float b,
const std::string & text,
int baseFontSize )
inline

◆ clear()

void ReUseX::vision::osd::LabelLayoutSolver::clear ( )
inline

Remove all items from the solver (allows reuse across frames).

Definition at line 281 of file labelLayoutSolver.hpp.

◆ getResults()

std::vector< LayoutResult > ReUseX::vision::osd::LabelLayoutSolver::getResults ( ) const
inline

Retrieve the placement result for each label in insertion order.

Returns
Vector of LayoutResult, one per call to add().

Definition at line 483 of file labelLayoutSolver.hpp.

◆ setCanvasSize()

void ReUseX::vision::osd::LabelLayoutSolver::setCanvasSize ( int w,
int h )
inline

Change the canvas dimensions (e.g. after a resize).

Definition at line 275 of file labelLayoutSolver.hpp.

◆ setConfig()

void ReUseX::vision::osd::LabelLayoutSolver::setConfig ( const LayoutConfig & cfg)
inline

Update the layout configuration.

Definition at line 272 of file labelLayoutSolver.hpp.

◆ solve()


The documentation for this class was generated from the following file: