vibedgames 0.10.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/rebuild-object/.cache/spec-search/core_3d.json +1 -0
- package/assets/rebuild-object/.cache/spec-search/cs2.json +1 -0
- package/assets/rebuild-object/LICENSE +201 -0
- package/assets/rebuild-object/NOTICE +7 -0
- package/assets/rebuild-object/docs/materials/material-reference.json +2324 -0
- package/assets/rebuild-object/docs/specs/render-profile.v2.example.json +63 -0
- package/assets/rebuild-object/docs/specs/render-profile.v2.schema.json +56 -0
- package/assets/rebuild-object/docs/specs/vocabulary/README.md +86 -0
- package/assets/rebuild-object/docs/specs/vocabulary/core_3d.jsonl +12 -0
- package/assets/rebuild-object/docs/specs/vocabulary/core_3d_reconstruction.jsonl +37 -0
- package/assets/rebuild-object/docs/specs/vocabulary/cs2.jsonl +8 -0
- package/assets/rebuild-object/docs/specs/vocabulary/cs2_reconstruction.jsonl +62 -0
- package/assets/rebuild-object/forge/_shared/artifact_cache.py +54 -0
- package/assets/rebuild-object/forge/_shared/chirality.py +272 -0
- package/assets/rebuild-object/forge/_shared/color_metrics.py +107 -0
- package/assets/rebuild-object/forge/_shared/feature_acceptance_policy.py +113 -0
- package/assets/rebuild-object/forge/_shared/image_hash.py +113 -0
- package/assets/rebuild-object/forge/_shared/jpeg.py +448 -0
- package/assets/rebuild-object/forge/_shared/material_physics.py +253 -0
- package/assets/rebuild-object/forge/_shared/pipeline_routing.py +177 -0
- package/assets/rebuild-object/forge/_shared/scalp_field.py +302 -0
- package/assets/rebuild-object/forge/_shared/sdf_primitives.py +172 -0
- package/assets/rebuild-object/forge/_shared/spec_search.py +1792 -0
- package/assets/rebuild-object/forge/_shared/spec_search_profiles.json +58 -0
- package/assets/rebuild-object/forge/_shared/status_banner.py +35 -0
- package/assets/rebuild-object/forge/_shared/subdivision.py +232 -0
- package/assets/rebuild-object/forge/_shared/vertex_paint.py +236 -0
- package/assets/rebuild-object/forge/_shared/workflow_state.py +406 -0
- package/assets/rebuild-object/forge/materials/__init__.py +17 -0
- package/assets/rebuild-object/forge/materials/compatibility.py +106 -0
- package/assets/rebuild-object/forge/materials/reference.py +240 -0
- package/assets/rebuild-object/forge/next.py +116 -0
- package/assets/rebuild-object/forge/report.py +38 -0
- package/assets/rebuild-object/forge/requirements.txt +6 -0
- package/assets/rebuild-object/forge/stage1_intake/analyze_texture.py +255 -0
- package/assets/rebuild-object/forge/stage1_intake/bind_detail_properties.py +99 -0
- package/assets/rebuild-object/forge/stage1_intake/build_detail_inventory.py +349 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_fitting_math.py +133 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_fitting_solver.py +197 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_fitting_types.py +291 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_image_helpers.py +133 -0
- package/assets/rebuild-object/forge/stage1_intake/check_intake_correctness.py +116 -0
- package/assets/rebuild-object/forge/stage1_intake/check_reference_admission.py +203 -0
- package/assets/rebuild-object/forge/stage1_intake/cs2_foundation.py +139 -0
- package/assets/rebuild-object/forge/stage1_intake/cs2_manifest.py +230 -0
- package/assets/rebuild-object/forge/stage1_intake/cs2_review_contract.py +42 -0
- package/assets/rebuild-object/forge/stage1_intake/delight_albedo.py +352 -0
- package/assets/rebuild-object/forge/stage1_intake/detect_cs2.py +276 -0
- package/assets/rebuild-object/forge/stage1_intake/detect_reference_effects.py +275 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_cs2_textures.py +126 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_gradient_stops.py +149 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_hair_evidence.py +385 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_landmarks.py +456 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_part_color_recipe.py +496 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_pbr_evidence.py +843 -0
- package/assets/rebuild-object/forge/stage1_intake/fetch_cs2_metadata.py +147 -0
- package/assets/rebuild-object/forge/stage1_intake/label_glb_nodes.py +318 -0
- package/assets/rebuild-object/forge/stage1_intake/locate_cs2_vpk.py +73 -0
- package/assets/rebuild-object/forge/stage1_intake/material_region_analysis.py +227 -0
- package/assets/rebuild-object/forge/stage1_intake/probe_glb.py +357 -0
- package/assets/rebuild-object/forge/stage1_intake/probe_image.py +168 -0
- package/assets/rebuild-object/forge/stage1_intake/run_vision_adapter.py +45 -0
- package/assets/rebuild-object/forge/stage1_intake/search_specs.py +258 -0
- package/assets/rebuild-object/forge/stage1_intake/semantic_decomposition.py +119 -0
- package/assets/rebuild-object/forge/stage1_intake/solve_camera_pose.py +254 -0
- package/assets/rebuild-object/forge/stage2_spec/apply_material_analysis.py +192 -0
- package/assets/rebuild-object/forge/stage2_spec/cs2_adapters.py +62 -0
- package/assets/rebuild-object/forge/stage2_spec/derive_geometry.py +118 -0
- package/assets/rebuild-object/forge/stage2_spec/hair_profile.py +306 -0
- package/assets/rebuild-object/forge/stage2_spec/humanoid_proportions.py +214 -0
- package/assets/rebuild-object/forge/stage2_spec/new_pre_spec_assessment.py +343 -0
- package/assets/rebuild-object/forge/stage2_spec/new_sculpt_spec.py +2396 -0
- package/assets/rebuild-object/forge/stage2_spec/validate_sculpt_spec.py +2871 -0
- package/assets/rebuild-object/forge/stage3_build/bake_projected_texture.py +181 -0
- package/assets/rebuild-object/forge/stage3_build/decimate.py +272 -0
- package/assets/rebuild-object/forge/stage3_build/generate_threejs_factory.py +4099 -0
- package/assets/rebuild-object/forge/stage3_build/module_cache.py +155 -0
- package/assets/rebuild-object/forge/stage3_build/morph_targets.py +178 -0
- package/assets/rebuild-object/forge/stage3_build/orchestrate_passes.py +653 -0
- package/assets/rebuild-object/forge/stage3_build/uv_unwrap.py +622 -0
- package/assets/rebuild-object/forge/stage3_build/visual_hull.py +357 -0
- package/assets/rebuild-object/forge/stage4_review/_fit_divine_eye.py +64 -0
- package/assets/rebuild-object/forge/stage4_review/append_review.py +453 -0
- package/assets/rebuild-object/forge/stage4_review/attachment_anchor.py +349 -0
- package/assets/rebuild-object/forge/stage4_review/calibrate_eye.py +131 -0
- package/assets/rebuild-object/forge/stage4_review/check_part_coverage.py +298 -0
- package/assets/rebuild-object/forge/stage4_review/compare_region_passes.py +169 -0
- package/assets/rebuild-object/forge/stage4_review/correction_loop.py +258 -0
- package/assets/rebuild-object/forge/stage4_review/cs2_review.py +224 -0
- package/assets/rebuild-object/forge/stage4_review/diagnose_render.py +356 -0
- package/assets/rebuild-object/forge/stage4_review/diagnose_render_multi_angle.py +143 -0
- package/assets/rebuild-object/forge/stage4_review/divine_eye.py +461 -0
- package/assets/rebuild-object/forge/stage4_review/fit_params.py +381 -0
- package/assets/rebuild-object/forge/stage4_review/geometry_integrity.py +294 -0
- package/assets/rebuild-object/forge/stage4_review/hair_gate.py +216 -0
- package/assets/rebuild-object/forge/stage4_review/interior_difference.py +188 -0
- package/assets/rebuild-object/forge/stage4_review/joint_loops.py +209 -0
- package/assets/rebuild-object/forge/stage4_review/make_comparison_sheet.py +292 -0
- package/assets/rebuild-object/forge/stage4_review/material_comparator.py +181 -0
- package/assets/rebuild-object/forge/stage4_review/material_feedback.py +143 -0
- package/assets/rebuild-object/forge/stage4_review/material_gate.py +126 -0
- package/assets/rebuild-object/forge/stage4_review/material_views.py +184 -0
- package/assets/rebuild-object/forge/stage4_review/mesh_reference_compare.py +362 -0
- package/assets/rebuild-object/forge/stage4_review/multi_pass.py +102 -0
- package/assets/rebuild-object/forge/stage4_review/objectness.py +143 -0
- package/assets/rebuild-object/forge/stage4_review/pairwise_penetration.py +376 -0
- package/assets/rebuild-object/forge/stage4_review/per_feature.py +215 -0
- package/assets/rebuild-object/forge/stage4_review/render_bridge.py +556 -0
- package/assets/rebuild-object/forge/stage4_review/scalp_exposure.py +257 -0
- package/assets/rebuild-object/forge/stage4_review/self_intersection.py +592 -0
- package/assets/rebuild-object/forge/stage4_review/swept_arc_gate.py +336 -0
- package/assets/rebuild-object/forge/stage4_review/turntable_gate.py +415 -0
- package/assets/rebuild-object/forge/stage4_review/validate_render_profile.py +182 -0
- package/assets/rebuild-object/forge/stage4_review/vertex_region_gate.py +456 -0
- package/assets/rebuild-object/forge/stage4_review/vlm_gate.py +196 -0
- package/assets/rebuild-object/forge/stage5_rig/NOTES.md +149 -0
- package/assets/rebuild-object/forge/stage5_rig/__init__.py +6 -0
- package/assets/rebuild-object/forge/stage5_rig/emit_rig.py +420 -0
- package/assets/rebuild-object/forge/stage5_rig/geodesic_skinning.py +508 -0
- package/assets/rebuild-object/forge/stage5_rig/rig_spec.py +174 -0
- package/assets/rebuild-object/forge/stage5_rig/validate_rig_payload.py +195 -0
- package/assets/rebuild-object/forge/state.py +98 -0
- package/assets/rebuild-object/steps.json +381 -0
- package/dist/{chunk-FXXVXDTW.js → chunk-24TITAFS.js} +1 -1
- package/dist/{chunk-OGX4DKIS.js → chunk-2C5PG2QO.js} +1 -1
- package/dist/{chunk-HYOXGNWS.js → chunk-2DEVOKI7.js} +1 -1
- package/dist/{chunk-RRI23NK2.js → chunk-2GHPYT2P.js} +1 -1
- package/dist/{chunk-S7HYWITX.js → chunk-2HXGMXGC.js} +1 -1
- package/dist/{chunk-N2UHAQXC.js → chunk-36FORP7T.js} +0 -1
- package/dist/{chunk-VB4WLJR2.js → chunk-3IXRQTRF.js} +1 -1
- package/dist/{chunk-2KVQJKIZ.js → chunk-4ENHS32B.js} +23 -36
- package/dist/{chunk-SXYQL4GK.js → chunk-4YHA32OE.js} +1 -1
- package/dist/{chunk-4FJXCS3K.js → chunk-4ZGQKPK5.js} +1 -1
- package/dist/{chunk-SBXCK2I2.js → chunk-6CLUPFQA.js} +2 -2
- package/dist/{chunk-TXOE5UY5.js → chunk-7WTF2BA4.js} +1 -1
- package/dist/{chunk-R2WVORGD.js → chunk-AAXZNK4Z.js} +1 -1
- package/dist/{chunk-DOOQUFPG.js → chunk-ALLBT4FB.js} +1 -1
- package/dist/{chunk-HRKVAXNN.js → chunk-BAZDPPIG.js} +5 -5
- package/dist/{chunk-RPJR3S5S.js → chunk-CYDENLZ4.js} +5 -8
- package/dist/{chunk-I5LELJSK.js → chunk-DKSUD44G.js} +1 -1
- package/dist/{chunk-43P4U7CB.js → chunk-DWWSJKTE.js} +1 -1
- package/dist/{chunk-SUSX3QIA.js → chunk-E72TFJZP.js} +1 -1
- package/dist/{chunk-E3FJUPLT.js → chunk-EUAAQMUA.js} +2 -0
- package/dist/{chunk-U6DTE5IX.js → chunk-F7LYJSZE.js} +1 -1
- package/dist/{chunk-MEAO33XW.js → chunk-FMON3C74.js} +8 -8
- package/dist/{chunk-GLEW7VJQ.js → chunk-FPILHRLZ.js} +1 -1
- package/dist/{chunk-OPUCUUID.js → chunk-G63MXDX2.js} +4 -0
- package/dist/{chunk-4UU622RK.js → chunk-GGO6ZYYI.js} +1 -3
- package/dist/{chunk-2ZKS7V72.js → chunk-GZCRYYS6.js} +5 -5
- package/dist/{chunk-E7NDOZ27.js → chunk-LE4GVTYI.js} +8 -8
- package/dist/{chunk-RKS7SI5L.js → chunk-NO6KPV64.js} +1 -1
- package/dist/{chunk-KJK5CB6E.js → chunk-NXW3Z4Y4.js} +1 -1
- package/dist/{chunk-7RPLQWR2.js → chunk-OHOAZGO4.js} +1 -1
- package/dist/chunk-PYJNI5WD.js +83 -0
- package/dist/{chunk-NCX6LYNJ.js → chunk-Q4XAGTFX.js} +1 -1
- package/dist/{chunk-3UGGMFJJ.js → chunk-QMZBSVKF.js} +1 -1
- package/dist/{chunk-ABTUEIRC.js → chunk-QO66UBOS.js} +2 -2
- package/dist/{chunk-LONQWRTR.js → chunk-S4KVGQQO.js} +8 -8
- package/dist/{chunk-HX5Q63UA.js → chunk-T777EXAO.js} +1 -1
- package/dist/{chunk-UQ7VO6B3.js → chunk-TZZNRA3S.js} +1 -1
- package/dist/{chunk-CTY2WZQK.js → chunk-UC3QLWMQ.js} +1 -1
- package/dist/{chunk-MR5KIFI7.js → chunk-UDJH2RED.js} +3 -3
- package/dist/{chunk-ZHLPE6LI.js → chunk-UIKYK7KI.js} +1 -1
- package/dist/{chunk-KAGVI3CE.js → chunk-UJRSQO2B.js} +1 -1
- package/dist/{chunk-Q2QC6KAZ.js → chunk-V7LEYVXB.js} +29 -25
- package/dist/{chunk-DB7WVFS7.js → chunk-WRMQEXUC.js} +1 -1
- package/dist/{chunk-HSMG6U7J.js → chunk-WXSBNC67.js} +3 -9
- package/dist/{chunk-QLCVLCPM.js → chunk-X4QIOXNQ.js} +1 -1
- package/dist/{chunk-5YPLKGY3.js → chunk-Y6WHUK2O.js} +1 -1
- package/dist/{chunk-VZEJ2ZHE.js → chunk-Z3E7ORGQ.js} +5 -5
- package/dist/index.js +20 -20
- package/package.json +32 -22
- package/dist/{chunk-Q3XQPNF6.js → chunk-BN7TR6OR.js} +3 -3
- package/dist/{chunk-LORGE2NB.js → chunk-U2NCN5RO.js} +3 -3
- package/dist/{chunk-UPHB5HWO.js → chunk-VQTTSPA3.js} +3 -3
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Detail → PBR/geometry property auto-binding (Plan 1.3 Workstream J).
|
|
3
|
+
|
|
4
|
+
Standardized intake: turn a plain-language detail/material observation into concrete
|
|
5
|
+
Three.js material properties + geometry/primitive hints, so a vague one-line prompt
|
|
6
|
+
still produces a rigorous quality contract instead of "make it shiny". Deterministic
|
|
7
|
+
keyword mapping — no model, no token. The bound properties are exactly the ones the
|
|
8
|
+
full property surface (Workstream H) can emit.
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
bind("glossy jade blade with internal smoke") ->
|
|
12
|
+
{materialProperties, primitiveHint, note}
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
import json
|
|
19
|
+
import re
|
|
20
|
+
import sys
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
# Each rule: (name, keyword-regex, material-properties dict, primitive hint or None, note).
|
|
24
|
+
# Ordered most-specific first; all matching rules contribute (union of properties).
|
|
25
|
+
_RULES: list[tuple[str, str, dict[str, Any], str | None, str]] = [
|
|
26
|
+
("gemstone/glass", r"jade|gem|glass|crystal|translucent|transparent|amber|resin",
|
|
27
|
+
{"transmission": 0.6, "ior": 1.6, "thickness": 0.5, "roughness": 0.1, "requiresEnvMap": True},
|
|
28
|
+
None, "translucent → transmission+ior+thickness; needs an environment map to read correctly"),
|
|
29
|
+
("brushed-metal", r"brushed|anisotropic|satin metal|machined",
|
|
30
|
+
{"metalness": 1.0, "roughness": 0.35, "anisotropy": 0.6, "anisotropyRotation": 0.0, "requiresEnvMap": True},
|
|
31
|
+
None, "brushed metal → anisotropy for the directional highlight streak"),
|
|
32
|
+
("metal", r"metal|steel|chrome|gold|silver|brass|copper|iron|alumin",
|
|
33
|
+
{"metalness": 1.0, "roughness": 0.3, "requiresEnvMap": True},
|
|
34
|
+
None, "metal → metalness 1 + low roughness + env map"),
|
|
35
|
+
("glossy-coat", r"gloss|glossy|lacquer|wet look|polished paint|clear ?coat|enamel|varnish",
|
|
36
|
+
{"clearcoat": 1.0, "clearcoatRoughness": 0.1, "requiresEnvMap": True},
|
|
37
|
+
None, "glossy paint → clearcoat 1.0 + low clearcoatRoughness"),
|
|
38
|
+
("iridescent", r"iridescen|oil ?slick|soap|pearlescent|nacre|holograph",
|
|
39
|
+
{"iridescence": 1.0, "iridescenceIOR": 1.3, "requiresEnvMap": True},
|
|
40
|
+
None, "iridescent → iridescence + iridescenceIOR"),
|
|
41
|
+
("fabric", r"fabric|cloth|velvet|suede|felt|textile|woven|denim|cotton",
|
|
42
|
+
{"sheen": 1.0, "sheenColor": "#ffffff", "sheenRoughness": 0.5, "metalness": 0.0, "roughness": 0.85},
|
|
43
|
+
None, "fabric → sheen for the soft grazing-angle retroreflection"),
|
|
44
|
+
("emissive", r"emissive|glow|glowing|led|neon|luminous|backlit|screen|display",
|
|
45
|
+
{"emissive": "#ffffff", "emissiveIntensity": 1.0},
|
|
46
|
+
None, "emissive/glowing → emissive + emissiveIntensity"),
|
|
47
|
+
("rubber/matte", r"rubber|matte plastic|matte|grip|polymer|abs plastic",
|
|
48
|
+
{"metalness": 0.0, "roughness": 0.8},
|
|
49
|
+
None, "matte polymer → high roughness, non-metal"),
|
|
50
|
+
("fastener", r"screw|rivet|bolt|stud|fastener|nut|nail|grommet|eyelet",
|
|
51
|
+
{},
|
|
52
|
+
"instanced-cluster", "repeated fasteners → instancing (InstancedMesh), not N meshes"),
|
|
53
|
+
("decal", r"logo|emblem|stamp|decal|marking|engrav|wordmark|serial|inscription|label",
|
|
54
|
+
{},
|
|
55
|
+
"decal", "flat marking → DecalGeometry stamped onto the surface"),
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def bind(description: str) -> dict[str, Any]:
|
|
60
|
+
"""Bind a free-text detail description to concrete properties + a primitive hint."""
|
|
61
|
+
text = (description or "").lower()
|
|
62
|
+
props: dict[str, Any] = {}
|
|
63
|
+
notes: list[str] = []
|
|
64
|
+
primitive_hint: str | None = None
|
|
65
|
+
matched: list[str] = []
|
|
66
|
+
for name, pattern, rule_props, hint, note in _RULES:
|
|
67
|
+
if re.search(pattern, text):
|
|
68
|
+
matched.append(name)
|
|
69
|
+
for k, v in rule_props.items():
|
|
70
|
+
props.setdefault(k, v) # first (most-specific) rule wins on conflict
|
|
71
|
+
if hint and primitive_hint is None:
|
|
72
|
+
primitive_hint = hint
|
|
73
|
+
notes.append(note)
|
|
74
|
+
return {
|
|
75
|
+
"matchedRules": matched,
|
|
76
|
+
"materialProperties": props,
|
|
77
|
+
"primitiveHint": primitive_hint,
|
|
78
|
+
"notes": notes,
|
|
79
|
+
"bound": bool(matched),
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def main(argv: list[str]) -> int:
|
|
84
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
85
|
+
parser.add_argument("description", help="free-text detail/material description")
|
|
86
|
+
parser.add_argument("--json", action="store_true")
|
|
87
|
+
args = parser.parse_args(argv)
|
|
88
|
+
result = bind(args.description)
|
|
89
|
+
if args.json:
|
|
90
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
91
|
+
else:
|
|
92
|
+
print(f"matched: {', '.join(result['matchedRules']) or '(none)'}")
|
|
93
|
+
print(f"properties: {result['materialProperties']}")
|
|
94
|
+
print(f"primitiveHint: {result['primitiveHint']}")
|
|
95
|
+
return 0
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Slice a reference image into inspection zones and scaffold a detailInventory to fill in.
|
|
3
|
+
|
|
4
|
+
Scans the reference zone by zone (a uniform grid, or named component regions) so small
|
|
5
|
+
identity-defining marks are not missed by a single glance at the whole image. Writes one
|
|
6
|
+
crop PNG per zone plus a detailInventory skeleton JSON (see docs/UPGRADE_PLAN.md 4.1 and
|
|
7
|
+
grimoire/intake/detail_inventory.md) with one detail stub per zone for the agent to classify,
|
|
8
|
+
describe, and link to a component/material field. This script only scaffolds zones and
|
|
9
|
+
crops; it does not judge what is in them.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import json
|
|
16
|
+
import shutil
|
|
17
|
+
import struct
|
|
18
|
+
import subprocess
|
|
19
|
+
import sys
|
|
20
|
+
import tempfile
|
|
21
|
+
import zlib
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "_shared"))
|
|
25
|
+
from jpeg import UnsupportedJpeg, decode_jpeg, is_jpeg # noqa: E402
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
PNG_SIGNATURE = b"\x89PNG\r\n\x1a\n"
|
|
29
|
+
|
|
30
|
+
TARGET_MIN_DETAILS = {
|
|
31
|
+
"simple": 3,
|
|
32
|
+
"moderate": 6,
|
|
33
|
+
"complex": 10,
|
|
34
|
+
"ultra-complex": 16,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# These thirds are a DEFAULT, not a limit -- `component-zones` mode with --components takes any named
|
|
38
|
+
# normalized regions, so an arbitrary per-feature ROI is already expressible. What is genuinely absent
|
|
39
|
+
# is automatic detection and scoring of details: nothing here finds a tear, only describes where to
|
|
40
|
+
# look. See grimoire/review/divine_eye_microscope.md for the feature-descriptor schema.
|
|
41
|
+
DEFAULT_COMPONENT_ZONES = [
|
|
42
|
+
("upper", 0.0, 0.0, 1.0, 1.0 / 3),
|
|
43
|
+
("middle", 0.0, 1.0 / 3, 1.0, 1.0 / 3),
|
|
44
|
+
("lower", 0.0, 2.0 / 3, 1.0, 1.0 / 3),
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def paeth_predictor(a: int, b: int, c: int) -> int:
|
|
49
|
+
p = a + b - c
|
|
50
|
+
pa = abs(p - a)
|
|
51
|
+
pb = abs(p - b)
|
|
52
|
+
pc = abs(p - c)
|
|
53
|
+
if pa <= pb and pa <= pc:
|
|
54
|
+
return a
|
|
55
|
+
if pb <= pc:
|
|
56
|
+
return b
|
|
57
|
+
return c
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def read_png(path: Path) -> tuple[int, int, list[tuple[int, int, int, int]]]:
|
|
61
|
+
data = path.read_bytes()
|
|
62
|
+
if not data.startswith(PNG_SIGNATURE):
|
|
63
|
+
raise ValueError("not a PNG file")
|
|
64
|
+
cursor = len(PNG_SIGNATURE)
|
|
65
|
+
width = height = bit_depth = color_type = interlace = None
|
|
66
|
+
idat = bytearray()
|
|
67
|
+
while cursor + 8 <= len(data):
|
|
68
|
+
length = struct.unpack(">I", data[cursor : cursor + 4])[0]
|
|
69
|
+
chunk_type = data[cursor + 4 : cursor + 8]
|
|
70
|
+
chunk_data = data[cursor + 8 : cursor + 8 + length]
|
|
71
|
+
cursor += 12 + length
|
|
72
|
+
if chunk_type == b"IHDR":
|
|
73
|
+
width, height, bit_depth, color_type, _, _, interlace = struct.unpack(">IIBBBBB", chunk_data)
|
|
74
|
+
elif chunk_type == b"IDAT":
|
|
75
|
+
idat.extend(chunk_data)
|
|
76
|
+
elif chunk_type == b"IEND":
|
|
77
|
+
break
|
|
78
|
+
if width is None or height is None or bit_depth != 8 or interlace != 0:
|
|
79
|
+
raise ValueError("unsupported PNG; expected 8-bit non-interlaced image")
|
|
80
|
+
channels_by_type = {0: 1, 2: 3, 4: 2, 6: 4}
|
|
81
|
+
if color_type not in channels_by_type:
|
|
82
|
+
raise ValueError("unsupported PNG color type; convert to RGB/RGBA first")
|
|
83
|
+
channels = channels_by_type[color_type]
|
|
84
|
+
row_bytes = width * channels
|
|
85
|
+
raw = zlib.decompress(bytes(idat))
|
|
86
|
+
rows: list[bytearray] = []
|
|
87
|
+
offset = 0
|
|
88
|
+
previous = bytearray(row_bytes)
|
|
89
|
+
for _ in range(height):
|
|
90
|
+
filter_type = raw[offset]
|
|
91
|
+
offset += 1
|
|
92
|
+
row = bytearray(raw[offset : offset + row_bytes])
|
|
93
|
+
offset += row_bytes
|
|
94
|
+
for index in range(row_bytes):
|
|
95
|
+
left = row[index - channels] if index >= channels else 0
|
|
96
|
+
up = previous[index]
|
|
97
|
+
up_left = previous[index - channels] if index >= channels else 0
|
|
98
|
+
if filter_type == 1:
|
|
99
|
+
row[index] = (row[index] + left) & 0xFF
|
|
100
|
+
elif filter_type == 2:
|
|
101
|
+
row[index] = (row[index] + up) & 0xFF
|
|
102
|
+
elif filter_type == 3:
|
|
103
|
+
row[index] = (row[index] + ((left + up) // 2)) & 0xFF
|
|
104
|
+
elif filter_type == 4:
|
|
105
|
+
row[index] = (row[index] + paeth_predictor(left, up, up_left)) & 0xFF
|
|
106
|
+
elif filter_type != 0:
|
|
107
|
+
raise ValueError(f"unsupported PNG filter {filter_type}")
|
|
108
|
+
rows.append(row)
|
|
109
|
+
previous = row
|
|
110
|
+
pixels: list[tuple[int, int, int, int]] = []
|
|
111
|
+
for row in rows:
|
|
112
|
+
for x in range(width):
|
|
113
|
+
base = x * channels
|
|
114
|
+
if color_type == 0:
|
|
115
|
+
gray = row[base]
|
|
116
|
+
pixels.append((gray, gray, gray, 255))
|
|
117
|
+
elif color_type == 2:
|
|
118
|
+
pixels.append((row[base], row[base + 1], row[base + 2], 255))
|
|
119
|
+
elif color_type == 4:
|
|
120
|
+
gray = row[base]
|
|
121
|
+
pixels.append((gray, gray, gray, row[base + 1]))
|
|
122
|
+
elif color_type == 6:
|
|
123
|
+
pixels.append((row[base], row[base + 1], row[base + 2], row[base + 3]))
|
|
124
|
+
return width, height, pixels
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def write_png_rgb(path: Path, width: int, height: int, pixels: list[tuple[int, int, int]]) -> None:
|
|
128
|
+
if len(pixels) != width * height:
|
|
129
|
+
raise ValueError("pixel payload has the wrong size")
|
|
130
|
+
|
|
131
|
+
def chunk(kind: bytes, payload: bytes) -> bytes:
|
|
132
|
+
checksum = zlib.crc32(kind)
|
|
133
|
+
checksum = zlib.crc32(payload, checksum) & 0xFFFFFFFF
|
|
134
|
+
return struct.pack(">I", len(payload)) + kind + payload + struct.pack(">I", checksum)
|
|
135
|
+
|
|
136
|
+
scanlines = bytearray()
|
|
137
|
+
for y in range(height):
|
|
138
|
+
scanlines.append(0)
|
|
139
|
+
for red, green, blue in pixels[y * width : (y + 1) * width]:
|
|
140
|
+
scanlines.extend((red, green, blue))
|
|
141
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
142
|
+
path.write_bytes(
|
|
143
|
+
PNG_SIGNATURE
|
|
144
|
+
+ chunk(b"IHDR", struct.pack(">IIBBBBB", width, height, 8, 2, 0, 0, 0))
|
|
145
|
+
+ chunk(b"IDAT", zlib.compress(bytes(scanlines), level=6))
|
|
146
|
+
+ chunk(b"IEND", b"")
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def load_image(path: Path) -> tuple[int, int, list[tuple[int, int, int, int]]]:
|
|
151
|
+
try:
|
|
152
|
+
return read_png(path)
|
|
153
|
+
except Exception as direct_error:
|
|
154
|
+
jpeg_bytes = path.read_bytes()
|
|
155
|
+
if is_jpeg(jpeg_bytes):
|
|
156
|
+
try:
|
|
157
|
+
return decode_jpeg(jpeg_bytes)[:3]
|
|
158
|
+
except UnsupportedJpeg:
|
|
159
|
+
pass
|
|
160
|
+
sips = shutil.which("sips")
|
|
161
|
+
if not sips:
|
|
162
|
+
raise ValueError(f"could not decode {path.name} as PNG and sips is unavailable: {direct_error}") from direct_error
|
|
163
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
164
|
+
converted = Path(tmpdir) / "converted.png"
|
|
165
|
+
result = subprocess.run(
|
|
166
|
+
[sips, "-s", "format", "png", str(path), "--out", str(converted)],
|
|
167
|
+
capture_output=True,
|
|
168
|
+
text=True,
|
|
169
|
+
check=False,
|
|
170
|
+
)
|
|
171
|
+
if result.returncode != 0:
|
|
172
|
+
raise ValueError(result.stderr.strip() or result.stdout.strip() or "sips conversion failed")
|
|
173
|
+
return read_png(converted)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def composite_over_white(pixel: tuple[int, int, int, int]) -> tuple[int, int, int]:
|
|
177
|
+
red, green, blue, alpha = pixel
|
|
178
|
+
mix = alpha / 255.0
|
|
179
|
+
return (
|
|
180
|
+
round(red * mix + 255 * (1 - mix)),
|
|
181
|
+
round(green * mix + 255 * (1 - mix)),
|
|
182
|
+
round(blue * mix + 255 * (1 - mix)),
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def parse_components(spec: str) -> list[tuple[str, float, float, float, float]]:
|
|
187
|
+
zones: list[tuple[str, float, float, float, float]] = []
|
|
188
|
+
for part in spec.split(";"):
|
|
189
|
+
part = part.strip()
|
|
190
|
+
if not part:
|
|
191
|
+
continue
|
|
192
|
+
name, sep, coords = part.partition(":")
|
|
193
|
+
if not sep:
|
|
194
|
+
raise ValueError(f"malformed --components entry (expected name:x,y,w,h): {part!r}")
|
|
195
|
+
values = [float(v) for v in coords.split(",")]
|
|
196
|
+
if len(values) != 4:
|
|
197
|
+
raise ValueError(f"malformed --components entry (expected 4 normalized values): {part!r}")
|
|
198
|
+
x, y, w, h = values
|
|
199
|
+
zones.append((name.strip(), x, y, w, h))
|
|
200
|
+
if not zones:
|
|
201
|
+
raise ValueError("--components produced no zones")
|
|
202
|
+
return zones
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def build_zones(mode: str, components_spec: str | None) -> list[dict]:
|
|
206
|
+
if mode == "component-zones":
|
|
207
|
+
zones_spec = parse_components(components_spec) if components_spec else DEFAULT_COMPONENT_ZONES
|
|
208
|
+
return [
|
|
209
|
+
{"id": name, "region": {"x": x, "y": y, "width": w, "height": h, "units": "normalized"}}
|
|
210
|
+
for name, x, y, w, h in zones_spec
|
|
211
|
+
]
|
|
212
|
+
grid = 3 if mode == "grid-3x3" else 4
|
|
213
|
+
step = 1.0 / grid
|
|
214
|
+
zones = []
|
|
215
|
+
for row in range(grid):
|
|
216
|
+
for col in range(grid):
|
|
217
|
+
zones.append(
|
|
218
|
+
{
|
|
219
|
+
"id": f"zone-r{row}c{col}",
|
|
220
|
+
"region": {
|
|
221
|
+
"x": round(col * step, 4),
|
|
222
|
+
"y": round(row * step, 4),
|
|
223
|
+
"width": round(step, 4),
|
|
224
|
+
"height": round(step, 4),
|
|
225
|
+
"units": "normalized",
|
|
226
|
+
},
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
return zones
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def make_detail_stub(zone: dict, crop_path: Path) -> dict:
|
|
233
|
+
return {
|
|
234
|
+
"id": zone["id"],
|
|
235
|
+
"kind": "",
|
|
236
|
+
"description": "",
|
|
237
|
+
"region": zone["region"],
|
|
238
|
+
"scale": "",
|
|
239
|
+
"affects": "",
|
|
240
|
+
"mapsTo": {"type": "", "ref": ""},
|
|
241
|
+
"evidenceRef": str(crop_path),
|
|
242
|
+
"confidence": 0.0,
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def build_inventory(
|
|
247
|
+
image: Path,
|
|
248
|
+
mode: str,
|
|
249
|
+
out_dir: Path,
|
|
250
|
+
target_min_details: int,
|
|
251
|
+
components_spec: str | None,
|
|
252
|
+
) -> dict:
|
|
253
|
+
width, height, pixels = load_image(image)
|
|
254
|
+
zones = build_zones(mode, components_spec)
|
|
255
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
256
|
+
details = []
|
|
257
|
+
for zone in zones:
|
|
258
|
+
region = zone["region"]
|
|
259
|
+
x0 = round(region["x"] * width)
|
|
260
|
+
y0 = round(region["y"] * height)
|
|
261
|
+
x1 = min(width, x0 + max(1, round(region["width"] * width)))
|
|
262
|
+
y1 = min(height, y0 + max(1, round(region["height"] * height)))
|
|
263
|
+
crop_w = max(1, x1 - x0)
|
|
264
|
+
crop_h = max(1, y1 - y0)
|
|
265
|
+
crop_pixels = []
|
|
266
|
+
for y in range(y0, y0 + crop_h):
|
|
267
|
+
source_y = min(height - 1, y)
|
|
268
|
+
for x in range(x0, x0 + crop_w):
|
|
269
|
+
source_x = min(width - 1, x)
|
|
270
|
+
crop_pixels.append(composite_over_white(pixels[source_y * width + source_x]))
|
|
271
|
+
crop_path = out_dir / f"{zone['id']}.png"
|
|
272
|
+
write_png_rgb(crop_path, crop_w, crop_h, crop_pixels)
|
|
273
|
+
details.append(make_detail_stub(zone, crop_path))
|
|
274
|
+
return {
|
|
275
|
+
"scanMethod": mode,
|
|
276
|
+
"targetMinDetails": target_min_details,
|
|
277
|
+
"details": details,
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def main(argv: list[str]) -> int:
|
|
282
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
283
|
+
parser.add_argument("image", type=Path)
|
|
284
|
+
parser.add_argument(
|
|
285
|
+
"--mode",
|
|
286
|
+
choices=["grid-3x3", "grid-4x4", "component-zones"],
|
|
287
|
+
default="grid-3x3",
|
|
288
|
+
help="Zone layout to scan (default: grid-3x3)",
|
|
289
|
+
)
|
|
290
|
+
parser.add_argument(
|
|
291
|
+
"--out-dir",
|
|
292
|
+
type=Path,
|
|
293
|
+
help="Directory to write zone crop PNGs (default: <image-stem>-zones next to the image)",
|
|
294
|
+
)
|
|
295
|
+
parser.add_argument(
|
|
296
|
+
"--out",
|
|
297
|
+
type=Path,
|
|
298
|
+
help="Output detailInventory skeleton JSON path (default: <out-dir>/detail-inventory.json)",
|
|
299
|
+
)
|
|
300
|
+
parser.add_argument(
|
|
301
|
+
"--complexity",
|
|
302
|
+
choices=sorted(TARGET_MIN_DETAILS),
|
|
303
|
+
default="moderate",
|
|
304
|
+
help="Sets targetMinDetails from the complexity tier; overridden by --target-min-details",
|
|
305
|
+
)
|
|
306
|
+
parser.add_argument("--target-min-details", type=int, help="Override targetMinDetails directly")
|
|
307
|
+
parser.add_argument(
|
|
308
|
+
"--components",
|
|
309
|
+
help="component-zones only: 'name:x,y,w,h;name2:x,y,w,h' normalized regions "
|
|
310
|
+
"(default: upper/middle/lower thirds)",
|
|
311
|
+
)
|
|
312
|
+
parser.add_argument("--force", action="store_true", help="Overwrite existing output JSON")
|
|
313
|
+
args = parser.parse_args(argv)
|
|
314
|
+
|
|
315
|
+
image = args.image.expanduser().resolve()
|
|
316
|
+
if not image.exists():
|
|
317
|
+
parser.error(f"{image} does not exist")
|
|
318
|
+
out_dir = (args.out_dir or image.with_name(f"{image.stem}-zones")).expanduser().resolve()
|
|
319
|
+
out_path = (args.out or out_dir / "detail-inventory.json").expanduser().resolve()
|
|
320
|
+
if out_path.exists() and not args.force:
|
|
321
|
+
parser.error(f"{out_path} already exists; use --force to overwrite")
|
|
322
|
+
target_min_details = args.target_min_details or TARGET_MIN_DETAILS[args.complexity]
|
|
323
|
+
|
|
324
|
+
try:
|
|
325
|
+
inventory = build_inventory(image, args.mode, out_dir, target_min_details, args.components)
|
|
326
|
+
except Exception as exc:
|
|
327
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
328
|
+
return 1
|
|
329
|
+
|
|
330
|
+
payload = {
|
|
331
|
+
"sourceImage": str(image),
|
|
332
|
+
"zonesDir": str(out_dir),
|
|
333
|
+
"detailInventory": inventory,
|
|
334
|
+
"authoringInstruction": (
|
|
335
|
+
"Open each zone crop under zonesDir and replace every detail stub's kind, description, "
|
|
336
|
+
"scale, affects, mapsTo, and confidence with what is actually observed. Add more detail "
|
|
337
|
+
"entries per zone if a single zone contains multiple distinct marks; do not leave stubs "
|
|
338
|
+
"unfilled or unlinked (mapsTo must reference a real component.localFeatures or "
|
|
339
|
+
"material.localOverrides entry)."
|
|
340
|
+
),
|
|
341
|
+
}
|
|
342
|
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
343
|
+
out_path.write_text(json.dumps(payload, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
344
|
+
print(out_path)
|
|
345
|
+
return 0
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
if __name__ == "__main__":
|
|
349
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Projection, residual, and degeneracy math for camera fitting."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from collections.abc import Sequence
|
|
7
|
+
|
|
8
|
+
from forge.stage1_intake.camera_fitting_types import (
|
|
9
|
+
MAXIMUM_FOV_DEGREES,
|
|
10
|
+
MINIMUM_CAMERA_DEPTH,
|
|
11
|
+
MINIMUM_FOV_DEGREES,
|
|
12
|
+
CameraParameters,
|
|
13
|
+
NormalizedCorrespondence,
|
|
14
|
+
Point2,
|
|
15
|
+
Point3,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def project_landmark(point: Point3, camera: CameraParameters) -> Point2 | None:
|
|
20
|
+
"""Project a world point using the established pitch, yaw, then roll convention."""
|
|
21
|
+
if not MINIMUM_FOV_DEGREES <= camera.fov_degrees <= MAXIMUM_FOV_DEGREES:
|
|
22
|
+
return None
|
|
23
|
+
tangent = math.tan(math.radians(camera.fov_degrees) / 2.0)
|
|
24
|
+
if not math.isfinite(tangent) or abs(tangent) <= MINIMUM_CAMERA_DEPTH:
|
|
25
|
+
return None
|
|
26
|
+
focal_length = (camera.image_height / 2.0) / tangent
|
|
27
|
+
translated_x = point[0] - camera.position[0]
|
|
28
|
+
translated_y = point[1] - camera.position[1]
|
|
29
|
+
translated_z = camera.position[2] - point[2]
|
|
30
|
+
|
|
31
|
+
pitch_radians = math.radians(camera.pitch_degrees)
|
|
32
|
+
pitch_cosine = math.cos(pitch_radians)
|
|
33
|
+
pitch_sine = math.sin(pitch_radians)
|
|
34
|
+
pitched_x = translated_x
|
|
35
|
+
pitched_y = translated_y * pitch_cosine - translated_z * pitch_sine
|
|
36
|
+
pitched_z = translated_y * pitch_sine + translated_z * pitch_cosine
|
|
37
|
+
|
|
38
|
+
yaw_radians = math.radians(camera.yaw_degrees)
|
|
39
|
+
yaw_cosine = math.cos(yaw_radians)
|
|
40
|
+
yaw_sine = math.sin(yaw_radians)
|
|
41
|
+
yawed_x = pitched_x * yaw_cosine + pitched_z * yaw_sine
|
|
42
|
+
yawed_y = pitched_y
|
|
43
|
+
yawed_z = -pitched_x * yaw_sine + pitched_z * yaw_cosine
|
|
44
|
+
|
|
45
|
+
roll_radians = math.radians(camera.roll_degrees)
|
|
46
|
+
roll_cosine = math.cos(roll_radians)
|
|
47
|
+
roll_sine = math.sin(roll_radians)
|
|
48
|
+
rolled_x = yawed_x * roll_cosine - yawed_y * roll_sine
|
|
49
|
+
rolled_y = yawed_x * roll_sine + yawed_y * roll_cosine
|
|
50
|
+
if yawed_z <= MINIMUM_CAMERA_DEPTH:
|
|
51
|
+
return None
|
|
52
|
+
projected_x = (camera.image_width / 2.0) + (focal_length * rolled_x / yawed_z)
|
|
53
|
+
projected_y = (camera.image_height / 2.0) - (focal_length * rolled_y / yawed_z)
|
|
54
|
+
if not math.isfinite(projected_x) or not math.isfinite(projected_y):
|
|
55
|
+
return None
|
|
56
|
+
return projected_x, projected_y
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def residual_components(
|
|
60
|
+
correspondences: Sequence[NormalizedCorrespondence], camera: CameraParameters
|
|
61
|
+
) -> tuple[float, ...] | None:
|
|
62
|
+
components: list[float] = []
|
|
63
|
+
for correspondence in correspondences:
|
|
64
|
+
projected = project_landmark(correspondence.world, camera)
|
|
65
|
+
if projected is None:
|
|
66
|
+
return None
|
|
67
|
+
delta_x = projected[0] - correspondence.observed[0]
|
|
68
|
+
delta_y = projected[1] - correspondence.observed[1]
|
|
69
|
+
if not math.isfinite(delta_x) or not math.isfinite(delta_y):
|
|
70
|
+
return None
|
|
71
|
+
components.extend((delta_x, delta_y))
|
|
72
|
+
return tuple(components)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def rms_reprojection_error(components: tuple[float, ...]) -> float:
|
|
76
|
+
return math.sqrt(sum(component * component for component in components) / (len(components) // 2))
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def has_degenerate_world_geometry(correspondences: Sequence[NormalizedCorrespondence]) -> bool:
|
|
80
|
+
coordinate_scale = 1.0
|
|
81
|
+
for correspondence in correspondences:
|
|
82
|
+
coordinate_scale = max(coordinate_scale, *(abs(value) for value in correspondence.world))
|
|
83
|
+
count = len(correspondences)
|
|
84
|
+
centroid = (
|
|
85
|
+
sum(correspondence.world[0] for correspondence in correspondences) / count,
|
|
86
|
+
sum(correspondence.world[1] for correspondence in correspondences) / count,
|
|
87
|
+
sum(correspondence.world[2] for correspondence in correspondences) / count,
|
|
88
|
+
)
|
|
89
|
+
span_square = 0.0
|
|
90
|
+
first_index = 0
|
|
91
|
+
second_index = 0
|
|
92
|
+
for index, first in enumerate(correspondences):
|
|
93
|
+
centered = (
|
|
94
|
+
first.world[0] - centroid[0],
|
|
95
|
+
first.world[1] - centroid[1],
|
|
96
|
+
first.world[2] - centroid[2],
|
|
97
|
+
)
|
|
98
|
+
span_square = max(span_square, sum(component * component for component in centered))
|
|
99
|
+
for candidate_index in range(index + 1, count):
|
|
100
|
+
second = correspondences[candidate_index]
|
|
101
|
+
delta_x = second.world[0] - first.world[0]
|
|
102
|
+
delta_y = second.world[1] - first.world[1]
|
|
103
|
+
delta_z = second.world[2] - first.world[2]
|
|
104
|
+
separation_square = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z
|
|
105
|
+
if separation_square > span_square:
|
|
106
|
+
span_square = separation_square
|
|
107
|
+
first_index = index
|
|
108
|
+
second_index = candidate_index
|
|
109
|
+
minimum_span = coordinate_scale * 1e-9
|
|
110
|
+
if span_square <= minimum_span * minimum_span:
|
|
111
|
+
return True
|
|
112
|
+
first_point = correspondences[first_index].world
|
|
113
|
+
second_point = correspondences[second_index].world
|
|
114
|
+
axis = (
|
|
115
|
+
second_point[0] - first_point[0],
|
|
116
|
+
second_point[1] - first_point[1],
|
|
117
|
+
second_point[2] - first_point[2],
|
|
118
|
+
)
|
|
119
|
+
axis_square = sum(component * component for component in axis)
|
|
120
|
+
maximum_perpendicular_square = 0.0
|
|
121
|
+
for correspondence in correspondences:
|
|
122
|
+
offset = (
|
|
123
|
+
correspondence.world[0] - first_point[0],
|
|
124
|
+
correspondence.world[1] - first_point[1],
|
|
125
|
+
correspondence.world[2] - first_point[2],
|
|
126
|
+
)
|
|
127
|
+
projection = sum(offset[index] * axis[index] for index in range(3)) / axis_square
|
|
128
|
+
perpendicular = tuple(offset[index] - projection * axis[index] for index in range(3))
|
|
129
|
+
maximum_perpendicular_square = max(
|
|
130
|
+
maximum_perpendicular_square,
|
|
131
|
+
sum(component * component for component in perpendicular),
|
|
132
|
+
)
|
|
133
|
+
return maximum_perpendicular_square <= span_square * 1e-12
|