dl::Point2DEncoder
dl::Point2DEncoder
Encodes Point2D
#include <Point2DEncoder.hpp>
Inherits from dl::ChannelEncoder
Public Functions
| Name | |
|---|---|
| virtual std::string | name() const override Human-readable name for UI / registry. |
| virtual std::string | inputTypeName() const override Which geometry type this encoder expects (e.g. “Point2D |
| void | encode(Point2D< float > point, ImageSize source_size, at::Tensor & tensor, EncoderContext const & ctx, Point2DEncoderParams const & params) Encode a single point into tensor[batch_index, target_channel, :, :]. |
| void | encode(std::vector< Point2D< float > > const & points, ImageSize source_size, at::Tensor & tensor, EncoderContext const & ctx, Point2DEncoderParams const & params) Encode multiple points into tensor[batch_index, target_channel, :, :]. |
Additional inherited members
Public Functions inherited from dl::ChannelEncoder
| Name | |
|---|---|
| virtual | ~ChannelEncoder() =default |
Detailed Description
class dl::Point2DEncoder;Encodes Point2D
Supported modes:
- Binary: Sets 1.0 at the nearest pixel for each point
- Heatmap: Places a 2D Gaussian centered on each point
Points are scaled from source ImageSize to the tensor’s (H, W).
Public Functions Documentation
function name
virtual std::string name() const overrideHuman-readable name for UI / registry.
Reimplements: dl::ChannelEncoder::name
function inputTypeName
virtual std::string inputTypeName() const overrideWhich geometry type this encoder expects (e.g. “Point2D
Reimplements: dl::ChannelEncoder::inputTypeName
function encode
static void encode(
Point2D< float > point,
ImageSize source_size,
at::Tensor & tensor,
EncoderContext const & ctx,
Point2DEncoderParams const & params
)Encode a single point into tensor[batch_index, target_channel, :, :].
Parameters:
- point Point in source image coordinate space
- source_size Spatial dimensions of the source image used to scale the point into tensor space
- tensor Pre-allocated [B, C, H, W] float32 tensor to write into
- ctx Encoder context (batch_index, target_channel, height, width)
- params User-configurable encoding parameters (mode, gaussian_sigma)
Precondition:
- params.mode == Binary or params.mode == Heatmap (enforcement: exception)
- source_size.width > 0 and source_size.height > 0; zero causes floating-point division by zero producing a +Inf scale factor, which makes static_cast
of the resulting Inf undefined behaviour (enforcement: none) [CRITICAL] - source_size.width > 0 and source_size.height > 0; negative values (e.g. the ImageSize default -1) produce a negative scale factor, mapping points to mirrored coordinates (enforcement: none) [IMPORTANT]
- tensor is a valid initialized [B, C, H, W] float32 tensor with at least 4 dimensions; fewer dimensions cause an out-of-bounds tensor access when indexing tensor[batch_index][target_channel] (enforcement: none) [CRITICAL]
- ctx.batch_index >= 0 and ctx.batch_index < tensor.size(0); an out-of-range value causes an out-of-bounds tensor access (enforcement: none) [CRITICAL]
- ctx.target_channel >= 0 and ctx.target_channel < tensor.size(1); an out-of-range value causes an out-of-bounds tensor access (enforcement: none) [IMPORTANT]
- ctx.height == tensor.size(2) and ctx.width == tensor.size(3); if either ctx dimension exceeds the actual tensor spatial dimension the channel write is out-of-bounds (enforcement: none) [CRITICAL]
- ctx.height > 0 and ctx.width > 0; zero causes std::clamp to receive an upper bound of -1 which is less than the lower bound of 0, invoking undefined behaviour (enforcement: none) [IMPORTANT]
- params.gaussian_sigma > 0 when mode == Heatmap; zero causes floating-point division by zero in the Gaussian weight computation, producing NaN at the centre pixel (enforcement: none) [IMPORTANT]
- point.x and point.y are finite; NaN coordinates cause round() to return an unspecified value and static_cast
of NaN is undefined behaviour in Binary mode; in Heatmap mode the bounding-box calculations also invoke UB (enforcement: none) [IMPORTANT]
function encode
static void encode(
std::vector< Point2D< float > > const & points,
ImageSize source_size,
at::Tensor & tensor,
EncoderContext const & ctx,
Point2DEncoderParams const & params
)Encode multiple points into tensor[batch_index, target_channel, :, :].
Parameters:
- points Points in source image coordinate space
- source_size Spatial dimensions of the source image used to scale points into tensor space
- tensor Pre-allocated [B, C, H, W] float32 tensor to write into
- ctx Encoder context (batch_index, target_channel, height, width)
- params User-configurable encoding parameters (mode, gaussian_sigma)
Precondition:
- params.mode == Binary or params.mode == Heatmap (enforcement: exception)
- source_size.width > 0 and source_size.height > 0; zero causes floating-point division by zero producing a +Inf scale factor, which makes static_cast
of the resulting Inf undefined behaviour (enforcement: none) [CRITICAL] - source_size.width > 0 and source_size.height > 0; negative values (e.g. the ImageSize default -1) produce a negative scale factor, mapping points to mirrored coordinates (enforcement: none) [IMPORTANT]
- tensor is a valid initialized [B, C, H, W] float32 tensor with at least 4 dimensions; fewer dimensions cause an out-of-bounds tensor access when indexing tensor[batch_index][target_channel] (enforcement: none) [CRITICAL]
- ctx.batch_index >= 0 and ctx.batch_index < tensor.size(0); an out-of-range value causes an out-of-bounds tensor access (enforcement: none) [CRITICAL]
- ctx.target_channel >= 0 and ctx.target_channel < tensor.size(1); an out-of-range value causes an out-of-bounds tensor access (enforcement: none) [IMPORTANT]
- ctx.height == tensor.size(2) and ctx.width == tensor.size(3); if either ctx dimension exceeds the actual tensor spatial dimension the channel write is out-of-bounds (enforcement: none) [CRITICAL]
- ctx.height > 0 and ctx.width > 0; zero causes std::clamp to receive an upper bound of -1 which is less than the lower bound of 0, invoking undefined behaviour (enforcement: none) [IMPORTANT]
- params.gaussian_sigma > 0 when mode == Heatmap; zero causes floating-point division by zero in the Gaussian weight computation, producing NaN at centre pixels (enforcement: none) [IMPORTANT]
- each element of points has finite x and y; NaN coordinates invoke undefined behaviour in the pixel-coordinate computation for both Binary and Heatmap modes (enforcement: none) [IMPORTANT]
An empty points vector is a safe no-op. When multiple points map to the same pixel in Binary mode the pixel is simply set to 1.0; in Heatmap mode the maximum Gaussian value across all points is retained.
Updated on 2026-11-13 at 20:25:42 +0000