# vin.geometry { #aria_nbv.vin.geometry }
`vin.geometry`
Geometry helpers shared by VIN scorer implementations.
The modules in this package own stateless SE(3), camera, frustum, and voxel
geometry contracts used by :mod:`aria_nbv.vin.models.scene_myopic` and related diagnostic
surfaces. Neural modules should import these helpers rather than keeping shape
normalization or camera-space math in model classes.
## Attributes
| Name | Description |
| --- | --- |
| [SEMIDENSE_GRID_CHANNELS](#aria_nbv.vin.geometry.SEMIDENSE_GRID_CHANNELS) | Channel count for semidense projection grid tensors. |
| [SEMIDENSE_PROJ_DIM](#aria_nbv.vin.geometry.SEMIDENSE_PROJ_DIM) | Feature dimension for semidense projection summary tensors. |
## Functions
| Name | Description |
| --- | --- |
| [build_frustum_points_world_p3d](#aria_nbv.vin.geometry.build_frustum_points_world_p3d) | Unproject a square image grid at fixed depths into world points. |
| [build_projection_grid](#aria_nbv.vin.geometry.build_projection_grid) | Build per-camera semidense projection grids for CNN encoders. |
| [build_scene_field](#aria_nbv.vin.geometry.build_scene_field) | Build a compact voxel-aligned scene field from EVL evidence tensors. |
| [candidate_valid_from_token](#aria_nbv.vin.geometry.candidate_valid_from_token) | Convert per-token validity into a per-candidate validity mask. |
| [center_crop_grid](#aria_nbv.vin.geometry.center_crop_grid) | Center-crop a voxel grid with trailing XYZ/channel values. |
| [encode_projection_summary](#aria_nbv.vin.geometry.encode_projection_summary) | Summarize semidense projection coverage, visibility, and depth. |
| [ensure_candidate_batch](#aria_nbv.vin.geometry.ensure_candidate_batch) | Ensure candidate camera poses are shaped as ``PoseTW["B N 12"]``. |
| [ensure_pose_batch](#aria_nbv.vin.geometry.ensure_pose_batch) | Broadcast one pose tensor to the VIN batch size. |
| [frustum_points_world_from_cameras](#aria_nbv.vin.geometry.frustum_points_world_from_cameras) | Generate per-candidate frustum sample points in world coordinates. |
| [infer_padded_grid_shape](#aria_nbv.vin.geometry.infer_padded_grid_shape) | Infer a symmetrically padded voxel-grid shape from a flattened count. |
| [pool_voxel_points](#aria_nbv.vin.geometry.pool_voxel_points) | Downsample voxel center points to a pooled token grid. |
| [pos_grid_from_pts_world](#aria_nbv.vin.geometry.pos_grid_from_pts_world) | Convert voxel centers to a normalized position grid in reference-rig frame. |
| [project_points_to_candidate_cameras](#aria_nbv.vin.geometry.project_points_to_candidate_cameras) | Project world points into a batch of candidate cameras. |
| [sample_candidate_voxel_coverage](#aria_nbv.vin.geometry.sample_candidate_voxel_coverage) | Sample normalized voxel observation coverage at candidate camera centers. |
| [sample_semidense_points](#aria_nbv.vin.geometry.sample_semidense_points) | Sample valid semidense world points from a VIN snippet. |
| [sample_voxel_field](#aria_nbv.vin.geometry.sample_voxel_field) | Sample a voxel-aligned field at world points. |
| [semidense_proj_feature_index](#aria_nbv.vin.geometry.semidense_proj_feature_index) | Resolve a canonical semidense projection feature name to its index. |
### build_frustum_points_world_p3d { #aria_nbv.vin.geometry.build_frustum_points_world_p3d }
```python
vin.geometry.build_frustum_points_world_p3d(cameras, *, grid_size, depths_m)
```
Unproject a square image grid at fixed depths into world points.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|-----------|-----------------------------------------------------------------------|--------------------------------------------------------------------------------------|------------|
| cameras | [PerspectiveCameras](`pytorch3d.renderer.cameras.PerspectiveCameras`) | PyTorch3D camera batch with pixel ``image_size`` and ``principal_point`` parameters. | _required_ |
| grid_size | [int](`int`) | Number of image samples per side. | _required_ |
| depths_m | [list](`list`)\[[float](`float`)\] | Positive metric depths to sample along each image ray. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|--------------------------|---------------------------------------------------------------------|
| | [Tensor](`torch.Tensor`) | ``Tensor["Nc G*G*D 3"]`` of world-frame points, where ``Nc`` is the |
| | [Tensor](`torch.Tensor`) | camera count and ``D`` is ``len(depths_m)``. |
### build_projection_grid { #aria_nbv.vin.geometry.build_projection_grid }
```python
vin.geometry.build_projection_grid(proj_data, *, device, dtype, grid_size)
```
Build per-camera semidense projection grids for CNN encoders.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|-----------|------------------------------------------------------------------|----------------------------------------------------------|------------|
| proj_data | [dict](`dict`)\[[str](`str`), [Tensor](`torch.Tensor`)\] \| None | Output from :func:`project_points_to_candidate_cameras`. | _required_ |
| device | [torch](`torch`).[device](`torch.device`) | Target device for the grid. | _required_ |
| dtype | [torch](`torch`).[dtype](`torch.dtype`) | Output dtype consumed by the caller-owned CNN. | _required_ |
| grid_size | [int](`int`) | Screen-space bin count per side. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|--------------------------|------------------------------------------------------------------------|
| | [Tensor](`torch.Tensor`) | ``Tensor["B*N_q C_grid G G", float32]`` containing occupancy, mean |
| | [Tensor](`torch.Tensor`) | camera-frame depth in metres, and depth standard-deviation grids, with |
| | [Tensor](`torch.Tensor`) | ``C_grid == SEMIDENSE_GRID_CHANNELS``. |
### build_scene_field { #aria_nbv.vin.geometry.build_scene_field }
```python
vin.geometry.build_scene_field(
out,
*,
use_channels,
occ_input_threshold,
counts_norm_mode,
occ_pr_is_logits,
)
```
Build a compact voxel-aligned scene field from EVL evidence tensors.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|---------------------|------------------------------------------------------|---------------------------------------------------------------------------|------------|
| out | [Any](`typing.Any`) | Backbone output object exposing EVL head/evidence tensors. | _required_ |
| use_channels | [list](`list`)\[[str](`str`)\] | Ordered channel names to concatenate. | _required_ |
| occ_input_threshold | [float](`float`) | Threshold for deriving free-space evidence when ``free_input`` is absent. | _required_ |
| counts_norm_mode | [Literal](`typing.Literal`)\[\'log1p\', \'linear\'\] | Observation-count normalization mode. | _required_ |
| occ_pr_is_logits | [bool](`bool`) | Whether ``occ_pr`` must be passed through sigmoid. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|--------------------------|--------------------------------------------------------------------|
| | [Tensor](`torch.Tensor`) | ``Tensor["B C D H W"]`` with channels ordered by ``use_channels``. |
### candidate_valid_from_token { #aria_nbv.vin.geometry.candidate_valid_from_token }
```python
vin.geometry.candidate_valid_from_token(token_valid, *, min_valid_frac)
```
Convert per-token validity into a per-candidate validity mask.
### center_crop_grid { #aria_nbv.vin.geometry.center_crop_grid }
```python
vin.geometry.center_crop_grid(grid, target_shape)
```
Center-crop a voxel grid with trailing XYZ/channel values.
### encode_projection_summary { #aria_nbv.vin.geometry.encode_projection_summary }
```python
vin.geometry.encode_projection_summary(
proj_data,
*,
batch_size,
num_candidates,
device,
dtype,
grid_size,
obs_count_max,
inv_dist_std_min,
inv_dist_std_p95,
)
```
Summarize semidense projection coverage, visibility, and depth.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|------------------|------------------------------------------------------------------|-------------------------------------------------------------------|------------|
| proj_data | [dict](`dict`)\[[str](`str`), [Tensor](`torch.Tensor`)\] \| None | Output from :func:`project_points_to_candidate_cameras`. | _required_ |
| batch_size | [int](`int`) | Batch size ``B``. | _required_ |
| num_candidates | [int](`int`) | Candidate count ``N_q`` per batch item. | _required_ |
| device | [torch](`torch`).[device](`torch.device`) | Target device for features. | _required_ |
| dtype | [torch](`torch`).[dtype](`torch.dtype`) | Output dtype. | _required_ |
| grid_size | [int](`int`) | Screen-space bin count per side for coverage. | _required_ |
| obs_count_max | [int](`int`) | Saturation point for the ``log1p(n_obs)`` reliability factor. | _required_ |
| inv_dist_std_min | [float](`float`) | Lower bound for inverse depth-uncertainty scaling. | _required_ |
| inv_dist_std_p95 | [float](`float`) | Upper reference percentile for inverse depth-uncertainty scaling. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|--------------------------|----------------------------------------------|
| | [Tensor](`torch.Tensor`) | ``Tensor["B N_q F_proj", float32]`` with |
| | [Tensor](`torch.Tensor`) | ``F_proj == SEMIDENSE_PROJ_DIM``, ordered by |
| | [Tensor](`torch.Tensor`) | `SEMIDENSE_PROJ_FEATURES`. |
### ensure_candidate_batch { #aria_nbv.vin.geometry.ensure_candidate_batch }
```python
vin.geometry.ensure_candidate_batch(candidate_poses_world_cam)
```
Ensure candidate camera poses are shaped as ``PoseTW["B N 12"]``.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|---------------------------|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|------------|
| candidate_poses_world_cam | [PoseBatchT](`aria_nbv.vin.geometry.pose_batch.PoseBatchT`) | Candidate camera poses ``T_w_c`` with shape ``PoseTW["N 12"]`` for one snippet or ``PoseTW["B N 12"]`` for a batch. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|-------------------------------------------------------------|----------------------------------------------|
| | [PoseBatchT](`aria_nbv.vin.geometry.pose_batch.PoseBatchT`) | Candidate poses with an explicit batch axis. |
#### Raises {.doc-section .doc-section-raises}
| Name | Type | Description |
|--------|----------------------------|---------------------------------------------------------------|
| | [ValueError](`ValueError`) | If the pose tensor is neither ``(N, 12)`` nor ``(B, N, 12)``. |
### ensure_pose_batch { #aria_nbv.vin.geometry.ensure_pose_batch }
```python
vin.geometry.ensure_pose_batch(pose, *, batch_size, name)
```
Broadcast one pose tensor to the VIN batch size.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|------------|-------------------------------------------------------------|-------------------------------------------------------------------------------------|------------|
| pose | [PoseBatchT](`aria_nbv.vin.geometry.pose_batch.PoseBatchT`) | Pose tensor with shape ``PoseTW["12"]``, ``PoseTW["1 12"]``, or ``PoseTW["B 12"]``. | _required_ |
| batch_size | [int](`int`) | Required batch size ``B``. | _required_ |
| name | [str](`str`) | Human-readable input name used in validation errors. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|-------------------------------------------------------------|----------------------------------------|
| | [PoseBatchT](`aria_nbv.vin.geometry.pose_batch.PoseBatchT`) | ``pose`` shaped as ``PoseTW["B 12"]``. |
#### Raises {.doc-section .doc-section-raises}
| Name | Type | Description |
|--------|----------------------------|-----------------------------------------------------------------------------|
| | [ValueError](`ValueError`) | If ``pose`` has an unsupported rank or a non-broadcastable batch dimension. |
### frustum_points_world_from_cameras { #aria_nbv.vin.geometry.frustum_points_world_from_cameras }
```python
vin.geometry.frustum_points_world_from_cameras(
poses_world_cam,
*,
p3d_cameras,
grid_size,
depths_m,
)
```
Generate per-candidate frustum sample points in world coordinates.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|-----------------|-----------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|
| poses_world_cam | [PoseTW](`efm3d.aria.pose.PoseTW`) | Candidate poses shaped as ``PoseTW["B N 12"]``. The tensor supplies the desired ``B`` and ``N`` layout; projection uses the aligned ``p3d_cameras`` batch. | _required_ |
| p3d_cameras | [PerspectiveCameras](`pytorch3d.renderer.cameras.PerspectiveCameras`) | PyTorch3D cameras aligned with candidates. The camera batch must be ``N`` when ``B == 1`` or ``B * N`` otherwise. | _required_ |
| grid_size | [int](`int`) | Number of image samples per side. | _required_ |
| depths_m | [list](`list`)\[[float](`float`)\] | Positive metric depths sampled along each image ray. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|--------------------------|---------------------------------------------------|
| | [Tensor](`torch.Tensor`) | ``Tensor["B N K 3"]`` world-frame frustum points. |
### infer_padded_grid_shape { #aria_nbv.vin.geometry.infer_padded_grid_shape }
```python
vin.geometry.infer_padded_grid_shape(num_pts, target_shape)
```
Infer a symmetrically padded voxel-grid shape from a flattened count.
### pool_voxel_points { #aria_nbv.vin.geometry.pool_voxel_points }
```python
vin.geometry.pool_voxel_points(pts_world, *, grid_shape, pool_grid)
```
Downsample voxel center points to a pooled token grid.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|------------|--------------------------------------------------------------|----------------------------------------------------------------------------|------------|
| pts_world | [Tensor](`torch.Tensor`) | Voxel centers as ``Tensor["B D H W 3"]`` or flattened ``Tensor["B V 3"]``. | _required_ |
| grid_shape | [tuple](`tuple`)\[[int](`int`), [int](`int`), [int](`int`)\] | Target ``(D, H, W)`` grid shape before pooling. | _required_ |
| pool_grid | [int](`int`) | Output side length ``G``. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|--------------------------|-----------------------------------------------------------|
| | [Tensor](`torch.Tensor`) | ``Tensor["B G*G*G 3"]`` pooled world-frame voxel centers. |
### pos_grid_from_pts_world { #aria_nbv.vin.geometry.pos_grid_from_pts_world }
```python
vin.geometry.pos_grid_from_pts_world(
pts_world,
*,
t_world_voxel,
pose_world_rig_ref,
voxel_extent,
grid_shape,
)
```
Convert voxel centers to a normalized position grid in reference-rig frame.
If ``pts_world`` corresponds to a padded grid (for example before a valid
Conv3d shrink), the grid is center-cropped to ``grid_shape`` before
normalization.
### project_points_to_candidate_cameras { #aria_nbv.vin.geometry.project_points_to_candidate_cameras }
```python
vin.geometry.project_points_to_candidate_cameras(
points_world,
p3d_cameras,
*,
batch_size,
num_candidates,
device,
)
```
Project world points into a batch of candidate cameras.
This is the shared projection path for semidense points and pooled voxel
centers. It enforces the PyTorch3D camera batch contract used by
:class:`aria_nbv.vin.models.scene_myopic.VinModelV3`: the camera batch is either
``Nq`` when ``B == 1`` or ``B * Nq`` for true batched inputs.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|----------------|-----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|
| points_world | [Tensor](`torch.Tensor`) \| None | ``Tensor["P C", float32]`` or ``Tensor["B P C", float32]`` in the world frame; XYZ is measured in metres. ``C`` must include XYZ; additional channels are propagated as ``inv_dist_std`` and optional ``obs_count`` when present. | _required_ |
| p3d_cameras | [PerspectiveCameras](`pytorch3d.renderer.cameras.PerspectiveCameras`) | PyTorch3D candidate camera batch with ``image_size``. | _required_ |
| batch_size | [int](`int`) | Batch size ``B``. | _required_ |
| num_candidates | [int](`int`) | Candidate count ``N_q`` per batch item. | _required_ |
| device | [torch](`torch`).[device](`torch.device`) | Target device for projection tensors. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|----------------------------------------------------------|---------------------------------------------------------------------|
| | [dict](`dict`)\[[str](`str`), [Tensor](`torch.Tensor`)\] | Dictionary with screen coordinates ``x``/``y``, camera depth ``z``, |
| | [dict](`dict`)\[[str](`str`), [Tensor](`torch.Tensor`)\] | ``finite`` and ``valid`` masks, optional reliability channels, |
| | [dict](`dict`)\[[str](`str`), [Tensor](`torch.Tensor`)\] | ``image_size``, and scalar ``num_cams``. |
### sample_candidate_voxel_coverage { #aria_nbv.vin.geometry.sample_candidate_voxel_coverage }
```python
vin.geometry.sample_candidate_voxel_coverage(
counts_norm,
*,
candidate_centers_world,
pose_finite,
t_world_voxel,
voxel_extent,
)
```
Sample normalized voxel observation coverage at candidate camera centers.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|-------------------------|------------------------------------|-----------------------------------------------------------------------------------------------------------------|------------|
| counts_norm | [Tensor](`torch.Tensor`) | ``Tensor["B 1 D H W", float32]`` normalized observation-count field from the VIN scene-field bundle. | _required_ |
| candidate_centers_world | [Tensor](`torch.Tensor`) | ``Tensor["B N 3", float32]`` candidate camera centers in the world frame. | _required_ |
| pose_finite | [Tensor](`torch.Tensor`) | ``Tensor["B N", bool]`` mask for finite candidate pose encodings. Non-finite poses are forced to zero coverage. | _required_ |
| t_world_voxel | [PoseTW](`efm3d.aria.pose.PoseTW`) | ``PoseTW["B 12"]`` world-from-voxel transform for the EVL grid. | _required_ |
| voxel_extent | [Tensor](`torch.Tensor`) | ``Tensor["B 6"]`` or ``Tensor["6"]`` voxel-frame grid bounds. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|--------------------------|------------------------------------------------------------------|
| | [Tensor](`torch.Tensor`) | ``Tensor["B N", float32]`` per-candidate coverage in ``[0, 1]``. |
#### Notes {.doc-section .doc-section-notes}
This helper keeps candidate-center voxel sampling out of scorer forward
methods. It is intentionally stateless and differentiability-neutral:
`sample_voxel_field` uses nearest-neighbor EVL sampling, and this helper
only folds in hard geometric validity plus pose finiteness.
### sample_semidense_points { #aria_nbv.vin.geometry.sample_semidense_points }
```python
vin.geometry.sample_semidense_points(snippet, *, device, max_points)
```
Sample valid semidense world points from a VIN snippet.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|------------|-------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|
| snippet | [Any](`typing.Any`) | Object with the :class:`aria_nbv.data_handling.vin_store.views.VinSnippetView` point contract. It must expose ``points_world`` as ``Tensor["P C", float32]`` or ``Tensor["B P C", float32]`` and optional ``lengths``. XYZ is measured in metres, ``1/sigma_d`` in inverse metres, and optional ``n_obs`` in channel five is a dimensionless count. | _required_ |
| device | [torch](`torch`).[device](`torch.device`) | Target device for the returned tensor. | _required_ |
| max_points | [int](`int`) | Maximum sampled point count per batch item. Batched inputs are padded to this length with NaNs so candidate projection keeps a rectangular ``Tensor["B P_fr C", float32]`` layout. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|--------------------------|----------------------------------------------------------------------|
| | [Tensor](`torch.Tensor`) | ``Tensor["P_fr C", float32]`` or ``Tensor["B P_max C", float32]`` on |
| | [Tensor](`torch.Tensor`) | ``device``. |
#### Raises {.doc-section .doc-section-raises}
| Name | Type | Description |
|--------|--------------------------------|----------------------------------------------------------------------------------------------------------------|
| | [RuntimeError](`RuntimeError`) | If the snippet has no valid points. |
| | [ValueError](`ValueError`) | If the point tensor has an invalid shape, insufficient channels, mismatched lengths, or non-finite XYZ values. |
### sample_voxel_field { #aria_nbv.vin.geometry.sample_voxel_field }
```python
vin.geometry.sample_voxel_field(
field,
*,
points_world,
t_world_voxel,
voxel_extent,
)
```
Sample a voxel-aligned field at world points.
World-space query points are transformed into EVL's metric voxel frame with
``T_voxel_world = T_world_voxel.inverse()`` and then converted to voxel-grid
indices with ``voxel_extent``.
#### Parameters {.doc-section .doc-section-parameters}
| Name | Type | Description | Default |
|---------------|------------------------------------|-------------------------------------------------------------------------------------------------------------------|------------|
| field | [Tensor](`torch.Tensor`) | ``Tensor["B C D H W"]`` voxel-aligned feature field. | _required_ |
| points_world | [Tensor](`torch.Tensor`) | ``Tensor["B N K 3"]`` world points where ``N`` is the candidate count and ``K`` is the query count per candidate. | _required_ |
| t_world_voxel | [PoseTW](`efm3d.aria.pose.PoseTW`) | ``PoseTW["B 12"]`` world-from-voxel transform. | _required_ |
| voxel_extent | [Tensor](`torch.Tensor`) | ``Tensor["B 6"]`` voxel-frame bounds ordered as ``[x_min, x_max, y_min, y_max, z_min, z_max]``. | _required_ |
#### Returns {.doc-section .doc-section-returns}
| Name | Type | Description |
|--------|------------------------------------------------------------------------|-----------------------------------------------------------------------|
| | [Tensor](`torch.Tensor`) | Tuple ``(tokens, valid)``: |
| | [Tensor](`torch.Tensor`) | - ``tokens``: ``Tensor["B N K C"]`` sampled field values. |
| | [tuple](`tuple`)\[[Tensor](`torch.Tensor`), [Tensor](`torch.Tensor`)\] | - ``valid``: ``Tensor["B N K", bool]`` extent and grid validity mask. |
### semidense_proj_feature_index { #aria_nbv.vin.geometry.semidense_proj_feature_index }
```python
vin.geometry.semidense_proj_feature_index(name)
```
Resolve a canonical semidense projection feature name to its index.
#### Parameters {.doc-section .doc-section-parameters}
name:
Canonical feature name from `SEMIDENSE_PROJ_FEATURES`.
#### Returns {.doc-section .doc-section-returns}
int
Zero-based channel index in the projection summary tensor.
#### Raises {.doc-section .doc-section-raises}
ValueError
If ``name`` does not identify a known projection summary feature.