Skip to content

Fix #194 and #15. Use world coordinates for synchronization. #275

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

Merged
merged 1 commit into from
Oct 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion examples/volume-viewer-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,14 @@ $(function() {
}

// Set coordinates and redraw.
viewer.volumes[vol_id].setWorldCoords(x, y, z);
if (viewer.synced) {
viewer.volumes.forEach(function(volume) {
volume.setWorldCoords(x, y, z);
});
}
else {
viewer.volumes[vol_id].setWorldCoords(x, y, z);
}

viewer.redrawVolumes();
});
Expand All @@ -298,6 +305,15 @@ $(function() {

// Set coordinates and redraw.
viewer.volumes[vol_id].setVoxelCoords(i, j, k);
if (viewer.synced) {
var synced_volume = viewer.volumes[vol_id];
var wc = synced_volume.getWorldCoords();
viewer.volumes.forEach(function(volume) {
if (synced_volume !== volume) {
volume.setWorldCoords(wc.x, wc.y, wc.z);
}
});
}

viewer.redrawVolumes();
});
Expand Down
17 changes: 1 addition & 16 deletions src/brainbrowser/volume-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@

var key = event.which;
var space_name, time;
var cursor;

var keys = {
// CTRL
Expand Down Expand Up @@ -472,21 +471,7 @@
});

if (viewer.synced){
cursor = panel.getCursorPosition();

viewer.volumes.forEach(function(synced_volume) {
var synced_panel;

if (synced_volume !== volume) {
synced_panel = synced_volume.display.getPanel(axis_name);
synced_panel.updateVolumePosition(cursor.x, cursor.y);
synced_volume.display.forEach(function(panel) {
if (panel !== synced_panel) {
panel.updateSlice();
}
});
}
});
viewer.syncPosition(panel, volume, axis_name);
}

return false;
Expand Down
47 changes: 19 additions & 28 deletions src/brainbrowser/volume-viewer/modules/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,22 @@ BrainBrowser.VolumeViewer.modules.loading = function(viewer) {
default_panel_height = height;
};

viewer.syncPosition = function(panel, volume, axis_name) {
var wc = volume.getWorldCoords();
viewer.volumes.forEach(function(synced_volume) {
if (synced_volume !== volume) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can directly return:
if (synced_volume === volume) return ;

var synced_panel = synced_volume.display.getPanel(axis_name);
synced_panel.volume.setWorldCoords(wc.x, wc.y, wc.z);
synced_panel.updated = true;
synced_volume.display.forEach(function(panel) {
if (panel !== synced_panel) {
panel.updateSlice();
}
});
}
});
};

///////////////////////////
// Private Functions
///////////////////////////
Expand Down Expand Up @@ -533,22 +549,9 @@ BrainBrowser.VolumeViewer.modules.loading = function(viewer) {
});

if (viewer.synced){
viewer.volumes.forEach(function(synced_volume, synced_vol_id) {
var synced_panel;

if (synced_vol_id !== vol_id) {
synced_panel = synced_volume.display.getPanel(axis_name);
synced_panel.updateVolumePosition(pointer.x, pointer.y);
synced_volume.display.forEach(function(panel) {
if (panel !== synced_panel) {
panel.updateSlice();
}
});
}
});
viewer.syncPosition(panel, volume, axis_name);
}
}

panel.updated = true;
}

Expand Down Expand Up @@ -576,19 +579,7 @@ BrainBrowser.VolumeViewer.modules.loading = function(viewer) {
});

if (viewer.synced){
viewer.volumes.forEach(function(synced_volume, synced_vol_id) {
var synced_panel;

if (synced_vol_id !== vol_id) {
synced_panel = synced_volume.display.getPanel(axis_name);
synced_panel.updateVolumePosition(pointer.x, pointer.y);
synced_volume.display.forEach(function(panel) {
if (panel !== synced_panel) {
panel.updateSlice();
}
});
}
});
viewer.syncPosition(panel, volume, axis_name);
}
}

Expand Down Expand Up @@ -736,4 +727,4 @@ BrainBrowser.VolumeViewer.modules.loading = function(viewer) {

return display;
}
};
};
67 changes: 39 additions & 28 deletions src/brainbrowser/volume-viewer/volume-loaders/minc.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
VolumeViewer.createVolume = function(header, byte_data) {
var image_creation_context = document.createElement("canvas").getContext("2d");
var cached_slices = {};

// Populate the header with the universal fields.
finishHeader(header);

var volume = {
position: {},
current_time: 0,
Expand Down Expand Up @@ -356,17 +360,41 @@

function createMincVolume(header, raw_data, callback){
var volume = VolumeViewer.createVolume(header, new Uint8Array(raw_data));
volume.type = "minc";

volume.saveOriginAndTransform(header);
if (BrainBrowser.utils.isFunction(callback)) {
callback(volume);
}
}

/*
* Creates common fields all headers must contain.
*/
function finishHeader(header) {
header.xspace.name = "xspace";
header.yspace.name = "yspace";
header.zspace.name = "zspace";

header.xspace.width_space = header.yspace;
header.xspace.width = header.yspace.space_length;
header.xspace.height_space = header.zspace;
header.xspace.height = header.zspace.space_length;

header.yspace.width_space = header.xspace;
header.yspace.width = header.xspace.space_length;
header.yspace.height_space = header.zspace;
header.yspace.height = header.zspace.space_length;

header.zspace.width_space = header.xspace;
header.zspace.width = header.xspace.space_length;
header.zspace.height_space = header.yspace;
header.zspace.height = header.yspace.space_length;
}

function parseHeader(header_text, callback) {
var header;
var error_message;
var startx, starty, startz, cx, cy, cz;

try{
header = JSON.parse(header_text);
Expand All @@ -378,22 +406,17 @@
throw new Error(error_message);
}


if(header.order.length === 4) {
header.order = header.order.slice(1);
}

header.xspace.name = "xspace";
header.yspace.name = "yspace";
header.zspace.name = "zspace";

header.xspace.space_length = parseFloat(header.xspace.space_length);
header.yspace.space_length = parseFloat(header.yspace.space_length);
header.zspace.space_length = parseFloat(header.zspace.space_length);

startx = header.xspace.start = parseFloat(header.xspace.start);
starty = header.yspace.start = parseFloat(header.yspace.start);
startz = header.zspace.start = parseFloat(header.zspace.start);
header.xspace.start = parseFloat(header.xspace.start);
header.yspace.start = parseFloat(header.yspace.start);
header.zspace.start = parseFloat(header.zspace.start);

header.xspace.step = parseFloat(header.xspace.step);
header.yspace.step = parseFloat(header.yspace.step);
Expand All @@ -403,26 +426,14 @@
header.yspace.direction_cosines = header.yspace.direction_cosines || [0, 1, 0];
header.zspace.direction_cosines = header.zspace.direction_cosines || [0, 0, 1];

cx = header.xspace.direction_cosines = header.xspace.direction_cosines.map(parseFloat);
cy = header.yspace.direction_cosines = header.yspace.direction_cosines.map(parseFloat);
cz = header.zspace.direction_cosines = header.zspace.direction_cosines.map(parseFloat);

header.xspace.width_space = header.yspace;
header.xspace.width = header.yspace.space_length;
header.xspace.height_space = header.zspace;
header.xspace.height = header.zspace.space_length;

header.yspace.width_space = header.xspace;
header.yspace.width = header.xspace.space_length;
header.yspace.height_space = header.zspace;
header.yspace.height = header.zspace.space_length;

header.zspace.width_space = header.xspace;
header.zspace.width = header.xspace.space_length;
header.zspace.height_space = header.yspace;
header.zspace.height = header.yspace.space_length;
header.xspace.direction_cosines = header.xspace.direction_cosines.map(parseFloat);
header.yspace.direction_cosines = header.yspace.direction_cosines.map(parseFloat);
header.zspace.direction_cosines = header.zspace.direction_cosines.map(parseFloat);

// Incrementation offsets for each dimension of the volume.
/* Incrementation offsets for each dimension of the volume.
* Note that this somewhat format-specific, so it does not
* belong in the generic "createVolume()" code.
*/
header[header.order[0]].offset = header[header.order[1]].space_length * header[header.order[2]].space_length;
header[header.order[1]].offset = header[header.order[2]].space_length;
header[header.order[2]].offset = 1;
Expand Down
27 changes: 1 addition & 26 deletions src/brainbrowser/volume-viewer/volume-loaders/nifti1.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
function createNifti1Volume(header, raw_data, callback) {
var volume = VolumeViewer.createVolume(header,
createNifti1Data(header, raw_data));

volume.type = "nifti";
volume.saveOriginAndTransform(header);
if (BrainBrowser.utils.isFunction(callback)) {
callback(volume);
Expand Down Expand Up @@ -412,31 +412,6 @@
header.order = header.order.slice(1);
}

header.xspace.name = "xspace";
header.yspace.name = "yspace";
header.zspace.name = "zspace";

header.voxel_origin = {
x: header.xspace.start,
y: header.yspace.start,
z: header.zspace.start
};

header.xspace.width_space = header.yspace;
header.xspace.width = header.yspace.space_length;
header.xspace.height_space = header.zspace;
header.xspace.height = header.zspace.space_length;

header.yspace.width_space = header.xspace;
header.yspace.width = header.xspace.space_length;
header.yspace.height_space = header.zspace;
header.yspace.height = header.zspace.space_length;

header.zspace.width_space = header.xspace;
header.zspace.width = header.xspace.space_length;
header.zspace.height_space = header.yspace;
header.zspace.height = header.yspace.space_length;

// Incrementation offsets for each dimension of the volume.
header[header.order[0]].offset = header[header.order[1]].space_length * header[header.order[2]].space_length;
header[header.order[1]].offset = header[header.order[2]].space_length;
Expand Down
Loading