@@ -250,7 +250,7 @@ BrainBrowser.SurfaceViewer.modules.rendering = function(viewer) {
250250 viewer . drawDot = function ( x , y , z , radius , color ) {
251251 radius = radius || 2 ;
252252 radius = radius >= 0 ? radius : 0 ;
253- color = color >= 0 ? color : 0xFF0000 ;
253+ color = color >= 0 ? color : 0xFF0000 ;
254254
255255 var geometry = new THREE . SphereGeometry ( radius ) ;
256256 var material = new THREE . MeshBasicMaterial ( { color : color } ) ;
@@ -292,9 +292,9 @@ BrainBrowser.SurfaceViewer.modules.rendering = function(viewer) {
292292 * var euler_rotation = new THREE.Euler( 0, 0, Math.PI/2, 'XYZ' );
293293 * viewer.drawGrid(100, 10, {euler_rotation: euler_rotation});
294294 * ```
295- *
296295 */
297296 viewer . drawGrid = function ( size , step , options ) {
297+ options = options || { } ;
298298 var name = options . name ;
299299 var color_center_line = options . color_center_line ;
300300 var color_grid = options . color_grid ;
@@ -317,7 +317,7 @@ BrainBrowser.SurfaceViewer.modules.rendering = function(viewer) {
317317 z = z || 0 ;
318318
319319 // Create the grid
320- var grid = new THREE . GridHelper ( size , step ) ;
320+ var grid = new THREE . GridHelper ( size , step ) ;
321321 grid . name = name ;
322322 grid . setColors ( color_center_line , color_grid ) ;
323323 grid . position . set ( x , y , z ) ;
@@ -335,6 +335,111 @@ BrainBrowser.SurfaceViewer.modules.rendering = function(viewer) {
335335 return grid ;
336336 } ;
337337
338+ /**
339+ * @doc function
340+ * @name viewer.rendering:drawLine
341+ * @param {object } start A Vector3, start of the line segment
342+ * @param {object } end A Vector3, end of the line segment
343+ * @param {object } options Options, which include the following:
344+ *
345+ * * **color** The color of the line as a hexadecimal integer (default 0x444444).
346+ * * **dashed** If true create a dashed line
347+ * * **draw** If false don't draw the line
348+ *
349+ * @returns {object } The line itself.
350+ *
351+ * @description Draw a line in the current scene.
352+ * ```js
353+ * var start = new THREE.Vector3(0,0,0);
354+ * var end = new THREE.Vector3(200,200,200);
355+ * viewer.drawLine(start, end, {dashed: true});
356+ * ```
357+ */
358+ viewer . drawLine = function ( start , end , options ) {
359+ options = options || { } ;
360+ var color = options . color >= 0 ? options . color : 0x444444 ;
361+
362+ // Create the geometry
363+ var geometry = new THREE . Geometry ( ) ;
364+ geometry . vertices . push ( start . clone ( ) ) ;
365+ geometry . vertices . push ( end . clone ( ) ) ;
366+ geometry . computeLineDistances ( ) ;
367+
368+ // Set the material according with the dashed option
369+ var material = options . dashed === true ?
370+ new THREE . LineDashedMaterial ( { linewidth : 3 , color : color , gapSize : 3 } )
371+ : new THREE . LineBasicMaterial ( { linewidth : 3 , color : color } ) ;
372+
373+ var line = new THREE . Line ( geometry , material , THREE . LinePieces ) ;
374+
375+ if ( options . draw === false ) { return line }
376+
377+ if ( viewer . model ) {
378+ viewer . model . add ( line ) ;
379+ } else {
380+ scene . add ( line ) ;
381+ }
382+
383+ viewer . updated = true ;
384+
385+ return line ;
386+ }
387+
388+ /**
389+ * @doc function
390+ * @name viewer.rendering:drawAxes
391+ * @param {number } size Define the size of the line representing the axes.
392+ * @param {object } options Options, which include the following:
393+ *
394+ * * **center** A Vector3, that represent the orgin of the axes
395+ * * **x_color** The color of the line as a hexadecimal integer (default 0xff0000).
396+ * * **y_color** The color of the line as a hexadecimal integer (default 0x00ff00).
397+ * * **z_color** The color of the line as a hexadecimal integer (default 0x0000ff).
398+ * * **complete** If true draw postive (plain) and negative axes (dashed)
399+ *
400+ *
401+ * @returns {object } The axes itself.
402+ *
403+ * @description
404+ * Draw Axes in the current scene
405+ * ```js
406+ * viewer.drawAxes(300)
407+ * ```
408+ */
409+ viewer . drawAxes = function ( size , options ) {
410+ size = size || 300 ;
411+ options = options || { } ;
412+ var center = options . center || new THREE . Vector3 ( 0 , 0 , 0 ) ;
413+ var x_color = options . x_color >= 0 ? options . x_color : 0xff0000 ;
414+ var y_color = options . y_color >= 0 ? options . y_color : 0x00ff00 ;
415+ var z_color = options . z_color >= 0 ? options . z_color : 0x0000ff ;
416+ var complete = options . complete === true ;
417+
418+ var axes = new THREE . Object3D ( ) ;
419+
420+ // X axes
421+ axes . add ( viewer . drawLine ( center , new THREE . Vector3 ( size , 0 , 0 ) , { color : x_color , dashed : false , draw : false } ) ) ;
422+ axes . add ( viewer . drawLine ( center , new THREE . Vector3 ( - size , 0 , 0 ) , { color : x_color , dashed : true , draw : false } ) ) ;
423+
424+ // Y axes
425+ axes . add ( viewer . drawLine ( center , new THREE . Vector3 ( 0 , size , 0 ) , { color : y_color , dashed : false , draw : false } ) ) ;
426+ axes . add ( viewer . drawLine ( center , new THREE . Vector3 ( 0 , - size , 0 ) , { color : y_color , dashed : true , draw : false } ) ) ;
427+
428+ // Z axes
429+ axes . add ( viewer . drawLine ( center , new THREE . Vector3 ( 0 , 0 , size ) , { color : z_color , dashed : false , draw : false } ) ) ;
430+ axes . add ( viewer . drawLine ( center , new THREE . Vector3 ( 0 , 0 , - size ) , { color : z_color , dashed : true , draw : false } ) ) ;
431+
432+ if ( viewer . model ) {
433+ viewer . model . add ( axes ) ;
434+ } else {
435+ scene . add ( axes ) ;
436+ }
437+
438+ viewer . updated = true ;
439+
440+ return axes ;
441+ }
442+
338443 /**
339444 * @doc function
340445 * @name viewer.rendering:pick
0 commit comments