diff --git a/CLAUDE.md b/CLAUDE.md index 7a96017..0a7a1f6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -23,7 +23,7 @@ ## 開発進捗 -最新: フェーズ 7(実装)— **新しい実機の要件と候補の比較計画を決めた**(現行の形の改良 A1・A2 と箱形 B1・B2 をシミュで現行機と比べる.[PLAN_03](docs/03_PLAN/PLAN_03_新しい実機の要件.md).均一さは厳密な基準を置かずシミュで現行機より改善していれば良い.基板は研究室の MITS 製基板加工機で切削.基準シーンの spp は 4096).その前: **Fusion の SmTIASv3 に実物の LED 基板を組み込み**(実機の製作資料から KiCad の基板設計を `cad/kicad/`,回路・部品・カラーチャート・改良点を [SPEC_05](docs/04_SPEC/SPEC_05_実機の構成と部品.md) に整理.KiCad を Fusion Electronics に取り込み(`SmTIAS_LEDs_sch/brd`),基板の 3D モデル `SmTIAS_LEDs_3D`(LED 0.7 mm 厚はデータシート値)を作って SmTIASv3 の LED ユニットに組み込んだ(バージョン 4).LED は実物どおり間隔 4.0 mm で,`scene_baseline.yaml` の LED 位置もこの値に更新(それ以前の TEST は旧値 4.2 mm・1.0 mm 厚).取り込みは `configs/fusion/smtias_v3_pcb_mapping.yaml`.Fusion を API で編集するときの注意は [TECH_12](docs/05_TECH/TECH_12_Fusionからのシーン取り込み.md)).前ステップ: Fusion MCP 接続と Fusion → シーン取り込みの仕組み,TEST_20 実機とシミュの形の突き合わせ(基準候補 ρ=0.85・ω=0.05・α=0.1 + spot 45〜60°,左上暗の傾きは未解決).サーバは `sm-remote`(学外からは `SM_REMOTE_HOST=Newton-via-lab`).**環境**: mitsuba は **3.7.1 に固定**(テストは `uv run python -m pytest`),開発機の **SAC はオフ**(ENV_04 参照).同一 seed の再レンダは集計指標が一致するので,ノイズフロアは `render.seed` を変えて測る.**spp の指針**([TEST_19](docs/06_TEST/TEST_19_sppと計算時間ノイズ指標安定性.md)): GPU 時間は spp に比例(1024 で 5 秒)・固定費 0.8 秒・ノイズは 1/√spp 則.構造 CoV なら 1024,画像全体 min/max 比を暗い条件で比べるなら 2048〜4096.詳細は [docs/PROGRESS.md](docs/PROGRESS.md). +最新: フェーズ 7(実装)— **LED を 3 個 1 組のモジュールに分けて置き場所を探索**([TEST_21](docs/06_TEST/TEST_21_新しい実機の候補の比較.md) 結果 9.H_y90 の箱で場所ごとの基底画像の和から組み合わせを総当たりし,最良の L5 で構造 CoV が現行の 0.47 倍.重い前処理はサーバで回す.次は L5 で Fusion の設計へ進むかの判断).その前: **上面を傾けた箱で LED の位置と筐体の形を工夫**(結果 6〜8.鼻の穴の仕切りと天井の LED はユーザー判断で採らない).その前: **新しい実機の候補をシミュで比較**(箱形は構造 CoV が現行の約半分,現行の形は基板の置き方では改善しない).その前: **新しい実機の要件と候補の比較計画を決めた**(現行の形の改良 A1・A2 と箱形 B1・B2 をシミュで現行機と比べる.[PLAN_03](docs/03_PLAN/PLAN_03_新しい実機の要件.md).均一さは厳密な基準を置かずシミュで現行機より改善していれば良い.基板は研究室の MITS 製基板加工機で切削.基準シーンの spp は 4096).その前: **Fusion の SmTIASv3 に実物の LED 基板を組み込み**(実機の製作資料から KiCad の基板設計を `cad/kicad/`,回路・部品・カラーチャート・改良点を [SPEC_05](docs/04_SPEC/SPEC_05_実機の構成と部品.md) に整理.KiCad を Fusion Electronics に取り込み(`SmTIAS_LEDs_sch/brd`),基板の 3D モデル `SmTIAS_LEDs_3D`(LED 0.7 mm 厚はデータシート値)を作って SmTIASv3 の LED ユニットに組み込んだ(バージョン 4).LED は実物どおり間隔 4.0 mm で,`scene_baseline.yaml` の LED 位置もこの値に更新(それ以前の TEST は旧値 4.2 mm・1.0 mm 厚).取り込みは `configs/fusion/smtias_v3_pcb_mapping.yaml`.Fusion を API で編集するときの注意は [TECH_12](docs/05_TECH/TECH_12_Fusionからのシーン取り込み.md)).前ステップ: Fusion MCP 接続と Fusion → シーン取り込みの仕組み,TEST_20 実機とシミュの形の突き合わせ(基準候補 ρ=0.85・ω=0.05・α=0.1 + spot 45〜60°,左上暗の傾きは未解決).サーバは `sm-remote`(学外からは `SM_REMOTE_HOST=Newton-via-lab`).**環境**: mitsuba は **3.7.1 に固定**(テストは `uv run python -m pytest`),開発機の **SAC はオフ**(ENV_04 参照).同一 seed の再レンダは集計指標が一致するので,ノイズフロアは `render.seed` を変えて測る.**spp の指針**([TEST_19](docs/06_TEST/TEST_19_sppと計算時間ノイズ指標安定性.md)): GPU 時間は spp に比例(1024 で 5 秒)・固定費 0.8 秒・ノイズは 1/√spp 則.構造 CoV なら 1024,画像全体 min/max 比を暗い条件で比べるなら 2048〜4096.詳細は [docs/PROGRESS.md](docs/PROGRESS.md). 実装済みモジュール: - `src/sm_tias_lightsim/uniformity.py` — Rec.709 輝度変換 + CoV/std/max-min(SmTIAS-Evaluation コピー) @@ -168,4 +168,5 @@ - オフ軸 LED 配置の影響とサイズ依存: docs/06_TEST/TEST_17_オフ軸LED配置の影響とサイズ依存.md(LED を側壁に置いた非対称の定量.サイズとともに減衰するが,頑健性は球 > 立方体で軸上の優劣と逆転.明るくなるのは LED の反対側) - spp と計算時間・ノイズ・指標の安定性: docs/06_TEST/TEST_19_sppと計算時間ノイズ指標安定性.md(spp 256〜8192 × 6 条件.GPU 時間は spp に比例・固定費 0.8 秒,ノイズは 1/√spp 則に一致.構造 CoV は 1024 で十分,画像全体 min/max 比を暗い条件で比べるなら 2048〜4096) - 実機とシミュの形の突き合わせと配光の検討: docs/06_TEST/TEST_20_実機とシミュの形の突き合わせと配光の検討.md(実機 DNG とシミュを同じノイズ処理で全灯 + 単灯 3 灯の形で比較.お椀は ρ で合うが単灯のピークのずれと傾きはシミュが半分.壁 ω・α のスイープでは形全体を崩さずに合わせられず,LED 配光を spot FWHM 45〜60° に狭めると最良.共通の左上暗の傾きは未解決) +- 新しい実機の候補の比較: docs/06_TEST/TEST_21_新しい実機の候補の比較.md(現行と同じ大きさで現行の形の改良と箱形を比較.現行の形は基板の置き方で改善せず,暗部は +Y 縁の壁の張り出し(喉)が原因.箱形は構造 CoV が現行の約半分.最良は側壁の評価板寄りに 4 枚(明るい)と底に 2 枚・評価板向き + 遮光板(LED 12 個)) - 照明配置依存性の球と立方体の比較: docs/06_TEST/TEST_18_照明配置依存性の球と立方体の比較.md(LED の位置 θ・向き・個数を同内面積ペアで振った 198 条件.配置依存は球が立方体の 1/2〜1/3,対向 2 灯以上で形状差が消える.追加実験: 立方体は面の稜へ寄せると悪化,真下向き多灯はバッフル無しで成立するが板向き多灯には劣る,校正材質 ρ=0.81 でも結論不変だが軸上は両形状とも最良になる) diff --git "a/docs/03_PLAN/PLAN_03_\346\226\260\343\201\227\343\201\204\345\256\237\346\251\237\343\201\256\350\246\201\344\273\266.md" "b/docs/03_PLAN/PLAN_03_\346\226\260\343\201\227\343\201\204\345\256\237\346\251\237\343\201\256\350\246\201\344\273\266.md" index 45e3891..afbe1cd 100644 --- "a/docs/03_PLAN/PLAN_03_\346\226\260\343\201\227\343\201\204\345\256\237\346\251\237\343\201\256\350\246\201\344\273\266.md" +++ "b/docs/03_PLAN/PLAN_03_\346\226\260\343\201\227\343\201\204\345\256\237\346\251\237\343\201\256\350\246\201\344\273\266.md" @@ -19,6 +19,12 @@ | 筐体の方向性 | **「現行の形を改良」と「箱形で作り直し」の両方で進め**,シミュで比べて選ぶ | | LED の数と置き方 | 少ない方が良いが,均一さを優先する.現実的な範囲で決める | | 大きさ | 現行機(外形 約 150 × 150 mm,深さ 約 175 mm)からあまり変えない | +| 候補(ステップ 1 の後) | 側壁の評価板寄りに基板を置く B2_z25 の形で,箱の内寸を 160 mm に広げて進める | +| 外側の形 | 真四角は製品として良くないので,外側の角を丸める.内側の角も丸めてよい(シミュで確かめる) | +| スマホの画面 | 撮影される人が装置の上越しにスマホの画面を見る.**今と同じくらいの範囲が見えることを必須とする**(2026-11-05.均一さのために画面の見え方を譲る案(上下対称の箱)は採らない) | +| 流用する部品 | 照明ムラ補正ボード(評価板)・スマホホルダ・顔側(前面)の形はそのまま使う.顔側は**外側(顔に当たる面)と評価板の受けだけ**流用し,内側はシミュの箱のとおり評価板の縁から水平に広がる天井にする(今の前側の内側には評価板の縁に張り出した壁(喉)があり,上の縁が暗くなる原因のため.2026-11-05 ユーザー判断) | +| 鼻の穴 | 2026-11-05 のユーザー判断.実際に使うには鼻を逃がす穴が要るので**必須**とする.シミュの候補もすべて穴を開けた形で比べる.口を開けて穴に入れるときの妨げになるので,鼻の穴と箱の中の間に仕切り(穴を袋にする壁)は入れない | +| LED の置き場所 | 2026-11-05 のユーザー判断.評価板の上の縁と上の壁の間(天井の近く)に LED を付けるのは現実的でないので置かない(シミュでは細い LED 列で鼻の穴の前の暗さを補えたが採らない) | ## 進め方 (Workflow) @@ -49,6 +55,8 @@ - LED 基板は現行と同じもの(1 枚に LED 6 個)を使う.向きは現行と同じく評価板と反対側(スマホ側).この向きなら遮光板なしで成り立つ([TEST_18](../06_TEST/TEST_18_照明配置依存性の球と立方体の比較.md)).遮光板を付けた場合も比べる - 現行機は評価板の中心と内部空間の中心が少しずれている可能性があるので,基板を足せる場所があるかを 3D で確かめる.**レンダの前に配置の 3D 画像をユーザーに見せて確認をもらう**(CLAUDE.md「シミュレーション実験の進め方」) +**結果(2026-11-04)**: [TEST_21](../06_TEST/TEST_21_新しい実機の候補の比較.md).現行の形は基板の置き方では改善しない(暗部は +Y 縁の壁の張り出しが原因).箱形は構造 CoV が現行の 0.46〜0.63 倍で,候補は C1(底に 2 枚・評価板向き + 遮光板.LED 12 個・明るさ 0.44 倍)と B2_z25(側壁の評価板寄りに 4 枚・下向き.LED 24 個・明るさ 1.08 倍)に絞られた. + ### ステップ 2: 良かった形を Fusion で設計する 改良案・箱形のそれぞれで最良のものを Fusion で形にする(三脚の穴・スマホの置き場所・ケーブルの穴・組み立てまで).取り込んでシミュで確かめ直す. @@ -62,10 +70,12 @@ | 項目 | 内容 | | --- | --- | | 開口部 | 舌を写すための開口部を設ける | +| 鼻の穴 | **必須**.顔を当てたときに鼻が入る切り欠きを上の壁(+Y 側)の顔側に設ける.形は現行機の前側と同じ(顔の面で幅 30 mm,深さ 15 mm で幅 15 mm に狭まり,底は半径 7.5 mm の丸.顔の面から深さ 22.5 mm).穴は箱の中につながるので,評価板の縁から光が逃げる.上の壁が評価板の縁に近い形ほど上の縁の中央が暗くなる(シミュは穴の外を光を返さない空間として扱う.現行機のシミュ A0 も同じ) | | 評価板 | 開口部をふさいで照明の均一さを測る評価板(照明ムラ補正ボード)を作る.シミュの評価面もこの板 | | 三脚の取付 | 三脚に固定するための穴をあける(現行機は Ulanzi MT-73) | | スマホの設置 | スマホを置ける(保持できる)ようにする | | カメラの視野 | カメラから見て開口部が筐体・部品でふさがれない(開口部全体が写る) | +| スマホの画面 | **必須**.撮影される人が装置の上(+Y 側)越しにスマホの画面を,今と同じくらいの範囲で見られる.現行機の上面が顔側で低く奥ほど下がっているのはこのため.外面の上端を顔側 Y = 62 mm・奥へ 1 mm につき 0.18 mm 下げる(Z = −150 で約 35 mm)と,目の高さ Y = 60〜90 mm(顔側から 25 mm 手前と仮定)で今と同じかそれ以上に見える | | ピントの合う距離 | カメラから開口部(評価板)までの距離を,使うスマホのカメラでピントが合う範囲(最短撮影距離より遠く)にする | | 外光の遮断 | 開口部のすき間・スマホ側から外の光が入らない(シミュは外光ゼロで計算している) | | 位置の再現性 | スマホと評価板を毎回同じ位置に置ける(突き当て・溝などで位置が決まる) | @@ -105,3 +115,4 @@ - **LED は対向 2〜4 か所に分ける**と,形による差が消えて 1 か所より均一になる - **大きいほど均一だが暗い**(明るさは内面積にほぼ反比例) - 現行機の 3 基板(下・右・左)は対称でないため,左右の偏りが出やすい配置である +- **鼻の穴は評価板の縁から離す**: 現行機の上の縁の中央が暗いのは主に鼻の穴から光が逃げるため.上面を傾けた箱では穴が縁に近く,構造 CoV が穴なしの 1.15〜1.2 倍に悪化する.上下対称の箱(上の壁が縁から 30 mm 離れる)ではほぼ影響がない([TEST_21](../06_TEST/TEST_21_新しい実機の候補の比較.md)) diff --git "a/docs/06_TEST/TEST_02_\343\202\267\343\203\237\343\203\245\343\203\254\343\203\274\343\202\267\343\203\247\343\203\263\345\256\237\350\241\214\350\250\230\351\214\262.md" "b/docs/06_TEST/TEST_02_\343\202\267\343\203\237\343\203\245\343\203\254\343\203\274\343\202\267\343\203\247\343\203\263\345\256\237\350\241\214\350\250\230\351\214\262.md" index 6c868f3..2634913 100644 --- "a/docs/06_TEST/TEST_02_\343\202\267\343\203\237\343\203\245\343\203\254\343\203\274\343\202\267\343\203\247\343\203\263\345\256\237\350\241\214\350\250\230\351\214\262.md" +++ "b/docs/06_TEST/TEST_02_\343\202\267\343\203\237\343\203\245\343\203\254\343\203\274\343\202\267\343\203\247\343\203\263\345\256\237\350\241\214\350\250\230\351\214\262.md" @@ -100,6 +100,7 @@ | `output/led_placement_sweep/{summary.csv,analysis.csv,position_summary.csv,position_sensitivity.png,position_maps.png,direction_comparison.png,count_comparison.png,azimuth_comparison.png,ring_comparison.png,analysis_report.txt}`・`_placement_check/cutaway_*.png` | TEST_18 | — | — | 条件別集約 CSV/方位フーリエ m=1〜4・構造 CoV・重心の解析 CSV/位置・向き・灯数・方位角・真下向き多灯の解析図 6 枚/レンダ前 3D 確認の半割り断面 23 枚 | `scripts/build_led_placement_comparison.py`・`show_scene_cutaway.py` の出力.レンダ前 3D 確認(CLAUDE.md 必須ルール)の記録を兼ねる | | `output/cube_size_sweep/board_baffle/{summary.csv,cube_vs_sphere.png,fourfold_component.png}`・`output/cube_size_sweep/_placement_check/cutaway_L*.png` | TEST_16 | — | — | 条件別集約 CSV/球との比較図(輝度マップ 5 枚 + 輪帯プロファイル + 内面積軸の指標カーブ + 直接ペア 3 組)/m=4(cos 4φ)成分の定量図/レンダ前 3D 確認の半割り断面 5 枚 | `scripts/build_cube_sphere_comparison.py`・`analyze_fourfold_component.py`・`show_scene_cutaway.py` の出力.m=4 は全条件 \|a4\| ≤ 0.26%(系統誤差床 ~0.1%)=四隅の写り込みは実質ゼロ.レンダ前 3D 確認(CLAUDE.md 必須ルール)の記録を兼ねる | | `output/_slide_panels/sphere_loft_disk_before_after.png`・`normal_artifact_explainer.png` | TEST_12 | — | — | 球ロフト円形光源の修正前後 1×2 比較(相対輝度・共通スケール)/法線アーティファクトの機構説明図(模式図+実物メッシュの補間法線再現+修正前マップの 4 パネル) | 発表スライド素材(アドホック生成.修正前後比較は CoV 0.1205→0.0628 の視覚版) | +| `output/candidate_layouts/`(17 候補 × seed 3 + `summary*.csv`・`comparison.png`・`_geometry/`) | TEST_21 | `configs/_tmp_candidates/scene_*.yaml`(`scripts/sweep_candidate_layouts.py` が基準シーンから生成.現行の形 A0〜A2・箱形 144 mm 角の B1/B2 と LED 高さ違い・底に置き評価板へ向け遮光板の C1/C2・診断 A0_white.spp 4096・Newton GPU 1・cuda) | TEST_20 と同じ処理(`compare_real_vs_sim_metrics.metrics_for`) | 箱形は構造 CoV が現行の 0.46〜0.63 倍・min 全体 0.90〜0.915.最良は B2_z25(0.46 倍・明るさ 1.08)と C1(0.48 倍・LED 12 個・明るさ 0.44).現行の形は基板の置き方で改善しない — [TEST_21](TEST_21_新しい実機の候補の比較.md) 参照 | 現行機の +Y 縁の暗部は壁の張り出し(喉)が原因.スマホ・ホルダを白にしても不変 | ### sweep_summary.csv の値(参考、TEST_01 line と一致確認用) @@ -158,6 +159,7 @@ | 球ロフト円形光源版レンダ・評価 (TEST_11 追補) | `$env:DRJIT_LIBLLVM_PATH = "C:\Program Files\LLVM\bin\LLVM-C.dll"; uv run sm-render --scene configs/scene_sphere_r100_loft_disk.yaml --output output/sphere_r100_loft_disk/` → `uv run sm-evaluate --image output/sphere_r100_loft_disk/luminance.npy --config configs/eval_baseline_dng_target_shape.yaml --output output/sphere_r100_loft_disk/` | | 単灯再検証レンダ・集計 (TEST_12 追補) | `$env:DRJIT_LIBLLVM_PATH = "C:\Program Files\LLVM\bin\LLVM-C.dll"; uv run sm-render --scene configs/_tmp_fix_{bottom,left,right}.yaml --output output/singles_fix/{bottom,left,right}/` → `uv run python scripts/build_singles_fix_summary.py` | | spp スイープ (TEST_19) | `uv run python scripts/sweep_spp_noise.py --prepare-only` → `uv run sm-remote push` → `uv run sm-remote run --name spp --gpu 0 --threads 16 -- python scripts/sweep_spp_noise.py` → `uv run sm-remote pull spp_noise_sweep` → `uv run python scripts/build_spp_noise_comparison.py` | +| 新しい実機の候補 (TEST_21) | `uv run sm-remote push` → `uv run sm-remote run --name cand --gpu 1 -- python scripts/sweep_candidate_layouts.py` → `uv run sm-remote pull candidate_layouts` → `uv run python scripts/build_candidate_comparison.py` | | spp スイープ追試・6 形状 (TEST_19) | `uv run python scripts/sweep_spp_noise.py --set shapes6 --prepare-only` → `uv run sm-remote push --include configs/_tmp_led_placement --include configs/_tmp_spp_noise_shapes6` → `uv run sm-remote run --name shapes6 --gpu 0 --threads 16 -- python scripts/sweep_spp_noise.py --set shapes6 --spps 256 512 1024 2048 4096 8192` → `uv run sm-remote pull spp_noise_shapes6` → `uv run python scripts/build_spp_shapes6_summary.py` | | 実機 vs シミュ 形の突き合わせ (TEST_20) | `uv run python scripts/compare_real_vs_sim_metrics.py --sim output/real_vs_sim/sim_rho081_spp4096/luminance.npy --tag rho081` → `uv run python scripts/compare_real_vs_sim_shapes.py --sim-set {legacy,rho081}` | | 壁反射特性・spot スイープ (TEST_20) | `uv run sm-remote push --only scripts` → `uv run sm-remote run --name wall --gpu 0 --threads 16 -- python scripts/sweep_wall_bsdf_spot.py --phase all --workers 2` → `uv run sm-remote pull wall_bsdf_spot` → `uv run python scripts/build_shape_fit_comparison.py` | diff --git "a/docs/06_TEST/TEST_21_\346\226\260\343\201\227\343\201\204\345\256\237\346\251\237\343\201\256\345\200\231\350\243\234\343\201\256\346\257\224\350\274\203.md" "b/docs/06_TEST/TEST_21_\346\226\260\343\201\227\343\201\204\345\256\237\346\251\237\343\201\256\345\200\231\350\243\234\343\201\256\346\257\224\350\274\203.md" new file mode 100644 index 0000000..60e5f1c --- /dev/null +++ "b/docs/06_TEST/TEST_21_\346\226\260\343\201\227\343\201\204\345\256\237\346\251\237\343\201\256\345\200\231\350\243\234\343\201\256\346\257\224\350\274\203.md" @@ -0,0 +1,257 @@ +# 新しい実機の候補の比較 (Candidate Layouts for the Next Device) + +[PLAN_03](../03_PLAN/PLAN_03_新しい実機の要件.md)「候補の比較計画」のステップ 1.現行機と同じ大きさのまま, +「現行の形を改良(A)」と「箱形で作り直し(B・C)」の候補をシミュで現行機と比べた(2026-11-04. +ユーザー不在の間に自律判断で実施.配置の 3D 確認もユーザーの代わりに行った). + +結論: **現行の形のまま基板を足し引きしても改善しない(悪化する)**.現行機の暗部(評価板の +Y 側の縁)は +**筐体の壁が評価板の縁の直下に張り出した「喉」**が原因で,LED の置き方では直らない. +**箱形にすると構造 CoV が現行機の 0.46〜0.63 倍**,画像全体の最小/最大が 0.794 → 0.90〜0.915 になる. +LED の数(2 枚 / 4 枚)は対称に置けば均一さにほぼ効かず,明るさだけが変わる. + +関連: + +- 要件・候補の計画: [PLAN_03](../03_PLAN/PLAN_03_新しい実機の要件.md) +- 喉が最大のレバーであること: [TEST_15](TEST_15_バッフル導入と球半径スイープ.md) +- 箱形(立方体)の有利さ・灯数と向き: [TEST_16](TEST_16_立方体キャビティ導入と球との比較.md),[TEST_18](TEST_18_照明配置依存性の球と立方体の比較.md) +- 指標の処理: [TEST_20](TEST_20_実機とシミュの形の突き合わせと配光の検討.md) +- 実行記録: [TEST_02](TEST_02_シミュレーション実行記録.md) + +## 実験条件 (Setup) + +- 基準: `configs/scene_baseline.yaml`(現行機.材質 ρ=0.85 diffuse・spp 4096・max_depth 16・512²).材質・LED 1 個あたりの放射量・レンダ設定は全候補で同じ(LED が増えれば全体は明るくなる) +- LED 基板: 現行と同じもの(LED 基板カバー + LED 6 個)を剛体として回転・移動して置く +- 箱形: 内寸 144 mm 角・深さ 144 mm(現行機の内寸の幅 X = ±72 mm に合わせた立方体.評価板・リムは TEST_16 と同じ).底面にスマホ側の窓の代わりの暗い板(120 × 34 mm,`holder_dark`)を置く +- C 系: 基板を箱の底に裏返して置き LED を評価板へ向け,各基板の 10 mm 上に遮光板(評価板裏面が LED から直接見えない大きさ+1.5 mm).遮蔽は `verify_baffle_occlusion.py` で全レイ(C1 66 万本・C2 133 万本)遮られることを確認 +- 評価: TEST_20 と同じ処理(`compare_real_vs_sim_metrics.metrics_for`.構造 CoV・画像全体のノイズ補正付き min/max・輪帯平均 min/max・方位フーリエ).seed を変えて 3 本ずつ回し平均(seed 間の標準偏差は構造 CoV で最大 0.0002,画像全体 min/max で最大 0.003) +- 実行: 研究室サーバ Newton の GPU 1 枚(1 本 約 18 秒) + +## 結果 (Results) + +比較図: `output/candidate_layouts/comparison.png`.構造 CoV の小さい順. + +| 候補 | 内容 | LED | 構造 CoV(現行比) | min 全体 | min 輪帯 | 明るさ(現行比) | +| --- | --- | --- | --- | --- | --- | --- | +| B2_z25 | 箱形・上下左右 4 枚・LED 高さ Z = −25(評価板寄り) | 24 | 0.0189(**0.46**) | 0.913 | 0.921 | **1.08** | +| C1 | 箱形・底に上下 2 枚・評価板向き + 遮光板 | **12** | 0.0197(**0.48**) | **0.915** | 0.921 | 0.44 | +| C2 | 箱形・底に 4 枚・評価板向き + 遮光板 | 24 | 0.0198(0.48) | 0.915 | 0.920 | 0.80 | +| B2_z115 | 箱形・4 枚・Z = −115 | 24 | 0.0216(0.53) | 0.912 | 0.914 | 0.91 | +| B1_z90 | 箱形・左右 2 枚・Z = −90 | 12 | 0.0218(0.53) | 0.909 | 0.916 | 0.47 | +| B1_z115 | 箱形・左右 2 枚・Z = −115 | 12 | 0.0221(0.54) | 0.909 | 0.914 | 0.45 | +| B2_z90 | 箱形・4 枚・Z = −90 | 24 | 0.0223(0.54) | 0.907 | 0.914 | 0.94 | +| B1 | 箱形・左右 2 枚・Z = −66(現行と同じ高さ) | 12 | 0.0240(0.59) | 0.898 | 0.906 | 0.50 | +| B1_z45 | 箱形・左右 2 枚・Z = −45 | 12 | 0.0242(0.59) | 0.894 | 0.905 | 0.52 | +| B2 | 箱形・4 枚・Z = −66 | 24 | 0.0255(0.62) | 0.896 | 0.902 | 0.97 | +| B2_z45 | 箱形・4 枚・Z = −45 | 24 | 0.0259(0.63) | 0.891 | 0.898 | 1.02 | +| B1_z25 | 箱形・左右 2 枚・Z = −25 | 12 | 0.0282(0.69) | 0.872 | 0.927 | 0.55 | +| A0 | 現行機 | 18 | 0.0409(1.00) | 0.794 | 0.890 | 1.00 | +| A0_white | 現行機・スマホとホルダを白に(診断) | 18 | 0.0409(1.00) | 0.794 | 0.891 | 1.00 | +| A2_lr | 現行の形・左右 2 枚 | 12 | 0.0426(1.04) | 0.792 | 0.892 | 0.67 | +| A1 | 現行の形 + 上の基板(4 枚) | 24 | 0.0477(1.17) | 0.772 | 0.886 | 1.30 | +| A2_tb | 現行の形・上下 2 枚 | 12 | 0.0483(1.18) | 0.769 | 0.879 | 0.65 | + +### 結果 1 — 現行の形では基板の置き方で改善しない + +- 現行の形の候補(A1・A2)はどれも現行機と同じか悪い.上の基板を足す(A1)と悪化する(上の基板は内壁の都合で評価板の中心から 41 mm と,下の基板の 71 mm より近い) +- 全候補に共通して,画像の上端中央(物理 +Y,評価板の縁)に暗部がある.方位フーリエの b1(Y 方向の傾き)は現行の形で 0.037〜0.049,箱形で 0.001〜0.003 +- **スマホとホルダを白にしても(A0_white)指標は 4 桁まで同じ** = 暗部は暗い部品の写り込みではない +- 筐体の形を見ると,+Y 側の壁が評価板の縁の直下(Z = −10〜−40 mm)で内側へ張り出しており,TEST_15 の「喉」と同じ形になっている.キャビティ全体も評価板の中心から −Y へ約 15 mm ずれている(LED 基板の高さで内壁は Y = −77〜+47 mm) + +### 結果 2 — 箱形は現行機の約半分のムラ + +- 同じ大きさの箱形にするだけで構造 CoV は 0.59〜0.62 倍,min 全体は 0.90 前後になる.傾き(b1)はほぼ消え,残るのは中央が明るい同心円のお椀だけ +- 下向き(スマホ側向き)の基板は,**4 枚なら評価板寄り(Z = −25)が最良**,2 枚なら深め(Z = −90〜−115)が良い.2 枚を評価板寄りに置くと左右方向に伸びた形(a2 = 0.035)になり悪化する +- **底に置いて評価板へ向け遮光板を付ける(C 系)と,2 枚でも 4 枚でも最良級**(0.48 倍・min 全体 0.915) + +### 結果 3 — 灯数は均一さにほぼ効かず明るさに効く + +- 対称に置けば 2 枚と 4 枚の差は小さい(C1 と C2 は構造 CoV 0.0197 / 0.0198).TEST_18 の「対向 2 灯以上で形状差が消える」と一致 +- 明るさは LED の数にほぼ比例する(C1 は現行の 0.44 倍).現行機の露光(ISO 40・8.3 ms)を保つなら,C1 は露光時間を約 2.3 倍にするか,LED を増やす必要がある + +### 結果 4 — カメラの視野と基板ごとの出力差 + +- **カメラの視野**(`scripts/check_camera_view.py`): カメラを窓の中心 (0, 4, −144) mm から ±10 mm・±25 mm ずらした 9 点から,評価板の開口部(±49.5 × ±51 mm)の 41 × 41 点へ線分を引き,LED 基板カバー・遮光板の外接箱と交わるかを調べた.B2_z25・C1・C2・B1_z90・B2 とも**ふさぐ部品なし**.検査が働くことは,カメラを遮光板の真下 (0, −48) に置くと C1 で 98〜100% ふさぐと出ることで確かめた +- **基板ごとの出力差**: 下の基板だけ放射量を +10% にした.構造 CoV の変化は全候補で 1% 未満,画像全体 min/max の変化は 0.004 以下,Y 方向の傾き b1 の変化は 0.004 以下 + +| 候補 | 構造 CoV(+10% 前 → 後) | min 全体 | b1 | +| --- | --- | --- | --- | +| A0 | 0.0409 → 0.0408 | 0.794 → 0.796 | 0.0372 → 0.0368 | +| B2_z25 | 0.0189 → 0.0190 | 0.913 → 0.914 | −0.0008 → 0.0026 | +| C1 | 0.0197 → 0.0198 | 0.915 → 0.919 | −0.0014 → −0.0007 | +| C2 | 0.0198 → 0.0198 | 0.915 → 0.915 | −0.0011 → −0.0003 | + +- 副次的な発見: 現行機(A0)でも下の基板の +10% は傾きをほとんど変えない.**TEST_20 で未解決の「左上が暗い」傾きを基板ごとの出力差で説明するのは難しい**(10% 程度の差では傾きは 0.001 も動かない.壁の形か基板の位置・向きの方が候補として残る) + +### 結果 5 — 箱の大きさへの感度 + +内寸 144 mm に対し 130 mm(−10%)・160 mm(+11%)を,C1 と B2_z25 で比べた(側壁の基板は壁からの距離を保って動かし,C1 の底の基板は Y = ±50 mm のまま).比較図: `output/candidate_layouts/comparison_size.png`. + +| 候補 | 内寸 | 構造 CoV(現行比) | min 全体 | min 輪帯 | 明るさ(現行比) | +| --- | --- | --- | --- | --- | --- | +| C1 | 130 mm | 0.0257(0.63) | 0.893 | 0.900 | 0.51 | +| C1 | 144 mm | 0.0197(0.48) | 0.915 | 0.921 | 0.44 | +| C1 | 160 mm | 0.0147(**0.36**) | **0.938** | 0.941 | 0.37 | +| B2_z25 | 130 mm | 0.0293(0.71) | 0.877 | 0.888 | 1.26 | +| B2_z25 | 144 mm | 0.0189(0.46) | 0.913 | 0.921 | 1.08 | +| B2_z25 | 160 mm | 0.0118(**0.29**) | **0.940** | 0.951 | 0.90 | + +- **大きさは置き方より強く効く**.内寸を 1 割変えると構造 CoV は 2〜3 割変わる(TEST_15・16 の「大きいほど均一だが暗い」と同じ) +- 大きくすると B2_z25 の方が伸びる(160 mm で 0.29 倍).小さくすると C1 の方が崩れにくい +- 外形は内寸 + 壁の厚さ 2 × 3 mm なので,内寸 160 mm で外形 166 mm 角(現行機 150 mm 幅の 1.1 倍)になる + +### 結果 6 — 内寸 160 mm の箱の角の丸み・スマホの画面・鼻の穴 + +ユーザー判断で B2_z25・内寸 160 mm に進めた後の確認(2026-11-05).数値は seed 3 本の平均で,比は現行機(A0)に対する値. + +**内側の角の丸み**(`B2_z25_L160_R{10,20,25}`.外側も丸める前提で,内側も丸めたときの影響).丸めるほど少し良くなる(構造 CoV 0.29 → 0.25 倍,明るさ 0.90 → 1.00 倍).半径 27 mm を超えると天井の平らな部分が評価板の縁より狭くなるので 25 mm が上限. + +**スマホの画面を見るための上面の傾き**(`F3_y80` など).撮影される人は装置の上越しにスマホの画面を見る.今と同じ範囲が見えるように上面を奥ほど下げた(外面の上端を顔側 Y = 62 mm・奥へ 1 mm につき 0.18 mm 下げる.PLAN_03「スマホの画面」).上の壁が評価板の縁から 8 mm しか離れず,上の壁には基板を置けない(置くとカメラの視野をふさぐ)ので,下・右・左の 3 枚にした. + +| 候補 | 内容 | 構造 CoV(現行比) | min 全体 | b1 | 明るさ | +| --- | --- | --- | --- | --- | --- | +| B2_z25_L160 | 上下対称の箱・4 枚 | 0.29 | 0.940 | 0.000 | 0.90 | +| F3_y80 | 上面を傾けた箱・3 枚 | 0.75 | 0.873 | +0.036 | 0.78 | +| F4_y80 | 同上 + 上の壁の奥(Z = −70)に 1 枚 | 0.87 | 0.863 | +0.041 | 1.00 | +| F3_y80_s10_b1 | 左右の基板を +Y へ 10 mm | 0.58 | 0.888 | +0.019 | 0.78 | +| F3_y80_s20_b1 | 左右の基板を +Y へ 20 mm | 0.58 | 0.875 | +0.004 | 0.78 | +| F3_y80_s10_b05 | +10 mm・下の基板の明るさ 0.5 倍 | 0.65 | 0.874 | −0.001 | 0.65 | +| F3_y80_s20_b0 | +20 mm・下の基板なし | 1.35 | 0.779 | −0.050 | 0.52 | + +- 上面を下げると +Y 側(評価板の上の縁)が暗くなる傾きが現行機並みに戻る.上の壁の奥に基板を足すと奥ばかり明るくなりかえって悪い +- 傾きは左右の基板を +Y へずらすと打ち消せる(+20 mm で b1 ≈ 0).下の基板を暗くすると全体が暗くなり,打ち消し過ぎもしやすい +- 傾きを消しても評価板の上の縁の中央が局所的に暗く,構造 CoV は 0.58 倍で止まる + +**鼻の穴**(候補名の末尾 `_N`).実際に使うには鼻の穴が必須(PLAN_03).現行機の前側と同じ切り欠き(顔の面で幅 30 mm・底は半径 7.5 mm の丸・深さ 22.5 mm)を上の壁に開けた.穴の外は光を返さない扱い(現行機のシミュ A0 の STL にも同じ穴があり,同じ扱い).比較図: `output/candidate_layouts/comparison_nose.png`・穴の形: `nose_closeup.png`. + +| 候補 | 構造 CoV(穴なし → 穴あり) | min 全体 | b1 | 明るさ | +| --- | --- | --- | --- | --- | +| B2_z25_L160_N | 0.29 → **0.30** | 0.942 | +0.003 | 0.89 | +| F3_y80_N | 0.75 → 0.87 | 0.837 | +0.043 | 0.77 | +| F3_y80_s10_b1_N | 0.58 → 0.70 | 0.840 | +0.025 | 0.77 | +| F3_y80_s20_b1_N | 0.58 → **0.67** | 0.827 | +0.011 | 0.77 | + +- **現行機の上の縁の中央が暗いのは主に鼻の穴のため**.上面を傾けた箱に穴を開けると同じ場所に同じ形の暗部が出る(壁が縁に近く,縁から見た穴が大きい) +- 上下対称の箱では穴が縁から 30 mm ほど離れ,影響はほぼ無い +- 撮影時は鼻と肌が穴をふさぐので,撮影時の悪化はこれより小さい可能性がある.ただし評価板での評価は顔を当てずに行うので,評価の条件はこのシミュと同じ(穴が開いたまま) + +### 結果 7 — 画面が見えることと鼻の穴を必須にした上での改善 + +画面が今と同じ範囲で見えることと鼻の穴を必須の要件にした(PLAN_03.2026-11-05 ユーザー判断)ので,上下対称の箱は採らず,F3_y80_s20_b1_N(上面を傾けた箱・左右の基板を +Y へ 20 mm・鼻の穴あり)から改善を探した.比較図: `output/candidate_layouts/comparison_improve.png`・配置: `geometry_improve.png`. + +| 候補 | 変更 | 構造 CoV(現行比) | min 全体 | min 輪帯 | b1 | 明るさ | +| --- | --- | --- | --- | --- | --- | --- | +| F3_y80_s20_b1_N | 出発点(LED Z = −25) | 0.67 | 0.827 | 0.967 | +0.011 | 0.77 | +| F3_y80_s20_b1_N_R10 | 内側の角を R10(上の縁の稜は R8) | 0.65 | 0.831 | 0.970 | +0.010 | 0.80 | +| F3_y80_s20_b1_N_R20 | 内側の角を R20(上の縁の稜は R8) | 0.63 | 0.836 | 0.970 | +0.010 | 0.83 | +| F3_y80_s20_b1_N_z15 | LED を Z = −15 へ | 0.83 | 0.792 | 0.980 | +0.010 | 0.78 | +| F3_y80_s20_b1_N_z35 | LED を Z = −35 へ | 0.66 | 0.857 | 0.936 | +0.015 | 0.76 | +| **F3_y80_s20_b1_N_R20_z35** | R20 + LED Z = −35 | **0.61** | **0.863** | 0.939 | +0.014 | 0.82 | +| F3_y80_s16_b1_N_R20_z45 | R20 + LED Z = −45(左右は +16 mm まで) | 0.71 | 0.864 | 0.914 | +0.022 | 0.80 | + +- 内側の角を丸めると少し均一になり明るくなる.天井と +Y 側の壁の稜は,天井の平らな部分が評価板の縁より狭くならないよう R8 まで(`build_rounded_sloped_box_housing`) +- LED を奥へ下げると鼻の穴の前の暗部が薄れ min 全体が上がるが,上下の傾きが少し戻る.上げると悪化する +- 奥ほど上の壁が低いので,左右の基板を +Y へずらせる量は LED を下げるほど減る(基板カバーが丸めた壁に食い込まない上限は Z = −35 で +20 mm,Z = −45 で +16 mm).Z = −45 ではずらしが足りず傾きが残る +- 左右の基板をさらに上へずらす案は,上の上限に当たるため余地が無かった + +### 結果 8 — LED の位置と筐体の形の追加の工夫 + +結果 7 の最良案 F3_y80_s20_b1_N_R20_z35(以下「基準」)から,LED の位置・向きと筐体の形をさらに振った(2026-11-05).重い前処理(筐体の引き算・壁との干渉・カメラの視野の厳密な確認)は研究室サーバで回した.比較図: `output/candidate_layouts/comparison_h1.png`・`comparison_strip.png`. + +| 候補 | 変更(基準から) | 構造 CoV(現行比) | min 全体 | b1 | 明るさ | +| --- | --- | --- | --- | --- | --- | +| H_bdz20 | 下の基板だけ 20 mm 奥へ | 0.66 | 0.865 | +0.002 | 0.81 | +| H_st15 / H_st30 | 左右の基板を +Y へ 15° / 30° 傾ける | 0.69 / 1.00 | 0.845 / 0.802 | −0.005 / −0.025 | 0.82 / 0.83 | +| H_bt30 | 下の基板を +Y へ 30° 傾ける | 0.64 | 0.869 | −0.007 | 0.83 | +| H_x90 | 箱を X ±90 へ広げる | 0.64 | 0.853 | +0.023 | 0.76 | +| **H_y90** | **-Y 側を -90 へ広げる** | **0.59** | 0.862 | +0.013 | 0.79 | +| G1 | H_y90 + 下の基板を 30° 傾ける | 0.62 | 0.867 | −0.004 | 0.80 | +| G2_g015 | H_y90 + 天井近くの細い LED 列(明るさ 0.15 倍) | 0.52 | 0.870 | −0.001 | 0.83 | +| H_y90_P(参考) | H_y90 + 鼻の穴を袋にする | 0.49 | 0.913 | +0.006 | 0.79 | + +- 上下の傾きは LED の向き・高さ・明るさの配分でほぼ 0 にできるが,構造 CoV は下がらない.残るムラの大部分が鼻の穴の前の局所的な暗部だから +- 鼻の穴を袋にする(箱の中との間に仕切りを入れる)と 0.49 倍まで下がり,穴の影響は約 0.1 と分かった.ただし口を開けて穴に入れる妨げになるので採らない(ユーザー判断.PLAN_03) +- 鼻の穴の左右の天井近く(評価板の上の縁と上の壁の間)に細い LED 列を置き,明るさを 0.15 倍に絞ると 0.52 倍になる.全灯では上の縁が明るすぎる(1.7 倍に悪化).ただし評価板の上に LED を付けるのは現実的でないので採らない(ユーザー判断.PLAN_03) +- 左右の基板を上の角へ 45° に置く案(F1)は,基板が長く(52 mm)角へ寄せると丸めた壁に食い込み,食い込まない位置ではカメラの視野を 0.6% ふさぐ(4 通りの位置で両立なし.シミュでも LED がカメラに直接写って崩れる) +- 採れる案の中では **H_y90(構造 CoV 0.59 倍・min 全体 0.862・明るさ 0.79 倍・今の基板 3 枚)が最良** + +### 結果 9 — LED を 3 個 1 組のモジュールに分けて置き場所を網羅的に探す + +現行基板の 6 個 1 組は電気の設計(12 V で LED 3 個を直列にし定電流 IC で 60 mA に保つ列が 2 本.SPEC_05)から来ていて,照明のために決めたものではない.電気の自然な単位である「LED 3 個の直列 1 本」を小さな基板(モジュール)にし,H_y90 の箱の中で置き場所を探した(2026-11-05). + +- 方法: 光は線形なので,置き場所の候補(左右・下・上の壁 × 高さ Z = −10〜−100.壁の丸みに食い込む場所とカメラの視野をふさぐ場所は除く)ごとにモジュール 1 個だけの画像を作り(`scripts/led_site_basis.py`.108 か所),その重み付き和で組み合わせのムラを近似して総当たりした(`scripts/optimize_led_sites.py`.左右対称に置く・60 mA か 30 mA・場所は 3 種類まで).上位は基板込みで本番どおりにレンダし直した +- 近似は基板どうしの遮りを無視するので,本番より 0.01〜0.04 よく出る.基板を重ねて置く配置(L6)は近似では最良だったが本番では遮りで悪化した + +| 候補 | 配置(どれも LED 18 個) | 構造 CoV(現行比) | min 全体 | min 輪帯 | b1 | 明るさ | +| --- | --- | --- | --- | --- | --- | --- | +| H_y90 | 現行基板 3 枚(下 1・左右 1 ずつ) | 0.59 | 0.862 | 0.946 | +0.013 | 0.79 | +| L3 | 下 X ±39・Z −15 + 左右 Y +10 と +30・Z −35 | 0.49 | 0.878 | 0.971 | +0.013 | 0.80 | +| **L5** | **下 X ±36・Z −10** + 左右 Y +10 と +30・Z −35 | **0.47** | **0.879** | 0.971 | +0.011 | 0.80 | +| L1 | 下 X ±39・Z −15 + 左右 Y +30・Z −25 と Y +10・Z −50 | 0.50 | 0.862 | 0.989 | +0.010 | 0.80 | +| L6 | 下 X ±36・Z −10 + 左右 Y +30・Z −35 と Y +20・Z −40(重ねる) | 0.58 | 0.856 | 0.994 | −0.005 | 0.78 | + +- 下の LED は真ん中にまとめず左右に分け(X ±33〜39),浅め(Z −10〜−15)に置く.真ん中にまとめると評価板の下の縁の中央が明るすぎる +- 左右の LED は上寄り(Y +10 と +30).鼻の穴の前の暗部を補う.Y を下げると悪化する +- 左右対称に置くと左右の傾き a1 が 0 になる(現行基板は LED が基板の中心からずれて並ぶので a1 が −0.005 残る) +- L3 のまわりを細かく振っても近似で 0.46〜0.48 にとどまり,最適の付近は平ら.場所を 4 種類に増やしても近似 0.47 +- L5 の部品: 左右は 3 個 1 組 2 本が同じ高さで中心間隔 20 mm に並ぶので現行基板(中心間隔 約 19 mm)とほぼ同じ形.下は 3 個 1 組の小基板を左右に 1 枚ずつ + +## 結論 (Conclusions) + +- **「現行の形を改良」は,LED の置き方ではなく壁の形を直す必要がある**.具体的には +Y 側で評価板の縁の直下に張り出した壁(喉)をなくし,キャビティを評価板の中心にそろえる.これは実質的に箱形へ近づける変更になる +- **箱形が有望**.候補は 2 つに絞れる: + - **C1(底に 2 枚・評価板向き + 遮光板.LED 12 個)**: 最も均一で LED が少ない.暗い(現行の 0.44 倍).遮光板が要る + - **B2_z25(側壁の評価板寄りに 4 枚・下向き.LED 24 個)**: C1 と同程度に均一で明るい(1.08 倍).遮光板は要らないが LED が多い +- **大きさは置き方より強く効く**.内寸を 144 → 160 mm(外形 約 166 mm)にすると構造 CoV は現行の 0.29〜0.36 倍・min 全体 0.94 になる.「大きさはあまり変えない」の範囲をどこまで許すかで結果が変わる +- どちらもカメラの視野をふさがず,基板ごとの出力差(10%)にも強い +- どちらも min 全体は 0.91 台で頭打ち.この大きさでは残りの同心円のお椀が限界に近い +- **内寸 160 mm で鼻の穴を開けると,スマホの画面の見え方と均一さが両立しない**.上下対称の箱は構造 CoV 0.30 倍だが画面がほとんど見えない.今と同じ範囲で画面が見える上面を傾けた箱は 0.67 倍(左右の基板を +Y へ 20 mm ずらした場合)(結果 6) +- **画面が見えることと鼻の穴を必須にした中での最良は F3_y80_s20_b1_N_R20_z35**(上面を傾けた箱・左右の基板を +Y へ 20 mm・内側の角を R20・LED 高さ Z = −35).構造 CoV 0.61 倍・min 全体 0.863・明るさ 0.82 倍(結果 7) +- **LED の位置・向きと筐体の形をさらに工夫した中での最良は H_y90**(基準の -Y 側を -90 へ広げる.構造 CoV 0.59 倍.外形 約 166 × 155 × 166 mm).残るムラは鼻の穴から光が抜けることによる上の縁中央の暗部で,仕切りも天井の LED も採らないので,これ以上は大きく減らせない(結果 8) +- **LED を 3 個 1 組のモジュールに分けて置き場所を探すと L5 で構造 CoV 0.47 倍**(H_y90 の箱・LED 18 個・明るさ 0.80 倍.現行基板 2 枚 + 3 個 1 組の小基板 2 枚).採れる案の最良(結果 9) + +## 限界・注意点 (Limitations) + +- 箱形のスマホ側は暗い板で近似した(スマホ本体・ホルダ・カメラの穴の形は入れていない) +- カメラの視野は外接箱による幾何的な判定で,カメラの位置は仮定(SH-02M のメッシュは直方体でカメラの穴が無い).カメラの画角(評価板全体が画角に入るか)は見ていない.Fusion で設計するときに SH-02M の実際のカメラ位置で確かめ直す +- 材質は基準シーンの ρ=0.85 純 diffuse(校正値 ρ≈0.81 ではない).現行機との比で見ているので結論は変わらないと考えるが,絶対値の予測には使わない +- 現行の形の「喉を直した版」はメッシュを直接作っていない(Fusion で作ってから確かめる) +- max_depth 16 で多重反射のエネルギーが約 9% 欠ける(警告).全候補で同じ条件なので比較には影響しない + +## 次にやること (Next Steps) + +- 鼻の穴を肌でふさいだ場合の見積もりは保留(2026-11-05 ユーザー判断).実機の評価は評価板で顔を当てずに行うので穴は開いたままで,肌でふさいだ条件は実機で確かめにくい.比較は穴が開いた条件(光を返さない)で行う +- L5(H_y90 の箱 + 3 個 1 組のモジュール)で Fusion の設計に進むかをユーザーが判断する.進む場合は顔側の外側と評価板の受けを今の前側から流用し(PLAN_03),実際の形(三脚の穴・スマホの置き場所・ケーブルの穴・組み立ての分割・モジュールの取付)を作って取り込み,シミュで確かめ直す +- 選んだ形を Fusion で設計し(三脚の穴・スマホの置き場所・ケーブルの穴・組み立て),取り込んでシミュで確かめ直す(PLAN_03 ステップ 2) + +## 再現コマンド (Reproduction) + +```bash +# 研究室サーバ(学外からは SM_REMOTE_HOST=Newton-via-lab) +uv run sm-remote push +uv run sm-remote run --name cand --gpu 1 -- python scripts/sweep_candidate_layouts.py +uv run sm-remote pull candidate_layouts + +# 手元 +uv run python scripts/sweep_candidate_layouts.py --screenshots # 配置確認の画像 +uv run python scripts/verify_baffle_occlusion.py --scene configs/_tmp_candidates/scene_C1.yaml +uv run python scripts/check_camera_view.py configs/_tmp_candidates/scene_C1.yaml --spread 25 +uv run python scripts/build_candidate_comparison.py --names A0 A1 A2_lr A2_tb B1 B2 B1_z90 B2_z25 C1 C2 B1_z25 B2_z115 +uv run python scripts/build_candidate_comparison.py --names A0 B2_z25_L160_N F3_y80_s10_b1_N F3_y80_s20_b1_N --out output/candidate_layouts/comparison_nose.png +# 重い前処理と確認はサーバで(manifold3d が全コアを使う.カメラの視野の厳密な確認も重い) +uv run python scripts/sweep_candidate_layouts.py --only H_y90 --prepare-only +uv run python scripts/check_wall_clearance.py configs/_tmp_candidates/scene_H_y90.yaml +uv run python scripts/check_camera_view.py --exact configs/_tmp_candidates/scene_H_y90.yaml +# LED モジュールの置き場所の探索(基底画像はサーバ.探索は手元でも軽い) +uv run python scripts/led_site_basis.py +uv run python scripts/optimize_led_sites.py --max-units 3 --top 25 +uv run python scripts/led_site_basis.py --layouts L5=B_x36_z-10:1,R_y10_z-35:1,R_y30_z-35:1 +``` + +## 参照 (References) + +- `scripts/sweep_candidate_layouts.py`(候補の定義・シーン生成・レンダ・評価) +- `scripts/build_candidate_comparison.py`(比較図) +- `scripts/check_camera_view.py`(カメラから開口部への視線をふさぐ部品の検査.`--exact` で三角形との交差) +- `scripts/check_wall_clearance.py`(LED 基板カバーが筐体の壁に食い込んでいないかの検査) +- `scripts/led_site_basis.py`・`scripts/optimize_led_sites.py`(LED モジュールの置き場所ごとの基底画像と,組み合わせの探索.`output/led_sites/`) +- `output/candidate_layouts/`(各候補の `s{seed}/`・`summary*.csv`・`comparison.png`・`_geometry/` 配置確認の画像) diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index 04c261d..aa68b07 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -122,3 +122,24 @@ - 設計判断: 照明の均一さに厳密な数値基準(例: 最小/最大 0.9)は置かず,シミュで現行機より改善していれば良いとした(ユーザー判断).比べるため基準シーンの spp を 1024 → 4096 にした(画像全体の最小/最大がノイズで揺れないように.TEST_19). - [x] **新しい実機の方針と候補の比較計画を決めた (2026-11-04)**: スマホは現行と同じ SH-02M,大きさは現行機からあまり変えない,LED は少ない方が良いが均一さ優先.筐体は「現行の形を改良」と「箱形で作り直し」の両方で進め,シミュで現行機(A0)と 4 候補(A1 上を足して 4 枚対称 / A2 対向 2 枚 / B1 箱形 2 枚 / B2 箱形 4 枚)を比べる計画を [PLAN_03](03_PLAN/PLAN_03_新しい実機の要件.md) に書いた. - 次: 候補のシーンを作り,配置の 3D 画像をユーザーに確認してもらってからレンダする. +- [x] **新しい実機の候補をシミュで比較 (2026-11-04)**: PLAN_03 のステップ 1.ユーザー不在の 4 時間に自律判断で実施し,計算は研究室サーバ(GPU)で回した.現行と同じ大きさで現行の形の改良(基板の足し引き)・箱形(144 mm 角)の LED 高さ違い・底に置いて評価板へ向け遮光板を付ける形を比べた([TEST_21](06_TEST/TEST_21_新しい実機の候補の比較.md)). + - 結果: 現行の形は基板の置き方で改善しない(暗部は +Y 縁の壁の張り出し=喉が原因で,スマホ・ホルダを白にしても不変).箱形は構造 CoV が現行の 0.46〜0.63 倍.最良は B2_z25(4 枚・明るさ 1.08 倍)と C1(2 枚・LED 12 個・明るさ 0.44 倍). + - 失敗パターン: `show_led_geometry.py` が YAML からの相対パスのメッシュを CWD 基準で探して落ちた → YAML の場所からも探すように直した. + - 追加確認: カメラの視野をふさぐ部品は無い(`scripts/check_camera_view.py`.カメラ位置は仮定).下の基板だけ +10% にしても構造 CoV の変化は 1% 未満で,基板ごとの出力差に強い.現行機でも傾きはほぼ動かないので,TEST_20 の左上暗の傾きを出力差で説明するのは難しい. + - 大きさの感度: 内寸 144 → 160 mm で構造 CoV は現行の 0.29〜0.36 倍(min 全体 0.94),130 mm では 0.63〜0.71 倍.置き方より大きさの方が強く効く. + - 次: C1 と B2_z25 のどちらで進めるか,内寸をどこまで広げてよいかをユーザーが選ぶ. +- [x] **内寸 160 mm の箱を製品の形へ近づけてシミュで確かめた (2026-11-05)**: ユーザー判断で B2_z25・内寸 160 mm に進め,製品として必要な形(角の丸み・スマホの画面が見える上面・鼻の穴)を加えて比べた([TEST_21](06_TEST/TEST_21_新しい実機の候補の比較.md) 結果 6). + - 結果: 内側の角を丸めると少し良くなる(0.29 → 0.25 倍).画面を今と同じ範囲で見るため上面を奥ほど下げると +Y 側が暗くなり 0.75 倍に戻るが,左右の基板を +Y へ 20 mm ずらすと傾きは消え 0.58 倍.鼻の穴を開けると 0.67 倍(上下対称の箱は 0.30 倍のまま).現行機の上の縁中央の暗部は主に鼻の穴から光が逃げるためと分かった. + - 設計判断: 鼻の穴は必須の要件にした(ユーザー判断.PLAN_03).穴を開けるためメッシュの引き算に manifold3d を開発用の依存に加えた. + - 失敗パターン: ① 上の壁に基板を足す → 壁が評価板の縁に近くカメラの視野をふさぐ.奥(Z = −70)へ下げると奥ばかり明るくなり悪化 / ② 下の基板を暗くして傾きを打ち消す → 全体が暗くなる. + - 次: 鼻の穴を肌でふさいだ場合を見積もり,上面を傾けた箱と上下対称の箱のどちらにするかをユーザーが選ぶ.Fusion の新しいデザイン(未保存)は一時停止中. +- [x] **画面が見えることと鼻の穴を必須にした上での改善 (2026-11-05)**: ユーザー判断で両方を必須の要件にした(PLAN_03)ので上下対称の箱は採らず,上面を傾けた箱で内側の角の丸みと LED の高さを振った([TEST_21](06_TEST/TEST_21_新しい実機の候補の比較.md) 結果 7).最良は R20・LED 高さ Z = −35 で構造 CoV 0.61 倍・min 全体 0.863. + - 設計判断: 鼻の穴を肌でふさいだ場合の見積もりは保留(実機の評価は評価板で顔を当てずに行うので,穴が開いた条件が評価と同じ). + - 失敗パターン: ① LED を Z = −45 まで下げる → 上の壁が低く左右の基板を +16 mm までしかずらせず傾きが残る / ② 左右の基板をさらに上へ → 基板カバーが丸めた壁に食い込む(干渉は manifold の積で確かめた). +- [x] **LED の位置と筐体の形の追加の工夫 (2026-11-05)**: 上面を傾けた箱で LED の向き・高さ・明るさの配分・箱の広さ・鼻の穴の形・天井の LED 列・上の角への基板を試した([TEST_21](06_TEST/TEST_21_新しい実機の候補の比較.md) 結果 8).採れる案の最良は H_y90(-Y 側を -90 へ広げる.構造 CoV 0.59 倍). + - 分かったこと: 残るムラの大部分は鼻の穴から光が抜けることによる上の縁中央の暗部(穴を袋にすると 0.49 倍).上下の傾きは消せても CoV は下がらない. + - 設計判断(ユーザー判断): 鼻の穴に仕切りは入れない(口を開けて入れる妨げ),評価板の上の縁の近くに LED は置かない(現実的でない).PLAN_03 に記録. + - 失敗パターン: ① 上の角に 45° の基板 → 長くて角へ寄せると壁に食い込み,寄せないとカメラの視野をふさぐ / ② 手元で manifold3d の引き算と視野の厳密な確認を回したら CPU が重くなりユーザーが止めた → 重い前処理・確認はサーバで回す. +- [x] **LED を 3 個 1 組のモジュールに分けて置き場所を探索 (2026-11-05)**: 現行基板の 6 個 1 組は電気の設計由来で照明のための理由は無いので,LED 3 個の直列 1 本を単位に H_y90 の箱で置き場所を網羅的に探した([TEST_21](06_TEST/TEST_21_新しい実機の候補の比較.md) 結果 9).最良は L5(下 X ±36・Z −10 + 左右 Y +10 と +30・Z −35)で構造 CoV 0.47 倍. + - 設計判断: 光の線形性を使い,場所ごとの基底画像(サーバで 108 枚)の重み付き和で組み合わせを総当たりした.グラム行列を使うので探索は手元でも軽い.上位は基板込みで本番どおりにレンダし直す.顔側は外側と評価板の受けだけ今の前側から流用し,内側の喉は入れない(ユーザー判断.PLAN_03). + - 失敗パターン: 基板を重ねる配置(L6)は近似で最良だったが本番では基板どうしの遮りで悪化(0.58 倍).近似は遮りを無視するので,重なる配置は本番で確かめる. diff --git a/pyproject.toml b/pyproject.toml index 519335c..a316633 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ [dependency-groups] dev = [ + "manifold3d>=3.5.4", "pytest>=9.0.3", "ruff>=0.15.12", ] diff --git a/scripts/build_candidate_comparison.py b/scripts/build_candidate_comparison.py new file mode 100644 index 0000000..8888377 --- /dev/null +++ b/scripts/build_candidate_comparison.py @@ -0,0 +1,96 @@ +"""新しい実機の候補(sweep_candidate_layouts.py の結果)を 1 枚の比較図にまとめる. + +各候補の seed 0 の輝度マップを TEST_20 と同じ表示処理(メディアン 5 → ガウス σ=4, +99 パーセンタイルを 1 に正規化)で並べ,summary.csv の seed 平均の指標を添える. +色の範囲は全候補で共通にする. + +実行方法: + uv run python scripts/build_candidate_comparison.py + uv run python scripts/build_candidate_comparison.py --names A0 B1 B2 --out output/x.png +""" + +from __future__ import annotations + +import argparse +import csv +import sys +import textwrap +from collections import defaultdict +from pathlib import Path + +import matplotlib +import numpy as np + +matplotlib.use("Agg") +import matplotlib.pyplot as plt # noqa: E402 + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) + +from compare_real_vs_sim_metrics import display_map, load_sim_roi # noqa: E402 + +plt.rcParams["font.family"] = ["Yu Gothic", "MS Gothic", "DejaVu Sans"] + +ROOT = Path(__file__).resolve().parents[1] +OUTPUT_BASE = ROOT / "output" / "candidate_layouts" +VMIN, VMAX = 0.75, 1.0 + + +def load_summary(paths: list[Path]) -> dict[str, dict[str, float | str]]: + """summary*.csv を読み,候補ごとに seed 平均した指標を返す(後のファイルが優先).""" + rows: dict[str, list[dict]] = defaultdict(list) + for path in paths: + with path.open(encoding="utf-8") as f: + per_file: dict[str, list[dict]] = defaultdict(list) + for row in csv.DictReader(f): + per_file[row["name"]].append(row) + rows.update(per_file) + out: dict[str, dict[str, float | str]] = {} + for name, items in rows.items(): + agg: dict[str, float | str] = {"note": items[0]["note"], "n_led": int(items[0]["n_led"])} + for key in ("mean", "structure_cov", "min_fullimage", "min_ring", "b1", "a1"): + agg[key] = float(np.mean([float(r[key]) for r in items])) + out[name] = agg + return out + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--names", nargs="+", help="並べる候補(既定: summary にある全部)") + parser.add_argument("--base", default="A0", help="比の基準にする候補(既定: A0 = 現行機)") + parser.add_argument("--out", type=Path, default=OUTPUT_BASE / "comparison.png") + args = parser.parse_args(argv) + + summary = load_summary(sorted(OUTPUT_BASE.glob("summary*.csv"))) + names = args.names or list(summary) + base = summary[args.base] + cols = min(len(names), 4) + rows = (len(names) + cols - 1) // cols + fig, axes = plt.subplots(rows, cols, figsize=(4.2 * cols, 6.0 * rows), squeeze=False) + image = None + for ax, name in zip(axes.ravel(), names, strict=False): + roi = load_sim_roi(OUTPUT_BASE / name / "s0" / "luminance.npy") + image = ax.imshow(display_map(roi), cmap="hot", vmin=VMIN, vmax=VMAX) + m = summary[name] + ax.set_title( + f"{name}\n{textwrap.fill(str(m['note']), 24)}\n" + f"構造CoV {m['structure_cov']:.4f}(現行比 {m['structure_cov'] / base['structure_cov']:.2f})\n" # noqa: E501 + f"min 全体 {m['min_fullimage']:.3f} / 輪帯 {m['min_ring']:.3f}\n" + f"明るさ 現行比 {m['mean'] / base['mean']:.2f}(LED {m['n_led']} 個)", + fontsize=9, + ) + ax.set_xticks([]) + ax.set_yticks([]) + for ax in axes.ravel()[len(names):]: + ax.axis("off") + if image is not None: + fig.colorbar(image, ax=axes.ravel().tolist(), shrink=0.6, + label="輝度(99 パーセンタイル = 1)") + args.out.parent.mkdir(parents=True, exist_ok=True) + fig.savefig(args.out, dpi=110, bbox_inches="tight") + print(f"[saved] {args.out}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/check_camera_view.py b/scripts/check_camera_view.py new file mode 100644 index 0000000..da5a91d --- /dev/null +++ b/scripts/check_camera_view.py @@ -0,0 +1,124 @@ +"""スマホのカメラから評価板の開口部が見えるか(部品が視野をふさがないか)を幾何的に確かめる. + +PLAN_03 の要件「カメラの視野」の確認用.カメラ位置の候補点(既定: 中心と ±dx・±dy の 9 点)から +開口部の矩形上の格子点へ線分を引き,筐体・評価板・スマホ以外のメッシュ(LED 基板カバー・ +遮光板など)の軸平行バウンディングボックスと交わるかを調べる.AABB で判定するので保守側 +(実際より「ふさぐ」と出やすい)である.斜めに置いた部品は AABB が大きく過大に出るので, +--exact で三角形と線分の交差を調べる(計算は重いので研究室サーバで回す). + +SH-02M のメッシュは直方体でカメラの穴が無いため,カメラ位置は引数で与える(既定は箱形の +スマホ側の窓の中心 (0, 4) mm・Z = -144 mm). + +実行方法: + uv run python scripts/check_camera_view.py configs/_tmp_candidates/scene_C1.yaml + uv run python scripts/check_camera_view.py configs/_tmp_candidates/scene_B2.yaml \ + --camera 0 4 -144 --spread 10 +""" + +from __future__ import annotations + +import argparse +import sys +from pathlib import Path + +import numpy as np +import trimesh +import yaml + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) + +# 評価板の開口(照明ムラ補正ボードの裏面の範囲.SPEC_03) +OPENING_HALF = (49.5, 51.0) +OPENING_Z = -4.5 +# 視野の判定から外すメッシュ(壁・評価板・スマホ側) +IGNORED_IDS = ("housing", "evaluation_board", "phone", "holder") + + +def segment_hits_aabb( + start: np.ndarray, ends: np.ndarray, lo: np.ndarray, hi: np.ndarray +) -> np.ndarray: + """線分 start→ends[i] が AABB [lo, hi] と交わるかを slab 法で返す(ends: (N, 3)).""" + d = ends - start + with np.errstate(divide="ignore", invalid="ignore"): + t1 = (lo - start) / d + t2 = (hi - start) / d + tmin = np.where(d == 0, np.where((start >= lo) & (start <= hi), -np.inf, np.inf), + np.minimum(t1, t2)) + tmax = np.where(d == 0, np.where((start >= lo) & (start <= hi), np.inf, -np.inf), + np.maximum(t1, t2)) + enter = np.max(tmin, axis=1) + leave = np.min(tmax, axis=1) + return (enter <= leave) & (leave >= 0.0) & (enter <= 1.0) + + +def segment_hits_triangles( + start: np.ndarray, ends: np.ndarray, triangles: np.ndarray, chunk: int = 64 +) -> np.ndarray: + """線分 start→ends[i] がいずれかの三角形と交わるかを返す(Moller-Trumbore 法).""" + d = ends - start # (N, 3).交点は t ∈ (0, 1) + hit = np.zeros(len(ends), dtype=bool) + for k in range(0, len(triangles), chunk): + tri = triangles[k:k + chunk] + a = tri[:, 0] + e1, e2 = tri[:, 1] - a, tri[:, 2] - a # (M, 3) + p = np.cross(d[:, None, :], e2[None, :, :]) # (N, M, 3) + det = np.einsum("nmk,mk->nm", p, e1) + ok = np.abs(det) > 1e-12 + inv = np.where(ok, 1.0 / np.where(ok, det, 1.0), 0.0) + s = start - a # (M, 3) + u = np.einsum("nmk,mk->nm", p, s) * inv + q = np.cross(s, e1) # (M, 3) + v = np.einsum("nk,mk->nm", d, q) * inv + t = np.einsum("mk,mk->m", q, e2)[None, :] * inv + hit |= np.any(ok & (u >= 0) & (v >= 0) & (u + v <= 1) & (t > 0) & (t < 1), axis=1) + return hit + + +def check_scene( + scene: Path, camera: np.ndarray, spread: float, grid: int, exact: bool = False +) -> list[str]: + """シーン 1 つを調べ,視野をふさぐメッシュ id とふさぐ割合を文字列で返す.""" + config = yaml.safe_load(scene.read_text(encoding="utf-8")) + xs = np.linspace(-OPENING_HALF[0], OPENING_HALF[0], grid) + ys = np.linspace(-OPENING_HALF[1], OPENING_HALF[1], grid) + targets = np.array([[x, y, OPENING_Z] for x in xs for y in ys]) + cams = [camera + np.array([dx, dy, 0.0]) + for dx in (-spread, 0.0, spread) for dy in (-spread, 0.0, spread)] + found = [] + for mesh in config["geometry"]["meshes"]: + if any(key in mesh["id"] for key in IGNORED_IDS): + continue + part = trimesh.load(scene.parent / mesh["path"], force="mesh") + if exact: + worst = max(segment_hits_triangles(c, targets, part.triangles).mean() for c in cams) + else: + worst = max(segment_hits_aabb(c, targets, part.bounds[0], part.bounds[1]).mean() + for c in cams) + if worst > 0: + found.append(f"{mesh['id']}: 開口部の {worst * 100:.1f}% をふさぐ(最悪のカメラ位置)") + return found + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("scenes", nargs="+", type=Path) + parser.add_argument("--camera", nargs=3, type=float, default=[0.0, 4.0, -144.0], + metavar=("X", "Y", "Z"), help="カメラ位置 [mm]") + parser.add_argument("--spread", type=float, default=10.0, + help="カメラ位置の不確かさ(±mm.9 点で調べる)") + parser.add_argument("--grid", type=int, default=41, help="開口部の格子の 1 辺の点数") + parser.add_argument("--exact", action="store_true", + help="AABB ではなく三角形との交差で調べる(斜めの部品向け.重い)") + args = parser.parse_args(argv) + camera = np.array(args.camera) + for scene in args.scenes: + found = check_scene(scene, camera, args.spread, args.grid, args.exact) + status = "OK(ふさぐ部品なし)" if not found else "要確認" + print(f"{scene.name}: {status}") + for line in found: + print(f" {line}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/check_wall_clearance.py b/scripts/check_wall_clearance.py new file mode 100644 index 0000000..56f7e4b --- /dev/null +++ b/scripts/check_wall_clearance.py @@ -0,0 +1,50 @@ +"""候補のシーンで LED 基板カバーが筐体の壁に食い込んでいないかを調べる. + +筐体(id が box_housing のメッシュ)と各 LED 基板カバー(id が led_cover_ で始まる)の積の体積を +manifold3d で求める.0 なら干渉なし.manifold3d は CPU の全コアを使うので,研究室サーバで +実行する(sm-remote run). + +実行方法: + uv run python scripts/check_wall_clearance.py configs/_tmp_candidates/scene_F1_58.yaml +""" + +from __future__ import annotations + +import argparse +from pathlib import Path + +import trimesh +import yaml + + +def overlap_volumes(scene: Path) -> dict[str, float]: + """LED 基板カバーごとに筐体との積の体積 [mm^3] を返す.""" + config = yaml.safe_load(scene.read_text(encoding="utf-8")) + meshes = config["geometry"]["meshes"] + housing_entry = next(m for m in meshes if m["id"] == "box_housing") + housing = trimesh.load(scene.parent / housing_entry["path"], force="mesh") + volumes = {} + for entry in meshes: + if not entry["id"].startswith("led_cover_"): + continue + cover = trimesh.load(scene.parent / entry["path"], force="mesh") + both = trimesh.boolean.intersection([housing, cover], engine="manifold") + volumes[entry["id"]] = float(both.volume) if len(both.faces) else 0.0 + return volumes + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("scenes", nargs="+", type=Path) + args = parser.parse_args(argv) + for scene in args.scenes: + bad = {k: v for k, v in overlap_volumes(scene).items() if v > 0.0} + status = "OK(干渉なし)" if not bad else "干渉あり" + print(f"{scene.name}: {status}") + for key, vol in bad.items(): + print(f" {key}: {vol:.2f} mm^3") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/generate_cube_housing.py b/scripts/generate_cube_housing.py index 7f2196e..377e1ff 100644 --- a/scripts/generate_cube_housing.py +++ b/scripts/generate_cube_housing.py @@ -201,6 +201,346 @@ return mesh +def _rounded_rect_radius(theta: np.ndarray, half: float, corner: float) -> np.ndarray: + """角を半径 corner で丸めた正方形(半幅 half)の境界までの極座標の半径を返す.""" + cos_t = np.abs(np.cos(theta)) + sin_t = np.abs(np.sin(theta)) + straight = _rect_radius(theta, half, half) + if corner <= 0.0: + return straight + inner = half - corner + # 直線部で当たるのは,当たる点のもう一方の座標が inner 以下のとき + on_edge = np.minimum(straight * cos_t, straight * sin_t) <= inner + 1e-9 + # 角の円(中心 (inner, inner))との交点: s = u·C + sqrt((u·C)^2 - |C|^2 + r^2) + uc = inner * (cos_t + sin_t) + s = uc + np.sqrt(np.maximum(uc**2 - 2.0 * inner**2 + corner**2, 0.0)) + return np.where(on_edge, straight, s) + + +def _rounded_surface( + theta: np.ndarray, + rim_r: np.ndarray, + half: float, + fillet: float, + rim_z: float, + top_z: float, + bottom_z: float, + n_ceiling: int, + n_fillet: int, + n_wall: int, + n_bottom: int, +) -> tuple[np.ndarray, np.ndarray]: + """リム → 天井 → 丸めた稜 → 側壁(縦の稜も丸める)→ 丸めた稜 → 底面の 1 枚曲面. + + 形は「一辺 2·(half - fillet) の箱を半径 fillet の球で膨らませたもの」(全ての稜と角を + 同じ半径で丸めた箱).高さ z の断面は,半幅 half - fillet + ρ・角の半径 ρ の角丸正方形. + """ + flat = half - fillet + rings_rho: list[np.ndarray] = [] + rings_z: list[float] = [] + if top_z > rim_z: + for z in np.linspace(rim_z, top_z, 2, endpoint=False): + rings_rho.append(rim_r) + rings_z.append(float(z)) + flat_r = _rect_radius(theta, flat, flat) + for t in np.linspace(0.0, 1.0, n_ceiling, endpoint=False): + rings_rho.append((1.0 - t) * rim_r + t * flat_r) + rings_z.append(top_z) + for a in np.linspace(0.0, np.pi / 2, n_fillet, endpoint=False): + rho = fillet * np.sin(a) + rings_rho.append(_rounded_rect_radius(theta, flat + rho, rho)) + rings_z.append(top_z - fillet * (1.0 - np.cos(a))) + wall_r = _rounded_rect_radius(theta, half, fillet) + for z in np.linspace(top_z - fillet, bottom_z + fillet, n_wall, endpoint=False): + rings_rho.append(wall_r) + rings_z.append(float(z)) + for a in np.linspace(0.0, np.pi / 2, n_fillet, endpoint=False): + rho = fillet * np.cos(a) + rings_rho.append(_rounded_rect_radius(theta, flat + rho, rho)) + rings_z.append(bottom_z + fillet * (1.0 - np.sin(a))) + for t in np.linspace(0.0, 1.0, n_bottom, endpoint=False): + rings_rho.append((1.0 - t) * flat_r) + rings_z.append(bottom_z) + + n_ring, n_theta = len(rings_rho), len(theta) + vertices = np.empty((n_ring * n_theta + 1, 3), dtype=np.float64) + rings = np.arange(n_ring * n_theta).reshape(n_ring, n_theta) + for i, (rho, z) in enumerate(zip(rings_rho, rings_z, strict=True)): + vertices[rings[i], 0] = rho * np.cos(theta) + vertices[rings[i], 1] = rho * np.sin(theta) + vertices[rings[i], 2] = z + vertices[-1] = (0.0, 0.0, bottom_z) + return vertices, rings + + +def build_rounded_cube_housing( + size: float, + thickness: float, + board_half_x: float, + board_half_y: float, + rim_inset: float, + rim_z: float, + fillet: float, + n_theta: int = 512, + n_ceiling: int = 24, + n_fillet: int = 16, + n_wall: int = 64, + n_bottom: int = 32, +) -> trimesh.Trimesh: + """内側の稜と角を半径 fillet で丸めた立方体キャビティ筐体の閉ソリッドを生成する. + + build_cube_housing と同じ構成(リム・天井・側壁・底面)で,内面の 12 本の稜と 8 つの + 角を半径 fillet で丸める.外面は半径 fillet + thickness で丸める.天井の平らな部分 + (半幅 size/2 - fillet)がリム矩形より外にある必要がある. + + Raises: + ValueError: fillet が負,または天井の平らな部分がリム矩形を含まない場合. + """ + hx_in = board_half_x - rim_inset + hy_in = board_half_y - rim_inset + half_in = size / 2.0 + if fillet <= 0.0: + raise ValueError(f"fillet は正の値にしてください({fillet}).0 なら build_cube_housing") + if half_in - fillet <= max(hx_in, hy_in) + thickness: + msg = ( + f"fillet={fillet}mm では天井の平らな部分(半幅 {half_in - fillet:g}mm)が" + f"リム(半幅 {max(hx_in, hy_in) + thickness:g}mm)より狭くなります" + ) + raise ValueError(msg) + half_out = half_in + thickness + flat = half_in - fillet + theta = _build_theta( + n_theta, + [(hx_in, hy_in), (flat, flat), (hx_in + thickness, hy_in + thickness)], + ) + v_in, rings_in = _rounded_surface( + theta, _rect_radius(theta, hx_in, hy_in), half_in, fillet, + rim_z, rim_z, rim_z - size, n_ceiling, n_fillet, n_wall, n_bottom, + ) + v_out, rings_out = _rounded_surface( + theta, _rect_radius(theta, hx_in + thickness, hy_in + thickness), half_out, + fillet + thickness, rim_z, rim_z + thickness, rim_z - size - thickness, + n_ceiling, n_fillet, n_wall, n_bottom, + ) + f_in = _stitch_rings(rings_in, len(v_in) - 1) + f_out = _stitch_rings(rings_out, len(v_out) - 1) + offset = len(v_in) + vertices = np.vstack([v_in, v_out]) + top_in, top_out = rings_in[0], rings_out[0] + offset + n_ring_theta = rings_in.shape[1] + band: list[tuple[int, int, int]] = [] + for j in range(n_ring_theta): + k = (j + 1) % n_ring_theta + band.append((top_in[j], top_out[j], top_out[k])) + band.append((top_in[j], top_out[k], top_in[k])) + faces = np.vstack([f_in, f_out + offset, np.asarray(band, dtype=np.int64)]) + mesh = trimesh.Trimesh(vertices=vertices, faces=faces, process=False) + mesh.fix_normals() + if not mesh.is_watertight: + raise ValueError("生成メッシュが watertight になりませんでした(縫合パラメータを確認)") + return mesh + + +def _bounds_radius( + theta: np.ndarray, x0: float, x1: float, y0: float, y1: float +) -> np.ndarray: + """原点を含む矩形 [x0, x1] × [y0, y1] の境界までの極座標の半径を返す.""" + cos_t = np.cos(theta) + sin_t = np.sin(theta) + with np.errstate(divide="ignore", invalid="ignore"): + rx = np.where(cos_t > 1e-12, x1 / cos_t, np.where(cos_t < -1e-12, x0 / cos_t, np.inf)) + ry = np.where(sin_t > 1e-12, y1 / sin_t, np.where(sin_t < -1e-12, y0 / sin_t, np.inf)) + return np.minimum(rx, ry) + + +def _sloped_surface( + theta: np.ndarray, + rim_r: np.ndarray, + half_x: float, + y_min: float, + y_top: float, + slope: float, + rim_z: float, + top_z: float, + bottom_z: float, + n_ceiling: int, + n_wall: int, + n_bottom: int, +) -> tuple[np.ndarray, np.ndarray]: + """+Y 側の壁だけが傾いた箱の 1 枚曲面(リム → 天井 → 側壁 → 底面). + + +Y 側の壁は y = y_top + slope·(z - top_z)(z は負なので slope > 0 で奥ほど低い). + """ + def bounds_at(z: float) -> np.ndarray: + return _bounds_radius(theta, -half_x, half_x, y_min, y_top + slope * (z - top_z)) + + rings_rho: list[np.ndarray] = [] + rings_z: list[float] = [] + if top_z > rim_z: + for z in np.linspace(rim_z, top_z, 2, endpoint=False): + rings_rho.append(rim_r) + rings_z.append(float(z)) + top_r = bounds_at(top_z) + for t in np.linspace(0.0, 1.0, n_ceiling, endpoint=False): + rings_rho.append((1.0 - t) * rim_r + t * top_r) + rings_z.append(top_z) + for z in np.linspace(top_z, bottom_z, n_wall, endpoint=False): + rings_rho.append(bounds_at(float(z))) + rings_z.append(float(z)) + bottom_r = bounds_at(bottom_z) + for t in np.linspace(0.0, 1.0, n_bottom, endpoint=False): + rings_rho.append((1.0 - t) * bottom_r) + rings_z.append(bottom_z) + + n_ring, n_theta = len(rings_rho), len(theta) + vertices = np.empty((n_ring * n_theta + 1, 3), dtype=np.float64) + rings = np.arange(n_ring * n_theta).reshape(n_ring, n_theta) + for i, (rho, z) in enumerate(zip(rings_rho, rings_z, strict=True)): + vertices[rings[i], 0] = rho * np.cos(theta) + vertices[rings[i], 1] = rho * np.sin(theta) + vertices[rings[i], 2] = z + vertices[-1] = (0.0, 0.0, bottom_z) + return vertices, rings + + +def build_sloped_box_housing( + half_x: float, + y_min: float, + y_top: float, + slope: float, + depth: float, + thickness: float, + board_half_x: float, + board_half_y: float, + rim_inset: float, + rim_z: float, + n_theta: int = 1024, + n_ceiling: int = 24, + n_wall: int = 96, + n_bottom: int = 32, +) -> trimesh.Trimesh: + """+Y 側(上面)の壁を奥ほど低く傾けた箱形キャビティ筐体の閉ソリッドを生成する. + + 撮影される人が装置の上越しにスマホの画面を見られるよう,上面を低く抑えた形 + (PLAN_03「スマホの画面」).内面は X = ±half_x,Y = y_min 〜 y_top + slope·z, + Z = rim_z 〜 rim_z - depth.外面は各面を thickness だけ外へ出す(傾いた面は Y 方向に + thickness だけずらす近似).傾いた壁の隅は周方向の分割で僅かに面取りされる. + + Raises: + ValueError: 評価板が天井に収まらない,または原点が断面に含まれない場合. + """ + hx_in = board_half_x - rim_inset + hy_in = board_half_y - rim_inset + y_bottom = y_top - slope * depth + if half_x <= hx_in + thickness or y_top <= hy_in + thickness or -y_min <= hy_in + thickness: + raise ValueError("評価板(リム)が天井に収まりません.half_x・y_top・y_min を確認") + if y_bottom <= 0.0: + raise ValueError(f"底の +Y 側の壁(Y={y_bottom:g})が原点より下です.slope を確認") + theta = (np.arange(n_theta) + 0.5) * (2.0 * np.pi / n_theta) + theta = np.unique(np.concatenate([ + theta, _corner_angles(hx_in, hy_in), _corner_angles(hx_in + thickness, hy_in + thickness), + ])) + v_in, rings_in = _sloped_surface( + theta, _rect_radius(theta, hx_in, hy_in), half_x, y_min, y_top, slope, + rim_z, rim_z, rim_z - depth, n_ceiling, n_wall, n_bottom, + ) + v_out, rings_out = _sloped_surface( + theta, _rect_radius(theta, hx_in + thickness, hy_in + thickness), half_x + thickness, + y_min - thickness, y_top + thickness + slope * thickness, slope, + rim_z, rim_z + thickness, rim_z - depth - thickness, n_ceiling, n_wall, n_bottom, + ) + f_in = _stitch_rings(rings_in, len(v_in) - 1) + f_out = _stitch_rings(rings_out, len(v_out) - 1) + offset = len(v_in) + vertices = np.vstack([v_in, v_out]) + top_in, top_out = rings_in[0], rings_out[0] + offset + n_ring_theta = rings_in.shape[1] + band: list[tuple[int, int, int]] = [] + for j in range(n_ring_theta): + k = (j + 1) % n_ring_theta + band.append((top_in[j], top_out[j], top_out[k])) + band.append((top_in[j], top_out[k], top_in[k])) + faces = np.vstack([f_in, f_out + offset, np.asarray(band, dtype=np.int64)]) + mesh = trimesh.Trimesh(vertices=vertices, faces=faces, process=False) + mesh.fix_normals() + if not mesh.is_watertight: + raise ValueError("生成メッシュが watertight になりませんでした(縫合パラメータを確認)") + return mesh + + +def _rounded_polytope( + planes_vertex: list[tuple[np.ndarray, float]], sphere: np.ndarray +) -> trimesh.Trimesh: + """各頂点に,その頂点で交わる 3 面に接する球を置き,その凸包を返す. + + 球の半径を頂点ごとに変えても各面は元の平面上に残る(全ての球が同じ平面に接する)ため, + 稜ごとに丸める半径が違う凸多面体を作れる.planes_vertex は (球の中心, 半径) の並び. + """ + points = np.vstack([center + radius * sphere for center, radius in planes_vertex]) + return trimesh.convex.convex_hull(points) + + +def build_rounded_sloped_box_housing( + half_x: float, + y_min: float, + y_top: float, + slope: float, + depth: float, + thickness: float, + board_half_x: float, + board_half_y: float, + rim_inset: float, + rim_z: float, + fillet: float, + top_edge_fillet: float, + sphere_subdivisions: int = 4, +) -> trimesh.Trimesh: + """build_sloped_box_housing の内側の稜と角を丸めた版(外側は fillet + thickness で丸まる). + + 天井と +Y 側の傾いた壁の稜(評価板の上の縁に近い)は top_edge_fillet で丸め, + 他は fillet で丸める.天井の平らな部分が評価板の縁より狭くならないよう + top_edge_fillet は小さくする.内面は凸多面体なので,頂点ごとに 3 面に接する球を置いて + 凸包を取り(_rounded_polytope),外面との差から評価板の開口を抜く. + + Raises: + ValueError: 丸める半径が正でない,または天井の平らな部分が評価板の縁より狭い場合. + """ + if fillet <= 0.0 or top_edge_fillet <= 0.0: + raise ValueError("fillet と top_edge_fillet は正の値にしてください") + hx_in = board_half_x - rim_inset + hy_in = board_half_y - rim_inset + norm = float(np.hypot(1.0, slope)) + # 天井と傾いた壁のなす角(内側)の半分の tan.稜から接点までの距離 = r / tan(角/2) + half_angle_tan = np.tan((np.pi / 2 + np.arctan(slope)) / 2) + if y_top - top_edge_fillet / half_angle_tan < board_half_y: + raise ValueError("天井の +Y 側の平らな部分が評価板の縁より狭くなります." + "top_edge_fillet を小さくしてください") + if half_x - fillet < board_half_x or -y_min - fillet < board_half_y: + raise ValueError("天井の平らな部分が評価板の縁より狭くなります.fillet を小さく") + sphere = trimesh.creation.icosphere(subdivisions=sphere_subdivisions).vertices + + def solid(offset: float) -> trimesh.Trimesh: + z_top, z_bottom = rim_z + offset, rim_z - depth - offset + c = y_top - slope * rim_z + offset * norm # 傾いた壁: y - slope·z = c + items = [] + for z, is_top in ((z_top, True), (z_bottom, False)): + for sx in (-1.0, 1.0): + for is_plus_y in (True, False): + r = (top_edge_fillet if (is_top and is_plus_y) else fillet) + offset + zc = z - r if is_top else z + r + xc = sx * (half_x + offset - r) + yc = (c - r * norm + slope * zc) if is_plus_y else (y_min - offset + r) + items.append((np.array([xc, yc, zc]), r)) + return _rounded_polytope(items, sphere) + + opening = trimesh.creation.box(extents=[2 * hx_in, 2 * hy_in, 2 * thickness + 2.0]) + opening.apply_translation([0.0, 0.0, rim_z]) + mesh = trimesh.boolean.difference([solid(thickness), solid(0.0), opening], engine="manifold") + if not mesh.is_watertight: + raise ValueError("生成メッシュが watertight になりませんでした") + return mesh + + def _parse_args(argv: list[str] | None = None) -> argparse.Namespace: """コマンドライン引数をパースして返す.""" parser = argparse.ArgumentParser( diff --git a/scripts/led_site_basis.py b/scripts/led_site_basis.py new file mode 100644 index 0000000..16778ea --- /dev/null +++ b/scripts/led_site_basis.py @@ -0,0 +1,298 @@ +"""LED の置き場所を 3 個 1 組のモジュール単位で網羅的に調べるための「1 か所だけ点けた」画像を作る. + +光の足し合わせは線形なので,置き場所の候補ごとに LED モジュールを 1 個だけ置いてレンダした +輝度画像(基底画像)を作っておけば,任意の組み合わせの画像はその和で近似できる +(他のモジュールの基板による遮りと反射は無視する近似.よい組み合わせは最後に本番どおりレンダして +確かめる).組み合わせの探索は scripts/optimize_led_sites.py で行う. + +モジュールは現行基板の電気的な単位(LED 3 個を直列にして定電流 IC で 60 mA.SPEC_05)を +小さな基板にしたもの: LED 3 個(間隔 4 mm)を壁に沿って並べ,箱の奥(-Z)へ向ける. +筐体は TEST_21 の H_y90(上面を傾けた箱・内側の角 R20・鼻の穴あり・-Y 側 -90)に固定する. + +壁の丸みに食い込む場所と,カメラから開口部への視線をふさぐ場所は候補から外す.X について +左右対称なので,候補は X ≥ 0 側だけ置き,左側は画像を左右反転して使う(反転の向きは +確認用の 1 か所(名前の末尾 _mirror)で確かめる). + +実行方法(重いので研究室サーバで): + uv run python scripts/led_site_basis.py --prepare-only # シーンと sites.csv だけ + uv run python scripts/led_site_basis.py # 全候補をレンダ + uv run python scripts/led_site_basis.py --only R_y-10_z-35 +""" + +from __future__ import annotations + +import argparse +import copy +import csv +import sys +import time +from dataclasses import dataclass, replace +from pathlib import Path + +import numpy as np +import trimesh +import yaml + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) + +from check_camera_view import OPENING_HALF, OPENING_Z, segment_hits_aabb # noqa: E402 +from sweep_candidate_layouts import ( # noqa: E402 + BASE_YAML, + CANDIDATES, + LED_WALL_OFFSET, + MESH_DIR, + ROOT, + SLOPED_SLOPE, + SLOPED_Y_TOP, + TMP_DIR, + _bottom_leds, + build_candidate_yaml, +) + +from sm_tias_lightsim.scene.paths import relative_mesh_path # noqa: E402 + +OUTPUT_BASE = ROOT / "output" / "led_sites" +BASE_CANDIDATE = "H_y90" + +# モジュールの寸法: LED 3 個を間隔 4 mm で並べた小基板.LED の中心は壁から LED_WALL_OFFSET +MODULE_PITCH = 4.0 +MODULE_ALONG = 16.0 # 壁に沿った長さ +MODULE_TO_WALL = LED_WALL_OFFSET - 1.0 # LED 列から壁側の端まで(壁と 1 mm 空ける) +MODULE_INWARD = 4.0 # LED 列から箱の内側の端まで +MODULE_THICKNESS = 1.6 + +# 箱(H_y90)の内面: X ±80,Y -90 〜 y_top(z),角の丸み R20(安全側に全部 R20 で判定) +HALF_X = 80.0 +Y_MIN = -90.0 +CORNER_R = 20.0 +Z_LEVELS = (-15.0, -25.0, -35.0, -50.0, -70.0, -100.0) +CAMERA = np.array([0.0, 4.0, -144.0]) +CAMERA_SPREAD = 10.0 + + +def y_top(z: float) -> float: + """上の傾いた壁の内面の Y.""" + return SLOPED_Y_TOP + SLOPED_SLOPE * z + + +@dataclass(frozen=True) +class Site: + """LED モジュールを置く場所 1 つ.""" + + name: str + wall: str # "right" / "bottom" / "top" + led: tuple[float, float, float] # 真ん中の LED の中心 + along: tuple[float, float] # LED を並べる向き(XY 平面の単位ベクトル) + inward: tuple[float, float] # 壁から箱の内側への向き + + +def _module_box(site: Site) -> tuple[np.ndarray, np.ndarray]: + """モジュールの基板(軸平行の箱)の (最小角, 最大角).""" + led = np.array(site.led) + along = np.array([*site.along, 0.0]) + inward = np.array([*site.inward, 0.0]) + corners = [] + for a in (-MODULE_ALONG / 2, MODULE_ALONG / 2): + for b in (-MODULE_TO_WALL, MODULE_INWARD): + for c in (0.05, 0.05 + MODULE_THICKNESS): + corners.append(led + a * along + b * inward + np.array([0.0, 0.0, c])) + pts = np.array(corners) + return pts.min(axis=0), pts.max(axis=0) + + +def _inside_cavity(x: float, y: float, z: float) -> bool: + """点が箱の内面(角の丸みを R20 とした安全側の近似)の内側にあるか.""" + top = y_top(z) + if abs(x) > HALF_X or y < Y_MIN or y > top: + return False + dx = abs(x) - (HALF_X - CORNER_R) + for dy in (y - (top - CORNER_R), (Y_MIN + CORNER_R) - y): + if dx > 0 and dy > 0 and dx * dx + dy * dy > CORNER_R * CORNER_R: + return False + return True + + +def module_fits(site: Site) -> bool: + """モジュールの基板の四隅が箱の内側に収まるか.""" + lo, hi = _module_box(site) + return all(_inside_cavity(x, y, z) for x in (lo[0], hi[0]) for y in (lo[1], hi[1]) + for z in (lo[2], hi[2])) + + +def camera_block(site: Site, grid: int = 41) -> float: + """カメラ位置の候補(中心 ±10 mm の 9 点)のうち最悪の,開口部をふさぐ割合.""" + lo, hi = _module_box(site) + xs = np.linspace(-OPENING_HALF[0], OPENING_HALF[0], grid) + ys = np.linspace(-OPENING_HALF[1], OPENING_HALF[1], grid) + targets = np.array([[x, y, OPENING_Z] for x in xs for y in ys]) + return max( + segment_hits_aabb(CAMERA + np.array([dx, dy, 0.0]), targets, lo, hi).mean() + for dx in (-CAMERA_SPREAD, 0.0, CAMERA_SPREAD) + for dy in (-CAMERA_SPREAD, 0.0, CAMERA_SPREAD) + ) + + +def build_sites() -> list[Site]: + """候補の場所を並べる(X ≥ 0 側.収まらない場所は除く).""" + sites = [] + wall_x = HALF_X - LED_WALL_OFFSET + wall_y = Y_MIN + LED_WALL_OFFSET + for z in Z_LEVELS: + for y in (-70.0, -50.0, -30.0, -10.0, 10.0, 30.0): + sites.append(Site(f"R_y{y:g}_z{z:g}", "right", (wall_x, y, z), (0.0, 1.0), + (-1.0, 0.0))) + for x in (0.0, 13.0, 26.0, 39.0, 52.0): + sites.append(Site(f"B_x{x:g}_z{z:g}", "bottom", (x, wall_y, z), (1.0, 0.0), + (0.0, 1.0))) + for x in (0.0, 15.0, 30.0, 45.0): + sites.append(Site(f"T_x{x:g}_z{z:g}", "top", (x, y_top(z) - LED_WALL_OFFSET, z), + (1.0, 0.0), (0.0, -1.0))) + # L3(下の壁 X ±39・Z -15 + 左右の壁 Y +10 と +30・Z -35)のまわりを細かく + for z in (-10.0, -15.0, -20.0): + for x in np.arange(30.0, 48.1, 3.0): + sites.append(Site(f"B_x{x:g}_z{z:g}", "bottom", (float(x), wall_y, z), (1.0, 0.0), + (0.0, 1.0))) + for z in (-30.0, -35.0, -40.0): + for y in np.arange(0.0, 40.1, 5.0): + sites.append(Site(f"R_y{y:g}_z{z:g}", "right", (wall_x, float(y), z), (0.0, 1.0), + (-1.0, 0.0))) + unique = {s.name: s for s in sites} + return [s for s in unique.values() if module_fits(s) and camera_block(s) == 0.0] + + +def mirror_site(site: Site) -> Site: + """X を反転した場所(左右反転の向きの確認用).""" + x, y, z = site.led + return replace(site, name=f"{site.name}_mirror", led=(-x, y, z), + along=(-site.along[0], site.along[1]), inward=(-site.inward[0], site.inward[1])) + + +def build_modules_yaml( + name: str, modules: list[tuple[Site, float]], base_scene: Path, description: str +) -> Path: + """箱だけのシーンに LED モジュール(基板 + LED 3 個.明るさの倍率つき)を足した YAML を書く.""" + config = yaml.safe_load(base_scene.read_text(encoding="utf-8")) + base = yaml.safe_load(BASE_YAML.read_text(encoding="utf-8")) + template = _bottom_leds(base)[0] + dest = TMP_DIR / "led_sites" / f"scene_{name}.yaml" + dest.parent.mkdir(parents=True, exist_ok=True) + for mesh in config["geometry"]["meshes"]: + mesh["path"] = relative_mesh_path(base_scene.parent / mesh["path"], dest.parent) + + lights = [] + for j, (site, gain) in enumerate(modules): + lo, hi = _module_box(site) + plate = trimesh.creation.box(extents=hi - lo) + plate.apply_translation((lo + hi) / 2) + plate_path = MESH_DIR / "led_sites" / f"{site.name}.stl" + plate_path.parent.mkdir(parents=True, exist_ok=True) + plate.export(plate_path) + config["geometry"]["meshes"].append({ + "id": f"led_cover_module{j}", "path": relative_mesh_path(plate_path, dest.parent), + "unit": "mm", "material": "printer_white", + }) + led = np.array(site.led) + along = np.array([*site.along, 0.0]) + for k in (-1, 0, 1): + light = copy.deepcopy(template) + light["id"] = f"led_module{j}_{k + 1}" + light["center"] = [round(float(c), 4) for c in led + k * MODULE_PITCH * along] + light["direction"] = [0.0, 0.0, -1.0] + light["radiance"] = [float(r) * gain for r in template["radiance"]] + if abs(site.along[0]) < 0.5: # Y に沿って並べるときは LED の縦横を入れ替える + light["size"] = [template["size"][1], template["size"][0]] + lights.append(light) + config["lights"] = lights + config["name"] = name + config["description"] = description + config["render"]["seed"] = 0 + dest.write_text(yaml.safe_dump(config, allow_unicode=True, sort_keys=False), + encoding="utf-8", newline="\n") + return dest + + +def build_site_yaml(site: Site, base_scene: Path) -> Path: + """箱だけのシーンにモジュール 1 個を足した基底画像用の YAML.""" + return build_modules_yaml(site.name, [(site, 1.0)], base_scene, + f"LED モジュール 1 個の基底画像: {site.name}(H_y90 の箱)") + + +def parse_layout(spec: str, sites: dict[str, Site]) -> list[tuple[Site, float]]: + """「場所:倍率,場所:倍率」を,X > 0 の場所は左右対称に 2 個にしたモジュールの並びにする.""" + modules = [] + for item in spec.split(","): + site_name, gain = item.split(":") + site = sites[site_name] + modules.append((site, float(gain))) + if abs(site.led[0]) > 1e-6: + modules.append((mirror_site(site), float(gain))) + return modules + + +def render_layouts(specs: list[str], sites: dict[str, Site], base_scene: Path, base_cand) -> int: + """組み合わせを基板込みでレンダし,候補比較(candidate_layouts)と同じ指標で集計する.""" + from sweep_candidate_layouts import OUTPUT_BASE as CAND_OUTPUT + from sweep_candidate_layouts import SUMMARY_COLUMNS, run_candidate + + names = [spec.split("=", 1)[0] for spec in specs] + summary = CAND_OUTPUT / f"summary_layouts_{'_'.join(names)}.csv" + CAND_OUTPUT.mkdir(parents=True, exist_ok=True) + with summary.open("w", newline="", encoding="utf-8") as f: + writer = csv.DictWriter(f, fieldnames=SUMMARY_COLUMNS) + writer.writeheader() + for spec in specs: + name, layout = spec.split("=", 1) + note = f"H_y90 の箱・3 個 1 組のモジュール: {layout}" + scene = build_modules_yaml(name, parse_layout(layout, sites), base_scene, note) + cand = replace(base_cand, name=name, note=note) + for seed in (0, 1, 2): + writer.writerow(run_candidate(cand, scene, seed)) + f.flush() + print(f"[done] {summary}") + return 0 + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--only", nargs="+", help="レンダする場所の名前(既定: 全部)") + parser.add_argument("--prepare-only", action="store_true", help="シーンと sites.csv だけ作る") + parser.add_argument("--layouts", nargs="+", metavar="NAME=SPEC", + help="組み合わせを基板込みで本番どおりにレンダする(seed 3 本)." + "SPEC は「場所:倍率,場所:倍率」(X > 0 の場所は左右に置く)") + args = parser.parse_args(argv) + + base_cand = next(c for c in CANDIDATES if c.name == BASE_CANDIDATE) + base_scene = build_candidate_yaml(replace(base_cand, name="led_sites_base", boards=())) + sites = build_sites() + if args.layouts: + return render_layouts(args.layouts, {s.name: s for s in sites}, base_scene, base_cand) + probe = next(s for s in sites if s.name == "R_y-10_z-35") + all_sites = [*sites, mirror_site(probe)] + + OUTPUT_BASE.mkdir(parents=True, exist_ok=True) + with (OUTPUT_BASE / "sites.csv").open("w", newline="", encoding="utf-8") as f: + writer = csv.writer(f) + writer.writerow(["name", "wall", "x", "y", "z"]) + for s in all_sites: + writer.writerow([s.name, s.wall, *s.led]) + scenes = {s.name: build_site_yaml(s, base_scene) for s in all_sites} + print(f"[prepare] {len(all_sites)} か所({OUTPUT_BASE / 'sites.csv'})") + if args.prepare_only: + return 0 + + from sm_tias_lightsim.render.pipeline import render_yaml + + for name in args.only or list(scenes): + out = OUTPUT_BASE / name + if (out / "luminance.npy").exists(): + continue + t0 = time.perf_counter() + render_yaml(scenes[name], out) + print(f"[render] {name} ({time.perf_counter() - t0:.1f}s)", flush=True) + print("[done]") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/optimize_led_sites.py b/scripts/optimize_led_sites.py new file mode 100644 index 0000000..2c0cd98 --- /dev/null +++ b/scripts/optimize_led_sites.py @@ -0,0 +1,174 @@ +"""LED モジュール(3 個 1 組)の置き場所の組み合わせを,基底画像の和で探す. + +scripts/led_site_basis.py で作った「1 か所だけ点けた」画像を使う.光は線形なので, +組み合わせの画像は基底画像の重み付き和で近似できる(他のモジュールの基板による遮りは無視). + +X > 0 の場所は左右対称に 2 個(左側は画像を左右反転)を 1 単位,X = 0 の場所は 1 個を 1 単位とする. +各単位の明るさは 60 mA(定電流 IC 2 個.重み 1)か 30 mA(IC 1 個.重み 0.5). + +ムラの指標は σ=12 px のガウス平滑化後の CoV(TEST_21 の構造 CoV と同じ平滑化.ノイズ補正なし). +平滑化は線形なので,平滑化した基底画像の内積の表(グラム行列)を先に作れば,組み合わせの +CoV² = N·wᵀGw / (wᵀm)² − 1 が小さな行列計算で求まる.これで単位を 2〜4 種類選ぶ組み合わせを +総当たりし,上位を本来の指標(metrics_for)で計算し直す. + +実行方法: + uv run python scripts/optimize_led_sites.py + uv run python scripts/optimize_led_sites.py --max-units 3 --top 20 +""" + +from __future__ import annotations + +import argparse +import csv +import itertools +import sys +from dataclasses import dataclass +from pathlib import Path + +import numpy as np +from scipy.ndimage import gaussian_filter + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) + +from compare_real_vs_sim_metrics import ( # noqa: E402 + STRUCTURE_SIGMA, + load_sim_roi, + metrics_for, +) + +ROOT = Path(__file__).resolve().parents[1] +SITE_DIR = ROOT / "output" / "led_sites" +A0_LUMINANCE = ROOT / "output" / "candidate_layouts" / "A0" / "s0" / "luminance.npy" +MIRROR_PROBE = "R_y-10_z-35" +WEIGHTS = (0.5, 1.0) +LEDS_PER_MODULE = 3 + + +@dataclass(frozen=True) +class Unit: + """左右対称に置くモジュールの組(X = 0 なら 1 個).""" + + site: str + modules: int # 1(X = 0)か 2(左右) + image: np.ndarray # 輝度 ROI(重み 1 のとき) + + +def mirror_axis() -> int: + """左右反転に使う画像の軸を,確認用の反転レンダと比べて決める.""" + probe = load_sim_roi(SITE_DIR / MIRROR_PROBE / "luminance.npy") + mirrored = load_sim_roi(SITE_DIR / f"{MIRROR_PROBE}_mirror" / "luminance.npy") + errors = {axis: float(np.abs(gaussian_filter(np.flip(probe, axis=axis) - mirrored, 8)).mean()) + for axis in (0, 1)} + axis = min(errors, key=errors.get) + rel = errors[axis] / mirrored.mean() + print(f"[mirror] 画像の軸 {axis} で反転(平均差 {rel:.4f}・もう一方 " + f"{errors[1 - axis] / mirrored.mean():.4f})") + return axis + + +def load_units(axis: int) -> list[Unit]: + """sites.csv の場所ごとに単位(左右の組)の画像を作る.""" + units = [] + with (SITE_DIR / "sites.csv").open(encoding="utf-8") as f: + for row in csv.DictReader(f): + if row["name"].endswith("_mirror"): + continue + path = SITE_DIR / row["name"] / "luminance.npy" + if not path.exists(): + print(f"[skip] {row['name']}(画像なし)") + continue + roi = load_sim_roi(path) + if abs(float(row["x"])) > 1e-6: + units.append(Unit(row["name"], 2, roi + np.flip(roi, axis=axis))) + else: + units.append(Unit(row["name"], 1, roi)) + return units + + +def search(units: list[Unit], max_units: int, top: int, min_bright: float, a0_mean: float, + max_modules: int) -> list[tuple[float, tuple[int, ...], tuple[float, ...]]]: + """単位を 1〜max_units 種類選び,重み(0.5 / 1)の全組み合わせで平滑化 CoV を求める.""" + smooth = np.stack([gaussian_filter(u.image, STRUCTURE_SIGMA).ravel() for u in units]) + n_pix = smooth.shape[1] + gram = smooth @ smooth.T + means = smooth.sum(axis=1) + modules = np.array([u.modules for u in units]) + best: list[tuple[float, tuple[int, ...], tuple[float, ...]]] = [] + for k in range(1, max_units + 1): + combos = np.array(list(itertools.combinations(range(len(units)), k))) + for weights in itertools.product(WEIGHTS, repeat=k): + w = np.array(weights) + n_mod = (modules[combos] * (w > 0)).sum(axis=1) + sub_g = gram[combos[:, :, None], combos[:, None, :]] + num = np.einsum("ci,cij,cj->c", np.broadcast_to(w, combos.shape), sub_g, + np.broadcast_to(w, combos.shape)) + den = (means[combos] * w).sum(axis=1) + cov2 = n_pix * num / den**2 - 1.0 + bright = den / n_pix / a0_mean + ok = (n_mod <= max_modules) & (bright >= min_bright) + for idx in np.argsort(np.where(ok, cov2, np.inf))[:top]: + if not ok[idx]: + break + best.append((float(np.sqrt(max(cov2[idx], 0.0))), tuple(combos[idx]), + tuple(weights))) + best.sort(key=lambda t: t[0]) + return best[:top] + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--max-units", type=int, default=3, help="選ぶ場所の種類の最大数") + parser.add_argument("--max-modules", type=int, default=8, + help="モジュール(3 個 1 組)の最大数(8 で LED 24 個)") + parser.add_argument("--min-bright", type=float, default=0.6, + help="明るさの下限(現行機 A0 の平均輝度との比)") + parser.add_argument("--top", type=int, default=15) + parser.add_argument("--out", type=Path, default=SITE_DIR / "best_layouts.csv") + args = parser.parse_args(argv) + + axis = mirror_axis() + units = load_units(axis) + a0 = load_sim_roi(A0_LUMINANCE) + a0_metrics = metrics_for(a0) + print(f"[units] {len(units)} 単位") + best = search(units, args.max_units, args.top * 4, args.min_bright, a0.mean(), + args.max_modules) + + rows = [] + seen = set() + for proxy, combo, weights in best: + key = (combo, weights) + if key in seen: + continue + seen.add(key) + image = sum(w * units[i].image for i, w in zip(combo, weights, strict=True)) + m = metrics_for(image) + n_mod = sum(units[i].modules for i in combo) + rows.append({ + "layout": " + ".join(f"{units[i].site}×{w:g}" for i, w in zip(combo, weights, + strict=True)), + "modules": n_mod, "leds": n_mod * LEDS_PER_MODULE, + "proxy_cov": round(proxy, 5), + "structure_cov_ratio": round(m["structure_cov"] / a0_metrics["structure_cov"], 3), + "min_fullimage": round(m["min_fullimage"], 3), + "b1": round(m["b1"], 4), "a1": round(m["a1"], 4), + "bright_ratio": round(m["mean"] / a0_metrics["mean"], 2), + }) + if len(rows) >= args.top: + break + rows.sort(key=lambda r: r["structure_cov_ratio"]) + with args.out.open("w", newline="", encoding="utf-8") as f: + writer = csv.DictWriter(f, fieldnames=list(rows[0])) + writer.writeheader() + writer.writerows(rows) + for r in rows: + print(f"{r['structure_cov_ratio']:.3f} min {r['min_fullimage']:.3f} " + f"b1 {r['b1']:+.4f} 明るさ {r['bright_ratio']:.2f} LED {r['leds']:2d} " + f"{r['layout']}") + print(f"[saved] {args.out}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/show_led_geometry.py b/scripts/show_led_geometry.py index d7bb2b6..9498861 100644 --- a/scripts/show_led_geometry.py +++ b/scripts/show_led_geometry.py @@ -25,7 +25,7 @@ from sm_tias_lightsim.geometry.loader import load_stl from sm_tias_lightsim.scene.schema import SceneConfig, load_scene_yaml -_GROUP_COLORS = {"bottom": "red", "left": "green", "right": "blue"} +_GROUP_COLORS = {"bottom": "red", "left": "green", "right": "blue", "top": "magenta"} _ARROW_LEN_MM = 12.0 # バグ修正前の縦ストリップ高さ(mm).バグ時 scale の Y が 1.0(m)=±1m のままだったため @@ -74,16 +74,28 @@ return pv.PolyData(corners, np.array([4, 0, 1, 2, 3])) -def _resolve_mesh_path(path: str) -> str: - """scene YAML のメッシュパスを解決する(絶対 → そのまま,無ければ configs/meshes/basename).""" +def _resolve_mesh_path(path: str, scene_dir: str | None = None) -> str: + """scene YAML のメッシュパスを解決する. + + 絶対・CWD 基準で見つかればそのまま,次に YAML からの相対(sm-render と同じ解釈), + どちらも無ければ configs/meshes/basename. + """ if os.path.isfile(path): return path + if scene_dir is not None: + candidate = os.path.join(scene_dir, path) + if os.path.isfile(candidate): + return candidate base = os.path.basename(path.replace(chr(92), "/")) return os.path.join("configs", "meshes", base) def _build_plotter( - scene_config: SceneConfig, *, off_screen: bool, buggy: bool = False + scene_config: SceneConfig, + *, + off_screen: bool, + buggy: bool = False, + scene_dir: str | None = None, ) -> pv.Plotter: pv.global_theme.allow_empty_mesh = True plotter = pv.Plotter(off_screen=off_screen, window_size=(1400, 1050)) @@ -91,7 +103,7 @@ # 筐体(半透明)・評価板(シアン)・暗い phone/holder for mesh_config in scene_config.geometry.meshes: - loaded = load_stl(_resolve_mesh_path(mesh_config.path), "mm") + loaded = load_stl(_resolve_mesh_path(mesh_config.path, scene_dir), "mm") vertices = np.array(loaded.vertices) faces_arr = np.array(loaded.faces) faces = np.hstack([np.full((faces_arr.shape[0], 1), 3), faces_arr]).ravel() @@ -176,7 +188,10 @@ print(f"[{mode}] LED 数: {len(scene_config.lights)} {dims} direction: {first.direction}") if args.screenshot: - plotter = _build_plotter(scene_config, off_screen=True, buggy=args.buggy) + plotter = _build_plotter( + scene_config, off_screen=True, buggy=args.buggy, + scene_dir=os.path.dirname(os.path.abspath(args.scene)), + ) views = [ ("iso", plotter.view_isometric), ("front_XY", plotter.view_xy), @@ -190,7 +205,10 @@ print("saved", out_path) plotter.close() else: - plotter = _build_plotter(scene_config, off_screen=False, buggy=args.buggy) + plotter = _build_plotter( + scene_config, off_screen=False, buggy=args.buggy, + scene_dir=os.path.dirname(os.path.abspath(args.scene)), + ) plotter.view_isometric() plotter.show() diff --git a/scripts/sweep_candidate_layouts.py b/scripts/sweep_candidate_layouts.py new file mode 100644 index 0000000..495fc2c --- /dev/null +++ b/scripts/sweep_candidate_layouts.py @@ -0,0 +1,814 @@ +"""新しい実機の候補(現行の形の改良 A・箱形 B)を現行機と比べる(PLAN_03「候補の比較計画」). + +現行機(A0 = configs/scene_baseline.yaml)を基準に,LED 基板の枚数・置き方と筐体の形だけを +変えたシーンを作り,同じレンダ設定・同じ評価指標で比べる.材質・LED 1 個あたりの放射量・ +レンダ設定(spp 4096 など)は基準シーンのまま変えない(LED の数が増えれば全体は明るくなる). + +候補: + A0 現行機(下・右・左の 3 枚) + A1 現行の形に上の基板を足して 4 枚(上の基板は現行の内壁際.評価板の中心からの距離は + 下の基板より近い) + A2_lr 現行の形で左右 2 枚だけ + A2_tb 現行の形で上下 2 枚だけ(上は A1 と同じ位置) + B1 現行機と同じくらいの箱形(内寸 144 mm 角・深さ 144 mm)に左右 2 枚 + B2 同じ箱形に上下左右 4 枚 + +LED 基板は現行と同じもの(LED 基板カバー + LED 6 個)を剛体として回転・平行移動して置く +(鏡映は使わない.面の向きが裏返るため).LED は現行どおり評価板と反対側(-Z)に向ける. +-Z 向きのランバート光源は評価板に直接光を出さないので,遮光板(バッフル)は不要. + +箱形の底面にはスマホとホルダが見える窓の代わりに暗い板(holder_dark.現行機でキャビティの +奥に見える開口と同じ 120 × 34 mm)を置く.スマホ本体・ホルダの形は入れない近似である. + +実行方法: + uv run python scripts/sweep_candidate_layouts.py --prepare-only # メッシュ + YAML + uv run python scripts/sweep_candidate_layouts.py --screenshots # 配置確認の画像 + uv run python scripts/sweep_candidate_layouts.py # レンダ + 評価 + 研究室サーバでは: + uv run sm-remote run --name cand --gpu 0 -- python scripts/sweep_candidate_layouts.py + +評価は TEST_20 と同じ処理(compare_real_vs_sim_metrics.metrics_for: 構造 CoV・画像全体の +ノイズ補正付き min/max・輪帯平均 min/max・方位フーリエ a1/b1/a2/a4).seed を変えて 3 本回す. + uv run python scripts/sweep_candidate_layouts.py --only A0 B2 +""" + +from __future__ import annotations + +import argparse +import copy +import csv +import subprocess +import sys +import time +from dataclasses import dataclass, replace +from pathlib import Path + +import numpy as np +import trimesh +import yaml + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) + +from generate_cube_housing import ( # noqa: E402 + build_cube_housing, + build_rounded_cube_housing, + build_rounded_sloped_box_housing, + build_sloped_box_housing, +) + +from sm_tias_lightsim.scene.paths import relative_mesh_path # noqa: E402 + +ROOT = Path(__file__).resolve().parents[1] +BASE_YAML = ROOT / "configs" / "scene_baseline.yaml" +EVAL_YAML = ROOT / "configs" / "eval_baseline_dng_target_shape.yaml" +TMP_DIR = ROOT / "configs" / "_tmp_candidates" +MESH_DIR = TMP_DIR / "meshes" +OUTPUT_BASE = ROOT / "output" / "candidate_layouts" + +# 現行機の下の基板(LED 基板カバー下 + led_bottom_*)を基準の部品として使う +BOTTOM_COVER_STL = ROOT / "configs" / "meshes" / "LED基板カバー下.stl" +BOTTOM_LED_Y = -71.0 +BOTTOM_LED_Z = -65.95 + +# 現行機の内壁(Z = -55 mm の断面.前側.stl の内側の輪郭): Y = -77.0 〜 +47.0 +CURRENT_WALL_BOTTOM_Y = -77.0 +CURRENT_WALL_TOP_Y = 47.0 + +# 箱形(generate_cube_housing の立方体.評価板・リムは TEST_16 と同じ) +BOX_SIZE = 144.0 # 現行機の内寸の幅(X = ±72 mm)に合わせる +BOX_THICKNESS = 3.0 +BOARD_HALF = (49.5, 51.0) +RIM_INSET = 1.5 +RIM_Z = 0.0 + +# 箱形の底面に置く「スマホ側の窓」(現行機の Z = -145 mm の開口: X ±61, Y -13〜+21) +WINDOW_SIZE = (120.0, 34.0) +WINDOW_CENTER_Y = 4.0 +WINDOW_THICKNESS = 1.0 + +# 下の基板が現行の内壁から離れている量(LED 中心で 6 mm) +LED_WALL_OFFSET = BOTTOM_LED_Y - CURRENT_WALL_BOTTOM_Y + + +@dataclass(frozen=True) +class Board: + """LED 基板 1 枚の置き方(下の基板を Z 軸まわりに回し,LED 中心を `led_xy` に移す).""" + + label: str + angle_deg: float + led_xy: tuple[float, float] + dz: float = 0.0 # この基板だけ Z 方向に追加で動かす量 [mm](候補の led_dz に足す) + tilt_deg: float = 0.0 # LED 列の中心を軸に X 軸まわりに傾ける角度(正で LED が +Y を向く) + + +@dataclass(frozen=True) +class Candidate: + """候補 1 つ.""" + + name: str + housing: str # "current" / "box" + boards: tuple[Board, ...] + note: str + led_dz: float = 0.0 # 置いた基板(カバー + LED)を Z 方向に動かす量(mm) + white_phone: bool = False # 診断用: スマホ・ホルダの材質を筐体と同じ白にする + floor_up: bool = False # 基板を箱の底(スマホ側)に置き,LED を評価板へ向けて遮光板を付ける + gain_bottom: float = 1.0 # 下の基板の LED の放射量の倍率(基板ごとの出力差への強さを見る) + box_size: float = 144.0 # 箱形の内寸(一辺・深さ)[mm] + fillet: float = 0.0 # 箱形の内側の稜と角を丸める半径 [mm](0 で丸めない) + y_min: float = -80.0 # housing="sloped": 内面の -Y 側の壁 [mm] + nose: bool = False # 箱形: 上の壁に鼻の穴(現行機と同じ U 字の切り欠き)を開ける + nose_pocket: bool = False # 鼻の穴を箱の中から壁で囲って袋にする + ceiling_strip: bool = False # 鼻の穴の左右の天井近くに細い LED 列(新しい細い基板)を置く + strip_gain: float = 1.0 # 細い LED 列の放射量の倍率(抵抗で電流を絞る想定) + half_x: float = 80.0 # housing="sloped": 内面の X の半幅 [mm] + + +def _current_top() -> Board: + return Board("top", 180.0, (0.0, CURRENT_WALL_TOP_Y - LED_WALL_OFFSET)) + + +CURRENT_BOTTOM = Board("bottom", 0.0, (0.0, BOTTOM_LED_Y)) +BOX_WALL = BOX_SIZE / 2 - LED_WALL_OFFSET + +CANDIDATES = ( + Candidate("A0", "current", (), "現行機(基準シーンそのまま)"), + Candidate("A1", "current", (_current_top(),), "現行の形 + 上の基板(4 枚)"), + Candidate("A2_lr", "current", (), "現行の形・左右 2 枚"), + Candidate("A2_tb", "current", (_current_top(),), "現行の形・上下 2 枚"), + Candidate( + "B1", "box", + (Board("right", 90.0, (BOX_WALL, 0.0)), Board("left", -90.0, (-BOX_WALL, 0.0))), + "箱形・左右 2 枚", + ), + Candidate( + "B2", "box", + ( + Board("bottom", 0.0, (0.0, -BOX_WALL)), + Board("top", 180.0, (0.0, BOX_WALL)), + Board("right", 90.0, (BOX_WALL, 0.0)), + Board("left", -90.0, (-BOX_WALL, 0.0)), + ), + "箱形・上下左右 4 枚", + ), + # 診断: 現行機の上端中央の暗部がスマホ・ホルダの暗い材質から来るか + Candidate("A0_white", "current", (), "現行機・スマホとホルダを白に(診断)", + white_phone=True), +) + +# 箱形で基板の高さ(LED 中心 Z.現行は -65.95)を振る +BOX_HEIGHTS = (-25.0, -45.0, -90.0, -115.0) +for _base in [c for c in CANDIDATES if c.housing == "box"]: + for _z in BOX_HEIGHTS: + CANDIDATES += ( + Candidate(f"{_base.name}_z{-_z:g}", "box", _base.boards, + f"{_base.note}・LED 高さ Z={_z:g}", led_dz=_z - (-65.95)), + ) + +# 箱の底に置き評価板へ向ける(遮光板付き.TEST_18 で最良だった「板向き + バッフル」). +# 基板はスマホ側の窓(Y -13〜+21)を避け,評価板の中心に対して対称に置く +FLOOR_BOARD_Y = 50.0 +FLOOR_BOARD_X = 65.0 # 裏返したカバーが側壁(X = ±72)に食い込まない位置 +CANDIDATES += ( + Candidate( + "C1", "box", + (Board("bottom", 0.0, (0.0, -FLOOR_BOARD_Y)), Board("top", 180.0, (0.0, FLOOR_BOARD_Y))), + "箱形・底に上下 2 枚・評価板向き + 遮光板", floor_up=True, + ), + Candidate( + "C2", "box", + ( + Board("bottom", 0.0, (0.0, -FLOOR_BOARD_Y)), + Board("top", 180.0, (0.0, FLOOR_BOARD_Y)), + Board("right", 90.0, (FLOOR_BOARD_X, 0.0)), + Board("left", -90.0, (-FLOOR_BOARD_X, 0.0)), + ), + "箱形・底に 4 枚・評価板向き + 遮光板", floor_up=True, + ), +) + +# 基板ごとの出力差への強さ: 下の基板だけ 10% 明るくする +IMBALANCE_GAIN = 1.1 +for _base in [c for c in CANDIDATES if c.name in ("A0", "B2_z25", "C1", "C2")]: + CANDIDATES += ( + Candidate(f"{_base.name}_imb", _base.housing, _base.boards, + f"{_base.note}・下の基板だけ +10%", led_dz=_base.led_dz, + floor_up=_base.floor_up, gain_bottom=IMBALANCE_GAIN), + ) + +# 箱の大きさへの感度(内寸 144 mm に対し ±10% 前後).側壁の基板は壁からの距離を保って動かす +BOX_SIZES = (130.0, 160.0) +for _size in BOX_SIZES: + _wall = _size / 2 - LED_WALL_OFFSET + CANDIDATES += ( + Candidate( + f"B2_z25_L{_size:g}", "box", + ( + Board("bottom", 0.0, (0.0, -_wall)), + Board("top", 180.0, (0.0, _wall)), + Board("right", 90.0, (_wall, 0.0)), + Board("left", -90.0, (-_wall, 0.0)), + ), + f"箱形 {_size:g} mm・上下左右 4 枚・LED 高さ Z=-25", led_dz=-25.0 - (-65.95), + box_size=_size, + ), + Candidate( + f"C1_L{_size:g}", "box", + (Board("bottom", 0.0, (0.0, -FLOOR_BOARD_Y)), + Board("top", 180.0, (0.0, FLOOR_BOARD_Y))), + f"箱形 {_size:g} mm・底に上下 2 枚・評価板向き + 遮光板", floor_up=True, + box_size=_size, + ), + ) + +# 内側の稜と角の丸み(B2_z25・内寸 160 mm.半径 27 mm 超は天井の平らな部分が評価板の縁より狭い) +FILLETS = (10.0, 20.0, 25.0) +_wall160 = 160.0 / 2 - LED_WALL_OFFSET +for _r in FILLETS: + CANDIDATES += ( + Candidate( + f"B2_z25_L160_R{_r:g}", "box", + ( + Board("bottom", 0.0, (0.0, -_wall160)), + Board("top", 180.0, (0.0, _wall160)), + Board("right", 90.0, (_wall160, 0.0)), + Board("left", -90.0, (-_wall160, 0.0)), + ), + f"箱形 160 mm・内側の角を R{_r:g} で丸める・上下左右 4 枚・LED 高さ Z=-25", + led_dz=-25.0 - (-65.95), box_size=160.0, fillet=_r, + ), + ) + +# 上面(+Y 側)を奥ほど低く傾けた箱(撮影される人がスマホの画面を今と同じ範囲で見られる形. +# 外面の上端を顔側 Y=62・傾き 0.18(Z=-150 で約 35)にすると,目の高さ 60〜90 mm で今の装置と +# 同じかそれ以上に画面が見える).内面はそこから壁厚だけ内側.X は ±80(内寸 160 と同じ) +SLOPED_HALF_X = 80.0 +SLOPED_Y_TOP = 59.0 +SLOPED_SLOPE = 0.18 +SLOPED_DEPTH = 160.0 +SLOPED_LED_Z = -25.0 +SLOPED_TOP_LED_Z = -70.0 + + +def _sloped_boards( + y_min: float, with_top: bool, half_x: float = SLOPED_HALF_X +) -> tuple[Board, ...]: + wall_x = half_x - LED_WALL_OFFSET + boards = [ + Board("bottom", 0.0, (0.0, y_min + LED_WALL_OFFSET)), + Board("right", 90.0, (wall_x, 0.0)), + Board("left", -90.0, (-wall_x, 0.0)), + ] + if with_top: + # 上の壁は評価板の縁に近く,Z=-25 ではカメラから開口部の縁をふさぐ.カメラの視野が + # 細くなる奥(Z=-70)へ下げる + top_wall = SLOPED_Y_TOP + SLOPED_SLOPE * SLOPED_TOP_LED_Z + boards.append(Board("top", 180.0, (0.0, top_wall - LED_WALL_OFFSET), + dz=SLOPED_TOP_LED_Z - SLOPED_LED_Z)) + return tuple(boards) + + +for _ymin in (-80.0, -65.0): + for _top in (True, False): + _n = 4 if _top else 3 + CANDIDATES += ( + Candidate( + f"F{_n}_y{-_ymin:g}", "sloped", _sloped_boards(_ymin, _top), + f"上面を傾けた箱(-Y 側 {_ymin:g})・{_n} 枚・LED 高さ Z=-25" + + ("(上の基板は Z=-70)" if _top else ""), + led_dz=SLOPED_LED_Z - (-65.95), box_size=SLOPED_DEPTH, y_min=_ymin, + ), + ) + +# 上面を傾けた箱で +Y 側が暗い傾きを,明るさの配分で打ち消す(上の壁には基板を置けないため). +# 左右の基板を +Y へずらす量 [mm] と下の基板の明るさの倍率(0 は下の基板なし)の組み合わせ +SLOPED_BALANCE = ((10.0, 1.0), (20.0, 1.0), (0.0, 0.5), (10.0, 0.5), (20.0, 0.5), (20.0, 0.0)) + +for _shift, _gain in SLOPED_BALANCE: + _boards = tuple( + Board(b.label, b.angle_deg, (b.led_xy[0], b.led_xy[1] + _shift)) + if b.label in ("right", "left") else b + for b in _sloped_boards(-80.0, False) + if not (b.label == "bottom" and _gain == 0.0) + ) + CANDIDATES += ( + Candidate( + f"F3_y80_s{_shift:g}_b{_gain:g}".replace(".", ""), "sloped", _boards, + f"上面を傾けた箱・左右を +Y へ {_shift:g} mm・" + + (f"下の基板 ×{_gain:g}" if _gain > 0 else "下の基板なし"), + led_dz=SLOPED_LED_Z - (-65.95), box_size=SLOPED_DEPTH, y_min=-80.0, + gain_bottom=_gain if _gain > 0 else 1.0, + ), + ) + +# 鼻の穴: 現行機の前側と同じ切り欠き.顔の面で幅 30 mm,深さ 15 mm で幅 15 mm に狭まり,底は +# 半径 7.5 mm の丸(顔の面から深さ 22.5 mm).この断面(凸)を上の壁に Y 方向へ貫通させる. +# 穴の外は何も無い(光を返さない)扱いで,A0(現行機の STL)と同じ条件になる +NOSE_TOP_HALF_WIDTH = 15.0 +NOSE_HALF_WIDTH = 7.5 +NOSE_DEPTH = 22.5 +NOSE_Y_START = BOARD_HALF[1] + 1.0 # 評価板の縁(受けの部分)は切らない +NOSE_POCKET_WALL = 1.5 # 鼻の穴を袋にするときの壁の厚さ +NOSE_POCKET_GAP = 0.2 # 袋の評価板側の壁と評価板の縁の隙間 + +for _base in [c for c in CANDIDATES + if c.name in ("B2_z25_L160", "F3_y80", "F3_y80_s10_b1", "F3_y80_s20_b1")]: + CANDIDATES += ( + replace(_base, name=f"{_base.name}_N", note=f"{_base.note}・鼻の穴あり", nose=True), + ) + +# 画面が今と同じ範囲で見えることと鼻の穴は必須(PLAN_03).その中での改善を F3_y80_s20_b1_N から探す +# A. 内側の角を丸める.天井と +Y 側の壁の稜は評価板の上の縁に近いので SLOPED_TOP_EDGE_FILLET まで +SLOPED_TOP_EDGE_FILLET = 8.0 +_best = next(c for c in CANDIDATES if c.name == "F3_y80_s20_b1_N") +for _r in (10.0, 20.0): + CANDIDATES += ( + replace(_best, name=f"{_best.name}_R{_r:g}", fillet=_r, + note=f"{_best.note}・内側の角を R{_r:g}(上の縁の稜は " + f"R{min(_r, SLOPED_TOP_EDGE_FILLET):g})"), + ) +# B. LED の高さ(基準は Z = -25) +for _z in (-15.0, -35.0): + CANDIDATES += ( + replace(_best, name=f"{_best.name}_z{-_z:g}", led_dz=_z - (-65.95), + note=f"{_best.note}・LED 高さ Z={_z:g}"), + ) +# A と B の組み合わせ(R20・LED を奥へ).奥ほど上の壁が低く,丸めた稜もあるので,左右の基板の +# ずらしは基板カバーが壁に食い込まない量まで(Z=-35 で +20 mm,Z=-45 で +16 mm が上限) +for _shift, _z in ((20.0, -35.0), (16.0, -45.0)): + _boards = tuple( + Board(b.label, b.angle_deg, (b.led_xy[0], b.led_xy[1] + _shift)) + if b.label in ("right", "left") else b + for b in _sloped_boards(-80.0, False) + ) + CANDIDATES += ( + replace(_best, name=f"F3_y80_s{_shift:g}_b1_N_R20_z{-_z:g}", boards=_boards, fillet=20.0, + led_dz=_z - (-65.95), + note=f"上面を傾けた箱・左右を +Y へ {_shift:g} mm・鼻の穴あり・内側の角を R20・" + f"LED 高さ Z={_z:g}"), + ) + +# 2 回目の改善(R20・LED Z=-35 の最良案 F3_y80_s20_b1_N_R20_z35 から).残る暗部は上の縁の中央 +# (鼻の穴の前)と下の角,わずかな上下の傾き. +# a. 下の基板だけ奥へ(下側が明るすぎる分を減らす) +# b. 左右の基板を傾けて LED を +Y(上の縁)へ向ける +# c. 下の基板も傾けて LED を +Y(中央)へ向ける +# d. 箱を X に広げる(左右の基板を評価板の縁から離す)・-Y 側を広げる +_best2 = next(c for c in CANDIDATES if c.name == "F3_y80_s20_b1_N_R20_z35") + + +def _shifted(boards: tuple[Board, ...], **per_label: dict) -> tuple[Board, ...]: + """基板ラベルごとに Board のフィールドを置き換えた組を返す.""" + return tuple(replace(b, **per_label.get(b.label, {})) for b in boards) + + +_side = {"right", "left"} +_variants = ( + ("bdz10", "下の基板だけ 10 mm 奥へ", _shifted(_best2.boards, bottom={"dz": -10.0}), {}), + ("bdz20", "下の基板だけ 20 mm 奥へ", _shifted(_best2.boards, bottom={"dz": -20.0}), {}), + ("st15", "左右の基板を +Y へ 15° 傾ける", + _shifted(_best2.boards, right={"tilt_deg": 15.0}, left={"tilt_deg": 15.0}), {}), + ("st30", "左右の基板を +Y へ 30° 傾ける", + _shifted(_best2.boards, right={"tilt_deg": 30.0}, left={"tilt_deg": 30.0}), {}), + ("bt30", "下の基板を +Y へ 30° 傾ける", _shifted(_best2.boards, bottom={"tilt_deg": 30.0}), {}), + ("x90", "箱を X に ±90 へ広げる", + tuple(Board(b.label, b.angle_deg, + (b.led_xy[0] + (10.0 if b.led_xy[0] > 0 else -10.0) if b.label in _side + else b.led_xy[0], b.led_xy[1]), b.dz, b.tilt_deg) + for b in _best2.boards), {"half_x": 90.0}), + ("y90", "-Y 側を -90 へ広げる", + _shifted(_best2.boards, bottom={"led_xy": (0.0, -90.0 + LED_WALL_OFFSET)}), {"y_min": -90.0}), +) +for _key, _desc, _boards, _extra in _variants: + CANDIDATES += ( + replace(_best2, name=f"H_{_key}", boards=_boards, note=f"R20・Z=-35 の最良案 + {_desc}", + **_extra), + ) + +# e. 鼻の穴を箱の中から壁で囲って袋にする(光が穴から逃げない.鼻が入る空間は同じ) +_by_name = {c.name: c for c in CANDIDATES} +for _src in ("F3_y80_s20_b1_N_R20_z35", "H_y90", "H_bt30"): + CANDIDATES += ( + replace(_by_name[_src], name=f"{_src}_P", nose_pocket=True, + note=f"{_by_name[_src].note}・鼻の穴を袋にする"), + ) + +# E. 鼻の穴の左右の天井近くに細い LED 列(新しい細い基板).評価板の上の縁(Y = 51)と上の壁の +# 間に収まる幅 4.5 mm の基板を,丸めた上の縁の稜(R8)より下に置き,LED は今の基板と同じく +# 箱の奥(-Z)へ向ける.片側 3 個 × 左右で 6 個(今の基板 1 枚分) +STRIP_LED_X = (25.0, 32.0, 39.0) +STRIP_Y = (51.5, 56.0) +STRIP_Z = (-10.0, -8.4) # 基板(カバー)の下面・上面 + + +def _ceiling_strips(base: dict, name: str, yaml_dir: Path) -> tuple[list[dict], list[dict]]: + """鼻の穴の左右に置く細い LED 列のメッシュエントリと光源エントリを作る.""" + template = _bottom_leds(base)[0] + y_mid = sum(STRIP_Y) / 2 + meshes, lights = [], [] + for sign, label in ((1.0, "strip_r"), (-1.0, "strip_l")): + x0, x1 = min(STRIP_LED_X) - 4.0, max(STRIP_LED_X) + 4.0 + plate = trimesh.creation.box( + extents=[x1 - x0, STRIP_Y[1] - STRIP_Y[0], STRIP_Z[1] - STRIP_Z[0]]) + plate.apply_translation([sign * (x0 + x1) / 2, y_mid, sum(STRIP_Z) / 2]) + path = MESH_DIR / f"{name}_led_cover_{label}.stl" + plate.export(path) + meshes.append({"id": f"led_cover_{label}", "path": relative_mesh_path(path, yaml_dir), + "unit": "mm", "material": "printer_white"}) + for k, x in enumerate(STRIP_LED_X): + light = copy.deepcopy(template) + light["id"] = f"led_{label}_{k}" + light["center"] = [sign * x, y_mid, STRIP_Z[0] - 0.05] + lights.append(light) + return meshes, lights + + +# F. 左右の基板を上の角へ移して 45° に置く(上の縁の方を照らす).基板が長い(52 mm)ので角の +# 奥までは入らない.カメラから開口部への視線と丸めた壁を避けられる位置を,角へ寄せながら探す +CORNER_LED_XYS = ((57.0, 30.0), (58.0, 31.0), (59.0, 31.5), (60.0, 32.0)) +_y90 = next(c for c in CANDIDATES if c.name == "H_y90") +_y90_bt30 = _shifted(_y90.boards, bottom={"tilt_deg": 30.0}) +CANDIDATES += ( + replace(_best2, name="E1", ceiling_strip=True, + note="R20・Z=-35 の最良案 + 鼻の穴の左右の天井近くに細い LED 列(6 個)"), + replace(_y90, name="G1", boards=_y90_bt30, + note="-Y を -90 へ広げた案 + 下の基板を +Y へ 30° 傾ける"), + replace(_y90, name="G2", ceiling_strip=True, + note="-Y を -90 へ広げた案 + 天井近くの細い LED 列"), + replace(_y90, name="G3", boards=_y90_bt30, ceiling_strip=True, + note="-Y を -90 へ広げた案 + 下の基板を 30° 傾ける + 天井近くの細い LED 列"), +) +# E の LED 列は全灯(今の LED と同じ明るさ)だと上の縁が明るすぎる(b1 が大きく負)ので絞る +for _g in (0.15, 0.25, 0.4): + CANDIDATES += ( + replace(_y90, name=f"G2_g{_g:g}".replace(".", ""), ceiling_strip=True, strip_gain=_g, + note=f"-Y を -90 へ広げた案 + 天井近くの細い LED 列(明るさ ×{_g:g})"), + ) +for _cx, _cy in CORNER_LED_XYS: + CANDIDATES += ( + replace(_best2, name=f"F1_{_cx:g}", boards=( + next(b for b in _best2.boards if b.label == "bottom"), + Board("corner_r", 135.0, (_cx, _cy)), + Board("corner_l", -135.0, (-_cx, _cy)), + ), note=f"R20・Z=-35 の最良案で左右の基板を上の角へ 45° に置く(±{_cx:g}, {_cy:g})"), + ) + +# 遮光板: LED 発光面から BAFFLE_GAP 上に置く厚さ BAFFLE_THICKNESS の板.LED のどの点からも +# 評価板の裏面(Z = -4.5,±49.5 × ±51)が直接見えない大きさにし,BAFFLE_MARGIN だけ広げる +BAFFLE_GAP = 10.0 +BAFFLE_THICKNESS = 1.0 +BAFFLE_MARGIN = 1.5 +EVAL_FACE_Z = -4.5 + +# 現行の形の候補で基準シーンから外す基板(メッシュ id の接尾辞 / LED id の接頭辞) +REMOVED_BOARDS = {"A2_lr": ("bottom",), "A2_tb": ("right", "left")} + + +def _board_transform(board: Board, base_led_xy: tuple[float, float]) -> np.ndarray: + """下の基板(LED 中心 base_led_xy)を board の位置へ動かす剛体変換(4×4).""" + rot = trimesh.transformations.rotation_matrix(np.radians(board.angle_deg), [0, 0, 1]) + base = np.array([base_led_xy[0], base_led_xy[1], 0.0, 1.0]) + rotated = rot @ base + shift = trimesh.transformations.translation_matrix( + [board.led_xy[0] - rotated[0], board.led_xy[1] - rotated[1], 0.0] + ) + return shift @ rot + + +def _bottom_leds(base: dict) -> list[dict]: + return [light for light in base["lights"] if light["id"].startswith("led_bottom_")] + + +def _place_board( + board: Board, base: dict, cover: trimesh.Trimesh, name: str, yaml_dir: Path, + dz: float = 0.0, floor_up: bool = False, box_size: float = BOX_SIZE, +) -> tuple[dict, list[dict]]: + """基板 1 枚分のメッシュエントリと光源エントリを作る(カバー STL も書き出す). + + floor_up のときは基板を長手方向の軸まわりに 180° 裏返して LED を +Z(評価板)へ向け, + カバーの下面が箱の底から 0.2 mm 浮く高さに置く(dz は無視する). + """ + pre = np.eye(4) + if floor_up: + pre = trimesh.transformations.rotation_matrix( + np.pi, [1, 0, 0], point=[0.0, BOTTOM_LED_Y, BOTTOM_LED_Z] + ) + transform = _board_transform(board, (0.0, BOTTOM_LED_Y)) @ pre + if floor_up: + probe = cover.copy() + probe.apply_transform(transform) + dz = (RIM_Z - box_size + 0.2) - float(probe.bounds[0][2]) + transform = trimesh.transformations.translation_matrix([0.0, 0.0, dz + board.dz]) @ transform + if board.tilt_deg: + pivot = transform @ np.array([0.0, BOTTOM_LED_Y, BOTTOM_LED_Z, 1.0]) + transform = trimesh.transformations.rotation_matrix( + np.radians(board.tilt_deg), [1, 0, 0], point=pivot[:3]) @ transform + mesh = cover.copy() + mesh.apply_transform(transform) + path = MESH_DIR / f"{name}_led_cover_{board.label}.stl" + path.parent.mkdir(parents=True, exist_ok=True) + mesh.export(path) + mesh_entry = { + "id": f"led_cover_{board.label}", + "path": relative_mesh_path(path, yaml_dir), + "unit": "mm", + "material": "printer_white", + } + lights = [] + for k, src in enumerate(_bottom_leds(base)): + light = copy.deepcopy(src) + light["id"] = f"led_{board.label}_{k}" + center = transform @ np.array([*src["center"], 1.0]) + light["center"] = [round(float(c), 4) for c in center[:3]] + direction = transform[:3, :3] @ np.array(src["direction"], dtype=float) + light["direction"] = [round(float(d), 6) + 0.0 for d in direction] + # 下の基板の LED は size=[X 幅, Y 幅].90° 回すと X/Y が入れ替わる + if round(board.angle_deg) % 180 != 0: + light["size"] = [src["size"][1], src["size"][0]] + lights.append(light) + return mesh_entry, lights + + +def build_baffle(lights: list[dict]) -> trimesh.Trimesh: + """+Z 向きの LED 群の上に,評価板への直接光を遮る板を作る. + + LED 発光面の四隅(向きに依らず大きい方の辺で正方形とみなす保守側の近似)と評価板裏面の + 四隅を結ぶ線分が,板の下面(LED + BAFFLE_GAP)を通る点の外接矩形を板にする. + """ + led_z = max(light["center"][2] for light in lights) + plane_z = led_z + BAFFLE_GAP + hits = [] + for light in lights: + half = max(light["size"]) / 2 + cx, cy, cz = light["center"] + for px in (cx - half, cx + half): + for py in (cy - half, cy + half): + for qx in (-BOARD_HALF[0], BOARD_HALF[0]): + for qy in (-BOARD_HALF[1], BOARD_HALF[1]): + t = (plane_z - cz) / (EVAL_FACE_Z - cz) + hits.append((px + t * (qx - px), py + t * (qy - py))) + hits_arr = np.array(hits) + lo = hits_arr.min(axis=0) - BAFFLE_MARGIN + hi = hits_arr.max(axis=0) + BAFFLE_MARGIN + plate = trimesh.creation.box(extents=[hi[0] - lo[0], hi[1] - lo[1], BAFFLE_THICKNESS]) + plate.apply_translation([(lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2, + plane_z + BAFFLE_THICKNESS / 2]) + return plate + + +def _nose_prism( + face_z: float, y0: float, y1: float, grow: float = 0.0 +) -> trimesh.Trimesh: + """鼻の穴の断面(NOSE_* .grow だけ外へ太らせる)を Y = y0〜y1 に押し出した凸多面体.""" + half, top_half = NOSE_HALF_WIDTH + grow, NOSE_TOP_HALF_WIDTH + grow + center_z = face_z - NOSE_DEPTH + NOSE_HALF_WIDTH + angles = np.linspace(np.pi, 2 * np.pi, 33) + section = [(half * np.cos(a), center_z + half * np.sin(a)) for a in angles] + section += [(top_half, face_z + 10.0), (-top_half, face_z + 10.0)] + points = [(x, y, z) for x, z in section for y in (y0, y1)] + return trimesh.convex.convex_hull(np.array(points)) + + +def cut_nose(housing: trimesh.Trimesh, pocket: bool = False) -> trimesh.Trimesh: + """箱形の筐体の上の壁に鼻の穴(NOSE_* 参照)を開ける. + + pocket のときは,鼻が入る空間を箱の中から厚さ NOSE_POCKET_WALL の壁で囲って袋にする + (顔側と上は開いたまま,箱の中とはつながらない).評価板側の壁は評価板の縁から + NOSE_POCKET_GAP だけ離す. + """ + face_z = float(housing.bounds[1][2]) + y_end = float(housing.bounds[1][1]) + 10.0 + if not pocket: + parts = [housing] + cutter = _nose_prism(face_z, NOSE_Y_START, y_end) + else: + y_wall = BOARD_HALF[1] + NOSE_POCKET_GAP + y_cut = y_wall + NOSE_POCKET_WALL + shell = trimesh.boolean.intersection( + [_nose_prism(face_z, y_wall, y_end, grow=NOSE_POCKET_WALL), housing.convex_hull], + engine="manifold") + parts = [trimesh.boolean.union([housing, shell], engine="manifold")] + cutter = _nose_prism(face_z, y_cut, y_end) + result = trimesh.boolean.difference([*parts, cutter], engine="manifold") + if not result.is_watertight: + raise RuntimeError("鼻の穴を開けた筐体が閉じた立体になっていない") + return result + + +def _box_meshes( + yaml_dir: Path, box_size: float = BOX_SIZE, fillet: float = 0.0, y_min: float | None = None, + nose: bool = False, half_x: float = SLOPED_HALF_X, nose_pocket: bool = False, +) -> list[dict]: + suffix = f"_R{fillet:g}" if fillet > 0 else "" + if y_min is not None: + suffix = f"_傾斜_y{-y_min:g}" + (f"_R{fillet:g}" if fillet > 0 else "") + if half_x != SLOPED_HALF_X: + suffix += f"_x{half_x:g}" + if nose: + plain = MESH_DIR / f"箱形_L{box_size:g}{suffix}.stl" + _box_meshes(yaml_dir, box_size, fillet, y_min, half_x=half_x) # 穴の無い筐体を先に用意 + housing = MESH_DIR / f"箱形_L{box_size:g}{suffix}_鼻{'袋' if nose_pocket else ''}.stl" + if not housing.exists(): + cut_nose(trimesh.load(plain, force="mesh"), nose_pocket).export(housing) + else: + housing = MESH_DIR / f"箱形_L{box_size:g}{suffix}.stl" + window = MESH_DIR / f"箱形_L{box_size:g}_スマホ側の窓.stl" + MESH_DIR.mkdir(parents=True, exist_ok=True) + if not housing.exists() and y_min is not None and fillet > 0: + build_rounded_sloped_box_housing( + half_x=half_x, y_min=y_min, y_top=SLOPED_Y_TOP, slope=SLOPED_SLOPE, + depth=box_size, thickness=BOX_THICKNESS, + board_half_x=BOARD_HALF[0], board_half_y=BOARD_HALF[1], + rim_inset=RIM_INSET, rim_z=RIM_Z, + fillet=fillet, top_edge_fillet=min(fillet, SLOPED_TOP_EDGE_FILLET), + ).export(housing) + elif not housing.exists() and y_min is not None: + build_sloped_box_housing( + half_x=half_x, y_min=y_min, y_top=SLOPED_Y_TOP, slope=SLOPED_SLOPE, + depth=box_size, thickness=BOX_THICKNESS, + board_half_x=BOARD_HALF[0], board_half_y=BOARD_HALF[1], + rim_inset=RIM_INSET, rim_z=RIM_Z, + ).export(housing) + elif not housing.exists() and fillet > 0: + build_rounded_cube_housing( + size=box_size, thickness=BOX_THICKNESS, + board_half_x=BOARD_HALF[0], board_half_y=BOARD_HALF[1], + rim_inset=RIM_INSET, rim_z=RIM_Z, fillet=fillet, + ).export(housing) + elif not housing.exists(): + build_cube_housing( + size=box_size, thickness=BOX_THICKNESS, + board_half_x=BOARD_HALF[0], board_half_y=BOARD_HALF[1], + rim_inset=RIM_INSET, rim_z=RIM_Z, + ).export(housing) + if not window.exists(): + bottom_z = RIM_Z - box_size + slab = trimesh.creation.box(extents=[*WINDOW_SIZE, WINDOW_THICKNESS]) + slab.apply_translation([0.0, WINDOW_CENTER_Y, bottom_z + WINDOW_THICKNESS / 2]) + slab.export(window) + return [ + {"id": "box_housing", "path": relative_mesh_path(housing, yaml_dir), + "unit": "mm", "material": "printer_white"}, + {"id": "phone_window", "path": relative_mesh_path(window, yaml_dir), + "unit": "mm", "material": "holder_dark"}, + ] + + +def build_candidate_yaml(cand: Candidate) -> Path: + """候補のシーン YAML を書き出してパスを返す.""" + base = yaml.safe_load(BASE_YAML.read_text(encoding="utf-8")) + config = copy.deepcopy(base) + dest = TMP_DIR / f"scene_{cand.name}.yaml" + yaml_dir = dest.parent + config["name"] = f"candidate_{cand.name}" + config["description"] = f"新しい実機の候補 {cand.name}: {cand.note}(PLAN_03)" + + removed = REMOVED_BOARDS.get(cand.name, ()) + if cand.housing == "current": + meshes = [ + m for m in config["geometry"]["meshes"] + if not any(m["id"] == f"led_cover_{r}" for r in removed) + ] + for m in meshes: + m["path"] = relative_mesh_path(BASE_YAML.parent / m["path"], yaml_dir) + lights = [ + light for light in config["lights"] + if not any(light["id"].startswith(f"led_{r}_") for r in removed) + ] + else: + meshes = _box_meshes(yaml_dir, cand.box_size, cand.fillet, + cand.y_min if cand.housing == "sloped" else None, cand.nose, + cand.half_x, cand.nose_pocket) + meshes.append({ + "id": "evaluation_board", + "path": relative_mesh_path(BASE_YAML.parent / "meshes" / "照明ムラ補正ボード.stl", + yaml_dir), + "unit": "mm", "material": "printer_white", + }) + lights = [] + + cover = trimesh.load(BOTTOM_COVER_STL, force="mesh") + for board in cand.boards: + mesh_entry, board_lights = _place_board( + board, base, cover, cand.name, yaml_dir, cand.led_dz, cand.floor_up, + cand.box_size, + ) + meshes.append(mesh_entry) + if cand.floor_up: + baffle_path = MESH_DIR / f"{cand.name}_baffle_{board.label}.stl" + build_baffle(board_lights).export(baffle_path) + meshes.append({"id": f"baffle_{board.label}", + "path": relative_mesh_path(baffle_path, yaml_dir), + "unit": "mm", "material": "printer_white"}) + lights.extend(board_lights) + + if cand.ceiling_strip: + strip_meshes, strip_lights = _ceiling_strips(base, cand.name, yaml_dir) + for light in strip_lights: + light["radiance"] = [float(r) * cand.strip_gain for r in light["radiance"]] + meshes.extend(strip_meshes) + lights.extend(strip_lights) + if cand.gain_bottom != 1.0: + for light in lights: + if light["id"].startswith("led_bottom_"): + light["radiance"] = [float(r) * cand.gain_bottom for r in light["radiance"]] + if cand.white_phone: + for m in meshes: + if m["id"] in ("phone_holder", "phone_body"): + m["material"] = "printer_white" + config["geometry"]["meshes"] = meshes + config["lights"] = lights + dest.parent.mkdir(parents=True, exist_ok=True) + dest.write_text(yaml.safe_dump(config, allow_unicode=True, sort_keys=False), encoding="utf-8") + return dest + + +def screenshot(scene: Path, name: str) -> None: + """配置確認の画像(筐体半透明・LED の向き付き)を保存する.""" + out_dir = OUTPUT_BASE / "_geometry" + out_dir.mkdir(parents=True, exist_ok=True) + subprocess.run( + [sys.executable, str(ROOT / "scripts" / "show_led_geometry.py"), + "--scene", str(scene), "--screenshot", str(out_dir / name)], + check=True, + ) + + +SUMMARY_COLUMNS = [ + "name", "note", "seed", "n_led", "mean", "structure_cov", "noise_cov", "min_fullimage", + "min_ring", "a1", "b1", "a2", "a4", "render_sec", +] + + +def run_candidate(cand: Candidate, scene: Path, seed: int) -> dict: + """seed を変えた YAML でレンダし,TEST_20 と同じ処理で指標を計算して 1 行を返す.""" + from compare_real_vs_sim_metrics import load_sim_roi, metrics_for + + from sm_tias_lightsim.evaluation.pipeline import evaluate_image + from sm_tias_lightsim.render.pipeline import render_yaml + + config = yaml.safe_load(scene.read_text(encoding="utf-8")) + config["render"]["seed"] = seed + seeded = scene.with_name(f"{scene.stem}_s{seed}.yaml") + seeded.write_text(yaml.safe_dump(config, allow_unicode=True, sort_keys=False), + encoding="utf-8") + out = OUTPUT_BASE / cand.name / f"s{seed}" + t0 = time.perf_counter() + _, npy = render_yaml(seeded, out) + sec = time.perf_counter() - t0 + evaluate_image(npy, EVAL_YAML, out, save_figures=(seed == 0)) + metrics = metrics_for(load_sim_roi(npy)) + row = {"name": cand.name, "note": cand.note, "seed": seed, "n_led": len(config["lights"]), + "render_sec": round(sec, 1)} + for key in SUMMARY_COLUMNS[4:-1]: + row[key] = metrics[key] + print(f"[render] {cand.name} s{seed}: 構造CoV={row['structure_cov']:.4f} " + f"min(全体)={row['min_fullimage']:.4f} min(輪帯)={row['min_ring']:.4f} " + f"mean={row['mean']:.4f} ({sec:.1f}s)", flush=True) + return row + + +def _parse_args(argv: list[str] | None = None) -> argparse.Namespace: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--only", nargs="+", help="実行する候補名(既定: 全部)") + parser.add_argument("--prepare-only", action="store_true", help="メッシュと YAML だけ作る") + parser.add_argument("--seeds", nargs="+", type=int, default=[0, 1, 2], + help="render.seed(ノイズフロアを見るため既定で 3 本)") + parser.add_argument("--screenshots", action="store_true", + help="YAML を作って配置確認の画像を保存する(レンダしない)") + return parser.parse_args(argv) + + +def main(argv: list[str] | None = None) -> int: + args = _parse_args(argv) + names = {c.name for c in CANDIDATES} + if args.only and (unknown := set(args.only) - names): + raise ValueError(f"未知の候補名: {sorted(unknown)}(使える名前: {sorted(names)})") + selected = [c for c in CANDIDATES if not args.only or c.name in args.only] + + scenes = {c.name: build_candidate_yaml(c) for c in selected} + for name, path in scenes.items(): + print(f"[prepare] {name}: {path.relative_to(ROOT)}") + if args.prepare_only: + return 0 + if args.screenshots: + for name, path in scenes.items(): + screenshot(path, name) + return 0 + + OUTPUT_BASE.mkdir(parents=True, exist_ok=True) + summary = OUTPUT_BASE / ("summary.csv" if not args.only else + f"summary_{'_'.join(args.only)}.csv") + with summary.open("w", newline="", encoding="utf-8") as f: + writer = csv.DictWriter(f, fieldnames=SUMMARY_COLUMNS) + writer.writeheader() + for cand in selected: + for seed in args.seeds: + writer.writerow(run_candidate(cand, scenes[cand.name], seed)) + f.flush() + print(f"[done] {summary.relative_to(ROOT)}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/uv.lock b/uv.lock index 2ca08b2..7fe2e77 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 5 +revision = 3 requires-python = ">=3.12" resolution-markers = [ "python_full_version >= '3.14' and sys_platform == 'win32'", @@ -417,6 +417,44 @@ ] [[package]] +name = "manifold3d" +version = "3.5.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "numpy" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/f3/0f/1f7e51a8f9a6f25e837159c5bf7c95a3ae948aa12e1c5fdeee0fd90ca5f9/manifold3d-3.5.4.tar.gz", hash = "sha256:5bd88c482c6fd7fc01aa7b715b3e31c2585ee98343d5559d286ba30db0d0b6f0", size = 307695, upload-time = "2026-09-25T10:46:09.083Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ad/f4/3bde89d5e37eb223ef7493b9ba782462dd8aea5af07d0370e6ce8a847186/manifold3d-3.5.4-cp312-cp312-macosx_10_14_universal2.whl", hash = "sha256:d4b47d7b0aba1ba1b575e7d549be8c9ba2d552b03e4043e3022454fdaad13447", size = 1843283, upload-time = "2026-09-25T10:45:25.725Z" }, + { url = "https://files.pythonhosted.org/packages/1f/95/3b2e63c154d3b2e70cb8e52fc72a061eaf1bc82e826c955b324381162dc7/manifold3d-3.5.4-cp312-cp312-macosx_10_14_x86_64.whl", hash = "sha256:b1ae587cf7cfa489fb50bba84a0e048d9daadd105b6a047a312e45a7602163fa", size = 1005349, upload-time = "2026-09-25T10:45:27.09Z" }, + { url = "https://files.pythonhosted.org/packages/66/28/6ec4f751be1b5868964eb92925da789c985efdaff5f0a5f85b47cbd87428/manifold3d-3.5.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d440e37d1e9888f90f42c70b4b3da98655be54105616e7739d84692bf7bda671", size = 884727, upload-time = "2026-09-25T10:45:28.554Z" }, + { url = "https://files.pythonhosted.org/packages/c3/f2/15ab84b2a80dcdc91ef53cde5fafdeb63cc3989646f17da7542011522b58/manifold3d-3.5.4-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4f4e8ca1c59d68047b262dbdb6e917ac4abff2942a65e7e469f4a398ce1f0b9b", size = 1317923, upload-time = "2026-09-25T10:45:30.034Z" }, + { url = "https://files.pythonhosted.org/packages/9e/04/91323ab10f23d185931b572622589673ec561a8106fa1ae0f2fc876fb960/manifold3d-3.5.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4a985892699268bbf07192b78b5e5569034c41ce74bf8183495123e8095af4fe", size = 1427177, upload-time = "2026-09-25T10:45:31.537Z" }, + { url = "https://files.pythonhosted.org/packages/a9/35/6b67f3af439f209b6f4ba653a5f3500f56464c99274fb4aa21323886c762/manifold3d-3.5.4-cp312-cp312-win_amd64.whl", hash = "sha256:5be1025860df8a83ed3c4fd585d87376b075e23ea45e833578fe77eacc49bee1", size = 1036128, upload-time = "2026-09-25T10:45:32.819Z" }, + { url = "https://files.pythonhosted.org/packages/79/55/aacf4b263a8bef710108cdcf1469156b53e44a63af574b435262b0e46820/manifold3d-3.5.4-cp312-cp312-win_arm64.whl", hash = "sha256:559b6cd07976a6ab3edf9806e5f1757432c397589069e01a0045e78d326ff510", size = 1145058, upload-time = "2026-09-29T05:41:55.705Z" }, + { url = "https://files.pythonhosted.org/packages/56/a7/12b1585a876eca4a1cf4985c45ce165a9c13583dd7b74f0c1f19cbf7c23e/manifold3d-3.5.4-cp313-cp313-macosx_10_14_universal2.whl", hash = "sha256:f26933565a268f91e222a494570bebe494bde204277134b3e32e0d6ac686a9ad", size = 1843251, upload-time = "2026-09-25T10:45:34.177Z" }, + { url = "https://files.pythonhosted.org/packages/b5/3b/4f030178617d1309883a857318e2764ca9ddb1080e9d9be66f326ce30286/manifold3d-3.5.4-cp313-cp313-macosx_10_14_x86_64.whl", hash = "sha256:95b512975ae13d5ecc57a9d388cf84be4cc717add5173d7d5fa408e6d6a07677", size = 1005296, upload-time = "2026-09-25T10:45:35.763Z" }, + { url = "https://files.pythonhosted.org/packages/5e/55/6f434b0b4750565ac57dd5dcd3b2770b7de408988f0d9a044bf587863e7d/manifold3d-3.5.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:ed0736f472c3362b8084867f10a724a9a483927bdb7cbfceb564acc52a7f4273", size = 884711, upload-time = "2026-09-25T10:45:37.364Z" }, + { url = "https://files.pythonhosted.org/packages/5c/91/f5ccf45874cd667005107b654390e6379a2d970ed5fe6e5989bf24f4c7d6/manifold3d-3.5.4-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8b46d2f19017fc2f3095d71cc111b8574e92afd5515d70529720324da5b1c0ed", size = 1317898, upload-time = "2026-09-25T10:45:38.768Z" }, + { url = "https://files.pythonhosted.org/packages/ac/9e/993cc841e4d88e2c8e6b1c5dfc52d4d0e8f78a46fbeaa98ff9bd539e3248/manifold3d-3.5.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7a5469641713f1bc291fea873cb134c435704df36828d134190fc2475b304259", size = 1427121, upload-time = "2026-09-25T10:45:40.199Z" }, + { url = "https://files.pythonhosted.org/packages/ea/7a/316e60dea127721fcd523210c2e6c641ab2fa5f6c957eb8a83222f0d7ee4/manifold3d-3.5.4-cp313-cp313-win_amd64.whl", hash = "sha256:76975aa4ebd18dcb0481e43dac3ed70d78066e9ad047e73a5f7dbc0df1553cf4", size = 1036021, upload-time = "2026-09-25T10:45:41.554Z" }, + { url = "https://files.pythonhosted.org/packages/d1/e7/a96928beac5287485cc0f61ac34c3b2ee42f57221d279a7d3bb176739a4d/manifold3d-3.5.4-cp313-cp313-win_arm64.whl", hash = "sha256:552ffb1f79ef77f1c7e05d638ee43e7fe88c652b1f9b042a88aab1fef85fc28c", size = 1144955, upload-time = "2026-09-29T05:41:57.75Z" }, + { url = "https://files.pythonhosted.org/packages/b8/20/86f3ec8c2481a002b378aeb28341f613eb8c10a2dec6945be7c1a4db0647/manifold3d-3.5.4-cp314-cp314-macosx_10_15_universal2.whl", hash = "sha256:7c96a28ef7ed7a34e37cad775db95831051f03ca9e188f572b0a08b3561f4763", size = 1843034, upload-time = "2026-09-25T10:45:43.258Z" }, + { url = "https://files.pythonhosted.org/packages/ce/de/f57e7aebf0092bca0a6a3435d45105043a1f902cc89289264ab68823b07e/manifold3d-3.5.4-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:487b351a9b064353c9a8cb86b9f004ec0064511d121355a0fe738e96a5ca5306", size = 1004990, upload-time = "2026-09-25T10:45:44.55Z" }, + { url = "https://files.pythonhosted.org/packages/43/83/6d168952066c22749fdc570a67ba580271057b3da9da299d9cac32e3b374/manifold3d-3.5.4-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:3d6a81f79f4812dd9e88c8093588c31c6e863c410f61a274656f9cdff76b80c0", size = 884652, upload-time = "2026-09-25T10:45:46.168Z" }, + { url = "https://files.pythonhosted.org/packages/00/cd/475da5e3d38586edd0c487e116a77896d28dfc0f90fdbf9bb1f1a64057c9/manifold3d-3.5.4-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:a7869f140b830faf93a76da3705d814b8e1652f3f68aab39351bfc6f05d93e01", size = 1319035, upload-time = "2026-09-25T10:45:47.572Z" }, + { url = "https://files.pythonhosted.org/packages/75/9f/d91de303052c3b6d851c14cc60c4ff9aabcdb4ed79e6a6122fde5c668aa9/manifold3d-3.5.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c3fc18f0712b5ff10fdc5307f9abc8a40affe3a5f8559a19b9c03e3a82e4513b", size = 1427465, upload-time = "2026-09-25T10:45:48.848Z" }, + { url = "https://files.pythonhosted.org/packages/17/a6/396f72fbcab489cb2678c066468fe2e33d7ce577351d11f948f0a7527d21/manifold3d-3.5.4-cp314-cp314-win_amd64.whl", hash = "sha256:a04a30eb686e913e1872dce6f537947d64a01c5b4a882af0be47beef2309b074", size = 1068405, upload-time = "2026-09-25T10:45:50.573Z" }, + { url = "https://files.pythonhosted.org/packages/aa/e8/f6751f97187a8e7fddc446ac5d73f5000cf4dcc033dec5683fea3fe906ff/manifold3d-3.5.4-cp314-cp314-win_arm64.whl", hash = "sha256:8c309c698837fdbca297ad7387f5348526e6635e49ce28476e2c9dcad30a947e", size = 1181481, upload-time = "2026-09-29T05:41:59.352Z" }, + { url = "https://files.pythonhosted.org/packages/93/00/5f7651472bab7378cc57b6a15edba155d056542b4c0c117b743f5cdc8a44/manifold3d-3.5.4-cp314-cp314t-macosx_10_15_universal2.whl", hash = "sha256:ee967a8f1b526194ea8a598e04d2fd6920a9a78e9d465a7b78e2a6827585b8f3", size = 1853599, upload-time = "2026-09-25T10:45:51.941Z" }, + { url = "https://files.pythonhosted.org/packages/f8/b4/63fa966d1138716a78c4e856c7846088f74a6797cc18346e6dbc8601f82f/manifold3d-3.5.4-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:a55945fccc1ad20c958bedf61397a12ea5329f897a29f2237c70e12bdf7bd51d", size = 1011076, upload-time = "2026-09-25T10:45:53.499Z" }, + { url = "https://files.pythonhosted.org/packages/28/2f/e200a5f4204d935435df2c6d58b35da8f2bfaaab61839365b2c1bac614e9/manifold3d-3.5.4-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:5284a8a14fc86798d1698b37729e519516ba6c0574624ae16542032764adf189", size = 890394, upload-time = "2026-09-25T10:45:55.033Z" }, + { url = "https://files.pythonhosted.org/packages/19/8d/3856eefc139ab1f18e928abcc4531515e75d4a43db31a6180583c33d90f0/manifold3d-3.5.4-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:fd68576b104f563a8d2a9629f7de565c5ac704f276394f9ffdb9f0c5a05c20d8", size = 1326941, upload-time = "2026-09-25T10:45:56.43Z" }, + { url = "https://files.pythonhosted.org/packages/0f/24/8c9d993e89cf758c3dbbd4470dcf3efc5efef11dcd8f89e208539fd11b21/manifold3d-3.5.4-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ae80814e5c6f85f4c53f632b71009fdfa185645a1d68c673d0d7a6171c29f78b", size = 1433600, upload-time = "2026-09-25T10:45:57.904Z" }, + { url = "https://files.pythonhosted.org/packages/9e/f0/fac6f8eaff4617eeab741c87bfae8a6afd1057648b0551f206c4247b0407/manifold3d-3.5.4-cp314-cp314t-win_amd64.whl", hash = "sha256:d034b1d74df1aad9377f30b2228c33b3887bf5057c7efd98a86892604edd86aa", size = 1070681, upload-time = "2026-09-25T10:45:59.412Z" }, +] + +[[package]] name = "markdown-it-py" version = "4.0.0" source = { registry = "https://pypi.org/simple" } @@ -1220,6 +1258,7 @@ [package.dev-dependencies] dev = [ + { name = "manifold3d" }, { name = "pytest" }, { name = "ruff" }, ] @@ -1243,6 +1282,7 @@ [package.metadata.requires-dev] dev = [ + { name = "manifold3d", specifier = ">=3.5.4" }, { name = "pytest", specifier = ">=9.0.3" }, { name = "ruff", specifier = ">=0.15.12" }, ]