Skip to main content

src/WhiskerToolbox/Media_Widget/Core/LineEditOperations.hpp

src/WhiskerToolbox/Media_Widget/Core/LineEditOperations.hpp

Qt-free helpers for in-place line geometry edits in the Media Viewer.

Classes

Name
struct LineSmoothBrushParams
Parameters for local brush smoothing on a polyline.

Types

Name
enum class LineSmoothAlgorithm { MovingAverage, PolynomialFit}
Local smoothing algorithm for brush-based line edits.

Functions

Name
void applyPolynomialFitToLine(Line2D & line, int order)
Apply a parametric polynomial fit to an entire line.
bool smoothPolylineLocally(Line2D & line, LineSmoothBrushParams const & params)
Smooth vertices of a polyline within a circular brush neighborhood.

Types Documentation

enum LineSmoothAlgorithm

Enumerator Value Description
MovingAverage 3-point moving average on the affected vertex subrange
PolynomialFit Parametric polynomial fit and resample on the subrange.

Local smoothing algorithm for brush-based line edits.

Functions Documentation

function applyPolynomialFitToLine

void applyPolynomialFitToLine(
    Line2D & line,
    int order
)

Apply a parametric polynomial fit to an entire line.

Parameters:

  • line Line geometry to smooth in place
  • order Polynomial order

Precondition:

  • order >= 0
  • line.size() > order for a successful fit

function smoothPolylineLocally

bool smoothPolylineLocally(
    Line2D & line,
    LineSmoothBrushParams const & params
)

Smooth vertices of a polyline within a circular brush neighborhood.

Parameters:

  • line Line geometry to modify in place
  • params Brush center, radius, algorithm, and strength

Return: True when any vertices were modified

Precondition: line must have at least 2 points for meaningful smoothing

Source code

#ifndef LINE_EDIT_OPERATIONS_HPP
#define LINE_EDIT_OPERATIONS_HPP


#include "CoreGeometry/lines.hpp"
#include "CoreGeometry/points.hpp"

#include <cstddef>

enum class LineSmoothAlgorithm {
    MovingAverage,
    PolynomialFit 
};

struct LineSmoothBrushParams {
    Point2D<float> center;  
    float radius_px = 10.0f;
    LineSmoothAlgorithm algorithm = LineSmoothAlgorithm::MovingAverage;
    int polynomial_order = 3;
    int strength = 1;        
};

void applyPolynomialFitToLine(Line2D & line, int order);

[[nodiscard]] bool smoothPolylineLocally(Line2D & line, LineSmoothBrushParams const & params);

#endif// LINE_EDIT_OPERATIONS_HPP

Updated on 2026-11-13 at 20:25:45 +0000