Skip to content

Add ToF point cloud visualization and slicing tools - #1

Open
ddwts503 wants to merge 89 commits into
mainfrom
claude/lucid-cerf-3muz44
Open

Add ToF point cloud visualization and slicing tools#1
ddwts503 wants to merge 89 commits into
mainfrom
claude/lucid-cerf-3muz44

Conversation

@ddwts503

@ddwts503 ddwts503 commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

This PR introduces a complete Python package for visualizing and analyzing Time-of-Flight (ToF) point cloud data from CSV/text files. The package provides 3D visualization, cross-sectional slicing along arbitrary axes, and both interactive and batch processing capabilities.

Key Changes

  • Data Loading (loader.py): Robust CSV/text parser with automatic detection of delimiters (comma, tab, space, semicolon), header rows, and column mapping. Supports flexible column specification and handles various naming conventions for x/y/z coordinates and intensity values.

  • Visualization (visualize.py): Four visualization modes:

    • show_3d(): 3D scatter plot with matplotlib or Open3D backend, color-coded by height or intensity
    • show_slice(): Single cross-sectional view along any axis (x/y/z)
    • show_slices_grid(): Multi-panel grid display of evenly-spaced cross-sections
    • interactive_slice(): Interactive slider-based cross-section viewer for real-time exploration
  • CLI Interface (__main__.py): Full command-line interface supporting all visualization modes with extensive options for axis selection, thickness control, point sampling, and output formats.

  • Data Model (PointCloud dataclass): Clean abstraction for point cloud data with convenient property accessors for x/y/z coordinates.

  • Sample Data Generator (examples/generate_sample.py): Utility to create synthetic ToF point clouds (cylinder + sphere + noise floor) for testing without real hardware data.

Notable Implementation Details

  • Automatic delimiter detection using csv.Sniffer with fallback heuristics
  • Robust handling of malformed data with NaN/Inf filtering
  • Equal aspect ratio 3D visualization for accurate spatial representation
  • Efficient numpy-based data loading with fallback to manual parsing for irregular formats
  • Support for large datasets via random sampling (max_points parameter)
  • Flexible column specification via header names or explicit indices
  • Matplotlib colorbar integration for intensity/height visualization
  • Proper handling of edge cases (empty slices, single-point datasets, etc.)

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU

claude added 30 commits June 9, 2026 00:35
CSV/テキスト形式のToF点群を3D表示し、任意軸(X/Y/Z)で輪切り(断面)
表示するツールを追加。

- loader.py: 区切り文字・ヘッダ・列構成を自動判定するCSVローダ
- visualize.py: 3D散布図(matplotlib/Open3D)、単一断面、断面グリッド、
  スライダー式インタラクティブ断面
- __main__.py: CLI (--mode 3d/slice/grid/interactive)
- examples/generate_sample.py: 動作確認用の擬似ToF点群生成

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
プログラミング初心者向けに、ターミナルを開くところから3D表示・輪切り
表示まで、コピペで進められるMac向け手順書を追加。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
ToForge.dll を逆コンパイルして解読した仕様に基づき、640x480のToF .dat
(1フレーム=256Bヘッダ+640*480*4ch*int16=2,457,856B)を読み込む機能を追加。
X=(v-32768)*0.25, Y=(v-32768)*0.25, Z=v*0.25 [mm], IR=v。

- toforge.py: フレーム単位で点群を読み出すローダ(巨大ファイルでもメモリ安全)
- __main__.py: .dat 自動判定、--frame / --list-frames / --min-depth / --max-depth
- 合成データによる往復テストでX/Y/Z一致を確認

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
距離ヒートマップをスライダーでコマ送りし、顔が正面のフレームを探す
プレビュー画面を追加。良いフレーム番号を見つけて --frame に使う。

- toforge.read_depth_image: 1コマの距離を480x640の2D配列で取得
- browse.py: Slider + 前後ボタン + 矢印キーでコマ送り(GUI)
- __main__.py: .dat で --mode browse を有効化

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
スライダーが動かない環境向けに、多数コマの距離ヒートマップを1枚の
サムネイル一覧画像(各コマに frame 番号付き)として保存するモードを追加。
操作不要で固まらない。--n 枚数, --start/--end で範囲指定。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
フォルダ(SSDルートや日付フォルダ)を渡しても、中の .dat を再帰的に
探して使うように改良。日本語フォルダ名のドラッグでも確実に動く。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
輪切り一覧の左上に案内図を追加。顔(正面/側面)に赤い番号線で各断面の
位置を表示し、断面パネルの #番号 と対応づけて「どこを切っているか」を
わかりやすくした。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
顔の正面図で2点(口角、耳珠-鼻根など)をクリック、または --p1/--p2 で
座標指定し、その線に沿った斜め断面プロフィール(ライン方向 x 奥行きZ)を
表示する機能を追加。任意角度の輪切りに対応。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
顔の3点(耳珠x2+鼻根など)で基準面を定義し、その面を基準(新Z=面からの
距離)に座標変換した点群をCSV保存。以後その整列CSVを通常の輪切り/3Dに使え、
基準面に平行な層でスライスできる。クリック指定/座標指定の両対応。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
3点(耳珠x2+鼻根)から解剖学的座標系を構築: x'=左右(矢状面の法線),
y'=前後(前頭/背中面の法線), z'=上下(横断面の法線)。整列CSVを --axis x/y/z
で輪切りすると、それぞれ矢状面/前頭面/横断面のスライスになる。プレビューも
正面(coronal)・側面(sagittal)・上面(transverse)の3ビューに刷新。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
断面の長さ(輪郭の弧長)と面積(輪郭と弦で囲む面積)を計測する --mode measure を
追加。--compare で前後2データを重ねて Δ長さ・Δ面積を表示。PCAで輪郭の長手方向に
沿って計測するため傾きに頑健(既知形状で誤差1%台、傾き不変を確認)。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
3点が近すぎる/一直線の場合に NaN を出さず明確なエラーにする。divide-by-zero
警告の原因となる退化配置を防止。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
基準面を決めやすいよう、1点ずつ案内(左耳→右耳→鼻根)を表示し、クリック位置に
番号印を付ける対話ピッカーに改良。3点目で自動的に確定し、3ビューを表示して整列
CSVを保存する。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
クリックが不安定な環境向けに、座標グリッド付きの正面図を画像保存するモードを
追加。画像から左耳/右耳/鼻根の X,Y を読み、--p1/--p2/--p3 で基準面を非対話に
定義できる。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
matplotlibの対話窓が動かない環境向けに、front モードで plotly の HTML も出力。
ブラウザでホバーすると点の X,Y,Z が表示され、耳/鼻根の座標を正確に読める。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
- 整列計算を np.errstate で囲み macOS の空振り警告を抑制、非有限行は除去
- 画像保存後に絶対パスと exists を表示し、macOSでは subprocess open で自動表示
  (ユーザが open で見つけられない問題を回避)

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
点が荒くて顔が読めない問題に対応。X-Yを細かいマスに区切り平均奥行きで塗る
ヒートマップにして、顔の凹凸と耳/鼻根の位置をくっきり表示。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
ベッド等の支配的な平面をRANSAC(Open3D)で自動検出し、それをXY面(Z=ベッドから
の高さ)に整列した点群を保存。顔3点クリック不要で安定した基準が得られる。合成
データでベッド面=0, 突起高さの復元を検証。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
遠近のノイズ点(Zパーセンタイル外 + 統計的外れ値)を除去してから RANSAC で
ベッド面を検出。プレビューの表示範囲もパーセンタイルで読みやすく。外れ値を
混ぜた合成データで高さ範囲が正常化することを確認。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…/oblique)

保存後に絶対パスと存在確認を表示し macOS では自動で開く共通ヘルパーを loader に
追加し全モードで使用。--save は窓を開かないので固まらず、結果が確実に表示される。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
体の対称軸(PCA)で矢状面をx'=0へ自動整列し、頭足方向をy'に。さらに --yaw[度]
--dx --dy[mm] で手動微調整、--no-center で自動を無効化。プレビューに矢状中線
(赤)を表示。合成データで30°回転+オフセットの復元を確認。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
ベッド基準・矢状面合わせの調整手順書を追加。画像の見方、--yaw/--dx/--dy の
使い方と向きの決め方、輪切り・前後比較までの流れを記載。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…st axis)

肩幅が広いと主成分軸が左右になり矢状面がズレるバグを修正。footprintの鏡映重なり
で左右対称面(矢状面)を直接検出し、x'=0=体の中心線に整列。頭足方向をy'に。合成
データ(左右が長い体)で対称性0.99・中心線一致を確認。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
matplotlibの窓が固まる環境向けに、ブラウザ(Dash)でスライダーを動かすと矢状中線
(赤)がその場で回転・移動する対話調整画面を追加。保存ボタンで整列CSVを出力。
bedの整列計算を compute_bed_aligned/apply_manual に部品化して共用。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
回転が±45°では足りず矢状面に合わせられない問題に対応。yawを±180°、移動を
±500mmに拡大し、どんな向き・位置でも赤い中線を体の中心に合わせられるように。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
compute_bed_aligned/_center_body の行列積を np.errstate で囲み、macOSで出る
overflow/invalid の空振り警告を抑制(結果に影響なし)。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
前のサーバーが残っていても起動できるよう、空きポートを自動選択。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
2つの静止データ(.dat frame/CSV)をベッド+矢状面整列し、顔の幅・断面周囲・
断面面積・体積を計測して前後比較。高さスライダー付きブラウザUIで断面を重ね、
変化量と『小顔になったか』判定を表示。合成データ(20%細い顔)で幅/面積/体積の
減少検出を確認。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
同じ録画の別コマ同士を比べるとき、--after same で before と同じファイルを使え、
ドラッグ1回で済むようにした。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
- compare_app: .dat入力時に before/after のコマをブラウザのスライダーで選べる
  ようにし、高さスライダーと合わせて再計算(lru_cacheで高速化)
- 小顔比較アプリ.command: ダブルクリックでSSDの.datを自動検出して比較アプリを
  起動するmacOSランチャー(実行権限つき)

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
claude added 30 commits June 18, 2026 06:51
スライスの厚みを1mm刻みで調整できるスライダーを追加(初期5mm)。薄く切れる。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
縦/横スライスでビフォー・アフターのスライス線が連動する問題に対応。hposを
hposB/hposAに分離し、各画像のドラッグが独立。断面測定も各自の位置で行う。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…, v14

断面の重ね合わせで左右を各曲線の中心にそろえ(高さは保持)、形を直接比較できる
ように。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…ongside drag, v15

ドラッグでは1mm単位で動かしにくい件に対応。中心からのオフセットを1mm刻みで指定
する微調整スライダーをビフォー/アフター別々に追加(ドラッグと併用、ctxで判定)。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…er), v16

円もドラッグだと動きすぎる件に対応。円の中心の左右/上下を1mm刻みで微調整する
スライダーをビフォー/アフター別々に追加(ドラッグ位置に加算)。

https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
… v20

- scan /Volumes, Desktop, Downloads, Documents for .dat/.csv
- dropdowns + load button switch files without restarting
- frame sliders, ranges and initial circles reset on reload

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
- paste any SSD/folder/file path to recursively find .dat/.csv
- rescan button refreshes the auto list
- both dropdowns get the found files added

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…frames, v23

- load_align no longer raises on frames with no valid points (returns empty)
- before defaults to a good frame in first half, after in second half
- show 'no person in this frame' message instead of blank graph

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…eel + face zoom), v24

- _cb/_ca subtract fine-offset on drag so position no longer accumulates
- enable scrollZoom (mouse wheel) on top views
- add 'zoom to face' checkbox that frames the circle area

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…cess, v25

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
- new tof_viz/view3d_app.py: rotatable 3D point cloud in browser (plotly)
- data picker scans all /Volumes SSDs + paste-path; frame/max-depth/point-size
- --mode view3d CLI route; double-click 3Dビューア.command launcher
- serves on LAN for iPhone/iPad too

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…are v26, view3d v2

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…n; case-insensitive ext; lighter 3D budget. view3d v3, compare v27

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…iew3d v4

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…re v29, view3d v5

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…iew3d v6

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…v32, view3d v8

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
… servers, keep window open

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…e url + skip auto-open when launched. compare v33, view3d v9

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…depth); show /Volumes on failure

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…to avoid startup freeze

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
…pth 1500 to remove background. v10

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
… fixes scroll trap. v11

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
… export, reset view. v12

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
… affects view/CSV/GIF. v14

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5DFEBG7bLJVuc3rr9k9CU
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