From 2c8523285c3d646476953c6929ca455188b907ec Mon Sep 17 00:00:00 2001 From: amrita.vishnoi Date: Mon, 4 Jul 2016 18:30:26 +0530 Subject: [PATCH] made changes to more optimized the code but facing issues in modifying image data in web worker. --- 400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------- 400-SOURCECODE/AIAHTML5.Web/term-number-wp.js | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 116 insertions(+), 80 deletions(-) diff --git a/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js b/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js index 6077048..5975900 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js @@ -1366,14 +1366,18 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo console.log('Start time taken for term: ' + TermList[i]._TermNumber + 'in posting: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); worker.postMessage({ 'termNumber': TermList[i]._TermNumber, - 'maskCanvasData': $scope.MaskCanvasData + 'maskCanvasData': $scope.MaskCanvasData, + 'coloredImageCanvasList': $rootScope.coloredImageCanvasList, + 'coloredImageMRCanvasList': $rootScope.coloredImageMRCanvasList, + 'grayImageDataList': $rootScope.grayImageDataList, + 'grayImageMRDataList': $rootScope.grayImageMRDataList }); } worker.onmessage = function (e) { console.log('callback time taken : ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); - $scope.fillMatchedTerm(e.data.value); + $scope.fillMatchedTerm(e.data.value, e.data.BRId); }; @@ -1456,113 +1460,117 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo - $scope.fillMatchedTerm = function (matchedLocationData) + $scope.fillMatchedTerm = function (grayImageDataVar, BrId) { console.log('Start time taken in fillMatchedTerm: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); - for (var x = 0; x < $scope.ColoredImageSRC.length; x++) { - // alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId); - var bodyRegionId = $scope.ColoredImageSRC[x].bodyRegionId; + //for (var x = 0; x < $scope.ColoredImageSRC.length; x++) { + // // alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId); + // var bodyRegionId = $scope.ColoredImageSRC[x].bodyRegionId; - { + // { - var scaledWidth = $scope.ColoredImageSRC[x].Width; - var scaledHeight = $scope.ColoredImageSRC[x].Height; - //var maskImg = $scope.ColoredImageSRC[x].SRC; + // var scaledWidth = $scope.ColoredImageSRC[x].Width; + // var scaledHeight = $scope.ColoredImageSRC[x].Height; + // //var maskImg = $scope.ColoredImageSRC[x].SRC; - var coloredImg = $scope.ColoredImageSRC[x].SRC; + // var coloredImg = $scope.ColoredImageSRC[x].SRC; - var maskImg = $scope.GetMaskImageSource(coloredImg); + // var maskImg = $scope.GetMaskImageSource(coloredImg); - var scledX = $scope.ColoredImageSRC[x].x; - var scledY = $scope.ColoredImageSRC[x].y; + // var scledX = $scope.ColoredImageSRC[x].x; + // var scledY = $scope.ColoredImageSRC[x].y; - // 1. get mask canvas for this body region. - //var maskCanvasID; - //if ($scope.ColoredImageSRC[x].haveMirror == 'true') { - // maskCanvasID = 'imageCanvas' + bodyRegionId + '_MR_mci'; - //} - //else { - // maskCanvasID = 'imageCanvas' + bodyRegionId + '_mci'; + // // 1. get mask canvas for this body region. + // //var maskCanvasID; + // //if ($scope.ColoredImageSRC[x].haveMirror == 'true') { + // // maskCanvasID = 'imageCanvas' + bodyRegionId + '_MR_mci'; + // //} + // //else { + // // maskCanvasID = 'imageCanvas' + bodyRegionId + '_mci'; - //} - //var maskCanvas = document.getElementById(maskCanvasID); - //var maskCanvasContext = maskCanvas.getContext("2d"); - //var maskImgData = maskCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); + // //} + // //var maskCanvas = document.getElementById(maskCanvasID); + // //var maskCanvasContext = maskCanvas.getContext("2d"); + // //var maskImgData = maskCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); - // 2. get coloured canvas for this body region. + // // 2. get coloured canvas for this body region. - var coloredImageDataVar; - var coloredImageDataMRVar + // var coloredImageDataVar; + // var coloredImageDataMRVar - if ($scope.ColoredImageSRC[x].haveMirror == 'true') { + // if ($scope.ColoredImageSRC[x].haveMirror == 'true') { - coloredImageDataVar = $rootScope.coloredImageMRCanvasList[parseInt(bodyRegionId)]; - } - else { - coloredImageDataVar = $rootScope.coloredImageCanvasList[parseInt(bodyRegionId - 1)]; - } - var grayImageDataVar; - var grayCanvas; - if ($scope.ColoredImageSRC[x].haveMirror == 'true') { - - //// 3. get mask canvas for this body region._MR - var grayCanvasID = 'imageCanvas' + bodyRegionId + '_MR'; - grayCanvas = document.getElementById(grayCanvasID); - var grayCanvasContext = grayCanvas.getContext("2d"); - var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); - grayImageDataVar = grayImageData.data; - } + // coloredImageDataVar = $rootScope.coloredImageMRCanvasList[parseInt(bodyRegionId)]; + // } + // else { + // coloredImageDataVar = $rootScope.coloredImageCanvasList[parseInt(bodyRegionId - 1)]; + // } + // var grayImageDataVar; + // var grayCanvas; + // if ($scope.ColoredImageSRC[x].haveMirror == 'true') { - else { - var grayCanvasID = 'imageCanvas' + bodyRegionId; - grayCanvas = document.getElementById(grayCanvasID); - var grayCanvasContext = grayCanvas.getContext("2d"); - var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); - grayImageDataVar = grayImageData.data; - } + // //// 3. get mask canvas for this body region._MR + // var grayCanvasID = 'imageCanvas' + bodyRegionId + '_MR'; + // grayCanvas = document.getElementById(grayCanvasID); + // var grayCanvasContext = grayCanvas.getContext("2d"); + // var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); + // grayImageDataVar = grayImageData.data; + // } - var coloredImageDataVarMR; - var coloredImageDataMR + // else { + // var grayCanvasID = 'imageCanvas' + bodyRegionId; + // grayCanvas = document.getElementById(grayCanvasID); + // var grayCanvasContext = grayCanvas.getContext("2d"); + // var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); + // grayImageDataVar = grayImageData.data; + // } + // var coloredImageDataVarMR; + // var coloredImageDataMR - var counter = 0; + // var counter = 0; - var dataForthisBR = new jinqJs() - .from(matchedLocationData) - .where('BRId == ' + bodyRegionId) - .select(); - for (var z = 0; z < dataForthisBR.length; z++) - { - var location = parseInt(dataForthisBR[z].location); + // var dataForthisBR = new jinqJs() + // .from(matchedLocationData) + // .where('BRId == ' + bodyRegionId) + // .select(); + + // for (var z = 0; z < dataForthisBR.length; z++) + // { + // var location = parseInt(dataForthisBR[z].location); - var RED_coloredImage = coloredImageDataVar[location]; + // var RED_coloredImage = coloredImageDataVar[location]; - grayImageDataVar[location] = RED_coloredImage; + // grayImageDataVar[location] = RED_coloredImage; - var GREEN_coloredImage = coloredImageDataVar[location + 1]; - grayImageDataVar[location + 1] = GREEN_coloredImage; + // var GREEN_coloredImage = coloredImageDataVar[location + 1]; + // grayImageDataVar[location + 1] = GREEN_coloredImage; - var BLUE_coloredImage = coloredImageDataVar[location + 2]; - grayImageDataVar[location + 2] = BLUE_coloredImage; + // var BLUE_coloredImage = coloredImageDataVar[location + 2]; + // grayImageDataVar[location + 2] = BLUE_coloredImage; - var ALPHA_coloredImage = coloredImageDataVar[location + 3]; - grayImageDataVar[location + 3] = ALPHA_coloredImage; + // var ALPHA_coloredImage = coloredImageDataVar[location + 3]; + // grayImageDataVar[location + 3] = ALPHA_coloredImage; - } - grayCanvasContext.putImageData(grayImageData, 0, 0); - } + // } + var grayCanvasID = 'imageCanvas' + BrId; + var grayCanvas = document.getElementById(grayCanvasID); + var grayCanvasContext = grayCanvas.getContext("2d"); - } + grayCanvasContext.putImageData(grayImageDataVar.toDataURL, 0, 0); + //} + + // } console.log('End time taken in fillMatchedTerm: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); } @@ -3342,12 +3350,12 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo var grayImageImageDataVar = grayImageData.data; if (value.haveMirror == 'true') { - $rootScope.grayImageMRDataList[parseInt(value.bodyRegionId)] = grayImageData; + $rootScope.grayImageMRDataList[parseInt(value.bodyRegionId)] = grayImageData.data; } else { //$rootScope.coloredImageMRCanvasList[parseInt(value.bodyRegionId - 1)] = 1; - $rootScope.grayImageDataList[parseInt(value.bodyRegionId - 1)] = grayImageData; + $rootScope.grayImageDataList[parseInt(value.bodyRegionId - 1)] = grayImageData.data; } } diff --git a/400-SOURCECODE/AIAHTML5.Web/term-number-wp.js b/400-SOURCECODE/AIAHTML5.Web/term-number-wp.js index 4404553..3d68123 100644 --- a/400-SOURCECODE/AIAHTML5.Web/term-number-wp.js +++ b/400-SOURCECODE/AIAHTML5.Web/term-number-wp.js @@ -11,7 +11,7 @@ } -getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData) +getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData, coloredImageCanvasList, coloredImageMRCanvasList, grayImageDataList, grayImageMRDataList) { var matchedRGBLocationInBodyRegion = []; @@ -21,6 +21,10 @@ getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData) var canvasId = maskCanvasData[x].canvasId; var maskData = maskCanvasData[x].maskData; + var coloredImageDataVar = coloredImageCanvasList[bodyRegionId -1]; + var grayImageDataVar = grayImageDataList[bodyRegionId-1]; + + // { //var scaledWidth = $scope.ColoredImageSRC[x].Width; //var scaledHeight = $scope.ColoredImageSRC[x].Height; @@ -143,6 +147,29 @@ getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData) //obj.location = i; matchedRGBLocationInBodyRegion.push({ "BRId": bodyRegionId, "location": i }); + + + + + var RED_coloredImage = coloredImageDataVar[i]; + + grayImageDataVar[i] = RED_coloredImage; + + + var GREEN_coloredImage = coloredImageDataVar[i + 1]; + grayImageDataVar[i + 1] = GREEN_coloredImage; + + var BLUE_coloredImage = coloredImageDataVar[i + 2]; + grayImageDataVar[i + 2] = BLUE_coloredImage; + + + var ALPHA_coloredImage = coloredImageDataVar[i + 3]; + grayImageDataVar[i + 3] = ALPHA_coloredImage; + + + + + // var have = machedIcolorInBodyRegion.indexOf(bodyRegionId); @@ -183,8 +210,8 @@ getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData) // grayCanvasContext.putImageData(grayImageData, 0, 0); } self.postMessage({ - 'cmd': 'getLocationsForMatchedTermsInWholeBody', - 'value': matchedRGBLocationInBodyRegion + 'BRId': bodyRegionId, + 'value': grayImageDataVar }); // grayCanvasContext.putImageData(grayImageData, 0, 0); @@ -199,7 +226,8 @@ getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData) } self.onmessage = function (e) { - getLocationForMatchedTermsInWholeBody(e.data.termNumber, e.data.maskCanvasData); + getLocationForMatchedTermsInWholeBody(e.data.termNumber, e.data.maskCanvasData,e.data.coloredImageCanvasList, + e.data.coloredImageMRCanvasList,e.data.grayImageDataList,e.data.grayImageMRDataList); } -- libgit2 0.21.4