Skip to content

Commit

Permalink
Merge pull request #322 from rdvincent/rdv-gifti
Browse files Browse the repository at this point in the history
Fix #321: Add support for GIFTI surfaces and vertex data.
  • Loading branch information
natacha-beck authored Nov 25, 2016
2 parents 8ca39ce + 33af6b4 commit 0d3ac3e
Show file tree
Hide file tree
Showing 9 changed files with 13,766 additions and 6 deletions.
11 changes: 9 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ module.exports = function(grunt) {
"<%= build_dir %>/workers/freesurferbin.intensity.worker.js": "src/brainbrowser/workers/freesurferbin.intensity.worker.js",
"<%= build_dir %>/workers/freesurferasc.intensity.worker.js": "src/brainbrowser/workers/freesurferasc.intensity.worker.js",
"<%= build_dir %>/workers/deindex.worker.js": "src/brainbrowser/workers/deindex.worker.js",
"<%= build_dir %>/workers/wireframe.worker.js": "src/brainbrowser/workers/wireframe.worker.js"
"<%= build_dir %>/workers/wireframe.worker.js": "src/brainbrowser/workers/wireframe.worker.js",
"<%= build_dir %>/workers/gifti.worker.js": "src/brainbrowser/workers/gifti.worker.js",
"<%= build_dir %>/workers/gifti-reader.js": "src/brainbrowser/workers/gifti-reader.js"

}
}
},
Expand Down Expand Up @@ -139,10 +142,14 @@ module.exports = function(grunt) {
globals: {
Float32Array: true,
Uint32Array: true,
gifti: true,
DataView: true
}
},
src: ["src/brainbrowser/workers/*.js"]
src: [
"src/brainbrowser/workers/*.js",
"!src/brainbrowser/workers/gifti-reader.js"
]
},
examples: {
options: {
Expand Down
2 changes: 2 additions & 0 deletions examples/surface-viewer-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ <h4>Load your own data!</h4>
<option value="freesurferasc">Freesurfer ASC</option>
<option value="wavefrontobj">Wavefront OBJ</option>
<option value="json">JSON</option>
<option value="gifti">GIFTI</option>
</select><br>
<div class="format-hint"></div>
<div id="obj_file_submit_div" class="file-submit-div">
Expand All @@ -124,6 +125,7 @@ <h4>Load your own data!</h4>
<option value="text">Text</option>
<option value="freesurferbin">Freesurfer Binary</option>
<option value="freesurferasc">Freesurfer ASC</option>
<option value="gifti">GIFTI</option>
</select><br>
<div class="format-hint"></div>
<div id="data-submit-div" class="file-submit-div">
Expand Down
16 changes: 14 additions & 2 deletions src/brainbrowser/lib/color-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,27 @@

if (data) {
lines = data.trim().split(/\n/);
color_map_colors = new Float32Array(lines.length * 4);
color_map_colors = [];
ic = 0;

for (i = 0, line_count = lines.length; i < line_count; i++) {
color = lines[i].trim().split(/\s+/).slice(0, 4);
color = lines[i].trim().split(/\s+/).slice(0, 5);
line_length = color.length;

if (line_length < 3) continue;

if (line_length > 4) {
/* Sparse colour map. The first column gives the
* label to associate with the colour, the remaining
* 4 columns give the RGBA values to associate with
* the label.
*/
ic = parseInt(color[0], 10);
ic *= 4;
line_length = 4;
color = color.slice(1, 5);
}

for (j = 0; j < line_length; j++) {
color_map_colors[ic + j] = parseFloat(color[j]);
}
Expand Down
19 changes: 19 additions & 0 deletions src/brainbrowser/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@
return window.URL.createObjectURL(new Blob([data], {type : mime_type || "text/plain"}));
},

/**
* @doc function
* @name BrainBrowser.utils:getWorkerImportURL
*
* @description
* Assemble an absolute path for possible script imports within
* a worker.
*/
getWorkerImportURL: function() {
var worker_dir = BrainBrowser.config.get("worker_dir");
var import_url = document.location.origin + '/' + worker_dir;
var doc_href = document.location.href;
var slash_index = doc_href.lastIndexOf('/');
if (slash_index >= 0) {
import_url = doc_href.substring(0, slash_index + 1) + worker_dir;
}
return import_url;
},

/**
* @doc function
* @name BrainBrowser.utils:min
Expand Down
3 changes: 3 additions & 0 deletions src/brainbrowser/surface-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,13 @@
BrainBrowser.config.set("model_types.freesurferbin.worker", "freesurferbin.worker.js");
BrainBrowser.config.set("model_types.freesurferbin.binary", true);
BrainBrowser.config.set("model_types.freesurferasc.worker", "freesurferasc.worker.js");
BrainBrowser.config.set("model_types.gifti.worker", "gifti.worker.js");

BrainBrowser.config.set("intensity_data_types.text.worker", "text.intensity.worker.js");
BrainBrowser.config.set("intensity_data_types.freesurferbin.worker", "freesurferbin.intensity.worker.js");
BrainBrowser.config.set("intensity_data_types.freesurferbin.binary", true);
BrainBrowser.config.set("intensity_data_types.freesurferasc.worker", "freesurferasc.intensity.worker.js");
BrainBrowser.config.set("intensity_data_types.gifti.worker", "gifti.worker.js");

// Build worker URLs and attempt to inline
// them using Blob URLs if possible.
Expand Down
3 changes: 2 additions & 1 deletion src/brainbrowser/surface-viewer/lib/parse-intensity-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ BrainBrowser.SurfaceViewer.parseIntensityData = function(data, type, callback) {
worker.terminate();
});

worker.postMessage({ cmd: "parse", data: data });
var url = BrainBrowser.utils.getWorkerImportURL();
worker.postMessage({ cmd: "parse", data: data, url: url });
};
8 changes: 7 additions & 1 deletion src/brainbrowser/surface-viewer/modules/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
var min;
var max;

if (intensity_data.colors) {
loadColorMap(BrainBrowser.createColorMap(intensity_data.colors));
}

if (viewer.getAttribute("fix_color_range") &&
old_range.min !== undefined && old_range.max !== undefined) {
min = old_range.min;
Expand Down Expand Up @@ -518,9 +522,11 @@ BrainBrowser.SurfaceViewer.modules.loading = function(viewer) {
parse_worker.terminate();
});

var import_url = BrainBrowser.utils.getWorkerImportURL();
parse_worker.postMessage({
data: data,
options: options
options: options,
url: import_url
});

}
Expand Down
Loading

0 comments on commit 0d3ac3e

Please sign in to comment.