Skip to content

Commit 60c2abc

Browse files
author
Robert D Vincent
committed
Merge pull request #283 from natacha-beck/add-axes-surf
Add axes surf
2 parents a26e233 + 682c419 commit 60c2abc

File tree

4 files changed

+166
-47
lines changed

4 files changed

+166
-47
lines changed

examples/surface-viewer-demo.html

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,15 @@ <h4>Background Color:</h4>
161161
<div id="views" class="box half_box" >
162162
<h4>Views:</h4>
163163
<div id="hem_views_1" class="half_box">
164-
<input id="left_hem_visible" class="visibility" data-hemisphere="left" type="checkbox" checked="true">Left
165-
<br />
166-
<input id="hem_superior" class="view_button" type="radio" name="hem_view" value="superior" checked="true">Superior
167-
168-
<br />
169-
<input id="hem_medial" class="view_button" type="radio" name="hem_view" value="medial">Medial
170-
171-
<br />
164+
<input id="left_hem_visible" class="visibility" data-hemisphere="left" type="checkbox" checked="true">Left<br />
165+
<input id="hem_superior" class="view_button" type="radio" name="hem_view" value="superior" checked="true">Superior<br />
166+
<input id="hem_medial" class="view_button" type="radio" name="hem_view" value="medial">Medial<br />
172167
<input id="hem_anterior" class="view_button" type="radio" name="hem_view" value="anterior">Anterior
173-
174168
</div>
175169
<div id="hem_views_2" class="half_box">
176170
<input id="right_hem_visible" class="visibility" data-hemisphere="right" type="checkbox" checked="true">Right<br />
177-
<input id="hem_inferior" class="view_button" type="radio" name="hem_view" value="inferior">Inferior
178-
<br />
179-
<input id="hem_lateral" class="view_button" type="radio" name="hem_view" value="lateral">Lateral
180-
<br />
171+
<input id="hem_inferior" class="view_button" type="radio" name="hem_view" value="inferior">Inferior<br />
172+
<input id="hem_lateral" class="view_button" type="radio" name="hem_view" value="lateral">Lateral<br />
181173
<input id="hem_posterior" class="view_button" type="radio" name="hem_view" value="posterior">Posterior
182174
</div>
183175
<p>
@@ -196,6 +188,9 @@ <h4>Views:</h4>
196188
<input type="checkbox" id="gridZ"><label for="gridZ">Z</label>
197189
</span>
198190
</p>
191+
<p>
192+
<input id="axes-controls" type="checkbox">Display axes<br />
193+
</p>
199194
<p>
200195
<a class="button" id="resetview">Reset View</a>
201196
<input type="checkbox" class="button" id="meshmode"><label for="meshmode">Mesh Mode</label>

examples/surface-viewer-demo.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ $(function() {
453453

454454
// If the grid already exists
455455
if (grid !== undefined) {
456-
grid.visible = is_checked;
456+
grid.visible = is_checked;
457457
viewer.updated = true;
458458
return;
459459
}
@@ -477,6 +477,23 @@ $(function() {
477477

478478
});
479479

480+
// Control Axes
481+
$("#axes-controls").change(function() {
482+
var axes_name = this.id;
483+
var is_checked = $(this).is(":checked");
484+
var axes = viewer.model.getObjectByName(axes_name);
485+
486+
// If the axes already exists
487+
if (axes !== undefined) {
488+
axes.visible = is_checked;
489+
viewer.updated = true;
490+
return;
491+
}
492+
493+
viewer.drawAxes(150, {name: axes_name});
494+
495+
});
496+
480497
// Color map URLs are read from the config file and added to the
481498
// color map select box.
482499
var color_map_select = $('<select id="color-map-select"></select>').change(function() {

src/brainbrowser/lib/color-map.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@
3131
/**
3232
* @doc function
3333
* @name BrainBrowser.static methods:createColorMap
34-
* @param {string} data The color map data as a string.
34+
* @param {string} data The color map data as a string.
3535
* @param {object} options Options for the color map.
3636
* Options include the following:
3737
*
3838
* * **clamp** {boolean} Should values be clamped to range?
3939
* * **flip** {boolean} Invert mapping?
4040
* * **scale** {number} Scale to use (usually 1 or 255).
41-
* * **contrast** {number} Color contrast.
42-
* * **brightness** {number} Extra intensity for colors.
43-
*
41+
* * **contrast** {number} Color contrast.
42+
* * **brightness** {number} Extra intensity for colors.
43+
*
4444
* @returns {object} Color map object.
45-
*
45+
*
4646
* @description
4747
* Factory function to produce color map object from a string of data. A given
4848
* color map is a set of colors to which intensity data can be mapped for display.
@@ -53,10 +53,10 @@
5353
BrainBrowser.createColorMap = function(data, options) {
5454
options = options || {};
5555

56-
var clamp = options.clamp === undefined ? true : options.clamp;
57-
var flip = options.flip || false;
58-
var scale = options.scale || 1;
59-
var contrast = options.contrast || 1;
56+
var clamp = options.clamp === undefined ? true : options.clamp;
57+
var flip = options.flip || false;
58+
var scale = options.scale || 1;
59+
var contrast = options.contrast || 1;
6060
var brightness = options.brightness || 0;
6161

6262
var color_map_colors;
@@ -90,7 +90,7 @@
9090
/**
9191
* @doc object
9292
* @name color_map
93-
*
93+
*
9494
* @description
9595
* Object representing the currently loaded color map.
9696
*/
@@ -114,12 +114,12 @@
114114
* * **clamp** {boolean} Should values be clamped to range (overrides color map default)?
115115
* * **flip** {boolean} Invert mapping (overrides color map default)?
116116
* * **scale** {number} Scale to use (usually 1 or 255, overrides color map default).
117-
* * **contrast** {number} Color contrast (overrides color map default).
118-
* * **brightness** {number} Extra intensity for colors (overrides color map default).
117+
* * **contrast** {number} Color contrast (overrides color map default).
118+
* * **brightness** {number} Extra intensity for colors (overrides color map default).
119119
* * **default_colors** {array} Colors to use if value is out of range.
120120
* * **destination** {array} Array to write the colors to (instead of creating
121-
* a new array).
122-
*
121+
* a new array).
122+
*
123123
* @returns {array} Colors modified based on options.
124124
*
125125
* @description
@@ -140,7 +140,7 @@
140140

141141
var color_map_colors = color_map.colors;
142142
var color_map_length = color_map.colors.length / 4;
143-
143+
144144
var scale = options.scale === undefined ? color_map.scale : options.scale;
145145
var clamp = options.clamp === undefined ? color_map.clamp : options.clamp;
146146
var flip = options.flip === undefined ? color_map.flip : options.flip;
@@ -154,7 +154,7 @@
154154
var default_color_offset = default_colors.length === 4 ? 0 : 1;
155155
var range = max - min;
156156
var increment = color_map_length / range;
157-
157+
158158
var value;
159159
var i, ic, idc, count;
160160
var color_map_index;
@@ -197,16 +197,16 @@
197197
* @param {object} options Options for the color mapping.
198198
* Options include the following:
199199
*
200-
* * **format** {string} Can be **float** for 0-1 range rgb array,
200+
* * **format** {string} Can be **float** for 0-1 range rgb array,
201201
* **255** for 0-255 range rgb array, or "hex" for a hex string.
202202
* * **min** {number} Minimum intensity value.
203203
* * **max** {number} Maximum intensity value.
204204
* * **clamp** {boolean} Should values be clamped to range (overrides color map default)?
205205
* * **flip** {boolean} Invert mapping (overrides color map default)?
206206
* * **scale** {number} Scale to use (usually 1 or 255, overrides color map default).
207-
* * **contrast** {number} Color contrast (overrides color map default).
208-
* * **brightness** {number} Extra intensity for colors (overrides color map default).
209-
*
207+
* * **contrast** {number} Color contrast (overrides color map default).
208+
* * **brightness** {number} Extra intensity for colors (overrides color map default).
209+
*
210210
* @returns {array|string} Color parsed from the value given.
211211
*
212212
* @description
@@ -236,7 +236,7 @@
236236
color_map.flip,
237237
color_map_length
238238
);
239-
239+
240240
var color;
241241

242242
if (color_map_index >= 0) {
@@ -273,7 +273,7 @@
273273
* @name color_map.color_map:createElement
274274
* @param {number} min Min value of the color data.
275275
* @param {number} max Max value of the color data.
276-
*
276+
*
277277
* @description
278278
* Create an element representing the color map.
279279
* ```js
@@ -285,8 +285,8 @@
285285
var context;
286286
var colors = color_map.colors;
287287
var range = max - min;
288-
289-
canvas = createCanvas(colors, 20, 40, flip);
288+
289+
canvas = createCanvas(colors, 20, 40, flip);
290290
context = canvas.getContext("2d");
291291

292292
context.fillStyle = "#FFA000";
@@ -334,7 +334,7 @@
334334
}
335335
}
336336

337-
// Creates an canvas with the color_map of colors
337+
// Creates a canvas with the color_map of colors
338338
// from low(left) to high(right) values
339339
// colors: array of colors
340340
// color_height: height of the color bar
@@ -346,13 +346,13 @@
346346
var context;
347347
var old_scale;
348348

349-
canvas.width = 256;
349+
canvas.width = 256;
350350
canvas.height = full_height;
351351

352352
for (i = 0; i < 256; i++) {
353353
value_array[i] = i;
354354
}
355-
355+
356356
old_scale = color_map.scale;
357357
color_map.scale = 255;
358358
colors = color_map.mapColors(value_array);
@@ -367,10 +367,9 @@
367367
}
368368

369369
return canvas;
370-
371370
}
372-
373-
371+
372+
374373

375374
return color_map;
376375

src/brainbrowser/surface-viewer/modules/rendering.js

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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,114 @@ 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+
* * **name** The name of the axes
395+
* * **center** A Vector3, that represent the orgin of the axes
396+
* * **x_color** The color of the line as a hexadecimal integer (default 0xff0000).
397+
* * **y_color** The color of the line as a hexadecimal integer (default 0x00ff00).
398+
* * **z_color** The color of the line as a hexadecimal integer (default 0x0000ff).
399+
* * **complete** If true draw postive (plain) and negative axes (dashed)
400+
*
401+
*
402+
* @returns {object} The axes itself.
403+
*
404+
* @description
405+
* Draw Axes in the current scene
406+
* ```js
407+
* viewer.drawAxes(300)
408+
* ```
409+
*/
410+
viewer.drawAxes = function(size, options) {
411+
size = size || 300;
412+
options = options || {};
413+
var name = options.name || "axes";
414+
var center = options.center || new THREE.Vector3(0,0,0);
415+
var x_color = options.x_color >= 0 ? options.x_color : 0xff0000 ;
416+
var y_color = options.y_color >= 0 ? options.y_color : 0x00ff00 ;
417+
var z_color = options.z_color >= 0 ? options.z_color : 0x0000ff ;
418+
var complete = options.complete === true;
419+
420+
var axes = new THREE.Object3D();
421+
axes.name = name;
422+
423+
// X axes
424+
axes.add(viewer.drawLine(center, new THREE.Vector3( size, 0, 0), {color: x_color, dashed: false, draw: false}));
425+
if (complete) { axes.add(viewer.drawLine(center, new THREE.Vector3(-size, 0, 0), {color: x_color, dashed: true , draw: false})); }
426+
427+
// Y axes
428+
axes.add(viewer.drawLine(center, new THREE.Vector3(0, size, 0), {color: y_color, dashed: false, draw: false}));
429+
if (complete) { axes.add(viewer.drawLine(center, new THREE.Vector3(0, -size, 0), {color: y_color, dashed: true, draw: false})); }
430+
431+
// Z axes
432+
axes.add(viewer.drawLine(center, new THREE.Vector3(0, 0, size), {color: z_color, dashed: false, draw: false}));
433+
if (complete) { axes.add(viewer.drawLine(center, new THREE.Vector3(0, 0, -size), {color: z_color, dashed: true, draw: false})); }
434+
435+
if (viewer.model) {
436+
viewer.model.add(axes);
437+
} else {
438+
scene.add(axes);
439+
}
440+
441+
viewer.updated = true;
442+
443+
return axes;
444+
};
445+
338446
/**
339447
* @doc function
340448
* @name viewer.rendering:pick

0 commit comments

Comments
 (0)