Skip to content

Commit

Permalink
Support the X.volume.labelmap.showOnly property in a X.renderer2D.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Haehn committed Apr 18, 2013
1 parent b6b0e2b commit feb5c46
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 60 deletions.
141 changes: 84 additions & 57 deletions math/array.js
@@ -1,30 +1,30 @@
/*
*
*
* 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
* 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.array');
Expand All @@ -35,7 +35,7 @@ goog.require('X.base');

/**
* Create an array which can be sorted in-place using merge sort.
*
*
* @constructor
* @param {Function} comparator
* @extends X.base
Expand All @@ -45,49 +45,76 @@ X.array = function(comparator) {
//
// call the standard constructor
goog.base(this);

//
// class attributes

/**
* @inheritDoc
* @const
*/
this._classname = 'array';

/**
* The underlying array.
*
*
* @type {!Array}
* @protected
*/
this._array = [];

/**
* The void pointer to a comparator function.
*
*
* @type {Function}
* @protected
*/
this._comparator = comparator;

};
// inherit from goog.math.Matrix
goog.inherits(X.array, X.base);


/**
* Compare two arrays element by element.
*
* The length defines the range of comparison starting
* from offset1 for the first array and offset2 for the
* second array.
*
* @param {!Array|Float32Array} arr1 The first array.
* @param {!Array|Float32Array} arr2 The second array.
* @param {!number} offset1 The index offset of the first array.
* @param {!number} offset2 The index offset of the second array.
* @param {!number} _length The length for both arrays.
* @return {boolean} TRUE if equal, FALSE if not equal.
*/
X.array.compare = function(arr1, arr2, offset1, offset2, _length) {

for(var i = 0; i < _length; i++) {
if(arr1[i + offset1] !== arr2[i + offset2]) {
return false;
}
}

return true;

};


/**
* Add an object to the array.
*
*
* @param {*} object The object to add.
* @return {boolean} TRUE if everything went fine.
*/
X.array.prototype.add = function(object) {

this._array.push(object);

return true;

};


Expand Down Expand Up @@ -118,30 +145,30 @@ X.array.prototype.remove = function(object) {
X.array.prototype.clear = function() {

this._array.length = 0;

};


/**
* Swap two elements in the array.
*
*
* @param {!number} index1 Index of element1.
* @param {!number} index2 Index of element2.
*/
X.array.prototype.swap_ = function(index1, index2) {

var tmp = this._array[index1];

this._array[index1] = this._array[index2];

this._array[index2] = tmp;

};


/**
* Orderly insert an element. This is part of the in-place sorting.
*
*
* @param {!number} begin The start index.
* @param {!number} end The end index.
* @param {*} v The value/object to insert.
Expand All @@ -151,68 +178,68 @@ X.array.prototype.insert_ = function(begin, end, v) {
// SOME COMPARISON
// while (begin + 1 < end && this._array[begin + 1] < v) {
while (begin + 1 < end && this._comparator(this._array[begin + 1], v) < 0) {

this.swap_(begin, begin + 1);

++begin;

}

this._array[begin] = v;

};


/**
* Merge component of the in-place sorting.
*
*
* @param {!number} begin The start index.
* @param {!number} begin_right The start index from the right.
* @param {!number} end The end index.
*/
X.array.prototype.merge_inplace_ = function(begin, begin_right, end) {

for (; begin < begin_right; ++begin) {

// SOME COMPARISON
// if (this._array[begin] > this._array[begin_right]) {
if (this._comparator(this._array[begin], this._array[begin_right]) > 0) {

var v = this._array[begin];

this._array[begin] = this._array[begin_right];

this.insert_(begin_right, end, v);

}

}

};


/**
* Recursive function to perform in-place merge sort.
*
*
* @param {!number} begin The start index.
* @param {!number} end The end index.
*/
X.array.prototype.msort_ = function(begin, end) {

var size = end - begin;

if (size < 2) {
return;
}

var begin_right = begin + Math.floor(size / 2);

this.msort_(begin, begin_right);

this.msort_(begin_right, end);

this.merge_inplace_(begin, begin_right, end);

};


Expand All @@ -222,17 +249,17 @@ X.array.prototype.msort_ = function(begin, end) {
X.array.prototype.sort = function() {

this.msort_(0, this._array.length);

};


/**
* Get the complete array.
*
*
* @return {!Array} The complete array.
*/
X.array.prototype.values = function() {

return this._array;

};
53 changes: 50 additions & 3 deletions visualization/renderer2D.js
Expand Up @@ -192,6 +192,14 @@ X.renderer2D = function() {
*/
this._windowHigh = -1;

/**
* The buffer of the showOnly labelmap color.
*
* @type {!Float32Array}
* @protected
*/
this._labelmapShowOnlyColor = new Float32Array([-255, -255, -255, -255]);

};
// inherit from X.base
goog.inherits(X.renderer2D, X.renderer);
Expand Down Expand Up @@ -759,6 +767,17 @@ X.renderer2D.prototype.render_ = function(picking, invoked) {
// grab the volume and current slice
//
var _volume = this._topLevelObjects[0];

var _labelmap = _volume._labelmap;

var _labelmapShowOnlyColor = null;
if (_labelmap) {

// since there is a labelmap, get the showOnlyColor property
_labelmapShowOnlyColor = _volume._labelmap._showOnlyColor;

}

var _currentSlice = _volume['index' + this._orientation];

// .. here is the current slice
Expand Down Expand Up @@ -799,9 +818,12 @@ X.renderer2D.prototype.render_ = function(picking, invoked) {
// - if the _currentSlice has changed
// - if the threshold has changed
// - if the window/level has changed
// - the labelmap show only color has changed
var _redraw_required = (this._currentSlice != _currentSlice ||
this._lowerThreshold != _lowerThreshold ||
this._upperThreshold != _upperThreshold || this._windowLow != _windowLow || this._windowHigh != _windowHigh);
this._upperThreshold != _upperThreshold ||
this._windowLow != _windowLow || this._windowHigh != _windowHigh || (_labelmapShowOnlyColor && !X.array
.compare(_labelmapShowOnlyColor, this._labelmapShowOnlyColor, 0, 0, 4)));

if (_redraw_required) {

Expand Down Expand Up @@ -844,8 +866,27 @@ X.renderer2D.prototype.render_ = function(picking, invoked) {
if (_currentLabelMap) {

// we have a label map here
_label = [_labelData[_index], _labelData[_index + 1],
_labelData[_index + 2], _labelData[_index + 3]];

// check if all labels are shown or only one
if (_labelmapShowOnlyColor[3] == -255) {


// all labels are shown
_label = [_labelData[_index], _labelData[_index + 1],
_labelData[_index + 2], _labelData[_index + 3]];

} else {

// show only the label which matches in color
if (X.array.compare(_labelmapShowOnlyColor, _labelData, 0, _index, 4)) {

// this label matches
_label = [_labelData[_index], _labelData[_index + 1],
_labelData[_index + 2], _labelData[_index + 3]];

}

}

}

Expand Down Expand Up @@ -880,6 +921,12 @@ X.renderer2D.prototype.render_ = function(picking, invoked) {
this._upperThreshold = _upperThreshold;
this._windowLow = _windowLow;
this._windowHigh = _windowHigh;
if (_currentLabelMap) {

// only update the setting if we have a labelmap
this._labelmapShowOnlyColor = _labelmapShowOnlyColor;

}

}

Expand Down

0 comments on commit feb5c46

Please sign in to comment.