Commit 3a2aa788cecaccc0c4473ca8faab9dd885c3f228

Authored by Nikita Kulshreshtha
1 parent 97944f00

We have moved term list iteration code in worker process. Now we are iterating …

…all termlist together for single body region return the updated data back to html to put on canavs.
400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js
... ... @@ -1376,7 +1376,7 @@ 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)
  1379 + // console.log(' TermList.length= ' + TermList.length)
1380 1380  
1381 1381  
1382 1382  
... ... @@ -1387,12 +1387,11 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
1387 1387 var coloredImageData = dataForthisBR.coloredImageData;
1388 1388 var worker = new Worker('term-number-wp.js');
1389 1389  
1390   - for (var i = 0; i < TermList.length; i++) {
1391   - debugger
  1390 + //for (var i = 0; i < TermList.length; i++) {
1392 1391  
1393   - console.log('Start time taken for term: ' + TermList[i]._TermNumber + 'in posting: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
  1392 + // console.log('Start time taken for term: ' + TermList[i]._TermNumber + 'in posting: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
1394 1393 worker.postMessage({
1395   - 'termNumber': TermList[i]._TermNumber,
  1394 + 'termList': TermList,
1396 1395 'maskCanvasData': $scope.MaskCanvasData,
1397 1396 'coloredImageCanvasList': $rootScope.coloredImageCanvasList,
1398 1397 'coloredImageMRCanvasList': $rootScope.coloredImageMRCanvasList,
... ... @@ -1401,18 +1400,11 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
1401 1400  
1402 1401 });
1403 1402  
1404   - }
1405   -
1406   - //var candata = e.value;
1407   - //var grayCanvasID = 'imageCanvas1'
1408   - //var grayCanvas = document.getElementById(grayCanvasID);
1409   - //var grayCanvasContext = grayCanvas.getContext("2d");
1410   - //var imageData = grayCanvasContext.getImageData(0, 0 ,348,507);
1411   -
1412   -
1413   - // worker.postMessage({ candata: coloredImageData });
  1403 + //}
1414 1404  
1415 1405 worker.onmessage = function (e) {
  1406 + // console.log('callback: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
  1407 +
1416 1408 var upadteddata = e.data.value;
1417 1409 var bodyRegionId = e.data.bodyRegionId;
1418 1410  
... ... @@ -1420,25 +1412,12 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
1420 1412 var grayCanvas = document.getElementById(grayCanvasID);
1421 1413 var grayCanvasContext = grayCanvas.getContext("2d");
1422 1414  
1423   - // var tempCanvas = document.createElement('canvas');
1424   - // tempCanvas.id = 'tempCanvas';
1425   - // $scope.tempCanvas = tempCanvas.id;
1426   - // tempCanvas.height = 507;
1427   - // tempCanvas.width = 348;
1428   - // tempCanvas.style.position = "absolute";
1429   - // tempCanvas.style.left = 200 + 'px';
1430   - // tempCanvas.style.top = 100 + 'px';
1431   -
1432   - //// tempCanvas.style.backgroundColor = "transparent";
1433   - // tempCanvas.style.visibility = 'visible';
1434   - // document.getElementById('canvasDiv').appendChild(tempCanvas);
1435   -
1436   - // var tempCanvas1 = document.getElementById('tempCanvas');
1437   - // var Context = tempCanvas1.getContext("2d");
  1415 +
  1416 +
  1417 + grayCanvasContext.putImageData(upadteddata, 0, 0);
1438 1418  
1439   - grayCanvasContext.putImageData(upadteddata, 0, 0);
1440 1419  
1441   -
  1420 + // $rootScope.grayImageDataList[bodyRegionId - 1] = upadteddata;
1442 1421  
1443 1422 };
1444 1423 worker.onerror = function (e) {
... ... @@ -1627,7 +1606,6 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
1627 1606 var grayCanvasContext = grayCanvas.getContext("2d");
1628 1607  
1629 1608  
1630   - debugger;
1631 1609 var garyDatalength = grayImageDataVar.length;
1632 1610 var pixelData = new Uint8ClampedArray(garyDatalength);
1633 1611 for (var i = 0; i < garyDatalength; i++) {
... ... @@ -1644,7 +1622,6 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
1644 1622 }
1645 1623  
1646 1624 $scope.GetRGBColor = function (maskCanvasContext, actulalX, actualY, x, y) {
1647   - debugger;
1648 1625 var pixelData = maskCanvasContext.getImageData(Math.round(actulalX - x), Math.round(actualY - y), 1, 1);
1649 1626  
1650 1627 pixelData.data[0] = pixelData.data[0] - 9;
... ...
400-SOURCECODE/AIAHTML5.Web/term-number-wp.js
1   -function abc(msg) {
2   -
3   -
4   - var msg1 = msg;
5   -
6   - self.postMessage({
7   - 'cmd': 'getLocationForMatchedTermsInWholeBody',
8   - 'value': msg1
9   - });
10   -
11   -
12   -}
13   -
14   -getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData, coloredImageCanvasList, coloredImageMRCanvasList, grayImageDataList, grayImageMRDataList) {
  1 +var previousGrayImageDataList = [];
  2 +var abc = 'hello';
15 3  
  4 +getLocationForMatchedTermsInWholeBody = function (TermList, maskCanvasData, coloredImageCanvasList, coloredImageMRCanvasList, grayImageDataList, grayImageMRDataList) {
  5 +
16 6 var matchedRGBLocationInBodyRegion = [];
17 7 var matched;
18 8 for (var x = 0; x < maskCanvasData.length; x++) {
19   - debugger;
  9 +
20 10 matched = false;
21 11 // alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId);
22 12 var bodyRegionId = maskCanvasData[x].bodyRegionId;
... ... @@ -25,106 +15,119 @@ getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData, colore
25 15  
26 16 var coloredImageDataVar1 = coloredImageCanvasList[bodyRegionId - 1];
27 17 var grayImageDataVar1 = grayImageDataList[bodyRegionId - 1];
28   - var coloredImageDataVar = coloredImageDataVar1.data;
29   - var grayImageDataVar = grayImageDataVar1.data;
  18 +
  19 +
  20 + var coloredImageDataVar = coloredImageDataVar1.data;
  21 + var grayImageDataVar = grayImageDataVar1.data;
30 22  
31 23  
32 24  
33 25  
34   - var counter = 0;
35   -
36   - var imageDataVar = maskData.data;
  26 + var counter = 0;
37 27  
38   - // var previousBRID;
  28 + var imageDataVar = maskData.data;
39 29  
40   - var counter = 0;
  30 + // var previousBRID;
41 31  
  32 + var counter = 0;
42 33  
43   - var n = maskData.data.length;
44 34  
45   - for (var i = 0; i < n; i += 4) {
  35 + var n = maskData.data.length;
  36 + for (var z = 0; z < TermList.length; z++)
  37 + {
  38 + if (previousGrayImageDataList[bodyRegionId - 1] != null) {
  39 + grayImageDataVar1 = previousGrayImageDataList[bodyRegionId - 1];
  40 + grayImageDataVar = grayImageDataVar1.data;
  41 + }
  42 + for (var i = 0; i < n; i += 4) {
46 43  
47 44  
48   - var RED = imageDataVar[i] - 9;
49   - var GREEN = imageDataVar[i + 1] - 9;
50   - var BLUE = imageDataVar[i + 2] - 9;
  45 + var RED = imageDataVar[i] - 9;
  46 + var GREEN = imageDataVar[i + 1] - 9;
  47 + var BLUE = imageDataVar[i + 2] - 9;
51 48  
52   - var Red;
53   - var Green;
54   - var Blue;
55   - var zero = "0";
  49 + var Red;
  50 + var Green;
  51 + var Blue;
  52 + var zero = "0";
56 53  
57   - if ((RED).toString().length != 2) {
58   - Red = zero.concat((RED).toString())
59   - }
60   - else {
61   - Red = (RED).toString()
62   - }
63   - if ((GREEN).toString().length != 2) {
64   - Green = zero.concat((GREEN).toString())
65   - }
66   - else {
67   - Green = (GREEN).toString()
  54 + if ((RED).toString().length != 2) {
  55 + Red = zero.concat((RED).toString())
  56 + }
  57 + else {
  58 + Red = (RED).toString()
  59 + }
  60 + if ((GREEN).toString().length != 2) {
  61 + Green = zero.concat((GREEN).toString())
  62 + }
  63 + else {
  64 + Green = (GREEN).toString()
68 65  
69   - }
70   - if ((BLUE).toString().length != 2) {
71   - Blue = zero.concat((BLUE).toString())
72   - }
73   - else {
74   - Blue = (BLUE).toString()
  66 + }
  67 + if ((BLUE).toString().length != 2) {
  68 + Blue = zero.concat((BLUE).toString())
  69 + }
  70 + else {
  71 + Blue = (BLUE).toString()
75 72  
76   - }
  73 + }
77 74  
78   - var Icolor = (Red + Green + Blue);
79   - // alert('Icolor: ' + Icolor)
  75 + var Icolor = (Red + Green + Blue);
  76 + // alert('Icolor: ' + Icolor)
80 77  
81   - if (parseInt(termNo) == parseInt(Icolor)) {
  78 + if (parseInt(TermList[z]._TermNumber) == parseInt(Icolor)) {
82 79  
83   - counter++;
  80 + counter++;
84 81  
85   - //var obj = new Object();
86   - //obj.bodyRegionId = bodyRegionId;
87   - //obj.location = i;
88 82  
89   - matchedRGBLocationInBodyRegion.push({ "BRId": bodyRegionId, "location": i });
  83 + matchedRGBLocationInBodyRegion.push({ "BRId": bodyRegionId, "location": i });
90 84  
91 85  
92   - matched = true;
  86 + matched = true;
93 87  
94   - var RED_coloredImage = coloredImageDataVar[i];
  88 + var RED_coloredImage = coloredImageDataVar[i];
95 89  
96   - grayImageDataVar[i] = RED_coloredImage;
  90 + grayImageDataVar[i] = RED_coloredImage;
97 91  
98 92  
99   - var GREEN_coloredImage = coloredImageDataVar[i + 1];
100   - grayImageDataVar[i + 1] = GREEN_coloredImage;
  93 + var GREEN_coloredImage = coloredImageDataVar[i + 1];
  94 + grayImageDataVar[i + 1] = GREEN_coloredImage;
101 95  
102   - var BLUE_coloredImage = coloredImageDataVar[i + 2];
103   - grayImageDataVar[i + 2] = BLUE_coloredImage;
  96 + var BLUE_coloredImage = coloredImageDataVar[i + 2];
  97 + grayImageDataVar[i + 2] = BLUE_coloredImage;
104 98  
105 99  
106   - var ALPHA_coloredImage = coloredImageDataVar[i + 3];
107   - grayImageDataVar[i + 3] = ALPHA_coloredImage;
  100 + var ALPHA_coloredImage = coloredImageDataVar[i + 3];
  101 + grayImageDataVar[i + 3] = ALPHA_coloredImage;
108 102  
109   - }
  103 + }
110 104  
111 105  
  106 + }
  107 + previousGrayImageDataList[parseInt(bodyRegionId - 1)] = grayImageDataVar1;
112 108 }
113   - self.postMessage({
114   - 'bodyRegionId':bodyRegionId,
115   - 'value': grayImageDataVar1,
116   -
117   - });
118 109  
  110 +
  111 +
  112 + if (matched == true) {
  113 + self.postMessage({
  114 + 'bodyRegionId': bodyRegionId,
  115 + 'value': grayImageDataVar1,
  116 +
  117 +
  118 + });
  119 +
  120 + }
119 121 }
120 122  
  123 +
121 124  
122 125  
123 126  
124 127 }
125 128  
126 129 self.onmessage = function (e) {
127   - getLocationForMatchedTermsInWholeBody(e.data.termNumber, e.data.maskCanvasData, e.data.coloredImageCanvasList,
  130 + getLocationForMatchedTermsInWholeBody(e.data.termList, e.data.maskCanvasData, e.data.coloredImageCanvasList,
128 131 e.data.coloredImageMRCanvasList, e.data.grayImageDataList, e.data.grayImageMRDataList);
129 132  
130 133 }
... ...