Commit e3f7afd345514fa875ebca83c983748ee160d5e7

Authored by Nikita Kulshreshtha
1 parent 781b28c4

now creating a new webworker for every body region and looping term list in webw…

…orker. sending back the updated gray canvas data for a single region.
This works well for cases except we click multiple time at very less interval. Need to destroy previous worker process on every click.
400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js
... ... @@ -1365,7 +1365,7 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
1365 1365  
1366 1366 }
1367 1367 $scope.highLightBodyBasedOnIcolor = function (RGBColor) {
1368   -
  1368 + console.log(' $scope.highLightBodyBasedOnIcolor')
1369 1369 //2. Find Actul Term No Based on Icolor.
1370 1370 var ActualTermNo = $scope.getActualTermNumber(RGBColor);
1371 1371  
... ... @@ -1376,259 +1376,76 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
1376 1376 //4.
1377 1377  
1378 1378 $scope.machedTermNoLocation = [];
1379   - // console.log(' TermList.length= ' + TermList.length)
1380   -
1381   -
  1379 +
1382 1380  
1383   - //var dataForthisBR = new jinqJs()
1384   - // .from($scope.ColoredCanvasData)
1385   - // .where('bodyRegionId == ' + 1)
1386   - // .select();
1387   - //var coloredImageData = dataForthisBR.coloredImageData;
1388   -
1389   -
1390   - var worker = new Worker('term-number-wp.js');
  1381 + var n = $scope.MaskCanvasData.length;
  1382 + // console.log('$scope.MaskCanvasData.length= ' + n)
1391 1383  
1392 1384 // console.log('Start time taken for term: ' + TermList[i]._TermNumber + 'in posting: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
1393   - worker.postMessage({
1394   -
1395   - 'termList': TermList,
1396   - 'maskCanvasData': $scope.MaskCanvasData,
1397   - 'coloredImageCanvasList': $rootScope.coloredImageCanvasList,
1398   - 'coloredImageMRCanvasList': $rootScope.coloredImageMRCanvasList,
1399   - 'grayImageDataList': $rootScope.grayImageDataList,
1400   - 'grayImageMRDataList': $rootScope.grayImageMRDataList
1401   -
1402   - });
1403   -
1404   - //}
1405   -
1406   - worker.onmessage = function (e) {
1407   - console.log('callback: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
1408   -
1409   - // alert(e.data.value + '....name= ' + e.data.name)
1410   - var updatedData = e.data.value;
1411   - debugger;
1412   - for (var i = 1; i <= updatedData.length; i++) {
1413   -
1414   - var grayCanvasID = 'imageCanvas' + i;
1415   - var grayCanvas = document.getElementById(grayCanvasID);
1416   - var grayCanvasContext = grayCanvas.getContext("2d");
1417   -
1418   -
1419   -
1420   - grayCanvasContext.putImageData(updatedData[i], 0, 0);
1421   - }
1422   - //var upadteddata = e.data.value;
1423   - //var bodyRegionId = e.data.bodyRegionId;
1424   -
1425   -
1426   -
1427   -
1428   - // $rootScope.grayImageDataList[bodyRegionId - 1] = upadteddata;
1429   -
1430   - };
1431   - worker.onerror = function (e) {
1432   - alert('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message);
1433   - };
1434   - }
1435   -
1436   -
1437   -
1438   - //$scope.highLightBodyBasedOnIcolor = function (RGBColor) {
1439   -
1440   - // $scope.previousSelectedTermList.length = 0;
1441   -
1442   - // var RGBColor = $scope.previousSelectedTermList[i];
1443   -
1444   - // //2. Find Actul Term No Based on Icolor.
1445   - // var ActualTermNo = $scope.getActualTermNumber(RGBColor);
1446   -
1447   - // //3. Find Term No List Based on ActualTermNo
1448   - // var TermList = $scope.getTermNumberList(ActualTermNo);
1449   -
1450   - // if ($scope.previousSelectedTermList.length > 0) {
1451   -
1452   - // var worker = new Worker('term-number-wp.js');
1453   -
1454   -
1455   - // for (var i = 0; i < $scope.previousSelectedTermList.length; i++) {
1456   - // $scope.machedTermNoLocation = [];
1457   - // for (var i = 0; i < TermList.length; i++) {
1458   -
1459   - // var termNumber = parseInt(TermList[i]._TermNumber);
1460   -
1461   - // // //Match Term No List in each bodyRegion
1462   - // // $scope.getLocationsForMatchedTermsInWholeBody(termNumber);
1463   -
1464   - // worker.postMessage({
1465   - // 'cmd': 'abc',
1466   - // 'value': termNumber
1467   - // });
1468   - // }
1469   -
1470   - // }
1471   -
1472   - // worker.onmessage = function (e) {
1473   - // var msg = e.data.msg1;
1474   - // };
1475   - // worker.onerror = function (e) {
1476   - // alert('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message);
1477   - // };
1478   - // }
1479   - // else {
  1385 + // debugger
  1386 + for (var x = 0; x < n; x++) {
  1387 + console.log('$scope.MaskCanvasData.length= ' + n)
1480 1388  
1481   - // $scope.machedTermNoLocation = [];
1482   - // for (var i = 0; i < TermList.length; i++) {
  1389 + var bodyRegionId = $scope.MaskCanvasData[x].bodyRegionId;
  1390 + var canvasId = $scope.MaskCanvasData[x].canvasId;
  1391 + var maskData = $scope.MaskCanvasData[x].maskData;
1483 1392  
1484   - // var termNumber = parseInt(TermList[i]._TermNumber);
  1393 + var coloredImageDataVar = $rootScope.coloredImageCanvasList[bodyRegionId - 1];
  1394 + var grayImageDataVar = $rootScope.grayImageDataList[bodyRegionId - 1];
1485 1395  
1486   - // var worker = new Worker('term-number-wp.js');
  1396 + var worker = new Worker('term-number-wp.js');
1487 1397  
1488   - // //start the worker
1489   - // worker.postMessage({
1490   - // 'cmd': 'abc',
1491   - // 'value': termNumber
1492   - // });
  1398 + console.log('for bodyRegionId = ' + bodyRegionId+ ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"))
  1399 + worker.postMessage({
1493 1400  
1494   - // worker.onmessage = function (e) {
1495   - // var msg = e.data.msg;
1496   - // };
1497   - // worker.onerror = function (e) {
1498   - // alert('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message);
1499   - // };
1500   - // //Match Term No List in each bodyRegion
1501   - // //$scope.getLocationsForMatchedTermsInWholeBody(termNumber);
1502   - // }
1503   -
1504   -
1505   - // }
1506   - //}
1507   -
1508   -
1509   -
1510   - $scope.fillMatchedTerm = function (grayImageDataVar, BrId) {
1511   - console.log('Start time taken in fillMatchedTerm: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
1512   -
1513   - //for (var x = 0; x < $scope.ColoredImageSRC.length; x++) {
1514   - // // alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId);
1515   - // var bodyRegionId = $scope.ColoredImageSRC[x].bodyRegionId;
1516   -
1517   - // {
1518   -
1519   - // var scaledWidth = $scope.ColoredImageSRC[x].Width;
1520   - // var scaledHeight = $scope.ColoredImageSRC[x].Height;
1521   - // //var maskImg = $scope.ColoredImageSRC[x].SRC;
1522   -
1523   -
1524   - // var coloredImg = $scope.ColoredImageSRC[x].SRC;
1525   -
1526   - // var maskImg = $scope.GetMaskImageSource(coloredImg);
1527   -
1528   -
1529   - // var scledX = $scope.ColoredImageSRC[x].x;
1530   - // var scledY = $scope.ColoredImageSRC[x].y;
1531   -
1532   -
1533   - // // 1. get mask canvas for this body region.
1534   - // //var maskCanvasID;
1535   - // //if ($scope.ColoredImageSRC[x].haveMirror == 'true') {
1536   - // // maskCanvasID = 'imageCanvas' + bodyRegionId + '_MR_mci';
1537   - // //}
1538   - // //else {
1539   - // // maskCanvasID = 'imageCanvas' + bodyRegionId + '_mci';
1540   -
1541   - // //}
1542   - // //var maskCanvas = document.getElementById(maskCanvasID);
1543   - // //var maskCanvasContext = maskCanvas.getContext("2d");
1544   - // //var maskImgData = maskCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight);
1545   -
1546   - // // 2. get coloured canvas for this body region.
1547   -
1548   -
1549   - // var coloredImageDataVar;
1550   - // var coloredImageDataMRVar
1551   -
1552   - // if ($scope.ColoredImageSRC[x].haveMirror == 'true') {
1553   -
1554   - // coloredImageDataVar = $rootScope.coloredImageMRCanvasList[parseInt(bodyRegionId)];
1555   - // }
1556   - // else {
1557   - // coloredImageDataVar = $rootScope.coloredImageCanvasList[parseInt(bodyRegionId - 1)];
1558   - // }
1559   - // var grayImageDataVar;
1560   - // var grayCanvas;
1561   - // if ($scope.ColoredImageSRC[x].haveMirror == 'true') {
1562   -
1563   - // //// 3. get mask canvas for this body region._MR
1564   - // var grayCanvasID = 'imageCanvas' + bodyRegionId + '_MR';
1565   - // grayCanvas = document.getElementById(grayCanvasID);
1566   - // var grayCanvasContext = grayCanvas.getContext("2d");
1567   - // var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight);
1568   - // grayImageDataVar = grayImageData.data;
1569   - // }
1570   -
1571   - // else {
1572   - // var grayCanvasID = 'imageCanvas' + bodyRegionId;
1573   - // grayCanvas = document.getElementById(grayCanvasID);
1574   - // var grayCanvasContext = grayCanvas.getContext("2d");
1575   - // var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight);
1576   - // grayImageDataVar = grayImageData.data;
1577   - // }
1578   -
1579   - // var coloredImageDataVarMR;
1580   - // var coloredImageDataMR
1581   -
1582   -
1583   - // var counter = 0;
  1401 + 'termList': TermList,
  1402 + 'maskCanvasData': maskData,
  1403 + 'coloredImageData': coloredImageDataVar,
  1404 + 'coloredImageMRCanvasList': $rootScope.coloredImageMRCanvasList,
  1405 + 'grayImageData': grayImageDataVar,
  1406 + 'grayImageMRDataList': $rootScope.grayImageMRDataList,
  1407 + 'bodyRegionId': bodyRegionId
1584 1408  
  1409 + });
1585 1410  
1586   - // var dataForthisBR = new jinqJs()
1587   - // .from(matchedLocationData)
1588   - // .where('BRId == ' + bodyRegionId)
1589   - // .select();
  1411 + //}
1590 1412  
1591   - // for (var z = 0; z < dataForthisBR.length; z++)
1592   - // {
1593   - // var location = parseInt(dataForthisBR[z].location);
  1413 + worker.onmessage = function (e) {
  1414 + console.log('callback: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
1594 1415  
  1416 +
  1417 + var updatedData = e.data.value;
1595 1418  
1596   - // var RED_coloredImage = coloredImageDataVar[location];
  1419 + var bodyRegionId = e.data.bodyRegionId;
  1420 + //debugger;
  1421 + //for (var i = 1; i <= updatedData.length; i++) {
1597 1422  
1598   - // grayImageDataVar[location] = RED_coloredImage;
  1423 + var grayCanvasID = 'imageCanvas' + bodyRegionId;
  1424 + var grayCanvas = document.getElementById(grayCanvasID);
  1425 + var grayCanvasContext = grayCanvas.getContext("2d");
1599 1426  
1600 1427  
1601   - // var GREEN_coloredImage = coloredImageDataVar[location + 1];
1602   - // grayImageDataVar[location + 1] = GREEN_coloredImage;
1603 1428  
1604   - // var BLUE_coloredImage = coloredImageDataVar[location + 2];
1605   - // grayImageDataVar[location + 2] = BLUE_coloredImage;
  1429 + grayCanvasContext.putImageData(updatedData, 0, 0);
  1430 + // }
1606 1431  
1607 1432  
1608   - // var ALPHA_coloredImage = coloredImageDataVar[location + 3];
1609   - // grayImageDataVar[location + 3] = ALPHA_coloredImage;
  1433 + worker.terminate();
1610 1434  
1611   - // }
1612   - var grayCanvasID = 'imageCanvas' + BrId;
1613   - var grayCanvas = document.getElementById(grayCanvasID);
1614   - var grayCanvasContext = grayCanvas.getContext("2d");
1615 1435  
  1436 + // $rootScope.grayImageDataList[bodyRegionId - 1] = upadteddata;
1616 1437  
1617   - var garyDatalength = grayImageDataVar.length;
1618   - var pixelData = new Uint8ClampedArray(garyDatalength);
1619   - for (var i = 0; i < garyDatalength; i++) {
1620   - pixelData[i] = grayImageDataVar[i];
  1438 + };
  1439 + worker.onerror = function (e) {
  1440 + alert('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message);
  1441 + };
1621 1442 }
1622   - var imgDta = grayCanvasContext.getImageData(0, 0, 348, 507);
1623   - imgDta.data.set
1624   - grayCanvasContext.putImageData(imgDta, 0, 0);
1625   - //}
1626   -
1627   - // }
1628 1443  
1629   - console.log('End time taken in fillMatchedTerm: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
1630 1444 }
1631 1445  
  1446 +
  1447 +
  1448 +
1632 1449 $scope.GetRGBColor = function (maskCanvasContext, actulalX, actualY, x, y) {
1633 1450 var pixelData = maskCanvasContext.getImageData(Math.round(actulalX - x), Math.round(actualY - y), 1, 1);
1634 1451  
... ... @@ -1720,6 +1537,15 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
1720 1537 //layer change function
1721 1538 $scope.LayerChange = function () {
1722 1539 // alert('layer chnage')
  1540 + if ($scope.MaskCanvasData.length > 0) {
  1541 + $scope.MaskCanvasData = null;
  1542 + $scope.MaskCanvasData = [];
  1543 + }
  1544 +
  1545 + if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
  1546 + // huzzah! a worker!
  1547 + console.log('worker is running')
  1548 + }
1723 1549  
1724 1550 var canvasDiv = document.getElementById('canvasDiv');
1725 1551 $scope.imageVerticalScrollPosition = canvasDiv.scrollTop;
... ...
400-SOURCECODE/AIAHTML5.Web/term-number-wp.js
1 1 var UpdatedGrayImageDataList = [];
2 2 var doneBRID = [];
3 3 var abc = 'hello';
4   -
5   -getLocationForMatchedTermsInWholeBody = function (termList, maskCanvasData, coloredImageCanvasList, coloredImageMRCanvasList, grayImageDataList, grayImageMRDataList) {
6   - // console.log('for termNumer: ' + termNo + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"))
  4 +previousGrayImageDataList = [];
  5 +getLocationForMatchedTermsInWholeBody = function (termList, maskCanvasData, coloredImageData, coloredImageMRCanvasList, grayImageData, grayImageMRDataList, bodyRegionId) {
  6 + console.log('for bodyRegionId: ' + bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"))
7 7 var matchedRGBLocationInBodyRegion = [];
8 8 var matched;
9 9  
10   - for (var x = 0; x < maskCanvasData.length; x++) {
  10 +
  11 + var n = maskCanvasData.data.length;
  12 + var maskData = maskCanvasData.data;
  13 + for (var z = 0; z < termList.length; z++) {
  14 +
  15 + if (previousGrayImageDataList[parseInt(bodyRegionId - 1)] != null) {
  16 + grayImageData = previousGrayImageDataList[parseInt(bodyRegionId - 1)];
11 17  
12   - matched = false;
13   - // alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId);
14   - var bodyRegionId = maskCanvasData[x].bodyRegionId;
15   - var canvasId = maskCanvasData[x].canvasId;
16   - var maskData = maskCanvasData[x].maskData;
  18 + }
  19 + var grayImageDataVar = grayImageData.data;
  20 + var coloredImageDataVar = coloredImageData.data;
17 21  
18   - var coloredImageDataVar = coloredImageCanvasList[bodyRegionId - 1];
19   - var grayImageDataVar = grayImageDataList[bodyRegionId - 1];
  22 + for (var i = 0; i < n; i += 4) {
20 23  
21   - //if (canvasId.match('MR')) {
22   - // coloredImageDataVar = coloredImageMRCanvasList[bodyRegionId - 1];
23   - // grayImageDataVar = grayImageMRDataList[bodyRegionId - 1];
24   - //}
25   - //else {
26   - // coloredImageDataVar = coloredImageCanvasList[bodyRegionId - 1];
27   - // grayImageDataVar = grayImageDataList[bodyRegionId - 1];
28   - //}
29 24  
30   - var counter = 0;
  25 + var RED = maskData[i] - 9;
  26 + var GREEN = maskData[i + 1] - 9;
  27 + var BLUE = maskData[i + 2] - 9;
31 28  
32   - var imageDataVar = maskData.data;
  29 + var Red;
  30 + var Green;
  31 + var Blue;
  32 + var zero = "0";
33 33  
34   - var machLocationWP = new Worker('match-pixel-wp.js');
  34 + if ((RED).toString().length != 2) {
  35 + Red = zero.concat((RED).toString())
  36 + }
  37 + else {
  38 + Red = (RED).toString()
  39 + }
  40 + if ((GREEN).toString().length != 2) {
  41 + Green = zero.concat((GREEN).toString())
  42 + }
  43 + else {
  44 + Green = (GREEN).toString()
35 45  
  46 + }
  47 + if ((BLUE).toString().length != 2) {
  48 + Blue = zero.concat((BLUE).toString())
  49 + }
  50 + else {
  51 + Blue = (BLUE).toString()
  52 +
  53 + }
36 54  
37   - machLocationWP.postMessage({
  55 + var Icolor = (Red + Green + Blue);
  56 + // alert('Icolor: ' + Icolor)
38 57  
39   - 'termList': termList,
40   - 'maskCanvasData': maskData,
41   - 'coloreImageData': coloredImageDataVar,
42   - 'grayImageData': grayImageDataVar,
43   - 'grayImageMRDataList': grayImageMRDataList,
44   - 'bodyRegionId': bodyRegionId
  58 + if (parseInt(termList[z]._TermNumber) == parseInt(Icolor)) {
45 59  
46   - });
47 60  
48   - machLocationWP.onmessage = function (e) {
49   - console.log('callback: ' + e.data.value + ', x=' + x);
50 61  
51   - //var upadteddata = e.data.value;
52   - //var bodyRegionId = e.data.bodyRegionId;
53 62  
54   - //var grayCanvasID = 'imageCanvas' + bodyRegionId;
55   - //var grayCanvas = document.getElementById(grayCanvasID);
56   - //var grayCanvasContext = grayCanvas.getContext("2d");
  63 + // matchedRGBLocationInBodyRegion.push({ "BRId": bodyRegionId, "location": i });
57 64  
58 65  
  66 + // matched = true;
59 67  
60   - //grayCanvasContext.putImageData(upadteddata, 0, 0);
61   - doneBRID.push(e.data.bodyRegionId);
62   - UpdatedGrayImageDataList[e.data.bodyRegionId] = e.data.value
  68 + var RED_coloredImage = coloredImageDataVar[i];
63 69  
64   - console.log('UpdatedGrayImageDataList: ' + UpdatedGrayImageDataList);
  70 + grayImageDataVar[i] = RED_coloredImage;
65 71  
66   - console.log('doneBRID: ' + e.data.bodyRegionId + 'length: ' + doneBRID.length);
67 72  
68   - if (doneBRID.length == 9) {
69   - console.log('before sending UpdatedGrayImageDataList= ' + UpdatedGrayImageDataList)
70   - self.postMessage({
71   - 'value': UpdatedGrayImageDataList,
72   - 'name': 'Happy'
73   - })
  73 + var GREEN_coloredImage = coloredImageDataVar[i + 1];
  74 + grayImageDataVar[i + 1] = GREEN_coloredImage;
  75 +
  76 + var BLUE_coloredImage = coloredImageDataVar[i + 2];
  77 + grayImageDataVar[i + 2] = BLUE_coloredImage;
  78 +
  79 +
  80 + var ALPHA_coloredImage = coloredImageDataVar[i + 3];
  81 + grayImageDataVar[i + 3] = ALPHA_coloredImage;
  82 +
74 83 }
75 84  
76   - };
77   - machLocationWP.onerror = function (e) {
78   - console.log('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message);
79   - };
80 85  
  86 + }
81 87  
82   - }
  88 + previousGrayImageDataList[parseInt(bodyRegionId - 1)] = grayImageData;
  89 +
  90 + // if (matched == true) {
83 91  
  92 + // }
  93 +
  94 + }
  95 + self.postMessage({
  96 + 'bodyRegionId': bodyRegionId,
  97 + 'value': grayImageData,
84 98  
85 99  
  100 + });
86 101  
87 102 }
88 103  
89 104 self.onmessage = function (e) {
90   - getLocationForMatchedTermsInWholeBody(e.data.termList, e.data.maskCanvasData, e.data.coloredImageCanvasList,
91   - e.data.coloredImageMRCanvasList, e.data.grayImageDataList, e.data.grayImageMRDataList);
  105 + getLocationForMatchedTermsInWholeBody(e.data.termList, e.data.maskCanvasData, e.data.coloredImageData,
  106 + e.data.coloredImageMRCanvasList, e.data.grayImageData, e.data.grayImageMRDataList, e.data.bodyRegionId);
92 107  
93 108 }
94 109  
... ...