Beispiel #1
0
        public virtual void MakeAlgorithm(ref Cl3DModel p_Model)
        {
            if (p_Model == null)
            {
                throw new Exception("NULL model");
            }

            ClInformationSender.SendInformation("-> In progress: " + m_sAlgorithmName + " for: " + p_Model.ModelFileName, ClInformationSender.eInformationType.eTextInternal);
            p_Model.ResetVisitedPoints();
            DateTime start = DateTime.Now;

            m_AlgorithmTime = TimeSpan.Zero;

            Algorithm(ref p_Model);

            DateTime stop = DateTime.Now;

            m_AlgorithmTime        = (stop - start);
            p_Model.IsModelChanged = true;
            ClInformationSender.SendInformation("-] Finished: " + m_sAlgorithmName + " for: " + p_Model.ModelFileName + " [time: " + m_AlgorithmTime.TotalSeconds + " sec.]", ClInformationSender.eInformationType.eTextInternal);

            string fullAlgorithmAdditionalData = GetAlgorithmFullPath() + "\n";

            foreach (KeyValuePair <string, string> prop in GetProperitis())
            {
                fullAlgorithmAdditionalData += "\t" + prop.Key + " -> " + prop.Value + "\n";
            }
            p_Model.AddDoneProcessingAlgorithm(fullAlgorithmAdditionalData);
        }
        public virtual void NewInformation(string p_sInformation, ClInformationSender.eInformationType p_eType)
        {
            if (p_eType == ClInformationSender.eInformationType.eStartProcessing)
            {
            #if RENDER_1
                ClRender.getInstance().StopRendering();
            #endif
            }
            else if (p_eType == ClInformationSender.eInformationType.eStopProcessing)
            {
            #if RENDER_1
             //   ClRender.getInstance().StartRendering();
            #endif
            }

            m_form.Invoke(d, new object[] { p_sInformation, p_eType });
        }
        static private void RunAlgorithmsForModel()
        {
            try
            {
                if (m_bIsRunning)
                {
                    return;
                }

                ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStartProcessing);

                m_bIsRunning = true;
                DateTime start = DateTime.Now;
                foreach (IFaceAlgorithm alg in m_lAlgorithmsList)
                {
                    alg.MakeAlgorithm(ref m_sProcessedModel);
                }
                DateTime stop = DateTime.Now;

                ClInformationSender.SendInformation("DONE in: " + (stop - start).TotalSeconds + " Sec.", ClInformationSender.eInformationType.eTextInternal);

                string algTimes = "";
                foreach (IFaceAlgorithm alg in m_lAlgorithmsList)
                {
                    algTimes += alg.GetAlgorithmFullPath() + " time[ms]:\t" + alg.GetComputationTime().TotalMilliseconds + "\n";
                }

                ClInformationSender.SendInformation(algTimes, ClInformationSender.eInformationType.eDebugText);
                ClInformationSender.SendInformation(algTimes, ClInformationSender.eInformationType.eStopProcessing);
                m_bIsRunning = false;
            }
            catch (ThreadAbortException)
            {
                ClInformationSender.SendInformation("Processing Interrupted", ClInformationSender.eInformationType.eTextInternal);
                ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStopProcessing);
                m_bIsRunning = false;
            }
            catch (Exception e)
            {
                ClInformationSender.SendInformation("ERROR:\n" + e.ToString(), ClInformationSender.eInformationType.eError);
                ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStopProcessing);
                m_bIsRunning = false;
            }
        }
        static public void ResetFasade()
        {
            m_sProcessedModel = null;
            m_bIsRunning      = false;
            m_lAlgorithmsList = null;
            m_lFilesList.Clear();
            m_sTestDirectory = @"c:\";

            if (m_sProcessingThread != null)
            {
                if (m_sProcessingThread.IsAlive)
                {
                    m_sProcessingThread.Abort();
                }
                while (m_sProcessingThread.ThreadState != ThreadState.AbortRequested &&
                       m_sProcessingThread.ThreadState != ThreadState.Stopped)
                {
                }
                m_sProcessingThread = null;
                ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStopProcessing);
            }
        }
        public virtual void NewInformation(string p_sInformation, ClInformationSender.eInformationType p_eType)
        {
            if (p_eType != ClInformationSender.eInformationType.eNewAlgorithm)
                return;

            string[] nodes = p_sInformation.Split('\\');
            System.Windows.Forms.TreeNode currentNode = null;
            bool firstSetUp = true;

            for(int i=0; i<nodes.Length; i++)
            {
                System.Windows.Forms.TreeNode node = new System.Windows.Forms.TreeNode();
                node.Text = nodes[i];
                node.Name = nodes[i];

                System.Windows.Forms.TreeNode[] finded;
                if(firstSetUp)
                    finded = m_tree.Nodes.Find(nodes[i], false);
                else
                    finded = currentNode.Nodes.Find(nodes[i],false);

                if (finded.Length == 1)
                {
                    currentNode = finded[0];
                    firstSetUp = false;
                }
                else
                {
                    if (firstSetUp)
                    {
                        m_tree.Nodes.Add(node);
                        firstSetUp = false;
                    }
                    else
                        currentNode.Nodes.Add(node);
                    currentNode = node;
                }
            }
        }
        public void UpdateUI(string p_sInfo, ClInformationSender.eInformationType p_eType)
        {
            if (p_eType == ClInformationSender.eInformationType.eError || p_eType == ClInformationSender.eInformationType.eDebugText || p_eType == ClInformationSender.eInformationType.eTextInternal || p_eType == ClInformationSender.eInformationType.eTextExternal)
            {
                this.DebugTextBox.Text += "\n-> "+p_sInfo;
            }
            if (p_eType == ClInformationSender.eInformationType.eError)
            {
                MessageBox.Show(p_sInfo, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (p_eType == ClInformationSender.eInformationType.eTextExternal)
            {
                this.toolStripStatusLabel1.Text = p_sInfo;
            }
            if (p_eType == ClInformationSender.eInformationType.eTextInternal)
            {
                this.toolStripStatusLabel2.Text = p_sInfo;
            }
            if (p_eType == ClInformationSender.eInformationType.eProgress)
            {
                int proc = Convert.ToInt32(p_sInfo);
                this.toolStripProgressBar1.Value = proc;
            }
            if (p_eType == ClInformationSender.eInformationType.eStartProcessing)
            {
                this.toolStripButtonOpen.Enabled = false;
                this.toolStripButtonOpenFolder.Enabled = false;
                this.toolStripButtonOpen.Enabled = false;
                pictureCorrelationMatrix = null;
            }
            if (p_eType == ClInformationSender.eInformationType.eStopProcessing)
            {
                this.toolStripButtonOpen.Enabled = true;
                this.toolStripButtonOpenFolder.Enabled = true;
                this.toolStripButtonOpen.Enabled = true;
                MessageBox.Show("Processing has ended !", "END of processing", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (p_eType == ClInformationSender.eInformationType.eColorMapChanged)
            {
                //"ColorMap: Max: 2.343455 Min: -2.54333"
                string[] splitedInfo = p_sInfo.Split(' ');
                float MaxValue = Single.Parse(splitedInfo[2]);
                float MinValue = Single.Parse(splitedInfo[4]);

                Bitmap info = new Bitmap(200,300);
                int WidthOfField = 40;
                int StartField = 20;
                for (int j = StartField; j < info.Height; j++)
                {
                    Color newColor = Preprocessing.ClTools.GetColorRGB(((float)j - StartField) / (info.Height - StartField - 1), 1.0f);

                    for (int i = 0; i < Math.Min(info.Width, WidthOfField); i++)
                    {
                        info.SetPixel(i, j, newColor);
                    }
                }

                Graphics graphic = Graphics.FromImage(info);

                string NameOfPlot = splitedInfo[0];
                graphic.DrawString(NameOfPlot, new Font("Arial", 10, FontStyle.Bold), new System.Drawing.SolidBrush(Color.Black), 5, 1);

                graphic.DrawString(MaxValue.ToString(), new Font("Arial", 10, FontStyle.Bold), new System.Drawing.SolidBrush(Preprocessing.ClTools.GetColorRGB(1.0f, 1.0f)), WidthOfField + 5, info.Height - 15);
                graphic.DrawString(MinValue.ToString(), new Font("Arial", 10, FontStyle.Bold), new System.Drawing.SolidBrush(Preprocessing.ClTools.GetColorRGB(0.0f, 1.0f)), WidthOfField + 5, StartField);

                int ZeroPosition = (int)(((0 - MinValue) / (MaxValue - MinValue)) * info.Height);
                if(ZeroPosition >=0)
                    graphic.DrawString("0.0", new Font("Arial", 10, FontStyle.Bold), new System.Drawing.SolidBrush(info.GetPixel(0, ZeroPosition)), WidthOfField + 5, ZeroPosition);

                pictureBoxAdditionalInfo.Image = info;
            }
            if (p_eType == ClInformationSender.eInformationType.eNextRecognitionScore)
            {
                string[] splitedInfo = p_sInfo.Split(' ');
                string[] score1 = splitedInfo[0].Split('/');
                string[] score2 = splitedInfo[1].Split('/');

                int x = Int32.Parse(score1[0]);
                int width = Int32.Parse(score1[1]);

                int y = Int32.Parse(score2[0]);
                int height = Int32.Parse(score2[1]);

                if (pictureCorrelationMatrix == null)
                {
                    pictureCorrelationMatrix = new Bitmap(width, height);
                    for(int i=0; i< width; i++)
                        for(int j=0; j< height; j++)
                            pictureCorrelationMatrix.SetPixel(i,j,Color.White);
                }

                pictureCorrelationMatrix.SetPixel(x, y, Color.Red);
                pictureBoxAdditionalInfo.Image = pictureCorrelationMatrix;
            }
            if (p_eType == ClInformationSender.eInformationType.eWindowInfo)
            {
                MessageBox.Show(p_sInfo,"Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public virtual void NewInformation(string p_sInformation, ClInformationSender.eInformationType p_eType)
        {
            mut.WaitOne();
            try
            {
                if (p_sInformation != null)
                {
                    if (p_eType == ClInformationSender.eInformationType.eDebugText)
                    {
                        p_sInformation = "\t" + p_sInformation;
                        p_sInformation = p_sInformation.Replace("\n", "\n\t");
                    }

                    if (m_HardLogging)
                    {
                        using (TextWriter tw = new StreamWriter(m_sFileName, true))
                        {
                            string date = DateTime.Now.ToString();
                            tw.WriteLine(date + "\t" + p_sInformation);
                            tw.Close();
                        }
                    }
                    else
                    {
                        string date = DateTime.Now.ToString();
                        m_LogMem += date + "\t" + p_sInformation + "\n";
                        m_logCount++;
                        if (m_logCount >= m_logInterval)
                        {
                            using (TextWriter tw = new StreamWriter(m_sFileName, true))
                            {
                                tw.Write(m_LogMem);
                                tw.Close();
                            }
                            m_logCount = 0;
                            m_LogMem = "";
                        }
                    }
                }
            }
            catch (Exception)
            {}

            mut.ReleaseMutex();
        }
        static private void RunAlgorithmsForFolder()
        {
            if (m_bIsRunning)
            {
                return;
            }

            m_bIsRunning = true;

            ClFileLogger FileLogger = new ClFileLogger(m_sTestDirectory + "log.txt", false);

            if (m_bLogging)
            {
                ClInformationSender.RegisterReceiver(FileLogger, ClInformationSender.eInformationType.eDebugText);
                ClInformationSender.RegisterReceiver(FileLogger, ClInformationSender.eInformationType.eTextExternal);
                ClInformationSender.RegisterReceiver(FileLogger, ClInformationSender.eInformationType.eTextInternal);
                ClInformationSender.RegisterReceiver(FileLogger, ClInformationSender.eInformationType.eError);
            }
            try
            {
                ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStartProcessing);

                int current = 1;
                int howMany = m_lFilesList.Count;

                ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStartProcessing);

                string fullAlgorithmAdditionalData = "";
                foreach (IFaceAlgorithm alg in m_lAlgorithmsList)
                {
                    fullAlgorithmAdditionalData += "\n- " + alg.GetAlgorithmFullPath();
                    fullAlgorithmAdditionalData += "\n";
                    foreach (KeyValuePair <string, string> prop in alg.GetProperitis())
                    {
                        fullAlgorithmAdditionalData += "\t" + prop.Key + " -> " + prop.Value + "\n";
                    }
                }
                fullAlgorithmAdditionalData += "\n------------------------------";
                ClInformationSender.SendInformation(fullAlgorithmAdditionalData, ClInformationSender.eInformationType.eDebugText);

                TimeSpan mean = TimeSpan.Zero;
                foreach (String file in m_lFilesList)
                {
                    DateTime start = DateTime.Now;
                    ClInformationSender.SendInformation(((current * 100) / howMany).ToString(), ClInformationSender.eInformationType.eProgress);
                    try
                    {
                        Cl3DModel newModel = new Cl3DModel();

                        newModel.LoadModel(file);

                        foreach (IFaceAlgorithm alg in m_lAlgorithmsList)
                        {
                            alg.MakeAlgorithm(ref newModel);
                        }
                    }
                    catch (ThreadAbortException)
                    {
                        ClInformationSender.SendInformation("Processing Interrupted", ClInformationSender.eInformationType.eTextInternal);
                        break;
                    }
                    catch (Exception ex)
                    {
                        ClInformationSender.SendInformation("ERROR:\n(" + file + ")\n" + ex.ToString(), ClInformationSender.eInformationType.eDebugText);
                    }
                    DateTime stop = DateTime.Now;
                    mean += (stop - start);
                    double MeanTotalHours = mean.TotalHours;
                    double MeanTotalMin   = mean.TotalMinutes;

                    int TotalTimeHours = (int)((MeanTotalHours / current) * (howMany - current));
                    int TotalTimeMin   = (int)((MeanTotalMin / current) * (howMany - current));

                    TotalTimeMin = TotalTimeMin - (TotalTimeHours * 60);

                    ClInformationSender.SendInformation("Time Remaining: " + TotalTimeHours.ToString() + "h" + TotalTimeMin.ToString("00") + "min [" + current.ToString() + "/" + howMany.ToString() + "]", ClInformationSender.eInformationType.eTextExternal);
                    current++;
                }
            }
            catch (Exception e)
            {
                ClInformationSender.SendInformation("ERROR:\n" + e.ToString(), ClInformationSender.eInformationType.eError);
            }

            m_bIsRunning = false;
            ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStopProcessing);

            ClInformationSender.UnRegisterReceiver(FileLogger, ClInformationSender.eInformationType.eDebugText);
            ClInformationSender.UnRegisterReceiver(FileLogger, ClInformationSender.eInformationType.eTextExternal);
            ClInformationSender.UnRegisterReceiver(FileLogger, ClInformationSender.eInformationType.eTextInternal);
            ClInformationSender.UnRegisterReceiver(FileLogger, ClInformationSender.eInformationType.eError);
        }
 public virtual void NewInformation(string p_sInformation, ClInformationSender.eInformationType p_eType)
 {
     m_recognitionButton.DropDownItems.Add(p_sInformation);
 }
        static public void RegisterNewAlgorithm(BuildAlgorithm p_Algorithm, string p_sAlgorithmName)
        {
            m_CreateMethodsDictionary.Add(p_sAlgorithmName, p_Algorithm);

            ClInformationSender.SendInformation(p_sAlgorithmName, ClInformationSender.eInformationType.eNewAlgorithm);
        }