Skip to content

ReorderUnorganizedTexture: orthographic path produces invalid output size for degenerate/tiny meshes (vtkOBBTree) #20

Description

@csparker247

Summary

The orthographic reorder path (ReorderUnorganizedTexture::create_texture_) estimates the mesh's oriented bounding box with vtkOBBTree::ComputeOBB and derives the output image dimensions from the realigned bounds. For degenerate or very small meshes — e.g. a perfectly planar (zero-thickness) sheet, or a mesh with only a handful of vertices — vtkOBBTree returns ill-conditioned/garbage axes. The huge OBB axis then propagates through the realignment transform, so the transformed bounds blow up to ~±DOUBLE_MAX and the computed size overflows:

Output size: 2147483647x2147483647 (Sample rate: 0.05)   xLen=2e+38 yLen=2e+38 pts=6 cells=4

which makes cv::Mat::zeros(rows, cols, CV_8UC3) throw OutOfMemoryError (attempts a ~1.4e19-byte allocation).

Repro

Build a tiny flat quad-pair mesh (6 vertices, 4 triangles, all z=0), a valid UV map, and run compute() in the default ProjectionMode::Orthographic. It crashes in the allocation. The ProjectionMode::Camera path with explicit ProjectionParams is unaffected (it does not use vtkOBBTree).

Impact

Real photogrammetry meshes are dense and only "roughly planar," so this hasn't been hit in production — but it makes the orthographic path impossible to exercise with a small synthetic fixture. The multi-texture unit tests added in the #2 fix (ReorderMultiTexture.*) therefore drive the shared sampler via the camera path instead.

Possible fixes

  • Validate the computed OBB extents / output dimensions and fail with a clear error (or fall back) when they are non-finite or exceed a sane bound.
  • Replace/augment vtkOBBTree with a more robust OBB (e.g. PCA over vertices with a guard for rank-deficient covariance), so a genuinely planar mesh yields a well-defined in-plane basis + normal.
  • Guard create_texture_ so a degenerate OBB doesn't propagate an infinite transform.

Discovered while implementing #2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions