Skip to content

OrientAverageFilter

roosit edited this page Nov 15, 2026 · 1 revision

OrientAverageFilter

Up | Previous | Next | Русский

Full source with short explanations

Below is the full source of the class in documentation form. The comments inside the block explain the purpose of the parts of the class, but they are not stored in the working file OrientAverageFilter.java: the production code stays clean and the explanations live in the wiki.

package com.velitask.plugin.official.processing.filters;

import com.velitask.sdk.data.OrientationSensorAtom;

/* Smoothing by average for camera orientation: quaternion w, x, y, z. */
public final class OrientAverageFilter extends VectorAverageFilter<OrientationSensorAtom> {

    /* Stable step name in the import plans. */
    public static final String NAME = "orientAverage";

    /* Step logic version is 1; atoms are OrientationSensorAtom. */
    public OrientAverageFilter() {
        super(NAME, 1, OrientationSensorAtom.class);
    }

    /* Four quaternion components: w, x, y, z. */
    @Override
    protected int components() {
        return 4;
    }

    /* Index 0..3 is w, x, y, z; any other index throws IndexOutOfBoundsException. */
    @Override
    protected double component(OrientationSensorAtom atom, int index) {
        return switch (index) {
            case 0 -> atom.w;
            case 1 -> atom.x;
            case 2 -> atom.y;
            case 3 -> atom.z;
            default -> throw new IndexOutOfBoundsException(index);
        };
    }

    /* The w, x, y, z fields are double, the value is written without rounding. */
    @Override
    protected void setComponent(OrientationSensorAtom atom, int index, double value) {
        switch (index) {
            case 0 -> atom.w = value;
            case 1 -> atom.x = value;
            case 2 -> atom.y = value;
            case 3 -> atom.z = value;
            default -> throw new IndexOutOfBoundsException(index);
        }
    }
}

Purpose

The "Smoothing by average: camera orientation" step replaces every orientation value with the average over a window around it. It removes sensor noise and vibration, but also softens short impacts (the Plugin.ImportStep.orientAverage.description string). An implementation of VectorAverageFilter for OrientationSensorAtom.

How it works

The algorithm is in VectorAverageFilter. The class defines the four quaternion components in the order w, x, y, z (double); period() is not overridden, there are no angles. Every component is averaged independently.

It is used by the GoPro import plan: window 0, that is, the step smooths nothing in the plan; the next stage is OrientToleranceCompress. The sensor is disabled in the plan by default. The step is also registered in BuiltinScenarios.steps().

Features and limitations

  • The average of quaternion components is not a correct average of rotations: the result is not normalized to unit length. With small windows and smooth movement the difference is small; with fast turns and sign jumps of the quaternion (q and −q are one rotation) it is noticeable.
  • The class does not convert the quaternion to angles; for yaw, pitch and roll there is a separate sensor and AttitudeAverageFilter.
  • The default window is 0: without an explicit value in the plan the step changes nothing.

Clone this wiki locally