term-number-wp.js 3.83 KB
function abc(msg) {


    var msg1 = msg;

    self.postMessage({
        'cmd': 'getLocationForMatchedTermsInWholeBody',
        'value': msg1
    });


}

getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData, coloredImageCanvasList, coloredImageMRCanvasList, grayImageDataList, grayImageMRDataList) {

    var matchedRGBLocationInBodyRegion = [];
    var matched;
    for (var x = 0; x < maskCanvasData.length; x++) {
        debugger;
        matched = false;
        // alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId);
        var bodyRegionId = maskCanvasData[x].bodyRegionId;
        var canvasId = maskCanvasData[x].canvasId;
        var maskData = maskCanvasData[x].maskData;

        var coloredImageDataVar1 = coloredImageCanvasList[bodyRegionId - 1];
        var grayImageDataVar1 = grayImageDataList[bodyRegionId - 1];
        var coloredImageDataVar = coloredImageDataVar1.data;
        var grayImageDataVar = grayImageDataVar1.data;

        


        var counter = 0;

        var imageDataVar = maskData.data;

        //    var previousBRID;

        var counter = 0;


        var n = maskData.data.length;

        for (var i = 0; i < n; i += 4) {


            var RED = imageDataVar[i] - 9;
            var GREEN = imageDataVar[i + 1] - 9;
            var BLUE = imageDataVar[i + 2] - 9;

            var Red;
            var Green;
            var Blue;
            var zero = "0";

            if ((RED).toString().length != 2) {
                Red = zero.concat((RED).toString())
            }
            else {
                Red = (RED).toString()
            }
            if ((GREEN).toString().length != 2) {
                Green = zero.concat((GREEN).toString())
            }
            else {
                Green = (GREEN).toString()

            }
            if ((BLUE).toString().length != 2) {
                Blue = zero.concat((BLUE).toString())
            }
            else {
                Blue = (BLUE).toString()

            }

            var Icolor = (Red + Green + Blue);
            // alert('Icolor: ' + Icolor)

            if (parseInt(termNo) == parseInt(Icolor)) {

                counter++;

                //var obj = new Object();
                //obj.bodyRegionId = bodyRegionId;
                //obj.location = i;

                matchedRGBLocationInBodyRegion.push({ "BRId": bodyRegionId, "location": i });


                matched = true;

                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;

            }

          
        }
        self.postMessage({
            'bodyRegionId':bodyRegionId,
            'value': grayImageDataVar1,
           
        });

    }




}

self.onmessage = function (e) {
    getLocationForMatchedTermsInWholeBody(e.data.termNumber, e.data.maskCanvasData, e.data.coloredImageCanvasList,
        e.data.coloredImageMRCanvasList, e.data.grayImageDataList, e.data.grayImageMRDataList);

}

function launchMatchPixelWorkerProcess() {

    var worker = new Worker('match-pixel-wp.js');

    worker.onmessage = function (e) {
        var pixelLocation = e.data.msg;

        self.postMessage({ 'msg': pixelLocation });
    };
    worker.onerror = function (e) {
        alert('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message);
    };



}