12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #! /bin/bash
- path_to_gong="./thirdparty/gong-refs.tags.v1.3.0"
- output_dir="./output/precomputed/segmentations"
- mesh_subdir="meshes"
- for dir in $(find ./neuroglancer-scripts-input/meshes/ -mindepth 1 -maxdepth 1 -type d)
- do
- cleaned_dir=${dir#./neuroglancer-scripts-input/meshes/}
- root_path=$output_dir/$cleaned_dir/
- info_path=$root_path/info
- mesh_subdir_path=$root_path/$mesh_subdir
- x_transl=$(jq '.[0][3]' $root_path/transform.json)
- y_transl=$(jq '.[1][3]' $root_path/transform.json)
- z_transl=$(jq '.[2][3]' $root_path/transform.json)
- # this looks weird
- # we will cross this bridge when we cross it...
- x_transl=${x_transl#-}
- y_transl=${y_transl#-}
- z_transl=${z_transl#-}
- base_xform="1e6,0,0,$x_transl,0,1e6,0,$y_transl,0,0,1e6,$z_transl"
- mkdir -p $mesh_subdir_path
-
- [ -f $info_path ] || echo "info $info_path does not exist. Skipping $cleaned_dir"
- [ -f $info_path ] || continue
- for key in $(jq -r 'keys[]' $dir/manifest.json)
- do
- echo Processing $key
- mesh_path=$dir/meshes/$key
- format=$(jq -r ".[\"$key\"].format" $dir/manifest.json)
- seg_id=$(jq -r ".[\"$key\"].labelIndex" $dir/manifest.json)
- new_mesh_name=${key##*/}
- new_mesh_name=${new_mesh_name%.*}
- # convert mesh
- $path_to_gong \
- -outputFormat NG_MESH \
- -dst $mesh_subdir_path/$new_mesh_name \
- -src $mesh_path \
- -srcFormat $format \
- -xformMatrix $base_xform
-
- # add mesh metadata
- mesh_meta_path=$mesh_subdir_path/$seg_id:0
- new_fragments="[\"$new_mesh_name\"]"
- if [ -f $mesh_meta_path ]
- then
- new_mesh_meta=$(jq "{ \"fragments\": (.fragments + $new_fragments) }" $mesh_meta_path)
- else
- new_mesh_meta="{\"fragments\": $new_fragments}"
- fi
- echo $new_mesh_meta | jq -c '.' > $mesh_meta_path
- done
- new_info=$(jq ". + {\"mesh\":\"$mesh_subdir\"}" $info_path)
- echo $new_info | jq -c '.' > $info_path
- done
|