Skip to content

feat(sensors): open external distortion factory and add an ExternalDistortionParameters base - #179

Queued
janickm wants to merge 1 commit into
NVIDIA:mainfrom
janickm:dev/janickm/external-distortion-factory
Queued

feat(sensors): open external distortion factory and add an ExternalDistortionParameters base#179
janickm wants to merge 1 commit into
NVIDIA:mainfrom
janickm:dev/janickm/external-distortion-factory

Conversation

@janickm

@janickm janickm commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Applies the treatment the camera model hierarchy received in #175 / #177 to the external distortion hierarchy. Companion to #178, which does the same for lidar; the two are independent.

This was the most asymmetric of the three hierarchies: it had an abstract model base but no abstract parameters base at all, so ConcreteExternalDistortionParametersUnion was a single-member union over nothing.

A parameters base to hang the interface on

ExternalDistortionParameters is introduced as the abstract base, carrying the JSON (de)serialization interface and a non-abstract type() exactly as CameraModelParameters does, with BivariateWindshieldModelParameters derived from it. CameraModelParameters.external_distortion_parameters and the four get_parameters casts can then name the abstract type instead of the concrete union.

This is the one genuinely new piece of public API here, rather than a re-annotation.

The closed dispatch table

ExternalDistortionModel.from_parameters was a static method on the abstract base holding a closed table over every concrete subclass, inherited by all of them and unable to construct a model defined outside NCore. Replaced by a module-level external_distortion_model_from_parameters() dispatching via functools.singledispatch, with register_external_distortion_model for out-of-tree models; the static method stays as a deprecated forwarder.

Generic model

ExternalDistortionModel.get_parameters() was abstract but returned the union rather than the concrete type. It is now generic in its parameter type, covariant for the usual reason (return position only).

Risk called out explicitly

Widening the external_distortion_parameters field annotation changes what dataclasses_json resolves for it, which is a behavioural risk rather than a pure typing one. The existing parameterized round-trip over the windshield fixtures already covers it and passes unchanged; a direct encode/decode round-trip of a camera carrying windshield distortion is added on top so the property is pinned by name.

Verified: 33/33 tests on 3.8 and 3.11, ty aspect clean, //:format.check clean.

@janickm janickm self-assigned this Sep 9, 2026
@janickm
janickm force-pushed the dev/janickm/external-distortion-factory branch from f9382f2 to 17b3d73 Compare September 9, 2026 08:58
@janickm
janickm added this pull request to the merge queue Sep 9, 2026
@janickm
janickm removed this pull request from the merge queue due to a manual request Sep 9, 2026
…tory with open registry

Applies the treatment the camera model hierarchy already received to the external distortion
hierarchy, which was the most asymmetric of the three: it had an abstract *model* base but no
abstract *parameters* base at all, so `ConcreteExternalDistortionParametersUnion` was a
single-member union over nothing.

Introduce `ExternalDistortionParameters` as the abstract base, carrying the JSON
(de)serialization interface and a non-abstract `type()` exactly as `CameraModelParameters` does,
and derive `BivariateWindshieldModelParameters` from it. `CameraModelParameters` can then declare
its `external_distortion_parameters` field, and the four `get_parameters` casts can name, the
abstract type rather than the concrete union.

`ExternalDistortionModel.from_parameters` was a static method on the abstract base holding a
closed dispatch table over every concrete subclass, inherited by all of them and unable to
construct a model defined outside NCore. Replace it with a module-level
`external_distortion_model_from_parameters()` dispatching via `functools.singledispatch`, plus
`register_external_distortion_model` for out-of-tree models, keeping the static method as a
deprecated forwarder. As with the camera factory, the registry sits behind a separate private
symbol so the public entry point can carry `typing.overload` signatures.

Make `ExternalDistortionModel` generic in its parameter type, so `get_parameters()` returns the
concrete type instead of the union. The parameter type is covariant: it appears only in a return
position, and invariance would leave concrete instantiations with no common supertype.

Widening the `external_distortion_parameters` field annotation changes what `dataclasses_json`
resolves for it, so the encode/decode round-trip of a camera carrying windshield distortion is
covered explicitly in addition to the existing parameterized round-trip.
@janickm
janickm force-pushed the dev/janickm/external-distortion-factory branch from 17b3d73 to 7ec1a95 Compare September 9, 2026 12:06
@janickm
janickm added this pull request to the merge queue Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant