Skip to content

feat: detect 3D cube shapes in neural network diagrams - #63

Open
ruanchenbin3 wants to merge 1 commit into
BIT-DataLab:mainfrom
ruanchenbin3:fix/cube-detection
Open

feat: detect 3D cube shapes in neural network diagrams#63
ruanchenbin3 wants to merge 1 commit into
BIT-DataLab:mainfrom
ruanchenbin3:fix/cube-detection

Conversation

@ruanchenbin3

Copy link
Copy Markdown

Summary

Adds detection of 3D cube projections commonly found in neural network architecture diagrams for representing tensors/feature maps.

Changes

  • Add cube to DRAWIO_STYLES (using isoCube shape)
  • Add cube to VECTOR_TYPES
  • Add _detect_cube_from_elements(): merges 3 adjacent rectangles/ parallelograms into a single cube element using geometric heuristics
  • Add _is_cube_triplet(): validates that 3 elements form a valid 3D cube projection
  • Hook cube detection into the processing pipeline

Testing

Tested on synthetic images with cube patterns. The heuristic checks:

  1. At least 2 out of 3 candidate rectangles share an edge (distance < 5px)
  2. Area ratio between largest and smallest face ≤ 10x

Related

Closes the issue where 3D cube shapes were not recognized as editable shapes in neural network diagrams.

Add detection of 3D cube projections commonly found in neural network
architecture diagrams for representing tensors/feature maps.

Changes:
- Add cube to DRAWIO_STYLES (using isoCube shape)
- Add cube to VECTOR_TYPES
- Add _detect_cube_from_elements: merges 3 adjacent rectangles/
  parallelograms into a single cube element
- Add _is_cube_triplet: heuristic check for cube topology
- Hook cube detection into the processing pipeline
Copilot AI review requested due to automatic review settings June 8, 2026 19:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds support for identifying and rendering 3D “cube” (feature-map/tensor) shapes by introducing a cube style and a post-processing pass that heuristically merges three adjacent face elements into a single cube element.

Changes:

  • Added DrawIO style mapping and vectorization support for a new cube shape type.
  • Added a post-processing step in process() to merge detected cube face triplets.
  • Implemented _detect_cube_from_elements() and _is_cube_triplet() heuristics for cube detection/merging.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1609 to +1621
"""检测3个相邻矩形/平行四边形是否构成3D立方体投影。

神经网络结构图中,3D tensor/feature map通常表示为3个相邻面的平行投影:
- 一个正面矩形(大)
- 一个顶面平行四边形(梯形)
- 一个侧面平行四边形

如果3个元素满足:
1. 每个都是矩形/平行四边形
2. 两两共享一条边
3. 相对位置构成透视投影
→ 合并为一个cube元素。
"""""
Comment on lines +1627 to +1635
# 收集所有矩形/平行四边形元素
rects = []
for elem in elements:
shape = elem.bbox or elem.shape_type
if not elem.bbox:
continue
b = elem.bbox
if hasattr(b, '__iter__'):
rects.append((elem, list(b)))
Comment on lines +1640 to +1649
# 暴力搜索:检查每3个元素是否构成cube
for i in range(len(rects)):
if i in merged:
continue
for j in range(i+1, len(rects)):
if j in merged:
continue
for k in range(j+1, len(rects)):
if k in merged:
continue
if len(elements) < 3:
return elements

import numpy as np
Comment on lines +1707 to +1710
# 至少两对相邻(距离==0)
adjacents = sum(1 for d in [d12, d13, d23] if d < 5)
if adjacents < 2:
return False
Comment on lines +1720 to +1722
# 最大面不应超过最小面的10倍
if min_a > 0 and max_a / min_a > 10:
return False
Comment on lines +1417 to +1419
# 检测3D立方体(3个相邻矩形合并为cube)
if hasattr(self, '_detect_cube_from_elements') and context.elements:
context.elements = self._detect_cube_from_elements(context.elements)
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.

2 participants