ImageDataController.js 10.3 KB
'use strict';
var AIA = angular.module('AIA', []);


AIA.controller("ImageDataController", ["$rootScope", "ImageService","DataService",
    function ($rootScope, ImageService, DataService) {

        $rootScope.JsonDataArray = [];
        $rootScope.imageDataArray = [];

        $rootScope.normalImageData = [];
        $rootScope.grayImageData = [];
        $rootScope.maskImageData = [];

        $rootScope.sendImageData = function () {
            {
                var imageData=[];
                //imageData = getImageData();
                //console.log('image data is created ' + ImageData)

                //1.
                $rootScope.getdata();

                //2.
                //$rootScope.processLayerData();

              
            }
        }

        $rootScope.getdata = function () {
            {
                var layerJsonPath = '/Content/da_dat_layer_1.json';

                DataService.getJson(layerJsonPath)
                .then(
                 function (result) {
                    //debugger;
                    $rootScope.BodyLayerData = result;
                    console.log($rootScope.BodyLayerData);

                    angular.forEach($rootScope.BodyLayerData, function (value, key) {
                       // debugger;
                        angular.forEach(value.DataLayer, function (value1,key1) {

                            if (value1._LayerNumber == 50)
                            {
                                alert('come in 50 layer')
                                angular.forEach(value1.BodyRegion, function (value2,key2) {
                                 //   debugger;
                                    if (value2._BodyRegionId == "1") {
                                        $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "676", "width": "474" });
                                    }
                                    else if (value2._BodyRegionId == "2") {
                                        $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "844", "width": "756" });
                                    }
                                    else if (value2._BodyRegionId == "3") {
                                        $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "932", "width": "948" });
                                    }
                                    else if (value2._BodyRegionId == "4") {
                                        $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "934", "width": "576" });
                                    }
                                    else if (value2._BodyRegionId == "5") {
                                        $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "944", "width": "576" });
                                    }
                                    else {
                                        $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "1504", "width": "1140" });
                                    }
                                })
                            }
                            else
                            {
                                console.log('50 layer not found');
                            }

                            for (var i = 0; i <= $rootScope.JsonDataArray.length - 1; i++) {
                                var srcs = "Content/images/DA/75/body-views/1/layers/50/" + $rootScope.JsonDataArray[i].bodyRegionID + "/" + $rootScope.JsonDataArray[i].imageName + "";
                                $("#scream").attr("src", srcs);
                                $("#scream").attr("width", $rootScope.JsonDataArray[i].width);
                                $("#scream").attr("height", $rootScope.JsonDataArray[i].height);
                                var c = document.getElementById("myCanvas");
                                var ctx = c.getContext("2d");
                                var img = document.getElementById("scream");
                                ctx.drawImage(img, 0, 0, $rootScope.JsonDataArray[i].width, $rootScope.JsonDataArray[i].height);
                                var imgData = ctx.getImageData(0, 0, $rootScope.JsonDataArray[i].width, $rootScope.JsonDataArray[i].height);
                                $rootScope.normalImageData.push({ "DataForNormalImage": imgData.data, "NormalImageName": $rootScope.JsonDataArray[i].imageName, "NormalImageBodyRegionID": $rootScope.JsonDataArray[i].bodyRegionID });
                            }
                            for (var i = 0; i <= $rootScope.JsonDataArray.length - 1; i++) {
                                var mciImage = $rootScope.JsonDataArray[i].imageName.split(".");
                                var mciImageName = mciImage[0] + "_mci" + ".jpg";
                                var srcs = "content/images/DA/75/body-views/1/layers/50/" + $rootScope.JsonDataArray[i].bodyRegionID + "/" + mciImageName + "";
                                $("#scream").attr("src", srcs);
                                $("#scream").attr("width", $rootScope.JsonDataArray[i].width);
                                $("#scream").attr("height", $rootScope.JsonDataArray[i].height);
                                var c = document.getElementById("myCanvas");
                                var ctx = c.getContext("2d");
                                var img = document.getElementById("scream");
                                ctx.drawImage(img, 0, 0, $rootScope.JsonDataArray[i].width, $rootScope.JsonDataArray[i].height);
                                var imgData = ctx.getImageData(0, 0, $rootScope.JsonDataArray[i].width, $rootScope.JsonDataArray[i].height);
                                $rootScope.maskImageData.push({ "DataForMciImage": imgData.data, "MciImageName": $rootScope.JsonDataArray[i].imageName, "MciImageBodyRegionID": $rootScope.JsonDataArray[i].bodyRegionID });

                                ImageService.sendImageDataArray($rootScope.maskImageData);
                            }
                            for (var i = 0; i <= $rootScope.JsonDataArray.length - 1; i++) {
                                var srcs = "content/images/DA/75/body-views/1/layers/50/" + $rootScope.JsonDataArray[i].bodyRegionID + "/";
                                $("#scream").attr("src", srcs);
                                $("#scream").attr("width", $rootScope.JsonDataArray[i].width);
                                $("#scream").attr("height",$rootScope.JsonDataArray[i].height);
                                var c = document.getElementById("myCanvas");
                                var ctx = c.getContext("2d");
                                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 grayScale = new ColorMatrixFilter(matrix);
                                $rootScope.grayImageData.push({ "DataForGrayImage": grayScale.matrix, "GrayImageName": $rootScope.JsonDataArray[i].imageName, "GrayImageBodyRegionID": $rootScope.JsonDataArray[i].bodyRegionID });

                            }
                            console.log($rootScope.imageDataArray)

                           

                        })
                    })
                 },

        function (error) {
            // handle errors here
            console.log(' $rootScope.BodyLayerData= ' + error.statusText);
        }
          );             
        }
        }

        $rootScope.processLayerData= function()
        {
            
            angular.forEach($rootScope.BodyLayerData, function (value, key) {
                angular.forEach(value.DataLayer, function (key1, value1) {
                    if (value1._LayerNumber == 50) {
                        angular.forEach(value1.BodyRegion, function (key2, value2) {
                            if (value2._BodyRegionId == "1") {
                                $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "676", "width": "474" });
                            }
                            else if (value2._BodyRegionId == "2") {
                                $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "844", "width": "756" });
                            }
                            else if (value2._BodyRegionId == "3") {
                                $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "932", "width": "948" });
                            }
                            else if (value2._BodyRegionId == "4") {
                                $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "934", "width": "576" });
                            }
                            else if (value2._BodyRegionId == "5") {
                                $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "944", "width": "576" });
                            }
                            else {
                                $rootScope.JsonDataArray.push({ "imageName": value2.Image._ImageName, "bodyRegionID": value2._BodyRegionId, "height": "1504", "width": "1140" });
                            }
                        })
                    }
                })
            })
        }
        
    }]);