|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Debug mesh and volume coordinate spaces""" |
| 3 | +import json |
| 4 | +import sys |
| 5 | +import os |
| 6 | + |
| 7 | +if len(sys.argv) < 2: |
| 8 | + print("Usage: python check_mesh_coords.py <dataset_path>") |
| 9 | + sys.exit(1) |
| 10 | + |
| 11 | +dataset_path = sys.argv[1] |
| 12 | + |
| 13 | +# Read main info |
| 14 | +with open(os.path.join(dataset_path, "info"), "r") as f: |
| 15 | + info = json.load(f) |
| 16 | + |
| 17 | +print("=== Dataset Info ===") |
| 18 | +print(f"Type: {info['type']}") |
| 19 | +print(f"Data type: {info['data_type']}") |
| 20 | +print(f"Volume size (XYZ): {info['scales'][0]['size']}") |
| 21 | +print(f"Resolution (XYZ): {info['scales'][0]['resolution']}") |
| 22 | +print(f"Chunk sizes: {info['scales'][0]['chunk_sizes']}") |
| 23 | + |
| 24 | +# Calculate physical bounds |
| 25 | +size = info["scales"][0]["size"] |
| 26 | +resolution = info["scales"][0]["resolution"] |
| 27 | +physical_bounds = [s * r for s, r in zip(size, resolution)] |
| 28 | +print(f"Physical bounds: {physical_bounds}") |
| 29 | + |
| 30 | +# Read mesh info if exists |
| 31 | +mesh_info_path = os.path.join(dataset_path, "mesh", "info") |
| 32 | +if os.path.exists(mesh_info_path): |
| 33 | + print("\n=== Mesh Info ===") |
| 34 | + with open(mesh_info_path, "r") as f: |
| 35 | + mesh_info = json.load(f) |
| 36 | + print(json.dumps(mesh_info, indent=2)) |
| 37 | + |
| 38 | + # Check a sample mesh file |
| 39 | + mesh_dir = os.path.join(dataset_path, "mesh") |
| 40 | + mesh_files = [ |
| 41 | + f |
| 42 | + for f in os.listdir(mesh_dir) |
| 43 | + if f.endswith(".gz") or (f.isdigit() and not f.endswith(".gz")) |
| 44 | + ] |
| 45 | + |
| 46 | + if mesh_files: |
| 47 | + sample_mesh = mesh_files[0] |
| 48 | + print(f"\nSample mesh file: {sample_mesh}") |
| 49 | + |
| 50 | + # Try to read and check coordinates |
| 51 | + try: |
| 52 | + from cloudvolume import CloudVolume |
| 53 | + from cloudvolume.mesh import Mesh |
| 54 | + |
| 55 | + vol = CloudVolume(f"file://{dataset_path}", mip=0) |
| 56 | + |
| 57 | + # Get segment ID from filename |
| 58 | + seg_id = int(sample_mesh.replace(".gz", "").replace(":", "_").split("_")[0]) |
| 59 | + |
| 60 | + try: |
| 61 | + mesh = vol.mesh.get(seg_id) |
| 62 | + if mesh and len(mesh.vertices) > 0: |
| 63 | + print(f"\nMesh {seg_id} vertices:") |
| 64 | + print(f" Min: {mesh.vertices.min(axis=0)}") |
| 65 | + print(f" Max: {mesh.vertices.max(axis=0)}") |
| 66 | + print(f" Shape: {mesh.vertices.shape}") |
| 67 | + |
| 68 | + # Compare with volume bounds |
| 69 | + max_voxel = mesh.vertices.max(axis=0) |
| 70 | + print(f"\nComparison:") |
| 71 | + print(f" Volume size (voxels): {size}") |
| 72 | + print(f" Mesh max (should be <= volume size): {max_voxel}") |
| 73 | + |
| 74 | + if any(max_voxel > size): |
| 75 | + print(f" ⚠ WARNING: Mesh vertices exceed volume bounds!") |
| 76 | + else: |
| 77 | + print(f" ✓ Mesh vertices within volume bounds") |
| 78 | + except Exception as e: |
| 79 | + print(f" Error loading mesh: {e}") |
| 80 | + |
| 81 | + except Exception as e: |
| 82 | + print(f"Error: {e}") |
| 83 | +else: |
| 84 | + print("\n⚠ No mesh info found") |
0 commit comments