-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #391 from favreau/master
Added references to CCFv3 new atlas with extended annotations
- Loading branch information
Showing
31 changed files
with
35,933 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions
111
bioexplorer/pythonsdk/notebooks/ccfv3/BioExplorer_add_material_to_meshes.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "f992ef9f", | ||
"metadata": {}, | ||
"source": [ | ||
"# BioExplorer - CCFv3\n", | ||
"![](../bioexplorer_ccfv3_banner.png)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "5b2edd2b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import json\n", | ||
"import os\n", | ||
"import glob\n", | ||
"from tqdm import tqdm\n", | ||
"\n", | ||
"atlas_data_folder = os.getenv('ATLAS_DATA_FOLDER')\n", | ||
"\n", | ||
"data_folder = os.path.join(atlas_data_folder, 'mouse', 'v3')\n", | ||
"f = open(os.path.join(data_folder, 'brain_regions.json'))\n", | ||
"obj = json.load(f)\n", | ||
"\n", | ||
"region_colors=dict()\n", | ||
"def node_color(node):\n", | ||
" node_id = node['id']\n", | ||
" color = node['color_hex_triplet']\n", | ||
" region_colors[node_id] = color\n", | ||
" for child in node['children']:\n", | ||
" node_color(child)\n", | ||
"\n", | ||
"for node in obj['msg']:\n", | ||
" node_color(node)\n", | ||
"\n", | ||
"def hex_to_rgb(value):\n", | ||
" value = value.lstrip('#')\n", | ||
" lv = len(value)\n", | ||
" return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ca01b536", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def add_material_to_obj(obj_file, material_name, diffuse_color):\n", | ||
" # Open the OBJ file in read mode\n", | ||
" with open(obj_file, 'r') as file:\n", | ||
" lines = file.readlines()\n", | ||
"\n", | ||
" # Insert the material definition before the first usemtl line\n", | ||
" lines.insert(0, 'mtllib {}\\n'.format(os.path.basename(obj_file).replace('.obj', '.mtl')))\n", | ||
"\n", | ||
" # Write the modified lines back to the OBJ file\n", | ||
" with open(obj_file, 'w') as file:\n", | ||
" file.writelines(lines)\n", | ||
"\n", | ||
" # Create the material file with diffuse color\n", | ||
" mtl_filename = obj_file.replace('.obj', '.mtl')\n", | ||
" with open('{}'.format(mtl_filename), 'w') as mtl_file:\n", | ||
" mtl_file.write('newmtl {}\\n'.format(material_name))\n", | ||
" mtl_file.write('Kd {} {} {}\\n'.format(*[int(diffuse_color[i:i+2], 16)/255 for i in (1, 3, 5)]))\n", | ||
" # You might want to add more properties like specular color, shininess, etc. if needed\n", | ||
"\n", | ||
" # print(\"Material '{}' added to '{}' with diffuse color '{}' successfully.\".format(material_name, obj_file, diffuse_color))\n", | ||
"\n", | ||
"\n", | ||
"# Example usage:\n", | ||
"mesh_folder = os.path.join(data_folder, 'meshes', 'obj')\n", | ||
"mesh_files = glob.glob(mesh_folder + '/*.obj')\n", | ||
"for mesh_file in tqdm(mesh_files):\n", | ||
" base_name = os.path.basename(mesh_file).split('.')[0]\n", | ||
" color = region_colors[int(base_name)]\n", | ||
" add_material_to_obj(mesh_file, 'default', color)\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"interpreter": { | ||
"hash": "ea9a5fa46eb6bad2806a8ea1d08e15bb1e255a2d4320b81e765591579963c56b" | ||
}, | ||
"kernelspec": { | ||
"display_name": "Python 3.8.10 64-bit ('env': venv)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.