morphoviewer
v0.1.20
Published
A 3D neuron morphology viewer for the web
Downloads
152
Readme
Morphology Viewer
Displays a neuron morphology. This relies on JSON morphology files, such as created by Morphology Converter.
Follow the examples and the documentation (also available in HTML)
Usage
Create a MorphoViewer
instance
let threedeediv = document.getElementById( 'threedeediv' )
let morphoViewer = new morphoviewer.MorphoViewer(threedeediv)
Since MorphoViewer
needs a div
to create a WebGL context into, you need to get the reference to one.
Add a morphology
To add a morphology, you need a morphology object. These can come from different source: straight from a JSON morphology file, or from this SWC parser. For this example, lets assume you have a JSon string from a JSON file.
// ... you have loaded the content of a morphology JSON file in 'jsonStr'
let rawMorphoObj = JSON.parse( jsonStr )
// we display a morpho, second param is it's name (null: a autogenarated will do)
// last param is "do we focus the camera on it"
morphoViewer.addMorphology (
rawMorphoObj,
options
)
The options
object may have the following properties:
name
: String. A name can be given to a morphology to identify it. This is useful especially to later focus on this morpho withmorphoViewer.focusOnMorphology(...)
. If not provided, a name with be generated automatically, of the formmorpho_XXX
whereXXX
is a random integer.focusOn
: Boolean. Iftrue
, the viewer will focus on the center of the soma of the loaded morphology. For the morphologies without soma, the focus will be done on the center of its bounding box. Iffalse
, the camera will not move. Default isfalse
.distance
: Number. Relevant only iffocusOn
istrue
. Distance between the camera and the soma. Default: 1000 (most likely in microns)asPolyline
: Boolean. Iftrue
, the morphology's axons and dendrites will be simple polylines with constant thickness of 1px on the screen, no matter the distance from the camera of the zoom - better performance. Iffalse
, the morphology's dendrites and axons will be displayed as cylinders - looks nicer, but can be very heavy with more than 10 morphologies. Default:true
color
: Integer. If provided, it's easier to use the hexadecimal form:0xRRGGBB
, then, all the axons and dendrites are collored the same way. If not provided, the every axons will be blue, basal dendrite will be red and apical dendrite will be pink. Default: not providedsomaMode
: String. If"fromOrphanSections"
then, the soma will be built using the 1st point of the axons and dendrite (this points is the connection to the soma). If it has a different value, only the data from the soma will be used.onDone
: Function. This function is called once the morphology is displayed, with thename
as argument.
Add a mesh
For the moment, only STL and OBJ files are compatible.
For STL meshesm a URL must be provided:
// optional: we load a brain model. Last param is for focusing on it
morphoViewer.addStlToMeshCollection(
'../data/meshes/mask_smooth_simple.stl',
options
)
Alternatively, a OBJ mesh can be added, using the string contained by the OBJ file:
morphoViewer.addObjToMeshCollection(
objStr,
options
)
The options
object may have the following properties:
name
: String. A name can be given to a mesh to identify it. This is useful especially to later focus on this morpho withmorphoViewer.focusOnMesh(...)
. If not provided, a name with be generated automatically, of the formmesh_XXX
whereXXX
is a random integer.focusOn
: Boolean. Iftrue
, the viewer will focus on the center of the mesh and the distance between the camera and the center of the mesh will be three times the radius of the bounding sphere of the mesh (this sort of guaranties we are neither too close nor too far). Default isfalse
.color
: Number. If provided, it's easier to use the hexadecimal form:0xRRGGBB
. Default:0xDDDDDD
, light greyopacity
: Number. Must in [0, 1], 0 being totally transparent and 1 is totally opaque. Default:0.15
wireframe
: Boolean. Iftrue
, the mesh displays as a wireframe. Default:false
shininess
: Number. The shininess of the mesh0
is very matter (not shinny at all) and 1000 is super slimy. Default:300
doubleSide
: Boolean. Iftrue
, the mesh will be visible from both side (outside and inside). Iffalse
, the mesh will be visible only from the outside. Default:false
onDone
: Function. This function is called once the mesh is displayed, with thename
as argument.