示例#1
0
        public override void SetAlpha(bool isVisible, OnTaskComplete onTask = null)
        {
            float to = 0f, from = 0f;

            // Desaparecer o aparecer elemento dependiendo de su estado Focus
            float transparency     = (matBag.GetFloat("Boolean_DAFC24A6") == 1f) ? 1f : focusTransparency;
            float currTransparency = matBag.GetVector("Vector2_B5455978").x;

            to   = (isVisible) ? transparency : 0f;
            from = (isVisible) ? 0f : currTransparency;

            LeanTween.value(this.gameObject, (f) =>
            {
                // Cambiar alpha
                matBag.SetVector("Vector2_B5455978", new Vector4(f, 0f, 0f, 0f));
            }, from, to, TimeTransition).setOnComplete(() =>
            {
                IsShow = isVisible;

                if (onTask != null)
                {
                    onTask();
                }
            });
        }
        public override void SetAlpha(bool isVisible, OnTaskComplete onTask = null)
        {
            float to = 0f, from = 0f;

            switch (ModeView)
            {
            case ModeBagView.Normal:
            {
                to   = (isVisible) ? 0f : 1f;
                from = (isVisible) ? 1f : 0f;

                LeanTween.value(this.gameObject, (f) =>
                    {
                        // Cambiar alpha
                        matBag.SetFloat("Vector1_FAB99759", f);
                    }, from, to, TimeTransition).setOnComplete(() =>
                    {
                        IsShow = isVisible;

                        if (onTask != null)
                        {
                            onTask();
                        }
                    });

                break;
            }

            case ModeBagView.Focus:
            {
                break;
            }
            }
        }
示例#3
0
        /// <summary>
        /// 初始化一个任务
        /// </summary>
        /// <param name="cfgFile">任务配置文件路径,如果已经初始化,则返回任务ID</param>
        /// <returns>返回任务对象</returns>
        public static Task InitTask(string cfgFile)
        {
            var fullPath = Snail.IO.PathUnity.GetFullPath(cfgFile);

            if (string.IsNullOrEmpty(fullPath))
            {
                return(null);
            }
            Task task = null;

            lock (LockObj)
            {
                if (!BufferTasks.ContainsKey(fullPath))
                {
                    task          = new Task(fullPath);
                    task.OnStart += (sender, e) =>
                    {
                        OnTaskRunning?.Invoke(task, new TaskEventArgs()
                        {
                            Task = task
                        });
                    };
                    task.OnStop += (sender, e) =>
                    {
                        OnTaskComplete?.Invoke(task, new TaskEventArgs()
                        {
                            Task = task
                        });
                    };
                    BufferTasks.Add(fullPath, task);
                }
            }
            return(BufferTasks[fullPath]);
        }
示例#4
0
        /// <summary>
        /// 初始化一个任务
        /// </summary>
        /// <param name="cfgFile">任务配置文件路径,如果已经初始化,则返回任务ID</param>
        /// <returns>返回任务对象</returns>
        public static Task InitTask(string cfgFile)
        {
            var fullPath = SnailCore.IO.PathUnity.GetFullPath(cfgFile);

            if (string.IsNullOrEmpty(fullPath))
            {
                throw new Exception("could not find the file with path:" + cfgFile);
            }
            Task task = null;

            lock (LockObj)
            {
                if (!BufferTasks.ContainsKey(fullPath))
                {
                    task = new Task(fullPath);
                    foreach (var kv in BufferTasks)
                    {
                        if (kv.Value.TaskId == task.TaskId)
                        {
                            throw new Exception(string.Format("任务id:{0},重复出现,请检查配置,并重新启动任务.", task.TaskId));
                        }
                    }
                    task.OnStart += (sender, e) =>
                    {
                        try
                        {
                            OnTaskRunning?.Invoke(sender, e);
                        }
                        catch (Exception ex)
                        {
                            LoggerProxy.Error(LogSource, "invoke OnTaskRunning failed.", ex);
                        }
                    };
                    task.OnStop += (sender, e) =>
                    {
                        try
                        {
                            OnTaskComplete?.Invoke(sender, e);
                        }
                        catch (Exception ex)
                        {
                            LoggerProxy.Error(LogSource, "invoke OnTaskComplete failed.", ex);
                        }
                    };
                    task.OnError += (sender, e) =>
                    {
                        try
                        {
                            OnTaskError?.Invoke(sender, e);
                        }
                        catch (Exception ex)
                        {
                            LoggerProxy.Error(LogSource, "invoke OnTaskError failed.", ex);
                        }
                    };
                    BufferTasks.Add(fullPath, task);
                }
            }
            return(BufferTasks[fullPath]);
        }
示例#5
0
 private void OnTaskCompleted()
 {
     ///rasie task begin evnet
     if (OnTaskComplete != null)
     {
         OnTaskComplete.Invoke(this, new QueueTaskEventArgs(this.CurrentJob));
     }
 }
示例#6
0
 public JobCNNClassify(GRasterLayer featureRasterLayer, GRasterLayer labelRasterLayer, int epochs, int model, int width, int height, int channel)
 {
     _t = new Thread(() => {
         ImageClassifyEnv env = new ImageClassifyEnv(featureRasterLayer, labelRasterLayer);
         CNN cnn = new CNN(new int[] { channel, width, height }, env.ActionNum);
         //training
         Summary = "模型训练中";
         for (int i = 0; i < epochs; i++)
         {
             int batchSize       = cnn.BatchSize;
             var(states, labels) = env.RandomEval(batchSize);
             double[][] inputX   = new double[batchSize][];
             for (int j = 0; j < batchSize; j++)
             {
                 inputX[j] = states[j];
             }
             double loss = cnn.Train(inputX, labels);
             Process     = (double)i / epochs;
         }
         //classify
         Summary = "分类应用中";
         IRasterLayerCursorTool pRasterLayerCursorTool = new GRasterLayerCursorTool();
         pRasterLayerCursorTool.Visit(featureRasterLayer);
         //GDI graph
         Bitmap classificationBitmap = new Bitmap(featureRasterLayer.XSize, featureRasterLayer.YSize);
         Graphics g = Graphics.FromImage(classificationBitmap);
         //
         int seed        = 0;
         int totalPixels = featureRasterLayer.XSize * featureRasterLayer.YSize;
         //应用dqn对图像分类
         for (int i = 0; i < featureRasterLayer.XSize; i++)
         {
             for (int j = 0; j < featureRasterLayer.YSize; j++)
             {
                 //get normalized input raw value
                 double[] normal = pRasterLayerCursorTool.PickNormalValue(i, j);
                 //}{debug
                 double[] action = cnn.Predict(normal);
                 //convert action to raw byte value
                 int gray = env.RandomSeedKeys[NP.Argmax(action)];
                 //后台绘制,报告进度
                 Color c          = Color.FromArgb(gray, gray, gray);
                 Pen p            = new Pen(c);
                 SolidBrush brush = new SolidBrush(c);
                 g.FillRectangle(brush, new Rectangle(i, j, 1, 1));
                 //report progress
                 Process = (double)(seed++) / totalPixels;
             }
         }
         //保存结果至tmp
         string fullFileName = Directory.GetCurrentDirectory() + @"\tmp\" + DateTime.Now.ToFileTimeUtc() + ".png";
         classificationBitmap.Save(fullFileName);
         //complete
         Summary  = "CNN训练分类完成";
         Complete = true;
         OnTaskComplete?.Invoke(Name, fullFileName);
     });
 }
        public override void Hide(OnTaskComplete onTask = null)
        {
            if (m_currModeView != ModeView)
            {
                return;
            }

            SetAlpha(false, onTask);
        }
示例#8
0
        protected virtual void NotifyCompleted()
        {
            if (State == TaskState.Completed)
            {
                if (OnTaskComplete != null)
                {
                    OnTaskComplete.Invoke(this);
                }

                CompleteWasNotified = true;
            }
        }
 /// <summary>
 /// DQN classify task
 /// </summary>
 /// <param name="featureRasterLayer"></param>
 /// <param name="labelRasterLayer"></param>
 /// <param name="epochs"></param>
 public JobDQNClassify(GRasterLayer featureRasterLayer, GRasterLayer labelRasterLayer, int epochs = 3000)
 {
     _t = new Thread(() =>
     {
         ImageClassifyEnv env = new ImageClassifyEnv(featureRasterLayer, labelRasterLayer);
         _dqn = new DQN(env);
         _dqn.SetParameters(epochs: epochs, gamma: _gamma);
         _dqn.OnLearningLossEventHandler += _dqn_OnLearningLossEventHandler;
         //training
         Summary = "模型训练中";
         _dqn.Learn();
         //classification
         Summary = "分类应用中";
         IRasterLayerCursorTool pRasterLayerCursorTool = new GRasterLayerCursorTool();
         pRasterLayerCursorTool.Visit(featureRasterLayer);
         Bitmap classificationBitmap = new Bitmap(featureRasterLayer.XSize, featureRasterLayer.YSize);
         Graphics g      = Graphics.FromImage(classificationBitmap);
         int seed        = 0;
         int totalPixels = featureRasterLayer.XSize * featureRasterLayer.YSize;
         for (int i = 0; i < featureRasterLayer.XSize; i++)
         {
             for (int j = 0; j < featureRasterLayer.YSize; j++)
             {
                 //get normalized input raw value
                 double[] normal = pRasterLayerCursorTool.PickNormalValue(i, j);
                 var(action, q)  = _dqn.ChooseAction(normal);
                 //convert action to raw byte value
                 int gray         = _dqn.ActionToRawValue(NP.Argmax(action));
                 Color c          = Color.FromArgb(gray, gray, gray);
                 Pen p            = new Pen(c);
                 SolidBrush brush = new SolidBrush(c);
                 g.FillRectangle(brush, new Rectangle(i, j, 1, 1));
                 //report progress
                 Process = (double)(seed++) / totalPixels;
             }
         }
         //save result
         string fullFileName = Directory.GetCurrentDirectory() + @"\tmp\" + DateTime.Now.ToFileTimeUtc() + ".png";
         classificationBitmap.Save(fullFileName);
         //complete
         Summary  = "DQN训练分类完成";
         Complete = true;
         OnTaskComplete?.Invoke(Name, fullFileName);
     });
 }
 public IJobRPCRectify(double[] a, double[] b, double[] c, double[] d, Dictionary <string, double> paramaters, List <string> rawBinRasterFullFilenames)
 {
     _t = new Thread(() =>
     {
         using (IRasterRPCTool pRasterRPCTool = new GRasterRPCTool(a, b, c, d, paramaters))
         {
             for (int i = 0; i < rawBinRasterFullFilenames.Count; i++)
             {
                 string rasterFilename    = rawBinRasterFullFilenames[i];
                 GRasterLayer rasterLayer = new GRasterLayer(rasterFilename);
                 Summary = string.Format("total:{1}/{2}, RPC rectify for {0} is in progress.... ", rasterLayer.Name, i + 1, rawBinRasterFullFilenames.Count);
                 pRasterRPCTool.Visit(rasterLayer);
                 pRasterRPCTool.DoRPCRectify();
                 Process = i / (double)rawBinRasterFullFilenames.Count;
             }
             OnTaskComplete?.Invoke(Name);
         }
     });
 }
示例#11
0
 public JobCOVRaster(GRasterBand target1band, GRasterBand target2band)
 {
     _t = new Thread(() => {
         IRasterBandCursorTool pRasterBandCursorTool1 = new GRasterBandCursorTool();
         IRasterBandCursorTool pRasterBandCursorTool2 = new GRasterBandCursorTool();
         pRasterBandCursorTool1.Visit(target1band);
         pRasterBandCursorTool2.Visit(target2band);
         //
         int seed        = 0;
         int totalPixels = target1band.Width * target1band.Height;
         Bitmap bitmap   = new Bitmap(target1band.Width, target1band.Height);
         Graphics g      = Graphics.FromImage(bitmap);
         //
         for (int i = 0; i < target1band.Width; i++)
         {
             for (int j = 0; j < target1band.Height; j++)
             {
                 double[] raw1 = pRasterBandCursorTool1.PickRangeRawValue(i, j, 3, 3);
                 double[] raw2 = pRasterBandCursorTool2.PickRangeRawValue(i, j, 3, 3);
                 double cov    = ConvarianceIndex.CalcuteConvarianceIndex(raw1, raw2);
                 //拉伸-1 - 1
                 int gray         = Convert.ToInt32((cov + 1.0) * 20);
                 Color c          = Color.FromArgb(gray, gray, gray);
                 Pen p            = new Pen(c);
                 SolidBrush brush = new SolidBrush(c);
                 g.FillRectangle(brush, new Rectangle(i, j, 1, 1));
                 Process = (double)(seed++) / totalPixels;
             }
         }
         //save result
         string fullFileName = Directory.GetCurrentDirectory() + @"\tmp\" + DateTime.Now.ToFileTimeUtc() + ".png";
         bitmap.Save(fullFileName);
         //
         Summary  = "计算完成";
         Complete = true;
         OnTaskComplete?.Invoke(Name, fullFileName);
     });
 }
示例#12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="fullFilename"></param>
 public JobReadRaster(string fullFilename)
 {
     _t = new Thread(() =>
     {
         Dictionary <string, Bitmap2> dict = new Dictionary <string, Bitmap2>();
         string name = Path.GetFileNameWithoutExtension(fullFilename);
         GRasterLayer rasterLayer = new GRasterLayer(fullFilename);
         //reading
         Summary = "数据读取中";
         for (int i = 0; i < rasterLayer.BandCount; i++)
         {
             GRasterBand band    = rasterLayer.BandCollection[i];
             band.BandName       = name + "_band_" + i;
             Bitmap2 bmp2        = new Bitmap2(bmp: band.GrayscaleImage, name: band.BandName, gdalBand: band, gdalLayer: rasterLayer);
             dict[band.BandName] = bmp2;
             Process             = (double)(i + 1) / rasterLayer.BandCount;
         }
         //read complete
         Summary  = "读取完毕";
         Complete = true;
         OnTaskComplete?.Invoke(Name, name, dict, rasterLayer);
     });
 }
示例#13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="treeCount"></param>
 /// <param name="fullFilename"></param>
 /// <param name="rasterLayer"></param>
 public JobRFClassify(int treeCount, string fullFilename, GRasterLayer rasterLayer)
 {
     _t = new Thread(() =>
     {
         RF rf = new RF(treeCount);
         //training
         Summary = "随机森林训练中";
         using (StreamReader sr = new StreamReader(fullFilename))
         {
             List <List <double> > inputList = new List <List <double> >();
             List <int> outputList           = new List <int>();
             string text = sr.ReadLine().Replace("\t", ",");
             do
             {
                 string[] rawdatas = text.Split(',');
                 outputList.Add(Convert.ToInt32(rawdatas.Last()));
                 List <double> inputItem = new List <double>();
                 for (int i = 0; i < rawdatas.Length - 1; i++)
                 {
                     inputItem.Add(Convert.ToDouble(rawdatas[i]));
                 }
                 inputList.Add(inputItem);
                 text = sr.ReadLine();
             } while (text != null);
             double[][] inputs = new double[inputList.Count][];
             int[] outputs     = outputList.ToArray();
             for (int i = 0; i < inputList.Count; i++)
             {
                 inputs[i] = inputList[i].ToArray();
             }
             rf.Train(inputs, outputs);
         }
         //image classify
         Summary = "分类应用中";
         IRasterLayerCursorTool pRasterLayerCursorTool = new GRasterLayerCursorTool();
         pRasterLayerCursorTool.Visit(rasterLayer);
         //GDI graph
         Bitmap classificationBitmap = new Bitmap(rasterLayer.XSize, rasterLayer.YSize);
         Graphics g = Graphics.FromImage(classificationBitmap);
         //
         int seed        = 0;
         int totalPixels = rasterLayer.XSize * rasterLayer.YSize;
         Process         = 0.0;
         //应用dqn对图像分类
         for (int i = 0; i < rasterLayer.XSize; i++)
         {
             for (int j = 0; j < rasterLayer.YSize; j++)
             {
                 //get normalized input raw value
                 double[] raw      = pRasterLayerCursorTool.PickRawValue(i, j);
                 double[][] inputs = new double[1][];
                 inputs[0]         = raw;
                 //}{debug
                 int[] ouputs = rf.Predict(inputs);
                 int gray     = ouputs[0];
                 //convert action to raw byte value
                 Color c          = Color.FromArgb(gray, gray, gray);
                 Pen p            = new Pen(c);
                 SolidBrush brush = new SolidBrush(c);
                 g.FillRectangle(brush, new Rectangle(i, j, 1, 1));
                 //report progress
                 Process = (double)seed++ / totalPixels;
             }
         }
         //保存结果至tmp
         string fullFileName = Directory.GetCurrentDirectory() + @"\tmp\" + DateTime.Now.ToFileTimeUtc() + ".png";
         classificationBitmap.Save(fullFileName);
         //rf complete
         Summary  = "RF训练分类完成";
         Complete = true;
         OnTaskComplete?.Invoke(Name, fullFileName);
     });
 }
示例#14
0
 public override void Hide(OnTaskComplete onTask = null)
 {
     SetAlpha(false);
 }
 public virtual void Hide(OnTaskComplete onTask = null)
 {
 }
 public virtual void SetAlpha(bool isVisible, OnTaskComplete onTask = null)
 {
 }