term-number-wp.js 2.68 KB
previousGrayImageDataList = [];

getLocationForMatchedTermsInWholeBody = function (termList, maskCanvasData, coloredImageData, grayImageData, bodyRegionId, canvasId) {
    console.log('for bodyRegionId in worker process: ' + bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"))

    var masklen = maskCanvasData.data.length;
    var maskData = maskCanvasData.data;
    var nextStep = 8;
    var zero = "0";
    for (var z = 0; z < termList.length; z++) {

        var termnumber = termList[z]._TermNumber;
        if (termnumber.length < 6) {
            continue;
        }
        if (previousGrayImageDataList[parseInt(bodyRegionId - 1)] != null) {
            grayImageData = previousGrayImageDataList[parseInt(bodyRegionId - 1)];
        }

        var grayImageDataVar = grayImageData.data;
        var coloredImageDataVar = coloredImageData.data;

        for (var i = 0; i < masklen; i += nextStep) {

            var RED = maskData[i] - 9;
            if (RED < 0) { continue; }

            var GREEN = maskData[i + 1] - 9;
            if (GREEN < 0) { continue; }

            var BLUE = maskData[i + 2] - 9;
            if (BLUE < 0) { continue; }

            BLUE = BLUE.toString();
            if (BLUE.length != 2) {
                BLUE = zero.concat(BLUE);
            }
            if (termnumber.startsWith(BLUE, 4)) {
                GREEN = GREEN.toString();
                if (GREEN.length != 2) {
                    GREEN = zero.concat(GREEN);
                }

                if (termnumber.startsWith(GREEN, 2)) {
                    RED = RED.toString();
                    if (RED.length != 2) {
                        RED = zero.concat(RED);
                    }
                    if (termnumber.startsWith(RED, 0)) {

                        var Icolor = (RED + GREEN + BLUE);

                        if (termnumber == Icolor) {

                            for (var index = i; index < i + nextStep; index += 1) {

                                grayImageDataVar[index] = coloredImageDataVar[index];

                            }
                        }
                    }
                    else { continue; }

                }
                else { continue; }

            }
            else { continue; }

        }

        previousGrayImageDataList[parseInt(bodyRegionId - 1)] = grayImageData;

    }
    self.postMessage({
        'bodyRegionId': bodyRegionId,
        'value': grayImageData,
        'canvasId': canvasId

    });

}

self.onmessage = function (e) {
    getLocationForMatchedTermsInWholeBody(e.data.termList, e.data.maskCanvasData, e.data.coloredImageData,
        e.data.grayImageData, e.data.bodyRegionId, e.data.canvasId);

}