From 15172c384abe15ee2f09a778e644ded15555d1ce Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 23 Jun 2017 15:16:56 +0530 Subject: [PATCH] highlight by body system is implemented in mirrored image --- 400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------- 1 file changed, 127 insertions(+), 50 deletions(-) diff --git a/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js b/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js index ddd1fe9..23a1569 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js @@ -2804,7 +2804,7 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo false; } - console.log('HighlightBodyByTermList is called'); + console.log('HighlightBodyByTermListForBodySystem is called'); $scope.highlightedBR = []; @@ -2816,12 +2816,14 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo DataService.getJson(matchedTermListPath) .then( function (result) { + console.log('1. HighlightBodyByTermListForBodySystem is called'); $rootScope.macthedTermList = result; var termNo = 0; var pixcelLocation = 0; var prevBRID = 0; if ($rootScope.macthedTermList.length > 0) { - + console.log('2. HighlightBodyByTermListForBodySystem is called'); + //remove existing data and draw fresh data for(var i=0; i<$rootScope.grayImageDataList.length;i++){ var grayCanvasID = 'imageCanvas' + parseInt(i+1); var grayCanvas = document.getElementById(grayCanvasID); @@ -2853,78 +2855,153 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo var TermExistInBodyRegionId = value.bodyRegionId; + console.log('3. HighlightBodyByTermListForBodySystem is called TermExistInBodyRegionId=' + TermExistInBodyRegionId); + if (TermExistInBodyRegionId != undefined) { + if (prevBRID != TermExistInBodyRegionId) { - if (prevBRID != TermExistInBodyRegionId) { - var grayCanvasID = 'imageCanvas' + TermExistInBodyRegionId; - var grayCanvas = document.getElementById(grayCanvasID); - - if (grayCanvas != null) { - var grayCanvasContext = grayCanvas.getContext("2d"); - var canvasHeight = grayCanvas.height; - var canvasWidth = grayCanvas.width; - grayCanvasContext.clearRect(0, 0, canvasHeight, canvasWidth) - grayCanvasContext.putImageData($rootScope.grayImageDataList[parseInt(TermExistInBodyRegionId) - 1], 0, 0); + var grayCanvasID = 'imageCanvas' + TermExistInBodyRegionId; + var grayCanvas = document.getElementById(grayCanvasID); - var gData = grayCanvasContext.getImageData(0, 0, canvasWidth,canvasHeight ) + if (grayCanvas != null) { - grayImageDataVar = null; - var macthedData = new jinqJs() - .from($rootScope.macthedTermList) - .where('bodyRegionId == ' + TermExistInBodyRegionId) - .select(); + var grayCanvasContext = grayCanvas.getContext("2d"); - //grayImageDataVar = $rootScope.grayImageDataList[parseInt(TermExistInBodyRegionId) - 1] - - - var coloredImageDataVar = $rootScope.coloredImageCanvasList[parseInt(TermExistInBodyRegionId) - 1]; + var canvasHeight = grayCanvas.height; + var canvasWidth = grayCanvas.width; + var canvasX = grayCanvas.style.left; + var canvasY = grayCanvas.style.top; - var grayImageDataValue = gData.data; - var coloredImageDataValue = coloredImageDataVar.data; - // $rootScope.termListWithLocation = value.terms; + grayCanvasContext.clearRect(0, 0, canvasHeight, canvasWidth) + grayCanvasContext.putImageData($rootScope.grayImageDataList[parseInt(TermExistInBodyRegionId) - 1], 0, 0); - angular.forEach(macthedData, function (value2, key) { - $rootScope.termListWithLocation = value2.terms; - angular.forEach($rootScope.termListWithLocation.PixelLocations, function (value1, key1) { + var gData = grayCanvasContext.getImageData(0, 0, canvasWidth, canvasHeight); - var RED = coloredImageDataValue[value1]; - var GREEN = coloredImageDataValue[value1 + 1]; - var BLUE = coloredImageDataValue[value1 + 2]; + //for mirror images + var grayCanvasMRID = 'imageCanvas' + TermExistInBodyRegionId + '_MR'; + var grayCanvasMR = document.getElementById(grayCanvasMRID); + var grayCanvasMRX; + var grayCanvasMRY; - grayImageDataValue[value1] = RED; - grayImageDataValue[value1 + 1] = GREEN; - grayImageDataValue[value1 + 2] = BLUE; - }) + //draw a canvas for same bodyregion wich will be flipped after coloring the body system + if (TermExistInBodyRegionId == 4 || TermExistInBodyRegionId == 5 || TermExistInBodyRegionId == 6) { - var grayCanvasID = 'imageCanvas' + TermExistInBodyRegionId; - var grayCanvas = document.getElementById(grayCanvasID); - if (grayCanvas != null) { - var grayCanvasContext = grayCanvas.getContext("2d"); - var canvasHeight = grayCanvas.height; - var canvasWidth = grayCanvas.width; + var grayCanvasMRID = 'imageCanvas' + TermExistInBodyRegionId + '_MR'; + var grayCanvasMR = document.getElementById(grayCanvasMRID); + grayCanvasMRX = grayCanvasMR.style.left; + grayCanvasMRY = grayCanvasMR.style.top; - //grayCanvasContext.clearRect(0, 0, canvasHeight, canvasWidth) + var FlipedImgCanvas = document.createElement('canvas'); + FlipedImgCanvas.height = canvasHeight; + FlipedImgCanvas.width = canvasWidth; + FlipedImgCanvas.setAttribute("data-IsMirrored", "Y") + FlipedImgCanvas.style.position = "absolute"; + FlipedImgCanvas.style.left = canvasX + "px"; + FlipedImgCanvas.style.top = canvasY + "px"; + FlipedImgCanvas.style.visibility = 'hidden'; + FlipedImgCanvas.id = 'imageCanvas' + TermExistInBodyRegionId + '_MR'; - grayCanvasContext.putImageData(gData, 0, 0); + //remove previous canavs + $('#' + grayCanvasMRID).remove(); - // grayCanvasContext.putImageData($rootScope.rawGrayImageDataList[parseInt(TermExistInBodyRegionId) - 1], 0, 0); + //add new canvas on same location and after flipping it will be added to mirrored position + document.getElementById('canvasDiv').appendChild(FlipedImgCanvas); + //put grayData + var filppedCanvasContx = FlipedImgCanvas.getContext("2d"); + filppedCanvasContx.putImageData(gData, 0, 0); } - $('#spinner').css('visibility', 'hidden') - $rootScope.isLoading = false; - prevBRID = TermExistInBodyRegionId; - }) + grayImageDataVar = null; + var macthedData = new jinqJs() + .from($rootScope.macthedTermList) + .where('bodyRegionId == ' + TermExistInBodyRegionId) + .select(); + + + + var coloredImageDataVar = $rootScope.coloredImageCanvasList[parseInt(TermExistInBodyRegionId) - 1]; + + var grayImageDataValue = gData.data; + var coloredImageDataValue = coloredImageDataVar.data; + + + angular.forEach(macthedData, function (value2, key) { + + $rootScope.termListWithLocation = value2.terms; + + //pick the color from coloredImage data and put on gray imagedata + angular.forEach($rootScope.termListWithLocation.PixelLocations, function (value1, key1) { + + var RED = coloredImageDataValue[value1]; + var GREEN = coloredImageDataValue[value1 + 1]; + var BLUE = coloredImageDataValue[value1 + 2]; + + grayImageDataValue[value1] = RED; + grayImageDataValue[value1 + 1] = GREEN; + grayImageDataValue[value1 + 2] = BLUE; + }) + + //for non mirrored bpdy regions + var grayCanvasID = 'imageCanvas' + TermExistInBodyRegionId; + var grayCanvas = document.getElementById(grayCanvasID); + + if (grayCanvas != null) { + + var grayCanvasContext = grayCanvas.getContext("2d"); + + grayCanvasContext.putImageData(gData, 0, 0); + + } + + //for mirror body regions + if (TermExistInBodyRegionId == 4 || TermExistInBodyRegionId == 5 || TermExistInBodyRegionId == 6) { + + var grayCanvasMRID = 'imageCanvas' + TermExistInBodyRegionId + '_MR'; + + var grayCanvasMR = document.getElementById(grayCanvasMRID); + + if (grayCanvasMR != null) { + + var grayCanvasMRContext = grayCanvasMR.getContext("2d"); + + grayCanvasMRContext.save(); + grayCanvasMRContext.translate(canvasWidth, 0); + grayCanvasMRContext.scale(-1, 1); + //flip does not work with putImageData, that is why we used drawImage + grayCanvasMRContext.drawImage(grayCanvas, 0, 0, canvasWidth, canvasHeight, 0, 0, canvasWidth, canvasHeight); + grayCanvasMRContext.restore(); + + //set this canavs on the actual posution of mirror image + grayCanvasMR.style.left = grayCanvasMRX; + grayCanvasMR.style.top = grayCanvasMRY; + grayCanvasMR.style.visibility = 'visible'; + + + } + } + + $('#spinner').css('visibility', 'hidden') + $rootScope.isLoading = false; + + prevBRID = TermExistInBodyRegionId; + }) + } } } - }) + else { + $('#spinner').css('visibility', 'hidden') + $rootScope.isLoading = false; + } - } + }) + } + }, function (error) { -- libgit2 0.21.4