-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shift in plotted mesh in flywire #4
Comments
This DM5 mesh has been shifting for me, having tried many times. Here's all the code I ran: import navis
import fafbseg
import flybrains
import os
import numpy as np
import pandas as pd
import copy
from pyroglancer.localserver import startdataserver, closedataserver
from pyroglancer.flywire import flywireurl2dict, add_flywirelayer
from pyroglancer.utils import pointcloud2meshes
import trimesh as tm
import open3d as o3d
from vfb_connect.cross_server_tools import VfbConnect
vc = VfbConnect()
vfb_id = 'VFB_00020020'
# 'VFB_00020048': DM6
# 'VFB_00020085': DM4
# VFB_00020010: SMPpv1
# VFB_00020051: SLPal3
# VFB_00020052: SLPal4
# VFB_00020059: SLPal5
# VFB_00020031: PSp3
# VFB_00020071: VLPp2
# VFB_00020203: DM5 (cleaner)
# VFB_00020020: DM5 (messy)
# VFB_00020023: SLPpl2
# VFB_00020008 ALl1
vcinfo = vc.neo_query_wrapper.get_anatomical_individual_TermInfo([vfb_id])
image_folder = vcinfo[0]['channel_image'][0]['image']['image_folder'] + 'volume.obj'
image_folder
vfb_mesh = tm.load_remote(image_folder)
vfb_mesh
mesh_files = '/Users/yijieyin/Documents/Python/Pyroglancer/gal4_lines/' + vfb_id + '.ply'
mesh_files
tempval = vfb_mesh.export(mesh_files)
pcd = o3d.io.read_point_cloud(mesh_files)
pcd.estimate_normals()
# estimate radius for rolling ball
distances = pcd.compute_nearest_neighbor_distance()
avg_dist = np.mean(distances)
radius = 3 * avg_dist
# This will take some time. This is generating a point cloud from the nrrd file
mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(pcd,
o3d.utility.DoubleVector([radius, radius * 2]))
# create the triangular mesh with the vertices and faces from open3d
tri_mesh = tm.Trimesh(np.asarray(mesh.vertices), np.asarray(mesh.triangles),
vertex_normals=np.asarray(mesh.vertex_normals))
# Checks if the mesh is broken
tm.convex.is_convex(tri_mesh)
vfb_mesh = navis.Volume(tri_mesh)
jrc2018u_mesh = navis.Volume(flybrains.JRC2018U.mesh)
vfb_mesh.color = 'blue'
vfb_mesh
fig, ax = navis.plot2d([vfb_mesh,jrc2018u_mesh], method='2d')
fig.gca().invert_yaxis()
vfbmesh_xyz_02 = pd.DataFrame(list(map(np.ravel, vfb_mesh.vertices)), columns=['x', 'y', 'z'])
vfb2flywiremesh = copy.deepcopy(vfb_mesh)
# Transform from Janelia Research Campus 2018 Unisex into Flywire space
vfb2flywiremesh_xyz = navis.xform_brain(vfbmesh_xyz_02[['x','y','z']],source='JRC2018U', target='FLYWIRE')
vfb2flywiremesh.vertices = vfb2flywiremesh_xyz
vfb2flywiremesh
# You should always close this even if you shut down the terminal
startdataserver()
# An empty url containing the brain mesh
shorturl = 'https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/4757698205712384'
# just a random number to show in FlyWire
vfb2flywiremesh.id = 1
# Note the type here is volumes
# The link this cell gives is the one that has the pre-computed mesh.
shorturl = add_flywirelayer(flywireurl2dict(shorturl), layer_kws = {'type': 'volumes','name': 'DM5',
'source': vfb2flywiremesh,'color': 'white'})
# Make sure you run this at the end:
closedataserver() |
Hi @YijieYin : If you carefully look the mesh is exceeding the neuropil boundaries at regions near medulla and anterior ventrolateral protocerebrum you can see that the point cloud mesh (green) was not registered properly in regions near medulla (red) and anterior ventrolateral protocerebrum (red). |
So in conclusion, I would do the following to fix this issue:
|
Re-referenced the issue to here: VirtualFlyBrain/VFB2#310 |
Further investigation reveals that some of these clones are actually registered to Further, when I transform them to the i was quickly able to find a match like below after some probing: So the part of the code that you need to change to achieve this transformation would be:
The main issue seems to be that @Robbie1977: FYI |
The meshes plotted by gal4line2flywire script sometimes have shifts anteriorly.
All the code comes from the gal4line2flywire example, except: ALad1 (VFB_00020032) may be a good example as you can see that some of the plotted mesh is outside the brain mesh. Here's a flywire link with the brain mesh. You could use this as the shorturl.
However this shift doesn't always happen, and I'm not sure what triggers it. Please let me know if you'd like me to paste all the code I ran here.
The text was updated successfully, but these errors were encountered: