Skip to content
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

2D color maps (reopened to pull from master) #197

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions io/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,9 @@ X.loader.prototype.load = function(container, object) {
// configure the URL
request.open('GET', filepath, true);
request.responseType = 'arraybuffer';

// .. and GO!
request.send(null);

};


Expand Down Expand Up @@ -293,6 +292,11 @@ X.loader.prototype.parse = function(request, container, object) {
// call the parse function and pass in the container, the object and the
// data stream and some additional value
_parser.parse(container, object, _data, flags);

var event = document.createEvent("HTMLEvents");
event.initEvent("parsingComplete", true, true);
event.eventName = "parsingComplete";
document.documentElement.dispatchEvent(event);

}.bind(this), 100);

Expand Down Expand Up @@ -323,12 +327,14 @@ X.loader.prototype.complete = function(event) {

// .. but mark the container as dirty since its content changed
container._dirty = true;

// fire the modified event on the object
object.modified();


// mark the loading job as completed
this._jobs.set(container._id, true);

// fire the modified event on the object if all loading jobs complete
if (this.completed()) {
object.modified();
}

}.bind(this), 100);

Expand Down
37 changes: 31 additions & 6 deletions io/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,12 @@ X.parser.xyBBox = function(_solutionsXY){
* @param {!X.object} object The X.volume.
* @param {!boolean} hasLabelMap Volume has labelmap attached.
* @param {goog.structs.Map} colorTable Associated color table.
* @param {Function} colormap Function mapping from labelmap pixel intensity to rgba.
*
* @return The target slice.
* @static
*/
X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color, _bbox, _IJKVolume, object, hasLabelMap, colorTable){
X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color, _bbox, _IJKVolume, object, hasLabelMap, colorTable, colormap){

var sliceXY = new X.slice();

Expand Down Expand Up @@ -913,7 +914,7 @@ X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color
// check for out of range and use the last label value in this case
if (!lookupValue) {

lookupValue = [ 0, .61, 0, 0, 1 ];
lookupValue = [ 0, 0.61, 0, 0, 1 ];

}

Expand All @@ -923,6 +924,14 @@ X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color
pixelValue_a = 255 * lookupValue[4];

}
// else if (colormap) {
// // colormap should be function taking value between 0 and 1 and returning rgba values [0,255]
// var mapColor = colormap((pixval - object._min) / (object._max - object._min));
// pixelValue_r = mapColor[0];
// pixelValue_g = mapColor[1];
// pixelValue_b = mapColor[2];
// pixelValue_a = mapColor[3];
// }
else {
// normalization should not happen here, only in the shaders/canvas??
pixelValue_r = pixelValue_g = pixelValue_b = 255 * ((pixval - object._min )/ (object._max - object._min));
Expand Down Expand Up @@ -1155,7 +1164,8 @@ X.parser.prototype.reslice = function(object) {
// ------------------------------------------
// SETUP LABEL MAPS AND COLOR TABLES
// ------------------------------------------
object.hasLabelMap = object._labelmap != null;
object.hasLabelMap = object._labelmap != null && !goog.isArray(object._labelmap);
object.hasLabelMapArray = object._labelmap != null && goog.isArray(object._labelmap);
if (object._colortable) {
object._colorTable = object._colortable._map;
}
Expand Down Expand Up @@ -1214,13 +1224,18 @@ X.parser.prototype.reslice = function(object) {
_sliceOrigin[1] = object._childrenInfo[0]._solutionsLine[0][0][1] + object._childrenInfo[0]._sliceDirection[1]*Math.floor(object._childrenInfo[0]._nb/2);
_sliceOrigin[2] = object._childrenInfo[0]._solutionsLine[0][0][2] + object._childrenInfo[0]._sliceDirection[2]*Math.floor(object._childrenInfo[0]._nb/2);

var _slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[0]._sliceXYSpacing, object._childrenInfo[0]._sliceNormal, object._childrenInfo[0]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable);
var _slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[0]._sliceXYSpacing, object._childrenInfo[0]._sliceNormal, object._childrenInfo[0]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable, object._colormap);

if (object.hasLabelMap) {
// if this object has a labelmap,
// we have it loaded at this point (for sure)
// ..so we can attach it as the second texture to this slice
_slice._labelmap = object._labelmap._children[0]._children[Math.floor(object._childrenInfo[0]._nb/2)]._texture;
} else if (object.hasLabelMapArray) {
_slice._labelmap = [];
for (var i=0; i<object._labelmap.length; i++) {
_slice._labelmap.push(object._labelmap[i]._children[0]._children[Math.floor(object._childrenInfo[0]._nb/2)]._texture);
}
}

object._children[0]._children[Math.floor(object._childrenInfo[0]._nb/2)] = _slice;
Expand Down Expand Up @@ -1261,13 +1276,18 @@ X.parser.prototype.reslice = function(object) {
_sliceOrigin[1] = object._childrenInfo[1]._solutionsLine[0][0][1] + object._childrenInfo[1]._sliceDirection[1]*Math.floor(object._childrenInfo[1]._nb/2);
_sliceOrigin[2] = object._childrenInfo[1]._solutionsLine[0][0][2] + object._childrenInfo[1]._sliceDirection[2]*Math.floor(object._childrenInfo[1]._nb/2);

_slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[1]._sliceXYSpacing, object._childrenInfo[1]._sliceNormal, object._childrenInfo[1]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable);
_slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[1]._sliceXYSpacing, object._childrenInfo[1]._sliceNormal, object._childrenInfo[1]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable, object._colormap);

if (object.hasLabelMap) {
// if this object has a labelmap,
// we have it loaded at this point (for sure)
// ..so we can attach it as the second texture to this slice
_slice._labelmap = object._labelmap._children[1]._children[Math.floor(object._childrenInfo[1]._nb/2)]._texture;
} else if (object.hasLabelMapArray) {
_slice._labelmap = [];
for (var i=0; i<object._labelmap.length; i++) {
_slice._labelmap.push(object._labelmap[i]._children[1]._children[Math.floor(object._childrenInfo[1]._nb/2)]._texture);
}
}

object._children[1]._children[Math.floor(object._childrenInfo[1]._nb/2)] = _slice;
Expand Down Expand Up @@ -1307,13 +1327,18 @@ X.parser.prototype.reslice = function(object) {
_sliceOrigin[1] = object._childrenInfo[2]._solutionsLine[0][0][1] + object._childrenInfo[2]._sliceDirection[1]*Math.floor(object._childrenInfo[2]._nb/2);
_sliceOrigin[2] = object._childrenInfo[2]._solutionsLine[0][0][2] + object._childrenInfo[2]._sliceDirection[2]*Math.floor(object._childrenInfo[2]._nb/2);

_slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[2]._sliceXYSpacing, object._childrenInfo[2]._sliceNormal, object._childrenInfo[2]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable);
_slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[2]._sliceXYSpacing, object._childrenInfo[2]._sliceNormal, object._childrenInfo[2]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable, object._colormap);

if (object.hasLabelMap) {
// if this object has a labelmap,
// we have it loaded at this point (for sure)
// ..so we can attach it as the second texture to this slice
_slice._labelmap = object._labelmap._children[2]._children[Math.floor(object._childrenInfo[2]._nb/2)]._texture;
} else if (object.hasLabelMapArray) {
_slice._labelmap = [];
for (var i=0; i<object._labelmap.length; i++) {
_slice._labelmap.push(object._labelmap[i]._children[2]._children[Math.floor(object._childrenInfo[2]._nb/2)]._texture);
}
}

object._children[2]._children[Math.floor(object._childrenInfo[2]._nb/2)] = _slice;
Expand Down
175 changes: 175 additions & 0 deletions math/vector4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
*
* xxxxxxx xxxxxxx
* x:::::x x:::::x
* x:::::x x:::::x
* x:::::xx:::::x
* x::::::::::x
* x::::::::x
* x::::::::x
* x::::::::::x
* x:::::xx:::::x
* x:::::x x:::::x
* x:::::x x:::::x
* THE xxxxxxx xxxxxxx TOOLKIT
*
* http://www.goXTK.com
*
* Copyright (c) 2012 The X Toolkit Developers <dev@goXTK.com>
*
* The X Toolkit (XTK) is licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
* "Free software" is a matter of liberty, not price.
* "Free" as in "free speech", not as in "free beer".
* - Richard M. Stallman
*
*
*/
// provides
goog.provide('X.vector4');

// requires
goog.require('goog.vec.Vec4');


// expose the following goog.math.Vec3 functionality
/**
* @constructor
* @see goog.math.Vec3
*/
X.vector4 = goog.vec.Vec4;


// /**
// * @see goog.math.Vec3.prototype.clone
// */
// X.vector.prototype.clone = goog.math.Vec3.prototype.clone;
//
//
// /**
// * @see goog.math.Vec3.prototype.magnitude
// */
// X.vector.prototype.magnitude = goog.math.Vec3.prototype.magnitude;
//
//
// /**
// * @see goog.math.Vec3.prototype.scale
// */
// X.vector.prototype.scale = goog.math.Vec3.prototype.scale;
//
//
// /**
// * @see goog.math.Vec3.prototype.invert
// */
// X.vector.prototype.invert = goog.math.Vec3.prototype.invert;
//
//
// /**
// * @see goog.math.Vec3.prototype.add
// */
// X.vector.prototype.add = goog.math.Vec3.prototype.add;
//
//
// /**
// * @see goog.math.Vec3.prototype.subtract
// */
// X.vector.prototype.subtract = goog.math.Vec3.prototype.subtract;
//
//
// /**
// * Normalize the vector. The goog.math.Vec3.prototype.normalize
// * did not check on a magnitude of 0 resulting in an error.
// *
// * @return {!X.vector|!goog.math.Vec3} The normalized vector.
// */
// X.vector.prototype.normalize = function() {
// // add a special check if the magnitude is 0
// var _magnitude = this.magnitude();
// if (_magnitude == 0) {
// return this.scale(0);
// }
// return this.scale(1 / _magnitude);
// };
//
//
// /**
// * @see goog.math.Vec3.dot
// */
// X.vector.dot = goog.math.Vec3.dot;
//
//
// /**
// * @see goog.math.Vec3.cross
// */
// X.vector.cross = goog.math.Vec3.cross;
//
//
// /**
// * @see goog.math.Vec3.distance
// */
// X.vector.distance = goog.math.Vec3.distance;
//
//
// /**
// * @see goog.math.Vec3.lerp
// */
// X.vector.lerp = goog.math.Vec3.lerp;

// // now we need to make sure we can access the x,y,z
// // components of a goog.math.Vec3 which might be renamed
// // during the compilation. we don't want to modify the goog.math.Vec3
// // class so this is the easiest workaround.
// /**
// * Get the x component of this vector.
// *
// * @return {number} The x component of this vector.
// * @public
// */
// X.vector4.prototype.__defineGetter__('xx', function() {
//
// return this.x;
//
// });
//
//
// /**
// * Get the y component of this vector.
// *
// * @return {number} The y component of this vector.
// * @public
// */
// X.vector4.prototype.__defineGetter__('yy', function() {
//
// return this.y;
//
// });
//
//
// /**
// * Get the z component of this vector.
// *
// * @return {number} The z component of this vector.
// * @public
// */
// X.vector4.prototype.__defineGetter__('zz', function() {
//
// return this.z;
//
// });


goog.exportSymbol('X.vector4', X.vector4);
goog.exportSymbol('X.vector4.createFloat32FromValues', X.vector4.createFloat32FromValues);
goog.exportSymbol('X.vector4.createFloat32', X.vector4.createFloat32);
// goog.exportSymbol('X.vector.prototype.clone', X.vector.prototype.clone);
// goog.exportSymbol('X.vector.prototype.magnitude', X.vector.prototype.magnitude);
// goog.exportSymbol('X.vector.prototype.scale', X.vector.prototype.scale);
// goog.exportSymbol('X.vector.prototype.invert', X.vector.prototype.invert);
// goog.exportSymbol('X.vector.prototype.normalize', X.vector.prototype.normalize);
// goog.exportSymbol('X.vector.prototype.add', X.vector.prototype.add);
// goog.exportSymbol('X.vector.prototype.subtract', X.vector.prototype.subtract);
// goog.exportSymbol('X.vector.dot', X.vector.dot);
// goog.exportSymbol('X.vector.cross', X.vector.cross);
// goog.exportSymbol('X.vector.distance', X.vector.distance);
// goog.exportSymbol('X.vector.lerp', X.vector.lerp);
1 change: 0 additions & 1 deletion objects/labelmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ X.labelmap.prototype.modified = function() {

};


/**
* Show only the label with the given value or color (RGBA 0..1). If null is passed,
* show all labels.
Expand Down