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


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


}

getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData)
{

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

       // {
            //var scaledWidth = $scope.ColoredImageSRC[x].Width;
            //var scaledHeight = $scope.ColoredImageSRC[x].Height;
            ////var maskImg = $scope.ColoredImageSRC[x].SRC;


            //var coloredImg = $scope.ColoredImageSRC[x].SRC;

            //var maskImg = $scope.GetMaskImageSource(coloredImg);


            //var scledX = $scope.ColoredImageSRC[x].x;
            //var scledY = $scope.ColoredImageSRC[x].y;


            //// 1. get mask canvas for this body region.
            //var maskCanvasID;
            //if ($scope.ColoredImageSRC[x].haveMirror == 'true') {
            //    maskCanvasID = 'imageCanvas' + bodyRegionId + '_MR_mci';
            //}
            //else {
            //    maskCanvasID = 'imageCanvas' + bodyRegionId + '_mci';

            //}
            //var maskCanvas = document.getElementById(maskCanvasID);
            //var maskCanvasContext = maskCanvas.getContext("2d");
            //var maskImgData = maskCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight);

            //// 2. get coloured canvas for this body region.


            //var coloredImageDataVar;
            //var coloredImageDataMRVar

            //if ($scope.ColoredImageSRC[x].haveMirror == 'true') {

            //    coloredImageDataVar = $rootScope.coloredImageMRCanvasList[parseInt(bodyRegionId)];
            //}
            //else {
            //    coloredImageDataVar = $rootScope.coloredImageCanvasList[parseInt(bodyRegionId - 1)];
    //}

            //var grayImageDataVar;
            //var grayCanvas;
            //if ($scope.ColoredImageSRC[x].haveMirror == 'true') {

            //    //// 3. get mask canvas for this body region._MR
            //    var grayCanvasID = 'imageCanvas' + bodyRegionId + '_MR';
            //    grayCanvas = document.getElementById(grayCanvasID);
            //    var grayCanvasContext = grayCanvas.getContext("2d");
            //    var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight);
            //    grayImageDataVar = grayImageData.data;
            //}

            //else {
            //    var grayCanvasID = 'imageCanvas' + bodyRegionId;
            //    grayCanvas = document.getElementById(grayCanvasID);
            //    var grayCanvasContext = grayCanvas.getContext("2d");
            //    var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight);
            //    grayImageDataVar = grayImageData.data;
            //}

            //var coloredImageDataVarMR;
            //var coloredImageDataMR


            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 });

                   // var have = machedIcolorInBodyRegion.indexOf(bodyRegionId);


                    //if (have == -1) {
                    // //  machedIcolorInBodyRegion.push(bodyRegionId);
                    //}
                    //else {

                    //}


                    //previousGrayColoredData = i;
                    //if (coloredImageDataVar != null) {


                    //    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;


                    //}

                }
             

                //     grayCanvasContext.putImageData(grayImageData, 0, 0);
            }
            self.postMessage({
                'cmd': 'getLocationsForMatchedTermsInWholeBody',
                'value': matchedRGBLocationInBodyRegion
            });

           // grayCanvasContext.putImageData(grayImageData, 0, 0);
        //}

          
    }

   


}

self.onmessage = function (e) {
    getLocationForMatchedTermsInWholeBody(e.data.termNumber, e.data.maskCanvasData);

}

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);
    };



}