Commit 2c8523285c3d646476953c6929ca455188b907ec
1 parent
dd39f0c8
made changes to more optimized the code but facing issues in modifying image data in web worker.
Showing
2 changed files
with
116 additions
and
80 deletions
400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js
... | ... | @@ -1366,14 +1366,18 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo |
1366 | 1366 | console.log('Start time taken for term: ' + TermList[i]._TermNumber + 'in posting: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); |
1367 | 1367 | worker.postMessage({ |
1368 | 1368 | 'termNumber': TermList[i]._TermNumber, |
1369 | - 'maskCanvasData': $scope.MaskCanvasData | |
1369 | + 'maskCanvasData': $scope.MaskCanvasData, | |
1370 | + 'coloredImageCanvasList': $rootScope.coloredImageCanvasList, | |
1371 | + 'coloredImageMRCanvasList': $rootScope.coloredImageMRCanvasList, | |
1372 | + 'grayImageDataList': $rootScope.grayImageDataList, | |
1373 | + 'grayImageMRDataList': $rootScope.grayImageMRDataList | |
1370 | 1374 | |
1371 | 1375 | }); |
1372 | 1376 | |
1373 | 1377 | } |
1374 | 1378 | worker.onmessage = function (e) { |
1375 | 1379 | console.log('callback time taken : ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); |
1376 | - $scope.fillMatchedTerm(e.data.value); | |
1380 | + $scope.fillMatchedTerm(e.data.value, e.data.BRId); | |
1377 | 1381 | |
1378 | 1382 | |
1379 | 1383 | }; |
... | ... | @@ -1456,113 +1460,117 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo |
1456 | 1460 | |
1457 | 1461 | |
1458 | 1462 | |
1459 | - $scope.fillMatchedTerm = function (matchedLocationData) | |
1463 | + $scope.fillMatchedTerm = function (grayImageDataVar, BrId) | |
1460 | 1464 | { |
1461 | 1465 | console.log('Start time taken in fillMatchedTerm: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); |
1462 | 1466 | |
1463 | - for (var x = 0; x < $scope.ColoredImageSRC.length; x++) { | |
1464 | - // alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId); | |
1465 | - var bodyRegionId = $scope.ColoredImageSRC[x].bodyRegionId; | |
1467 | + //for (var x = 0; x < $scope.ColoredImageSRC.length; x++) { | |
1468 | + // // alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId); | |
1469 | + // var bodyRegionId = $scope.ColoredImageSRC[x].bodyRegionId; | |
1466 | 1470 | |
1467 | - { | |
1471 | + // { | |
1468 | 1472 | |
1469 | - var scaledWidth = $scope.ColoredImageSRC[x].Width; | |
1470 | - var scaledHeight = $scope.ColoredImageSRC[x].Height; | |
1471 | - //var maskImg = $scope.ColoredImageSRC[x].SRC; | |
1473 | + // var scaledWidth = $scope.ColoredImageSRC[x].Width; | |
1474 | + // var scaledHeight = $scope.ColoredImageSRC[x].Height; | |
1475 | + // //var maskImg = $scope.ColoredImageSRC[x].SRC; | |
1472 | 1476 | |
1473 | 1477 | |
1474 | - var coloredImg = $scope.ColoredImageSRC[x].SRC; | |
1478 | + // var coloredImg = $scope.ColoredImageSRC[x].SRC; | |
1475 | 1479 | |
1476 | - var maskImg = $scope.GetMaskImageSource(coloredImg); | |
1480 | + // var maskImg = $scope.GetMaskImageSource(coloredImg); | |
1477 | 1481 | |
1478 | 1482 | |
1479 | - var scledX = $scope.ColoredImageSRC[x].x; | |
1480 | - var scledY = $scope.ColoredImageSRC[x].y; | |
1483 | + // var scledX = $scope.ColoredImageSRC[x].x; | |
1484 | + // var scledY = $scope.ColoredImageSRC[x].y; | |
1481 | 1485 | |
1482 | 1486 | |
1483 | - // 1. get mask canvas for this body region. | |
1484 | - //var maskCanvasID; | |
1485 | - //if ($scope.ColoredImageSRC[x].haveMirror == 'true') { | |
1486 | - // maskCanvasID = 'imageCanvas' + bodyRegionId + '_MR_mci'; | |
1487 | - //} | |
1488 | - //else { | |
1489 | - // maskCanvasID = 'imageCanvas' + bodyRegionId + '_mci'; | |
1487 | + // // 1. get mask canvas for this body region. | |
1488 | + // //var maskCanvasID; | |
1489 | + // //if ($scope.ColoredImageSRC[x].haveMirror == 'true') { | |
1490 | + // // maskCanvasID = 'imageCanvas' + bodyRegionId + '_MR_mci'; | |
1491 | + // //} | |
1492 | + // //else { | |
1493 | + // // maskCanvasID = 'imageCanvas' + bodyRegionId + '_mci'; | |
1490 | 1494 | |
1491 | - //} | |
1492 | - //var maskCanvas = document.getElementById(maskCanvasID); | |
1493 | - //var maskCanvasContext = maskCanvas.getContext("2d"); | |
1494 | - //var maskImgData = maskCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); | |
1495 | + // //} | |
1496 | + // //var maskCanvas = document.getElementById(maskCanvasID); | |
1497 | + // //var maskCanvasContext = maskCanvas.getContext("2d"); | |
1498 | + // //var maskImgData = maskCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); | |
1495 | 1499 | |
1496 | - // 2. get coloured canvas for this body region. | |
1500 | + // // 2. get coloured canvas for this body region. | |
1497 | 1501 | |
1498 | 1502 | |
1499 | - var coloredImageDataVar; | |
1500 | - var coloredImageDataMRVar | |
1503 | + // var coloredImageDataVar; | |
1504 | + // var coloredImageDataMRVar | |
1501 | 1505 | |
1502 | - if ($scope.ColoredImageSRC[x].haveMirror == 'true') { | |
1506 | + // if ($scope.ColoredImageSRC[x].haveMirror == 'true') { | |
1503 | 1507 | |
1504 | - coloredImageDataVar = $rootScope.coloredImageMRCanvasList[parseInt(bodyRegionId)]; | |
1505 | - } | |
1506 | - else { | |
1507 | - coloredImageDataVar = $rootScope.coloredImageCanvasList[parseInt(bodyRegionId - 1)]; | |
1508 | - } | |
1509 | - var grayImageDataVar; | |
1510 | - var grayCanvas; | |
1511 | - if ($scope.ColoredImageSRC[x].haveMirror == 'true') { | |
1512 | - | |
1513 | - //// 3. get mask canvas for this body region._MR | |
1514 | - var grayCanvasID = 'imageCanvas' + bodyRegionId + '_MR'; | |
1515 | - grayCanvas = document.getElementById(grayCanvasID); | |
1516 | - var grayCanvasContext = grayCanvas.getContext("2d"); | |
1517 | - var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); | |
1518 | - grayImageDataVar = grayImageData.data; | |
1519 | - } | |
1508 | + // coloredImageDataVar = $rootScope.coloredImageMRCanvasList[parseInt(bodyRegionId)]; | |
1509 | + // } | |
1510 | + // else { | |
1511 | + // coloredImageDataVar = $rootScope.coloredImageCanvasList[parseInt(bodyRegionId - 1)]; | |
1512 | + // } | |
1513 | + // var grayImageDataVar; | |
1514 | + // var grayCanvas; | |
1515 | + // if ($scope.ColoredImageSRC[x].haveMirror == 'true') { | |
1520 | 1516 | |
1521 | - else { | |
1522 | - var grayCanvasID = 'imageCanvas' + bodyRegionId; | |
1523 | - grayCanvas = document.getElementById(grayCanvasID); | |
1524 | - var grayCanvasContext = grayCanvas.getContext("2d"); | |
1525 | - var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); | |
1526 | - grayImageDataVar = grayImageData.data; | |
1527 | - } | |
1517 | + // //// 3. get mask canvas for this body region._MR | |
1518 | + // var grayCanvasID = 'imageCanvas' + bodyRegionId + '_MR'; | |
1519 | + // grayCanvas = document.getElementById(grayCanvasID); | |
1520 | + // var grayCanvasContext = grayCanvas.getContext("2d"); | |
1521 | + // var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); | |
1522 | + // grayImageDataVar = grayImageData.data; | |
1523 | + // } | |
1528 | 1524 | |
1529 | - var coloredImageDataVarMR; | |
1530 | - var coloredImageDataMR | |
1525 | + // else { | |
1526 | + // var grayCanvasID = 'imageCanvas' + bodyRegionId; | |
1527 | + // grayCanvas = document.getElementById(grayCanvasID); | |
1528 | + // var grayCanvasContext = grayCanvas.getContext("2d"); | |
1529 | + // var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight); | |
1530 | + // grayImageDataVar = grayImageData.data; | |
1531 | + // } | |
1531 | 1532 | |
1533 | + // var coloredImageDataVarMR; | |
1534 | + // var coloredImageDataMR | |
1532 | 1535 | |
1533 | - var counter = 0; | |
1534 | 1536 | |
1537 | + // var counter = 0; | |
1535 | 1538 | |
1536 | - var dataForthisBR = new jinqJs() | |
1537 | - .from(matchedLocationData) | |
1538 | - .where('BRId == ' + bodyRegionId) | |
1539 | - .select(); | |
1540 | 1539 | |
1541 | - for (var z = 0; z < dataForthisBR.length; z++) | |
1542 | - { | |
1543 | - var location = parseInt(dataForthisBR[z].location); | |
1540 | + // var dataForthisBR = new jinqJs() | |
1541 | + // .from(matchedLocationData) | |
1542 | + // .where('BRId == ' + bodyRegionId) | |
1543 | + // .select(); | |
1544 | + | |
1545 | + // for (var z = 0; z < dataForthisBR.length; z++) | |
1546 | + // { | |
1547 | + // var location = parseInt(dataForthisBR[z].location); | |
1544 | 1548 | |
1545 | 1549 | |
1546 | - var RED_coloredImage = coloredImageDataVar[location]; | |
1550 | + // var RED_coloredImage = coloredImageDataVar[location]; | |
1547 | 1551 | |
1548 | - grayImageDataVar[location] = RED_coloredImage; | |
1552 | + // grayImageDataVar[location] = RED_coloredImage; | |
1549 | 1553 | |
1550 | 1554 | |
1551 | - var GREEN_coloredImage = coloredImageDataVar[location + 1]; | |
1552 | - grayImageDataVar[location + 1] = GREEN_coloredImage; | |
1555 | + // var GREEN_coloredImage = coloredImageDataVar[location + 1]; | |
1556 | + // grayImageDataVar[location + 1] = GREEN_coloredImage; | |
1553 | 1557 | |
1554 | - var BLUE_coloredImage = coloredImageDataVar[location + 2]; | |
1555 | - grayImageDataVar[location + 2] = BLUE_coloredImage; | |
1558 | + // var BLUE_coloredImage = coloredImageDataVar[location + 2]; | |
1559 | + // grayImageDataVar[location + 2] = BLUE_coloredImage; | |
1556 | 1560 | |
1557 | 1561 | |
1558 | - var ALPHA_coloredImage = coloredImageDataVar[location + 3]; | |
1559 | - grayImageDataVar[location + 3] = ALPHA_coloredImage; | |
1562 | + // var ALPHA_coloredImage = coloredImageDataVar[location + 3]; | |
1563 | + // grayImageDataVar[location + 3] = ALPHA_coloredImage; | |
1560 | 1564 | |
1561 | - } | |
1562 | - grayCanvasContext.putImageData(grayImageData, 0, 0); | |
1563 | - } | |
1565 | + // } | |
1566 | + var grayCanvasID = 'imageCanvas' + BrId; | |
1567 | + var grayCanvas = document.getElementById(grayCanvasID); | |
1568 | + var grayCanvasContext = grayCanvas.getContext("2d"); | |
1564 | 1569 | |
1565 | - } | |
1570 | + grayCanvasContext.putImageData(grayImageDataVar.toDataURL, 0, 0); | |
1571 | + //} | |
1572 | + | |
1573 | + // } | |
1566 | 1574 | |
1567 | 1575 | console.log('End time taken in fillMatchedTerm: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); |
1568 | 1576 | } |
... | ... | @@ -3342,12 +3350,12 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo |
3342 | 3350 | var grayImageImageDataVar = grayImageData.data; |
3343 | 3351 | |
3344 | 3352 | if (value.haveMirror == 'true') { |
3345 | - $rootScope.grayImageMRDataList[parseInt(value.bodyRegionId)] = grayImageData; | |
3353 | + $rootScope.grayImageMRDataList[parseInt(value.bodyRegionId)] = grayImageData.data; | |
3346 | 3354 | } |
3347 | 3355 | else { |
3348 | 3356 | //$rootScope.coloredImageMRCanvasList[parseInt(value.bodyRegionId - 1)] = 1; |
3349 | 3357 | |
3350 | - $rootScope.grayImageDataList[parseInt(value.bodyRegionId - 1)] = grayImageData; | |
3358 | + $rootScope.grayImageDataList[parseInt(value.bodyRegionId - 1)] = grayImageData.data; | |
3351 | 3359 | } |
3352 | 3360 | } |
3353 | 3361 | ... | ... |
400-SOURCECODE/AIAHTML5.Web/term-number-wp.js
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | |
12 | 12 | } |
13 | 13 | |
14 | -getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData) | |
14 | +getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData, coloredImageCanvasList, coloredImageMRCanvasList, grayImageDataList, grayImageMRDataList) | |
15 | 15 | { |
16 | 16 | |
17 | 17 | var matchedRGBLocationInBodyRegion = []; |
... | ... | @@ -21,6 +21,10 @@ getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData) |
21 | 21 | var canvasId = maskCanvasData[x].canvasId; |
22 | 22 | var maskData = maskCanvasData[x].maskData; |
23 | 23 | |
24 | + var coloredImageDataVar = coloredImageCanvasList[bodyRegionId -1]; | |
25 | + var grayImageDataVar = grayImageDataList[bodyRegionId-1]; | |
26 | + | |
27 | + | |
24 | 28 | // { |
25 | 29 | //var scaledWidth = $scope.ColoredImageSRC[x].Width; |
26 | 30 | //var scaledHeight = $scope.ColoredImageSRC[x].Height; |
... | ... | @@ -143,6 +147,29 @@ getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData) |
143 | 147 | //obj.location = i; |
144 | 148 | |
145 | 149 | matchedRGBLocationInBodyRegion.push({ "BRId": bodyRegionId, "location": i }); |
150 | + | |
151 | + | |
152 | + | |
153 | + | |
154 | + var RED_coloredImage = coloredImageDataVar[i]; | |
155 | + | |
156 | + grayImageDataVar[i] = RED_coloredImage; | |
157 | + | |
158 | + | |
159 | + var GREEN_coloredImage = coloredImageDataVar[i + 1]; | |
160 | + grayImageDataVar[i + 1] = GREEN_coloredImage; | |
161 | + | |
162 | + var BLUE_coloredImage = coloredImageDataVar[i + 2]; | |
163 | + grayImageDataVar[i + 2] = BLUE_coloredImage; | |
164 | + | |
165 | + | |
166 | + var ALPHA_coloredImage = coloredImageDataVar[i + 3]; | |
167 | + grayImageDataVar[i + 3] = ALPHA_coloredImage; | |
168 | + | |
169 | + | |
170 | + | |
171 | + | |
172 | + | |
146 | 173 | |
147 | 174 | // var have = machedIcolorInBodyRegion.indexOf(bodyRegionId); |
148 | 175 | |
... | ... | @@ -183,8 +210,8 @@ getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData) |
183 | 210 | // grayCanvasContext.putImageData(grayImageData, 0, 0); |
184 | 211 | } |
185 | 212 | self.postMessage({ |
186 | - 'cmd': 'getLocationsForMatchedTermsInWholeBody', | |
187 | - 'value': matchedRGBLocationInBodyRegion | |
213 | + 'BRId': bodyRegionId, | |
214 | + 'value': grayImageDataVar | |
188 | 215 | }); |
189 | 216 | |
190 | 217 | // grayCanvasContext.putImageData(grayImageData, 0, 0); |
... | ... | @@ -199,7 +226,8 @@ getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData) |
199 | 226 | } |
200 | 227 | |
201 | 228 | self.onmessage = function (e) { |
202 | - getLocationForMatchedTermsInWholeBody(e.data.termNumber, e.data.maskCanvasData); | |
229 | + getLocationForMatchedTermsInWholeBody(e.data.termNumber, e.data.maskCanvasData,e.data.coloredImageCanvasList, | |
230 | + e.data.coloredImageMRCanvasList,e.data.grayImageDataList,e.data.grayImageMRDataList); | |
203 | 231 | |
204 | 232 | } |
205 | 233 | ... | ... |