run-mesh.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #! /bin/bash
  2. path_to_gong="./thirdparty/gong-refs.tags.v1.3.0"
  3. output_dir="./output/precomputed/segmentations"
  4. mesh_subdir="meshes"
  5. for dir in $(find ./neuroglancer-scripts-input/meshes/ -mindepth 1 -maxdepth 1 -type d)
  6. do
  7. cleaned_dir=${dir#./neuroglancer-scripts-input/meshes/}
  8. root_path=$output_dir/$cleaned_dir/
  9. info_path=$root_path/info
  10. mesh_subdir_path=$root_path/$mesh_subdir
  11. x_transl=$(jq '.[0][3]' $root_path/transform.json)
  12. y_transl=$(jq '.[1][3]' $root_path/transform.json)
  13. z_transl=$(jq '.[2][3]' $root_path/transform.json)
  14. # this looks weird
  15. # we will cross this bridge when we cross it...
  16. x_transl=${x_transl#-}
  17. y_transl=${y_transl#-}
  18. z_transl=${z_transl#-}
  19. base_xform="1e6,0,0,$x_transl,0,1e6,0,$y_transl,0,0,1e6,$z_transl"
  20. mkdir -p $mesh_subdir_path
  21. [ -f $info_path ] || echo "info $info_path does not exist. Skipping $cleaned_dir"
  22. [ -f $info_path ] || continue
  23. for key in $(jq -r 'keys[]' $dir/manifest.json)
  24. do
  25. echo Processing $key
  26. mesh_path=$dir/meshes/$key
  27. format=$(jq -r ".[\"$key\"].format" $dir/manifest.json)
  28. seg_id=$(jq -r ".[\"$key\"].labelIndex" $dir/manifest.json)
  29. new_mesh_name=${key##*/}
  30. new_mesh_name=${new_mesh_name%.*}
  31. # convert mesh
  32. $path_to_gong \
  33. -outputFormat NG_MESH \
  34. -dst $mesh_subdir_path/$new_mesh_name \
  35. -src $mesh_path \
  36. -srcFormat $format \
  37. -xformMatrix $base_xform
  38. # add mesh metadata
  39. mesh_meta_path=$mesh_subdir_path/$seg_id:0
  40. new_fragments="[\"$new_mesh_name\"]"
  41. if [ -f $mesh_meta_path ]
  42. then
  43. new_mesh_meta=$(jq "{ \"fragments\": (.fragments + $new_fragments) }" $mesh_meta_path)
  44. else
  45. new_mesh_meta="{\"fragments\": $new_fragments}"
  46. fi
  47. echo $new_mesh_meta | jq -c '.' > $mesh_meta_path
  48. done
  49. new_info=$(jq ". + {\"mesh\":\"$mesh_subdir\"}" $info_path)
  50. echo $new_info | jq -c '.' > $info_path
  51. done