threeJsHelper.js 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686
  1. IPE.app = {};
  2. IPE.helper = {};
  3. IPE.interceptors = {};
  4. String.prototype.endsWith = function(suffix) {
  5. return this.indexOf(suffix, this.length - suffix.length) !== -1;
  6. };
  7. Array.prototype.last = function() {
  8. return this[this.length-1];
  9. }
  10. IPE.app = {
  11. init : function(config) {
  12. var headerHeight = $('header').height();
  13. if($(window).height() < 500) {
  14. $("body").animate({ scrollTop: headerHeight }, "slow");
  15. }
  16. $.each(IPE.interceptors, function(index, interceptor) {
  17. interceptor.init();
  18. });
  19. Globals.init();
  20. IPE.app.initializeHelper();
  21. IPE.app.bindEvents();
  22. IPE.app.initData();
  23. tempRenderer = new THREE.WebGLRenderer();
  24. maximumTextureSize = tempRenderer.context.getParameter(tempRenderer.context.MAX_TEXTURE_SIZE);
  25. // we have to take an power of 2 less
  26. maximumTextureSize /= 2;
  27. if(config.defaultSize > maximumTextureSize) {
  28. config.defaultSize = maximumTextureSize;
  29. }
  30. // Getting info file
  31. $.ajax({
  32. url: infoUrl + config.defaultSize,
  33. success: function (data) {
  34. textureInfo = data;
  35. originalSizeArray[0] = textureInfo.originalSize.sizex;
  36. originalSizeArray[1] = textureInfo.originalSize.sizey;
  37. originalSizeArray[2] = textureInfo.originalSize.sizez;
  38. imgInfo = data.info;
  39. currentVolumeDimension.xmin = 0;
  40. currentVolumeDimension.xmax = textureInfo.originalSize.sizex;
  41. currentVolumeDimension.ymin = 0;
  42. currentVolumeDimension.ymax = textureInfo.originalSize.sizey;
  43. currentVolumeDimension.zmin = imgInfo.imgMin;
  44. currentVolumeDimension.zmax = imgInfo.imgMax;
  45. // downloading first image and starting
  46. helper.downloadImage(spriteUrl + textureInfo.sprites[0][0].$oid, 0, 0, true);
  47. $(document).trigger('basicsReady');
  48. },
  49. dataType: 'json'
  50. });
  51. container = document.getElementById( 'container' );
  52. $container = $(container);
  53. containerHeader = document.getElementById( 'container-header' );
  54. $containerHeader = $(containerHeader);
  55. containerOverview = document.getElementById('container-overview');
  56. $containerOverview = $(containerOverview);
  57. statsHelper = new StatsHelper($containerHeader.children('#container-stats'));
  58. // until now, it has to be initialized here, needs a new internal structure
  59. zoomHelper = new ZoomHelper();
  60. $(window).on('scroll', function(e) {
  61. if($(this).scrollTop() >= headerHeight) {
  62. $container.css('position', 'relative');
  63. $container.css('top', $(this).scrollTop() - headerHeight);
  64. } else {
  65. $container.css('top', 0);
  66. }
  67. });
  68. },
  69. initializeHelper: function() {
  70. helper = new Helper();
  71. geometryHelper = new GeometryHelper();
  72. stepHelper = new StepHelper();
  73. overviewHelper = new OverviewHelper();
  74. transferHelper = new TransferHelper();
  75. opacityPlotter = new OpacityPlotter();
  76. },
  77. initData: function() {
  78. volumeId = $('#volumeId').val();
  79. $resSpan = $('span#currentRes');
  80. volumeUrl = IPE.util.buildUrl('volumes/' + volumeId + '/');
  81. infoUrl = volumeUrl + 'texture-info/';
  82. spriteUrl = volumeUrl + 'sprite/';
  83. waitDiv = $('div#wait');
  84. helper.initializeShaders(IPE.util.buildUrl('static/shaders/three-shader.vert'), function(script) {
  85. vertexShader = script
  86. });
  87. helper.initializeShaders(IPE.util.buildUrl('static/shaders/three-shader-simple.frag'), function(script) {
  88. fragmentSimleShader = script
  89. });
  90. helper.initializeShaders(IPE.util.buildUrl('static/shaders/three-shader.frag'), function(script) {
  91. fragmentShader = script
  92. });
  93. },
  94. bindEvents : function() {
  95. $(document).on('firstImageOnLoad',function (e, firstImageParams){
  96. initTextures(imgInfo, firstImageParams, true);
  97. initFrameControls();
  98. stepHelper.initStepControls();
  99. initSliders();
  100. });
  101. $(document).on('imageOnLoad', function(e, imageParams) {
  102. initTextures(imgInfo, imageParams, false);
  103. if(useDownloadedTextureImmediately) {
  104. updateTexture();
  105. useDownloadedTextureImmediately = false;
  106. updateFrameControls();
  107. }
  108. });
  109. $(document).on('firstFrameSpritesCompleted', function() {
  110. init();
  111. addResolutionLinks();
  112. overviewHelper.initOverview(containerOverview);
  113. animate();
  114. });
  115. showPopup = false;
  116. $('#save-canvas').click(function(e, params) {
  117. if(params != undefined && params.source != undefined && params.source == 'animate-function') {
  118. window.open(params.imageUrl);
  119. return false;
  120. } else {
  121. saveImage = true;
  122. return false;
  123. }
  124. });
  125. $(window).on('resize', function() {
  126. var rendererSizeHolder = calculateWidthHeight();
  127. width = rendererSizeHolder.width.px;
  128. height = rendererSizeHolder.height.px;
  129. cameraRTT.aspect = width / height;
  130. cameraRTT.updateProjectionMatrix();
  131. camera.aspect = width / height;
  132. camera.updateProjectionMatrix();
  133. renderer.setSize( width, height );
  134. renderer.domElement.style.width = rendererSizeHolder.width.percent + '%';
  135. renderer.domElement.style.height = rendererSizeHolder.height.percent + '%';
  136. });
  137. $resolutionLinks.on('click', 'a', function(e) {
  138. e.preventDefault();
  139. e.stopPropagation();
  140. var $this = $(this);
  141. if($this.attr('href') == undefined) {
  142. return false;
  143. }
  144. requestedSize = $this.attr('data');
  145. $('.res-link').each(function(index, value) {
  146. var $value = $(value);
  147. $value.attr('href', '#');
  148. });
  149. $this.removeAttr('href');
  150. $.ajax({
  151. // todo test after remove of sync flag
  152. url: infoUrl + requestedSize,
  153. success: function (data) {
  154. framesDownloaded = 0;
  155. textures = {};
  156. currentTexture = 0;
  157. textureInfo = data;
  158. imgInfo = data.info;
  159. imgMin = imgInfo.imgMin;
  160. imgMax = imgInfo.imgMax;
  161. useDownloadedTextureImmediately = true;
  162. helper.downloadImage(spriteUrl + textureInfo.sprites[0][0].$oid, 0, 0, false);
  163. $resSpan.text(requestedSize);
  164. if($('input#hide-content-small-devices').is(':visible')) {
  165. $('input#hide-content-small-devices').trigger('click');
  166. }
  167. },
  168. dataType: 'json'
  169. });
  170. return false;
  171. });
  172. $('div.controls').on('click', function() {
  173. var $this = $(this),
  174. bottomControlsContainer = $('div#bottom-controls-container'),
  175. bottomControls = $('div#bottom-controls'),
  176. filledById = '',
  177. thisControlHolder = null;
  178. filledById = hideBottomControlsContainer();
  179. if(filledById === $this.attr('id')) {
  180. return;
  181. }
  182. thisControlHolder = $this.children('.control-holder')[0];
  183. thisControlHolder = $(thisControlHolder);
  184. bottomControls.append(thisControlHolder.children());
  185. bottomControls.attr('filledBy', $this.attr('id'));
  186. bottomControlsContainer.removeClass('hidden');
  187. // inform, that it is showed
  188. $this.trigger('controlsShowed');
  189. });
  190. $('input#hide-bottom-controls-container').on('click', function() {
  191. hideBottomControlsContainer();
  192. });
  193. $('div#menu-buttons-small-devices input').on('click', function() {
  194. var $this = $(this),
  195. target = $this.attr('data'),
  196. $target = $('#' + target),
  197. $overlay = $('div#overlay-small-devices'),
  198. $content = $('div#content-small-devices');
  199. $overlay.attr('source', target);
  200. $content.append($target.children());
  201. $overlay.show();
  202. });
  203. $('input#hide-content-small-devices').on('click', function() {
  204. var $overlay = $('div#overlay-small-devices'),
  205. $content = $('div#content-small-devices'),
  206. source = $overlay.attr('source'),
  207. $source = $('#' + source);
  208. $overlay.hide();
  209. $overlay.attr('source', '');
  210. $source.append($content.children());
  211. });
  212. var buttonAdvCons = $('input#show-adv-con');
  213. buttonAdvCons.on('click', function() {
  214. var advCons = $('div#advanced-controls');
  215. if(advCons.hasClass('hidden')) {
  216. advCons.removeClass('hidden');
  217. buttonAdvCons.val('hide adv cons');
  218. } else {
  219. advCons.addClass('hidden');
  220. buttonAdvCons.val('show adv cons');
  221. }
  222. });
  223. $(document).on('initFinished', function() {
  224. $canvas.addClass('context-menu');
  225. $.contextMenu({
  226. selector: 'canvas.context-menu',
  227. callback: function(key, options) {
  228. if(key === 'save') {
  229. saveImage = true;
  230. }
  231. },
  232. items: {
  233. "save": {name: "Open image in new tab"}
  234. }
  235. });
  236. });
  237. }
  238. }
  239. function initTextures(imgInfo, imageParams, whileInit) {
  240. // set initial array to index
  241. if(textures[imageParams.textureIndex] == undefined
  242. || textures[imageParams.textureIndex] == null) {
  243. textures[imageParams.textureIndex] = [];
  244. }
  245. // using texture
  246. texture = initTexture(imageParams.texture);
  247. textures[imageParams.textureIndex].push(texture);
  248. // fetch new sprites of same time frame
  249. if(imageParams.spriteIndex < imgInfo.numberOfSprites - 1) {
  250. nextSpriteIndex = imageParams.spriteIndex + 1;
  251. nextSpriteId = textureInfo.sprites[imageParams.textureIndex][nextSpriteIndex].$oid
  252. helper.downloadImage(spriteUrl + nextSpriteId, imageParams.textureIndex, nextSpriteIndex, whileInit);
  253. return;
  254. }
  255. // inform the rest, that the first frame is loaded completely
  256. if(whileInit && imageParams.textureIndex == 0) {
  257. $(document).trigger('firstFrameSpritesCompleted');
  258. }
  259. // todo some logic
  260. if(!imgInfo.multipleFrames) {
  261. currentTexture = 0;
  262. return;
  263. } else {
  264. var numberOfFrames = Object.keys(textureInfo.sprites).length,
  265. nextIndex = null,
  266. nextFrameName = null,
  267. nextFramePath = null;
  268. framesDownloaded++;
  269. if(framesDownloaded == 1) {
  270. currentTexture = 0;
  271. }
  272. currentMaxFrame = imgInfo.frameFrom + framesDownloaded - 1;
  273. if(framesDownloaded > 1) {
  274. // updating frame control maximums
  275. updateFrameControlsMaxFrame();
  276. }
  277. if(numberOfFrames == framesDownloaded) {
  278. return;
  279. } else {
  280. nextIndex = framesDownloaded;
  281. nextFrameName = textureInfo.sprites[nextIndex][0].$oid;
  282. var framePath = spriteUrl + nextFrameName;
  283. helper.downloadImage(framePath, nextIndex, false);
  284. }
  285. }
  286. }
  287. function initTexture(texture) {
  288. texture.magFilter = THREE.LinearFilter;
  289. texture.minFilter = THREE.LinearFilter;
  290. texture.needsUpdate = true;
  291. return texture;
  292. }
  293. function getCurrentTexture() {
  294. return textures[currentTexture];
  295. }
  296. function useFrameControls() {
  297. return (imgInfo.multipleFrames && (imgInfo.frameTo - imgInfo.frameFrom) != 0);
  298. }
  299. function initFrameControls() {
  300. if(!useFrameControls()) {
  301. return;
  302. }
  303. $('#frame-controls').removeClass('hidden');
  304. var $frameSlider = $('#frame-slider'),
  305. $playButton = $('#frame-play'),
  306. $pauseButton = $('#frame-pause'),
  307. $currentFrameInput = $('#currentFrame'),
  308. playId = $playButton.attr('id'),
  309. pauseId = $pauseButton.attr('id'),
  310. minFrame = imgInfo.frameFrom;
  311. $currentFrameInput.val(minFrame);
  312. var play = function() {
  313. if(Object.keys(textures).length == 1) {
  314. console.warn('only one texture loaded, can not play yet');
  315. return;
  316. }
  317. $playButton.addClass('hidden');
  318. $pauseButton.removeClass('hidden');
  319. playFrames = true;
  320. $frameSlider.slider({disabled: true});
  321. $currentFrameInput.prop('disabled', true);
  322. }
  323. var pause = function() {
  324. $playButton.removeClass('hidden');
  325. $pauseButton.addClass('hidden');
  326. playFrames = false;
  327. $frameSlider.slider({disabled: false});
  328. $currentFrameInput.prop('disabled', false);
  329. }
  330. $('.frame-button').click(function() {
  331. var $this = $(this),
  332. thisId = $this.attr('id');
  333. if(thisId == playId) {
  334. play();
  335. } else if(thisId == pauseId) {
  336. pause();
  337. }
  338. });
  339. $(document).on('zoomActionFinished', function(e, params) {
  340. zoomedIn = params.zoomAction == 'zoomIn';
  341. if(zoomedIn) {
  342. pause();
  343. currentTexture = minFrame + params.textureNumber;
  344. updateFrameControls();
  345. $frameSlider.slider({disabled: true});
  346. $currentFrameInput.prop('disabled', true);
  347. $playButton.prop('disabled', true);
  348. $pauseButton.prop('disabled', true);
  349. } else {
  350. $frameSlider.slider({disabled: false});
  351. $currentFrameInput.prop('disabled', false);
  352. $playButton.prop('disabled', false);
  353. $pauseButton.prop('disabled', false);
  354. }
  355. });
  356. $frameSlider.slider(
  357. {
  358. min: minFrame,
  359. max: currentMaxFrame,
  360. slide: function( event, ui ) {
  361. currentTexture = ui.value - minFrame;
  362. updateTexture();
  363. $currentFrameInput.val(ui.value);
  364. }
  365. }
  366. );
  367. $currentFrameInput.change(function() {
  368. var value = parseInt($(this).val());
  369. if(value >= imgInfo.frameFrom && currentMaxFrame >= value) {
  370. currentTexture = value - minFrame;
  371. updateTexture();
  372. $frameSlider.slider('value', value);
  373. } else {
  374. $(this).val($frameSlider.slider('value'));
  375. }
  376. });
  377. }
  378. function updateFrameControlsMaxFrame() {
  379. if(!useFrameControls()) {
  380. return;
  381. }
  382. var $frameSlider = $('#frame-slider');
  383. $frameSlider.slider('option', 'max', currentMaxFrame);
  384. }
  385. function updateFrameControls() {
  386. if(!useFrameControls()) {
  387. return;
  388. }
  389. var $frameSlider = $('#frame-slider'),
  390. $currentFrameInput = $('#currentFrame'),
  391. minFrame = imgInfo.frameFrom,
  392. value = currentTexture + minFrame;
  393. $frameSlider.slider('value', value);
  394. $currentFrameInput.val(value);
  395. }
  396. function init() {
  397. rendererSizeHolder = calculateWidthHeight();
  398. width = rendererSizeHolder.width.px;
  399. height = rendererSizeHolder.height.px;
  400. //width = window.innerWidth;
  401. //height = window.innerHeight;
  402. camera = new THREE.PerspectiveCamera( 45, width / height, .1, 1000 );
  403. camera.position.z = 2;
  404. cameraRTT = new THREE.PerspectiveCamera( 45, width / height, .1, 1000 );
  405. cameraRTT.position.z = 2;
  406. scene = new THREE.Scene();
  407. sceneRTT = new THREE.Scene();
  408. rtTexture = new THREE.WebGLRenderTarget( width, height, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat } );
  409. var geometry = geometryHelper.createBoxGeometry(originalDimension, currentVolumeDimension);
  410. var attributes = {
  411. frontColor: {type: 'c', value: [] }
  412. }
  413. material = new THREE.ShaderMaterial({
  414. attributes: attributes,
  415. vertexShader: vertexShader,
  416. fragmentShader: fragmentSimleShader,
  417. side: THREE.FrontSide
  418. });
  419. var spriteMaps = getCurrentTexture();
  420. var transferImageData = transferHelper.getCurrentTransferFunction();
  421. var transferTexture = new THREE.Texture(transferImageData);
  422. transferTexture.needsUpdate = true;
  423. var uniforms = {
  424. tBackground: {type: 't', value: rtTexture},
  425. tvSlices: {type: 'tv', value: spriteMaps},
  426. tTransfer: { type: 't', value: transferTexture},
  427. steps: {type: 'f', value: 100},
  428. numberOfSlices: {type: 'f', value: imgInfo.numberOfSlices },
  429. numberOfSprites: {type: 'f', value: imgInfo.numberOfSprites },
  430. slicesPerSprite: {type: 'f', value: imgInfo.slicesPerSprite },
  431. slicesOverX: {type: 'f', value: imgInfo.slicesOverX },
  432. slicesOverY: {type: 'f', value: imgInfo.slicesOverY },
  433. };
  434. materialScreen = new THREE.ShaderMaterial({
  435. attributes: attributes,
  436. uniforms: uniforms,
  437. vertexShader: vertexShader,
  438. fragmentShader: fragmentShader,
  439. side: THREE.BackSide,
  440. transparent: true
  441. });
  442. backgroundBox = new THREE.Mesh(geometry, material);
  443. sceneRTT.add(backgroundBox);
  444. frontBox = new THREE.Mesh(geometry, materialScreen);//
  445. scene.add(frontBox);
  446. objectsToIntersect.push(frontBox);
  447. translateBoxes(-0.5, -0.5, -0.5 * currentVolumeDimension.getZStretchFactor());
  448. rotateBoxesX(Math.PI / -2);
  449. //rotateBoxesY(Math.PI);
  450. //rotateBoxesZ(Math.PI);
  451. renderer = new THREE.WebGLRenderer();
  452. renderer.setSize(width, height);
  453. renderer.domElement.style.width = rendererSizeHolder.width.percent + '%';
  454. renderer.domElement.style.height = rendererSizeHolder.height.percent + '%';
  455. renderer.setClearColor(0xffffff, 1);
  456. container.appendChild(renderer.domElement);
  457. $canvas = $('canvas', $container);
  458. controls1 = new THREE.OrbitControls( camera, renderer.domElement );
  459. controls1.damping = 0.2;
  460. controls2 = new THREE.OrbitControls( cameraRTT, renderer.domElement );
  461. controls2.damping = 0.2;
  462. rendererContext = renderer.context;
  463. raycaster = new THREE.Raycaster();
  464. $(document).trigger('initFinished');
  465. }
  466. function rotateBoxesX(radian) {
  467. rotationMatrix = new THREE.Matrix4().makeRotationX(radian);
  468. rotateBoxes(rotationMatrix);
  469. }
  470. function rotateBoxesY(radian) {
  471. rotationMatrix = new THREE.Matrix4().makeRotationY(radian);
  472. rotateBoxes(rotationMatrix);
  473. }
  474. function rotateBoxesZ(radian) {
  475. rotationMatrix = new THREE.Matrix4().makeRotationZ(radian);
  476. rotateBoxes(rotationMatrix);
  477. }
  478. function rotateBoxes(matrix) {
  479. backgroundBox.applyMatrix(rotationMatrix);
  480. frontBox.applyMatrix(rotationMatrix);
  481. }
  482. function translateBoxes(x, y, z) {
  483. translationMatrix = new THREE.Matrix4().makeTranslation(x, y, z);
  484. backgroundBox.applyMatrix(translationMatrix);
  485. frontBox.applyMatrix(translationMatrix);
  486. }
  487. function initSliders() {
  488. initLayerSliders();
  489. // init gray value slider
  490. GenericSlider.initSlider(
  491. slider = $( "#gray-slider" ),
  492. sliderInputs = $('input.gray'),
  493. minGray,
  494. maxGray,
  495. function(values) {
  496. $(document).trigger(
  497. 'opacityBordersChanged',
  498. {
  499. minGray: values[0],
  500. maxGray : values[1]
  501. }
  502. );
  503. }
  504. );
  505. $('#gray-slider-container').on('controlsShowed', function() {
  506. var values = $("#gray-slider").slider('values');
  507. $(document).trigger('opacityBordersChanged', { minGray: values[0], maxGray: values[1] });
  508. });
  509. GenericSlider.initSimpleSlider(
  510. slider = $('#background-slider'),
  511. sliderInput = $('#background-input'),
  512. startVal = 255,
  513. 0,
  514. 255,
  515. function(value) {
  516. var colorFloat = calculateGrayFloat(value);
  517. renderer.setClearColor(
  518. new THREE.Color(colorFloat, colorFloat, colorFloat),
  519. 1
  520. );
  521. }
  522. );
  523. }
  524. function initLayerSliders() {
  525. // init xlayer slider
  526. GenericSlider.initSlider(
  527. $( "#xlayer-slider" ),
  528. sliderInputs = $('input.xlayer'),
  529. currentVolumeDimension.xmin,
  530. currentVolumeDimension.xmax,
  531. function(values) {
  532. dimMin = currentVolumeDimension.xmin;
  533. dimMax = currentVolumeDimension.xmax;
  534. currentDimension.xmin = calculateLayerFloat(values[0], dimMin, dimMax);
  535. currentDimension.xmax = calculateLayerFloat(values[1], dimMin, dimMax);
  536. updateCubeLayers(currentDimension);
  537. },
  538. function() {
  539. values = Array(2);
  540. values[0] = calculateLayerInt(currentDimension.xmin, currentVolumeDimension.xmin, currentVolumeDimension.xmax );
  541. values[1] = calculateLayerInt(currentDimension.xmax, currentVolumeDimension.xmin, currentVolumeDimension.xmax );
  542. return values;
  543. }
  544. );
  545. // init ylayer slider
  546. GenericSlider.initSlider(
  547. $( "#ylayer-slider" ),
  548. sliderInputs = $('input.ylayer'),
  549. currentVolumeDimension.ymin,
  550. currentVolumeDimension.ymax,
  551. function(values) {
  552. dimMin = currentVolumeDimension.ymin;
  553. dimMax = currentVolumeDimension.ymax;
  554. currentDimension.ymin = calculateLayerFloat(values[0], dimMin, dimMax);
  555. currentDimension.ymax = calculateLayerFloat(values[1], dimMin, dimMax);
  556. updateCubeLayers(currentDimension);
  557. },
  558. function() {
  559. values = Array(2);
  560. values[0] = calculateLayerInt(currentDimension.ymin, currentVolumeDimension.ymin, currentVolumeDimension.ymax );
  561. values[1] = calculateLayerInt(currentDimension.ymax, currentVolumeDimension.ymin, currentVolumeDimension.ymax );
  562. return values;
  563. }
  564. );
  565. // init zlayer slider
  566. GenericSlider.initSlider(
  567. $( "#zlayer-slider" ),
  568. sliderInputs = $('input.zlayer'),
  569. currentVolumeDimension.zmin,
  570. currentVolumeDimension.zmax,
  571. function(values) {
  572. dimMin = currentVolumeDimension.zmin;
  573. dimMax = currentVolumeDimension.zmax;
  574. currentDimension.zmin = calculateLayerFloat(values[0], dimMin, dimMax),
  575. currentDimension.zmax = calculateLayerFloat(values[1], dimMin, dimMax);
  576. updateCubeLayers(currentDimension);
  577. },
  578. function() {
  579. values = Array(2);
  580. values[0] = calculateLayerInt(currentDimension.zmin, currentVolumeDimension.zmin, currentVolumeDimension.zmax );
  581. values[1] = calculateLayerInt(currentDimension.zmax, currentVolumeDimension.zmin, currentVolumeDimension.zmax );
  582. return values;
  583. }
  584. );
  585. }
  586. function repositionLayerSliders() {
  587. initLayerSliders();
  588. $.each($('.slider.layer'), function(index, value) {
  589. $(value).trigger('reposition');
  590. });
  591. updateCubeLayers(currentDimension);
  592. }
  593. var prevTime = Date.now();
  594. var fps = 0;
  595. var frames = 0;
  596. function animate() {
  597. requestAnimationFrame( animate );
  598. $container.trigger('animation');
  599. var numberOfTextures = Object.keys(textures).length;
  600. var now = Date.now();
  601. frames++;
  602. if(now > prevTime + 1000) {
  603. fps = (frames * 1000) / (now - prevTime);
  604. if(adjustSteps) {
  605. if(fps < 10) {
  606. stepHelper.decreaseSteps();
  607. } else if(fps > 15) {
  608. stepHelper.increaseSteps();
  609. }
  610. }
  611. prevTime = now;
  612. frames = 0;
  613. }
  614. if(playFrames && numberOfTextures > 1) {
  615. var timeStamp = (new Date()).getTime();
  616. if(timeStamp - textureTimestamp > 400) {
  617. currentTexture++;
  618. if(currentTexture >= numberOfTextures) {
  619. currentTexture = 0;
  620. }
  621. updateTexture();
  622. textureTimestamp = timeStamp;
  623. updateFrameControls();
  624. }
  625. }
  626. if(nextCubeDeletionTimeStamp == null && intersectCubesTimeStamps.length != 0) {
  627. nextCubeDeletionTimeStamp = intersectCubesTimeStamps.shift();
  628. }
  629. if((Date.now() - nextCubeDeletionTimeStamp) > 1500) {
  630. cubeToDelete = intersectCubes.shift();
  631. scene.remove(cubeToDelete);
  632. nextCubeDeletionTimeStamp = null;
  633. }
  634. if(transferHelper.transferFunctionChanged()) {
  635. var transfer = new THREE.Texture(transferHelper.getCurrentTransferFunction());
  636. transfer.needsUpdate = true;
  637. materialScreen.uniforms.tTransfer.value = transfer;
  638. }
  639. cameraPoint = camera.position.clone();
  640. overviewHelper.updateCameraPosition(cameraPoint);
  641. statsHelper.update();
  642. controls1.update();
  643. controls2.update();
  644. render();
  645. if(saveImage) {
  646. $('#save-canvas').trigger('click', { source: 'animate-function', imageUrl: renderer.domElement.toDataURL() });
  647. saveImage = false;
  648. }
  649. }
  650. function updateTexture(textures) {
  651. if(textures == undefined || textures == null) {
  652. textures = getCurrentTexture();
  653. }
  654. $.each(textures, function(index, texture) {
  655. value.needsUpdate = true;
  656. });
  657. materialScreen.uniforms.tvSlices.value = textures;
  658. }
  659. function render() {
  660. renderer.clear();
  661. renderer.context.clearDepth(-50.0);
  662. renderer.context.depthFunc(renderer.context.GEQUAL);
  663. renderer.render(sceneRTT, cameraRTT, rtTexture, true);
  664. renderer.context.clearDepth(50.0);
  665. renderer.context.depthFunc(renderer.context.LEQUAL);
  666. renderer.render(scene, camera);
  667. overviewHelper.render();
  668. }
  669. function updateCubeLayers(geometryDimension) {
  670. var geometry = geometryHelper.createBoxGeometry(geometryDimension, currentVolumeDimension);
  671. var colorArray = geometry.attributes.frontColor.array,
  672. positionArray = geometry.attributes.position.array;
  673. frontBox.geometry.attributes.frontColor.array = colorArray;
  674. frontBox.geometry.attributes.frontColor.needsUpdate = true;
  675. frontBox.geometry.attributes.position.array = positionArray;
  676. frontBox.geometry.attributes.position.needsUpdate = true;
  677. }
  678. // invert function of calculateLayerFloat
  679. function calculateLayerInt(position, dimMin, dimMax) {
  680. if(position <= 0.005) {
  681. return dimMin;
  682. }
  683. if(position >= 0.995) {
  684. return dimMax;
  685. }
  686. value = Math.round(position * (dimMax - dimMin) + dimMin);
  687. return value;
  688. }
  689. // calculate the float value for a layer input integer
  690. // 150 of [0, 299] will be 0.5
  691. function calculateLayerFloat(value, dimMin, dimMax) {
  692. var floatVal = (value - dimMin) / (dimMax - dimMin);
  693. if (floatVal == 0) {
  694. return 0.005;
  695. }
  696. if (floatVal == 1) {
  697. return 0.995;
  698. }
  699. return floatVal;
  700. }
  701. function calculateGrayFloat(value) {
  702. return value / 255.0;
  703. }
  704. function distance (v1, v2) {
  705. dx = v1.x - v2.x;
  706. dy = v1.y - v2.y;
  707. dz = v1.z - v2.z;
  708. return Math.sqrt(dx*dx+dy*dy+dz*dz);
  709. }
  710. function calculateWidthHeight() {
  711. downScaleFactor = 0.66;
  712. valueholder = {
  713. height: {},
  714. width: {}
  715. }
  716. containerHeight = $container.height();
  717. volumeInfoHeight = $('#volume-information').height();
  718. headerHeight = $('header').height();
  719. valueholder.height.px = (containerHeight - volumeInfoHeight) * downScaleFactor;
  720. volumeInfoHeightPercent = Math.floor(volumeInfoHeight / containerHeight * 100);
  721. valueholder.height.percent = 100 - volumeInfoHeightPercent;
  722. valueholder.width.px = $container.width() * downScaleFactor;
  723. valueholder.width.percent = 100;
  724. return valueholder;
  725. }
  726. function hideBottomControlsContainer() {
  727. var bottomControlsContainer = $('div#bottom-controls-container'),
  728. bottomControls = $('div#bottom-controls'),
  729. filledById = bottomControls.attr('filledBy'),
  730. filledBy = $('#' + filledById);
  731. // writing data back to original, because append MOVES the children
  732. if(filledBy.length == 1) {
  733. filledBy = $(filledBy[0]);
  734. filledByControlHolder = filledBy.children('.control-holder')[0];
  735. $(filledByControlHolder).append(bottomControls.children());
  736. }
  737. bottomControls.attr('filledBy', '');
  738. bottomControlsContainer.addClass('hidden');
  739. return filledById;
  740. }
  741. function addResolutionLinks() {
  742. $resSpan.text(config.defaultSize);
  743. textureSizes = config.textureSizes;
  744. textureSizes.forEach(function(size) {
  745. if(size > maximumTextureSize) {
  746. return;
  747. }
  748. href = size == config.defaultSize ? '' : 'href="#"';
  749. $resolutionLinks.append('<a '+href+' class="res-link" data="'+size+'">'+size+'</a> ');
  750. });
  751. }
  752. ;var volumeId;
  753. var stats, container, $container, containerHeader, $containerHeader, $canvas, cameraRTT, camera, sceneRTT, scene, renderer, controls, controls2;
  754. var maximumTextureSize;
  755. var containerOverview, $containerOverview;
  756. var $resSpan;
  757. var $resolutionLinks;
  758. var raycaster;
  759. var width, height;
  760. var steps, adjustSteps;
  761. var rtTexture, material;
  762. var backgroundBox, frontBox;
  763. var objectsToIntersect = [];
  764. var minGray = 5, maxGray = 255;
  765. var originalDimension,
  766. zoomedDimension,
  767. currentDimension,
  768. originalVolumeDimension,
  769. zoomedVolumeDimension,
  770. currentVolumeDimension,
  771. volumeUrl,
  772. infoUrl,
  773. spriteUrl,
  774. imgInfo = null,
  775. textureInfo = null,
  776. originalSizeArray = Array(3),
  777. zoomedInfo,
  778. rotationMatrix;
  779. var textures = {},
  780. currentTexture = 0,
  781. useDownloadedTextureImmediately = false,
  782. textureTimestamp = (new Date()).getTime(),
  783. playFrames = false,
  784. currentMaxFrame = 0;
  785. var framesDownloaded = 0,
  786. cachedImages = {};
  787. var vertexShader = null,
  788. fragmentSimleShader = null,
  789. fragmentShader = null;
  790. var intersectCubes = [],
  791. intersectCubesTimeStamps = []
  792. nextCubeDeletionTimeStamp = null,
  793. zoomedIn = false;
  794. var helper,
  795. geometryHelper,
  796. stepHelper,
  797. overviewHelper,
  798. transferHelper,
  799. zoomHelper,
  800. opacityPlotter,
  801. statsHelper;
  802. var waitDiv;
  803. var saveImage = false;
  804. // prefetch first image to cache it
  805. var progressContainer,
  806. imageProgress,
  807. progressSpan;
  808. var Globals = (function() {
  809. return {
  810. init: function() {
  811. originalDimension = new GeometryDimension();
  812. zoomedDimension = new GeometryDimension();
  813. currentDimension = originalDimension;
  814. originalVolumeDimension = new VolumeDimension();
  815. zoomedVolumeDimension = new VolumeDimension();
  816. currentVolumeDimension = originalVolumeDimension;
  817. $resolutionLinks = $('#resolution-links');
  818. }
  819. }
  820. }());
  821. ;var GeometryHelper = function() {
  822. return {
  823. createBoxGeometry: function(dimension, volumeDimension) {
  824. var vertexPos = [
  825. //front face first
  826. [dimension.xmin, dimension.ymin, dimension.zmax],
  827. [dimension.xmax, dimension.ymin, dimension.zmax],
  828. [dimension.xmax, dimension.ymax, dimension.zmax],
  829. //front face second
  830. [dimension.xmin, dimension.ymin, dimension.zmax],
  831. [dimension.xmax, dimension.ymax, dimension.zmax],
  832. [dimension.xmin, dimension.ymax, dimension.zmax],
  833. // back face first
  834. [dimension.xmin, dimension.ymin, dimension.zmin],
  835. [dimension.xmin, dimension.ymax, dimension.zmin],
  836. [dimension.xmax, dimension.ymax, dimension.zmin],
  837. // back face second
  838. [dimension.xmin, dimension.ymin, dimension.zmin],
  839. [dimension.xmax, dimension.ymax, dimension.zmin],
  840. [dimension.xmax, dimension.ymin, dimension.zmin],
  841. // top face first
  842. [dimension.xmin, dimension.ymax, dimension.zmin],
  843. [dimension.xmin, dimension.ymax, dimension.zmax],
  844. [dimension.xmax, dimension.ymax, dimension.zmax],
  845. // top face second
  846. [dimension.xmin, dimension.ymax, dimension.zmin],
  847. [dimension.xmax, dimension.ymax, dimension.zmax],
  848. [dimension.xmax, dimension.ymax, dimension.zmin],
  849. // bottom face first
  850. [dimension.xmin, dimension.ymin, dimension.zmin],
  851. [dimension.xmax, dimension.ymin, dimension.zmin],
  852. [dimension.xmax, dimension.ymin, dimension.zmax],
  853. // bottom face second
  854. [dimension.xmin, dimension.ymin, dimension.zmin],
  855. [dimension.xmax, dimension.ymin, dimension.zmax],
  856. [dimension.xmin, dimension.ymin, dimension.zmax],
  857. // right face first
  858. [dimension.xmax, dimension.ymin, dimension.zmin],
  859. [dimension.xmax, dimension.ymax, dimension.zmin],
  860. [dimension.xmax, dimension.ymax, dimension.zmax],
  861. // right face second
  862. [dimension.xmax, dimension.ymin, dimension.zmin],
  863. [dimension.xmax, dimension.ymax, dimension.zmax],
  864. [dimension.xmax, dimension.ymin, dimension.zmax],
  865. // left face first
  866. [dimension.xmin, dimension.ymin, dimension.zmin],
  867. [dimension.xmin, dimension.ymin, dimension.zmax],
  868. [dimension.xmin, dimension.ymax, dimension.zmax],
  869. // left face second
  870. [dimension.xmin, dimension.ymin, dimension.zmin],
  871. [dimension.xmin, dimension.ymax, dimension.zmax],
  872. [dimension.xmin, dimension.ymax, dimension.zmin]
  873. ];
  874. var positions = [];
  875. var colors = [];
  876. for(var i = 0; i < vertexPos.length; i++) {
  877. var backCounter = vertexPos.length - 1 - i,
  878. x = vertexPos[backCounter][0],
  879. y = vertexPos[backCounter][1],
  880. z = vertexPos[backCounter][2];
  881. positions.push(x);
  882. positions.push(y);
  883. positions.push(z * volumeDimension.getZStretchFactor());
  884. colors.push(x);
  885. colors.push(y);
  886. colors.push(z);
  887. colors.push(1.0);
  888. }
  889. var geometry = new THREE.BufferGeometry();
  890. var bufferPositions = new Float32Array(positions);
  891. geometry.addAttribute( 'position', new THREE.BufferAttribute( bufferPositions, 3 ) );
  892. geometry.addAttribute( 'frontColor', new THREE.BufferAttribute(new Float32Array(colors), 4));
  893. geometry.computeBoundingSphere();
  894. return geometry;
  895. }
  896. }
  897. }
  898. var GeometryDimension = function() {
  899. this.xmin = 0.005;
  900. this.xmax = 0.995;
  901. this.ymin = 0.005;
  902. this.ymax = 0.995;
  903. this.zmin = 0.005;
  904. this.zmax = 0.995;
  905. }
  906. var VolumeDimension = function() {
  907. this.xmin;
  908. this.xmax;
  909. this.ymin;
  910. this.ymax;
  911. this.zmin;
  912. this.zmax;
  913. return {
  914. getZStretchFactor: function() {
  915. return (this.zmax - this.zmin + 1) / (this.xmax - this.xmin);
  916. }
  917. }
  918. }
  919. ;var Helper = function() {
  920. var messagePopup = $('#popup'),
  921. popupVisible = messagePopup.hasClass('hidden'),
  922. progressContainer = $('#progress-container'),
  923. imageProgress = $('#image-progress'),
  924. progressSpan = $('#texturePath');
  925. return {
  926. initializeShaders: function(url, callback) {
  927. $.ajax({
  928. url: url,
  929. error: function() {
  930. console.error('failed to load shader file from: ' + url);
  931. },
  932. success: callback
  933. });
  934. },
  935. downloadImage: function (texturePath, textureIndex, spriteIndex, whileInit) {
  936. me = this;
  937. onProgressHolder = me.showProgress(texturePath);
  938. if(!texturePath.endsWith('/')) {
  939. texturePath += '/';
  940. }
  941. var xmlHttp = new XMLHttpRequest();
  942. xmlHttp.open('GET', texturePath, true);
  943. xmlHttp.onprogress = onProgressHolder.onProgressFunction;
  944. xmlHttp.onload = function(e) {
  945. var blob = new Blob([xmlHttp.response], {
  946. type: this.getResponseHeader('content-type')
  947. });
  948. var blobSrc = window.URL.createObjectURL(blob);
  949. var image = new Image();
  950. var texture = new THREE.Texture(image);
  951. image.onload = function() {
  952. me.hideProgress();
  953. texture.needsUpdate = true;
  954. var params = {
  955. textureIndex: textureIndex,
  956. spriteIndex: spriteIndex,
  957. texture: texture
  958. };
  959. if(textureIndex == 0 && whileInit) {
  960. $(document).trigger('firstImageOnLoad', params);
  961. } else {
  962. $(document).trigger('imageOnLoad', params);
  963. }
  964. }
  965. image.src = blobSrc;
  966. };
  967. xmlHttp.responseType = 'blob';
  968. xmlHttp.send();
  969. },
  970. showProgress: function(texturePath) {
  971. progressContainer.removeClass('hidden');
  972. progressSpan.text(texturePath);
  973. return {
  974. onProgressFunction: function(e) {
  975. if (e.lengthComputable) {
  976. value = Math.floor(e.loaded / e.total * 100);
  977. imageProgress.val(value);
  978. }
  979. }
  980. }
  981. },
  982. hideProgress: function() {
  983. imageProgress.val(0);
  984. progressSpan.text('');
  985. progressContainer.addClass('hidden');
  986. },
  987. displayMessage: function(message, fadeOutAutomatically, callback, timeout) {
  988. var me = this;
  989. messagePopup.html(message);
  990. messagePopup.show();
  991. if(fadeOutAutomatically) {
  992. this.fadeoutMessage(callback, timeout);
  993. }
  994. },
  995. fadeoutMessage: function(callback, timeout) {
  996. if(timeout == undefined) {
  997. timeout = 0;
  998. }
  999. setTimeout(function() {
  1000. messagePopup.fadeOut(400, function() {
  1001. $(this).html('');
  1002. if(callback) {
  1003. callback();
  1004. }
  1005. });
  1006. }, timeout);
  1007. }
  1008. };
  1009. }
  1010. ;var OpacityPlotter = function() {
  1011. // we have 255 colors
  1012. var coordinateLength = 255;
  1013. // set with respect on plotter height
  1014. var height = 40;
  1015. // array for holding the x coordinates
  1016. var coordinates = Array(coordinateLength);
  1017. // array for holding the y coordinates values elementOf [0, height]
  1018. var linePosition = Array(coordinateLength);
  1019. // array holding the resulting opacities, that will be generated
  1020. // of line position, values elementof [0, 255]
  1021. var opacities = Array(coordinateLength);
  1022. for(counter = 0; counter < coordinateLength; counter++) {
  1023. coordinates[counter] = counter;
  1024. linePosition[counter] = 0;
  1025. opacities[counter] = 255;
  1026. }
  1027. var stage = new Kinetic.Stage({
  1028. container : 'opacity-plot',
  1029. width : coordinateLength,
  1030. height: height
  1031. });
  1032. var layer = new Kinetic.Layer();
  1033. var rect = new Kinetic.Rect({
  1034. x: 0,
  1035. y: 0,
  1036. width: stage.getWidth(),
  1037. height: stage.getHeight(),
  1038. fill: '#cccccc'
  1039. });
  1040. layer.add(rect);
  1041. var spline = new Kinetic.Line({
  1042. points: getResultingPoints(),
  1043. stroke: 'red',
  1044. strokeWidth: 3,
  1045. lineCap: 'round'
  1046. });
  1047. layer.add(spline);
  1048. stage.add(layer);
  1049. stage.on("mousedown", function() {
  1050. processEvent();
  1051. });
  1052. stage.on("mousemove", function(e) {
  1053. if(e.evt.which == 1) {
  1054. processEvent();
  1055. }
  1056. });
  1057. $('#transfer-function-definition').on('controlsShowed', function() {
  1058. populateOpacities();
  1059. });
  1060. $('input#opacity-visible').on('click', function() {
  1061. setToFixedValue(255);
  1062. });
  1063. $('input#opacity-invisible').on('click', function() {
  1064. setToFixedValue(0);
  1065. });
  1066. function setToFixedValue(value) {
  1067. var opacityValue = value;
  1068. var yValue = height - ((value / 255) * height)
  1069. for(counter = 0; counter < opacities.length; counter++) {
  1070. opacities[counter] = opacityValue ;
  1071. linePosition[counter] = yValue;
  1072. }
  1073. populateOpacities();
  1074. spline.setPoints(getResultingPoints());
  1075. layer.draw();
  1076. }
  1077. function populateOpacities() {
  1078. $(document).trigger('opacityChanged', { opacities: opacities.slice() });
  1079. }
  1080. function processEvent() {
  1081. var mousePosition = stage.getPointerPosition();
  1082. calculateOpacities(mousePosition);
  1083. spline.setPoints(getResultingPoints());
  1084. layer.draw();
  1085. }
  1086. function calculateOpacities(mousePosition) {
  1087. // Set area of click to this value
  1088. var xMin = (mousePosition.x - 2 >= 0) ? mousePosition.x - 2 : 0;
  1089. var xMax = (mousePosition.x + 2 <= 255) ? mousePosition.x + 2 : 255;
  1090. var opacityValue = (height - mousePosition.y) / height;
  1091. opacityValue *= 255;
  1092. for(counter = xMin; counter <= xMax; counter++) {
  1093. linePosition[counter] = mousePosition.y;
  1094. opacities[counter] = opacityValue;
  1095. }
  1096. populateOpacities();
  1097. }
  1098. function getResultingPoints() {
  1099. return combineArrays(coordinates, linePosition);
  1100. }
  1101. function combineArrays(array1, array2) {
  1102. return $.map(array1, function(v, i) { return [v, array2[i]]; });
  1103. }
  1104. }
  1105. ;var StatsHelper = function(parentElement) {
  1106. if(IPE.environment != 'dev') {
  1107. // fill parentElement with emptyness
  1108. parentElement.append('&nbsp;');
  1109. // we don't want to do display anything
  1110. // in production
  1111. return {
  1112. update: function() {}
  1113. };
  1114. }
  1115. var stats = new Stats();
  1116. var parentElement = parentElement;
  1117. parentElement.append(stats.domElement);
  1118. return {
  1119. update: function() {
  1120. stats.update();
  1121. }
  1122. }
  1123. };
  1124. ;var StepHelper = function() {
  1125. // default is the step 100
  1126. currentStepIndex = 2;
  1127. // steps just defined
  1128. availableSteps = [10, 20, 50, 80, 100, 150, 200];
  1129. return {
  1130. decreaseSteps: function() {
  1131. var currentStepIndex = this.determineCurrentStepIndex();
  1132. if(currentStepIndex > 0) {
  1133. this.updateStepValue(availableSteps[currentStepIndex - 1], true);
  1134. }
  1135. },
  1136. increaseSteps: function() {
  1137. var currentStepIndex = this.determineCurrentStepIndex();
  1138. if(currentStepIndex > -1 && currentStepIndex < availableSteps.length - 1) {
  1139. this.updateStepValue(availableSteps[currentStepIndex + 1], true);
  1140. }
  1141. },
  1142. determineCurrentStepIndex: function() {
  1143. var minDeviation = null,
  1144. minDeviationIndex;
  1145. // first we have to find an appropiate predefined stepValue for input stepvalue
  1146. for(var index = 0; index < availableSteps.length; index++) {
  1147. deviation = Math.abs(steps - availableSteps[index]);
  1148. if(minDeviation == null || deviation < minDeviation) {
  1149. minDeviation = deviation;
  1150. minDeviationIndex = index;
  1151. }
  1152. }
  1153. if(minDeviation !== null) {
  1154. return minDeviationIndex;
  1155. } else {
  1156. return -1;
  1157. }
  1158. },
  1159. updateStepValue: function(stepValue, updateInputField) {
  1160. steps = stepValue;
  1161. materialScreen.uniforms.steps.value = steps;
  1162. if(updateInputField) {
  1163. $('#steps').val(stepValue);
  1164. }
  1165. },
  1166. initStepControls: function() {
  1167. var me = this,
  1168. stepsInput = $('#steps'),
  1169. stepsAdjustInput = $('#steps-adjust');
  1170. steps = stepsInput.val();
  1171. stepsInput.change(function() {
  1172. steps = stepsInput.val();
  1173. me.updateStepValue(steps, false);
  1174. });
  1175. adjustSteps = stepsAdjustInput.is(':checked');
  1176. stepsAdjustInput.change(function() {
  1177. adjustSteps = $(this).is(':checked');
  1178. if(adjustSteps) {
  1179. stepsInput.prop('disabled', true);
  1180. } else {
  1181. stepsInput.prop('disabled', false);
  1182. }
  1183. });
  1184. }
  1185. };
  1186. };
  1187. ;var TransferHelper = function() {
  1188. var me = this,
  1189. changed = false,
  1190. canvas = document.getElementById('transfer-function'),
  1191. $canvas = $(canvas),
  1192. context = canvas.getContext('2d'),
  1193. hiddenCanvas = document.getElementById('hidden-transfer'),
  1194. hiddenContext = hiddenCanvas.getContext('2d'),
  1195. transferSpanHolder = $('#transfer-span-holder'),
  1196. transfer = $('#transfer'),
  1197. disabled = true,
  1198. handles = $('span.transfer'),
  1199. $standardTf = $('img#standard-tf').get(0),
  1200. offsetLeft = {
  1201. blue: 0,
  1202. turquois: 0.25,
  1203. green: 0.5,
  1204. orange: 0.75,
  1205. red: 1
  1206. },
  1207. colorCodes = {
  1208. blue: '#0000FF',
  1209. turquois: '#00FFFF',
  1210. green: '#00FF00',
  1211. orange: '#FFFF00',
  1212. red: '#FF0000'
  1213. },
  1214. opacities = Array(255);
  1215. //black values are disabled defaultly
  1216. opacities[0] = 0;
  1217. for(counter = 0; counter < opacities.length; counter++) {
  1218. opacities[counter] = 255;
  1219. if (counter <= minGray) {
  1220. opacities[counter] = 0;
  1221. }
  1222. }
  1223. $('input#toggle-transfer').on('click', function() {
  1224. if(disabled) {
  1225. enableTransferFunction();
  1226. } else {
  1227. disableTransferFunction();
  1228. }
  1229. });
  1230. var getOffsetLeft = function() {
  1231. return transfer.offset().left - transfer.parent().offset().left;
  1232. }
  1233. var removePxOffString = function(str) {
  1234. return parseInt(str.replace('px', ''));
  1235. }
  1236. var updateGradient = function() {
  1237. // Create gradient
  1238. var grd = context.createLinearGradient(0,0,255,0);
  1239. $.each(handles, function(index, value) {
  1240. var $value = $(value),
  1241. colorName = $value.attr('color'),
  1242. colorOffsetLeft = offsetLeft[colorName],
  1243. colorCode = colorCodes[colorName];
  1244. grd.addColorStop(colorOffsetLeft, colorCode);
  1245. });
  1246. // Fill with gradient
  1247. context.fillStyle = grd;
  1248. context.fillRect(0,0,255, 10);
  1249. applyOpacities();
  1250. changed = true;
  1251. };
  1252. var applyOpacities = function() {
  1253. var imageData = context.getImageData(0, 0, 255, 1),
  1254. data = imageData.data;
  1255. for(counter = 0; counter < opacities.length; counter++) {
  1256. data[(counter * 4) + 3] = opacities[counter];
  1257. }
  1258. hiddenContext.putImageData(imageData, 0, 0, 0, 0, 255, 1);
  1259. }
  1260. var updateHandlePosition = function(element) {
  1261. var colorLeft = removePxOffString($(element).css('left')) - getOffsetLeft(),
  1262. colorOffsetLeft = colorLeft / $canvas.width(),
  1263. colorName = $(element).attr('color');
  1264. if(colorOffsetLeft > 1.0) {
  1265. colorOffsetLeft = 1.0;
  1266. }
  1267. if(colorOffsetLeft < 0.0) {
  1268. colorOffsetLeft = 0.0;
  1269. }
  1270. offsetLeft[colorName] = colorOffsetLeft;
  1271. updateGradient();
  1272. };
  1273. var enableTransferFunction = function() {
  1274. $.each(handles, function(index, value) {
  1275. var $value = $(value),
  1276. colorName = $value.attr('color'),
  1277. colorOffsetLeft = offsetLeft[colorName],
  1278. colorLeft = getOffsetLeft() + ($canvas.width() * colorOffsetLeft),
  1279. colorCode = colorCodes[colorName];
  1280. $value.css({left: colorLeft, 'background-color': colorCode });
  1281. $(value).draggable({
  1282. containment: '#transfer-span-holder',
  1283. scroll: false,
  1284. axis: 'x',
  1285. cursor: "crosshair",
  1286. stop: function() {
  1287. updateHandlePosition(this);
  1288. },
  1289. drag: function() {
  1290. updateHandlePosition(this);
  1291. }
  1292. });
  1293. });
  1294. showHandles();
  1295. updateGradient();
  1296. disabled = false;
  1297. };
  1298. var disableTransferFunction = function() {
  1299. context.drawImage($standardTf, 0, 0, 255, 10);
  1300. applyOpacities();
  1301. hideHandles();
  1302. disabled = true;
  1303. changed = true;
  1304. };
  1305. var showHandles = function() {
  1306. $.each(handles, function(index, value) {
  1307. $(value).removeClass('hidden');
  1308. });
  1309. };
  1310. var hideHandles = function() {
  1311. $.each(handles, function(index, value) {
  1312. $(value).addClass('hidden');
  1313. });
  1314. };
  1315. //canvas.setAttribute('width', $canvas.width());
  1316. //canvas.setAttribute('height', $canvas.height());
  1317. disableTransferFunction();
  1318. $(document).on('opacityChanged', function(e, params) {
  1319. if(params != undefined && params.opacities != undefined) {
  1320. opacities = params.opacities;
  1321. applyOpacities();
  1322. changed = true;
  1323. }
  1324. });
  1325. $(document).on('opacityBordersChanged', function(e, params) {
  1326. var minGray = 0,
  1327. maxGray = 255;
  1328. if(params != undefined && params.minGray != undefined && params.maxGray != undefined) {
  1329. minGray = params.minGray;
  1330. maxGray = params.maxGray;
  1331. for(counter = 0; counter < 255; counter++) {
  1332. var opacity = 255;
  1333. if(counter < minGray || counter > maxGray) {
  1334. opacity = 1;
  1335. }
  1336. opacities[counter] = opacity;
  1337. }
  1338. applyOpacities();
  1339. changed = true;
  1340. }
  1341. });
  1342. return {
  1343. transferFunctionChanged : function() {
  1344. return changed;
  1345. },
  1346. getCurrentTransferFunction : function() {
  1347. changed = false;
  1348. return hiddenContext.getImageData(0, 0, 255, 1);
  1349. }
  1350. };
  1351. }
  1352. ;var OverviewHelper = function() {
  1353. var sceneOveriew, rendererOverview, cameraOverview, innerCubeOverview;
  1354. var originalZStretchFactor;
  1355. //private method
  1356. var addInnerCubeOverView = function(x, y, z) {
  1357. var innerCubeGeometry = new THREE.BoxGeometry( x, y, z );
  1358. var innerCubeMaterial = new THREE.MeshBasicMaterial( {color: 0xaaaaaa} );
  1359. innerCubeOverview = new THREE.Mesh( innerCubeGeometry, innerCubeMaterial );
  1360. sceneOverview.add( innerCubeOverview );
  1361. }
  1362. var addInnerFullCube = function() {
  1363. addInnerCubeOverView(1, 1 * originalZStretchFactor, 1);
  1364. };
  1365. var initiateEventListener = function(containerOverviewElement) {
  1366. // change overview box
  1367. $(document).on('zoomActionFinished', function(e, params) {
  1368. zoomedIn = params.zoomAction == 'zoomIn' || zoomedInfo != null;
  1369. sceneOverview.remove(innerCubeOverview);
  1370. if(zoomedIn) {
  1371. xWidth = zoomedInfo.dimension.xywidth / textureInfo.originalSize.sizex;
  1372. yWidth = zoomedInfo.dimension.xywidth / textureInfo.originalSize.sizey;
  1373. zWidth = zoomedInfo.numberOfSlices / textureInfo.originalSize.sizez;
  1374. xOffset = zoomedInfo.dimension.xmin / textureInfo.originalSize.sizex;
  1375. yOffset = zoomedInfo.dimension.ymin / textureInfo.originalSize.sizey;
  1376. zOffset = zoomedInfo.dimension.zmin / (textureInfo.originalSize.sizez * originalZStretchFactor);
  1377. addInnerCubeOverView(xWidth, yWidth, zWidth);
  1378. // main cube was rotated around x axis, so have to swap y and z coordinates
  1379. // for the overview
  1380. innerCubeOverview.position.x = -0.5 + xOffset + xWidth / 2;
  1381. innerCubeOverview.position.y = (-0.5 + zOffset + zWidth / 2);
  1382. innerCubeOverview.position.z = (-0.5 + yOffset + yWidth / 2) * -1;
  1383. } else {
  1384. addInnerFullCube();
  1385. }
  1386. });
  1387. var headerHeight = $('header').height();
  1388. $(window).on('scroll', function(e) {
  1389. $containerOverviewElement = $(containerOverviewElement)
  1390. if($(this).scrollTop() >= headerHeight) {
  1391. $containerOverviewElement.css('position', 'relative');
  1392. $containerOverviewElement.css('top', $(this).scrollTop() - headerHeight);
  1393. } else {
  1394. $containerOverviewElement.css('top', 0);
  1395. }
  1396. });
  1397. }
  1398. var addTextsToScene = function() {
  1399. var shapeParameters = {font: 'helvetiker', size: 0.2, height: 0.05},
  1400. shape = new THREE.TextGeometry("0", shapeParameters),
  1401. wrapper = new THREE.MeshBasicMaterial({color: 0x000000}),
  1402. words = new THREE.Mesh(shape, wrapper);
  1403. words.position.x = -0.6;
  1404. words.position.y = -0.6;
  1405. words.position.z = 0.52;
  1406. sceneOverview.add(words);
  1407. }
  1408. var addCubeEdges = function() {
  1409. // fix for cube
  1410. var numberOfEdges = 12;
  1411. var xColorEdge = new THREE.Color(1,0,0);
  1412. var yColorEdge = new THREE.Color(0,1,0);
  1413. var zColorEdge = new THREE.Color(0,0,1);
  1414. var geometry = new THREE.BufferGeometry();
  1415. var material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors });
  1416. var colors = new Float32Array( numberOfEdges * 2 * 3 );
  1417. var zMin = -0.5 * originalZStretchFactor;
  1418. var zMax = 0.5 * originalZStretchFactor;
  1419. var positions = new Float32Array([
  1420. // edges in x direction
  1421. // front face
  1422. -0.5, zMin, -0.5, 0.5, zMin, -0.5,
  1423. -0.5, zMax, -0.5, 0.5, zMax, -0.5,
  1424. // back face
  1425. -0.5, zMin, 0.5, 0.5, zMin, 0.5,
  1426. -0.5, zMax, 0.5, 0.5, zMax, 0.5,
  1427. // edges in y direction
  1428. // front face
  1429. -0.5, zMin, -0.5, -0.5, zMax, -0.5,
  1430. 0.5, zMin, -0.5, 0.5, zMax, -0.5,
  1431. // back face
  1432. -0.5, zMin, 0.5, -0.5, zMax, 0.5,
  1433. 0.5, zMin, 0.5, 0.5, zMax, 0.5,
  1434. // edges in z direction
  1435. // left side
  1436. -0.5, zMin, -0.5, -0.5, zMin, 0.5,
  1437. -0.5, zMax, -0.5, -0.5, zMax, 0.5,
  1438. // right side
  1439. 0.5, zMin, -0.5, 0.5, zMin, 0.5,
  1440. 0.5, zMax, -0.5, 0.5, zMax, 0.5
  1441. ]);
  1442. for(edgeCounter = 0; edgeCounter < 12 * 2; edgeCounter++) {
  1443. var colorToUse = null
  1444. if(edgeCounter <= 7) {
  1445. colorToUse = xColorEdge;
  1446. } else if(edgeCounter <= 15) {
  1447. colorToUse = zColorEdge;
  1448. } else {
  1449. colorToUse = yColorEdge;
  1450. }
  1451. colors[edgeCounter * 3 + 0] = colorToUse.r;
  1452. colors[edgeCounter * 3 + 1] = colorToUse.g;
  1453. colors[edgeCounter * 3 + 2] = colorToUse.b;
  1454. }
  1455. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  1456. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  1457. var lines = new THREE.Line( geometry, material, THREE.LinePieces );
  1458. sceneOverview.add( lines );
  1459. }
  1460. return {
  1461. initOverview: function(containerOverviewElement) {
  1462. originalZStretchFactor = currentVolumeDimension.getZStretchFactor();
  1463. sceneOverview = new THREE.Scene();
  1464. cameraOverview = new THREE.PerspectiveCamera( 45, 150 / 150, .1, 1000 );
  1465. cameraOverview.position.z = 2;
  1466. var cubeGeometry = new THREE.BoxGeometry( 1, 1, 1 );
  1467. var cubeMaterial = new THREE.MeshBasicMaterial( {color: 0x000000} );
  1468. var cubeOverview = new THREE.Mesh( cubeGeometry, cubeMaterial );
  1469. var edgesHelper = new THREE.EdgesHelper(cubeOverview, 0x000000);
  1470. edgesHelper.material.linewidth = 2;
  1471. //sceneOverview.add( edgesHelper );
  1472. addInnerFullCube();
  1473. addCubeEdges();
  1474. addTextsToScene();
  1475. rendererOverview = new THREE.WebGLRenderer();
  1476. rendererOverview.setSize(200, 200);
  1477. rendererOverview.setClearColor(0xffffff, 1);
  1478. containerOverviewElement.appendChild(rendererOverview.domElement);
  1479. initiateEventListener(containerOverviewElement);
  1480. },
  1481. updateCameraPosition: function(position) {
  1482. cameraPoint.normalize().multiplyScalar(4);
  1483. cameraPoint = sceneOverview.position.clone().add(cameraPoint);
  1484. cameraOverview.position.x = cameraPoint.x;
  1485. cameraOverview.position.y = cameraPoint.y;
  1486. cameraOverview.position.z = cameraPoint.z;
  1487. cameraOverview.lookAt(sceneOverview.position);
  1488. },
  1489. render: function() {
  1490. rendererOverview.render(sceneOverview, cameraOverview);
  1491. }
  1492. }
  1493. }
  1494. ;var VolumeFace = function(orientation, direction) {
  1495. this.orientation = orientation;
  1496. this.direction = direction;
  1497. }
  1498. VolumeFace.prototype = {
  1499. constructor: VolumeFace,
  1500. orientation: 0,
  1501. direction: 0,
  1502. getAxisOfNaviation: function() {
  1503. var axis = {
  1504. plane: {
  1505. ver: null,
  1506. hor: null
  1507. },
  1508. slider: null
  1509. };
  1510. if(this.orientation == VolumeFaceOrientation.XY) {
  1511. axis.plane.ver = new Orientation(Axis.Y);
  1512. axis.plane.hor = new Orientation(Axis.X);
  1513. axis.slider = new Orientation(Axis.Z);
  1514. } else if(this.orientation == VolumeFaceOrientation.YZ) {
  1515. axis.plane.ver = new Orientation(Axis.Z);
  1516. axis.plane.hor = new Orientation(Axis.Y);
  1517. axis.slider = new Orientation(Axis.X);
  1518. } else if(this.orientation == VolumeFaceOrientation.XZ) {
  1519. axis.plane.ver = new Orientation(Axis.Z);
  1520. axis.plane.hor = new Orientation(Axis.X);
  1521. axis.slider = new Orientation(Axis.Y);
  1522. }
  1523. return axis;
  1524. },
  1525. getIdentifier: function() {
  1526. return this.orientation + '-' + this.direction;
  1527. }
  1528. };
  1529. var VolumeFaceOrientation = {
  1530. XY: 0,
  1531. XZ: 1,
  1532. YZ: 2
  1533. }
  1534. var VolumeFaceDirection = {
  1535. FRONT: 0,
  1536. BACK: 1
  1537. }
  1538. function determineVolumeFace(cubeFaceNormal) {
  1539. var orientation, direction;
  1540. if(cubeFaceNormal.x != 0) {
  1541. orientation = VolumeFaceOrientation.YZ;
  1542. direction = determineFaceOrientation(cubeFaceNormal.x);
  1543. } else if(cubeFaceNormal.y != 0) {
  1544. orientation = VolumeFaceOrientation.XZ;
  1545. direction = determineFaceOrientation(cubeFaceNormal.y);
  1546. } else if(cubeFaceNormal.z != 0) {
  1547. orientation = VolumeFaceOrientation.XY;
  1548. direction = determineFaceOrientation(cubeFaceNormal.z);
  1549. }
  1550. return new VolumeFace(orientation, direction);
  1551. }
  1552. function determineFaceOrientation(normalComp) {
  1553. return normalComp > 0 ? VolumeFaceDirection.FRONT : VolumeFaceDirection.BACK;
  1554. }
  1555. function isFrontFace(orientation, direction) {
  1556. return orientation == VolumeFaceOrientation.XY
  1557. && direction == VolumeFaceDirection.FRONT;
  1558. }
  1559. function isBackFace(orientation, direction) {
  1560. return orientation == VolumeFaceOrientation.XY
  1561. && direction == VolumeFaceDirection.BACK;
  1562. }
  1563. function isLeftFace(orientation, direction) {
  1564. return orientation == VolumeFaceOrientation.YZ
  1565. && direction == VolumeFaceDirection.FRONT;
  1566. }
  1567. function isRightFace(orientation, direction) {
  1568. return orientation == VolumeFaceOrientation.YZ
  1569. && direction == VolumeFaceDirection.BACK;
  1570. }
  1571. function isTopFace(orientation, direction) {
  1572. return orientation == VolumeFaceOrientation.XZ
  1573. && direction == VolumeFaceDirection.FRONT;
  1574. }
  1575. function isBottomFace(orientation, direction) {
  1576. return orientation == VolumeFaceOrientation.XZ
  1577. && direction == VolumeFaceDirection.BACK;
  1578. }
  1579. ;var ZoomHelper = function() {
  1580. var navigationPlaneHorLabel = $('#navigation-plane-hor-label'),
  1581. navigationPlaneVerLabel = $('#navigation-plane-ver-label'),
  1582. navigationSliderLabel = $('#navigation-slider-label'),
  1583. zoomStatus = $('#zoom-status'),
  1584. zoomInButton = $('input#zoomin'),
  1585. zoomOutButton = $('input#zoomout'),
  1586. navigationPlane = $('div#navigation-plane'),
  1587. navigationPlaneParent = navigationPlane.parent(),
  1588. navigationSlider = $('div#navigation-slider'),
  1589. navigationSliderParent = navigationSlider.parent(),
  1590. displayTimestamp = null,
  1591. planeOrientation = {
  1592. ver: new Orientation(Axis.Y, OffsetTo.LEFT),
  1593. hor: new Orientation(Axis.X, OffsetTo.TOP),
  1594. direction: VolumeFaceDirection.BACK,
  1595. orientation: VolumeFaceOrientation.XY
  1596. },
  1597. sliderOrientation = {axis: new Orientation(Axis.Z, OffsetTo.TOP) },
  1598. zoomedIn,
  1599. zoomedInfoArray = {
  1600. dimension: Array(3),
  1601. offset: Array(3)
  1602. },
  1603. oldZoomedInfos = [];
  1604. var lastExecutionTime = Date.now();
  1605. // adjust navigation related navigations
  1606. $container.on('animation', function() {
  1607. determineAxisLabels();
  1608. determinePlanePosition();
  1609. determineSliderPosition();
  1610. });
  1611. // one has to press ctrl AND alt while clicking
  1612. $container.on('click', 'canvas', function(event){
  1613. event.stopPropagation();
  1614. event.preventDefault();
  1615. // keyboard shortcut activated or button zoom in pressed before?
  1616. if((event.ctrlKey == false || event.altKey == false)
  1617. && !zoomInActivated) {
  1618. return;
  1619. }
  1620. var mouseX = ( (event.clientX - $canvas.offset().left) / ($canvas.width()) ) * 2 - 1,
  1621. mouseY = - ( (event.clientY - $canvas.offset().top) / ($canvas.height()) ) * 2 + 1;
  1622. var vector = new THREE.Vector3( mouseX, mouseY, camera.near);
  1623. vector = vector.unproject( camera );
  1624. var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
  1625. var intersects = raycaster.intersectObjects( [frontBox] );
  1626. if(intersects.length > 0) {
  1627. if(!handleZoomStatus(true)) {
  1628. return false;
  1629. }
  1630. var intersect = intersects[0],
  1631. point = intersect.point;
  1632. var geometry = new THREE.BoxGeometry( 0.1, 0.1, 0.1 );
  1633. var material = new THREE.MeshBasicMaterial( {
  1634. color: new THREE.Color( 0xaaaaaa ),
  1635. opacity: 0.3
  1636. });
  1637. mesh = new THREE.Mesh( geometry, material );
  1638. mesh.position.x = point.x;
  1639. mesh.position.y = point.y;
  1640. mesh.position.z = point.z;
  1641. scene.add(mesh);
  1642. intersectCubes[intersectCubes.length] = mesh;
  1643. intersectCubesTimeStamps[intersectCubesTimeStamps.length] = Date.now();
  1644. var realPoint = point.clone();
  1645. getSubvolume(point, false, 'zoomIn', false);
  1646. }
  1647. });
  1648. function getSubvolume(realPoint, alreadyTranslated, zoomAction, sameDepth, fromDraggable) {
  1649. if(alreadyTranslated == undefined || !alreadyTranslated) {
  1650. realPoint = realPoint.applyMatrix4((new THREE.Matrix4).makeRotationX(Math.PI / -2));
  1651. // retranslate the point into original position beginning from 0,0,0
  1652. realPoint.add(new THREE.Vector3(0.5, 0.5, 0.5));
  1653. }
  1654. volumePointArray = realPoint.toArray();
  1655. var processingUrl = IPE.util.buildUrl('volumes/' + volumeId + '/processing/sub/');
  1656. $.each(volumePointArray, function(index, value) {
  1657. dimWidth = null;
  1658. // have to decide, whether we in zoomed in or zoomed out status
  1659. if(zoomedInfo == undefined || zoomedInfo == null || fromDraggable) {
  1660. if(index == 0) {
  1661. dimWidth = textureInfo.originalSize.sizex;
  1662. } else if(index == 1) {
  1663. dimWidth = textureInfo.originalSize.sizey;
  1664. } else {
  1665. dimWidth = textureInfo.originalSize.sizez;
  1666. }
  1667. } else {
  1668. if(index < 2) {
  1669. dimWidth = zoomedInfo.dimension.xywidth;
  1670. } else {
  1671. dimWidth = zoomedInfo.numberOfSlices;
  1672. }
  1673. }
  1674. value *= dimWidth;
  1675. // due to interpolation algorithm, we had to rotate the whole cube, that it matches
  1676. // the display of imagej
  1677. // so we have to map the current pointer values to the real volume values
  1678. // but only for the y and z direction --> the x direction is all right
  1679. if(index > 0) {
  1680. value = dimWidth - value;
  1681. }
  1682. if(!fromDraggable && zoomedInfo) {
  1683. if(index == 0) {
  1684. value = value + zoomedInfo.dimension.xmin;
  1685. } else if(index == 1) {
  1686. value = value + zoomedInfo.dimension.ymin;
  1687. } else {
  1688. value = value + zoomedInfo.dimension.zmin;
  1689. }
  1690. }
  1691. value = Math.floor(value);
  1692. volumePointArray[index] = value;
  1693. processingUrl += value + '/';
  1694. });
  1695. frameNumber = imgInfo.frameFrom + currentTexture;
  1696. processingUrl += frameNumber + '/';
  1697. depth = 1;
  1698. if(zoomAction == 'zoomIn') {
  1699. if(zoomedInfo != null){
  1700. if(sameDepth) {
  1701. depth = zoomedInfo.depth;
  1702. } else {
  1703. depth = zoomedInfo.depth + 1;
  1704. }
  1705. }
  1706. } else if(zoomAction == 'zoomOut') {
  1707. if(zoomedInfo.depth > 1) {
  1708. depth = zoomedInfo.depth - 1;
  1709. }
  1710. }
  1711. while(oldZoomedInfos.length > 0
  1712. && oldZoomedInfos.last().zoomedInfo.depth >= depth)
  1713. {
  1714. oldZoomedInfos.pop();
  1715. }
  1716. processingUrl += depth + '/';
  1717. $.ajax({
  1718. url: processingUrl,
  1719. success: function(data) {
  1720. var available = false;
  1721. var availableTestCounter = 0;
  1722. zoomedInfo = data;
  1723. oldZoomedInfos.push({
  1724. point: realPoint,
  1725. translated: true,
  1726. zoomedInfo: zoomedInfo
  1727. });
  1728. // this function is called recursive by the settimeout statement
  1729. availableTest = function() {
  1730. $.ajax({
  1731. url: IPE.util.buildUrl('volumes/' + volumeId + '/processing/sprite/' + zoomedInfo.spriteId + '/available/'),
  1732. success: function(data) {
  1733. available = data.available;
  1734. },
  1735. dataType: 'json',
  1736. async: false
  1737. });
  1738. if(available) {
  1739. // subvolume available: fetch it
  1740. fetchSubVolume(zoomAction);
  1741. } else if(availableTestCounter < 80) {
  1742. // abort condition not reached --> try again
  1743. setTimeout(availableTest, 500);
  1744. availableTestCounter++;
  1745. } else {
  1746. oldZoomedInfos.pop();
  1747. // abort condition reached --> error handling
  1748. $(document).trigger('zoomActionFinished', { zoomAction: zoomAction, error: true });
  1749. }
  1750. };
  1751. setTimeout(availableTest, 500);
  1752. },
  1753. dataType: 'json',
  1754. async: true,
  1755. error: function(data) {
  1756. helper.displayMessage('Sorry, an error occured during processing zoom', true, null, 2500);
  1757. }
  1758. });
  1759. };
  1760. var fetchSubVolume = function(zoomAction) {
  1761. imageSrc = IPE.util.buildUrl('volumes/' + volumeId + '/processing/sprite/' + zoomedInfo.spriteId + '/show/');
  1762. var image = new Image();
  1763. var texture = initTexture(new THREE.Texture(image));
  1764. image.onload = function() {
  1765. materialScreen.uniforms.numberOfSlices.value = zoomedInfo.numberOfSlices;
  1766. materialScreen.uniforms.numberOfSlices.needsupdate = true;
  1767. materialScreen.uniforms.slicesOverX.value = zoomedInfo.slicesOverX;
  1768. materialScreen.uniforms.slicesOverX.needsUpdate = true;
  1769. materialScreen.uniforms.slicesOverY.value = zoomedInfo.slicesOverY;
  1770. materialScreen.uniforms.slicesOverY.needsUpdate = true;
  1771. materialScreen.uniforms.numberOfSprites.value = 1;
  1772. materialScreen.uniforms.numberOfSprites.needsUpdate = true;
  1773. materialScreen.uniforms.slicesPerSprite.value = zoomedInfo.numberOfSlices;
  1774. materialScreen.uniforms.slicesPerSprite.needsUpdate = true;
  1775. updateTexture([texture]);
  1776. zoomedVolumeDimension.xmin = zoomedInfo.dimension.xmin;
  1777. zoomedVolumeDimension.xmax = zoomedInfo.dimension.xmin + zoomedInfo.dimension.xywidth - 1;
  1778. zoomedVolumeDimension.ymin = zoomedInfo.dimension.ymin;
  1779. zoomedVolumeDimension.ymax = zoomedInfo.dimension.ymin + zoomedInfo.dimension.xywidth - 1;
  1780. zoomedVolumeDimension.zmin = zoomedInfo.dimension.zmin;
  1781. zoomedVolumeDimension.zmax = zoomedInfo.dimension.zmin + zoomedInfo.numberOfSlices - 1;
  1782. originalVolumeDimension = currentVolumeDimension;
  1783. originalDimension = currentDimension;
  1784. currentVolumeDimension = zoomedVolumeDimension;
  1785. repositionLayerSliders();
  1786. $(document).trigger('zoomActionFinished', {
  1787. zoomAction: zoomAction, textureNumber: frameNumber
  1788. });
  1789. }
  1790. image.src = imageSrc;
  1791. };
  1792. $container.on('contextmenu', function(event){
  1793. if(event.ctrlKey == false) {
  1794. return;
  1795. }
  1796. if(event.altKey == false) {
  1797. return;
  1798. }
  1799. if(!handleZoomStatus(false)) {
  1800. return false;
  1801. }
  1802. return zoomOut();
  1803. });
  1804. function zoomOut() {
  1805. currentZoomPoint = oldZoomedInfos.pop().point;
  1806. if(oldZoomedInfos.length > 0) {
  1807. // using the current point to get a new subvolume
  1808. getSubvolume(currentZoomPoint, true, 'zoomOut', true);
  1809. return false;
  1810. }
  1811. else
  1812. {
  1813. zoomedInfo = null;
  1814. materialScreen.uniforms.numberOfSlices.value = textureInfo.info.numberOfSlices;
  1815. materialScreen.uniforms.numberOfSlices.needsupdate = true;
  1816. materialScreen.uniforms.slicesOverX.value = textureInfo.info.slicesOverX;
  1817. materialScreen.uniforms.slicesOverX.needsUpdate = true;
  1818. materialScreen.uniforms.slicesOverY.value = textureInfo.info.slicesOverY;
  1819. materialScreen.uniforms.slicesOverY.needsUpdate = true;
  1820. materialScreen.uniforms.numberOfSprites.value = imgInfo.numberOfSprites;
  1821. materialScreen.uniforms.numberOfSprites.needsUpdate = true;
  1822. materialScreen.uniforms.slicesPerSprite.value = imgInfo.slicesPerSprite;
  1823. materialScreen.uniforms.slicesPerSprite.needsUpdate = true;
  1824. updateTexture();
  1825. currentVolumeDimension = originalVolumeDimension;
  1826. currentDimension = originalDimension;
  1827. repositionLayerSliders();
  1828. }
  1829. $(document).trigger('zoomActionFinished', {
  1830. zoomAction: 'zoomOut'
  1831. });
  1832. return false;
  1833. }
  1834. function zoomInAllowed() {
  1835. return !zoomedIn || zoomedInfo.dimension.xywidth > 300;
  1836. }
  1837. /**
  1838. * return: procceed or not
  1839. */
  1840. function handleZoomStatus(zoomIn) {
  1841. zoomInButton.removeClass('red');
  1842. zoomInActivated = false;
  1843. if(zoomIn && !zoomInAllowed()) {
  1844. return false;
  1845. } else if(!zoomIn && !zoomedIn) {
  1846. return false;
  1847. }
  1848. waitDiv.removeClass('hidden');
  1849. displayMessage = zoomIn ? 'Generating zoomed subvolume, please wait a moment' : 'Zooming out';
  1850. helper.displayMessage(displayMessage);
  1851. displayTimestamp = Date.now();
  1852. return true;
  1853. }
  1854. // general function to disable stuff like messages etc.
  1855. $(document).on('zoomActionFinished', function(e, params) {
  1856. zoomedIn = zoomedInfo != null;
  1857. timeout = 2000 - (Date.now() - displayTimestamp);
  1858. if(timeout < 0) {
  1859. timeout = 0;
  1860. }
  1861. helper.fadeoutMessage(null, timeout);
  1862. zoomedStatusText = '';
  1863. if(zoomedIn) {
  1864. zoomStatus.addClass('green-background');
  1865. zoomedStatusText = 'zoomed in';
  1866. $.each($('.res-link'), function(index, value) {
  1867. $(value).addClass('disabled');
  1868. });
  1869. if(zoomedInfo.dimension.xywidth <= 300) {
  1870. zoomInButton.prop('disabled', true);
  1871. }
  1872. } else {
  1873. zoomStatus.removeClass('green-background');
  1874. zoomedStatusText = 'zoomed out';
  1875. if(params.error) {
  1876. errorMessage = 'Error during subvolume generation - zoomed out again';
  1877. helper.displayMessage(errorMessage, true, null, 5000);
  1878. }
  1879. $.each($('.res-link'), function(index, value) {
  1880. $(value).removeClass('disabled');
  1881. });
  1882. zoomInButton.prop('disabled', false);
  1883. }
  1884. zoomStatus.html(zoomedStatusText);
  1885. waitDiv.addClass('hidden');
  1886. });
  1887. // draggable related stuff
  1888. // TODO for multilevel zooming
  1889. $(document).on('zoomActionFinished', function(e, params) {
  1890. zoomedIn = zoomedInfo != null;
  1891. if(zoomedIn) {
  1892. zoomedInfoArray.offset[Axis.X] = zoomedVolumeDimension.xmin;
  1893. zoomedInfoArray.offset[Axis.Y] = zoomedVolumeDimension.ymin;
  1894. zoomedInfoArray.offset[Axis.Z] = zoomedVolumeDimension.zmin;
  1895. zoomedInfoArray.dimension[Axis.X] = zoomedInfo.dimension.xywidth;
  1896. zoomedInfoArray.dimension[Axis.Y] = zoomedInfo.dimension.xywidth;
  1897. zoomedInfoArray.dimension[Axis.Z] = zoomedInfo.numberOfSlices;
  1898. } else {
  1899. navigationPlane.hide();
  1900. navigationPlaneParent.removeClass('white');
  1901. navigationSlider.hide();
  1902. navigationSliderParent.removeClass('white');
  1903. }
  1904. navigationPlane.removeClass('no-pos-set');
  1905. navigationSlider.removeClass('no-pos-set');
  1906. });
  1907. navigationPlane.draggable({
  1908. containment: '#navigation-plane-container',
  1909. scroll: false,
  1910. stop: function() {
  1911. zoomedDraggableChanged();
  1912. }
  1913. });
  1914. navigationSlider.draggable({
  1915. containment: '#navigation-slider-container',
  1916. scroll: false,
  1917. stop: function() {
  1918. zoomedDraggableChanged();
  1919. }
  1920. });
  1921. function zoomedDraggableChanged() {
  1922. waitDiv.removeClass('hidden');
  1923. var planeWidthHalf = navigationPlane.width() / 2,
  1924. planeHeightHalf = navigationPlane.height() / 2,
  1925. planeOffsetLeft = navigationPlane.offset().left - navigationPlaneParent.offset().left - 1,
  1926. planeOffsetTop = navigationPlane.offset().top - navigationPlaneParent.offset().top - 1,
  1927. sliderHeightHalf = navigationSlider.height() / 2,
  1928. sliderOffsetTop = navigationSlider.offset().top - navigationSliderParent.offset().top - 1,
  1929. orientation = planeOrientation.orientation,
  1930. direction = planeOrientation.direction;
  1931. // set correct border values due to messure errors
  1932. if(planeOffsetLeft < 0) {
  1933. planeOffsetLeft = 0;
  1934. } else if(planeOffsetLeft > navigationPlaneParent.width() - navigationPlane.width()) {
  1935. planeOffsetLeft = navigationPlaneParent.width() - navigationPlane.width();
  1936. }
  1937. if(planeOffsetTop < 0) {
  1938. planeOffsetTop = 0;
  1939. } else if(planeOffsetTop > navigationPlaneParent.height() - navigationPlane.height()) {
  1940. planeOffsetTop = navigationPlaneParent.height() - navigationPlane.height();
  1941. }
  1942. if(sliderOffsetTop < 0) {
  1943. sliderOffsetTop = 0;
  1944. } else if(sliderOffsetTop > navigationSliderParent.height() - navigationSlider.height()) {
  1945. sliderOffsetTop = navigationSliderParent.height() - navigationSlider.height();
  1946. }
  1947. planeOffsetLeft = planeOffsetLeft + planeWidthHalf;
  1948. planeOffsetTop = planeOffsetTop + planeHeightHalf;
  1949. sliderOffsetTop = sliderOffsetTop + sliderHeightHalf;
  1950. horAxis = planeOrientation.hor.axis;
  1951. verAxis = planeOrientation.ver.axis;
  1952. pointAsArray = Array(3);
  1953. pointAsArray[horAxis] = planeOffsetLeft / navigationPlaneParent.width();
  1954. pointAsArray[verAxis] = planeOffsetTop / navigationPlaneParent.height();
  1955. /*if(planeOrientation.direction == VolumeFaceDirection.BACK) {
  1956. pointAsArray[horAxis] = 1.0 - pointAsArray[horAxis];
  1957. } else if(planeOrientation.orientation == VolumeFaceOrientation.XZ) {
  1958. pointAsArray[horAxis] = 1.0 - pointAsArray[horAxis];
  1959. }*/
  1960. if((planeOrientation.orientation == VolumeFaceOrientation.XY
  1961. && planeOrientation.direction == VolumeFaceDirection.BACK)
  1962. || (planeOrientation.orientation == VolumeFaceOrientation.YZ
  1963. && planeOrientation.direction == VolumeFaceDirection.BACK)
  1964. || (planeOrientation.orientation == VolumeFaceOrientation.XZ
  1965. && planeOrientation.direction == VolumeFaceDirection.BACK)) {
  1966. pointAsArray[horAxis] = 1.0 - pointAsArray[horAxis];
  1967. }
  1968. pointAsArray[sliderOrientation.axis] = sliderOffsetTop / navigationSliderParent.height();
  1969. /*if((sliderOrientation.axis == Axis.Z
  1970. && planeOrientation.direction == VolumeFaceDirection.FRONT)
  1971. || (sliderOrientation.axis == Axis.Y
  1972. && planeOrientation.direction == VolumeFaceDirection.FRONT)
  1973. || (sliderOrientation.axis == Axis.X
  1974. && planeOrientation.direction == VolumeFaceDirection.BACK)) {
  1975. pointAsArray[sliderOrientation.axis] = 1.0 - pointAsArray[sliderOrientation.axis];
  1976. }*/
  1977. if((sliderOrientation.axis == Axis.X
  1978. && planeOrientation.direction == VolumeFaceDirection.FRONT)
  1979. || (sliderOrientation.axis == Axis.Y
  1980. && planeOrientation.direction == VolumeFaceDirection.BACK)
  1981. || (sliderOrientation.axis == Axis.Z
  1982. && planeOrientation.direction == VolumeFaceDirection.BACK)) {
  1983. pointAsArray[sliderOrientation.axis] = 1.0 - pointAsArray[sliderOrientation.axis];
  1984. }
  1985. point = new THREE.Vector3(pointAsArray[0], pointAsArray[1], pointAsArray[2]);
  1986. getSubvolume(point, true, 'zoomIn', true, true);
  1987. };
  1988. var zoomInActivated = false;
  1989. zoomInButton.on('click', function() {
  1990. zoomInActivated = !zoomInActivated;
  1991. if(zoomInActivated) {
  1992. $(this).addClass('red');
  1993. } else {
  1994. $(this).removeClass('red');
  1995. }
  1996. });
  1997. zoomOutButton.on('click', function() {
  1998. zoomInButton.removeClass('red');
  1999. if(!handleZoomStatus(false)) {
  2000. return false;
  2001. }
  2002. return zoomOut();
  2003. });
  2004. function determineAxisLabels() {
  2005. if(Date.now() - lastExecutionTime > 100) {
  2006. var lookAtVector = new THREE.Vector3(0,0, -1);
  2007. lookAtVector.applyQuaternion(camera.quaternion);
  2008. xIterator = -0.4;
  2009. yIterator = -0.4;
  2010. facesIntersect = {};
  2011. interSectStartingPoint = new THREE.Vector3(xIterator, yIterator, camera.near);
  2012. for(xIterator = -0.4; xIterator <= 0.4; xIterator += 0.2) {
  2013. for(yIterator = -0.4; yIterator <= 0.4; yIterator += 0.2) {
  2014. interSectStartingPoint.x = xIterator;
  2015. interSectStartingPoint.y = yIterator;
  2016. vector = interSectStartingPoint.unproject( camera );
  2017. var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
  2018. var intersects = raycaster.intersectObjects( [frontBox] );
  2019. if(intersects.length > 0) {
  2020. var intersect = intersects[0],
  2021. point = intersect.point,
  2022. face = intersect.face,
  2023. faceObject = determineVolumeFace(face.normal),
  2024. faceIdent = faceObject.getIdentifier();
  2025. alreadyAdded = Object.keys(facesIntersect).indexOf(faceIdent) >= 0;
  2026. if(alreadyAdded) {
  2027. facesIntersect[faceIdent].count++;
  2028. } else {
  2029. facesIntersect[faceIdent] = { faceObject: faceObject, count: 1};
  2030. }
  2031. }
  2032. }
  2033. }
  2034. frontFace = { count: 0 };
  2035. for(faceIdent in facesIntersect) {
  2036. if(facesIntersect[faceIdent].count > frontFace.count) {
  2037. frontFace = facesIntersect[faceIdent];
  2038. }
  2039. }
  2040. if(frontFace.faceObject != undefined) {
  2041. volumeFace = frontFace.faceObject;
  2042. axisOfNaviation = volumeFace.getAxisOfNaviation();
  2043. planeOrientation = axisOfNaviation.plane;
  2044. planeOrientation.hor.offsetTo = OffsetTo.LEFT;
  2045. planeOrientation.ver.offsetTo = OffsetTo.TOP;
  2046. planeOrientation.direction = volumeFace.direction;
  2047. planeOrientation.orientation = volumeFace.orientation;
  2048. sliderOrientation = axisOfNaviation.slider;
  2049. sliderOrientation.offsetTo = OffsetTo.TOP;
  2050. navigationPlaneHorLabel.html(planeOrientation.hor.getLabel());
  2051. navigationPlaneVerLabel.html(planeOrientation.ver.getLabel());
  2052. navigationSliderLabel.html(sliderOrientation.getLabel());
  2053. }
  2054. lastExecutionTime = Date.now();
  2055. }
  2056. }
  2057. function determinePlanePosition() {
  2058. if(!zoomedIn) {
  2059. return;
  2060. }
  2061. if(navigationPlane.hasClass('ui-draggable-dragging')
  2062. || navigationPlane.hasClass('no-pos-set')) {
  2063. navigationPlane.addClass('no-pos-set');
  2064. return;
  2065. }
  2066. horAxis = planeOrientation.hor.axis;
  2067. verAxis = planeOrientation.ver.axis;
  2068. planeRelativeX = navigationPlaneParent.width() / originalSizeArray[horAxis];
  2069. planeRelativeY = navigationPlaneParent.height() / originalSizeArray[verAxis];
  2070. planeWidth = planeRelativeX * zoomedInfoArray.dimension[horAxis];
  2071. planeHeight = planeRelativeY * zoomedInfoArray.dimension[verAxis];
  2072. planeWidth = Math.ceil(planeWidth);
  2073. planeHeight = Math.ceil(planeHeight);
  2074. planeOffsetLeft = zoomedInfoArray.offset[horAxis] * planeRelativeX;
  2075. if((planeOrientation.direction == VolumeFaceDirection.BACK
  2076. && planeOrientation.orientation == VolumeFaceOrientation.XZ)
  2077. || (planeOrientation.direction == VolumeFaceDirection.FRONT
  2078. && planeOrientation.orientation == VolumeFaceOrientation.YZ)) {
  2079. planeOffsetLeft = navigationPlaneParent.width() - (planeOffsetLeft + navigationPlane.width());
  2080. }
  2081. planeOffsetTop = zoomedInfoArray.offset[verAxis] * planeRelativeY;
  2082. if(planeOrientation.orientation == VolumeFaceOrientation.XZ
  2083. || planeOrientation.orientation == VolumeFaceOrientation.YZ){
  2084. planeOffsetTop = navigationPlaneParent.height() - (planeOffsetTop + navigationPlane.height());
  2085. }
  2086. navigationPlane.css({
  2087. 'top': planeOffsetTop + 'px',
  2088. 'left' : planeOffsetLeft + 'px',
  2089. 'width': planeWidth + 'px',
  2090. 'height': planeHeight + 'px'
  2091. });
  2092. navigationPlane.show();
  2093. navigationPlaneParent.addClass('white');
  2094. }
  2095. function determineSliderPosition() {
  2096. if(!zoomedIn) {
  2097. return;
  2098. }
  2099. if(navigationSlider.hasClass('ui-draggable-dragging')
  2100. || navigationSlider.hasClass('no-pos-set')) {
  2101. navigationSlider.addClass('no-pos-set');
  2102. return;
  2103. }
  2104. sliderRelative = navigationSliderParent.height() / originalSizeArray[sliderOrientation.axis];
  2105. sliderOffsetTop = zoomedInfoArray.offset[sliderOrientation.axis] * sliderRelative;
  2106. sliderHeight = Math.ceil(sliderRelative * zoomedInfoArray.dimension[sliderOrientation.axis]);
  2107. if(planeOrientation.direction == VolumeFaceDirection.FRONT) {
  2108. sliderOffsetTop = navigationSliderParent.height() - (navigationSlider.height() + sliderOffsetTop);
  2109. }
  2110. navigationSlider.css({
  2111. 'top': sliderOffsetTop + 'px',
  2112. 'height': sliderHeight + 'px'
  2113. });
  2114. navigationSlider.show();
  2115. navigationSliderParent.addClass('white');
  2116. }
  2117. };
  2118. function radToDeg(rad) {
  2119. return rad * 180 / Math.PI;
  2120. }
  2121. ;var Orientation = function(axis, offsetTo) {
  2122. this._axis = axis;
  2123. this._offsetTo = null;
  2124. }
  2125. Orientation.prototype = {
  2126. constructor: Orientation,
  2127. getLabel: function() {
  2128. switch(this._axis) {
  2129. case(Axis.X):
  2130. return 'x-axis';
  2131. case(Axis.Y):
  2132. return 'y-axis';
  2133. case(Axis.Z):
  2134. return 'z-axis';
  2135. }
  2136. },
  2137. get axis() {
  2138. return this._axis;
  2139. },
  2140. get offsetTo() {
  2141. return this._offsetTo;
  2142. },
  2143. set offsetTo(value) {
  2144. this._offsetTo = value;
  2145. }
  2146. }
  2147. var Axis = {
  2148. X: 0,
  2149. Y: 1,
  2150. Z: 2
  2151. }
  2152. var OffsetTo = {
  2153. TOP: 0,
  2154. LEFT: 1,
  2155. BOTTOM: 2,
  2156. RIGHT: 3
  2157. }
  2158. ;IPE.interceptors.SendInterceptor = (function() {
  2159. return {
  2160. init: function() {
  2161. $(document).ajaxSend(function (e, xhr, settings) {
  2162. if(settings.url.indexOf('/static/') === -1) {
  2163. if(!settings.url.endsWith('/')) {
  2164. settings.url += '/';
  2165. }
  2166. }
  2167. });
  2168. }
  2169. };
  2170. }())
  2171. ;var NavigationPlane = function(element, horizontalLabel, verticalLabel) {
  2172. this._element = element;
  2173. this._parent = element.parent();
  2174. this._horizontalLabel = horizontalLabel;
  2175. this._verticalLabel = verticalLabel;
  2176. this._zoomedInfoArray = null;
  2177. this._volumeFace = null;
  2178. }
  2179. NavigationPlane.prototype = {
  2180. constructor: NavigationPlane,
  2181. set zoomedInfoArray(value) {
  2182. this._zoomedInfoArray = value;
  2183. },
  2184. set volumeFace(value) {
  2185. this._volumeFace = value;
  2186. },
  2187. }
  2188. ;