Skip to content

Commit b9abdb8

Browse files
author
Robert D Vincent
committed
Merge pull request #300 from natacha-beck/centric_rotation
First tries to recenter user model to origin
2 parents cf79ab1 + 9f06f53 commit b9abdb8

File tree

4 files changed

+196
-66
lines changed

4 files changed

+196
-66
lines changed

examples/surface-viewer-demo.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ <h4>Views:</h4>
191191
<p>
192192
<input id="axes-controls" type="checkbox">Display axes<br />
193193
</p>
194+
<p>
195+
<div>
196+
<input type="checkbox" id="model_centric"><label for="model_centric">Origin corresponds to model's center</label>
197+
</div>
198+
</p>
194199
<p>
195200
<a class="button" id="resetview">Reset View</a>
196201
<input type="checkbox" class="button" id="meshmode"><label for="meshmode">Mesh Mode</label>

examples/surface-viewer-demo.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ $(function() {
494494

495495
});
496496

497+
// Origin position
498+
$("#model_centric").change(function() {
499+
viewer.modelCentric($(this).is(":checked"));
500+
});
501+
497502
// Color map URLs are read from the config file and added to the
498503
// color map select box.
499504
var color_map_select = $('<select id="color-map-select"></select>').change(function() {
@@ -511,6 +516,7 @@ $(function() {
511516
viewer.clearScreen();
512517
current_request = 0;
513518
current_request_name = "";
519+
document.getElementById("model_centric").checked = false;
514520
loading_div.hide();
515521
});
516522

@@ -519,8 +525,8 @@ $(function() {
519525
if (viewer.model.children.length === 0) return;
520526

521527
var annotation_display = $("#annotation-display");
522-
var media = $("#annotation-media");
523-
var pick_info = viewer.pick();
528+
var media = $("#annotation-media");
529+
var pick_info = viewer.pick();
524530
var model_data, intensity_data;
525531
var annotation_info;
526532
var value, label, text;
@@ -532,8 +538,8 @@ $(function() {
532538
$("#pick-index").html(pick_info.index);
533539
$("#annotation-wrapper").show();
534540

535-
picked_object = pick_info.object;
536-
model_data = viewer.model_data.get(picked_object.userData.model_name);
541+
picked_object = pick_info.object;
542+
model_data = viewer.model_data.get(picked_object.userData.model_name);
537543
intensity_data = model_data.intensity_data[0];
538544

539545
if (intensity_data) {
@@ -634,9 +640,9 @@ $(function() {
634640
});
635641

636642
$("#annotation-save").click(function() {
637-
var vertex_num = parseInt($("#pick-index").html(), 10);
643+
var vertex_num = parseInt($("#pick-index").html(), 10);
638644
var annotation_display = $("#annotation-display");
639-
var media = $("#annotation-media");
645+
var media = $("#annotation-media");
640646

641647
var annotation, annotation_data;
642648
var vertex;
@@ -658,15 +664,15 @@ $(function() {
658664
vertex = viewer.getVertex(vertex_num);
659665

660666
annotation_data.image = $("#annotation-image").val();
661-
annotation_data.url = $("#annotation-url").val();
662-
annotation_data.text = $("#annotation-text").val();
667+
annotation_data.url = $("#annotation-url").val();
668+
annotation_data.text = $("#annotation-text").val();
663669

664670
media.html("");
665671

666672
if (annotation_data.image) {
667-
var image = new Image();
673+
var image = new Image();
668674
image.width = 200;
669-
image.src = annotation_data.image;
675+
image.src = annotation_data.image;
670676
annotation_display.show();
671677
media.append(image);
672678
}
@@ -914,7 +920,14 @@ $(function() {
914920
showLoading();
915921
viewer.loadModelFromFile(document.getElementById("objfile"), {
916922
format: format,
917-
complete: hideLoading
923+
complete: function() {
924+
document.getElementById("model_centric").checked = true;
925+
viewer.modelCentric(true);
926+
$("#vertex-data-wrapper").show();
927+
$("#pick-value-wrapper").show();
928+
$("#pick-label-wrapper").show();
929+
hideLoading();
930+
}
918931
});
919932

920933
return false;

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

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
164164
* function. The function will receive the model description and the model name
165165
* as arguments.
166166
* ```js
167-
* viewer.model_data.forEach(function(mode_data, model_name) {
167+
* viewer.model_data.forEach(function(model_data, model_name) {
168168
* console.log(model_name, model_data.vertices.length);
169169
* });
170170
* ```
@@ -363,9 +363,9 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
363363
////////////////////////////////////
364364

365365
function loadModel(data, filename, options) {
366-
options = options || {};
367-
var type = options.format || "mniobj";
368-
var parse_options = options.parse || {};
366+
options = options || {};
367+
var type = options.format || "mniobj";
368+
var parse_options = options.parse || {};
369369

370370
// Parse model info based on the given file type.
371371
parseModel(data, type, parse_options, function(model_data) {
@@ -376,12 +376,12 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
376376
}
377377

378378
function loadIntensityData(text, filename, options) {
379-
options = options || {};
380-
var name = options.name || filename;
381-
var type = options.format || "text";
382-
var blend = options.blend;
383-
var model_name = options.model_name;
384-
var model_data = viewer.model_data.get(model_name);
379+
options = options || {};
380+
var name = options.name || filename;
381+
var type = options.format || "text";
382+
var blend = options.blend;
383+
var model_name = options.model_name;
384+
var model_data = viewer.model_data.get(model_name);
385385
var intensity_data = model_data.intensity_data[0];
386386

387387
var old_range = {};
@@ -564,18 +564,18 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
564564
///////////////////////////////////////////
565565

566566
// Creates three.js objects based on the
567-
// description in **model_data** and
567+
// description in **model_data** and
568568
// displays in on the viewer.
569569
function displayModel(model_data, filename, options) {
570-
options = options || {};
570+
options = options || {};
571571
var complete = options.complete;
572572

573573
var new_shapes = createModel(model_data, filename, options);
574574

575575
viewer.triggerEvent("displaymodel", {
576-
model: viewer.model,
576+
model: viewer.model,
577577
model_data: model_data,
578-
new_shapes: new_shapes
578+
new_shapes: new_shapes,
579579
});
580580

581581
if (complete) complete();
@@ -586,13 +586,13 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
586586
// object, though they may share attributes and
587587
// buffers.
588588
function createModel(model_data, filename, options){
589-
var model = viewer.model;
590-
var shapes = model_data.shapes;
591-
var is_line = model_data.type === "line";
592-
var render_depth = options.render_depth;
593-
var pick_ignore = options.pick_ignore;
594-
var recenter = options.recenter || model_data.split;
595-
var new_shapes = [];
589+
var model = viewer.model;
590+
var shapes = model_data.shapes;
591+
var is_line = model_data.type === "line";
592+
var render_depth = options.render_depth;
593+
var pick_ignore = options.pick_ignore;
594+
var recenter = options.recenter || model_data.split;
595+
var new_shapes = [];
596596
var shape, shape_data;
597597
var i, count;
598598
var object_description = {is_line: is_line};
@@ -628,9 +628,9 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
628628

629629
object_description = {
630630
position: position_buffer,
631-
normal: normal_buffer,
632-
color: color_buffer,
633-
index: new THREE.BufferAttribute(new Uint32Array(shape_data.indices), 1),
631+
normal: normal_buffer,
632+
color: color_buffer,
633+
index: new THREE.BufferAttribute(new Uint32Array(shape_data.indices), 1),
634634
};
635635

636636
} else {
@@ -649,26 +649,26 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
649649

650650
object_description = {
651651
position: position_buffer,
652-
normal: normal_buffer,
653-
color: color_buffer
652+
normal: normal_buffer,
653+
color: color_buffer
654654
};
655655

656656
}
657657

658-
object_description.is_line = is_line;
658+
object_description.is_line = is_line;
659659
object_description.centroid = shape_data.centroid;
660660
object_description.recenter = recenter;
661661

662-
shape = createShape(object_description);
662+
shape = createShape(object_description);
663663
shape.name = shape_data.name || filename + "_" + (i + 1);
664664

665665
shape.userData.model_name = model_data.name;
666666

667667
shape.userData.original_data = {
668668
vertices: model_data.vertices,
669-
indices: shape_data.indices,
670-
normals: model_data.normals,
671-
colors: model_data.colors
669+
indices: shape_data.indices,
670+
normals: model_data.normals,
671+
colors: model_data.colors,
672672
};
673673

674674
shape.userData.pick_ignore = pick_ignore;
@@ -694,14 +694,14 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
694694
// a shape from the model data 'shapes'
695695
// array.
696696
function createShape(object_description) {
697-
var position = object_description.position;
697+
var position = object_description.position;
698698
var position_array = position.array;
699-
var normal = object_description.normal;
700-
var color = object_description.color;
701-
var index = object_description.index;
702-
var centroid = object_description.centroid;
703-
var is_line = object_description.is_line;
704-
var recenter = object_description.recenter;
699+
var normal = object_description.normal;
700+
var color = object_description.color;
701+
var index = object_description.index;
702+
var centroid = object_description.centroid;
703+
var is_line = object_description.is_line;
704+
var recenter = object_description.recenter;
705705

706706
var geometry = new THREE.BufferGeometry();
707707
var index_array, tmp_position_array, position_index;
@@ -748,10 +748,10 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
748748

749749
if (is_line) {
750750
material = new THREE.LineBasicMaterial({vertexColors: THREE.VertexColors});
751-
shape = new THREE.Line(geometry, material, THREE.LinePieces);
751+
shape = new THREE.Line(geometry, material, THREE.LinePieces);
752752
} else {
753753
material = new THREE.MeshPhongMaterial({color: 0xFFFFFF, ambient: 0xFFFFFF, specular: 0x101010, shininess: 150, vertexColors: THREE.VertexColors});
754-
shape = new THREE.Mesh(geometry, material);
754+
shape = new THREE.Mesh(geometry, material);
755755
shape.userData.has_wireframe = true;
756756
}
757757

0 commit comments

Comments
 (0)