'use strict';
AIA.controller("DAController", ["$scope", "$rootScope", "$compile", "$http", "$log", "$location", "$timeout", "DA", "Modules", "$routeParams", "DataService",
function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Modules, $routeParam, DataService) {
console.log('DAController initialized')
$scope.genderId = "";
$scope.BodyViewData;
$scope.selectedGenderBodyViewData;
$scope.imagePath = "";
$scope.BodyRegionData;
$scope.BodyRegionCordinatesData;
$scope.isTransparencyActivated;
$scope.BodyLayerData;
$scope.VocabTermData;
$scope.TermNumberData;
$scope.bodyViewId = 0;
$scope.bgartData;
//view specific constants
$scope.voId;
$scope.layerNumber;
$scope.daCounter = 1;
$scope.bagartDetails;
$scope.transNumber = 50;
//for transarency scale
$scope.TBDrawStartX;
$scope.TBDrawStartY;
$scope.isHighLight = false;
$scope.coloredImageCanvasList = [];
$scope.zoomInOut = 75;
//array for bodyviewid correspoing to male female(used for gender change)
$scope.correspondingBodyViewIds = {
'1': '5',
'2': '6',
'3': '7',
'4': '8',
'9': '11',
'10': '12',
'5': '1',
'6': '2',
'7': '3',
'8': '4',
'11': '9',
'12': '10',
}
$scope.bodyViews = {
'Anterior': '1',
'Lateral': '2',
'Medial': '3',
'Posterior': '4',
'Lateral Arm': '5',
'Medial Arm': '6'
}
$scope.isBodylayerdataLoaded = false;
$scope.isBodyRegionDataLoaded = false;
$scope.showme = false;
$scope.IsVisible = function () {
$scope.scroll();
}
$scope.scroll = function () {
// $window.scrollTo(0, 0);
$("html,body").scrollTop(0);
//alert("scroll");
}
//get the DA body view list based on selected gender
//get the DA body view list based on selected gender
$scope.getDAViewList = function ($event) {
// debugger;
if ($('#MainImage') != null) {
$('#MainImage').remove();
}
$rootScope.currentActiveModuleTitle = Modules[0].Name;
$("#bodyViewList").empty();
//for default load
if ($event == null || $event == undefined) {
//if ((localStorage.getItem("genderId") != "")||(localStorage.getItem("genderId")!="null")) {
// $scope.genderId = localStorage.getItem("genderId");
//}
var selectedGender = localStorage.getItem("genderId");
if ((selectedGender == null)) {
$scope.genderId = "Male";
}
else
$scope.genderId = localStorage.getItem("genderId");
}
else {
$scope.genderId = $event.currentTarget.id;
}
localStorage.setItem("genderId", $scope.genderId);
var selectedGender = localStorage.getItem("genderId");
if (selectedGender != null) {
if (selectedGender == "Male") {
$('#Male').addClass('active');
$('#Female').removeClass("active");
}
else {
$('#Female').addClass('active');
$('#Male').removeClass("active");
}
}
$scope.selectedGenderBodyViewData = new jinqJs()
.from($scope.BodyViewData.BodyViews.view)
.where('_gender == ' + $scope.genderId)
.select();
angular.forEach($scope.selectedGenderBodyViewData, function (value, key) {
var userEthnicity = DA[0].ethnicity;
var userModestysettings = DA[0].modesty;
var userSelectedSkintone = 'W';
$scope.userModestySetting = 'Y'
var thumbnailImage;
if ((value._id == 1) || (value._id == 3) || (value._id == 5) || (value._id == 6) || (value._id == 7) || (value._id == 11))
thumbnailImage = ((value._thumbnailImage).replace('.jpg', '_' + userEthnicity + userModestysettings)) + '.jpg';
else {
thumbnailImage = ((value._thumbnailImage).replace('.jpg', '_' + userEthnicity)) + '.jpg';
}
$scope.imagePath = "~/../content/images/DA/"+$scope.zoomInOut +"/body-views/" + value._id + '/skintone/' + userEthnicity + '/' + thumbnailImage;
// debugger;
var $el = $('
').addClass('rectangle');
document.getElementById("DAView")
$selection.css({
'position': 'absolute',
//'background': 'transparent',
'border': '1px dotted #000'
});
var currentMousePosition = $scope.getMousePos(e);
$scope.TBDrawStartX = currentMousePosition.x;
$scope.TBDrawStartY = currentMousePosition.y;
var actulalX = currentMousePosition.x + $scope.horizontlScrollPosition
var actualY = currentMousePosition.y + $scope.verticalScrollPosition
//alert('$scope.TransparencyBoxStartX in mouseDown: ' + $scope.TransparencyBoxStartX + ' & Y= ' + $scope.TransparencyBoxStartY);
$scope.TransparencyBoxStartX = actulalX;
$scope.TransparencyBoxStartY = actualY
$scope.startX = actulalX;
$scope.startY = actualY;
var tBox = document.getElementById('transparencyCanvas');
if (tBox == null) {
//// canvasDiv.style.cursor = "crosshair";
$selection.css({
'top': actualY,
'left': actulalX,
'width': 0,
'height': 0,
'z-index': 1000
//'background': 'transparent',
});
$selection.appendTo($container);
}
document.getElementById('canvasDiv').removeEventListener("mousedown", mouseDownListener);
}
function mouseMoveListener(e) {
var currentMousePosition = $scope.getMousePos(e);
var move_x = currentMousePosition.x + $scope.horizontlScrollPosition,
move_y = currentMousePosition.y + $scope.verticalScrollPosition,
width = move_x - $scope.TransparencyBoxStartX,
height = move_y - $scope.TransparencyBoxStartY,
new_x, new_y;
new_x = (move_x < $scope.TransparencyBoxStartX) ? ($scope.TransparencyBoxStartX - width) : $scope.TransparencyBoxStartX;
new_y = (move_y < $scope.TransparencyBoxStartY) ? ($scope.TransparencyBoxStartY - height) : $scope.TransparencyBoxStartY;
$('.rectangle').css({
'width': width,
'height': height,
//'background': 'transparent'
});
}
function mouseUpListener(e) {
// $selection.remove();
// debugger;
$scope.currentLayerNumber = parseInt($('#txtlayerNumber').val());
$('.rectangle').remove();
var currentMousePosition = $scope.getMousePos(e);
var canvasDiv = document.getElementById('canvasDiv');
var verticalScrollPosition = canvasDiv.scrollTop;
var horizontlScrollPosition = canvasDiv.scrollLeft;
var TransparencyEndX = currentMousePosition.x + horizontlScrollPosition
var TransparencyBoxEndY = currentMousePosition.y + verticalScrollPosition
$scope.isTboxDrwan = true;
$scope.TbEndX = TransparencyEndX;
$scope.TbEndY = TransparencyBoxEndY;
$scope.TransparencyEndX = TransparencyEndX;
$scope.TransparencyBoxEndY = TransparencyBoxEndY;
//draw temp box to store the canvas data with original transparecy
if (document.getElementById('tempCanvas') != null) {
$('#tempCanvas').remove();
}
if (document.getElementById('tempCanvas') == null) {
var tempCanvas = document.createElement('canvas');
tempCanvas.id = 'tempCanvas';
// $scope.tempCanvas = transparencyCanvas.id;
tempCanvas.height = TransparencyBoxEndY - $scope.startY;
tempCanvas.width = TransparencyEndX - $scope.startX;
tempCanvas.style.position = "absolute";
tempCanvas.style.left = 200 + 'px';
tempCanvas.style.top = 200 + 'px';
tempCanvas.style.backgroundColor = "transparent";
tempCanvas.style.visibility = 'hidden';
tempCanvas.style.border = "black 1px solid";
document.getElementById('canvasDiv').appendChild(tempCanvas);
}
var BodyRegionDictionary = $scope.BodyRegionCordinatesData;
$scope.IncludedBodyRegions = [];
////debugger;
$.each(BodyRegionDictionary, function (index, value) {
// alert(' $.each(BodyRegionDictionary1')
var transparencyBoxHeight = parseInt(TransparencyBoxEndY) - parseInt($scope.TransparencyBoxStartY);
var transparencyBoxWidth = parseInt(TransparencyEndX) - parseInt($scope.TransparencyBoxStartX);
var transparencyBoxBottom = parseInt($scope.TransparencyBoxStartY) + parseInt(transparencyBoxHeight);
var transparencyBoxRight = parseInt($scope.TransparencyBoxStartX) + parseInt(transparencyBoxWidth);
// alert(' $.each(BodyRegionDictionary2. transparencyBoxHeight: ' + transparencyBoxHeight + ',transparencyBoxBottom: ' + transparencyBoxBottom+', transparencyBoxRight: '+transparencyBoxRight)
var bodyRegionRight = parseInt(value.X) + parseInt(value.Width);
var bodyRegionBottom = parseInt(value.Y) + parseInt(value.Height);
var transparencyCanvas = document.createElement('canvas');
var tBox = document.getElementById('transparencyCanvas');
if (tBox == null) {
transparencyCanvas.id = 'transparencyCanvas';
$scope.transparencyCanvasId = transparencyCanvas.id;
transparencyCanvas.height = TransparencyBoxEndY - $scope.startY;
transparencyCanvas.width = TransparencyEndX - $scope.startX;
transparencyCanvas.style.position = "absolute";
transparencyCanvas.style.left = $scope.startX + 'px' // x + "px";
transparencyCanvas.style.top = $scope.startY + "px"//y + "px";
transparencyCanvas.style.border = "black 1px solid";
transparencyCanvas.style.backgroundColor = "transparent";
// transparencyCanvas.style.visibility = 'hidden';
document.getElementById('canvasDiv').appendChild(transparencyCanvas);
$scope.transparencyChangeCounter = 0;
$('#transparencyCanvas').resizable({ handles: "e,s,se,w,n,ne,nw,sw", stop: function (event, ui) { resizeCanvas(); }, start: function (event, ui) { clearTransCanvas(); } });
$scope.transparencyCanvasHeight = transparencyCanvas.height;
$scope.transparencyCanvasWidth = transparencyCanvas.width;
//bind click listener
transparencyCanvas.addEventListener('click', TransparencyCanvasClickListener);
$(".ui-wrapper").css("z-index", "600");
// $('#transparencyScale').modal('show');
//canvasDiv.removeEventListener('mouseup', arguments.callee);
//canvasDiv.removeEventListener('mousedown', arguments.callee);
//canvasDiv.removeEventListener('mousemove', arguments.callee);
}
if ($scope.TransparencyBoxStartX <= bodyRegionRight && value.X <= transparencyBoxRight && $scope.TransparencyBoxStartY <= bodyRegionBottom && value.Y <= transparencyBoxBottom) {
//if ($scope.voId != "9") {
// if ($scope.voId != "11") {
// $scope.loadTransparencyImage(value.bodyRegionId, value.Height, value.Width, value.X, value.Y, value.IsMirror, $scope.TransparencyBoxStartX, TransparencyEndX, $scope.TransparencyBoxStartY, TransparencyBoxEndY, $scope, false, false);
// }
//}
//else {
// if (value.bodyRegionId == "6") {
// $scope.loadTransparencyImage(value.bodyRegionId, value.Height, value.Width, value.X, value.Y, value.IsMirror, $scope.TransparencyBoxStartX, TransparencyEndX, $scope.TransparencyBoxStartY, TransparencyBoxEndY, $scope, false, false);
// }
//}
if (($scope.voId == "9" || $scope.voId == "11")) {
if (value.bodyRegionId == "6") {
$scope.loadTransparencyImage(value.bodyRegionId, value.Height, value.Width, value.X, value.Y, value.IsMirror, $scope.TransparencyBoxStartX, TransparencyEndX, $scope.TransparencyBoxStartY, TransparencyBoxEndY, $scope, false, false);
}
else {
}
}
else {
$scope.loadTransparencyImage(value.bodyRegionId, value.Height, value.Width, value.X, value.Y, value.IsMirror, $scope.TransparencyBoxStartX, TransparencyEndX, $scope.TransparencyBoxStartY, TransparencyBoxEndY, $scope, false, false);
}
}
})
// $('#transparencyScale').modal('show');
$('#transparencyScale').css('position', 'fixed')
$('#transparencyScale').css('top', $scope.TBDrawStartY - 10)
$('#transparencyScale').css('left', $scope.TBDrawStartX + 130)
$('#transparencyScale').css('visibility', 'visible')
$('#transparencyScale').css("z-index", "900")
document.getElementById('canvasDiv').removeEventListener("mousedown", mouseUpListener);
document.getElementById('canvasDiv').removeEventListener("mousemove", mouseUpListener);
document.getElementById('canvasDiv').removeEventListener("mouseup", mouseUpListener);
// document.getElementById('canvasDiv').removeEventListener("mousemove", mouseMoveListener);
$('#btnTranparency').removeClass('btn-black');
$('#btnTranparency').addClass('tButtonActive');
//debugger;
$('#txtlayerNumber').val((parseInt($scope.currentLayerNumber))+1);
}
$scope.loadTransparencyImage = function (bodyRegionId, Height, Width, X, Y, IsMirror, TransparencyBoxStartX, TransparencyEndX, TransparencyBoxStartY, TransparencyBoxEndY, scope, isLayerChanged, isTransparencyChanged) {
// debugger;
var scope1 = angular.element(document.getElementById("DAView")).scope();
var transparencyCanvas = document.getElementById('transparencyCanvas');
TransparencyBoxStartX = parseInt((transparencyCanvas.style.left).replace('px', ''));
TransparencyBoxStartY = parseInt((transparencyCanvas.style.top).replace('px', ''));
TransparencyEndX = parseInt(transparencyCanvas.width) + parseInt(TransparencyBoxStartX);
TransparencyBoxEndY = parseInt(transparencyCanvas.height) + parseInt(TransparencyBoxStartY);
var XforCopyImage = 0;
var YforCopyImage = 0;
var WidthforCopyImage = 0;
var HeightforCopyImage = 0;
var XforTransImage = 0;
var WidthforTransImage = 0;
var HeightforTransImage = 0;
var YforTransImage = 0;
var PreviousBodyRegionHeight = 0;
var PreviousBodyRegionY;
var PreviousBodyRegionWidth;
var PreviousBodyRegionX;
var previousBodyRegionId;
var transparencyTempCanvas;
//X ends outside and start outside of bodyregion
if (TransparencyBoxStartX < X && TransparencyEndX > parseInt(X) + parseInt(Width)) {
XforCopyImage = 0;
WidthforCopyImage = Width;
WidthforTransImage = Width;
XforTransImage = parseInt(X) - (parseInt(TransparencyBoxStartX));
// alert('1')
}
else if (TransparencyBoxStartX < X && TransparencyEndX < parseInt(X) + parseInt(Width)) {
XforCopyImage = 0;
WidthforCopyImage = parseInt(TransparencyEndX) - parseInt(X);
WidthforTransImage = parseInt(TransparencyEndX) - parseInt(X);
// alert(' scope.WidthforCopyImage: ' + scope.WidthforCopyImage)
XforTransImage = parseInt(X) - (parseInt(TransparencyBoxStartX));
// alert('2')
}
else if (TransparencyBoxStartX > X && TransparencyEndX > parseInt(X) + parseInt(Width)) {
// alert('TransparencyEndX: ' + TransparencyEndX + ', X: ' + X + ', Width: ' + Width + 'scope.TransparencyBoxStartX: ' + scope.TransparencyBoxStartX)
XforCopyImage = parseInt(TransparencyBoxStartX) - parseInt(X);
WidthforCopyImage = parseInt(X) + parseInt(Width) - parseInt(TransparencyBoxStartX);
WidthforTransImage = parseInt(X) + parseInt(Width) - parseInt(TransparencyBoxStartX);
XforTransImage = 0;
// alert('3')
}
else if (TransparencyBoxStartX > X && TransparencyEndX < parseInt(X) + parseInt(Width)) {
// alert('startX inside & endX inside')
XforCopyImage = parseInt(TransparencyBoxStartX) - parseInt(X);//parseInt(X) + parseInt(Width) - parseInt(scope.TransparencyBoxStartX)// scope.TransparencyBoxStartX ;
WidthforCopyImage = parseInt(TransparencyEndX) - parseInt(TransparencyBoxStartX);
WidthforTransImage = parseInt(TransparencyEndX) - parseInt(TransparencyBoxStartX);
XforTransImage = 0
// alert('4. TransparencyBoxStartX: ' + TransparencyBoxStartX + ',X: ' + parseInt(X) + ',TransparencyEndX: ' + TransparencyEndX + ',XforCopyImage: ' + XforCopyImage)
}
//calculate Y and height for tempTranparency box from where to cut the image
if (TransparencyBoxStartY < Y && TransparencyBoxEndY > parseInt(Y) + parseInt(Height)) {
// alert('start Y outside and end Y outside');
YforCopyImage = 0;
HeightforCopyImage = Height;
HeightforTransImage = Height;
//alert('Y ' + Y)
YforTransImage = parseFloat(Y) - parseInt(TransparencyBoxStartY)//parseFloat(Y) - (24.4);
// alert('5')
}
else if (TransparencyBoxStartY < Y && TransparencyBoxEndY < (parseInt(Y) + parseInt(Height))) {
YforCopyImage = 0;
HeightforCopyImage = (parseInt(TransparencyBoxEndY)) - parseInt(Y)//(parseInt(Height) + parseInt(Y)) - (parseInt(TransparencyBoxEndY) - parseInt(scope.TransparencyBoxStartY));
HeightforTransImage = (parseInt(TransparencyBoxEndY)) - parseInt(Y)// - parseInt(scope.TransparencyBoxStartY));
YforTransImage = parseFloat(Y) - parseInt(TransparencyBoxStartY);// - (24.4);
}
else if (TransparencyBoxStartY > Y && TransparencyBoxEndY > parseInt(Y) + parseInt(Height)) {
YforCopyImage = parseInt(TransparencyBoxStartY) - parseInt(Y);
HeightforCopyImage = parseInt(Y) + parseInt(Height) - parseInt(TransparencyBoxStartY);
HeightforTransImage = parseInt(Y) + parseInt(Height) - parseInt(TransparencyBoxStartY);
YforTransImage = 0;
}
else if (TransparencyBoxStartY > Y && TransparencyBoxEndY < parseInt(Y) + parseInt(Height)) {
YforCopyImage = parseInt(TransparencyBoxStartY) - parseInt(Y);
HeightforCopyImage = parseInt(TransparencyBoxEndY) - parseInt(TransparencyBoxStartY);
HeightforTransImage = parseInt(TransparencyBoxEndY) - parseInt(TransparencyBoxStartY);
YforTransImage = 0;
}
//this changes the transparency when user click on transparency scale(we have already set the original
//data on tras canvas irrespective of the trans number, so we can chnage the transparnecy of original data not the manipulated)
if (isTransparencyChanged == true) {
// var txtTransparencyChange = document.getElementById("txtTransparencyChange");
var transNumber = $scope.transNumber;
var ctx = document.getElementById('transparencyCanvas').getContext('2d');
var imageDa = ctx.getImageData(XforTransImage, YforTransImage, WidthforTransImage, HeightforTransImage);
// get the image data values
var imageData = imageDa.data;
var length = imageData.length;
// set every fourth value to 50
for (var i = 3; i < length; i += 4) {
imageData[i] = ((255) * (parseInt(transNumber))) / 100;
}
// after the manipulation, reset the data
// imageDa.data = imageData;
// and put the imagedata back to the canvas
ctx.putImageData(imageDa, XforTransImage, YforTransImage);
}
else {
//0. get current layer number
if ($scope.isResized) {
//do nothing
}
else if (isLayerChanged) {
// debugger
$scope.layerNumber = parseInt($('#txtlayerNumber').val());
}
else {
var currentLayer = parseInt($('#txtlayerNumber').val());
var tranparencyLayer = currentLayer + 1;
$scope.layerNumber = tranparencyLayer;
}
//dedebugger;
//1. get the image source
var tranparencyImgSrc;
tranparencyImgSrc = $scope.GetImageSource(bodyRegionId);
var tranparencyMaskImgSrc = $scope.GetMaskImageSource(tranparencyImgSrc);
// debugger;
var oldCanvas;
if (IsMirror == 'Yes') {
oldCanvas = document.getElementById('transparencyTempCanvas_MR_' + bodyRegionId)
}
else {
oldCanvas = document.getElementById('transparencyTempCanvas_' + bodyRegionId)
}
if (oldCanvas != null) {
document.getElementById('canvasDiv').removeChild(oldCanvas);
}
//remove tempmask canvas
var oldtempTransCanvasMask;
if (IsMirror == 'Yes') {
oldtempTransCanvasMask = document.getElementById('transparencyTempCanvasMask_MR_' + bodyRegionId + '_mci');
}
else {
oldtempTransCanvasMask = document.getElementById('transparencyTempCanvasMask_' + bodyRegionId + '_mci');
}
if (oldtempTransCanvasMask != null) {
document.getElementById('canvasDiv').removeChild(oldtempTransCanvasMask);
}
transparencyTempCanvas = document.createElement('canvas');
var transparencyTempcanavsMask = document.createElement('canvas');
//if mirror then draw mask image for non mirrored body region for annotation
if (IsMirror == 'Yes') {
transparencyTempCanvas.id = 'transparencyTempCanvas_MR_' + bodyRegionId;
transparencyTempcanavsMask.id = 'transparencyTempCanvasMask_MR' + bodyRegionId + '_mci';
}
else {
transparencyTempCanvas.id = 'transparencyTempCanvas_' + bodyRegionId;
transparencyTempcanavsMask.id = 'transparencyTempCanvasMask_' + bodyRegionId + '_mci';
}
transparencyTempCanvas.height = Height;
transparencyTempCanvas.width = Width;
transparencyTempCanvas.style.position = "absolute";
transparencyTempCanvas.style.left = X + 'px' // x + "px";
transparencyTempCanvas.style.top = Y + "px"//y + "px";
transparencyTempCanvas.style.visibility = 'hidden';
//transparencyTempCanvas.style.visibility = 'visible';
// transparencyCanvas.style.zIndex = 4000;
document.getElementById('canvasDiv').appendChild(transparencyTempCanvas);
//create temp mask canvas
transparencyTempcanavsMask.height = Height;
transparencyTempcanavsMask.width = Width;
transparencyTempcanavsMask.style.position = "absolute";
transparencyTempcanavsMask.style.left = X + 'px' // x + "px";
transparencyTempcanavsMask.style.top = Y + "px"//y + "px";
transparencyTempcanavsMask.style.visibility = 'hidden';
//transparencyTempCanvas.style.visibility = 'visible';
// transparencyCanvas.style.border = "black 1px solid";
document.getElementById('canvasDiv').appendChild(transparencyTempcanavsMask);
var tempImg = new Image();
tempImg.src = tranparencyImgSrc;//"http://localhost/AIA/" + tranparencyImgSrc;
tempImg.onload = function () {
// debugger;
var tempCtx = transparencyTempCanvas.getContext('2d');
if (IsMirror == 'Yes') {
//debugger;
tempCtx.save();
tempCtx.translate(Width, 0);
tempCtx.scale(-1, 1);
tempCtx.drawImage(tempImg, 0, 0);
}
else {
tempCtx.drawImage(tempImg, 0, 0);
}
// debugger;
var tempCanvasID;
if (IsMirror == 'Yes') {
tempCanvasID = 'transparencyTempCanvas_MR_' + bodyRegionId;
}
else {
tempCanvasID = 'transparencyTempCanvas_' + bodyRegionId;
}
// niki 3june
//var txtTransparencyChange = document.getElementById("txtTransparencyChange");
////for first time, the transparency should be 50%
//if ($scope.isTboxDrwan) {
// if (txtTransparencyChange != null)
// txtTransparencyChange.value = 50;
// $scope.isTboxDrwan = false;
//}
//check if transparency is activated
var transNumber = $scope.transNumber;//txtTransparencyChange.value;
// debugger;
//this changes the transparency when transparency is already activated(on scale the value is >0) and user resizes or chage the layer
var imageD = tempCtx.getImageData(0, 0, Width, Height);
if (transNumber > 0) {
// debugger;
// tempCanvasID = 'transparencyTempCanvas_' + bodyRegionId;
var tempCtx = document.getElementById(tempCanvasID).getContext('2d');
// var image = ctx.getImageData(0, 0, scope.transparencyCanvasWidth, scope.transparencyCanvasHeight);
//keep the original image on temp canavs to use it in changing transparency
// if (scope.isResized == true || scope.isLayerChanged) {
//debugger;
if (document.getElementById('tempCanvas') != null) {
var contx = document.getElementById('tempCanvas').getContext('2d');
var tbTempCanvas = document.getElementById(tempCanvasID)
contx.drawImage(tbTempCanvas, XforCopyImage, YforCopyImage, WidthforCopyImage, HeightforCopyImage, XforTransImage, YforTransImage, WidthforTransImage, HeightforTransImage);
}
// get the image data values
var imageData = imageD.data;
var length = imageData.length;
//change background of image from transparent to white
if ($scope.voId == 9 || $scope.voId == 11) {
for (var i = 3; i < length; i += 4) {
imageData[i] = '#FFFFFFFF';
}
tempCtx.putImageData(imageD, 0, 0);
var imageDWhite = tempCtx.getImageData(0, 0, Width, Height);
var imageDataWhite = imageDWhite.data;
var lengthW = imageDataWhite.length;
//
for (var i = 3; i < lengthW; i += 4) {
imageDataWhite[i] = ((255) * (parseInt(transNumber))) / 100;
}
// imageD.data = imageData;
// and put the imagedata back to the canvas
// debugger
tempCtx.putImageData(imageDWhite, 0, 0);
}
else {
// set every fourth value to 50
for (var i = 3; i < length; i += 4) {
imageData[i] = ((255) * (parseInt(transNumber))) / 100;
}
// imageD.data = imageData;
// and put the imagedata back to the canvas
// debugger
tempCtx.putImageData(imageD, 0, 0);
}
}
var ctx = transparencyCanvas.getContext('2d');
var TrtempCanvasID
if (IsMirror == 'Yes') {
TrtempCanvasID = 'transparencyTempCanvas_MR_' + bodyRegionId;
}
else {
TrtempCanvasID = 'transparencyTempCanvas_' + bodyRegionId;
}
var tmpCanvasContext = document.getElementById(TrtempCanvasID);//.getContext('2d');
ctx.drawImage(tmpCanvasContext, XforCopyImage, YforCopyImage, WidthforCopyImage, HeightforCopyImage, XforTransImage, YforTransImage, WidthforTransImage, HeightforTransImage)
XforCopyImage = 0;
YforCopyImage = 0;
WidthforCopyImage = 0;
HeightforCopyImage = 0;
XforTransImage = 0;
WidthforTransImage = 0;
HeightforTransImage = 0;
YforTransImage = 0;
PreviousBodyRegionHeight = 0;
} //niki
// }
//mask image code
//draw mask for annotation
var tempMaskImg = new Image();
var tranparencyMaskImgSrc = $scope.GetMaskImageSource(tranparencyImgSrc);
tempMaskImg.src = tranparencyMaskImgSrc;//"http://localhost/AIA/" + tranparencyMaskImgSrc;
tempMaskImg.onload = function () {
// debugger;
var tempmaskCtx = transparencyTempcanavsMask.getContext('2d');
if (IsMirror == 'Yes') {
//debugger;
tempmaskCtx.save();
tempmaskCtx.translate(Width, 0);
tempmaskCtx.scale(-1, 1);
tempmaskCtx.drawImage(tempMaskImg, 0, 0);
}
else {
tempmaskCtx.drawImage(tempMaskImg, 0, 0);
}
}
PreviousBodyRegionHeight = HeightforTransImage;
PreviousBodyRegionY = YforTransImage;
PreviousBodyRegionWidth = WidthforTransImage;
PreviousBodyRegionX = XforTransImage;
previousBodyRegionId = bodyRegionId;
// $scope.layerNumber = parseInt($scope.layerNumber - 1);
}
}
function resizeCanvas() {
//debugger;
// alert('reload')
clearTransCanvas();
if ($('#speechBubbleTrns').length > 0) {
$('#speechBubbleTrns').remove();
}
var tCanvas = document.getElementById('transparencyCanvas');
var tCanvasContext = tCanvas.getContext('2d');
var tCanvasHeight = parseInt((tCanvas.style.height).replace('px', ''));
var tCanvasWidth = parseInt((tCanvas.style.width).replace('px', ''));
var tBoxStartX = parseInt((tCanvas.style.left).replace('px', ''));
var tBoxEndX = parseInt((tCanvas.style.left).replace('px', '')) + parseInt((tCanvas.style.width.replace('px', '')));
var tBoxStartY = parseInt((tCanvas.style.top).replace('px', ''));
var tBoxEndY = parseInt((tCanvas.style.top).replace('px', '')) + parseInt((tCanvas.style.height).replace('px', ''));
var transparencyBoxBottom = parseInt(tBoxStartY) + parseInt(tCanvasHeight);
var transparencyBoxRight = parseInt(tBoxStartX) + parseInt(tCanvasWidth);
if (tCanvas != null) {
$('#transparencyCanvas').remove();
}
$scope.isResized = true;
if (tCanvasHeight != $scope.transparencyCanvasHeight || tCanvasWidth != $scope.transparencyCanvasWidth) {
var transparencyCanvas = document.createElement('canvas');
transparencyCanvas.id = 'transparencyCanvas';
$scope.transparencyCanvas = tCanvas.id;
transparencyCanvas.height = tCanvasHeight;
transparencyCanvas.width = tCanvasWidth;
transparencyCanvas.style.position = "absolute";
transparencyCanvas.style.left = tCanvas.style.left; // x + "px";
transparencyCanvas.style.top = tCanvas.style.top//y + "px";
transparencyCanvas.style.border = "black 1px solid";
document.getElementById('canvasDiv').appendChild(transparencyCanvas);
$('#transparencyCanvas').resizable({ handles: "e,s,se,w,n,ne,nw,sw", stop: function (event, ui) { resizeCanvas(); }, start: function (event, ui) { clearTransCanvas(); } });
}
$scope.transparencyCanvasHeight = tCanvasHeight;
$scope.transparencyCanvasWidth = tCanvasWidth;
// debugger;
//create temp cavas to retain the original anavs data for use in transparency change as
//if u use original canvas data for transprency change then at 0 transparency all data will become transparent and if u increase transparency with this data then the canavs will be blank
if (document.getElementById('tempCanvas') != null) {
$('#tempCanvas').remove();
}
var tempCanvas = document.createElement('canvas');
tempCanvas.id = 'tempCanvas';
$scope.tempCanvas = tempCanvas.id;
tempCanvas.height = $scope.transparencyCanvasHeight;
tempCanvas.width = $scope.transparencyCanvasWidth;
tempCanvas.style.position = "absolute";
tempCanvas.style.left = 200 + 'px';
tempCanvas.style.backgroundColor = "transparent";
tempCanvas.style.visibility = 'hidden';
// tempCanvas.style.border = "black 1px solid";
document.getElementById('canvasDiv').appendChild(tempCanvas);
var BodyRegionDictionary = $scope.BodyRegionCordinatesData;
$scope.IncludedBodyRegions = [];
// $scope.layerNo = parseInt(document.getElementById(''))
var counter = 0;
$.each(BodyRegionDictionary, function (index, value) {
var bodyRegionRight = parseInt(value.X) + parseInt(value.Width);
var bodyRegionBottom = parseInt(value.Y) + parseInt(value.Height);
var TBRight = parseInt((document.getElementById('transparencyCanvas').style.left).replace('px', '')) + parseInt((document.getElementById('transparencyCanvas').style.width).replace('px', ''));
var TBBottom = parseInt((document.getElementById('transparencyCanvas').style.top).replace('px', '')) + parseInt((document.getElementById('transparencyCanvas').style.height).replace('px', ''));
var TBStartX = parseInt((document.getElementById('transparencyCanvas').style.left).replace('px', ''));
var TBStartY = parseInt((document.getElementById('transparencyCanvas').style.top).replace('px', ''));
if (TBStartX <= bodyRegionRight && value.X <= TBRight && TBStartY <= bodyRegionBottom && value.Y <= TBBottom) {
$scope.loadTransparencyImage(value.bodyRegionId, value.Height, value.Width, value.X, value.Y, value.IsMirror, $scope.TransparencyBoxStartX, $scope.TransparencyEndX, $scope.TransparencyBoxStartY, $scope.TransparencyBoxEndY, $scope, false, false);
}
})
//bind click listener
//bind click listener
transparencyCanvas.addEventListener('click', TransparencyCanvasClickListener);
// });
$(".ui-wrapper").css("z-index", "600");
$scope.isResized = false;
}
function TransparencyCanvasClickListener(evt) {
//alert('tb clicked')
// debugger;
var pixelData;
var pixelDataTrans;
var mousePos = $scope.getMousePos(evt);
// alert(mousePos.x + ',' + mousePos.y);
var canvasDiv = document.getElementById('canvasDiv');
var verticalScrollPosition = canvasDiv.scrollTop;
var horizontlScrollPosition = canvasDiv.scrollLeft;
//We substracted 135, as the difference between flex and html coordinates for same organ is 135
var actulalX = mousePos.x + horizontlScrollPosition;
var actualY = mousePos.y + verticalScrollPosition //- 135; //+ tomenuBarheight + titleBarheight + searchComboheight;
var clickedBodyRegion;
var x;
var y;
var isMirror;
var width;
var BodyRegionDictionary = $scope.BodyRegionCordinatesData;
$.each(BodyRegionDictionary, function (index, value) {
var bodyRegionRight = parseInt(value.X) + parseInt(value.Width);
var bodyRegionBottom = parseInt(value.Y) + parseInt(value.Height);
if (actulalX <= bodyRegionRight && value.X <= actulalX && actualY <= bodyRegionBottom && value.Y <= actualY) {
clickedBodyRegion = value.bodyRegionId;
x = value.X;
y = value.Y;
width = value.Width;
isMirror = value.IsMirror;
return false;
}
})
if (isMirror == "Yes") {
var mirrorCanvasX = x;
var mirrorCanvasWidth = width;
var clickedCanvasMaskId = 'imageCanvas' + clickedBodyRegion + '_mci';
var clickedCanavs = document.getElementById(clickedCanvasMaskId);
//if non mirrored canvas does not exist for this irror Body region then draw non mirrored image to get annotation
var clickedBodyRegionData = new jinqJs()
.from(BodyRegionDictionary)
.where('bodyRegionId == ' + clickedBodyRegion)
.select();
var nomMirroredBodyRegion = new jinqJs()
.from(clickedBodyRegionData)
.where('IsMirror == No')
.select();
//debugger;
var oldMirrorMaskId = 'transparencyTempCanvasMask_' + clickedBodyRegion + '_mci';
var oldMirrorMask = document.getElementById(oldMirrorMaskId);
if (oldMirrorMask != null) {
document.getElementById('canvasDiv').removeChild(oldMirrorMask);
}
var transparencyTempcanavsMask = document.createElement('canvas');
transparencyTempcanavsMask.id = 'transparencyTempCanvasMask_' + clickedBodyRegion + '_mci';
transparencyTempcanavsMask.height = nomMirroredBodyRegion[0].Height;
transparencyTempcanavsMask.width = nomMirroredBodyRegion[0].Width;
transparencyTempcanavsMask.style.position = "absolute";
transparencyTempcanavsMask.style.left = nomMirroredBodyRegion[0].X + 'px' // x + "px";
transparencyTempcanavsMask.style.top = nomMirroredBodyRegion[0].Y + "px"//y + "px";
transparencyTempcanavsMask.style.visibility = 'hidden';
document.getElementById('canvasDiv').appendChild(transparencyTempcanavsMask);
var tranparencyImgSrc = $scope.GetImageSource(clickedBodyRegion);
var tempMaskImg = new Image();
var tranparencyMaskImgSrc = $scope.GetMaskImageSource(tranparencyImgSrc);
tempMaskImg.onload = function () {
var tempmaskCtx = transparencyTempcanavsMask.getContext('2d');
tempmaskCtx.drawImage(tempMaskImg, 0, 0);
//get x,y of non mirrored canvas for this body region
x = transparencyTempcanavsMask.style.left;
y = transparencyTempcanavsMask.style.top;
var maskCanvasTransId = 'transparencyTempCanvasMask_' + clickedBodyRegion + '_mci';
var maskCanvastrans = document.getElementById(maskCanvasTransId);
var maskCanvasContexttrans = maskCanvastrans.getContext("2d");
var canvasDiv = document.getElementById('canvasDiv');
var verticalScrollPosition = canvasDiv.scrollTop;
var horizontlScrollPosition = canvasDiv.scrollLeft;
var distanceXOnMirrorImage = (parseInt(mirrorCanvasX) + parseInt(mirrorCanvasWidth)) - (parseInt(mousePos.x) + horizontlScrollPosition);// - 135);
var mirrorXOnNormalImage = parseInt(maskCanvasContexttrans.canvas.offsetLeft) + parseInt(distanceXOnMirrorImage);
var actulalX = mirrorXOnNormalImage
var actualY = mousePos.y + verticalScrollPosition
var clickedCanvasMaskId = 'imageCanvas' + clickedBodyRegion + '_mci';
var maskCanvas = document.getElementById(clickedCanvasMaskId);
var canvasContextForRGB = maskCanvas.getContext("2d");
var imgX = Math.round(actulalX - parseInt(x.replace('px', '')));
var imgY = Math.round(actualY - parseInt(y.replace('px', '')));
pixelData = canvasContextForRGB.getImageData(imgX, imgY, 1, 1);
//trans layer image data
pixelDataTrans = maskCanvasContexttrans.getImageData(imgX, imgY, 1, 1);
// console.log('at the time' + pixelData.data[0])
// debugger;
var annotations = $scope.getAnnotationForTransparencyBox(pixelData, pixelDataTrans, $scope);
if ($('#speechBubble').length > 0)
$('#speechBubble').remove();
if ($('#speechBubbleTrns').length > 0) {
$('#speechBubbleTrns').remove();
createSpeechBubbleOnTransparencyBox(evt, annotations.annotationT1, annotations.annotationT2, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left + 5, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top - 50)
}
else
createSpeechBubbleOnTransparencyBox(evt, annotations.annotationT1, annotations.annotationT2, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left + 5, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top - 50)
}
tempMaskImg.src = "http://localhost/AIAHtml/" + tranparencyMaskImgSrc;
}
else {
var clickedCanvasMaskId = 'imageCanvas' + clickedBodyRegion + '_mci';
var maskCanvas = document.getElementById(clickedCanvasMaskId);
var canvasContextForRGB = maskCanvas.getContext("2d");
//transparecncy canvas
var maskCanvasTransId = 'transparencyTempCanvasMask_' + clickedBodyRegion + '_mci';
var maskCanvastrans = document.getElementById(maskCanvasTransId);
var maskCanvasContexttrans = maskCanvastrans.getContext("2d");
pixelData = canvasContextForRGB.getImageData(Math.round(actulalX - x), Math.round(actualY - y), 1, 1);
pixelDataTrans = maskCanvasContexttrans.getImageData(Math.round(actulalX - x), Math.round(actualY - y), 1, 1);
var annotations = $scope.getAnnotationForTransparencyBox(pixelData, pixelDataTrans, $scope);
//var annotations = $scope.getAnnotationForTransparencyBox(pixelData, pixelDataTrans, $scope);
if ($('#speechBubble').length > 0)
$('#speechBubble').remove();
if ($('#speechBubbleTrns').length > 0) {
$('#speechBubbleTrns').remove();
$scope.createSpeechBubbleOnTransparencyBox(evt, annotations.annotationT1, annotations.annotationT2, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left + 5, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top - 50)
}
else
$scope.createSpeechBubbleOnTransparencyBox(evt, annotations.annotationT1, annotations.annotationT2, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left + 5, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top - 50)
}
//debugger;
}
function clearTransCanvas() {
var tCanvas = document.getElementById('transparencyCanvas');
if (tCanvas != null) {
var tCanvasContext = tCanvas.getContext('2d');
tCanvasContext.clearRect(0, 0, parseInt(tCanvas.style.width), parseInt(tCanvas.style.height));
}
}
$scope.getAnnotationForTransparencyBox = function (pixelData, pixelDataTrans, scope) {
console.log('hkhkdfhkhi' + pixelData.data[0])
pixelData.data[0] = pixelData.data[0] - 9;
pixelData.data[1] = pixelData.data[1] - 9;
pixelData.data[2] = pixelData.data[2] - 9;
//trans pixel data
pixelDataTrans.data[0] = pixelDataTrans.data[0] - 9;
pixelDataTrans.data[1] = pixelDataTrans.data[1] - 9;
pixelDataTrans.data[2] = pixelDataTrans.data[2] - 9;
var Red;
var Green;
var Blue;
var zero = "0";
if ((pixelData.data[0]).toString().length != 2) {
Red = zero.concat((pixelData.data[0]).toString())
}
else {
Red = (pixelData.data[0]).toString()
}
if ((pixelData.data[1]).toString().length != 2) {
Green = zero.concat((pixelData.data[1]).toString())
}
else {
Green = (pixelData.data[1]).toString()
}
if ((pixelData.data[2]).toString().length != 2) {
Blue = zero.concat((pixelData.data[2]).toString())
}
else {
Blue = (pixelData.data[2]).toString()
}
var RGBColor = (Red + Green + Blue);
var annotationText1 = $scope.GetAnnotationText(parseInt(RGBColor));
//get annotation for trans canavs
var RedTrans;
var GreenTrans;
var BlueTrans;
var zero = "0";
if ((pixelDataTrans.data[0]).toString().length != 2) {
RedTrans = zero.concat((pixelDataTrans.data[0]).toString())
}
else {
RedTrans = (pixelDataTrans.data[0]).toString()
}
if ((pixelDataTrans.data[1]).toString().length != 2) {
GreenTrans = zero.concat((pixelDataTrans.data[1]).toString())
}
else {
GreenTrans = (pixelDataTrans.data[1]).toString()
}
if ((pixelDataTrans.data[2]).toString().length != 2) {
BlueTrans = zero.concat((pixelDataTrans.data[2]).toString())
}
else {
BlueTrans = (pixelDataTrans.data[2]).toString()
}
var RGBColorTrans = (RedTrans + GreenTrans + BlueTrans);
var annotationText2 = $scope.GetAnnotationText(parseInt(RGBColorTrans));
return {
annotationT1: annotationText1,
annotationT2: annotationText2
}
}
$scope.onTransparencyChange = function (ev, ui) {
//debugger;
// alert('t change')
$scope.transNumber = ui.value;
var tCanvas = document.getElementById('transparencyCanvas');
var tCanvasContext = tCanvas.getContext('2d');
var tCanvasHeight = parseInt((tCanvas.style.height).replace('px', ''));
var tCanvasWidth = parseInt((tCanvas.style.width).replace('px', ''));
var tBoxStartX = parseInt((tCanvas.style.left).replace('px', ''));
var tBoxEndX = parseInt((tCanvas.style.left).replace('px', '')) + parseInt((tCanvas.style.width.replace('px', '')));
var tBoxStartY = parseInt((tCanvas.style.top).replace('px', ''));
var tBoxEndY = parseInt((tCanvas.style.top).replace('px', '')) + parseInt((tCanvas.style.height).replace('px', ''));
var transparencyBoxBottom = parseInt(tBoxStartY) + parseInt(tCanvasHeight);
var transparencyBoxRight = parseInt(tBoxStartX) + parseInt(tCanvasWidth);
//var scope = angular.element(document.getElementById("DAView")).scope();
//scope.$apply(function () {
var arr = [];
$scope.transparencyChangeCounter++;
//before changing the transparency of first canvas, hold the orignal canvas data on temp canvas
//put original data on transcanvas so that it can be used to change transparency properly
var tempCanavs = document.getElementById('tempCanvas');
var tempCanvasContext = tempCanavs.getContext('2d');
var originalTransparencyData = tempCanvasContext.getImageData(0, 0, $scope.transparencyCanvasWidth, $scope.transparencyCanvasHeight);
var ctx = document.getElementById('transparencyCanvas').getContext('2d');
ctx.putImageData(originalTransparencyData, 0, 0);
var BodyRegionDictionary = $scope.BodyRegionCordinatesData;
$scope.IncludedBodyRegions = [];
var counter = 0;
$.each(BodyRegionDictionary, function (index, value) {
var bodyRegionRight = parseInt(value.X) + parseInt(value.Width);
var bodyRegionBottom = parseInt(value.Y) + parseInt(value.Height);
if (tBoxStartX <= bodyRegionRight && value.X <= transparencyBoxRight && tBoxStartY <= bodyRegionBottom && value.Y <= transparencyBoxBottom) {
$scope.loadTransparencyImage(value.bodyRegionId, value.Height, value.Width, value.X, value.Y, value.IsMirror, $scope.TransparencyBoxStartX, $scope.TransparencyEndX, $scope.TransparencyBoxStartY, $scope.TransparencyBoxEndY, $scope, false, true);
}
});
// });
}
$scope.CloseTransparencyBox = function () {
var tBox = document.getElementById('transparencyCanvas');
// debugger;
// alert('mouseDown is called');
if (tBox != null) {
tBox.parentNode.removeChild(tBox)
var elements = document.getElementsByClassName('ui-icon ui-icon-gripsmall-diagonal-se');
while (elements.length > 0) {
elements[0].parentNode.removeChild(elements[0]);
}
//var txtTransparencyChange = document.getElementById("txtTransparencyChange");
//txtTransparencyChange.value = 0;
// document.getElementById('txtLayerNumber').value = 0;
// debugger;
$('#layerChangeSlider').slider("option", "value", parseInt($scope.totalLayers) - parseInt($scope.currentLayerNumber));
$("#txtlayerNumber").val(parseInt($scope.currentLayerNumber));
if (document.getElementById('tempCanvas') != null) {
$('#tempCanvas').remove();
}
if ($('#speechBubbleTrns').length > 0) {
$('#speechBubbleTrns').remove();
}
//var scope = angular.element(document.getElementById("DAView")).scope();
//scope.$apply(function () {
// $scope.layerNumber = 0;
$scope.isTransparencyActivated = false;
//})
var tempCanvases = $("canvas[id*='transparencyTempCanvas']");
for (var i = 0; i < tempCanvases.length; i++) {
tempCanvases[i].remove();
}
$('.ui-wrapper').remove();
//$("canvas[name*='transparencyTempCanvas']").nextUntil($("canvas[name*='transparencyTempCanvas']"))
//.remove();
}
$('#transparencyScale').css('visibility', 'hidden');
$scope.isTransparencyActivated = false;
// document.getElementById('btnTranparency').className = 't-transparency'
$('#btnTranparency').removeClass('tButtonActive');
$('#btnTranparency').addClass('btn-black');
$('#btnIdentity').removeClass('btn-black');
$('#btnIdentity').addClass('btn-primary');
document.getElementById('btnTranparency').removeEventListener("click", $scope.createTransparencyBox);
}
$scope.createSpeechBubbleOnTransparencyBox = function (event, text1, text2, x, y) {
$('#canvasDiv').css('cursor', 'pointer');
$('
'
+ '
'
+ '
' + text1 + '
' + text2 + '
'
//+'
+ '
').appendTo('#canvasDiv');
$('#speechBubbleTrns').on('click', '.BubbleCloseBtn', function (e) {
$('#speechBubbleTrns').css('display', 'none');
});
$('#canvasDiv').attr("data-bubbleid", "speechBubble")
};
function positionTooltip(event, x, y) {
// alert('positionTooltip')
x = 100,
y = 200,
$('div.speech-bubble').css({
'position': 'absolute', 'top': x, 'left': y, 'background-color': '#f8f8f8',
'border': '2px solid #c8c8c8', 'width': '150px', 'height': '50px'
});
$('.arrow').css({
'border-style': 'solid',
'position': 'absolute'
});
$('.bottom').css({
'border-color': '#c8c8c8 transparent transparent transparent',
'border-width': ' 8px 8px 0px 8px',
'bottom': -'8px'
})
};
$scope.OnIdentityClick = function () {
// $('#btnIdentity').addClass('btn-primary');
if ($scope.isTransparencyActivated == true) {
$scope.isTransparencyActivated = false;
var canvasDiv = document.getElementById('canvasDiv');
canvasDiv.removeEventListener("mousedown", mouseDownListener);
canvasDiv.removeEventListener("mousemove", mouseMoveListener);
canvasDiv.removeEventListener("mouseup", mouseUpListener)
$('#btnTranparency').removeClass('tButtonActive');
$('#btnTranparency').addClass('btn-black');
}
}
$scope.Zoom = function () {
$scope.flushCanvas();
if ($scope.zoomInOut == 25) {
$scope.zoomInOut = 75;
}
else {
$scope.zoomInOut = 25;
}
$scope.CalculateImageCordinates($scope.viewOrientationId);
}
$scope.flushCanvas = function () {
angular.forEach($scope.ColoredImageSRC, function (value, key) {
var id;
if (value.haveMirror == 'true') {
id = 'imageCanvas' + value.bodyRegionId + '_MR';
}
else {
id = 'imageCanvas' + value.bodyRegionId;
}
var canvas = document.getElementById(id);
document.getElementById('canvasDiv').removeChild(canvas);
});
}
$scope.enableHighlight = function () {
$scope.isHighLight = true;
// alert('enableHighlight is called');
$scope.highLightBody();
}
$scope.highLightBody = function () {
// alert('highlight body is called');
angular.forEach($scope.ColoredImageSRC, function (value, key) {
var id;
if (value.haveMirror == 'true') {
id = 'imageCanvas' + value.bodyRegionId + '_MR';
}
else {
id = 'imageCanvas' + value.bodyRegionId;
}
var imageCanvas = document.getElementById(id);
var context_gray = imageCanvas.getContext('2d');
var dataURL = imageCanvas.toDataURL();
var img = new Image();
img.src = dataURL;
var DAData = new BitmapData(img.width, img.height);
DAData.draw(img);
var RED = 0.3086; // luminance contrast value for red
var GREEN = 0.694; // luminance contrast value for green
var BLUE = 0.0820; // luminance contrast value for blue
var RGB = [RED, GREEN, BLUE, 0, 0];
var RGB2 = [RED, GREEN, BLUE, 0, 0];
var RGB3 = [RED, GREEN, BLUE, 0, 0];
var ALPHA = [0, 0, 0, 1, 0];
var rgbPx = RGB.concat(RGB2);
var rgbPx2 = rgbPx.concat(RGB3);
var matrix = rgbPx2.concat(ALPHA);
var zeroPoint = new Point();
var grayScale = new ColorMatrixFilter(matrix);
DAData.applyFilter(DAData, DAData.rect, zeroPoint, grayScale);
context_gray.putImageData(DAData.data, 0, 0)
});
}
$scope.OnGenderChange = function (event) {
//use $scope.correspondingBodyViewIds for getting correspnding viewid
// alert('gender changed= ' + event.currentTarget.attributes[1].value)
// $(".enableGender li").removeClass("active");
// $(event.currentTarget.attributes[2].value).parent().addClass("active");
var viewname= localStorage.getItem("currentViewTitle")
var currentBodyViewId = $scope.correspondingBodyViewIds[$scope.voId];
if ((event.currentTarget.attributes[1].value == 'Male') && (localStorage.getItem("genderId") == 'Female')) {
localStorage.setItem("genderId", 'Male');
$scope.loadSelectedBodyView(currentBodyViewId);
$('#daImagePanel')[0].childNodes[0].childNodes[0].innerHTML = localStorage.getItem("currentViewTitle").replace('Female','Male');
}
else if ((event.currentTarget.attributes[1].value == 'Female') && (localStorage.getItem("genderId") == 'Male')) {
localStorage.setItem("genderId", 'Female');
$scope.loadSelectedBodyView(currentBodyViewId)
$('#daImagePanel')[0].childNodes[0].childNodes[0].innerHTML = localStorage.getItem("currentViewTitle").replace('Male','Female');
}
}
$scope.loadSelectedBodyView = function (currentBodyViewId) {
$scope.voId = currentBodyViewId;
var layerJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_layer_' + currentBodyViewId + '.json';
DataService.getJson(layerJsonPath)
.then(
function (result) {
//debugger;
$scope.BodyLayerData = result;
$scope.isBodylayerdataLoaded = true;
//load json for annotations
// $http({ method: 'GET', url: '~/../content/data/json/da_dat_tm_sg_1.json' }).success(function (data) {
var termJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json';
DataService.getAnotherJson(termJsonPath)
.then(
function (result) {
$scope.TermNumberData = result;
var canDiv = document.getElementById('canvasDiv');
var canDivChildCount = canDiv.childElementCount;
if (canDivChildCount > 0) {
canDiv.innerHTML = '';
}
$scope.CalculateImageCordinates($scope.viewOrientationId);
},
function (error) {
// handle errors here
console.log(' $scope.TermNumberData= ' + error.statusText);
}
)
},
function (error) {
// handle errors here
console.log(' $scope.BodyLayerData= ' + error.statusText);
}
);
}
$scope.OnViewChange = function (event) {
$scope.layerNumber = 0;
// debugger;
var selectedViewId = $scope.bodyViews[event.currentTarget.attributes[1].value];
$scope.viewOrientationId = selectedViewId;
if (localStorage.getItem("genderId") == 'Male') {
if ($scope.voId != selectedViewId) {
if (selectedViewId == 5) {
$scope.voId = 9;
}
else if (selectedViewId == 6) {
$scope.voId = 10;
}
else
$scope.voId = selectedViewId;
$scope.loadSelectedBodyView($scope.voId);
};
//set selected view name as the title of jspanel
// $('#daImagePanel')[0].childNodes[0].childNodes[0].innerHTML = localStorage.getItem("genderId") +" "+ event.currentTarget.attributes[1].value;
}
else {
if (selectedViewId == 5) {
selectedViewId = 11;
}
else if (selectedViewId == 6) {
selectedViewId = 12;
}
else
selectedViewId = $scope.correspondingBodyViewIds[selectedViewId];;
if ($scope.voId != selectedViewId) {
$scope.voId = selectedViewId;
$scope.loadSelectedBodyView($scope.voId);
};
// $('#daImagePanel')[0].childNodes[0].childNodes[0].innerHTML = localStorage.getItem("genderId") + " " + $scope.bodyViews[event.currentTarget.attributes[1].value;
}
$('#daImagePanel')[0].childNodes[0].childNodes[0].innerHTML = localStorage.getItem("genderId") +" "+ event.currentTarget.attributes[1].value;
localStorage.setItem("currentViewTitle", localStorage.getItem("genderId") + " " + event.currentTarget.attributes[1].value);
}
//Annotation tool event lsitener
$scope.$on('annotationToolEvent', function (event, data) {
console.log('annotation window opend');
//draw new canvas on canavs div to draw/paint on that
//debugger;
if (document.getElementById('paintCanvas') == null) {
var paintCanvas = document.createElement('canvas');
paintCanvas.id = 'paintCanvas';
paintCanvas.height = parseInt(document.getElementById('canvasDiv').style.height);// - 5;
paintCanvas.style.width = '2277px';//(this is width of canavses of arm+thorax+arm+40)
paintCanvas.style.position = "absolute";
paintCanvas.style.left = 0 + 'px';
paintCanvas.style.top = 0 + 'px';
// paintCanvas.className = 'col-lg-12';
paintCanvas.style.backgroundColor = 'yellow';
paintCanvas.style.zIndex = '1100'
//this is to get annoatation while annotation window is open
paintCanvas.addEventListener('click', OnPaintCanvasClick);
paintCanvas.addEventListener('mousedown', OnPaintCanvasMouseDown, false)
paintCanvas.addEventListener('mouseup', OnPaintCanvasMouseUp, false)
document.getElementById('canvasDiv').appendChild(paintCanvas);
$scope.paintCanvasContext = document.getElementById('paintCanvas').getContext('2d');
}
});
function OnPaintCanvasClick(event) {
if ($rootScope.isIdetifyClicked == true) {
// alert('show annotation')
}
}
$scope.mousePressed = false;
$scope.lastX; $scope.lastY;
var ctx;
function OnPaintCanvasMouseDown(event) {
if ($rootScope.isDrawingToolSelected == true) {
//var mousePos = $scope.getMousePos(event)
//var canvasDiv = document.getElementById('canvasDiv');
//var verticalScrollPosition = canvasDiv.scrollTop;
//var horizontlScrollPosition = canvasDiv.scrollLeft;
//$rootScope.PaintCanvasMousedownListener($scope.paintCanvasContext,mousePos.x, mousePos.y)
var mousePos = $scope.getMousePos(event)
$scope.mousePressed = true;
$rootScope.Draw(mousePos.x, mousePos.y, false, $scope.paintCanvasContext);
if ($rootScope.isAnnotationWindowClose) {
document.getElementById('paintCanvas').removeEventListener('mousemove', OnPaintCanvasMouseMove, false);
}
else
document.getElementById('paintCanvas').addEventListener('mousemove', OnPaintCanvasMouseMove, false)
}
//ctx.moveTo(50, 50);
}
function OnPaintCanvasMouseUp(event) {
if ($rootScope.isDrawingToolSelected == true) {
//$rootScope.paint = false;
$scope.mousePressed = false;
//// $rootScope.Redraw();
document.getElementById('paintCanvas').removeEventListener('mousemove', OnPaintCanvasMouseMove, false);
}
}
function OnPaintCanvasMouseMove(event) {
if ($rootScope.isDrawingToolSelected == true) {
console.log('moving');
//var mousePos = $scope.getMousePos(event);
//var canvasDiv = document.getElementById('canvasDiv');
//var verticalScrollPosition = canvasDiv.scrollTop;
//var horizontlScrollPosition = canvasDiv.scrollLeft;
//$rootScope.PaintCanvasMousemoveListener($scope.paintCanvasContext, mousePos.x, mousePos.y)
if ($scope.mousePressed) {
var mousePos = $scope.getMousePos(event)
$rootScope.Draw(mousePos.x, mousePos.y, true,$scope.paintCanvasContext);
}
}
}
// $scope.Draw=function(x, y, isDown) {
// if (isDown) {
// $scope.paintCanvasContext.beginPath();
// $scope.paintCanvasContext.strokeStyle = '#000000';
// $scope.paintCanvasContext.lineWidth = 1//$('#selWidth').val();
// $scope.paintCanvasContext.lineJoin = "round";
// $scope.paintCanvasContext.moveTo($scope.lastX, $scope.lastY);
// $scope.paintCanvasContext.lineTo(x, y);
// $scope.paintCanvasContext.closePath();
// $scope.paintCanvasContext.stroke();
// }
// $scope.lastX = x; $scope.lastY = y;
//}
}]
);