Commit 43a10c1ddfa6619c87dea994c23f1bd306780354
1 parent
3a2aa788
Implemented 2 worker process. In one worker process there is a loop of body regi…
…ons and in each iteration a new worker process is initialize i.e secon worekr process in which looping is done on term list for a single body regiona nd it returns the updated grayimagedata along with BRID, we hold this returned data in first worker process in an array whch is indexed by bodyregion. and once all process for all bodyregions are comlpeted then we return this indexed array to the controller and loop through thsi aaray and put updated data on respective canavs
Showing
3 changed files
with
173 additions
and
131 deletions
400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js
... | ... | @@ -1385,12 +1385,13 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo |
1385 | 1385 | .where('bodyRegionId == ' + 1) |
1386 | 1386 | .select(); |
1387 | 1387 | var coloredImageData = dataForthisBR.coloredImageData; |
1388 | - var worker = new Worker('term-number-wp.js'); | |
1389 | 1388 | |
1390 | - //for (var i = 0; i < TermList.length; i++) { | |
1391 | - | |
1389 | + //for (var i = 0; i < TermList.length; i++) { | |
1390 | + var worker = new Worker('term-number-wp.js'); | |
1391 | + | |
1392 | 1392 | // 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({ | |
1393 | + worker.postMessage({ | |
1394 | + | |
1394 | 1395 | 'termList': TermList, |
1395 | 1396 | 'maskCanvasData': $scope.MaskCanvasData, |
1396 | 1397 | 'coloredImageCanvasList': $rootScope.coloredImageCanvasList, |
... | ... | @@ -1400,21 +1401,28 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo |
1400 | 1401 | |
1401 | 1402 | }); |
1402 | 1403 | |
1403 | - //} | |
1404 | + //} | |
1404 | 1405 | |
1405 | 1406 | worker.onmessage = function (e) { |
1406 | - // console.log('callback: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); | |
1407 | + console.log('callback: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); | |
1407 | 1408 | |
1408 | - var upadteddata = e.data.value; | |
1409 | - var bodyRegionId = e.data.bodyRegionId; | |
1410 | - | |
1411 | - var grayCanvasID = 'imageCanvas' + bodyRegionId; | |
1412 | - var grayCanvas = document.getElementById(grayCanvasID); | |
1413 | - var grayCanvasContext = grayCanvas.getContext("2d"); | |
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++) { | |
1414 | 1413 | |
1415 | - | |
1416 | - | |
1417 | - grayCanvasContext.putImageData(upadteddata, 0, 0); | |
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 | + | |
1418 | 1426 | |
1419 | 1427 | |
1420 | 1428 | // $rootScope.grayImageDataList[bodyRegionId - 1] = upadteddata; | ... | ... |
400-SOURCECODE/AIAHTML5.Web/match-pixel-wp.js
1 | - | |
2 | -function getLocationsForMatchedTermsInWholeBody(msg) | |
1 | +previousGrayImageDataList = []; | |
2 | + | |
3 | +function updateGrayCanvasDataOnMatcghedLocation(termList, maskCanvasData, coloreImageData, | |
4 | + grayImageData, grayImageMRDataList, bodyRegionId) | |
3 | 5 | { |
4 | - debugger; | |
6 | + console.log('updateGrayCanvasDataOnMatcghedLocation= ' + bodyRegionId) | |
7 | + | |
8 | + | |
9 | + var n = maskCanvasData.data.length; | |
10 | + var maskData = maskCanvasData.data; | |
11 | + for (var z = 0; z < termList.length; z++) { | |
12 | + | |
13 | + if (previousGrayImageDataList[parseInt(bodyRegionId - 1)] != null) { | |
14 | + grayImageData = previousGrayImageDataList[parseInt(bodyRegionId - 1)]; | |
15 | + | |
16 | + } | |
17 | + var grayImageDataVar = grayImageData.data; | |
18 | + var coloredImageDataVar = coloreImageData.data; | |
19 | + | |
20 | + for (var i = 0; i < n; i += 4) { | |
21 | + | |
22 | + | |
23 | + var RED = maskData[i] - 9; | |
24 | + var GREEN = maskData[i + 1] - 9; | |
25 | + var BLUE = maskData[i + 2] - 9; | |
26 | + | |
27 | + var Red; | |
28 | + var Green; | |
29 | + var Blue; | |
30 | + var zero = "0"; | |
31 | + | |
32 | + if ((RED).toString().length != 2) { | |
33 | + Red = zero.concat((RED).toString()) | |
34 | + } | |
35 | + else { | |
36 | + Red = (RED).toString() | |
37 | + } | |
38 | + if ((GREEN).toString().length != 2) { | |
39 | + Green = zero.concat((GREEN).toString()) | |
40 | + } | |
41 | + else { | |
42 | + Green = (GREEN).toString() | |
43 | + | |
44 | + } | |
45 | + if ((BLUE).toString().length != 2) { | |
46 | + Blue = zero.concat((BLUE).toString()) | |
47 | + } | |
48 | + else { | |
49 | + Blue = (BLUE).toString() | |
50 | + | |
51 | + } | |
52 | + | |
53 | + var Icolor = (Red + Green + Blue); | |
54 | + // alert('Icolor: ' + Icolor) | |
55 | + | |
56 | + if (parseInt(termList[z]._TermNumber) == parseInt(Icolor)) { | |
57 | + | |
58 | + | |
59 | + | |
60 | + | |
61 | + // matchedRGBLocationInBodyRegion.push({ "BRId": bodyRegionId, "location": i }); | |
62 | + | |
63 | + | |
64 | + // matched = true; | |
5 | 65 | |
6 | - self.postMessage({ 'value': msg }); | |
66 | + var RED_coloredImage = coloredImageDataVar[i]; | |
67 | + | |
68 | + grayImageDataVar[i] = RED_coloredImage; | |
69 | + | |
70 | + | |
71 | + var GREEN_coloredImage = coloredImageDataVar[i + 1]; | |
72 | + grayImageDataVar[i + 1] = GREEN_coloredImage; | |
73 | + | |
74 | + var BLUE_coloredImage = coloredImageDataVar[i + 2]; | |
75 | + grayImageDataVar[i + 2] = BLUE_coloredImage; | |
76 | + | |
77 | + | |
78 | + var ALPHA_coloredImage = coloredImageDataVar[i + 3]; | |
79 | + grayImageDataVar[i + 3] = ALPHA_coloredImage; | |
80 | + | |
81 | + } | |
82 | + | |
83 | + | |
84 | + } | |
85 | + | |
86 | + previousGrayImageDataList[parseInt(bodyRegionId - 1)] = grayImageData; | |
87 | + | |
88 | + // if (matched == true) { | |
89 | + self.postMessage({ | |
90 | + 'bodyRegionId': bodyRegionId, | |
91 | + 'value': grayImageData, | |
92 | + | |
93 | + | |
94 | + }); | |
95 | + // } | |
7 | 96 | |
8 | 97 | } |
98 | + | |
99 | +} | |
9 | 100 | |
10 | 101 | self.onmessage = function (e) { |
11 | - getLocationsForMatchedTermsInWholeBody(e.data.candata); | |
12 | -} | |
13 | 102 | \ No newline at end of file |
103 | + console.log('shd') | |
104 | + updateGrayCanvasDataOnMatcghedLocation(e.data.termList, e.data.maskCanvasData, e.data.coloreImageData, | |
105 | + e.data.grayImageData, e.data.grayImageMRDataList, e.data.bodyRegionId); | |
106 | + | |
107 | +} | |
108 | + | ... | ... |
400-SOURCECODE/AIAHTML5.Web/term-number-wp.js
1 | -var previousGrayImageDataList = []; | |
1 | +var UpdatedGrayImageDataList = []; | |
2 | +var doneBRID = []; | |
2 | 3 | var abc = 'hello'; |
3 | 4 | |
4 | -getLocationForMatchedTermsInWholeBody = function (TermList, maskCanvasData, coloredImageCanvasList, coloredImageMRCanvasList, grayImageDataList, grayImageMRDataList) { | |
5 | - | |
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")) | |
6 | 7 | var matchedRGBLocationInBodyRegion = []; |
7 | 8 | var matched; |
8 | - for (var x = 0; x < maskCanvasData.length; x++) { | |
9 | + | |
10 | + for (var x = 0; x < maskCanvasData.length; x++) | |
11 | + { | |
9 | 12 | |
10 | 13 | matched = false; |
11 | 14 | // alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId); |
... | ... | @@ -13,115 +16,67 @@ getLocationForMatchedTermsInWholeBody = function (TermList, maskCanvasData, colo |
13 | 16 | var canvasId = maskCanvasData[x].canvasId; |
14 | 17 | var maskData = maskCanvasData[x].maskData; |
15 | 18 | |
16 | - var coloredImageDataVar1 = coloredImageCanvasList[bodyRegionId - 1]; | |
17 | - var grayImageDataVar1 = grayImageDataList[bodyRegionId - 1]; | |
19 | + var coloredImageDataVar= coloredImageCanvasList[bodyRegionId - 1]; | |
20 | + var grayImageDataVar = grayImageDataList[bodyRegionId - 1]; | |
18 | 21 | |
19 | - | |
20 | - var coloredImageDataVar = coloredImageDataVar1.data; | |
21 | - var grayImageDataVar = grayImageDataVar1.data; | |
22 | - | |
23 | - | |
24 | - | |
25 | - | |
26 | - var counter = 0; | |
27 | - | |
28 | - var imageDataVar = maskData.data; | |
29 | - | |
30 | - // var previousBRID; | |
31 | - | |
32 | - var counter = 0; | |
33 | - | |
34 | - | |
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) { | |
43 | - | |
44 | - | |
45 | - var RED = imageDataVar[i] - 9; | |
46 | - var GREEN = imageDataVar[i + 1] - 9; | |
47 | - var BLUE = imageDataVar[i + 2] - 9; | |
48 | - | |
49 | - var Red; | |
50 | - var Green; | |
51 | - var Blue; | |
52 | - var zero = "0"; | |
53 | - | |
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() | |
65 | - | |
66 | - } | |
67 | - if ((BLUE).toString().length != 2) { | |
68 | - Blue = zero.concat((BLUE).toString()) | |
69 | - } | |
70 | - else { | |
71 | - Blue = (BLUE).toString() | |
72 | - | |
73 | - } | |
22 | + //var coloredImageDataVar = coloredImageDataVar1.data; | |
23 | + //var grayImageDataVar = grayImageDataVar1.data; | |
74 | 24 | |
75 | - var Icolor = (Red + Green + Blue); | |
76 | - // alert('Icolor: ' + Icolor) | |
25 | + var counter = 0; | |
77 | 26 | |
78 | - if (parseInt(TermList[z]._TermNumber) == parseInt(Icolor)) { | |
27 | + var imageDataVar = maskData.data; | |
79 | 28 | |
80 | - counter++; | |
29 | + var machLocationWP = new Worker('match-pixel-wp.js'); | |
30 | + | |
81 | 31 | |
32 | + machLocationWP.postMessage({ | |
82 | 33 | |
83 | - matchedRGBLocationInBodyRegion.push({ "BRId": bodyRegionId, "location": i }); | |
34 | + 'termList': termList, | |
35 | + 'maskCanvasData': maskData, | |
36 | + 'coloreImageData': coloredImageDataVar, | |
37 | + 'grayImageData': grayImageDataVar, | |
38 | + 'grayImageMRDataList': grayImageMRDataList, | |
39 | + 'bodyRegionId': bodyRegionId | |
84 | 40 | |
41 | + }); | |
85 | 42 | |
86 | - matched = true; | |
87 | - | |
88 | - var RED_coloredImage = coloredImageDataVar[i]; | |
89 | - | |
90 | - grayImageDataVar[i] = RED_coloredImage; | |
91 | - | |
92 | - | |
93 | - var GREEN_coloredImage = coloredImageDataVar[i + 1]; | |
94 | - grayImageDataVar[i + 1] = GREEN_coloredImage; | |
95 | - | |
96 | - var BLUE_coloredImage = coloredImageDataVar[i + 2]; | |
97 | - grayImageDataVar[i + 2] = BLUE_coloredImage; | |
98 | - | |
43 | + machLocationWP.onmessage = function (e) { | |
44 | + console.log('callback: ' + e.data.value+', x='+x); | |
45 | + | |
46 | + //var upadteddata = e.data.value; | |
47 | + //var bodyRegionId = e.data.bodyRegionId; | |
99 | 48 | |
100 | - var ALPHA_coloredImage = coloredImageDataVar[i + 3]; | |
101 | - grayImageDataVar[i + 3] = ALPHA_coloredImage; | |
49 | + //var grayCanvasID = 'imageCanvas' + bodyRegionId; | |
50 | + //var grayCanvas = document.getElementById(grayCanvasID); | |
51 | + //var grayCanvasContext = grayCanvas.getContext("2d"); | |
102 | 52 | |
103 | - } | |
104 | 53 | |
54 | + | |
55 | + //grayCanvasContext.putImageData(upadteddata, 0, 0); | |
56 | + doneBRID.push(e.data.bodyRegionId); | |
57 | + UpdatedGrayImageDataList[e.data.bodyRegionId] = e.data.value | |
105 | 58 | |
106 | - } | |
107 | - previousGrayImageDataList[parseInt(bodyRegionId - 1)] = grayImageDataVar1; | |
108 | - } | |
59 | + console.log('UpdatedGrayImageDataList: '+ UpdatedGrayImageDataList); | |
109 | 60 | |
110 | - | |
61 | + console.log('doneBRID: ' + doneBRID.length); | |
111 | 62 | |
112 | - if (matched == true) { | |
63 | + if (doneBRID.length==9) { | |
64 | + console.log('before sending UpdatedGrayImageDataList= ' + UpdatedGrayImageDataList) | |
113 | 65 | self.postMessage({ |
114 | - 'bodyRegionId': bodyRegionId, | |
115 | - 'value': grayImageDataVar1, | |
66 | + 'value': UpdatedGrayImageDataList, | |
67 | + 'name': 'Happy' | |
68 | + }) | |
69 | + } | |
116 | 70 | |
71 | + }; | |
72 | + machLocationWP.onerror = function (e) { | |
73 | + console.log('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message); | |
74 | + }; | |
117 | 75 | |
118 | - }); | |
119 | - | |
120 | - } | |
76 | + | |
121 | 77 | } |
122 | 78 | |
123 | - | |
124 | - | |
79 | + | |
125 | 80 | |
126 | 81 | |
127 | 82 | } |
... | ... | @@ -132,20 +87,4 @@ self.onmessage = function (e) { |
132 | 87 | |
133 | 88 | } |
134 | 89 | |
135 | -function launchMatchPixelWorkerProcess() { | |
136 | - | |
137 | - var worker = new Worker('match-pixel-wp.js'); | |
138 | - | |
139 | - worker.onmessage = function (e) { | |
140 | - var pixelLocation = e.data.msg; | |
141 | - | |
142 | - self.postMessage({ 'msg': pixelLocation }); | |
143 | - }; | |
144 | - worker.onerror = function (e) { | |
145 | - alert('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message); | |
146 | - }; | |
147 | - | |
148 | - | |
149 | - | |
150 | -} | |
151 | 90 | ... | ... |